]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:utils: Migrate testparm to new cmdline option parser
authorAndreas Schneider <asn@samba.org>
Wed, 13 Jan 2021 08:54:52 +0000 (09:54 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 25 May 2021 00:23:37 +0000 (00:23 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/utils/testparm.c
source3/utils/wscript_build

index bb4957ef557728cbab7084c052a2badea42e1449..59ca8b700f3cbb60a0e237baafbb9a3eec5aeadb 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "includes.h"
 #include "system/filesys.h"
-#include "popt_common.h"
+#include "lib/cmdline/cmdline.h"
 #include "lib/param/loadparm.h"
 #include "lib/crypto/gnutls_helpers.h"
 #include "cmdline_contexts.h"
@@ -669,7 +669,7 @@ static void do_per_share_checks(int s)
 
  int main(int argc, const char *argv[])
 {
-       const char *config_file = get_dyn_CONFIGFILE();
+       const char *config_file = NULL;
        const struct loadparm_substitution *lp_sub =
                loadparm_s3_global_substitution();
        int s;
@@ -684,6 +684,7 @@ static void do_per_share_checks(int s)
        static int show_defaults;
        static int skip_logic_checks = 0;
        const char *weak_crypo_str = "";
+       bool ok;
 
        struct poptOption long_options[] = {
                POPT_AUTOHELP
@@ -736,15 +737,25 @@ static void do_per_share_checks(int s)
                        .val        = 0,
                        .descrip    = "Limit testparm to a named section",
                },
+               POPT_COMMON_DEBUG_ONLY
+               POPT_COMMON_OPTION_ONLY
                POPT_COMMON_VERSION
-               POPT_COMMON_DEBUGLEVEL
-               POPT_COMMON_OPTION
                POPT_TABLEEND
        };
 
        TALLOC_CTX *frame = talloc_stackframe();
 
        smb_init_locale();
+
+       ok = samba_cmdline_init(frame,
+                               SAMBA_CMDLINE_CONFIG_NONE,
+                               true /* require_smbconf */);
+       if (!ok) {
+               DBG_ERR("Failed to init cmdline parser!\n");
+               ret = 1;
+               goto done;
+       }
+
        /*
         * Set the default debug level to 1.
         * Allow it to be overridden by the command line,
@@ -752,8 +763,17 @@ static void do_per_share_checks(int s)
         */
        lp_set_cmdline("log level", "1");
 
-       pc = poptGetContext(NULL, argc, argv, long_options,
-                           POPT_CONTEXT_KEEP_FIRST);
+       pc = samba_popt_get_context(getprogname(),
+                                   argc,
+                                   argv,
+                                   long_options,
+                                   0);
+       if (pc == NULL) {
+               DBG_ERR("Failed to setup popt context!\n");
+               ret = 1;
+               goto done;
+       }
+
        poptSetOtherOptionHelp(pc, "[OPTION...] <config-file> [host-name] [host-ip]");
 
        while(poptGetNextOpt(pc) != -1);
@@ -763,10 +783,11 @@ static void do_per_share_checks(int s)
                exit(0);
        }
 
-       setup_logging(poptGetArg(pc), DEBUG_STDERR);
-
-       if (poptPeekArg(pc))
+       if (poptPeekArg(pc)) {
                config_file = poptGetArg(pc);
+       } else {
+               config_file = get_dyn_CONFIGFILE();
+       }
 
        cname = poptGetArg(pc);
        caddr = poptGetArg(pc);
index 1242a9f237e76d388af1031690f3e052148dc016..4688994dfec3850d4e8a3d43e8229696b2393012 100644 (file)
@@ -168,7 +168,7 @@ bld.SAMBA3_BINARY('testparm',
                  deps='''
                  talloc
                  smbconf
-                 popt_samba3
+                 CMDLINE_S3
                  cmdline_contexts
                  GNUTLS_HELPERS
                  ''')