ldb: fixed ldbsearch when no baseDN specified and cross-ncs is used
authorAndrew Tridgell <tridge@samba.org>
Wed, 31 Aug 2011 06:17:54 +0000 (16:17 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 1 Sep 2011 05:23:09 +0000 (15:23 +1000)
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

lib/ldb/tools/ldbsearch.c

index d10b9650daf9882c19a0b2df25aa9c2d81638fb2..2da7072fa60045a54cd33f7517ed3bb1ccb370ac 100644 (file)
@@ -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);