mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
Changed check_dir_exists() behaviour to be more robust
and to work better when used recursively under sites with open_basedir enabled. Credit goes to René Samselnig. MDL-11437 Merged from MOODLE_19_STABLE
This commit is contained in:
parent
df7ecfe486
commit
5fab4931b4
@ -7272,7 +7272,7 @@ function remove_dir($dir, $content_only=false) {
|
||||
/**
|
||||
* Function to check if a directory exists and optionally create it.
|
||||
*
|
||||
* @param string absolute directory path
|
||||
* @param string absolute directory path (must be under $CFG->dataroot)
|
||||
* @param boolean create directory if does not exist
|
||||
* @param boolean create directory recursively
|
||||
*
|
||||
@ -7282,6 +7282,10 @@ function check_dir_exists($dir, $create=false, $recursive=false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
if (strstr($dir, $CFG->dataroot) === false) {
|
||||
debugging('Warning. Wrong call to check_dir_exists(). $dir must be an absolute path under $CFG->dataroot ("' . $dir . '" is incorrect)', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
$status = true;
|
||||
|
||||
if(!is_dir($dir)) {
|
||||
@ -7290,10 +7294,14 @@ function check_dir_exists($dir, $create=false, $recursive=false) {
|
||||
} else {
|
||||
umask(0000);
|
||||
if ($recursive) {
|
||||
// PHP 5.0 has recursive mkdir parameter, but 4.x does not :-(
|
||||
/// PHP 5.0 has recursive mkdir parameter, but 4.x does not :-(
|
||||
$dir = str_replace('\\', '/', $dir); //windows compatibility
|
||||
$dirs = explode('/', $dir);
|
||||
$dir = array_shift($dirs).'/'; //skip root or drive letter
|
||||
/// We are going to make it recursive under $CFG->dataroot only
|
||||
/// (will help sites running open_basedir security and others)
|
||||
$dir = str_replace($CFG->dataroot . '/', '', $dir);
|
||||
$dirs = explode('/', $dir); /// Extract path parts
|
||||
/// Iterate over each part with start point $CFG->dataroot
|
||||
$dir = $CFG->dataroot . '/';
|
||||
foreach ($dirs as $part) {
|
||||
if ($part == '') {
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user