diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-10-06 05:24:46 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:39:26 -0500 |
commit | 5fd031c97daaa1bf09a7ad80550753acd434075f (patch) | |
tree | 8221ef256c17f138b11d22d9da26ae95db5618c4 /source4/lib/ldb/ldb_ldap | |
parent | 92da5aa6b8d5141b22d781442583c9f3ad94d3af (diff) | |
download | samba-5fd031c97daaa1bf09a7ad80550753acd434075f.tar.gz samba-5fd031c97daaa1bf09a7ad80550753acd434075f.tar.bz2 samba-5fd031c97daaa1bf09a7ad80550753acd434075f.zip |
r10753: don't require every ldb module to implement both a search_bytree() and
a search() function, instead each module now only implements the
bytree method, and the expression based search is handled generically
by the modules code. This makes for more consistency and less code
duplication.
fixed the tdb backend to handle BASE searches much more
efficiently. They now always only lookup one record, regardless of the
search expression
(This used to be commit 7e44f9153c5578624e2fca04cdc0a00af0fd9eb4)
Diffstat (limited to 'source4/lib/ldb/ldb_ldap')
-rw-r--r-- | source4/lib/ldb/ldb_ldap/ldb_ldap.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index 1d1dd66e84..268e2b0291 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -174,15 +174,16 @@ static int lldb_add_msg_attr(struct ldb_context *ldb, /* search for matching records */ -static int lldb_search(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, const char *expression, - const char * const *attrs, struct ldb_message ***res) +static int lldb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const *attrs, struct ldb_message ***res) { struct ldb_context *ldb = module->ldb; struct lldb_private *lldb = module->private_data; - int count, msg_count; + int count, msg_count, ldap_scope; char *search_base; LDAPMessage *ldapres, *msg; + char *expression; search_base = ldb_dn_linearize(ldb, base); if (base == NULL) { @@ -192,11 +193,25 @@ static int lldb_search(struct ldb_module *module, const struct ldb_dn *base, return -1; } - if (expression == NULL || expression[0] == '\0') { - expression = "objectClass=*"; + expression = ldb_filter_from_tree(search_base, tree); + if (expression == NULL) { + talloc_free(search_base); + return -1; + } + + switch (scope) { + case LDB_SCOPE_BASE: + ldap_scope = LDAP_SCOPE_BASE; + break; + case LDB_SCOPE_ONELEVEL: + ldap_scope = LDAP_SCOPE_ONELEVEL; + break; + default: + ldap_scope = LDAP_SCOPE_SUBTREE; + break; } - lldb->last_rc = ldap_search_s(lldb->ldap, search_base, (int)scope, + lldb->last_rc = ldap_search_s(lldb->ldap, search_base, ldap_scope, expression, discard_const_p(char *, attrs), 0, &ldapres); @@ -288,27 +303,6 @@ failed: /* - search for matching records using a ldb_parse_tree -*/ -static int lldb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) -{ - struct lldb_private *lldb = module->private_data; - char *expression; - int ret; - - expression = ldb_filter_from_tree(lldb, tree); - if (expression == NULL) { - return -1; - } - ret = lldb_search(module, base, scope, expression, attrs, res); - talloc_free(expression); - return ret; -} - - -/* convert a ldb_message structure to a list of LDAPMod structures ready for ldap_add() or ldap_modify() */ @@ -478,7 +472,6 @@ static int lldb_del_trans(struct ldb_module *module) static const struct ldb_module_ops lldb_ops = { .name = "ldap", - .search = lldb_search, .search_bytree = lldb_search_bytree, .add_record = lldb_add, .modify_record = lldb_modify, |