From 5f0bf222e0e11fa3265b02a993653ebd400018c3 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 3 Dec 2008 16:06:36 -0500 Subject: - 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 --- src/plug-nis.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'src/plug-nis.c') 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; } -- cgit