]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli:nbt: Migrate nmblookup4 to new cmdline option parser
authorAndreas Schneider <asn@samba.org>
Thu, 14 Jan 2021 09:50:28 +0000 (10:50 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 20 Jun 2021 23:26:32 +0000 (23:26 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
libcli/nbt/tools/nmblookup.c
libcli/nbt/wscript_build

index 17ede19c8679049bca99324342572ab53f167e25..689240f90a4ddb68c7de7e5a0f6cb03f4a00ad49 100644 (file)
@@ -22,7 +22,7 @@
 */
 
 #include "includes.h"
-#include "lib/cmdline/popt_common.h"
+#include "lib/cmdline/cmdline.h"
 #include "lib/socket/socket.h"
 #include "lib/events/events.h"
 #include "system/network.h"
@@ -288,6 +288,9 @@ int main(int argc, const char *argv[])
        struct tevent_context *ev;
        poptContext pc;
        int opt;
+       struct loadparm_context *lp_ctx = NULL;
+       TALLOC_CTX *mem_ctx = NULL;
+       bool ok;
        enum {
                OPT_BROADCAST_ADDRESS   = 1000,
                OPT_UNICAST_ADDRESS,
@@ -373,11 +376,34 @@ int main(int argc, const char *argv[])
                        .argDescrip = NULL
                },
                POPT_COMMON_SAMBA
+               POPT_COMMON_VERSION
                POPT_TABLEEND
        };
 
-       pc = poptGetContext("nmblookup", argc, argv, long_options, 
-                           POPT_CONTEXT_KEEP_FIRST);
+       mem_ctx = talloc_init("nmblookup.c/main");
+       if (mem_ctx == NULL) {
+               exit(ENOMEM);
+       }
+
+       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, "<NODE> ...");
 
@@ -415,24 +441,28 @@ int main(int argc, const char *argv[])
 
        if(!poptPeekArg(pc)) { 
                poptPrintUsage(pc, stderr, 0);
+               TALLOC_FREE(mem_ctx);
                exit(1);
        }
 
-       load_interface_list(NULL, cmdline_lp_ctx, &ifaces);
+       lp_ctx = samba_cmdline_get_lp_ctx();
+
+       load_interface_list(mem_ctx, lp_ctx, &ifaces);
 
-       ev = s4_event_context_init(NULL);
+       ev = s4_event_context_init(mem_ctx);
 
        while (poptPeekArg(pc)) {
                const char *name = poptGetArg(pc);
 
-               ret &= process_one(cmdline_lp_ctx, ev, ifaces, name, lpcfg_nbt_port(cmdline_lp_ctx));
+               ret &= process_one(lp_ctx,
+                                  ev,
+                                  ifaces,
+                                  name,
+                                  lpcfg_nbt_port(lp_ctx));
        }
 
-       talloc_free(ev);
-
-       talloc_free(ifaces);
-
        poptFreeContext(pc);
+       TALLOC_FREE(mem_ctx);
 
        if (!ret) {
                return 1;
index 15610765268eb7270fe4be3ea1cad5828c5322ab..0e2a13f5623d48af5e82a3cddbe5190e57a0a3c9 100644 (file)
@@ -20,7 +20,7 @@ bld.SAMBA_LIBRARY('cli-nbt',
 bld.SAMBA_BINARY('nmblookup' + bld.env.suffix4,
                  source='tools/nmblookup.c',
                  manpages='man/nmblookup4.1',
-                 deps='samba-hostconfig samba-util cli-nbt popt POPT_SAMBA netif LIBCLI_RESOLVE',
+                 deps='samba-hostconfig samba-util cli-nbt popt CMDLINE_S4 netif LIBCLI_RESOLVE',
                  install=False,
                  )