summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2006-03-05 16:05:26 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:52:14 -0500
commit5d0aa16dfcf3047a52d3dd7e12ffb704a9725e83 (patch)
tree8a9ae36a29652dec9dbb5138ba3c0dee86b8e32d /source4/lib/ldb/common
parent8edf29e8ef4d886321a6e8ec3902065641d34f40 (diff)
downloadsamba-5d0aa16dfcf3047a52d3dd7e12ffb704a9725e83.tar.gz
samba-5d0aa16dfcf3047a52d3dd7e12ffb704a9725e83.tar.bz2
samba-5d0aa16dfcf3047a52d3dd7e12ffb704a9725e83.zip
r13839: Use registration mechanism for backends as well (in the same sense
my previous patch added it for modules). This is the next step towards LDB backends and modules as run-time loadable .so files. (This used to be commit fb2f70de4f6c4a9b13ad590cb4d3a9c858cede49)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c61
-rw-r--r--source4/lib/ldb/common/ldb_modules.c16
2 files changed, 58 insertions, 19 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 9d8783324c..b664ba680d 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -55,6 +55,40 @@ struct ldb_context *ldb_init(void *mem_ctx)
return ldb;
}
+static struct ldb_backend {
+ const char *name;
+ ldb_connect_fn connect_fn;
+ struct ldb_backend *prev, *next;
+} *ldb_backends = NULL;
+/*
+ register a new ldb backend
+*/
+int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
+{
+ struct ldb_backend *backend = talloc(talloc_autofree_context(), struct ldb_backend);
+
+ /* Maybe check for duplicity here later on? */
+
+ backend->name = talloc_strdup(backend, url_prefix);
+ backend->connect_fn = connectfn;
+ DLIST_ADD(ldb_backends, backend);
+
+ return LDB_SUCCESS;
+}
+
+static ldb_connect_fn ldb_find_backend(const char *url)
+{
+ struct ldb_backend *backend;
+
+ for (backend = ldb_backends; backend; backend = backend->next) {
+ if (strncmp(backend->name, url, strlen(backend->name)) == 0) {
+ return backend->connect_fn;
+ }
+ }
+
+ return NULL;
+}
+
/*
connect to a database. The URL can either be one of the following forms
ldb://path
@@ -68,31 +102,22 @@ struct ldb_context *ldb_init(void *mem_ctx)
int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[])
{
int ret;
+ ldb_connect_fn fn;
- if (strncmp(url, "tdb:", 4) == 0 ||
- strchr(url, ':') == NULL) {
- ret = ltdb_connect(ldb, url, flags, options);
+ if (strchr(url, ':') != NULL) {
+ fn = ldb_find_backend(url);
+ } else {
+ /* Default to tdb */
+ fn = ldb_find_backend("tdb:");
}
-#if HAVE_ILDAP
- else if (strncmp(url, "ldap", 4) == 0) {
- ret = ildb_connect(ldb, url, flags, options);
- }
-#elif HAVE_LDAP
- else if (strncmp(url, "ldap", 4) == 0) {
- ret = lldb_connect(ldb, url, flags, options);
- }
-#endif
-#if HAVE_SQLITE3
- else if (strncmp(url, "sqlite:", 7) == 0) {
- ret = lsqlite3_connect(ldb, url, flags, options);
- }
-#endif
- else {
+ if (fn == NULL) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to find backend for '%s'\n", url);
return LDB_ERR_OTHER;
}
+ ret = fn(ldb, url, flags, options);
+
if (ret != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to '%s'\n", url);
return ret;
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 17c5231e54..53394e7047 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -126,10 +126,24 @@ static const struct ldb_module_ops *ldb_find_module_ops(const char *name)
return NULL;
}
-
+#ifdef HAVE_LDAP
+#define LDAP_INIT ldb_ldap_init,
+#else
+#define LDAP_INIT
+#endif
+
+#ifdef HAVE_SQLITE3
+#define SQLITE3_INIT ldb_sqlite3_init,
+#else
+#define SQLITE3_INIT
+#endif
+
#ifndef STATIC_LIBLDB_MODULES
#define STATIC_LIBLDB_MODULES \
{ \
+ LDAP_INIT \
+ SQLITE3_INIT \
+ ldb_tdb_init, \
ldb_schema_init, \
ldb_operational_init, \
ldb_rdn_name_init, \