made the password prompt nicer
This commit is contained in:
Родитель
722ece4055
Коммит
8823679e70
16
src/main.c
16
src/main.c
|
@ -1051,24 +1051,34 @@ static void cleanarg(char *str)
|
||||||
#endif
|
#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, ':');
|
char *ptr = strchr(*userpwd, ':');
|
||||||
if(!ptr) {
|
if(!ptr) {
|
||||||
/* no password present, prompt for one */
|
/* no password present, prompt for one */
|
||||||
char passwd[256]="";
|
char passwd[256]="";
|
||||||
|
char prompt[256];
|
||||||
int passwdlen;
|
int passwdlen;
|
||||||
int userlen = strlen(*userpwd);
|
int userlen = strlen(*userpwd);
|
||||||
char *ptr;
|
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));
|
getpass_r(prompt, passwd, sizeof(passwd));
|
||||||
passwdlen = strlen(passwd);
|
passwdlen = strlen(passwd);
|
||||||
|
|
||||||
|
/* extend the allocated memory are to fit the password too */
|
||||||
ptr = realloc(*userpwd,
|
ptr = realloc(*userpwd,
|
||||||
passwdlen + 1 + /* an extra for the colon */
|
passwdlen + 1 + /* an extra for the colon */
|
||||||
userlen + 1); /* an extra for the zero */
|
userlen + 1); /* an extra for the zero */
|
||||||
|
|
||||||
if(ptr) {
|
if(ptr) {
|
||||||
|
/* append the password separated with a colon */
|
||||||
ptr[userlen]=':';
|
ptr[userlen]=':';
|
||||||
memcpy(&ptr[userlen+1], passwd, passwdlen+1);
|
memcpy(&ptr[userlen+1], passwd, passwdlen+1);
|
||||||
*userpwd = ptr;
|
*userpwd = ptr;
|
||||||
|
@ -1834,13 +1844,13 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
|
||||||
/* user:password */
|
/* user:password */
|
||||||
GetStr(&config->userpwd, nextarg);
|
GetStr(&config->userpwd, nextarg);
|
||||||
cleanarg(nextarg);
|
cleanarg(nextarg);
|
||||||
checkpasswd("Enter host password:", &config->userpwd);
|
checkpasswd("host", &config->userpwd);
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
/* Proxy user:password */
|
/* Proxy user:password */
|
||||||
GetStr(&config->proxyuserpwd, nextarg);
|
GetStr(&config->proxyuserpwd, nextarg);
|
||||||
cleanarg(nextarg);
|
cleanarg(nextarg);
|
||||||
checkpasswd("Enter proxy password:", &config->proxyuserpwd);
|
checkpasswd("proxy", &config->proxyuserpwd);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
config->conf ^= CONF_VERBOSE; /* talk a lot */
|
config->conf ^= CONF_VERBOSE; /* talk a lot */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче