diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-11-01 16:42:21 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-11-01 18:55:19 +1100 |
commit | c74601e0b333f81570dfca6959e047d83e6ab32c (patch) | |
tree | 9571b44470dd9dc1cfe311fcac8c216bd513a70b /source4/lib/ldb/common | |
parent | 05b37385fcfc67f4203b2a4822f94813d11511ca (diff) | |
download | samba-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
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r-- | source4/lib/ldb/common/ldb_modules.c | 57 |
1 files changed, 30 insertions, 27 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; |