Merge tag 'upstream/4.0.5+dfsg1' into samba_4.0_ivo
[abartlet/samba-debian.git] / lib / ldb / tools / ldbsearch.c
similarity index 90%
rename from source4/lib/ldb/tools/ldbsearch.c
rename to lib/ldb/tools/ldbsearch.c
index d10b9650daf9882c19a0b2df25aa9c2d81638fb2..a030a5abda663c05ec590243a6c0c15dc600bd42 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);
@@ -285,7 +305,7 @@ int main(int argc, const char **argv)
        /* the check for '=' is for compatibility with ldapsearch */
        if (!options->interactive &&
            options->argc > 0 && 
-           strchr(options->argv[0], '=')) {
+           strpbrk(options->argv[0], "=<>~:")) {
                expression = options->argv[0];
                options->argv++;
                options->argc--;