From d8cc75a4578c10a31eb0e2f0cfb176123d8d20eb Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Sat, 30 Jan 2010 20:55:01 +0000 Subject: [PATCH] - fix write access check when write mode only is requested (not RW) --- TSRM/tsrm_win32.c | 7 +- .../tests/file/windows_acls/bug44859.phpt | 2 + .../tests/file/windows_acls/bug44859_2.phpt | 6 +- .../tests/file/windows_acls/bug44859_4.phpt | 64 +++++++++++++++++++ 4 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 ext/standard/tests/file/windows_acls/bug44859_4.phpt diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index 99f27794a1..50c6210e96 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -303,7 +303,7 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode) fAccess = bucket->is_writable; goto Finished; } - desired_access = FILE_GENERIC_READ | FILE_GENERIC_WRITE; + desired_access = FILE_GENERIC_WRITE; } else if(mode <= 4) { if(bucket != NULL && bucket->is_rvalid) { fAccess = bucket->is_readable; @@ -348,6 +348,11 @@ TSRM_API int tsrm_win32_access(const char *pathname, int mode) else if(desired_access == FILE_GENERIC_WRITE) { bucket->is_wvalid = 1; bucket->is_writable = fAccess; + } else if (desired_access == FILE_GENERIC_READ | FILE_GENERIC_WRITE) { + bucket->is_rvalid = 1; + bucket->is_readable = fAccess; + bucket->is_wvalid = 1; + bucket->is_writable = fAccess; } } diff --git a/ext/standard/tests/file/windows_acls/bug44859.phpt b/ext/standard/tests/file/windows_acls/bug44859.phpt index 0716ee5ac4..bb22a5cd8e 100644 --- a/ext/standard/tests/file/windows_acls/bug44859.phpt +++ b/ext/standard/tests/file/windows_acls/bug44859.phpt @@ -21,6 +21,7 @@ $i = 1; $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 @@ $path = __DIR__ . '/adir'; $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"; diff --git a/ext/standard/tests/file/windows_acls/bug44859_2.phpt b/ext/standard/tests/file/windows_acls/bug44859_2.phpt index 8326eb473e..3cc4ed1ba1 100644 --- a/ext/standard/tests/file/windows_acls/bug44859_2.phpt +++ b/ext/standard/tests/file/windows_acls/bug44859_2.phpt @@ -21,11 +21,12 @@ $i = 1; $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 @@ $path = __DIR__ . '/adir'; $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); diff --git a/ext/standard/tests/file/windows_acls/bug44859_4.phpt b/ext/standard/tests/file/windows_acls/bug44859_4.phpt new file mode 100644 index 0000000000..61aae65ca3 --- /dev/null +++ b/ext/standard/tests/file/windows_acls/bug44859_4.phpt @@ -0,0 +1,64 @@ +--TEST-- +bug #44859 (incorrect result with NTFS ACL permissions, is_readable) +--CREDITS-- +Venkat Raman Don +--SKIPIF-- + +--FILE-- + true, + PHPT_ACL_NONE => false, + PHPT_ACL_WRITE => false, + PHPT_ACL_WRITE|PHPT_ACL_READ => true, +); + +echo "Testing file with relative path:\n"; +$i = 1; +$path = './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_readable($path), $exp); + echo "failed.\n"; + } + delete_file($path); +} + +echo "Testing directory with relative path:\n"; +$path = 'adir'; +$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_readable($path), $exp); + echo "failed.\n"; + } + delete_file($path); +} + +?> +--EXPECT-- +Testing file with relative path: +Iteration #1: passed. +Iteration #2: passed. +Iteration #3: passed. +Iteration #4: passed. +Testing directory with relative path: +Iteration #1: passed. +Iteration #2: passed. +Iteration #3: passed. +Iteration #4: passed. -- 2.50.1