summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-12-17 03:35:59 +0100
committerStefan Metzmacher <metze@samba.org>2007-12-21 05:50:38 +0100
commitcb62bbbb7c2ee542a3a5f978ed25e501825a44d7 (patch)
tree3442b8c96280e85aa8c2b37cf922c55c699471a5 /source4/lib/ldb/common
parent07beaf09c95a06636cb029fcc2dbbeb7293879ba (diff)
downloadsamba-cb62bbbb7c2ee542a3a5f978ed25e501825a44d7.tar.gz
samba-cb62bbbb7c2ee542a3a5f978ed25e501825a44d7.tar.bz2
samba-cb62bbbb7c2ee542a3a5f978ed25e501825a44d7.zip
r26481: Make function for loading symbol from DSO more generic, and allow modules to provide an ops table directly rather than an initialization function.
(This used to be commit a71419a73a869c24121005ccbbcb4396f888888b)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c6
-rw-r--r--source4/lib/ldb/common/ldb_modules.c30
2 files changed, 25 insertions, 11 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index f687e152d3..87f791cb38 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -126,7 +126,11 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op
fn = ldb_find_backend(backend);
if (fn == NULL) {
- if (ldb_try_load_dso(ldb, backend) == 0) {
+ int (*init_fn) (void);
+
+ init_fn = ldb_dso_load_symbol(ldb, backend,
+ "init_module");
+ if (init_fn != NULL && init_fn() == 0) {
fn = ldb_find_backend(backend);
}
}
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 877c28e8fd..72ed969298 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -203,14 +203,15 @@ int ldb_register_module(const struct ldb_module_ops *ops)
return 0;
}
-int ldb_try_load_dso(struct ldb_context *ldb, const char *name)
+void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name,
+ const char *symbol)
{
char *path;
void *handle;
- int (*init_fn) (void);
+ void *sym;
if (ldb->modules_dir == NULL)
- return -1;
+ return NULL;
path = talloc_asprintf(ldb, "%s/%s.%s", ldb->modules_dir, name,
SHLIBEXT);
@@ -220,19 +221,19 @@ int ldb_try_load_dso(struct ldb_context *ldb, const char *name)
handle = dlopen(path, RTLD_NOW);
if (handle == NULL) {
ldb_debug(ldb, LDB_DEBUG_WARNING, "unable to load %s from %s: %s\n", name, path, dlerror());
- return -1;
+ return NULL;
}
- init_fn = (int (*)(void))dlsym(handle, "init_module");
+ sym = (int (*)(void))dlsym(handle, symbol);
- if (init_fn == NULL) {
- ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `init_module' found in %s: %s\n", path, dlerror());
- return -1;
+ if (sym == NULL) {
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `%s' found in %s: %s\n", symbol, path, dlerror());
+ return NULL;
}
talloc_free(path);
- return init_fn();
+ return sym;
}
int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out)
@@ -248,10 +249,19 @@ int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, str
ops = ldb_find_module_ops(module_list[i]);
if (ops == NULL) {
- if (ldb_try_load_dso(ldb, module_list[i]) == 0) {
+ int (*init_fn) (void);
+
+ init_fn = ldb_dso_load_symbol(ldb, module_list[i],
+ "init_module");
+ if (init_fn != NULL && init_fn() == 0) {
ops = ldb_find_module_ops(module_list[i]);
}
}
+
+ if (ops == NULL) {
+ ops = ldb_dso_load_symbol(ldb, module_list[i],
+ "ldb_module_ops");
+ }
if (ops == NULL) {
ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n",