diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-25 23:03:09 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-25 23:03:09 +0000 |
commit | cb63908a05c846bda608b091e2fced3a08472c1f (patch) | |
tree | 63bb7f57cf4978ce318476bfd6c0685d3cc10ae6 | |
parent | 269ac3fa6bd0e4bbb54b5b7fd07acdadac8e7db4 (diff) | |
download | gnunet-cb63908a05c846bda608b091e2fced3a08472c1f.tar.gz gnunet-cb63908a05c846bda608b091e2fced3a08472c1f.zip |
-normalize input names. important for DHT queries
-rw-r--r-- | src/gns/gnunet-service-gns.c | 33 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_resolver.c | 6 |
2 files changed, 31 insertions, 8 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 9947dc03f..6acd2285c 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "gnunet_dnsparser_lib.h" | 31 | #include "gnunet_dnsparser_lib.h" |
32 | #include "gnunet_dht_service.h" | 32 | #include "gnunet_dht_service.h" |
33 | #include "gnunet_namestore_service.h" | 33 | #include "gnunet_namestore_service.h" |
34 | #include <unicase.h> | ||
34 | #include "gnunet_gns_service.h" | 35 | #include "gnunet_gns_service.h" |
35 | #include "block_gns.h" | 36 | #include "block_gns.h" |
36 | #include "gns.h" | 37 | #include "gns.h" |
@@ -155,6 +156,25 @@ static int auto_import_pkey; | |||
155 | static struct GNUNET_TIME_Relative default_lookup_timeout; | 156 | static struct GNUNET_TIME_Relative default_lookup_timeout; |
156 | 157 | ||
157 | /** | 158 | /** |
159 | * Normalizes the name in old | ||
160 | * | ||
161 | * @param old the old name to normalize | ||
162 | * @param new the buffer to write the new name to | ||
163 | */ | ||
164 | static void | ||
165 | normalize_name(const char* old, char** new) | ||
166 | { | ||
167 | uint8_t *tmp_name; | ||
168 | size_t n_len; | ||
169 | |||
170 | tmp_name = u8_tolower ((uint8_t*)old, strlen ((char *) old), | ||
171 | NULL, UNINORM_NFD, NULL, &n_len); | ||
172 | |||
173 | memcpy(*new, tmp_name, n_len); | ||
174 | (*new)[n_len] = '\0'; | ||
175 | free(tmp_name); | ||
176 | } | ||
177 | /** | ||
158 | * Continue shutdown | 178 | * Continue shutdown |
159 | */ | 179 | */ |
160 | static void | 180 | static void |
@@ -448,7 +468,7 @@ static void handle_shorten(void *cls, | |||
448 | 468 | ||
449 | size_t msg_size = 0; | 469 | size_t msg_size = 0; |
450 | struct ClientShortenHandle *csh; | 470 | struct ClientShortenHandle *csh; |
451 | const char* name; | 471 | char name[MAX_DNS_NAME_LENGTH]; |
452 | 472 | ||
453 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage)) | 473 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientShortenMessage)) |
454 | { | 474 | { |
@@ -475,7 +495,7 @@ static void handle_shorten(void *cls, | |||
475 | csh->client = client; | 495 | csh->client = client; |
476 | csh->unique_id = sh_msg->id; | 496 | csh->unique_id = sh_msg->id; |
477 | 497 | ||
478 | name = (char*)&sh_msg[1]; | 498 | normalize_name((char*)&sh_msg[1], (char**)&name); |
479 | 499 | ||
480 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) { | 500 | if (strlen (name) < strlen(GNUNET_GNS_TLD)) { |
481 | csh->name = NULL; | 501 | csh->name = NULL; |
@@ -563,7 +583,7 @@ static void handle_get_authority(void *cls, | |||
563 | 583 | ||
564 | size_t msg_size = 0; | 584 | size_t msg_size = 0; |
565 | struct ClientGetAuthHandle *cah; | 585 | struct ClientGetAuthHandle *cah; |
566 | const char* name; | 586 | char name[MAX_DNS_NAME_LENGTH]; |
567 | 587 | ||
568 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage)) | 588 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage)) |
569 | { | 589 | { |
@@ -586,7 +606,8 @@ static void handle_get_authority(void *cls, | |||
586 | return; | 606 | return; |
587 | } | 607 | } |
588 | 608 | ||
589 | name = (char*)&sh_msg[1]; | 609 | normalize_name((char*)&sh_msg[1], (char**)&name); |
610 | |||
590 | 611 | ||
591 | cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); | 612 | cah = GNUNET_malloc(sizeof(struct ClientGetAuthHandle)); |
592 | cah->client = client; | 613 | cah->client = client; |
@@ -690,7 +711,7 @@ handle_lookup(void *cls, | |||
690 | 711 | ||
691 | size_t msg_size = 0; | 712 | size_t msg_size = 0; |
692 | size_t namelen; | 713 | size_t namelen; |
693 | char* name; | 714 | char name[MAX_DNS_NAME_LENGTH]; |
694 | struct ClientLookupHandle *clh; | 715 | struct ClientLookupHandle *clh; |
695 | 716 | ||
696 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) | 717 | if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientLookupMessage)) |
@@ -714,7 +735,7 @@ handle_lookup(void *cls, | |||
714 | return; | 735 | return; |
715 | } | 736 | } |
716 | 737 | ||
717 | name = (char*)&sh_msg[1]; | 738 | normalize_name((char*)&sh_msg[1], (char**)&name); |
718 | namelen = strlen(name)+1; | 739 | namelen = strlen(name)+1; |
719 | clh = GNUNET_malloc(sizeof(struct ClientLookupHandle)); | 740 | clh = GNUNET_malloc(sizeof(struct ClientLookupHandle)); |
720 | clh->client = client; | 741 | clh->client = client; |
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 6e83957a2..2ba10c5da 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c | |||
@@ -1993,8 +1993,10 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, | |||
1993 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1993 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1994 | "ZKEY is %s!\n", string_hash); | 1994 | "ZKEY is %s!\n", string_hash); |
1995 | 1995 | ||
1996 | normalized_zkey = u8_toupper ((uint8_t*)string_hash, strlen ((char *) string_hash), | 1996 | normalized_zkey = u8_toupper ((uint8_t*)string_hash, |
1997 | NULL, UNINORM_NFD, NULL, &normal_len); | 1997 | strlen ((char *) string_hash), |
1998 | NULL, UNINORM_NFD, NULL, &normal_len); | ||
1999 | |||
1998 | 2000 | ||
1999 | memcpy(nzkey, normalized_zkey, normal_len); | 2001 | memcpy(nzkey, normalized_zkey, normal_len); |
2000 | nzkey[normal_len] = '\0'; | 2002 | nzkey[normal_len] = '\0'; |