From cadcc12169dc6e57362fcdb0dad763a237c5efc5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Oct 2003 14:09:39 +0000 Subject: Added support for password prompting if only used name is given on the command line. --- src/main.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 9015362c3..4165d2a3b 100644 --- a/src/main.c +++ b/src/main.c @@ -40,6 +40,7 @@ #include "urlglob.h" #include "writeout.h" +#include "getpass.h" #ifdef USE_ENVIRONMENT #include "writeenv.h" #endif @@ -1050,6 +1051,31 @@ static void cleanarg(char *str) #endif } +static void checkpasswd(const char *prompt, char **userpwd) +{ + char *ptr = strchr(*userpwd, ':'); + if(!ptr) { + /* no password present, prompt for one */ + char passwd[256]=""; + int passwdlen; + int userlen = strlen(*userpwd); + char *ptr; + + getpass_r(prompt, passwd, sizeof(passwd)); + passwdlen = strlen(passwd); + + ptr = realloc(*userpwd, + passwdlen + 1 + /* an extra for the colon */ + userlen + 1); /* an extra for the zero */ + + if(ptr) { + ptr[userlen]=':'; + memcpy(&ptr[userlen+1], passwd, passwdlen+1); + *userpwd = ptr; + } + } +} + static ParameterError getparameter(char *flag, /* f or -long-flag */ char *nextarg, /* NULL if unset */ bool *usedarg, /* set to TRUE if the arg @@ -1808,11 +1834,13 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */ /* user:password */ GetStr(&config->userpwd, nextarg); cleanarg(nextarg); + checkpasswd("Enter host password:", &config->userpwd); break; case 'U': /* Proxy user:password */ GetStr(&config->proxyuserpwd, nextarg); cleanarg(nextarg); + checkpasswd("Enter proxy password:", &config->proxyuserpwd); break; case 'v': config->conf ^= CONF_VERBOSE; /* talk a lot */ -- cgit v1.2.3