From 4d6c120fb7a9aef80e83f00b155ff93e96034897 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 31 Aug 2011 16:17:54 +1000 Subject: ldb: fixed ldbsearch when no baseDN specified and cross-ncs is used Pair-Programmed-With: Andrew Bartlett --- lib/ldb/tools/ldbsearch.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'lib/ldb/tools/ldbsearch.c') diff --git a/lib/ldb/tools/ldbsearch.c b/lib/ldb/tools/ldbsearch.c index d10b9650da..2da7072fa6 100644 --- a/lib/ldb/tools/ldbsearch.c +++ b/lib/ldb/tools/ldbsearch.c @@ -204,10 +204,6 @@ static int do_search(struct ldb_context *ldb, return LDB_ERR_OPERATIONS_ERROR; } - if (basedn == NULL) { - basedn = ldb_get_default_basedn(ldb); - } - again: /* free any previous requests */ if (req) talloc_free(req); @@ -224,6 +220,30 @@ again: return ret; } + if (basedn == NULL) { + /* + we need to use a NULL base DN when doing a cross-ncs + search so we find results on all partitions in a + forest. When doing a domain-local search, default to + the default basedn + */ + struct ldb_control *ctrl; + struct ldb_search_options_control *search_options = NULL; + + ctrl = ldb_request_get_control(req, LDB_CONTROL_SEARCH_OPTIONS_OID); + if (ctrl) { + search_options = talloc_get_type(ctrl->data, struct ldb_search_options_control); + } + + if (ctrl == NULL || search_options == NULL || + !(search_options->search_options & LDB_SEARCH_OPTION_PHANTOM_ROOT)) { + struct ldb_dn *base = ldb_get_default_basedn(ldb); + if (base != NULL) { + req->op.search.base = base; + } + } + } + sctx->pending = 0; ret = ldb_request(ldb, req); -- cgit