#include "librpc/gen_ndr/ndr_misc.h"
#include <time.h>
-static int objectguid_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)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_search\n");
- return ldb_next_search(module, base, scope, expression, attrs, res);
-}
-
static int objectguid_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)
static const struct ldb_module_ops objectguid_ops = {
.name = "objectguid",
- .search = objectguid_search,
.search_bytree = objectguid_search_bytree,
.add_record = objectguid_add_record,
.modify_record = objectguid_modify_record,
#define SAM_ACCOUNT_NAME_BASE "$000000-000000000000"
-static int samldb_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)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_search\n");
- return ldb_next_search(module, base, scope, expression, attrs, res);
-}
-
static int samldb_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)
static const struct ldb_module_ops samldb_ops = {
.name = "samldb",
- .search = samldb_search,
.search_bytree = samldb_search_bytree,
.add_record = samldb_add_record,
.modify_record = samldb_modify_record,
const char *expression,
const char * const *attrs, struct ldb_message ***res)
{
- ldb_reset_err_string(ldb);
+ struct ldb_parse_tree *tree;
+ int ret;
+
+ tree = ldb_parse_tree(ldb, expression);
+ if (tree == NULL) {
+ ldb_set_errstring(ldb->modules, talloc_strdup(ldb, "Unable to parse search expression"));
+ return -1;
+ }
+
+ ret = ldb_search_bytree(ldb, base, scope, tree, attrs, res);
+ talloc_free(tree);
- return ldb->modules->ops->search(ldb->modules, base, scope, expression, attrs, res);
+ return ret;
}
/*
- search the database given a LDAP-like search expression
+ search the database given a search tree
return the number of records found, or -1 on error
{ "objectguid", objectguid_module_init },
{ "samldb", samldb_module_init },
{ "samba3sam", ldb_samba3sam_module_init },
+ { "proxy", proxy_module_init },
#endif
{ NULL, NULL }
};
return -1;
}
if (ret > 1) {
- ldb_debug(ldb, LDB_DEBUG_FATAL, "Too many records found, bailing out\n");
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Too many records found (%d), bailing out\n", ret);
talloc_free(msg);
return -1;
}
/*
helper functions to call the next module in chain
*/
+int ldb_next_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)
+{
+ if (!module->next) {
+ return -1;
+ }
+ return module->next->ops->search_bytree(module->next, base, scope, tree, attrs, res);
+}
int ldb_next_search(struct ldb_module *module,
const struct ldb_dn *base,
const char *expression,
const char * const *attrs, struct ldb_message ***res)
{
+ struct ldb_parse_tree *tree;
+ int ret;
if (!module->next) {
return -1;
}
- return module->next->ops->search(module->next, base, scope, expression, attrs, res);
-}
-
-int ldb_next_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)
-{
- if (!module->next) {
+ tree = ldb_parse_tree(module, expression);
+ if (tree == NULL) {
+ ldb_set_errstring(module, talloc_strdup(module, "Unable to parse search expression"));
return -1;
}
- return module->next->ops->search_bytree(module->next, base, scope, tree, attrs, res);
+ ret = module->next->ops->search_bytree(module->next, base, scope, tree, attrs, res);
+ talloc_free(tree);
+ return ret;
}
+
int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *message)
{
if (!module->next) {
*/
struct ldb_parse_tree *ldb_parse_tree(void *mem_ctx, const char *s)
{
- /* allowing NULL makes the _bytree() searches easier */
- if (s == NULL) {
- return NULL;
+ if (s == NULL || *s == 0) {
+ s = "(|(objectClass=*)(dn=*))";
}
while (isspace((unsigned char)*s)) s++;
*/
struct ldb_module_ops {
const char *name;
- int (*search)(struct ldb_module *, const struct ldb_dn *, enum ldb_scope,
- const char *, const char * const [], struct ldb_message ***);
int (*search_bytree)(struct ldb_module *, const struct ldb_dn *, enum ldb_scope,
struct ldb_parse_tree *, const char * const [], struct ldb_message ***);
int (*add_record)(struct ldb_module *, const struct ldb_message *);
int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
int ldb_next_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);
+ const struct ldb_dn *base,
+ enum ldb_scope scope,
+ const char *expression,
+ const char * const *attrs, struct ldb_message ***res);
int ldb_next_search_bytree(struct ldb_module *module,
const struct ldb_dn *base,
enum ldb_scope scope,
}
-/*
- search for matching records
-*/
-static int ildb_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)
-{
- struct ildb_private *ildb = module->private_data;
- int ret;
- struct ldb_parse_tree *tree;
-
- if (expression == NULL || expression[0] == '\0') {
- expression = "objectClass=*";
- }
-
- tree = ldb_parse_tree(ildb, expression);
-
- ret = ildb_search_bytree(module, base, scope, tree, attrs, res);
-
- talloc_free(tree);
- return ret;
-}
-
-
/*
convert a ldb_message structure to a list of ldap_mod structures
ready for ildap_add() or ildap_modify()
static const struct ldb_module_ops ildb_ops = {
.name = "ldap",
- .search = ildb_search,
.search_bytree = ildb_search_bytree,
.add_record = ildb_add,
.modify_record = ildb_modify,
struct ldb_message **res = NULL;
struct ldb_dn *empty_dn = ldb_dn_new(ildb);
int ret;
- ret = ildb_search(module, empty_dn, LDB_SCOPE_BASE, "dn=dc=rootDSE", NULL, &res);
+ ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE,
+ ldb_parse_tree(empty_dn, "dn=dc=rootDSE"),
+ NULL, &res);
if (ret == 1) {
ildb->rootDSE = talloc_steal(ildb, res[0]);
}
/*
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) {
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);
}
-/*
- 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()
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,
int ret, i;
/* create a local ctx */
- local_ctx = talloc_named(lsqlite3, 0, "lsqlite3_search_by_tree local context");
+ local_ctx = talloc_named(lsqlite3, 0, "lsqlite3_search_bytree local context");
if (local_ctx == NULL) {
return -1;
}
return -1;
}
-/* search for matching records, by expression */
-static int lsqlite3_search(struct ldb_module * module, const struct ldb_dn *basedn,
- enum ldb_scope scope, const char * expression,
- const char * const *attrs, struct ldb_message *** res)
-{
- struct ldb_parse_tree * tree;
- int ret;
-
- /* Handle tdb specials */
- if (ldb_dn_is_special(basedn)) {
-#warning "handle tdb specials"
- return 0;
- }
-
-#if 0
-/* (|(objectclass=*)(dn=*)) is passed by the command line tool now instead */
- /* Handle the special case of requesting all */
- if (pExpression != NULL && *pExpression == '\0') {
- pExpression = "dn=*";
- }
-#endif
-
- /* Parse the filter expression into a tree we can work with */
- if ((tree = ldb_parse_tree(module->ldb, expression)) == NULL) {
- return -1;
- }
-
- /* Now use the bytree function for the remainder of processing */
- ret = lsqlite3_search_bytree(module, basedn, scope, tree, attrs, res);
-
- /* Free the parse tree */
- talloc_free(tree);
-
- /* All done. */
- return ret;
-}
-
/* add a record */
static int lsqlite3_add(struct ldb_module *module, const struct ldb_message *msg)
*/
static const struct ldb_module_ops lsqlite3_ops = {
.name = "sqlite",
- .search = lsqlite3_search,
.search_bytree = lsqlite3_search_bytree,
.add_record = lsqlite3_add,
.modify_record = lsqlite3_modify,
struct dn_list *dn_list;
int ret;
- if (ltdb->cache->indexlist->num_elements == 0) {
+ if (ltdb->cache->indexlist->num_elements == 0 &&
+ scope != LDB_SCOPE_BASE) {
/* no index list? must do full search */
return -1;
}
return -1;
}
- ret = ltdb_index_dn(module, tree, ltdb->cache->indexlist, dn_list);
+ if (scope == LDB_SCOPE_BASE) {
+ /* with BASE searches only one DN can match */
+ char *dn = ldb_dn_linearize(dn_list, base);
+ if (dn == NULL) {
+ return -1;
+ }
+ dn_list->count = 1;
+ dn_list->dn = &dn;
+ ret = 1;
+ } else {
+ ret = ltdb_index_dn(module, tree, ltdb->cache->indexlist, dn_list);
+ }
if (ret == 1) {
/* we've got a candidate list - now filter by the full tree
for (i=0;i<msg->num_elements;i++) {
const struct ldb_attrib_handler *h;
h = ldb_attrib_handler(ldb, msg->elements[i].name);
- if (ldb_dn_is_special(msg->dn) && (h->flags & LDB_ATTR_FLAG_HIDDEN)) {
+ if (h->flags & LDB_ATTR_FLAG_HIDDEN) {
continue;
}
if (msg_add_element(ldb, ret, &msg->elements[i]) != 0) {
if ((base == NULL || base->comp_num == 0) &&
(scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1;
- /* check if we are looking for a simple dn */
- if (scope == LDB_SCOPE_BASE && tree == NULL) {
- return ltdb_search_dn(module, base, attrs, res);
- }
-
- if (tree == NULL) {
- char *err_string = talloc_strdup(module, "expression parse failed");
- if (err_string) ldb_set_errstring(module, err_string);
- return -1;
- }
-
/* it is important that we handle dn queries this way, and not
via a full db search, otherwise ldb is horribly slow */
if (tree->operation == LDB_OP_EQUALITY &&
}
-/*
- search the database with a LDAP-like expression.
- choses a search method
-*/
-int ltdb_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)
-{
- struct ltdb_private *ltdb = module->private_data;
- struct ldb_parse_tree *tree;
- int ret;
-
- if ((base == NULL || base->comp_num == 0) &&
- (scope == LDB_SCOPE_BASE || scope == LDB_SCOPE_ONELEVEL)) return -1;
-
- tree = ldb_parse_tree(ltdb, expression);
-
- ret = ltdb_search_bytree(module, base, scope, tree, attrs, res);
- talloc_free(tree);
- return ret;
-}
-
static const struct ldb_module_ops ltdb_ops = {
.name = "tdb",
- .search = ltdb_search,
.search_bytree = ltdb_search_bytree,
.add_record = ltdb_add,
.modify_record = ltdb_modify,
const char * const attrs[],
int *count,
struct ldb_message ***res);
-int ltdb_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);
int ltdb_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);
}
/* search fallback database */
-static int map_search_bytree_fb(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)
+static int map_search_fb(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)
{
int ret;
struct ldb_parse_tree t_and, t_not, t_present, *childs[2];
}
/* Search in the database against which we are mapping */
-static int map_search_bytree_mp(struct ldb_module *module, const struct ldb_dn *base,
+static int map_search_mp(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)
{
search for matching records using a ldb_parse_tree
*/
static int map_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)
+ enum ldb_scope scope, struct ldb_parse_tree *tree,
+ const char * const *attrs, struct ldb_message ***res)
{
struct ldb_message **fbres, **mpres = NULL;
int i;
int ret_fb, ret_mp;
- ret_fb = map_search_bytree_fb(module, base, scope, tree, attrs, &fbres);
+ ret_fb = map_search_fb(module, base, scope, tree, attrs, &fbres);
if (ret_fb == -1)
return -1;
return ret_fb;
}
- ret_mp = map_search_bytree_mp(module, base, scope, tree, attrs, &mpres);
+ ret_mp = map_search_mp(module, base, scope, tree, attrs, &mpres);
if (ret_mp == -1) {
return -1;
}
return ret_fb + ret_mp;
}
-/*
- search for matching records
-*/
-static int map_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)
-{
- struct ldb_parse_tree *tree;
- int ret;
-
- tree = ldb_parse_tree(NULL, expression);
- if (tree == NULL) {
- ldb_set_errstring(module, talloc_strdup(module, "expression parse failed"));
- return -1;
- }
-
- ret = map_search_bytree(module, base, scope, tree, attrs, res);
- talloc_free(tree);
- return ret;
-}
static int msg_contains_objectclass(const struct ldb_message *msg, const char *name)
{
static const struct ldb_module_ops map_ops = {
.name = "map",
- .search = map_search,
.search_bytree = map_search_bytree,
.add_record = map_add,
.modify_record = map_modify,
#include "ldb/include/ldb_private.h"
#include <time.h>
-static int rdn_name_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)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_search\n");
- return ldb_next_search(module, base, scope, expression, attrs, res);
-}
-
static int rdn_name_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)
+ enum ldb_scope scope, struct ldb_parse_tree *tree,
+ const char * const *attrs, struct ldb_message ***res)
{
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_search\n");
return ldb_next_search_bytree(module, base, scope, tree, attrs, res);
static const struct ldb_module_ops rdn_name_ops = {
.name = "rdn_name",
- .search = rdn_name_search,
.search_bytree = rdn_name_search_bytree,
.add_record = rdn_name_add_record,
.modify_record = rdn_name_modify_record,
}
/* search */
-static int schema_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)
-{
- return ldb_next_search(module, base, scope, expression, attrs, res);
-}
-
static int schema_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)
static const struct ldb_module_ops schema_ops = {
.name = "schema",
- .search = schema_search,
.search_bytree = schema_search_bytree,
.add_record = schema_add_record,
.modify_record = schema_modify_record,
/* search */
static int skel_search(struct ldb_module *module, const struct ldb_dn *base,
- enum ldb_scope scope, const char *expression,
+ enum ldb_scope scope, struct ldb_parse_tree *tree,
const char * const *attrs, struct ldb_message ***res)
{
- return ldb_next_search(module, base, scope, expression, attrs, res);
+ return ldb_next_search(module, base, scope, tree, attrs, res);
}
/* add_record */
static const struct ldb_module_ops skel_ops = {
.name = "skel",
- .search = skel_search,
- .search_bytree = skel_search_bytree,
+ .search_bytree = skel_search_bytree,
.add_record = skel_add_record,
.modify_record = skel_modify_record,
.delete_record = skel_delete_record,
#include "ldb/include/ldb_private.h"
#include <time.h>
-static int timestamps_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)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_search\n");
- return ldb_next_search(module, base, scope, expression, attrs, res);
-}
-
static int timestamps_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)
static const struct ldb_module_ops timestamps_ops = {
.name = "timestamps",
- .search = timestamps_search,
.search_bytree = timestamps_search_bytree,
.add_record = timestamps_add_record,
.modify_record = timestamps_modify_record,