r7833: changed ldbsearch and ldbedit to have command line syntax closer to
authorAndrew Tridgell <tridge@samba.org>
Wed, 22 Jun 2005 03:10:40 +0000 (03:10 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:18:41 +0000 (13:18 -0500)
ldapsearch. They look for an '=' in the first argument to see if it is
a search expression, and if not then it does an 'all records' search

source/lib/ldb/tests/test-generic.sh
source/lib/ldb/tools/ldbedit.c
source/lib/ldb/tools/ldbsearch.c

index 02325b83561fdbda2fac7b4d5959dfb22dbb9ba3..aa5c5dfb88292a9a7dc48c0e16dff434534be3ba 100755 (executable)
@@ -37,7 +37,7 @@ $VALGRIND bin/ldbsearch '(|(uid=uham)(uid=uham)(objectclass=OpenLDAPperson))'  |
 $VALGRIND bin/ldbsearch '(&(uid=uham)(uid=uham)(!(objectclass=xxx)))'  || exit 1
 $VALGRIND bin/ldbsearch '(&(objectclass=person)(uid=uham)(!(uid=uhamxx)))' uid \* \+ dn  || exit 1
 $VALGRIND bin/ldbsearch '(&(uid=uham)(uid=uha*)(title=*))' uid || exit 1
-$VALGRIND bin/ldbsearch '((' uid && exit 1
+$VALGRIND bin/ldbsearch '((' uid || exit 1
 $VALGRIND bin/ldbsearch '(objectclass=)' uid || exit 1
 $VALGRIND bin/ldbsearch -b 'cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' -s base "" sn || exit 1
 
index e8497ba18fffdd2cbe1ec712e1da76fdf05ec4f9..12bf12bfff0411fb819d4fba35599e3377d04fab 100644 (file)
@@ -278,28 +278,23 @@ static void usage(void)
        struct ldb_context *ldb;
        struct ldb_message **msgs;
        int ret;
-       const char *expression = NULL;
+       const char *expression = "(|(objectclass=*)(dn=*))";
        const char * const * attrs = NULL;
 
        ldb = ldb_init(NULL);
 
        options = ldb_cmdline_process(ldb, argc, argv, usage);
 
-       if (options->all_records) {
-               expression = "(|(objectclass=*)(dn=*))";
-       }
-
-       if (!expression) {
-               if (options->argc == 0) {
-                       usage();
-               }
+       /* the check for '=' is for compatibility with ldapsearch */
+       if (options->argc > 0 && 
+           strchr(options->argv[0], '=')) {
                expression = options->argv[0];
-               options->argc--;
                options->argv++;
+               options->argc--;
        }
 
        if (options->argc > 0) {
-               attrs = (const char * const *)options->argv;
+               attrs = (const char * const *)(options->argv);
        }
 
        ret = ldb_search(ldb, options->basedn, options->scope, expression, attrs, &msgs);
index 0e81da5de345c2fc1246ccf2751b66d107809601..396bb7797a216e2eb62971bd33979b2b68246609 100644 (file)
@@ -120,18 +120,23 @@ static int do_search(struct ldb_context *ldb,
        const char * const * attrs = NULL;
        struct ldb_cmdline *options;
        int ret = -1;
+       const char *expression = "(|(objectclass=*)(dn=*))";
 
        ldb = ldb_init(NULL);
 
        options = ldb_cmdline_process(ldb, argc, argv, usage);
-       
-       if (options->argc < 1 && !options->interactive) {
-               usage();
-               exit(1);
+
+       /* the check for '=' is for compatibility with ldapsearch */
+       if (!options->interactive &&
+           options->argc > 0 && 
+           strchr(options->argv[0], '=')) {
+               expression = options->argv[0];
+               options->argv++;
+               options->argc--;
        }
 
-       if (options->argc > 1) {
-               attrs = (const char * const *)(options->argv+1);
+       if (options->argc > 0) {
+               attrs = (const char * const *)(options->argv);
        }
 
        if (options->interactive) {
@@ -144,7 +149,7 @@ static int do_search(struct ldb_context *ldb,
                }
        } else {
                ret = do_search(ldb, options->basedn, options->scope, options->sorted, 
-                               options->argv[0], attrs);
+                               expression, attrs);
        }
 
        talloc_free(ldb);