Skip to content

Commit

Permalink
Allow empty configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoisin committed Aug 7, 2020
1 parent 71721a0 commit aedf561
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/php_snuffleupagus.h
Expand Up @@ -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;
Expand Down
31 changes: 21 additions & 10 deletions src/snuffleupagus.c
Expand Up @@ -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 &&
Expand All @@ -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();
}
Expand All @@ -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;
Expand All @@ -238,22 +249,22 @@ 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;
}
}
globfree(&globbuf);
}

SNUFFLEUPAGUS_G(is_config_valid) = true;
SNUFFLEUPAGUS_G(is_config_valid) = 1;

if ((SNUFFLEUPAGUS_G(config).config_sloppy->enable)) {
hook_sloppy();
Expand Down

0 comments on commit aedf561

Please sign in to comment.