Skip to content

Commit

Permalink
Sanify urlpath settings... no longer include leading /
Browse files Browse the repository at this point in the history
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Apr 1, 2009
1 parent d0b1fcd commit f3af84c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
19 changes: 11 additions & 8 deletions http.c
Expand Up @@ -584,14 +584,14 @@ static int parse_xml_response(struct openconnect_info *vpninfo, char *response,

form_method = (char *)xmlGetProp(xml_node, (unsigned char *)"method");
form_action = (char *)xmlGetProp(xml_node, (unsigned char *)"action");
if (strcasecmp(form_method, "POST")) {
vpninfo->progress(vpninfo, PRG_ERR, "Cannot handle form method '%s'\n",
form_method);
if (strcasecmp(form_method, "POST") || form_action[0] != '/') {
vpninfo->progress(vpninfo, PRG_ERR, "Cannot handle form method='%s', action='%s'\n",
form_method, form_action);
xmlFreeDoc(xml_doc);
return -EINVAL;
}
free(vpninfo->urlpath);
vpninfo->urlpath = strdup(form_action);
vpninfo->urlpath = strdup(form_action+1);

ret = parse_form(vpninfo, auth_id, form_message,
form_error, xml_node, request_body,
Expand Down Expand Up @@ -699,7 +699,7 @@ int openconnect_obtain_cookie(struct openconnect_info *vpninfo)
*
* So we process the HTTP for ourselves...
*/
sprintf(buf, "%s %s HTTP/1.1\r\n", method, vpninfo->urlpath);
sprintf(buf, "%s /%s HTTP/1.1\r\n", method, vpninfo->urlpath?:"");
sprintf(buf + strlen(buf), "Host: %s\r\n", vpninfo->hostname);
sprintf(buf + strlen(buf), "User-Agent: %s\r\n", vpninfo->useragent);
sprintf(buf + strlen(buf), "Accept: */*\r\n");
Expand All @@ -721,6 +721,8 @@ int openconnect_obtain_cookie(struct openconnect_info *vpninfo)
if (request_body_type)
sprintf(buf + strlen(buf), "%s", request_body);

vpninfo->progress(vpninfo, PRG_INFO, "%s %s/%s\n", method, vpninfo->hostname, vpninfo->urlpath?:"");

SSL_write(vpninfo->https_ssl, buf, strlen(buf));

buflen = process_http_response(vpninfo, &result, NULL, buf, 65536);
Expand All @@ -737,10 +739,10 @@ int openconnect_obtain_cookie(struct openconnect_info *vpninfo)

free(vpninfo->urlpath);
if (path) {
vpninfo->urlpath = strdup(path);
*(path++) = 0;
vpninfo->urlpath = strdup(path);
} else
vpninfo->urlpath = strdup("/");
vpninfo->urlpath = NULL;

if (strcmp(vpninfo->hostname, host)) {
free(vpninfo->hostname);
Expand Down Expand Up @@ -768,7 +770,8 @@ int openconnect_obtain_cookie(struct openconnect_info *vpninfo)
} else if (vpninfo->redirect_url[0] == '/') {
/* Absolute redirect within same host */
free(vpninfo->urlpath);
vpninfo->urlpath = vpninfo->redirect_url;
vpninfo->urlpath = strdup(vpninfo->redirect_url + 1);
free(vpninfo->redirect_url);
vpninfo->redirect_url = NULL;
goto retry;
} else {
Expand Down
7 changes: 3 additions & 4 deletions main.c
Expand Up @@ -161,7 +161,6 @@ int main(int argc, char **argv)
vpninfo->max_qlen = 10;
vpninfo->reconnect_interval = RECONNECT_INTERVAL_MIN;
vpninfo->reconnect_timeout = 300;
vpninfo->urlpath = strdup("/");

if (RAND_bytes(vpninfo->dtls_secret, sizeof(vpninfo->dtls_secret)) != 1) {
fprintf(stderr, "Failed to initialise DTLS secret\n");
Expand Down Expand Up @@ -222,9 +221,9 @@ int main(int argc, char **argv)
vpninfo->deflate = 0;
break;
case 'g':
free(vpninfo->urlpath);
vpninfo->urlpath = malloc(strlen(optarg)+2);
sprintf(vpninfo->urlpath, "/%s", optarg);
if (vpninfo->urlpath)
free(vpninfo->urlpath);
vpninfo->urlpath = strdup(optarg);
break;
case 'h':
usage();
Expand Down
4 changes: 2 additions & 2 deletions nm-auth-dialog.c
Expand Up @@ -896,7 +896,8 @@ static void connect_host(auth_ui_data *ui_data)
host = host->next;

ui_data->vpninfo->hostname = g_strdup(host->hostaddress);
ui_data->vpninfo->urlpath = g_strdup_printf("/%s", host->usergroup?:"");
if (host->usergroup)
ui_data->vpninfo->urlpath = g_strdup(host->usergroup);
ui_data->firsthost = g_strdup(host->hostname);

thread = g_thread_create((GThreadFunc)obtain_cookie, ui_data,
Expand Down Expand Up @@ -1086,7 +1087,6 @@ static auth_ui_data *init_ui_data (char *vpn_name)
ui_data->cert_response_changed = g_cond_new();

ui_data->vpninfo = g_slice_new0(struct openconnect_info);
ui_data->vpninfo->urlpath = strdup("/");
ui_data->vpninfo->mtu = 1406;
ui_data->vpninfo->useragent = openconnect_create_useragent("OpenConnect VPN Agent (NetworkManager)");
ui_data->vpninfo->ssl_fd = -1;
Expand Down
6 changes: 3 additions & 3 deletions xml.c
Expand Up @@ -126,9 +126,9 @@ int config_lookup_host(struct openconnect_info *vpninfo, const char *host)
!strcmp((char *)xml_node2->name, "UserGroup")) {
char *content = (char *)xmlNodeGetContent(xml_node2);
if (content) {
free(vpninfo->urlpath);
vpninfo->urlpath = malloc(strlen(content)+2);
sprintf(vpninfo->urlpath, "/%s", content);
if (vpninfo->urlpath)
free(vpninfo->urlpath);
vpninfo->urlpath = strdup(content);
printf("Host \"%s\" has UserGroup \"%s\"\n",
host, content);
}
Expand Down

0 comments on commit f3af84c

Please sign in to comment.