From aedf561f8d1ebe8517d231844c1bb94b6b552055 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Fri, 7 Aug 2020 16:04:43 +0200 Subject: [PATCH] Allow empty configuration --- src/php_snuffleupagus.h | 2 +- src/snuffleupagus.c | 31 +++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/php_snuffleupagus.h b/src/php_snuffleupagus.h index b42c300f..d5e70502 100644 --- a/src/php_snuffleupagus.h +++ b/src/php_snuffleupagus.h @@ -97,7 +97,7 @@ extern zend_module_entry snuffleupagus_module_entry; ZEND_BEGIN_MODULE_GLOBALS(snuffleupagus) size_t in_eval; sp_config config; -bool is_config_valid; +int is_config_valid; // 1 = valid, 0 = invalid, -1 = empty bool allow_broken_configuration; HashTable *disabled_functions_hook; HashTable *sp_internal_functions_hook; diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index ff2d2b6a..9372e68f 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c @@ -190,9 +190,9 @@ PHP_RINIT_FUNCTION(snuffleupagus) { ZEND_TSRMLS_CACHE_UPDATE(); #endif - if (!SNUFFLEUPAGUS_G(allow_broken_configuration) && !SNUFFLEUPAGUS_G(is_config_valid)) { - sp_log_err("config", "Invalid configuration file"); - } + if (!SNUFFLEUPAGUS_G(allow_broken_configuration) && SNUFFLEUPAGUS_G(is_config_valid) != 1) { + sp_log_err("config", "Invalid configuration file"); + } // We need to disable wrappers loaded by extensions loaded after SNUFFLEUPAGUS. if (config_wrapper->enabled && @@ -213,12 +213,22 @@ PHP_RINIT_FUNCTION(snuffleupagus) { PHP_RSHUTDOWN_FUNCTION(snuffleupagus) { return SUCCESS; } PHP_MINFO_FUNCTION(snuffleupagus) { + const char *valid_config; + switch(SNUFFLEUPAGUS_G(is_config_valid)) { + case 1: + valid_config = "yes"; + break; + case 0: + valid_config = "no"; + break; + case -1: + valid_config = "empty"; + break; + } php_info_print_table_start(); php_info_print_table_row(2, "snuffleupagus support", "enabled"); php_info_print_table_row(2, "Version", PHP_SNUFFLEUPAGUS_VERSION); - php_info_print_table_row( - 2, "Valid config", - (SNUFFLEUPAGUS_G(is_config_valid) == true) ? "yes" : "no"); + php_info_print_table_row( 2, "Valid config", valid_config); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); } @@ -227,7 +237,8 @@ static PHP_INI_MH(OnUpdateConfiguration) { TSRMLS_FETCH(); if (!new_value || !new_value->len) { - return FAILURE; + SNUFFLEUPAGUS_G(is_config_valid) = -1; + return SUCCESS; } glob_t globbuf; @@ -238,14 +249,14 @@ static PHP_INI_MH(OnUpdateConfiguration) { int ret = glob(config_file, GLOB_NOCHECK, NULL, &globbuf); if (ret != 0) { - SNUFFLEUPAGUS_G(is_config_valid) = false; + SNUFFLEUPAGUS_G(is_config_valid) = 0; globfree(&globbuf); return FAILURE; } for (size_t i = 0; globbuf.gl_pathv[i]; i++) { if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { - SNUFFLEUPAGUS_G(is_config_valid) = false; + SNUFFLEUPAGUS_G(is_config_valid) = 0; globfree(&globbuf); return FAILURE; } @@ -253,7 +264,7 @@ static PHP_INI_MH(OnUpdateConfiguration) { globfree(&globbuf); } - SNUFFLEUPAGUS_G(is_config_valid) = true; + SNUFFLEUPAGUS_G(is_config_valid) = 1; if ((SNUFFLEUPAGUS_G(config).config_sloppy->enable)) { hook_sloppy();