Skip to content

Commit

Permalink
main: Move username/password/authgroup vars into main.c
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
cernekee authored and David Woodhouse committed Dec 30, 2013
1 parent a8c1238 commit 90c5a08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
33 changes: 18 additions & 15 deletions main.c
Expand Up @@ -83,6 +83,10 @@ int nocertcheck;
int non_inter;
int cookieonly;

char *username;
char *password;
char *authgroup;

enum {
OPT_AUTHENTICATE = 0x100,
OPT_AUTHGROUP,
Expand Down Expand Up @@ -563,7 +567,7 @@ int main(int argc, char **argv)
vpninfo->cookie = NULL;
break;
case OPT_PASSWORD_ON_STDIN:
read_stdin(&vpninfo->password);
read_stdin(&password);
break;
case OPT_NO_PASSWD:
vpninfo->nopasswd = 1;
Expand All @@ -581,7 +585,7 @@ int main(int argc, char **argv)
vpninfo->dtls_ciphers = keep_config_arg();
break;
case OPT_AUTHGROUP:
vpninfo->authgroup = keep_config_arg();
authgroup = keep_config_arg();
break;
case 'b':
background = 1;
Expand Down Expand Up @@ -661,7 +665,7 @@ int main(int argc, char **argv)
vpninfo->script_tun = 1;
break;
case 'u':
vpninfo->username = keep_config_arg();
username = keep_config_arg();
break;
case 'U': {
char *strend;
Expand Down Expand Up @@ -1106,21 +1110,20 @@ static int process_auth_form(void *_vpninfo,
if (!select_opt->nr_choices)
continue;

if (vpninfo->authgroup &&
if (authgroup &&
!strcmp(opt->name, "group_list")) {
for (i = 0; i < select_opt->nr_choices; i++) {
choice = &select_opt->choices[i];

if (!strcmp(vpninfo->authgroup,
choice->label)) {
if (!strcmp(authgroup, choice->label)) {
opt->value = choice->name;
break;
}
}
if (!opt->value)
vpn_progress(vpninfo, PRG_ERR,
_("Auth choice \"%s\" not available\n"),
vpninfo->authgroup);
authgroup);
}
if (!opt->value && select_opt->nr_choices == 1) {
choice = &select_opt->choices[0];
Expand Down Expand Up @@ -1173,9 +1176,9 @@ static int process_auth_form(void *_vpninfo,
for (opt = form->opts; opt; opt = opt->next) {

if (opt->type == OC_FORM_OPT_TEXT) {
if (vpninfo->username &&
if (username &&
!strcmp(opt->name, "username")) {
opt->value = strdup(vpninfo->username);
opt->value = strdup(username);
if (!opt->value)
goto err;
} else if (non_inter) {
Expand All @@ -1199,10 +1202,10 @@ static int process_auth_form(void *_vpninfo,
}

} else if (opt->type == OC_FORM_OPT_PASSWORD) {
if (vpninfo->password &&
if (password &&
!strcmp(opt->name, "password")) {
opt->value = vpninfo->password;
vpninfo->password = NULL;
opt->value = password;
password = NULL;
if (!opt->value)
goto err;
} else if (non_inter) {
Expand Down Expand Up @@ -1239,9 +1242,9 @@ static int process_auth_form(void *_vpninfo,
}
}

if (vpninfo->password) {
free(vpninfo->password);
vpninfo->password = NULL;
if (password) {
free(password);
password = NULL;
}

return 0;
Expand Down
2 changes: 0 additions & 2 deletions openconnect-internal.h
Expand Up @@ -171,8 +171,6 @@ struct openconnect_info {
const char *servercert;
const char *xmlconfig;
char xmlsha1[(SHA1_SIZE * 2) + 1];
char *username;
char *password;
char *authgroup;
int nopasswd;
int xmlpost;
Expand Down

0 comments on commit 90c5a08

Please sign in to comment.