commit b9d775d8626aca6ee8e244775d819be6dd1a28b4 Author: Letharion Date: Sat Dec 1 21:25:31 2012 +0100 CMI File Step 1 diff --git a/core/includes/file.inc b/core/includes/file.inc index bcd3033..061e8d8 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -1525,13 +1525,13 @@ function file_get_mimetype($uri, $mapping = NULL) { /** * Sets the permissions on a file or directory. * - * This function will use the 'file_chmod_directory' and 'file_chmod_file' - * variables for the default modes for directories and uploaded/generated - * files. By default these will give everyone read access so that users - * accessing the files with a user account without the webserver group (e.g. - * via FTP) can read these files, and give group write permissions so webserver - * group members (e.g. a vhost account) can alter files uploaded and owned by - * the webserver. + * This function will use the system.file:chmod.directory and + * system.file:chmod.file configuration for the default modes for directories + * and uploaded/generated files. By default these will give everyone read access + * so that users accessing the files with a user account without the webserver + * group (e.g. via FTP) can read these files, and give group write permissions + * so webserver group members (e.g. a vhost account) can alter files uploaded + * and owned by the webserver. * * PHP's chmod does not support stream wrappers so we use our wrapper * implementation which interfaces with chmod() by default. Contrib wrappers @@ -1550,11 +1550,20 @@ function file_get_mimetype($uri, $mapping = NULL) { */ function drupal_chmod($uri, $mode = NULL) { if (!isset($mode)) { + // Configuration system stores default modes as strings. We use octdec() so + // that the octal permission numbers can be expressed as integers or strings + // and will be converted correctly in both cases. if (is_dir($uri)) { - $mode = variable_get('file_chmod_directory', 0775); + $mode = octdec(config('system.file')->get('chmod.directory')); + if (!$mode) { + $mode = 0775; + } } else { - $mode = variable_get('file_chmod_file', 0664); + $mode = octdec(config('system.file')->get('chmod.file')); + if (!$mode) { + $mode = 0664; + } } } @@ -1731,7 +1740,11 @@ function drupal_basename($uri, $suffix = NULL) { */ function drupal_mkdir($uri, $mode = NULL, $recursive = FALSE, $context = NULL) { if (!isset($mode)) { - $mode = variable_get('file_chmod_directory', 0775); + // Configuration system stores default mode as strings. + $mode = octdec(config('system.file')->get('chmod.directory')); + if (!$mode) { + $mode = 0775; + } } if (!isset($context)) { diff --git a/core/modules/system/config/system.file.yml b/core/modules/system/config/system.file.yml new file mode 100644 index 0000000..e5bac32 --- /dev/null +++ b/core/modules/system/config/system.file.yml @@ -0,0 +1,10 @@ +allow_insecure_uploads: '0' +# chmod variables should be a string in PHP Octal Notation. +chmod: + directory: '0775' + file: '0664' +default_scheme: public +path: + private: '' + public: '' + temporary: '' diff --git a/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php b/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php index e6f3396..399e4dc 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/DirectoryTest.php @@ -51,7 +51,7 @@ function testFileCheckDirectoryHandling() { } // Test that the directory has the correct permissions. - $this->assertDirectoryPermissions($directory, variable_get('file_chmod_directory', 0775)); + $this->assertDirectoryPermissions($directory, octdec(config('system.file')->get('chmod.directory'))); // Remove .htaccess file to then test that it gets re-created. @drupal_unlink(file_default_scheme() . '://.htaccess'); diff --git a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php index 7056946..7f5248c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedCopyTest.php @@ -23,6 +23,7 @@ public static function getInfo() { * Copy a normal file. */ function testNormal() { + $config = config('system.file'); // Create a file for testing $uri = $this->createUri(); @@ -33,7 +34,7 @@ function testNormal() { $this->assertEqual($new_filepath, $desired_filepath, 'Returned expected filepath.'); $this->assertTrue(file_exists($uri), 'Original file remains.'); $this->assertTrue(file_exists($new_filepath), 'New file exists.'); - $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($new_filepath, octdec($config->get('chmod.file'))); // Copying with rename. $desired_filepath = 'public://' . $this->randomName(); @@ -43,7 +44,7 @@ function testNormal() { $this->assertNotEqual($newer_filepath, $desired_filepath, 'Returned expected filepath.'); $this->assertTrue(file_exists($uri), 'Original file remains.'); $this->assertTrue(file_exists($newer_filepath), 'New file exists.'); - $this->assertFilePermissions($newer_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($newer_filepath, octdec($config->get('chmod.file'))); // TODO: test copying to a directory (rather than full directory/file path) // TODO: test copying normal files using normal paths (rather than only streams) @@ -64,6 +65,7 @@ function testNonExistent() { * Copy a file onto itself. */ function testOverwriteSelf() { + $config = config('system.file'); // Create a file for testing $uri = $this->createUri(); @@ -73,7 +75,7 @@ function testOverwriteSelf() { $this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.'); $this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.'); $this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.'); - $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($new_filepath, octdec($config->get('chmod.file'))); // Copy the file onto itself without renaming fails. $new_filepath = file_unmanaged_copy($uri, $uri, FILE_EXISTS_ERROR); @@ -91,6 +93,6 @@ function testOverwriteSelf() { $this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.'); $this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.'); $this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.'); - $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($new_filepath, octdec($config->get('chmod.file'))); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php index 6e0ec14..23ac632 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedMoveTest.php @@ -23,6 +23,7 @@ public static function getInfo() { * Move a normal file. */ function testNormal() { + $config = config('system.file'); // Create a file for testing $uri = $this->createUri(); @@ -33,7 +34,7 @@ function testNormal() { $this->assertEqual($new_filepath, $desired_filepath, 'Returned expected filepath.'); $this->assertTrue(file_exists($new_filepath), 'File exists at the new location.'); $this->assertFalse(file_exists($uri), 'No file remains at the old location.'); - $this->assertFilePermissions($new_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($new_filepath, octdec($config->get('chmod.file'))); // Moving with rename. $desired_filepath = 'public://' . $this->randomName(); @@ -44,7 +45,7 @@ function testNormal() { $this->assertNotEqual($newer_filepath, $desired_filepath, 'Returned expected filepath.'); $this->assertTrue(file_exists($newer_filepath), 'File exists at the new location.'); $this->assertFalse(file_exists($new_filepath), 'No file remains at the old location.'); - $this->assertFilePermissions($newer_filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($newer_filepath, octdec($config->get('chmod.file'))); // TODO: test moving to a directory (rather than full directory/file path) // TODO: test creating and moving normal files (rather than streams) diff --git a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedSaveDataTest.php b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedSaveDataTest.php index cde75c7..1077c4c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedSaveDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/UnmanagedSaveDataTest.php @@ -36,6 +36,6 @@ function testFileSaveData() { $this->assertTrue($filepath, 'Unnamed file saved correctly.'); $this->assertEqual('asdf.txt', drupal_basename($filepath), 'File was named correctly.'); $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.'); - $this->assertFilePermissions($filepath, variable_get('file_chmod_file', 0664)); + $this->assertFilePermissions($filepath, octdec(config('system.file')->get('chmod.file'))); } }