aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2003-10-16 14:09:39 +0000
committerDaniel Stenberg <daniel@haxx.se>2003-10-16 14:09:39 +0000
commitcadcc12169dc6e57362fcdb0dad763a237c5efc5 (patch)
tree8fd45ee9006271a1df48740dd5a81c3a6fb2c204 /src/main.c
parent22adcb9cd1d99858f10e55dc140ceb19d382eee5 (diff)
Added support for password prompting if only used name is given on the
command line.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c28
1 files changed, 28 insertions, 0 deletions
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 */