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.c15
-rw-r--r--source4/lib/ldb/common/ldb_modules.c39
-rw-r--r--source4/lib/ldb/config.mk1
-rw-r--r--source4/lib/ldb/configure.in10
-rw-r--r--source4/lib/ldb/include/includes.h3
-rw-r--r--source4/lib/ldb/include/ldb_private.h1
-rw-r--r--source4/lib/ldb/ldb.pc.in2
-rw-r--r--source4/lib/ldb/ldb_ildap/ldb_ildap.c4
-rw-r--r--source4/lib/ldb/ldb_ldap/ldb_ldap.c4
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c2
10 files changed, 75 insertions, 6 deletions
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;
@@ -253,6 +286,12 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
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;
diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk
index 661c31d027..20d1437288 100644
--- a/source4/lib/ldb/config.mk
+++ b/source4/lib/ldb/config.mk
@@ -132,6 +132,7 @@ REQUIRED_SUBSYSTEMS = \
VERSION = 0.0.1
SO_VERSION = 0
DESCRIPTION = LDAP-like embedded database library
+EXTRA_CFLAGS = -DMODULESDIR="$(MODULESDIR)/ldb" -DSHLIBEXT="$(SHLIBEXT)"
INIT_FUNCTION_TYPE = int (*) (void)
OBJ_FILES = \
common/ldb.o \
diff --git a/source4/lib/ldb/configure.in b/source4/lib/ldb/configure.in
index 385c0caef0..54ec24df4d 100644
--- a/source4/lib/ldb/configure.in
+++ b/source4/lib/ldb/configure.in
@@ -23,8 +23,16 @@ AC_FUNC_MMAP
AC_PATH_PROG(XSLTPROC,xsltproc)
AC_PATH_PROG(DOXYGEN,doxygen)
AC_PATH_PROG(GCOV,gcov)
-AC_CHECK_HEADERS(stdint.h)
+AC_CHECK_HEADERS(stdint.h dlfcn.h)
AC_CONFIG_HEADER(include/config.h)
+AC_CHECK_FUNCS(dlopen dlsym dlclose)
+
+SHLIBEXT="so" # Should be set based on OS later on
+AC_SUBST(SHLIBEXT)
+
+MODULESDIR="$libdir/ldb"
+AC_DEFINE(MODULESDIR,$MODULESDIR,[Modules directory])
+AC_SUBST(MODULESDIR)
AC_CHECK_LIB(popt, poptGetContext)
diff --git a/source4/lib/ldb/include/includes.h b/source4/lib/ldb/include/includes.h
index c85ffadb6d..26309df381 100644
--- a/source4/lib/ldb/include/includes.h
+++ b/source4/lib/ldb/include/includes.h
@@ -34,6 +34,9 @@
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index 27b6883c3d..0ea6c4e9de 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -135,6 +135,7 @@ 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);
/* 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);
diff --git a/source4/lib/ldb/ldb.pc.in b/source4/lib/ldb/ldb.pc.in
index e524fbed36..8b0536e21e 100644
--- a/source4/lib/ldb/ldb.pc.in
+++ b/source4/lib/ldb/ldb.pc.in
@@ -2,9 +2,11 @@ prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
+modulesdir=@modulesdir@
Name: ldb
Description: An LDAP-like embedded database
Version: 4.0
Libs: @LIBS@ -L${libdir} -lldb
Cflags: -I${includedir} @CFLAGS@
+Modulesdir: ${modulesdir}
diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
index 2b43193864..3c6101bb1a 100644
--- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c
+++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
@@ -1069,5 +1069,7 @@ failed:
int ldb_ildap_init(void)
{
- return ldb_register_backend("ldap", ildb_connect);
+ return ldb_register_backend("ldap", ildb_connect) +
+ ldb_register_backend("ldapi", ildb_connect) +
+ ldb_register_backend("ldaps", ildb_connect);
}
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index 49de229a1e..8bfff117da 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -1105,5 +1105,7 @@ failed:
int ldb_ldap_init(void)
{
- return ldb_register_backend("ldap", lldb_connect);
+ return ldb_register_backend("ldap", lldb_connect) +
+ ldb_register_backend("ldapi", lldb_connect) +
+ ldb_register_backend("ldaps", lldb_connect);
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index bc936eb71e..3a1a08aafd 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -1102,5 +1102,5 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
int ldb_tdb_init(void)
{
- return ldb_register_backend("tdb:", ltdb_connect);
+ return ldb_register_backend("tdb", ltdb_connect);
}