chmod_info)) { if (!function_exists('fileowner') || !function_exists('filegroup')) { // No need to further determine owner/group - it is unknown $this->chmod_info['process'] = 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); // 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; if (!$php_uid || empty($php_gids) || !$common_php_owner || !$common_php_group) { $this->chmod_info['process'] = false; } else { $this->chmod_info = array( 'process' => true, 'common_owner' => $common_php_owner, 'common_group' => $common_php_group, 'php_uid' => $php_uid, 'php_gids' => $php_gids, ); } } } if ($this->chmod_info['process']) { // Change owner if (@chown($filename, $this->chmod_info['common_owner'])) { clearstatcache(); $file_uid = fileowner($filename); } // Change group if (@chgrp($filename, $this->chmod_info['common_group'])) { clearstatcache(); $file_gid = filegroup($filename); } // If the file_uid/gid now match the one from common.php we can process further, else we are not able to change something if ($file_uid != $this->chmod_info['common_owner'] || $file_gid != $this->chmod_info['common_group']) { $this->chmod_info['process'] = false; } } // Still able to process? if ($this->chmod_info['process']) { if ($file_uid == $this->chmod_info['php_uid']) { $php = 'owner'; } else if (in_array($file_gid, $this->chmod_info['php_gids'])) { $php = 'group'; } else { // Since we are setting the everyone bit anyway, no need to do expensive operations $this->chmod_info['process'] = false; } } // We are not able to determine or change something if (!$this->chmod_info['process']) { $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 'owner': $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; } } ?>