* 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.

* The function uses bit fields to build the permissions.

* The function sets the appropiate execute bit on directories.

*

* Supported constants representing bit fields are:

*

* CHMOD_ALL - all permissions (7)

* CHMOD_READ - read permission (4)

* CHMOD_WRITE - write permission (2)

* 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 string $filename The file/directory to be chmodded

* @param int $perms Permissions to set

*

* @return bool true on success, otherwise false

* @author faw, phpBB Group

*/

functionphpbb_chmod($filename, $perms=CHMOD_READ)

{

static$_chmod_info;

// Return if the file no longer exists.

if (!file_exists($filename))

{

returnfalse;

}

// Determine some common vars

if (empty($_chmod_info))

{

if (!function_exists('fileowner') ||!function_exists('filegroup'))

{

// No need to further determine owner/group - it is unknown

$_chmod_info['process'] =false;

}

else

{

global$phpbb_root_path, $phpEx;

// Determine owner/group of common.php file and the filename we want to change here