summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-11-01 16:42:21 +1100
committerAndrew Tridgell <tridge@samba.org>2010-11-01 18:55:19 +1100
commitc74601e0b333f81570dfca6959e047d83e6ab32c (patch)
tree9571b44470dd9dc1cfe311fcac8c216bd513a70b
parent05b37385fcfc67f4203b2a4822f94813d11511ca (diff)
downloadsamba-c74601e0b333f81570dfca6959e047d83e6ab32c.tar.gz
samba-c74601e0b333f81570dfca6959e047d83e6ab32c.tar.bz2
samba-c74601e0b333f81570dfca6959e047d83e6ab32c.zip
s4-ldb: added an override flag to ldb_register_backend()
this will be used to allow a system ldb build with an ldb backend to have its ldap handler overridden by the s4 one
-rw-r--r--source4/lib/ldb/common/ldb_modules.c57
-rw-r--r--source4/lib/ldb/ldb_ildap/ldb_ildap.c2
-rw-r--r--source4/lib/ldb/ldb_ldap/ldb_ldap.c2
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c2
4 files changed, 33 insertions, 30 deletions
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 6c0cbfcb00..4590842d8f 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -131,14 +131,14 @@ static struct ops_list_entry {
struct ops_list_entry *next;
} *registered_modules = NULL;
-static ldb_connect_fn ldb_find_backend(const char *url)
+static backends_list_entry *ldb_find_backend(const char *url)
{
struct backends_list_entry *backend;
for (backend = ldb_backends; backend; backend = backend->next) {
if (strncmp(backend->ops->name, url,
strlen(backend->ops->name)) == 0) {
- return backend->ops->connect_fn;
+ return backend;
}
}
@@ -146,32 +146,35 @@ static ldb_connect_fn ldb_find_backend(const char *url)
}
/*
- register a new ldb backend
+ register a new ldb backend
+
+ if override is true, then override any existing backend for this prefix
*/
-int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
+int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn, bool override)
{
struct ldb_backend_ops *backend;
- struct backends_list_entry *entry;
-
- backend = talloc(talloc_autofree_context(), struct ldb_backend_ops);
- if (!backend) return LDB_ERR_OPERATIONS_ERROR;
+ struct backends_list_entry *be;
- entry = talloc(talloc_autofree_context(), struct backends_list_entry);
- if (!entry) {
- talloc_free(backend);
- return LDB_ERR_OPERATIONS_ERROR;
- }
-
- if (ldb_find_backend(url_prefix)) {
- return LDB_SUCCESS;
+ be = ldb_find_backend(url_prefix);
+ if (be) {
+ if (!override) {
+ return LDB_SUCCESS;
+ }
+ } else {
+ be = talloc(ldb_backends, struct backends_list_entry);
+ if (!be) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ be->ops = talloc(be, struct ldb_backend_ops);
+ if (!backend) {
+ talloc_free(be);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ DLIST_ADD_END(ldb_backends, entry, struct backends_list_entry);
}
- /* Maybe check for duplicity here later on? */
-
- backend->name = talloc_strdup(backend, url_prefix);
- backend->connect_fn = connectfn;
- entry->ops = backend;
- DLIST_ADD(ldb_backends, entry);
+ be->ops->name = url_prefix;
+ be->ops->connect_fn = connectfn;
return LDB_SUCCESS;
}
@@ -197,7 +200,7 @@ int ldb_connect_backend(struct ldb_context *ldb,
{
int ret;
char *backend;
- ldb_connect_fn fn;
+ struct backends_list_entry *be;
if (strchr(url, ':') != NULL) {
backend = talloc_strndup(ldb, url, strchr(url, ':')-url);
@@ -206,21 +209,21 @@ int ldb_connect_backend(struct ldb_context *ldb,
backend = talloc_strdup(ldb, "tdb");
}
- fn = ldb_find_backend(backend);
+ be = ldb_find_backend(backend);
talloc_free(backend);
- if (fn == NULL) {
+ if (be == NULL) {
ldb_debug(ldb, LDB_DEBUG_FATAL,
"Unable to find backend for '%s'", url);
return LDB_ERR_OTHER;
}
- ret = fn(ldb, url, ldb->flags, options, backend_module);
+ ret = be->ops->connect_fn(ldb, url, ldb->flags, options, backend_module);
if (ret != LDB_SUCCESS) {
ldb_debug(ldb, LDB_DEBUG_ERROR,
- "Failed to connect to '%s'", url);
+ "Failed to connect to '%s' with backend '%s'", url, be->ops->name);
return ret;
}
return ret;
diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
index 9ede379c81..a312cc9fe2 100644
--- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c
+++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
@@ -870,7 +870,7 @@ _PUBLIC_ int ldb_ildap_init(const char *ldb_version)
int ret, i;
const char *names[] = { "ldap", "ldaps", "ldapi", NULL };
for (i=0; names[i]; i++) {
- ret = ldb_register_backend(names[i], ildb_connect);
+ ret = ldb_register_backend(names[i], ildb_connect, true);
if (ret != LDB_SUCCESS) {
return ret;
}
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index 5b8b2d7b7d..b32be90a89 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -962,7 +962,7 @@ int ldb_ldap_init(const char *ldb_version)
int ret, i;
const char *names[] = { "ldap", "ldaps", "ldapi", NULL };
for (i=0; names[i]; i++) {
- ret = ldb_register_backend(names[i], lldb_connect);
+ ret = ldb_register_backend(names[i], lldb_connect, false);
if (ret != LDB_SUCCESS) {
return ret;
}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 90eb209ec5..4a96af3ab8 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -1449,5 +1449,5 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
int ldb_tdb_init(const char *version)
{
- return ldb_register_backend("tdb", ltdb_connect);
+ return ldb_register_backend("tdb", ltdb_connect, false);
}