letoDMS on a open_basedir system limitation - matteocisilino - 04-05-2011
Hallo ,
i've reached some problems with open_basedir , and the patch from alekseynfor , imho , doesn't fit well .
This is my patch , done with fury/dirt/quick phProgramming
PHP Code: function makeDir($path) { if (strncmp($path, DIRECTORY_SEPARATOR, 1) == 0) { $mkfolder = DIRECTORY_SEPARATOR; } else { $mkfolder = ""; } /* $path = preg_split( "/[\\\\\/]/" , $path ); for( $i=0 ; isset( $path[$i] ) ; $i++ ) { if(!strlen(trim($path[$i])))continue; $mkfolder .= $path[$i]; */ $mkfolder = $path; if( !is_dir( $mkfolder ) ){ $res=@mkdir($mkfolder,0777,true); if (!$res) return false; } $mkfolder .= DIRECTORY_SEPARATOR; // }
return true;
// patch from alekseynfor safe_mod or open_basedir
global $settings; $path = substr_replace ($path, "/", 0, strlen($settings->_contentDir)); $mkfolder = $settings->_contentDir;
$path = preg_split( "/[\\\\\/]/" , $path );
for( $i=0 ; isset( $path[$i] ) ; $i++ ) { if(!strlen(trim($path[$i])))continue; $mkfolder .= $path[$i];
if( !is_dir( $mkfolder ) ){ $res= @mkdir( "$mkfolder" , 0777); if (!$res) return false; } $mkfolder .= DIRECTORY_SEPARATOR; }
return true;
}
What was the problem ? simple :
The Open_basedir prevents the render to access all nodes that are behind the node that i "jail" it .
so if your script want to make / del a DIRECTORY that is :
/home/SITE/sub/DIRECTORY
and my basepath is fixed to sub , i cannot recurse directly using :
is_dir(/home) and then is_dir(/home/SITE) , and so on , tha restriction "kill" it at the first step .
But if i point the process directly to /home/SITE/sub/DIRECTORY and use the mkdir() option for recursion i'll fix directly the problem , also bypassing another problem , the making of the "track" directories , if i need to make a foo/bar/THIS , and foo/bar doesn't exists , using recursion the system will create the "intermediate" directoris autonomusly .
( http://php.net/manual/en/function.mkdir.php )
hope this "Italinglish" words help anyone 
RE: letoDMS on a open_basedir system limitation - steinm - 04-05-2011
(04-05-2011, 05:06 PM)matteocisilino Wrote: Hallo ,
i've reached some problems with open_basedir , and the patch from alekseynfor , imho , doesn't fit well .
This is my patch , done with fury/dirt/quick phProgramming
PHP Code: function makeDir($path) { if (strncmp($path, DIRECTORY_SEPARATOR, 1) == 0) { $mkfolder = DIRECTORY_SEPARATOR; } else { $mkfolder = ""; } /* $path = preg_split( "/[\\\\\/]/" , $path ); for( $i=0 ; isset( $path[$i] ) ; $i++ ) { if(!strlen(trim($path[$i])))continue; $mkfolder .= $path[$i]; */ $mkfolder = $path; if( !is_dir( $mkfolder ) ){ $res=@mkdir($mkfolder,0777,true); if (!$res) return false; } $mkfolder .= DIRECTORY_SEPARATOR; // }
return true;
// patch from alekseynfor safe_mod or open_basedir
global $settings; $path = substr_replace ($path, "/", 0, strlen($settings->_contentDir)); $mkfolder = $settings->_contentDir;
$path = preg_split( "/[\\\\\/]/" , $path );
for( $i=0 ; isset( $path[$i] ) ; $i++ ) { if(!strlen(trim($path[$i])))continue; $mkfolder .= $path[$i];
if( !is_dir( $mkfolder ) ){ $res= @mkdir( "$mkfolder" , 0777); if (!$res) return false; } $mkfolder .= DIRECTORY_SEPARATOR; }
return true;
}
What was the problem ? simple :
The Open_basedir prevents the render to access all nodes that are behind the node that i "jail" it .
so if your script want to make / del a DIRECTORY that is :
/home/SITE/sub/DIRECTORY
and my basepath is fixed to sub , i cannot recurse directly using :
is_dir(/home) and then is_dir(/home/SITE) , and so on , tha restriction "kill" it at the first step .
But if i point the process directly to /home/SITE/sub/DIRECTORY and use the mkdir() option for recursion i'll fix directly the problem , also bypassing another problem , the making of the "track" directories , if i need to make a foo/bar/THIS , and foo/bar doesn't exists , using recursion the system will create the "intermediate" directoris autonomusly .
( http://php.net/manual/en/function.mkdir.php )
hope this "Italinglish" words help anyone 
Your code makes most of the current code unneeded. I'm just not sure if there needs to be more path checking or not. Some old code did actually check if the new directory is below the contentDir as specified in the configuration.
Uwe
|