From: Greg Beaver Date: Sat, 20 Jan 2007 22:40:47 +0000 (+0000) Subject: implement ini handler for phar.readonly and phar.require_hash that allows enabling... X-Git-Tag: RELEASE_1_0_0RC1~184 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=773fc514578b8055f99e6900a967f885107f1702;p=php implement ini handler for phar.readonly and phar.require_hash that allows enabling it on PHP_INI_ALL if it is disabled in the system, but does not allow disabling it if it is enabled in the syste --- diff --git a/ext/phar/TODO b/ext/phar/TODO index 7de2bf197c..e1e7f6bb6c 100644 --- a/ext/phar/TODO +++ b/ext/phar/TODO @@ -1,9 +1,9 @@ Version 1.0.0 X make permissions in the lowest bits of flags to simplify using them [Greg] - * implement ini handler for phar.readonly and phar.require_hash that allows enabling it on + X implement ini handler for phar.readonly and phar.require_hash that allows enabling it on PHP_INI_ALL if it is disabled in the system, but does not allow disabling it - if it is enabled in the system + if it is enabled in the system [Greg] * implement metadata in manifest as [type32][len16][metadata...] where 0 type is used to finish metadata for this file * if SPL is disabled, disable the Phar class diff --git a/ext/phar/phar.c b/ext/phar/phar.c index e3511ab1e9..6d8eabc246 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -110,13 +110,65 @@ ZEND_BEGIN_MODULE_GLOBALS(phar) HashTable phar_alias_map; int readonly; int require_hash; + zend_bool readonly_orig; + zend_bool require_hash_orig; ZEND_END_MODULE_GLOBALS(phar) ZEND_DECLARE_MODULE_GLOBALS(phar) +/* if the original value is 0 (disabled), then allow setting/unsetting at will + otherwise, only allow 1 (enabled), and error on disabling */ +ZEND_INI_MH(phar_ini_modify_handler) +{ + zend_bool *p, test; +#ifndef ZTS + char *base = (char *) mh_arg2; +#else + char *base; + + base = (char *) ts_resource(*((int *) mh_arg2)); +#endif + + p = (zend_bool *) (base+(size_t) mh_arg1); + + if (new_value_length==2 && strcasecmp("on", new_value)==0) { + *p = (zend_bool) 1; + } + else if (new_value_length==3 && strcasecmp("yes", new_value)==0) { + *p = (zend_bool) 1; + } + else if (new_value_length==4 && strcasecmp("true", new_value)==0) { + *p = (zend_bool) 1; + } + else { + *p = (zend_bool) atoi(new_value); + } + if (stage == ZEND_INI_STAGE_STARTUP && !entry->modified) { + /* this is more efficient than processing orig_value every time */ + if (entry->name_length == 14) { /* phar.readonly */ + PHAR_G(readonly_orig) = *p; + } else { /* phar.require_hash */ + PHAR_G(require_hash_orig) = *p; + } + } + if (stage != ZEND_INI_STAGE_STARTUP) { + if (entry->name_length == 14) { /* phar.readonly */ + test = PHAR_G(readonly_orig); + } else { /* phar.require_hash */ + test = PHAR_G(require_hash_orig); + } + if (test && !*p) { + /* do not allow unsetting in runtime */ + *p = (zend_bool) 1; + return FAILURE; + } + } + return SUCCESS; +} + PHP_INI_BEGIN() - STD_PHP_INI_BOOLEAN("phar.readonly", "1", PHP_INI_SYSTEM, OnUpdateBool, readonly, zend_phar_globals, phar_globals) - STD_PHP_INI_BOOLEAN("phar.require_hash", "1", PHP_INI_SYSTEM, OnUpdateBool, require_hash, zend_phar_globals, phar_globals) + STD_PHP_INI_BOOLEAN("phar.readonly", "1", PHP_INI_ALL, phar_ini_modify_handler, readonly, zend_phar_globals, phar_globals) + STD_PHP_INI_BOOLEAN("phar.require_hash", "1", PHP_INI_ALL, phar_ini_modify_handler, require_hash, zend_phar_globals, phar_globals) PHP_INI_END() #ifndef php_uint16 diff --git a/ext/phar/tests/ini_set.phpt b/ext/phar/tests/ini_set.phpt new file mode 100644 index 0000000000..7fa9291119 --- /dev/null +++ b/ext/phar/tests/ini_set.phpt @@ -0,0 +1,28 @@ +--TEST-- +Phar - test ini_set with readonly and require_hash enabled +--SKIPIF-- + +--INI-- +phar.require_hash=1 +phar.readonly=1 +--FILE-- + +--EXPECT-- +string("1") +string("1") +string("1") +string("1") +string("1") +string("1") +string("1") +string("1") diff --git a/ext/phar/tests/ini_set_off.phpt b/ext/phar/tests/ini_set_off.phpt new file mode 100644 index 0000000000..84aee76c7d --- /dev/null +++ b/ext/phar/tests/ini_set_off.phpt @@ -0,0 +1,28 @@ +--TEST-- +Phar - test ini_set with readonly and require_hash disabled +--SKIPIF-- + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- + +--EXPECT-- +string("0") +string("0") +string("1") +string("1") +string("1") +string("1") +string("0") +string("0")