From: Luke Howard Date: Thu, 21 Jul 2005 17:15:44 +0000 (+0000) Subject: Add support for post-result SLAPI plugins X-Git-Tag: OPENLDAP_AC_BP~291 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b8f86c4f2864aae66822c017d8f4312199274a33;p=openldap Add support for post-result SLAPI plugins Use overlay_op_walk again - needed to match 2.2 SLAPI behaviour --- diff --git a/servers/slapd/slapi/slapi_overlay.c b/servers/slapd/slapi/slapi_overlay.c index f38a0bece6..2a872d7f4c 100644 --- a/servers/slapd/slapi/slapi_overlay.c +++ b/servers/slapd/slapi/slapi_overlay.c @@ -146,7 +146,7 @@ slapi_over_search( Operation *op, SlapReply *rs, int type ) slapi_over_operational( op, rs ); } - slapi_pblock_set( op->o_pb, SLAPI_RESCONTROLS, NULL ); + slapi_pblock_set( pb, SLAPI_RESCONTROLS, NULL ); slapi_pblock_destroy(pb); return rc; @@ -199,7 +199,7 @@ slapi_over_merge_controls( Operation *op, SlapReply *rs, Slapi_PBlock *pb) } static int -slapi_over_result( Operation *op, SlapReply *rs ) +slapi_over_result( Operation *op, SlapReply *rs, int type ) { int rc; @@ -207,7 +207,7 @@ slapi_over_result( Operation *op, SlapReply *rs ) slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text ); slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, (void *)rs->sr_matched ); - rc = slapi_int_call_plugins( op->o_bd, SLAPI_PLUGIN_PRE_RESULT_FN, op->o_pb ); + rc = slapi_int_call_plugins( op->o_bd, type, op->o_pb ); if ( rc < 0 ) { return rc; } @@ -216,7 +216,7 @@ slapi_over_result( Operation *op, SlapReply *rs ) slapi_pblock_get( op->o_pb, SLAPI_RESULT_TEXT, (void **)&rs->sr_text ); slapi_pblock_get( op->o_pb, SLAPI_RESULT_MATCHED, (void **)&rs->sr_matched ); - if ( rc == 0 ) { + if ( rc == 0 && type == SLAPI_PLUGIN_PRE_RESULT_FN ) { rc = slapi_over_merge_controls( op, rs, op->o_pb ); } @@ -235,7 +235,7 @@ slapi_op_add_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb ) } static int -slapi_op_bind_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb ) +slapi_op_bind_preop_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb ) { 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 ); @@ -245,6 +245,19 @@ slapi_op_bind_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb ) return LDAP_SUCCESS; } +static int +slapi_op_bind_postop_init( Operation *op, SlapReply *rs, Slapi_PBlock *pb ) +{ + char *dn = NULL; + + if ( rs->sr_err == LDAP_SUCCESS ) { + /* fix for ITS#2971 */ + slapi_pblock_set( pb, SLAPI_CONN_DN, op->o_conn->c_authz.sai_dn.bv_val ); + } + + return LDAP_SUCCESS; +} + static int slapi_op_bind_callback( Operation *op, SlapReply *rs, Slapi_PBlock *pb ) { @@ -460,15 +473,17 @@ typedef int (slapi_over_callback)( Operation *, SlapReply *rs, Slapi_PBlock * ); struct slapi_op_info { int soi_preop; int soi_postop; - slapi_over_callback *soi_init; - slapi_over_callback *soi_callback; + slapi_over_callback *soi_preop_init; + slapi_over_callback *soi_callback; + slapi_over_callback *soi_postop_init; slapi_over_callback *soi_cleanup; } slapi_op_dispatch_table[] = { { SLAPI_PLUGIN_PRE_BIND_FN, SLAPI_PLUGIN_POST_BIND_FN, - slapi_op_bind_init, + slapi_op_bind_preop_init, slapi_op_bind_callback, + slapi_op_bind_postop_init, NULL }, { @@ -476,6 +491,7 @@ struct slapi_op_info { SLAPI_PLUGIN_POST_UNBIND_FN, NULL, NULL, + NULL, NULL }, { @@ -483,6 +499,7 @@ struct slapi_op_info { SLAPI_PLUGIN_POST_SEARCH_FN, slapi_op_search_init, slapi_op_search_callback, + NULL, slapi_op_search_cleanup }, { @@ -490,6 +507,7 @@ struct slapi_op_info { SLAPI_PLUGIN_POST_COMPARE_FN, slapi_op_compare_init, NULL, + NULL, NULL }, { @@ -497,6 +515,7 @@ struct slapi_op_info { SLAPI_PLUGIN_POST_MODIFY_FN, slapi_op_modify_init, slapi_op_modify_callback, + NULL, slapi_op_modify_cleanup }, { @@ -504,6 +523,7 @@ struct slapi_op_info { SLAPI_PLUGIN_POST_MODRDN_FN, slapi_op_modrdn_init, NULL, + NULL, NULL }, { @@ -511,6 +531,7 @@ struct slapi_op_info { SLAPI_PLUGIN_POST_ADD_FN, slapi_op_add_init, NULL, + NULL, NULL }, { @@ -518,6 +539,7 @@ struct slapi_op_info { SLAPI_PLUGIN_POST_DELETE_FN, NULL, NULL, + NULL, NULL }, { @@ -525,6 +547,7 @@ struct slapi_op_info { SLAPI_PLUGIN_POST_ABANDON_FN, NULL, NULL, + NULL, NULL }, { @@ -532,6 +555,7 @@ struct slapi_op_info { 0, NULL, NULL, + NULL, NULL } }; @@ -581,7 +605,7 @@ slapi_op_response( Operation *op, SlapReply *rs ) switch ( rs->sr_type ) { case REP_RESULT: - rc = slapi_over_result( op, rs ); + rc = slapi_over_result( op, rs, SLAPI_PLUGIN_PRE_RESULT_FN ); break; case REP_SEARCH: rc = slapi_over_search( op, rs, SLAPI_PLUGIN_PRE_ENTRY_FN ); @@ -600,25 +624,24 @@ slapi_op_response( Operation *op, SlapReply *rs ) static int slapi_op_cleanup( Operation *op, SlapReply *rs ) { - struct slapi_op_info *opinfo; - Slapi_PBlock *pb = op->o_pb; - - assert( pb != NULL ); - - if ( rs->sr_type != REP_RESULT ) { - return SLAP_CB_CONTINUE; - } - - opinfo = (struct slapi_op_info *)op->o_callback->sc_private; - - /* call post-operation plugins */ - slapi_int_call_plugins( op->o_bd, opinfo->soi_postop, pb ); + int rc; - if ( opinfo->soi_cleanup != NULL ) { - (opinfo->soi_cleanup)( op, rs, pb ); + switch ( rs->sr_type ) { + case REP_RESULT: + rc = slapi_over_search( 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: + rc = SLAP_CB_CONTINUE; + break; } - return SLAP_CB_CONTINUE; + return rc; } static int @@ -630,7 +653,7 @@ slapi_op_func( Operation *op, SlapReply *rs ) int rc, flags = 0; slap_overinfo *oi; slap_overinst *on; - slap_callback *cb; + slap_callback cb; /* * We check for op->o_extensions to verify that we are not @@ -658,33 +681,23 @@ slapi_op_func( Operation *op, SlapReply *rs ) slapi_int_pblock_set_operation( pb, op ); + cb.sc_response = slapi_op_response; + cb.sc_cleanup = slapi_op_cleanup; + cb.sc_private = opinfo; + cb.sc_next = op->o_callback; + op->o_callback = &cb; + /* - * soi_init is responsible for setting any operation-specific - * pblock parameters ("pre-preoperation plugin") + * Call preoperation plugins */ - if ( opinfo->soi_init != NULL ) { - rs->sr_err = (opinfo->soi_init)( op, rs, pb ); + if ( opinfo->soi_preop_init != NULL ) { + rs->sr_err = (opinfo->soi_preop_init)( op, rs, pb ); if ( rs->sr_err != LDAP_SUCCESS ) return rs->sr_err; } - /* - * Call preoperation plugins - */ rs->sr_err = slapi_int_call_plugins( op->o_bd, opinfo->soi_preop, pb ); - /* - * Setup callback so postoperation plugins will get called; - * don't do this before, because if a preop plugin fails then - * the postop plugin shouldn't be called - */ - cb = op->o_tmpcalloc(1, sizeof(slap_callback), op->o_tmpmemctx); - cb->sc_response = slapi_op_response; - cb->sc_cleanup = slapi_op_cleanup; - cb->sc_private = opinfo; - cb->sc_next = op->o_callback; - op->o_callback = cb; - /* * soi_callback is responsible for examining the result code * of the preoperation plugin and determining whether to @@ -698,18 +711,40 @@ slapi_op_func( Operation *op, SlapReply *rs ) if ( opinfo->soi_callback == NULL ) { if ( rs->sr_err < 0 ) { slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void **)&rs->sr_err ); - return rs->sr_err; + goto cleanup; } } else { rc = (opinfo->soi_callback)( op, rs, pb ); if ( rc ) - return rs->sr_err; + goto cleanup; + } + + /* + * Call actual backend (or next overlay in stack) + */ + on = (slap_overinst *)op->o_bd->bd_info; + oi = on->on_info; + + rs->sr_err = overlay_op_walk( op, rs, which, oi, on->on_next ); + + /* + * Call postoperation plugins + */ + slapi_pblock_set( pb, SLAPI_RESULT_CODE, (void *)rs->sr_err ); + + if ( opinfo->soi_postop_init != NULL ) { + (opinfo->soi_postop_init)( op, rs, pb ); } - if ( rs->sr_err == 0 ) { - rs->sr_err = SLAP_CB_CONTINUE; + slapi_int_call_plugins( op->o_bd, opinfo->soi_postop, pb ); + +cleanup: + if ( opinfo->soi_cleanup != NULL ) { + (opinfo->soi_cleanup)( op, rs, pb ); } + op->o_callback = cb.sc_next; + return rs->sr_err; }