]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:utils: Migrate mdfind to new cmdline option parser
authorAndreas Schneider <asn@samba.org>
Wed, 13 Jan 2021 09:44:57 +0000 (10:44 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 25 May 2021 00:23:37 +0000 (00:23 +0000)
The signing_state is correctly handled by --client-protection now!

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/utils/mdsearch.c
source3/utils/wscript_build

index 831f77f431422ed476558f45f4d7e858b70f97ff..ac0b75fca513b9dfbcf80b771b447ad26c37d1b7 100644 (file)
 
 #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"
 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] <server> <share> <query>\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(),
index 4688994dfec3850d4e8a3d43e8229696b2393012..85bfe2f092fc800a774a9c9aeef14aa17d65eee6 100644 (file)
@@ -314,8 +314,8 @@ bld.SAMBA3_BINARY('mdsearch',
                  talloc
                  tevent
                  smbconf
-                 popt_samba3
-                 popt_samba3_cmdline
+                 CMDLINE_S3
+                 cmdline_contexts
                  libsmb
                  msrpc3
                  RPCCLI_MDSSVC