]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/compare.c
Improve schema error messages
[openldap] / servers / slapd / back-meta / compare.c
index 9ba3ac29368360afe2fc82be0fbd0719254edaad..40cc65159ace4f554e7a14785b47ae1ec535423a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2001 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  *
  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
@@ -80,8 +80,8 @@ meta_back_compare(
                Backend                 *be,
                Connection              *conn,
                Operation               *op,
-               const char              *dn,
-               const char              *ndn,
+               struct berval           *dn,
+               struct berval           *ndn,
                AttributeAssertion      *ava
 )
 {
@@ -89,7 +89,8 @@ meta_back_compare(
        struct metaconn *lc;
        struct metasingleconn **lsc;
        char *match = NULL, *err = NULL, *mmatch = NULL;
-       int candidates = 0, last = 0, i, count, rc, cres, rres;
+       int candidates = 0, last = 0, i, count, rc;
+               int cres = LDAP_SUCCESS, rres = LDAP_SUCCESS;
        int *msgid;
 
        lc = meta_back_getconn( li, conn, op, META_OP_ALLOW_MULTIPLE,
@@ -108,8 +109,8 @@ meta_back_compare(
         */
        for ( i = 0, lsc = lc->conns; lsc[ 0 ] != NULL; ++i, ++lsc ) {
                char *mdn = NULL;
-               char *mapped_attr = ava->aa_desc->ad_cname->bv_val;
-               char *mapped_value = ava->aa_value->bv_val;
+               struct berval mapped_attr = ava->aa_desc->ad_cname;
+               struct berval mapped_value = ava->aa_value;
 
                if ( lsc[ 0 ]->candidate != META_CANDIDATE ) {
                        continue;
@@ -119,22 +120,32 @@ meta_back_compare(
                 * Rewrite the compare dn, if needed
                 */
                switch ( rewrite_session( li->targets[ i ]->rwinfo,
-                                       "compareDn", dn, conn, &mdn ) ) {
+                                       "compareDn", 
+                                       dn->bv_val, conn, &mdn ) ) {
                case REWRITE_REGEXEC_OK:
                        if ( mdn == NULL ) {
-                               mdn = ( char * )dn;
+                               mdn = ( char * )dn->bv_val;
                        }
+#ifdef NEW_LOGGING
+                       LDAP_LOG( BACK_META, DETAIL1,
+                               "[rw] compareDn: \"%s\" -> \"%s\"\n", dn->bv_val, mdn, 0 );
+#else /* !NEW_LOGGING */
                        Debug( LDAP_DEBUG_ARGS,
                                        "rw> compareDn: \"%s\" -> \"%s\"\n%s",
-                                       dn, mdn, "" );
+                                       dn->bv_val, mdn, "" );
+#endif /* !NEW_LOGGING */
                        break;
                
                case REWRITE_REGEXEC_UNWILLING:
                        send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
                                        NULL, "Unwilling to perform",
                                        NULL, NULL );
+                       return -1;
                        
                case REWRITE_REGEXEC_ERR:
+                       send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
+                                       NULL, "Operations error",
+                                       NULL, NULL );
                        return -1;
                }
 
@@ -143,10 +154,10 @@ meta_back_compare(
                 */
                if ( ava->aa_desc->ad_type->sat_oid 
                        == slap_schema.si_ad_objectClass->ad_type->sat_oid ) {
-                       mapped_value = ldap_back_map( &li->targets[ i ]->oc_map,
-                                       ava->aa_value->bv_val, 0 );
+                       ldap_back_map( &li->targets[ i ]->oc_map,
+                                       &ava->aa_value, &mapped_value, 0 );
 
-                       if ( mapped_value == NULL ) {
+                       if ( mapped_value.bv_val == NULL ) {
                                lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
                                continue;
                        }
@@ -154,9 +165,9 @@ meta_back_compare(
                 * else try to remap the attribute
                 */
                } else {
-                       mapped_attr = ldap_back_map( &li->targets[ i ]->at_map,
-                               ava->aa_desc->ad_cname->bv_val, 0 );
-                       if ( mapped_attr == NULL ) {
+                       ldap_back_map( &li->targets[ i ]->at_map,
+                               &ava->aa_desc->ad_cname, &mapped_attr, 0 );
+                       if ( mapped_attr.bv_val == NULL ) {
                                lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
                                continue;
                        }
@@ -168,20 +179,20 @@ meta_back_compare(
                 * of the result ought to be enforced
                 */
                msgid[ i ] = ldap_compare( lc->conns[ i ]->ld, mdn,
-                               mapped_attr, mapped_value );
+                               mapped_attr.bv_val, mapped_value.bv_val );
                if ( msgid[ i ] == -1 ) {
                        lsc[ 0 ]->candidate = META_NOT_CANDIDATE;
                        continue;
                }
 
-               if ( mdn != dn ) {
+               if ( mdn != dn->bv_val ) {
                        free( mdn );
                }
-               if ( mapped_attr != ava->aa_desc->ad_cname->bv_val ) {
-                       free( mapped_attr );
+               if ( mapped_attr.bv_val != ava->aa_desc->ad_cname.bv_val ) {
+                       free( mapped_attr.bv_val );
                }
-               if ( mapped_value != ava->aa_value->bv_val ) {
-                       free( mapped_value );
+               if ( mapped_value.bv_val != ava->aa_value.bv_val ) {
+                       free( mapped_value.bv_val );
                }
 
                ++candidates;
@@ -232,7 +243,7 @@ meta_back_compare(
                                         * sending to cache ...
                                         */
                                        if ( li->cache.ttl != META_DNCACHE_DISABLED ) {
-                                               ( void )meta_dncache_update_entry( &li->cache, ch_strdup( ndn ), i );
+                                               ( void )meta_dncache_update_entry( &li->cache, ndn, i );
                                        }
 
                                        count++;
@@ -270,7 +281,7 @@ meta_back_compare(
                }
        }
 
-finish:
+finish:;
 
        /*
         * Rewrite the matched portion of the search base, if required
@@ -301,9 +312,14 @@ finish:
                        if ( mmatch == NULL ) {
                                mmatch = ( char * )match;
                        }
+#ifdef NEW_LOGGING
+                       LDAP_LOG( BACK_META, DETAIL1,
+                               "[rw] matchedDn: \"%s\" -> \"%s\"\n", match, mmatch, 0 );
+#else /* !NEW_LOGGING */
                        Debug( LDAP_DEBUG_ARGS, "rw> matchedDn:"
                                        " \"%s\" -> \"%s\"\n%s",
                                        match, mmatch, "" );
+#endif /* !NEW_LOGGING */
                        break;
                        
                
@@ -311,15 +327,21 @@ finish:
                        send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
                                        NULL, "Unwilling to perform",
                                        NULL, NULL );
-                       /* continue to the next case */
+                       rc = -1;
+                       goto cleanup;
                        
                case REWRITE_REGEXEC_ERR:
+                       send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
+                                       NULL, "Operations error",
+                                       NULL, NULL );
                        rc = -1;
-                       break;
+                       goto cleanup;
                }
-       }       
+       }
+
        send_ldap_result( conn, op, rres, mmatch, err, NULL, NULL );
 
+cleanup:;
        if ( match != NULL ) {
                if ( mmatch != match ) {
                        free( mmatch );