From: Howard Chu Date: Tue, 27 Jul 2021 18:01:10 +0000 (+0100) Subject: ITS#6138 let frontend handle all exop responses X-Git-Tag: OPENLDAP_REL_ENG_2_6_0~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a54f99858c8182afee4b0b4d600d277f0c277df0;p=thirdparty%2Fopenldap.git ITS#6138 let frontend handle all exop responses --- diff --git a/servers/slapd/back-ldap/extended.c b/servers/slapd/back-ldap/extended.c index f51257753f..1d9c7b2081 100644 --- a/servers/slapd/back-ldap/extended.c +++ b/servers/slapd/back-ldap/extended.c @@ -54,18 +54,15 @@ ldap_back_extended_one( Operation *op, SlapReply *rs, ldap_back_exop_f exop ) * called twice; maybe we could avoid the * ldap_back_dobind() call inside each extended() * call ... */ - if ( !ldap_back_dobind( &lc, op, rs, LDAP_BACK_SENDERR ) ) { - return -1; + if ( !ldap_back_dobind( &lc, op, rs, LDAP_BACK_DONTSEND ) ) { + return rs->sr_err; } ctrls = oldctrls = op->o_ctrls; if ( ldap_back_controls_add( op, rs, lc, &ctrls ) ) { op->o_ctrls = oldctrls; - send_ldap_extended( op, rs ); - rs->sr_text = NULL; - /* otherwise frontend resends result */ - rc = rs->sr_err = SLAPD_ABANDON; + rc = rs->sr_err; goto done; } @@ -242,11 +239,22 @@ retry: } } + if ( text ) { + /* copy to tmpmem, doesn't need to be freed */ + rs->sr_text = op->o_tmpalloc( strlen( text ) + 1, op->o_tmpmemctx ); + strcpy( rs->sr_text, text ); + ch_free( text ); + } + if ( rs->sr_matched ) + rs->sr_flags |= REP_MATCHED_MUSTBEFREED; + if ( rs->sr_ctrls ) + rs->sr_flags |= REP_CTRLS_MUSTBEFREED; + if ( rc != LDAP_SUCCESS ) { rs->sr_err = slap_map_api2result( rs ); if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) { do_retry = 0; - if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) { + if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_DONTSEND ) ) { goto retry; } } @@ -255,11 +263,6 @@ retry: ldap_back_quarantine( op, rs ); } - if ( text ) rs->sr_text = text; - send_ldap_extended( op, rs ); - /* otherwise frontend resends result */ - rc = rs->sr_err = SLAPD_ABANDON; - } else if ( LDAP_BACK_QUARANTINE( li ) ) { ldap_back_quarantine( op, rs ); } @@ -273,22 +276,6 @@ retry: op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx ); } - /* these have to be freed anyway... */ - if ( rs->sr_matched ) { - free( (char *)rs->sr_matched ); - rs->sr_matched = NULL; - } - - if ( rs->sr_ctrls ) { - ldap_controls_free( rs->sr_ctrls ); - rs->sr_ctrls = NULL; - } - - if ( text ) { - free( text ); - rs->sr_text = NULL; - } - /* in case, cleanup handler */ if ( lc == NULL ) { *lcp = NULL; @@ -363,7 +350,7 @@ retry: rs->sr_err = slap_map_api2result( rs ); if ( rs->sr_err == LDAP_UNAVAILABLE && do_retry ) { do_retry = 0; - if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_SENDERR ) ) { + if ( ldap_back_retry( &lc, op, rs, LDAP_BACK_DONTSEND ) ) { goto retry; } } @@ -371,12 +358,6 @@ retry: if ( LDAP_BACK_QUARANTINE( li ) ) { ldap_back_quarantine( op, rs ); } - - if ( text ) rs->sr_text = text; - send_ldap_extended( op, rs ); - /* otherwise frontend resends result */ - rc = rs->sr_err = SLAPD_ABANDON; - } else if ( LDAP_BACK_QUARANTINE( li ) ) { ldap_back_quarantine( op, rs ); } @@ -385,21 +366,16 @@ retry: ldap_pvt_mp_add( li->li_ops_completed[ SLAP_OP_EXTENDED ], 1 ); ldap_pvt_thread_mutex_unlock( &li->li_counter_mutex ); - /* these have to be freed anyway... */ - if ( rs->sr_matched ) { - free( (char *)rs->sr_matched ); - rs->sr_matched = NULL; - } - - if ( rs->sr_ctrls ) { - ldap_controls_free( rs->sr_ctrls ); - rs->sr_ctrls = NULL; - } - if ( text ) { - free( text ); - rs->sr_text = NULL; + /* copy to tmpmem, doesn't need to be freed */ + rs->sr_text = op->o_tmpalloc( strlen( text ) + 1, op->o_tmpmemctx ); + strcpy( rs->sr_text, text ); + ch_free( text ); } + if ( rs->sr_matched ) + rs->sr_flags |= REP_MATCHED_MUSTBEFREED; + if ( rs->sr_ctrls ) + rs->sr_flags |= REP_CTRLS_MUSTBEFREED; /* in case, cleanup handler */ if ( lc == NULL ) {