From e407349f1961cc74e2042deaf801cc5606f0cc0e Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Wed, 27 Aug 2014 11:16:30 +0200 Subject: [PATCH 2/2] define openconnect_set_option_value() to set the value in oc_form_opt Signed-off-by: Nikos Mavrogiannopoulos --- auth.c | 33 +++++++++++++++++++++------------ main.c | 16 ++++++++-------- openconnect.h | 6 +++++- ssl.c | 4 ++-- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/auth.c b/auth.c index 1a8a3fa..6c43c53 100644 --- a/auth.c +++ b/auth.c @@ -42,6 +42,15 @@ static int can_gen_tokencode(struct openconnect_info *vpninfo, struct oc_auth_form *form, struct oc_form_opt *opt); static int do_gen_tokencode(struct openconnect_info *vpninfo, struct oc_auth_form *form); +int +openconnect_set_option_value(struct oc_form_opt *opt, const char *value) +{ + opt->value1 = strdup(value); + if (opt->value1 == NULL) + return -ENOMEM; + return 0; +} + static int append_opt(struct oc_text_buf *body, char *opt, char *name) { if (buf_error(body)) @@ -64,7 +73,7 @@ static int append_form_opts(struct openconnect_info *vpninfo, int ret; for (opt = form->opts; opt; opt = opt->next) { - ret = append_opt(body, opt->name, opt->value); + ret = append_opt(body, opt->name, opt->value1); if (ret) return ret; } @@ -75,7 +84,7 @@ static void free_opt(struct oc_form_opt *opt) { /* for SELECT options, opt->value is a pointer to oc_choice->name */ if (opt->type != OC_FORM_OPT_SELECT) - free(opt->value); + free(opt->value1); else { struct oc_form_opt_select *sel = (void *)opt; int i; @@ -247,7 +256,7 @@ static int parse_form(struct openconnect_info *vpninfo, struct oc_auth_form *for if (!strcmp(input_type, "hidden")) { opt->type = OC_FORM_OPT_HIDDEN; - opt->value = (char *)xmlGetProp(xml_node, (unsigned char *)"value"); + opt->value1 = (char *)xmlGetProp(xml_node, (unsigned char *)"value"); } else if (!strcmp(input_type, "text")) { opt->type = OC_FORM_OPT_TEXT; } else if (!strcmp(input_type, "password")) { @@ -678,8 +687,8 @@ void nuke_opt_values(struct oc_form_opt *opt) for (; opt; opt = opt->next) { if (opt->type == OC_FORM_OPT_TEXT || opt->type == OC_FORM_OPT_PASSWORD) { - free(opt->value); - opt->value = NULL; + free(opt->value1); + opt->value1 = NULL; } } } @@ -722,8 +731,8 @@ retry: opt->flags |= OC_FORM_OPT_IGNORE; else if (!strcmp(opt->name, "secondary_username") && second_auth) { if (auth_choice->secondary_username) { - free(opt->value); - opt->value = strdup(auth_choice->secondary_username); + free(opt->value1); + opt->value1 = strdup(auth_choice->secondary_username); } if (!auth_choice->secondary_username_editable) opt->flags |= OC_FORM_OPT_IGNORE; @@ -734,9 +743,9 @@ retry: if (ret == OC_FORM_RESULT_NEWGROUP && form->authgroup_opt && - form->authgroup_opt->form.value) { + form->authgroup_opt->form.value1) { free(vpninfo->authgroup); - vpninfo->authgroup = strdup(form->authgroup_opt->form.value); + vpninfo->authgroup = strdup(form->authgroup_opt->form.value1); if (!vpninfo->xmlpost) goto retry; @@ -987,7 +996,7 @@ static int xmlpost_append_form_opts(struct openconnect_info *vpninfo, for (opt = form->opts; opt; opt = opt->next) { /* group_list: create a new node under */ if (!strcmp(opt->name, "group_list")) { - if (!xmlNewTextChild(root, NULL, XCAST("group-select"), XCAST(opt->value))) + if (!xmlNewTextChild(root, NULL, XCAST("group-select"), XCAST(opt->value1))) goto bad; continue; } @@ -996,7 +1005,7 @@ static int xmlpost_append_form_opts(struct openconnect_info *vpninfo, if (!strcmp(opt->name, "answer") || !strcmp(opt->name, "whichpin") || !strcmp(opt->name, "new_password")) { - if (!xmlNewTextChild(node, NULL, XCAST("password"), XCAST(opt->value))) + if (!xmlNewTextChild(node, NULL, XCAST("password"), XCAST(opt->value1))) goto bad; continue; } @@ -1008,7 +1017,7 @@ static int xmlpost_append_form_opts(struct openconnect_info *vpninfo, } /* everything else: create user_input under */ - if (!xmlNewTextChild(node, NULL, XCAST(opt->name), XCAST(opt->value))) + if (!xmlNewTextChild(node, NULL, XCAST(opt->name), XCAST(opt->value1))) goto bad; } diff --git a/main.c b/main.c index 8c5a18a..a0e8bf3 100644 --- a/main.c +++ b/main.c @@ -1597,7 +1597,7 @@ static int match_choice_label(struct openconnect_info *vpninfo, if (!strncasecmp(label, choice->label, input_len)) { if (strlen(choice->label) == input_len) { - select_opt->form.value = choice->name; + select_opt->form.value1 = choice->name; return 0; } else { match = choice->name; @@ -1607,7 +1607,7 @@ static int match_choice_label(struct openconnect_info *vpninfo, } if (partial_matches == 1) { - select_opt->form.value = match; + select_opt->form.value1 = match; return 0; } else if (partial_matches > 1) { vpn_progress(vpninfo, PRG_ERR, @@ -1736,26 +1736,26 @@ static int process_auth_form_cb(void *_vpninfo, } else if (opt->type == OC_FORM_OPT_TEXT) { if (username && !strcmp(opt->name, "username")) { - opt->value = username; + opt->value1 = username; username = NULL; } else { - opt->value = prompt_for_input(opt->label, vpninfo, 0); + opt->value1 = prompt_for_input(opt->label, vpninfo, 0); } - if (!opt->value) + if (!opt->value1) goto err; empty = 0; } else if (opt->type == OC_FORM_OPT_PASSWORD) { if (password && !strcmp(opt->name, "password")) { - opt->value = password; + opt->value1 = password; password = NULL; } else { - opt->value = prompt_for_input(opt->label, vpninfo, 1); + opt->value1 = prompt_for_input(opt->label, vpninfo, 1); } - if (!opt->value) + if (!opt->value1) goto err; empty = 0; } diff --git a/openconnect.h b/openconnect.h index 913b38c..a72e396 100644 --- a/openconnect.h +++ b/openconnect.h @@ -149,11 +149,15 @@ struct oc_form_opt { int type; char *name; char *label; - char *value; + char *value1; unsigned int flags; void *reserved; }; +/* To set the value to a form use the following function */ +int +openconnect_set_option_value(struct oc_form_opt *opt, const char *value); + /* All fields are static, owned by the XML parser */ struct oc_choice { char *name; diff --git a/ssl.c b/ssl.c index ebce5fc..6330daa 100644 --- a/ssl.c +++ b/ssl.c @@ -357,11 +357,11 @@ int request_passphrase(struct openconnect_info *vpninfo, const char *label, o.type = OC_FORM_OPT_PASSWORD; o.name = (char *)label; o.label = buf; - o.value = NULL; + o.value1 = NULL; ret = process_auth_form(vpninfo, &f); if (!ret) { - *response = o.value; + *response = o.value1; return 0; } -- 1.9.3