static int slapi_int_search_reference( Operation *op, SlapReply *rs ) { int i, rc = LDAP_SUCCESS; plugin_referral_entry_callback prec = NULL; void *callback_data = NULL; Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op ); assert( pb != NULL ); slapi_pblock_get( pb, SLAPI_X_INTOP_REFERRAL_ENTRY_CALLBACK, (void **)&prec ); slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA, &callback_data ); if ( prec != NULL ) { for ( i = 0; rs->sr_ref[i].bv_val != NULL; i++ ) { rc = (*prec)( rs->sr_ref[i].bv_val, callback_data ); if ( rc != LDAP_SUCCESS ) { break; } } } return rc; }
static int slapi_int_result( Operation *op, SlapReply *rs ) { Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op ); plugin_result_callback prc = NULL; void *callback_data = NULL; LDAPControl **ctrls = NULL; assert( pb != NULL ); slapi_pblock_get( pb, SLAPI_X_INTOP_RESULT_CALLBACK, (void **)&prc ); slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA, &callback_data ); /* we need to duplicate controls because they might go out of scope */ ctrls = slapi_int_dup_controls( rs->sr_ctrls ); slapi_pblock_set( pb, SLAPI_RESCONTROLS, ctrls ); if ( prc != NULL ) { (*prc)( rs->sr_err, callback_data ); } return rs->sr_err; }
static int slapi_over_cleanup( Operation *op, SlapReply *rs ) { Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op ); int rc = SLAP_CB_CONTINUE; slapi_over_unmerge_controls( op, rs ); if ( pb->pb_intop == 0 ) { switch ( rs->sr_type ) { case REP_RESULT: case REP_SASL: case REP_EXTENDED: rc = slapi_over_result( op, rs, SLAPI_PLUGIN_POST_RESULT_FN ); break; case REP_SEARCH: rc = slapi_over_search( op, rs, SLAPI_PLUGIN_POST_ENTRY_FN ); break; case REP_SEARCHREF: rc = slapi_over_search( op, rs, SLAPI_PLUGIN_POST_REFERRAL_FN ); break; default: break; } } return rc; }
static int slapi_op_search_callback( Operation *op, SlapReply *rs, int prc ) { Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op ); Filter *f = op->ors_filter; /* check preoperation result code */ if ( prc < 0 ) { return rs->sr_err; } rs->sr_err = LDAP_SUCCESS; if ( pb->pb_intop == 0 && slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_COMPUTE_SEARCH_REWRITER_FN, pb ) == 0 ) { /* * The plugin can set the SLAPI_SEARCH_FILTER. * SLAPI_SEARCH_STRFILER is not normative. */ if (f != op->ors_filter) { op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx ); filter2bv_x( op, op->ors_filter, &op->ors_filterstr ); } } return LDAP_SUCCESS; }
/* * Call pre- and post-result plugins */ static int slapi_over_result( Operation *op, SlapReply *rs, int type ) { Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op ); assert( rs->sr_type == REP_RESULT || rs->sr_type == REP_SASL || rs->sr_type == REP_EXTENDED ); slapi_over_call_plugins( pb, type ); return SLAP_CB_CONTINUE; }
static int slapi_over_extended( Operation *op, SlapReply *rs ) { Slapi_PBlock *pb; SLAPI_FUNC callback; int rc; int internal_op; slap_callback cb; slapi_int_get_extop_plugin( &op->ore_reqoid, &callback ); if ( callback == NULL ) { return SLAP_CB_CONTINUE; } internal_op = slapi_op_internal_p( op, rs, &cb ); if ( internal_op ) { return SLAP_CB_CONTINUE; } pb = SLAPI_OPERATION_PBLOCK( op ); rc = (*callback)( pb ); if ( rc == SLAPI_PLUGIN_EXTENDED_SENT_RESULT ) { goto cleanup; } else if ( rc == SLAPI_PLUGIN_EXTENDED_NOT_HANDLED ) { rc = SLAP_CB_CONTINUE; goto cleanup; } assert( rs->sr_rspoid != NULL ); send_ldap_extended( op, rs ); #if 0 slapi_ch_free_string( (char **)&rs->sr_rspoid ); #endif if ( rs->sr_rspdata != NULL ) ber_bvfree( rs->sr_rspdata ); rc = rs->sr_err; cleanup: slapi_pblock_destroy( pb ); op->o_callback = cb.sc_next; return rc; }
static int slapi_over_unmerge_controls( Operation *op, SlapReply *rs ) { Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op ); LDAPControl **rs_ctrls = NULL; slapi_pblock_get( pb, SLAPI_X_OLD_RESCONTROLS, (void **)&rs_ctrls ); if ( rs_ctrls == NULL || rs->sr_ctrls == rs_ctrls ) { /* no copying done */ return LDAP_SUCCESS; } op->o_tmpfree( rs->sr_ctrls, op->o_tmpmemctx ); rs->sr_ctrls = rs_ctrls; return LDAP_SUCCESS; }
static int slapi_int_search_entry( Operation *op, SlapReply *rs ) { Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op ); plugin_search_entry_callback psec = NULL; void *callback_data = NULL; int rc = LDAP_SUCCESS; assert( pb != NULL ); slapi_pblock_get( pb, SLAPI_X_INTOP_SEARCH_ENTRY_CALLBACK, (void **)&psec ); slapi_pblock_get( pb, SLAPI_X_INTOP_CALLBACK_DATA, &callback_data ); if ( psec != NULL ) { rc = (*psec)( rs->sr_entry, callback_data ); } return rc; }
/* Add SLAPI_RESCONTROLS to rs->sr_ctrls, with care, because * rs->sr_ctrls could be allocated on the stack */ static int slapi_over_merge_controls( Operation *op, SlapReply *rs ) { Slapi_PBlock *pb = SLAPI_OPERATION_PBLOCK( op ); LDAPControl **ctrls = NULL; LDAPControl **slapi_ctrls = NULL; size_t n_slapi_ctrls = 0; size_t n_rs_ctrls = 0; size_t i; slapi_pblock_get( pb, SLAPI_RESCONTROLS, (void **)&slapi_ctrls ); n_slapi_ctrls = slapi_int_count_controls( slapi_ctrls ); n_rs_ctrls = slapi_int_count_controls( rs->sr_ctrls ); slapi_pblock_set( pb, SLAPI_X_OLD_RESCONTROLS, (void *)rs->sr_ctrls ); if ( n_slapi_ctrls == 0 ) return LDAP_SUCCESS; /* no SLAPI controls */ ctrls = (LDAPControl **) op->o_tmpalloc( ( n_slapi_ctrls + n_rs_ctrls + 1 ) * sizeof(LDAPControl *), op->o_tmpmemctx ); for ( i = 0; i < n_slapi_ctrls; i++ ) { ctrls[i] = slapi_ctrls[i]; } if ( rs->sr_ctrls != NULL ) { for ( i = 0; i < n_rs_ctrls; i++ ) { ctrls[n_slapi_ctrls + i] = rs->sr_ctrls[i]; } } ctrls[n_slapi_ctrls + n_rs_ctrls] = NULL; rs->sr_ctrls = ctrls; return LDAP_SUCCESS; }
static int slapi_over_access_allowed( Operation *op, Entry *e, AttributeDescription *desc, struct berval *val, slap_access_t access, AccessControlState *state, slap_mask_t *maskp ) { int rc; Slapi_PBlock *pb; slap_callback cb; int internal_op; SlapReply rs = { REP_RESULT }; internal_op = slapi_op_internal_p( op, &rs, &cb ); cb.sc_response = NULL; cb.sc_cleanup = NULL; pb = SLAPI_OPERATION_PBLOCK( op ); rc = slapi_int_access_allowed( op, e, desc, val, access, state ); if ( rc ) { rc = SLAP_CB_CONTINUE; } if ( !internal_op ) { slapi_pblock_destroy( pb ); } op->o_callback = cb.sc_next; return rc; }
static int slapi_over_acl_group( Operation *op, Entry *target, struct berval *gr_ndn, struct berval *op_ndn, ObjectClass *group_oc, AttributeDescription *group_at ) { Slapi_Entry *e; int rc; Slapi_PBlock *pb; BackendDB *be = op->o_bd; GroupAssertion *g; SlapReply rs = { REP_RESULT }; op->o_bd = select_backend( gr_ndn, 0 ); for ( g = op->o_groups; g; g = g->ga_next ) { if ( g->ga_be != op->o_bd || g->ga_oc != group_oc || g->ga_at != group_at || g->ga_len != gr_ndn->bv_len ) { continue; } if ( strcmp( g->ga_ndn, gr_ndn->bv_val ) == 0 ) { break; } } if ( g != NULL ) { rc = g->ga_res; goto done; } if ( target != NULL && dn_match( &target->e_nname, gr_ndn ) ) { e = target; rc = 0; } else { rc = be_entry_get_rw( op, gr_ndn, group_oc, group_at, 0, &e ); } if ( e != NULL ) { int internal_op; slap_callback cb; internal_op = slapi_op_internal_p( op, &rs, &cb ); cb.sc_response = NULL; cb.sc_cleanup = NULL; pb = SLAPI_OPERATION_PBLOCK( 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 ); slapi_pblock_set( pb, SLAPI_X_GROUP_TARGET_ENTRY, (void *)target ); rc = slapi_over_call_plugins( pb, SLAPI_X_PLUGIN_PRE_GROUP_FN ); if ( rc >= 0 ) /* 1 means no plugins called */ rc = SLAP_CB_CONTINUE; else rc = pb->pb_rs->sr_err; slapi_pblock_delete_param( pb, SLAPI_X_GROUP_ENTRY ); slapi_pblock_delete_param( pb, SLAPI_X_GROUP_OPERATION_DN ); slapi_pblock_delete_param( pb, SLAPI_X_GROUP_ATTRIBUTE ); slapi_pblock_delete_param( pb, SLAPI_X_GROUP_TARGET_ENTRY ); if ( !internal_op ) slapi_pblock_destroy( pb ); if ( e != target ) { be_entry_release_r( op, e ); } op->o_callback = cb.sc_next; } else { rc = LDAP_NO_SUCH_OBJECT; /* return SLAP_CB_CONTINUE for correctness? */ } if ( op->o_tag != LDAP_REQ_BIND && !op->o_do_not_cache && rc != SLAP_CB_CONTINUE ) { g = op->o_tmpalloc( sizeof( GroupAssertion ) + gr_ndn->bv_len, op->o_tmpmemctx ); g->ga_be = op->o_bd; g->ga_oc = group_oc; g->ga_at = group_at; g->ga_res = rc; g->ga_len = gr_ndn->bv_len; strcpy( g->ga_ndn, gr_ndn->bv_val ); g->ga_next = op->o_groups; op->o_groups = g; } /* * XXX don't call POST_GROUP_FN, I have no idea what the point of * that plugin function was anyway */ done: op->o_bd = be; return rc; }
static int slapi_op_func( Operation *op, SlapReply *rs ) { Slapi_PBlock *pb; slap_operation_t which; struct slapi_op_info *opinfo; int rc; slap_overinfo *oi; slap_overinst *on; slap_callback cb; int internal_op; int preop_type, postop_type; BackendDB *be; if ( !slapi_plugins_used ) return SLAP_CB_CONTINUE; /* * Find the SLAPI operation information for this LDAP * operation; this will contain the preop and postop * plugin types, as well as optional callbacks for * setting up the SLAPI environment. */ which = slapi_tag2op( op->o_tag ); if ( which >= op_last ) { /* invalid operation, but let someone else deal with it */ return SLAP_CB_CONTINUE; } opinfo = &slapi_op_dispatch_table[which]; if ( opinfo == NULL ) { /* no SLAPI plugin types for this operation */ return SLAP_CB_CONTINUE; } internal_op = slapi_op_internal_p( op, rs, &cb ); if ( internal_op ) { preop_type = opinfo->soi_internal_preop; postop_type = opinfo->soi_internal_postop; } else { preop_type = opinfo->soi_preop; postop_type = opinfo->soi_postop; } if ( preop_type == 0 ) { /* no SLAPI plugin types for this operation */ pb = NULL; rc = SLAP_CB_CONTINUE; goto cleanup; } pb = SLAPI_OPERATION_PBLOCK( op ); /* cache backend so we call correct postop plugins */ be = pb->pb_op->o_bd; rc = slapi_int_call_plugins( be, preop_type, pb ); /* * soi_callback is responsible for examining the result code * of the preoperation plugin and determining whether to * abort. This is needed because of special SLAPI behaviour e with bind preoperation plugins. * * The soi_callback function is also used to reset any values * returned from the preoperation plugin before calling the * backend (for the success case). */ if ( opinfo->soi_callback == NULL ) { /* default behaviour is preop plugin can abort operation */ if ( rc < 0 ) { rc = rs->sr_err; goto cleanup; } } else { rc = (opinfo->soi_callback)( op, rs, rc ); if ( rc ) goto cleanup; } /* * Call actual backend (or next overlay in stack). We need to * do this rather than returning SLAP_CB_CONTINUE and calling * postoperation plugins in a response handler to match the * behaviour of SLAPI in OpenLDAP 2.2, where postoperation * plugins are called after the backend has completely * finished processing the operation. */ on = (slap_overinst *)op->o_bd->bd_info; oi = on->on_info; rc = overlay_op_walk( op, rs, which, oi, on->on_next ); /* * Call postoperation plugins */ slapi_int_call_plugins( be, postop_type, pb ); cleanup: if ( !internal_op ) { slapi_pblock_destroy(pb); cb.sc_private = NULL; } op->o_callback = cb.sc_next; return rc; }