]> granicus.if.org Git - php/commitdiff
Avoid file clash in root_check skipifs
authorFabien Villepinte <fabien.villepinte@gmail.com>
Sat, 5 Oct 2019 12:26:33 +0000 (14:26 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 8 Oct 2019 16:20:13 +0000 (18:20 +0200)
Extract root check into skipif_root.inc to share this commonly
repeated logic.

Closes GH-4779.

34 files changed:
ext/sockets/tests/socket_create_listen-nobind.phpt
ext/sockets/tests/socket_set_option_error_socket_option.phpt
ext/standard/tests/dir/dir_variation3.phpt
ext/standard/tests/dir/dir_variation7.phpt
ext/standard/tests/dir/opendir_variation5.phpt
ext/standard/tests/dir/opendir_variation7.phpt
ext/standard/tests/dir/readdir_variation5.phpt
ext/standard/tests/dir/scandir_variation5.phpt
ext/standard/tests/dir/scandir_variation7.phpt
ext/standard/tests/file/006_basic.phpt
ext/standard/tests/file/006_error.phpt
ext/standard/tests/file/006_variation1.phpt
ext/standard/tests/file/006_variation2.phpt
ext/standard/tests/file/copy_variation15.phpt
ext/standard/tests/file/copy_variation9.phpt
ext/standard/tests/file/is_executable_basic.phpt
ext/standard/tests/file/is_executable_variation2.phpt
ext/standard/tests/file/is_executable_variation3.phpt
ext/standard/tests/file/is_readable_basic.phpt
ext/standard/tests/file/is_readable_variation1.phpt
ext/standard/tests/file/is_readable_variation2.phpt
ext/standard/tests/file/is_readable_variation3.phpt
ext/standard/tests/file/is_writable_basic.phpt
ext/standard/tests/file/is_writable_variation1.phpt
ext/standard/tests/file/is_writable_variation2.phpt
ext/standard/tests/file/is_writable_variation3.phpt
ext/standard/tests/file/lchown_error.phpt
ext/standard/tests/file/mkdir_rmdir_variation1.phpt
ext/standard/tests/file/mkdir_rmdir_variation2.phpt
ext/standard/tests/file/symlink_link_linkinfo_is_link_variation6.phpt
ext/standard/tests/file/tempnam_variation4-0.phpt
ext/standard/tests/file/tempnam_variation4-1.phpt
ext/standard/tests/file/unlink_variation1.phpt
ext/standard/tests/skipif_root.inc [new file with mode: 0644]

index 81e7297339d01c81f140a9169e5d6675a5a029db..d6a9a767a3276c55a035fb3da5aa2fbd663e31f6 100644 (file)
@@ -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
index 18afcc8fb1411ee2d54d8cd010ecc0eb60b9c185..53d76fa4c1153bacde7829b5105f62b01be95504 100644 (file)
@@ -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--
index 041304eba42c81f17fea3f0d5bb38d03a5cbbfdc..b79b2befe4ecaa2e194a06a889755b3a4de3561c 100644 (file)
@@ -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
index e069043fe33c98cc75bfaaaaa0d96239b223598c..c2e6519dfede987afbf5d48d9e71ee908eee1a4e 100644 (file)
@@ -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
index ac129302800ea17ae4612dba43481f0436c96cdb..937911227c40b15e8ed24989cfb9508542a5957d 100644 (file)
@@ -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
index d468f27008aef0b33aab4e301627586df8b56911..d781c4f538403093d6c4010d9cc3edd5c99849b7 100644 (file)
@@ -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
index 575a4000ac692481508a04dbf9d06d7f94c7738a..72ec24a9d8f1ca0966b9b7918f549a5c5ce2951f 100644 (file)
@@ -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
index 47539c493f62f063df77496934d9d2b4ba85474b..189687f1d0cf2a60467e4f2666b519831fbc9b18 100644 (file)
@@ -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
index b0305a6e03741e99dfcf7fba455a85118091f4af..bd0cb74a15b58c3df3e9e19611f7b324e3f9e098 100644 (file)
@@ -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
index 553e8445f17b8e8bd37105693401fbd208583be2..43c9b86ab0363847943cf251d93b093e0f9e35bf 100644 (file)
@@ -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
index 0e95f8056e2f1ff76feeaa983094c59e34a84110..9451a3e18be461b7a76900bf1c84189e347316e6 100644 (file)
@@ -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
index 102bc28432d1f51da21d9cdf4ea3ea67edcb2505..5a90ea6fb33d6e184a1d07e16311f35a92bd91e5 100644 (file)
@@ -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
index cba524882f627346e9e631adac5385a670e266f7..6e87d24675c8f99fedb304e7073d5f27e14500dd 100644 (file)
@@ -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
index a641a8675a8b373c861ddd8c7f2d088e00793d2d..6b52eb7f9b938b02ffad5efdc00b44339e58f92b 100644 (file)
@@ -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
index c0651a737552c86ef07e50e2356700fc2832c29c..2c1005ec646a68d77ba2974a15f89e3ce6cee32a 100644 (file)
@@ -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
index ef2d2388cf349e863bf13f9a6659c60b6752bfe2..6c78d2be0333faf0e8a37ea8da9ef0e9d9b78ae4 100644 (file)
@@ -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
index 935b5548f29943c7da88d40cf4b445a6d19ca4e5..5b07f683d3631f64a67df12e5d9935ad3698c9f0 100644 (file)
@@ -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
index 5051504be9e8c5863e71aaa1a957fc7a4640172f..1a71a5a005226b25c266f5181ea4c92602519995 100644 (file)
@@ -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
index 5df3e36dddde4c42e9184e31e98ce4714b3a61b6..a3f72a30489cd4a1367d5a733c28b0452f49a5e2 100644 (file)
@@ -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
index c00c01cac796e8608ab33404c37be81ef2500bd5..60729b5ac2f5687e341650ec8de0e637f0491f4c 100644 (file)
@@ -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
index dccee47c92a935689678267cc8a4917a41ddfe5a..1dd4ffd06a5bf082f8f5bac0aedc86aae86c8ec2 100644 (file)
@@ -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
index 0821bfe4cd2507dac6077aab4206b2dab49b754e..c73a28520fe13f613d8d80ed95bd4430984a7766 100644 (file)
@@ -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
index ad0660bdfd90aeb67bd71f87e94da8cd33f4f87e..ba6676836d38208bd999299785bcf3b09996904a 100644 (file)
@@ -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
index 31187b66d0cfe0839d6985e7d1cbaffc6e5c363f..6ce05f172e67c68722e985e767a1a88b40863d74 100644 (file)
@@ -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
index eb75cf895f46002409a8e1fd08b43c8cb52ef63d..def45bd2a0b118bc8a52ed1f8965f03516ae2580 100644 (file)
@@ -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
index f682bd329294db50cd8902fb86c770f0255e46c4..305bebef8f5e5c9c918ed0c7bb4905cfdcc99e57 100644 (file)
@@ -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
index fd54b482b3b379f4c91dd496e1819c36c6e0d0e9..dbd9a7bbe8bc7461f4bb3cedc5aa4a107b8a0861 100644 (file)
@@ -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
index 94573646438db516b79029f02adb0f8d9f60ccc5..6fe177250cd8541a90a10b365f294528f8decc08 100644 (file)
@@ -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
index d9e041fa28fdef86b5741bafb03a5cceb0bc91f0..22c055ddb577bb582a2a44a3cd3023eee8706895 100644 (file)
@@ -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
index 3a829580eadf9a68c2bfb03a02098435b2c7f440..8095972b73c7339a8a116ef0f79a8cdfbd21fdf4 100644 (file)
@@ -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
index 4232ef0b085b7a6c30009f1bcd66b9cdb0cf168a..646179beca6594dc2be9f64a834d4c50306b891d 100644 (file)
@@ -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
index 48d450d9222347765166587b54ce7af77df4d0ef..b614404c94d7bcf2fe540241de3f8c191012a030 100644 (file)
@@ -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
index 0ce7cdf74fa6b1626cc439998c90ae7d43cef344..1c4569a5fd0670481871a8727189318467e23b42 100644 (file)
@@ -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 (file)
index 0000000..d43cae8
--- /dev/null
@@ -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');
+}
+