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/plug-nis.c | 74 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 22 deletions(-) (limited to 'src/plug-nis.c') 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; -- cgit