aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 4165d2a3b..54b973775 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1051,24 +1051,34 @@ static void cleanarg(char *str)
#endif
}
-static void checkpasswd(const char *prompt, char **userpwd)
+static void checkpasswd(const char *kind, /* for what purpose */
+ char **userpwd) /* pointer to allocated string */
{
char *ptr = strchr(*userpwd, ':');
if(!ptr) {
/* no password present, prompt for one */
char passwd[256]="";
+ char prompt[256];
int passwdlen;
int userlen = strlen(*userpwd);
char *ptr;
+ /* build a nice-looking prompt */
+ curl_msnprintf(prompt, sizeof(prompt),
+ "Enter %s password for user '%s':",
+ kind, *userpwd);
+
+ /* get password */
getpass_r(prompt, passwd, sizeof(passwd));
passwdlen = strlen(passwd);
+ /* extend the allocated memory are to fit the password too */
ptr = realloc(*userpwd,
passwdlen + 1 + /* an extra for the colon */
userlen + 1); /* an extra for the zero */
if(ptr) {
+ /* append the password separated with a colon */
ptr[userlen]=':';
memcpy(&ptr[userlen+1], passwd, passwdlen+1);
*userpwd = ptr;
@@ -1834,13 +1844,13 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
/* user:password */
GetStr(&config->userpwd, nextarg);
cleanarg(nextarg);
- checkpasswd("Enter host password:", &config->userpwd);
+ checkpasswd("host", &config->userpwd);
break;
case 'U':
/* Proxy user:password */
GetStr(&config->proxyuserpwd, nextarg);
cleanarg(nextarg);
- checkpasswd("Enter proxy password:", &config->proxyuserpwd);
+ checkpasswd("proxy", &config->proxyuserpwd);
break;
case 'v':
config->conf ^= CONF_VERBOSE; /* talk a lot */