From 8d84e10e8776eab8a44a039af0c15443fba83bc6 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 22 Oct 2019 08:27:13 -0400 Subject: Make options_validate() no longer use its "defaults" argument. It can just look at what the defaults are. Closes ticket 32185. --- src/app/config/config.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/app/config/config.c b/src/app/config/config.c index 77b73f8851..f07c9bbc2a 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -3434,7 +3434,7 @@ options_validate_single_onion(or_options_t *options, char **msg) */ STATIC int 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) { config_line_t *cl; @@ -3442,6 +3442,7 @@ options_validate(or_options_t *old_options, or_options_t *options, int n_ports=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); *msg = NULL; @@ -4486,12 +4487,17 @@ options_validate(or_options_t *old_options, or_options_t *options, "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) \ STMT_BEGIN \ if (!options->TestingTorNetwork && \ !options->UsingTestNetworkDefaults_ && \ - !config_is_same(get_options_mgr(),options, \ - default_options,#arg)) { \ + !config_is_same(get_options_mgr(),options, \ + dflt_options,#arg)) { \ + or_options_free(dflt_options); \ REJECT(#arg " may only be changed in testing Tor " \ "networks!"); \ } STMT_END @@ -4515,6 +4521,7 @@ options_validate(or_options_t *old_options, or_options_t *options, CHECK_DEFAULT(TestingAuthKeySlop); CHECK_DEFAULT(TestingLinkKeySlop); #undef CHECK_DEFAULT + or_options_free(dflt_options); if (!options->ClientDNSRejectInternalAddresses && !(options->DirAuthorities || -- cgit v1.2.3-54-g00ecf From 4413b030f28fcbe96f1b568796b20a7e90d55301 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 22 Oct 2019 08:32:33 -0400 Subject: Simplify CHECK_DEFAULT() logic a little further. Since each of these tests only applies to testing networks, put them all into a single block that checks for testing networks. (I recommend reviewing with the "diff -b" option, since the change is mostly indentation.) --- src/app/config/config.c | 57 +++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/app/config/config.c b/src/app/config/config.c index f07c9bbc2a..337ae93575 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -4487,41 +4487,42 @@ options_validate(or_options_t *old_options, or_options_t *options, "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) \ STMT_BEGIN \ - if (!options->TestingTorNetwork && \ - !options->UsingTestNetworkDefaults_ && \ - !config_is_same(get_options_mgr(),options, \ + if (!config_is_same(get_options_mgr(),options, \ dflt_options,#arg)) { \ or_options_free(dflt_options); \ REJECT(#arg " may only be changed in testing Tor " \ "networks!"); \ - } STMT_END - CHECK_DEFAULT(TestingV3AuthInitialVotingInterval); - CHECK_DEFAULT(TestingV3AuthInitialVoteDelay); - CHECK_DEFAULT(TestingV3AuthInitialDistDelay); - CHECK_DEFAULT(TestingV3AuthVotingStartOffset); - CHECK_DEFAULT(TestingAuthDirTimeToLearnReachability); - CHECK_DEFAULT(TestingEstimatedDescriptorPropagationTime); - CHECK_DEFAULT(TestingServerDownloadInitialDelay); - CHECK_DEFAULT(TestingClientDownloadInitialDelay); - CHECK_DEFAULT(TestingServerConsensusDownloadInitialDelay); - CHECK_DEFAULT(TestingClientConsensusDownloadInitialDelay); - CHECK_DEFAULT(TestingBridgeDownloadInitialDelay); - CHECK_DEFAULT(TestingBridgeBootstrapDownloadInitialDelay); - CHECK_DEFAULT(TestingClientMaxIntervalWithoutRequest); - CHECK_DEFAULT(TestingDirConnectionMaxStall); - CHECK_DEFAULT(TestingAuthKeyLifetime); - CHECK_DEFAULT(TestingLinkCertLifetime); - CHECK_DEFAULT(TestingSigningKeySlop); - CHECK_DEFAULT(TestingAuthKeySlop); - CHECK_DEFAULT(TestingLinkKeySlop); + } STMT_END + + /* Check for options that can only be changed from the defaults in testing + networks. */ + if (! options->TestingTorNetwork && !options->UsingTestNetworkDefaults_) { + or_options_t *dflt_options = options_new(); + options_init(dflt_options); + CHECK_DEFAULT(TestingV3AuthInitialVotingInterval); + CHECK_DEFAULT(TestingV3AuthInitialVoteDelay); + CHECK_DEFAULT(TestingV3AuthInitialDistDelay); + CHECK_DEFAULT(TestingV3AuthVotingStartOffset); + CHECK_DEFAULT(TestingAuthDirTimeToLearnReachability); + CHECK_DEFAULT(TestingEstimatedDescriptorPropagationTime); + CHECK_DEFAULT(TestingServerDownloadInitialDelay); + CHECK_DEFAULT(TestingClientDownloadInitialDelay); + CHECK_DEFAULT(TestingServerConsensusDownloadInitialDelay); + CHECK_DEFAULT(TestingClientConsensusDownloadInitialDelay); + CHECK_DEFAULT(TestingBridgeDownloadInitialDelay); + CHECK_DEFAULT(TestingBridgeBootstrapDownloadInitialDelay); + CHECK_DEFAULT(TestingClientMaxIntervalWithoutRequest); + CHECK_DEFAULT(TestingDirConnectionMaxStall); + CHECK_DEFAULT(TestingAuthKeyLifetime); + CHECK_DEFAULT(TestingLinkCertLifetime); + CHECK_DEFAULT(TestingSigningKeySlop); + CHECK_DEFAULT(TestingAuthKeySlop); + CHECK_DEFAULT(TestingLinkKeySlop); + or_options_free(dflt_options); + } #undef CHECK_DEFAULT - or_options_free(dflt_options); if (!options->ClientDNSRejectInternalAddresses && !(options->DirAuthorities || -- cgit v1.2.3-54-g00ecf