diff options
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/config.c | 11 | ||||
-rw-r--r-- | src/or/confparse.h | 1 | ||||
-rw-r--r-- | src/or/control.c | 10 | ||||
-rw-r--r-- | src/or/or.h | 3 |
4 files changed, 20 insertions, 5 deletions
diff --git a/src/or/config.c b/src/or/config.c index 09d558e1b4..a1212cfd3c 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -5056,6 +5056,7 @@ options_init_from_string(const char *cf_defaults, const char *cf, config_line_t *cl; int retval; setopt_err_t err = SETOPT_ERR_MISC; + int cf_has_include; tor_assert(msg); oldoptions = global_options; /* get_options unfortunately asserts if @@ -5072,7 +5073,8 @@ options_init_from_string(const char *cf_defaults, const char *cf, if (!body) continue; /* get config lines, assign them */ - retval = config_get_lines(body, &cl, 1); + retval = config_get_lines_include(body, &cl, 1, + body == cf ? &cf_has_include : NULL); if (retval < 0) { err = SETOPT_ERR_PARSE; goto err; @@ -5100,6 +5102,8 @@ options_init_from_string(const char *cf_defaults, const char *cf, goto err; } + newoptions->IncludeUsed = cf_has_include; + /* If this is a testing network configuration, change defaults * for a list of dependent config options, re-initialize newoptions * with the new defaults, and assign all options to it second time. */ @@ -5143,7 +5147,8 @@ options_init_from_string(const char *cf_defaults, const char *cf, if (!body) continue; /* get config lines, assign them */ - retval = config_get_lines(body, &cl, 1); + retval = config_get_lines_include(body, &cl, 1, + body == cf ? &cf_has_include : NULL); if (retval < 0) { err = SETOPT_ERR_PARSE; goto err; @@ -5166,6 +5171,8 @@ options_init_from_string(const char *cf_defaults, const char *cf, } } + newoptions->IncludeUsed = cf_has_include; + /* Validate newoptions */ if (options_validate(oldoptions, newoptions, newdefaultoptions, 0, msg) < 0) { diff --git a/src/or/confparse.h b/src/or/confparse.h index 6f5c681ba8..9c4205d07c 100644 --- a/src/or/confparse.h +++ b/src/or/confparse.h @@ -124,7 +124,6 @@ const char *config_find_deprecation(const config_format_t *fmt, const char *key); const config_var_t *config_find_option(const config_format_t *fmt, const char *key); - const char *config_expand_abbrev(const config_format_t *fmt, const char *option, int command_line, int warn_obsolete); diff --git a/src/or/control.c b/src/or/control.c index 4e85c38123..083768c3d3 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -1462,8 +1462,10 @@ handle_control_saveconf(control_connection_t *conn, uint32_t len, const char *body) { (void) len; - (void) body; - if (options_save_current()<0) { + + int force = !strcmpstart(body, "FORCE"); + const or_options_t *options = get_options(); + if ((!force && options->IncludeUsed) || options_save_current() < 0) { connection_write_str_to_buf( "551 Unable to write configuration to disk.\r\n", conn); } else { @@ -1677,6 +1679,8 @@ getinfo_helper_misc(control_connection_t *conn, const char *question, *answer = tor_strdup(a); } else if (!strcmp(question, "config-text")) { *answer = options_dump(get_options(), OPTIONS_DUMP_MINIMAL); + } else if (!strcmp(question, "config-can-saveconf")) { + *answer = tor_strdup(get_options()->IncludeUsed ? "0" : "1"); } else if (!strcmp(question, "info/names")) { *answer = list_getinfo_options(); } else if (!strcmp(question, "dormant")) { @@ -2931,6 +2935,8 @@ static const getinfo_item_t getinfo_items[] = { ITEM("config-defaults-file", misc, "Current location of the defaults file."), ITEM("config-text", misc, "Return the string that would be written by a saveconf command."), + ITEM("config-can-saveconf", misc, + "Is it possible to save the configuration to the \"torrc\" file?"), ITEM("accounting/bytes", accounting, "Number of bytes read/written so far in the accounting interval."), ITEM("accounting/bytes-left", accounting, diff --git a/src/or/or.h b/src/or/or.h index 297ec47fc1..41d9e8445f 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -4549,6 +4549,9 @@ typedef struct { * do we enforce Ed25519 identity match? */ /* NOTE: remove this option someday. */ int AuthDirTestEd25519LinkKeys; + + /** Bool (default: 0): Tells if a %include was used on torrc */ + int IncludeUsed; } or_options_t; /** Persistent state for an onion router, as saved to disk. */ |