summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-12-03 16:06:36 -0500
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2008-12-03 16:06:36 -0500
commit5f0bf222e0e11fa3265b02a993653ebd400018c3 (patch)
treefaed59d8d6541851c6ee20765adf0860b29ab4e1
parentcd84215d4d2907ddfae0b560ae8adfe40bc5f1cf (diff)
downloadslapi-nis-5f0bf222e0e11fa3265b02a993653ebd400018c3.tar.gz
slapi-nis-5f0bf222e0e11fa3265b02a993653ebd400018c3.tar.xz
slapi-nis-5f0bf222e0e11fa3265b02a993653ebd400018c3.zip
- give callback registration the ability to return errors
- make the nis plugin register two types of internal plugins, since it can't just be a postop plugin any more
-rw-r--r--src/back-nis.c14
-rw-r--r--src/back-sch.c22
-rw-r--r--src/backend.h6
-rw-r--r--src/plug-nis.c58
-rw-r--r--src/plug-sch.c44
5 files changed, 128 insertions, 16 deletions
diff --git a/src/back-nis.c b/src/back-nis.c
index 9d95789..9e0475c 100644
--- a/src/back-nis.c
+++ b/src/back-nis.c
@@ -929,10 +929,18 @@ backend_startup(struct plugin_state *state)
}
/* Set up our post-op callbacks. */
-void
-backend_init(Slapi_PBlock *pb, struct plugin_state *state)
+int
+backend_init_postop(Slapi_PBlock *pb, struct plugin_state *state)
{
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
"hooking up postoperation callbacks\n");
- backend_shr_postop_init(pb, state);
+ return backend_shr_postop_init(pb, state);
+}
+
+int
+backend_init_internal_postop(Slapi_PBlock *pb, struct plugin_state *state)
+{
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "hooking up internal postoperation callbacks\n");
+ return backend_shr_internal_postop_init(pb, state);
}
diff --git a/src/back-sch.c b/src/back-sch.c
index 8a6486f..1a4107e 100644
--- a/src/back-sch.c
+++ b/src/back-sch.c
@@ -1098,7 +1098,7 @@ backend_startup(struct plugin_state *state)
backend_shr_startup(state, SCH_CONTAINER_CONFIGURATION_FILTER);
}
-void
+int
backend_init_preop(Slapi_PBlock *pb, struct plugin_state *state)
{
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
@@ -1109,18 +1109,21 @@ backend_init_preop(Slapi_PBlock *pb, struct plugin_state *state)
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) {
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) {
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
"error hooking up search callback\n");
+ return -1;
}
/* Intercept write requests and return an insufficient-access error for
* attempts to write to anything we're managing. */
@@ -1128,30 +1131,43 @@ backend_init_preop(Slapi_PBlock *pb, struct plugin_state *state)
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) {
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) {
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) {
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;
}
-void
+int
backend_init_postop(Slapi_PBlock *pb, struct plugin_state *state)
{
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
"hooking up postoperation callbacks\n");
- backend_shr_postop_init(pb, state);
+ return backend_shr_postop_init(pb, state);
+}
+
+int
+backend_init_internal_postop(Slapi_PBlock *pb, struct plugin_state *state)
+{
+ slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
+ "hooking up internal postoperation callbacks\n");
+ return backend_shr_internal_postop_init(pb, state);
}
diff --git a/src/backend.h b/src/backend.h
index 94bbca1..09f5af6 100644
--- a/src/backend.h
+++ b/src/backend.h
@@ -37,9 +37,9 @@ struct backend_shr_set_data {
/* Startup/initialization functions called through the map. */
void backend_startup(struct plugin_state *state);
-void backend_init(struct slapi_pblock *pb, struct plugin_state *state);
-void backend_init_preop(struct slapi_pblock *pb, struct plugin_state *state);
-void backend_init_postop(struct slapi_pblock *pb, struct plugin_state *state);
+int backend_init_preop(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);
/* Read the server's name. */
int backend_read_master_name(struct plugin_state *state, char **master);
diff --git a/src/plug-nis.c b/src/plug-nis.c
index 6f911d1..ae01984 100644
--- a/src/plug-nis.c
+++ b/src/plug-nis.c
@@ -59,6 +59,10 @@
#include "portmap.h"
#include "wrap.h"
+#define PLUGIN_ID "nis-server-plugin"
+#define PLUGIN_POSTOP_ID PLUGIN_ID "-postop"
+#define PLUGIN_INTERNAL_POSTOP_ID PLUGIN_ID "-internal-postop"
+
/* the module initialization function */
static Slapi_PluginDesc
plugin_description = {
@@ -67,6 +71,7 @@ plugin_description = {
.spd_version = PACKAGE_VERSION,
.spd_description = "NIS Server Plugin",
};
+static struct plugin_state *global_plugin_state;
/* Populate the map cache, register with the local portmapper, and then start
* the plugin's work thread to answer requests using the cache. */
@@ -411,6 +416,34 @@ failed:
return -1;
}
+static int
+nis_plugin_init_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_postop(pb, global_plugin_state) == -1) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ global_plugin_state->plugin_desc->spd_id,
+ "error registering postoperation hooks\n");
+ return -1;
+ }
+ return 0;
+}
+static int
+nis_plugin_init_internal_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_internal_postop(pb, global_plugin_state) == -1) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ global_plugin_state->plugin_desc->spd_id,
+ "error registering internal postop hooks\n");
+ return -1;
+ }
+ return 0;
+}
int
nis_plugin_init(Slapi_PBlock *pb)
{
@@ -427,11 +460,30 @@ 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 and let the backend do its
- * registration. */
+ /* Let the map cache initialize itself. */
map_init(pb, state);
- backend_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;
return 0;
}
diff --git a/src/plug-sch.c b/src/plug-sch.c
index 2e7dc35..f5fdbf4 100644
--- a/src/plug-sch.c
+++ b/src/plug-sch.c
@@ -61,6 +61,7 @@
#define PLUGIN_ID "schema-compat-plugin"
#define PLUGIN_PREOP_ID PLUGIN_ID "-preop"
#define PLUGIN_POSTOP_ID PLUGIN_ID "-postop"
+#define PLUGIN_INTERNAL_POSTOP_ID PLUGIN_ID "-internal-postop"
/* the module initialization function */
static Slapi_PluginDesc
@@ -129,7 +130,12 @@ schema_compat_plugin_init_preop(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);
- backend_init_preop(pb, global_plugin_state);
+ if (backend_init_preop(pb, global_plugin_state) == -1) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ global_plugin_state->plugin_desc->spd_id,
+ "error registering postoperation hooks\n");
+ return -1;
+ }
return 0;
}
static int
@@ -138,7 +144,26 @@ schema_compat_plugin_init_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);
- backend_init_postop(pb, global_plugin_state);
+ if (backend_init_postop(pb, global_plugin_state) == -1) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ global_plugin_state->plugin_desc->spd_id,
+ "error registering postoperation hooks\n");
+ return -1;
+ }
+ return 0;
+}
+static int
+schema_compat_plugin_init_internal_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_internal_postop(pb, global_plugin_state) == -1) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ global_plugin_state->plugin_desc->spd_id,
+ "error registering internal postop hooks\n");
+ return -1;
+ }
return 0;
}
int
@@ -159,8 +184,6 @@ schema_compat_plugin_init(Slapi_PBlock *pb)
slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, state);
/* Let the backend do its setup. */
map_init(pb, state);
- slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
- "registered plugin\n");
/* Register the sub-plugins. */
global_plugin_state = state;
if (slapi_register_plugin("preoperation", TRUE,
@@ -170,6 +193,7 @@ schema_compat_plugin_init(Slapi_PBlock *pb)
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",
@@ -178,7 +202,19 @@ schema_compat_plugin_init(Slapi_PBlock *pb)
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;
return 0;
}