Make options_validate() no longer use its "defaults" argument.

It can just look at what the defaults are.

Closes ticket 32185.
This commit is contained in:
Nick Mathewson 2019-10-22 08:27:13 -04:00
parent a1d5341374
commit 8d84e10e87
2 changed files with 14 additions and 3 deletions

4
changes/ticket32185 Normal file
View File

@ -0,0 +1,4 @@
o Code simplification and refactoring:
- Simplify the options_validate() code so that it looks at the default
options directly, rather than taking default options as an argument.
This change lets us simplify its interface. Closes ticket 32185.

View File

@ -3434,7 +3434,7 @@ options_validate_single_onion(or_options_t *options, char **msg)
*/ */
STATIC int STATIC int
options_validate(or_options_t *old_options, or_options_t *options, options_validate(or_options_t *old_options, or_options_t *options,
or_options_t *default_options, int from_setconf_unused, or_options_t *default_options_unused, int from_setconf_unused,
char **msg) char **msg)
{ {
config_line_t *cl; config_line_t *cl;
@ -3442,6 +3442,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
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)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;
@ -4486,12 +4487,17 @@ options_validate(or_options_t *old_options, or_options_t *options,
"AlternateDirAuthority and AlternateBridgeAuthority configured."); "AlternateDirAuthority and AlternateBridgeAuthority configured.");
} }
/* Check for options that can only be changed from the defaults in testing
networks. */
or_options_t *dflt_options = options_new();
options_init(dflt_options);
#define CHECK_DEFAULT(arg) \ #define CHECK_DEFAULT(arg) \
STMT_BEGIN \ STMT_BEGIN \
if (!options->TestingTorNetwork && \ if (!options->TestingTorNetwork && \
!options->UsingTestNetworkDefaults_ && \ !options->UsingTestNetworkDefaults_ && \
!config_is_same(get_options_mgr(),options, \ !config_is_same(get_options_mgr(),options, \
default_options,#arg)) { \ dflt_options,#arg)) { \
or_options_free(dflt_options); \
REJECT(#arg " may only be changed in testing Tor " \ REJECT(#arg " may only be changed in testing Tor " \
"networks!"); \ "networks!"); \
} STMT_END } STMT_END
@ -4515,6 +4521,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
CHECK_DEFAULT(TestingAuthKeySlop); CHECK_DEFAULT(TestingAuthKeySlop);
CHECK_DEFAULT(TestingLinkKeySlop); CHECK_DEFAULT(TestingLinkKeySlop);
#undef CHECK_DEFAULT #undef CHECK_DEFAULT
or_options_free(dflt_options);
if (!options->ClientDNSRejectInternalAddresses && if (!options->ClientDNSRejectInternalAddresses &&
!(options->DirAuthorities || !(options->DirAuthorities ||