Hello,
I created a patch to allow subdirectories to be created
and used when safemode is enabled.
Please let me demonstrate the approach I took to comment
it (implementation also).
We have the following file/dir structure:
/script.php (owned by sUID)
/parent_directory/ (owned by sUID, perm=777)
/parent_directory/child_directory/ (owned by rUID)
/parent_directory/child_directory/file.txt (owned by rUID)
sUID stands for "scriptUID" (the UID of user owning the script)
rUID stands for "runningUID" (the UID of user executing the script)
Safemode by design works like this:
- script.php is executed and it want's to access
"/parent_directory/child_directory/file.txt" for reading or inclusion; - PHP first checks if file.txt owner is the same as sUID - if
condition is met access is granted; - if first condition is not met PHP continues and checks if
"/parent_directory/child_directory/" owner (directory which file.txt
resides in) is the same as sUID - if condition is met
access is granted - If both conditions fail then access is denied and PHP issues an error
The idea for modification is quite simple and it extends third statement:
- if "child_directory/" owner UID is not the same as sUID but it is the
same as rUID, recursively check parent directories until directory
with different owner UID is found or only root directory is left to check
Then PHP checks directories towards root and when different UID than rUID
is found it has 2 options:
- if it is the same as sUID access is granted
- if it is not the same as sUID then access is denied.
The concept / idea behind is that if running user (rUID) is able to write into
directory owned by himself he had to create that directory. And to create
that directory he had to had a permission to do so.
I also attached a patch for evaluation but please do not think I consider it
good - I am not a C programmer - though it works (at least it seems so)...
Best regards,
Bostjan