]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/chain.c
Merge remote-tracking branch 'origin/mdb.RE/0.9' into OPENLDAP_REL_ENG_2_4
[openldap] / servers / slapd / back-ldap / chain.c
index a7c53ed41bddf91adf858548c9c421195f4d1076..1b9bd8654d7841b4a71a4bc2a7708c66d35d667f 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003-2013 The OpenLDAP Foundation.
+ * Copyright 2003-2015 The OpenLDAP Foundation.
  * Portions Copyright 2003 Howard Chu.
  * All rights reserved.
  *
@@ -196,12 +196,13 @@ chaining_control_remove(
         * added by the chain overlay, so it's the only one we explicitly 
         * free */
        if ( op->o_ctrls != oldctrls ) {
-               assert( op->o_ctrls != NULL );
-               assert( op->o_ctrls[ 0 ] != NULL );
+               if ( op->o_ctrls != NULL ) {
+                       assert( op->o_ctrls[ 0 ] != NULL );
 
-               free( op->o_ctrls );
+                       free( op->o_ctrls );
 
-               op->o_chaining = 0;
+                       op->o_chaining = 0;
+               }
                op->o_ctrls = oldctrls;
        } 
 
@@ -320,6 +321,10 @@ ldap_chain_cb_search_response( Operation *op, SlapReply *rs )
 
                /* back-ldap tried to send result */
                lb->lb_status = LDAP_CH_RES;
+               /* don't let other callbacks run, this isn't
+                * the real result for this op.
+                */
+               op->o_callback->sc_next = NULL;
        }
 
        return 0;
@@ -623,6 +628,11 @@ cleanup:;
                }
 
 further_cleanup:;
+               if ( op->o_req_dn.bv_val == pdn.bv_val ) {
+                       op->o_req_dn = odn;
+                       op->o_req_ndn = ondn;
+               }
+
                if ( free_dn ) {
                        op->o_tmpfree( pdn.bv_val, op->o_tmpmemctx );
                        op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
@@ -648,9 +658,6 @@ further_cleanup:;
                rc = rs2.sr_err;
        }
 
-       op->o_req_dn = odn;
-       op->o_req_ndn = ondn;
-
 #ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
        (void)chaining_control_remove( op, &ctrls );
 #endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
@@ -894,14 +901,16 @@ cleanup:;
                }
                
 further_cleanup:;
+               if ( op->o_req_dn.bv_val == pdn.bv_val ) {
+                       op->o_req_dn = odn;
+                       op->o_req_ndn = ondn;
+               }
+
                if ( free_dn ) {
                        op->o_tmpfree( pdn.bv_val, op->o_tmpmemctx );
                        op->o_tmpfree( ndn.bv_val, op->o_tmpmemctx );
                }
 
-               op->o_req_dn = odn;
-               op->o_req_ndn = ondn;
-
                if ( tmp_oq_search.rs_filter != NULL ) {
                        filter_free_x( op, tmp_oq_search.rs_filter, 1 );
                }
@@ -924,8 +933,6 @@ further_cleanup:;
        (void)chaining_control_remove( op, &ctrls );
 #endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
 
-       op->o_req_dn = odn;
-       op->o_req_ndn = ondn;
        rs->sr_type = REP_SEARCHREF;
        rs->sr_entry = save_entry;
        rs->sr_flags = save_flags;
@@ -1356,17 +1363,18 @@ fail:
 
        li = ca->be->be_private;
 
-
-       li->li_uri = ch_strdup( at->a_vals[ 0 ].bv_val );
-       value_add_one( &li->li_bvuri, &at->a_vals[ 0 ] );
-       if ( avl_insert( &lc->lc_lai.lai_tree, (caddr_t)li,
-               ldap_chain_uri_cmp, ldap_chain_uri_dup ) )
-       {
-               Debug( LDAP_DEBUG_ANY, "slapd-chain: "
-                       "database \"%s\" insert failed.\n",
-                       e->e_name.bv_val, 0, 0 );
-               rc = LDAP_CONSTRAINT_VIOLATION;
-               goto done;
+       if ( at ) {
+               li->li_uri = ch_strdup( at->a_vals[ 0 ].bv_val );
+               value_add_one( &li->li_bvuri, &at->a_vals[ 0 ] );
+               if ( avl_insert( &lc->lc_lai.lai_tree, (caddr_t)li,
+                       ldap_chain_uri_cmp, ldap_chain_uri_dup ) )
+               {
+                       Debug( LDAP_DEBUG_ANY, "slapd-chain: "
+                               "database \"%s\" insert failed.\n",
+                               e->e_name.bv_val, 0, 0 );
+                       rc = LDAP_CONSTRAINT_VIOLATION;
+                       goto done;
+               }
        }
 
        ca->ca_private = on;