mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-14 07:03:44 +01:00
Merge remote-tracking branch 'tor-github/pr/1449'
This commit is contained in:
commit
34509e78c6
3
changes/ticket32187
Normal file
3
changes/ticket32187
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
o Code simplification and refactoring:
|
||||||
|
- Remove some unused arguments from the options_validate() function,
|
||||||
|
to simplify our code and tests. Closes ticket 32187.
|
@ -843,9 +843,8 @@ static int parse_outbound_addresses(or_options_t *options, int validate_only,
|
|||||||
char **msg);
|
char **msg);
|
||||||
static void config_maybe_load_geoip_files_(const or_options_t *options,
|
static void config_maybe_load_geoip_files_(const or_options_t *options,
|
||||||
const or_options_t *old_options);
|
const or_options_t *old_options);
|
||||||
static int options_validate_cb(void *old_options, void *options,
|
static int options_validate_cb(const void *old_options, void *options,
|
||||||
void *default_options,
|
char **msg);
|
||||||
int from_setconf, char **msg);
|
|
||||||
static void cleanup_protocol_warning_severity_level(void);
|
static void cleanup_protocol_warning_severity_level(void);
|
||||||
static void set_protocol_warning_severity_level(int warning_severity);
|
static void set_protocol_warning_severity_level(int warning_severity);
|
||||||
static void options_clear_cb(const config_mgr_t *mgr, void *opts);
|
static void options_clear_cb(const config_mgr_t *mgr, void *opts);
|
||||||
@ -1228,7 +1227,8 @@ add_default_fallback_dir_servers,(void))
|
|||||||
* user if we changed any dangerous ones.
|
* user if we changed any dangerous ones.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
validate_dir_servers(or_options_t *options, or_options_t *old_options)
|
validate_dir_servers(const or_options_t *options,
|
||||||
|
const or_options_t *old_options)
|
||||||
{
|
{
|
||||||
config_line_t *cl;
|
config_line_t *cl;
|
||||||
|
|
||||||
@ -2682,7 +2682,7 @@ options_trial_assign(config_line_t *list, unsigned flags, char **msg)
|
|||||||
in_option_validation = 1;
|
in_option_validation = 1;
|
||||||
|
|
||||||
if (options_validate(cur_options, trial_options,
|
if (options_validate(cur_options, trial_options,
|
||||||
global_default_options, 1, msg) < 0) {
|
msg) < 0) {
|
||||||
or_options_free(trial_options);
|
or_options_free(trial_options);
|
||||||
rv = SETOPT_ERR_PARSE; /*XXX make this a separate return value. */
|
rv = SETOPT_ERR_PARSE; /*XXX make this a separate return value. */
|
||||||
goto done;
|
goto done;
|
||||||
@ -3231,12 +3231,10 @@ compute_publishserverdescriptor(or_options_t *options)
|
|||||||
#define RECOMMENDED_MIN_CIRCUIT_BUILD_TIMEOUT (10)
|
#define RECOMMENDED_MIN_CIRCUIT_BUILD_TIMEOUT (10)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
options_validate_cb(void *old_options, void *options, void *default_options,
|
options_validate_cb(const void *old_options, void *options, char **msg)
|
||||||
int from_setconf, char **msg)
|
|
||||||
{
|
{
|
||||||
in_option_validation = 1;
|
in_option_validation = 1;
|
||||||
int rv = options_validate(old_options, options, default_options,
|
int rv = options_validate(old_options, options, msg);
|
||||||
from_setconf, msg);
|
|
||||||
in_option_validation = 0;
|
in_option_validation = 0;
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
@ -3433,16 +3431,13 @@ options_validate_single_onion(or_options_t *options, char **msg)
|
|||||||
* On error, tor_strdup an error explanation into *<b>msg</b>.
|
* On error, tor_strdup an error explanation into *<b>msg</b>.
|
||||||
*/
|
*/
|
||||||
STATIC int
|
STATIC int
|
||||||
options_validate(or_options_t *old_options, or_options_t *options,
|
options_validate(const or_options_t *old_options, or_options_t *options,
|
||||||
or_options_t *default_options_unused, int from_setconf_unused,
|
|
||||||
char **msg)
|
char **msg)
|
||||||
{
|
{
|
||||||
config_line_t *cl;
|
config_line_t *cl;
|
||||||
const char *uname = get_uname();
|
const char *uname = get_uname();
|
||||||
int n_ports=0;
|
int n_ports=0;
|
||||||
int world_writable_control_socket=0;
|
int world_writable_control_socket=0;
|
||||||
(void)from_setconf_unused; /* 29211 TODO: Remove this from the API. */
|
|
||||||
(void)default_options_unused; /* 29211 TODO: Remove this from the API. */
|
|
||||||
|
|
||||||
tor_assert(msg);
|
tor_assert(msg);
|
||||||
*msg = NULL;
|
*msg = NULL;
|
||||||
@ -5522,8 +5517,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
|||||||
newoptions->FilesOpenedByIncludes = opened_files;
|
newoptions->FilesOpenedByIncludes = opened_files;
|
||||||
|
|
||||||
/* Validate newoptions */
|
/* Validate newoptions */
|
||||||
if (options_validate(oldoptions, newoptions, newdefaultoptions,
|
if (options_validate(oldoptions, newoptions, msg) < 0) {
|
||||||
0, msg) < 0) {
|
|
||||||
err = SETOPT_ERR_PARSE; /*XXX make this a separate return value.*/
|
err = SETOPT_ERR_PARSE; /*XXX make this a separate return value.*/
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -277,10 +277,9 @@ STATIC void port_cfg_free_(port_cfg_t *port);
|
|||||||
STATIC void or_options_free_(or_options_t *options);
|
STATIC void or_options_free_(or_options_t *options);
|
||||||
STATIC int options_validate_single_onion(or_options_t *options,
|
STATIC int options_validate_single_onion(or_options_t *options,
|
||||||
char **msg);
|
char **msg);
|
||||||
STATIC int options_validate(or_options_t *old_options,
|
STATIC int options_validate(const or_options_t *old_options,
|
||||||
or_options_t *options,
|
or_options_t *options,
|
||||||
or_options_t *default_options,
|
char **msg);
|
||||||
int from_setconf, char **msg);
|
|
||||||
STATIC int parse_transport_line(const or_options_t *options,
|
STATIC int parse_transport_line(const or_options_t *options,
|
||||||
const char *line, int validate_only,
|
const char *line, int validate_only,
|
||||||
int server);
|
int server);
|
||||||
|
@ -141,9 +141,8 @@ static const config_var_t state_vars_[] = {
|
|||||||
|
|
||||||
static int or_state_validate(or_state_t *state, char **msg);
|
static int or_state_validate(or_state_t *state, char **msg);
|
||||||
|
|
||||||
static int or_state_validate_cb(void *old_options, void *options,
|
static int or_state_validate_cb(const void *old_options,
|
||||||
void *default_options,
|
void *options, char **msg);
|
||||||
int from_setconf, char **msg);
|
|
||||||
|
|
||||||
/** Magic value for or_state_t. */
|
/** Magic value for or_state_t. */
|
||||||
#define OR_STATE_MAGIC 0x57A73f57
|
#define OR_STATE_MAGIC 0x57A73f57
|
||||||
@ -269,13 +268,10 @@ validate_transports_in_state(or_state_t *state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
or_state_validate_cb(void *old_state, void *state, void *default_state,
|
or_state_validate_cb(const void *old_state, void *state, char **msg)
|
||||||
int from_setconf, char **msg)
|
|
||||||
{
|
{
|
||||||
/* We don't use these; only options do. Still, we need to match that
|
/* We don't use these; only options do. Still, we need to match that
|
||||||
* signature. */
|
* signature. */
|
||||||
(void) from_setconf;
|
|
||||||
(void) default_state;
|
|
||||||
(void) old_state;
|
(void) old_state;
|
||||||
|
|
||||||
return or_state_validate(state, msg);
|
return or_state_validate(state, msg);
|
||||||
|
@ -60,8 +60,7 @@ DUMMY_TYPECHECK_INSTANCE(sr_disk_state_t);
|
|||||||
#define SR_DISK_STATE_MAGIC 0x98AB1254
|
#define SR_DISK_STATE_MAGIC 0x98AB1254
|
||||||
|
|
||||||
static int
|
static int
|
||||||
disk_state_validate_cb(void *old_state, void *state, void *default_state,
|
disk_state_validate_cb(const void *old_state, void *state, char **msg);
|
||||||
int from_setconf, char **msg);
|
|
||||||
|
|
||||||
/** Array of variables that are saved to disk as a persistent state. */
|
/** Array of variables that are saved to disk as a persistent state. */
|
||||||
static const config_var_t state_vars[] = {
|
static const config_var_t state_vars[] = {
|
||||||
@ -345,12 +344,9 @@ disk_state_validate(const sr_disk_state_t *state)
|
|||||||
|
|
||||||
/** Validate the disk state (NOP for now). */
|
/** Validate the disk state (NOP for now). */
|
||||||
static int
|
static int
|
||||||
disk_state_validate_cb(void *old_state, void *state, void *default_state,
|
disk_state_validate_cb(const void *old_state, void *state, char **msg)
|
||||||
int from_setconf, char **msg)
|
|
||||||
{
|
{
|
||||||
/* We don't use these; only options do. */
|
/* We don't use these; only options do. */
|
||||||
(void) from_setconf;
|
|
||||||
(void) default_state;
|
|
||||||
(void) old_state;
|
(void) old_state;
|
||||||
|
|
||||||
/* This is called by config_dump which is just before we are about to
|
/* This is called by config_dump which is just before we are about to
|
||||||
|
@ -1166,7 +1166,7 @@ config_dump(const config_mgr_t *mgr, const void *default_options,
|
|||||||
|
|
||||||
/* XXX use a 1 here so we don't add a new log line while dumping */
|
/* XXX use a 1 here so we don't add a new log line while dumping */
|
||||||
if (default_options == NULL) {
|
if (default_options == NULL) {
|
||||||
if (fmt->validate_fn(NULL, defaults_tmp, defaults_tmp, 1, &msg) < 0) {
|
if (fmt->validate_fn(NULL, defaults_tmp, &msg) < 0) {
|
||||||
// LCOV_EXCL_START
|
// LCOV_EXCL_START
|
||||||
log_err(LD_BUG, "Failed to validate default config: %s", msg);
|
log_err(LD_BUG, "Failed to validate default config: %s", msg);
|
||||||
tor_free(msg);
|
tor_free(msg);
|
||||||
|
@ -68,10 +68,8 @@ typedef struct config_deprecation_t {
|
|||||||
* config_dump(); later in our refactoring, it will be cleaned up and used
|
* config_dump(); later in our refactoring, it will be cleaned up and used
|
||||||
* more generally.
|
* more generally.
|
||||||
*/
|
*/
|
||||||
typedef int (*validate_fn_t)(void *oldval,
|
typedef int (*validate_fn_t)(const void *oldval,
|
||||||
void *newval,
|
void *newval,
|
||||||
void *default_val,
|
|
||||||
int from_setconf,
|
|
||||||
char **msg_out);
|
char **msg_out);
|
||||||
|
|
||||||
struct config_mgr_t;
|
struct config_mgr_t;
|
||||||
|
@ -906,14 +906,12 @@ test_config_fix_my_family(void *arg)
|
|||||||
family3->next = NULL;
|
family3->next = NULL;
|
||||||
|
|
||||||
or_options_t* options = options_new();
|
or_options_t* options = options_new();
|
||||||
or_options_t* defaults = options_new();
|
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
options_init(options);
|
options_init(options);
|
||||||
options_init(defaults);
|
|
||||||
options->MyFamily_lines = family;
|
options->MyFamily_lines = family;
|
||||||
|
|
||||||
options_validate(NULL, options, defaults, 0, &err) ;
|
options_validate(NULL, options, &err) ;
|
||||||
|
|
||||||
if (err != NULL) {
|
if (err != NULL) {
|
||||||
TT_FAIL(("options_validate failed: %s", err));
|
TT_FAIL(("options_validate failed: %s", err));
|
||||||
@ -935,7 +933,6 @@ test_config_fix_my_family(void *arg)
|
|||||||
done:
|
done:
|
||||||
tor_free(err);
|
tor_free(err);
|
||||||
or_options_free(options);
|
or_options_free(options);
|
||||||
or_options_free(defaults);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int n_hostname_01010101 = 0;
|
static int n_hostname_01010101 = 0;
|
||||||
@ -5640,7 +5637,6 @@ test_config_check_bridge_distribution_setting_not_a_bridge(void *arg)
|
|||||||
{
|
{
|
||||||
or_options_t* options = get_options_mutable();
|
or_options_t* options = get_options_mutable();
|
||||||
or_options_t* old_options = options;
|
or_options_t* old_options = options;
|
||||||
or_options_t* default_options = options;
|
|
||||||
char* message = NULL;
|
char* message = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -5649,7 +5645,7 @@ test_config_check_bridge_distribution_setting_not_a_bridge(void *arg)
|
|||||||
options->BridgeRelay = 0;
|
options->BridgeRelay = 0;
|
||||||
options->BridgeDistribution = (char*)("https");
|
options->BridgeDistribution = (char*)("https");
|
||||||
|
|
||||||
ret = options_validate(old_options, options, default_options, 0, &message);
|
ret = options_validate(old_options, options, &message);
|
||||||
|
|
||||||
tt_int_op(ret, OP_EQ, -1);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
tt_str_op(message, OP_EQ, "You set BridgeDistribution, but you "
|
tt_str_op(message, OP_EQ, "You set BridgeDistribution, but you "
|
||||||
|
@ -103,12 +103,9 @@ static config_deprecation_t test_deprecation_notes[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test_validate_cb(void *old_options, void *options, void *default_options,
|
test_validate_cb(const void *old_options, void *options, char **msg)
|
||||||
int from_setconf, char **msg)
|
|
||||||
{
|
{
|
||||||
(void)old_options;
|
(void)old_options;
|
||||||
(void)default_options;
|
|
||||||
(void)from_setconf;
|
|
||||||
(void)msg;
|
(void)msg;
|
||||||
test_struct_t *ts = options;
|
test_struct_t *ts = options;
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user