svn commit: samba r17473 - in
branches/SAMBA_4_0/source/lib/ldb/common: .
abartlet at samba.org
abartlet at samba.org
Thu Aug 10 00:52:57 GMT 2006
Author: abartlet
Date: 2006-08-10 00:52:56 +0000 (Thu, 10 Aug 2006)
New Revision: 17473
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=17473
Log:
Split loading a list of modules and initialising them into a seperate
function.
Andrew Bartlett
Modified:
branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c
Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c 2006-08-09 22:10:26 UTC (rev 17472)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_modules.c 2006-08-10 00:52:56 UTC (rev 17473)
@@ -236,11 +236,63 @@
#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 @@
/* 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 @@
}
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;
}
-
- talloc_free(modules);
} 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);
}
/*
More information about the samba-cvs
mailing list