From 917b77fff12435dda54b3651a871baa129bd41cb Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 16 Nov 2005 14:17:19 +0000 Subject: [PATCH] fix matched handling of slapd-ldap/slapo-chain (ITS#4176) --- servers/slapd/back-ldap/chain.c | 4 ++++ servers/slapd/back-ldap/search.c | 5 +++-- tests/scripts/test032-chain | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/servers/slapd/back-ldap/chain.c b/servers/slapd/back-ldap/chain.c index a0dbb581c2..3a582883c3 100644 --- a/servers/slapd/back-ldap/chain.c +++ b/servers/slapd/back-ldap/chain.c @@ -368,6 +368,7 @@ ldap_chain_response( Operation *op, SlapReply *rs ) sc2 = { 0 }; int rc = 0; int cache = op->o_do_not_cache; + char *matched; BerVarray ref; struct berval ndn = op->o_ndn; @@ -423,6 +424,8 @@ ldap_chain_response( Operation *op, SlapReply *rs ) * e) what ssf */ + matched = rs->sr_matched; + rs->sr_matched = NULL; ref = rs->sr_ref; rs->sr_ref = NULL; @@ -626,6 +629,7 @@ dont_chain:; op->o_bd->be_private = private; op->o_callback = sc; op->o_ndn = ndn; + rs->sr_matched = matched; rs->sr_ref = ref; ldap_pvt_thread_mutex_unlock( &lc->lc_mutex ); diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 9c880bc552..5c824d0b0c 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -155,6 +155,7 @@ ldap_back_search( int freetext = 0; int do_retry = 1; LDAPControl **ctrls = NULL; + char *save_matched = rs->sr_matched; lc = ldap_back_getconn( op, rs, LDAP_BACK_SENDERR ); if ( !lc || !ldap_back_dobind( lc, op, rs, LDAP_BACK_SENDERR ) ) { @@ -454,14 +455,14 @@ finish:; rs->sr_ctrls = NULL; } - if ( rs->sr_matched != NULL ) { + if ( rs->sr_matched != NULL && rs->sr_matched != save_matched ) { if ( rs->sr_matched != match.bv_val ) { ber_memfree_x( (char *)rs->sr_matched, op->o_tmpmemctx ); } else { LDAP_FREE( match.bv_val ); } - rs->sr_matched = NULL; + rs->sr_matched = save_matched; } if ( !BER_BVISNULL( &filter ) && filter.bv_val != op->ors_filterstr.bv_val ) { diff --git a/tests/scripts/test032-chain b/tests/scripts/test032-chain index 5b6a1db01b..cec27d7016 100755 --- a/tests/scripts/test032-chain +++ b/tests/scripts/test032-chain @@ -21,6 +21,8 @@ if test $BACKLDAP = "ldapno" ; then exit 0 fi +rm -rf $TESTDIR + mkdir -p $TESTDIR $DBDIR1 $DBDIR2 echo "Running slapadd to build slapd database..." @@ -50,6 +52,7 @@ if test $WAIT != 0 ; then echo PID $PID1 read foo fi +KILLPIDS="$PID1" echo "Starting second slapd on TCP/IP port $PORT2..." . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $CONF2 @@ -60,7 +63,7 @@ if test $WAIT != 0 ; then read foo fi -KILLPIDS="$PID1 $PID2" +KILLPIDS="$KILLPIDS $PID2" sleep 1 @@ -76,6 +79,12 @@ for i in 0 1 2 3 4 5; do sleep 5 done +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + echo "Using ldapsearch to check that second slapd is running..." for i in 0 1 2 3 4 5; do $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \ @@ -88,6 +97,12 @@ for i in 0 1 2 3 4 5; do sleep 5 done +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + for P in $PORT1 $PORT2 ; do echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..." $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \ -- 2.39.5