aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c164
1 files changed, 58 insertions, 106 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index e13beb889..90cd47e1d 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2013 GNUnet e.V. 3 Copyright (C) 2011-2018 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -29,7 +29,7 @@
29#include "gnunet_dnsparser_lib.h" 29#include "gnunet_dnsparser_lib.h"
30#include "gnunet_dht_service.h" 30#include "gnunet_dht_service.h"
31#include "gnunet_namecache_service.h" 31#include "gnunet_namecache_service.h"
32#include "gnunet_identity_service.h" 32#include "gnunet_gnsrecord_lib.h"
33#include "gnunet_gns_service.h" 33#include "gnunet_gns_service.h"
34#include "gnunet_statistics_service.h" 34#include "gnunet_statistics_service.h"
35#include "gns.h" 35#include "gns.h"
@@ -44,7 +44,7 @@
44struct GnsClient; 44struct GnsClient;
45 45
46/** 46/**
47 * Handle to a lookup operation from api 47 * Handle to a lookup operation from client via API.
48 */ 48 */
49struct ClientLookupHandle 49struct ClientLookupHandle
50{ 50{
@@ -76,6 +76,10 @@ struct ClientLookupHandle
76 76
77}; 77};
78 78
79
80/**
81 * Information we track per connected client.
82 */
79struct GnsClient 83struct GnsClient
80{ 84{
81 /** 85 /**
@@ -122,7 +126,7 @@ struct GNS_TopLevelDomain
122 /** 126 /**
123 * Public key associated with the @a tld. 127 * Public key associated with the @a tld.
124 */ 128 */
125 struct GNUNET_CRYPTO_EddsaPublicKey pkey; 129 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
126 130
127 /** 131 /**
128 * Top-level domain as a string, including leading ".". 132 * Top-level domain as a string, including leading ".".
@@ -143,17 +147,6 @@ static struct GNUNET_DHT_Handle *dht_handle;
143static struct GNUNET_NAMECACHE_Handle *namecache_handle; 147static struct GNUNET_NAMECACHE_Handle *namecache_handle;
144 148
145/** 149/**
146 * Our handle to the identity service
147 */
148static struct GNUNET_IDENTITY_Handle *identity_handle;
149
150/**
151 * Our handle to the identity operation to find the master zone
152 * for intercepted queries.
153 */
154static struct GNUNET_IDENTITY_Operation *identity_op;
155
156/**
157 * #GNUNET_YES if ipv6 is supported 150 * #GNUNET_YES if ipv6 is supported
158 */ 151 */
159static int v6_enabled; 152static int v6_enabled;
@@ -188,7 +181,7 @@ static struct GNS_TopLevelDomain *tld_tail;
188 */ 181 */
189int 182int
190GNS_find_tld (const char *tld_str, 183GNS_find_tld (const char *tld_str,
191 struct GNUNET_CRYPTO_EddsaPublicKey *pkey) 184 struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
192{ 185{
193 if ('\0' == *tld_str) 186 if ('\0' == *tld_str)
194 return GNUNET_NO; 187 return GNUNET_NO;
@@ -204,16 +197,36 @@ GNS_find_tld (const char *tld_str,
204 } 197 }
205 } 198 }
206 if (GNUNET_OK == 199 if (GNUNET_OK ==
207 GNUNET_STRINGS_string_to_data (tld_str + 1, 200 GNUNET_GNSRECORD_zkey_to_pkey (tld_str + 1,
208 strlen (tld_str + 1), 201 pkey))
209 pkey,
210 sizeof (*pkey)))
211 return GNUNET_YES; /* TLD string *was* the public key */ 202 return GNUNET_YES; /* TLD string *was* the public key */
212 return GNUNET_NO; 203 return GNUNET_NO;
213} 204}
214 205
215 206
216/** 207/**
208 * Obtain the TLD of the given @a name.
209 *
210 * @param name a name
211 * @return the part of @a name after the last ".",
212 * or @a name if @a name does not contain a "."
213 */
214const char *
215GNS_get_tld (const char *name)
216{
217 const char *tld;
218
219 tld = strrchr (name,
220 (unsigned char) '.');
221 if (NULL == tld)
222 tld = name;
223 else
224 tld++; /* skip the '.' */
225 return tld;
226}
227
228
229/**
217 * Task run during shutdown. 230 * Task run during shutdown.
218 * 231 *
219 * @param cls unused 232 * @param cls unused
@@ -223,19 +236,10 @@ static void
223shutdown_task (void *cls) 236shutdown_task (void *cls)
224{ 237{
225 struct GNS_TopLevelDomain *tld; 238 struct GNS_TopLevelDomain *tld;
239
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
227 "Shutting down!\n"); 241 "Shutting down!\n");
228 GNS_interceptor_done (); 242 GNS_interceptor_done ();
229 if (NULL != identity_op)
230 {
231 GNUNET_IDENTITY_cancel (identity_op);
232 identity_op = NULL;
233 }
234 if (NULL != identity_handle)
235 {
236 GNUNET_IDENTITY_disconnect (identity_handle);
237 identity_handle = NULL;
238 }
239 GNS_resolver_done (); 243 GNS_resolver_done ();
240 if (NULL != statistics) 244 if (NULL != statistics)
241 { 245 {
@@ -415,7 +419,8 @@ handle_lookup (void *cls,
415 419
416 GNUNET_SERVICE_client_continue (gc->client); 420 GNUNET_SERVICE_client_continue (gc->client);
417 utf_in = (const char *) &sh_msg[1]; 421 utf_in = (const char *) &sh_msg[1];
418 GNUNET_STRINGS_utf8_tolower (utf_in, nameptr); 422 GNUNET_STRINGS_utf8_tolower (utf_in,
423 nameptr);
419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
420 "Received LOOKUP `%s' message\n", 425 "Received LOOKUP `%s' message\n",
421 name); 426 name);
@@ -431,7 +436,9 @@ handle_lookup (void *cls,
431 { 436 {
432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
433 "LOOKUP: Query for A record but AF_INET not supported!"); 438 "LOOKUP: Query for A record but AF_INET not supported!");
434 send_lookup_response (clh, 0, NULL); 439 send_lookup_response (clh,
440 0,
441 NULL);
435 return; 442 return;
436 } 443 }
437 if ( (GNUNET_DNSPARSER_TYPE_AAAA == ntohl (sh_msg->type)) && 444 if ( (GNUNET_DNSPARSER_TYPE_AAAA == ntohl (sh_msg->type)) &&
@@ -439,7 +446,9 @@ handle_lookup (void *cls,
439 { 446 {
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "LOOKUP: Query for AAAA record but AF_INET6 not supported!"); 448 "LOOKUP: Query for AAAA record but AF_INET6 not supported!");
442 send_lookup_response (clh, 0, NULL); 449 send_lookup_response (clh,
450 0,
451 NULL);
443 return; 452 return;
444 } 453 }
445 clh->lookup = GNS_resolver_lookup (&sh_msg->zone, 454 clh->lookup = GNS_resolver_lookup (&sh_msg->zone,
@@ -454,57 +463,6 @@ handle_lookup (void *cls,
454 463
455 464
456/** 465/**
457 * Method called to inform about the ego to be used for the master zone
458 * for DNS interceptions.
459 *
460 * This function is only called ONCE, and 'NULL' being passed in
461 * @a ego does indicate that interception is not configured.
462 * If @a ego is non-NULL, we should start to intercept DNS queries
463 * and resolve ".gnu" queries using the given ego as the master zone.
464 *
465 * @param cls closure, our `const struct GNUNET_CONFIGURATION_Handle *c`
466 * @param ego ego handle
467 * @param ctx context for application to store data for this ego
468 * (during the lifetime of this process, initially NULL)
469 * @param name name assigned by the user for this ego,
470 * NULL if the user just deleted the ego and it
471 * must thus no longer be used
472 */
473static void
474identity_intercept_cb (void *cls,
475 struct GNUNET_IDENTITY_Ego *ego,
476 void **ctx,
477 const char *name)
478{
479 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
480 struct GNUNET_CRYPTO_EcdsaPublicKey dns_root;
481
482 identity_op = NULL;
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
484 "Looking for gns-intercept ego\n");
485 if (NULL == ego)
486 {
487 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
488 _("No ego configured for `%s`\n"),
489 "gns-intercept");
490
491 return;
492 }
493 GNUNET_IDENTITY_ego_get_public_key (ego,
494 &dns_root);
495 if (GNUNET_SYSERR ==
496 GNS_interceptor_init (&dns_root,
497 cfg))
498 {
499 GNUNET_break (0);
500 GNUNET_SCHEDULER_add_now (&shutdown_task,
501 NULL);
502 return;
503 }
504}
505
506
507/**
508 * Reads the configuration and populates TLDs 466 * Reads the configuration and populates TLDs
509 * 467 *
510 * @param cls unused 468 * @param cls unused
@@ -518,7 +476,7 @@ read_service_conf (void *cls,
518 const char *option, 476 const char *option,
519 const char *value) 477 const char *value)
520{ 478{
521 struct GNUNET_CRYPTO_EddsaPublicKey pk; 479 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
522 struct GNS_TopLevelDomain *tld; 480 struct GNS_TopLevelDomain *tld;
523 481
524 if (option[0] != '.') 482 if (option[0] != '.')
@@ -536,7 +494,7 @@ read_service_conf (void *cls,
536 return; 494 return;
537 } 495 }
538 tld = GNUNET_new (struct GNS_TopLevelDomain); 496 tld = GNUNET_new (struct GNS_TopLevelDomain);
539 tld->tld = GNUNET_strdup (option); 497 tld->tld = GNUNET_strdup (&option[1]);
540 tld->pkey = pk; 498 tld->pkey = pk;
541 GNUNET_CONTAINER_DLL_insert (tld_head, 499 GNUNET_CONTAINER_DLL_insert (tld_head,
542 tld_tail, 500 tld_tail,
@@ -544,7 +502,6 @@ read_service_conf (void *cls,
544} 502}
545 503
546 504
547
548/** 505/**
549 * Process GNS requests. 506 * Process GNS requests.
550 * 507 *
@@ -593,29 +550,24 @@ run (void *cls,
593 NULL); 550 NULL);
594 return; 551 return;
595 } 552 }
596
597 identity_handle = GNUNET_IDENTITY_connect (c,
598 NULL,
599 NULL);
600 if (NULL == identity_handle)
601 {
602 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
603 "Could not connect to identity service!\n");
604 }
605 else
606 {
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
608 "Looking for gns-intercept ego\n");
609 identity_op = GNUNET_IDENTITY_get (identity_handle,
610 "gns-intercept",
611 &identity_intercept_cb,
612 (void *) c);
613 }
614 GNS_resolver_init (namecache_handle, 553 GNS_resolver_init (namecache_handle,
615 dht_handle, 554 dht_handle,
616 c, 555 c,
617 max_parallel_bg_queries); 556 max_parallel_bg_queries);
618 statistics = GNUNET_STATISTICS_create ("gns", c); 557 if ( (GNUNET_YES ==
558 GNUNET_CONFIGURATION_get_value_yesno (c,
559 "gns",
560 "INTERCEPT_DNS")) &&
561 (GNUNET_SYSERR ==
562 GNS_interceptor_init (c)) )
563 {
564 GNUNET_break (0);
565 GNUNET_SCHEDULER_add_now (&shutdown_task,
566 NULL);
567 return;
568 }
569 statistics = GNUNET_STATISTICS_create ("gns",
570 c);
619 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 571 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
620 NULL); 572 NULL);
621} 573}