From 71bc5acead0e16473273eb8741373e865b6d2c44 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 01:37:53 +0100 Subject: Allow ldb backends without init function, use init function-less ldb modules. (This used to be commit 141ee91272fb4dafca0149f679e17721b6a3011e) --- source4/lib/ldb/common/ldb.c | 9 +++++++++ source4/lib/ldb/common/ldb_modules.c | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/common') diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 87f791cb38..ffda705a0b 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -135,6 +135,15 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op } } + if (fn == NULL) { + char *symbol_name = talloc_asprintf(ldb, "ldb_%s_connect", backend); + if (symbol_name == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + fn = ldb_dso_load_symbol(ldb, backend, symbol_name); + talloc_free(symbol_name); + } + talloc_free(backend); if (fn == NULL) { diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 18070bdb86..2dae40ddb0 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -257,8 +257,13 @@ int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, str } if (ops == NULL) { - ops = ldb_dso_load_symbol(ldb, module_list[i], - "ldb_module_ops"); + char *symbol_name = talloc_asprintf(ldb, "ldb_%s_module_ops", + module_list[i]); + if (symbol_name == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + ops = ldb_dso_load_symbol(ldb, module_list[i], symbol_name); + talloc_free(symbol_name); } if (ops == NULL) { -- cgit From 995788536e5ba7b3a0e67e377a9769b279d0b8ae Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 02:57:07 +0100 Subject: Remove more function-based inits. (This used to be commit b1a7810f3e70f9a831d9b8e85d531e448072adaf) --- source4/lib/ldb/common/ldb.c | 59 ++++++++++++++++++++++++++------ source4/lib/ldb/common/ldb_modules.c | 66 ++++++++++++------------------------ 2 files changed, 69 insertions(+), 56 deletions(-) (limited to 'source4/lib/ldb/common') diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index ffda705a0b..ce69256c69 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -56,20 +56,51 @@ struct ldb_context *ldb_init(void *mem_ctx) return ldb; } -struct ldb_backend { - const char *name; - ldb_connect_fn connect_fn; - struct ldb_backend *prev, *next; +static struct backends_list_entry { + struct ldb_backend_ops *ops; + struct backends_list_entry *prev, *next; } *ldb_backends = NULL; +#ifndef STATIC_LIBLDB_BACKENDS + +#ifdef HAVE_LDB_LDAP +#define LDAP_INIT &ldb_ldap_backend_ops, \ + &ldb_ildap_backend_ops, \ + &ldb_ldaps_backend_ops, +#else +#define LDAP_INIT +#endif + +#ifdef HAVE_LDB_SQLITE3 +#define SQLITE3_INIT &ldb_sqlite3_backend_ops, +#else +#define SQLITE3_INIT +#endif + +#define STATIC_LIBLDB_BACKENDS \ + LDAP_INIT \ + SQLITE3_INIT \ + &ldb_tdb_backend_ops, \ + NULL +#endif + +const static struct ldb_backend_ops *builtin_backends[] = { + STATIC_LIBLDB_BACKENDS +}; static ldb_connect_fn ldb_find_backend(const char *url) { - struct ldb_backend *backend; + struct backends_list_entry *backend; + int i; + + for (i = 0; builtin_backends[i]; i++) { + if (strncmp(builtin_backends[i]->name, url, strlen(builtin_backends[i]->name)) == 0) + return builtin_backends[i]->connect_fn; + } for (backend = ldb_backends; backend; backend = backend->next) { - if (strncmp(backend->name, url, strlen(backend->name)) == 0) { - return backend->connect_fn; + if (strncmp(backend->ops->name, url, strlen(backend->ops->name)) == 0) { + return backend->ops->connect_fn; } } @@ -81,7 +112,8 @@ static ldb_connect_fn ldb_find_backend(const char *url) */ int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn) { - struct ldb_backend *backend = talloc(talloc_autofree_context(), struct ldb_backend); + struct ldb_backend_ops *backend = talloc(talloc_autofree_context(), struct ldb_backend_ops); + struct backends_list_entry *entry = talloc(talloc_autofree_context(), struct backends_list_entry); if (ldb_find_backend(url_prefix)) { return LDB_SUCCESS; @@ -91,7 +123,8 @@ int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn) backend->name = talloc_strdup(backend, url_prefix); backend->connect_fn = connectfn; - DLIST_ADD(ldb_backends, backend); + entry->ops = backend; + DLIST_ADD(ldb_backends, entry); return LDB_SUCCESS; } @@ -136,11 +169,15 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op } if (fn == NULL) { - char *symbol_name = talloc_asprintf(ldb, "ldb_%s_connect", backend); + struct ldb_backend_ops *ops; + char *symbol_name = talloc_asprintf(ldb, "ldb_%s_backend_ops", backend); if (symbol_name == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - fn = ldb_dso_load_symbol(ldb, backend, symbol_name); + ops = ldb_dso_load_symbol(ldb, backend, symbol_name); + if (ops != NULL) { + fn = ops->connect_fn; + } talloc_free(symbol_name); } diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 2dae40ddb0..7da7b9ba34 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -126,9 +126,30 @@ static struct ops_list_entry { struct ops_list_entry *next; } *registered_modules = NULL; +#ifndef STATIC_LIBLDB_MODULES + +#define STATIC_LIBLDB_MODULES \ + ldb_operational_module_ops, \ + ldb_rdn_name_module_ops, \ + ldb_paged_results_module_ops, \ + ldb_sort_module_ops, \ + ldb_asq_module_ops, \ + NULL +#endif + +const static struct ldb_module_ops *builtin_modules[] = { + STATIC_LIBLDB_MODULES +}; + static const struct ldb_module_ops *ldb_find_module_ops(const char *name) { struct ops_list_entry *e; + int i; + + for (i = 0; builtin_modules[i]; i++) { + if (strcmp(builtin_modules[i]->name, name) == 0) + return builtin_modules[i]; + } for (e = registered_modules; e; e = e->next) { if (strcmp(e->ops->name, name) == 0) @@ -138,51 +159,6 @@ static const struct ldb_module_ops *ldb_find_module_ops(const char *name) return NULL; } -#ifndef STATIC_LIBLDB_MODULES - -#ifdef HAVE_LDB_LDAP -#define LDAP_INIT ldb_ldap_init, -#else -#define LDAP_INIT -#endif - -#ifdef HAVE_LDB_SQLITE3 -#define SQLITE3_INIT ldb_sqlite3_init, -#else -#define SQLITE3_INIT -#endif - -#define STATIC_LIBLDB_MODULES \ - LDAP_INIT \ - SQLITE3_INIT \ - ldb_tdb_init, \ - ldb_operational_init, \ - ldb_rdn_name_init, \ - ldb_paged_results_init, \ - ldb_sort_init, \ - ldb_asq_init, \ - NULL -#endif - -int ldb_global_init(void) -{ - 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) { -- cgit From 0020793515ade04f3ef5754717490e2eb2ca6bb9 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 03:40:44 +0100 Subject: Fix static module list generation for ldb. (This used to be commit 92c1c0e9137f0845cac6cc96bf78711b6aaffe21) --- source4/lib/ldb/common/ldb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/common') diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index ce69256c69..5f2e5e3ffc 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -282,7 +282,6 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co int ret; const char *url2; /* We seem to need to do this here, or else some utilities don't get ldb backends */ - ldb_global_init(); ldb->flags = flags; -- cgit