made the password prompt nicer

This commit is contained in:
Daniel Stenberg 2003-10-17 07:04:56 +00:00
Родитель 722ece4055
Коммит 8823679e70
1 изменённых файлов: 13 добавлений и 3 удалений

Просмотреть файл

@ -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 */