mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-11 11:13:59 +02:00
add some properties
change phpbb_chmod to phpbb::$system->chmod() also changed chmod behaviour to the most failsafe method. If we are not able to tell the exact outcome, we simply do not mess with it. git-svn-id: file:///svn/phpbb/trunk@9296 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
@@ -126,150 +126,6 @@ function still_on_time($extra_time = 15)
|
||||
return (ceil($current_time - $start_time) < $max_execution_time) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Global function for chmodding directories and files for internal use
|
||||
* This function determines owner and group whom the file belongs to and user and group of PHP and then set safest possible file permissions.
|
||||
* The function determines owner and group from common.php file and sets the same to the provided file. Permissions are mapped to the group, user always has rw(x) permission.
|
||||
* The function uses bit fields to build the permissions.
|
||||
* The function sets the appropiate execute bit on directories.
|
||||
*
|
||||
* Supported constants representing bit fields are:
|
||||
*
|
||||
* phpbb::CHMOD_ALL - all permissions (7)
|
||||
* phpbb::CHMOD_READ - read permission (4)
|
||||
* phpbb::CHMOD_WRITE - write permission (2)
|
||||
* phpbb::CHMOD_EXECUTE - execute permission (1)
|
||||
*
|
||||
* NOTE: The function uses POSIX extension and fileowner()/filegroup() functions. If any of them is disabled, this function tries to build proper permissions, by calling is_readable() and is_writable() functions.
|
||||
*
|
||||
* @param $filename The file/directory to be chmodded
|
||||
* @param $perms Permissions to set
|
||||
* @return true on success, otherwise false
|
||||
*
|
||||
* @author faw, phpBB Group
|
||||
*/
|
||||
function phpbb_chmod($filename, $perms = phpbb::CHMOD_READ)
|
||||
{
|
||||
// Return if the file no longer exists.
|
||||
if (!file_exists($filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!function_exists('fileowner') || !function_exists('filegroup'))
|
||||
{
|
||||
$file_uid = $file_gid = false;
|
||||
$common_php_owner = $common_php_group = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Determine owner/group of common.php file and the filename we want to change here
|
||||
$common_php_owner = fileowner(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
|
||||
$common_php_group = filegroup(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
|
||||
|
||||
$file_uid = fileowner($filename);
|
||||
$file_gid = filegroup($filename);
|
||||
|
||||
// Try to set the owner to the same common.php has
|
||||
if ($common_php_owner !== $file_uid && $common_php_owner !== false && $file_uid !== false)
|
||||
{
|
||||
// Will most likely not work
|
||||
if (@chown($filename, $common_php_owner));
|
||||
{
|
||||
clearstatcache();
|
||||
$file_uid = fileowner($filename);
|
||||
}
|
||||
}
|
||||
|
||||
// Try to set the group to the same common.php has
|
||||
if ($common_php_group !== $file_gid && $common_php_group !== false && $file_gid !== false)
|
||||
{
|
||||
if (@chgrp($filename, $common_php_group));
|
||||
{
|
||||
clearstatcache();
|
||||
$file_gid = filegroup($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// And the owner and the groups PHP is running under.
|
||||
$php_uid = (function_exists('posix_getuid')) ? @posix_getuid() : false;
|
||||
$php_gids = (function_exists('posix_getgroups')) ? @posix_getgroups() : false;
|
||||
|
||||
// Who is PHP?
|
||||
if ($file_uid === false || $file_gid === false || $php_uid === false || $php_gids === false)
|
||||
{
|
||||
$php = NULL;
|
||||
}
|
||||
else if ($file_uid == $php_uid /* && $common_php_owner !== false && $common_php_owner === $file_uid*/)
|
||||
{
|
||||
$php = 'owner';
|
||||
}
|
||||
else if (in_array($file_gid, $php_gids))
|
||||
{
|
||||
$php = 'group';
|
||||
}
|
||||
else
|
||||
{
|
||||
$php = 'other';
|
||||
}
|
||||
|
||||
// Owner always has read/write permission
|
||||
$owner = phpbb::CHMOD_READ | phpbb::CHMOD_WRITE;
|
||||
if (is_dir($filename))
|
||||
{
|
||||
$owner |= phpbb::CHMOD_EXECUTE;
|
||||
|
||||
// Only add execute bit to the permission if the dir needs to be readable
|
||||
if ($perms & phpbb::CHMOD_READ)
|
||||
{
|
||||
$perms |= phpbb::CHMOD_EXECUTE;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($php)
|
||||
{
|
||||
case null:
|
||||
case 'owner':
|
||||
/* ATTENTION: if php is owner or NULL we set it to group here. This is the most failsafe combination for the vast majority of server setups.
|
||||
|
||||
$result = @chmod($filename, ($owner << 6) + (0 << 3) + (0 << 0));
|
||||
|
||||
clearstatcache();
|
||||
|
||||
if (!is_null($php) || (is_readable($filename) && is_writable($filename)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
case 'group':
|
||||
$result = @chmod($filename, ($owner << 6) + ($perms << 3) + (0 << 0));
|
||||
|
||||
clearstatcache();
|
||||
|
||||
if (!is_null($php) || ((!($perms & phpbb::CHMOD_READ) || is_readable($filename)) && (!($perms & phpbb::CHMOD_WRITE) || is_writable($filename))))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case 'other':
|
||||
$result = @chmod($filename, ($owner << 6) + ($perms << 3) + ($perms << 0));
|
||||
|
||||
clearstatcache();
|
||||
|
||||
if (!is_null($php) || ((!($perms & phpbb::CHMOD_READ) || is_readable($filename)) && (!($perms & phpbb::CHMOD_WRITE) || is_writable($filename))))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a secret hash for use in links/GET requests
|
||||
|
Reference in New Issue
Block a user