mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
- when either username or password are not specified via commandline arguments or configuration file, ask them on standard input - unify function to read username and password - move function to read username and password from mfshell to utils/strings.c - remove commented cruft from utils/strings.c
73 lines
2.1 KiB
C
73 lines
2.1 KiB
C
/*
|
|
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
|
* 2014 Johannes Schauer <j.schauer@email.de>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2, as published by
|
|
* the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
|
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "../mfshell.h"
|
|
#include "../../utils/strings.h"
|
|
#include "../../mfapi/mfconn.h"
|
|
#include "../commands.h" // IWYU pragma: keep
|
|
|
|
int mfshell_cmd_auth(mfshell * mfshell, int argc, char *const argv[])
|
|
{
|
|
char *username;
|
|
char *password;
|
|
|
|
if (mfshell == NULL)
|
|
return -1;
|
|
if (mfshell->server == NULL)
|
|
return -1;
|
|
|
|
switch (argc) {
|
|
case 1:
|
|
printf("login: ");
|
|
username = string_line_from_stdin(false);
|
|
printf("passwd: ");
|
|
password = string_line_from_stdin(true);
|
|
break;
|
|
case 2:
|
|
username = argv[1];
|
|
printf("passwd: ");
|
|
password = string_line_from_stdin(true);
|
|
break;
|
|
case 3:
|
|
username = argv[1];
|
|
password = argv[2];
|
|
break;
|
|
default:
|
|
fprintf(stderr, "Invalid number of arguments\n");
|
|
return -1;
|
|
}
|
|
|
|
if (username == NULL || password == NULL)
|
|
return -1;
|
|
|
|
mfshell->conn = mfconn_create(mfshell->server, username, password,
|
|
mfshell->app_id, mfshell->app_key);
|
|
|
|
if (mfshell->conn != NULL)
|
|
printf("\n\rAuthentication SUCCESS\n\r");
|
|
else
|
|
printf("\n\rAuthentication FAILURE\n\r");
|
|
|
|
return (mfshell->conn != NULL);
|
|
}
|