Skip to content

Commit 28b73af

Browse files
author
Raghubansh Kumar
committed
better check for root user
1 parent fd78465 commit 28b73af

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

ext/standard/tests/file/006_basic.phpt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ Test fileperms() & chmod() functions: basic functionality
55
if (substr(PHP_OS, 0, 3) == 'WIN') {
66
die('skip Not on Windows');
77
}
8-
elseif (get_current_user() == 'root') {
9-
die( "skip Do not run with root permissions" );
8+
// Skip if being run by root
9+
$filename = dirname(__FILE__)."/006_root_check.tmp";
10+
$fp = fopen($filename, 'w');
11+
fclose($fp);
12+
if(fileowner($filename) == 0) {
13+
unlink ($filename);
14+
die('skip...cannot be run as root\n');
1015
}
16+
17+
unlink($filename);
18+
1119
?>
1220
--FILE--
1321
<?php

ext/standard/tests/file/006_variation1.phpt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ Test fileperms() & chmod() functions: usage variation - perms(0000-0777)
55
if (substr(PHP_OS, 0, 3) == 'WIN') {
66
die('skip Not on Windows');
77
}
8-
elseif (get_current_user() == 'root') {
9-
die( "skip Do not run with root permissions" );
8+
// Skip if being run by root
9+
$filename = dirname(__FILE__)."/006_root_check.tmp";
10+
$fp = fopen($filename, 'w');
11+
fclose($fp);
12+
if(fileowner($filename) == 0) {
13+
unlink ($filename);
14+
die('skip...cannot be run as root\n');
1015
}
16+
17+
unlink($filename);
18+
1119
?>
1220
--FILE--
1321
<?php

ext/standard/tests/file/006_variation2.phpt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ Test fileperms() & chmod() functions: usage variation - misc. perms
55
if (substr(PHP_OS, 0, 3) == 'WIN') {
66
die('skip Not on Windows');
77
}
8-
elseif (get_current_user() == 'root') {
9-
die( "skip Do not run with root permissions" );
8+
// Skip if being run by root
9+
$filename = dirname(__FILE__)."/006_root_check.tmp";
10+
$fp = fopen($filename, 'w');
11+
fclose($fp);
12+
if(fileowner($filename) == 0) {
13+
unlink ($filename);
14+
die('skip...cannot be run as root\n');
1015
}
16+
17+
unlink($filename);
18+
1119
?>
1220
--FILE--
1321
<?php

0 commit comments

Comments
 (0)