diff options
Diffstat (limited to 'src/sp_config_keywords.c')
| -rw-r--r-- | src/sp_config_keywords.c | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index c547f10..b627122 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -1,5 +1,14 @@ | |||
| 1 | #include "php_snuffleupagus.h" | 1 | #include "php_snuffleupagus.h" |
| 2 | 2 | ||
| 3 | #define SP_SET_ENABLE_DISABLE(enable, disable, varname) \ | ||
| 4 | if (enable && disable) { \ | ||
| 5 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu", sp_line_no); \ | ||
| 6 | return -1; \ | ||
| 7 | } \ | ||
| 8 | if (enable || disable) { \ | ||
| 9 | (varname) = (enable || !disable); \ | ||
| 10 | } | ||
| 11 | |||
| 3 | static int parse_enable(char *line, bool *restrict retval, | 12 | static int parse_enable(char *line, bool *restrict retval, |
| 4 | bool *restrict simulation) { | 13 | bool *restrict simulation) { |
| 5 | bool enable = false, disable = false; | 14 | bool enable = false, disable = false; |
| @@ -15,13 +24,7 @@ static int parse_enable(char *line, bool *restrict retval, | |||
| 15 | return ret; | 24 | return ret; |
| 16 | } | 25 | } |
| 17 | 26 | ||
| 18 | if (!(enable ^ disable)) { | 27 | SP_SET_ENABLE_DISABLE(enable, disable, *retval); |
| 19 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu", | ||
| 20 | sp_line_no); | ||
| 21 | return -1; | ||
| 22 | } | ||
| 23 | |||
| 24 | *retval = enable; | ||
| 25 | 28 | ||
| 26 | return ret; | 29 | return ret; |
| 27 | } | 30 | } |
| @@ -141,13 +144,7 @@ int parse_unserialize(char *line) { | |||
| 141 | return ret; | 144 | return ret; |
| 142 | } | 145 | } |
| 143 | 146 | ||
| 144 | if (!(enable ^ disable)) { | 147 | SP_SET_ENABLE_DISABLE(enable, disable, SNUFFLEUPAGUS_G(config).config_unserialize->enable); |
| 145 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu", | ||
| 146 | sp_line_no); | ||
| 147 | return -1; | ||
| 148 | } | ||
| 149 | |||
| 150 | SNUFFLEUPAGUS_G(config).config_unserialize->enable = enable; | ||
| 151 | 148 | ||
| 152 | return ret; | 149 | return ret; |
| 153 | } | 150 | } |
| @@ -172,13 +169,7 @@ int parse_readonly_exec(char *line) { | |||
| 172 | return ret; | 169 | return ret; |
| 173 | } | 170 | } |
| 174 | 171 | ||
| 175 | if (!(enable ^ disable)) { | 172 | SP_SET_ENABLE_DISABLE(enable, disable, SNUFFLEUPAGUS_G(config).config_readonly_exec->enable); |
| 176 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu", | ||
| 177 | sp_line_no); | ||
| 178 | return -1; | ||
| 179 | } | ||
| 180 | |||
| 181 | SNUFFLEUPAGUS_G(config).config_readonly_exec->enable = enable; | ||
| 182 | 173 | ||
| 183 | return ret; | 174 | return ret; |
| 184 | } | 175 | } |
| @@ -535,12 +526,7 @@ int parse_upload_validation(char *line) { | |||
| 535 | return ret; | 526 | return ret; |
| 536 | } | 527 | } |
| 537 | 528 | ||
| 538 | if (!(enable ^ disable)) { | 529 | SP_SET_ENABLE_DISABLE(enable, disable, SNUFFLEUPAGUS_G(config).config_upload_validation->enable); |
| 539 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu", | ||
| 540 | sp_line_no); | ||
| 541 | return -1; | ||
| 542 | } | ||
| 543 | SNUFFLEUPAGUS_G(config).config_upload_validation->enable = enable; | ||
| 544 | 530 | ||
| 545 | zend_string const *script = | 531 | zend_string const *script = |
| 546 | SNUFFLEUPAGUS_G(config).config_upload_validation->script; | 532 | SNUFFLEUPAGUS_G(config).config_upload_validation->script; |
| @@ -584,14 +570,7 @@ int parse_ini_protection(char *line) { | |||
| 584 | int ret = parse_keywords(sp_config_ini_protection, line); | 570 | int ret = parse_keywords(sp_config_ini_protection, line); |
| 585 | if (ret) { return ret; } | 571 | if (ret) { return ret; } |
| 586 | 572 | ||
| 587 | if (enable && disable) { | 573 | SP_SET_ENABLE_DISABLE(enable, disable, cfg->enable); |
| 588 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu", | ||
| 589 | sp_line_no); | ||
| 590 | return -1; | ||
| 591 | } | ||
| 592 | if (enable || disable) { | ||
| 593 | cfg->enable = (enable || !disable); | ||
| 594 | } | ||
| 595 | 574 | ||
| 596 | if (ro && rw) { | 575 | if (ro && rw) { |
| 597 | sp_log_err("config", "rule cannot be both read-write and read-only on line %zu", sp_line_no); | 576 | sp_log_err("config", "rule cannot be both read-write and read-only on line %zu", sp_line_no); |
