From c57ccd6df1b3d9243409bc0788bdf4a6ffebd6da Mon Sep 17 00:00:00 2001 From: josch Date: Wed, 17 Sep 2014 00:09:31 +0200 Subject: [PATCH] allow username and password as arguments to auth command --- cmd_auth.c | 24 +++++++++++++++++------- mfshell.c | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cmd_auth.c b/cmd_auth.c index 0c69ff7..d8aea2b 100644 --- a/cmd_auth.c +++ b/cmd_auth.c @@ -42,11 +42,6 @@ mfshell_cmd_auth(mfshell_t *mfshell, int argc, char **argv) if(mfshell == NULL) return -1; if(mfshell->server == NULL) return -1; - if (argc != 1) { - fprintf(stderr, "Invalid number of arguments\n"); - return -1; - } - // free and invalidate existing user name if(mfshell->user != NULL) { @@ -61,8 +56,23 @@ mfshell_cmd_auth(mfshell_t *mfshell, int argc, char **argv) mfshell->passwd = NULL; } - mfshell->user = _get_login_from_user(); - mfshell->passwd = _get_passwd_from_user(); + switch (argc) { + case 1: + mfshell->user = _get_login_from_user(); + mfshell->passwd = _get_passwd_from_user(); + break; + case 2: + mfshell->user = argv[1]; + mfshell->passwd = _get_passwd_from_user(); + break; + case 3: + mfshell->user = argv[1]; + mfshell->passwd = argv[2]; + break; + default: + fprintf(stderr, "Invalid number of arguments\n"); + return -1; + } if(mfshell->user == NULL || mfshell->passwd == NULL) return -1; diff --git a/mfshell.c b/mfshell.c index 60407e6..5b3bf1c 100644 --- a/mfshell.c +++ b/mfshell.c @@ -42,7 +42,7 @@ struct _cmd_s commands[] = { {"help", "", "show this help", mfshell_cmd_help}, {"debug", "", "show debug information", mfshell_cmd_debug}, {"host", "", "change target server", mfshell_cmd_host}, - {"auth", "", "authenticate with active server", + {"auth", ">", "authenticate with active server", mfshell_cmd_auth}, {"whoami", "", "show basic user info", mfshell_cmd_whoami}, {"ls", "", "show contents of active folder",