#46498 [Opn->Fbk]: is_writable() returns invalid result
ID: 46498
Updated by: jani@php.net
Reported By: registrace at koren dot cz
-Status: Open
+Status: Feedback
Bug Type: Filesystem function related
Operating System: Linux
PHP Version: 5.2.6
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
Previous Comments:
------------------------------------------------------------------------
[2008-11-05 21:01:31] registrace at koren dot cz
Description:
------------
PHP Function is_writable() sometimes reports false results.
Requirements: Linux - getuid() != geteuid()
After inspection of PHP source, I realized, that is_writable()
internally uses syscall access(2). In turn, access(2) man page (on
Linux) says:
The check is done with the calling processâs real UID and
GID, rather
than with the effective IDs as is done when actually
attempting an
operation. This is to allow set-user-ID programs to easily
determine
the invoking userâs authority.
Reproduce code:
---------------
<?
$file = "testfile.txt";
echo "GetUID: " . posix_getuid() . "/" . posix_geteuid() . "<br
/>";
echo "file is writable " . (is_writable($file)?"TRUE":"FALSE") .
"<br
/>";
fopen("testfile.txt", 'wt');
echo ("file created");
?>
Expected result:
----------------
Expected result:
either:
file is writable TRUE
file created
or
file is writable FALSE
ERROR
Actual result:
--------------
GetUID: 933/10099
file is writable FALSE
file created
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46498&edit=1
Thread (3 messages)