r152: a quick airport commit ....
[bbaumbach/samba-autobuild/.git] / source4 / lib / ldb / tools / ldbsearch.c
index f4eb8f00db3c4562b71d98f0d6b52da3f0136db5..327feb28efa71db734677bb4a05ef62f94a3faba 100644 (file)
  */
 
 #include "includes.h"
-#include <getopt.h>
+
+static void usage(void)
+{
+       printf("Usage: ldbsearch <options> <expression> <attrs...>\n");
+       printf("Options:\n");
+       printf("  -H ldb_url       choose the database (or $LDB_URL)\n");
+       printf("  -s base|sub|one  choose search scope\n");
+       printf("  -b basedn        choose baseDN\n");
+       exit(1);
+}
 
  int main(int argc, char * const argv[])
 {
-       static struct ldb_context *ldb;
+       struct ldb_context *ldb;
        struct ldb_message **msgs;
        int ret, i;
        const char *expression;
-       const char * const *attrs = NULL;
+       char * const *attrs = NULL;
        const char *ldb_url;
        const char *basedn = NULL;
        int opt;
        enum ldb_scope scope = LDB_SCOPE_SUBTREE;
 
        ldb_url = getenv("LDB_URL");
-       if (!ldb_url) {
-               ldb_url = "tdb://test.ldb";
-       }
 
-       while ((opt = getopt(argc, argv, "b:H:s:")) != EOF) {
+       while ((opt = getopt(argc, argv, "b:H:s:h")) != EOF) {
                switch (opt) {
                case 'b':
                        basedn = optarg;
                                scope = LDB_SCOPE_ONELEVEL;
                        }
                        break;
+
+               case 'h':
+               default:
+                       usage();
+                       break;
                }
        }
 
+       if (!ldb_url) {
+               fprintf(stderr, "You must specify a ldb URL\n");
+               exit(1);
+       }
+
        argc -= optind;
        argv += optind;
 
        if (argc < 1) {
-               printf("Usage: ldbsearch <expression> [attrs...]\n");
+               usage();
                exit(1);
        }