diff options
| author | Nalin Dahyabhai <nalin@redhat.com> | 2012-11-01 19:25:23 -0400 |
|---|---|---|
| committer | Nalin Dahyabhai <nalin@redhat.com> | 2012-11-01 19:25:23 -0400 |
| commit | f3107c65d71d2167e9b95ff79a0d75ed5385bb56 (patch) | |
| tree | cdf9bb03a961074cc8cc386ffc47f2a85d7560bf /src | |
| parent | 8c2ec5b5cad770c4e13dbfebf888a4ef08c0c4d2 (diff) | |
| download | slapi-nis-f3107c65d71d2167e9b95ff79a0d75ed5385bb56.tar.gz slapi-nis-f3107c65d71d2167e9b95ff79a0d75ed5385bb56.tar.xz slapi-nis-f3107c65d71d2167e9b95ff79a0d75ed5385bb56.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/back-nis.c | 24 | ||||
| -rw-r--r-- | src/back-sch.c | 177 | ||||
| -rw-r--r-- | src/back-shr.c | 194 | ||||
| -rw-r--r-- | src/back-shr.h | 5 | ||||
| -rw-r--r-- | src/backend.h | 5 | ||||
| -rw-r--r-- | src/plug-nis.c | 74 | ||||
| -rw-r--r-- | src/plug-sch.c | 145 | ||||
| -rw-r--r-- | src/plugin.h | 3 |
8 files changed, 414 insertions, 213 deletions
diff --git a/src/back-nis.c b/src/back-nis.c index fa810ab..40df624 100644 --- a/src/back-nis.c +++ b/src/back-nis.c @@ -748,7 +748,7 @@ backend_update_params(Slapi_PBlock *pb, struct plugin_state *state) Slapi_DN *our_dn; Slapi_Entry *our_entry; char *tmp, **tmpv; - int i; + int i, use_be_txns; our_dn = slapi_sdn_new_dn_byval(state->plugin_base); if (our_dn == NULL) { @@ -810,6 +810,18 @@ backend_update_params(Slapi_PBlock *pb, struct plugin_state *state) DEFAULT_TCPWRAP_NAME); } #endif + 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); } @@ -970,6 +982,16 @@ backend_startup(Slapi_PBlock *pb, struct plugin_state *state) } /* Set up our post-op callbacks. */ +#ifdef SLAPI_NIS_SUPPORT_BE_TXNS +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) { 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 @@ -1345,6 +1387,22 @@ backend_write_cb(Slapi_PBlock *pb) } 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) { struct backend_entry_data *data; @@ -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. */ @@ -1549,6 +1591,15 @@ backend_init_betxnpreop(Slapi_PBlock *pb, struct plugin_state *state) } 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) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, diff --git a/src/back-shr.c b/src/back-shr.c index 99955b6..a6a7230 100644 --- a/src/back-shr.c +++ b/src/back-shr.c @@ -1592,10 +1592,29 @@ backend_shr_add_cb(Slapi_PBlock *pb) wrap_dec_call_level(); return 0; } + static int -backend_shr_internal_add_cb(Slapi_PBlock *pb) +backend_shr_betxn_post_add_cb(Slapi_PBlock *pb) { - return backend_shr_add_cb(pb); + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? backend_shr_add_cb(pb) : 0; +} + +static int +backend_shr_post_add_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? 0 : backend_shr_add_cb(pb); +} + +static int +backend_shr_internal_post_add_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? 0 : backend_shr_add_cb(pb); } struct backend_shr_modify_entry_cbdata { @@ -2015,10 +2034,29 @@ backend_shr_modify_cb(Slapi_PBlock *pb) free(cbdata.modlist); return 0; } + static int -backend_shr_internal_modify_cb(Slapi_PBlock *pb) +backend_shr_betxn_post_modify_cb(Slapi_PBlock *pb) { - return backend_shr_modify_cb(pb); + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? backend_shr_modify_cb(pb) : 0; +} + +static int +backend_shr_post_modify_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? 0 : backend_shr_modify_cb(pb); +} + +static int +backend_shr_internal_post_modify_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? 0 : backend_shr_modify_cb(pb); } struct backend_shr_modrdn_entry_cbdata { @@ -2141,10 +2179,29 @@ backend_shr_modrdn_cb(Slapi_PBlock *pb) wrap_dec_call_level(); return 0; } + +static int +backend_shr_betxn_post_modrdn_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? backend_shr_modrdn_cb(pb) : 0; +} + +static int +backend_shr_post_modrdn_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? 0 : backend_shr_modrdn_cb(pb); +} + static int -backend_shr_internal_modrdn_cb(Slapi_PBlock *pb) +backend_shr_internal_post_modrdn_cb(Slapi_PBlock *pb) { - return backend_shr_modrdn_cb(pb); + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? 0 : backend_shr_modrdn_cb(pb); } /* Delete any map entries which correspond to a directory server entry in this @@ -2234,53 +2291,93 @@ backend_shr_delete_cb(Slapi_PBlock *pb) wrap_dec_call_level(); return 0; } + static int -backend_shr_internal_delete_cb(Slapi_PBlock *pb) +backend_shr_betxn_post_delete_cb(Slapi_PBlock *pb) { - return backend_shr_delete_cb(pb); + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? backend_shr_delete_cb(pb) : 0; +} + +static int +backend_shr_post_delete_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? 0 : backend_shr_delete_cb(pb); +} + +static int +backend_shr_internal_post_delete_cb(Slapi_PBlock *pb) +{ + struct plugin_state *state; + slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state); + return state->use_be_txns ? 0 : backend_shr_delete_cb(pb); } /* Set up our post-op callbacks. */ +#ifdef SLAPI_NIS_SUPPORT_BE_TXNS +int +backend_shr_betxn_postop_init(Slapi_PBlock *pb, struct plugin_state *state) +{ + if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_ADD_FN, + backend_shr_betxn_post_add_cb) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error hooking up betxn post add callback\n"); + return -1; + } + if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN, + backend_shr_betxn_post_modify_cb) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error hooking up betxn post modify " + "callback\n"); + return -1; + } + if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN, + backend_shr_betxn_post_modrdn_cb) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error hooking up betxn post modrdn " + "callback\n"); + return -1; + } + if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN, + backend_shr_betxn_post_delete_cb) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error hooking up betxn post delete " + "callback\n"); + return -1; + } + return 0; +} +#endif + int backend_shr_postop_init(Slapi_PBlock *pb, struct plugin_state *state) { - 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) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN, + backend_shr_post_add_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up add callback\n"); + "error hooking up post add callback\n"); return -1; } - if (slapi_pblock_set(pb, modfn, backend_shr_modify_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN, + backend_shr_post_modify_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up modify callback\n"); + "error hooking up post modify callback\n"); return -1; } - if (slapi_pblock_set(pb, mdnfn, backend_shr_modrdn_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN, + backend_shr_post_modrdn_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up modrdn callback\n"); + "error hooking up post modrdn callback\n"); return -1; } - if (slapi_pblock_set(pb, delfn, backend_shr_delete_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN, + backend_shr_post_delete_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up delete callback\n"); + "error hooking up post delete callback\n"); return -1; } return 0; @@ -2289,29 +2386,32 @@ backend_shr_postop_init(Slapi_PBlock *pb, struct plugin_state *state) int backend_shr_internal_postop_init(Slapi_PBlock *pb, struct plugin_state *state) { - 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) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_ADD_FN, + backend_shr_internal_post_add_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up internal add callback\n"); + "error hooking up internal post add " + "callback\n"); return -1; } - if (slapi_pblock_set(pb, modfn, backend_shr_internal_modify_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN, + backend_shr_internal_post_modify_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up internal modify callback\n"); + "error hooking up internal post modify " + "callback\n"); return -1; } - if (slapi_pblock_set(pb, mdnfn, backend_shr_internal_modrdn_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN, + backend_shr_internal_post_modrdn_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up internal modrdn callback\n"); + "error hooking up internal post modrdn " + "callback\n"); return -1; } - if (slapi_pblock_set(pb, delfn, backend_shr_internal_delete_cb) != 0) { + if (slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN, + backend_shr_internal_post_delete_cb) != 0) { slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error hooking up internal delete callback\n"); + "error hooking up internal post delete " + "callback\n"); return -1; } return 0; diff --git a/src/back-shr.h b/src/back-shr.h index e8c0213..9b2eda9 100644 --- a/src/back-shr.h +++ b/src/back-shr.h @@ -36,8 +36,11 @@ void backend_shr_add_strlist(char ***strlist, const char *item); void backend_shr_startup(struct plugin_state *state, Slapi_PBlock *pb, const char *set_filter); +int backend_shr_betxn_postop_init(Slapi_PBlock *pb, + struct plugin_state *state); int backend_shr_postop_init(Slapi_PBlock *pb, struct plugin_state *state); -int backend_shr_internal_postop_init(Slapi_PBlock *pb, struct plugin_state *state); +int backend_shr_internal_postop_init(Slapi_PBlock *pb, + struct plugin_state *state); int backend_shr_set_config_entry_add(struct plugin_state *state, Slapi_PBlock *pb, diff --git a/src/backend.h b/src/backend.h index 6dff74f..c8f053d 100644 --- a/src/backend.h +++ b/src/backend.h @@ -52,7 +52,10 @@ struct backend_shr_set_data { /* Startup/initialization functions called through the map. */ void backend_startup(struct slapi_pblock *pb, struct plugin_state *state); int backend_init_preop(struct slapi_pblock *pb, struct plugin_state *state); -int backend_init_betxnpreop(struct slapi_pblock *pb, struct plugin_state *state); +int backend_init_betxn_preop(struct slapi_pblock *pb, + struct plugin_state *state); +int backend_init_betxn_postop(struct slapi_pblock *pb, + struct plugin_state *state); int backend_init_postop(struct slapi_pblock *pb, struct plugin_state *state); int backend_init_internal_postop(struct slapi_pblock *pb, struct plugin_state *state); diff --git a/src/plug-nis.c b/src/plug-nis.c index 201ba4e..4815749 100644 --- a/src/plug-nis.c +++ b/src/plug-nis.c @@ -50,6 +50,7 @@ #endif #include "backend.h" +#include "back-shr.h" #include "disp-nis.h" #include "map.h" #include "nis.h" @@ -58,6 +59,7 @@ #include "wrap.h" #define PLUGIN_ID "nis-server-plugin" +#define PLUGIN_BETXN_POSTOP_ID PLUGIN_ID "-betxn_postop" #define PLUGIN_POSTOP_ID PLUGIN_ID "-postop" #define PLUGIN_INTERNAL_POSTOP_ID PLUGIN_ID "-internal-postop" @@ -478,21 +480,28 @@ nis_plugin_init_internal_postop(Slapi_PBlock *pb) } return 0; } +#ifdef SLAPI_NIS_SUPPORT_BE_TXNS +static int +nis_plugin_init_betxn_postop(Slapi_PBlock *pb) +{ + slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03); + slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &plugin_description); + slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, global_plugin_state); + if (backend_init_betxn_postop(pb, global_plugin_state) == -1) { + slapi_log_error(SLAPI_LOG_PLUGIN, + global_plugin_state->plugin_desc->spd_id, + "error registering betxn postop hooks\n"); + return -1; + } + return 0; +} +#endif int nis_plugin_init(Slapi_PBlock *pb) { struct plugin_state *state = NULL; Slapi_Entry *plugin_entry = NULL; int is_betxn = 0; - char *plugin_type = "postoperation"; - - /* get args */ - if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) && - plugin_entry) { - is_betxn = slapi_entry_attr_get_bool(plugin_entry, - "nsslapd-pluginbetxn"); - plugin_type = "betxnpostoperation"; - } /* Allocate the module-global data and set up listening sockets. */ if (plugin_state_init(pb, &state) == -1) { @@ -500,6 +509,18 @@ nis_plugin_init(Slapi_PBlock *pb) "error setting up plugin\n"); return -1; } + /* Read global configuration. */ + if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, + &plugin_entry) == 0) && + (plugin_entry != NULL)) { + is_betxn = backend_shr_get_vattr_boolean(state, plugin_entry, + "nsslapd-pluginbetxn", + DEFAULT_PLUGIN_USE_BETXNS); + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "starting with betxn support %s", + is_betxn ? "enabled" : "disabled"); + state->use_be_txns = is_betxn; + } /* Minimally set up our cache. */ map_init(pb, state); /* Register the plugin with the server. */ @@ -510,7 +531,7 @@ nis_plugin_init(Slapi_PBlock *pb) slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, state); /* Register the sub-plugins. */ global_plugin_state = state; - if (slapi_register_plugin(plugin_type, TRUE, + if (slapi_register_plugin("postoperation", TRUE, "nis_plugin_init_postop", nis_plugin_init_postop, PLUGIN_POSTOP_ID, NULL, @@ -519,19 +540,28 @@ nis_plugin_init(Slapi_PBlock *pb) "error registering postoperation plugin\n"); return -1; } - if (!is_betxn) { - /* if betxn is on, the plugin is called inside of backend transaction, - * which does not distinguish the internal operation. */ - if (slapi_register_plugin("internalpostoperation", TRUE, - "nis_plugin_init_internal_postop", - nis_plugin_init_internal_postop, - PLUGIN_INTERNAL_POSTOP_ID, NULL, - state->plugin_identity) != 0) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error registering internal postoperation plugin\n"); - return -1; - } + if (slapi_register_plugin("internalpostoperation", TRUE, + "nis_plugin_init_internal_postop", + nis_plugin_init_internal_postop, + PLUGIN_INTERNAL_POSTOP_ID, NULL, + state->plugin_identity) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error registering internal postoperation " + "plugin\n"); + return -1; + } +#ifdef SLAPI_NIS_SUPPORT_BE_TXNS + if (slapi_register_plugin("betxnpostoperation", TRUE, + "nis_plugin_init_betxn_postop", + nis_plugin_init_betxn_postop, + PLUGIN_BETXN_POSTOP_ID, NULL, + state->plugin_identity) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error registering betxn postoperation " + "plugin\n"); + return -1; } +#endif slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "registered plugin hooks\n"); global_plugin_state = NULL; diff --git a/src/plug-sch.c b/src/plug-sch.c index cb4a63e..a1c6344 100644 --- a/src/plug-sch.c +++ b/src/plug-sch.c @@ -58,6 +58,8 @@ #define PLUGIN_ID "schema-compat-plugin" #define PLUGIN_PREOP_ID PLUGIN_ID "-preop" +#define PLUGIN_BETXN_PREOP_ID PLUGIN_ID "-betxn_preop" +#define PLUGIN_BETXN_POSTOP_ID PLUGIN_ID "-betxn_postop" #define PLUGIN_POSTOP_ID PLUGIN_ID "-postop" #define PLUGIN_INTERNAL_POSTOP_ID PLUGIN_ID "-internal-postop" @@ -123,7 +125,6 @@ plugin_shutdown(Slapi_PBlock *pb) return 0; } -/* preoperation: all callbacks are called at preop */ static int schema_compat_plugin_init_preop(Slapi_PBlock *pb) { @@ -138,15 +139,14 @@ schema_compat_plugin_init_preop(Slapi_PBlock *pb) } return 0; } - -/* betxnpreoperation: bind, compare and search callbacks are called at preop */ +#ifdef SLAPI_NIS_SUPPORT_BE_TXNS static int -schema_compat_plugin_init_betxnpreop_preop(Slapi_PBlock *pb) +schema_compat_plugin_init_betxnpreop(Slapi_PBlock *pb) { slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03); slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &plugin_description); slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, global_plugin_state); - if (backend_init_preop(pb, global_plugin_state) == -1) { + if (backend_init_betxn_preop(pb, global_plugin_state) == -1) { slapi_log_error(SLAPI_LOG_PLUGIN, global_plugin_state->plugin_desc->spd_id, "error registering preoperation hooks\n"); @@ -154,23 +154,22 @@ schema_compat_plugin_init_betxnpreop_preop(Slapi_PBlock *pb) } return 0; } - -/* betxnpreoperation: add, delete, modify and modrdn callbacks are called at betxnpreop */ static int -schema_compat_plugin_init_betxnpreop(Slapi_PBlock *pb) +schema_compat_plugin_init_betxn_postop(Slapi_PBlock *pb) { slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03); slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &plugin_description); slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, global_plugin_state); - if (backend_init_betxnpreop(pb, global_plugin_state) == -1) { + if (backend_init_betxn_postop(pb, global_plugin_state) == -1) { slapi_log_error(SLAPI_LOG_PLUGIN, global_plugin_state->plugin_desc->spd_id, - "error registering preoperation hooks\n"); + "error registering betxn postoperation " + "hooks\n"); return -1; } return 0; } - +#endif static int schema_compat_plugin_init_postop(Slapi_PBlock *pb) { @@ -206,19 +205,24 @@ schema_compat_plugin_init(Slapi_PBlock *pb) Slapi_Entry *plugin_entry = NULL; int is_betxn = 0; - /* get args */ - if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) && - plugin_entry) { - is_betxn = slapi_entry_attr_get_bool(plugin_entry, - "nsslapd-pluginbetxn"); - } - /* Allocate a memory pool. */ if (plugin_state_init(pb, &state) == -1) { slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id, "error setting up plugin\n"); return -1; } + /* Read global configuration. */ + if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, + &plugin_entry) == 0) && + (plugin_entry != NULL)) { + is_betxn = backend_shr_get_vattr_boolean(state, plugin_entry, + "nsslapd-pluginbetxn", + DEFAULT_PLUGIN_USE_BETXNS); + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "starting with betxn support %s", + is_betxn ? "enabled" : "disabled"); + state->use_be_txns = is_betxn; + } /* Minimally set up our cache. */ map_init(pb, state); /* Register the plugin with the server. */ @@ -229,65 +233,52 @@ schema_compat_plugin_init(Slapi_PBlock *pb) slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, state); /* Register the sub-plugins. */ global_plugin_state = state; - if (is_betxn) { - /* bind, compare and search callbacks are called at preop */ - if (slapi_register_plugin("preoperation", TRUE, - "schema_compat_plugin_init_betxnpreop_preop", - schema_compat_plugin_init_betxnpreop_preop, - PLUGIN_PREOP_ID, NULL, - state->plugin_identity) != 0) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error registering betxn preoperation plugin\n"); - return -1; - } - /* add, delete, modify and modrdn callbacks are called at betxnpreop */ - if (slapi_register_plugin("betxnpreoperation", TRUE, - "schema_compat_plugin_init_betxnpreop", - schema_compat_plugin_init_betxnpreop, - PLUGIN_PREOP_ID, NULL, - state->plugin_identity) != 0) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error registering betxn preoperation plugin\n"); - return -1; - } - if (slapi_register_plugin("betxnpostoperation", TRUE, - "schema_compat_plugin_init_postop", - schema_compat_plugin_init_postop, - PLUGIN_POSTOP_ID, NULL, - state->plugin_identity) != 0) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error registering postoperation plugin\n"); - return -1; - } - } else { - /* preoperation: all callbacks are called at preop */ - if (slapi_register_plugin("preoperation", TRUE, - "schema_compat_plugin_init_preop", - schema_compat_plugin_init_preop, - PLUGIN_PREOP_ID, NULL, - state->plugin_identity) != 0) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error registering preoperation plugin\n"); - return -1; - } - if (slapi_register_plugin("postoperation", TRUE, - "schema_compat_plugin_init_postop", - schema_compat_plugin_init_postop, - PLUGIN_POSTOP_ID, NULL, - state->plugin_identity) != 0) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error registering postoperation plugin\n"); - return -1; - } - if (slapi_register_plugin("internalpostoperation", TRUE, - "schema_compat_plugin_init_internal_postop", - schema_compat_plugin_init_internal_postop, - PLUGIN_INTERNAL_POSTOP_ID, NULL, - state->plugin_identity) != 0) { - slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, - "error registering internal postoperation plugin\n"); - return -1; - } + if (slapi_register_plugin("preoperation", TRUE, + "schema_compat_plugin_init_preop", + schema_compat_plugin_init_preop, + PLUGIN_PREOP_ID, NULL, + state->plugin_identity) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error registering preoperation plugin\n"); + return -1; + } +#ifdef SLAPI_NIS_SUPPORT_BE_TXNS + if (slapi_register_plugin("betxnpreoperation", TRUE, + "schema_compat_plugin_init_betxnpreop", + schema_compat_plugin_init_betxnpreop, + PLUGIN_BETXN_PREOP_ID, NULL, + state->plugin_identity) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error registering betxn preoperation plugin\n"); + return -1; + } + if (slapi_register_plugin("betxnpostoperation", TRUE, + "schema_compat_plugin_init_betxn_postop", + schema_compat_plugin_init_betxn_postop, + PLUGIN_BETXN_POSTOP_ID, NULL, + state->plugin_identity) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error registering betxn postoperation plugin\n"); + return -1; + } +#endif + if (slapi_register_plugin("postoperation", TRUE, + "schema_compat_plugin_init_postop", + schema_compat_plugin_init_postop, + PLUGIN_POSTOP_ID, NULL, + state->plugin_identity) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error registering postoperation plugin\n"); + return -1; + } + if (slapi_register_plugin("internalpostoperation", TRUE, + "schema_compat_plugin_init_internal_postop", + schema_compat_plugin_init_internal_postop, + PLUGIN_INTERNAL_POSTOP_ID, NULL, + state->plugin_identity) != 0) { + slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, + "error registering internal postoperation plugin\n"); + return -1; } slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "registered plugin hooks\n"); diff --git a/src/plugin.h b/src/plugin.h index 7119135..4d62cf3 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Red Hat, Inc. + * Copyright 2008,2012 Red Hat, Inc. * * This Program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,7 @@ struct plugin_state { char *plugin_base; Slapi_ComponentId *plugin_identity; Slapi_PluginDesc *plugin_desc; + int use_be_txns: 1; /* NIS-specific data. */ struct wrapped_thread *tid; |
