1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-11 00:23:51 +03:00

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 commit is contained in:
Andrew Tridgell
2005-10-06 05:24:46 +00:00
committed by Gerald (Jerry) Carter
parent e83635941c
commit 7e44f9153c
18 changed files with 97 additions and 239 deletions

View File

@@ -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;
}
lldb->last_rc = ldap_search_s(lldb->ldap, search_base, (int)scope,
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, 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,