From 009768124df70258806ec3120189432d1b2bb912 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 30 Sep 2007 20:42:50 +0200 Subject: don't use realpath() anymore (FS#1261 and others) The use of realpath() to clean up relative file names caused some trouble in certain setups relying on symlinks or having restricitve file structure setups. This patch replaces all realpath() calls with a PHP only replacement which should solve those problems. darcs-hash:20070930184250-7ad00-512ff04c95f57fc9eaf104f80372237a3c94286f.gz --- inc/init.php | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'inc/init.php') diff --git a/inc/init.php b/inc/init.php index 416b117eb..f96997f21 100644 --- a/inc/init.php +++ b/inc/init.php @@ -11,7 +11,7 @@ define('DOKU_START_TIME', delta_time()); // define the include path - if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); + if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/'); // define config path (packagers may want to change this to /etc/dokuwiki/) if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/'); @@ -201,9 +201,9 @@ function init_files(){ */ function init_path($path){ // check existance - $p = realpath($path); + $p = fullpath($path); if(!@file_exists($p)){ - $p = realpath(DOKU_INC.$path); + $p = fullpath(DOKU_INC.$path); if(!@file_exists($p)){ return ''; } @@ -400,4 +400,44 @@ EOT; } +/** + * A realpath() replacement + * + * This function behaves similar to PHP's realpath() but does not resolve + * symlinks or accesses upper directories + * + * @author + * @link http://de3.php.net/manual/en/function.realpath.php#75992 + */ +function fullpath($path){ + + // check if path begins with "/" ie. is absolute + // if it isnt concat with script path + if (strpos($path,"/") !== 0) { + $base=dirname($_SERVER['SCRIPT_FILENAME']); + $path=$base."/".$path; + } + + // canonicalize + $path=explode('/', $path); + $newpath=array(); + for ($i=0; $i