]> git.sur5r.net Git - openldap/commitdiff
Remove SLAPI pblock from operation structure
authorLuke Howard <lukeh@openldap.org>
Fri, 22 Jul 2005 07:54:17 +0000 (07:54 +0000)
committerLuke Howard <lukeh@openldap.org>
Fri, 22 Jul 2005 07:54:17 +0000 (07:54 +0000)
servers/slapd/operation.c
servers/slapd/slap.h
servers/slapd/slapi/slapi.h
servers/slapd/slapi/slapi_ops.c
servers/slapd/slapi/slapi_overlay.c
servers/slapd/slapi/slapi_utils.c

index 24805df0ab7ca5ed9d3dbbcc82deeec435bdb6dd..f8ecf3b920548920b5d3bbb7f85372ea9e09882d 100644 (file)
@@ -97,8 +97,7 @@ slap_op_free( Operation *op )
        }
 
 #if defined( LDAP_SLAPI )
-       if ( SLAPI_OPERATION_PBLOCK( op ) ) {
-               slapi_pblock_destroy( SLAPI_OPERATION_PBLOCK( op ) );
+       if ( slapi_plugins_used ) {
                slapi_int_free_object_extensions( SLAPI_X_EXT_OPERATION, op );
        }
 #endif /* defined( LDAP_SLAPI ) */
@@ -152,7 +151,6 @@ slap_op_alloc(
 
 #if defined( LDAP_SLAPI )
        if ( slapi_plugins_used ) {
-               SLAPI_OPERATION_PBLOCK( op ) = slapi_pblock_new();
                slapi_int_create_object_extensions( SLAPI_X_EXT_OPERATION, op );
        }
 #endif /* defined( LDAP_SLAPI ) */
index 76f22039ee94c3afe8c7017a592f72372c7ac079..49ff60dbe27195196398ddf2c27cd932add92202 100644 (file)
@@ -2292,7 +2292,6 @@ typedef struct slap_op_header {
        char            oh_log_prefix[sizeof("conn=18446744073709551615 op=18446744073709551615")];
 
 #ifdef LDAP_SLAPI
-       void    *oh_pb;                  /* NS-SLAPI plugin */
        void    *oh_extensions;         /* NS-SLAPI plugin */
 #endif
 } Opheader;
index baa14b605e8aa0caf8809c1619d024d20be5aa84..78aef6f6ef38ea1a19ae30d09d4fce05c197d664 100644 (file)
@@ -55,7 +55,7 @@ typedef struct _Audit_record Audit_record;
 
 #define SLAPI_OVERLAY_NAME                     "slapi"
 
-#define SLAPI_OPERATION_PBLOCK(_op)            ((_op)->o_hdr->oh_pb)
+#define SLAPI_OPERATION_PBLOCK(_op)            ((_op)->o_callback->sc_private)
 #define SLAPI_CONNECTION_PBLOCK(_conn)         ((_conn)->c_pb);
 #define SLAPI_BACKEND_PBLOCK(_be)              ((_be)->be_pb)
 
index 58bd5912c18790da793b0a81b3d0bb46cb97b02e..734183d9dacebc05b89db8bfb1975b88dcfa5ba5 100644 (file)
@@ -309,9 +309,14 @@ slapi_int_init_connection( Slapi_PBlock *pb,
 
        op = (Operation *) slapi_ch_calloc( 1, OPERATION_BUFFER_SIZE );
        op->o_hdr = (Opheader *)(op + 1);
-       op->o_hdr->oh_pb = pb;
        op->o_hdr->oh_extensions = NULL;
 
+       op->o_callback = (slap_callback *) slapi_ch_calloc( 1, sizeof(slap_callback) );
+       op->o_callback->sc_response = NULL;
+       op->o_callback->sc_cleanup = NULL;
+       op->o_callback->sc_private = pb;
+       op->o_callback->sc_next = NULL;
+
        op->o_controls = (void **)(op->o_hdr + 1);
 
        conn->c_pending_ops.stqh_first = op;
@@ -435,7 +440,9 @@ void slapi_int_connection_destroy( Connection **pConn )
        if ( op->o_req_ndn.bv_val != NULL ) {
                slapi_ch_free( (void **)&op->o_req_ndn.bv_val );
        }
-
+       if ( op->o_callback != NULL ) {
+               slapi_ch_free( (void **)&op->o_callback );
+       }
        if ( conn->c_sb != NULL ) {
                ber_sockbuf_free( conn->c_sb );
        }
index 97d97e39116411fc937cc029c0ffde91da6496b4..7772467ec6db3f8e3b8f51dcb254cd827a32c04e 100644 (file)
 
 static slap_overinst slapi;
 
+static Slapi_PBlock *
+slapi_over_pblock_new ( Operation *op )
+{
+       Slapi_PBlock            *pb;
+
+       pb = slapi_pblock_new();
+       if ( pb == NULL )
+               return NULL;
+
+       slapi_int_pblock_set_operation( pb, op );
+
+       return pb;
+}
+
 static int
 slapi_over_compute_output(
        computed_attr_context *c,
@@ -97,7 +111,7 @@ slapi_over_aux_operational( Operation *op, SlapReply *rs )
        AttributeName           *anp;
        AccessControlState      acl_state = ACL_STATE_INIT;
 
-       ctx.cac_pb = SLAPI_OPERATION_PBLOCK( op );
+       ctx.cac_pb = slapi_over_pblock_new( op );
        ctx.cac_op = op;
        ctx.cac_private = rs;
        ctx.cac_acl_state = &acl_state;
@@ -123,6 +137,8 @@ slapi_over_aux_operational( Operation *op, SlapReply *rs )
                }
        }
 
+       slapi_pblock_destroy( ctx.cac_pb );
+
        return SLAP_CB_CONTINUE;
 }
 
@@ -134,11 +150,9 @@ slapi_over_search( Operation *op, SlapReply *rs, int type )
 
        assert( rs->sr_type == REP_SEARCH || rs->sr_type == REP_SEARCHREF );
 
-       pb = slapi_pblock_new(); /* create a new pblock to not trample on
-                                 * result controls
-                                 */
+       /* create a new pblock to not trample on result controls */
+       pb = slapi_over_pblock_new( op );
 
-       slapi_int_pblock_set_operation( pb, op );
        slapi_pblock_set( pb, SLAPI_RESCONTROLS,         (void *)rs->sr_ctrls );
        slapi_pblock_set( pb, SLAPI_SEARCH_RESULT_ENTRY, (void *)rs->sr_entry );
 
@@ -169,8 +183,9 @@ slapi_over_count_controls( LDAPControl **controls )
 }
 
 static int
