From 850e54025ec7980f68c059c9342566670079d8c1 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 2 Jun 2013 18:38:09 +0200 Subject: [PATCH] Fixed FileUtil::makeWritable during WCFSetup --- .../install/files/lib/util/FileUtil.class.php | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/lib/util/FileUtil.class.php b/wcfsetup/install/files/lib/util/FileUtil.class.php index ba55dee5af..6ca07a8868 100644 --- a/wcfsetup/install/files/lib/util/FileUtil.class.php +++ b/wcfsetup/install/files/lib/util/FileUtil.class.php @@ -495,13 +495,42 @@ final class FileUtil { return; } - // mirror permissions of WCF.class.php if (self::$mode === null) { - if (!file_exists(WCF_DIR . 'lib/system/WCF.class.php')) { - throw new SystemException("Unable to find 'wcf/lib/system/WCF.class.php'."); + // WCFSetup + if (defined('NO_IMPORTS')) { + // do not use PHP_OS here, as this represents the system it was built on != running on + if (strpos(php_uname(), 'Windows') !== false) { + self::$mode = 0777; + } + else { + self::$mode = 0666; + + $tmpFilename = '__permissions_'.sha1(time()).'.txt'; + @touch($tmpFilename); + + // create a new file and check the file owner, if it is the same + // as this file (uploaded through FTP), we can safely grant write + // permissions exclusively to the owner rather than everyone + if (file_exists($tmpFilename)) { + $scriptOwner = fileowner(__FILE__); + $fileOwner = fileowner($tmpFilename); + + if ($scriptOwner === $fileOwner) { + self::$mode = 0644; + } + + @unlink($tmpFilename); + } + } + } + else { + // mirror permissions of WCF.class.php + if (!file_exists(WCF_DIR . 'lib/system/WCF.class.php')) { + throw new SystemException("Unable to find 'wcf/lib/system/WCF.class.php'."); + } + + self::$mode = '0' . substr(sprintf('%o', fileperms(WCF_DIR . 'lib/system/WCF.class.php')), -3); } - - self::$mode = '0' . substr(sprintf('%o', fileperms(WCF_DIR . 'lib/system/WCF.class.php')), -3); } if (is_dir($filename)) { -- 2.20.1