[PATCH/RFC V3 06/13] Create a common process_auth_form() wrapper function
Kevin Cernekee
cernekee at gmail.com
Sun Dec 15 01:42:57 EST 2013
This will be used to translate between internal library structs and
public structs.
Signed-off-by: Kevin Cernekee <cernekee at gmail.com>
---
auth.c | 25 ++++++++++++-------------
gnutls.c | 2 +-
openconnect-internal.h | 2 ++
openssl.c | 2 +-
ssl.c | 5 +----
5 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/auth.c b/auth.c
index c957897..7bd2641 100644
--- a/auth.c
+++ b/auth.c
@@ -579,6 +579,15 @@ int parse_xml_response(struct openconnect_info *vpninfo, char *response, struct
return ret;
}
+int process_auth_form(struct openconnect_info *vpninfo, struct __oc_auth_form *form)
+{
+ if (!vpninfo->process_auth_form) {
+ vpn_progress(vpninfo, PRG_ERR, _("No form handler; cannot authenticate.\n"));
+ return OC_FORM_RESULT_ERR;
+ }
+ return vpninfo->process_auth_form(vpninfo->cbdata, form);
+}
+
/* Return value:
* < 0, on error
* = OC_FORM_RESULT_OK (0), when form parsed and POST required
@@ -621,12 +630,7 @@ int handle_auth_form(struct openconnect_info *vpninfo, struct __oc_auth_form *fo
return -EPERM;
}
- if (vpninfo->process_auth_form)
- ret = vpninfo->process_auth_form(vpninfo->cbdata, form);
- else {
- vpn_progress(vpninfo, PRG_ERR, _("No form handler; cannot authenticate.\n"));
- ret = OC_FORM_RESULT_CANCELLED;
- }
+ ret = process_auth_form(vpninfo, form);
if (ret)
return ret;
@@ -944,11 +948,11 @@ int prepare_stoken(struct openconnect_info *vpninfo)
if (!opts[0].type) {
/* don't bug the user if there's nothing to enter */
ret = 0;
- } else if (vpninfo->process_auth_form) {
+ } else {
int some_empty = 0, all_empty = 1;
/* < 0 for error; 1 if cancelled */
- ret = vpninfo->process_auth_form(vpninfo->cbdata, &form);
+ ret = process_auth_form(vpninfo, &form);
if (ret)
break;
@@ -970,11 +974,6 @@ int prepare_stoken(struct openconnect_info *vpninfo)
_("All fields are required; try again.\n"));
continue;
}
- } else {
- vpn_progress(vpninfo, PRG_ERR,
- _("No form handler; cannot authenticate.\n"));
- ret = -EIO;
- break;
}
ret = stoken_decrypt_seed(vpninfo->stoken_ctx,
diff --git a/gnutls.c b/gnutls.c
index 5c56c3d..852e061 100644
--- a/gnutls.c
+++ b/gnutls.c
@@ -2183,7 +2183,7 @@ static P11KitPin *pin_callback(const char *pin_source, P11KitUri *pin_uri,
o.label = (char *)_("Enter PIN:");
o.value = NULL;
- ret = vpninfo->process_auth_form(vpninfo->cbdata, &f);
+ ret = process_auth_form(vpninfo, &f);
if (ret || !o.value)
return NULL;
diff --git a/openconnect-internal.h b/openconnect-internal.h
index 0dc1175..7048c0f 100644
--- a/openconnect-internal.h
+++ b/openconnect-internal.h
@@ -438,6 +438,8 @@ int config_lookup_host(struct openconnect_info *vpninfo, const char *host);
/* auth.c */
int parse_xml_response(struct openconnect_info *vpninfo, char *response,
struct __oc_auth_form **form, int *cert_rq);
+int process_auth_form(struct openconnect_info *vpninfo,
+ struct __oc_auth_form *form);
int handle_auth_form(struct openconnect_info *vpninfo, struct __oc_auth_form *form,
char *request_body, int req_len, const char **method,
const char **request_body_type);
diff --git a/openssl.c b/openssl.c
index d79e8af..dda102c 100644
--- a/openssl.c
+++ b/openssl.c
@@ -306,7 +306,7 @@ static int ui_flush(UI *ui)
struct ui_form_opt *opt;
int ret;
- ret = vpninfo->process_auth_form(vpninfo->cbdata, &ui_data->form);
+ ret = process_auth_form(vpninfo, &ui_data->form);
if (ret)
return 0;
diff --git a/ssl.c b/ssl.c
index f8dd361..7c1f194 100644
--- a/ssl.c
+++ b/ssl.c
@@ -318,9 +318,6 @@ int request_passphrase(struct openconnect_info *vpninfo, const char *label,
va_list args;
int ret;
- if (!vpninfo->process_auth_form)
- return -EINVAL;
-
buf[1023] = 0;
memset(&f, 0, sizeof(f));
va_start(args, fmt);
@@ -336,7 +333,7 @@ int request_passphrase(struct openconnect_info *vpninfo, const char *label,
o.label = buf;
o.value = NULL;
- ret = vpninfo->process_auth_form(vpninfo->cbdata, &f);
+ ret = process_auth_form(vpninfo, &f);
if (!ret) {
*response = o.value;
return 0;
--
1.7.9.5
More information about the openconnect-devel
mailing list