diff options
author | Andreas Gohr <andi@splitbrain.org> | 2006-03-03 18:32:52 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2006-03-03 18:32:52 +0100 |
commit | 0d8850c4c07c1ecc45ffb8d823840f9978db5597 (patch) | |
tree | 7f0a9a46c400b46ab89e146e9f635e0f29f40aad /inc/init.php | |
parent | e4a98f5caea4dba0f1ac8d8695ede3f1667a639f (diff) | |
download | rpg-0d8850c4c07c1ecc45ffb8d823840f9978db5597.tar.gz rpg-0d8850c4c07c1ecc45ffb8d823840f9978db5597.tar.bz2 |
better permission checking
init.php now checks for the accessability of the data directories
(executebit on UNIX systems)
darcs-hash:20060303173252-7ad00-7ce3281926ac93f282d9865e9617ec4d179c2c23.gz
Diffstat (limited to 'inc/init.php')
-rw-r--r-- | inc/init.php | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/inc/init.php b/inc/init.php index 114c012f6..e4d2fac5b 100644 --- a/inc/init.php +++ b/inc/init.php @@ -128,39 +128,62 @@ function init_paths(){ foreach($paths as $c => $p){ if(!$conf[$c]) $conf[$c] = $conf['savedir'].'/'.$p; $conf[$c] = init_path($conf[$c]); - if(!$conf[$c]) die("$c does not exist or isn't writable. Check config!"); + if(!$conf[$c]) die("$c does not exist, isn't accessable or writable. Check config and permissions!"); } } /** - * Checks the existance of certain files and creates them if missing + * Checks the existance of certain files and creates them if missing. */ function init_files(){ global $conf; + $files = array( $conf['cachedir'].'/word.idx', $conf['cachedir'].'/page.idx', - $conf['cachedir'].'/index.idx', ); + $conf['cachedir'].'/index.idx'); foreach($files as $file){ if(!@file_exists($file)){ - $fh = fopen($file,'a'); - fclose($fh); - if(isset($conf['fmask'])) { chmod($file, $conf['fmask']); } + $fh = @fopen($file,'a'); + if($fh){ + fclose($fh); + if(isset($conf['fmask'])) { chmod($file, $conf['fmask']); } + }else{ + die("$file is not writable. Check permissions!"); + } } } } /** - * returns absolute path + * Returns absolute path + * + * This tries the given path first, then checks in DOKU_INC. + * Check for accessability on directories as well. * - * This tries the given path first, then checks in DOKU_INC + * @author Andreas Gohr <andi@splitbrain.org> */ function init_path($path){ + // check existance $p = realpath($path); - if(@file_exists($p)) return $p; - $p = realpath(DOKU_INC.$path); - if(@file_exists($p)) return $p; - return ''; + if(!@file_exists($p)){ + $p = realpath(DOKU_INC.$path); + if(!@file_exists($p)){ + return ''; + } + } + + // check writability + if(!@is_writable($p)){ + return ''; + } + + // check accessability (execute bit) for directories + if(@is_dir($p) && !@file_exists("$p/.")){ + return ''; + } + + return $p; } /** |