From 63b6ac9e3795e3d531b4e2608cdc6d8e24f210d1 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 3 Jul 2016 21:48:09 +0900 Subject: [PATCH] Set the default umask automatically upon install --- common/framework/parsers/configparser.php | 2 ++ common/framework/storage.php | 6 +++--- modules/install/install.controller.php | 5 ++++- tests/unit/framework/StorageTest.php | 6 +++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/common/framework/parsers/configparser.php b/common/framework/parsers/configparser.php index aa4501d9e..3c4edce18 100644 --- a/common/framework/parsers/configparser.php +++ b/common/framework/parsers/configparser.php @@ -5,6 +5,7 @@ namespace Rhymix\Framework\Parsers; use Rhymix\Framework\Config; use Rhymix\Framework\DateTime; use Rhymix\Framework\Security; +use Rhymix\Framework\Storage; /** * Config parser class for XE compatibility. @@ -242,6 +243,7 @@ class ConfigParser } // Convert miscellaneous configuration. + $config['file']['umask'] = Storage::recommendUmask(); $config['mobile']['enabled'] = $db_info->use_mobile_view === 'N' ? false : true; $config['use_prepared_statements'] = $db_info->use_prepared_statements === 'Y' ? true : false; $config['use_rewrite'] = $db_info->use_rewrite === 'Y' ? true : false; diff --git a/common/framework/storage.php b/common/framework/storage.php index 26ceacfbe..969d880d9 100644 --- a/common/framework/storage.php +++ b/common/framework/storage.php @@ -738,7 +738,7 @@ class Storage // On Windows, set the umask to 0000. if (strncasecmp(\PHP_OS, 'Win', 3) === 0) { - return 0000; + return '0000'; } // Get the UID of the owner of the current file. @@ -770,13 +770,13 @@ class Storage // If both UIDs are the same, set the umask to 0022. if ($file_uid == $php_uid) { - return 0022; + return '0022'; } // Otherwise, set the umask to 0000. else { - return 0000; + return '0000'; } } } diff --git a/modules/install/install.controller.php b/modules/install/install.controller.php index 77ce89ec5..fc101f070 100644 --- a/modules/install/install.controller.php +++ b/modules/install/install.controller.php @@ -195,6 +195,9 @@ class installController extends install // Set the default URL. $config['url']['default'] = Context::getRequestUri(); + // Set the default umask. + $config['file']['umask'] = Rhymix\Framework\Storage::recommendUmask(); + // Load the new configuration. Rhymix\Framework\Config::setAll($config); Context::loadDBInfo($config); @@ -240,7 +243,7 @@ class installController extends install } // Apply site lock. - + if (Context::get('use_sitelock') === 'Y') { $user_ip_range = getView('install')->detectUserIPRange(); diff --git a/tests/unit/framework/StorageTest.php b/tests/unit/framework/StorageTest.php index 3dd2d3a0b..f12b797a1 100644 --- a/tests/unit/framework/StorageTest.php +++ b/tests/unit/framework/StorageTest.php @@ -333,16 +333,16 @@ class StorageTest extends \Codeception\TestCase\Test { if (get_current_user() === exec('whoami')) { - $this->assertEquals(0022, $umask); + $this->assertEquals('0022', $umask); } else { - $this->assertEquals(0, $umask); + $this->assertEquals('0000', $umask); } } else { - $this->assertEquals(0, $umask); + $this->assertEquals('0000', $umask); } $this->assertFalse(file_exists(\RX_BASEDIR . 'files/cache/uidcheck'));