summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common/ldb.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2006-08-25 12:59:03 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:16:46 -0500
commit88b04ab6e65137079b2dad76d1cea07e7ea9ab80 (patch)
tree7357d0b7a7b602cb5f6fd508bffbe47592d2d270 /source4/lib/ldb/common/ldb.c
parentfd4e294c41a568c9f7d196361bb19fdeab3f4fde (diff)
downloadsamba-88b04ab6e65137079b2dad76d1cea07e7ea9ab80.tar.gz
samba-88b04ab6e65137079b2dad76d1cea07e7ea9ab80.tar.bz2
samba-88b04ab6e65137079b2dad76d1cea07e7ea9ab80.zip
r17830: Set the default_basedn (hey, it comes from the "default" naming contex :-)
once at connection time, after modules have been loaded. Introduce a function to retrieve the value where needed. (This used to be commit 0caf6a44e03393c645030a9288e7dfd31e97c98b)
Diffstat (limited to 'source4/lib/ldb/common/ldb.c')
-rw-r--r--source4/lib/ldb/common/ldb.c71
1 files changed, 39 insertions, 32 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index db5333187b..04ac3e7d81 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -141,6 +141,41 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op
return ret;
}
+/*
+ try to autodetect a basedn if none specified. This fixes one of my
+ pet hates about ldapsearch, which is that you have to get a long,
+ complex basedn right to make any use of it.
+*/
+static const struct ldb_dn *ldb_set_default_basedn(struct ldb_context *ldb)
+{
+ TALLOC_CTX *tmp_ctx;
+ int ret;
+ static const char *attrs[] = { "defaultNamingContext", NULL };
+ struct ldb_result *res;
+ struct ldb_dn *basedn=NULL;
+
+ basedn = ldb_get_opaque(ldb, "default_baseDN");
+ if (basedn) {
+ return basedn;
+ }
+
+ tmp_ctx = talloc_new(ldb);
+ ret = ldb_search(ldb, ldb_dn_new(tmp_ctx), LDB_SCOPE_BASE,
+ "(objectClass=*)", attrs, &res);
+ if (ret == LDB_SUCCESS && res->count == 1) {
+ basedn = ldb_msg_find_attr_as_dn(ldb, res->msgs[0], "defaultNamingContext");
+ }
+
+ ldb_set_opaque(ldb, "default_baseDN", basedn);
+
+ talloc_free(tmp_ctx);
+ return basedn;
+}
+
+const struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb)
+{
+ return ldb_get_opaque(ldb, "default_baseDN");
+}
/*
connect to a database. The URL can either be one of the following forms
@@ -171,6 +206,9 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
/* TODO: get timeout from options if available there */
ldb->default_timeout = 300; /* set default to 5 minutes */
+ /* set the default base dn */
+ ldb_set_default_basedn(ldb);
+
return LDB_SUCCESS;
}
@@ -530,37 +568,6 @@ error:
}
/*
- try to autodetect a basedn if none specified. This fixes one of my
- pet hates about ldapsearch, which is that you have to get a long,
- complex basedn right to make any use of it.
-*/
-const struct ldb_dn *ldb_auto_basedn(struct ldb_context *ldb)
-{
- TALLOC_CTX *tmp_ctx;
- int ret;
- static const char *attrs[] = { "defaultNamingContext", NULL };
- struct ldb_result *res;
- struct ldb_dn *basedn=NULL;
-
- basedn = ldb_get_opaque(ldb, "auto_baseDN");
- if (basedn) {
- return basedn;
- }
-
- tmp_ctx = talloc_new(ldb);
- ret = ldb_search(ldb, ldb_dn_new(tmp_ctx), LDB_SCOPE_BASE,
- "(objectClass=*)", attrs, &res);
- if (ret == LDB_SUCCESS && res->count == 1) {
- basedn = ldb_msg_find_attr_as_dn(ldb, res->msgs[0], "defaultNamingContext");
- }
-
- ldb_set_opaque(ldb, "auto_baseDN", basedn);
-
- talloc_free(tmp_ctx);
- return basedn;
-}
-
-/*
note that ldb_search() will automatically replace a NULL 'base' value with the
defaultNamingContext from the rootDSE if available.
*/
@@ -583,7 +590,7 @@ int ldb_search(struct ldb_context *ldb,
}
if (base == NULL) {
- base = ldb_auto_basedn(ldb);
+ base = ldb_get_default_basedn(ldb);
}
req->operation = LDB_SEARCH;