s4:torture: Migrate gentest to new cmdline option parser
authorAndreas Schneider <asn@samba.org>
Thu, 17 Dec 2020 15:25:08 +0000 (16:25 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 16 Jun 2021 00:34:38 +0000 (00:34 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/torture/gentest.c
source4/torture/wscript_build

index 76d0f9ca424befb8e70c713fd196cffe025186c4..bc336aac052ab3ea05f563298d35536760390d1c 100644 (file)
@@ -20,7 +20,7 @@
 */
 
 #include "includes.h"
-#include "lib/cmdline/popt_common.h"
+#include "lib/cmdline/cmdline.h"
 #include "lib/events/events.h"
 #include "system/time.h"
 #include "system/filesys.h"
@@ -3323,9 +3323,11 @@ int main(int argc, const char *argv[])
                POPT_COMMON_CONNECTION
                POPT_COMMON_CREDENTIALS
                POPT_COMMON_VERSION
-               {0}
+               POPT_LEGACY_S4
+               POPT_TABLEEND
        };
        TALLOC_CTX *mem_ctx = NULL;
+       bool ok;
 
        memset(&bad_smb2_handle, 0xFF, sizeof(bad_smb2_handle));
 
@@ -3341,12 +3343,29 @@ int main(int argc, const char *argv[])
                exit(1);
        }
 
-       pc = poptGetContext("gentest", argc, argv, long_options,
-                           POPT_CONTEXT_KEEP_FIRST);
+       ok = samba_cmdline_init(mem_ctx,
+                               SAMBA_CMDLINE_CONFIG_CLIENT,
+                               false /* require_smbconf */);
+       if (!ok) {
+               DBG_ERR("Failed to init cmdline parser!\n");
+               TALLOC_FREE(mem_ctx);
+               exit(1);
+       }
+
+       pc = samba_popt_get_context(getprogname(),
+                                   argc,
+                                   argv,
+                                   long_options,
+                                   POPT_CONTEXT_KEEP_FIRST);
+       if (pc == NULL) {
+               DBG_ERR("Failed to setup popt context!\n");
+               TALLOC_FREE(mem_ctx);
+               exit(1);
+       }
 
        poptSetOtherOptionHelp(pc, "<unc1> <unc2>");
 
-       lp_ctx = cmdline_lp_ctx;
+       lp_ctx = samba_cmdline_get_lp_ctx();
        servers[0].credentials = cli_credentials_init(mem_ctx);
        servers[1].credentials = cli_credentials_init(mem_ctx);
        cli_credentials_guess(servers[0].credentials, lp_ctx);
@@ -3355,7 +3374,7 @@ int main(int argc, const char *argv[])
        while((opt = poptGetNextOpt(pc)) != -1) {
                switch (opt) {
                case OPT_UNCLIST:
-                       lpcfg_set_cmdline(cmdline_lp_ctx, "torture:unclist", poptGetOptArg(pc));
+                       lpcfg_set_cmdline(lp_ctx, "torture:unclist", poptGetOptArg(pc));
                        break;
                case OPT_USER1:
                        cli_credentials_parse_string(servers[0].credentials,
index 4b3309a9ab4997c768f3866c71debfa9c76a232f..7f315ef3030fd49c896564279d0c7cdae18de740 100644 (file)
@@ -331,7 +331,7 @@ bld.SAMBA_BINARY('smbtorture',
 bld.SAMBA_BINARY('gentest',
        source='gentest.c',
        manpages='man/gentest.1',
-       deps='samba-hostconfig samba-util popt POPT_SAMBA POPT_CREDENTIALS LIBCLI_SMB smbclient-raw param_options'
+       deps='samba-hostconfig samba-util popt CMDLINE_S4 LIBCLI_SMB smbclient-raw param_options'
        )