Skip to content

Commit

Permalink
Add option to read password from standard input
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Andrew <nick@nick-andrew.net>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
nickandrew authored and David Woodhouse committed Oct 26, 2008
1 parent c68494d commit 4a0e4a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions http.c
Expand Up @@ -483,7 +483,7 @@ static int parse_form(struct openconnect_info *vpninfo, char *auth_id,
We know how to do it for 64-bit tokens, already. */
UI_add_input_string(ui, pass_form_prompt, UI_INPUT_FLAG_ECHO, password, 1, 9);
UI_add_input_string(ui, "SecurID PIN:", 0, tpin, 0, 9);
} else {
} else if (!vpninfo->password) {
/* No echo */
UI_add_input_string(ui, pass_form_prompt, 0, password, 1, 80);
}
Expand All @@ -503,7 +503,7 @@ static int parse_form(struct openconnect_info *vpninfo, char *auth_id,
return ret;
}

append_opt(body, bodylen, pass_form_id, password);
append_opt(body, bodylen, pass_form_id, vpninfo->password?:password);

return 0;
}
Expand Down
19 changes: 12 additions & 7 deletions main.c
Expand Up @@ -70,6 +70,7 @@ static struct option long_options[] = {
{"quiet", 0, 0, 'q'},
{"xmlconfig", 1, 0, 'x'},
{"cookie-on-stdin", 0, 0, '4'},
{"passwd-on-stdin", 0, 0, '5'},
{NULL, 0, 0, 0},
};

Expand All @@ -80,7 +81,7 @@ void usage(void)
printf(" -c, --certificate=CERT Use SSL client certificate CERT\n");
printf(" -k, --sslkey=KEY Use SSL private key file KEY\n");
printf(" -C, --cookie=COOKIE Use WebVPN cookie COOKIE\n");
printf(" --cookie-on-stdin First line of standard input is cookie\n");
printf(" --cookie-on-stdin Read cookie from standard input\n");
printf(" -d, --deflate Enable compression (default)\n");
printf(" -D, --no-deflate Disable compression\n");
printf(" -h, --help Display help text\n");
Expand All @@ -101,24 +102,25 @@ void usage(void)
printf(" --printcookie Print webvpn cookie before connecting\n");
printf(" --cafile=FILE Cert file for server verification\n");
printf(" --no-dtls Disable DTLS\n");
printf(" --passwd-on-stdin Read password from standard input\n");
exit(1);
}

static void read_stdin_cookie(struct openconnect_info *vpninfo)
static void read_stdin(char **string)
{
char *c = malloc(100);
if (!c) {
fprintf(stderr, "Allocation failure for cookie\n");
fprintf(stderr, "Allocation failure for string from stdin\n");
exit(1);
}
if (!fgets(c, 100, stdin)) {
perror("fgets (cookie)");
perror("fgets (stdin)");
exit(1);
}

vpninfo->cookie = c;
*string = c;

c = strchr(vpninfo->cookie, '\n');
c = strchr(*string, '\n');
if (c)
*c = 0;
}
Expand Down Expand Up @@ -176,7 +178,10 @@ int main(int argc, char **argv)
cookieonly = 2;
break;
case '4':
read_stdin_cookie(vpninfo);
read_stdin(&vpninfo->cookie);
break;
case '5':
read_stdin(&vpninfo->password);
break;
case 'C':
vpninfo->cookie = optarg;
Expand Down
3 changes: 2 additions & 1 deletion openconnect.h
Expand Up @@ -82,8 +82,9 @@ struct openconnect_info {
const char *xmlconfig;
char xmlsha1[(SHA_DIGEST_LENGTH * 2) + 1];
char *username;
char *password;

const char *cookie;
char *cookie;
struct vpn_option *cookies;
struct vpn_option *cstp_options;
struct vpn_option *dtls_options;
Expand Down

0 comments on commit 4a0e4a5

Please sign in to comment.