/* XX: if our "cookie" is bogus (doesn't include at least 'user', 'authcookie',
* and 'portal' fields) the server will respond like this.
*/
- if (result == -EINVAL && !strcmp(xml_buf, "errors getting SSL/VPN config"))
+ if (result == -EINVAL && xml_buf && !strcmp(xml_buf, "errors getting SSL/VPN config"))
result = -EPERM;
goto out;
}
ret = vpninfo->ssl_gets(vpninfo, buf+sizeof(start_tunnel), sizeof(buf)-sizeof(start_tunnel));
ret = (ret>0 ? ret : 0) + sizeof(start_tunnel);
}
- vpn_progress(vpninfo, PRG_ERR,
- _("Got inappropriate HTTP GET-tunnel response: %.*s\n"), ret, buf);
- /* XX: this is what GP servers return when they don't like the cookie */
- ret = !strncmp(buf, "HTTP/1.1 502 ", 13) ? -EPERM : -EINVAL;
+ int status = check_http_status(buf, ret);
+ /* XX: GP servers return 502 when they don't like the cookie */
+ if (status == 502)
+ ret = -EPERM;
+ else {
+ vpn_progress(vpninfo, PRG_ERR, _("Got unexpected HTTP response: %.*s\n"),
+ ret, buf);
+ ret = -EINVAL;
+ }
}
if (ret < 0)
int ppp_udp_mainloop(struct openconnect_info *vpninfo, int *timeout, int readable);
int openconnect_ppp_new(struct openconnect_info *vpninfo, int encap, int want_ipv4, int want_ipv6);
int ppp_reset(struct openconnect_info *vpninfo);
+int check_http_status(const char *buf, int len);
/* auth-globalprotect.c */
int gpst_obtain_cookie(struct openconnect_info *vpninfo);
p->ppp.hlen = p->data - ph;
}
+int check_http_status(const char *buf, int len)
+{
+ if (len >= 5 && !memcmp(buf, "HTTP/", 5)) {
+ const char *eol = memchr(buf, '\r', len) ?: memchr(buf, '\n', len);
+ const char *sp1 = memchr(buf, ' ', len);
+ const char *sp2 = sp1 ? memchr(sp1+1, ' ', len - (sp1-buf) + 1) : NULL;
+ return (sp1 && sp2 && (!eol || sp2<eol)) ? atoi(sp1+1) : 500;
+ }
+ return -EINVAL;
+}
+
static int ppp_mainloop(struct openconnect_info *vpninfo, int dtls,
struct keepalive_info *kai, int *timeout, int readable)
{
* of the first packet
*/
if (ppp->check_http_response) {
+ int status = check_http_status((const char *)eh, len);
ppp->check_http_response = 0;
- if (!memcmp(eh, "HTTP/", 5)) {
- const char *sol = (const char *)eh;
- const char *eol = memchr(sol, '\r', len) ?: memchr(sol, '\n', len);
- const char *sp1 = memchr(sol, ' ', len);
- const char *sp2 = memchr(sp1+1, ' ', len - (sp1-sol) + 1);
- int status = sp1 && sp2 ? atoi(sp1+1) : -1;
- if (eol)
- len = eol - sol;
- vpn_progress(vpninfo, PRG_ERR,
- _("Got unexpected HTTP response: %.*s\n"), len, sol);
+ if (status >= 0) {
+ vpn_progress(vpninfo, PRG_ERR,_("Got unexpected HTTP response: %.*s\n"),
+ len, (const char *)eh);
vpninfo->quit_reason = "Received HTTP response (not a PPP packet)";
return (status >= 400 && status <= 499) ? -EPERM : -EINVAL;
}