diff options
author | Stefan Metzmacher <metze@samba.org> | 2006-12-22 16:59:07 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:29:38 -0500 |
commit | ff322519af326452ea86c5f5d4cb19d1f27e0f16 (patch) | |
tree | 2d69f8e82d95214228524f61f5ddb299ef931f66 | |
parent | 525447821e70e089d03713ff92d0ad0f2860b38f (diff) | |
download | samba-ff322519af326452ea86c5f5d4cb19d1f27e0f16.tar.gz samba-ff322519af326452ea86c5f5d4cb19d1f27e0f16.tar.bz2 samba-ff322519af326452ea86c5f5d4cb19d1f27e0f16.zip |
r20317: store references to all important naming contexts.
add ldb_get_config_basedn(), ldb_get_schema_basedn()
and ldb_get_root_basedn()
metze
(This used to be commit e28cb83904299fe01e8c0797f5429387f254ed1e)
-rw-r--r-- | source4/lib/ldb/common/ldb.c | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 7321f7a6f7..9b4386547c 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -153,37 +153,69 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op pet hates about ldapsearch, which is that you have to get a long, complex basedn right to make any use of it. */ -static struct ldb_dn *ldb_set_default_basedn(struct ldb_context *ldb) +static void ldb_set_default_dns(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 = (struct ldb_dn *)ldb_get_opaque(ldb, "default_baseDN"); - if (basedn) { - return basedn; - } + struct ldb_dn *tmp_dn=NULL; + static const char *attrs[] = { + "rootDomainNamingContext", + "configurationNamingContext", + "schemaNamingContext", + "defaultNamingContext", + NULL + }; tmp_ctx = talloc_new(ldb); ret = ldb_search(ldb, ldb_dn_new(tmp_ctx, ldb, NULL), LDB_SCOPE_BASE, "(objectClass=*)", attrs, &res); if (ret == LDB_SUCCESS) { if (res->count == 1) { - basedn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], "defaultNamingContext"); - ldb_set_opaque(ldb, "default_baseDN", basedn); + if (!ldb_get_opaque(ldb, "rootDomainNamingContext")) { + tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], "rootDomainNamingContext"); + ldb_set_opaque(ldb, "rootDomainNamingContext", tmp_dn); + } + + if (!ldb_get_opaque(ldb, "configurationNamingContext")) { + tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], "configurationNamingContext"); + ldb_set_opaque(ldb, "configurationNamingContext", tmp_dn); + } + + if (!ldb_get_opaque(ldb, "schemaNamingContext")) { + tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], "schemaNamingContext"); + ldb_set_opaque(ldb, "schemaNamingContext", tmp_dn); + } + + if (!ldb_get_opaque(ldb, "defaultNamingContext")) { + tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], "defaultNamingContext"); + ldb_set_opaque(ldb, "defaultNamingContext", tmp_dn); + } } talloc_free(res); } talloc_free(tmp_ctx); - return basedn; +} + +struct ldb_dn *ldb_get_root_basedn(struct ldb_context *ldb) +{ + return talloc_get_type(ldb_get_opaque(ldb, "rootDomainNamingContext"), struct ldb_dn); +} + +struct ldb_dn *ldb_get_config_basedn(struct ldb_context *ldb) +{ + return talloc_get_type(ldb_get_opaque(ldb, "configurationNamingContext"), struct ldb_dn); +} + +struct ldb_dn *ldb_get_schema_basedn(struct ldb_context *ldb) +{ + return talloc_get_type(ldb_get_opaque(ldb, "schemaNamingContext"), struct ldb_dn); } struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb) { - return (struct ldb_dn *)ldb_get_opaque(ldb, "default_baseDN"); + return talloc_get_type(ldb_get_opaque(ldb, "defaultNamingContext"), struct ldb_dn); } /* @@ -217,7 +249,7 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co ldb->default_timeout = 300; /* set default to 5 minutes */ /* set the default base dn */ - ldb_set_default_basedn(ldb); + ldb_set_default_dns(ldb); return LDB_SUCCESS; } |