summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-02-25 12:58:09 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-02-25 12:58:09 +0100
commit584c4a518f4d18452b6515db132e4f75fba733a1 (patch)
treebbe367f36f092f233d7aefb61d75d5d1e1e85031 /source4/lib/ldb/common
parent03ab8f9d79f2a06b357b2f5d392ea8b5be263c5e (diff)
parent71943b209b181e1e4a65ab477b83780add7051ae (diff)
downloadsamba-584c4a518f4d18452b6515db132e4f75fba733a1.tar.gz
samba-584c4a518f4d18452b6515db132e4f75fba733a1.tar.bz2
samba-584c4a518f4d18452b6515db132e4f75fba733a1.zip
Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-gmake3
Conflicts: source/build/smb_build/header.pm source/build/smb_build/makefile.pm source/lib/ldb/include/ldb_private.h (This used to be commit 1a646af0647f021d99473a8991c35e616a423ea6)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c73
-rw-r--r--source4/lib/ldb/common/ldb_modules.c75
2 files changed, 90 insertions, 58 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 87f791cb38..3c9ef3ff69 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;
}
@@ -135,6 +168,19 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op
}
}
+ if (fn == NULL) {
+ 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;
+ }
+ ops = ldb_dso_load_symbol(ldb, backend, symbol_name);
+ if (ops != NULL) {
+ fn = ops->connect_fn;
+ }
+ talloc_free(symbol_name);
+ }
+
talloc_free(backend);
if (fn == NULL) {
@@ -236,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;
@@ -463,11 +508,17 @@ static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_reque
int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type)
{
+ int ret;
if (!handle) {
return LDB_SUCCESS;
}
- return handle->module->ops->wait(handle, type);
+ ret = handle->module->ops->wait(handle, type);
+ if (!ldb_errstring(handle->module->ldb)) {
+ /* Set a default error string, to place the blame somewhere */
+ ldb_asprintf_errstring(handle->module->ldb, "error waiting on module %s: %s (%d)", handle->module->ops->name, ldb_strerror(ret), ret);
+ }
+ return ret;
}
/* set the specified timeout or, if timeout is 0 set the default timeout */
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index a3bf71d0d8..a4e0b94188 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -125,9 +125,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)
@@ -137,51 +158,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)
{
@@ -256,8 +232,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) {