allow username and password as arguments to auth command

This commit is contained in:
josch
2014-09-17 00:09:31 +02:00
parent 08b808f893
commit c57ccd6df1
2 changed files with 18 additions and 8 deletions

View File

@@ -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;

View File

@@ -42,7 +42,7 @@ struct _cmd_s commands[] = {
{"help", "", "show this help", mfshell_cmd_help},
{"debug", "", "show debug information", mfshell_cmd_debug},
{"host", "<server>", "change target server", mfshell_cmd_host},
{"auth", "", "authenticate with active server",
{"auth", "<user <pass>>", "authenticate with active server",
mfshell_cmd_auth},
{"whoami", "", "show basic user info", mfshell_cmd_whoami},
{"ls", "", "show contents of active folder",