From: Daniel Lenski Date: Tue, 5 Jan 2021 18:40:39 +0000 (-0800) Subject: make .sso_detect_done a protocol-specific VFN, and use in openconnect_webview_load_ch... X-Git-Tag: v9.00~92 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f829c51a7b65baf702ca42a47e83f454430b951c;p=users%2Fdwmw2%2Fopenconnect.git make .sso_detect_done a protocol-specific VFN, and use in openconnect_webview_load_changed Also changes the "keep going" return value to -EAGAIN. Signed-off-by: Daniel Lenski --- diff --git a/cstp.c b/cstp.c index 0b7a0930..81ea1fef 100644 --- 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; +} diff --git a/library.c b/library.c index 9e21cab9..79532e0c 100644 --- 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; } diff --git a/openconnect-internal.h b/openconnect-internal.h index 8b644cbe..633f6fd6 100644 --- a/openconnect-internal.h +++ b/openconnect-internal.h @@ -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);