diff options
| author | Ben Fuhrmannek | 2021-08-06 20:23:52 +0200 |
|---|---|---|
| committer | Ben Fuhrmannek | 2021-08-06 20:23:52 +0200 |
| commit | 2392c46836ceea520fa2a45369c8d638aadb943c (patch) | |
| tree | fe4b5eb10a49b2b45c4d7bc24de54fd3888c168e /src/sp_config_keywords.c | |
| parent | 260f17f112e2d081783c6dc102f81666ac2435d9 (diff) | |
implemented ini settings protection
Diffstat (limited to 'src/sp_config_keywords.c')
| -rw-r--r-- | src/sp_config_keywords.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 8080eec..e6eb05e 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c | |||
| @@ -562,3 +562,80 @@ int parse_upload_validation(char *line) { | |||
| 562 | 562 | ||
| 563 | return ret; | 563 | return ret; |
| 564 | } | 564 | } |
| 565 | |||
| 566 | int parse_ini_protection(char *line) { | ||
| 567 | bool disable = false, enable = false; | ||
| 568 | bool rw = false, ro = false; // rw is ignored, but declaring .policy_rw is valid for readability | ||
| 569 | sp_config_functions sp_config_ini_protection[] = { | ||
| 570 | {parse_empty, SP_TOKEN_ENABLE, &(enable)}, | ||
| 571 | {parse_empty, SP_TOKEN_DISABLE, &(disable)}, | ||
| 572 | {parse_empty, SP_TOKEN_SIMULATION, &(SNUFFLEUPAGUS_G(config).config_ini->simulation)}, | ||
| 573 | {parse_empty, ".policy_readonly(", &ro}, | ||
| 574 | {parse_empty, ".policy_ro(", &ro}, | ||
| 575 | {parse_empty, ".policy_readwrite(", &rw}, | ||
| 576 | {parse_empty, ".policy_rw(", &rw}, | ||
| 577 | {0, 0, 0}}; | ||
| 578 | |||
| 579 | int ret = parse_keywords(sp_config_ini_protection, line); | ||
| 580 | if (ret) { return ret; } | ||
| 581 | |||
| 582 | if (enable && disable) { | ||
| 583 | sp_log_err("config", "A rule can't be enabled and disabled on line %zu", | ||
| 584 | sp_line_no); | ||
| 585 | return -1; | ||
| 586 | } | ||
| 587 | if (enable || disable) { | ||
| 588 | SNUFFLEUPAGUS_G(config).config_ini->enable = (enable || !disable); | ||
| 589 | } | ||
| 590 | |||
| 591 | if (ro && rw) { | ||
| 592 | sp_log_err("config", "rule cannot be both read-write and read-only on line %zu", sp_line_no); | ||
| 593 | return -1; | ||
| 594 | } | ||
| 595 | SNUFFLEUPAGUS_G(config).config_ini->policy_readonly = ro; | ||
| 596 | |||
| 597 | return ret; | ||
| 598 | } | ||
| 599 | |||
| 600 | int parse_ini_entry(char *line) { | ||
| 601 | sp_ini_entry *entry = pecalloc(sizeof(sp_ini_entry), 1, 1); | ||
| 602 | bool rw = false, ro = false; | ||
| 603 | |||
| 604 | sp_config_functions sp_config_ini_protection[] = { | ||
| 605 | {parse_empty, SP_TOKEN_SIMULATION, &entry->simulation}, | ||
| 606 | {parse_str, ".key(", &entry->key}, | ||
| 607 | {parse_str, ".msg(", &entry->msg}, | ||
| 608 | {parse_str, ".set(", &entry->set}, | ||
| 609 | {parse_str, ".min(", &entry->min}, | ||
| 610 | {parse_str, ".max(", &entry->max}, | ||
| 611 | {parse_regexp, ".regexp(", &entry->regexp}, | ||
| 612 | {parse_empty, ".readonly(", &ro}, | ||
| 613 | {parse_empty, ".ro(", &ro}, | ||
| 614 | {parse_empty, ".readwrite()", &rw}, | ||
| 615 | {parse_empty, ".rw()", &rw}, | ||
| 616 | {0, 0, 0}}; | ||
| 617 | |||
| 618 | int ret = parse_keywords(sp_config_ini_protection, line); | ||
| 619 | if (ret) { goto err; } | ||
| 620 | |||
| 621 | if (!entry->key) { | ||
| 622 | sp_log_err("config", "A .key() must be provided on line %zu", sp_line_no); | ||
| 623 | ret = -1; goto err; | ||
| 624 | } | ||
| 625 | |||
| 626 | if (ro && rw) { | ||
| 627 | sp_log_err("config", "rule cannot be both read-write and read-only on line %zu", sp_line_no); | ||
| 628 | ret = -1; goto err; | ||
| 629 | } | ||
| 630 | entry->access = ro - rw; | ||
| 631 | |||
| 632 | zend_hash_add_ptr(SNUFFLEUPAGUS_G(config).config_ini->entries, entry->key, entry); | ||
| 633 | return ret; | ||
| 634 | |||
| 635 | err: | ||
| 636 | if (entry) { | ||
| 637 | sp_free_ini_entry(entry); | ||
| 638 | pefree(entry, 1); | ||
| 639 | } | ||
| 640 | return ret; | ||
| 641 | } \ No newline at end of file | ||
