From: Martin Schanzenbach Date: Mon, 2 Jul 2012 15:16:51 +0000 (+0000) Subject: -towards cookies... broke resolver X-Git-Tag: initial-import-from-subversion-38251~12690 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=c7abe0aef79a076e2b82c3173b9419685d65f650;p=oweals%2Fgnunet.git -towards cookies... broke resolver --- 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 /* The associated response */ struct MHD_Response *response; + + /* Cookies to set */ + struct ProxySetCookieHeader *set_cookies_head; + + /* Cookies to set */ + struct ProxySetCookieHeader *set_cookies_tail; }; +/** + * Struct for set-cookies + */ +struct ProxySetCookieHeader +{ + /* DLL */ + struct ProxySetCookieHeader *next; + + /* DLL */ + struct ProxySetCookieHeader *prev; + + /* the cookie */ + char *cookie; +}; + /* The port the proxy is running on (default 7777) */ static unsigned long port = GNUNET_GNS_PROXY_PORT; @@ -376,20 +397,46 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls) { size_t bytes = size * nmemb; struct ProxyCurlTask *ctask = cls; - int len = strlen (HTML_HDR_CONTENT); - char hdr[len+1]; + int html_mime_len = strlen (HTML_HDR_CONTENT); + int cookie_hdr_len = strlen (MHD_HTTP_HEADER_SET_COOKIE); + char hdr_mime[html_mime_len+1]; + char hdr_cookie[size+1]; + struct ProxySetCookieHeader *pch; + size_t len; - if ( (len+1) > bytes) - return bytes; + if (html_mime_len <= size) + { + memcpy (hdr_mime, buffer, html_mime_len); + hdr_mime[html_mime_len] = '\0'; - memcpy (hdr, buffer, len); - hdr[len] = '\0'; + if (0 == strcmp (hdr_mime, HTML_HDR_CONTENT)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got HTML HTTP response header\n"); + ctask->parse_content = GNUNET_YES; + } + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got header %s\n", buffer); - if (0 == strcmp (hdr, HTML_HDR_CONTENT)) + if (cookie_hdr_len <= size) { + memcpy (hdr_cookie, buffer, size); + hdr_cookie[size] = '\0'; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Got HTML HTTP response header\n"); - ctask->parse_content = GNUNET_YES; + "Got Set-Cookie HTTP header %s\n", hdr_cookie); + GNUNET_assert (0); + + pch = GNUNET_malloc (sizeof (struct ProxySetCookieHeader)); + len = strlen (hdr_cookie) - strlen (MHD_HTTP_HEADER_SET_COOKIE); + pch->cookie = GNUNET_malloc (len + 1); + memset (pch->cookie, 0, len + 1); + memcpy (pch->cookie, hdr_cookie+strlen (MHD_HTTP_HEADER_SET_COOKIE), len); + GNUNET_CONTAINER_DLL_insert (ctask->set_cookies_head, + ctask->set_cookies_tail, + pch); } return bytes; @@ -572,9 +619,28 @@ mhd_content_cb (void *cls, int nomatch; char *hostptr; regmatch_t m[RE_N_MATCHES]; + struct ProxySetCookieHeader *pch; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MHD: content cb %s\n", ctask->url); + + pch = ctask->set_cookies_head; + while (pch != NULL) + { + if (GNUNET_NO == MHD_add_response_header (ctask->response, + MHD_HTTP_HEADER_SET_COOKIE, + pch->cookie)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "MHD: Error adding set-cookie header field %s\n", + pch->cookie); + } + GNUNET_free (pch->cookie); + GNUNET_CONTAINER_DLL_remove (ctask->set_cookies_head, + ctask->set_cookies_tail, + pch); + pch = ctask->set_cookies_head; + } if (ctask->download_successful && (ctask->buf_status == BUF_WAIT_FOR_CURL)) @@ -1557,7 +1623,7 @@ add_handle_to_mhd (struct GNUNET_NETWORK_Handle *h, struct MHD_Daemon *daemon) struct sockaddr *addr; socklen_t len; - fd = GNUNET_NETWORK_get_fd (h); + fd = dup (GNUNET_NETWORK_get_fd (h)); addr = GNUNET_NETWORK_get_addr (h); len = GNUNET_NETWORK_get_addrlen (h); @@ -2444,7 +2510,6 @@ run (void *cls, char *const *args, const char *cfgfile, char* proxy_sockfile; char* cafile_cfg = NULL; char* cafile; - char* shorten_keyfile; curl_multi = NULL; @@ -2481,25 +2546,6 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading Template\n"); - if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy", - "PROXY_CACERT", - &shorten_keyfile)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unable to load shorten zonekey config value!\n"); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No shorten key provided!\n"); - return; - } - else - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Loading shorten zonekey %s!\n", - shorten_keyfile); - shorten_zonekey = GNUNET_CRYPTO_rsa_key_create_from_file (shorten_keyfile); - GNUNET_free (shorten_keyfile); - } - compile_regex (&re_dotplus, (char*) RE_A_HREF); gns_handle = GNUNET_GNS_connect (cfg); @@ -2593,12 +2639,13 @@ run (void *cls, char *const *args, const char *cfgfile, mhd_unix_sock_addr.sun_family = AF_UNIX; strcpy (mhd_unix_sock_addr.sun_path, proxy_sockfile); - if (0 != unlink (proxy_sockfile)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unable to unlink sockfile!\n"); - return; - } + +#if LINUX + mhd_unix_sock_addr.sun_path[0] = '\0'; +#endif +#if HAVE_SOCKADDR_IN_SIN_LEN + mhd_unix_sock_addr.sun_len = (u_char) sizeof (struct sockaddr_un); +#endif len = strlen (proxy_sockfile) + sizeof(AF_UNIX); diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 1f103f421..f86b07f67 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -906,6 +906,9 @@ free_resolver_handle (struct ResolverHandle* rh) GNUNET_NETWORK_socket_close (rh->dns_sock); if (NULL != rh->dns_resolver_handle) GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle); + + if (NULL != rh->rd.data) + GNUNET_free ((void*)(rh->rd.data)); GNUNET_free(rh); } @@ -2260,7 +2263,7 @@ process_pkey_revocation_result_ns (void *cls, rh->private_local_zone, GNUNET_GNS_RECORD_REV, GNUNET_GNS_TLD, - rh->priv_key, + NULL, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NO, &background_lookup_result_processor, @@ -2275,9 +2278,10 @@ process_pkey_revocation_result_ns (void *cls, * else resolve again with new authority */ if (strcmp (rh->name, "") == 0) - rh->proc (rh->proc_cls, rh, 0, NULL); + rh->proc (rh->proc_cls, rh, rh->rd_count, &rh->rd); else resolve_delegation_ns (rh); + return; } @@ -2447,6 +2451,14 @@ process_delegation_result_dht(void* cls, rh->authority_chain_tail, auth); + if (NULL != rh->rd.data) + GNUNET_free ((void*)rh->rd.data); + + rh->rd.data = GNUNET_malloc (rd[i].data_size); + memcpy (&rh->rd, &rd[i], sizeof (struct GNUNET_NAMESTORE_RecordData)); + memcpy ((void*)(rh->rd.data), rd[i].data, rd[i].data_size); + rh->rd_count = 1; + /** try to import pkey if private key available */ //if (rh->priv_key && is_canonical (rh->name)) // process_discovered_authority(name, auth->zone, @@ -2520,6 +2532,7 @@ process_delegation_result_dht(void* cls, else rh->proc = &handle_delegation_ns; + /* Check for key revocation and delegate */ rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle, &rh->authority, @@ -3147,7 +3160,6 @@ handle_delegation_ns (void* cls, struct ResolverHandle *rh, } else if (rlh->record_type == GNUNET_GNS_RECORD_PKEY) { - GNUNET_assert(rd_count == 1); GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "GNS_PHASE_DELEGATE_NS-%llu: Resolved queried PKEY in NS.\n", rh->id); @@ -3432,7 +3444,13 @@ process_delegation_result_ns (void* cls, GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head, rh->authority_chain_tail, auth); + if (NULL != rh->rd.data) + GNUNET_free ((void*)(rh->rd.data)); + rh->rd.data = GNUNET_malloc (rd[i].data_size); + memcpy (&rh->rd, &rd[i], sizeof (struct GNUNET_NAMESTORE_RecordData)); + memcpy ((void*)rh->rd.data, rd[i].data, rd[i].data_size); + rh->rd_count = 1; /* Check for key revocation and delegate */ rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle, &rh->authority, @@ -3557,6 +3575,7 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone, rh->private_local_zone = pzone; rh->only_cached = only_cached; rh->namestore_task = NULL; + rh->rd.data = NULL; GNUNET_CONTAINER_DLL_insert (rlh_head, rlh_tail, rh); diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index e9cbf0d53..b57386f4f 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h @@ -126,6 +126,12 @@ struct ResolverHandle /* DLL */ struct ResolverHandle *prev; + /* Last record data found */ + struct GNUNET_NAMESTORE_RecordData rd; + + /* Number of last record data found */ + unsigned int rd_count; + /* The name to resolve */ char name[MAX_DNS_NAME_LENGTH];