smbtorture: Add "auth" command to the shell.
authorJames Peach <jpeach@samba.org>
Mon, 22 Mar 2010 04:56:05 +0000 (21:56 -0700)
committerJames Peach <jpeach@apple.com>
Mon, 21 Jun 2010 15:58:10 +0000 (08:58 -0700)
Add a new "auth" command to set the cmdline credentials from withing
the smbtorture shell.

source4/torture/shell.c

index 31efb28447cdc208edbd87aa900a19219fb6472c..a0f9d7d3a3e9ff27ff993cbc3f0a05011b8f5e83 100644 (file)
@@ -22,6 +22,8 @@
 #include "includes.h"
 #include "system/readline.h"
 #include "lib/smbreadline/smbreadline.h"
+#include "lib/cmdline/popt_common.h"
+#include "auth/credentials/credentials.h"
 #include "torture/smbtorture.h"
 
 struct shell_command;
@@ -39,6 +41,8 @@ static void shell_run(const struct shell_command *,
        struct torture_context *, int, const char **);
 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_usage(const struct shell_command *);
 static bool match_command(const char *, const struct shell_command *);
@@ -76,6 +80,12 @@ static const struct shell_command commands[] =
     {
        shell_run, "run", "[TESTNAME]",
        "run the specified test"
+    },
+
+    {
+       shell_auth, "auth",
+       "[[username | principal | domain | realm | password] STRING]",
+       "set authentication parameters"
     }
 };
 
@@ -87,6 +97,15 @@ void torture_shell(struct torture_context *tctx)
        int ret;
        int i;
 
+       /* If we don't have a specified password, specify it as empty. This
+        * 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);
+       }
+
        while (1) {
                cline = smb_readline("torture> ", NULL, NULL);
 
@@ -180,6 +199,60 @@ static void shell_list(const struct shell_command * command,
     torture_print_tests(true);
 }
 
+static void shell_auth(const struct shell_command * command,
+       struct torture_context *tctx, int argc, const char **argv)
+{
+
+    if (argc == 0) {
+           const char * username;
+           const char * domain;
+           const char * realm;
+           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);
+
+           printf("Username: %s\n", username ? username : "");
+           printf("User Principal: %s\n", principal ? principal : "");
+           printf("Domain: %s\n", domain ? domain : "");
+           printf("Realm: %s\n", realm ? realm : "");
+           printf("Password: %s\n", password ? password : "");
+    } else if (argc == 2) {
+           bool result;
+
+           if (!strcmp(argv[0], "username")) {
+                   result = cli_credentials_set_username(
+                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+           } else if (!strcmp(argv[0], "principal")) {
+                   result = cli_credentials_set_principal(
+                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+           } else if (!strcmp(argv[0], "domain")) {
+                   result = cli_credentials_set_domain(
+                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+           } else if (!strcmp(argv[0], "realm")) {
+                   result = cli_credentials_set_realm(
+                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+           } else if (!strcmp(argv[0], "password")) {
+                   result = cli_credentials_set_password(
+                       cmdline_credentials, argv[1], CRED_SPECIFIED);
+           } else {
+                   shell_usage(command);
+                   return;
+           }
+
+           if (!result) {
+                   printf("failed to set %s\n", argv[0]);
+           }
+    } else {
+           shell_usage(command);
+    }
+
+}
+
 static void shell_usage(const struct shell_command * command)
 {
     if (command->usage) {