Ask for the password in the terminal if it is omitted in the command line.

This commit is contained in:
braga
2006-10-23 12:54:49 +00:00
parent 42bc0f59ea
commit 41ec6c20c1

42
ftpfs.c
View File

@@ -1214,6 +1214,45 @@ static void set_common_curl_stuff(CURL* easy) {
curl_easy_setopt_or_die(easy, CURLOPT_IPRESOLVE, ftpfs.ip_version);
}
static void checkpasswd(const char *kind, /* for what purpose */
char **userpwd) /* pointer to allocated string */
{
char *ptr;
if(!*userpwd)
return;
ptr = strchr(*userpwd, ':');
if(!ptr) {
/* no password present, prompt for one */
char *passwd;
char prompt[256];
size_t passwdlen;
size_t userlen = strlen(*userpwd);
char *passptr;
/* build a nice-looking prompt */
snprintf(prompt, sizeof(prompt),
"Enter %s password for user '%s':",
kind, *userpwd);
/* get password */
passwd = getpass(prompt);
passwdlen = strlen(passwd);
/* extend the allocated memory area to fit the password too */
passptr = realloc(*userpwd,
passwdlen + 1 + /* an extra for the colon */
userlen + 1); /* an extra for the zero */
if(passptr) {
/* append the password separated with a colon */
passptr[userlen]=':';
memcpy(&passptr[userlen+1], passwd, passwdlen+1);
*userpwd = passptr;
}
}
}
int main(int argc, char** argv) {
int res;
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
@@ -1249,6 +1288,9 @@ int main(int argc, char** argv) {
if (res == -1)
exit(1);
checkpasswd("host", &ftpfs.user);
checkpasswd("proxy", &ftpfs.proxy_user);
if (ftpfs.transform_symlinks && !ftpfs.mountpoint) {
fprintf(stderr, "cannot transform symlinks: no mountpoint given\n");
exit(1);