summaryrefslogtreecommitdiff
path: root/src/sp_config_keywords.c
diff options
context:
space:
mode:
authorxXx-caillou-xXx2018-08-28 14:24:29 +0200
committerjvoisin2018-08-28 12:24:29 +0000
commitaa5d6895d0ac8c6ea050a8ea55e2f8a39ddfe365 (patch)
treec640e50ab007bae3a2fd55ca05bc13c73e293c69 /src/sp_config_keywords.c
parenteff2c658d37108020215f838d4c47c176ec3e050 (diff)
Use php's logging functions
This commit replace our usage of `php_log_err` with `zend_error`. This should allow administrators to display errors in the webpage, should they want to; and to properly manipulate the verbosity's level. This should close #217
Diffstat (limited to 'src/sp_config_keywords.c')
-rw-r--r--src/sp_config_keywords.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c
index b86b9d9..13a2f89 100644
--- a/src/sp_config_keywords.c
+++ b/src/sp_config_keywords.c
@@ -19,7 +19,7 @@ static int parse_enable(char *line, bool *restrict retval,
19 } 19 }
20 20
21 if (!(enable ^ disable)) { 21 if (!(enable ^ disable)) {
22 sp_log_err("config", "A rule can't be enabled and disabled on line %zu.", 22 sp_log_err("config", "A rule can't be enabled and disabled on line %zu",
23 sp_line_no); 23 sp_line_no);
24 return -1; 24 return -1;
25 } 25 }
@@ -44,9 +44,9 @@ int parse_session(char *line) {
44 if (0 == (SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var)) { 44 if (0 == (SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var)) {
45 sp_log_err( 45 sp_log_err(
46 "config", 46 "config",
47 "You're trying to use the session cookie encryption feature" 47 "You're trying to use the session cookie encryption feature "
48 "on line %zu without having set the `.cookie_env_var` option in" 48 "on line %zu without having set the `.cookie_env_var` option in"
49 "`sp.global`: please set it first.", 49 "`sp.global`: please set it first",
50 sp_line_no); 50 sp_line_no);
51 pefree(session, 0); 51 pefree(session, 0);
52 return -1; 52 return -1;
@@ -54,9 +54,9 @@ int parse_session(char *line) {
54 (SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key)) { 54 (SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key)) {
55 sp_log_err( 55 sp_log_err(
56 "config", 56 "config",
57 "You're trying to use the session cookie encryption feature" 57 "You're trying to use the session cookie encryption feature "
58 "on line %zu without having set the `.encryption_key` option in" 58 "on line %zu without having set the `.encryption_key` option in"
59 "`sp.global`: please set it first.", 59 "`sp.global`: please set it first",
60 sp_line_no); 60 sp_line_no);
61 pefree(session, 0); 61 pefree(session, 0);
62 return -1; 62 return -1;
@@ -114,7 +114,7 @@ int parse_unserialize(char *line) {
114 } 114 }
115 115
116 if (!(enable ^ disable)) { 116 if (!(enable ^ disable)) {
117 sp_log_err("config", "A rule can't be enabled and disabled on line %zu.", 117 sp_log_err("config", "A rule can't be enabled and disabled on line %zu",
118 sp_line_no); 118 sp_line_no);
119 return -1; 119 return -1;
120 } 120 }
@@ -145,7 +145,7 @@ int parse_readonly_exec(char *line) {
145 } 145 }
146 146
147 if (!(enable ^ disable)) { 147 if (!(enable ^ disable)) {
148 sp_log_err("config", "A rule can't be enabled and disabled on line %zu.", 148 sp_log_err("config", "A rule can't be enabled and disabled on line %zu",
149 sp_line_no); 149 sp_line_no);
150 return -1; 150 return -1;
151 } 151 }
@@ -236,7 +236,7 @@ int parse_cookie(char *line) {
236 "config", 236 "config",
237 "You're trying to use the cookie encryption feature" 237 "You're trying to use the cookie encryption feature"
238 "on line %zu without having set the `.cookie_env_var` option in" 238 "on line %zu without having set the `.cookie_env_var` option in"
239 "`sp.global`: please set it first.", 239 "`sp.global`: please set it first",
240 sp_line_no); 240 sp_line_no);
241 return -1; 241 return -1;
242 } else if (0 == 242 } else if (0 ==
@@ -245,28 +245,28 @@ int parse_cookie(char *line) {
245 "config", 245 "config",
246 "You're trying to use the cookie encryption feature" 246 "You're trying to use the cookie encryption feature"
247 "on line %zu without having set the `.encryption_key` option in" 247 "on line %zu without having set the `.encryption_key` option in"
248 "`sp.global`: please set it first.", 248 "`sp.global`: please set it first",
249 sp_line_no); 249 sp_line_no);
250 return -1; 250 return -1;
251 } 251 }
252 } else if (!samesite) { 252 } else if (!samesite) {
253 sp_log_err("config", 253 sp_log_err("config",
254 "You must specify a at least one action to a cookie on line " 254 "You must specify a at least one action to a cookie on line "
255 "%zu.", 255 "%zu",
256 sp_line_no); 256 sp_line_no);
257 return -1; 257 return -1;
258 } 258 }
259 if ((!cookie->name || 0 == ZSTR_LEN(cookie->name)) && !cookie->name_r) { 259 if ((!cookie->name || 0 == ZSTR_LEN(cookie->name)) && !cookie->name_r) {
260 sp_log_err("config", 260 sp_log_err("config",
261 "You must specify a cookie name/regexp on line " 261 "You must specify a cookie name/regexp on line "
262 "%zu.", 262 "%zu",
263 sp_line_no); 263 sp_line_no);
264 return -1; 264 return -1;
265 } 265 }
266 if (cookie->name && cookie->name_r) { 266 if (cookie->name && cookie->name_r) {
267 sp_log_err("config", 267 sp_log_err("config",
268 "name and name_r are mutually exclusive on line " 268 "name and name_r are mutually exclusive on line "
269 "%zu.", 269 "%zu",
270 sp_line_no); 270 sp_line_no);
271 return -1; 271 return -1;
272 } 272 }
@@ -280,7 +280,7 @@ int parse_cookie(char *line) {
280 sp_log_err( 280 sp_log_err(
281 "config", 281 "config",
282 "%s is an invalid value to samesite (expected %s or %s) on line " 282 "%s is an invalid value to samesite (expected %s or %s) on line "
283 "%zu.", 283 "%zu",
284 ZSTR_VAL(samesite), SP_TOKEN_SAMESITE_LAX, SP_TOKEN_SAMESITE_STRICT, 284 ZSTR_VAL(samesite), SP_TOKEN_SAMESITE_LAX, SP_TOKEN_SAMESITE_STRICT,
285 sp_line_no); 285 sp_line_no);
286 return -1; 286 return -1;
@@ -350,7 +350,7 @@ int parse_disabled_functions(char *line) {
350 if (X && Y) { \ 350 if (X && Y) { \
351 sp_log_err("config", \ 351 sp_log_err("config", \
352 "Invalid configuration line: 'sp.disabled_functions%s': " \ 352 "Invalid configuration line: 'sp.disabled_functions%s': " \
353 "'.%s' and '.%s' are mutually exclusive on line %zu.", \ 353 "'.%s' and '.%s' are mutually exclusive on line %zu", \
354 line, STR1, STR2, sp_line_no); \ 354 line, STR1, STR2, sp_line_no); \
355 return 1; \ 355 return 1; \
356 } 356 }
@@ -367,38 +367,38 @@ int parse_disabled_functions(char *line) {
367 sp_log_err( 367 sp_log_err(
368 "config", 368 "config",
369 "Invalid configuration line: 'sp.disabled_functions%s':" 369 "Invalid configuration line: 'sp.disabled_functions%s':"
370 "'.r_param', '.param' and '.pos' are mutually exclusive on line %zu.", 370 "'.r_param', '.param' and '.pos' are mutually exclusive on line %zu",
371 line, sp_line_no); 371 line, sp_line_no);
372 return -1; 372 return -1;
373 } else if ((df->r_key || df->key) && (df->r_value || df->value)) { 373 } else if ((df->r_key || df->key) && (df->r_value || df->value)) {
374 sp_log_err("config", 374 sp_log_err("config",
375 "Invalid configuration line: 'sp.disabled_functions%s':" 375 "Invalid configuration line: 'sp.disabled_functions%s':"
376 "`key` and `value` are mutually exclusive on line %zu.", 376 "`key` and `value` are mutually exclusive on line %zu",
377 line, sp_line_no); 377 line, sp_line_no);
378 return -1; 378 return -1;
379 } else if ((df->r_ret || df->ret || df->ret_type) && (df->r_param || param)) { 379 } else if ((df->r_ret || df->ret || df->ret_type) && (df->r_param || param)) {
380 sp_log_err("config", 380 sp_log_err("config",
381 "Invalid configuration line: 'sp.disabled_functions%s':" 381 "Invalid configuration line: 'sp.disabled_functions%s':"
382 "`ret` and `param` are mutually exclusive on line %zu.", 382 "`ret` and `param` are mutually exclusive on line %zu",
383 line, sp_line_no); 383 line, sp_line_no);
384 return -1; 384 return -1;
385 } else if ((df->r_ret || df->ret || df->ret_type) && (var)) { 385 } else if ((df->r_ret || df->ret || df->ret_type) && (var)) {
386 sp_log_err("config", 386 sp_log_err("config",
387 "Invalid configuration line: 'sp.disabled_functions%s':" 387 "Invalid configuration line: 'sp.disabled_functions%s':"
388 "`ret` and `var` are mutually exclusive on line %zu.", 388 "`ret` and `var` are mutually exclusive on line %zu",
389 line, sp_line_no); 389 line, sp_line_no);
390 return -1; 390 return -1;
391 } else if ((df->r_ret || df->ret || df->ret_type) && 391 } else if ((df->r_ret || df->ret || df->ret_type) &&
392 (df->value || df->r_value)) { 392 (df->value || df->r_value)) {
393 sp_log_err("config", 393 sp_log_err("config",
394 "Invalid configuration line: 'sp.disabled_functions%s':" 394 "Invalid configuration line: 'sp.disabled_functions%s':"
395 "`ret` and `value` are mutually exclusive on line %zu.", 395 "`ret` and `value` are mutually exclusive on line %zu",
396 line, sp_line_no); 396 line, sp_line_no);
397 return -1; 397 return -1;
398 } else if (!(df->r_function || df->function)) { 398 } else if (!(df->r_function || df->function)) {
399 sp_log_err("config", 399 sp_log_err("config",
400 "Invalid configuration line: 'sp.disabled_functions%s':" 400 "Invalid configuration line: 'sp.disabled_functions%s':"
401 " must take a function name on line %zu.", 401 " must take a function name on line %zu",
402 line, sp_line_no); 402 line, sp_line_no);
403 return -1; 403 return -1;
404 } else if (df->filename && (*ZSTR_VAL(df->filename) != '/') && 404 } else if (df->filename && (*ZSTR_VAL(df->filename) != '/') &&
@@ -407,13 +407,13 @@ int parse_disabled_functions(char *line) {
407 sp_log_err( 407 sp_log_err(
408 "config", 408 "config",
409 "Invalid configuration line: 'sp.disabled_functions%s':" 409 "Invalid configuration line: 'sp.disabled_functions%s':"
410 "'.filename' must be an absolute path or a phar archive on line %zu.", 410 "'.filename' must be an absolute path or a phar archive on line %zu",
411 line, sp_line_no); 411 line, sp_line_no);
412 return -1; 412 return -1;
413 } else if (!(allow ^ drop)) { 413 } else if (!(allow ^ drop)) {
414 sp_log_err("config", 414 sp_log_err("config",
415 "Invalid configuration line: 'sp.disabled_functions%s': The " 415 "Invalid configuration line: 'sp.disabled_functions%s': The "
416 "rule must either be a `drop` or `allow` one on line %zu.", 416 "rule must either be a `drop` or `allow` one on line %zu",
417 line, sp_line_no); 417 line, sp_line_no);
418 return -1; 418 return -1;
419 } 419 }
@@ -423,7 +423,7 @@ int parse_disabled_functions(char *line) {
423 char *endptr; 423 char *endptr;
424 df->pos = (int)strtol(ZSTR_VAL(pos), &endptr, 10); 424 df->pos = (int)strtol(ZSTR_VAL(pos), &endptr, 10);
425 if (errno != 0 || endptr == ZSTR_VAL(pos)) { 425 if (errno != 0 || endptr == ZSTR_VAL(pos)) {
426 sp_log_err("config", "Failed to parse arg '%s' of `pos` on line %zu.", 426 sp_log_err("config", "Failed to parse arg '%s' of `pos` on line %zu",
427 ZSTR_VAL(pos), sp_line_no); 427 ZSTR_VAL(pos), sp_line_no);
428 return -1; 428 return -1;
429 } 429 }
@@ -434,7 +434,7 @@ int parse_disabled_functions(char *line) {
434 char *endptr; 434 char *endptr;
435 df->line = (unsigned int)strtoul(ZSTR_VAL(line_number), &endptr, 10); 435 df->line = (unsigned int)strtoul(ZSTR_VAL(line_number), &endptr, 10);
436 if (errno != 0 || endptr == ZSTR_VAL(line_number)) { 436 if (errno != 0 || endptr == ZSTR_VAL(line_number)) {
437 sp_log_err("config", "Failed to parse arg '%s' of `line` on line %zu.", 437 sp_log_err("config", "Failed to parse arg '%s' of `line` on line %zu",
438 ZSTR_VAL(line_number), sp_line_no); 438 ZSTR_VAL(line_number), sp_line_no);
439 return -1; 439 return -1;
440 } 440 }
@@ -460,7 +460,7 @@ int parse_disabled_functions(char *line) {
460 df->param = sp_parse_var(ZSTR_VAL(param)); 460 df->param = sp_parse_var(ZSTR_VAL(param));
461 } 461 }
462 if (!df->param) { 462 if (!df->param) {
463 sp_log_err("config", "Invalid value '%s' for `param` on line %zu.", 463 sp_log_err("config", "Invalid value '%s' for `param` on line %zu",
464 ZSTR_VAL(param), sp_line_no); 464 ZSTR_VAL(param), sp_line_no);
465 return -1; 465 return -1;
466 } 466 }
@@ -470,12 +470,12 @@ int parse_disabled_functions(char *line) {
470 if (ZSTR_LEN(var)) { 470 if (ZSTR_LEN(var)) {
471 df->var = sp_parse_var(ZSTR_VAL(var)); 471 df->var = sp_parse_var(ZSTR_VAL(var));
472 if (!df->var) { 472 if (!df->var) {
473 sp_log_err("config", "Invalid value '%s' for `var` on line %zu.", 473 sp_log_err("config", "Invalid value '%s' for `var` on line %zu",
474 ZSTR_VAL(var), sp_line_no); 474 ZSTR_VAL(var), sp_line_no);
475 return -1; 475 return -1;
476 } 476 }
477 } else { 477 } else {
478 sp_log_err("config", "Empty value in `var` on line %zu.", sp_line_no); 478 sp_log_err("config", "Empty value in `var` on line %zu", sp_line_no);
479 return -1; 479 return -1;
480 } 480 }
481 } 481 }
@@ -534,7 +534,7 @@ int parse_upload_validation(char *line) {
534 } 534 }
535 535
536 if (!(enable ^ disable)) { 536 if (!(enable ^ disable)) {
537 sp_log_err("config", "A rule can't be enabled and disabled on line %zu.", 537 sp_log_err("config", "A rule can't be enabled and disabled on line %zu",
538 sp_line_no); 538 sp_line_no);
539 return -1; 539 return -1;
540 } 540 }
@@ -545,15 +545,15 @@ int parse_upload_validation(char *line) {
545 545
546 if (!script) { 546 if (!script) {
547 sp_log_err("config", 547 sp_log_err("config",
548 "The `script` directive is mandatory in '%s' on line %zu.", line, 548 "The `script` directive is mandatory in '%s' on line %zu", line,
549 sp_line_no); 549 sp_line_no);
550 return -1; 550 return -1;
551 } else if (-1 == access(ZSTR_VAL(script), F_OK)) { 551 } else if (-1 == access(ZSTR_VAL(script), F_OK)) {
552 sp_log_err("config", "The `script` (%s) doesn't exist on line %zu.", 552 sp_log_err("config", "The `script` (%s) doesn't exist on line %zu",
553 ZSTR_VAL(script), sp_line_no); 553 ZSTR_VAL(script), sp_line_no);
554 return -1; 554 return -1;
555 } else if (-1 == access(ZSTR_VAL(script), X_OK)) { 555 } else if (-1 == access(ZSTR_VAL(script), X_OK)) {
556 sp_log_err("config", "The `script` (%s) isn't executable on line %zu.", 556 sp_log_err("config", "The `script` (%s) isn't executable on line %zu",
557 ZSTR_VAL(script), sp_line_no); 557 ZSTR_VAL(script), sp_line_no);
558 return -1; 558 return -1;
559 } 559 }