GNUnet 0.29.1-21-g8c89d4373
 
Loading...
Searching...
No Matches
configuration.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2006, 2007, 2008, 2009, 2013, 2020, 2021, 2026 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 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
29
30#define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__)
31
32#define LOG_STRERROR_FILE(kind, syscall, filename) \
33 GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
34
39{
44
48 char *value;
49
53 char *filename;
54
58 unsigned int lineno;
59};
60
61
66{
71
75 char *key;
76
80 char *val;
81
86};
87
88
137
139{
144
148 unsigned int level;
149
151
153
159
164
169
174};
175
176
236
237
248
249
250void
256
257
260{
262 char *p;
263
265 cfg->pd = pd;
266 /* make certain values from the project data available
267 as PATHS */
270 if (NULL != p)
271 {
273 "PATHS",
274 "DATADIR",
275 p);
276 GNUNET_free (p);
277 }
280 if (NULL != p)
281 {
283 "PATHS",
284 "LIBDIR",
285 p);
286 GNUNET_free (p);
287 }
290 if (NULL != p)
291 {
293 "PATHS",
294 "BINDIR",
295 p);
296 GNUNET_free (p);
297 }
300 if (NULL != p)
301 {
303 "PATHS",
304 "PREFIX",
305 p);
306 GNUNET_free (p);
307 }
310 if (NULL != p)
311 {
313 "PATHS",
314 "LOCALEDIR",
315 p);
316 GNUNET_free (p);
317 }
320 if (NULL != p)
321 {
323 "PATHS",
324 "ICONDIR",
325 p);
326 GNUNET_free (p);
327 }
330 if (NULL != p)
331 {
333 "PATHS",
334 "DOCDIR",
335 p);
336 GNUNET_free (p);
337 }
340 if (NULL != p)
341 {
343 "PATHS",
344 "LIBEXECDIR",
345 p);
346 GNUNET_free (p);
347 }
348 return cfg;
349}
350
351
352void
354{
355 struct ConfigSection *sec;
356 struct ConfigFile *cf;
357
358 while (NULL != (sec = cfg->sections))
360 while (NULL != (cf = cfg->loaded_files_head))
361 {
366 cf);
367 GNUNET_free (cf);
368 }
371}
372
373
376 const char *filename,
378 void *cb_cls)
379{
382
384 if (GNUNET_OK !=
386 filename))
387 {
388 GNUNET_break (0);
390 return GNUNET_SYSERR;
391 }
392 ret = cb (cb_cls,
393 cfg);
395 return ret;
396}
397
398
403{
407 char **files;
408
412 unsigned int files_length;
413};
414
415
427 const char *filename)
428{
429 struct CollectFilesContext *igc = cls;
430
432 igc->files_length,
434 return GNUNET_OK;
435}
436
437
445static struct ConfigSection *
447 const char *section)
448{
449 struct ConfigSection *pos;
450
451 if (NULL == cfg)
452 return NULL;
453 pos = cfg->sections;
454 while ( (NULL != pos) &&
455 (0 != strcasecmp (section,
456 pos->name)) )
457 pos = pos->next;
458 return pos;
459}
460
461
462static int
463pstrcmp (const void *a,
464 const void *b)
465{
466 return strcmp (*((const char **) a),
467 *((const char **) b));
468}
469
470
471static void
473 const char *section,
474 const struct ConfigEntry *entry);
475
476
484 const char *path_or_glob,
485 bool path_is_glob,
486 const char *restrict_section,
487 const char *source_filename,
488 unsigned int source_lineno)
489{
490 char *inline_path = NULL;
491 struct GNUNET_CONFIGURATION_Handle *other_cfg = NULL;
492 struct CollectFilesContext igc = {
493 .files = NULL,
494 .files_length = 0,
495 };
496 enum GNUNET_GenericReturnValue fun_ret;
497 unsigned int old_nest_level = cfg->current_nest_level++;
498
499 /* We support the section restriction only for non-globs */
500 GNUNET_assert (! (path_is_glob && (NULL != restrict_section)));
501
502 if (NULL == source_filename)
503 {
505 "Refusing to parse inline configurations, "
506 "not allowed without source filename!\n");
507 fun_ret = GNUNET_SYSERR;
508 goto cleanup;
509 }
510
511 if ('/' == *path_or_glob)
512 inline_path = GNUNET_strdup (path_or_glob);
513 else
514 {
515 /* We compute the canonical, absolute path first,
516 so that relative imports resolve properly with symlinked
517 config files. */
518 char *source_realpath;
519 char *endsep;
520
521 source_realpath = realpath (source_filename,
522 NULL);
523 if (NULL == source_realpath)
524 {
525 /* Couldn't even resolve path of base dir. */
526 GNUNET_break (0);
527 /* failed to parse included config */
528 fun_ret = GNUNET_SYSERR;
529 goto cleanup;
530 }
531 endsep = strrchr (source_realpath, '/');
532 GNUNET_assert (NULL != endsep);
533 *endsep = '\0';
534 GNUNET_asprintf (&inline_path,
535 "%s/%s",
536 source_realpath,
537 path_or_glob);
538 free (source_realpath);
539 }
540
541 if (path_is_glob)
542 {
543 int nret;
544
546 "processing config glob '%s'\n",
547 inline_path);
548
549 nret = GNUNET_DISK_glob (inline_path,
551 &igc);
552 if (-1 == nret)
553 {
554 fun_ret = GNUNET_SYSERR;
555 goto cleanup;
556 }
557 GNUNET_assert (nret == igc.files_length);
558 qsort (igc.files,
559 igc.files_length,
560 sizeof (char *),
561 &pstrcmp);
562 for (int i = 0; i < nret; i++)
563 {
564 if (GNUNET_OK !=
566 igc.files[i]))
567 {
568 fun_ret = GNUNET_SYSERR;
569 goto cleanup;
570 }
571 }
572 fun_ret = GNUNET_OK;
573 }
574 else if (NULL != restrict_section)
575 {
576 enum GNUNET_GenericReturnValue inner_ret;
577 struct ConfigSection *cs;
578 struct ConfigFile *cf = GNUNET_new (struct ConfigFile);
579
580 inner_ret = GNUNET_DISK_file_test_read (inline_path);
581
582 cs = find_section (cfg, restrict_section);
583
584 if (NULL == cs)
585 {
586 cs = GNUNET_new (struct ConfigSection);
587 cs->name = GNUNET_strdup (restrict_section);
588 cs->next = cfg->sections;
589 cfg->sections = cs;
590 cs->entries = NULL;
591 }
592 if (cfg->diagnostics)
593 {
594 const char *pwname;
595 const char *grname;
596 char *sfn = GNUNET_STRINGS_filename_expand (inline_path);
597 struct stat istat;
598
599 cs->hint_secret_filename = sfn;
600 if (0 == stat (sfn, &istat))
601 {
602 struct passwd *pw = getpwuid (istat.st_uid);
603 struct group *gr = getgrgid (istat.st_gid);
604 pwname = (NULL == pw) ? "<unknown>" : pw->pw_name;
605 grname = (NULL == gr) ? "<unknown>" : gr->gr_name;
606
608 "%s:%s %o",
609 pwname,
610 grname,
611 istat.st_mode);
612 }
613 else
614 {
615 cs->hint_secret_stat = GNUNET_strdup ("<can't stat file>");
616 }
617 if (source_filename)
618 {
619 /* Possible that this secret section has been inlined before */
621 cs->hint_inlined_from_filename = GNUNET_strdup (source_filename);
622 cs->hint_inlined_from_line = source_lineno;
623 }
624 }
625
626 /* Put file in the load list for diagnostics, even if we can't access it. */
627 {
629 cf->source_filename = GNUNET_strdup (inline_path);
630 cf->hint_restrict_section = GNUNET_strdup (restrict_section);
633 cf);
634 }
635
636 if (GNUNET_OK != inner_ret)
637 {
638 cs->inaccessible = true;
639 cf->hint_inaccessible = true;
640 /* File can't be accessed, but that's okay. */
641 fun_ret = GNUNET_OK;
642 goto cleanup;
643 }
644
645 other_cfg = GNUNET_CONFIGURATION_create (cfg->pd);
646 if (cfg->diagnostics)
648 other_cfg->restrict_section = restrict_section;
649 inner_ret = GNUNET_CONFIGURATION_parse (other_cfg,
650 inline_path);
651 if (GNUNET_OK != inner_ret)
652 {
653 cf->hint_inaccessible = true;
654 fun_ret = inner_ret;
655 goto cleanup;
656 }
657
658 cs = find_section (other_cfg,
659 restrict_section);
660 if (NULL == cs)
661 {
663 "Configuration file '%s' loaded with @inline-secret@ "
664 "does not contain section '%s'.\n",
665 inline_path,
666 restrict_section);
667 /* Inlined configuration is accessible but doesn't contain any values.
668 We treat this as if the inlined section was empty, and do not
669 consider it an error. */
670 fun_ret = GNUNET_OK;
671 goto cleanup;
672 }
673 for (struct ConfigEntry *ce = cs->entries;
674 NULL != ce;
675 ce = ce->next)
677 restrict_section,
678 ce);
679 fun_ret = GNUNET_OK;
680 }
681 else if (GNUNET_OK !=
683 inline_path))
684 {
685 fun_ret = GNUNET_SYSERR;
686 goto cleanup;
687 }
688 else
689 {
690 fun_ret = GNUNET_OK;
691 }
692cleanup:
693 cfg->current_nest_level = old_nest_level;
694 if (NULL != other_cfg)
696 GNUNET_free (inline_path);
697 if (igc.files_length > 0)
698 {
699 for (size_t i = 0; i < igc.files_length; i++)
700 GNUNET_free (igc.files[i]);
702 }
703 return fun_ret;
704}
705
706
715static struct ConfigEntry *
717 const char *section,
718 const char *key)
719{
720 struct ConfigSection *sec;
721
722 if (NULL == (sec = find_section (cfg,
723 section)))
724 return NULL;
725 for (struct ConfigEntry *pos = sec->entries;
726 pos != NULL;
727 pos = pos->next)
728 if (0 == strcasecmp (key,
729 pos->key))
730 return pos;
731 if (sec->inaccessible)
732 {
734 "Section '%s' is marked as inaccessible, because the configuration "
735 "file that contains the section can't be read. Attempts to use "
736 "option '%s' will fail.\n",
737 section,
738 key);
739 return NULL;
740 }
741 return NULL;
742}
743
744
755static void
757 const char *section,
758 const char *option,
759 const char *value,
760 const char *filename,
761 unsigned int line)
762{
763 struct ConfigEntry *e;
764 struct ConfigSource *source;
765
766 if (! cfg->diagnostics)
767 return;
768 e = find_entry (cfg,
769 section,
770 option);
771 if (NULL == e)
772 return;
773 source = GNUNET_new (struct ConfigSource);
774 source->value = GNUNET_strdup (value);
775 source->filename = GNUNET_strdup (filename);
776 source->lineno = line;
777 source->next = e->sources;
778 e->sources = source;
779}
780
781
790static void
792 const char *section,
793 const struct ConfigEntry *entry)
794{
795 struct ConfigEntry *dst;
796 struct ConfigSource *head = NULL;
797 struct ConfigSource *tail = NULL;
798
800 section,
801 entry->key,
802 entry->val);
803 if ( (! cfg->diagnostics) ||
804 (NULL == entry->sources) )
805 return;
806 dst = find_entry (cfg,
807 section,
808 entry->key);
809 GNUNET_assert (NULL != dst);
810 for (const struct ConfigSource *pos = entry->sources;
811 NULL != pos;
812 pos = pos->next)
813 {
814 struct ConfigSource *copy = GNUNET_new (struct ConfigSource);
815
816 copy->value = GNUNET_strdup (pos->value);
817 copy->filename = GNUNET_strdup (pos->filename);
818 copy->lineno = pos->lineno;
819 if (NULL == tail)
820 head = copy;
821 else
822 tail->next = copy;
823 tail = copy;
824 }
825 tail->next = dst->sources;
826 dst->sources = head;
827}
828
829
832 const char *mem,
833 size_t size,
834 const char *source_filename)
835{
836 size_t line_size;
837 unsigned int nr;
838 size_t r_bytes;
839 size_t to_read;
841 char *section;
842 char *eq;
843 char *tag;
844 char *value;
845 char *line_orig = NULL;
846
847 ret = GNUNET_OK;
848 section = NULL;
849 nr = 0;
850 r_bytes = 0;
851 while (r_bytes < size)
852 {
853 const char *pos;
854 char *line;
855 bool emptyline;
856
857 GNUNET_free (line_orig);
858 /* fgets-like behaviour on buffer */
859 to_read = size - r_bytes;
860 pos = memchr (&mem[r_bytes], '\n', to_read);
861 if (NULL == pos)
862 {
863 line_orig = GNUNET_strndup (&mem[r_bytes],
864 line_size = to_read);
865 r_bytes += line_size;
866 }
867 else
868 {
869 line_orig = GNUNET_strndup (&mem[r_bytes],
870 line_size = (pos - &mem[r_bytes]));
871 r_bytes += line_size + 1;
872 }
873 line = line_orig;
874 /* increment line number */
875 nr++;
876 if (strlen (line_orig) != line_size)
877 {
879 "NUL byte in line %u\n",
880 nr);
882 break;
883 }
884 /* tabs and '\r' are whitespace */
885 emptyline = GNUNET_YES;
886 for (size_t i = 0; i < line_size; i++)
887 {
888 if (line[i] == '\t')
889 line[i] = ' ';
890 if (line[i] == '\r')
891 line[i] = ' ';
892 if (' ' != line[i])
893 emptyline = GNUNET_NO;
894 }
895 /* ignore empty lines */
896 if (GNUNET_YES == emptyline)
897 continue;
898
899 /* remove tailing whitespace */
900 for (size_t i = line_size - 1;
901 (i >= 1) && (isspace ((unsigned char) line[i]));
902 i--)
903 line[i] = '\0';
904
905 /* remove leading whitespace */
906 for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++)
907 ;
908 line_size = strlen (line);
909
910 /* ignore comments */
911 if ( ('#' == line[0]) ||
912 ('%' == line[0]) )
913 continue;
914
915 /* Handle special directives. */
916 if ('@' == line[0])
917 {
918 char *end = strchr (line + 1, '@');
919 char *directive;
920 enum GNUNET_GenericReturnValue directive_ret;
921
922 if (NULL != cfg->restrict_section)
923 {
925 "Illegal directive in line %u (parsing restricted section %s)\n",
926 nr,
929 break;
930 }
931
932 if (NULL == end)
933 {
935 "Bad directive in line %u\n",
936 nr);
938 break;
939 }
940 *end = '\0';
941 directive = line + 1;
942
943 if (0 == strcasecmp (directive,
944 "INLINE"))
945 {
946 const char *path = end + 1;
947
948 /* Skip space before path */
949 for (; isspace (*path); path++)
950 ;
951
952 directive_ret = handle_inline (cfg,
953 path,
954 false,
955 NULL,
956 source_filename,
957 nr);
958 }
959 else if (0 == strcasecmp (directive,
960 "INLINE-MATCHING"))
961 {
962 const char *path = end + 1;
963
964 /* Skip space before path */
965 for (; isspace (*path); path++)
966 ;
967
968 directive_ret = handle_inline (cfg,
969 path,
970 true,
971 NULL,
972 source_filename,
973 nr);
974 }
975 else if (0 == strcasecmp (directive,
976 "INLINE-SECRET"))
977 {
978 char *secname = end + 1;
979 char *secname_end;
980 const char *path;
981
982 /* Skip space before secname */
983 for (; isspace (*secname); secname++)
984 ;
985
986 secname_end = strchr (secname, ' ');
987
988 if (NULL == secname_end)
989 {
991 "Bad inline-secret directive in line %u\n",
992 nr);
994 break;
995 }
996 *secname_end = '\0';
997 path = secname_end + 1;
998
999 /* Skip space before path */
1000 for (; isspace (*path); path++)
1001 ;
1002
1003 directive_ret = handle_inline (cfg,
1004 path,
1005 false,
1006 secname,
1007 source_filename,
1008 nr);
1009 }
1010 else
1011 {
1013 "Unknown or malformed directive '%s' in line %u\n",
1014 directive,
1015 nr);
1017 break;
1018 }
1019 if (GNUNET_OK != directive_ret)
1020 {
1021 ret = directive_ret;
1022 break;
1023 }
1024 continue;
1025 }
1026 if ( ('[' == line[0]) &&
1027 (']' == line[line_size - 1]) )
1028 {
1029 /* [value] */
1030 line[line_size - 1] = '\0';
1031 value = &line[1];
1032 GNUNET_free (section);
1033 section = GNUNET_strdup (value);
1034 continue;
1035 }
1036 if (NULL != (eq = strchr (line, '=')))
1037 {
1038
1039 if (NULL == section)
1040 {
1042 "Syntax error while deserializing in line %u (option without section)\n",
1043 nr);
1045 break;
1046 }
1047
1048 /* tag = value */
1049 tag = GNUNET_strndup (line, eq - line);
1050 /* remove tailing whitespace */
1051 for (int i = strlen (tag) - 1;
1052 (i >= 1) && (isspace ((unsigned char) tag[i]));
1053 i--)
1054 tag[i] = '\0';
1055
1056 /* Strip whitespace */
1057 value = eq + 1;
1058 while (isspace ((unsigned char) value[0]))
1059 value++;
1060 for (int i = strlen (value) - 1;
1061 (i >= 1) && (isspace ((unsigned char) value[i]));
1062 i--)
1063 value[i] = '\0';
1064
1065 /* remove quotes */
1066 if ( ('"' == value[0]) &&
1067 ('"' == value[strlen (value) - 1]) )
1068 {
1069 value[strlen (value) - 1] = '\0';
1070 value++;
1071 }
1073 section,
1074 tag,
1075 value);
1076 if (cfg->diagnostics)
1077 {
1079 section,
1080 tag,
1081 value,
1082 source_filename
1083 ? source_filename
1084 : "<input>",
1085 nr);
1086 }
1087 GNUNET_free (tag);
1088 continue;
1089 }
1090 /* parse error */
1092 "Syntax error while deserializing in line %u\n",
1093 nr);
1095 break;
1096 }
1097 GNUNET_free (line_orig);
1098 GNUNET_free (section);
1099 GNUNET_assert ( (GNUNET_OK != ret) ||
1100 (r_bytes == size) );
1101 return ret;
1102}
1103
1104
1107 const char *filename)
1108{
1109 struct ConfigFile *loaded_file;
1110 uint64_t fs64;
1111 size_t fs;
1112 char *fn;
1113 char *mem;
1114 int dirty;
1116 ssize_t sret;
1117
1120 "Asked to parse config file `%s'\n",
1121 fn);
1122 if (NULL == fn)
1123 return GNUNET_SYSERR;
1124
1125
1126 /* Check for cycles */
1127 {
1128 unsigned int lvl = cfg->current_nest_level;
1129 struct ConfigFile *cf = cfg->loaded_files_tail;
1130 struct ConfigFile *parent = NULL;
1131
1132
1133 for (; NULL != cf; parent = cf, cf = cf->prev)
1134 {
1135 /* Check parents based on level, skipping children of siblings. */
1136 if (cf->level >= lvl)
1137 continue;
1138 lvl = cf->level;
1139 if ( (NULL == cf->source_filename) ||
1140 (NULL == filename) )
1141 continue;
1142 if (0 == strcmp (cf->source_filename,
1143 filename))
1144 {
1145 if (NULL == parent)
1146 {
1148 "Forbidden direct cyclic configuration import (%s -> %s)\n",
1149 cf->source_filename,
1150 filename);
1151 }
1152 else
1154 "Forbidden indirect cyclic configuration import (%s -> ... -> %s -> %s)\n",
1155 cf->source_filename,
1156 parent->source_filename,
1157 filename);
1158 GNUNET_free (fn);
1159 return GNUNET_SYSERR;
1160 }
1161 }
1162
1163 }
1164
1165 /* Keep track of loaded files.*/
1166 {
1167 loaded_file = GNUNET_new (struct ConfigFile);
1168
1169 loaded_file->level = cfg->current_nest_level;
1170 loaded_file->source_filename = GNUNET_strdup (filename
1171 ? filename
1172 : "<input>");
1175 loaded_file);
1176 }
1177
1178 dirty = cfg->dirty; /* back up value! */
1179 if (GNUNET_SYSERR ==
1181 &fs64,
1182 GNUNET_NO,
1183 GNUNET_YES))
1184 {
1186 "Error while determining the file size of `%s'\n",
1187 fn);
1188 GNUNET_free (fn);
1189 return GNUNET_SYSERR;
1190 }
1191 if (fs64 > SIZE_MAX)
1192 {
1193 GNUNET_break (0); /* File size is more than the heap size */
1194 GNUNET_free (fn);
1195 return GNUNET_SYSERR;
1196 }
1197 fs = fs64;
1198 mem = GNUNET_malloc (fs);
1199 sret = GNUNET_DISK_fn_read (fn,
1200 mem,
1201 fs);
1202 if ((sret < 0) || (fs != (size_t) sret))
1203 {
1205 "Error while reading file `%s'\n",
1206 fn);
1207 GNUNET_free (fn);
1208 GNUNET_free (mem);
1209 return GNUNET_SYSERR;
1210 }
1211 if (cfg->diagnostics)
1212 {
1213 GNUNET_CRYPTO_hash (mem,
1214 fs,
1215 &loaded_file->content_hash);
1216 }
1218 "Deserializing contents of file `%s'\n",
1219 fn);
1221 mem,
1222 fs,
1223 fn);
1224 if (GNUNET_SYSERR == ret)
1225 {
1227 _ ("Failed to parse configuration file `%s'\n"),
1228 fn);
1229 }
1230 else if (cfg->diagnostics)
1231 {
1232 loaded_file->have_content_hash = true;
1233 }
1234 GNUNET_free (fn);
1235 GNUNET_free (mem);
1236 /* restore dirty flag - anything we set in the meantime
1237 * came from disk */
1238 cfg->dirty = dirty;
1239 return ret;
1240}
1241
1242
1248
1249
1257static bool
1258do_skip (const char *sec,
1259 const char *key)
1260{
1261 if (0 != strcasecmp ("PATHS",
1262 sec))
1263 return false;
1264 return ( (0 == strcasecmp ("DATADIR",
1265 key)) ||
1266 (0 == strcasecmp ("LIBDIR",
1267 key)) ||
1268 (0 == strcasecmp ("BINDIR",
1269 key)) ||
1270 (0 == strcasecmp ("PREFIX",
1271 key)) ||
1272 (0 == strcasecmp ("LOCALEDIR",
1273 key)) ||
1274 (0 == strcasecmp ("ICONDIR",
1275 key)) ||
1276 (0 == strcasecmp ("DOCDIR",
1277 key)) ||
1278 (0 == strcasecmp ("DEFAULTCONFIG",
1279 key)) ||
1280 (0 == strcasecmp ("LIBEXECDIR",
1281 key)) );
1282}
1283
1284
1285char *
1287 size_t *size)
1288{
1289 char *mem;
1290 char *cbuf;
1291 char *val;
1292 char *pos;
1293 size_t m_size;
1294 size_t c_size;
1295
1296 /* Pass1 : calculate the buffer size required */
1297 m_size = 0;
1298 for (struct ConfigSection *sec = cfg->sections;
1299 NULL != sec;
1300 sec = sec->next)
1301 {
1302 if (sec->inaccessible && (NULL == sec->entries))
1303 continue;
1304 /* For each section we need to add 3 characters: {'[',']','\n'} */
1305 m_size += strlen (sec->name) + 3;
1306 for (struct ConfigEntry *ent = sec->entries;
1307 NULL != ent;
1308 ent = ent->next)
1309 {
1310 if (do_skip (sec->name,
1311 ent->key))
1312 continue;
1313 if (NULL != ent->val)
1314 {
1315 /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */
1316 pos = ent->val;
1317 while (NULL != (pos = strstr (pos, "\n")))
1318 {
1319 m_size++;
1320 pos++;
1321 }
1322 /* For each key = value pair we need to add 4 characters (2
1323 spaces and 1 equal-to character and 1 new line) */
1324 m_size += strlen (ent->key) + strlen (ent->val) + 4;
1325 }
1326 }
1327 /* A new line after section end */
1328 m_size++;
1329 }
1330
1331 /* Pass2: Allocate memory and write the configuration to it */
1332 mem = GNUNET_malloc (m_size);
1333 c_size = 0;
1334 *size = c_size;
1335 for (struct ConfigSection *sec = cfg->sections;
1336 NULL != sec;
1337 sec = sec->next)
1338 {
1339 int len;
1340
1341 /* skipped in pass 1 */
1342 if (sec->inaccessible && (NULL == sec->entries))
1343 continue;
1344 len = GNUNET_asprintf (&cbuf,
1345 "[%s]\n",
1346 sec->name);
1347 GNUNET_assert (0 < len);
1348 GNUNET_memcpy (mem + c_size,
1349 cbuf,
1350 len);
1351 c_size += len;
1352 GNUNET_free (cbuf);
1353 for (struct ConfigEntry *ent = sec->entries;
1354 NULL != ent;
1355 ent = ent->next)
1356 {
1357 if (do_skip (sec->name,
1358 ent->key))
1359 continue;
1360 if (NULL != ent->val)
1361 {
1362 val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1363 strcpy (val, ent->val);
1364 while (NULL != (pos = strstr (val, "\n")))
1365 {
1366 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1367 pos[0] = '\\';
1368 pos[1] = 'n';
1369 }
1370 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
1371 GNUNET_free (val);
1372 GNUNET_memcpy (mem + c_size, cbuf, len);
1373 c_size += len;
1374 GNUNET_free (cbuf);
1375 }
1376 }
1377 GNUNET_memcpy (mem + c_size, "\n", 1);
1378 c_size++;
1379 }
1380 GNUNET_assert (c_size == m_size);
1381 *size = c_size;
1382 return mem;
1383}
1384
1385
1394static void
1396 const struct GNUNET_CONFIGURATION_Handle *cfg,
1397 struct GNUNET_Buffer *buf,
1399{
1401 ipk);
1402 const char *ipkname;
1403 switch (ipk)
1404 {
1406 ipkname = "IPK_DATADIR";
1407 break;
1409 ipkname = "IPK_BINDIR";
1410 break;
1412 ipkname = "IPK_LIBDIR";
1413 break;
1415 ipkname = "IPK_PREFIX";
1417 ipkname = "IPK_LOCALEDIR";
1418 break;
1420 ipkname = "IPK_ICONDIR";
1422 ipkname = "IPK_DOCDIR";
1423 break;
1425 ipkname = "IPK_LIBEXECDIR";
1426 break;
1428 ipkname = "IPK_SELF_PREFIX";
1429 break;
1430 default:
1431 ipkname = "??";
1432 break;
1433 }
1435 "# %s = %s\n",
1436 ipkname,
1437 v);
1438 GNUNET_free (v);
1439}
1440
1441
1449static char *
1451 bool verbose)
1452{
1453 struct GNUNET_Buffer buf = { 0 };
1454
1456 "#\n# Configuration file diagnostics\n#\n");
1458 "# Entry point: %s\n",
1460 "<none>");
1462 "#\n# Files Loaded:\n");
1463
1464 for (struct ConfigFile *cfil = cfg->loaded_files_head;
1465 NULL != cfil;
1466 cfil = cfil->next)
1467 {
1469 "# ");
1470 for (unsigned int i = 0; i < cfil->level; i++)
1472 "+");
1473 if (0 != cfil->level)
1475 " ");
1476
1478 "%s",
1479 cfil->source_filename);
1480
1481 if (NULL != cfil->hint_restrict_section)
1483 " (%s secret section %s)",
1484 cfil->hint_inaccessible
1485 ? "inaccessible"
1486 : "loaded",
1487 cfil->hint_restrict_section);
1488
1490 "\n");
1491 }
1492
1494 "#\n# Installation paths:\n");
1495
1505
1506
1508 "#\n\n");
1509
1510 for (struct ConfigSection *sec = cfg->sections;
1511 NULL != sec;
1512 sec = sec->next)
1513 {
1514 if (sec->hint_secret_filename)
1516 "# secret section from %s\n# secret file stat %s\n",
1517 sec->hint_secret_filename,
1518 sec->hint_secret_stat);
1519 if (sec->hint_inlined_from_filename)
1520 {
1522 "# inlined from %s:%u\n",
1523 sec->hint_inlined_from_filename,
1524 sec->hint_inlined_from_line);
1525 }
1527 "[%s]\n\n",
1528 sec->name);
1529 if (sec->inaccessible && (NULL == sec->entries))
1530 {
1532 "# <section contents inaccessible>\n\n\n");
1533 continue;
1534 }
1535 for (struct ConfigEntry *ent = sec->entries;
1536 NULL != ent;
1537 ent = ent->next)
1538 {
1539 if (do_skip (sec->name,
1540 ent->key))
1541 continue;
1542 if (NULL != ent->val)
1543 {
1544 char *pos;
1545 char *val = GNUNET_malloc (strlen (ent->val) * 2 + 1);
1546 strcpy (val, ent->val);
1547 while (NULL != (pos = strstr (val, "\n")))
1548 {
1549 memmove (&pos[2], &pos[1], strlen (&pos[1]));
1550 pos[0] = '\\';
1551 pos[1] = 'n';
1552 }
1553 if (NULL != ent->sources)
1554 {
1555 if (verbose &&
1556 (NULL != ent->sources->next))
1557 {
1559 &buf,
1560 "# duplicate definitions (highest precedence first):\n");
1561 for (const struct ConfigSource *source = ent->sources;
1562 NULL != source;
1563 source = source->next)
1564 {
1565 const char *status;
1566
1567 if (source == ent->sources)
1568 status = "effective";
1569 else if (0 == strcmp (source->value,
1570 ent->val))
1571 status = "same value";
1572 else
1573 status = "different value";
1575 &buf,
1576 "# %s:%u (%s)\n",
1577 source->filename,
1578 source->lineno,
1579 status);
1580 }
1581 }
1582 else
1583 {
1585 "# %s:%u\n",
1586 ent->sources->filename,
1587 ent->sources->lineno);
1588 }
1589 }
1591 "%s = %s\n",
1592 ent->key,
1593 val);
1594 GNUNET_free (val);
1595 }
1596 GNUNET_buffer_write_str (&buf, "\n");
1597 }
1598 if (sec->inaccessible)
1599 {
1601 "# <additional section contents inaccessible>\n\n\n");
1602 continue;
1603 }
1604
1605 GNUNET_buffer_write_str (&buf, "\n");
1606 }
1607 return GNUNET_buffer_reap_str (&buf);
1608}
1609
1610
1611char *
1618
1619
1620char *
1627
1628
1629static enum GNUNET_GenericReturnValue
1630read_file (const char *filename,
1631 char **contents,
1632 size_t *size)
1633{
1634 uint64_t fs64;
1635 ssize_t ret;
1636
1637 if ( (GNUNET_SYSERR ==
1639 &fs64,
1640 GNUNET_NO,
1641 GNUNET_YES)) ||
1642 (fs64 > SIZE_MAX) )
1643 return GNUNET_SYSERR;
1644 *size = (size_t) fs64;
1645 *contents = GNUNET_malloc (*size);
1647 *contents,
1648 *size);
1649 if ( (ret < 0) || ((size_t) ret != *size) )
1650 {
1651 GNUNET_free (*contents);
1652 *contents = NULL;
1653 return GNUNET_SYSERR;
1654 }
1655 return GNUNET_OK;
1656}
1657
1658
1666static bool
1668 const struct GNUNET_HashCode *expected)
1669{
1670 struct GNUNET_HashCode actual;
1671 char *contents;
1672 size_t size;
1673
1675 &contents,
1676 &size))
1677 return false;
1678 GNUNET_CRYPTO_hash (contents,
1679 size,
1680 &actual);
1681 GNUNET_free (contents);
1682 return 0 == GNUNET_memcmp (&actual,
1683 expected);
1684}
1685
1686
1696static enum GNUNET_GenericReturnValue
1698 const char *contents,
1699 size_t size,
1700 const struct GNUNET_HashCode *expected_hash)
1701{
1702 char *fn;
1703 char *tfn;
1704
1706 if (fn == NULL)
1707 return GNUNET_SYSERR;
1709 {
1710 GNUNET_free (fn);
1711 return GNUNET_SYSERR;
1712 }
1713 {
1714 /* If @a filename is a symlink, replace what it points at, the way
1715 truncating it in place used to. */
1716 char *rfn = realpath (fn,
1717 NULL);
1718
1719 if (NULL != rfn)
1720 {
1721 GNUNET_free (fn);
1722 fn = GNUNET_strdup (rfn);
1723 free (rfn);
1724 }
1725 }
1726 /* Never rewrite the configuration in place: opening it with O_TRUNC leaves
1727 it observably empty until we have written the new contents, and anyone
1728 parsing the file in that instant -- say a daemon that was just started
1729 with this very configuration -- reads a truncated file and fails. So
1730 write a sibling file and rename(2) it over the target; readers then
1731 always see either the complete old or the complete new configuration. */
1732 GNUNET_asprintf (&tfn,
1733 "%s.%u.tmp",
1734 fn,
1735 (unsigned int) getpid ());
1736 {
1737 struct GNUNET_DISK_FileHandle *h;
1738
1739 h = GNUNET_DISK_file_open (tfn,
1747 if (NULL == h)
1748 {
1749 GNUNET_free (tfn);
1750 GNUNET_free (fn);
1751 return GNUNET_SYSERR;
1752 }
1753 if (((ssize_t) size) !=
1755 contents,
1756 size))
1757 {
1759 "write",
1760 tfn);
1762 (void) unlink (tfn);
1763 GNUNET_free (tfn);
1764 GNUNET_free (fn);
1765 return GNUNET_SYSERR;
1766 }
1767 /* Get the contents onto the disk before the rename publishes them, so
1768 that a crash cannot leave an empty configuration behind. */
1770 {
1772 "fsync",
1773 tfn);
1774 (void) GNUNET_DISK_file_close (h);
1775 (void) unlink (tfn);
1776 GNUNET_free (tfn);
1777 GNUNET_free (fn);
1778 return GNUNET_SYSERR;
1779 }
1781 {
1783 "close",
1784 tfn);
1785 (void) unlink (tfn);
1786 GNUNET_free (tfn);
1787 GNUNET_free (fn);
1788 return GNUNET_SYSERR;
1789 }
1790 }
1791 {
1792 struct stat sbuf;
1793
1794 /* rename(2) replaces the inode, so carry over the permissions of the
1795 configuration we are about to replace (we just created @a tfn). */
1796 if ( (0 == stat (fn,
1797 &sbuf)) &&
1798 (0 != chmod (tfn,
1799 sbuf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO))) )
1801 "chmod",
1802 tfn);
1803 }
1804 if ( (NULL != expected_hash) &&
1805 (! file_hash_matches (fn,
1806 expected_hash)) )
1807 {
1809 "Configuration file `%s' changed while it was being cleaned\n",
1810 fn);
1811 (void) unlink (tfn);
1812 GNUNET_free (tfn);
1813 GNUNET_free (fn);
1814 return GNUNET_SYSERR;
1815 }
1816 if (0 != rename (tfn,
1817 fn))
1818 {
1820 "rename",
1821 fn);
1822 (void) unlink (tfn);
1823 GNUNET_free (tfn);
1824 GNUNET_free (fn);
1825 return GNUNET_SYSERR;
1826 }
1827 GNUNET_free (tfn);
1828 GNUNET_free (fn);
1829 return GNUNET_OK;
1830}
1831
1832
1836 const char *filename)
1837{
1839 char *cfg_buf;
1840 size_t size;
1841
1843 &size);
1845 cfg_buf,
1846 size,
1847 NULL);
1848 GNUNET_free (cfg_buf);
1850 return ret;
1851}
1852
1853
1858{
1859 const char *section;
1860 const char *option;
1861 unsigned int line;
1863};
1864
1865
1869static struct CleanLine *
1871 unsigned int lines_length,
1872 unsigned int line)
1873{
1874 for (unsigned int i = 0; i < lines_length; i++)
1875 if (lines[i].line == line)
1876 return &lines[i];
1877 return NULL;
1878}
1879
1880
1884static bool
1886 const char *target,
1887 struct CleanLine *lines,
1888 unsigned int lines_length)
1889{
1890 struct CleanLine *line;
1891
1892 if (0 != strcmp (source->filename,
1893 target))
1894 return false;
1895 line = find_clean_line (lines,
1896 lines_length,
1897 source->lineno);
1898 return (NULL != line) && line->remove;
1899}
1900
1901
1905static int
1906clean_line_cmp (const void *a,
1907 const void *b)
1908{
1909 const struct CleanLine *la = a;
1910 const struct CleanLine *lb = b;
1911
1912 if (la->line < lb->line)
1913 return -1;
1914 if (la->line > lb->line)
1915 return 1;
1916 return 0;
1917}
1918
1919
1922 const struct GNUNET_CONFIGURATION_Handle *cfg,
1923 const char *filename,
1925 void *cb_cls,
1926 unsigned int *removed)
1927{
1928 struct CleanLine *lines = NULL;
1929 unsigned int lines_length = 0;
1930 const struct ConfigFile *parsed_file = NULL;
1931 char *target;
1932 char *contents = NULL;
1933 char *cleaned = NULL;
1934 size_t size;
1935 size_t cleaned_size = 0;
1937
1938 if (NULL != removed)
1939 *removed = 0;
1940 if ( (! cfg->diagnostics) ||
1941 (NULL == filename) )
1942 return GNUNET_SYSERR;
1944 if (NULL == target)
1945 return GNUNET_SYSERR;
1946
1947 for (const struct ConfigFile *cf = cfg->loaded_files_head;
1948 NULL != cf;
1949 cf = cf->next)
1950 {
1951 char *source;
1952
1953 if (! cf->have_content_hash)
1954 continue;
1955 source = GNUNET_STRINGS_filename_expand (cf->source_filename);
1956 if ( (NULL != source) &&
1957 (0 == strcmp (source,
1958 target)) )
1959 parsed_file = cf;
1961 }
1962 if (NULL == parsed_file)
1963 {
1965 "Configuration file `%s' was not parsed with diagnostics enabled\n",
1966 target);
1967 goto cleanup;
1968 }
1969 if (GNUNET_OK != read_file (target,
1970 &contents,
1971 &size))
1972 {
1974 "Configuration file `%s' changed since it was parsed\n",
1975 target);
1976 goto cleanup;
1977 }
1978 {
1979 struct GNUNET_HashCode actual;
1980
1981 GNUNET_CRYPTO_hash (contents,
1982 size,
1983 &actual);
1984 if (0 != GNUNET_memcmp (&actual,
1985 &parsed_file->content_hash))
1986 {
1988 "Configuration file `%s' changed since it was parsed\n",
1989 target);
1990 goto cleanup;
1991 }
1992 }
1993
1994 /* First mark every target definition that has an exact duplicate at a
1995 distinct source location. */
1996 for (const struct ConfigSection *sec = cfg->sections;
1997 NULL != sec;
1998 sec = sec->next)
1999 for (const struct ConfigEntry *ent = sec->entries;
2000 NULL != ent;
2001 ent = ent->next)
2002 for (const struct ConfigSource *source = ent->sources;
2003 NULL != source;
2004 source = source->next)
2005 {
2006 bool duplicate = false;
2007 struct CleanLine line;
2008
2009 if (0 != strcmp (source->filename,
2010 target))
2011 continue;
2012 for (const struct ConfigSource *other = ent->sources;
2013 NULL != other;
2014 other = other->next)
2015 {
2016 if ( (0 == strcmp (source->value,
2017 other->value)) &&
2018 ( (source->lineno != other->lineno) ||
2019 (0 != strcmp (source->filename,
2020 other->filename)) ) )
2021 {
2022 duplicate = true;
2023 break;
2024 }
2025 }
2026 if ( (! duplicate) ||
2027 (NULL != find_clean_line (lines,
2028 lines_length,
2029 source->lineno)) )
2030 continue;
2031 line.section = sec->name;
2032 line.option = ent->key;
2033 line.line = source->lineno;
2034 line.remove = true;
2035 GNUNET_array_append (lines,
2036 lines_length,
2037 line);
2038 }
2039
2040 /* Keep the highest-precedence target duplicate needed to preserve every
2041 effective value after all of the tentative removals. */
2042 for (const struct ConfigSection *sec = cfg->sections;
2043 NULL != sec;
2044 sec = sec->next)
2045 for (const struct ConfigEntry *ent = sec->entries;
2046 NULL != ent;
2047 ent = ent->next)
2048 {
2049 const struct ConfigSource *survivor = NULL;
2050
2051 for (const struct ConfigSource *source = ent->sources;
2052 NULL != source;
2053 source = source->next)
2055 target,
2056 lines,
2057 lines_length))
2058 {
2059 survivor = source;
2060 break;
2061 }
2062 if ( (NULL != survivor) &&
2063 (0 == strcmp (survivor->value,
2064 ent->val)) )
2065 continue;
2066 for (const struct ConfigSource *source = ent->sources;
2067 NULL != source;
2068 source = source->next)
2069 {
2070 struct CleanLine *line;
2071
2072 if ( (0 != strcmp (source->filename,
2073 target)) ||
2074 (0 != strcmp (source->value,
2075 ent->val)) )
2076 continue;
2077 line = find_clean_line (lines,
2078 lines_length,
2079 source->lineno);
2080 if ( (NULL != line) && line->remove)
2081 {
2082 line->remove = false;
2083 break;
2084 }
2085 }
2086 }
2087
2088 if (lines_length > 1)
2089 qsort (lines,
2090 lines_length,
2091 sizeof (*lines),
2093 {
2094 unsigned int remove_count = 0;
2095
2096 for (unsigned int i = 0; i < lines_length; i++)
2097 if (lines[i].remove)
2098 remove_count++;
2099 if (0 == remove_count)
2100 {
2101 if (NULL != removed)
2102 *removed = 0;
2103 ret = GNUNET_OK;
2104 goto cleanup;
2105 }
2106
2107 cleaned = GNUNET_malloc (size);
2108 for (size_t offset = 0, line_number = 1; offset < size; line_number++)
2109 {
2110 size_t end = offset;
2111 struct CleanLine *line;
2112
2113 while ( (end < size) && ('\n' != contents[end]) )
2114 end++;
2115 if (end < size)
2116 end++;
2117 line = find_clean_line (lines,
2118 lines_length,
2119 (unsigned int) line_number);
2120 if ( (NULL == line) || (! line->remove) )
2121 {
2122 GNUNET_memcpy (&cleaned[cleaned_size],
2123 &contents[offset],
2124 end - offset);
2125 cleaned_size += end - offset;
2126 }
2127 offset = end;
2128 }
2129 if (GNUNET_OK !=
2130 write_buffer_atomic (target,
2131 cleaned,
2132 cleaned_size,
2133 &parsed_file->content_hash))
2134 goto cleanup;
2135 if (NULL != removed)
2136 *removed = remove_count;
2137 if (NULL != cb)
2138 for (unsigned int i = 0; i < lines_length; i++)
2139 if (lines[i].remove)
2140 cb (cb_cls,
2141 lines[i].section,
2142 lines[i].option,
2143 lines[i].line);
2144 ret = GNUNET_OK;
2145 }
2146
2147cleanup:
2148 GNUNET_free (cleaned);
2149 GNUNET_free (contents);
2150 GNUNET_array_grow (lines,
2151 lines_length,
2152 0);
2153 GNUNET_free (target);
2154 return ret;
2155}
2156
2157
2158void
2160 const struct GNUNET_CONFIGURATION_Handle *cfg,
2162 void *iter_cls)
2163{
2164 for (struct ConfigSection *spos = cfg->sections;
2165 NULL != spos;
2166 spos = spos->next)
2167 for (struct ConfigEntry *epos = spos->entries;
2168 NULL != epos;
2169 epos = epos->next)
2170 if (NULL != epos->val)
2171 iter (iter_cls,
2172 spos->name,
2173 epos->key,
2174 epos->val);
2175}
2176
2177
2178void
2180 const struct GNUNET_CONFIGURATION_Handle *cfg,
2181 const char *section,
2183 void *iter_cls)
2184{
2185 struct ConfigSection *spos;
2186
2187 spos = cfg->sections;
2188 while ((spos != NULL) && (0 != strcasecmp (spos->name, section)))
2189 spos = spos->next;
2190 if (NULL == spos)
2191 return;
2192 for (struct ConfigEntry *epos = spos->entries;
2193 NULL != epos;
2194 epos = epos->next)
2195 if (NULL != epos->val)
2196 iter (iter_cls,
2197 spos->name,
2198 epos->key,
2199 epos->val);
2200 if (spos->inaccessible)
2201 {
2203 "Section '%s' is marked as inaccessible, because a configuration "
2204 "file that contains the section can't be read.\n",
2205 section);
2206 return;
2207 }
2208}
2209
2210
2211void
2213 const struct GNUNET_CONFIGURATION_Handle *cfg,
2215 void *iter_cls)
2216{
2217 struct ConfigSection *spos;
2218 struct ConfigSection *next;
2219
2220 next = cfg->sections;
2221 while (NULL != next)
2222 {
2223 spos = next;
2224 next = spos->next;
2225 if (spos->inaccessible && (NULL == spos->entries))
2226 continue;
2227 iter (iter_cls,
2228 spos->name);
2229 }
2230}
2231
2232
2233void
2235 const char *section)
2236{
2237 struct ConfigSection *spos;
2238 struct ConfigSection *prev;
2239 struct ConfigEntry *ent;
2240
2241 prev = NULL;
2242 spos = cfg->sections;
2243 while (NULL != spos)
2244 {
2245 if (0 == strcasecmp (section,
2246 spos->name))
2247 {
2248 if (NULL == prev)
2249 cfg->sections = spos->next;
2250 else
2251 prev->next = spos->next;
2252 while (NULL != (ent = spos->entries))
2253 {
2254 struct ConfigSource *source;
2255
2256 spos->entries = ent->next;
2257 GNUNET_free (ent->key);
2258 GNUNET_free (ent->val);
2259 while (NULL != (source = ent->sources))
2260 {
2261 ent->sources = source->next;
2262 GNUNET_free (source->value);
2263 GNUNET_free (source->filename);
2265 }
2266 GNUNET_free (ent);
2267 cfg->dirty = GNUNET_YES;
2268 }
2269 GNUNET_free (spos->name);
2273 GNUNET_free (spos);
2274 return;
2275 }
2276 prev = spos;
2277 spos = spos->next;
2278 }
2279}
2280
2281
2291static void
2292copy_entry (void *cls,
2293 const char *section,
2294 const char *option,
2295 const char *value)
2296{
2297 struct GNUNET_CONFIGURATION_Handle *dst = cls;
2298
2300 section,
2301 option,
2302 value);
2303}
2304
2305
2318
2319
2330static void
2332 const char *section,
2333 const char *option,
2334 const char *value)
2335{
2336 struct DiffHandle *dh = cls;
2337 struct ConfigEntry *entNew;
2338
2339 entNew = find_entry (dh->cfg_default, section, option);
2340 if ((NULL != entNew) && (NULL != entNew->val) &&
2341 (0 == strcmp (entNew->val, value)))
2342 return;
2344 section,
2345 option,
2346 value);
2347}
2348
2349
2352 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
2353 const struct GNUNET_CONFIGURATION_Handle *cfg_new)
2354{
2355 struct DiffHandle diffHandle;
2356
2357 GNUNET_break (cfg_default->pd == cfg_new->pd);
2358 diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (cfg_new->pd);
2359 diffHandle.cfg_default = cfg_default;
2362 &diffHandle);
2363 return diffHandle.cfgDiff;
2364}
2365
2366
2370 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
2371 const char *filename)
2372{
2373 int ret;
2374 struct GNUNET_CONFIGURATION_Handle *diff;
2375
2376 diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new);
2379 return ret;
2380}
2381
2382
2383void
2386 const char *section,
2387 const char *option,
2388 const char *value)
2389{
2390 struct ConfigSection *sec;
2391 struct ConfigEntry *e;
2392 char *nv;
2393
2394 e = find_entry (cfg, section, option);
2395 if (NULL != e)
2396 {
2397 if (NULL == value)
2398 {
2399 GNUNET_free (e->val);
2400 e->val = NULL;
2401 }
2402 else
2403 {
2404 nv = GNUNET_strdup (value);
2405 GNUNET_free (e->val);
2406 e->val = nv;
2407 }
2408 return;
2409 }
2410 sec = find_section (cfg, section);
2411 if (sec == NULL)
2412 {
2413 sec = GNUNET_new (struct ConfigSection);
2414 sec->name = GNUNET_strdup (section);
2415 sec->next = cfg->sections;
2416 cfg->sections = sec;
2417 }
2418 e = GNUNET_new (struct ConfigEntry);
2419 e->key = GNUNET_strdup (option);
2420 e->val = GNUNET_strdup (value);
2421 e->next = sec->entries;
2422 sec->entries = e;
2423}
2424
2425
2426void
2428 const char *section,
2429 const char *option,
2430 unsigned long long number)
2431{
2432 char s[64];
2433
2434 GNUNET_snprintf (s,
2435 64,
2436 "%llu",
2437 number);
2439 section,
2440 option,
2441 s);
2442}
2443
2444
2447 const struct GNUNET_CONFIGURATION_Handle *cfg,
2448 const char *section,
2449 const char *option,
2450 unsigned long long *number)
2451{
2452 struct ConfigEntry *e;
2453 char dummy[2];
2454
2455 if (NULL == (e = find_entry (cfg,
2456 section,
2457 option)))
2458 return GNUNET_NO;
2459 if (NULL == e->val)
2460 return GNUNET_NO;
2461 if (1 != sscanf (e->val,
2462 "%llu%1s",
2463 number,
2464 dummy))
2465 return GNUNET_SYSERR;
2466 return GNUNET_OK;
2467}
2468
2469
2470void
2472 const char *section,
2473 const char *option,
2474 float number)
2475{
2476 char s[64];
2477
2478 /* See: #9369 */
2479 const locale_t cl = newlocale (LC_NUMERIC_MASK,
2480 "C",
2481 (locale_t) 0);
2482 locale_t old_locale;
2483
2484 GNUNET_assert ((locale_t) 0 != cl);
2485 old_locale = uselocale (cl);
2486 GNUNET_snprintf (s,
2487 64,
2488 "%f",
2489 (double) number);
2490 uselocale (old_locale);
2491 freelocale (cl);
2493 section,
2494 option,
2495 s);
2496}
2497
2498
2501 const struct GNUNET_CONFIGURATION_Handle *cfg,
2502 const char *section,
2503 const char *option,
2504 float *number)
2505{
2506 struct ConfigEntry *e;
2507 char dummy[2];
2508
2509 if (NULL == (e = find_entry (cfg,
2510 section,
2511 option)))
2512 return GNUNET_NO;
2513 if (NULL == e->val)
2514 return GNUNET_NO;
2515 /* See #9369 */
2516 {
2517 const locale_t cl = newlocale (LC_NUMERIC_MASK,
2518 "C",
2519 (locale_t) 0);
2520 locale_t old_locale;
2521 int n;
2522
2523 GNUNET_assert ((locale_t) 0 != cl);
2524 old_locale = uselocale (cl);
2525 n = sscanf (e->val,
2526 "%f%1s",
2527 number,
2528 dummy);
2529 uselocale (old_locale);
2530 freelocale (cl);
2531 if (1 != n)
2532 return GNUNET_SYSERR;
2533 }
2534 return GNUNET_OK;
2535}
2536
2537
2540 const struct GNUNET_CONFIGURATION_Handle *cfg,
2541 const char *section,
2542 const char *option,
2543 struct GNUNET_TIME_Relative *time)
2544{
2545 struct ConfigEntry *e;
2546 int ret;
2547
2548 if (NULL == (e = find_entry (cfg,
2549 section,
2550 option)))
2551 return GNUNET_NO;
2552 if (NULL == e->val)
2553 return GNUNET_NO;
2555 time);
2556 if (GNUNET_OK != ret)
2558 section,
2559 option,
2560 _ ("Not a valid relative time specification"));
2561 return ret;
2562}
2563
2564
2567 const struct GNUNET_CONFIGURATION_Handle *cfg,
2568 const char *section,
2569 const char *option,
2570 unsigned long long *size)
2571{
2572 struct ConfigEntry *e;
2573
2574 if (NULL == (e = find_entry (cfg,
2575 section,
2576 option)))
2577 return GNUNET_NO;
2578 if (NULL == e->val)
2579 return GNUNET_NO;
2581 size);
2582}
2583
2584
2597 const struct GNUNET_CONFIGURATION_Handle *cfg,
2598 const char *section,
2599 const char *option,
2600 char **value)
2601{
2602 struct ConfigEntry *e;
2603
2604 if ( (NULL == (e = find_entry (cfg,
2605 section,
2606 option))) ||
2607 (NULL == e->val) )
2608 {
2609 *value = NULL;
2610 return GNUNET_NO;
2611 }
2612 *value = GNUNET_strdup (e->val);
2613 return GNUNET_OK;
2614}
2615
2616
2619 const struct GNUNET_CONFIGURATION_Handle *cfg,
2620 const char *section,
2621 const char *option,
2622 const char *const *choices,
2623 const char **value)
2624{
2625 struct ConfigEntry *e;
2626 unsigned int i;
2627
2628 if (NULL == (e = find_entry (cfg,
2629 section,
2630 option)))
2631 return GNUNET_NO;
2632 for (i = 0; NULL != choices[i]; i++)
2633 if (0 == strcasecmp (choices[i], e->val))
2634 break;
2635 if (NULL == choices[i])
2636 {
2638 _ ("Configuration value '%s' for '%s'"
2639 " in section '%s' is not in set of legal choices\n"),
2640 e->val,
2641 option,
2642 section);
2643 return GNUNET_SYSERR;
2644 }
2645 *value = choices[i];
2646 return GNUNET_OK;
2647}
2648
2649
2652 const char *section,
2653 const char *option,
2654 void *buf,
2655 size_t buf_size)
2656{
2657 char *enc;
2658 int res;
2659 size_t data_size;
2660
2661 if (GNUNET_OK !=
2662 (res =
2664 section,
2665 option,
2666 &enc)))
2667 return res;
2668 data_size = (strlen (enc) * 5) / 8;
2669 if (data_size != buf_size)
2670 {
2671 GNUNET_free (enc);
2672 return GNUNET_SYSERR;
2673 }
2674 if (GNUNET_OK !=
2676 strlen (enc),
2677 buf,
2678 buf_size))
2679 {
2680 GNUNET_free (enc);
2681 return GNUNET_SYSERR;
2682 }
2683 GNUNET_free (enc);
2684 return GNUNET_OK;
2685}
2686
2687
2690 const char *section,
2691 const char *option)
2692{
2693 struct ConfigEntry *e;
2694
2695 if ( (NULL == (e = find_entry (cfg,
2696 section,
2697 option))) ||
2698 (NULL == e->val) )
2699 return GNUNET_NO;
2700 return GNUNET_YES;
2701}
2702
2703
2709{
2713 const struct ExpansionFrame *parent;
2714
2718 const char *name;
2719};
2720
2721
2722static char *
2724 char *orig,
2725 const struct ExpansionFrame *frame);
2726
2727
2748static char *
2750 char *orig,
2751 unsigned int depth,
2752 const struct ExpansionFrame *frame,
2753 size_t *skip)
2754{
2755 char *prefix;
2756 char *result;
2757 char *start;
2758 const char *post;
2759 const char *env;
2760 char *def;
2761 char *end;
2762 unsigned int lopen;
2763 char erased_char;
2764 char *erased_pos;
2765 size_t len;
2766 size_t def_skip;
2767 bool recursive = false;
2768 struct ExpansionFrame inner;
2769
2770 *skip = 1;
2771 if (NULL == orig)
2772 return NULL;
2773 if (depth > 128)
2774 {
2776 "Recursive expansion suspected, aborting $-expansion for term `%s'\n",
2777 orig);
2778 return orig;
2779 }
2781 "Asked to $-expand %s\n",
2782 orig);
2783 if ('$' != orig[0])
2784 {
2786 "Doesn't start with $ - not expanding\n");
2787 return orig;
2788 }
2789 erased_char = 0;
2790 erased_pos = NULL;
2791 if ('{' == orig[1])
2792 {
2793 start = &orig[2];
2794 lopen = 1;
2795 end = &orig[1];
2796 while (lopen > 0)
2797 {
2798 end++;
2799 switch (*end)
2800 {
2801 case '}':
2802 lopen--;
2803 break;
2804
2805 case '{':
2806 lopen++;
2807 break;
2808
2809 case '\0':
2811 "Missing closing `}' in option `%s'\n",
2812 orig);
2813 return orig;
2814
2815 default:
2816 break;
2817 }
2818 }
2819 erased_char = *end;
2820 erased_pos = end;
2821 *end = '\0';
2822 post = end + 1;
2823 def = strchr (orig, ':');
2824 if (NULL != def)
2825 {
2826 *def = '\0';
2827 def++;
2828 if (('-' == *def) || ('=' == *def))
2829 def++;
2830 def = GNUNET_strdup (def);
2831 }
2832 }
2833 else
2834 {
2835 int i;
2836
2837 start = &orig[1];
2838 def = NULL;
2839 i = 0;
2840 while ( (orig[i] != '/') &&
2841 (orig[i] != '\\') &&
2842 (orig[i] != '\0') &&
2843 (orig[i] != ' ') )
2844 i++;
2845 if (orig[i] == '\0')
2846 {
2847 post = "";
2848 }
2849 else
2850 {
2851 erased_char = orig[i];
2852 erased_pos = &orig[i];
2853 orig[i] = '\0';
2854 post = &orig[i + 1];
2855 }
2856 }
2858 "Split into `%s' and `%s' with default %s\n",
2859 start,
2860 post,
2861 def);
2862 for (const struct ExpansionFrame *pos = frame;
2863 NULL != pos;
2864 pos = pos->parent)
2865 {
2866 if (0 == strcmp (pos->name,
2867 start))
2868 {
2870 "The definition of `%s' refers to itself, not expanding it\n",
2871 start);
2872 recursive = true;
2873 break;
2874 }
2875 }
2876 if (recursive ||
2877 (GNUNET_OK !=
2879 "PATHS",
2880 start,
2881 &prefix)))
2882 {
2883 if (recursive ||
2884 (NULL == (env = getenv (start))))
2885 {
2886 /* try default */
2887 def = expand_dollar (cfg,
2888 def,
2889 depth + 1,
2890 frame,
2891 &def_skip);
2892 env = def;
2893 }
2894 if (NULL == env)
2895 {
2897 if (erased_pos)
2898 *erased_pos = erased_char;
2900 "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n",
2901 start,
2902 orig);
2904 return orig;
2905 }
2907 }
2908 inner.parent = frame;
2909 inner.name = start;
2911 prefix,
2912 &inner);
2913 if ((erased_pos) && ('}' != erased_char))
2914 {
2915 len = strlen (prefix) + 1;
2916 prefix = GNUNET_realloc (prefix, len + 1);
2917 prefix[len - 1] = erased_char;
2918 prefix[len] = '\0';
2919 }
2920 *skip = strlen (prefix);
2921 result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1);
2922 strcpy (result, prefix);
2923 strcat (result, post);
2924 GNUNET_free (def);
2926 GNUNET_free (orig);
2927 return result;
2928}
2929
2930
2939static char *
2941 char *orig,
2942 const struct ExpansionFrame *frame)
2943{
2944 char *dup;
2945 size_t i;
2946 size_t len;
2947 size_t skip;
2948
2949 i = 0;
2950 while ('\0' != orig[i])
2951 {
2952 if ('$' != orig[i])
2953 {
2954 i++;
2955 continue;
2956 }
2957 dup = GNUNET_strdup (orig + i);
2958 dup = expand_dollar (cfg, dup, 0, frame, &skip);
2959 GNUNET_assert (NULL != dup); /* make compiler happy */
2960 len = strlen (dup) + 1;
2961 orig = GNUNET_realloc (orig, i + len);
2962 GNUNET_memcpy (orig + i, dup, len);
2963 GNUNET_free (dup);
2964 /* The expansion is final; continue right after it, which may well be
2965 the end of the string or another '$' if it expanded to "". */
2966 i += skip;
2967 }
2968 return orig;
2969}
2970
2971
2972char *
2974 const struct GNUNET_CONFIGURATION_Handle *cfg,
2975 char *orig)
2976{
2977 return expand_all (cfg,
2978 orig,
2979 NULL);
2980}
2981
2982
2985 const struct GNUNET_CONFIGURATION_Handle *cfg,
2986 const char *section,
2987 const char *option,
2988 char **value)
2989{
2990 char *tmp;
2992
2994 section,
2995 option,
2996 &tmp);
2997 if (GNUNET_OK != ret)
2998 {
3000 "Failed to retrieve filename\n");
3001 *value = NULL;
3002 return ret;
3003 }
3005 tmp);
3007 GNUNET_free (tmp);
3008 if (*value == NULL)
3009 return GNUNET_SYSERR;
3010 return GNUNET_OK;
3011}
3012
3013
3016 const struct GNUNET_CONFIGURATION_Handle *cfg,
3017 const char *section,
3018 const char *option)
3019{
3020 static const char *yesno[] = {
3021 "YES",
3022 "NO",
3023 NULL
3024 };
3025 const char *val;
3027
3028 ret =
3030 section,
3031 option,
3032 yesno,
3033 &val);
3034 if (GNUNET_OK != ret)
3035 return ret;
3036 if (val == yesno[0])
3037 return GNUNET_YES;
3038 return GNUNET_NO;
3039}
3040
3041
3042int
3044 const struct GNUNET_CONFIGURATION_Handle *cfg,
3045 const char *section,
3046 const char *option,
3048 void *cb_cls)
3049{
3050 char *list;
3051 char *pos;
3052 char *end;
3053 char old;
3054 int ret;
3055
3056 if (GNUNET_OK !=
3058 section,
3059 option,
3060 &list))
3061 return 0;
3062 GNUNET_assert (list != NULL);
3063 ret = 0;
3064 pos = list;
3065 while (1)
3066 {
3067 while (pos[0] == ' ')
3068 pos++;
3069 if (strlen (pos) == 0)
3070 break;
3071 end = pos + 1;
3072 while ((end[0] != ' ') && (end[0] != '\0'))
3073 {
3074 if (end[0] == '\\')
3075 {
3076 switch (end[1])
3077 {
3078 case '\\':
3079 case ' ':
3080 memmove (end, &end[1], strlen (&end[1]) + 1);
3081
3082 case '\0':
3083 /* illegal, but just keep it */
3084 break;
3085
3086 default:
3087 /* illegal, but just ignore that there was a '/' */
3088 break;
3089 }
3090 }
3091 end++;
3092 }
3093 old = end[0];
3094 end[0] = '\0';
3095 if (strlen (pos) > 0)
3096 {
3097 ret++;
3098 if ( (NULL != cb) &&
3099 (GNUNET_OK != cb (cb_cls,
3100 pos)))
3101 {
3103 break;
3104 }
3105 }
3106 if (old == '\0')
3107 break;
3108 pos = end + 1;
3109 }
3110 GNUNET_free (list);
3111 return ret;
3112}
3113
3114
3121static char *
3122escape_name (const char *value)
3123{
3124 char *escaped;
3125 const char *rpos;
3126 char *wpos;
3127
3128 escaped = GNUNET_malloc (strlen (value) * 2 + 1);
3129 memset (escaped, 0, strlen (value) * 2 + 1);
3130 rpos = value;
3131 wpos = escaped;
3132 while (rpos[0] != '\0')
3133 {
3134 switch (rpos[0])
3135 {
3136 case '\\':
3137 case ' ':
3138 wpos[0] = '\\';
3139 wpos[1] = rpos[0];
3140 wpos += 2;
3141 break;
3142
3143 default:
3144 wpos[0] = rpos[0];
3145 wpos++;
3146 }
3147 rpos++;
3148 }
3149 return escaped;
3150}
3151
3152
3160static enum GNUNET_GenericReturnValue
3161test_match (void *cls,
3162 const char *fn)
3163{
3164 const char *of = cls;
3165
3166 return (0 == strcmp (of, fn))
3168 : GNUNET_OK;
3169}
3170
3171
3175 const char *section,
3176 const char *option,
3177 const char *value)
3178{
3179 char *escaped;
3180 char *old;
3181 char *nw;
3182
3183 if (GNUNET_SYSERR ==
3185 section,
3186 option,
3187 &test_match,
3188 (void *) value))
3189 return GNUNET_NO; /* already exists */
3190 if (GNUNET_OK !=
3191 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old))
3192 old = GNUNET_strdup ("");
3193 escaped = escape_name (value);
3194 nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2);
3195 strcpy (nw, old);
3196 if (strlen (old) > 0)
3197 strcat (nw, " ");
3198 strcat (nw, escaped);
3200 section,
3201 option,
3202 nw);
3203 GNUNET_free (old);
3204 GNUNET_free (nw);
3205 GNUNET_free (escaped);
3206 return GNUNET_OK;
3207}
3208
3209
3213 const char *section,
3214 const char *option,
3215 const char *value)
3216{
3217 char *list;
3218 char *pos;
3219 char *end;
3220 char *match;
3221 char old;
3222
3223 if (GNUNET_OK !=
3225 section,
3226 option,
3227 &list))
3228 return GNUNET_NO;
3229 match = escape_name (value);
3230 pos = list;
3231 while (1)
3232 {
3233 while (pos[0] == ' ')
3234 pos++;
3235 if (strlen (pos) == 0)
3236 break;
3237 end = pos + 1;
3238 while ((end[0] != ' ') && (end[0] != '\0'))
3239 {
3240 if (end[0] == '\\')
3241 {
3242 switch (end[1])
3243 {
3244 case '\\':
3245 case ' ':
3246 end++;
3247 break;
3248
3249 case '\0':
3250 /* illegal, but just keep it */
3251 break;
3252
3253 default:
3254 /* illegal, but just ignore that there was a '/' */
3255 break;
3256 }
3257 }
3258 end++;
3259 }
3260 old = end[0];
3261 end[0] = '\0';
3262 if (0 == strcmp (pos, match))
3263 {
3264 if (old != '\0')
3265 memmove (pos,
3266 &end[1],
3267 strlen (&end[1]) + 1);
3268 else
3269 {
3270 if (pos != list)
3271 pos[-1] = '\0';
3272 else
3273 pos[0] = '\0';
3274 }
3276 section,
3277 option,
3278 list);
3279 GNUNET_free (list);
3280 GNUNET_free (match);
3281 return GNUNET_OK;
3282 }
3283 if (old == '\0')
3284 break;
3285 end[0] = old;
3286 pos = end + 1;
3287 }
3288 GNUNET_free (list);
3289 GNUNET_free (match);
3290 return GNUNET_NO;
3291}
3292
3293
3297 const char *defaults_d)
3298{
3299 struct CollectFilesContext files_context = {
3300 .files = NULL,
3301 .files_length = 0,
3302 };
3303 enum GNUNET_GenericReturnValue fun_ret = GNUNET_NO;
3304
3305 if (GNUNET_SYSERR ==
3306 GNUNET_DISK_directory_scan (defaults_d,
3308 &files_context))
3309 return GNUNET_SYSERR; /* no configuration at all found */
3310 qsort (files_context.files,
3311 files_context.files_length,
3312 sizeof (char *),
3313 &pstrcmp);
3314 for (unsigned int i = 0; i < files_context.files_length; i++)
3315 {
3316 const char *ext;
3317 const char *filename = files_context.files[i];
3318
3319 /* Examine file extension */
3320 ext = strrchr (filename, '.');
3321 if ( (NULL == ext) ||
3322 (0 != strcmp (ext,
3323 ".conf")) )
3324 {
3326 "Skipping file `%s'\n",
3327 filename);
3328 fun_ret = GNUNET_OK;
3329 continue;
3330 }
3332 filename);
3333 if (fun_ret != GNUNET_OK)
3334 break;
3335 }
3336 if (files_context.files_length > 0)
3337 {
3338 for (size_t i = 0; i < files_context.files_length; i++)
3339 GNUNET_free (files_context.files[i]);
3340 GNUNET_array_grow (files_context.files,
3341 files_context.files_length,
3342 0);
3343 }
3344 return fun_ret;
3345}
3346
3347
3348char *
3350 const struct GNUNET_OS_ProjectData *pd)
3351{
3352 char *cfg_fn;
3353 const char *xdg = getenv ("XDG_CONFIG_HOME");
3354
3355 if (NULL != xdg)
3356 GNUNET_asprintf (&cfg_fn,
3357 "%s%s%s",
3358 xdg,
3360 pd->config_file);
3361 else
3362 cfg_fn = GNUNET_strdup (pd->user_config_file);
3363
3364 if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn))
3365 return cfg_fn;
3366 GNUNET_free (cfg_fn);
3367
3368 /* Fall back to /etc/ for the default configuration.
3369 Should be okay to use forward slashes here. */
3370
3371 GNUNET_asprintf (&cfg_fn,
3372 "/etc/%s",
3373 pd->config_file);
3374 if (GNUNET_OK ==
3376 return cfg_fn;
3377 GNUNET_free (cfg_fn);
3378
3379 GNUNET_asprintf (&cfg_fn,
3380 "/etc/%s/%s",
3381 pd->project_dirname,
3382 pd->config_file);
3383 if (GNUNET_OK ==
3385 return cfg_fn;
3386
3387 GNUNET_free (cfg_fn);
3388 return NULL;
3389}
3390
3391
3395 const char *filename)
3396{
3397 char *baseconfig;
3398 const char *base_config_varname;
3399
3400 if (cfg->load_called)
3401 {
3402 /* FIXME: Make this a GNUNET_assert later */
3403 GNUNET_break (0);
3405 }
3406 cfg->load_called = true;
3407 if (NULL != filename)
3408 {
3411 }
3412
3413 base_config_varname = cfg->pd->base_config_varname;
3414
3415 if ((NULL != base_config_varname)
3416 && (NULL != (baseconfig = getenv (base_config_varname))))
3417 {
3418 baseconfig = GNUNET_strdup (baseconfig);
3419 }
3420 else
3421 {
3422 char *ipath;
3423
3426 if (NULL == ipath)
3427 {
3428 GNUNET_break (0);
3429 return GNUNET_SYSERR;
3430 }
3431 GNUNET_asprintf (&baseconfig,
3432 "%s%s",
3433 ipath,
3434 "config.d");
3435 GNUNET_free (ipath);
3436 }
3437
3438 {
3439 char *dname = GNUNET_STRINGS_filename_expand (baseconfig);
3440
3441 GNUNET_free (baseconfig);
3442
3443 if ((GNUNET_YES ==
3445 GNUNET_YES)) &&
3446 (GNUNET_SYSERR ==
3448 dname)))
3449 {
3451 "Failed to load base configuration from '%s'\n",
3452 filename);
3453 GNUNET_free (dname);
3454 return GNUNET_SYSERR; /* no configuration at all found */
3455 }
3456 GNUNET_free (dname);
3457 }
3458 if ((NULL != filename) &&
3459 (GNUNET_OK !=
3461 filename)))
3462 {
3463 /* specified configuration not found */
3465 "Failed to load configuration from file '%s'\n",
3466 filename);
3467 return GNUNET_SYSERR;
3468 }
3469 if (((GNUNET_YES !=
3471 "PATHS",
3472 "DEFAULTCONFIG"))) &&
3473 (filename != NULL))
3475 "PATHS",
3476 "DEFAULTCONFIG",
3477 filename);
3478 return GNUNET_OK;
3479}
3480
3481
3490static void
3492 const char *section,
3493 const char *option,
3494 const char *value)
3495{
3496 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
3497
3498 char *value_fn;
3499 char *fn;
3500
3503 section,
3504 option,
3505 &value_fn));
3506 fn = GNUNET_STRINGS_filename_expand (value_fn);
3507 if (NULL == fn)
3508 fn = value_fn;
3509 else
3510 GNUNET_free (value_fn);
3511 fprintf (stdout,
3512 "%s = %s\n",
3513 option,
3514 fn);
3515 GNUNET_free (fn);
3516}
3517
3518
3527static void
3528print_option (void *cls,
3529 const char *section,
3530 const char *option,
3531 const char *value)
3532{
3533 (void) cls;
3534 (void) section;
3535
3536 fprintf (stdout,
3537 "%s = %s\n",
3538 option,
3539 value);
3540}
3541
3542
3549static void
3551 const char *section)
3552{
3553 (void) cls;
3554 fprintf (stdout,
3555 "%s\n",
3556 section);
3557}
3558
3559
3560void
3562 void *cls,
3563 char *const *args,
3564 const char *cfgfile,
3565 const struct GNUNET_CONFIGURATION_Handle *cfg)
3566{
3567 struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls;
3568 struct GNUNET_CONFIGURATION_Handle *out = NULL;
3569 struct GNUNET_CONFIGURATION_Handle *ncfg = NULL;
3570
3571 (void) args;
3572 if (cs->diagnostics &&
3573 (! cfg->diagnostics))
3574 {
3575 /* Re-parse the configuration with diagnostics enabled. */
3578 if (GNUNET_OK !=
3580 cfgfile))
3581 {
3582 fprintf (stderr,
3583 _ ("Failed to load config file `%s'"),
3584 cfgfile);
3585 return;
3586 }
3587 cfg = ncfg;
3588 }
3589
3590 if (cs->full)
3591 cs->rewrite = GNUNET_YES;
3592 if (cs->list_sections)
3593 {
3594 fprintf (stderr,
3595 _ ("The following sections are available:\n"));
3598 NULL);
3599 return;
3600 }
3601 if ( (! cs->rewrite) &&
3602 (NULL == cs->section) )
3603 {
3604 char *serialization;
3605
3606 if (! cs->diagnostics)
3607 {
3608 fprintf (stderr,
3609 _ ("%s, %s or %s argument is required\n"),
3610 "--section",
3611 "--list-sections",
3612 "--diagnostics");
3614 return;
3615 }
3616 serialization = (cs->diagnostics > 1)
3619 fprintf (stdout,
3620 "%s",
3621 serialization);
3622 GNUNET_free (serialization);
3623 }
3624 else if ( (NULL != cs->section) &&
3625 (NULL == cs->value) )
3626 {
3627 if (NULL == cs->option)
3628 {
3630 cfg,
3631 cs->section,
3632 cs->is_filename
3634 : &print_option,
3635 (void *) cfg);
3636 }
3637 else
3638 {
3639 char *value;
3640
3641 if (cs->is_filename)
3642 {
3643 if (GNUNET_OK !=
3645 cs->section,
3646 cs->option,
3647 &value))
3648 {
3650 cs->section,
3651 cs->option);
3653 return;
3654 }
3655 }
3656 else
3657 {
3658 if (GNUNET_OK !=
3660 cs->section,
3661 cs->option,
3662 &value))
3663 {
3665 cs->section,
3666 cs->option);
3668 return;
3669 }
3670 }
3671 fprintf (stdout,
3672 "%s\n",
3673 value);
3675 }
3676 }
3677 else if (NULL != cs->section)
3678 {
3679 if (NULL == cs->option)
3680 {
3681 fprintf (stderr,
3682 _ ("--option argument required to set value\n"));
3684 return;
3685 }
3688 cs->section,
3689 cs->option,
3690 cs->value);
3691 cs->rewrite = GNUNET_YES;
3692 }
3693 if (cs->rewrite)
3694 {
3695 char *cfg_fn = NULL;
3696
3697 if (NULL == out)
3699
3700 if (NULL == cfgfile)
3701 {
3702 const char *xdg = getenv ("XDG_CONFIG_HOME");
3703
3704 if (NULL != xdg)
3705 GNUNET_asprintf (&cfg_fn,
3706 "%s%s%s",
3707 xdg,
3709 cfg->pd->config_file);
3710 else
3711 cfg_fn = GNUNET_strdup (cfg->pd->user_config_file);
3712 cfgfile = cfg_fn;
3713 }
3714
3715 if (! cs->full)
3716 {
3717 struct GNUNET_CONFIGURATION_Handle *def;
3718
3720 if (GNUNET_OK !=
3722 NULL))
3723 {
3724 fprintf (stderr,
3725 _ ("failed to load configuration defaults"));
3726 cs->global_ret = 1;
3729 GNUNET_free (cfg_fn);
3730 return;
3731 }
3732 if (GNUNET_OK !=
3734 out,
3735 cfgfile))
3736 cs->global_ret = 2;
3738 }
3739 else
3740 {
3741 if (GNUNET_OK !=
3743 cfgfile))
3744 cs->global_ret = 2;
3745 }
3746 GNUNET_free (cfg_fn);
3747 }
3748 if (NULL != out)
3750 if (NULL != ncfg)
3752}
3753
3754
3755void
3763
3764
3765const struct GNUNET_OS_ProjectData *
3767 const struct GNUNET_CONFIGURATION_Handle *cfg)
3768{
3769 return cfg->pd;
3770}
3771
3772
3773char *
3775 pd,
3776 const struct
3778 const char *progname)
3779{
3780 static char *cache;
3781 char *binary = NULL;
3782 char *path = NULL;
3783 size_t path_len;
3784
3785 if (GNUNET_YES ==
3787 GNUNET_NO,
3788 NULL,
3789 NULL))
3790 {
3791 return GNUNET_strdup (progname);
3792 }
3793 if (NULL != cache)
3794 path = cache;
3795 else
3797 "PATHS",
3798 "SUID_BINARY_PATH",
3799 &path);
3800 if ( (NULL == path) ||
3801 (0 == strlen (path)) )
3802 {
3803 if (NULL != path)
3804 GNUNET_free (path);
3805 cache = NULL;
3807 progname);
3808 }
3809 path_len = strlen (path);
3810 GNUNET_asprintf (&binary,
3811 "%s%s%s",
3812 path,
3813 (path[path_len - 1] == DIR_SEPARATOR) ? ""
3815 progname);
3816 cache = path;
3817 return binary;
3818}
3819
3820
3821/* end of configuration.c */
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static bool do_skip(const char *sec, const char *key)
Should we skip this configuration entry when serializing?
static void print_filename_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section as a filename.
static char * expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig, unsigned int depth, const struct ExpansionFrame *frame, size_t *skip)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
static bool source_is_removed(const struct ConfigSource *source, const char *target, struct CleanLine *lines, unsigned int lines_length)
Return whether a source is a target line currently marked for removal.
static struct CleanLine * find_clean_line(struct CleanLine *lines, unsigned int lines_length, unsigned int line)
Find a cleanup record for a physical line.
static int clean_line_cmp(const void *a, const void *b)
Sort cleanup records by source line.
static struct ConfigEntry * find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *key)
Find an entry from a configuration.
static enum GNUNET_GenericReturnValue handle_inline(struct GNUNET_CONFIGURATION_Handle *cfg, const char *path_or_glob, bool path_is_glob, const char *restrict_section, const char *source_filename, unsigned int source_lineno)
Handle an inline directive.
static void print_section_name(void *cls, const char *section)
Print out given section name.
static enum GNUNET_GenericReturnValue read_file(const char *filename, char **contents, size_t *size)
static char * escape_name(const char *value)
FIXME.
static void compare_entries(void *cls, const char *section, const char *option, const char *value)
A callback function, compares entries from two configurations (default against a new configuration) a...
static void add_entry_source(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value, const char *filename, unsigned int line)
Record the source of a configuration value.
static char * serialize_diagnostics(const struct GNUNET_CONFIGURATION_Handle *cfg, bool verbose)
Serialize configuration diagnostics.
static enum GNUNET_GenericReturnValue test_match(void *cls, const char *fn)
FIXME.
static char * expand_all(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig, const struct ExpansionFrame *frame)
$-expand all terms in a string.
static struct ConfigSection * find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Find a section entry from a configuration.
static enum GNUNET_GenericReturnValue write_buffer_atomic(const char *filename, const char *contents, size_t size, const struct GNUNET_HashCode *expected_hash)
Atomically replace a file with the given bytes.
static void copy_entry_with_sources(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const struct ConfigEntry *entry)
Copy an entry parsed through an @inline-secret@ directive, including all diagnostic source informatio...
static int pstrcmp(const void *a, const void *b)
static enum GNUNET_GenericReturnValue collect_files_cb(void *cls, const char *filename)
Function called with a filename.
#define LOG(kind,...)
static bool file_hash_matches(const char *filename, const struct GNUNET_HashCode *expected)
Check that a file still has the expected contents.
static void copy_entry(void *cls, const char *section, const char *option, const char *value)
Copy a configuration value to the given target configuration.
static void print_option(void *cls, const char *section, const char *option, const char *value)
Print each option in a given section.
static void dump_os_ipk(const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_Buffer *buf, enum GNUNET_OS_InstallationPathKind ipk)
Dump an os installation path to a buffer.
char * getenv()
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
static int start
Set if we are to start default services (including ARM).
Definition gnunet-arm.c:38
static int list
Set if we should print a list of currently running services.
Definition gnunet-arm.c:68
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static int end
Set if we are to shutdown all services (including ARM).
Definition gnunet-arm.c:33
static int prefix
If printing the value of PREFIX has been requested.
static char * line
Desired phone line (string to be converted to a hash).
static unsigned int verbose
Be verbose.
struct GNUNET_HashCode key
The key used in the DHT.
static char * filename
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition gnunet-fs.c:35
static GstElement * source
Appsrc instance into which we write data for the pipeline.
static OpusEncoder * enc
OPUS encoder.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static char * res
Currently read line or NULL on EOF.
static char * value
Value of the record to add/remove.
static size_t data_size
Number of bytes in data.
static int status
The program status; 0 for success.
Definition gnunet-nse.c:39
static int result
Global testing status.
static void cleanup()
Cleanup task.
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
Configuration API.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
Get Crockford32-encoded fixed-size binary data from a configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_is_dirty(const struct GNUNET_CONFIGURATION_Handle *cfg)
Test if there are configuration options that were changed since the last save.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_append_value_filename(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Append a filename to a configuration value that represents a list of filenames.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
void GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section)
Remove the given section and all options in it.
enum GNUNET_GenericReturnValue(* GNUNET_CONFIGURATION_Callback)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Signature of a function to be run with a configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
char * GNUNET_CONFIGURATION_get_suid_binary_path(const struct GNUNET_OS_ProjectData *pd, const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
Given the name of a helper, service or daemon binary construct the full path to the binary using the ...
void GNUNET_CONFIGURATION_config_settings_free(struct GNUNET_CONFIGURATION_ConfigSettings *cs)
Free resources associated with cs.
void GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over all options in the configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_remove_value_filename(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Remove a filename from a configuration value that represents a list of filenames.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run(const struct GNUNET_OS_ProjectData *pd, const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls)
Parse a configuration file filename and run the function cb with the resulting configuration object.
void GNUNET_CONFIGURATION_config_tool_run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main task to run to perform operations typical for gnunet-config as per the configuration settings gi...
void(* GNUNET_CONFIGURATION_SectionIterator)(void *cls, const char *section)
Function to iterate over all configuration sections.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *size)
Get a configuration value that should be a size in bytes.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
char * GNUNET_CONFIGURATION_default_filename(const struct GNUNET_OS_ProjectData *pd)
Return the filename of the default configuration filename that is used when no explicit configuration...
char * GNUNET_CONFIGURATION_expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
void GNUNET_CONFIGURATION_set_value_float(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float number)
Set a configuration value that should be a float.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_clean_file(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename, GNUNET_CONFIGURATION_CleanCallback cb, void *cb_cls, unsigned int *removed)
Remove redundant option definitions from a parsed configuration file.
const struct GNUNET_OS_ProjectData * GNUNET_CONFIGURATION_get_project_data(const struct GNUNET_CONFIGURATION_Handle *cfg)
Return the project data associated with this configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_get_diff(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new)
Compute configuration with only entries that have been changed.
char * GNUNET_CONFIGURATION_serialize_diagnostics_verbose(const struct GNUNET_CONFIGURATION_Handle *cfg)
Serializes the given configuration with verbose diagnostics information, including all source definit...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, float *number)
Get a configuration value that should be a floating point number.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d)
Load default configuration.
int GNUNET_CONFIGURATION_iterate_value_filenames(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, GNUNET_FileNameCallback cb, void *cb_cls)
Iterate over the set of filenames stored in a configuration value.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *const *choices, const char **value)
Get a configuration value that should be in a set of predefined strings.
void(* GNUNET_CONFIGURATION_CleanCallback)(void *cls, const char *section, const char *option, unsigned int line)
Function called for each duplicate definition removed by GNUNET_CONFIGURATION_clean_file().
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
void(* GNUNET_CONFIGURATION_Iterator)(void *cls, const char *section, const char *option, const char *value)
Function to iterate over options.
void GNUNET_CONFIGURATION_iterate_section_values(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over values of a section in the configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write_diffs(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new, const char *filename)
Write only configuration entries that have been changed to configuration file.
char * GNUNET_CONFIGURATION_serialize_diagnostics(const struct GNUNET_CONFIGURATION_Handle *cfg)
Serializes the given configuration with diagnostics information.
void GNUNET_CONFIGURATION_enable_diagnostics(struct GNUNET_CONFIGURATION_Handle *cfg)
Enable extra diagnostics.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition disk.c:1307
int GNUNET_DISK_glob(const char *glob_pattern, GNUNET_FileNameCallback callback, void *callback_cls)
Find all files matching a glob pattern.
Definition disk.c:1062
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition disk.c:745
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test_read(const char *fil)
Check that fil corresponds to a filename and the file has read permissions.
Definition disk.c:565
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition disk.c:235
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition disk.c:1506
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition disk.c:466
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition disk.c:1385
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition disk.c:664
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition disk.c:720
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition disk.c:881
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#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.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
enum GNUNET_GenericReturnValue(* GNUNET_FileNameCallback)(void *cls, const char *filename)
Function called with a filename.
#define GNUNET_log(kind,...)
char * GNUNET_buffer_reap_str(struct GNUNET_Buffer *buf)
Clear the buffer and return the string it contained.
Definition buffer.c:89
void GNUNET_buffer_write_fstr(struct GNUNET_Buffer *buf, const char *fmt,...) __attribute__((format(printf
Write a 0-terminated formatted string to a buffer, excluding the 0-terminator.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
void GNUNET_buffer_write_str(struct GNUNET_Buffer *buf, const char *str)
Write a 0-terminated string to a buffer, excluding the 0-terminator.
Definition buffer.c:77
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ 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.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
GNUNET_OS_InstallationPathKind
Possible installation paths to request.
char * GNUNET_OS_get_libexec_binary_path(const struct GNUNET_OS_ProjectData *pd, const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
@ GNUNET_OS_IPK_SELF_PREFIX
Return the installation directory of this application, not the one of the overall GNUnet installation...
@ GNUNET_OS_IPK_ICONDIR
Return the prefix of the path with application icons (share/icons/).
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
@ GNUNET_OS_IPK_DOCDIR
Return the prefix of the path with documentation files, including the license (share/doc/gnunet/).
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
@ GNUNET_OS_IPK_LIBDIR
Return the directory where libraries are installed.
@ GNUNET_OS_IPK_PREFIX
Return the "PREFIX" directory given to configure.
@ GNUNET_OS_IPK_BINDIR
Return the directory where the program binaries are installed.
@ GNUNET_OS_IPK_LIBEXECDIR
Return the directory where helper binaries are installed (lib/gnunet/libexec/)
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
Definition strings.c:531
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition strings.c:843
enum GNUNET_GenericReturnValue GNUNET_STRINGS_path_is_absolute(const char *filename, int can_be_uri, int *r_is_uri, char **r_uri_scheme)
Check whether filename is absolute or not, and if it's an URI.
Definition strings.c:1012
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:259
enum GNUNET_GenericReturnValue GNUNET_STRINGS_fancy_size_to_bytes(const char *fancy_size, unsigned long long *size)
Convert a given fancy human-readable size to bytes.
Definition strings.c:235
static unsigned int size
Size of the "table".
Definition peer.c:68
#define DIR_SEPARATOR
Definition platform.h:166
#define DIR_SEPARATOR_STR
Definition platform.h:167
#define _(String)
GNU gettext support macro.
Definition platform.h:179
#define SIZE_MAX
Definition platform.h:213
#define EXIT_INVALIDARGUMENT
Definition platform.h:258
#define EXIT_NOTCONFIGURED
Definition platform.h:274
uint32_t number
One physical assignment line considered for removal.
const char * option
unsigned int line
const char * section
Closure to collect_files_cb.
char ** files
Collected files from globbing.
unsigned int files_length
Size of the files array.
configuration entry
struct ConfigEntry * next
This is a linked list.
char * key
key for this entry
struct ConfigSource * sources
Source definitions retained for diagnostics.
char * val
current, committed value
char * hint_restrict_section
Was this configuration file parsed via @inline-secret@?
struct ConfigFile * next
char * source_filename
Source filename.
bool hint_inaccessible
Was this configuration file inaccessible?
struct ConfigFile * prev
bool have_content_hash
Whether content_hash is available.
unsigned int level
Level in the tree of loaded config files.
struct GNUNET_HashCode content_hash
Hash of the file contents seen while parsing.
configuration section
char * name
name of the section
char * hint_inlined_from_filename
For secret sections: Where was this inlined from?
struct ConfigEntry * entries
entries in the section
bool inaccessible
Is the configuration section marked as inaccessible?
struct ConfigSection * next
This is a linked list.
char * hint_secret_filename
Diagnostics hint for the secret file.
unsigned int hint_inlined_from_line
For secret sections: Where was this inlined from?
char * hint_secret_stat
Extra information regarding permissions of the secret file.
source location of a configuration value
char * value
Value as normalized by the configuration parser.
unsigned int lineno
Line containing the definition.
char * filename
Filename containing the definition.
struct ConfigSource * next
Sources are ordered from highest to lowest precedence.
Used for diffing a configuration object against the default one.
const struct GNUNET_CONFIGURATION_Handle * cfg_default
struct GNUNET_CONFIGURATION_Handle * cfgDiff
A [PATHS] option or environment variable whose value is being $-expanded, used to detect definitions ...
const struct ExpansionFrame * parent
The expansion this one is part of, or NULL.
const char * name
Name of the variable whose value is being expanded.
Dynamically growing buffer.
Closure for GNUNET_CONFIGURATION_config_tool_run() with settings for what should be done with the con...
int full
Should the generated configuration file contain the whole configuration?
int global_ret
Return value from the operation, to be returned from 'main'.
int list_sections
Whether to show the sections.
int rewrite
Should we write out the configuration file, even if no value was changed?
int is_filename
Treat option as a filename.
unsigned int diagnostics
Diagnostics verbosity.
struct ConfigFile * loaded_files_tail
Linked list of loaded files.
bool load_called
Was the configuration ever loaded via GNUNET_CONFIGURATION_load?
unsigned int current_nest_level
Current nesting level of file loading.
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.
struct ConfigSection * sections
Configuration sections.
struct ConfigFile * loaded_files_head
Linked list of loaded files.
char * main_filename
Name of the entry point configuration file.
enum GNUNET_GenericReturnValue dirty
Modification indication since last save GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on err...
bool diagnostics
Enable diagnostics.
const char * restrict_section
When parsing into this configuration, and this value is non-NULL, only parse sections of the same nam...
Handle used to access files (and pipes).
A 512-bit hashcode.
Project-specific data used to help the OS subsystem find installation paths.
const char * base_config_varname
Name of an environment variable that can be used to override the location from which default configur...
const char * project_dirname
Name of the project that is used in the "libexec" prefix, For example, "gnunet".
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
Time for relative time used by GNUnet, in microseconds.