From 5fd031c97daaa1bf09a7ad80550753acd434075f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Oct 2005 05:24:46 +0000 Subject: 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) --- source4/lib/ldb/ldb_ldap/ldb_ldap.c | 51 ++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 29 deletions(-) (limited to 'source4/lib/ldb/ldb_ldap') 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); @@ -287,27 +302,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, -- cgit