php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72600 Consider root special perms with stream_wrapper
Submitted: 2016-07-15 06:40 UTC Modified: 2016-07-15 06:55 UTC
From: w1s2j3229 at 163 dot com Assigned:
Status: Open Package: *Directory/Filesystem functions
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: w1s2j3229 at 163 dot com
New email:
PHP Version: OS:

 

 [2016-07-15 06:40 UTC] w1s2j3229 at 163 dot com
Description:
------------
I found the problem when calling is_writable() after stream_wrapper_register().

It is OK with non-root user, but the result is not as expected with root user.

I want to remain the same permission as no stream_wrapper so I return just what "stat()" returns in "url_stat()" with my stream_wrapper class.

However, in the filestat.c source code, it does special check to root user( getuid() == 0) only with php_plain_files_wrapper. So I got false while calling is_writable after stream_wrapper_register().

I wonder if it is possible to add a function "is_super_user" in the stream_wrapper, and call it while calling permission check functions such as is_readable, is_writable and is_executable in case to keep consistent with system root user where needed.


Test script:
---------------
class TestStream{
        public static function wrap() { stream_wrapper_unregister('file'); stream_wrapper_register('file', get_called_class()); }
        public static function unwrap(){ stream_wrapper_restore('file'); }
        public function url_stat($path, $flags){
                $this->unwrap(); $result = stat($path); $this->wrap();
                return $result;
        }
}
$file = __DIR__."/tmp"; @mkdir($file, 0777, true); chmod($file, 0);
clearstatcache(); var_dump(is_writable($file));
clearstatcache(); TestStream::wrap(); var_dump(is_writable($file)); TestStream::unwrap();
chmod($file, 0777); rmdir($file);

Expected result:
----------------
bool(true)
bool(true)

Actual result:
--------------
bool(true)
bool(false)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-15 06:55 UTC] w1s2j3229 at 163 dot com
Test script must run as root user
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 08:01:24 2019 UTC