cellog Sat Jan 20 22:40:46 2007 UTC
Added files:
/pecl/phar/tests ini_set.phpt ini_set_off.phpt
Modified files:
/pecl/phar TODO phar.c
Log:
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
http://cvs.php.net/viewvc.cgi/pecl/phar/TODO?r1=1.2&r2=1.3&diff_format=u
Index: pecl/phar/TODO
diff -u pecl/phar/TODO:1.2 pecl/phar/TODO:1.3
--- pecl/phar/TODO:1.2 Sat Jan 20 05:28:47 2007
+++ pecl/phar/TODO Sat Jan 20 22:40:46 2007
@@ -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
http://cvs.php.net/viewvc.cgi/pecl/phar/phar.c?r1=1.120&r2=1.121&diff_format=u
Index: pecl/phar/phar.c
diff -u pecl/phar/phar.c:1.120 pecl/phar/phar.c:1.121
--- pecl/phar/phar.c:1.120 Sat Jan 20 16:43:44 2007
+++ pecl/phar/phar.c Sat Jan 20 22:40:46 2007
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: phar.c,v 1.120 2007/01/20 16:43:44 helly Exp $ */
+/* $Id: phar.c,v 1.121 2007/01/20 22:40:46 cellog Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -110,13 +110,65 @@
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
@@ -3120,7 +3172,7 @@
php_info_print_table_start();
php_info_print_table_header(2, "Phar: PHP Archive support", "enabled");
php_info_print_table_row(2, "Phar API version", PHAR_VERSION_STR);
- php_info_print_table_row(2, "CVS revision", "$Revision: 1.120 $");
+ php_info_print_table_row(2, "CVS revision", "$Revision: 1.121 $");
php_info_print_table_row(2, "gzip compression",
#if HAVE_ZLIB
"enabled");
http://cvs.php.net/viewvc.cgi/pecl/phar/tests/ini_set.phpt?view=markup&rev=1.1
Index: pecl/phar/tests/ini_set.phpt
+++ pecl/phar/tests/ini_set.phpt
--TEST--
Phar - test ini_set with readonly and require_hash enabled
--SKIPIF--
<?php if (!extension_loaded("phar")) print "skip";?>
--INI--
phar.require_hash=1
phar.readonly=1
--FILE--
<?php
var_dump(ini_set('phar.require_hash', 1));
var_dump(ini_set('phar.readonly', 1));
var_dump(ini_get('phar.require_hash'));
var_dump(ini_get('phar.readonly'));
var_dump(ini_set('phar.require_hash', 0));
var_dump(ini_set('phar.readonly', 0));
var_dump(ini_get('phar.require_hash'));
var_dump(ini_get('phar.readonly'));
__HALT_COMPILER();
?>
--EXPECT--
string("1")
string("1")
string("1")
string("1")
string("1")
string("1")
string("1")
string("1")
http://cvs.php.net/viewvc.cgi/pecl/phar/tests/ini_set_off.phpt?view=markup&rev=1.1
Index: pecl/phar/tests/ini_set_off.phpt
+++ pecl/phar/tests/ini_set_off.phpt
--TEST--
Phar - test ini_set with readonly and require_hash disabled
--SKIPIF--
<?php if (!extension_loaded("phar")) print "skip";?>
--INI--
phar.require_hash=0
phar.readonly=0
--FILE--
<?php
var_dump(ini_set('phar.require_hash', 1));
var_dump(ini_set('phar.readonly', 1));
var_dump(ini_get('phar.require_hash'));
var_dump(ini_get('phar.readonly'));
var_dump(ini_set('phar.require_hash', 0));
var_dump(ini_set('phar.readonly', 0));
var_dump(ini_get('phar.require_hash'));
var_dump(ini_get('phar.readonly'));
__HALT_COMPILER();
?>
--EXPECT--
string("0")
string("0")
string("1")
string("1")
string("1")
string("1")
string("0")
string("0")
|