diff options
author | Simo Sorce <idra@samba.org> | 2005-06-14 19:15:17 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:18:11 -0500 |
commit | 9189833a8753a723a8b8d0af9c8b096571b06a84 (patch) | |
tree | d20481827bb51e1d2a6cddb2a7bcb64ff653b7a7 /source4/lib | |
parent | 056d63c62f3793fda0d3049a2f98cef435c9003e (diff) | |
download | samba-9189833a8753a723a8b8d0af9c8b096571b06a84.tar.gz samba-9189833a8753a723a8b8d0af9c8b096571b06a84.tar.bz2 samba-9189833a8753a723a8b8d0af9c8b096571b06a84.zip |
r7582: Better way to have a fast path searching for a specific DN.
Old way was ugly and had a bug, you couldn't add an attribute named
dn or distinguishedName and search for it, tdb would change that search in a dn search.
This makes it also possible to search by dn against an ldap server as the old method was
not supported by ldap syntaxes.
sss
(This used to be commit a614466dec2484a0d39bdfae53da822cfcf80926)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/gendb.c | 31 | ||||
-rw-r--r-- | source4/lib/ldb/Makefile.in | 2 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_ldap/ldb_ldap.c | 4 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_search.c | 23 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.h | 2 | ||||
-rwxr-xr-x | source4/lib/ldb/tests/start_slapd.sh | 2 |
6 files changed, 49 insertions, 15 deletions
diff --git a/source4/lib/gendb.c b/source4/lib/gendb.c index 5b4f7b251e..dc5b7f39aa 100644 --- a/source4/lib/gendb.c +++ b/source4/lib/gendb.c @@ -61,7 +61,7 @@ int gendb_search_v(struct ldb_context *ldb, /* search the LDB for the specified attributes - varargs variant */ -int gendb_search(struct ldb_context *sam_ldb, +int gendb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *basedn, struct ldb_message ***res, @@ -72,12 +72,39 @@ int gendb_search(struct ldb_context *sam_ldb, int count; va_start(ap, format); - count = gendb_search_v(sam_ldb, mem_ctx, basedn, res, attrs, format, ap); + count = gendb_search_v(ldb, mem_ctx, basedn, res, attrs, format, ap); va_end(ap); return count; } +int gendb_search_dn(struct ldb_context *ldb, + TALLOC_CTX *mem_ctx, + const char *dn, + struct ldb_message ***res, + const char * const *attrs) +{ + va_list ap; + int count; + + *res = NULL; + + count = ldb_search(ldb, dn, LDB_SCOPE_BASE, "", attrs, res); + + if (count > 1) { + DEBUG(1, ("DB Corruption ? - Found more then one entry for dn: %s", dn)); + return -1; + } + + if (*res) talloc_steal(mem_ctx, *res); + + DEBUG(4,("gendb_search_dn: %s -> %d (%s)\n", + dn, count, count==-1?ldb_errstring(ldb):"OK")); + + return count; +} + + /* setup some initial ldif in a ldb */ diff --git a/source4/lib/ldb/Makefile.in b/source4/lib/ldb/Makefile.in index 3bfae08c27..88935b6f3a 100644 --- a/source4/lib/ldb/Makefile.in +++ b/source4/lib/ldb/Makefile.in @@ -148,9 +148,11 @@ test-sqlite3: @echo "SKIP SQLITE3 TEST - NO SQLITE3 SUPPORT" endif +ifeq (1,0) test-schema: @echo "STARTING SCHEMA MODULE TEST" tests/test-schema.sh +endif test: $(BINS) test-tdb test-ldap test-sqlite3 test-schema diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index fceaf02196..b3d8fcc1a5 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -196,6 +196,10 @@ static int lldb_search(struct ldb_module *module, const char *base, base = ""; } + if (expression == NULL || expression[0] == '\0') { + expression = "objectClass=*"; + } + lldb->last_rc = ldap_search_s(lldb->ldap, base, (int)scope, expression, discard_const_p(char *, attrs), diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 17eff6f0a6..d210510ff2 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -272,7 +272,7 @@ int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_messag /* search the database for a single simple dn */ -int ltdb_search_dn(struct ldb_module *module, char *dn, +int ltdb_search_dn(struct ldb_module *module, const char *dn, const char * const attrs[], struct ldb_message ***res) { struct ldb_context *ldb = module->ldb; @@ -482,17 +482,9 @@ int ltdb_search_bytree(struct ldb_module *module, const char *base, *res = NULL; - if (tree->operation == LDB_OP_SIMPLE && - (ldb_attr_cmp(tree->u.simple.attr, "dn") == 0 || - ldb_attr_cmp(tree->u.simple.attr, "distinguishedName") == 0) && - !ltdb_has_wildcard(module, tree->u.simple.attr, &tree->u.simple.value)) { - /* yay! its a nice simple one */ - ret = ltdb_search_dn(module, tree->u.simple.value.data, attrs, res); - } else { - ret = ltdb_search_indexed(module, base, scope, tree, attrs, res); - if (ret == -1) { - ret = ltdb_search_full(module, base, scope, tree, attrs, res); - } + ret = ltdb_search_indexed(module, base, scope, tree, attrs, res); + if (ret == -1) { + ret = ltdb_search_full(module, base, scope, tree, attrs, res); } ltdb_unlock_read(module); @@ -513,6 +505,13 @@ int ltdb_search(struct ldb_module *module, const char *base, struct ldb_parse_tree *tree; int ret; + /* check if we are looking for a simple dn */ + if (scope == LDB_SCOPE_BASE && (expression == NULL || expression[0] == '\0')) { + ret = ltdb_search_dn(module, base, attrs, res); + ltdb_unlock_read(module); + return ret; + } + tree = ldb_parse_tree(ltdb, expression); if (tree == NULL) { ltdb->last_err_string = "expression parse failed"; diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index 891522f300..b77e02fba5 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -91,7 +91,7 @@ int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, const struct ldb_val *val); void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg); int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_message *msg); -int ltdb_search_dn(struct ldb_module *module, char *dn, +int ltdb_search_dn(struct ldb_module *module, const char *dn, const char * const attrs[], struct ldb_message ***res); int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg, const char * const attrs[], diff --git a/source4/lib/ldb/tests/start_slapd.sh b/source4/lib/ldb/tests/start_slapd.sh index a7ec69c855..6dd3eaa9b8 100755 --- a/source4/lib/ldb/tests/start_slapd.sh +++ b/source4/lib/ldb/tests/start_slapd.sh @@ -3,3 +3,5 @@ mkdir -p tests/tmp/db slapd -f tests/slapd.conf -h "`tests/ldapi_url.sh`" $* + +sleep 2 |