s3:utils: Migrate ntlm_auth to new cmdline option parser
authorAndreas Schneider <asn@samba.org>
Wed, 13 Jan 2021 09:57:36 +0000 (10:57 +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/ntlm_auth.c
source3/utils/wscript_build

index d833ee90b35138fa6f460796dbaced237815e660..2ac8d3cba5cbdc2c9121fbfd35da6b46bb6c0e8f 100644 (file)
@@ -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:
index 85bfe2f092fc800a774a9c9aeef14aa17d65eee6..b9a5facb65c241438e4df7b75c7cf6e0fda655e3 100644 (file)
@@ -127,7 +127,7 @@ bld.SAMBA3_BINARY('ntlm_auth',
                  krb5samba
                  tiniparser
                  libsmb
-                 popt_samba3
+                 CMDLINE_S3
                  cmdline_contexts
                  gse gensec''')