From c96e94fbef83ed2658ea08eb17cfcab19de89371 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 13 Jan 2021 10:57:36 +0100 Subject: [PATCH] s3:utils: Migrate ntlm_auth to new cmdline option parser Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- source3/utils/ntlm_auth.c | 48 ++++++++++++++++--------------------- source3/utils/wscript_build | 2 +- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c index d833ee90b35..2ac8d3cba5c 100644 --- a/source3/utils/ntlm_auth.c +++ b/source3/utils/ntlm_auth.c @@ -26,7 +26,7 @@ #include "includes.h" #include "lib/param/param.h" -#include "popt_common.h" +#include "lib/cmdline/cmdline.h" #include "libcli/security/security.h" #include "utils/ntlm_auth.h" #include "../libcli/auth/libcli_auth.h" @@ -2531,6 +2531,7 @@ enum { const char *hex_nt_response = NULL; struct loadparm_context *lp_ctx; poptContext pc; + bool ok; /* NOTE: DO NOT change this interface without considering the implications! This is an external interface, which other programs will use to interact @@ -2687,45 +2688,36 @@ enum { .val = OPT_TARGET_HOSTNAME, .descrip = "Target hostname", }, - POPT_COMMON_CONFIGFILE + POPT_COMMON_DEBUG_ONLY + POPT_COMMON_CONFIG_ONLY + POPT_COMMON_OPTION_ONLY POPT_COMMON_VERSION - POPT_COMMON_OPTION POPT_TABLEEND }; /* Samba client initialisation */ smb_init_locale(); - setup_logging("ntlm_auth", DEBUG_STDERR); - fault_setup(); - - /* Parse options */ - - pc = poptGetContext("ntlm_auth", argc, argv, long_options, 0); - - /* Parse command line options */ - - if (argc == 1) { - poptPrintHelp(pc, stderr, 0); - poptFreeContext(pc); - return 1; - } - - while((opt = poptGetNextOpt(pc)) != -1) { - /* Get generic config options like --configfile */ + ok = samba_cmdline_init(frame, + SAMBA_CMDLINE_CONFIG_CLIENT, + false /* require_smbconf */); + if (!ok) { + DBG_ERR("Failed to init cmdline parser!\n"); + TALLOC_FREE(frame); + exit(1); } - poptFreeContext(pc); - - if (!lp_load_global(get_dyn_CONFIGFILE())) { - d_fprintf(stderr, "ntlm_auth: error opening config file %s. Error was %s\n", - get_dyn_CONFIGFILE(), strerror(errno)); + 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(frame); exit(1); } - pc = poptGetContext(NULL, argc, (const char **)argv, long_options, - POPT_CONTEXT_KEEP_FIRST); - while((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_CHALLENGE: diff --git a/source3/utils/wscript_build b/source3/utils/wscript_build index 85bfe2f092f..b9a5facb65c 100644 --- a/source3/utils/wscript_build +++ b/source3/utils/wscript_build @@ -127,7 +127,7 @@ bld.SAMBA3_BINARY('ntlm_auth', krb5samba tiniparser libsmb - popt_samba3 + CMDLINE_S3 cmdline_contexts gse gensec''') -- 2.47.3