summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/build/smb_build/config_mk.pm2
-rw-r--r--source4/build/smb_build/header.pm7
-rw-r--r--source4/build/smb_build/input.pm4
-rw-r--r--source4/dsdb/samdb/ldb_modules/config.mk9
-rw-r--r--source4/dsdb/samdb/ldb_modules/extended_dn.c21
-rw-r--r--source4/dsdb/samdb/ldb_modules/kludge_acl.c39
-rw-r--r--source4/dsdb/samdb/ldb_modules/objectguid.c16
-rw-r--r--source4/dsdb/samdb/ldb_modules/password_hash.c16
-rw-r--r--source4/dsdb/samdb/ldb_modules/proxy.c19
-rw-r--r--source4/dsdb/samdb/ldb_modules/rootdse.c34
-rw-r--r--source4/dsdb/samdb/ldb_modules/samba3sam.c4
-rw-r--r--source4/dsdb/samdb/ldb_modules/samldb.c25
-rw-r--r--source4/ldap_server/ldap_server.c2
-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
-rw-r--r--source4/nbt_server/config.mk1
-rw-r--r--source4/nbt_server/wins/wins_ldb.c41
-rw-r--r--source4/nbt_server/wins/winsserver.c3
-rw-r--r--source4/scripting/ejs/smbscript.c6
-rw-r--r--source4/smbd/process_thread.c2
44 files changed, 326 insertions, 396 deletions
diff --git a/source4/build/smb_build/config_mk.pm b/source4/build/smb_build/config_mk.pm
index 1475ee09ee..c7ff8648eb 100644
--- a/source4/build/smb_build/config_mk.pm
+++ b/source4/build/smb_build/config_mk.pm
@@ -67,6 +67,8 @@ my $section_types = {
"MAJOR_VERSION" => "string",
"MINOR_VERSION" => "string",
"RELEASE_VERSION" => "string",
+
+ "INIT_FUNCTION_TYPE" => "string",
"OBJ_FILES" => "list",
diff --git a/source4/build/smb_build/header.pm b/source4/build/smb_build/header.pm
index 456c29368a..1cc5361b65 100644
--- a/source4/build/smb_build/header.pm
+++ b/source4/build/smb_build/header.pm
@@ -30,13 +30,16 @@ sub _prepare_build_h($)
my $DEFINE = ();
next if ($key->{TYPE} ne "LIBRARY" and $key->{TYPE} ne "SUBSYSTEM");
next unless defined($key->{INIT_FUNCTIONS});
-
+
$DEFINE->{COMMENT} = "$key->{TYPE} $key->{NAME} INIT";
$DEFINE->{KEY} = "STATIC_$key->{NAME}_MODULES";
$DEFINE->{VAL} = "{ \\\n";
foreach (@{$key->{INIT_FUNCTIONS}}) {
$DEFINE->{VAL} .= "\t$_, \\\n";
- $output .= "NTSTATUS $_(void);\n";
+ my $fn = $key->{INIT_FUNCTION_TYPE};
+ unless(defined($fn)) { $fn = "NTSTATUS (*) (void)"; }
+ $fn =~ s/\(\*\)/$_/;
+ $output .= "$fn;\n";
}
$DEFINE->{VAL} .= "\tNULL \\\n }";
diff --git a/source4/build/smb_build/input.pm b/source4/build/smb_build/input.pm
index c34930f39a..fbeeddcda1 100644
--- a/source4/build/smb_build/input.pm
+++ b/source4/build/smb_build/input.pm
@@ -97,6 +97,10 @@ sub check_library($$$)
return;
}
+ unless (defined($lib->{INIT_FUNCTION_TYPE})) {
+ $lib->{INIT_FUNCTION_TYPE} = "NTSTATUS (*) (void)";
+ }
+
$lib->{INSTALLDIR} = "LIBDIR";
}
diff --git a/source4/dsdb/samdb/ldb_modules/config.mk b/source4/dsdb/samdb/ldb_modules/config.mk
index c53c7c1606..e14b9bfecf 100644
--- a/source4/dsdb/samdb/ldb_modules/config.mk
+++ b/source4/dsdb/samdb/ldb_modules/config.mk
@@ -2,6 +2,7 @@
# Start MODULE libldb_objectguid
[MODULE::libldb_objectguid]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = objectguid_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
objectguid.o
@@ -14,6 +15,7 @@ REQUIRED_SUBSYSTEMS = \
# Start MODULE libldb_samldb
[MODULE::libldb_samldb]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = samldb_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
samldb.o
@@ -26,6 +28,8 @@ REQUIRED_SUBSYSTEMS = SAMDB
# Start MODULE libldb_samba3sam
[MODULE::libldb_samba3sam]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = ldb_samba3sam_module_init
+ENABLE = NO
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
samba3sam.o
@@ -37,6 +41,7 @@ OBJ_FILES = \
# Start MODULE libldb_proxy
[MODULE::libldb_proxy]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = proxy_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
proxy.o
@@ -49,6 +54,7 @@ OBJ_FILES = \
# Start MODULE libldb_rootdse
[MODULE::libldb_rootdse]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = rootdse_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
rootdse.o
@@ -60,6 +66,7 @@ OBJ_FILES = \
# Start MODULE libldb_password_hash
[MODULE::libldb_password_hash]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = password_hash_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
password_hash.o
@@ -73,6 +80,7 @@ REQUIRED_SUBSYSTEMS = \
# Start MODULE libldb_cludge_acl
[MODULE::libldb_kludge_acl]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = ldb_kludge_acl_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
kludge_acl.o
@@ -86,6 +94,7 @@ REQUIRED_SUBSYSTEMS = \
# Start MODULE libldb_extended_dn
[MODULE::libldb_extended_dn]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = ldb_extended_dn_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
extended_dn.o
diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn.c b/source4/dsdb/samdb/ldb_modules/extended_dn.c
index 9795758dc2..5b288aa311 100644
--- a/source4/dsdb/samdb/ldb_modules/extended_dn.c
+++ b/source4/dsdb/samdb/ldb_modules/extended_dn.c
@@ -269,7 +269,7 @@ static int extended_request(struct ldb_module *module, struct ldb_request *req)
}
}
-static int extended_init_2(struct ldb_module *module)
+static int extended_init(struct ldb_module *module)
{
struct ldb_request request;
int ret;
@@ -284,27 +284,16 @@ static int extended_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 extended_dn_ops = {
.name = "extended_dn",
.request = extended_request,
- .second_stage_init = extended_init_2
+ .init_context = extended_init
};
-struct ldb_module *extended_dn_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_extended_dn_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 = &extended_dn_ops;
- ctx->private_data = NULL;
-
- return ctx;
+ return ldb_register_module(&extended_dn_ops);
}
diff --git a/source4/dsdb/samdb/ldb_modules/kludge_acl.c b/source4/dsdb/samdb/ldb_modules/kludge_acl.c
index 9ce3217104..4c680df3e6 100644
--- a/source4/dsdb/samdb/ldb_modules/kludge_acl.c
+++ b/source4/dsdb/samdb/ldb_modules/kludge_acl.c
@@ -175,7 +175,7 @@ static int kludge_acl_request(struct ldb_module *module, struct ldb_request *req
}
}
-static int kludge_acl_init_2(struct ldb_module *module)
+static int kludge_acl_init(struct ldb_module *module)
{
int ret, i;
TALLOC_CTX *mem_ctx = talloc_new(module);
@@ -184,8 +184,15 @@ static int kludge_acl_init_2(struct ldb_module *module)
struct ldb_message *msg;
struct ldb_message_element *password_attributes;
- struct kludge_private_data *data = talloc_get_type(module->private_data, struct kludge_private_data);
+ struct kludge_private_data *data;
+
+ data = talloc(module, struct kludge_private_data);
+ if (data == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
data->password_attrs = NULL;
+ module->private_data = data;
if (!mem_ctx) {
return LDB_ERR_OPERATIONS_ERROR;
@@ -227,7 +234,7 @@ static int kludge_acl_init_2(struct ldb_module *module)
done:
talloc_free(mem_ctx);
- return ldb_next_second_stage_init(module);
+ return ldb_next_init(module);
}
static const struct ldb_module_ops kludge_acl_ops = {
@@ -236,30 +243,10 @@ static const struct ldb_module_ops kludge_acl_ops = {
.start_transaction = kludge_acl_start_trans,
.end_transaction = kludge_acl_end_trans,
.del_transaction = kludge_acl_del_trans,
- .second_stage_init = kludge_acl_init_2
+ .init_context = kludge_acl_init
};
-struct ldb_module *kludge_acl_module_init(struct ldb_context *ldb, const char *options[])
+int ldb_kludge_acl_init(void)
{
- struct ldb_module *ctx;
- struct kludge_private_data *data;
-
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx)
- return NULL;
-
- data = talloc(ctx, struct kludge_private_data);
- if (data == NULL) {
- talloc_free(ctx);
- return NULL;
- }
-
- data->password_attrs = NULL;
- ctx->private_data = data;
-
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &kludge_acl_ops;
-
- return ctx;
+ return ldb_register_module(&kludge_acl_ops);
}
diff --git a/source4/dsdb/samdb/ldb_modules/objectguid.c b/source4/dsdb/samdb/ldb_modules/objectguid.c
index c9063af6ef..7169aa6842 100644
--- a/source4/dsdb/samdb/ldb_modules/objectguid.c
+++ b/source4/dsdb/samdb/ldb_modules/objectguid.c
@@ -127,19 +127,7 @@ static const struct ldb_module_ops objectguid_ops = {
};
-/* the init function */
-struct ldb_module *objectguid_module_init(struct ldb_context *ldb, const char *options[])
+int objectguid_module_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 = &objectguid_ops;
-
- return ctx;
+ return ldb_register_module(&objectguid_ops);
}
diff --git a/source4/dsdb/samdb/ldb_modules/password_hash.c b/source4/dsdb/samdb/ldb_modules/password_hash.c
index e28c85ae37..414f79ea10 100644
--- a/source4/dsdb/samdb/ldb_modules/password_hash.c
+++ b/source4/dsdb/samdb/ldb_modules/password_hash.c
@@ -731,19 +731,7 @@ static const struct ldb_module_ops password_hash_ops = {
};
-/* the init function */
-struct ldb_module *password_hash_module_init(struct ldb_context *ldb, const char *options[])
+int password_hash_module_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 = &password_hash_ops;
-
- return ctx;
+ return ldb_register_module(&password_hash_ops);
}
diff --git a/source4/dsdb/samdb/ldb_modules/proxy.c b/source4/dsdb/samdb/ldb_modules/proxy.c
index 511f9aeec5..85b40b62d1 100644
--- a/source4/dsdb/samdb/ldb_modules/proxy.c
+++ b/source4/dsdb/samdb/ldb_modules/proxy.c
@@ -333,22 +333,7 @@ static const struct ldb_module_ops proxy_ops = {
.request = proxy_request
};
-struct ldb_module *proxy_module_init(struct ldb_context *ldb, const char *options[])
+int proxy_module_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 = &proxy_ops;
-
- ctx->private_data = talloc_zero(ctx, struct proxy_data);
- if (ctx->private_data == NULL) {
- return NULL;
- }
-
- return ctx;
+ return ldb_register_module(&proxy_ops);
}
diff --git a/source4/dsdb/samdb/ldb_modules/rootdse.c b/source4/dsdb/samdb/ldb_modules/rootdse.c
index 987fd7a7f1..69b1648040 100644
--- a/source4/dsdb/samdb/ldb_modules/rootdse.c
+++ b/source4/dsdb/samdb/ldb_modules/rootdse.c
@@ -199,34 +199,30 @@ static int rootdse_request(struct ldb_module *module, struct ldb_request *req)
return ldb_next_request(module, req);
}
-static const struct ldb_module_ops rootdse_ops = {
- .name = "rootdse",
- .request = rootdse_request
-};
-
-struct ldb_module *rootdse_module_init(struct ldb_context *ldb, const char *options[])
+static int rootdse_init(struct ldb_module *module)
{
- struct ldb_module *ctx;
struct private_data *data;
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx)
- return NULL;
-
- data = talloc(ctx, struct private_data);
+ data = talloc(module, struct private_data);
if (data == NULL) {
- talloc_free(ctx);
- return NULL;
+ return -1;
}
data->num_controls = 0;
data->controls = NULL;
- ctx->private_data = data;
+ module->private_data = data;
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &rootdse_ops;
+ return ldb_next_init(module);
+}
- return ctx;
+static const struct ldb_module_ops rootdse_ops = {
+ .name = "rootdse",
+ .init_context = rootdse_init,
+ .request = rootdse_request
+};
+
+int rootdse_module_init(void)
+{
+ return ldb_register_module(&rootdse_ops);
}
diff --git a/source4/dsdb/samdb/ldb_modules/samba3sam.c b/source4/dsdb/samdb/ldb_modules/samba3sam.c
index 3f593235fa..06774780a1 100644
--- a/source4/dsdb/samdb/ldb_modules/samba3sam.c
+++ b/source4/dsdb/samdb/ldb_modules/samba3sam.c
@@ -855,8 +855,8 @@ const struct ldb_map_attribute samba3_attributes[] =
}
};
- /* the init function */
-struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
+/* the init function */
+int ldb_samba3sam_module_init(void)
{
return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, "samba3sam");
}
diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c
index a582127bbe..3355df4e23 100644
--- a/source4/dsdb/samdb/ldb_modules/samldb.c
+++ b/source4/dsdb/samdb/ldb_modules/samldb.c
@@ -819,27 +819,20 @@ static int samldb_request(struct ldb_module *module, struct ldb_request *req)
}
}
+static int samldb_init(struct ldb_module *module)
+{
+ talloc_set_destructor(module, samldb_destructor);
+ return ldb_next_init(module);
+}
+
static const struct ldb_module_ops samldb_ops = {
.name = "samldb",
+ .init_context = samldb_init,
.request = samldb_request
};
-/* the init function */
-struct ldb_module *samldb_module_init(struct ldb_context *ldb, const char *options[])
+int samldb_module_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 = &samldb_ops;
-
- talloc_set_destructor(ctx, samldb_destructor);
-
- return ctx;
+ return ldb_register_module(&samldb_ops);
}
diff --git a/source4/ldap_server/ldap_server.c b/source4/ldap_server/ldap_server.c
index a9a4b06645..b919894d69 100644
--- a/source4/ldap_server/ldap_server.c
+++ b/source4/ldap_server/ldap_server.c
@@ -545,6 +545,8 @@ static void ldapsrv_task_init(struct task_server *task)
struct ldapsrv_service *ldap_service;
NTSTATUS status;
+ ldb_global_init();
+
ldap_service = talloc_zero(task, struct ldapsrv_service);
if (ldap_service == NULL) goto failed;
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);
diff --git a/source4/nbt_server/config.mk b/source4/nbt_server/config.mk
index 4d5f90e9fb..94c3e9efce 100644
--- a/source4/nbt_server/config.mk
+++ b/source4/nbt_server/config.mk
@@ -16,6 +16,7 @@ REQUIRED_SUBSYSTEMS = \
# Start MODULE libldb_wins_ldb
[MODULE::libldb_wins_ldb]
SUBSYSTEM = LIBLDB
+INIT_FUNCTION = wins_ldb_module_init
OUTPUT_TYPE = MERGEDOBJ
OBJ_FILES = \
wins/wins_ldb.o
diff --git a/source4/nbt_server/wins/wins_ldb.c b/source4/nbt_server/wins/wins_ldb.c
index d348c3231f..5efe6bd3ab 100644
--- a/source4/nbt_server/wins/wins_ldb.c
+++ b/source4/nbt_server/wins/wins_ldb.c
@@ -89,27 +89,12 @@ call_next:
return ldb_next_request(module, req);
}
-static const struct ldb_module_ops wins_ldb_ops = {
- .name = "wins_ldb",
- .request = wins_ldb_request
-};
-
-
-/* the init function */
-struct ldb_module *wins_ldb_module_init(struct ldb_context *ldb, const char *options[])
+static int wins_ldb_init(struct ldb_module *ctx)
{
- struct ldb_module *ctx;
struct winsdb_handle *h;
const char *owner;
- int ret;
-
- ctx = talloc(ldb, struct ldb_module);
- if (!ctx) return NULL;
ctx->private_data = NULL;
- ctx->ldb = ldb;
- ctx->prev = ctx->next = NULL;
- ctx->ops = &wins_ldb_ops;
owner = lp_parm_string(-1, "winsdb", "local_owner");
if (!owner) {
@@ -121,17 +106,27 @@ struct ldb_module *wins_ldb_module_init(struct ldb_context *ldb, const char *opt
h = talloc(ctx, struct winsdb_handle);
if (!h) goto failed;
- h->ldb = ldb;
+ h->ldb = ctx->ldb;
h->caller = WINSDB_HANDLE_CALLER_ADMIN;
h->local_owner = talloc_strdup(h, owner);
if (!h->local_owner) goto failed;
- ret = ldb_set_opaque(ldb, "winsdb_handle", h);
- if (ret != LDB_SUCCESS) goto failed;
-
- return ctx;
+ return ldb_set_opaque(ctx->ldb, "winsdb_handle", h);
failed:
- talloc_free(ctx);
- return NULL;
+ talloc_free(h);
+ return LDB_ERR_OTHER;
+}
+
+static const struct ldb_module_ops wins_ldb_ops = {
+ .name = "wins_ldb",
+ .request = wins_ldb_request,
+ .init_context = wins_ldb_init
+};
+
+
+/* the init function */
+int wins_ldb_module_init(void)
+{
+ return ldb_register_module(&wins_ldb_ops);
}
diff --git a/source4/nbt_server/wins/winsserver.c b/source4/nbt_server/wins/winsserver.c
index 7f67429996..62e152e05c 100644
--- a/source4/nbt_server/wins/winsserver.c
+++ b/source4/nbt_server/wins/winsserver.c
@@ -29,6 +29,7 @@
#include "libcli/composite/composite.h"
#include "smbd/service_task.h"
#include "lib/socket/socket.h"
+#include "lib/ldb/include/ldb.h"
/*
work out the ttl we will use given a client requested ttl
@@ -840,6 +841,8 @@ NTSTATUS nbtd_winsserver_init(struct nbtd_server *nbtsrv)
return NT_STATUS_OK;
}
+ ldb_global_init();
+
nbtsrv->winssrv = talloc_zero(nbtsrv, struct wins_server);
NT_STATUS_HAVE_NO_MEMORY(nbtsrv->winssrv);
diff --git a/source4/scripting/ejs/smbscript.c b/source4/scripting/ejs/smbscript.c
index 20675dadf9..d470d33a22 100644
--- a/source4/scripting/ejs/smbscript.c
+++ b/source4/scripting/ejs/smbscript.c
@@ -26,6 +26,7 @@
#include "lib/appweb/ejs/ejsInternal.h"
#include "scripting/ejs/smbcalls.h"
#include "auth/gensec/gensec.h"
+#include "ldb/include/ldb.h"
static EjsId eid;
@@ -37,7 +38,7 @@ void ejs_exception(const char *reason)
exit(127);
}
- int main(int argc, const char **argv)
+int main(int argc, const char **argv)
{
EjsHandle handle = 0;
MprVar result;
@@ -50,6 +51,9 @@ void ejs_exception(const char *reason)
int exit_status, i;
fault_setup(argv[0]);
+
+ ldb_global_init();
+
gensec_init();
mprSetCtx(mem_ctx);
diff --git a/source4/smbd/process_thread.c b/source4/smbd/process_thread.c
index 328658b939..10b7051356 100644
--- a/source4/smbd/process_thread.c
+++ b/source4/smbd/process_thread.c
@@ -35,7 +35,7 @@
#include "smb_server/smb_server.h"
#include "mutex.h"
-/* For sepecifiying event context to GSSAPI below */
+/* For specifying event context to GSSAPI below */
#include "system/kerberos.h"
#include "heimdal/lib/gssapi/gssapi_locl.h"