-/*
- * To allow plugins to forward frontend requests to internal operations,
- * the internal operation and connection structures should import as
- * much state as practicable from the supplied parameter block.
- */
-
-/*
- * Select the backend to be used for an internal operation, either
- * from the operation target DN or from the parameter block.
- */
-static int
-slapi_int_pblock_get_backend( Slapi_PBlock *pb, Operation *op )
-{
- int manageDsaIt = 0, isCritical;
- LDAPControl **controls = NULL;
- BackendDB *be_op;
-
- slapi_pblock_get( pb, SLAPI_REQCONTROLS, (void **)&controls );
-
- slapi_pblock_get( pb, SLAPI_MANAGEDSAIT, (void **)&manageDsaIt );
- if ( manageDsaIt != 0 )
- manageDsaIt = SLAP_CONTROL_CRITICAL;
- else if ( slapi_control_present( controls, SLAPI_CONTROL_MANAGEDSAIT_OID,
- NULL, &isCritical ))
- manageDsaIt = isCritical ? SLAP_CONTROL_CRITICAL : SLAP_CONTROL_NONCRITICAL;
-
- /* let caller force a specific backend */
- slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be_op );
- if ( be_op == NULL ) {
- be_op = select_backend( &op->o_req_ndn, 0, 0 );
- slapi_pblock_set( pb, SLAPI_BACKEND, (void *)be_op );
- }
-
- op->o_bd = frontendDB; /* but we actually use frontend DB */
-
- return LDAP_SUCCESS;
-}
-
-static int
-slapi_int_pblock_get_connection( Slapi_PBlock *pb, Operation *op )
-{
- char *connDn = NULL;
- Connection *conn = op->o_conn;
-
- slapi_pblock_get( pb, SLAPI_X_CONN_SSF, (void **)&conn->c_ssf );
- slapi_pblock_get( pb, SLAPI_X_CONN_SASL_CONTEXT, (void **)&conn->c_sasl_authctx );
-
- if ( slapi_pblock_get( pb, SLAPI_CONN_DN, (void **)&connDn ) != 0
- || connDn == NULL )
- {
- /* default to operation DN */
- conn->c_ndn = op->o_ndn;
- conn->c_dn = op->o_ndn;
-
- } else {
- /* NB: conn DN must be normalized */
- ber_str2bv( connDn, 0, 0, &conn->c_ndn );
- conn->c_dn = conn->c_ndn;
- }
-
- return LDAP_SUCCESS;
-}
-
-static int
-slapi_int_pblock_get_operation( Slapi_PBlock *pb, Operation *op, SlapReply *rs )
-{
- int isRoot = 0;
- int isUpdateDn = 0;
- char *requestorDn = NULL;
- struct berval targetDn = BER_BVNULL;
- LDAPControl **controls;
- int rc;
- BackendDB *be_op;
-
- /* All internal operations must specify a target DN */
- slapi_pblock_get( pb, SLAPI_TARGET_DN, (void **)&targetDn.bv_val );
- if ( targetDn.bv_val == NULL) {
- return LDAP_PARAM_ERROR;
- }
- targetDn.bv_len = strlen( targetDn.bv_val );
-
- rc = dnPrettyNormal( NULL, &targetDn, &op->o_req_dn, &op->o_req_ndn, NULL );
- if ( rc != LDAP_SUCCESS ) {
- return rc;
- }
-
- rc = slapi_int_pblock_get_backend( pb, op );
- if ( rc != LDAP_SUCCESS ) {
- return rc;
- }
-
- slapi_pblock_get( pb, SLAPI_REQUESTOR_ISROOT, (void **)&isRoot );
- slapi_pblock_get( pb, SLAPI_REQUESTOR_ISUPDATEDN, (void **)&isUpdateDn );
- /* NB: requestor DN must be normalized */
- slapi_pblock_get( pb, SLAPI_REQUESTOR_DN, (void **)&requestorDn );
- slapi_pblock_get( pb, SLAPI_BACKEND, (void **)&be_op );
-
- /* Default authorization identity for internal operations is root DN */
- if ( isRoot || requestorDn == NULL ) {
- assert( be_op != NULL );
- op->o_dn = be_op->be_rootdn;
- op->o_ndn = be_op->be_rootndn;
- isRoot = 1;
- } else {
- ber_str2bv( requestorDn, 0, 0, &op->o_ndn );
- op->o_dn = op->o_ndn;
- }
-
- slapi_pblock_set( pb, SLAPI_REQUESTOR_ISROOT, (void *)isRoot );
-
- rc = slapi_int_pblock_get_connection( pb, op );
- if ( rc != LDAP_SUCCESS ) {
- return rc;
- }
-
- slapi_pblock_get( pb, SLAPI_REQCONTROLS, (void **)&controls );
- rc = slapi_int_get_ctrls( op, rs, controls );
- if ( rc != LDAP_SUCCESS ) {
- return rs->sr_err;
- }
-
- return LDAP_SUCCESS;
-}
-
-int
-slapi_int_connection_init( Slapi_PBlock *pb,
- SlapReply *rs,
- int OpType,
- Connection **pConn )