pajoye          Tue Jun 16 00:07:05 2009 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/standard/tests/file/windows_acls       bug44859_4.phpt 

  Modified files:              
    /TSRM       tsrm_virtual_cwd.c tsrm_virtual_cwd.h tsrm_win32.c 
    /php-src/ext/standard/tests/file/windows_acls       bug44859.phpt 
                                                        bug44859_2.phpt 
                                                        common.inc 
  Log:
  - Windows ACL cache support, update existing tests and add a new one
  
http://cvs.php.net/viewvc.cgi/TSRM/tsrm_virtual_cwd.c?r1=1.74.2.9.2.35.2.18&r2=1.74.2.9.2.35.2.19&diff_format=u
Index: TSRM/tsrm_virtual_cwd.c
diff -u TSRM/tsrm_virtual_cwd.c:1.74.2.9.2.35.2.18 
TSRM/tsrm_virtual_cwd.c:1.74.2.9.2.35.2.19
--- TSRM/tsrm_virtual_cwd.c:1.74.2.9.2.35.2.18  Sat Apr  4 11:37:48 2009
+++ TSRM/tsrm_virtual_cwd.c     Tue Jun 16 00:07:04 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: tsrm_virtual_cwd.c,v 1.74.2.9.2.35.2.18 2009/04/04 11:37:48 pajoye Exp 
$ */
+/* $Id: tsrm_virtual_cwd.c,v 1.74.2.9.2.35.2.19 2009/06/16 00:07:04 pajoye Exp 
$ */
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -471,6 +471,12 @@
                }
                bucket->realpath_len = realpath_len;
                bucket->is_dir = is_dir;
+#ifdef PHP_WIN32
+               bucket->is_rvalid   = 0;
+               bucket->is_readable = 0;
+               bucket->is_wvalid   = 0;
+               bucket->is_writable = 0;
+#endif
                bucket->expires = t + CWDG(realpath_cache_ttl);
                n = bucket->key % (sizeof(CWDG(realpath_cache)) / 
sizeof(CWDG(realpath_cache)[0]));
                bucket->next = CWDG(realpath_cache)[n];
@@ -503,6 +509,12 @@
 }
 /* }}} */
 
+CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int 
path_len, time_t t TSRMLS_DC) /* {{{ */
+{
+    return realpath_cache_find(path, path_len, t TSRMLS_CC);
+}
+/* }}} */
+
 #undef LINK_MAX
 #define LINK_MAX 32
 
http://cvs.php.net/viewvc.cgi/TSRM/tsrm_virtual_cwd.h?r1=1.48.2.5.2.8.2.6&r2=1.48.2.5.2.8.2.7&diff_format=u
Index: TSRM/tsrm_virtual_cwd.h
diff -u TSRM/tsrm_virtual_cwd.h:1.48.2.5.2.8.2.6 
TSRM/tsrm_virtual_cwd.h:1.48.2.5.2.8.2.7
--- TSRM/tsrm_virtual_cwd.h:1.48.2.5.2.8.2.6    Wed Dec 31 11:15:31 2008
+++ TSRM/tsrm_virtual_cwd.h     Tue Jun 16 00:07:04 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: tsrm_virtual_cwd.h,v 1.48.2.5.2.8.2.6 2008/12/31 11:15:31 sebastian 
Exp $ */
+/* $Id: tsrm_virtual_cwd.h,v 1.48.2.5.2.8.2.7 2009/06/16 00:07:04 pajoye Exp $ 
*/
 
 #ifndef VIRTUAL_CWD_H
 #define VIRTUAL_CWD_H
@@ -210,6 +210,12 @@
        int                            realpath_len;
        int                            is_dir;
        time_t                         expires;
+#ifdef PHP_WIN32
+       unsigned char                  is_rvalid;
+       unsigned char                  is_readable;
+       unsigned char                  is_wvalid;
+       unsigned char                  is_writable;
+#endif
        struct _realpath_cache_bucket *next;    
 } realpath_cache_bucket;
 
@@ -231,6 +237,7 @@
 
 CWD_API void realpath_cache_clean(TSRMLS_D);
 CWD_API void realpath_cache_del(const char *path, int path_len TSRMLS_DC);
