diff options
author | James Peach <jpeach@samba.org> | 2010-03-21 21:56:05 -0700 |
---|---|---|
committer | James Peach <jpeach@apple.com> | 2010-06-21 08:58:10 -0700 |
commit | bf35aa86038aa5bbf06bf73eb58cfa6fa1eae904 (patch) | |
tree | 86b8be128e4b665b8a3a44684ac4d440ece3e00e /source4 | |
parent | 3f398ec36d6b733c92682f5eb03eeacb047e582f (diff) | |
download | samba-bf35aa86038aa5bbf06bf73eb58cfa6fa1eae904.tar.gz samba-bf35aa86038aa5bbf06bf73eb58cfa6fa1eae904.tar.bz2 samba-bf35aa86038aa5bbf06bf73eb58cfa6fa1eae904.zip |
smbtorture: Add "auth" command to the shell.
Add a new "auth" command to set the cmdline credentials from withing
the smbtorture shell.
Diffstat (limited to 'source4')
-rw-r--r-- | source4/torture/shell.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/source4/torture/shell.c b/source4/torture/shell.c index 31efb28447..a0f9d7d3a3 100644 --- a/source4/torture/shell.c +++ b/source4/torture/shell.c @@ -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) { |