diff options
| author | Fabien Villepinte <fabien.villepinte@gmail.com> | 2019-10-05 14:26:33 +0200 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-10-08 18:20:13 +0200 |
| commit | 8b5c351154284a88152ee3d166a32dc77316a658 (patch) | |
| tree | e38e10fe7b65983618ae29a290adea19a97f005d | |
| parent | bea832cbf6b7a06ee65b93902233864c1ac9ec98 (diff) | |
| download | php-git-8b5c351154284a88152ee3d166a32dc77316a658.tar.gz | |
Avoid file clash in root_check skipifs
Extract root check into skipif_root.inc to share this commonly
repeated logic.
Closes GH-4779.
34 files changed, 53 insertions, 320 deletions
diff --git a/ext/sockets/tests/socket_create_listen-nobind.phpt b/ext/sockets/tests/socket_create_listen-nobind.phpt index 81e7297339..d6a9a767a3 100644 --- a/ext/sockets/tests/socket_create_listen-nobind.phpt +++ b/ext/sockets/tests/socket_create_listen-nobind.phpt @@ -5,13 +5,14 @@ Test if socket_create_listen() returns false, when it cannot bind to the port. if (!extension_loaded('sockets')) { die('SKIP The sockets extension is not loaded.'); } -$filename = __DIR__ . '/006_root_check.tmp'; +$filename = __FILE__ . '.root_check.tmp'; $fp = fopen($filename, 'w'); fclose($fp); if (fileowner($filename) == 0) { - unlink ($filename); + unlink($filename); die('SKIP Test cannot be run as root.'); } +unlink($filename); if (@socket_create_listen(80)) { die('SKIP Test cannot be run in environment that will allow binding to port 80 (azure)'); } @@ -20,9 +21,6 @@ if (@socket_create_listen(80)) { $sock = socket_create_listen(80); --EXPECTF-- Warning: socket_create_listen(): unable to bind to given address [13]: Permission denied in %s on line %d ---CLEAN-- -<?php -unlink(__DIR__ . '/006_root_check.tmp'); --CREDITS-- Till Klampaeckel, till@php.net PHP Testfest Berlin 2009-05-09 diff --git a/ext/sockets/tests/socket_set_option_error_socket_option.phpt b/ext/sockets/tests/socket_set_option_error_socket_option.phpt index 18afcc8fb1..53d76fa4c1 100644 --- a/ext/sockets/tests/socket_set_option_error_socket_option.phpt +++ b/ext/sockets/tests/socket_set_option_error_socket_option.phpt @@ -8,13 +8,14 @@ if (!extension_loaded('sockets')) { if (PHP_OS == 'Darwin') { die('skip Not for OSX'); } -$filename = __DIR__ . '/006_root_check.tmp'; +$filename = __FILE__ . '.root_check.tmp'; $fp = fopen($filename, 'w'); fclose($fp); if (fileowner($filename) == 0) { - unlink ($filename); + unlink($filename); die('SKIP Test cannot be run as root.'); } +unlink($filename); ?> --FILE-- <?php @@ -26,9 +27,6 @@ if (!$socket) { socket_set_option( $socket, SOL_SOCKET, 1, 1); socket_close($socket); ?> ---CLEAN-- -<?php -unlink(__DIR__ . '/006_root_check.tmp'); --EXPECTF-- Warning: socket_set_option(): unable to set socket option [%d]: Permission denied in %s on line %d --CREDITS-- diff --git a/ext/standard/tests/dir/dir_variation3.phpt b/ext/standard/tests/dir/dir_variation3.phpt index 041304eba4..b79b2befe4 100644 --- a/ext/standard/tests/dir/dir_variation3.phpt +++ b/ext/standard/tests/dir/dir_variation3.phpt @@ -5,15 +5,7 @@ Test dir() function : usage variations - different directory permissions if( substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not for Windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/dir_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip...cannot be run as root\n'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/dir/dir_variation7.phpt b/ext/standard/tests/dir/dir_variation7.phpt index e069043fe3..c2e6519dfe 100644 --- a/ext/standard/tests/dir/dir_variation7.phpt +++ b/ext/standard/tests/dir/dir_variation7.phpt @@ -5,15 +5,7 @@ Test dir() function : usage variations - directories with restricted permissions if( substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not for Windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/dir_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip...cannot be run as root\n'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/dir/opendir_variation5.phpt b/ext/standard/tests/dir/opendir_variation5.phpt index ac12930280..937911227c 100644 --- a/ext/standard/tests/dir/opendir_variation5.phpt +++ b/ext/standard/tests/dir/opendir_variation5.phpt @@ -5,15 +5,7 @@ Test opendir() function : usage variations - directories with restricted permiss if( substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not for Windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/dir_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip...cannot be run as root\n'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/dir/opendir_variation7.phpt b/ext/standard/tests/dir/opendir_variation7.phpt index d468f27008..d781c4f538 100644 --- a/ext/standard/tests/dir/opendir_variation7.phpt +++ b/ext/standard/tests/dir/opendir_variation7.phpt @@ -5,15 +5,7 @@ Test opendir() function : usage variations - different directory permissions if( substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not for Windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__ . "/opendir_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip...cannot be run as root\n'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/dir/readdir_variation5.phpt b/ext/standard/tests/dir/readdir_variation5.phpt index 575a4000ac..72ec24a9d8 100644 --- a/ext/standard/tests/dir/readdir_variation5.phpt +++ b/ext/standard/tests/dir/readdir_variation5.phpt @@ -5,15 +5,7 @@ Test readdir() function : usage variations - different permissions if( substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not for Windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/readdir_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip...cannot be run as root\n'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/dir/scandir_variation5.phpt b/ext/standard/tests/dir/scandir_variation5.phpt index 47539c493f..189687f1d0 100644 --- a/ext/standard/tests/dir/scandir_variation5.phpt +++ b/ext/standard/tests/dir/scandir_variation5.phpt @@ -5,15 +5,7 @@ Test scandir() function : usage variations - different directory permissions if( substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not for Windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/dir_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip...cannot be run as root\n'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/dir/scandir_variation7.phpt b/ext/standard/tests/dir/scandir_variation7.phpt index b0305a6e03..bd0cb74a15 100644 --- a/ext/standard/tests/dir/scandir_variation7.phpt +++ b/ext/standard/tests/dir/scandir_variation7.phpt @@ -5,15 +5,7 @@ Test scandir() function : usage variations - different directory permissions if( substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not for Windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__ . "/dir_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip...cannot be run as root\n'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/006_basic.phpt b/ext/standard/tests/file/006_basic.phpt index 553e8445f1..43c9b86ab0 100644 --- a/ext/standard/tests/file/006_basic.phpt +++ b/ext/standard/tests/file/006_basic.phpt @@ -5,17 +5,7 @@ Test fileperms() & chmod() functions: basic functionality if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not on Windows'); } -// Skip if being run by root -$filename = __DIR__."/006_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); - +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/006_error.phpt b/ext/standard/tests/file/006_error.phpt index 0e95f8056e..9451a3e18b 100644 --- a/ext/standard/tests/file/006_error.phpt +++ b/ext/standard/tests/file/006_error.phpt @@ -5,17 +5,7 @@ Test fileperms(), chmod() functions: error conditions if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not on Windows'); } -// Skip if being run by root -$filename = __DIR__."/006_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); - +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/006_variation1.phpt b/ext/standard/tests/file/006_variation1.phpt index 102bc28432..5a90ea6fb3 100644 --- a/ext/standard/tests/file/006_variation1.phpt +++ b/ext/standard/tests/file/006_variation1.phpt @@ -5,17 +5,7 @@ Test fileperms() & chmod() functions: usage variation - perms(0000-0777) if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not on Windows'); } -// Skip if being run by root -$filename = __DIR__."/006_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); - +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/006_variation2.phpt b/ext/standard/tests/file/006_variation2.phpt index cba524882f..6e87d24675 100644 --- a/ext/standard/tests/file/006_variation2.phpt +++ b/ext/standard/tests/file/006_variation2.phpt @@ -5,17 +5,7 @@ Test fileperms() & chmod() functions: usage variation - misc. perms if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not on Windows'); } -// Skip if being run by root -$filename = __DIR__."/006_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); - +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/copy_variation15.phpt b/ext/standard/tests/file/copy_variation15.phpt index a641a8675a..6b52eb7f9b 100644 --- a/ext/standard/tests/file/copy_variation15.phpt +++ b/ext/standard/tests/file/copy_variation15.phpt @@ -4,15 +4,7 @@ Test copy() function: usage variations - destination dir access perms <?php if(substr(PHP_OS, 0, 3) == 'WIN') die("skip do not run on Windows"); -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/copy_variation15_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/copy_variation9.phpt b/ext/standard/tests/file/copy_variation9.phpt index c0651a7375..2c1005ec64 100644 --- a/ext/standard/tests/file/copy_variation9.phpt +++ b/ext/standard/tests/file/copy_variation9.phpt @@ -4,16 +4,7 @@ Test copy() function: usage variations - destination file access perms <?php if(substr(PHP_OS, 0, 3) == 'WIN') die("skip do not run on Windows"); - -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/copy_variation9_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_executable_basic.phpt b/ext/standard/tests/file/is_executable_basic.phpt index ef2d2388cf..6c78d2be03 100644 --- a/ext/standard/tests/file/is_executable_basic.phpt +++ b/ext/standard/tests/file/is_executable_basic.phpt @@ -5,16 +5,7 @@ Test is_executable() function: basic functionality if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip not for windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/is_executable_basic_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_executable_variation2.phpt b/ext/standard/tests/file/is_executable_variation2.phpt index 935b5548f2..5b07f683d3 100644 --- a/ext/standard/tests/file/is_executable_variation2.phpt +++ b/ext/standard/tests/file/is_executable_variation2.phpt @@ -5,16 +5,7 @@ Test is_executable() function: usage variations - file/dir with diff. perms if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip not for windows'); } -// Skip if being run by root -$filename = __DIR__."/is_executable_variation2_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_executable_variation3.phpt b/ext/standard/tests/file/is_executable_variation3.phpt index 5051504be9..1a71a5a005 100644 --- a/ext/standard/tests/file/is_executable_variation3.phpt +++ b/ext/standard/tests/file/is_executable_variation3.phpt @@ -5,16 +5,7 @@ Test is_executable() function: usage variations - invalid file names if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip not for windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/is_executable_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_readable_basic.phpt b/ext/standard/tests/file/is_readable_basic.phpt index 5df3e36ddd..a3f72a3048 100644 --- a/ext/standard/tests/file/is_readable_basic.phpt +++ b/ext/standard/tests/file/is_readable_basic.phpt @@ -5,16 +5,7 @@ Test is_readable() function: basic functionality if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip not for windows'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/is_readable_basic_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_readable_variation1.phpt b/ext/standard/tests/file/is_readable_variation1.phpt index c00c01cac7..60729b5ac2 100644 --- a/ext/standard/tests/file/is_readable_variation1.phpt +++ b/ext/standard/tests/file/is_readable_variation1.phpt @@ -2,17 +2,7 @@ Test is_readable() function: usage variations - diff. file notations --SKIPIF-- <?php -if (substr(PHP_OS, 0, 3) != 'WIN') { - // Skip if being run by root (files are always readable, writeable and executable) - $filename = __DIR__."/is_readable_variation1_root_check.tmp"; - $fp = fopen($filename, 'w'); - fclose($fp); - if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); - } - unlink($filename); -} +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_readable_variation2.phpt b/ext/standard/tests/file/is_readable_variation2.phpt index dccee47c92..1dd4ffd06a 100644 --- a/ext/standard/tests/file/is_readable_variation2.phpt +++ b/ext/standard/tests/file/is_readable_variation2.phpt @@ -5,15 +5,7 @@ Test is_readable() function: usage variations - file/dir with diff. perms if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip not for windows'); } -// Skip if being run by root -$filename = __DIR__."/is_readable_variation2_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_readable_variation3.phpt b/ext/standard/tests/file/is_readable_variation3.phpt index 0821bfe4cd..c73a28520f 100644 --- a/ext/standard/tests/file/is_readable_variation3.phpt +++ b/ext/standard/tests/file/is_readable_variation3.phpt @@ -2,18 +2,7 @@ Test is_readable() function: usage variations - invalid file names --SKIPIF-- <?php -if (substr(PHP_OS, 0, 3) != 'WIN') { - - // Skip if being run by root (files are always readable, writeable and executable) - $filename = __DIR__."/is_readable_variation3_root_check.tmp"; - $fp = fopen($filename, 'w'); - fclose($fp); - if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); - } - unlink($filename); -} +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_writable_basic.phpt b/ext/standard/tests/file/is_writable_basic.phpt index ad0660bdfd..ba6676836d 100644 --- a/ext/standard/tests/file/is_writable_basic.phpt +++ b/ext/standard/tests/file/is_writable_basic.phpt @@ -2,16 +2,7 @@ Test is_writable() and its alias is_writeable() function: basic functionality --SKIPIF-- <?php -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/is_writable_basic_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_writable_variation1.phpt b/ext/standard/tests/file/is_writable_variation1.phpt index 31187b66d0..6ce05f172e 100644 --- a/ext/standard/tests/file/is_writable_variation1.phpt +++ b/ext/standard/tests/file/is_writable_variation1.phpt @@ -2,19 +2,7 @@ Test is_writable() and its alias is_writeable() function: usage variations - diff. path notations --SKIPIF-- <?php -if (substr(PHP_OS, 0, 3) != 'WIN') { - - // Skip if being run by root (files are always readable, writeable and executable) - $filename = __DIR__."/is_writable_root_check.tmp"; - $fp = fopen($filename, 'w'); - fclose($fp); - if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); - } - - unlink($filename); -} +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_writable_variation2.phpt b/ext/standard/tests/file/is_writable_variation2.phpt index eb75cf895f..def45bd2a0 100644 --- a/ext/standard/tests/file/is_writable_variation2.phpt +++ b/ext/standard/tests/file/is_writable_variation2.phpt @@ -5,16 +5,7 @@ Test is_writable() and its alias is_writeable() function: usage variations - fil if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip.. only on LINUX'); } -// Skip if being run by root -$filename = __DIR__."/is_writable_variation2_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink ($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/is_writable_variation3.phpt b/ext/standard/tests/file/is_writable_variation3.phpt index f682bd3292..305bebef8f 100644 --- a/ext/standard/tests/file/is_writable_variation3.phpt +++ b/ext/standard/tests/file/is_writable_variation3.phpt @@ -2,17 +2,7 @@ Test is_writable() and its alias is_writeable() function: usage variations - invalid file names --SKIPIF-- <?php -if (substr(PHP_OS, 0, 3) != 'WIN') { - // Skip if being run by root (files are always readable, writeable and executable) - $filename = __DIR__."/is_writable_root_check.tmp"; - $fp = fopen($filename, 'w'); - fclose($fp); - if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); - } - unlink($filename); -} +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/lchown_error.phpt b/ext/standard/tests/file/lchown_error.phpt index fd54b482b3..dbd9a7bbe8 100644 --- a/ext/standard/tests/file/lchown_error.phpt +++ b/ext/standard/tests/file/lchown_error.phpt @@ -4,15 +4,7 @@ Test lchown() function : error functionality <?php if (substr(PHP_OS, 0, 3) == 'WIN') die('skip no windows support'); if (!function_exists("posix_getuid")) die("skip no posix_getuid()"); -// Skip if being run by root -$filename = __DIR__."/lchow_error_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/mkdir_rmdir_variation1.phpt b/ext/standard/tests/file/mkdir_rmdir_variation1.phpt index 9457364643..6fe177250c 100644 --- a/ext/standard/tests/file/mkdir_rmdir_variation1.phpt +++ b/ext/standard/tests/file/mkdir_rmdir_variation1.phpt @@ -5,16 +5,7 @@ Test mkdir() and rmdir() functions: usage variations - perms(0000-0777) if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip.. only on LINUX'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/mkdir_rmdir_variation1_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/mkdir_rmdir_variation2.phpt b/ext/standard/tests/file/mkdir_rmdir_variation2.phpt index d9e041fa28..22c055ddb5 100644 --- a/ext/standard/tests/file/mkdir_rmdir_variation2.phpt +++ b/ext/standard/tests/file/mkdir_rmdir_variation2.phpt @@ -5,16 +5,7 @@ Test mkdir() and rmdir() functions: usage variations - misc. if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip.. only on LINUX'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/mkdir_rmdir_variation2_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/symlink_link_linkinfo_is_link_variation6.phpt b/ext/standard/tests/file/symlink_link_linkinfo_is_link_variation6.phpt index 3a829580ea..8095972b73 100644 --- a/ext/standard/tests/file/symlink_link_linkinfo_is_link_variation6.phpt +++ b/ext/standard/tests/file/symlink_link_linkinfo_is_link_variation6.phpt @@ -5,17 +5,7 @@ Test symlink(), linkinfo(), link() and is_link() functions : usage variations - if ( substr(PHP_OS, 0, 3) == 'WIN' ) { die('skip no symlinks on Windows'); } - -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/symlink_link_linkinfo_is_link6_check_root.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/tempnam_variation4-0.phpt b/ext/standard/tests/file/tempnam_variation4-0.phpt index 4232ef0b08..646179beca 100644 --- a/ext/standard/tests/file/tempnam_variation4-0.phpt +++ b/ext/standard/tests/file/tempnam_variation4-0.phpt @@ -5,15 +5,7 @@ Test tempnam() function: usage variations - permissions(0000 to 0350) of dir if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not valid for Windows'); } -// Skip if being run by root -$filename = __DIR__."/tempnam_variation4-0_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/tempnam_variation4-1.phpt b/ext/standard/tests/file/tempnam_variation4-1.phpt index 48d450d922..b614404c94 100644 --- a/ext/standard/tests/file/tempnam_variation4-1.phpt +++ b/ext/standard/tests/file/tempnam_variation4-1.phpt @@ -5,15 +5,7 @@ Test tempnam() function: usage variations - permissions(0351 to 0777) of dir if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip Not valid for Windows'); } -// Skip if being run by root -$filename = __DIR__."/tempnam_variation4-1_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/file/unlink_variation1.phpt b/ext/standard/tests/file/unlink_variation1.phpt index 0ce7cdf74f..1c4569a5fd 100644 --- a/ext/standard/tests/file/unlink_variation1.phpt +++ b/ext/standard/tests/file/unlink_variation1.phpt @@ -5,16 +5,7 @@ Test unlink() function : usage variations - unlinking file in a directory if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip only on Linux'); } -// Skip if being run by root (files are always readable, writeable and executable) -$filename = __DIR__."/unlink_root_check.tmp"; -$fp = fopen($filename, 'w'); -fclose($fp); -if(fileowner($filename) == 0) { - unlink ($filename); - die('skip cannot be run as root'); -} - -unlink($filename); +require __DIR__ . '/../skipif_root.inc'; ?> --FILE-- <?php diff --git a/ext/standard/tests/skipif_root.inc b/ext/standard/tests/skipif_root.inc new file mode 100644 index 0000000000..d43cae8674 --- /dev/null +++ b/ext/standard/tests/skipif_root.inc @@ -0,0 +1,16 @@ +<?php + +// Skip if being run by root (files are always readable, writeable and executable) +$filename = @tempnam(__DIR__, 'root_check_'); +if (!file_exists($filename)) { + die('WARN Unable to create the "root check" file'); +} + +$isRoot = fileowner($filename) == 0; + +unlink($filename); + +if ($isRoot) { + die('SKIP Cannot be run as root'); +} + |
