From f3107c65d71d2167e9b95ff79a0d75ed5385bb56 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Thu, 1 Nov 2012 19:25:23 -0400 Subject: Overhaul betxn support * Check for BETXN support at build-time, provide options for disabling or requiring that it be available for build to succeed. * Track whether or not BETXN support is enabled in the plugin-local state. * Skip processing in post/internalpost callbacks if BETXN support is enabled. * Skip work in betxnpost callbacks if BETXN support is disabled. --- src/back-sch.c | 177 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 114 insertions(+), 63 deletions(-) (limited to 'src/back-sch.c') diff --git a/src/back-sch.c b/src/back-sch.c index e889458..85de48c 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -836,6 +836,48 @@ backend_entry_get_set_config_entry_filter(void) void backend_update_params(Slapi_PBlock *pb, struct plugin_state *state) { + Slapi_DN *our_dn; + Slapi_Entry *our_entry; + char *tmp, **tmpv; + int i, use_be_txns; + + our_dn = slapi_sdn_new_dn_byval(state->plugin_base); + if (our_dn == NULL) { + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "backend_update_params: " + "error parsing %s%s%s\n", + state->plugin_base ? "\"" : "", + state->plugin_base ? + state->plugin_base : "NULL", + state->plugin_base ? "\"" : ""); + return; + } + wrap_search_internal_get_entry(pb, our_dn, NULL, NULL, &our_entry, + state->plugin_identity); + slapi_sdn_free(&our_dn); + our_dn = NULL; + if (our_entry == NULL) { + slapi_log_error(SLAPI_LOG_PLUGIN, + state->plugin_desc->spd_id, + "backend_update_params: failure reading entry " + "\"%s\"\n", state->plugin_base); + return; + } + /* Pull out the attribute values. Just the one here. */ + use_be_txns = backend_shr_get_vattr_boolean(state, our_entry, + "nsslapd-pluginbetxn", + DEFAULT_PLUGIN_USE_BETXNS); + if (state->use_be_txns && !use_be_txns) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "turning off betxn support"); + } + if (!state->use_be_txns && use_be_txns) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "turning on betxn support"); + } + state->use_be_txns = use_be_txns; + slapi_entry_free(our_entry); } /* Intercept a search request, and if it belongs to one of our compatibility @@ -1344,6 +1386,22 @@ backend_write_cb(Slapi_PBlock *pb) return ret; } +static int +backend_pre_write_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? 0: backend_write_cb(pb); +} + +static int +backend_betxn_pre_write_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? backend_write_cb(pb) : 0; +} + static int backend_bind_cb(Slapi_PBlock *pb) { @@ -1441,106 +1499,90 @@ 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, bindfn, backend_bind_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_BIND_FN, + backend_bind_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up bind callback\n"); + "error hooking up pre bind callback\n"); return -1; } /* Intercept compare requests and return the right data. */ - if (slapi_pblock_set(pb, cmpfn, backend_compare_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_COMPARE_FN, + backend_compare_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up compare callback\n"); + "error hooking up pre compare callback\n"); return -1; } /* Intercept search requests and return the right data. */ - if (slapi_pblock_set(pb, srchfn, backend_search_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_SEARCH_FN, + backend_search_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up search callback\n"); + "error hooking up pre 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; - } + /* Intercept write requests to our areas. */ + if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN, + backend_pre_write_cb) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error hooking up pre add callback\n"); + return -1; + } + if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODIFY_FN, + backend_pre_write_cb) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error hooking up pre modify callback\n"); + return -1; + } + if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODRDN_FN, + backend_pre_write_cb) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error hooking up pre modrdn callback\n"); + return -1; + } + if (slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_DELETE_FN, + backend_pre_write_cb) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error hooking up pre delete callback\n"); + return -1; } /* We don't hook abandonment requests. */ /* We don't hook unbind requests. */ return 0; } +#ifdef SLAPI_NIS_SUPPORT_BE_TXNS int -backend_init_betxnpreop(Slapi_PBlock *pb, struct plugin_state *state) +backend_init_betxn_preop(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, addfn, backend_write_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN, + backend_betxn_pre_write_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up add callback\n"); + "error hooking up betxn pre add callback\n"); return -1; } - if (slapi_pblock_set(pb, modfn, backend_write_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN, + backend_betxn_pre_write_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up modify callback\n"); + "error hooking up betxn pre modify callback\n"); return -1; } - if (slapi_pblock_set(pb, mdnfn, backend_write_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN, + backend_betxn_pre_write_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up modrdn callback\n"); + "error hooking up betxn pre modrdn callback\n"); return -1; } - if (slapi_pblock_set(pb, delfn, backend_write_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN, + backend_betxn_pre_write_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up delete callback\n"); + "error hooking up betxn pre delete callback\n"); return -1; } /* We don't hook abandonment requests. */ @@ -1548,6 +1590,15 @@ backend_init_betxnpreop(Slapi_PBlock *pb, struct plugin_state *state) return 0; } +int +backend_init_betxn_postop(Slapi_PBlock *pb, struct plugin_state *state) +{ + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "hooking up betxn postoperation callbacks\n"); + return backend_shr_betxn_postop_init(pb, state); +} +#endif + int backend_init_postop(Slapi_PBlock *pb, struct plugin_state *state) { -- cgit