[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r24617 - in gnunet/src: gns include namestore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r24617 - in gnunet/src: gns include namestore |
Date: |
Tue, 30 Oct 2012 21:52:14 +0100 |
Author: grothoff
Date: 2012-10-30 21:52:14 +0100 (Tue, 30 Oct 2012)
New Revision: 24617
Modified:
gnunet/src/gns/gns.h
gnunet/src/gns/gnunet-service-gns.c
gnunet/src/gns/gnunet-service-gns_interceptor.c
gnunet/src/gns/gnunet-service-gns_resolver.c
gnunet/src/gns/gnunet-service-gns_resolver.h
gnunet/src/gns/test_gns_cname_lookup.c
gnunet/src/gns/test_gns_max_queries.c
gnunet/src/gns/test_gns_simple_zkey_lookup.c
gnunet/src/include/gnunet_common.h
gnunet/src/include/gnunet_dnsparser_lib.h
gnunet/src/include/gnunet_namestore_service.h
gnunet/src/namestore/namestore_common.c
Log:
-more cleanup and input validation fixes
Modified: gnunet/src/gns/gns.h
===================================================================
--- gnunet/src/gns/gns.h 2012-10-30 19:16:03 UTC (rev 24616)
+++ gnunet/src/gns/gns.h 2012-10-30 20:52:14 UTC (rev 24617)
@@ -42,17 +42,7 @@
*/
#define GNUNET_GNS_TLD_PLUS "+"
-/**
- * Maximum length of a label in DNS.
- */
-#define MAX_DNS_LABEL_LENGTH 63
-/**
- * Maximum length of a name in DNS.
- */
-#define MAX_DNS_NAME_LENGTH 253
-
-
GNUNET_NETWORK_STRUCT_BEGIN
/**
Modified: gnunet/src/gns/gnunet-service-gns.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns.c 2012-10-30 19:16:03 UTC (rev 24616)
+++ gnunet/src/gns/gnunet-service-gns.c 2012-10-30 20:52:14 UTC (rev 24617)
@@ -116,17 +116,17 @@
/**
* name to shorten
*/
- char name[MAX_DNS_NAME_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* name of private zone (relative to root)
*/
- char private_zone_id[MAX_DNS_NAME_LENGTH];
+ char private_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* name of shorten zone (relative to root)
*/
- char shorten_zone_id[MAX_DNS_NAME_LENGTH];
+ char shorten_zone_id[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
};
@@ -787,7 +787,7 @@
{
struct ClientShortenHandle *csh;
const char *utf_in;
- char name[MAX_DNS_NAME_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
char* nameptr = name;
uint16_t msg_size;
const struct GNUNET_GNS_ClientShortenMessage *sh_msg;
@@ -828,7 +828,7 @@
GNUNET_SERVER_receive_done (client, GNUNET_OK);
return;
}
- if (strlen (name) > MAX_DNS_NAME_LENGTH)
+ if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"SHORTEN: %s is too long\n", name);
@@ -922,7 +922,7 @@
{
struct ClientGetAuthHandle *cah;
const char *utf_in;
- char name[MAX_DNS_NAME_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
char* nameptr = name;
uint16_t msg_size;
const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg;
@@ -957,7 +957,7 @@
send_get_auth_response(cah, name);
return;
}
- if (strlen (name) > MAX_DNS_NAME_LENGTH)
+ if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"GET_AUTH: `%s' is too long", name);
@@ -1059,7 +1059,7 @@
const struct GNUNET_MessageHeader * message)
{
size_t namelen;
- char name[MAX_DNS_NAME_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
struct ClientLookupHandle *clh;
char* nameptr = name;
const char *utf_in;
@@ -1113,7 +1113,7 @@
only_cached = ntohl (sh_msg->only_cached);
- if (strlen (name) > MAX_DNS_NAME_LENGTH) {
+ if (strlen (name) > GNUNET_DNSPARSER_MAX_NAME_LENGTH) {
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"LOOKUP: %s is too long", name);
clh->name = NULL;
Modified: gnunet/src/gns/gnunet-service-gns_interceptor.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns_interceptor.c 2012-10-30 19:16:03 UTC
(rev 24616)
+++ gnunet/src/gns/gnunet-service-gns_interceptor.c 2012-10-30 20:52:14 UTC
(rev 24617)
@@ -30,8 +30,6 @@
#include "gnunet-service-gns_resolver.h"
#include "gns.h"
-#define MAX_DNS_LABEL_LENGTH 63
-
/**
* Handle to a DNS intercepted
* reslution request
Modified: gnunet/src/gns/gnunet-service-gns_resolver.c
===================================================================
--- gnunet/src/gns/gnunet-service-gns_resolver.c 2012-10-30 19:16:03 UTC
(rev 24616)
+++ gnunet/src/gns/gnunet-service-gns_resolver.c 2012-10-30 20:52:14 UTC
(rev 24617)
@@ -50,12 +50,7 @@
*/
#define DHT_GNS_REPLICATION_LEVEL 5
-/**
- * Maximum label length of DNS names
- */
-#define MAX_DNS_LABEL_LENGTH 63
-
/**
* Our handle to the namestore service
*/
@@ -150,8 +145,9 @@
* a resolution identifier pool variable
* This is a non critical identifier useful for debugging
*/
-static unsigned long long rid = 0;
+static unsigned long long rid_gen;
+
/**
* Check if name is in srv format (_x._y.xxx)
*
@@ -159,30 +155,25 @@
* @return GNUNET_YES if true
*/
static int
-is_srv (char* name)
+is_srv (const char *name)
{
- char* ndup;
- int ret = GNUNET_YES;
+ char *ndup;
+ int ret;
if (*name != '_')
return GNUNET_NO;
if (NULL == strstr (name, "._"))
return GNUNET_NO;
-
+ ret = GNUNET_YES;
ndup = GNUNET_strdup (name);
strtok (ndup, ".");
-
if (NULL == strtok (NULL, "."))
ret = GNUNET_NO;
-
if (NULL == strtok (NULL, "."))
ret = GNUNET_NO;
-
if (NULL != strtok (NULL, "."))
ret = GNUNET_NO;
-
GNUNET_free (ndup);
-
return ret;
}
@@ -203,7 +194,7 @@
* @return GNUNET_YES if canonical
*/
static int
-is_canonical (const char* name)
+is_canonical (const char *name)
{
const char *pos;
const char *dot;
@@ -243,7 +234,7 @@
/**
- * Continueation for pkey record creation (shorten)
+ * Continuation for pkey record creation (shorten)
*
* @param cls a GetPseuAuthorityHandle
* @param success unused
@@ -293,7 +284,8 @@
/* name is free */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "GNS_AUTO_PSEU: Name %s not taken in NS! Adding\n",
gph->test_name);
+ "GNS_AUTO_PSEU: Name %s not taken in NS! Adding\n",
+ gph->test_name);
new_pkey.expiration_time = UINT64_MAX;
new_pkey.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode);
@@ -310,6 +302,7 @@
gph);
}
+
/**
* process result of a dht pseu lookup
*
@@ -317,7 +310,8 @@
* @param name the pseu result or NULL
*/
static void
-process_pseu_result (struct GetPseuAuthorityHandle* gph, char* name)
+process_pseu_result (struct GetPseuAuthorityHandle* gph,
+ const char* name)
{
if (NULL == name)
{
@@ -353,7 +347,7 @@
handle_auth_discovery_timeout (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct GetPseuAuthorityHandle* gph = (struct GetPseuAuthorityHandle*)cls;
+ struct GetPseuAuthorityHandle* gph = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_GET_AUTH: dht lookup for query PSEU timed out.\n");
@@ -571,7 +565,6 @@
static void
shorten_authority_chain (struct GetPseuAuthorityHandle *gph)
{
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_AUTO_PSEU: New authority %s discovered\n",
gph->auth->name);
@@ -581,7 +574,6 @@
&gph->auth->zone,
&process_zone_to_name_discover,
gph);
-
}
@@ -626,6 +618,7 @@
shorten_authority_chain (gph);
}
+
/**
* Initialize the resolver
*
@@ -726,8 +719,8 @@
struct ResolverHandle *rh = element;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_CLEANUP-%llu: Terminating background lookup for %s\n",
- rh->id, rh->name);
+ "GNS_CLEANUP-%llu: Terminating background lookup\n",
+ rh->id);
GNUNET_CONTAINER_heap_remove_node (node);
if (0 == GNUNET_CONTAINER_heap_get_size (dht_lookup_heap))
{
@@ -753,36 +746,30 @@
if (NULL == rh)
return;
- ac = rh->authority_chain_head;
-
- while (NULL != ac)
+ ac_next = rh->authority_chain_head;
+ while (NULL != (ac = ac_next))
{
ac_next = ac->next;
GNUNET_free (ac);
- ac = ac_next;
}
if (NULL != rh->get_handle)
GNUNET_DHT_get_stop (rh->get_handle);
-
if (NULL != rh->dns_raw_packet)
GNUNET_free (rh->dns_raw_packet);
-
if (NULL != rh->namestore_task)
+ {
GNUNET_NAMESTORE_cancel (rh->namestore_task);
- rh->namestore_task = NULL;
-
+ rh->namestore_task = NULL;
+ }
if (GNUNET_SCHEDULER_NO_TASK != rh->dns_read_task)
GNUNET_SCHEDULER_cancel (rh->dns_read_task);
-
if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
GNUNET_SCHEDULER_cancel (rh->timeout_task);
-
if (NULL != rh->dns_sock)
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);
@@ -854,8 +841,9 @@
}
s = GNUNET_CONTAINER_heap_get_size (dht_lookup_heap);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_CLEANUP: %d pending background queries to terminate\n", s);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "GNS_CLEANUP: %u pending background queries to terminate\n",
+ s);
if (0 != s)
GNUNET_CONTAINER_heap_iterate (dht_lookup_heap,
&cleanup_pending_background_queries,
@@ -866,6 +854,7 @@
&cleanup_pending_ns_tasks,
NULL);
}
+ // FIXME: what about freeing the heaps themselves?
}
@@ -953,7 +942,7 @@
{
struct ResolverHandle *rh = cls;
struct RecordLookupHandle *rlh = rh->proc_cls;
- char new_name[MAX_DNS_NAME_LENGTH];
+ char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_REC-%llu: dht lookup for query %s (%llus) timed
out.\n",
@@ -961,7 +950,7 @@
/**
* Start resolution in bg
*/
- GNUNET_snprintf (new_name, MAX_DNS_NAME_LENGTH, "%s.%s",
+ GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
rh->name, GNUNET_GNS_TLD);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1012,60 +1001,51 @@
enum GNUNET_BLOCK_Type type,
size_t size, const void *data)
{
- struct ResolverHandle *rh;
- struct RecordLookupHandle *rlh;
- struct GNSNameRecordBlock *nrb;
+ struct ResolverHandle *rh = cls;
+ struct RecordLookupHandle *rlh = rh->proc_cls;
+ const struct GNSNameRecordBlock *nrb = data;
uint32_t num_records;
- char* name = NULL;
- char* rd_data = (char*)data;
- int i;
- int rd_size;
+ const char* name;
+ const char* rd_data;
+ uint32_t i;
+ size_t rd_size;
- rh = (struct ResolverHandle *)cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_REC-%llu: got dht result (size=%d)\n", rh->id, size);
-
- rlh = (struct RecordLookupHandle *) rh->proc_cls;
- nrb = (struct GNSNameRecordBlock*)data;
-
/* stop lookup and timeout task */
GNUNET_DHT_get_stop (rh->get_handle);
rh->get_handle = NULL;
-
if (rh->dht_heap_node != NULL)
{
GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
rh->dht_heap_node = NULL;
}
-
if (rh->timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (rh->timeout_task);
rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
-
rh->get_handle = NULL;
- name = (char*)&nrb[1];
+ name = (const char*) &nrb[1];
num_records = ntohl (nrb->rd_count);
{
struct GNUNET_NAMESTORE_RecordData rd[num_records];
struct NamestoreBGTask *ns_heap_root;
struct NamestoreBGTask *namestore_bg_task;
- rd_data += strlen (name) + 1 + sizeof (struct GNSNameRecordBlock);
+ rd_data = &name[strlen (name) + 1];
rd_size = size - strlen (name) - 1 - sizeof (struct GNSNameRecordBlock);
-
- if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size,
- rd_data,
- num_records,
- rd))
+ if (GNUNET_SYSERR ==
+ GNUNET_NAMESTORE_records_deserialize (rd_size,
+ rd_data,
+ num_records,
+ rd))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"GNS_PHASE_REC-%llu: Error deserializing data!\n", rh->id);
rh->proc (rh->proc_cls, rh, 0, NULL);
return;
}
-
for (i = 0; i < num_records; i++)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1120,14 +1100,11 @@
namestore_bg_task->node = GNUNET_CONTAINER_heap_insert (ns_task_heap,
namestore_bg_task,
GNUNET_TIME_absolute_get().abs_value);
-
-
if (0 < rh->answered)
rh->proc (rh->proc_cls, rh, num_records, rd);
else
rh->proc (rh->proc_cls, rh, 0, NULL);
}
-
}
@@ -1140,9 +1117,9 @@
static void
resolve_record_dht (struct ResolverHandle *rh)
{
+ struct RecordLookupHandle *rlh = rh->proc_cls;
uint32_t xquery;
struct GNUNET_HashCode lookup_key;
- struct RecordLookupHandle *rlh = rh->proc_cls;
struct ResolverHandle *rh_heap_root;
GNUNET_GNS_get_key_for_record (rh->name, &rh->authority, &lookup_key);
@@ -1233,35 +1210,26 @@
const struct GNUNET_NAMESTORE_RecordData *rd,
const struct GNUNET_CRYPTO_RsaSignature *signature)
{
- struct ResolverHandle *rh;
- struct RecordLookupHandle *rlh;
+ struct ResolverHandle *rh = cls;
+ struct RecordLookupHandle *rlh = rh->proc_cls;
struct GNUNET_TIME_Relative remaining_time;
struct GNUNET_CRYPTO_ShortHashCode zone;
struct GNUNET_TIME_Absolute et;
unsigned int i;
- rh = cls;
- rlh = rh->proc_cls;
-
rh->namestore_task = NULL;
GNUNET_CRYPTO_short_hash (key,
- sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &zone);
+ sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &zone);
remaining_time = GNUNET_TIME_absolute_get_remaining (expiration);
-
-
-
rh->status = 0;
-
if (NULL != name)
{
rh->status |= RSL_RECORD_EXISTS;
-
if (remaining_time.rel_value == 0)
rh->status |= RSL_RECORD_EXPIRED;
}
-
- if (rd_count == 0)
+ if (0 == rd_count)
{
/**
* Lookup terminated and no results
@@ -1570,10 +1538,7 @@
finish_lookup (rh, rlh, 0, NULL);
return;
}
-
- packet = GNUNET_DNSPARSER_parse (buf, r);
-
- if (NULL == packet)
+ if (NULL == (packet = GNUNET_DNSPARSER_parse (buf, r)))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Failed to parse DNS reply!\n");
@@ -1584,9 +1549,9 @@
for (i = 0; i < packet->num_answers; i++)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got record type %d (want %d)\n",
- packet->answers[i].type,
- rlh->record_type);
+ "Got record type %d (want %d)\n",
+ packet->answers[i].type,
+ rlh->record_type);
/* http://tools.ietf.org/html/rfc1034#section-3.6.2 */
if (packet->answers[i].type == GNUNET_GNS_RECORD_CNAME)
{
@@ -1641,8 +1606,7 @@
}
for (i = 0; i < packet->num_authority_records; i++)
- {
-
+ {
if (packet->authority_records[i].type == GNUNET_GNS_RECORD_NS)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1676,7 +1640,6 @@
"Nothing useful in DNS reply!\n");
finish_lookup (rh, rlh, 0, NULL);
GNUNET_DNSPARSER_free_packet (packet);
- return;
}
@@ -1688,12 +1651,13 @@
static void
send_dns_packet (struct ResolverHandle *rh)
{
- struct GNUNET_NETWORK_FDSet *rset = GNUNET_NETWORK_fdset_create ();
+ struct GNUNET_NETWORK_FDSet *rset;
+
+ rset = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set (rset, rh->dns_sock);
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending %dbyte DNS query\n",
- rh->dns_raw_packet_size);
+ "Sending %d byte DNS query\n",
+ (int) rh->dns_raw_packet_size);
if (GNUNET_SYSERR ==
GNUNET_NETWORK_socket_sendto (rh->dns_sock,
@@ -1712,9 +1676,7 @@
NULL,
&read_dns_response,
rh);
-
GNUNET_NETWORK_fdset_destroy (rset);
-
}
@@ -1728,17 +1690,17 @@
*/
static void
resolve_record_dns (struct ResolverHandle *rh,
- int rd_count,
+ unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
{
+ struct RecordLookupHandle *rlh = rh->proc_cls;
struct GNUNET_DNSPARSER_Query query;
struct GNUNET_DNSPARSER_Packet packet;
struct GNUNET_DNSPARSER_Flags flags;
struct in_addr dnsip;
struct sockaddr_in addr;
struct sockaddr *sa;
- int i;
- struct RecordLookupHandle *rlh = rh->proc_cls;
+ unsigned int i;
memset (&packet, 0, sizeof (struct GNUNET_DNSPARSER_Packet));
memset (rh->dns_name, 0, sizeof (rh->dns_name));
@@ -1839,7 +1801,6 @@
#if HAVE_SOCKADDR_IN_SIN_LEN
rh->dns_addr.sin_len = (u_char) sizeof (struct sockaddr_in);
#endif
-
send_dns_packet (rh);
}
@@ -1854,7 +1815,7 @@
*/
static void
resolve_record_vpn (struct ResolverHandle *rh,
- int rd_count,
+ unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
{
struct RecordLookupHandle *rlh = rh->proc_cls;
@@ -1880,8 +1841,6 @@
}
vpn = (struct vpn_data*)rd->data;
-
-
GNUNET_CRYPTO_hash ((char*)&vpn[1],
strlen ((char*)&vpn[1]) + 1,
&serv_desc);
@@ -1934,7 +1893,7 @@
static void
resolve_record_ns(struct ResolverHandle *rh)
{
- struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls;
+ struct RecordLookupHandle *rlh = rh->proc_cls;
/* We cancel here as to not include the ns lookup in the timeout */
if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
@@ -1980,7 +1939,7 @@
{
struct ResolverHandle *rh = cls;
struct RecordLookupHandle *rlh = rh->proc_cls;
- char new_name[MAX_DNS_NAME_LENGTH];
+ char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_DHT-%llu: dht lookup for query %s (%llus)
timed out.\n",
@@ -2015,7 +1974,7 @@
/**
* Start resolution in bg
*/
- GNUNET_snprintf (new_name, MAX_DNS_NAME_LENGTH,
+ GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
"%s.%s.%s",
rh->name, rh->authority_name, GNUNET_GNS_TLD);
strcpy (rh->name, new_name);
@@ -2043,7 +2002,7 @@
* @param rh the pending gns query
*/
static void
-resolve_delegation_dht(struct ResolverHandle *rh);
+resolve_delegation_dht (struct ResolverHandle *rh);
/**
@@ -2052,7 +2011,7 @@
* @param rh the resolver handle
*/
static void
-resolve_delegation_ns(struct ResolverHandle *rh);
+resolve_delegation_ns (struct ResolverHandle *rh);
/**
@@ -2064,9 +2023,9 @@
* @param rd record data (always NULL)
*/
static void
-handle_delegation_ns(void* cls, struct ResolverHandle *rh,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd);
+handle_delegation_ns (void* cls, struct ResolverHandle *rh,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd);
/**
@@ -2082,12 +2041,12 @@
*/
static void
process_pkey_revocation_result_ns (void *cls,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
- struct GNUNET_TIME_Absolute expiration,
- const char *name,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_RsaSignature *signature)
+ const struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+ struct GNUNET_TIME_Absolute expiration,
+ const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_RsaSignature
*signature)
{
struct ResolverHandle *rh = cls;
struct GNUNET_TIME_Relative remaining_time;
@@ -2223,10 +2182,7 @@
rh->id);
if (data == NULL)
return;
-
- nrb = (struct GNSNameRecordBlock*)data;
-
- /* stop dht lookup and timeout task */
+ /* stop dht lookup and timeout task */
GNUNET_DHT_get_stop (rh->get_handle);
rh->get_handle = NULL;
if (rh->dht_heap_node != NULL)
@@ -2283,7 +2239,7 @@
if (0 == strcmp(rh->name, ""))
strcpy(rh->name, rh->authority_name);
else
- GNUNET_snprintf(rh->name, MAX_DNS_NAME_LENGTH, "%s.%s",
+ GNUNET_snprintf(rh->name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
rh->name, rh->authority_name); //FIXME ret
rh->answered = 1;
break;
@@ -2408,7 +2364,7 @@
if (0 == strcmp(rh->name, ""))
strcpy(rh->name, rh->authority_name);
else
- GNUNET_snprintf(rh->name, MAX_DNS_NAME_LENGTH, "%s.%s",
+ GNUNET_snprintf(rh->name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
rh->name, rh->authority_name); //FIXME ret
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -2421,9 +2377,9 @@
//FIXME maybe define somewhere else?
#define MAX_SOA_LENGTH
sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint32_t)\
- +(MAX_DNS_NAME_LENGTH*2)
-#define MAX_MX_LENGTH sizeof(uint16_t)+MAX_DNS_NAME_LENGTH
-#define MAX_SRV_LENGTH (sizeof(uint16_t)*3)+MAX_DNS_NAME_LENGTH
+ +(GNUNET_DNSPARSER_MAX_NAME_LENGTH*2)
+#define MAX_MX_LENGTH sizeof(uint16_t)+GNUNET_DNSPARSER_MAX_NAME_LENGTH
+#define MAX_SRV_LENGTH (sizeof(uint16_t)*3)+GNUNET_DNSPARSER_MAX_NAME_LENGTH
/**
@@ -2485,7 +2441,7 @@
const struct GNUNET_NAMESTORE_RecordData *rd)
{
unsigned int i;
- char new_rr_data[MAX_DNS_NAME_LENGTH];
+ char new_rr_data[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
char new_mx_data[MAX_MX_LENGTH];
char new_soa_data[MAX_SOA_LENGTH];
char new_srv_data[MAX_SRV_LENGTH];
@@ -2609,9 +2565,9 @@
* @param rd record data
*/
static void
-handle_record_dht(void* cls, struct ResolverHandle *rh,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd)
+handle_record_dht (void* cls, struct ResolverHandle *rh,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd)
{
struct RecordLookupHandle* rlh = cls;
@@ -2712,6 +2668,8 @@
* Move one level up in the domain hierarchy and return the
* passed top level domain.
*
+ * FIXME: funky API: not only 'dest' is updated, so is 'name'!
+ *
* @param name the domain
* @param dest the destination where the tld will be put
*/
@@ -2722,8 +2680,8 @@
if (GNUNET_YES == is_canonical (name))
{
- strcpy(dest, name);
- strcpy(name, "");
+ strcpy (dest, name);
+ strcpy (name, "");
return;
}
@@ -2744,32 +2702,6 @@
/**
- * Checks if name is in tld
- *
- * @param name the name to check
- * @param tld the TLD to check for
- * @return GNUNET_YES or GNUNET_NO
- */
-int
-is_tld(const char* name, const char* tld)
-{
- int offset = 0;
-
- if (strlen(name) <= strlen(tld))
- return GNUNET_NO;
-
- offset = strlen(name)-strlen(tld);
- if (0 != strcmp(name+offset, tld))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "%s is not in .%s TLD\n", name, tld);
- return GNUNET_NO;
- }
- return GNUNET_YES;
-}
-
-
-/**
* DHT resolution for delegation finished. Processing result.
*
* @param cls the closure
@@ -2891,6 +2823,32 @@
/**
+ * Checks if name is in tld
+ *
+ * @param name the name to check
+ * @param tld the TLD to check for
+ * @return GNUNET_YES or GNUNET_NO
+ */
+int
+is_tld (const char* name, const char* tld)
+{
+ size_t offset = 0;
+
+ if (strlen (name) <= strlen (tld))
+ return GNUNET_NO;
+
+ offset = strlen (name) - strlen (tld);
+ if (0 != strcmp (name + offset, tld))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "%s is not in .%s TLD\n", name, tld);
+ return GNUNET_NO;
+ }
+ return GNUNET_YES;
+}
+
+
+/**
* Namestore resolution for delegation finished. Processing result.
*
* @param cls the closure
@@ -2903,10 +2861,9 @@
unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
{
- struct RecordLookupHandle* rlh;
- rlh = cls;
- int check_dht = GNUNET_YES;
- int s_len = 0;
+ struct RecordLookupHandle* rlh = cls;
+ int check_dht;
+ size_t s_len;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_NS-%llu: Resolution status: %d.\n",
@@ -3063,6 +3020,7 @@
* or we are authority
**/
+ check_dht = GNUNET_YES;
if ((rh->status & RSL_RECORD_EXISTS) &&
!(rh->status & RSL_RECORD_EXPIRED))
check_dht = GNUNET_NO;
@@ -3130,7 +3088,7 @@
struct ResolverHandle *rh = cls;
struct GNUNET_TIME_Relative remaining_time;
struct GNUNET_CRYPTO_ShortHashCode zone;
- char new_name[MAX_DNS_NAME_LENGTH];
+ char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
unsigned int i;
struct GNUNET_TIME_Absolute et;
@@ -3190,7 +3148,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_NS-%llu: Adding %s back to %s\n",
rh->id, rh->authority_name, rh->name);
- GNUNET_snprintf (new_name, MAX_DNS_NAME_LENGTH, "%s.%s",
+ GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
rh->name, rh->authority_name);
strcpy (rh->name, new_name);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3348,7 +3306,7 @@
}
else
{
- GNUNET_snprintf (new_name, MAX_DNS_NAME_LENGTH,
+ GNUNET_snprintf (new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
"%s.%s", rh->name, rh->authority_name);
strcpy (rh->name, new_name);
rh->proc (rh->proc_cls, rh, 0, NULL);
@@ -3405,8 +3363,8 @@
{
struct ResolverHandle *rh;
struct RecordLookupHandle* rlh;
- char string_hash[MAX_DNS_LABEL_LENGTH];
- char nzkey[MAX_DNS_LABEL_LENGTH];
+ char string_hash[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
+ char nzkey[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
char* nzkey_ptr = nzkey;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3426,7 +3384,7 @@
rlh = GNUNET_malloc (sizeof(struct RecordLookupHandle));
rh = GNUNET_malloc (sizeof (struct ResolverHandle));
rh->authority = zone;
- rh->id = rid++;
+ rh->id = rid_gen++;
rh->proc_cls = rlh;
rh->priv_key = key;
rh->timeout = timeout;
@@ -3612,11 +3570,11 @@
const struct GNUNET_CRYPTO_RsaSignature *signature)
{
struct ResolverHandle *rh = cls;
- struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls;
+ struct NameShortenHandle* nsh = rh->proc_cls;
struct AuthorityChain *next_authority;
- char result[MAX_DNS_NAME_LENGTH];
- char tmp_name[MAX_DNS_NAME_LENGTH];
+ char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
+ char tmp_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
size_t answer_len;
rh->namestore_task = NULL;
@@ -3684,7 +3642,7 @@
if (0 == strcmp (rh->name, ""))
strcpy (tmp_name, next_authority->name);
else
- GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH,
+ GNUNET_snprintf(tmp_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
"%s.%s", rh->name, next_authority->name);
strcpy(rh->name, tmp_name);
@@ -3728,11 +3686,11 @@
const struct GNUNET_CRYPTO_RsaSignature *signature)
{
struct ResolverHandle *rh = cls;
- struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls;
+ struct NameShortenHandle* nsh = rh->proc_cls;
struct AuthorityChain *next_authority;
- char result[MAX_DNS_NAME_LENGTH];
- char tmp_name[MAX_DNS_NAME_LENGTH];
+ char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
+ char tmp_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
size_t answer_len;
rh->namestore_task = NULL;
@@ -3798,7 +3756,7 @@
if (0 == strcmp (rh->name, ""))
strcpy (tmp_name, next_authority->name);
else
- GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH,
+ GNUNET_snprintf(tmp_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
"%s.%s", rh->name, next_authority->name);
strcpy(rh->name, tmp_name);
@@ -3843,10 +3801,10 @@
const struct GNUNET_CRYPTO_RsaSignature *signature)
{
struct ResolverHandle *rh = cls;
- struct NameShortenHandle* nsh = (struct NameShortenHandle*)rh->proc_cls;
+ struct NameShortenHandle* nsh = rh->proc_cls;
struct AuthorityChain *next_authority;
- char result[MAX_DNS_NAME_LENGTH];
- char tmp_name[MAX_DNS_NAME_LENGTH];
+ char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
+ char tmp_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
size_t answer_len;
rh->namestore_task = NULL;
@@ -3920,7 +3878,7 @@
if (0 == strcmp (rh->name, ""))
strcpy (tmp_name, next_authority->name);
else
- GNUNET_snprintf(tmp_name, MAX_DNS_NAME_LENGTH,
+ GNUNET_snprintf(tmp_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH,
"%s.%s", rh->name, next_authority->name);
strcpy(rh->name, tmp_name);
@@ -3959,7 +3917,7 @@
const struct GNUNET_NAMESTORE_RecordData *rd)
{
struct NameShortenHandle *nsh;
- char result[MAX_DNS_NAME_LENGTH];
+ char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
nsh = (struct NameShortenHandle *)cls;
rh->namestore_task = NULL;
@@ -4067,7 +4025,7 @@
{
struct ResolverHandle *rh = cls;
struct NameShortenHandle *nsh = rh->proc_cls;
- char new_name[MAX_DNS_NAME_LENGTH];
+ char new_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
rh->namestore_task = NULL;
@@ -4084,10 +4042,10 @@
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"No name found for zkey %s returning verbatim!\n", nsh->result);
/*if (strcmp(rh->name, "") != 0)
- GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, "%s.%s.%s",
+ GNUNET_snprintf(new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s.%s",
rh->name, enc, GNUNET_GNS_TLD_ZKEY);
else
- GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, "%s.%s",
+ GNUNET_snprintf(new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
enc, GNUNET_GNS_TLD_ZKEY);
strcpy (nsh->result, new_name);*/
@@ -4097,7 +4055,7 @@
}
if (strcmp(rh->name, "") != 0)
- GNUNET_snprintf(new_name, MAX_DNS_NAME_LENGTH, "%s.%s",
+ GNUNET_snprintf(new_name, GNUNET_DNSPARSER_MAX_NAME_LENGTH, "%s.%s",
rh->name, name);
else
strcpy(new_name, name);
@@ -4141,9 +4099,9 @@
{
struct ResolverHandle *rh;
struct NameShortenHandle *nsh;
- char string_hash[MAX_DNS_LABEL_LENGTH];
+ char string_hash[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
struct GNUNET_CRYPTO_ShortHashCode zkey;
- char nzkey[MAX_DNS_LABEL_LENGTH];
+ char nzkey[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
char* nzkey_ptr = nzkey;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -4169,12 +4127,9 @@
rh = GNUNET_malloc (sizeof (struct ResolverHandle));
rh->authority = *zone;
- rh->id = rid++;
- rh->priv_key = NULL;
- rh->namestore_task = NULL;
+ rh->id = rid_gen++;
rh->proc = &handle_delegation_ns_shorten;
rh->proc_cls = nsh;
- rh->id = rid++;
rh->private_local_zone = *zone;
GNUNET_CONTAINER_DLL_insert (nsh_head, nsh_tail, rh);
@@ -4245,7 +4200,6 @@
rh->authority_chain_tail = rh->authority_chain_head;
rh->authority_chain_head->zone = *zone;
-
/* Start delegation resolution in our namestore */
resolve_delegation_ns (rh);
}
@@ -4363,7 +4317,7 @@
nah = GNUNET_malloc(sizeof (struct GetNameAuthorityHandle));
rh = GNUNET_malloc(sizeof (struct ResolverHandle));
rh->authority = zone;
- rh->id = rid++;
+ rh->id = rid_gen++;
rh->private_local_zone = pzone;
GNUNET_CONTAINER_DLL_insert (nah_head, nah_tail, rh);
Modified: gnunet/src/gns/gnunet-service-gns_resolver.h
===================================================================
--- gnunet/src/gns/gnunet-service-gns_resolver.h 2012-10-30 19:16:03 UTC
(rev 24616)
+++ gnunet/src/gns/gnunet-service-gns_resolver.h 2012-10-30 20:52:14 UTC
(rev 24617)
@@ -59,7 +59,7 @@
/**
* (local) name of the authority
*/
- char name[MAX_DNS_LABEL_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* was the ns entry fresh
@@ -201,7 +201,7 @@
/**
* The name to resolve
*/
- char name[MAX_DNS_NAME_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* has this query been answered? how many matches
@@ -221,7 +221,7 @@
/**
* the name of the authoritative zone to query
*/
- char authority_name[MAX_DNS_LABEL_LENGTH];
+ char authority_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* a handle for dht lookups. should be NULL if no lookups are in progress
@@ -246,12 +246,12 @@
/**
* a synthesized dns name
*/
- char dns_name[MAX_DNS_NAME_LENGTH];
+ char dns_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* the authoritative dns zone
*/
- char dns_zone[MAX_DNS_NAME_LENGTH];
+ char dns_zone[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* the address of the DNS server FIXME not needed?
@@ -361,7 +361,7 @@
/**
* the name to look up
*/
- char name[MAX_DNS_NAME_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* Method to call on record resolution result
@@ -394,7 +394,7 @@
/**
* result of shorten
*/
- char result[MAX_DNS_NAME_LENGTH];
+ char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* root zone
@@ -409,7 +409,7 @@
/**
* name of private zone
*/
- char private_zone_name[MAX_DNS_LABEL_LENGTH];
+ char private_zone_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* shorten zone
@@ -419,7 +419,7 @@
/**
* name of shorten zone
*/
- char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
+ char shorten_zone_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
};
@@ -432,12 +432,12 @@
/**
* the name to look up authority for
*/
- char name[MAX_DNS_NAME_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* the result
*/
- char result[MAX_DNS_NAME_LENGTH];
+ char result[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
/**
* Method to call on result
@@ -469,12 +469,12 @@
/**
* the name to store the zone under
*/
- char name[MAX_DNS_LABEL_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* test name to store the zone under
*/
- char test_name[MAX_DNS_LABEL_LENGTH];
+ char test_name[GNUNET_DNSPARSER_MAX_LABEL_LENGTH];
/**
* the zone of our authority
Modified: gnunet/src/gns/test_gns_cname_lookup.c
===================================================================
--- gnunet/src/gns/test_gns_cname_lookup.c 2012-10-30 19:16:03 UTC (rev
24616)
+++ gnunet/src/gns/test_gns_cname_lookup.c 2012-10-30 20:52:14 UTC (rev
24617)
@@ -164,32 +164,32 @@
if (rd_count == 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Lookup failed, rp_filtering?\n");
- ok = 2;
- GNUNET_SCHEDULER_shutdown ();
- return;
+ "CNAME to DNS delegation failed. System offline?\n");
}
- ok = 1;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
- for (i=0; i<rd_count; i++)
+ else
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
- if (rd[i].record_type == GNUNET_GNS_RECORD_A)
+ ok = 1;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
+ for (i=0; i<rd_count; i++)
{
- memcpy(&a, rd[i].data, sizeof(a));
- addr = inet_ntoa(a);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
- if (0 == strcmp(addr, TEST_IP_DNS))
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
+ if (rd[i].record_type == GNUNET_GNS_RECORD_A)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "%s correctly resolved to %s!\n", TEST_DOMAIN_DNS, addr);
- ok = 0;
+ memcpy(&a, rd[i].data, sizeof(a));
+ addr = inet_ntoa(a);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
+ if (0 == strcmp(addr, TEST_IP_DNS))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "%s correctly resolved to %s!\n", TEST_DOMAIN_DNS, addr);
+ ok = 0;
+ }
}
- }
- else
+ else
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n");
}
+ }
}
GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN_PLUS, GNUNET_GNS_RECORD_CNAME,
GNUNET_YES,
Modified: gnunet/src/gns/test_gns_max_queries.c
===================================================================
--- gnunet/src/gns/test_gns_max_queries.c 2012-10-30 19:16:03 UTC (rev
24616)
+++ gnunet/src/gns/test_gns_max_queries.c 2012-10-30 20:52:14 UTC (rev
24617)
@@ -212,7 +212,7 @@
commence_testing (void *cls, int32_t success, const char *emsg)
{
int i;
- char lookup_name[MAX_DNS_NAME_LENGTH];
+ char lookup_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
struct GNUNET_GNS_LookupRequest *lr;
gns_handle = GNUNET_GNS_connect(cfg);
@@ -229,7 +229,7 @@
for (i=0; i<max_parallel_lookups+TEST_ADDITIONAL_LOOKUPS; i++)
{
GNUNET_snprintf(lookup_name,
- MAX_DNS_NAME_LENGTH,
+ GNUNET_DNSPARSER_MAX_NAME_LENGTH,
"www.doesnotexist-%d.bob.gads", i);
lr = GNUNET_GNS_lookup (gns_handle, lookup_name, GNUNET_GNS_RECORD_A,
GNUNET_NO,
Modified: gnunet/src/gns/test_gns_simple_zkey_lookup.c
===================================================================
--- gnunet/src/gns/test_gns_simple_zkey_lookup.c 2012-10-30 19:16:03 UTC
(rev 24616)
+++ gnunet/src/gns/test_gns_simple_zkey_lookup.c 2012-10-30 20:52:14 UTC
(rev 24617)
@@ -162,7 +162,7 @@
static void
commence_testing (void *cls, int32_t success, const char *emsg)
{
- char name[MAX_DNS_NAME_LENGTH];
+ char name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
char* pos;
struct GNUNET_CRYPTO_ShortHashAsciiEncoded hash_str;
Modified: gnunet/src/include/gnunet_common.h
===================================================================
--- gnunet/src/include/gnunet_common.h 2012-10-30 19:16:03 UTC (rev 24616)
+++ gnunet/src/include/gnunet_common.h 2012-10-30 20:52:14 UTC (rev 24617)
@@ -238,7 +238,7 @@
/**
- * @brief 512-bit hashcode
+ * @brief A SHA-512 hashcode
*/
struct GNUNET_HashCode
{
@@ -247,9 +247,8 @@
/**
- * FIXME
- * @brief 256-bit hashcode
- **/
+ * @brief A SHA-256 hashcode
+ */
struct GNUNET_CRYPTO_ShortHashCode
{
uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */
Modified: gnunet/src/include/gnunet_dnsparser_lib.h
===================================================================
--- gnunet/src/include/gnunet_dnsparser_lib.h 2012-10-30 19:16:03 UTC (rev
24616)
+++ gnunet/src/include/gnunet_dnsparser_lib.h 2012-10-30 20:52:14 UTC (rev
24617)
@@ -31,6 +31,17 @@
#include "gnunet_common.h"
/**
+ * Maximum length of a label in DNS.
+ */
+#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH 63
+
+/**
+ * Maximum length of a name in DNS.
+ */
+#define GNUNET_DNSPARSER_MAX_NAME_LENGTH 253
+
+
+/**
* A few common DNS types.
*/
#define GNUNET_DNSPARSER_TYPE_A 1
Modified: gnunet/src/include/gnunet_namestore_service.h
===================================================================
--- gnunet/src/include/gnunet_namestore_service.h 2012-10-30 19:16:03 UTC
(rev 24616)
+++ gnunet/src/include/gnunet_namestore_service.h 2012-10-30 20:52:14 UTC
(rev 24617)
@@ -526,16 +526,6 @@
/**
- * Checks if a name is wellformed
- *
- * @param name the name to check
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int
-GNUNET_NAMESTORE_check_name (const char * name);
-
-
-/**
* Convert the 'value' of a record to a string.
*
* @param type type of the record
Modified: gnunet/src/namestore/namestore_common.c
===================================================================
--- gnunet/src/namestore/namestore_common.c 2012-10-30 19:16:03 UTC (rev
24616)
+++ gnunet/src/namestore/namestore_common.c 2012-10-30 20:52:14 UTC (rev
24617)
@@ -318,23 +318,7 @@
return sig;
}
-/**
- * Checks if a name is wellformed
- *
- * @param name the name to check
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int
-GNUNET_NAMESTORE_check_name (const char * name)
-{
- if (name == NULL)
- return GNUNET_SYSERR;
- if (strlen (name) > 63)
- return GNUNET_SYSERR;
- return GNUNET_OK;
-}
-
/**
* Convert the 'value' of a record to a string.
*
@@ -489,11 +473,11 @@
struct soa_data *soa;
struct vpn_data *vpn;
struct tlsa_data *tlsa;
- char result[253];
- char soa_rname[63];
- char soa_mname[63];
- char s_peer[104];
- char s_serv[253];
+ char result[253 + 1];
+ char soa_rname[253 + 1];
+ char soa_mname[253 + 1];
+ char s_peer[103 + 1];
+ char s_serv[253 + 1];
uint32_t soa_serial;
uint32_t soa_refresh;
uint32_t soa_retry;
@@ -502,15 +486,22 @@
uint16_t mx_pref;
uint16_t mx_pref_n;
uint16_t proto;
- int ret;
switch (type)
{
case 0:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unsupported record type %d\n"),
+ (int) type);
return GNUNET_SYSERR;
case GNUNET_DNSPARSER_TYPE_A:
if (1 != inet_pton (AF_INET, s, &value_a))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse IPv4 address `%s'\n"),
+ s);
return GNUNET_SYSERR;
+ }
*data = GNUNET_malloc (sizeof (struct in_addr));
memcpy (*data, &value_a, sizeof (value_a));
*data_size = sizeof (value_a);
@@ -524,13 +515,16 @@
*data_size = strlen (s) + 1;
return GNUNET_OK;
case GNUNET_DNSPARSER_TYPE_SOA:
-
- if (SSCANF(s, "rname=%s mname=%s %u,%u,%u,%u,%u",
- soa_rname, soa_mname,
- &soa_serial, &soa_refresh, &soa_retry, &soa_expire, &soa_min)
- != 7)
+ if (7 != SSCANF (s,
+ "rname=%253s mname=%253s %u,%u,%u,%u,%u",
+ soa_rname, soa_mname,
+ &soa_serial, &soa_refresh, &soa_retry, &soa_expire,
&soa_min))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse SOA record `%s'\n"),
+ s);
return GNUNET_SYSERR;
-
+ }
*data_size = sizeof (struct
soa_data)+strlen(soa_rname)+strlen(soa_mname)+2;
*data = GNUNET_malloc (*data_size);
soa = (struct soa_data*)*data;
@@ -542,14 +536,18 @@
strcpy((char*)&soa[1], soa_rname);
strcpy((char*)&soa[1]+strlen(*data)+1, soa_mname);
return GNUNET_OK;
-
case GNUNET_DNSPARSER_TYPE_PTR:
*data = GNUNET_strdup (s);
*data_size = strlen (s);
return GNUNET_OK;
case GNUNET_DNSPARSER_TYPE_MX:
- if (SSCANF(s, "%hu,%s", &mx_pref, result) != 2)
+ if (2 != SSCANF(s, "%hu,%253s", &mx_pref, result))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse MX record `%s'\n"),
+ s);
return GNUNET_SYSERR;
+ }
*data_size = sizeof (uint16_t)+strlen(result)+1;
*data = GNUNET_malloc (*data_size);
mx_pref_n = htons(mx_pref);
@@ -562,7 +560,12 @@
return GNUNET_OK;
case GNUNET_DNSPARSER_TYPE_AAAA:
if (1 != inet_pton (AF_INET6, s, &value_aaaa))
- return GNUNET_SYSERR;
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse IPv6 address `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
*data = GNUNET_malloc (sizeof (struct in6_addr));
*data_size = sizeof (struct in6_addr);
memcpy (*data, &value_aaaa, sizeof (value_aaaa));
@@ -570,7 +573,12 @@
case GNUNET_NAMESTORE_TYPE_PKEY:
if (GNUNET_OK !=
GNUNET_CRYPTO_short_hash_from_string (s, &pkey))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to parse PKEY record `%s'\n"),
+ s);
return GNUNET_SYSERR;
+ }
*data = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_ShortHashCode));
memcpy (*data, &pkey, sizeof (pkey));
*data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode);
@@ -584,52 +592,49 @@
*data_size = strlen (s);
return GNUNET_OK;
case GNUNET_NAMESTORE_TYPE_VPN:
-
- ret = SSCANF (s,"%hu %s %s",
- &proto, s_peer, s_serv);
- if (3 != ret)
+ if (3 != SSCANF (s,"%hu %103s %253s",
+ &proto, s_peer, s_serv))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable to parse VPN record string %s %d\n", s, ret);
+ _("Unable to parse VPN record string `%s'\n"),
+ s);
return GNUNET_SYSERR;
}
*data_size = sizeof (struct vpn_data) + strlen (s_serv) + 1;
- *data = GNUNET_malloc (*data_size);
-
- vpn = (struct vpn_data*)*data;
-
- if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer,
&vpn->peer))
+ *data = vpn = GNUNET_malloc (*data_size);
+ if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char*)&s_peer,
+ &vpn->peer))
{
- GNUNET_free (*data);
+ GNUNET_free (vpn);
+ *data_size = 0;
return GNUNET_SYSERR;
}
-
vpn->proto = htons (proto);
strcpy ((char*)&vpn[1], s_serv);
return GNUNET_OK;
case GNUNET_DNSPARSER_TYPE_TLSA:
*data_size = sizeof (struct tlsa_data) + strlen (s) - 6;
- *data = GNUNET_malloc (*data_size);
- tlsa = (struct tlsa_data*)*data;
- ret = SSCANF (s, "%c %c %c %s",
- &tlsa->usage,
- &tlsa->selector,
- &tlsa->matching_type,
- (char*)&tlsa[1]);
-
- if (4 != ret)
+ *data = tlsa = GNUNET_malloc (*data_size);
+ if (4 != SSCANF (s, "%c %c %c %s",
+ &tlsa->usage,
+ &tlsa->selector,
+ &tlsa->matching_type,
+ (char*)&tlsa[1]))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable to parse TLSA record string %s\n", s);
+ _("Unable to parse TLSA record string `%s'\n"),
+ s);
*data_size = 0;
GNUNET_free (tlsa);
return GNUNET_SYSERR;
}
return GNUNET_OK;
default:
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unsupported record type %d\n"),
+ (int) type);
+ return GNUNET_SYSERR;
}
- return GNUNET_SYSERR;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r24617 - in gnunet/src: gns include namestore,
gnunet <=