From bb1909e15e7a9f3cd79da2ce8b8ef90f1a557376 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Mar 2006 21:44:59 +0000 Subject: r14592: Add support for loading shared modules to LDB. (This used to be commit f10fae23f0685b2d9c6174596e1c66d799f02c52) --- source4/lib/ldb/common/ldb.c | 15 ++++++++++++-- source4/lib/ldb/common/ldb_modules.c | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/common') diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 9acf74535b..0d424ad601 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -102,15 +102,26 @@ static ldb_connect_fn ldb_find_backend(const char *url) int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]) { int ret; + char *backend; ldb_connect_fn fn; if (strchr(url, ':') != NULL) { - fn = ldb_find_backend(url); + backend = talloc_strndup(ldb, url, strchr(url, ':')-url); } else { /* Default to tdb */ - fn = ldb_find_backend("tdb:"); + backend = talloc_strdup(ldb, "tdb"); } + fn = ldb_find_backend(backend); + + if (fn == NULL) { + if (ldb_try_load_dso(ldb, backend) == 0) { + fn = ldb_find_backend(backend); + } + } + + talloc_free(backend); + if (fn == NULL) { ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to find backend for '%s'\n", url); return LDB_ERR_OTHER; diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 0cb0041d84..6ba5fbbc20 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -195,6 +195,39 @@ int ldb_register_module(const struct ldb_module_ops *ops) return 0; } +int ldb_try_load_dso(struct ldb_context *ldb, const char *name) +{ + char *path; + void *handle; + int (*init_fn) (void); + +#ifdef HAVE_DLOPEN + path = talloc_asprintf(ldb, "%s/%s.%s", MODULESDIR, name, SHLIBEXT); + + ldb_debug(ldb, LDB_DEBUG_TRACE, "trying to load %s from %s\n", name, path); + + handle = dlopen(path, 0); + if (handle == NULL) { + ldb_debug(ldb, LDB_DEBUG_WARNING, "unable to load %s from %s: %s\n", name, path, dlerror()); + return -1; + } + + init_fn = dlsym(handle, "init_module"); + + if (init_fn == NULL) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `init_module' found in %s: %s\n", path, dlerror()); + return -1; + } + + talloc_free(path); + + return init_fn(); +#else + ldb_debug(ldb, LDB_DEBUG_TRACE, "no dlopen() - not trying to load %s module\n", name); + return -1; +#endif +} + int ldb_load_modules(struct ldb_context *ldb, const char *options[]) { char **modules = NULL; @@ -252,6 +285,12 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) 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]); -- cgit