MDL-40642 set more restrictive umask and use proper permission for new dirs and files

This commit is contained in:
Petr Škoda
2013-07-19 09:18:44 +02:00
parent ffc3f5308b
commit eb459f7192
25 changed files with 52 additions and 15 deletions
+4 -2
View File
@@ -1224,7 +1224,7 @@ function upgrade_ensure_not_running($warningonly = false) {
function check_dir_exists($dir, $create = true, $recursive = true) {
global $CFG;
umask(0000); // just in case some evil code changed it
umask($CFG->umaskpermissions);
if (is_dir($dir)) {
return true;
@@ -1256,7 +1256,7 @@ function make_writable_directory($dir, $exceptiononerror = true) {
}
}
umask(0000); // just in case some evil code changed it
umask($CFG->umaskpermissions);
if (!file_exists($dir)) {
if (!mkdir($dir, $CFG->directorypermissions, true)) {
@@ -1287,11 +1287,13 @@ function make_writable_directory($dir, $exceptiononerror = true) {
* @param string $dir the full path of the directory to be protected
*/
function protect_directory($dir) {
global $CFG;
// Make sure a .htaccess file is here, JUST IN CASE the files area is in the open and .htaccess is supported
if (!file_exists("$dir/.htaccess")) {
if ($handle = fopen("$dir/.htaccess", 'w')) { // For safety
@fwrite($handle, "deny from all\r\nAllowOverride None\r\nNote: this file is broken intentionally, we do not want anybody to undo it in subdirectory!\r\n");
@fclose($handle);
@chmod("$dir/.htaccess", $CFG->filepermissions);
}
}
}