]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapi/slapi_pblock.c
Remember to NULL terminate control arrays - not sure how I managed to
[openldap] / servers / slapd / slapi / slapi_pblock.c
index 8342e82abaeb8211530851463f2a2242372ee896..cc1b653e76c7f1ad9a4534af4daee43f0a2209b0 100644 (file)
@@ -420,6 +420,24 @@ pblock_set_default( Slapi_PBlock *pb, int param, void *value )
        return PBLOCK_SUCCESS;
 }
 
+static int
+pblock_be_call( Slapi_PBlock *pb, int (*bep)(Operation *) )
+{
+       BackendDB *be_orig;
+       Operation *op;
+       int rc;
+
+       PBLOCK_ASSERT_OP( pb, 0 );
+       op = pb->pb_op;
+
+       be_orig = op->o_bd;
+       op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
+       rc = (*bep)( op );
+       op->o_bd = be_orig;
+
+       return rc;
+}
+
 static int 
 pblock_get( Slapi_PBlock *pb, int param, void **value ) 
 {
@@ -485,12 +503,10 @@ pblock_get( Slapi_PBlock *pb, int param, void **value )
                *((char **)value) = pb->pb_op->o_req_ndn.bv_val;
                break;
        case SLAPI_REQUESTOR_ISROOT:
-               PBLOCK_ASSERT_OP( pb, 0 );
-               *((int *)value) = be_isroot( pb->pb_op );
+               *((int *)value) = pblock_be_call( pb, be_isroot );
                break;
        case SLAPI_IS_REPLICATED_OPERATION:
-               PBLOCK_ASSERT_OP( pb, 0 );
-               *((int *)value) = be_isupdate( pb->pb_op );
+               *((int *)value) = pblock_be_call( pb, be_slurp_update );
                break;
        case SLAPI_CONN_AUTHTYPE:
        case SLAPI_CONN_AUTHMETHOD: /* XXX should return SASL mech */
@@ -746,7 +762,8 @@ pblock_add_control( Slapi_PBlock *pb, LDAPControl *control )
 
        controls = (LDAPControl **)slapi_ch_realloc( (char *)controls,
                ( i + 2 ) * sizeof(LDAPControl *));
-       controls[i] = control;
+       controls[i++] = slapi_dup_control( control );
+       controls[i] = NULL;
 
        return pblock_set_default( pb, SLAPI_RESCONTROLS, (void *)controls );
 }
@@ -802,7 +819,7 @@ pblock_set( Slapi_PBlock *pb, int param, void *value )
                LDAPControl **ctrls = NULL;
 
                pblock_get_default( pb, param, (void **)&ctrls );
-               if ( ctrls == NULL ) {
+               if ( ctrls != NULL ) {
                        /* free old ones first */
                        ldap_controls_free( ctrls );
                }
@@ -896,10 +913,7 @@ pblock_set( Slapi_PBlock *pb, int param, void *value )
                }
 
                if ( *mlp != NULL ) {
-                       if ( pb->pb_intop )
-                               slapi_int_mods_free( *mlp ); /* caller owns values */
-                       else
-                               slap_mods_free( *mlp );  /* we own values */
+                       slapi_int_mods_free( *mlp );
                        *mlp = NULL;
                }
                *mlp = slapi_int_ldapmods2modifications( (LDAPMod **)value, NULL );
@@ -910,7 +924,8 @@ pblock_set( Slapi_PBlock *pb, int param, void *value )
                PBLOCK_VALIDATE_IS_INTOP( pb );
                if ( pb->pb_op->o_tag == LDAP_REQ_MODRDN ) {
                        rc = pblock_set_dn( value, &pb->pb_op->orr_newrdn, &pb->pb_op->orr_nnewrdn, pb->pb_op->o_tmpmemctx );
-                       if ( rc == LDAP_SUCCESS ) rc = rdn_validate( &pb->pb_op->orr_nnewrdn );
+                       if ( rc == LDAP_SUCCESS )
+                               rc = rdn_validate( &pb->pb_op->orr_nnewrdn );
                } else {
                        rc = PBLOCK_ERROR;
                }
@@ -1247,8 +1262,7 @@ pblock_destroy( Slapi_PBlock *pb )
                slapi_int_connection_done_pb( pb );
        } else {
                pblock_get_default( pb, SLAPI_MODIFY_MODS, (void **)&mods );
-               if ( mods != NULL )
-                       slapi_int_free_ldapmods( mods );
+               slapi_int_free_ldapmods( mods );
 
                pblock_get_default( pb, SLAPI_SEARCH_ATTRS, (void **)&attrs );
                if ( attrs != NULL )