Merge branch 'w30_MDL-40642_m26_umask' of https://github.com/skodak/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2013-07-23 23:42:11 +02:00
commit 154bc6b240
25 changed files with 50 additions and 15 deletions

View File

@ -323,6 +323,7 @@ EOF
fwrite($f, ";\n");
}
fclose($f);
@chmod($filepath, $CFG->filepermissions);
}
/**

View File

@ -66,7 +66,7 @@ class cc112moodle extends cc2moodle {
$cdir = static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'course_files';
if (!file_exists($cdir)) {
mkdir($cdir);
mkdir($cdir, $CFG->directorypermissions, true);
}
$sheet_base = static::loadsheet(SHEET_BASE);

View File

@ -149,7 +149,7 @@ class cc2moodle {
$cdir = static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'course_files';
if (!file_exists($cdir)) {
mkdir($cdir);
mkdir($cdir, $CFG->directorypermissions, true);
}
$sheet_base = static::loadsheet(SHEET_BASE);

View File

@ -63,11 +63,13 @@ abstract class cc_helpers {
* @return mixed - directory short name or false in case of faliure
*/
public static function randomdir($where, $prefix = '', $suffix = '') {
global $CFG;
$dirname = false;
$randomname = self::uuidgen($prefix, $suffix, false);
$newdirname = $where.DIRECTORY_SEPARATOR.$randomname;
if (mkdir($newdirname)) {
chmod($newdirname, 0755);
chmod($newdirname, $CFG->directorypermissions);
$dirname = $randomname;
}
return $dirname;
@ -155,6 +157,8 @@ abstract class cc_helpers {
}
public static function add_files(cc_i_manifest &$manifest, $packageroot, $outdir, $allinone = true) {
global $CFG;
if (pkg_static_resources::instance()->finished) {
return;
}
@ -170,7 +174,7 @@ abstract class cc_helpers {
//let us try to recreate them
$justdir = $rdir->fullpath(false).$values[7];
if (!file_exists($justdir)) {
if (!mkdir($justdir, 0777, true)) {
if (!mkdir($justdir, $CFG->directorypermissions, true)) {
throw new RuntimeException('Unable to create directories!');
}
}

View File

@ -156,6 +156,7 @@ function pathDiff($path1, $path2) {
*/
function copyr($source, $dest)
{
global $CFG;
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
@ -163,7 +164,7 @@ function pathDiff($path1, $path2) {
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
mkdir($dest, $CFG->directorypermissions, true);
}
// Loop through the folder

View File

@ -266,7 +266,7 @@ class entities {
$fpath = $dpath . DIRECTORY_SEPARATOR . $rfpath;
if (!file_exists($dpath)) {
mkdir($dpath);
mkdir($dpath, $CFG->directorypermissions, true);
}
//copy the folder.gif file
$folder_gif = "{$CFG->dirroot}/pix/i/files.gif";

View File

@ -65,7 +65,7 @@ class entities11 extends entities {
$rfpath = 'files.gif';
$fpath = $dpath . DIRECTORY_SEPARATOR . 'files.gif';
if (!file_exists($dpath)) {
mkdir($dpath);
mkdir($dpath, $CFG->directorypermissions, true);
}
//copy the folder.gif file
$folder_gif = "{$CFG->dirroot}/pix/i/files.gif";

View File

@ -141,7 +141,7 @@ class imscc11_backup_convert extends backup_execution_step {
$tempdir = $CFG->dataroot . '/temp/backup/' . uniqid('', true);
if (mkdir($tempdir, 0777, true)) {
if (mkdir($tempdir, $CFG->directorypermissions, true)) {
cc_convert_moodle2::convert($basepath, $tempdir);
//Switch the directories

View File

@ -259,7 +259,7 @@ abstract class backup_helper {
if (@rename($filepath, $filedest)) {
return null;
}
umask(0000);
umask($CFG->umaskpermissions);
if (copy($filepath, $filedest)) {
@chmod($filedest, $CFG->filepermissions); // may fail because the permissions may not make sense outside of dataroot
unlink($filepath);

1
cache/locallib.php vendored
View File

@ -108,6 +108,7 @@ class cache_config_writer extends cache_config {
fflush($handle);
fclose($handle);
$locking->unlock('configwrite', 'config');
@chmod($cachefile, $CFG->filepermissions);
// Tell PHP to recompile the script.
core_component::invalidate_opcode_php_cache($cachefile);
} else {

View File

@ -720,6 +720,7 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i
// Finally rename the temp file to the desired file, returning the true|false result.
$result = rename($tempfile, $file);
@chmod($file, $this->cfg->filepermissions);
if (!$result) {
// Failed to rename, don't leave files lying around.
@unlink($tempfile);

View File

@ -263,6 +263,7 @@ class core_files_external extends external_api {
}
file_put_contents($savedfilepath, base64_decode($fileinfo['filecontent']));
@chmod($savedfilepath, $CFG->filepermissions);
unset($fileinfo['filecontent']);
if (!empty($fileinfo['filepath'])) {

View File

@ -626,6 +626,7 @@ function is_dataroot_insecure($fetchtest=false) {
$testfile = $CFG->dataroot.'/diag/public.txt';
if (!file_exists($testfile)) {
file_put_contents($testfile, 'test file, do not delete');
@chmod($testfile, $CFG->filepermissions);
}
$teststr = trim(file_get_contents($testfile));
if (empty($teststr)) {

View File

@ -87,13 +87,15 @@ class sqlite3_pdo_moodle_database extends pdo_moodle_database {
* @return bool success
*/
public function create_database($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null) {
global $CFG;
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
$this->dbname = $dbname;
$filepath = $this->get_dbfilepath();
$dirpath = dirname($filepath);
@mkdir($dirpath);
@mkdir($dirpath, $CFG->directorypermissions, true);
return touch($filepath);
}

View File

@ -65,9 +65,11 @@ class file_xml_database_exporter extends xml_database_exporter {
* @param string $description a user description of the data.
*/
public function export_database($description=null) {
global $CFG;
// TODO: add exception if file creation fails
$this->file = fopen($this->filepath, 'wb');
parent::export_database($description);
fclose($this->file);
@chmod($this->filepath, $CFG->filepermissions);
}
}

View File

@ -2544,6 +2544,7 @@ function put_records_csv($file, $records, $table = NULL) {
}
fclose($fp);
@chmod($CFG->tempdir.'/'.$file, $CFG->filepermissions);
return true;
}
@ -3714,6 +3715,7 @@ class curl_cache {
$fp = fopen($this->dir.$filename, 'w');
fwrite($fp, serialize($val));
fclose($fp);
@chmod($this->dir.$filename, $CFG->filepermissions);
}
/**

View File

@ -64,6 +64,8 @@ class file_storage {
* @param int $filepermissions new file permissions
*/
public function __construct($filedir, $trashdir, $tempdir, $dirpermissions, $filepermissions) {
global $CFG;
$this->filedir = $filedir;
$this->trashdir = $trashdir;
$this->tempdir = $tempdir;
@ -79,6 +81,7 @@ class file_storage {
if (!file_exists($this->filedir.'/warning.txt')) {
file_put_contents($this->filedir.'/warning.txt',
'This directory contains the content of uploaded files and is controlled by Moodle code. Do not manually move, change or rename any of the files and subdirectories here.');
chmod($this->filedir.'/warning.txt', $CFG->filepermissions);
}
}
// make sure the file pool directory exists

View File

@ -93,7 +93,7 @@ function install_init_dataroot($dataroot, $dirpermissions) {
return false;
}
umask(0000);
umask(0000); // $CFG->umaskpermissions is not set yet.
if (!file_exists($dataroot)) {
if (!mkdir($dataroot, $dirpermissions, true)) {
// most probably this does not work, but anyway

View File

@ -7263,6 +7263,7 @@ class core_string_manager implements string_manager {
collatorlib::asort($languages);
check_dir_exists(dirname($this->menucache), true, true);
file_put_contents($this->menucache, json_encode($languages));
@chmod($this->menucache, $CFG->filepermissions);
}
}

View File

@ -2205,6 +2205,7 @@ class available_update_deployer {
if (!file_exists($filepath)) {
$success = file_put_contents($filepath, $password . PHP_EOL . $now . PHP_EOL, LOCK_EX);
chmod($filepath, $CFG->filepermissions);
}
}

View File

@ -298,8 +298,12 @@ if (!isset($CFG->directorypermissions)) {
if (!isset($CFG->filepermissions)) {
$CFG->filepermissions = ($CFG->directorypermissions & 0666); // strip execute flags
}
// better also set default umask because recursive mkdir() does not apply permissions recursively otherwise
umask(0000);
// Better also set default umask because developers often forget to include directory
// permissions in mkdir() and chmod() after creating new files.
if (!isset($CFG->umaskpermissions)) {
$CFG->umaskpermissions = (($CFG->directorypermissions & 0777) ^ 0777);
}
umask($CFG->umaskpermissions);
// exact version of currently used yui2 and 3 library
$CFG->yui2version = '2.9.0';

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);
}
}
}

View File

@ -582,6 +582,8 @@ function clam_handle_infected_file($file, $userid=0, $basiconly=false) {
* @return boolean
*/
function clam_replace_infected_file($file) {
global $CFG;
$newcontents = get_string('virusplaceholder');
if (!$f = fopen($file, 'w')) {
return false;
@ -589,6 +591,7 @@ function clam_replace_infected_file($file) {
if (!fwrite($f, $newcontents)) {
return false;
}
@chmod($file, $CFG->filepermissions);
return true;
}

View File

@ -1014,6 +1014,7 @@ function scorm_debug_log_filename($type, $scoid) {
* @param integer $scoid - scoid of object this log entry is for.
*/
function scorm_debug_log_write($type, $text, $scoid) {
global $CFG;
$debugenablelog = get_config('scorm', 'allowapidebug');
if (!$debugenablelog || empty($text)) {
@ -1022,6 +1023,7 @@ function scorm_debug_log_write($type, $text, $scoid) {
if (make_temp_directory('scormlogs/')) {
$logfile = scorm_debug_log_filename($type, $scoid);
@file_put_contents($logfile, date('Y/m/d H:i:s O')." DEBUG $text\r\n", FILE_APPEND);
@chmod($logfile, $CFG->filepermissions);
}
}

View File

@ -414,12 +414,15 @@ class repository_googledocs extends repository {
* @return string JSON encoded array of information about the file.
*/
public function get_file($reference, $filename = '') {
global $CFG;
$request = new Google_HttpRequest($reference);
$httpRequest = Google_Client::$io->authenticatedRequest($request);
if ($httpRequest->getResponseHttpCode() == 200) {
$path = $this->prepare_file($filename);
$content = $httpRequest->getResponseBody();
if (file_put_contents($path, $content) !== false) {
@chmod($path, $CFG->filepermissions);
return array(
'path' => $path,
'url' => $reference