s4: popt: Global replace of cmdline_credentials -> popt_get_cmdline_credentials().
[gd/samba-autobuild/.git] / source4 / torture / shell.c
index 888097de7fa4657110ba6410bd8200e63588427f..5a4eb5c1d6a1b60482ffaf8704e5bab66ee94ef4 100644 (file)
 
 #include "includes.h"
 #include "system/readline.h"
-#include "lib/smbreadline/smbreadline.h"
+#include "../libcli/smbreadline/smbreadline.h"
 #include "lib/cmdline/popt_common.h"
 #include "auth/credentials/credentials.h"
 #include "torture/smbtorture.h"
+#include "param/param.h"
 
 struct shell_command;
 
@@ -43,6 +44,8 @@ static void shell_list(const struct shell_command *,
        struct torture_context *, int, const char **);
 static void shell_auth(const struct shell_command *,
        struct torture_context *, int, const char **);
+static void shell_target(const struct shell_command *,
+       struct torture_context *, int, const char **);
 
 static void shell_usage(const struct shell_command *);
 static bool match_command(const char *, const struct shell_command *);
@@ -86,6 +89,11 @@ static const struct shell_command commands[] =
     {
        shell_set, "set", "[NAME VALUE]",
        "print or set test configuration parameters"
+    },
+
+    {
+       shell_target, "target", "[TARGET]",
+       "print or set the test target"
     }
 
 };
@@ -102,10 +110,8 @@ void torture_shell(struct torture_context *tctx)
         * stops the credentials system prompting when we use the "auth"
         * command to display the current auth parameters.
         */
-       if (cmdline_credentials->password_obtained != CRED_SPECIFIED) {
-           cli_credentials_set_password(cmdline_credentials, "",
-                   CRED_SPECIFIED);
-       }
+       cli_credentials_set_password(popt_get_cmdline_credentials(),
+                       "", CRED_GUESS_ENV);
 
        while (1) {
                cline = smb_readline("torture> ", NULL, NULL);
@@ -167,19 +173,20 @@ static void shell_help(const struct shell_command * command,
 static void shell_set(const struct shell_command *command,
        struct torture_context *tctx, int argc, const char **argv)
 {
-       char * name;
-
        switch (argc) {
        case 0:
-           lp_dump(tctx->lp_ctx, stdout,
+           lpcfg_dump(tctx->lp_ctx, stdout,
                    false /* show_defaults */,
                    0 /* skip services */);
            break;
 
        case 2:
-           name = talloc_asprintf(NULL, "torture:%s", argv[0]);
-           lp_set_cmdline(tctx->lp_ctx, name, argv[1]);
-           talloc_free(name);
+           /* We want to allow users to set any config option. Top level
+            * options will get checked against their static definition, but
+            * parametric options can't be checked and will just get stashed
+            * as they are provided.
+            */
+           lpcfg_set_cmdline(tctx->lp_ctx, argv[0], argv[1]);
            break;
 
        default:
@@ -206,7 +213,7 @@ static void shell_list(const struct shell_command * command,
        return;
     }
 
-    torture_print_tests(true);
+    torture_print_testsuites(true);
 }
 
 static void shell_auth(const struct shell_command * command,
@@ -220,11 +227,14 @@ static void shell_auth(const struct shell_command * command,
            const char * password;
            const char * principal;
 
-           username = cli_credentials_get_username(cmdline_credentials);
-           principal = cli_credentials_get_principal(cmdline_credentials, tctx);
-           domain = cli_credentials_get_domain(cmdline_credentials);
-           realm = cli_credentials_get_realm(cmdline_credentials);
-           password = cli_credentials_get_password(cmdline_credentials);
+           username = cli_credentials_get_username(
+                       popt_get_cmdline_credentials());
+           principal = cli_credentials_get_principal(
+                               popt_get_cmdline_credentials(), tctx);
+           domain = cli_credentials_get_domain(popt_get_cmdline_credentials());
+           realm = cli_credentials_get_realm(popt_get_cmdline_credentials());
+           password = cli_credentials_get_password(
+                               popt_get_cmdline_credentials());
 
            printf("Username: %s\n", username ? username : "");
            printf("User Principal: %s\n", principal ? principal : "");
@@ -236,19 +246,24 @@ static void shell_auth(const struct shell_command * command,
 
            if (!strcmp(argv[0], "username")) {
                    result = cli_credentials_set_username(
-                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+                       popt_get_cmdline_credentials(),
+                       argv[1], CRED_SPECIFIED);
            } else if (!strcmp(argv[0], "principal")) {
                    result = cli_credentials_set_principal(
-                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+                       popt_get_cmdline_credentials(),
+                       argv[1], CRED_SPECIFIED);
            } else if (!strcmp(argv[0], "domain")) {
                    result = cli_credentials_set_domain(
-                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+                       popt_get_cmdline_credentials(),
+                       argv[1], CRED_SPECIFIED);
            } else if (!strcmp(argv[0], "realm")) {
                    result = cli_credentials_set_realm(
-                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+                       popt_get_cmdline_credentials(),
+                       argv[1], CRED_SPECIFIED);
            } else if (!strcmp(argv[0], "password")) {
                    result = cli_credentials_set_password(
-                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+                       popt_get_cmdline_credentials(),
+                       argv[1], CRED_SPECIFIED);
            } else {
                    shell_usage(command);
                    return;
@@ -263,6 +278,28 @@ static void shell_auth(const struct shell_command * command,
 
 }
 
+static void shell_target(const struct shell_command *command,
+       struct torture_context *tctx, int argc, const char **argv)
+{
+       if (argc == 0) {
+               const char * host;
+               const char * share;
+               const char * binding;
+
+               host = torture_setting_string(tctx, "host", NULL);
+               share = torture_setting_string(tctx, "share", NULL);
+               binding = torture_setting_string(tctx, "binding", NULL);
+
+               printf("Target host: %s\n", host ? host : "");
+               printf("Target share: %s\n", share ? share : "");
+               printf("Target binding: %s\n", binding ? binding : "");
+       } else if (argc == 1) {
+               torture_parse_target(tctx, tctx->lp_ctx, argv[0]);
+       } else {
+               shell_usage(command);
+       }
+}
+
 static void shell_usage(const struct shell_command * command)
 {
     if (command->usage) {
@@ -287,4 +324,3 @@ static bool match_command(const char * name,
 
        return false;
 }
-