GNUnet 0.21.0
gnunet-namestore.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014, 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
28#include "platform.h"
29#include <gnunet_util_lib.h>
32#include <gnunet_gns_service.h>
34#include <inttypes.h>
35
40#define WARN_RELATIVE_EXPIRATION_LIMIT GNUNET_TIME_relative_multiply ( \
41 GNUNET_TIME_UNIT_MINUTES, 15)
42
47{
52
57};
58
63{
68
73
77 char *name;
78
83};
84
89{
93 struct EgoEntry *next;
94
98 struct EgoEntry *prev;
99
104
109};
110
115
120
125
129static char *ego_name;
130
135
140
145
150
155
160
165
169static struct EgoEntry *ego_head;
170
174static struct EgoEntry *ego_tail;
175
180
185
189static int list;
190
194static int add;
195
199static int del;
200
204static int is_public;
205
209static int is_shadow;
210
214static int is_maintenance;
215
219static int omit_private;
220
225
226
230static int purge_zone;
231
236
240static int purge_orphaned;
241
245static int list_orphaned;
246
251
256
261
265static char *name;
266
270static char *value;
271
275static char *uri;
276
280static char *reverse_pkey;
281
285static char *typestring;
286
290static char *expirationstring;
291
295static char *nickstring;
296
300static int ret;
301
305static uint32_t type;
306
310static void *data;
311
315static size_t data_size;
316
320static uint64_t etime;
321
326
331
335static int monitor;
336
341
346
355static int
357 int *etime_is_rel,
358 uint64_t *etime)
359{
360 struct GNUNET_TIME_Relative etime_rel;
361 struct GNUNET_TIME_Absolute etime_abs;
362
363 if (0 == strcmp (expirationstring, "never"))
364 {
365 *etime = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
367 return GNUNET_OK;
368 }
369 if (GNUNET_OK ==
371 {
373 *etime = etime_rel.rel_value_us;
375 {
377 "Relative expiration times of less than %s are not recommended. To improve availability, consider increasing this value.\n",
380 }
382 "Storing record with relative expiration time of %s\n",
384 return GNUNET_OK;
385 }
386 if (GNUNET_OK ==
388 {
390 *etime = etime_abs.abs_value_us;
392 "Storing record with absolute expiration time of %s\n",
394 return GNUNET_OK;
395 }
396 return GNUNET_SYSERR;
397}
398
399
400static int
402{
403 struct RecordSetEntry **head = &recordset;
404 struct RecordSetEntry *r;
406 char *cp;
407 char *tok;
408 char *saveptr;
409 void *raw_data;
410
411 cp = GNUNET_strdup (line);
412 tok = strtok_r (cp, " ", &saveptr);
413 if (NULL == tok)
414 {
416 _ ("Missing entries in record line `%s'.\n"),
417 line);
418 GNUNET_free (cp);
419 return GNUNET_SYSERR;
420 }
422 if (UINT32_MAX == record.record_type)
423 {
424 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Unknown record type `%s'\n"), tok);
425 GNUNET_free (cp);
426 return GNUNET_SYSERR;
427 }
428 tok = strtok_r (NULL, " ", &saveptr);
429 if (NULL == tok)
430 {
432 _ ("Empty record line argument is not allowed.\n"));
433 GNUNET_free (cp);
434 return GNUNET_SYSERR;
435 }
436 if (1 != sscanf (tok, "%" SCNu64, &record.expiration_time))
437 {
438 fprintf (stderr,
439 _ ("Error parsing expiration time %s.\n"), tok);
440 GNUNET_free (cp);
441 return GNUNET_SYSERR;
442 }
443 tok = strtok_r (NULL, " ", &saveptr);
444 if (NULL == tok)
445 {
447 _ ("Empty record line argument is not allowed.\n"));
448 GNUNET_free (cp);
449 return GNUNET_SYSERR;
450 }
452 if (NULL != strchr (tok, (unsigned char) 'r'))
454 if (NULL == strchr (tok, (unsigned char) 'p')) /* p = public */
456 if (NULL != strchr (tok, (unsigned char) 'S'))
458 if (NULL != strchr (tok, (unsigned char) 's'))
460 if (NULL != strchr (tok, (unsigned char) 'C'))
462 tok += strlen (tok) + 1;
464 tok,
465 &raw_data,
466 &record.data_size))
467 {
469 _ ("Invalid record data for type %s: `%s'.\n"),
471 tok);
472 GNUNET_free (cp);
473 return GNUNET_SYSERR;
474 }
475 GNUNET_free (cp);
476
477 r = GNUNET_malloc (sizeof(struct RecordSetEntry) + record.data_size);
478 r->next = *head;
479 record.data = &r[1];
480 memcpy (&r[1], raw_data, record.data_size);
481 GNUNET_free (raw_data);
482 r->record = record;
483 *head = r;
484 return GNUNET_OK;
485}
486
487
488static void
490{
491 struct MarkedRecord *mrec;
492 struct MarkedRecord *mrec_tmp;
493 struct RecordSetEntry *rs_entry;
494
495 rs_entry = recordset;
496 while (NULL != (rs_entry = recordset))
497 {
499 GNUNET_free (rs_entry);
500 }
501 recordset = NULL;
502 if (NULL != ego_name)
503 {
505 ego_name = NULL;
506 }
507 if (NULL != name)
508 {
510 name = NULL;
511 }
512 if (NULL != value)
513 {
515 value = NULL;
516 }
517 if (NULL != uri)
518 {
520 uri = NULL;
521 }
522 if (NULL != expirationstring)
523 {
525 expirationstring = NULL;
526 }
527 if (NULL != purge_task)
528 {
530 purge_task = NULL;
531 }
532 for (mrec = marked_head; NULL != mrec;)
533 {
534 mrec_tmp = mrec;
535 mrec = mrec->next;
536 GNUNET_free (mrec_tmp->name);
537 GNUNET_free (mrec_tmp);
538 }
539 if (NULL != list_it)
540 {
542 list_it = NULL;
543 }
544 if (NULL != add_qe)
545 {
547 add_qe = NULL;
548 }
549 if (NULL != set_qe)
550 {
552 set_qe = NULL;
553 }
554 if (NULL != add_qe_uri)
555 {
557 add_qe_uri = NULL;
558 }
559 if (NULL != get_qe)
560 {
562 get_qe = NULL;
563 }
564 if (NULL != del_qe)
565 {
567 del_qe = NULL;
568 }
569 if (NULL != reverse_qe)
570 {
572 reverse_qe = NULL;
573 }
574 memset (&zone_pkey, 0, sizeof(zone_pkey));
575 if (NULL != zm)
576 {
578 zm = NULL;
579 }
580 if (NULL != data)
581 {
583 data = NULL;
584 }
585 if (NULL != typestring)
586 {
588 typestring = NULL;
589 }
590 list = 0;
591 is_public = 0;
592 is_shadow = 0;
593 is_maintenance = 0;
594 purge_zone = 0;
595}
596
597
603static void
604do_shutdown (void *cls)
605{
606 struct EgoEntry *ego_entry;
607 struct EgoEntry *ego_tmp;
608 (void) cls;
609
610 reset_handles ();
611 if (NULL != ns_qe)
612 {
614 ns_qe = NULL;
615 }
616 if (NULL != ns)
617 {
619 ns = NULL;
620 }
621 if (NULL != idh)
622 {
624 idh = NULL;
625 }
626 for (ego_entry = ego_head; NULL != ego_entry;)
627 {
628 ego_tmp = ego_entry;
629 ego_entry = ego_entry->next;
630 GNUNET_free (ego_tmp->identifier);
631 GNUNET_free (ego_tmp);
632 }
633}
634
635
636static void
638
639
640static void
642{
643 reset_handles ();
644 if (read_from_stdin)
645 {
647 return;
648 }
650}
651
652
653static void
655{
656 struct GNUNET_NAMESTORE_QueueEntry **qe = cls;
657
658 *qe = NULL;
659 if (GNUNET_EC_NONE != ec)
660 {
661 fprintf (stderr,
662 _ ("Adding record failed: %s\n"),
665 ret = 1;
666 }
667 ret = 0;
669}
670
671
672static void
674{
675 (void) cls;
676 del_qe = NULL;
678 {
679 fprintf (stderr,
680 _ ("Deleting record failed: %s\n"), GNUNET_ErrorCode_get_hint (
681 ec));
682 }
684}
685
686
687static void
688purge_next_record (void *cls);
689
690static void
692{
693 del_qe = NULL;
694 if (GNUNET_EC_NONE != ec)
695 {
696 fprintf (stderr,
697 _ ("Deleting record failed: %s\n"),
699 }
701}
702
703
704static void
706{
707 struct MarkedRecord *mrec;
708 purge_task = NULL;
709
710 if (NULL == marked_head)
711 {
712 ret = 0;
714 return;
715 }
716 mrec = marked_head;
719 mrec);
721 &mrec->key,
722 mrec->name,
723 0, NULL,
725 NULL);
726 GNUNET_free (mrec->name);
727 GNUNET_free (mrec);
728}
729
730
734static void
736{
737 (void) cls;
738 list_it = NULL;
740 {
742 return;
743 }
744 ret = 0;
746}
747
748
752static void
754{
755 (void) cls;
756 list_it = NULL;
757 fprintf (stderr, "Error iterating over zone\n");
758 ret = 1;
760}
761
762
763static void
765 GNUNET_CRYPTO_PrivateKey *zone_key,
766 const char *rname,
767 unsigned int rd_len,
768 const struct GNUNET_GNSRECORD_Data *rd)
769{
770 struct MarkedRecord *mrec;
771
772 mrec = GNUNET_new (struct MarkedRecord);
773 mrec->key = *zone_key;
774 mrec->name = GNUNET_strdup (rname);
777 mrec);
778}
779
780
781static void
783 const char *rname,
784 unsigned int rd_len,
785 const struct GNUNET_GNSRECORD_Data *rd)
786{
787 struct EgoEntry *ego;
788 struct MarkedRecord *orphan;
789 int is_orphaned = 1;
790
791 for (ego = ego_head; NULL != ego; ego = ego->next)
792 {
793 if (0 == memcmp (GNUNET_IDENTITY_ego_get_private_key (ego->ego),
794 zone_key,
795 sizeof (*zone_key)))
796 {
797 is_orphaned = 0;
798 break;
799 }
800 }
801 if (is_orphaned)
802 {
803 orphan = GNUNET_new (struct MarkedRecord);
804 orphan->key = *zone_key;
805 orphan->name = GNUNET_strdup (rname);
808 orphan);
809 }
810}
811
812
820static void
822 const char *rname,
823 unsigned int rd_len,
824 const struct GNUNET_GNSRECORD_Data *rd)
825{
826 const char *typestr;
827 char *s;
828 const char *ets;
829 struct GNUNET_TIME_Absolute at;
830 struct GNUNET_TIME_Relative rt;
831 struct EgoEntry *ego;
832 int have_record;
833 int is_orphaned = 1;
834 char *orphaned_str;
835
836 if ((NULL != name) && (0 != strcmp (name, rname)))
837 return;
838 have_record = GNUNET_NO;
839 for (unsigned int i = 0; i < rd_len; i++)
840 {
841 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
842 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
843 continue;
844 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
845 continue;
846 have_record = GNUNET_YES;
847 break;
848 }
849 if (GNUNET_NO == have_record)
850 return;
851 for (ego = ego_head; NULL != ego; ego = ego->next)
852 {
853 if (0 == memcmp (GNUNET_IDENTITY_ego_get_private_key (ego->ego),
854 zone_key,
855 sizeof (*zone_key)))
856 {
857 is_orphaned = 0;
858 break;
859 }
860 }
861 if (list_orphaned && ! is_orphaned)
862 return;
863 if (! list_orphaned && is_orphaned)
864 return;
865 orphaned_str = GNUNET_CRYPTO_private_key_to_string (zone_key);
866 fprintf (stdout, "%s.%s:\n", rname, is_orphaned ? orphaned_str :
867 ego->identifier);
868 GNUNET_free (orphaned_str);
869 if (NULL != typestring)
871 else
873 for (unsigned int i = 0; i < rd_len; i++)
874 {
875 if ((GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) &&
876 (0 != strcmp (rname, GNUNET_GNS_EMPTY_LABEL_AT)))
877 continue;
878 if ((type != rd[i].record_type) && (GNUNET_GNSRECORD_TYPE_ANY != type))
879 continue;
880 typestr = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
881 s = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
882 rd[i].data,
883 rd[i].data_size);
884 if (NULL == s)
885 {
886 fprintf (stdout,
887 _ ("\tCorrupt or unsupported record of type %u\n"),
888 (unsigned int) rd[i].record_type);
889 continue;
890 }
891 if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
892 {
895 }
896 else
897 {
900 }
901 char flgstr[16];
902 sprintf (flgstr, "[%s%s%s%s%s]",
903 (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE) ? "" : "p",
904 (rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL) ? "S" : "",
905 (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION) ? "r" : "",
906 (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW) ? "S" : "",
907 (rd[i].flags & GNUNET_GNSRECORD_RF_CRITICAL) ? "C" : "");
909 fprintf (stdout,
910 " %s %" PRIu64 " %s %s\n",
911 typestr,
912 rd[i].expiration_time,
913 flgstr,
914 s);
915 else
916 fprintf (stdout,
917 "\t%s: %s (%s)\t%s\t%s\t%s\n",
918 typestr,
919 s,
920 ets,
921 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE"
922 : "PUBLIC",
923 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW)) ? "SHADOW"
924 : "",
925 (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_MAINTENANCE)) ?
926 "MAINTENANCE"
927 : "");
928 GNUNET_free (s);
929 }
930 // fprintf (stdout, "%s", "\n");
931}
932
933
934static void
936 const struct GNUNET_CRYPTO_PrivateKey *zone_key,
937 const char *rname,
938 unsigned int rd_len,
939 const struct GNUNET_GNSRECORD_Data *rd,
940 struct GNUNET_TIME_Absolute expiry)
941{
942 (void) cls;
943 (void) zone_key;
944 (void) expiry;
945 collect_zone_records_to_purge (zone_key, rname, rd_len, rd);
947}
948
949
950static void
952 const struct GNUNET_CRYPTO_PrivateKey *zone_key,
953 const char *rname,
954 unsigned int rd_len,
955 const struct GNUNET_GNSRECORD_Data *rd,
956 struct GNUNET_TIME_Absolute expiry)
957{
958 (void) cls;
959 (void) zone_key;
960 (void) expiry;
961 collect_orphans (zone_key, rname, rd_len, rd);
963}
964
965
975static void
977 const struct GNUNET_CRYPTO_PrivateKey *zone_key,
978 const char *rname,
979 unsigned int rd_len,
980 const struct GNUNET_GNSRECORD_Data *rd,
981 struct GNUNET_TIME_Absolute expiry)
982{
983 (void) cls;
984 (void) zone_key;
985 (void) expiry;
986 display_record (zone_key, rname, rd_len, rd);
988}
989
990
1000static void
1002 const struct GNUNET_CRYPTO_PrivateKey *zone_key,
1003 const char *rname,
1004 unsigned int rd_len,
1005 const struct GNUNET_GNSRECORD_Data *rd,
1006 struct GNUNET_TIME_Absolute expiry)
1007{
1008 (void) cls;
1009 (void) zone_key;
1010 (void) expiry;
1011 display_record (zone_key, rname, rd_len, rd);
1013}
1014
1015
1025static void
1027 const struct GNUNET_CRYPTO_PrivateKey *zone_key,
1028 const char *rname,
1029 unsigned int rd_len,
1030 const struct GNUNET_GNSRECORD_Data *rd)
1031{
1032 (void) cls;
1033 (void) zone_key;
1034 get_qe = NULL;
1035 display_record (zone_key, rname, rd_len, rd);
1036 finish_command ();
1037}
1038
1039
1045static void
1046sync_cb (void *cls)
1047{
1048 (void) cls;
1049 fprintf (stdout, "%s", "Monitor is now in sync.\n");
1050}
1051
1052
1058static void
1060{
1061 (void) cls;
1062 fprintf (stderr, "%s", "Monitor disconnected and out of sync.\n");
1063}
1064
1065
1071static void
1073{
1074 (void) cls;
1075 get_qe = NULL;
1076 fprintf (stderr, "%s", "Failed to lookup record.\n");
1077 finish_command ();
1078}
1079
1080
1084static void
1085add_error_cb (void *cls)
1086{
1087 (void) cls;
1088 add_qe = NULL;
1089 GNUNET_break (0);
1090 ret = 1;
1091 finish_command ();
1092}
1093
1094
1105static void
1107 const struct GNUNET_CRYPTO_PrivateKey *zone_key,
1108 const char *rec_name,
1109 unsigned int rd_count,
1110 const struct GNUNET_GNSRECORD_Data *rd)
1111{
1112 struct GNUNET_GNSRECORD_Data rdn[rd_count + 1];
1113 struct GNUNET_GNSRECORD_Data *rde;
1114
1115 (void) cls;
1116 (void) zone_key;
1117 add_qe = NULL;
1118 if (0 != strcmp (rec_name, name))
1119 {
1120 GNUNET_break (0);
1121 ret = 1;
1122 finish_command ();
1123 return;
1124 }
1125
1127 "Received %u records for name `%s'\n",
1128 rd_count,
1129 rec_name);
1130 for (unsigned int i = 0; i < rd_count; i++)
1131 {
1132 switch (rd[i].record_type)
1133 {
1136 {
1137 fprintf (
1138 stderr,
1139 _ (
1140 "A SOA record exists already under `%s', cannot add a second SOA to the same zone.\n"),
1141 rec_name);
1142 ret = 1;
1143 finish_command ();
1144 return;
1145 }
1146 break;
1147 }
1148 }
1149 memset (rdn, 0, sizeof(struct GNUNET_GNSRECORD_Data));
1150 GNUNET_memcpy (&rdn[1], rd, rd_count * sizeof(struct GNUNET_GNSRECORD_Data));
1151 rde = &rdn[0];
1152 rde->data = data;
1153 rde->data_size = data_size;
1154 rde->record_type = type;
1155 if (1 == is_shadow)
1157 if (1 == is_maintenance)
1159 if (1 != is_public)
1161 rde->expiration_time = etime;
1162 if (GNUNET_YES == etime_is_rel)
1164 else if (GNUNET_NO != etime_is_rel)
1166 GNUNET_assert (NULL != name);
1168 &zone_pkey,
1169 name,
1170 rd_count + 1,
1171 rde,
1173 &add_qe);
1174}
1175
1176
1180static void
1182{
1183 (void) cls;
1184 reverse_qe = NULL;
1185 fprintf (stdout, "%s.zkey\n", reverse_pkey);
1186}
1187
1188
1199static void
1201 const struct GNUNET_CRYPTO_PrivateKey *zone,
1202 const char *label,
1203 unsigned int rd_count,
1204 const struct GNUNET_GNSRECORD_Data *rd)
1205{
1206 (void) cls;
1207 (void) zone;
1208 (void) rd_count;
1209 (void) rd;
1210 reverse_qe = NULL;
1211 if (NULL == label)
1212 fprintf (stdout, "%s\n", reverse_pkey);
1213 else
1214 fprintf (stdout, "%s.%s\n", label, ego_name);
1215 finish_command ();
1216}
1217
1218
1222static void
1224{
1225 (void) cls;
1226 del_qe = NULL;
1227 GNUNET_break (0);
1228 ret = 1;
1229 finish_command ();
1230}
1231
1232
1244static void
1245del_monitor (void *cls,
1246 const struct GNUNET_CRYPTO_PrivateKey *zone,
1247 const char *label,
1248 unsigned int rd_count,
1249 const struct GNUNET_GNSRECORD_Data *rd)
1250{
1251 struct GNUNET_GNSRECORD_Data rdx[rd_count];
1252 unsigned int rd_left;
1253 uint32_t type;
1254 char *vs;
1255
1256 (void) cls;
1257 (void) zone;
1258 del_qe = NULL;
1259 if (0 == rd_count)
1260 {
1261 fprintf (stderr,
1262 _ (
1263 "There are no records under label `%s' that could be deleted.\n"),
1264 label);
1265 ret = 1;
1266 finish_command ();
1267 return;
1268 }
1269 if ((NULL == value) && (NULL == typestring))
1270 {
1271 /* delete everything */
1273 &zone_pkey,
1274 name,
1275 0,
1276 NULL,
1278 NULL);
1279 return;
1280 }
1281 rd_left = 0;
1282 if (NULL != typestring)
1284 else
1286 for (unsigned int i = 0; i < rd_count; i++)
1287 {
1288 vs = NULL;
1289 if (! (((GNUNET_GNSRECORD_TYPE_ANY == type) ||
1290 (rd[i].record_type == type)) &&
1291 ((NULL == value) ||
1292 (NULL ==
1294 rd[i].data,
1295 rd[i].data_size)))) ||
1296 (0 == strcmp (vs, value)))))
1297 rdx[rd_left++] = rd[i];
1298 GNUNET_free (vs);
1299 }
1300 if (rd_count == rd_left)
1301 {
1302 /* nothing got deleted */
1303 fprintf (
1304 stderr,
1305 _ (
1306 "There are no records under label `%s' that match the request for deletion.\n"),
1307 label);
1308 finish_command ();
1309 return;
1310 }
1311 /* delete everything but what we copied to 'rdx' */
1313 &zone_pkey,
1314 name,
1315 rd_left,
1316 rdx,
1318 NULL);
1319}
1320
1321
1322static void
1323replace_cont (void *cls, enum GNUNET_ErrorCode ec)
1324{
1325 (void) cls;
1326
1327 set_qe = NULL;
1328 if (GNUNET_EC_NONE != ec)
1329 {
1331 _ ("%s\n"),
1333 ret = 1; /* fail from 'main' */
1334 }
1335 finish_command ();
1336}
1337
1338
1345static void
1347{
1350
1351 if (omit_private)
1355 if (! (add | del | list | (NULL != nickstring) | (NULL != uri)
1356 | (NULL != reverse_pkey) | (NULL != recordset) | (monitor)
1358 {
1359 /* nothing more to be done */
1360 fprintf (stderr, _ ("No options given\n"));
1361 finish_command ();
1362 return;
1363 }
1364
1365 if (NULL != recordset)
1366 {
1367 /* replace entire record set */
1368 unsigned int rd_count;
1369 struct GNUNET_GNSRECORD_Data *rd;
1370
1371 /* FIXME: We could easily support append and delete with this as well */
1372 if (! add)
1373 {
1374 fprintf (stderr, _ ("Recordlines only work with option `%s'\n"),
1375 "-a");
1376 ret = 1;
1377 finish_command ();
1378 return;
1379 }
1380 if (NULL == name)
1381 {
1382 fprintf (stderr,
1383 _ ("Missing option `%s' for operation `%s'\n"),
1384 "-n",
1385 _ ("name"));
1386 ret = 1;
1387 finish_command ();
1388 return;
1389 }
1390 rd_count = 0;
1391 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1392 rd_count++;
1394 rd_count = 0;
1395 for (struct RecordSetEntry *e = recordset; NULL != e; e = e->next)
1396 {
1397 rd[rd_count] = e->record;
1398 rd_count++;
1399 }
1401 &zone_pkey,
1402 name,
1403 rd_count,
1404 rd,
1405 &replace_cont,
1406 NULL);
1407 GNUNET_free (rd);
1408 return;
1409 }
1410 if (NULL != nickstring)
1411 {
1412 if (0 == strlen (nickstring))
1413 {
1414 fprintf (stderr, _ ("Invalid nick `%s'\n"), nickstring);
1415 ret = 1;
1416 finish_command ();
1417 return;
1418 }
1419 add = 1;
1424 is_public = 0;
1425 expirationstring = GNUNET_strdup ("never");
1427 nickstring = NULL;
1428 }
1429
1430 if (add)
1431 {
1432 if (NULL == ego_name)
1433 {
1434 fprintf (stderr,
1435 _ ("Missing option `%s' for operation `%s'\n"),
1436 "-z",
1437 _ ("add"));
1438 ret = 1;
1439 finish_command ();
1440 return;
1441 }
1442 if (NULL == name)
1443 {
1444 fprintf (stderr,
1445 _ ("Missing option `%s' for operation `%s'\n"),
1446 "-n",
1447 _ ("add"));
1448 ret = 1;
1449 finish_command ();
1450 return;
1451 }
1452 if (NULL == typestring)
1453 {
1454 fprintf (stderr,
1455 _ ("Missing option `%s' for operation `%s'\n"),
1456 "-t",
1457 _ ("add"));
1458 ret = 1;
1459 finish_command ();
1460 return;
1461 }
1463 if (UINT32_MAX == type)
1464 {
1465 fprintf (stderr, _ ("Unsupported type `%s'\n"), typestring);
1466 ret = 1;
1467 finish_command ();
1468 return;
1469 }
1474 {
1475 fprintf (stderr,
1476 _ (
1477 "For DNS record types `SRV', `TLSA', `SMIMEA' and `OPENPGPKEY'"));
1478 fprintf (stderr, ", please use a `BOX' record instead\n");
1479 ret = 1;
1480 finish_command ();
1481 return;
1482 }
1483 if (NULL == value)
1484 {
1485 fprintf (stderr,
1486 _ ("Missing option `%s' for operation `%s'\n"),
1487 "-V",
1488 _ ("add"));
1489 ret = 1;
1490 finish_command ();
1491 return;
1492 }
1493 if (GNUNET_OK !=
1495 {
1496 fprintf (stderr,
1497 _ ("Value `%s' invalid for record type `%s'\n"),
1498 value,
1499 typestring);
1500 ret = 1;
1501 finish_command ();
1502 return;
1503 }
1504 if (NULL == expirationstring)
1505 {
1506 fprintf (stderr,
1507 _ ("Missing option `%s' for operation `%s'\n"),
1508 "-e",
1509 _ ("add"));
1510 ret = 1;
1511 finish_command ();
1512 return;
1513 }
1515 {
1516 fprintf (stderr, _ ("Invalid time format `%s'\n"), expirationstring);
1517 ret = 1;
1518 finish_command ();
1519 return;
1520 }
1522 &zone_pkey,
1523 name,
1524 &add_error_cb,
1525 NULL,
1527 NULL);
1528 }
1529 if (del)
1530 {
1531 if (NULL == ego_name)
1532 {
1533 fprintf (stderr,
1534 _ ("Missing option `%s' for operation `%s'\n"),
1535 "-z",
1536 _ ("del"));
1537 ret = 1;
1538 finish_command ();
1539 return;
1540 }
1541 if (NULL == name)
1542 {
1543 fprintf (stderr,
1544 _ ("Missing option `%s' for operation `%s'\n"),
1545 "-n",
1546 _ ("del"));
1547 ret = 1;
1548 finish_command ();
1549 return;
1550 }
1552 &zone_pkey,
1553 name,
1555 NULL,
1556 &del_monitor,
1557 NULL,
1558 filter_flags);
1559 }
1560 if (purge_orphaned)
1561 {
1563 NULL,
1565 NULL,
1567 NULL,
1569 NULL,
1570 filter_flags);
1571
1572 }
1573 else if (purge_zone)
1574 {
1575 if (NULL == ego_name)
1576 {
1577 fprintf (stderr,
1578 _ ("Missing option `%s' for operation `%s'\n"),
1579 "-z",
1580 _ ("purge-zone"));
1581 ret = 1;
1582 finish_command ();
1583 return;
1584 }
1586 &zone_pkey,
1588 NULL,
1590 NULL,
1592 NULL,
1593 filter_flags);
1594
1595 }
1596 else if (list || list_orphaned)
1597 {
1598 if (NULL != name)
1599 {
1600 if (NULL == ego_name)
1601 {
1602 fprintf (stderr,
1603 _ ("Missing option `%s' for operation `%s'\n"),
1604 "-z",
1605 _ ("list"));
1606 ret = 1;
1607 finish_command ();
1608 return;
1609 }
1611 &zone_pkey,
1612 name,
1614 NULL,
1616 NULL);
1617 }
1618 else
1620 (NULL == ego_name) ?
1621 NULL : &zone_pkey,
1623 NULL,
1625 NULL,
1627 NULL,
1628 filter_flags);
1629 }
1630 if (NULL != reverse_pkey)
1631 {
1633
1634 if (NULL == ego_name)
1635 {
1636 fprintf (stderr,
1637 _ ("Missing option `%s' for operation `%s'\n"),
1638 "-z",
1639 _ ("reverse-pkey"));
1640 ret = 1;
1641 finish_command ();
1642 return;
1643 }
1644 if (GNUNET_OK !=
1646 &pubkey))
1647 {
1648 fprintf (stderr,
1649 _ ("Invalid public key for reverse lookup `%s'\n"),
1650 reverse_pkey);
1651 ret = 1;
1652 finish_command ();
1653 return;
1654 }
1656 &zone_pkey,
1657 &pubkey,
1659 NULL,
1661 NULL);
1662 }
1663 if (NULL != uri)
1664 {
1665 char sh[105];
1666 char sname[64];
1668 if (NULL == ego_name)
1669 {
1670 fprintf (stderr,
1671 _ ("Missing option `%s' for operation `%s'\n"),
1672 "-z",
1673 _ ("uri"));
1674 ret = 1;
1675 finish_command ();
1676 return;
1677 }
1678
1679 memset (sh, 0, 105);
1680 memset (sname, 0, 64);
1681
1682 if ((2 != (sscanf (uri, "gnunet://gns/%58s/%63s", sh, sname))) ||
1683 (GNUNET_OK !=
1685 {
1686 fprintf (stderr, _ ("Invalid URI `%s'\n"), uri);
1687 ret = 1;
1688 finish_command ();
1689 return;
1690 }
1691 if (NULL == expirationstring)
1692 {
1693 fprintf (stderr,
1694 _ ("Missing option `%s' for operation `%s'\n"),
1695 "-e",
1696 _ ("add"));
1697 ret = 1;
1698 finish_command ();
1699 return;
1700 }
1702 {
1703 fprintf (stderr, _ ("Invalid time format `%s'\n"), expirationstring);
1704 ret = 1;
1705 finish_command ();
1706 return;
1707 }
1708 memset (&rd, 0, sizeof(rd));
1709 rd.data = &pkey;
1711 rd.record_type = ntohl (pkey.type);
1713 if (GNUNET_YES == etime_is_rel)
1715 if (1 == is_shadow)
1717 if (1 == is_maintenance)
1720 &zone_pkey,
1721 sname,
1722 1,
1723 &rd,
1725 &add_qe_uri);
1726 }
1727 if (monitor)
1728 {
1730 (NULL != ego_name) ?
1731 &zone_pkey : NULL,
1732 GNUNET_YES,
1734 NULL,
1736 NULL,
1737 &sync_cb,
1738 NULL,
1739 filter_flags);
1740 }
1741}
1742
1743
1744#define MAX_LINE_LEN 4086
1745
1746#define MAX_ARGS 20
1747
1748static int
1750 struct GNUNET_CRYPTO_PrivateKey *zk)
1751{
1752 const struct GNUNET_CRYPTO_PrivateKey *privkey;
1754 struct GNUNET_CRYPTO_PublicKey ego_pubkey;
1755 struct EgoEntry *ego_entry;
1756
1758 &pubkey))
1759 {
1760 for (ego_entry = ego_head;
1761 NULL != ego_entry; ego_entry = ego_entry->next)
1762 {
1763 privkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1764 GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &ego_pubkey);
1765 if (0 == memcmp (&ego_pubkey, &pubkey, sizeof (pubkey)))
1766 {
1767 *zk = *privkey;
1768 return GNUNET_OK;
1769 }
1770 }
1771 }
1772 else
1773 {
1774 for (ego_entry = ego_head; NULL != ego_entry; ego_entry = ego_entry->next)
1775 {
1777 if (0 != strcmp (str, ego_entry->identifier))
1778 continue;
1779 *zk = *GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
1780 return GNUNET_OK;
1781 }
1782 }
1783 return GNUNET_NO;
1784}
1785
1786
1787static void
1789{
1790 char buf[MAX_LINE_LEN];
1791 static struct GNUNET_CRYPTO_PrivateKey next_zone_key;
1792 static char next_name[GNUNET_DNSPARSER_MAX_NAME_LENGTH];
1793 static int finished = GNUNET_NO;
1794 static int have_next_zonekey = GNUNET_NO;
1795 int zonekey_set = GNUNET_NO;
1796 char *tmp;
1797
1798
1799 if (GNUNET_YES == have_next_zonekey)
1800 {
1801 zone_pkey = next_zone_key;
1802 if (NULL != name)
1803 GNUNET_free (name);
1804 name = GNUNET_strdup (next_name);
1805 zonekey_set = GNUNET_YES;
1806 }
1807 while (NULL != fgets (buf, sizeof (buf), stdin))
1808 {
1809 if (1 >= strlen (buf))
1810 continue;
1811 if (buf[strlen (buf) - 1] == '\n')
1812 buf[strlen (buf) - 1] = '\0';
1816 if (buf[strlen (buf) - 1] == ':')
1817 {
1818 memset (next_name, 0, sizeof (next_name));
1819 strncpy (next_name, buf, strlen (buf) - 1);
1820 tmp = strchr (next_name, '.');
1821 if (NULL == tmp)
1822 {
1823 fprintf (stderr, "Error parsing name `%s'\n", next_name);
1825 ret = 1;
1826 return;
1827 }
1828 if (GNUNET_OK != get_identity_for_string (tmp + 1, &next_zone_key))
1829 {
1830 fprintf (stderr, "Error parsing zone name `%s'\n", tmp + 1);
1831 ret = 1;
1833 return;
1834 }
1835 *tmp = '\0';
1836 have_next_zonekey = GNUNET_YES;
1837 /* Run a command for the previous record set */
1838 if (NULL != recordset)
1839 {
1841 return;
1842 }
1843 zone_pkey = next_zone_key;
1844 if (NULL != name)
1845 GNUNET_free (name);
1846 name = GNUNET_strdup (next_name);
1847 zonekey_set = GNUNET_YES;
1848 continue;
1849 }
1850 if (GNUNET_NO == zonekey_set)
1851 {
1852 fprintf (stderr, "Warning, encountered recordline without zone\n");
1853 continue;
1854 }
1855 parse_recordline (buf);
1856 }
1857 if (GNUNET_NO == finished)
1858 {
1859 if (NULL != recordset)
1860 {
1861 if (GNUNET_YES == zonekey_set)
1862 {
1864 finished = GNUNET_YES;
1865 return;
1866 }
1867 fprintf (stderr, "Warning, encountered recordline without zone\n");
1868 }
1869 }
1871 return;
1872}
1873
1874
1887static void
1888id_connect_cb (void *cls,
1889 struct GNUNET_IDENTITY_Ego *ego,
1890 void **ctx,
1891 const char *name)
1892{
1894 struct EgoEntry *ego_entry;
1895
1896 (void) ctx;
1897 (void) name;
1898 if ((NULL != name) && (NULL != ego))
1899 {
1900 ego_entry = GNUNET_new (struct EgoEntry);
1902 ego_entry->ego = ego;
1903 ego_entry->identifier = GNUNET_strdup (name);
1905 ego_tail,
1906 ego_entry);
1907 if ((NULL != ego_name) &&
1908 (0 == strcmp (name, ego_name)))
1910 return;
1911 }
1912 if (NULL != ego)
1913 return;
1914 if (read_from_stdin)
1915 {
1917 return;
1918 }
1920}
1921
1922
1931static void
1932run (void *cls,
1933 char *const *args,
1934 const char *cfgfile,
1935 const struct GNUNET_CONFIGURATION_Handle *_cfg)
1936{
1937 (void) cls;
1938 (void) args;
1939 (void) cfgfile;
1940 cfg = _cfg;
1941 if (NULL != args[0])
1942 GNUNET_log (
1944 _ ("Superfluous command line arguments (starting with `%s') ignored\n"),
1945 args[0]);
1946
1949 if (NULL == ns)
1950 {
1951 fprintf (stderr, _ ("Failed to connect to namestore\n"));
1953 return;
1954 }
1956 if (NULL == idh)
1957 {
1958 ret = -1;
1959 fprintf (stderr, _ ("Cannot connect to identity service\n"));
1961 }
1962}
1963
1964
1972int
1973main (int argc, char *const *argv)
1974{
1975 int lret;
1977 { GNUNET_GETOPT_option_flag ('a', "add", gettext_noop ("add record"), &add),
1979 "delete",
1980 gettext_noop ("delete record"),
1981 &del),
1983 "display",
1984 gettext_noop ("display records"),
1985 &list),
1987 "from-stdin",
1988 gettext_noop ("read commands from stdin"),
1991 'e',
1992 "expiration",
1993 "TIME",
1994 gettext_noop (
1995 "expiration time for record to use (for adding only), \"never\" is possible"),
1998 "nick",
1999 "NICKNAME",
2000 gettext_noop (
2001 "set the desired nick name for the zone"),
2002 &nickstring),
2004 "monitor",
2005 gettext_noop (
2006 "monitor changes in the namestore"),
2007 &monitor),
2009 "name",
2010 "NAME",
2011 gettext_noop (
2012 "name of the record to add/delete/display"),
2013 &name),
2015 "recordline",
2016 gettext_noop ("Output in recordline format"),
2019 "zone-to-name",
2020 "KEY",
2021 gettext_noop (
2022 "determine our name for the given KEY"),
2023 &reverse_pkey),
2025 "type",
2026 "TYPE",
2027 gettext_noop (
2028 "type of the record to add/delete/display"),
2029 &typestring),
2031 "uri",
2032 "URI",
2033 gettext_noop ("URI to import into our zone"),
2034 &uri),
2036 "value",
2037 "VALUE",
2038 gettext_noop (
2039 "value of the record to add/delete"),
2040 &value),
2042 "public",
2043 gettext_noop ("create or list public record"),
2044 &is_public),
2046 "omit-private",
2047 gettext_noop ("omit private records"),
2048 &omit_private),
2050 "include-maintenance",
2051 gettext_noop (
2052 "do not filter maintenance records"),
2055 "purge-orphans",
2056 gettext_noop (
2057 "purge namestore of all orphans"),
2060 "list-orphans",
2061 gettext_noop (
2062 "show private key for orphaned records for recovery using `gnunet-identity -C -P <key>'. Use in combination with --display"),
2063 &list_orphaned),
2065 "purge-zone-records",
2066 gettext_noop (
2067 "delete all records in specified zone"),
2068 &purge_zone),
2070 's',
2071 "shadow",
2072 gettext_noop (
2073 "create shadow record (only valid if all other records of the same type have expired)"),
2074 &is_shadow),
2076 'M',
2077 "maintenance",
2078 gettext_noop (
2079 "create maintenance record (e.g TOMBSTONEs)"),
2082 "zone",
2083 "EGO",
2084 gettext_noop (
2085 "name of the ego controlling the zone"),
2086 &ego_name),
2088
2089
2090 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
2091 return 2;
2092
2093 is_public = -1;
2094 is_shadow = -1;
2095 is_maintenance = -1;
2096 GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL);
2097 if (GNUNET_OK !=
2098 (lret = GNUNET_PROGRAM_run (argc,
2099 argv,
2100 "gnunet-namestore",
2101 _ ("GNUnet zone manipulation tool"),
2102 options,
2103 &run,
2104 NULL)))
2105 {
2106 GNUNET_free_nz ((void *) argv);
2107 // FIXME
2108 // GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
2109 return lret;
2110 }
2111 GNUNET_free_nz ((void *) argv);
2112 // FIXME
2113 // GNUNET_CRYPTO_ecdsa_key_clear (&zone_pkey);
2114 return ret;
2115}
2116
2117
2118/* end of gnunet-namestore.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static char * line
Desired phone line (string to be converted to a hash).
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * pkey
Public key of the zone to look in, in ASCII.
static struct GNUNET_CRYPTO_PublicKey pubkey
Public key of the zone to look in.
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static struct EgoEntry * ego_tail
Ego list.
static struct GNUNET_NAMESTORE_QueueEntry * ns_qe
Queue entry for begin/commit.
#define MAX_LINE_LEN
static void display_record_monitor(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
Process a record that was stored in the namestore.
static int output_recordline
Output in recordline format.
static int omit_private
Filter private records.
static void zone_iteration_finished(void *cls)
Function called when we are done with a zone iteration.
static void replace_cont(void *cls, enum GNUNET_ErrorCode ec)
static void sync_cb(void *cls)
Function called once we are in sync in monitor mode.
static struct GNUNET_NAMESTORE_QueueEntry * get_qe
Queue entry for the 'lookup' operation.
static void del_lookup_error_cb(void *cls)
Function called if lookup for deletion fails.
static void purge_zone_iterator(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
static struct GNUNET_CRYPTO_PrivateKey zone_pkey
Private key for the our zone.
static struct GNUNET_NAMESTORE_ZoneMonitor * zm
Monitor handle.
static int parse_recordline(const char *line)
static void del_continuation(void *cls, enum GNUNET_ErrorCode ec)
static int list_orphaned
List records and zone keys of orphaned records.
#define WARN_RELATIVE_EXPIRATION_LIMIT
The upper bound for the zone iteration interval (per record).
static void purge_next_record(void *cls)
static int purge_orphaned
Purge orphaned records.
static struct GNUNET_NAMESTORE_QueueEntry * add_qe
Queue entry for the 'add' operation.
static char * nickstring
Desired nick name.
static void display_record_lookup(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
static int monitor
Enables monitor mode.
static char * value
Value of the record to add/remove.
static int list
Desired action is to list records.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle.
static struct GNUNET_NAMESTORE_QueueEntry * del_qe
Queue entry for the 'del' operation.
static int purge_zone
Purge zone contents.
static char * name
Name of the records to add/list/remove.
static int include_maintenance
Do not filter maintenance records.
static struct GNUNET_NAMESTORE_QueueEntry * set_qe
Queue entry for the 'set/replace' operation.
static int get_identity_for_string(const char *str, struct GNUNET_CRYPTO_PrivateKey *zk)
static void display_record(const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
static void collect_orphans(const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
static int ret
Global return value.
static void handle_reverse_lookup(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called with the result of our attempt to obtain a name for a given public key.
static void reset_handles(void)
static void * data
Value in binary format.
static void lookup_error_cb(void *cls)
Function called on errors while monitoring.
static void do_shutdown(void *cls)
Task run on shutdown.
static struct GNUNET_IDENTITY_Handle * idh
Identity service handle.
static struct RecordSetEntry * recordset
Entry in record set for processing records in bulk.
static char * ego_name
Name of the ego controlling the zone.
static void reverse_error_cb(void *cls)
Function called if we encountered an error in zone-to-name.
static struct MarkedRecord * marked_head
Marked record list.
static struct EgoEntry * ego_head
Ego list.
static int is_shadow
Is record a shadow record (GNUNET_GNSRECORD_RF_SHADOW)
static void add_continuation(void *cls, enum GNUNET_ErrorCode ec)
static struct GNUNET_SCHEDULER_Task * purge_task
Purge task.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *_cfg)
Main function that will be run.
static void finish_command(void)
static int del
Desired action is to remove a record.
static int etime_is_rel
Is expiration time relative or absolute time?
static void add_error_cb(void *cls)
Function called if lookup fails.
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static int parse_expiration(const char *expirationstring, int *etime_is_rel, uint64_t *etime)
Parse expiration time.
static void marked_deleted(void *cls, enum GNUNET_ErrorCode ec)
static void id_connect_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Function called with ALL of the egos known to the identity service, used on startup if the user did n...
static struct GNUNET_NAMESTORE_ZoneIterator * list_it
List iterator for the 'list' operation.
static int is_maintenance
Is record a maintenance record (GNUNET_GNSRECORD_RF_MAINTENANCE)
static struct MarkedRecord * marked_tail
Marked record list.
static void display_record_iterator(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
Process a record that was stored in the namestore.
static void purge_orphans_iterator(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
static void monitor_error_cb(void *cls)
Function called on errors while monitoring.
static int read_from_stdin
Run in read from stdin mode.
static void run_with_zone_pkey(const struct GNUNET_CONFIGURATION_Handle *cfg)
We have obtained the zone's private key, so now process the main commands using it.
int main(int argc, char *const *argv)
The main function for gnunet-namestore.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static char * expirationstring
Desired expiration time.
static void collect_zone_records_to_purge(const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *rname, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
static struct GNUNET_NAMESTORE_QueueEntry * add_qe_uri
Queue entry for the 'add-uri' operation.
static void del_monitor(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
We were asked to delete something; this function is called with the existing records.
static void process_command_stdin()
static int add
Desired action is to add a record.
static struct GNUNET_NAMESTORE_QueueEntry * reverse_qe
Queue entry for the 'reverse lookup' operation (in combination with a name).
static void zone_iteration_error_cb(void *cls)
Function called when we encountered an error in a zone iteration.
static void get_existing_record(void *cls, const struct GNUNET_CRYPTO_PrivateKey *zone_key, const char *rec_name, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
We're storing a record; this function is given the existing record so that we can merge the informati...
static char * typestring
Type of the record to add/remove, NULL to remove all.
static char * uri
URI to import.
static uint64_t etime
Expiration string converted to numeric value.
static char * reverse_pkey
Reverse lookup to perform.
static int is_public
Is record public (opposite of GNUNET_GNSRECORD_RF_PRIVATE)
API to the GNS service.
API that can be used to manipulate GNS record data.
Identity service; implements identity management for GNUnet.
API that can be used to store naming information on a GNUnet node;.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_DNSPARSER_TYPE_OPENPGPKEY
#define GNUNET_DNSPARSER_TYPE_TLSA
#define GNUNET_DNSPARSER_TYPE_SRV
#define GNUNET_DNSPARSER_TYPE_SOA
#define GNUNET_DNSPARSER_TYPE_SMIMEA
#define GNUNET_DNSPARSER_MAX_NAME_LENGTH
Maximum length of a name in DNS.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number to the corresponding type string (e.g.
Definition: gnsrecord.c:227
uint32_t GNUNET_GNSRECORD_typename_to_number(const char *dns_typename)
Convert a type name (e.g.
Definition: gnsrecord.c:200
int GNUNET_GNSRECORD_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of the value s of a record of type type to the respective binary repre...
Definition: gnsrecord.c:177
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
GNUNET_GNSRECORD_Filter
Filter for GNUNET_GNSRECORD_normalize_record_set().
#define GNUNET_GNSRECORD_TYPE_ANY
Record type indicating any record/'*'.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the binary value data of a record of type type to a human-readable string.
Definition: gnsrecord.c:155
@ GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
This expiration time of the record is a relative time (not an absolute time).
@ GNUNET_GNSRECORD_RF_CRITICAL
This record is critical.
@ GNUNET_GNSRECORD_RF_SUPPLEMENTAL
This is a supplemental record.
@ GNUNET_GNSRECORD_RF_MAINTENANCE
Maintenance records.
@ GNUNET_GNSRECORD_RF_SHADOW
This record should not be used unless all (other) records in the set with an absolute expiration time...
@ GNUNET_GNSRECORD_RF_PRIVATE
This is a private record of this peer and it should thus not be published.
@ GNUNET_GNSRECORD_RF_NONE
Entry for no flags / cleared flags.
@ GNUNET_GNSRECORD_FILTER_NONE
No filter flags set.
@ GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE
Include maintenance records (TOMBSTONE etc).
@ GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE
Filter private records.
const struct GNUNET_CRYPTO_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:517
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:487
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:732
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:529
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:68
#define GNUNET_log(kind,...)
char * GNUNET_CRYPTO_private_key_to_string(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates a (Base32) string representation of the private key.
Definition: crypto_pkey.c:561
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_public_key_from_string(const char *str, struct GNUNET_CRYPTO_PublicKey *key)
Parses a (Base32) string representation of the public key.
Definition: crypto_pkey.c:571
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_MESSAGE
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start2(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordSetMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls, enum GNUNET_GNSRECORD_Filter filter)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT).
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_record_set_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup2(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls, enum GNUNET_GNSRECORD_Filter filter)
Lookup an item in the namestore with GNSRECORD filter.
void GNUNET_NAMESTORE_zone_monitor_stop(struct GNUNET_NAMESTORE_ZoneMonitor *zm)
Stop monitoring a zone for changes.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_PrivateKey *zone, const struct GNUNET_CRYPTO_PublicKey *value_zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls)
Look for an existing PKEY delegation record for a given public key.
struct GNUNET_NAMESTORE_ZoneMonitor * GNUNET_NAMESTORE_zone_monitor_start2(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_PrivateKey *zone, int iterate_first, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordSetMonitor monitor, void *monitor_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, enum GNUNET_GNSRECORD_Filter filter)
Begin monitoring a zone for changes.
void GNUNET_NAMESTORE_zone_monitor_next(struct GNUNET_NAMESTORE_ZoneMonitor *zm, uint64_t limit)
Calls the monitor processor specified in GNUNET_NAMESTORE_zone_monitor_start for the next record(s).
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1334
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1299
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_relative(const char *fancy_time, struct GNUNET_TIME_Relative *rtime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:260
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
#define GNUNET_TIME_relative_cmp(t1, op, t2)
Compare two relative times.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:617
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_time_to_absolute(const char *fancy_time, struct GNUNET_TIME_Absolute *atime)
Convert a given fancy human-readable time to our internal representation.
Definition: strings.c:302
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define GNUNET_GNSRECORD_TYPE_NICK
GNS zone nickname.
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
GNUNET_ErrorCode
Taler error codes.
@ GNUNET_EC_NONE
No error (success).
@ GNUNET_EC_NAMESTORE_RECORD_EXISTS
Record already exists.
@ GNUNET_EC_NAMESTORE_RECORD_NOT_FOUND
Record not found.
The default namestore ego.
char * identifier
Ego Identifier.
struct EgoEntry * prev
DLL.
struct EgoEntry * next
DLL.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Definition of a command line option.
uint32_t record_type
Type of the GNS/DNS record.
const void * data
Binary value stored in the DNS record.
size_t data_size
Number of bytes in data.
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
uint64_t expiration_time
Expiration time for the DNS record.
Handle for an ego.
Definition: identity.h:37
Handle for the service.
Definition: identity_api.c:97
Connection to the NAMESTORE service.
An QueueEntry used to store information for a pending NAMESTORE record operation.
Definition: namestore_api.c:49
Handle for a zone iterator operation.
Handle for a monitoring activity.
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
The record marked for deletion.
struct MarkedRecord * next
DLL.
struct GNUNET_CRYPTO_PrivateKey key
The zone key.
char * name
Ego Identifier.
struct MarkedRecord * prev
DLL.
Entry in record set for bulk processing.
struct GNUNET_GNSRECORD_Data record
The record to add/remove.
struct RecordSetEntry * next
Kept in a linked list.