+CWD_API realpath_cache_bucket* realpath_cache_lookup(const char *path, int 
path_len, time_t t TSRMLS_DC);
 
 /* The actual macros to be used in programs using TSRM
  * If the program defines VIRTUAL_DIR it will use the
http://cvs.php.net/viewvc.cgi/TSRM/tsrm_win32.c?r1=1.27.2.1.2.7.2.10&r2=1.27.2.1.2.7.2.11&diff_format=u
Index: TSRM/tsrm_win32.c
diff -u TSRM/tsrm_win32.c:1.27.2.1.2.7.2.10 TSRM/tsrm_win32.c:1.27.2.1.2.7.2.11
--- TSRM/tsrm_win32.c:1.27.2.1.2.7.2.10 Mon Jun 15 15:01:01 2009
+++ TSRM/tsrm_win32.c   Tue Jun 16 00:07:04 2009
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: tsrm_win32.c,v 1.27.2.1.2.7.2.10 2009/06/15 15:01:01 pajoye Exp $ */
+/* $Id: tsrm_win32.c,v 1.27.2.1.2.7.2.11 2009/06/16 00:07:04 pajoye Exp $ */
 
 #include <stdio.h>
 #include <fcntl.h>
@@ -32,6 +32,7 @@
 #ifdef TSRM_WIN32
 
 #include "tsrm_win32.h"
+#include "tsrm_virtual_cwd.h"
 
 #ifdef ZTS
 static ts_rsrc_id win32_globals_id;
@@ -114,6 +115,11 @@
        BYTE * psec_desc = NULL;
        BOOL fAccess = FALSE;
        HANDLE process_token = NULL;
