mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 21:53:48 +01:00
Add a CFLG_IMMUTABLE flag to mark a field as unchangeable.
This commit is contained in:
parent
f579541f13
commit
2a2c7049b8
@ -178,6 +178,11 @@ typedef struct struct_magic_decl_t {
|
|||||||
* however, setting them appends to their old value.
|
* however, setting them appends to their old value.
|
||||||
*/
|
*/
|
||||||
#define CFLG_NOREPLACE (1u<<5)
|
#define CFLG_NOREPLACE (1u<<5)
|
||||||
|
/**
|
||||||
|
* Flag to indicate that an option or type cannot be changed while Tor is
|
||||||
|
* running.
|
||||||
|
**/
|
||||||
|
#define CFLG_IMMUTABLE (1u<<6)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A group of flags that should be set on all obsolete options and types.
|
* A group of flags that should be set on all obsolete options and types.
|
||||||
|
@ -1153,6 +1153,41 @@ config_init(const config_mgr_t *mgr, void *options)
|
|||||||
} SMARTLIST_FOREACH_END(mv);
|
} SMARTLIST_FOREACH_END(mv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper for config_validate_single: see whether any immutable option
|
||||||
|
* has changed between old_options and new_options.
|
||||||
|
*
|
||||||
|
* On success return 0; on failure set *msg_out to a newly allocated
|
||||||
|
* string explaining what is wrong, and return -1.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
config_check_immutable_flags(const config_format_t *fmt,
|
||||||
|
const void *old_options,
|
||||||
|
const void *new_options,
|
||||||
|
char **msg_out)
|
||||||
|
{
|
||||||
|
tor_assert(fmt);
|
||||||
|
tor_assert(new_options);
|
||||||
|
if (BUG(! old_options))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
unsigned i;
|
||||||
|
for (i = 0; fmt->vars[i].member.name; ++i) {
|
||||||
|
const config_var_t *v = &fmt->vars[i];
|
||||||
|
if (! config_var_has_flag(v, CFLG_IMMUTABLE))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (! struct_var_eq(old_options, new_options, &v->member)) {
|
||||||
|
tor_asprintf(msg_out,
|
||||||
|
"While Tor is running, changing %s is not allowed",
|
||||||
|
v->member.name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize and validate a single object `options` within a configuration
|
* Normalize and validate a single object `options` within a configuration
|
||||||
* suite, according to its format. `options` may be modified as appropriate
|
* suite, according to its format. `options` may be modified as appropriate
|
||||||
@ -1189,10 +1224,16 @@ config_validate_single(const config_format_t *fmt,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmt->check_transition_fn && old_options) {
|
if (old_options) {
|
||||||
if (fmt->check_transition_fn(old_options, options, msg_out) < 0) {
|
if (config_check_immutable_flags(fmt, old_options, options, msg_out) < 0) {
|
||||||
return VSTAT_TRANSITION_ERR;
|
return VSTAT_TRANSITION_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fmt->check_transition_fn) {
|
||||||
|
if (fmt->check_transition_fn(old_options, options, msg_out) < 0) {
|
||||||
|
return VSTAT_TRANSITION_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmt->post_normalize_fn) {
|
if (fmt->post_normalize_fn) {
|
||||||
|
Loading…
Reference in New Issue
Block a user