r13786: [merge] Add registration functions for LDB modules
authorJelmer Vernooij <jelmer@samba.org>
Thu, 2 Mar 2006 16:32:53 +0000 (16:32 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:52:11 +0000 (13:52 -0500)
Applications that use LDB modules will now have to run ldb_global_init()
before they can use LDB.

The next step will be adding support for loading LDB modules from .so
files. This will also allow us to use one LDB without difference between the
standalone and the Samba-specific build

44 files changed:
source/build/smb_build/config_mk.pm
source/build/smb_build/header.pm
source/build/smb_build/input.pm
source/dsdb/samdb/ldb_modules/config.mk
source/dsdb/samdb/ldb_modules/extended_dn.c
source/dsdb/samdb/ldb_modules/kludge_acl.c
source/dsdb/samdb/ldb_modules/objectguid.c
source/dsdb/samdb/ldb_modules/password_hash.c
source/dsdb/samdb/ldb_modules/proxy.c
source/dsdb/samdb/ldb_modules/rootdse.c
source/dsdb/samdb/ldb_modules/samba3sam.c
source/dsdb/samdb/ldb_modules/samldb.c
source/ldap_server/ldap_server.c
source/lib/ldb/common/ldb.c
source/lib/ldb/common/ldb_modules.c
source/lib/ldb/config.mk
source/lib/ldb/include/includes.h
source/lib/ldb/include/ldb.h
source/lib/ldb/include/ldb_private.h
source/lib/ldb/ldb_ildap/ldb_ildap.c
source/lib/ldb/ldb_ldap/ldb_ldap.c
source/lib/ldb/ldb_tdb/ldb_tdb.c
source/lib/ldb/modules/asq.c
source/lib/ldb/modules/objectclass.c
source/lib/ldb/modules/operational.c
source/lib/ldb/modules/paged_results.c
source/lib/ldb/modules/rdn_name.c
source/lib/ldb/modules/schema.c
source/lib/ldb/modules/skel.c
source/lib/ldb/modules/sort.c
source/lib/ldb/tools/cmdline.c
source/lib/ldb/tools/ldbadd.c
source/lib/ldb/tools/ldbdel.c
source/lib/ldb/tools/ldbedit.c
source/lib/ldb/tools/ldbmodify.c
source/lib/ldb/tools/ldbrename.c
source/lib/ldb/tools/ldbsearch.c
source/lib/ldb/tools/ldbtest.c
source/lib/ldb/tools/oLschema2ldif.c
source/nbt_server/config.mk
source/nbt_server/wins/wins_ldb.c
source/nbt_server/wins/winsserver.c
source/scripting/ejs/smbscript.c
source/smbd/process_thread.c

index 1475ee09eea7f010eefe39527f31c9214befb317..c7ff8648ebe69ceebc553f528c3f693b7994faf6 100644 (file)
@@ -67,6 +67,8 @@ my $section_types = {
                "MAJOR_VERSION"         => "string",
                "MINOR_VERSION"         => "string",
                "RELEASE_VERSION"       => "string",
+               
+               "INIT_FUNCTION_TYPE" => "string",
 
                "OBJ_FILES"             => "list",
 
index 456c29368ad6bf1a0607b4688a122c9d8c5cb346..1cc5361b658d086ca164fde6202a2f09cba616dd 100644 (file)
@@ -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 }";
index c34930f39a0ba942c3759a6271a581664b98b562..fbeeddcda134706f33571c6d9c7d6389a075e358 100644 (file)
@@ -97,6 +97,10 @@ sub check_library($$$)
                return;
        }
 
+       unless (defined($lib->{INIT_FUNCTION_TYPE})) {
+               $lib->{INIT_FUNCTION_TYPE} = "NTSTATUS (*) (void)";
+       }
+
        $lib->{INSTALLDIR} = "LIBDIR";
 }
 
