From 981cc68a63c71ba11aaca84f559f3cf86a29c0ec Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 25 Jun 2017 19:36:44 +0200 Subject: [PATCH] fix configuration parsing issue with inlines from configuration not in cwd --- src/datacache/datacache.c | 6 +++--- src/include/gnunet_configuration_lib.h | 6 +++--- src/nat-auto/gnunet-service-nat-auto.c | 2 +- src/nat-auto/nat_auto_api.c | 2 +- src/set/gnunet-service-set_union.c | 4 ---- src/testbed/gnunet-helper-testbed.c | 5 ++++- src/testbed/testbed_api.c | 5 +++-- src/testbed/testbed_api_hosts.c | 5 ++++- src/util/configuration.c | 29 ++++++++++++++++++++------ 9 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c index a1869a8bd..92cc40b53 100644 --- a/src/datacache/datacache.c +++ b/src/datacache/datacache.c @@ -185,9 +185,9 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg, } if (NULL == ret->filter) { - ret->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, - bf_size, - 5); /* approx. 3% false positives at max use */ + ret->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, + bf_size, + 5); /* approx. 3% false positives at max use */ } } ret->stats = GNUNET_STATISTICS_create ("datacache", cfg); diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index c1537e4f8..8a874da13 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h @@ -132,8 +132,8 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, * @param cfg configuration to update * @param mem the memory block of serialized configuration * @param size the size of the memory block - * @param allow_inline set to #GNUNET_YES if we recursively load configuration - * from inlined configurations; #GNUNET_NO if not and raise warnings + * @param allow_inline set to the base directory if we recursively load configuration + * from inlined configurations; NULL if not and raise warnings * when we come across them * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ @@ -141,7 +141,7 @@ int GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, - int allow_inline); + const char *basedir); /** diff --git a/src/nat-auto/gnunet-service-nat-auto.c b/src/nat-auto/gnunet-service-nat-auto.c index ae570c351..5f10dad94 100644 --- a/src/nat-auto/gnunet-service-nat-auto.c +++ b/src/nat-auto/gnunet-service-nat-auto.c @@ -310,7 +310,7 @@ handle_autoconfig_request (void *cls, GNUNET_CONFIGURATION_deserialize (ac->c, (const char *) &message[1], left, - GNUNET_NO)) + NULL)) { GNUNET_break (0); GNUNET_SERVICE_client_drop (ch->client); diff --git a/src/nat-auto/nat_auto_api.c b/src/nat-auto/nat_auto_api.c index 8a7eaf264..43a5212c8 100644 --- a/src/nat-auto/nat_auto_api.c +++ b/src/nat-auto/nat_auto_api.c @@ -155,7 +155,7 @@ handle_auto_result (void *cls, GNUNET_CONFIGURATION_deserialize (cfg, (const char *) &res[1], left, - GNUNET_NO)) + NULL)) { GNUNET_break (0); ah->arc (ah->arc_cls, diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 4ca10f0b4..b2983545f 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c @@ -1467,8 +1467,6 @@ maybe_finish (struct Operation *op) num_demanded); if (0 == num_demanded) { - struct GNUNET_MQ_Envelope *ev; - op->state->phase = PHASE_DONE; send_client_done (op); destroy_channel (op); @@ -1894,8 +1892,6 @@ handle_union_p2p_full_done (void *cls, break; case PHASE_FULL_SENDING: { - struct GNUNET_MQ_Envelope *ev; - LOG (GNUNET_ERROR_TYPE_DEBUG, "got FULL DONE, finishing\n"); /* We sent the full set, and got the response for that. We're done. */ diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c index d2a3a98b7..392f257dd 100644 --- a/src/testbed/gnunet-helper-testbed.c +++ b/src/testbed/gnunet-helper-testbed.c @@ -358,7 +358,10 @@ tokenizer_cb (void *cls, } cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != - GNUNET_CONFIGURATION_deserialize (cfg, config, ul_config_size, GNUNET_NO)) + GNUNET_CONFIGURATION_deserialize (cfg, + config, + ul_config_size, + NULL)) { LOG (GNUNET_ERROR_TYPE_WARNING, "Unable to deserialize config -- exiting\n"); diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 0e0a5da9c..1acd0e47c 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c @@ -2158,9 +2158,10 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg) } cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != - GNUNET_CONFIGURATION_deserialize (cfg, (const char *) data, + GNUNET_CONFIGURATION_deserialize (cfg, + (const char *) data, (size_t) data_len, - GNUNET_NO)) + NULL)) { GNUNET_free (data); GNUNET_break_op (0); /* De-serialization failure */ diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 5d2c1cc37..8efcab649 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c @@ -983,7 +983,10 @@ helper_mst (void *cls, GNUNET_CONFIGURATION_destroy (cp->host->cfg); cp->host->cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_CONFIGURATION_deserialize - (cp->host->cfg, config, config_size, GNUNET_NO)); + (cp->host->cfg, + config, + config_size, + NULL)); GNUNET_free (config); if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))) hostname = "localhost"; diff --git a/src/util/configuration.c b/src/util/configuration.c index 639bd55a2..f63903b4e 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -145,8 +145,8 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) * @param cfg configuration to update * @param mem the memory block of serialized configuration * @param size the size of the memory block - * @param allow_inline set to #GNUNET_YES if we recursively load configuration - * from inlined configurations; #GNUNET_NO if not and raise warnings + * @param basedir set to path from which we recursively load configuration + * from inlined configurations; NULL if not and raise warnings * when we come across them * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ @@ -154,7 +154,7 @@ int GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, - int allow_inline) + const char *basedir) { char *line; char *line_orig; @@ -228,13 +228,23 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, { /* @INLINE@ value */ value = &line[strlen ("@INLINE@ ")]; - if (GNUNET_YES == allow_inline) + if (NULL != basedir) { - if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value)) + char *fn; + + GNUNET_asprintf (&fn, + "%s/%s", + basedir, + value); + if (GNUNET_OK != + GNUNET_CONFIGURATION_parse (cfg, + fn)) { + GNUNET_free (fn); ret = GNUNET_SYSERR; /* failed to parse included config */ break; } + GNUNET_free (fn); } else { @@ -311,6 +321,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, size_t fs; char *fn; char *mem; + char *endsep; int dirty; int ret; @@ -350,8 +361,14 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn); + endsep = strrchr (fn, (int) '/'); + if (NULL != endsep) + *endsep = '\0'; + ret = GNUNET_CONFIGURATION_deserialize (cfg, + mem, + fs, + fn); GNUNET_free (fn); - ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, GNUNET_YES); GNUNET_free (mem); /* restore dirty flag - anything we set in the meantime * came from disk */ -- 2.25.1