--- embedaddon/php/ext/standard/tests/file/windows_acls/common.inc 2012/02/21 23:48:04 1.1.1.1 +++ embedaddon/php/ext/standard/tests/file/windows_acls/common.inc 2013/07/22 01:32:08 1.1.1.2 @@ -19,15 +19,45 @@ function skipif() { } function get_username(){ - return getenv('USERNAME'); + $user = getenv('USERNAME'); + + if (!$user) { + $user = get_current_user(); + } + + if (!$user) { + $user = exec('echo %USERNAME%'); + } + + return $user; } function get_domainname() { - return getenv('USERDOMAIN'); + $domain = getenv('USERDOMAIN'); + + return $domain; } +function get_icacls() +{ + $sysroot = exec('echo %SYSTEMROOT%'); + + return "$sysroot\\System32\\icacls.exe"; +} + +function fix_acls() { + $user = get_username(); + /* Current user needs to be owner of the test files. As well + all the other users having acls on the files must loose them. + The following fixes this just partially, as dynamically reading + all the users having acls on a file could be sophisticated. */ + exec(get_icacls() . ' . /setowner $user /T /L /Q 2> nul'); + exec(get_icacls() . ' . /remove:g Administrators /T /L /Q 2> nul'); +} + function icacls_set($path, $mode, $perm) { + $icacls = get_icacls(); $user = get_username(); $path_escaped = '"' . $path . '"'; $perm_entry = array(); @@ -38,7 +68,7 @@ function icacls_set($path, $mode, $perm) { if ($perm & PHPT_ACL_FULL) $perm_entry[] = 'F'; // Deny all - $cmd = 'icacls ' . $path_escaped . ' /inheritance:r /deny ' . $user . ':(F,M,R,RX,W)'; + $cmd = $icacls . ' ' . $path_escaped . ' /inheritance:r /deny ' . $user . ':(F,M,R,RX,W)'; exec($cmd); if ($perm & PHPT_ACL_NONE) { @@ -47,11 +77,9 @@ function icacls_set($path, $mode, $perm) { permission for the USER. Just granting permission doesn't remove the previously denied permission. */ - $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:d'; - $cmd .= ' ' . $user; + $cmd = $icacls . ' ' . $path_escaped . ' /remove:d ' . $user; exec($cmd); - $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:g'; - $cmd .= ' ' . $user; + $cmd = $icacls . ' ' . $path_escaped . ' /remove:g ' . $user; exec($cmd); return; } @@ -64,7 +92,7 @@ function icacls_set($path, $mode, $perm) { // Deny all - $cmd = 'icacls ' . $path_escaped . ' /deny ' . $user . ':(F,M,R,RX,W)'; + $cmd = $icacls . ' ' . $path_escaped . ' /deny ' . $user . ':(F,M,R,RX,W)'; exec($cmd); /* @@ -72,11 +100,9 @@ function icacls_set($path, $mode, $perm) { permission for the USER. Just granting permission doesn't remove the previously denied permission. */ - $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:d'; - $cmd .= ' ' . $user; + $cmd = $icacls . ' ' . $path_escaped . ' /remove:d ' . $user; exec($cmd); - $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:g'; - $cmd .= ' ' . $user; + $cmd = $icacls . ' ' . $path_escaped . ' /remove:g ' . $user; exec($cmd); @@ -91,15 +117,12 @@ function icacls_set($path, $mode, $perm) { permission for the USER. Just granting permission doesn't remove the previously denied permission. */ - $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:d'; - $cmd .= ' ' . get_username(); + $cmd = $icacls . ' ' . $path_escaped . ' /remove:d ' . $user; exec($cmd); - $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:g'; - $cmd .= ' ' . get_username(); + $cmd = $icacls . ' ' . $path_escaped . ' /remove:g ' . $user; exec($cmd); - $cmd = 'icacls ' . $path_escaped . ' /' . $mode; - $cmd .= ' ' . get_username(); + $cmd = $icacls . ' ' . $path_escaped . ' /' . $mode . ' ' . $user; $cmd .= ':' . '(' . implode($perm_entry, ',') . ')'; exec($cmd); }