From fcbc1f484d4216757ec0ff32436afa1f7fe3a437 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 18 May 2006 22:28:22 +0000 Subject: [PATCH] fix referrals return for ops other than search (ITS#4557); use slab memory for temporaries in returning referrals --- servers/slapd/back-ldap/bind.c | 36 +++++++++++++++++++++++++++++--- servers/slapd/back-ldap/search.c | 10 +++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/servers/slapd/back-ldap/bind.c b/servers/slapd/back-ldap/bind.c index 44d621d45c..11f55d21f1 100644 --- a/servers/slapd/back-ldap/bind.c +++ b/servers/slapd/back-ldap/bind.c @@ -1126,11 +1126,15 @@ ldap_back_op_result( char *match = NULL; LDAPMessage *res = NULL; char *text = NULL; + char **refs = NULL; + LDAPControl **ctrls = NULL; #define ERR_OK(err) ((err) == LDAP_SUCCESS || (err) == LDAP_COMPARE_FALSE || (err) == LDAP_COMPARE_TRUE) rs->sr_text = NULL; rs->sr_matched = NULL; + rs->sr_ref = NULL; + rs->sr_ctrls = NULL; /* if the error recorded in the reply corresponds * to a successful state, get the error from the @@ -1176,11 +1180,26 @@ retry:; * LDAP_COMPARE_{TRUE|FALSE}) */ default: rc = ldap_parse_result( lc->lc_ld, res, &rs->sr_err, - &match, &text, NULL, NULL, 1 ); + &match, &text, &refs, &ctrls, 1 ); rs->sr_text = text; if ( rc != LDAP_SUCCESS ) { rs->sr_err = rc; } + if ( refs != NULL ) { + int i; + + for ( i = 0; refs[ i ] != NULL; i++ ) + /* count */ ; + rs->sr_ref = op->o_tmpalloc( sizeof( struct berval ) * ( i + 1 ), + op->o_tmpmemctx ); + for ( i = 0; refs[ i ] != NULL; i++ ) { + ber_str2bv( refs[ i ], 0, 0, &rs->sr_ref[ i ] ); + } + BER_BVZERO( &rs->sr_ref[ i ] ); + } + if ( ctrls != NULL ) { + rs->sr_ctrls = ctrls; + } } } @@ -1200,8 +1219,8 @@ retry:; } } if ( op->o_conn && - ( ( sendok & LDAP_BACK_SENDOK ) - || ( ( sendok & LDAP_BACK_SENDERR ) && rs->sr_err != LDAP_SUCCESS ) ) ) + ( ( sendok & LDAP_BACK_SENDOK ) + || ( ( sendok & LDAP_BACK_SENDERR ) && rs->sr_err != LDAP_SUCCESS ) ) ) { send_ldap_result( op, rs ); } @@ -1216,6 +1235,17 @@ retry:; ldap_memfree( text ); } rs->sr_text = NULL; + if ( rs->sr_ref ) { + assert( refs != NULL ); + ber_memvfree( (void **)refs ); + op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx ); + rs->sr_ref = NULL; + } + if ( ctrls ) { + assert( rs->sr_ctrls != NULL ); + ldap_controls_free( ctrls ); + rs->sr_ctrls = NULL; + } return( ERR_OK( rs->sr_err ) ? LDAP_SUCCESS : rs->sr_err ); } diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index dbe612d549..ec68159ccf 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -344,7 +344,8 @@ retry: /* NO OP */ ; /* FIXME: there MUST be at least one */ - rs->sr_ref = ch_malloc( ( cnt + 1 ) * sizeof( struct berval ) ); + rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ), + op->o_tmpmemctx ); for ( cnt = 0; references[ cnt ]; cnt++ ) { ber_str2bv( references[ cnt ], 0, 0, &rs->sr_ref[ cnt ] ); @@ -365,7 +366,7 @@ retry: /* cleanup */ if ( references ) { ber_memvfree( (void **)references ); - ch_free( rs->sr_ref ); + op->o_tmpfree( rs->sr_ref, op->o_tmpmemctx ); rs->sr_ref = NULL; } @@ -405,7 +406,8 @@ retry: for ( cnt = 0; references[ cnt ]; cnt++ ) /* NO OP */ ; - rs->sr_ref = ch_malloc( ( cnt + 1 ) * sizeof( struct berval ) ); + rs->sr_ref = op->o_tmpalloc( ( cnt + 1 ) * sizeof( struct berval ), + op->o_tmpmemctx ); for ( cnt = 0; references[ cnt ]; cnt++ ) { /* duplicating ...*/ @@ -495,7 +497,7 @@ finish:; } if ( rs->sr_ref ) { - ber_bvarray_free( rs->sr_ref ); + ber_bvarray_free_x( rs->sr_ref, op->o_tmpmemctx ); rs->sr_ref = NULL; } -- 2.39.5