-slapi_over_merge_controls( Operation *op, SlapReply *rs, Slapi_PBlock *pb)
+slapi_over_merge_controls( Operation *op, SlapReply *rs )
 {
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
        LDAPControl             **slapiControls = NULL, **mergedControls;
        int                     nSlapiControls = 0;
        int                     nResControls = 0;
@@ -235,23 +250,27 @@ slapi_over_result( Operation *op, SlapReply *rs, int type )
        slapi_pblock_get( pb, SLAPI_RESULT_MATCHED, (void **)&rs->sr_matched );
 
        if ( type == SLAPI_PLUGIN_PRE_RESULT_FN ) {
-               rc = slapi_over_merge_controls( op, rs, pb );
+               rc = slapi_over_merge_controls( op, rs );
        }
 
        return SLAP_CB_CONTINUE;
 }
 
 static int
-slapi_op_add_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_add_init( Operation *op, SlapReply *rs )
 {
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+
        slapi_pblock_set( pb, SLAPI_ADD_ENTRY, (void *)op->ora_e );
 
        return LDAP_SUCCESS;
 }
 
 static int
-slapi_op_bind_preop_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_bind_preop_init( Operation *op, SlapReply *rs )
 {
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+
        slapi_pblock_set( pb, SLAPI_BIND_TARGET,      (void *)op->o_req_dn.bv_val );
        slapi_pblock_set( pb, SLAPI_BIND_METHOD,      (void *)op->orb_method );
        slapi_pblock_set( pb, SLAPI_BIND_CREDENTIALS, (void *)&op->orb_cred );
@@ -261,9 +280,10 @@ slapi_op_bind_preop_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_bind_postop_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_bind_postop_init( Operation *op, SlapReply *rs )
 {
-       char *dn = NULL;
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+       char                    *dn = NULL;
 
        if ( rs->sr_err == LDAP_SUCCESS ) {
                /* fix for ITS#2971 */
@@ -274,9 +294,10 @@ slapi_op_bind_postop_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_bind_callback( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_bind_callback( Operation *op, SlapReply *rs )
 {
-       int rc = rs->sr_err;
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+       int                     rc = rs->sr_err;
 
        switch ( rc ) {
        case SLAPI_BIND_SUCCESS:
@@ -340,8 +361,10 @@ slapi_op_bind_callback( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_compare_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_compare_init( Operation *op, SlapReply *rs )
 {
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+
        slapi_pblock_set( pb, SLAPI_COMPARE_TYPE,  (void *)op->orc_ava->aa_desc->ad_cname.bv_val );
        slapi_pblock_set( pb, SLAPI_COMPARE_VALUE, (void *)&op->orc_ava->aa_value );
 
@@ -349,9 +372,10 @@ slapi_op_compare_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_modify_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_modify_init( Operation *op, SlapReply *rs )
 {
-       LDAPMod         **modv = NULL;
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+       LDAPMod                 **modv = NULL;
 
        modv = slapi_int_modifications2ldapmods( &op->orm_modlist );
        slapi_pblock_set( pb, SLAPI_MODIFY_MODS, (void *)modv );
@@ -360,9 +384,10 @@ slapi_op_modify_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_modify_callback( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_modify_callback( Operation *op, SlapReply *rs )
 {
-       LDAPMod         **modv = NULL;
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+       LDAPMod                 **modv = NULL;
 
        /* check preoperation result code */
        if ( rs->sr_err < 0 ) {
@@ -389,9 +414,10 @@ slapi_op_modify_callback( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_modify_cleanup( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_modify_cleanup( Operation *op, SlapReply *rs )
 {
-       LDAPMod         **modv = NULL;
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+       LDAPMod                 **modv = NULL;
 
        slapi_pblock_get( pb, SLAPI_MODIFY_MODS, (void **)&modv );
 
@@ -402,8 +428,10 @@ slapi_op_modify_cleanup( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_modrdn_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_modrdn_init( Operation *op, SlapReply *rs )
 {
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+
        slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN,      (void *)op->orr_newrdn.bv_val );
        slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR, (void *)op->orr_newSup->bv_val );
        slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN,   (void *)op->orr_deleteoldrdn );
@@ -412,9 +440,10 @@ slapi_op_modrdn_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_search_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_search_init( Operation *op, SlapReply *rs )
 {
-       char            **attrs;
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+       char                    **attrs;
 
        attrs = anlist2charray_x( op->ors_attrs, 0, op->o_tmpmemctx );
 
@@ -431,8 +460,10 @@ slapi_op_search_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_search_callback( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_search_callback( Operation *op, SlapReply *rs )
 {
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+
        /* check preoperation result code */
        if ( rs->sr_err < 0 ) {
                slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void **)&rs->sr_err );
@@ -471,9 +502,10 @@ slapi_op_search_callback( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
 }
 
 static int
-slapi_op_search_cleanup( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
+slapi_op_search_cleanup( Operation *op, SlapReply *rs )
 {
-       char            **attrs = NULL;
+       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+       char                    **attrs = NULL;
 
        slapi_pblock_get( pb, SLAPI_SEARCH_ATTRS,     (void *)&attrs );
 
@@ -483,15 +515,13 @@ slapi_op_search_cleanup( Operation *op, SlapReply *rs, Slapi_PBlock *pb )
        return LDAP_SUCCESS;
 }
 
-typedef int (slapi_over_callback)( Operation *, SlapReply *rs, Slapi_PBlock * );
-
 struct slapi_op_info {
-       int soi_preop;                          /* preoperation plugin parameter */
-       int soi_postop;                         /* postoperation plugin parameter */
-       slapi_over_callback *soi_preop_init;    /* preoperation pblock init function */
-       slapi_over_callback *soi_callback;      /* preoperation result handler */
-       slapi_over_callback *soi_postop_init;   /* postoperation pblock init function */
-       slapi_over_callback *soi_cleanup;       /* cleanup function */
+       int soi_preop;                  /* preoperation plugin parameter */
+       int soi_postop;                 /* postoperation plugin parameter */
+       slap_response *soi_preop_init;  /* preoperation pblock init function */
+       slap_response *soi_callback;    /* preoperation result handler */
+       slap_response *soi_postop_init; /* postoperation pblock init function */
+       slap_response *soi_cleanup;     /* cleanup function */
 } slapi_op_dispatch_table[] = {
        {
                SLAPI_PLUGIN_PRE_BIND_FN,
@@ -670,13 +700,11 @@ slapi_op_func( Operation *op, SlapReply *rs )
        slap_overinst           *on;
        slap_callback           cb;
 
-       pb = SLAPI_OPERATION_PBLOCK( op );
-
        /*
         * We check for op->o_extensions to verify that we are not
         * processing a SLAPI internal operation. XXX
         */
-       if ( pb == NULL || op->o_hdr->oh_extensions == NULL ) {
+       if ( op->o_hdr->oh_extensions == NULL ) {
                return SLAP_CB_CONTINUE;
        }
 
@@ -698,15 +726,16 @@ slapi_op_func( Operation *op, SlapReply *rs )
                return SLAP_CB_CONTINUE;
        }
 
-       slapi_int_pblock_set_operation( pb, op );
+       pb = slapi_over_pblock_new( op );
 
+       /* XXX we need to fill this out for MMR support */
        slapi_pblock_set( pb, SLAPI_TARGET_ADDRESS, NULL );
        slapi_pblock_set( pb, SLAPI_TARGET_UNIQUEID, NULL );
        slapi_pblock_set( pb, SLAPI_TARGET_DN, (void *)op->o_req_dn.bv_val );
        
        cb.sc_response = slapi_over_response; /* call pre-entry/result plugins */
        cb.sc_cleanup = slapi_over_cleanup;  /* call post-entry/result plugins */
-       cb.sc_private = opinfo;
+       cb.sc_private = pb;
        cb.sc_next = op->o_callback;
        op->o_callback = &cb;
 
@@ -714,9 +743,9 @@ slapi_op_func( Operation *op, SlapReply *rs )
         * Call preoperation plugins 
         */
        if ( opinfo->soi_preop_init != NULL ) {
-               rs->sr_err = (opinfo->soi_preop_init)( op, rs, pb );
+               rs->sr_err = (opinfo->soi_preop_init)( op, rs );
                if ( rs->sr_err != LDAP_SUCCESS )
-                       return rs->sr_err;
+                       goto cleanup;
        }
 
        rs->sr_err = slapi_int_call_plugins( op->o_bd, opinfo->soi_preop, pb );
@@ -738,7 +767,7 @@ slapi_op_func( Operation *op, SlapReply *rs )
                        goto cleanup;
                }
        } else {
-               rc = (opinfo->soi_callback)( op, rs, pb );
+               rc = (opinfo->soi_callback)( op, rs );
                if ( rc )
                        goto cleanup;
        }
@@ -762,17 +791,18 @@ slapi_op_func( Operation *op, SlapReply *rs )
        slapi_pblock_set( pb, SLAPI_RESULT_CODE, (void *)rs->sr_err );
 
        if ( opinfo->soi_postop_init != NULL ) {
-               (opinfo->soi_postop_init)( op, rs, pb );
+               (opinfo->soi_postop_init)( op, rs );
        }
 
        slapi_int_call_plugins( op->o_bd, opinfo->soi_postop, pb );
 
 cleanup:
        if ( opinfo->soi_cleanup != NULL ) {
-               (opinfo->soi_cleanup)( op, rs, pb );
+               (opinfo->soi_cleanup)( op, rs );
        }
 
        op->o_callback = cb.sc_next;
+       slapi_pblock_destroy(pb);
 
        return rs->sr_err;
 }
@@ -786,17 +816,12 @@ slapi_over_extended( Operation *op, SlapReply *rs )
        int             rc;
        struct berval   reqdata = BER_BVNULL;
 
-       pb = SLAPI_OPERATION_PBLOCK( op );
-       if ( pb == NULL ) {
-               return SLAP_CB_CONTINUE;
-       }
-
        slapi_int_get_extop_plugin( &op->ore_reqoid, &callback );
        if ( callback == NULL ) {
                return SLAP_CB_CONTINUE;
        }
 
-       slapi_int_pblock_set_operation( pb, op );
+       pb = slapi_over_pblock_new( op );
 
        if ( op->ore_reqdata != NULL ) {
                reqdata = *op->ore_reqdata;
@@ -807,8 +832,10 @@ slapi_over_extended( Operation *op, SlapReply *rs )
 
        rc = (*callback)( pb );
        if ( rc == SLAPI_PLUGIN_EXTENDED_SENT_RESULT ) {
+               slapi_pblock_destroy( pb );
                return rc;
        } else if ( rc == SLAPI_PLUGIN_EXTENDED_NOT_HANDLED ) {
+               slapi_pblock_destroy( pb );
                return SLAP_CB_CONTINUE;
        }
 
@@ -824,6 +851,8 @@ slapi_over_extended( Operation *op, SlapReply *rs )
        if ( rs->sr_rspdata != NULL )
                ber_bvfree( rs->sr_rspdata );
 
+       slapi_pblock_destroy( pb );
+
        return rs->sr_err;
 }
 
@@ -837,13 +866,26 @@ slapi_over_access_allowed(
        AccessControlState      *state,
        slap_mask_t             *maskp )
 {
-       int rc;
+       int                     rc;
+       Slapi_PBlock            *pb;
+       slap_callback           cb;
+
+       pb = slapi_over_pblock_new( op );
+
+       cb.sc_response = NULL;
+       cb.sc_cleanup = NULL;
+       cb.sc_private = pb;
+       cb.sc_next = op->o_callback;
+       op->o_callback = &cb;
 
        rc = slapi_int_access_allowed( op, e, desc, val, access, state );
        if ( rc != 0 ) {
                rc = SLAP_CB_CONTINUE;
        }
 
+       op->o_callback = cb.sc_next;
+       slapi_pblock_destroy( pb );
+
        return rc;
 }
 
@@ -858,14 +900,10 @@ slapi_over_acl_group(
 {
        Slapi_Entry             *e;
        int                     rc;
-       Slapi_PBlock            *pb = SLAPI_OPERATION_PBLOCK( op );
+       Slapi_PBlock            *pb;
        BackendDB               *be = NULL;
        BackendDB               *be_orig = op->o_bd;
 
-       if ( pb == NULL ) {
-               return SLAP_CB_CONTINUE;
-       }
-
        if ( target != NULL && dn_match( &target->e_nname, gr_ndn ) ) {
                e = target;
                rc = 0;
@@ -884,6 +922,8 @@ slapi_over_acl_group(
                return SLAP_CB_CONTINUE;
        }
 
+       pb = slapi_over_pblock_new( op );
+
        slapi_pblock_set( pb, SLAPI_X_GROUP_ENTRY,        (void *)e );
        slapi_pblock_set( pb, SLAPI_X_GROUP_OPERATION_DN, (void *)op_ndn->bv_val );
        slapi_pblock_set( pb, SLAPI_X_GROUP_ATTRIBUTE,    (void *)group_at->ad_cname.bv_val );
@@ -895,10 +935,7 @@ slapi_over_acl_group(
        else
                slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void **)&rc );
 
-       slapi_pblock_set( pb, SLAPI_X_GROUP_ENTRY,         NULL );
-       slapi_pblock_set( pb, SLAPI_X_GROUP_OPERATION_DN,  NULL );
-       slapi_pblock_set( pb, SLAPI_X_GROUP_ATTRIBUTE,     NULL );
-       slapi_pblock_set( pb, SLAPI_X_GROUP_TARGET_ENTRY,  NULL );
+       slapi_pblock_destroy( pb );
 
        if ( e != target ) {
                op->o_bd = be;
index 14a9aeda836294c606627c6cbab2c1376ac83a60..12a9a3ffe10c4147a179b5864392313bcc3f3f35 100644 (file)
@@ -2403,19 +2403,13 @@ slapi_free_search_results_internal( Slapi_PBlock *pb )
  */
 static int slapi_int_pblock_set_backend( Slapi_PBlock *pb, Backend *be )
 {
-       int rc;
-       
-       rc = slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+       slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be );
        
        if ( be != NULL ) {
-               rc = slapi_pblock_set( pb, SLAPI_BE_TYPE, (void *)be->bd_info->bi_type );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
+               slapi_pblock_set( pb, SLAPI_BE_TYPE, (void *)be->bd_info->bi_type );
        }
 
-       return LDAP_SUCCESS;
+       return 0;
 }
 
 /*
@@ -2468,40 +2462,25 @@ static int slapi_int_pblock_set_connection( Slapi_PBlock *pb, Connection *conn )
        char *connAuthType;
        int rc;
 
-       rc = slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn );
-       if ( rc != LDAP_SUCCESS ) {
-               return rc;
-       }
+       slapi_pblock_set( pb, SLAPI_CONNECTION, (void *)conn );
 
        if ( strncmp( conn->c_peer_name.bv_val, "IP=", 3 ) == 0 ) {
-               rc = slapi_pblock_set( pb, SLAPI_CONN_CLIENTIP, (void *)&conn->c_peer_name.bv_val[3] );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
+               slapi_pblock_set( pb, SLAPI_CONN_CLIENTIP, (void *)&conn->c_peer_name.bv_val[3] );
        } else if ( strncmp( conn->c_peer_name.bv_val, "PATH=", 5 ) == 0 ) {
-               rc = slapi_pblock_set( pb, SLAPI_X_CONN_CLIENTPATH, (void *)&conn->c_peer_name.bv_val[5] );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
+               slapi_pblock_set( pb, SLAPI_X_CONN_CLIENTPATH, (void *)&conn->c_peer_name.bv_val[5] );
        }
 
        if ( strncmp( conn->c_sock_name.bv_val, "IP=", 3 ) == 0 ) {
-               rc = slapi_pblock_set( pb, SLAPI_CONN_SERVERIP, (void *)&conn->c_sock_name.bv_val[3] );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
+               slapi_pblock_set( pb, SLAPI_CONN_SERVERIP, (void *)&conn->c_sock_name.bv_val[3] );
        } else if ( strncmp( conn->c_sock_name.bv_val, "PATH=", 5 ) == 0 ) {
-               rc = slapi_pblock_set( pb, SLAPI_X_CONN_SERVERPATH, (void *)&conn->c_sock_name.bv_val[5] );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
+               slapi_pblock_set( pb, SLAPI_X_CONN_SERVERPATH, (void *)&conn->c_sock_name.bv_val[5] );
        }
 
 #ifdef LDAP_CONNECTIONLESS
-       rc = slapi_pblock_set( pb, SLAPI_X_CONN_IS_UDP, (void *)conn->c_is_udp );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+       slapi_pblock_set( pb, SLAPI_X_CONN_IS_UDP, (void *)conn->c_is_udp );
 #endif
 
-       rc = slapi_pblock_set( pb, SLAPI_CONN_ID, (void *)conn->c_connid );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+       slapi_pblock_set( pb, SLAPI_CONN_ID, (void *)conn->c_connid );
 
        /* Returns pointer to static string */
        connAuthType = Authorization2AuthType( &conn->c_authz,
@@ -2512,9 +2491,7 @@ static int slapi_int_pblock_set_connection( Slapi_PBlock *pb, Connection *conn )
 #endif
                1 );
        if ( connAuthType != NULL ) {
-               rc = slapi_pblock_set(pb, SLAPI_CONN_AUTHTYPE, (void *)connAuthType);
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
+               slapi_pblock_set(pb, SLAPI_CONN_AUTHTYPE, (void *)connAuthType);
        }
 
        /* Returns pointer to allocated string */
@@ -2526,32 +2503,24 @@ static int slapi_int_pblock_set_connection( Slapi_PBlock *pb, Connection *conn )
 #endif
                0 );
        if ( connAuthType != NULL ) {
-               rc = slapi_pblock_set(pb, SLAPI_CONN_AUTHMETHOD, (void *)connAuthType);
+               slapi_pblock_set(pb, SLAPI_CONN_AUTHMETHOD, (void *)connAuthType);
                /* slapi_pblock_set dups this itself */
                slapi_ch_free( (void **)&connAuthType );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
        }
 
        if ( conn->c_authz.sai_method != LDAP_AUTH_NONE &&
             conn->c_authz.sai_dn.bv_val != NULL ) {
                /* slapi_pblock_set dups this itself */
-               rc = slapi_pblock_set(pb, SLAPI_CONN_DN, (void *)conn->c_authz.sai_dn.bv_val);
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
+               slapi_pblock_set(pb, SLAPI_CONN_DN, (void *)conn->c_authz.sai_dn.bv_val);
        }
 
-       rc = slapi_pblock_set(pb, SLAPI_X_CONN_SSF, (void *)conn->c_ssf);
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+       slapi_pblock_set(pb, SLAPI_X_CONN_SSF, (void *)conn->c_ssf);
 
-       rc = slapi_pblock_set(pb, SLAPI_X_CONN_SASL_CONTEXT,
+       slapi_pblock_set(pb, SLAPI_X_CONN_SASL_CONTEXT,
                ( conn->c_sasl_authctx != NULL ? conn->c_sasl_authctx :
                                                 conn->c_sasl_sockctx ) );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
 
-       return rc;
+       return 0;
 }
 #endif /* LDAP_SLAPI */
 
@@ -2566,69 +2535,41 @@ int slapi_int_pblock_set_operation( Slapi_PBlock *pb, Operation *op )
        int rc;
        char *opAuthType;
        void *existingOp = NULL;
+       BackendDB *be_orig;
+
+       be_orig = op->o_bd;
 
-       if ( op->o_bd != NULL ) {
-               isRoot = be_isroot( op );
-               isUpdateDn = be_isupdate( op );
+       if ( op->o_req_ndn.bv_len ) {
+               op->o_bd = select_backend( &op->o_req_ndn, 0, 0 );
+               if ( op->o_bd != NULL ) {
+                       isRoot = be_isroot( op );
+                       isUpdateDn = be_isupdate( op );
+               }
        }
 
        /* This should only be called once per operation */
        slapi_pblock_get( pb, SLAPI_OPERATION, &existingOp );
        assert( existingOp == NULL );
 
-       rc = slapi_int_pblock_set_backend( pb, op->o_bd );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_int_pblock_set_connection( pb, op->o_conn );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_OPERATION, (void *)op );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_OPINITIATED_TIME, (void *)op->o_time );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_OPERATION_ID, (void *)op->o_opid );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_OPERATION_TYPE, (void *)op->o_tag );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_REQUESTOR_ISROOT, (void *)isRoot );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_REQUESTOR_ISUPDATEDN, (void *)isUpdateDn );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_REQCONTROLS, (void *)op->o_ctrls );
-       if ( rc != LDAP_SUCCESS)
-               return rc;
-
-       rc = slapi_pblock_set( pb, SLAPI_REQUESTOR_DN, (void *)op->o_ndn.bv_val );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+       slapi_int_pblock_set_backend( pb, op->o_bd );
+       slapi_int_pblock_set_connection( pb, op->o_conn );
 
-       rc = slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)get_manageDSAit( op ) );
-       if ( rc != LDAP_SUCCESS )
-               return rc;
+       slapi_pblock_set( pb, SLAPI_OPERATION,            (void *)op );
+       slapi_pblock_set( pb, SLAPI_OPINITIATED_TIME,     (void *)op->o_time );
+       slapi_pblock_set( pb, SLAPI_OPERATION_ID,         (void *)op->o_opid );
+       slapi_pblock_set( pb, SLAPI_OPERATION_TYPE,       (void *)op->o_tag );
+       slapi_pblock_set( pb, SLAPI_REQUESTOR_ISROOT,     (void *)isRoot );
+       slapi_pblock_set( pb, SLAPI_REQUESTOR_ISUPDATEDN, (void *)isUpdateDn );
+       slapi_pblock_set( pb, SLAPI_REQCONTROLS,          (void *)op->o_ctrls );
+       slapi_pblock_set( pb, SLAPI_REQUESTOR_DN,         (void *)op->o_ndn.bv_val );
+       slapi_pblock_set( pb, SLAPI_MANAGEDSAIT,          (void *)get_manageDSAit( op ) );
+       slapi_pblock_get( pb, SLAPI_CONN_AUTHMETHOD,      (void *)&opAuthType );
+       if ( opAuthType != NULL )
+               slapi_pblock_set( pb, SLAPI_OPERATION_AUTHTYPE, (void *)opAuthType );
 
-       rc = slapi_pblock_get( pb, SLAPI_CONN_AUTHMETHOD, (void *)&opAuthType );
-       if ( rc == LDAP_SUCCESS && opAuthType != NULL ) {
-               /* Not quite sure what the point of this is. */
-               rc = slapi_pblock_set( pb, SLAPI_OPERATION_AUTHTYPE, (void *)opAuthType );
-               if ( rc != LDAP_SUCCESS )
-                       return rc;
-       }
+       op->o_bd = be_orig;
 
-       return LDAP_SUCCESS;
+       return 0;
 #else
        return -1;
 #endif