From: Pierangelo Masarati Date: Sat, 7 Jan 2006 12:35:02 +0000 (+0000) Subject: improve previous commit X-Git-Tag: OPENLDAP_REL_ENG_2_4_BP~409 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a6203bd1ef20931e75de137ecbd993d9ca00e029;p=openldap improve previous commit --- diff --git a/servers/slapd/back-ldbm/compare.c b/servers/slapd/back-ldbm/compare.c index 4055f4bccb..7b80428047 100644 --- a/servers/slapd/back-ldbm/compare.c +++ b/servers/slapd/back-ldbm/compare.c @@ -36,13 +36,20 @@ ldbm_back_compare( Attribute *a; int manageDSAit = get_manageDSAit( op ); + rs->sr_matched = NULL; + rs->sr_ref = NULL; + /* grab giant lock for reading */ ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock); /* get entry with reader lock */ - if ( (e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched )) == NULL ) { + e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched ); + if ( e == NULL ) { if ( matched != NULL ) { - rs->sr_matched = ch_strdup( matched->e_dn ); + struct berval bv; + + ber_str2bv_x( matched, 0, 1, &bv, op->o_tmpmemctx ); + rs->sr_matched = bv.bv_val; rs->sr_ref = is_entry_referral( matched ) ? get_entry_referrals( op, matched ) : NULL; @@ -55,16 +62,12 @@ ldbm_back_compare( ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock); rs->sr_err = LDAP_REFERRAL; - send_ldap_result( op, rs ); - - if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); - free( (char *)rs->sr_matched ); - rs->sr_ref = NULL; - rs->sr_matched = NULL; - return rs->sr_err; + goto return_results; } - if (!manageDSAit && is_entry_referral( e ) ) { + if ( !manageDSAit && is_entry_referral( e ) ) { + struct berval bv; + /* entry is a referral, don't allow add */ rs->sr_ref = get_entry_referrals( op, e ); @@ -73,12 +76,9 @@ ldbm_back_compare( rs->sr_err = LDAP_REFERRAL; - rs->sr_matched = e->e_name.bv_val; - send_ldap_result( op, rs ); + ber_dupbv_x( &bv, &e->e_name, op->o_tmpmemctx ); + rs->sr_matched = bv.bv_val; - if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref ); - rs->sr_ref = NULL; - rs->sr_matched = NULL; goto return_results; } @@ -113,16 +113,24 @@ return_results:; cache_return_entry_r( &li->li_cache, e ); ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock); + send_ldap_result( op, rs ); + switch ( rs->sr_err ) { - case LDAP_NO_SUCH_ATTRIBUTE: case LDAP_COMPARE_FALSE: case LDAP_COMPARE_TRUE: - send_ldap_result( op, rs ); - if ( rs->sr_err != LDAP_NO_SUCH_ATTRIBUTE ) { - rs->sr_err = LDAP_SUCCESS; - } + rs->sr_err = LDAP_SUCCESS; break; } + if ( rs->sr_ref != NULL ) { + ber_bvarray_free( rs->sr_ref ); + rs->sr_ref = NULL; + } + + if ( rs->sr_matched != NULL ) { + op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx ); + rs->sr_matched = NULL; + } + return rs->sr_err; }