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: 2024-01-04 21:07 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: w1s2j3229 at 163 dot com Assigned:
Status: Open Package: Streams related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-15 06:55 UTC] w1s2j3229 at 163 dot com
Test script must run as root user
 [2024-01-04 21:07 UTC] bukka@php.net
-Package: *Directory/Filesystem functions +Package: Streams related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 08 20:01:27 2024 UTC