summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/common/ldb.c6
-rw-r--r--source4/lib/ldb/common/ldb_modules.c30
-rw-r--r--source4/lib/ldb/include/ldb_private.h3
3 files changed, 27 insertions, 12 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",
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index f88c55664d..d9f2defdc9 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -159,7 +159,8 @@ void ldb_reset_err_string(struct ldb_context *ldb);
int ldb_register_module(const struct ldb_module_ops *);
int ldb_register_backend(const char *url_prefix, ldb_connect_fn);
-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);
/* The following definitions come from lib/ldb/common/ldb_debug.c */
void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);