r26481: Make function for loading symbol from DSO more generic, and allow modules...
authorJelmer Vernooij <jelmer@samba.org>
Mon, 17 Dec 2007 02:35:59 +0000 (03:35 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2007 04:50:38 +0000 (05:50 +0100)
(This used to be commit a71419a73a869c24121005ccbbcb4396f888888b)

source4/lib/ldb/common/ldb.c
source4/lib/ldb/common/ldb_modules.c
source4/lib/ldb/include/ldb_private.h

index f687e152d30f800df2f8dfd5e993fba56158476e..87f791cb38795879f9283a03502083476b33e79f 100644 (file)
@@ -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);
                }
        }
index 877c28e8fdcc3c52c9a93de9b1e00cce9126c78c..72ed9692980064d909dbe77c3b7a3100bee2b856 100644 (file)
@@ -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", 
index f88c55664debac24ae51f24f624459ed567622da..d9f2defdc914931e3d12e0643ef7ec5b6faea8dc 100644 (file)
@@ -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);