From: Marcus Boerger Date: Sun, 28 Jan 2007 10:32:45 +0000 (+0000) Subject: - Fix read/write mode handling X-Git-Tag: RELEASE_1_0_0RC1~98 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e1db72467c278b1281eb88f8bce26730ea63d07e;p=php - Fix read/write mode handling --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index ef6843639d..9b49517237 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -912,7 +912,9 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al } if (phar_open_loaded(fname, fname_len, alias, alias_len, options, pphar TSRMLS_CC) == SUCCESS) { - (*pphar)->is_writeable = 1; + if (!PHAR_G(readonly)) { + (*pphar)->is_writeable = 1; + } return SUCCESS; } @@ -926,10 +928,12 @@ int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int al return FAILURE; } - fp = php_stream_open_wrapper(fname, "r+b", IGNORE_URL|STREAM_MUST_SEEK|0, NULL); + fp = php_stream_open_wrapper(fname, PHAR_G(readonly)?"rb":"r+b", IGNORE_URL|STREAM_MUST_SEEK|0, NULL); if (fp && phar_open_fp(fp, fname, fname_len, alias, alias_len, options, pphar TSRMLS_CC) == SUCCESS) { - (*pphar)->is_writeable = 1; + if (!PHAR_G(readonly)) { + (*pphar)->is_writeable = 1; + } return SUCCESS; } @@ -1142,6 +1146,11 @@ static php_url* phar_open_url(php_stream_wrapper *wrapper, char *filename, char } #endif if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) { + if (PHAR_G(readonly)) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: write operations disabled by INI setting"); + php_url_free(resource); + return NULL; + } if (phar_open_or_create_filename(resource->host, arch_len, NULL, 0, options, NULL TSRMLS_CC) == FAILURE) { php_url_free(resource); @@ -2232,7 +2241,7 @@ static void phar_dostat(phar_archive_data *phar, phar_entry_info *data, php_stre ssb->sb.st_ctime = phar->max_timestamp; #endif } - if (PHAR_G(readonly)) { + if (!phar->is_writeable) { ssb->sb.st_mode = (ssb->sb.st_mode & 0555) | (ssb->sb.st_mode & ~0777); } diff --git a/ext/phar/tests/create_new_phar_b.phpt b/ext/phar/tests/create_new_phar_b.phpt index 9cf86fc177..4f0601be10 100755 --- a/ext/phar/tests/create_new_phar_b.phpt +++ b/ext/phar/tests/create_new_phar_b.phpt @@ -18,7 +18,7 @@ include 'phar://' . dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.pha --EXPECTF-- -Warning: file_put_contents(phar://%screate_new_phar_b.phar.php/a.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d +Warning: file_put_contents(phar://%screate_new_phar_b.phar.php/a.php): failed to open stream: phar error: write operations disabled by INI setting in %screate_new_phar_b.php on line %d Warning: include(%screate_new_phar_b.phar.php): failed to open stream: No such file or directory in %screate_new_phar_b.php on line %d diff --git a/ext/phar/tests/open_for_write_existing_b.phpt b/ext/phar/tests/open_for_write_existing_b.phpt index fbfce79c41..a4f4d03092 100755 --- a/ext/phar/tests/open_for_write_existing_b.phpt +++ b/ext/phar/tests/open_for_write_existing_b.phpt @@ -32,8 +32,8 @@ include $pname . '/b/c.php'; --CLEAN-- --EXPECTF-- -Warning: fopen(phar://%sopen_for_write_existing_b.phar.php/b/c.php): failed to open stream: phar error: file "%sopen_for_write_existing_b.phar.php" cannot opened for writing, disabled by ini setting -phar error: file "b/c.php" could not be created in phar "%sopen_for_write_existing_b.phar.php" in %sopen_for_write_existing_b.php on line %d + +Warning: fopen(phar://%sopen_for_write_existing_b.phar.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_b.php on line %d Warning: fwrite(): supplied argument is not a valid stream resource in %spen_for_write_existing_b.php on line %d diff --git a/ext/phar/tests/open_for_write_existing_c.phpt b/ext/phar/tests/open_for_write_existing_c.phpt index 1733cea584..b7a61c7b0b 100755 --- a/ext/phar/tests/open_for_write_existing_c.phpt +++ b/ext/phar/tests/open_for_write_existing_c.phpt @@ -26,8 +26,8 @@ include $pname . '/b/c.php'; --CLEAN-- --EXPECTF-- -Warning: fopen(phar://%sopen_for_write_existing_c.phar.php/b/c.php): failed to open stream: phar error: file "%sopen_for_write_existing_c.phar.php" cannot opened for writing, disabled by ini setting -phar error: file "b/c.php" could not be created in phar "%sopen_for_write_existing_c.phar.php" in %sopen_for_write_existing_c.php on line %d + +Warning: fopen(phar://%sopen_for_write_existing_c.phar.php/b/c.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_existing_c.php on line %d Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_existing_c.php on line %d diff --git a/ext/phar/tests/open_for_write_newfile_b.phpt b/ext/phar/tests/open_for_write_newfile_b.phpt index b62158201a..3ee7b70947 100755 --- a/ext/phar/tests/open_for_write_newfile_b.phpt +++ b/ext/phar/tests/open_for_write_newfile_b.phpt @@ -35,8 +35,7 @@ include $pname . '/b/new.php'; --EXPECTF-- -Warning: fopen(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: file "%sopen_for_write_newfile_b.phar.php" cannot opened for writing, disabled by ini setting -phar error: file "b/new.php" could not be created in phar "%sopen_for_write_newfile_b.phar.php" in %sopen_for_write_newfile_b.php on line %d +Warning: fopen(phar://%sopen_for_write_newfile_b.phar.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_b.php on line %d Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_b.php on line %d diff --git a/ext/phar/tests/open_for_write_newfile_c.phpt b/ext/phar/tests/open_for_write_newfile_c.phpt index c4242bdb2e..ce0562b48c 100755 --- a/ext/phar/tests/open_for_write_newfile_c.phpt +++ b/ext/phar/tests/open_for_write_newfile_c.phpt @@ -28,8 +28,8 @@ include $pname . '/b/new.php'; --CLEAN-- --EXPECTF-- -Warning: fopen(phar://%sopen_for_write_newfile_c.phar.php/b/new.php): failed to open stream: phar error: file "%sopen_for_write_newfile_c.phar.php" cannot opened for writing, disabled by ini setting -phar error: file "b/new.php" could not be created in phar "%sopen_for_write_newfile_c.phar.php" in %sopen_for_write_newfile_c.php on line %d + +Warning: fopen(phar://%sopen_for_write_newfile_c.phar.php/b/new.php): failed to open stream: phar error: write operations disabled by INI setting in %sopen_for_write_newfile_c.php on line %d Warning: fwrite(): supplied argument is not a valid stream resource in %sopen_for_write_newfile_c.php on line %d diff --git a/ext/phar/tests/phar_oo_002.phpt b/ext/phar/tests/phar_oo_002.phpt index d2769b034b..080df2c61a 100755 --- a/ext/phar/tests/phar_oo_002.phpt +++ b/ext/phar/tests/phar_oo_002.phpt @@ -4,6 +4,7 @@ Phar object: iterator & entries --INI-- +phar.readonly=1 phar.require_hash=0 --FILE--