index c53c7c160699c8ffc5f8b0c767213c05831ba3fd..e14b9bfecf3fc0ebc4ce0131b2c02080e1718478 100644 (file)
@@ -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
index 9795758dc2ccab9e171041efb6e32597224e0def..5b288aa311570e0bbf35e6cc5b6b822285046cb0 100644 (file)
@@ -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);
 }
index 9ce32171042a9b4b6d6bfc2251e812a361e27184..4c680df3e6132256b2fae894854e09d7ca43e935 100644 (file)
@@ -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);
 }
index c9063af6ef950f5b2ed193be65d2990276d5a1b8..7169aa684213be5f348f06fbea0c70df844daf72 100644 (file)
@@ -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);
 }
index e28c85ae37d80501ed5076a32062f08f9a8c2fcf..414f79ea10f37c47af4a1982380c006f3e7c027b 100644 (file)
@@ -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);
 }
index 511f9aeec587c9eecda88bbf36a9b6fe6a7c21f0..85b40b62d1c096bd3bb78ef333b1ca9c47408cc5 100644 (file)
@@ -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);
 }
index 987fd7a7f1c6444dbdf4680b58a426a4e3d23886..69b1648040ab098821380b06a388b394cfb23065 100644 (file)
@@ -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);
 }
 
index 3f593235faaec160329e1c26638402b75f2f8698..06774780a154e054a8bd4309180798acd4d2c7c0 100644 (file)
@@ -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");
 }
index a582127bbeab2f552ccc03bbb697923355192b2b..3355df4e23c1742d6eae536cd1cd7fedc36a056f 100644 (file)
@@ -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);
 }
index a9a4b06645a8d56ad210d841ee9b8ea3840fb214..b919894d692051aa6dc874ae52c602c99e25ddee 100644 (file)
@@ -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;
 
index 87705a855a0970be3ef824996ed409a5bd86e71d..28bed0b0ea6ee06ac7e635e07c67f6cdc7f31a9a 100644 (file)
@@ -128,19 +128,6 @@ void ldb_reset_err_string(struct ldb_context *ldb)
        if (module == NULL) return -1; \
 } 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
 */
index 922506ea4d6e2bc9abc564c2a162f425060ca9e5..f1b4783fcaec105055ff676651f43c6cf02731e2 100644 (file)
@@ -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)
index 16f4001acd0ada796d435f7dd8da42338a3e6c60..82b98fa123f51db55926bee2510123f73b2dc231 100644 (file)
@@ -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 \
index 15eb18a5e802581791adaca68fffd0efdead56ee..b10f329a2d63bff6fe7f4449ea4959956c211a57 100644 (file)
@@ -10,6 +10,8 @@
 #include "system/iconv.h"
 #include "system/time.h"
 
+#include "build.h"
+
 #else /*_SAMBA_BUILD_*/
 
 #ifndef _GNU_SOURCE
index f5bca965adc82b46a679f47aa2d4f22272630e8a..13e69282cada252fc6d5765c90f1000463bfc0d5 100644 (file)
@@ -665,6 +665,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
 
