]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/compare.c
minor cleanup
[openldap] / servers / slapd / back-meta / compare.c
index e447f7a8d10345468a8d648ebb1d12890fd01b0f..65fdde05f01c50c9a084b29dacd6ba974f750884 100644 (file)
@@ -35,8 +35,7 @@ int
 meta_back_compare( Operation *op, SlapReply *rs )
 {
        metainfo_t              *mi = ( metainfo_t * )op->o_bd->be_private;
-       metaconn_t              *mc;
-       metasingleconn_t        *msc;
+       metaconn_t              *mc = NULL;
        char                    *match = NULL,
                                *err = NULL;
        struct berval           mmatch = BER_BVNULL;
@@ -59,7 +58,9 @@ meta_back_compare( Operation *op, SlapReply *rs )
        
        msgid = ch_calloc( sizeof( int ), mi->mi_ntargets );
        if ( msgid == NULL ) {
-               return -1;
+               send_ldap_error( op, rs, LDAP_OTHER, NULL );
+               rc = LDAP_OTHER;
+               goto done;
        }
 
        /*
@@ -69,10 +70,10 @@ meta_back_compare( Operation *op, SlapReply *rs )
        dc.rs = rs;
        dc.ctx = "compareDN";
 
-       for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); ++i, ++msc ) {
-               struct berval mdn = BER_BVNULL;
-               struct berval mapped_attr = op->orc_ava->aa_desc->ad_cname;
-               struct berval mapped_value = op->orc_ava->aa_value;
+       for ( i = 0; i < mi->mi_ntargets; i++ ) {
+               struct berval           mdn = BER_BVNULL;
+               struct berval           mapped_attr = op->orc_ava->aa_desc->ad_cname;
+               struct berval           mapped_value = op->orc_ava->aa_value;
 
                if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
                        msgid[ i ] = -1;
@@ -171,13 +172,13 @@ meta_back_compare( Operation *op, SlapReply *rs )
                /*
                 * FIXME: should we check for abandon?
                 */
-               for ( i = 0, msc = &mc->mc_conns[ 0 ]; !META_LAST( msc ); msc++, i++ ) {
-                       int             lrc;
-                       LDAPMessage     *res = NULL;
-                       struct timeval  tv = { 0 };
+               for ( i = 0; i < mi->mi_ntargets; i++ ) {
+                       metasingleconn_t        *msc = &mc->mc_conns[ i ];
+                       int                     lrc;
+                       LDAPMessage             *res = NULL;
+                       struct timeval          tv;
 
-                       tv.tv_sec = 0;
-                       tv.tv_usec = 0;
+                       LDAP_BACK_TV_SET( &tv );
 
                        if ( msgid[ i ] == -1 ) {
                                continue;
@@ -287,13 +288,19 @@ finish:;
                 * At least one compare failed with matched portion,
                 * and none was successful
                 */
-       } else if ( match != NULL &&  match[0] != '\0' ) {
-               struct berval matched;
+       } else if ( match != NULL && match[ 0 ] != '\0' ) {
+               struct berval matched, pmatched;
 
                ber_str2bv( match, 0, 0, &matched );
 
                dc.ctx = "matchedDN";
                ldap_back_dn_massage( &dc, &matched, &mmatch );
+               if ( dnPretty( NULL, &mmatch, &pmatched, NULL ) == LDAP_SUCCESS ) {
+                       if ( mmatch.bv_val != match ) {
+                               free( mmatch.bv_val );
+                       }
+                       mmatch = pmatched;
+               }
        }
 
        if ( rres != LDAP_SUCCESS ) {
@@ -313,7 +320,10 @@ finish:;
        if ( msgid ) {
                free( msgid );
        }
-       
+
+done:;
+       meta_back_release_conn( op, mc );
+
        return rc;
 }