From: Andreas Schneider Date: Thu, 14 Jan 2021 09:50:28 +0000 (+0100) Subject: libcli:nbt: Migrate nmblookup4 to new cmdline option parser X-Git-Tag: tevent-0.11.0~280 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e520feace893411522bf02718dd91d12de91074;p=thirdparty%2Fsamba.git libcli:nbt: Migrate nmblookup4 to new cmdline option parser Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/libcli/nbt/tools/nmblookup.c b/libcli/nbt/tools/nmblookup.c index 17ede19c867..689240f90a4 100644 --- a/libcli/nbt/tools/nmblookup.c +++ b/libcli/nbt/tools/nmblookup.c @@ -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, " ..."); @@ -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; diff --git a/libcli/nbt/wscript_build b/libcli/nbt/wscript_build index 15610765268..0e2a13f5623 100644 --- a/libcli/nbt/wscript_build +++ b/libcli/nbt/wscript_build @@ -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, )