index 3f9be357a772f17490f7d345da4debe56e24d43e..d4cba9797c4671eeeaa024106cd2065fa9f374c1 100644 (file)
@@ -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,
index a5f4ab67fd8b7e955e147036a15ecfd80a9e9efc..69053cc1100c7fccc531be416733dc890c46554a 100644 (file)
@@ -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
 };
 
 /*
index 167bbfbd63fb38065c4e60e9dc7a39ac731aad0e..4f840868a18723a5a72bf357cde1a2e387a52b54 100644 (file)
@@ -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
 };
 
 
index b58b03f221f366ac8bd2e19d7315b526df6a04bb..7cf6138b1298edbc32385502f17ff73b293324ce 100644 (file)
@@ -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
 };
 
 
index 2975f4d832d464517cb26554a9e8416257e25101..33ba9bed0481c21cac40db4ee9149b791ecfff8a 100644 (file)
@@ -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);
 }
index 8b4ad598cc53786b6fb972e0819010d97f149f12..a9c51341a8c4617e9705bab36291bb4eb66fe103 100644 (file)
@@ -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);
 }
index 51f0ce25e47f2723ad710a63fabe5d7584a9ebcd..441c899a586e87e84a439cd5f5f5b92fdfd5cd8d 100644 (file)
@@ -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);
 }
index c4aad4500efaa469808a646cd593c940102e7725..9d6a50e27f0c46f4cd0b7f7434b274007cc09b28 100644 (file)
@@ -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);
 }
+
index 2e4e2507555b1045c39831dcaa69f263e11d57de..59930046cef5ed32d2c174660a16b399064a2b37 100644 (file)
@@ -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);
 }
index 9bf9a4d2c5b6bf91639e810fca23020a3bbd491f..73b07023da5f1fed7ed657a06870e8cec7a05b49 100644 (file)
@@ -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);
 }
index e9b76be2babb7af857e2c1c43e53f665d45aa48c..0089433b37a44bb9ecb3bcb898a4effed5835017 100644 (file)
@@ -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);
 }
index ac9f1081de0fc9c94b2439fb4b44ed1f7f6b3159..d01e468956d4f444aaa2b6b1ff0008076eb741fe 100644 (file)
@@ -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);
 }
index a67c41e67f7522f56233fa9b2a1b36923cfe3d51..8f803c51189b9c54042b66e65017d71d8b9fbda8 100644 (file)
@@ -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) {
index 0d5acd3787292d68e51935022dba27b0dee6d4f6..6a0f51024465e8f430622d35a185ed663bc9d181 100644 (file)
@@ -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);
index 26544d8a9eb7beb3e5dfcf2a9a43bf382ecec4aa..749ce3f91c254c8d7b8bc217211ac3c24e72fb24 100644 (file)
@@ -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);
index 9cef81f1db3c2397485d2f87ce9b51d4de757aac..b4e2b0a8480da5324394c9a2457b2dd31bb77279 100644 (file)
@@ -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);
index e785a42a234ece2f1a4c5a29ddbf732e2eccc658..4ce49c2ce8136e503f2f7237a966005194c986c0 100644 (file)
@@ -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);
index 9c3774427765b64cde87f2d3d3e162e93a34fecb..3229426875774a688da3fea3f1fc2b8575814fb5 100644 (file)
@@ -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);
index c380862c5d6da3cd3b0199e98d355d66bc8b97b3..fbf32c0777a9a826d36b80f4e7d3891316f13776 100644 (file)
@@ -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);
index 69362d0f20134194fc47aea6f87e5a4ba07d0154..5fd75a0cab4c4eb4b23870fb59bd9e8bd47d8b20 100644 (file)
@@ -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);
index b4fe4211617c7b0fbb359bb788d1bfbb718d55cd..288cf4c3c3ece7d5e95c6648cb3e96554e312111 100644 (file)
@@ -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);
 
index 4d5f90e9fbabc394473bfa236d4c859e3f4fcea8..94c3e9efce193e3c860efb6caf8bc0a77ec707bb 100644 (file)
@@ -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
index d348c3231faa55004bab9d33e037598049b7cd18..5efe6bd3abd339e71d8803f1fa505405599c1faf 100644 (file)
@@ -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);
 }
index 7f674299966b37f36e95f5ea4a8edc4d7ad2a092..62e152e05cbe1356279adf78bce0a2997633edb7 100644 (file)
@@ -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);
 
index 20675dadf907f879b634c018f1e48d3d9d2d726e..d470d33a223a4554723993d38604b6236ea34032 100644 (file)
@@ -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);
 
index 328658b939acee5292dcd52c81db5b998790cabe..10b7051356f19b41b4336e788cb32c7b8e8acba1 100644 (file)
@@ -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"