summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2009-05-06 13:55:53 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2009-05-06 13:55:53 -0400
commit76b9c9b548ffce7e995f36d8b17d1aa0f83df7e1 (patch)
tree0d4c46b80bedd79f27988c3c8192380bab1c1919
parent9dd264ca8bf412bb915850cf69f48eb0b36e7fa5 (diff)
downloadslapi-nis-76b9c9b548ffce7e995f36d8b17d1aa0f83df7e1.tar.gz
slapi-nis-76b9c9b548ffce7e995f36d8b17d1aa0f83df7e1.tar.xz
slapi-nis-76b9c9b548ffce7e995f36d8b17d1aa0f83df7e1.zip
- register our internal pre-/post-/internalpre-op plugins at
startup-time, so that the hooks will only be used if we're enabled
-rw-r--r--src/plug-nis.c74
-rw-r--r--src/plug-sch.c96
2 files changed, 92 insertions, 78 deletions
diff --git a/src/plug-nis.c b/src/plug-nis.c
index 1305cf9..05af0a1 100644
--- a/src/plug-nis.c
+++ b/src/plug-nis.c
@@ -72,6 +72,9 @@ plugin_description = {
};
static struct plugin_state *global_plugin_state;
+static int nis_plugin_init_postop(Slapi_PBlock *pb);
+static int nis_plugin_init_internal_postop(Slapi_PBlock *pb);
+
/* Populate the map cache, register with the local portmapper, and then start
* the plugin's work thread to answer requests using the cache. */
static int
@@ -82,7 +85,13 @@ plugin_startup(Slapi_PBlock *pb)
int i, protocol;
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
slapi_pblock_get(pb, SLAPI_TARGET_DN, &state->plugin_base);
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "configuration entry is %s%s%s\n",
+ state->plugin_base ? "\"" : "",
+ state->plugin_base ? state->plugin_base : "NULL",
+ state->plugin_base ? "\"" : "");
/* Populate the maps and data. */
+ map_init(pb, state);
backend_startup(state);
/* Start a new listening thread to handle incoming traffic. */
state->tid = wrap_start_thread(&dispatch_thread, state);
@@ -156,6 +165,30 @@ plugin_startup(Slapi_PBlock *pb)
}
}
}
+ /* Register the sub-plugins. */
+ global_plugin_state = state;
+ if (slapi_register_plugin("postoperation", TRUE,
+ "nis_plugin_init_postop",
+ nis_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,
+ "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;
+ }
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "registered plugin hooks\n");
+ global_plugin_state = NULL;
+
slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id,
"plugin startup completed\n");
return 0;
@@ -206,7 +239,9 @@ plugin_shutdown(Slapi_PBlock *pb)
#ifdef HAVE_TCPD_H
free(state->request_info);
#endif
- free(state);
+ state->plugin_base = NULL;
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "plugin shutdown completed\n");
return 0;
}
@@ -222,7 +257,6 @@ plugin_read_config(Slapi_PBlock *plugin_pb, int *port)
*port = 0;
slapi_pblock_get(plugin_pb, SLAPI_PLUGIN_IDENTITY, &id);
- slapi_pblock_get(plugin_pb, SLAPI_TARGET_DN, &dn);
slapi_pblock_get(plugin_pb, SLAPI_PLUGIN_ARGC, &argc);
slapi_pblock_get(plugin_pb, SLAPI_PLUGIN_ARGV, &argv);
for (i = 0; (i < argc) && (argv != NULL) && (argv[i] != NULL); i++) {
@@ -254,17 +288,11 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
}
memset(state, 0, sizeof(*state));
state->plugin_base = NULL;
+ slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &state->plugin_identity);
state->plugin_desc = &plugin_description;
state->max_value_size = DEFAULT_MAX_VALUE_SIZE;
state->max_dgram_size = DEFAULT_MAX_DGRAM_SIZE;
state->pmap_client_socket = -1;
- slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &state->plugin_identity);
- slapi_pblock_get(pb, SLAPI_TARGET_DN, &state->plugin_base);
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "init: target-dn is %s%s%s\n",
- state->plugin_base ? "\"" : "",
- state->plugin_base ? state->plugin_base : "NULL",
- state->plugin_base ? "\"" : "");
plugin_read_config(pb, &port);
#ifdef HAVE_TCPD_H
@@ -476,30 +504,8 @@ nis_plugin_init(Slapi_PBlock *pb)
slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, &plugin_startup);
slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, &plugin_shutdown);
slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, state);
- /* Let the map cache initialize itself. */
- map_init(pb, state);
- /* Register the sub-plugins. */
- global_plugin_state = state;
- if (slapi_register_plugin("postoperation", TRUE,
- "nis_plugin_init_postop",
- nis_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,
- "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;
- }
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "registered plugin hooks\n");
- global_plugin_state = NULL;
+ /* Note that the plugin was successfully loaded. */
+ slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id,
+ "plugin initialized\n");
return 0;
}
diff --git a/src/plug-sch.c b/src/plug-sch.c
index 34dfa74..3aaed35 100644
--- a/src/plug-sch.c
+++ b/src/plug-sch.c
@@ -72,8 +72,12 @@ plugin_description = {
};
static struct plugin_state *global_plugin_state;
-/* Handle the part of startup that needs to be done before we drop privileges.
- */
+static int schema_compat_plugin_init_preop(Slapi_PBlock *pb);
+static int schema_compat_plugin_init_postop(Slapi_PBlock *pb);
+static int schema_compat_plugin_init_internal_postop(Slapi_PBlock *pb);
+
+/* Handle the part of startup that needs to be done before we drop privileges,
+ * which for this plugin isn't much at all. */
static int
plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
{
@@ -87,12 +91,7 @@ plugin_state_init(Slapi_PBlock *pb, struct plugin_state **lstate)
state->plugin_base = NULL;
state->plugin_desc = &plugin_description;
slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &state->plugin_identity);
- slapi_pblock_get(pb, SLAPI_TARGET_DN, &state->plugin_base);
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "init: target-dn is %s%s%s\n",
- state->plugin_base ? "\"" : "",
- state->plugin_base ? state->plugin_base : "NULL",
- state->plugin_base ? "\"" : "");
+ state->plugin_base = NULL;
*lstate = state;
return 0;
}
@@ -105,11 +104,48 @@ plugin_startup(Slapi_PBlock *pb)
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
slapi_pblock_get(pb, SLAPI_TARGET_DN, &state->plugin_base);
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "startup: target-dn is %s%s%s\n",
+ "configuration entry is %s%s%s\n",
state->plugin_base ? "\"" : "",
state->plugin_base ? state->plugin_base : "NULL",
state->plugin_base ? "\"" : "");
+ /* Populate the tree of fake entries. */
+ map_init(pb, state);
backend_startup(state);
+ /* Register the sub-plugins. */
+ global_plugin_state = state;
+ 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;
+ }
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "registered plugin hooks\n");
+ global_plugin_state = NULL;
+
+ slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id,
+ "plugin startup completed\n");
return 0;
}
@@ -118,8 +154,11 @@ plugin_shutdown(Slapi_PBlock *pb)
{
struct plugin_state *state;
slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "close");
map_done(state);
- free(state);
+ state->plugin_base = NULL;
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "plugin shutdown completed\n");
return 0;
}
@@ -181,39 +220,8 @@ schema_compat_plugin_init(Slapi_PBlock *pb)
slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, &plugin_startup);
slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, &plugin_shutdown);
slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, state);
- /* Let the backend do its setup. */
- map_init(pb, state);
- /* Register the sub-plugins. */
- global_plugin_state = state;
- 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;
- }
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "registered plugin\n");
- global_plugin_state = NULL;
+ /* Note that the plugin was successfully loaded. */
+ slapi_log_error(SLAPI_LOG_PLUGIN, plugin_description.spd_id,
+ "plugin initialized\n");
return 0;
}