Bug #68926 [Com]: is_writable returns false but file_put_contents works

From: Date: Fri, 02 Dec 2016 23:10:42 +0000
Subject: Bug #68926 [Com]: is_writable returns false but file_put_contents works
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205743@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68926&edit=1 ID: 68926 Comment by: anrdaemon at freemail dot ru Reported by: lukyer at gmail dot com Summary: is_writable returns false but file_put_contents works Status: Analyzed Type: Bug Package: *Directory/Filesystem functions Operating System: Windows 8 64b Prof. PHP Version: 5.6Git-2015-01-27 (Git) Assigned To: ab Block user comment: N Private report: N New Comment: This is not directly related to Samba. Accessing AD share from a machine not joined to domain produce similar results. Bottom line is: You MUST NOT make any decisions based on manual ACL inspection, if you are not the access control entity. I've had to namespace something to get my code going forward. <?php namespace Same\As\One\You\Use\Them\In; function is_readable($file) { if(file_exists($file) && is_file($file)) { $f = @fopen($file, 'rb'); if(fclose($f)) { return true; } } return false; } function is_writable($file) { $result = false; if(file_exists($file) && is_file($file)) { $f = @fopen($file, 'ab'); if(fclose($f)) { return true; } } return false; } ?> Previous Comments: ------------------------------------------------------------------------ [2016-11-21 11:38:41] ab@php.net Related To: Bug #73543 ------------------------------------------------------------------------ [2016-08-26 12:48:09] alex dot goris at fastlikehell dot com I believe I have this bug in my development environment. I am running PHP 5.6.22, 64-bit version, my workstation is Windows 10 Pro x64. I am developing in Visual Studio using the DevSense phptools plugin, this plugin debugs the code using xdebug and the built-in webserver of php.exe I have created the following test script: <?php var_dump(is_writable("//10.151.140.102/TestAlex/SubFolder1/")); var_dump(file_put_contents("//10.151.140.102/TestAlex/SubFolder1/Test.txt", "Testing...")); var_dump(is_writable("//127.0.0.1/c$/temp/SubFolder1/")); var_dump(file_put_contents("//127.0.0.1/c$/temp/SubFolder1/Test.txt", "Testing...")); ?> Which outputs: script1.php:2:boolean false script1.php:3:int 10 script1.php:4:boolean true script1.php:5:int 10 Note that the first line returns false However, I do have write permissions on the //10.151.140.102/TestAlex/SubFolder1/ folder. Also, the Test.txt file exists in that directory with the 'Tersting...' string. Note that am a member of the Administrators group on the 10.151.140.102 machine. I was surprised to see the is_writable() function returning true on the \\127.0.0.1\c$\... share, this I can not explain... This is going wrong on 2 different development machines (both running above mentioned configuration). On our test webserver, which runs Windows 2008 R2 x64, Apache 2.4.4 and php 5.6.16 the is_writable() function correctly sees the \\10.151.140.102\TestAlex\... path as writable and returns true ------------------------------------------------------------------------ [2015-06-05 17:34:21] ab@php.net @webmastersguide2000, thanks for the report. How it looks like, your issue is different from what is originally reported here. If it is on the local FS, it's most likely a misconfiguration. The unmapped unix users are unlikely to be in the game, but what were imaginable for example is the ACLs difference concerning the system account for CLI and the impersonated account used under IIS. If you still think it's the same issue, please prove it with some stable reproduce case. Maybe some rolle could play that those files are additionally shared through SMB. Please test also the latest VC11 builds like PHP 5.6, the 5.4 branch only accepts the security fixes so we won't be able to pass any corrections there, just for the case. Thanks. ------------------------------------------------------------------------ [2015-06-04 21:28:02] webmastersguide2000 at yahoo dot com > This issue is related to SAMBA. The problem does occur when files are accessed locally, without SMB. (SAMBA is Linux, SMB is Windows). In our case, the storage is _also_ shared from the affected machine to other clients via SMB, but the problem occurs when the files are accessed locally, not via SMB. ------------------------------------------------------------------------ [2015-06-04 21:06:42] yohgaki@php.net This issue is related to SAMBA. Anyone who experiences this, please add your Samba configurations. There is similar issue reported for session storage on mounted (shared) file system. This may be the reason why some users have session storage issue on mounted files under windows. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=68926 -- Edit this bug report at https://bugs.php.net/bug.php?id=68926&edit=1

« previous php.bugs (#205743) next »