From 97318cdb45f1022ca2beebbf24ab11af80c07dc2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 09:48:17 +0000 Subject: r7719: make the ildap ldb backend use the defaultNamingContext if the basedn is not specified, so: ldbsearch ldap://hostname '(objectclass=user)' works without knowing the domain name (This used to be commit f6c2c5190737ca11f55a147f5295ccca505fb58b) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 9cccec0313..3f63af482f 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -37,9 +37,9 @@ #include "lib/cmdline/popt_common.h" struct ildb_private { - const char *basedn; struct ldap_connection *ldap; NTSTATUS last_rc; + struct ldb_message *rootDSE; }; /* @@ -100,6 +100,8 @@ static int ildb_delete(struct ldb_module *module, const char *dn) } +static void ildb_rootdse(struct ldb_module *module); + /* search for matching records */ @@ -116,7 +118,13 @@ static int ildb_search(struct ldb_module *module, const char *base, } if (base == NULL) { - base = ""; + if (ildb->rootDSE == NULL) { + ildb_rootdse(module); + } + if (ildb->rootDSE != NULL) { + base = ldb_msg_find_string(ildb->rootDSE, + "defaultNamingContext", ""); + } } if (expression == NULL || expression[0] == '\0') { @@ -351,6 +359,22 @@ static const struct ldb_module_ops ildb_ops = { }; +/* + fetch the rootDSE +*/ +static void ildb_rootdse(struct ldb_module *module) +{ + struct ildb_private *ildb = module->private_data; + struct ldb_message **res = NULL; + int ret; + ret = ildb_search(module, "", LDB_SCOPE_BASE, "dn=dc=rootDSE", NULL, &res); + if (ret == 1) { + ildb->rootDSE = talloc_steal(ildb, res[0]); + } + talloc_free(res); +} + + /* connect to the database */ @@ -366,6 +390,8 @@ int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } + ildb->rootDSE = NULL; + ildb->ldap = ldap_new_connection(ildb, NULL); if (!ildb->ldap) { ldb_oom(ldb); -- cgit