summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2006-08-10 00:52:56 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:15:27 -0500
commit11685acd1d79591ed2b9d2656bee5a51442ced0f (patch)
tree4109d31d042377fe091b9eec6c6cae52de72932e /source4/lib/ldb
parent5104e4e83f7ff4864cc6085127d57e752d5050b0 (diff)
downloadsamba-11685acd1d79591ed2b9d2656bee5a51442ced0f.tar.gz
samba-11685acd1d79591ed2b9d2656bee5a51442ced0f.tar.bz2
samba-11685acd1d79591ed2b9d2656bee5a51442ced0f.zip
r17473: Split loading a list of modules and initialising them into a seperate
function. Andrew Bartlett (This used to be commit bed17cc579d82f04e44ce3c3d1e74d999c2ab867)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/common/ldb_modules.c100
1 files changed, 58 insertions, 42 deletions
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index b425796dfc..9eb0a950a4 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -236,11 +236,63 @@ int ldb_try_load_dso(struct ldb_context *ldb, const char *name)
#endif
}
+static int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out)
+{
+ struct ldb_module *module;
+ int i, ret;
+
+ module = backend;
+
+ for (i = 0; module_list[i] != NULL; i++) {
+ struct ldb_module *current;
+ const struct ldb_module_ops *ops;
+
+ ops = ldb_find_module_ops(module_list[i]);
+ if (ops == NULL) {
+ if (ldb_try_load_dso(ldb, module_list[i]) == 0) {
+ ops = ldb_find_module_ops(module_list[i]);
+ }
+ }
+
+ if (ops == NULL) {
+ ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n",
+ module_list[i]);
+ continue;
+ }
+
+ current = talloc_zero(ldb, struct ldb_module);
+ if (current == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ current->ldb = ldb;
+ current->ops = ops;
+
+ DLIST_ADD(module, current);
+ }
+ *out = module;
+ return LDB_SUCCESS;
+}
+
+static int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module)
+{
+ 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 LDB_ERR_OPERATIONS_ERROR;
+ }
+
+ return LDB_SUCCESS;
+}
+
int ldb_load_modules(struct ldb_context *ldb, const char *options[])
{
const char **modules = NULL;
- struct ldb_module *module;
int i;
+ int ret;
TALLOC_CTX *mem_ctx = talloc_new(ldb);
if (!mem_ctx) {
return LDB_ERR_OPERATIONS_ERROR;
@@ -259,7 +311,6 @@ 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 from ldb */
if ((modules == NULL) && (strcmp("ldap", ldb->modules->ops->name) != 0)) {
- int ret;
const char * const attrs[] = { "@LIST" , NULL};
struct ldb_result *res = NULL;
struct ldb_dn *mods_dn;
@@ -295,51 +346,16 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
if (modules != NULL) {
- for (i = 0; modules[i] != NULL; i++) {
- struct ldb_module *current;
- const struct ldb_module_ops *ops;
-
- ops = ldb_find_module_ops(modules[i]);
- if (ops == NULL) {
- if (ldb_try_load_dso(ldb, modules[i]) == 0) {
- 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);
- }
-
+ ret = ldb_load_modules_list(ldb, modules, ldb->modules, &ldb->modules);
talloc_free(modules);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
} else {
ldb_debug(ldb, LDB_DEBUG_TRACE, "No modules specified for this database\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;
- }
-
- return 0;
+ return ldb_init_module_chain(ldb, ldb->modules);
}
/*