pajoye          Sun May 17 19:51:14 2009 UTC

  Modified files:              
    /php-src/ext/standard/tests/file/windows_acls       bug44859.phpt 
                                                        bug44859_2.phpt 
                                                        bug44859_3.phpt 
                                                        common.inc tiny.bat 
                                                        tiny.exe 
  Log:
  - MFB: #44859, fixed support for windows ACL, drop win9x code
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/bug44859.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/file/windows_acls/bug44859.phpt
diff -u /dev/null php-src/ext/standard/tests/file/windows_acls/bug44859.phpt:1.2
--- /dev/null   Sun May 17 19:51:13 2009
+++ php-src/ext/standard/tests/file/windows_acls/bug44859.phpt  Sun May 17 
19:51:13 2009
@@ -0,0 +1,60 @@
+--TEST--
+bug #44859 (incorrect result with NTFS ACL permissions, is_writable)
+--SKIPIF--
+<?php 
+include_once __DIR__ . '/common.inc';
+skipif();
+?>
+--FILE--
+<?php
+include_once __DIR__ . '/common.inc';
+
+$iteration = array(
+       PHPT_ACL_READ => false,
+       PHPT_ACL_NONE => false,
+       PHPT_ACL_WRITE => true,
+       PHPT_ACL_WRITE|PHPT_ACL_READ => true,
+);
+
+echo "Testing file:\n";
+$i = 1;
+$path = __DIR__ . '/a.txt';
+foreach ($iteration as $perms => $exp) {
+       create_file($path, $perms);
+       echo 'Iteration #' . $i++ . ': ';
+       if (is_writable($path) == $exp) {
+               echo "passed.\n";
+       } else {
+               var_dump(is_writable($path), $exp);
+               echo "failed.\n";
+       }
+       delete_file($path);
+}
+
+echo "Testing directory:\n";
+$path = __DIR__ . '/adir';
+$i = 1;
+foreach ($iteration as $perms => $exp) {
+       create_file($path, $perms);
+       echo 'Iteration #' . $i++ . ': ';
+       if (is_writable($path) == $exp) {
+               echo "passed.\n";
+       } else {
+               var_dump(is_writable($path), $exp);
+               echo "failed.\n";
+       }
+       delete_file($path);
+}
+
+?>
+--EXPECT--
+Testing file:
+Iteration #1: passed.
+Iteration #2: passed.
+Iteration #3: passed.
+Iteration #4: passed.
+Testing directory:
+Iteration #1: passed.
+Iteration #2: passed.
+Iteration #3: passed.
+Iteration #4: passed.
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt
diff -u /dev/null 
php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt:1.2
--- /dev/null   Sun May 17 19:51:13 2009
+++ php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt        Sun May 
17 19:51:13 2009
@@ -0,0 +1,60 @@
+--TEST--
+bug #44859 (incorrect result with NTFS ACL permissions, is_readable)
+--SKIPIF--
+<?php 
+include_once __DIR__ . '/common.inc';
+skipif();
+?>
+--FILE--
+<?php
+include_once __DIR__ . '/common.inc';
+
+$iteration = array(
+       PHPT_ACL_READ => true,
+       PHPT_ACL_NONE => false,
+       PHPT_ACL_WRITE => false,
+       PHPT_ACL_WRITE|PHPT_ACL_READ => true,
+);
+
+echo "Testing file:\n";
+$i = 1;
+$path = __DIR__ . '/a.txt';
+foreach ($iteration as $perms => $exp) {
+       create_file($path, $perms);
+       echo 'Iteration #' . $i++ . ': ';
+       if (is_readable($path) == $exp) {
+               echo "passed.\n";
+       } else {
+               var_dump(is_writable($path), $exp);
+               echo "failed.\n";
+       }
+       delete_file($path);
+}
+
+echo "Testing directory:\n";
+$path = __DIR__ . '/adir';
+$i = 1;
+foreach ($iteration as $perms => $exp) {
+       create_file($path, $perms);
+       echo 'Iteration #' . $i++ . ': ';
+       if (is_readable($path) == $exp) {
+               echo "passed.\n";
+       } else {
+               var_dump(is_writable($path), $exp);
+               echo "failed.\n";
+       }
+       delete_file($path);
+}
+
+?>
+--EXPECT--
+Testing file:
+Iteration #1: passed.
+Iteration #2: passed.
+Iteration #3: passed.
+Iteration #4: passed.
+Testing directory:
+Iteration #1: passed.
+Iteration #2: passed.
+Iteration #3: passed.
+Iteration #4: passed.
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/bug44859_3.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/file/windows_acls/bug44859_3.phpt
diff -u /dev/null 
php-src/ext/standard/tests/file/windows_acls/bug44859_3.phpt:1.2
--- /dev/null   Sun May 17 19:51:13 2009
+++ php-src/ext/standard/tests/file/windows_acls/bug44859_3.phpt        Sun May 
17 19:51:13 2009
@@ -0,0 +1,36 @@
+--TEST--
+bug #44859 (incorrect result with NTFS ACL permissions, is_executable)
+--SKIPIF--
+<?php 
+include_once __DIR__ . '/common.inc';
+skipif();
+?>
+--FILE--
+<?php
+include_once __DIR__ . '/common.inc';
+
+$iteration = array(
+       'tiny.exe' => true,
+       //'tiny.bat' => true, To be fixed in _access
+       __FILE__ => false
+);
+
+$i = 1;
+$path = __DIR__;
+
+foreach ($iteration as $file => $exp) {
+       $path = __DIR__ . '/' . $file;
+       echo 'Iteration #' . $i++ . ': ';
+       if (is_executable($path) == $exp) {
+               echo "passed.\n";
+       } else {
+               var_dump(is_executable($path), $exp);
+               echo "failed.\n";
+       }
+}
+
+
+?>
+--EXPECT--
+Iteration #1: passed.
+Iteration #2: passed.
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/common.inc?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/file/windows_acls/common.inc
diff -u /dev/null php-src/ext/standard/tests/file/windows_acls/common.inc:1.2
--- /dev/null   Sun May 17 19:51:13 2009
+++ php-src/ext/standard/tests/file/windows_acls/common.inc     Sun May 17 
19:51:13 2009
@@ -0,0 +1,177 @@
+<?php
+error_reporting(E_ALL);
+define('PHPT_ACL_READ',  1 << 1);
+define('PHPT_ACL_WRITE', 1 << 2);
+define('PHPT_ACL_EXEC',  1 << 3);
+define('PHPT_ACL_NONE',  1 << 4);
+define('PHPT_ACL_FULL',  1 << 5);
+
+define('PHPT_ACL_GRANT',  1);
+define('PHPT_ACL_DENY',  2);
+
+function skipif() {
+       if(substr(PHP_OS, 0, 3) != 'WIN' ) {
+               die('skip windows only test');
+       }
+       if(stripos(php_uname(), 'XP') !== FALSE) {
+               die('skip windows 2003 or newer only test');
+       }
+}
+
+function get_username(){
+       return getenv('USERNAME');
+}
+
+function get_domainname()
+{
+       return getenv('USERDOMAIN');
+}
+
+function icacls_set($path, $mode, $perm) {
+       $user = get_username();
+       $path_escaped =  '"' . $path . '"';
+       $perm_entry = array();
+
+       if ($perm & PHPT_ACL_READ) $perm_entry[]  = 'R';
+       if ($perm & PHPT_ACL_WRITE) $perm_entry[] = 'W';
+       if ($perm & PHPT_ACL_EXEC) $perm_entry[]  = 'RX';
+       if ($perm & PHPT_ACL_FULL) $perm_entry[]  = 'F';
+
+       // Deny all
+       $cmd = 'icacls ' . $path_escaped . ' /inheritance:r /deny ' . $user . 
':(F,M,R,RX,W)';
+       exec($cmd);
+
+       if ($perm & PHPT_ACL_NONE) {
+               /*
+                This is required to remove all the previously denied
+                permission for the USER. Just granting permission doesn't
+                remove the previously denied permission.
+               */
+               $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:d';
+               $cmd .= ' ' . $user;
+               exec($cmd);
+               $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:g';
+               $cmd .= ' ' . $user;
+               exec($cmd);
+               return;
+       }
+
+       if ($mode == PHPT_ACL_GRANT) {
+               $mode = 'grant';
+       } else {
+               $mode = 'deny';
+       }
+
+
+       // Deny all
+       $cmd = 'icacls ' . $path_escaped . ' /deny ' . $user . ':(F,M,R,RX,W)';
+       exec($cmd);
+
+       /*
+        This is required to remove all the previously denied
+        permission for the USER. Just granting permission doesn't
+        remove the previously denied permission.
+       */
+       $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:d';
+       $cmd .= ' ' . $user;
+       exec($cmd);
+       $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:g';
+       $cmd .= ' ' . $user;
+       exec($cmd);
+
+
+       /*
+        Required to set no permission and check that is_readable()
+        returns false. If the $perm_entry contains 'N' skip this step.
+        This will make the file/dir with NO aceess.
+       */
+       if (!in_array('N', $perm_entry)) {
+               /*
+                This is required to remove all the previously denied
+                permission for the USER. Just granting permission doesn't
+                remove the previously denied permission.
+               */
+               $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:d';
+               $cmd .= ' ' . get_username();
+               exec($cmd);
+               $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:g';
+               $cmd .= ' ' . get_username();
+               exec($cmd);
+
+               $cmd = 'icacls ' . $path_escaped . ' /' . $mode;
+               $cmd .= ' ' . get_username();
+               $cmd .= ':' . '(' . implode($perm_entry, ',') . ')';
+               exec($cmd);
+       }
+}
+
+function create_dir($name, $perms) {
+       if (empty($name)) {
+               echo "create_dir: Empty name is not allowed\n";
+               return;
+       }
+
+       mkdir($name);
+       $dst = realpath($name);
+       icacls_set($name, PHPT_ACL_GRANT, $perms);
+}
+
+function create_file($name, $perms) {
+       if (empty($name)) {
+               echo "create_dir: Empty name is not allowed\n";
+               return;
+       }
+
+       touch($name);
+       $dst = realpath($name);
+       icacls_set($name, PHPT_ACL_GRANT, $perms);
+}
+
+function delete_file($path) {
+       icacls_set($path, PHPT_ACL_GRANT, PHPT_ACL_FULL);
+       if (is_file($path)) {
+               unlink($path);
+       } else {
+               echo "delete_file: '$path' is not a file\n";
+               return;
+       }
+}
+
+function delete_dir($path) {
+       if (is_dir($path)) {
+               icacls_set($path, PHPT_ACL_GRANT, PHPT_ACL_FULL);
+               rmdir($path);
+       } else {
+               echo "delete_dir: '$path' is not a directory\n";
+               return;
+       }
+}
+if (0) {
+$path = __DIR__ . '/a.txt';
+create_file($path, PHPT_ACL_NONE);
+if (!is_writable($path)) {
+       echo "PHPT_ACL_NONE success!!\n";
+} else {
+       echo "PHPT_ACL_NONE failed!!\n";
+}
+delete_file($path);
+
+$path = __DIR__ . '/a.txt';
+create_file($path, PHPT_ACL_READ);
+if (!is_writable($path)) {
+       echo "PHPT_ACL_READ success!!\n";
+} else {
+       echo "PHPT_ACL_READ failed!!\n";
+}
+delete_file($path);
+
+$path = __DIR__ . '/adir';
+create_dir($path, PHPT_ACL_READ);
+if (!is_writable($path)) {
+       echo "PHPT_ACL_READ dir success!!\n";
+} else {
+       echo "PHPT_ACL_READ dir failed!!\n";
+}
+delete_dir($path);
+
+}
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/tiny.bat?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/file/windows_acls/tiny.bat
diff -u /dev/null php-src/ext/standard/tests/file/windows_acls/tiny.bat:1.2
--- /dev/null   Sun May 17 19:51:13 2009
+++ php-src/ext/standard/tests/file/windows_acls/tiny.bat       Sun May 17 
19:51:13 2009
@@ -0,0 +1 @@
+echo FOO
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/tiny.exe?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/standard/tests/file/windows_acls/tiny.exe

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to