From c5bfff6c6e6ae5e255b2432be1ed8790a6c07e82 Mon Sep 17 00:00:00 2001 From: Noriko Hosoi Date: Fri, 31 Aug 2012 14:42:05 -0700 Subject: make NIS Plugin and Schema Compatibility Plugin betxn aware When NIS Plugin and Schema Compatibility Plugin config entries include nsslapd-pluginbetxn: on (the value could be yes, true or 1, too), the plugins' update callbacks (add, delete, modify, and modrdn) are called at the betxn pre/postop timing. By default, the value of nsslapd-pluginbetxn is off. (See also https://fedorahosted.org/389/ticket/351) --- src/back-shr.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'src/back-shr.c') diff --git a/src/back-shr.c b/src/back-shr.c index a2c31c9..99955b6 100644 --- a/src/back-shr.c +++ b/src/back-shr.c @@ -2245,26 +2245,40 @@ backend_shr_internal_delete_cb(Slapi_PBlock *pb) int backend_shr_postop_init(Slapi_PBlock *pb, struct plugin_state *state) { - if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN, - backend_shr_add_cb) != 0) { + int addfn = SLAPI_PLUGIN_POST_ADD_FN; + int modfn = SLAPI_PLUGIN_POST_MODIFY_FN; + int mdnfn = SLAPI_PLUGIN_POST_MODRDN_FN; + int delfn = SLAPI_PLUGIN_POST_DELETE_FN; + Slapi_Entry *plugin_entry = NULL; + char *plugin_type = NULL; + + if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) && + plugin_entry && + (plugin_type = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype")) && + plugin_type && strstr(plugin_type, "betxn")) { + addfn = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN; + modfn = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN; + mdnfn = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN; + delfn = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN; + } + slapi_ch_free_string(&plugin_type); + + if (slapi_pblock_set(pb, addfn, backend_shr_add_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up add callback\n"); return -1; } - if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN, - backend_shr_modify_cb) != 0) { + if (slapi_pblock_set(pb, modfn, backend_shr_modify_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up modify callback\n"); return -1; } - if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN, - backend_shr_modrdn_cb) != 0) { + if (slapi_pblock_set(pb, mdnfn, backend_shr_modrdn_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up modrdn callback\n"); return -1; } - if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN, - backend_shr_delete_cb) != 0) { + if (slapi_pblock_set(pb, delfn, backend_shr_delete_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up delete callback\n"); return -1; @@ -2275,26 +2289,27 @@ backend_shr_postop_init(Slapi_PBlock *pb, struct plugin_state *state) int backend_shr_internal_postop_init(Slapi_PBlock *pb, struct plugin_state *state) { - if (slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_ADD_FN, - backend_shr_internal_add_cb) != 0) { + int addfn = SLAPI_PLUGIN_INTERNAL_POST_ADD_FN; + int modfn = SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN; + int mdnfn = SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN; + int delfn = SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN; + + if (slapi_pblock_set(pb, addfn, backend_shr_internal_add_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up internal add callback\n"); return -1; } - if (slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN, - backend_shr_internal_modify_cb) != 0) { + if (slapi_pblock_set(pb, modfn, backend_shr_internal_modify_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up internal modify callback\n"); return -1; } - if (slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN, - backend_shr_internal_modrdn_cb) != 0) { + if (slapi_pblock_set(pb, mdnfn, backend_shr_internal_modrdn_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up internal modrdn callback\n"); return -1; } - if (slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN, - backend_shr_internal_delete_cb) != 0) { + if (slapi_pblock_set(pb, delfn, backend_shr_internal_delete_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up internal delete callback\n"); return -1; -- cgit