]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-sql/other.c
now I remember why I introduced the 'has_ldapinfo_dn_ru' flag
[openldap] / servers / slapd / back-sql / other.c
index c5a9d10132e540f1e30170a9f85b28311b3c9a6f..6c9dd6e188a892c5359554e08a8e7285d11a3c5d 100644 (file)
@@ -1,10 +1,21 @@
-/*
- *      Copyright 1999, Dmitry Kovalev <mit@openldap.org>, All rights reserved.
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1999-2004 The OpenLDAP Foundation.
+ * Portions Copyright 1999 Dmitry Kovalev.
+ * All rights reserved.
  *
- *      Redistribution and use in source and binary forms are permitted only
- *      as authorized by the OpenLDAP Public License.  A copy of this
- *      license is available at http://www.OpenLDAP.org/license.html or
- *      in file LICENSE in the top-level directory of the distribution.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by Dmitry Kovalev for inclusion
+ * by OpenLDAP Software.
  */
 
 #include "portable.h"
@@ -25,11 +36,17 @@ backsql_compare( Operation *op, SlapReply *rs )
        backsql_info            *bi = (backsql_info*)op->o_bd->be_private;
        backsql_entryID         user_id;
        SQLHDBC                 dbh;
-       Entry                   *e, user_entry;
-       Attribute               *a;
+       Entry                   *e = NULL, user_entry;
+       Attribute               *a = NULL, *a_op = NULL;
        backsql_srch_info       bsi;
        int                     rc;
        AttributeName           anlist[2];
+
+       user_entry.e_name.bv_val = NULL;
+       user_entry.e_name.bv_len = 0;
+       user_entry.e_nname.bv_val = NULL;
+       user_entry.e_nname.bv_len = 0;
+       user_entry.e_attrs = NULL;
  
        Debug( LDAP_DEBUG_TRACE, "==>backsql_compare()\n", 0, 0, 0 );
 
@@ -47,25 +64,60 @@ backsql_compare( Operation *op, SlapReply *rs )
        rc = backsql_dn2id( bi, &user_id, dbh, &op->o_req_ndn );
        if ( rc != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
-                       "could not retrieve bind dn id - no such entry\n", 
+                       "could not retrieve compare dn id - no such entry\n", 
                        0, 0, 0 );
-               rs->sr_err = LDAP_INVALID_CREDENTIALS;
+               rs->sr_err = LDAP_NO_SUCH_OBJECT;
                goto return_results;
        }
 
        anlist[0].an_name = op->oq_compare.rs_ava->aa_desc->ad_cname;
        anlist[0].an_desc = op->oq_compare.rs_ava->aa_desc;
        anlist[1].an_name.bv_val = NULL;
-       backsql_init_search( &bsi, bi, &op->o_req_ndn, LDAP_SCOPE_BASE, 
-                       -1, -1, -1, NULL, dbh, op->o_bd, op->o_conn, op,
-                       anlist);
-       e = backsql_id2entry( &bsi, &user_entry, &user_id );
-       if ( e == NULL ) {
-               Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
-                       "error in backsql_id2entry() - auth failed\n",
-                       0, 0, 0 );
-               rs->sr_err = LDAP_OTHER;
-               goto return_results;
+
+       /*
+        * Try to get attr as dynamic operational
+        */
+       if ( is_at_operational( op->oq_compare.rs_ava->aa_desc->ad_type ) ) {
+               AttributeName   *an_old;
+               Entry           *e_old;
+
+               user_entry.e_attrs = NULL;
+               user_entry.e_name = op->o_req_dn;
+               user_entry.e_nname = op->o_req_ndn;
+
+               an_old = rs->sr_attrs;
+               e_old = rs->sr_entry;
+
+               rs->sr_attrs = anlist;
+               rs->sr_entry = &user_entry;
+               rs->sr_err = backsql_operational( op, rs, 0, &a_op );
+               rs->sr_attrs = an_old;
+               rs->sr_entry = e_old;
+
+               if ( rs->sr_err != LDAP_SUCCESS ) {
+                       goto return_results;
+               }
+               
+       }
+
+       /*
+        * attr was dynamic operational
+        */
+       if ( a_op != NULL ) {
+               user_entry.e_attrs = a_op;
+               e = &user_entry;
+
+       } else {
+               backsql_init_search( &bsi, &op->o_req_ndn, LDAP_SCOPE_BASE, 
+                               -1, -1, -1, NULL, dbh, op, anlist );
+               e = backsql_id2entry( &bsi, &user_entry, &user_id );
+               if ( e == NULL ) {
+                       Debug( LDAP_DEBUG_TRACE, "backsql_compare(): "
+                               "error in backsql_id2entry() "
+                               "- compare failed\n", 0, 0, 0 );
+                       rs->sr_err = LDAP_OTHER;
+                       goto return_results;
+               }
        }
 
        if ( ! access_allowed( op, e, op->oq_compare.rs_ava->aa_desc, 
@@ -75,7 +127,6 @@ backsql_compare( Operation *op, SlapReply *rs )
                goto return_results;
        }
 
-
        rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
        for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc );
                        a != NULL;
@@ -85,7 +136,9 @@ backsql_compare( Operation *op, SlapReply *rs )
                if ( value_find_ex( op->oq_compare.rs_ava->aa_desc,
                                        SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH |
                                        SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH,
-                                       a->a_nvals, &op->oq_compare.rs_ava->aa_value ) == 0 )
+                                       a->a_nvals,
+                                       &op->oq_compare.rs_ava->aa_value,
+                                       op->o_tmpmemctx ) == 0 )
                {
                        rs->sr_err = LDAP_COMPARE_TRUE;
                        break;
@@ -95,6 +148,20 @@ backsql_compare( Operation *op, SlapReply *rs )
 return_results:;
        send_ldap_result( op, rs );
 
+       if ( e != NULL ) {
+               if ( e->e_name.bv_val != NULL ) {
+                       free( e->e_name.bv_val );
+               }
+
+               if ( e->e_nname.bv_val != NULL ) {
+                       free( e->e_nname.bv_val );
+               }
+
+               if ( e->e_attrs != NULL ) {
+                       attrs_free( e->e_attrs );
+               }
+       }
+
        Debug(LDAP_DEBUG_TRACE,"<==backsql_compare()\n",0,0,0);
        switch ( rs->sr_err ) {
        case LDAP_COMPARE_TRUE:
@@ -151,15 +218,15 @@ backsql_operational(
                        break;
 
                default:
-                       Debug(LDAP_DEBUG_TRACE, 
-                               "backsql_operational(): "
-                               "has_children failed( %d)\n", 
-                               rc, 0, 0 );
+                       Debug( LDAP_DEBUG_TRACE, "backsql_operational(): "
+                               "has_children failed( %d)\n", rc, 0, 0 );
                        rc = 1;
                        break;
                }
        }
 
+       Debug( LDAP_DEBUG_TRACE, "<==backsql_operational()\n", 0, 0, 0);
+
        return rc;
 }