summaryrefslogtreecommitdiffstats
path: root/src/plug-sch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plug-sch.c')
-rw-r--r--src/plug-sch.c129
1 files changed, 103 insertions, 26 deletions
diff --git a/src/plug-sch.c b/src/plug-sch.c
index 44b0918..cb4a63e 100644
--- a/src/plug-sch.c
+++ b/src/plug-sch.c
@@ -123,6 +123,7 @@ plugin_shutdown(Slapi_PBlock *pb)
return 0;
}
+/* preoperation: all callbacks are called at preop */
static int
schema_compat_plugin_init_preop(Slapi_PBlock *pb)
{
@@ -137,6 +138,39 @@ schema_compat_plugin_init_preop(Slapi_PBlock *pb)
}
return 0;
}
+
+/* betxnpreoperation: bind, compare and search callbacks are called at preop */
+static int
+schema_compat_plugin_init_betxnpreop_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);
+ if (backend_init_preop(pb, global_plugin_state) == -1) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ global_plugin_state->plugin_desc->spd_id,
+ "error registering preoperation hooks\n");
+ return -1;
+ }
+ return 0;
+}
+
+/* betxnpreoperation: add, delete, modify and modrdn callbacks are called at betxnpreop */
+static int
+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_betxnpreop(pb, global_plugin_state) == -1) {
+ slapi_log_error(SLAPI_LOG_PLUGIN,
+ global_plugin_state->plugin_desc->spd_id,
+ "error registering preoperation hooks\n");
+ return -1;
+ }
+ return 0;
+}
+
static int
schema_compat_plugin_init_postop(Slapi_PBlock *pb)
{
@@ -169,6 +203,16 @@ int
schema_compat_plugin_init(Slapi_PBlock *pb)
{
struct plugin_state *state = NULL;
+ 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,
@@ -185,32 +229,65 @@ schema_compat_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("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 (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;
+ }
}
slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
"registered plugin hooks\n");