diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-29 18:31:00 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-29 18:31:00 +0900 |
commit | 914fd6adac878abfa3050568ba02a1c57a150e8e (patch) | |
tree | 28c4fee5f4696ac36f8fda24594453baf87501c9 | |
parent | 0c673248ab51517532cb5782f4999bd870b7023e (diff) | |
download | gnunet-914fd6adac878abfa3050568ba02a1c57a150e8e.tar.gz gnunet-914fd6adac878abfa3050568ba02a1c57a150e8e.zip |
-fix GNS API
-rw-r--r-- | src/gns/gns.h | 13 | ||||
-rw-r--r-- | src/gns/gns_api.c | 16 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns.c | 33 | ||||
-rw-r--r-- | src/identity/identity_api_suffix_lookup.c | 17 |
4 files changed, 56 insertions, 23 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h index d824742ad..d882278f5 100644 --- a/src/gns/gns.h +++ b/src/gns/gns.h | |||
@@ -46,11 +46,6 @@ struct LookupMessage | |||
46 | uint32_t id GNUNET_PACKED; | 46 | uint32_t id GNUNET_PACKED; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Zone that is to be used for lookup | ||
50 | */ | ||
51 | struct GNUNET_IDENTITY_PublicKey zone; | ||
52 | |||
53 | /** | ||
54 | * Local options for where to look for results | 49 | * Local options for where to look for results |
55 | * (an `enum GNUNET_GNS_LocalOptions` in NBO). | 50 | * (an `enum GNUNET_GNS_LocalOptions` in NBO). |
56 | */ | 51 | */ |
@@ -68,7 +63,13 @@ struct LookupMessage | |||
68 | */ | 63 | */ |
69 | int32_t type GNUNET_PACKED; | 64 | int32_t type GNUNET_PACKED; |
70 | 65 | ||
71 | /* Followed by the zero-terminated name to look up */ | 66 | /** |
67 | * Length of the zone key | ||
68 | */ | ||
69 | uint32_t key_len GNUNET_PACKED; | ||
70 | /** | ||
71 | * Followed by the zone that is to be used for lookup | ||
72 | * Followed by the zero-terminated name to look up */ | ||
72 | }; | 73 | }; |
73 | 74 | ||
74 | 75 | ||
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index 841a0d240..9e25154ef 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c | |||
@@ -354,6 +354,9 @@ GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, | |||
354 | struct LookupMessage *lookup_msg; | 354 | struct LookupMessage *lookup_msg; |
355 | struct GNUNET_GNS_LookupRequest *lr; | 355 | struct GNUNET_GNS_LookupRequest *lr; |
356 | size_t nlen; | 356 | size_t nlen; |
357 | size_t key_len; | ||
358 | ssize_t written; | ||
359 | char *buf; | ||
357 | 360 | ||
358 | if (NULL == name) | 361 | if (NULL == name) |
359 | { | 362 | { |
@@ -374,16 +377,23 @@ GNUNET_GNS_lookup_limited (struct GNUNET_GNS_Handle *handle, | |||
374 | lr->lookup_proc = proc; | 377 | lr->lookup_proc = proc; |
375 | lr->proc_cls = proc_cls; | 378 | lr->proc_cls = proc_cls; |
376 | lr->r_id = handle->r_id_gen++; | 379 | lr->r_id = handle->r_id_gen++; |
380 | key_len = GNUNET_IDENTITY_public_key_get_length (zone); | ||
377 | lr->env = GNUNET_MQ_msg_extra (lookup_msg, | 381 | lr->env = GNUNET_MQ_msg_extra (lookup_msg, |
378 | nlen, | 382 | nlen + key_len, |
379 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP); | 383 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP); |
384 | buf = (char *) &lookup_msg[1]; | ||
380 | lookup_msg->id = htonl (lr->r_id); | 385 | lookup_msg->id = htonl (lr->r_id); |
381 | lookup_msg->options = htons ((uint16_t) options); | 386 | lookup_msg->options = htons ((uint16_t) options); |
382 | lookup_msg->recursion_depth_limit | 387 | lookup_msg->recursion_depth_limit |
383 | = htons (recursion_depth_limit); | 388 | = htons (recursion_depth_limit); |
384 | lookup_msg->zone = *zone; | 389 | lookup_msg->key_len = htonl (key_len); |
390 | written = GNUNET_IDENTITY_write_public_key_to_buffer (zone, | ||
391 | buf, | ||
392 | key_len); | ||
393 | GNUNET_assert (0 <= written); | ||
394 | buf += written; | ||
385 | lookup_msg->type = htonl (type); | 395 | lookup_msg->type = htonl (type); |
386 | GNUNET_memcpy (&lookup_msg[1], | 396 | GNUNET_memcpy (buf, |
387 | name, | 397 | name, |
388 | nlen); | 398 | nlen); |
389 | GNUNET_CONTAINER_DLL_insert (handle->lookup_head, | 399 | GNUNET_CONTAINER_DLL_insert (handle->lookup_head, |
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 6a11ec2ce..7e770ce5a 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -395,10 +395,11 @@ check_lookup (void *cls, | |||
395 | const struct LookupMessage *l_msg) | 395 | const struct LookupMessage *l_msg) |
396 | { | 396 | { |
397 | size_t nlen; | 397 | size_t nlen; |
398 | size_t klen; | ||
398 | 399 | ||
399 | (void) cls; | 400 | (void) cls; |
400 | GNUNET_MQ_check_zero_termination (l_msg); | 401 | klen = ntohl (l_msg->key_len); |
401 | nlen = ntohs (l_msg->header.size) - sizeof(struct LookupMessage); | 402 | nlen = ntohs (l_msg->header.size) - sizeof(struct LookupMessage) - klen; |
402 | if (nlen > GNUNET_DNSPARSER_MAX_NAME_LENGTH) | 403 | if (nlen > GNUNET_DNSPARSER_MAX_NAME_LENGTH) |
403 | { | 404 | { |
404 | GNUNET_break (0); | 405 | GNUNET_break (0); |
@@ -420,19 +421,37 @@ handle_lookup (void *cls, | |||
420 | { | 421 | { |
421 | struct GnsClient *gc = cls; | 422 | struct GnsClient *gc = cls; |
422 | struct ClientLookupHandle *clh; | 423 | struct ClientLookupHandle *clh; |
424 | struct GNUNET_IDENTITY_PublicKey zone; | ||
423 | const char *name; | 425 | const char *name; |
426 | size_t key_len; | ||
427 | size_t read; | ||
424 | 428 | ||
425 | GNUNET_SERVICE_client_continue (gc->client); | 429 | GNUNET_SERVICE_client_continue (gc->client); |
426 | name = (const char *) &sh_msg[1]; | 430 | key_len = ntohl (sh_msg->key_len); |
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
428 | "Received LOOKUP `%s' message\n", | ||
429 | name); | ||
430 | clh = GNUNET_new (struct ClientLookupHandle); | 431 | clh = GNUNET_new (struct ClientLookupHandle); |
431 | GNUNET_CONTAINER_DLL_insert (gc->clh_head, | 432 | GNUNET_CONTAINER_DLL_insert (gc->clh_head, |
432 | gc->clh_tail, | 433 | gc->clh_tail, |
433 | clh); | 434 | clh); |
434 | clh->gc = gc; | 435 | clh->gc = gc; |
435 | clh->request_id = sh_msg->id; | 436 | clh->request_id = sh_msg->id; |
437 | if ((GNUNET_SYSERR == | ||
438 | GNUNET_IDENTITY_read_public_key_from_buffer (&sh_msg[1], | ||
439 | key_len, | ||
440 | &zone, | ||
441 | &read)) || | ||
442 | (read != key_len)) | ||
443 | { | ||
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
445 | "LOOKUP: Failed to read zone key!"); | ||
446 | send_lookup_response (clh, | ||
447 | 0, | ||
448 | NULL); | ||
449 | return; | ||
450 | } | ||
451 | name = (const char *) &sh_msg[1] + key_len; | ||
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
453 | "Received LOOKUP `%s' message\n", | ||
454 | name); | ||
436 | if ((GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) && | 455 | if ((GNUNET_DNSPARSER_TYPE_A == ntohl (sh_msg->type)) && |
437 | (GNUNET_OK != v4_enabled)) | 456 | (GNUNET_OK != v4_enabled)) |
438 | { | 457 | { |
@@ -453,7 +472,7 @@ handle_lookup (void *cls, | |||
453 | NULL); | 472 | NULL); |
454 | return; | 473 | return; |
455 | } | 474 | } |
456 | clh->lookup = GNS_resolver_lookup (&sh_msg->zone, | 475 | clh->lookup = GNS_resolver_lookup (&zone, |
457 | ntohl (sh_msg->type), | 476 | ntohl (sh_msg->type), |
458 | name, | 477 | name, |
459 | (enum GNUNET_GNS_LocalOptions) ntohs ( | 478 | (enum GNUNET_GNS_LocalOptions) ntohs ( |
diff --git a/src/identity/identity_api_suffix_lookup.c b/src/identity/identity_api_suffix_lookup.c index fa6bd8310..4b459345d 100644 --- a/src/identity/identity_api_suffix_lookup.c +++ b/src/identity/identity_api_suffix_lookup.c | |||
@@ -138,13 +138,16 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
138 | tmp = (const char*) &um[1]; | 138 | tmp = (const char*) &um[1]; |
139 | str = (0 == name_len) ? NULL : tmp; | 139 | str = (0 == name_len) ? NULL : tmp; |
140 | memset (&private_key, 0, sizeof (private_key)); | 140 | memset (&private_key, 0, sizeof (private_key)); |
141 | key_len = ntohs (um->header.size) - name_len; | 141 | key_len = ntohs (um->header.size) - name_len - sizeof (*um); |
142 | GNUNET_assert (GNUNET_SYSERR != | 142 | if (0 < key_len) |
143 | GNUNET_IDENTITY_read_private_key_from_buffer (tmp + name_len, | 143 | { |
144 | key_len, | 144 | GNUNET_assert (GNUNET_SYSERR != |
145 | &private_key, | 145 | GNUNET_IDENTITY_read_private_key_from_buffer (tmp + name_len, |
146 | &kb_read)); | 146 | key_len, |
147 | GNUNET_assert (key_len == kb_read); | 147 | &private_key, |
148 | &kb_read)); | ||
149 | GNUNET_assert (key_len == kb_read); | ||
150 | } | ||
148 | el->cb (el->cb_cls, &private_key, str); | 151 | el->cb (el->cb_cls, &private_key, str); |
149 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); | 152 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); |
150 | } | 153 | } |