diff options
| author | jvoisin | 2017-10-01 20:54:03 +0200 |
|---|---|---|
| committer | jvoisin | 2017-10-02 15:20:53 +0200 |
| commit | 36c06637ad262f0e5fc0c8e70f4c1fc6a565f056 (patch) | |
| tree | ea55e322dd3e02ae7fdc2f35a815a9ba8330f301 /src/sp_config_keywords.c | |
| parent | 7418a0e1e9b02aef8535e33d30cfb8f082680f69 (diff) | |
First pass for #9
Diffstat (limited to 'src/sp_config_keywords.c')
| -rw-r--r-- | src/sp_config_keywords.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index b068bec..cf52ae3 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -19,10 +19,10 @@ static int parse_enable(char *line, bool * restrict retval, bool * restrict simu | |||
| 19 | if (!(enable ^ disable)) { | 19 | if (!(enable ^ disable)) { |
| 20 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu.", sp_line_no); | 20 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu.", sp_line_no); |
| 21 | return -1; | 21 | return -1; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | *retval = enable; | 24 | *retval = enable; |
| 25 | 25 | ||
| 26 | return ret; | 26 | return ret; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| @@ -51,11 +51,13 @@ int parse_readonly_exec(char *line) { | |||
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | int parse_global(char *line) { | 53 | int parse_global(char *line) { |
| 54 | sp_config_functions sp_config_funcs_encryption_key[] = { | 54 | sp_config_functions sp_config_global[] = { |
| 55 | {parse_str, SP_TOKEN_ENCRYPTION_KEY, | 55 | {parse_str, SP_TOKEN_ENCRYPTION_KEY, |
| 56 | &(SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key)}, | 56 | &(SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key)}, |
| 57 | {parse_str, SP_TOKEN_ENV_VAR, | ||
| 58 | &(SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var)}, | ||
| 57 | {0}}; | 59 | {0}}; |
| 58 | return parse_keywords(sp_config_funcs_encryption_key, line); | 60 | return parse_keywords(sp_config_global, line); |
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | int parse_cookie_encryption(char *line) { | 63 | int parse_cookie_encryption(char *line) { |
| @@ -64,10 +66,6 @@ int parse_cookie_encryption(char *line) { | |||
| 64 | 66 | ||
| 65 | sp_config_functions sp_config_funcs_cookie_encryption[] = { | 67 | sp_config_functions sp_config_funcs_cookie_encryption[] = { |
| 66 | {parse_str, SP_TOKEN_NAME, &name}, | 68 | {parse_str, SP_TOKEN_NAME, &name}, |
| 67 | {parse_int, SP_TOKEN_MASK_IPV4, | ||
| 68 | &(SNUFFLEUPAGUS_G(config).config_cookie_encryption->mask_ipv4)}, | ||
| 69 | {parse_int, SP_TOKEN_MASK_IPV6, | ||
| 70 | &(SNUFFLEUPAGUS_G(config).config_cookie_encryption->mask_ipv6)}, | ||
| 71 | {0}}; | 69 | {0}}; |
| 72 | 70 | ||
| 73 | ret = parse_keywords(sp_config_funcs_cookie_encryption, line); | 71 | ret = parse_keywords(sp_config_funcs_cookie_encryption, line); |
| @@ -75,11 +73,16 @@ int parse_cookie_encryption(char *line) { | |||
| 75 | return ret; | 73 | return ret; |
| 76 | } | 74 | } |
| 77 | 75 | ||
| 78 | if (32 < SNUFFLEUPAGUS_G(config).config_cookie_encryption->mask_ipv4) { | 76 | if (0 == (SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var)) { |
| 79 | SNUFFLEUPAGUS_G(config).config_cookie_encryption->mask_ipv4 = 32; | 77 | sp_log_err("config", "You're trying to use the cookie encryption feature" |
| 80 | } | 78 | "on line %zu without having set the `.cookie_env_var` option in" |
| 81 | if (128 < SNUFFLEUPAGUS_G(config).config_cookie_encryption->mask_ipv6) { | 79 | "`sp.global`: please set it first.", sp_line_no); |
| 82 | SNUFFLEUPAGUS_G(config).config_cookie_encryption->mask_ipv6 = 128; | 80 | return -1; |
| 81 | } else if (0 == (SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key)) { | ||
| 82 | sp_log_err("config", "You're trying to use the cookie encryption feature" | ||
| 83 | "on line %zu without having set the `.encryption_key` option in" | ||
| 84 | "`sp.global`: please set it first.", sp_line_no); | ||
| 85 | return -1; | ||
| 83 | } | 86 | } |
| 84 | 87 | ||
| 85 | if (name) { | 88 | if (name) { |
| @@ -190,7 +193,7 @@ int parse_disabled_functions(char *line) { | |||
| 190 | } | 193 | } |
| 191 | df->param_is_array = 1; | 194 | df->param_is_array = 1; |
| 192 | } | 195 | } |
| 193 | 196 | ||
| 194 | if (df->var && strchr(df->var, '[')) { // assume that this is an array | 197 | if (df->var && strchr(df->var, '[')) { // assume that this is an array |
| 195 | df->var_array_keys = sp_new_list(); | 198 | df->var_array_keys = sp_new_list(); |
| 196 | if (0 != array_to_list(&df->var, &df->var_array_keys)) { | 199 | if (0 != array_to_list(&df->var, &df->var_array_keys)) { |
| @@ -247,7 +250,7 @@ int parse_upload_validation(char *line) { | |||
| 247 | if (!(enable ^ disable)) { | 250 | if (!(enable ^ disable)) { |
| 248 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu.", sp_line_no); | 251 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu.", sp_line_no); |
| 249 | return -1; | 252 | return -1; |
| 250 | } | 253 | } |
| 251 | SNUFFLEUPAGUS_G(config).config_upload_validation->enable = enable; | 254 | SNUFFLEUPAGUS_G(config).config_upload_validation->enable = enable; |
| 252 | 255 | ||
| 253 | char const *script = SNUFFLEUPAGUS_G(config).config_upload_validation->script; | 256 | char const *script = SNUFFLEUPAGUS_G(config).config_upload_validation->script; |
| @@ -263,6 +266,6 @@ int parse_upload_validation(char *line) { | |||
| 263 | sp_log_err("config", "The `script` (%s) isn't executable on line %zu.", script, sp_line_no); | 266 | sp_log_err("config", "The `script` (%s) isn't executable on line %zu.", script, sp_line_no); |
| 264 | return -1; | 267 | return -1; |
| 265 | } | 268 | } |
| 266 | 269 | ||
| 267 | return ret; | 270 | return ret; |
| 268 | } | 271 | } |