+
+       realpath_cache_bucket * bucket = NULL;
+       char * real_path = NULL;
+       time_t t;
+
        TSRMLS_FETCH();
 
        if (mode == 1 /*X_OK*/) {
@@ -121,22 +127,60 @@
                return GetBinaryType(pathname, &type) ? 0 : -1;
        } else {
                if(access(pathname, mode)) {
-                               return errno;
+                       return errno;
                }
 
-               if(TWG(impersonation_token) == NULL) {
-                       goto Finished;
-               }
+               if(!IS_ABSOLUTE_PATH(pathname, strlen(pathname)+1)) {
+                       real_path = (char *)malloc(MAX_PATH);
+                       if(tsrm_realpath(pathname, real_path TSRMLS_CC) == 
NULL) {
+                               goto Finished;
+                       }
+                       pathname = real_path;
+               }
 
-               /* Do a full access check because access() will only check 
read-only attribute */
-               if(mode == 0 || mode > 6) {
+               if (CWDG(realpath_cache_size_limit)) {
+                       t = time(0);
+                       bucket = realpath_cache_lookup(pathname, 
strlen(pathname), t TSRMLS_CC);
+                       if(bucket == NULL && real_path == NULL) {
+                               /* We used the pathname directly. Call 
tsrm_realpath */
+                               /* so that entry is created in realpath cache */
+                               real_path = (char *)malloc(MAX_PATH);
+                               if(tsrm_realpath(pathname, real_path TSRMLS_CC) 
!= NULL) {
+                                       pathname = real_path;
+                                       bucket = 
realpath_cache_lookup(pathname, strlen(pathname), t TSRMLS_CC);
+                               }
+                       }
+               }
+ 
+               /* Do a full access check because access() will only check 
read-only attribute */
+               if(mode == 0 || mode > 6) {
+                       if(bucket != NULL && bucket->is_rvalid) {
+                               fAccess = bucket->is_readable;
+                               goto Finished;
+                       }
+                       desired_access = FILE_GENERIC_READ;
+               } else if(mode <= 2) {
+                       if(bucket != NULL && bucket->is_wvalid) {
+                               fAccess = bucket->is_writable;
+                               goto Finished;
+                       }
+                       desired_access = FILE_GENERIC_WRITE;
+               } else if(mode <= 4) {
+                       if(bucket != NULL && bucket->is_rvalid) {
+                               fAccess = bucket->is_readable;
+                               goto Finished;
+                       }
                        desired_access = FILE_GENERIC_READ;
-               } else if(mode <= 2) {
-                               desired_access = FILE_GENERIC_WRITE;
-               } else if(mode <= 4) {
-                               desired_access = FILE_GENERIC_READ;
-               } else { // if(mode <= 6)
-                               desired_access = FILE_GENERIC_READ | 
FILE_GENERIC_WRITE;
+               } else { // if(mode <= 6)
+                       if(bucket != NULL && bucket->is_rvalid && 
bucket->is_wvalid) {
+                               fAccess = bucket->is_readable & 
bucket->is_writable;
+                               goto Finished;
+                       }
+                       desired_access = FILE_GENERIC_READ | FILE_GENERIC_WRITE;
+               }
+
+               if(TWG(impersonation_token) == NULL) {
+                       goto Finished;
                }
 
                /* Get size of security buffer. Call is expected to fail */
@@ -154,12 +198,29 @@
                                goto Finished;
                }
 
+               /* Keep the result in realpath_cache */
+               if(bucket != NULL) {
+                       if(desired_access == FILE_GENERIC_READ) {
+                               bucket->is_rvalid = 1;
+                               bucket->is_readable = fAccess;
+                       }
+                       else if(desired_access == FILE_GENERIC_WRITE) {
+                               bucket->is_wvalid = 1;
+                               bucket->is_writable = fAccess;
+                       }
+               }
+
 Finished:
                if(psec_desc != NULL) {
                        free(psec_desc);
                        psec_desc = NULL;
                }
 
+               if(real_path != NULL) {
+                       free(real_path);
+                       real_path = NULL;
+               }
+
                if(fAccess == FALSE) {
                        errno = EACCES;
                        return errno;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/bug44859.phpt?r1=1.1.2.1&r2=1.1.2.2&diff_format=u
Index: php-src/ext/standard/tests/file/windows_acls/bug44859.phpt
diff -u php-src/ext/standard/tests/file/windows_acls/bug44859.phpt:1.1.2.1 
php-src/ext/standard/tests/file/windows_acls/bug44859.phpt:1.1.2.2
--- php-src/ext/standard/tests/file/windows_acls/bug44859.phpt:1.1.2.1  Sun May 
17 19:43:22 2009
+++ php-src/ext/standard/tests/file/windows_acls/bug44859.phpt  Tue Jun 16 
00:07:05 2009
@@ -21,6 +21,7 @@
 $path = __DIR__ . '/a.txt';
 foreach ($iteration as $perms => $exp) {
        create_file($path, $perms);
+       clearstatcache(true, $path);
        echo 'Iteration #' . $i++ . ': ';
        if (is_writable($path) == $exp) {
                echo "passed.\n";
@@ -36,6 +37,7 @@
 $i = 1;
 foreach ($iteration as $perms => $exp) {
        create_file($path, $perms);
+       clearstatcache(true, $path);
        echo 'Iteration #' . $i++ . ': ';
        if (is_writable($path) == $exp) {
                echo "passed.\n";
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt?r1=1.1.2.1&r2=1.1.2.2&diff_format=u
Index: php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt
diff -u php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt:1.1.2.1 
php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt:1.1.2.2
--- php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt:1.1.2.1        
Sun May 17 19:43:22 2009
+++ php-src/ext/standard/tests/file/windows_acls/bug44859_2.phpt        Tue Jun 
16 00:07:05 2009
@@ -21,11 +21,12 @@
 $path = __DIR__ . '/a.txt';
 foreach ($iteration as $perms => $exp) {
        create_file($path, $perms);
+       clearstatcache(true, $path);
        echo 'Iteration #' . $i++ . ': ';
        if (is_readable($path) == $exp) {
                echo "passed.\n";
        } else {
-               var_dump(is_writable($path), $exp);
+               var_dump(is_readable($path), $exp);
                echo "failed.\n";
        }
        delete_file($path);
@@ -36,11 +37,12 @@
 $i = 1;
 foreach ($iteration as $perms => $exp) {
        create_file($path, $perms);
+       clearstatcache(true, $path);
        echo 'Iteration #' . $i++ . ': ';
        if (is_readable($path) == $exp) {
                echo "passed.\n";
        } else {
-               var_dump(is_writable($path), $exp);
+               var_dump(is_readable($path), $exp);
                echo "failed.\n";
        }
        delete_file($path);
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/common.inc?r1=1.1.2.1&r2=1.1.2.2&diff_format=u
Index: php-src/ext/standard/tests/file/windows_acls/common.inc
diff -u php-src/ext/standard/tests/file/windows_acls/common.inc:1.1.2.1 
php-src/ext/standard/tests/file/windows_acls/common.inc:1.1.2.2
--- php-src/ext/standard/tests/file/windows_acls/common.inc:1.1.2.1     Sun May 
17 19:44:27 2009
+++ php-src/ext/standard/tests/file/windows_acls/common.inc     Tue Jun 16 
00:07:05 2009
@@ -123,7 +123,6 @@
        }
 
        touch($name);
-       $dst = realpath($name);
        icacls_set($name, PHPT_ACL_GRANT, $perms);
 }
 

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/windows_acls/bug44859_4.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/file/windows_acls/bug44859_4.phpt
+++ php-src/ext/standard/tests/file/windows_acls/bug44859_4.phpt

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

Reply via email to