diff options
author | Florian Dold <florian@dold.me> | 2021-07-28 15:26:55 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-07-28 15:27:39 +0200 |
commit | 94ea7a1fab12d1ad81209f84087c04a5a5b790dc (patch) | |
tree | dc33d6aaefd9ec6e8b781e000569c7029bd51cf8 /src/util/configuration.c | |
parent | 7615d46b09275383bd244a0ef1d94b3a77559b88 (diff) | |
download | gnunet-94ea7a1fab12d1ad81209f84087c04a5a5b790dc.tar.gz gnunet-94ea7a1fab12d1ad81209f84087c04a5a5b790dc.zip |
implement @inline-secret@ directive
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r-- | src/util/configuration.c | 154 |
1 files changed, 127 insertions, 27 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index da9cdb924..3bb08e6c0 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -75,6 +75,14 @@ struct ConfigSection | |||
75 | * name of the section | 75 | * name of the section |
76 | */ | 76 | */ |
77 | char *name; | 77 | char *name; |
78 | |||
79 | /** | ||
80 | * Is the configuration section marked as inaccessible? | ||
81 | * | ||
82 | * This can happen if the section name is used in an @inline-secret@ | ||
83 | * directive, but the referenced file can't be found or accessed. | ||
84 | */ | ||
85 | bool inaccessible; | ||
78 | }; | 86 | }; |
79 | 87 | ||
80 | 88 | ||
@@ -263,6 +271,46 @@ inline_glob_cb (void *cls, | |||
263 | return GNUNET_OK; | 271 | return GNUNET_OK; |
264 | } | 272 | } |
265 | 273 | ||
274 | |||
275 | /** | ||
276 | * Find a section entry from a configuration. | ||
277 | * | ||
278 | * @param cfg configuration to search in | ||
279 | * @param section name of the section to look for | ||
280 | * @return matching entry, NULL if not found | ||
281 | */ | ||
282 | static struct ConfigSection * | ||
283 | find_section (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
284 | const char *section) | ||
285 | { | ||
286 | struct ConfigSection *pos; | ||
287 | |||
288 | pos = cfg->sections; | ||
289 | while ((pos != NULL) && (0 != strcasecmp (section, pos->name))) | ||
290 | pos = pos->next; | ||
291 | return pos; | ||
292 | } | ||
293 | |||
294 | static void | ||
295 | set_section_inaccessible (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
296 | const char *section) | ||
297 | { | ||
298 | struct ConfigSection *sec; | ||
299 | |||
300 | sec = find_section (cfg, section); | ||
301 | |||
302 | if (NULL == sec) | ||
303 | { | ||
304 | sec = GNUNET_new (struct ConfigSection); | ||
305 | sec->name = GNUNET_strdup (section); | ||
306 | sec->next = cfg->sections; | ||
307 | cfg->sections = sec; | ||
308 | sec->entries = NULL; | ||
309 | } | ||
310 | |||
311 | sec->inaccessible = true; | ||
312 | } | ||
313 | |||
266 | /** | 314 | /** |
267 | * Handle an inline directive. | 315 | * Handle an inline directive. |
268 | * | 316 | * |
@@ -333,6 +381,50 @@ handle_inline (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
333 | return GNUNET_SYSERR; | 381 | return GNUNET_SYSERR; |
334 | } | 382 | } |
335 | } | 383 | } |
384 | else if (NULL != restrict_section) | ||
385 | { | ||
386 | struct GNUNET_CONFIGURATION_Handle *other_cfg; | ||
387 | enum GNUNET_GenericReturnValue fret; | ||
388 | struct ConfigSection *cs; | ||
389 | |||
390 | fret = GNUNET_DISK_file_test_read (inline_path); | ||
391 | |||
392 | if (GNUNET_OK != fret) | ||
393 | { | ||
394 | set_section_inaccessible (cfg, restrict_section); | ||
395 | GNUNET_free (inline_path); | ||
396 | return GNUNET_OK; | ||
397 | } | ||
398 | |||
399 | other_cfg = GNUNET_CONFIGURATION_create (); | ||
400 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (other_cfg, | ||
401 | inline_path)) | ||
402 | { | ||
403 | GNUNET_free (inline_path); | ||
404 | GNUNET_CONFIGURATION_destroy (other_cfg); | ||
405 | return GNUNET_SYSERR; | ||
406 | } | ||
407 | |||
408 | cs = find_section (other_cfg, restrict_section); | ||
409 | if (NULL == cs) | ||
410 | { | ||
411 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
412 | "inlined configuration '%s' does not contain section '%s'\n", | ||
413 | inline_path, | ||
414 | restrict_section); | ||
415 | GNUNET_free (inline_path); | ||
416 | GNUNET_free (other_cfg); | ||
417 | return GNUNET_SYSERR; | ||
418 | } | ||
419 | for (struct ConfigEntry *ce = cs->entries; | ||
420 | NULL != ce; | ||
421 | ce = ce->next) | ||
422 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
423 | restrict_section, | ||
424 | ce->key, | ||
425 | ce->val); | ||
426 | GNUNET_CONFIGURATION_destroy (other_cfg); | ||
427 | } | ||
336 | else if (GNUNET_OK != | 428 | else if (GNUNET_OK != |
337 | GNUNET_CONFIGURATION_parse (cfg, | 429 | GNUNET_CONFIGURATION_parse (cfg, |
338 | inline_path)) | 430 | inline_path)) |
@@ -346,10 +438,10 @@ handle_inline (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
346 | 438 | ||
347 | 439 | ||
348 | enum GNUNET_GenericReturnValue | 440 | enum GNUNET_GenericReturnValue |
349 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | 441 | deserialize_internal (struct GNUNET_CONFIGURATION_Handle *cfg, |
350 | const char *mem, | 442 | const char *mem, |
351 | size_t size, | 443 | size_t size, |
352 | const char *source_filename) | 444 | const char *source_filename) |
353 | { | 445 | { |
354 | size_t line_size; | 446 | size_t line_size; |
355 | unsigned int nr; | 447 | unsigned int nr; |
@@ -469,9 +561,9 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
469 | } | 561 | } |
470 | else if (0 == strcasecmp (directive, "INLINE-SECRET")) | 562 | else if (0 == strcasecmp (directive, "INLINE-SECRET")) |
471 | { | 563 | { |
472 | const char *secname = end + 1; | 564 | char *secname = end + 1; |
565 | char *secname_end; | ||
473 | const char *path; | 566 | const char *path; |
474 | const char *secname_end; | ||
475 | 567 | ||
476 | /* Skip space before secname */ | 568 | /* Skip space before secname */ |
477 | for (; isspace (*secname); secname++) | 569 | for (; isspace (*secname); secname++) |
@@ -487,7 +579,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
487 | ret = GNUNET_SYSERR; | 579 | ret = GNUNET_SYSERR; |
488 | break; | 580 | break; |
489 | } | 581 | } |
490 | secname_end = '\0'; | 582 | *secname_end = '\0'; |
491 | path = secname_end + 1; | 583 | path = secname_end + 1; |
492 | 584 | ||
493 | /* Skip space before path */ | 585 | /* Skip space before path */ |
@@ -577,6 +669,16 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
577 | 669 | ||
578 | 670 | ||
579 | enum GNUNET_GenericReturnValue | 671 | enum GNUNET_GenericReturnValue |
672 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | ||
673 | const char *mem, | ||
674 | size_t size, | ||
675 | const char *source_filename) | ||
676 | { | ||
677 | return deserialize_internal (cfg, mem, size, source_filename); | ||
678 | } | ||
679 | |||
680 | |||
681 | enum GNUNET_GenericReturnValue | ||
580 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | 682 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, |
581 | const char *filename) | 683 | const char *filename) |
582 | { | 684 | { |
@@ -870,6 +972,14 @@ GNUNET_CONFIGURATION_iterate_section_values ( | |||
870 | spos = spos->next; | 972 | spos = spos->next; |
871 | if (NULL == spos) | 973 | if (NULL == spos) |
872 | return; | 974 | return; |
975 | if (spos->inaccessible) | ||
976 | { | ||
977 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
978 | "Section '%s' is marked as inaccessible, because the configuration " | ||
979 | " file that contains the section can't be read.\n", | ||
980 | section); | ||
981 | return; | ||
982 | } | ||
873 | for (epos = spos->entries; NULL != epos; epos = epos->next) | 983 | for (epos = spos->entries; NULL != epos; epos = epos->next) |
874 | if (NULL != epos->val) | 984 | if (NULL != epos->val) |
875 | iter (iter_cls, spos->name, epos->key, epos->val); | 985 | iter (iter_cls, spos->name, epos->key, epos->val); |
@@ -964,26 +1074,6 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
964 | 1074 | ||
965 | 1075 | ||
966 | /** | 1076 | /** |
967 | * Find a section entry from a configuration. | ||
968 | * | ||
969 | * @param cfg configuration to search in | ||
970 | * @param section name of the section to look for | ||
971 | * @return matching entry, NULL if not found | ||
972 | */ | ||
973 | static struct ConfigSection * | ||
974 | find_section (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
975 | const char *section) | ||
976 | { | ||
977 | struct ConfigSection *pos; | ||
978 | |||
979 | pos = cfg->sections; | ||
980 | while ((pos != NULL) && (0 != strcasecmp (section, pos->name))) | ||
981 | pos = pos->next; | ||
982 | return pos; | ||
983 | } | ||
984 | |||
985 | |||
986 | /** | ||
987 | * Find an entry from a configuration. | 1077 | * Find an entry from a configuration. |
988 | * | 1078 | * |
989 | * @param cfg handle to the configuration | 1079 | * @param cfg handle to the configuration |
@@ -1001,6 +1091,16 @@ find_entry (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1001 | 1091 | ||
1002 | if (NULL == (sec = find_section (cfg, section))) | 1092 | if (NULL == (sec = find_section (cfg, section))) |
1003 | return NULL; | 1093 | return NULL; |
1094 | if (sec->inaccessible) | ||
1095 | { | ||
1096 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1097 | "Section '%s' is marked as inaccessible, because the configuration " | ||
1098 | " file that contains the section can't be read. Attempts to use " | ||
1099 | "option '%s' will fail.\n", | ||
1100 | section, | ||
1101 | key); | ||
1102 | return NULL; | ||
1103 | } | ||
1004 | pos = sec->entries; | 1104 | pos = sec->entries; |
1005 | while ((pos != NULL) && (0 != strcasecmp (key, pos->key))) | 1105 | while ((pos != NULL) && (0 != strcasecmp (key, pos->key))) |
1006 | pos = pos->next; | 1106 | pos = pos->next; |