From: Andreas Schneider Date: Wed, 13 Jan 2021 08:54:52 +0000 (+0100) Subject: s3:utils: Migrate testparm to new cmdline option parser X-Git-Tag: tevent-0.11.0~757 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e63bf24d89ad7d5930efc3fa2ac4dc66ecad04a2;p=thirdparty%2Fsamba.git s3:utils: Migrate testparm to new cmdline option parser Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c index bb4957ef557..59ca8b700f3 100644 --- a/source3/utils/testparm.c +++ b/source3/utils/testparm.c @@ -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...] [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); diff --git a/source3/utils/wscript_build b/source3/utils/wscript_build index 1242a9f237e..4688994dfec 100644 --- a/source3/utils/wscript_build +++ b/source3/utils/wscript_build @@ -168,7 +168,7 @@ bld.SAMBA3_BINARY('testparm', deps=''' talloc smbconf - popt_samba3 + CMDLINE_S3 cmdline_contexts GNUTLS_HELPERS ''')