summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/common/ldb.c13
-rw-r--r--source4/lib/ldb/common/ldb_modules.c153
-rw-r--r--source4/lib/ldb/config.mk9
-rw-r--r--source4/lib/ldb/include/includes.h2
-rw-r--r--source4/lib/ldb/include/ldb.h9
-rw-r--r--source4/lib/ldb/include/ldb_private.h25
-rw-r--r--source4/lib/ldb/ldb_ildap/ldb_ildap.c5
-rw-r--r--source4/lib/ldb/ldb_ldap/ldb_ldap.c6
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c8
-rw-r--r--source4/lib/ldb/modules/asq.c21
-rw-r--r--source4/lib/ldb/modules/objectclass.c16
-rw-r--r--source4/lib/ldb/modules/operational.c37
-rw-r--r--source4/lib/ldb/modules/paged_results.c46
-rw-r--r--source4/lib/ldb/modules/rdn_name.c16
-rw-r--r--source4/lib/ldb/modules/schema.c16
-rw-r--r--source4/lib/ldb/modules/skel.c46
-rw-r--r--source4/lib/ldb/modules/sort.c21
-rw-r--r--source4/lib/ldb/tools/cmdline.c2
-rw-r--r--source4/lib/ldb/tools/ldbadd.c4
-rw-r--r--source4/lib/ldb/tools/ldbdel.c2
-rw-r--r--source4/lib/ldb/tools/ldbedit.c2
-rw-r--r--source4/lib/ldb/tools/ldbmodify.c2
-rw-r--r--source4/lib/ldb/tools/ldbrename.c2
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c4
-rw-r--r--source4/lib/ldb/tools/ldbtest.c2
-rw-r--r--source4/lib/ldb/tools/oLschema2ldif.c2
26 files changed, 226 insertions, 245 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 87705a855a..28bed0b0ea 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -129,19 +129,6 @@ void ldb_reset_err_string(struct ldb_context *ldb)
} while (0)
/*
- second stage init all modules loaded
-*/
-int ldb_second_stage_init(struct ldb_context *ldb)
-{
- struct ldb_module *module;
-
- FIRST_OP(ldb, second_stage_init);
-
- return module->ops->second_stage_init(module);
-}
-
-
-/*
start a transaction
*/
int ldb_transaction_start(struct ldb_context *ldb)
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 922506ea4d..f1b4783fca 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -67,7 +67,7 @@ static char *talloc_strdup_no_spaces(struct ldb_context *ldb, const char *string
/* modules are called in inverse order on the stack.
Lets place them as an admin would think the right order is.
- Modules order is imprtant */
+ Modules order is important */
static char **ldb_modules_list_from_string(struct ldb_context *ldb, const char *string)
{
char **modules = NULL;
@@ -109,35 +109,79 @@ static char **ldb_modules_list_from_string(struct ldb_context *ldb, const char *
return modules;
}
+static struct ops_list_entry {
+ const struct ldb_module_ops *ops;
+ struct ops_list_entry *next;
+} *registered_modules = NULL;
+
+static const struct ldb_module_ops *ldb_find_module_ops(const char *name)
+{
+ struct ops_list_entry *e;
+
+ for (e = registered_modules; e; e = e->next) {
+ if (strcmp(e->ops->name, name) == 0)
+ return e->ops;
+ }
+
+ return NULL;
+}
+
+
+#ifndef STATIC_LIBLDB_MODULES
+#define STATIC_LIBLDB_MODULES \
+ { \
+ ldb_schema_init, \
+ ldb_operational_init, \
+ ldb_rdn_name_init, \
+ ldb_objectclass_init, \
+ ldb_paged_results_init, \
+ ldb_sort_init, \
+ NULL \
+ }
+#endif
+
+int ldb_global_init(void)
+{
+ static int (*static_init_fns[])(void) = STATIC_LIBLDB_MODULES;
+
+ static int initialized = 0;
+ int ret = 0, i;
+
+ if (initialized)
+ return 0;
+
+ initialized = 1;
+
+ for (i = 0; static_init_fns[i]; i++) {
+ if (static_init_fns[i]() == -1)
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int ldb_register_module(const struct ldb_module_ops *ops)
+{
+ struct ops_list_entry *entry = talloc(talloc_autofree_context(), struct ops_list_entry);
+
+ if (ldb_find_module_ops(ops->name) != NULL)
+ return -1;
+
+ if (entry == NULL)
+ return -1;
+
+ entry->ops = ops;
+ entry->next = registered_modules;
+ registered_modules = entry;
+
+ return 0;
+}
+
int ldb_load_modules(struct ldb_context *ldb, const char *options[])
{
char **modules = NULL;
+ struct ldb_module *module;
int i;
- const struct {
- const char *name;
- ldb_module_init_t init;
- } well_known_modules[] = {
- { "schema", schema_module_init },
- { "operational", operational_module_init },
- { "rdn_name", rdn_name_module_init },
- { "objectclass", objectclass_module_init },
- { "paged_results", paged_results_module_init },
- { "server_sort", server_sort_module_init },
- { "asq", asq_module_init },
-#ifdef _SAMBA_BUILD_
- { "objectguid", objectguid_module_init },
- { "samldb", samldb_module_init },
- { "samba3sam", ldb_samba3sam_module_init },
- { "proxy", proxy_module_init },
- { "rootdse", rootdse_module_init },
- { "extended_dn", extended_dn_module_init },
- { "password_hash", password_hash_module_init },
- { "kludge_acl", kludge_acl_module_init },
- { "wins_ldb", wins_ldb_module_init },
-#endif
- { NULL, NULL }
- };
-
/* find out which modules we are requested to activate */
/* check if we have a custom module list passd as ldb option */
@@ -149,7 +193,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
}
- /* if not overloaded by options and the backend is not ldap try to load the modules list form ldb */
+ /* if not overloaded by options and the backend is not ldap try to load the modules list from ldb */
if ((modules == NULL) && (strcmp("ldap", ldb->modules->ops->name) != 0)) {
int ret;
const char * const attrs[] = { "@LIST" , NULL};
@@ -191,27 +235,34 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
for (i = 0; modules[i] != NULL; i++) {
struct ldb_module *current;
- int m;
- for (m=0;well_known_modules[m].name;m++) {
- if (strcmp(modules[i], well_known_modules[m].name) == 0) {
- current = well_known_modules[m].init(ldb, options);
- if (current == NULL) {
- ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]);
- return -1;
- }
- DLIST_ADD(ldb->modules, current);
- break;
- }
- }
- if (well_known_modules[m].name == NULL) {
+ const struct ldb_module_ops *ops;
+
+ ops = ldb_find_module_ops(modules[i]);
+ if (ops == NULL) {
ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n",
modules[i]);
+ continue;
}
+
+ current = talloc_zero(ldb, struct ldb_module);
+ if (current == NULL) {
+ return -1;
+ }
+
+ current->ldb = ldb;
+ current->ops = ops;
+
+ DLIST_ADD(ldb->modules, current);
}
- /* second stage init */
- if (ldb_second_stage_init(ldb) != LDB_SUCCESS) {
- ldb_debug(ldb, LDB_DEBUG_ERROR, "ERROR: Second stage init failed!\n");
+ module = ldb->modules;
+
+ while (module && module->ops->init_context == NULL)
+ module = module->next;
+
+ if (module && module->ops->init_context &&
+ module->ops->init_context(module) != LDB_SUCCESS) {
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "module initialization failed\n");
return -1;
}
@@ -240,10 +291,20 @@ int ldb_next_request(struct ldb_module *module, struct ldb_request *request)
return module->ops->request(module, request);
}
-int ldb_next_second_stage_init(struct ldb_module *module)
+int ldb_next_init(struct ldb_module *module)
{
- FIND_OP(module, second_stage_init);
- return module->ops->second_stage_init(module);
+ /* init is different in that it is not an error if modules
+ * do not require initialization */
+
+ module = module->next;
+
+ while (module && module->ops->init_context == NULL)
+ module = module->next;
+
+ if (module == NULL)
+ return LDB_SUCCESS;
+
+ return module->ops->init_context(module);
}
int ldb_next_start_trans(struct ldb_module *module)
diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk
index 16f4001acd..82b98fa123 100644
--- a/source4/lib/ldb/config.mk
+++ b/source4/lib/ldb/config.mk
@@ -1,6 +1,7 @@
################################################
# Start MODULE libldb_asq
[MODULE::libldb_asq]
+INIT_FUNCTION = ldb_asq_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@@ -11,6 +12,7 @@ OBJ_FILES = \
################################################
# Start MODULE libldb_sort
[MODULE::libldb_sort]
+INIT_FUNCTION = ldb_sort_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@@ -21,6 +23,7 @@ OBJ_FILES = \
################################################
# Start MODULE libldb_paged_results
[MODULE::libldb_paged_results]
+INIT_FUNCTION = ldb_paged_results_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@@ -32,6 +35,7 @@ OBJ_FILES = \
# Start MODULE libldb_operational
[MODULE::libldb_operational]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = ldb_operational_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
modules/operational.o
@@ -41,6 +45,7 @@ OBJ_FILES = \
################################################
# Start MODULE libldb_objectclass
[MODULE::libldb_objectclass]
+INIT_FUNCTION = ldb_objectclass_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@@ -52,6 +57,7 @@ OBJ_FILES = \
# Start MODULE libldb_rdn_name
[MODULE::libldb_rdn_name]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = ldb_rdn_name_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
modules/rdn_name.o
@@ -61,6 +67,7 @@ OBJ_FILES = \
################################################
# Start MODULE libldb_schema
[MODULE::libldb_schema]
+INIT_FUNCTION = ldb_schema_init
SUBSYSTEM = LIBLDB
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
@@ -94,6 +101,7 @@ OBJ_FILES = modules/ldb_map.o
# Start MODULE libldb_skel
[MODULE::libldb_skel]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = ldb_skel_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = modules/skel.o
# End MODULE libldb_skel
@@ -136,6 +144,7 @@ NOPROTO = YES
MAJOR_VERSION = 0
MINOR_VERSION = 0
DESCRIPTION = LDAP-like embedded database library
+INIT_FUNCTION_TYPE = int (*) (void)
RELEASE_VERSION = 1
OBJ_FILES = \
common/ldb.o \
diff --git a/source4/lib/ldb/include/includes.h b/source4/lib/ldb/include/includes.h
index 15eb18a5e8..b10f329a2d 100644
--- a/source4/lib/ldb/include/includes.h
+++ b/source4/lib/ldb/include/includes.h
@@ -10,6 +10,8 @@
#include "system/iconv.h"
#include "system/time.h"
+#include "build.h"
+
#else /*_SAMBA_BUILD_*/
#ifndef _GNU_SOURCE
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index f5bca965ad..13e69282ca 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -666,6 +666,15 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *request);
int ldb_async_wait(struct ldb_context *ldb, struct ldb_async_handle *handle, enum ldb_async_wait_type type);
/**
+ Initialise ldbs' global information
+
+ This is required before any other LDB call
+
+ \return 0 if initialisation succeeded, -1 otherwise
+*/
+int ldb_global_init(void);
+
+/**
Initialise an ldb context
This is required before any other LDB call.
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index 3f9be357a7..d4cba9797c 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -56,11 +56,11 @@ struct ldb_module {
*/
struct ldb_module_ops {
const char *name;
+ int (*init_context) (struct ldb_module *);
int (*request)(struct ldb_module *, struct ldb_request *);
int (*start_transaction)(struct ldb_module *);
int (*end_transaction)(struct ldb_module *);
int (*del_transaction)(struct ldb_module *);
- int (*second_stage_init)(struct ldb_module *);
};
@@ -112,9 +112,6 @@ struct ldb_context {
uint64_t (*sequence_number)(struct ldb_context *);
};
-/* the modules init function */
-typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, const char **);
-
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#endif
@@ -124,9 +121,6 @@ typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, const char
*/
#define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__)
-/* The following definitions come from lib/ldb/common/ldb.c */
-int ldb_second_stage_init(struct ldb_context *ldb);
-
/* The following definitions come from lib/ldb/common/ldb_modules.c */
int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
@@ -134,11 +128,13 @@ int ldb_next_request(struct ldb_module *module, struct ldb_request *request);
int ldb_next_start_trans(struct ldb_module *module);
int ldb_next_end_trans(struct ldb_module *module);
int ldb_next_del_trans(struct ldb_module *module);
-int ldb_next_second_stage_init(struct ldb_module *module);
+int ldb_next_init(struct ldb_module *module);
void ldb_set_errstring(struct ldb_context *ldb, char *err_string);
void ldb_reset_err_string(struct ldb_context *ldb);
+int ldb_register_module(const struct ldb_module_ops *);
+
/* The following definitions come from lib/ldb/common/ldb_debug.c */
void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level,
@@ -161,14 +157,13 @@ int lsqlite3_connect(struct ldb_context *ldb,
const char *url,
unsigned int flags,
const char *options[]);
-struct ldb_module *objectclass_module_init(struct ldb_context *ldb, const char *options[]);
-struct ldb_module *operational_module_init(struct ldb_context *ldb, const char *options[]);
-struct ldb_module *paged_results_module_init(struct ldb_context *ldb, const char *options[]);
-struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[]);
-struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[]);
-struct ldb_module *server_sort_module_init(struct ldb_context *ldb, const char *options[]);
-struct ldb_module *asq_module_init(struct ldb_context *ldb, const char *options[]);
+int ldb_objectclass_init(void);
+int ldb_operational_init(void);
+int ldb_paged_results_init(void);
+int ldb_rdn_name_init(void);
+int ldb_schema_init(void);
+int ldb_sort_init(void);
int ldb_match_msg(struct ldb_context *ldb,
struct ldb_message *msg,
diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
index a5f4ab67fd..69053cc110 100644
--- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c
+++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
@@ -898,7 +898,6 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req)
}
}
-
static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type)
{
struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context);
@@ -939,7 +938,7 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_
/*
fetch the rootDSE for later use
*/
-static int ildb_init_2(struct ldb_module *module)
+static int ildb_init(struct ldb_module *module)
{
struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private);
struct ldb_result *res = NULL;
@@ -963,7 +962,7 @@ static const struct ldb_module_ops ildb_ops = {
.start_transaction = ildb_start_trans,
.end_transaction = ildb_end_trans,
.del_transaction = ildb_del_trans,
- .second_stage_init = ildb_init_2
+ .init_context = ildb_init
};
/*
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index 167bbfbd63..4f840868a1 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -1006,18 +1006,12 @@ static int lldb_request(struct ldb_module *module, struct ldb_request *req)
}
}
-static int lldb_init_2(struct ldb_module *module)
-{
- return LDB_SUCCESS;
-}
-
static const struct ldb_module_ops lldb_ops = {
.name = "ldap",
.request = lldb_request,
.start_transaction = lldb_start_trans,
.end_transaction = lldb_end_trans,
.del_transaction = lldb_del_trans,
- .second_stage_init = lldb_init_2
};
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index b58b03f221..7cf6138b12 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -797,18 +797,12 @@ static uint64_t ltdb_sequence_number(struct ldb_context *ldb)
return seq_num;
}
-static int ltdb_init_2(struct ldb_module *module)
-{
- return LDB_SUCCESS;
-}
-
static const struct ldb_module_ops ltdb_ops = {
.name = "tdb",
.request = ltdb_request,
.start_transaction = ltdb_start_trans,
.end_transaction = ltdb_end_trans,
- .del_transaction = ltdb_del_trans,
- .second_stage_init = ltdb_init_2
+ .del_transaction = ltdb_del_trans
};
diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c
index 2975f4d832..33ba9bed04 100644
--- a/source4/lib/ldb/modules/asq.c
+++ b/source4/lib/ldb/modules/asq.c
@@ -210,7 +210,7 @@ static int asq(struct ldb_module *module, struct ldb_request *req)
}
}
-static int asq_init_2(struct ldb_module *module)
+static int asq_init(struct ldb_module *module)
{
struct ldb_request request;
int ret;
@@ -225,28 +225,17 @@ static int asq_init_2(struct ldb_module *module)
return LDB_ERR_OTHER;
}
- return ldb_next_second_stage_init(module);
+ return ldb_next_init(module);
}
static const struct ldb_module_ops asq_ops = {
.name = "asq",
.request = asq,
- .second_stage_init = asq_init_2
+ .init_context = asq_init
};
-struct ldb_module *asq_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_asq_init(void)
{
- struct ldb_module *ctx;
-
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx)
- return NULL;
-
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &asq_ops;
- ctx->private_data = NULL;
-
- return ctx;
+ return ldb_register_module(&asq_ops);
}
diff --git a/source4/lib/ldb/modules/objectclass.c b/source4/lib/ldb/modules/objectclass.c
index 8b4ad598cc..a9c51341a8 100644
--- a/source4/lib/ldb/modules/objectclass.c
+++ b/source4/lib/ldb/modules/objectclass.c
@@ -302,19 +302,7 @@ static const struct ldb_module_ops objectclass_ops = {
.request = objectclass_request,
};
-struct ldb_module *objectclass_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_objectclass_init(void)
{
- struct ldb_module *ctx;
-
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx)
- return NULL;
-
- ctx->private_data = NULL;
-
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &objectclass_ops;
-
- return ctx;
+ return ldb_register_module(&objectclass_ops);
}
diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c
index 51f0ce25e4..441c899a58 100644
--- a/source4/lib/ldb/modules/operational.c
+++ b/source4/lib/ldb/modules/operational.c
@@ -400,31 +400,24 @@ static int operational_request(struct ldb_module *module, struct ldb_request *re
}
}
+static int operational_init(struct ldb_module *ctx)
+{
+ /* setup some standard attribute handlers */
+ ldb_set_attrib_handler_syntax(ctx->ldb, "whenCreated", LDB_SYNTAX_UTC_TIME);
+ ldb_set_attrib_handler_syntax(ctx->ldb, "whenChanged", LDB_SYNTAX_UTC_TIME);
+ ldb_set_attrib_handler_syntax(ctx->ldb, "subschemaSubentry", LDB_SYNTAX_DN);
+ ldb_set_attrib_handler_syntax(ctx->ldb, "structuralObjectClass", LDB_SYNTAX_OBJECTCLASS);
+
+ return ldb_next_init(ctx);
+}
+
static const struct ldb_module_ops operational_ops = {
.name = "operational",
- .request = operational_request
+ .request = operational_request,
+ .init_context = operational_init
};
-
-/* the init function */
-struct ldb_module *operational_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_operational_init(void)
{
- struct ldb_module *ctx;
-
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx)
- return NULL;
-
- ctx->private_data = NULL;
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &operational_ops;
-
- /* setup some standard attribute handlers */
- ldb_set_attrib_handler_syntax(ldb, "whenCreated", LDB_SYNTAX_UTC_TIME);
- ldb_set_attrib_handler_syntax(ldb, "whenChanged", LDB_SYNTAX_UTC_TIME);
- ldb_set_attrib_handler_syntax(ldb, "subschemaSubentry", LDB_SYNTAX_DN);
- ldb_set_attrib_handler_syntax(ldb, "structuralObjectClass", LDB_SYNTAX_OBJECTCLASS);
-
- return ctx;
+ return ldb_register_module(&operational_ops);
}
diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c
index c4aad4500e..9d6a50e27f 100644
--- a/source4/lib/ldb/modules/paged_results.c
+++ b/source4/lib/ldb/modules/paged_results.c
@@ -247,10 +247,20 @@ static int paged_request(struct ldb_module *module, struct ldb_request *req)
}
}
-static int paged_request_init_2(struct ldb_module *module)
+static int paged_request_init(struct ldb_module *module)
{
struct ldb_request request;
int ret;
+ struct private_data *data;
+
+ data = talloc(module, struct private_data);
+ if (data == NULL) {
+ return LDB_ERR_OTHER;
+ }
+
+ data->next_free_id = 1;
+ data->store = NULL;
+ module->private_data = data;
request.operation = LDB_REQ_REGISTER;
request.op.reg.oid = LDB_CONTROL_PAGED_RESULTS_OID;
@@ -262,37 +272,17 @@ static int paged_request_init_2(struct ldb_module *module)
return LDB_ERR_OTHER;
}
- return ldb_next_second_stage_init(module);
+ return ldb_next_init(module);
}
static const struct ldb_module_ops paged_ops = {
- .name = "paged_results",
- .request = paged_request,
- .second_stage_init = paged_request_init_2
+ .name = "paged_results",
+ .request = paged_request,
+ .init_context = paged_request_init
};
-struct ldb_module *paged_results_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_paged_results_init(void)
{
- struct ldb_module *ctx;
- struct private_data *data;
-
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx)
- return NULL;
-
- data = talloc(ctx, struct private_data);
- if (data == NULL) {
- talloc_free(ctx);
- return NULL;
- }
-
- data->next_free_id = 1;
- data->store = NULL;
- ctx->private_data = data;
-
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &paged_ops;
-
- return ctx;
+ return ldb_register_module(&paged_ops);
}
+
diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c
index 2e4e250755..59930046ce 100644
--- a/source4/lib/ldb/modules/rdn_name.c
+++ b/source4/lib/ldb/modules/rdn_name.c
@@ -211,19 +211,7 @@ static const struct ldb_module_ops rdn_name_ops = {
};
-/* the init function */
-struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_rdn_name_init(void)
{
- struct ldb_module *ctx;
-
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx)
- return NULL;
-
- ctx->private_data = NULL;
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &rdn_name_ops;
-
- return ctx;
+ return ldb_register_module(&rdn_name_ops);
}
diff --git a/source4/lib/ldb/modules/schema.c b/source4/lib/ldb/modules/schema.c
index 9bf9a4d2c5..73b07023da 100644
--- a/source4/lib/ldb/modules/schema.c
+++ b/source4/lib/ldb/modules/schema.c
@@ -482,19 +482,7 @@ static const struct ldb_module_ops schema_ops = {
.request = schema_request
};
-struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_schema_init(void)
{
- struct ldb_module *ctx;
-
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx) {
- return NULL;
- }
-
- ctx->private_data = NULL;
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &schema_ops;
-
- return ctx;
+ return ldb_register_module(&schema_ops);
}
diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c
index e9b76be2ba..0089433b37 100644
--- a/source4/lib/ldb/modules/skel.c
+++ b/source4/lib/ldb/modules/skel.c
@@ -122,45 +122,33 @@ static int skel_request(struct ldb_module *module, struct ldb_request *req)
}
}
-static int skel_init_2(struct ldb_module *module)
+static int skel_init(struct ldb_module *ctx)
{
- /* second stage init stuff */
- /* see control modules as example */
- return ldb_next_second_stage_init(module);
-}
-
-static const struct ldb_module_ops skel_ops = {
- .name = "skel",
- .request = skel_request,
- .start_transaction = skel_start_trans,
- .end_transaction = skel_end_trans,
- .del_transaction = skel_del_trans,
- .second_stage_init = skel_init_2
-};
-
-struct ldb_module *skel_module_init(struct ldb_context *ldb, const char *options[])
-{
- struct ldb_module *ctx;
struct private_data *data;
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx)
- return NULL;
-
data = talloc(ctx, struct private_data);
if (data == NULL) {
- talloc_free(ctx);
- return NULL;
+ return 1;
}
data->some_private_data = NULL;
ctx->private_data = data;
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &skel_ops;
-
talloc_set_destructor (ctx, skel_destructor);
- return ctx;
+ return ldb_next_init(ctx);
+}
+
+static const struct ldb_module_ops skel_ops = {
+ .name = "skel",
+ .init_context = skel_init,
+ .request = skel_request,
+ .start_transaction = skel_start_trans,
+ .end_transaction = skel_end_trans,
+ .del_transaction = skel_del_trans,
+};
+
+int ldb_skel_init(void)
+{
+ return ldb_register_module(&skel_ops);
}
diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c
index ac9f1081de..d01e468956 100644
--- a/source4/lib/ldb/modules/sort.c
+++ b/source4/lib/ldb/modules/sort.c
@@ -228,7 +228,7 @@ static int server_sort(struct ldb_module *module, struct ldb_request *req)
}
}
-static int server_sort_init_2(struct ldb_module *module)
+static int server_sort_init(struct ldb_module *module)
{
struct ldb_request request;
int ret;
@@ -243,27 +243,16 @@ static int server_sort_init_2(struct ldb_module *module)
return LDB_ERR_OTHER;
}
- return ldb_next_second_stage_init(module);
+ return ldb_next_init(module);
}
static const struct ldb_module_ops server_sort_ops = {
.name = "server_sort",
.request = server_sort,
- .second_stage_init = server_sort_init_2
+ .init_context = server_sort_init
};
-struct ldb_module *server_sort_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_sort_init(void)
{
- struct ldb_module *ctx;
-
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx)
- return NULL;
-
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &server_sort_ops;
- ctx->private_data = NULL;
-
- return ctx;
+ return ldb_register_module(&server_sort_ops);
}
diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c
index a67c41e67f..8f803c5118 100644
--- a/source4/lib/ldb/tools/cmdline.c
+++ b/source4/lib/ldb/tools/cmdline.c
@@ -71,6 +71,8 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
POPT_TABLEEND
};
+ ldb_global_init();
+
#ifdef _SAMBA_BUILD_
r = ldb_register_samba_handlers(ldb);
if (r != 0) {
diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c
index 0d5acd3787..6a0f510244 100644
--- a/source4/lib/ldb/tools/ldbadd.c
+++ b/source4/lib/ldb/tools/ldbadd.c
@@ -84,12 +84,14 @@ static int process_file(struct ldb_context *ldb, FILE *f)
- int main(int argc, const char **argv)
+int main(int argc, const char **argv)
{
struct ldb_context *ldb;
int i, count=0;
struct ldb_cmdline *options;
+ ldb_global_init();
+
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c
index 26544d8a9e..749ce3f91c 100644
--- a/source4/lib/ldb/tools/ldbdel.c
+++ b/source4/lib/ldb/tools/ldbdel.c
@@ -79,6 +79,8 @@ static void usage(void)
int ret, i;
struct ldb_cmdline *options;
+ ldb_global_init();
+
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index 9cef81f1db..b4e2b0a848 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -281,6 +281,8 @@ static void usage(void)
const char *expression = "(|(objectClass=*)(distinguishedName=*))";
const char * const * attrs = NULL;
+ ldb_global_init();
+
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c
index e785a42a23..4ce49c2ce8 100644
--- a/source4/lib/ldb/tools/ldbmodify.c
+++ b/source4/lib/ldb/tools/ldbmodify.c
@@ -91,6 +91,8 @@ static int process_file(struct ldb_context *ldb, FILE *f)
int i;
struct ldb_cmdline *options;
+ ldb_global_init();
+
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbrename.c b/source4/lib/ldb/tools/ldbrename.c
index 9c37744277..3229426875 100644
--- a/source4/lib/ldb/tools/ldbrename.c
+++ b/source4/lib/ldb/tools/ldbrename.c
@@ -58,6 +58,8 @@ static void usage(void)
struct ldb_cmdline *options;
const struct ldb_dn *dn1, *dn2;
+ ldb_global_init();
+
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index c380862c5d..fbf32c0777 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -148,7 +148,7 @@ static int do_search(struct ldb_context *ldb,
return 0;
}
- int main(int argc, const char **argv)
+int main(int argc, const char **argv)
{
struct ldb_context *ldb;
struct ldb_dn *basedn = NULL;
@@ -157,6 +157,8 @@ static int do_search(struct ldb_context *ldb,
int ret = -1;
const char *expression = "(|(objectClass=*)(distinguishedName=*))";
+ ldb_global_init();
+
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c
index 69362d0f20..5fd75a0cab 100644
--- a/source4/lib/ldb/tools/ldbtest.c
+++ b/source4/lib/ldb/tools/ldbtest.c
@@ -376,6 +376,8 @@ static void usage(void)
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct ldb_context *ldb;
+ ldb_global_init();
+
ldb = ldb_init(mem_ctx);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/oLschema2ldif.c b/source4/lib/ldb/tools/oLschema2ldif.c
index b4fe421161..288cf4c3c3 100644
--- a/source4/lib/ldb/tools/oLschema2ldif.c
+++ b/source4/lib/ldb/tools/oLschema2ldif.c
@@ -583,6 +583,8 @@ static void usage(void)
FILE *in = stdin;
FILE *out = stdout;
+ ldb_global_init();
+
ctx = talloc_new(NULL);
ldb_ctx = ldb_init(ctx);