diff options
Diffstat (limited to 'src/gns/gnunet-gns.c')
-rw-r--r-- | src/gns/gnunet-gns.c | 162 |
1 files changed, 20 insertions, 142 deletions
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c index 17fe4cbda..a261e008b 100644 --- a/src/gns/gnunet-gns.c +++ b/src/gns/gnunet-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) 2012-2013 GNUnet e.V. | 3 | Copyright (C) 2012-2013, 2017 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 |
@@ -66,16 +66,6 @@ static char *zone_ego_name; | |||
66 | static char *public_key; | 66 | static char *public_key; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Reverse key | ||
70 | */ | ||
71 | static char *reverse_key; | ||
72 | |||
73 | /** | ||
74 | * Reverse key | ||
75 | */ | ||
76 | static struct GNUNET_CRYPTO_EcdsaPublicKey rkey; | ||
77 | |||
78 | /** | ||
79 | * Set to GNUNET_GNS_LO_LOCAL_MASTER if we are looking up in the master zone. | 69 | * Set to GNUNET_GNS_LO_LOCAL_MASTER if we are looking up in the master zone. |
80 | */ | 70 | */ |
81 | static enum GNUNET_GNS_LocalOptions local_options; | 71 | static enum GNUNET_GNS_LocalOptions local_options; |
@@ -96,11 +86,6 @@ static int rtype; | |||
96 | static struct GNUNET_GNS_LookupRequest *lookup_request; | 86 | static struct GNUNET_GNS_LookupRequest *lookup_request; |
97 | 87 | ||
98 | /** | 88 | /** |
99 | * Handle to reverse lookup request | ||
100 | */ | ||
101 | static struct GNUNET_GNS_ReverseLookupRequest *rev_lookup_request; | ||
102 | |||
103 | /** | ||
104 | * Lookup an ego with the identity service. | 89 | * Lookup an ego with the identity service. |
105 | */ | 90 | */ |
106 | static struct GNUNET_IDENTITY_EgoLookup *el; | 91 | static struct GNUNET_IDENTITY_EgoLookup *el; |
@@ -174,24 +159,6 @@ do_timeout (void *cls) | |||
174 | GNUNET_SCHEDULER_shutdown (); | 159 | GNUNET_SCHEDULER_shutdown (); |
175 | } | 160 | } |
176 | 161 | ||
177 | static void | ||
178 | process_reverse_result (void *cls, | ||
179 | const char *name) | ||
180 | { | ||
181 | rev_lookup_request = NULL; | ||
182 | if (NULL == name) | ||
183 | { | ||
184 | printf ("No name found.\n"); | ||
185 | return; | ||
186 | } | ||
187 | if (raw) | ||
188 | printf ("%s\n", name); | ||
189 | else | ||
190 | printf ("%s is known as %s\n", | ||
191 | reverse_key, | ||
192 | name); | ||
193 | GNUNET_SCHEDULER_shutdown (); | ||
194 | } | ||
195 | 162 | ||
196 | /** | 163 | /** |
197 | * Function called with the result of a GNS lookup. | 164 | * Function called with the result of a GNS lookup. |
@@ -201,7 +168,8 @@ process_reverse_result (void *cls, | |||
201 | * @param rd array of @a rd_count records with the results | 168 | * @param rd array of @a rd_count records with the results |
202 | */ | 169 | */ |
203 | static void | 170 | static void |
204 | process_lookup_result (void *cls, uint32_t rd_count, | 171 | process_lookup_result (void *cls, |
172 | uint32_t rd_count, | ||
205 | const struct GNUNET_GNSRECORD_Data *rd) | 173 | const struct GNUNET_GNSRECORD_Data *rd) |
206 | { | 174 | { |
207 | const char *name = cls; | 175 | const char *name = cls; |
@@ -253,11 +221,9 @@ process_lookup_result (void *cls, uint32_t rd_count, | |||
253 | * identified by the given public key and the shorten zone. | 221 | * identified by the given public key and the shorten zone. |
254 | * | 222 | * |
255 | * @param pkey public key to use for the zone, can be NULL | 223 | * @param pkey public key to use for the zone, can be NULL |
256 | * @param shorten_key private key used for shortening, can be NULL | ||
257 | */ | 224 | */ |
258 | static void | 225 | static void |
259 | lookup_with_keys (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, | 226 | lookup_with_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) |
260 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key) | ||
261 | { | 227 | { |
262 | if (NULL != lookup_type) | 228 | if (NULL != lookup_type) |
263 | rtype = GNUNET_GNSRECORD_typename_to_number (lookup_type); | 229 | rtype = GNUNET_GNSRECORD_typename_to_number (lookup_type); |
@@ -277,18 +243,9 @@ lookup_with_keys (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, | |||
277 | pkey, | 243 | pkey, |
278 | rtype, | 244 | rtype, |
279 | local_options, | 245 | local_options, |
280 | shorten_key, | ||
281 | &process_lookup_result, | 246 | &process_lookup_result, |
282 | lookup_name); | 247 | lookup_name); |
283 | } | 248 | } |
284 | else if (NULL != reverse_key) | ||
285 | { | ||
286 | rev_lookup_request = GNUNET_GNS_reverse_lookup (gns, | ||
287 | &rkey, | ||
288 | pkey, | ||
289 | &process_reverse_result, | ||
290 | NULL); | ||
291 | } | ||
292 | else | 249 | else |
293 | { | 250 | { |
294 | fprintf (stderr, | 251 | fprintf (stderr, |
@@ -300,63 +257,6 @@ lookup_with_keys (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey, | |||
300 | 257 | ||
301 | 258 | ||
302 | /** | 259 | /** |
303 | * Method called to with the ego we are to use for shortening | ||
304 | * during the lookup. | ||
305 | * | ||
306 | * @param cls closure contains the public key to use | ||
307 | * @param ego ego handle, NULL if not found | ||
308 | * @param ctx context for application to store data for this ego | ||
309 | * (during the lifetime of this process, initially NULL) | ||
310 | * @param name name assigned by the user for this ego, | ||
311 | * NULL if the user just deleted the ego and it | ||
312 | * must thus no longer be used | ||
313 | */ | ||
314 | static void | ||
315 | identity_shorten_cb (void *cls, | ||
316 | struct GNUNET_IDENTITY_Ego *ego, | ||
317 | void **ctx, | ||
318 | const char *name) | ||
319 | { | ||
320 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkeym = cls; | ||
321 | |||
322 | id_op = NULL; | ||
323 | if (NULL == ego) | ||
324 | lookup_with_keys (pkeym, NULL); | ||
325 | else | ||
326 | lookup_with_keys (pkeym, | ||
327 | GNUNET_IDENTITY_ego_get_private_key (ego)); | ||
328 | GNUNET_free (pkeym); | ||
329 | } | ||
330 | |||
331 | |||
332 | /** | ||
333 | * Perform the actual resolution, starting with the zone | ||
334 | * identified by the given public key. | ||
335 | * | ||
336 | * @param pkey public key to use for the zone | ||
337 | */ | ||
338 | static void | ||
339 | lookup_with_public_key (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) | ||
340 | { | ||
341 | struct GNUNET_CRYPTO_EcdsaPublicKey *pkeym; | ||
342 | |||
343 | GNUNET_assert (NULL != pkey); | ||
344 | pkeym = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
345 | *pkeym = *pkey; | ||
346 | GNUNET_break (NULL == id_op); | ||
347 | id_op = GNUNET_IDENTITY_get (identity, | ||
348 | "gns-short", | ||
349 | &identity_shorten_cb, | ||
350 | pkeym); | ||
351 | if (NULL == id_op) | ||
352 | { | ||
353 | GNUNET_break (0); | ||
354 | lookup_with_keys (pkey, NULL); | ||
355 | } | ||
356 | } | ||
357 | |||
358 | |||
359 | /** | ||
360 | * Method called to with the ego we are to use for the lookup, | 260 | * Method called to with the ego we are to use for the lookup, |
361 | * when the ego is determined by a name. | 261 | * when the ego is determined by a name. |
362 | * | 262 | * |
@@ -449,7 +349,6 @@ run (void *cls, | |||
449 | 349 | ||
450 | cfg = c; | 350 | cfg = c; |
451 | gns = GNUNET_GNS_connect (cfg); | 351 | gns = GNUNET_GNS_connect (cfg); |
452 | identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL); | ||
453 | if (NULL == gns) | 352 | if (NULL == gns) |
454 | { | 353 | { |
455 | fprintf (stderr, | 354 | fprintf (stderr, |
@@ -457,22 +356,13 @@ run (void *cls, | |||
457 | return; | 356 | return; |
458 | } | 357 | } |
459 | tt = GNUNET_SCHEDULER_add_delayed (timeout, | 358 | tt = GNUNET_SCHEDULER_add_delayed (timeout, |
460 | &do_timeout, NULL); | 359 | &do_timeout, |
461 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 360 | NULL); |
462 | if (NULL != reverse_key) | 361 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
463 | { | 362 | NULL); |
464 | if (GNUNET_OK != | 363 | identity = GNUNET_IDENTITY_connect (cfg, |
465 | GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_key, | 364 | NULL, |
466 | strlen (reverse_key), | 365 | NULL); |
467 | &rkey)) | ||
468 | { | ||
469 | fprintf (stderr, | ||
470 | _("Reverse key `%s' is not well-formed\n"), | ||
471 | reverse_key); | ||
472 | GNUNET_SCHEDULER_shutdown (); | ||
473 | return; | ||
474 | } | ||
475 | } | ||
476 | if (NULL != public_key) | 366 | if (NULL != public_key) |
477 | { | 367 | { |
478 | if (GNUNET_OK != | 368 | if (GNUNET_OK != |
@@ -489,20 +379,6 @@ run (void *cls, | |||
489 | lookup_with_public_key (&pkey); | 379 | lookup_with_public_key (&pkey); |
490 | return; | 380 | return; |
491 | } | 381 | } |
492 | if (NULL != reverse_key) | ||
493 | { | ||
494 | if (GNUNET_OK != | ||
495 | GNUNET_CRYPTO_ecdsa_public_key_from_string (reverse_key, | ||
496 | strlen (reverse_key), | ||
497 | &rkey)) | ||
498 | { | ||
499 | fprintf (stderr, | ||
500 | _("Reverse key `%s' is not well-formed\n"), | ||
501 | reverse_key); | ||
502 | GNUNET_SCHEDULER_shutdown (); | ||
503 | return; | ||
504 | } | ||
505 | } | ||
506 | if (NULL != zone_ego_name) | 382 | if (NULL != zone_ego_name) |
507 | { | 383 | { |
508 | el = GNUNET_IDENTITY_ego_lookup (cfg, | 384 | el = GNUNET_IDENTITY_ego_lookup (cfg, |
@@ -541,7 +417,8 @@ run (void *cls, | |||
541 | * @return 0 ok, 1 on error | 417 | * @return 0 ok, 1 on error |
542 | */ | 418 | */ |
543 | int | 419 | int |
544 | main (int argc, char *const *argv) | 420 | main (int argc, |
421 | char *const *argv) | ||
545 | { | 422 | { |
546 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 423 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
547 | {'u', "lookup", "NAME", | 424 | {'u', "lookup", "NAME", |
@@ -562,21 +439,22 @@ main (int argc, char *const *argv) | |||
562 | {'z', "zone", "NAME", | 439 | {'z', "zone", "NAME", |
563 | gettext_noop ("Specify the name of the ego of the zone to lookup the record in"), 1, | 440 | gettext_noop ("Specify the name of the ego of the zone to lookup the record in"), 1, |
564 | &GNUNET_GETOPT_set_string, &zone_ego_name}, | 441 | &GNUNET_GETOPT_set_string, &zone_ego_name}, |
565 | {'R', "reverse", "PKEY", | ||
566 | gettext_noop ("Specify the public key of the zone to reverse lookup a name for"), 1, | ||
567 | &GNUNET_GETOPT_set_string, &reverse_key}, | ||
568 | GNUNET_GETOPT_OPTION_END | 442 | GNUNET_GETOPT_OPTION_END |
569 | }; | 443 | }; |
570 | int ret; | 444 | int ret; |
571 | 445 | ||
572 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 446 | timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
573 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 447 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, |
448 | &argc, &argv)) | ||
574 | return 2; | 449 | return 2; |
575 | 450 | ||
576 | GNUNET_log_setup ("gnunet-gns", "WARNING", NULL); | 451 | GNUNET_log_setup ("gnunet-gns", |
452 | "WARNING", | ||
453 | NULL); | ||
577 | ret = | 454 | ret = |
578 | (GNUNET_OK == | 455 | (GNUNET_OK == |
579 | GNUNET_PROGRAM_run (argc, argv, "gnunet-gns", | 456 | GNUNET_PROGRAM_run (argc, argv, |
457 | "gnunet-gns", | ||
580 | _("GNUnet GNS resolver tool"), | 458 | _("GNUnet GNS resolver tool"), |
581 | options, | 459 | options, |
582 | &run, NULL)) ? 0 : 1; | 460 | &run, NULL)) ? 0 : 1; |