From 6b4710b5f3c49759d920c570cd1aba16e356f168 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 13 Jan 2021 10:44:57 +0100 Subject: [PATCH] s3:utils: Migrate mdfind to new cmdline option parser The signing_state is correctly handled by --client-protection now! Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- source3/utils/mdsearch.c | 92 ++++++++++++++++--------------------- source3/utils/wscript_build | 4 +- 2 files changed, 42 insertions(+), 54 deletions(-) diff --git a/source3/utils/mdsearch.c b/source3/utils/mdsearch.c index 831f77f4314..ac0b75fca51 100644 --- a/source3/utils/mdsearch.c +++ b/source3/utils/mdsearch.c @@ -19,11 +19,9 @@ #include "includes.h" #include "lib/util/debug.h" -#include "popt_common.h" -#include "popt_common_cmdline.h" +#include "lib/cmdline/cmdline.h" #include "lib/cmdline_contexts.h" #include "param.h" -#include "auth_info.h" #include "client.h" #include "libsmb/proto.h" #include "librpc/rpc/rpc_common.h" @@ -34,33 +32,11 @@ static char *opt_path; static int opt_live; -static struct poptOption long_options[] = { - POPT_AUTOHELP - { - .longName = "path", - .shortName = 'p', - .argInfo = POPT_ARG_STRING, - .arg = &opt_path, - .descrip = "Server-relative search path", - }, - { - .longName = "live", - .shortName = 'L', - .argInfo = POPT_ARG_NONE, - .arg = &opt_live, - .descrip = "live query", - }, - POPT_COMMON_SAMBA - POPT_COMMON_CREDENTIALS - POPT_TABLEEND -}; - int main(int argc, char **argv) { const char **const_argv = discard_const_p(const char *, argv); TALLOC_CTX *frame = talloc_stackframe(); struct tevent_context *ev = NULL; - struct user_auth_info *auth = NULL; struct cli_credentials *creds = NULL; struct rpc_pipe_client *rpccli = NULL; struct mdscli_ctx *mdscli_ctx = NULL; @@ -71,7 +47,6 @@ int main(int argc, char **argv) struct cli_state *cli = NULL; char *basepath = NULL; uint32_t flags = CLI_FULL_CONNECTION_IPC; - int signing_state = SMB_SIGNING_IPC_DEFAULT; uint64_t *cnids = NULL; size_t ncnids; size_t i; @@ -80,15 +55,46 @@ int main(int argc, char **argv) NTSTATUS status; bool ok; - setup_logging(argv[0], DEBUG_STDERR); + struct poptOption long_options[] = { + POPT_AUTOHELP + { + .longName = "path", + .shortName = 'p', + .argInfo = POPT_ARG_STRING, + .arg = &opt_path, + .descrip = "Server-relative search path", + }, + { + .longName = "live", + .shortName = 'L', + .argInfo = POPT_ARG_NONE, + .arg = &opt_live, + .descrip = "live query", + }, + POPT_COMMON_SAMBA + POPT_COMMON_CREDENTIALS + POPT_LEGACY_S3 + POPT_COMMON_VERSION + POPT_TABLEEND + }; + smb_init_locale(); + + 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); + } lp_set_cmdline("log level", "1"); - pc = poptGetContext(argv[0], - argc, - const_argv, - long_options, - POPT_CONTEXT_KEEP_FIRST); + pc = samba_popt_get_context(getprogname(), + argc, + const_argv, + long_options, + POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "mdsearch [OPTIONS] \n"); @@ -110,7 +116,7 @@ int main(int argc, char **argv) goto fail; } - popt_burn_cmdline_password(argc, argv); + samba_cmdline_burn(argc, argv); if ((server[0] == '/' && server[1] == '/') || (server[0] == '\\' && server[1] == '\\')) @@ -118,19 +124,6 @@ int main(int argc, char **argv) server += 2; } - auth = popt_get_cmdline_auth_info(); - creds = get_cmdline_auth_info_creds(auth); - - signing_state = get_cmdline_auth_info_signing_state(auth); - switch (signing_state) { - case SMB_SIGNING_OFF: - lp_set_cmdline("client ipc signing", "no"); - break; - case SMB_SIGNING_REQUIRED: - lp_set_cmdline("client ipc signing", "required"); - break; - } - ev = samba_tevent_context_init(frame); if (ev == NULL) { goto fail; @@ -138,12 +131,7 @@ int main(int argc, char **argv) cmdline_messaging_context(get_dyn_CONFIGFILE()); - ok = lp_load_client(get_dyn_CONFIGFILE()); - if (!ok) { - fprintf(stderr, "ERROR: Can't load %s\n", - get_dyn_CONFIGFILE()); - exit(1); - } + creds = samba_cmdline_get_creds(); status = cli_full_connection_creds(&cli, lp_netbios_name(), diff --git a/source3/utils/wscript_build b/source3/utils/wscript_build index 4688994dfec..85bfe2f092f 100644 --- a/source3/utils/wscript_build +++ b/source3/utils/wscript_build @@ -314,8 +314,8 @@ bld.SAMBA3_BINARY('mdsearch', talloc tevent smbconf - popt_samba3 - popt_samba3_cmdline + CMDLINE_S3 + cmdline_contexts libsmb msrpc3 RPCCLI_MDSSVC