diff options
author | Noriko Hosoi <nhosoi@redhat.com> | 2012-08-31 14:42:05 -0700 |
---|---|---|
committer | Nalin Dahyabhai <nalin@redhat.com> | 2012-10-16 16:18:34 -0400 |
commit | c5bfff6c6e6ae5e255b2432be1ed8790a6c07e82 (patch) | |
tree | 1595673b93e151bdb2782717a62e2dcdf790679d /src/back-sch.c | |
parent | 375c82e0cfc3d7494ddf63610353da30a77b4491 (diff) | |
download | slapi-nis-c5bfff6c6e6ae5e255b2432be1ed8790a6c07e82.tar.gz slapi-nis-c5bfff6c6e6ae5e255b2432be1ed8790a6c07e82.tar.xz slapi-nis-c5bfff6c6e6ae5e255b2432be1ed8790a6c07e82.zip |
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)
Diffstat (limited to 'src/back-sch.c')
-rw-r--r-- | src/back-sch.c | 80 |
1 files changed, 66 insertions, 14 deletions
diff --git a/src/back-sch.c b/src/back-sch.c index aecea67..e889458 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -1441,52 +1441,104 @@ backend_startup(Slapi_PBlock *pb, struct plugin_state *state) int backend_init_preop(Slapi_PBlock *pb, struct plugin_state *state) { + int bindfn = SLAPI_PLUGIN_PRE_BIND_FN; + int cmpfn = SLAPI_PLUGIN_PRE_COMPARE_FN; + int srchfn = SLAPI_PLUGIN_PRE_SEARCH_FN; + int addfn = SLAPI_PLUGIN_PRE_ADD_FN; + int modfn = SLAPI_PLUGIN_PRE_MODIFY_FN; + int mdnfn = SLAPI_PLUGIN_PRE_MODRDN_FN; + int delfn = SLAPI_PLUGIN_PRE_DELETE_FN; + Slapi_Entry *plugin_entry = NULL; + char *plugin_type = NULL; + int is_betxn = 0; + + 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")) { + is_betxn = 1; + } + slapi_ch_free_string(&plugin_type); + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "hooking up preoperation callbacks\n"); /* Intercept bind requests and return a referral or failure for entries * that we're managing. */ - if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_BIND_FN, - backend_bind_cb) != 0) { + if (slapi_pblock_set(pb, bindfn, backend_bind_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up bind callback\n"); return -1; } /* Intercept compare requests and return the right data. */ - if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_COMPARE_FN, - backend_compare_cb) != 0) { + if (slapi_pblock_set(pb, cmpfn, backend_compare_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up compare callback\n"); return -1; } /* Intercept search requests and return the right data. */ - if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_SEARCH_FN, - backend_search_cb) != 0) { + if (slapi_pblock_set(pb, srchfn, backend_search_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up search callback\n"); return -1; } + if (!is_betxn) { + /* if is_betxn, these callbacks are registered for betxnpreop */ + /* Intercept write requests and return an insufficient-access error for + * attempts to write to anything we're managing. */ + if (slapi_pblock_set(pb, addfn, backend_write_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, modfn, backend_write_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, mdnfn, backend_write_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, delfn, backend_write_cb) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error hooking up delete callback\n"); + return -1; + } + } + /* We don't hook abandonment requests. */ + /* We don't hook unbind requests. */ + return 0; +} + +int +backend_init_betxnpreop(Slapi_PBlock *pb, struct plugin_state *state) +{ + int addfn = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN; + int modfn = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN; + int mdnfn = SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN; + int delfn = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN; + + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "hooking up betxn preoperation callbacks\n"); /* Intercept write requests and return an insufficient-access error for * attempts to write to anything we're managing. */ - if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN, - backend_write_cb) != 0) { + if (slapi_pblock_set(pb, addfn, backend_write_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_PRE_MODIFY_FN, - backend_write_cb) != 0) { + if (slapi_pblock_set(pb, modfn, backend_write_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_PRE_MODRDN_FN, - backend_write_cb) != 0) { + if (slapi_pblock_set(pb, mdnfn, backend_write_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_PRE_DELETE_FN, - backend_write_cb) != 0) { + if (slapi_pblock_set(pb, delfn, backend_write_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "error hooking up delete callback\n"); return -1; |