]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#6138 let frontend handle all exop responses
authorHoward Chu <hyc@openldap.org>
Tue, 27 Jul 2021 18:01:10 +0000 (19:01 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 3 Aug 2021 15:19:49 +0000 (15:19 +0000)
servers/slapd/back-ldap/extended.c

index f51257753f74a382bc8899529a517d3a27cc76d0..1d9c7b208180cef7b2981e9ec5b726d78e3bd7b5 100644 (file)
@@ -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 ) {