]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
make .sso_detect_done a protocol-specific VFN, and use in openconnect_webview_load_ch...
authorDaniel Lenski <dlenski@gmail.com>
Tue, 5 Jan 2021 18:40:39 +0000 (10:40 -0800)
committerLuca Boccassi <bluca@debian.org>
Wed, 23 Feb 2022 19:22:53 +0000 (19:22 +0000)
Also changes the "keep going" return value to -EAGAIN.

Signed-off-by: Daniel Lenski <dlenski@gmail.com>
cstp.c
library.c
openconnect-internal.h

diff --git a/cstp.c b/cstp.c
index 0b7a09301a4a667fd547be99a0ff8e5406ff3725..81ea1fefb2157db1c8700c9a37ce2308c75236bc 100644 (file)
--- a/cstp.c
+++ b/cstp.c
@@ -1248,3 +1248,28 @@ void cstp_common_headers(struct openconnect_info *vpninfo, struct oc_text_buf *b
 
        append_mobile_headers(vpninfo, buf);
 }
+
+int cstp_sso_detect_done(struct openconnect_info *vpninfo,
+                        const struct oc_webview_result *result)
+{
+       int i;
+
+       /* If we're not at the final URI, tell the webview to keep going */
+       if (strcmp(result->uri, vpninfo->sso_login_final))
+               return -EAGAIN;
+
+       for (i=0; result->cookies[i] != NULL; i+=2) {
+               const char *cname = result->cookies[i], *cval = result->cookies[i+1];
+               if (!strcmp(vpninfo->sso_token_cookie, cname)) {
+                       vpninfo->sso_cookie_value = strdup(cval);
+                       break;
+               } else if (!strcmp(vpninfo->sso_error_cookie, cname)) {
+                       /* XX: or should we combine both the error cookie name and its value? */
+                       vpninfo->quit_reason = strdup(cval);
+                       return -EINVAL;
+               }
+       }
+
+       /* Tell the webview to terminate */
+       return 0;
+}
index 9e21cab92293a22c9d1c1e8e015eef935de2b69f..79532e0cc88a0c46f7c522132be2602cf8b6dd8a 100644 (file)
--- a/library.c
+++ b/library.c
@@ -130,6 +130,7 @@ static const struct vpn_proto openconnect_protos[] = {
                .tcp_mainloop = cstp_mainloop,
                .add_http_headers = cstp_common_headers,
                .obtain_cookie = cstp_obtain_cookie,
+               .sso_detect_done = cstp_sso_detect_done,
                .secure_cookie = "webvpn",
                .udp_protocol = "DTLS",
 #ifdef HAVE_DTLS
@@ -1624,21 +1625,11 @@ void openconnect_set_webview_callback(struct openconnect_info *vpninfo,
 int openconnect_webview_load_changed(struct openconnect_info *vpninfo,
                                      const struct oc_webview_result *result)
 {
-    int i;
-
-    // If we're not at the final URI, tell the webview to keep going
-    if (strcmp(result->uri, vpninfo->sso_login_final)) {
-        return 1;
-    }
+       if (!vpninfo || !result)
+               return -EINVAL;
 
-    for (i=0; result->cookies[i] != NULL; i+=2) {
-        if (!strcmp(vpninfo->sso_token_cookie, result->cookies[i]))
-        {
-            vpninfo->sso_cookie_value = strdup(result->cookies[i+1]);
-            break;
-        }
-    }
+       if (vpninfo->proto->sso_detect_done)
+               return (vpninfo->proto->sso_detect_done)(vpninfo, result);
 
-    // Tell the webview to terminate
-    return 0;
+       return -EOPNOTSUPP;
 }
index 8b644cbe4dbbd816614342530587e004fd122305..633f6fd6239d627cd118c89cf4bacfa6a1fb1c58 100644 (file)
@@ -798,6 +798,9 @@ struct vpn_proto {
        /* This does the full authentication, calling back as appropriate */
        int (*obtain_cookie)(struct openconnect_info *vpninfo);
 
+       /* This checks if SSO authentication is complete */
+       int (*sso_detect_done)(struct openconnect_info *vpninfo, const struct oc_webview_result *result);
+
        /* Establish the TCP connection (and obtain configuration) */
        int (*tcp_connect)(struct openconnect_info *vpninfo);
 
@@ -1232,6 +1235,7 @@ int cstp_bye(struct openconnect_info *vpninfo, const char *reason);
 int decompress_and_queue_packet(struct openconnect_info *vpninfo, int compr_type,
                                unsigned char *buf, int len);
 int compress_packet(struct openconnect_info *vpninfo, int compr_type, struct pkt *this);
+int cstp_sso_detect_done(struct openconnect_info *vpninfo, const struct oc_webview_result *result);
 
 /* auth-html.c */
 xmlNodePtr htmlnode_next(xmlNodePtr top, xmlNodePtr node);