diff options
Diffstat (limited to 'src/gns/gnunet-gns-proxy.c')
-rw-r--r-- | src/gns/gnunet-gns-proxy.c | 119 |
1 files changed, 83 insertions, 36 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c index 91fa852cc..bb67b7b26 100644 --- a/src/gns/gnunet-gns-proxy.c +++ b/src/gns/gnunet-gns-proxy.c | |||
@@ -244,9 +244,30 @@ struct ProxyCurlTask | |||
244 | 244 | ||
245 | /* The associated response */ | 245 | /* The associated response */ |
246 | struct MHD_Response *response; | 246 | struct MHD_Response *response; |
247 | |||
248 | /* Cookies to set */ | ||
249 | struct ProxySetCookieHeader *set_cookies_head; | ||
250 | |||
251 | /* Cookies to set */ | ||
252 | struct ProxySetCookieHeader *set_cookies_tail; | ||
247 | 253 | ||
248 | }; | 254 | }; |
249 | 255 | ||
256 | /** | ||
257 | * Struct for set-cookies | ||
258 | */ | ||
259 | struct ProxySetCookieHeader | ||
260 | { | ||
261 | /* DLL */ | ||
262 | struct ProxySetCookieHeader *next; | ||
263 | |||
264 | /* DLL */ | ||
265 | struct ProxySetCookieHeader *prev; | ||
266 | |||
267 | /* the cookie */ | ||
268 | char *cookie; | ||
269 | }; | ||
270 | |||
250 | /* The port the proxy is running on (default 7777) */ | 271 | /* The port the proxy is running on (default 7777) */ |
251 | static unsigned long port = GNUNET_GNS_PROXY_PORT; | 272 | static unsigned long port = GNUNET_GNS_PROXY_PORT; |
252 | 273 | ||
@@ -376,20 +397,46 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) | |||
376 | { | 397 | { |
377 | size_t bytes = size * nmemb; | 398 | size_t bytes = size * nmemb; |
378 | struct ProxyCurlTask *ctask = cls; | 399 | struct ProxyCurlTask *ctask = cls; |
379 | int len = strlen (HTML_HDR_CONTENT); | 400 | int html_mime_len = strlen (HTML_HDR_CONTENT); |
380 | char hdr[len+1]; | 401 | int cookie_hdr_len = strlen (MHD_HTTP_HEADER_SET_COOKIE); |
402 | char hdr_mime[html_mime_len+1]; | ||
403 | char hdr_cookie[size+1]; | ||
404 | struct ProxySetCookieHeader *pch; | ||
405 | size_t len; | ||
381 | 406 | ||
382 | if ( (len+1) > bytes) | 407 | if (html_mime_len <= size) |
383 | return bytes; | 408 | { |
409 | memcpy (hdr_mime, buffer, html_mime_len); | ||
410 | hdr_mime[html_mime_len] = '\0'; | ||
384 | 411 | ||
385 | memcpy (hdr, buffer, len); | 412 | if (0 == strcmp (hdr_mime, HTML_HDR_CONTENT)) |
386 | hdr[len] = '\0'; | 413 | { |
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
415 | "Got HTML HTTP response header\n"); | ||
416 | ctask->parse_content = GNUNET_YES; | ||
417 | } | ||
418 | } | ||
419 | |||
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
421 | "Got header %s\n", buffer); | ||
387 | 422 | ||
388 | if (0 == strcmp (hdr, HTML_HDR_CONTENT)) | 423 | if (cookie_hdr_len <= size) |
389 | { | 424 | { |
425 | memcpy (hdr_cookie, buffer, size); | ||
426 | hdr_cookie[size] = '\0'; | ||
427 | |||
390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 428 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
391 | "Got HTML HTTP response header\n"); | 429 | "Got Set-Cookie HTTP header %s\n", hdr_cookie); |
392 | ctask->parse_content = GNUNET_YES; | 430 | GNUNET_assert (0); |
431 | |||
432 | pch = GNUNET_malloc (sizeof (struct ProxySetCookieHeader)); | ||
433 | len = strlen (hdr_cookie) - strlen (MHD_HTTP_HEADER_SET_COOKIE); | ||
434 | pch->cookie = GNUNET_malloc (len + 1); | ||
435 | memset (pch->cookie, 0, len + 1); | ||
436 | memcpy (pch->cookie, hdr_cookie+strlen (MHD_HTTP_HEADER_SET_COOKIE), len); | ||
437 | GNUNET_CONTAINER_DLL_insert (ctask->set_cookies_head, | ||
438 | ctask->set_cookies_tail, | ||
439 | pch); | ||
393 | } | 440 | } |
394 | 441 | ||
395 | return bytes; | 442 | return bytes; |
@@ -572,9 +619,28 @@ mhd_content_cb (void *cls, | |||
572 | int nomatch; | 619 | int nomatch; |
573 | char *hostptr; | 620 | char *hostptr; |
574 | regmatch_t m[RE_N_MATCHES]; | 621 | regmatch_t m[RE_N_MATCHES]; |
622 | struct ProxySetCookieHeader *pch; | ||
575 | 623 | ||
576 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 624 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
577 | "MHD: content cb %s\n", ctask->url); | 625 | "MHD: content cb %s\n", ctask->url); |
626 | |||
627 | pch = ctask->set_cookies_head; | ||
628 | while (pch != NULL) | ||
629 | { | ||
630 | if (GNUNET_NO == MHD_add_response_header (ctask->response, | ||
631 | MHD_HTTP_HEADER_SET_COOKIE, | ||
632 | pch->cookie)) | ||
633 | { | ||
634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
635 | "MHD: Error adding set-cookie header field %s\n", | ||
636 | pch->cookie); | ||
637 | } | ||
638 | GNUNET_free (pch->cookie); | ||
639 | GNUNET_CONTAINER_DLL_remove (ctask->set_cookies_head, | ||
640 | ctask->set_cookies_tail, | ||
641 | pch); | ||
642 | pch = ctask->set_cookies_head; | ||
643 | } | ||
578 | 644 | ||
579 | if (ctask->download_successful && | 645 | if (ctask->download_successful && |
580 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) | 646 | (ctask->buf_status == BUF_WAIT_FOR_CURL)) |
@@ -1557,7 +1623,7 @@ add_handle_to_mhd (struct GNUNET_NETWORK_Handle *h, struct MHD_Daemon *daemon) | |||
1557 | struct sockaddr *addr; | 1623 | struct sockaddr *addr; |
1558 | socklen_t len; | 1624 | socklen_t len; |
1559 | 1625 | ||
1560 | fd = GNUNET_NETWORK_get_fd (h); | 1626 | fd = dup (GNUNET_NETWORK_get_fd (h)); |
1561 | addr = GNUNET_NETWORK_get_addr (h); | 1627 | addr = GNUNET_NETWORK_get_addr (h); |
1562 | len = GNUNET_NETWORK_get_addrlen (h); | 1628 | len = GNUNET_NETWORK_get_addrlen (h); |
1563 | 1629 | ||
@@ -2444,7 +2510,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
2444 | char* proxy_sockfile; | 2510 | char* proxy_sockfile; |
2445 | char* cafile_cfg = NULL; | 2511 | char* cafile_cfg = NULL; |
2446 | char* cafile; | 2512 | char* cafile; |
2447 | char* shorten_keyfile; | ||
2448 | 2513 | ||
2449 | curl_multi = NULL; | 2514 | curl_multi = NULL; |
2450 | 2515 | ||
@@ -2481,25 +2546,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
2481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2482 | "Loading Template\n"); | 2547 | "Loading Template\n"); |
2483 | 2548 | ||
2484 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy", | ||
2485 | "PROXY_CACERT", | ||
2486 | &shorten_keyfile)) | ||
2487 | { | ||
2488 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2489 | "Unable to load shorten zonekey config value!\n"); | ||
2490 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2491 | "No shorten key provided!\n"); | ||
2492 | return; | ||
2493 | } | ||
2494 | else | ||
2495 | { | ||
2496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2497 | "Loading shorten zonekey %s!\n", | ||
2498 | shorten_keyfile); | ||
2499 | shorten_zonekey = GNUNET_CRYPTO_rsa_key_create_from_file (shorten_keyfile); | ||
2500 | GNUNET_free (shorten_keyfile); | ||
2501 | } | ||
2502 | |||
2503 | compile_regex (&re_dotplus, (char*) RE_A_HREF); | 2549 | compile_regex (&re_dotplus, (char*) RE_A_HREF); |
2504 | 2550 | ||
2505 | gns_handle = GNUNET_GNS_connect (cfg); | 2551 | gns_handle = GNUNET_GNS_connect (cfg); |
@@ -2593,12 +2639,13 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
2593 | 2639 | ||
2594 | mhd_unix_sock_addr.sun_family = AF_UNIX; | 2640 | mhd_unix_sock_addr.sun_family = AF_UNIX; |
2595 | strcpy (mhd_unix_sock_addr.sun_path, proxy_sockfile); | 2641 | strcpy (mhd_unix_sock_addr.sun_path, proxy_sockfile); |
2596 | if (0 != unlink (proxy_sockfile)) | 2642 | |
2597 | { | 2643 | #if LINUX |
2598 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2644 | mhd_unix_sock_addr.sun_path[0] = '\0'; |
2599 | "Unable to unlink sockfile!\n"); | 2645 | #endif |
2600 | return; | 2646 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2601 | } | 2647 | mhd_unix_sock_addr.sun_len = (u_char) sizeof (struct sockaddr_un); |
2648 | #endif | ||
2602 | 2649 | ||
2603 | len = strlen (proxy_sockfile) + sizeof(AF_UNIX); | 2650 | len = strlen (proxy_sockfile) + sizeof(AF_UNIX); |
2604 | 2651 | ||