s3:dbwrap_tool: add popt support and standard samba options
authorMichael Adam <obnox@samba.org>
Tue, 20 Sep 2011 02:32:25 +0000 (04:32 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 20 Sep 2011 04:28:28 +0000 (06:28 +0200)
source3/Makefile.in
source3/utils/dbwrap_tool.c
source3/wscript_build

index d64adb8baaf3f3764876462257ce31262a8d0d9a..0796bc62f961c15fe967bae17e0b0286970134fe 100644 (file)
@@ -1549,7 +1549,8 @@ RPC_OPEN_TCP_OBJ = torture/rpc_open_tcp.o \
 DBWRAP_TOOL_OBJ = utils/dbwrap_tool.o \
                  $(PARAM_OBJ) \
                  $(LIB_NONSMBD_OBJ) \
-                 $(LIBSMB_ERR_OBJ)
+                 $(LIBSMB_ERR_OBJ) \
+                 $(POPT_LIB_OBJ)
 
 DBWRAP_TORTURE_OBJ = utils/dbwrap_torture.o \
                     $(PARAM_OBJ) \
@@ -3204,6 +3205,7 @@ bin/dbwrap_tool@EXEEXT@: $(DBWRAP_TOOL_OBJ) $(LIBTALLOC) $(LIBTDB)
        @$(CC) -o $@ $(DBWRAP_TOOL_OBJ)\
                $(LDFLAGS) $(DYNEXP) $(LIBS) \
                $(LDAP_LIBS) \
+               $(POPT_LIBS) \
                $(LIBTALLOC_LIBS) $(LIBTDB_LIBS)
 
 install-dbwrap_tool:: bin/dbwrap_tool@EXEEXT@
index 7902b0832a2d366bd55c1916b173622b8158b4a8..7aeaa394ebd0810f922f99dce626fa0d52ebf71a 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 #include "system/filesys.h"
+#include "popt_common.h"
 #include "dbwrap/dbwrap.h"
 #include "dbwrap/dbwrap_open.h"
 #include "messages.h"
@@ -214,12 +215,41 @@ int main(int argc, const char **argv)
 
        int ret = 1;
 
+       struct poptOption popt_options[] = {
+               POPT_AUTOHELP
+               POPT_COMMON_SAMBA
+               POPT_TABLEEND
+       };
+       int opt;
+       const char **extra_argv;
+       int extra_argc = 0;
+       poptContext pc;
+
        load_case_tables();
        lp_set_cmdline("log level", "0");
        setup_logging(argv[0], DEBUG_STDERR);
+
+       pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
+
+       while ((opt = poptGetNextOpt(pc)) != -1) {
+               switch (opt) {
+               default:
+                       fprintf(stderr, "Invalid option %s: %s\n",
+                               poptBadOption(pc, 0), poptStrerror(opt));
+                       goto done;
+               }
+       }
+
+       /* setup the remaining options for the main program to use */
+       extra_argv = poptGetArgs(pc);
+       if (extra_argv) {
+               extra_argv++;
+               while (extra_argv[extra_argc]) extra_argc++;
+       }
+
        lp_load_global(get_dyn_CONFIGFILE());
 
-       if ((argc < 3) || (argc > 6)) {
+       if ((extra_argc < 2) || (extra_argc > 5)) {
                d_fprintf(stderr,
                          "USAGE: %s <database> <op> [<key> [<type> [<value>]]]\n"
                          "       ops: fetch, store, delete, erase, listkeys\n"
@@ -228,45 +258,45 @@ int main(int argc, const char **argv)
                goto done;
        }
 
-       dbname = argv[1];
-       opname = argv[2];
+       dbname = extra_argv[0];
+       opname = extra_argv[1];
 
        if (strcmp(opname, "store") == 0) {
-               if (argc != 6) {
+               if (extra_argc != 5) {
                        d_fprintf(stderr, "ERROR: operation 'store' requires "
                                  "value argument\n");
                        goto done;
                }
-               valuestr = argv[5];
-               keytype = argv[4];
-               keyname = argv[3];
+               valuestr = extra_argv[4];
+               keytype = extra_argv[3];
+               keyname = extra_argv[2];
                op = OP_STORE;
        } else if (strcmp(opname, "fetch") == 0) {
-               if (argc != 5) {
+               if (extra_argc != 4) {
                        d_fprintf(stderr, "ERROR: operation 'fetch' requires "
                                  "type but not value argument\n");
                        goto done;
                }
                op = OP_FETCH;
-               keytype = argv[4];
-               keyname = argv[3];
+               keytype = extra_argv[3];
+               keyname = extra_argv[2];
        } else if (strcmp(opname, "delete") == 0) {
-               if (argc != 4) {
+               if (extra_argc != 3) {
                        d_fprintf(stderr, "ERROR: operation 'delete' does "
                                  "not allow type nor value argument\n");
                        goto done;
                }
-               keyname = argv[3];
+               keyname = extra_argv[2];
                op = OP_DELETE;
        } else if (strcmp(opname, "erase") == 0) {
-               if (argc != 3) {
+               if (extra_argc != 2) {
                        d_fprintf(stderr, "ERROR: operation 'erase' does "
                                  "not take a key argument\n");
                        goto done;
                }
                op = OP_ERASE;
        } else if (strcmp(opname, "listkeys") == 0) {
-               if (argc != 3) {
+               if (extra_argc != 2) {
                        d_fprintf(stderr, "ERROR: operation 'listkeys' does "
                                  "not take a key argument\n");
                        goto done;
index 4bedbfe0321b5f104f239ea1f9604e0e0be564f3..ff33c9948d3c91df88ac19e0cafae4f676a4e11c 100755 (executable)
@@ -1393,7 +1393,8 @@ bld.SAMBA3_BINARY('test_lp_load',
 
 bld.SAMBA3_BINARY('dbwrap_tool',
                  source=DBWRAP_TOOL_SRC,
-                 deps='''talloc tdb_compat tevent cap param smbd_shim LIBSMB_ERR''',
+                 deps='''talloc tdb_compat tevent cap param smbd_shim LIBSMB_ERR
+                popt_samba3''',
                  vars=locals())
 
 bld.SAMBA3_BINARY('dbwrap_torture',