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
This commit is contained in:
Andreas Gohr 2007-09-30 20:42:50 +02:00
parent 0b30864498
commit 009768124d
44 changed files with 92 additions and 52 deletions

View File

@ -8,7 +8,7 @@
// xdebug_start_profiling();
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__)).'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__)).'/');
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/events.php');

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__)).'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__)).'/');
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/events.php');

View File

@ -5,7 +5,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/HTTPClient.php');
require_once(DOKU_INC.'inc/SimplePie.php');

View File

@ -6,7 +6,7 @@
* @author Andreas Goetz <cpuidle@gmx.de>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_CONF.'dokuwiki.php');
define('HTTP_NL',"\r\n");

View File

@ -58,7 +58,7 @@
*/
// for DokuWiki
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/utf8.php');
/**

View File

@ -1196,7 +1196,7 @@ class JpegMeta
if (file_exists($this->_fileName)) {
$this->_info['file'] = array();
$this->_info['file']['Name'] = basename($this->_fileName);
$this->_info['file']['Path'] = realpath($this->_fileName);
$this->_info['file']['Path'] = fullpath($this->_fileName);
$this->_info['file']['Size'] = filesize($this->_fileName);
if ($this->_info['file']['Size'] < 1024) {
$this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B';

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/template.php');

View File

@ -9,7 +9,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/io.php');

View File

@ -6,7 +6,7 @@
* @author Chris Smith <chris@jalakai.co.uk>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/io.php');
require_once(DOKU_INC.'inc/pageutils.php');

View File

@ -20,7 +20,7 @@
// +----------------------------------------------------------------------+
//
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
//------------------------------------------------------------------------------
/**
@ -86,7 +86,7 @@ define('DOKU_CLI_OPTS_ARG_READ',5);//Could not read argv
}
// Compatibility between "php extensions.php" and "./extensions.php"
if ( realpath($_SERVER['argv'][0]) == $bin_file ) {
if ( fullpath($_SERVER['argv'][0]) == $bin_file ) {
$options = Doku_Cli_Opts::getOpt($args,$short_options,$long_options);
} else {
$options = Doku_Cli_Opts::getOpt2($args,$short_options,$long_options);

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_CONF.'dokuwiki.php');
require_once(DOKU_INC.'inc/io.php');
require_once(DOKU_INC.'inc/changelog.php');
@ -136,7 +136,7 @@ function pageinfo(){
$info['namespace'] = getNS($ID);
$info['locked'] = checklock($ID);
$info['filepath'] = realpath(wikiFN($ID));
$info['filepath'] = fullpath(wikiFN($ID));
$info['exists'] = @file_exists($info['filepath']);
if($REV){
//check if current revision was meant
@ -144,7 +144,7 @@ function pageinfo(){
$REV = '';
}else{
//really use old revision
$info['filepath'] = realpath(wikiFN($ID,$REV));
$info['filepath'] = fullpath(wikiFN($ID,$REV));
$info['exists'] = @file_exists($info['filepath']);
}
}

View File

@ -6,7 +6,7 @@
* @author Harry Fuecks <hfuecks@gmail.com>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
/**
* Returns the (known) extension and mimetype of a given filename

View File

@ -6,7 +6,7 @@
* @author Christopher Smith <chris@jalakai.co.uk>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/pluginutils.php');
class Doku_Event {

View File

@ -6,7 +6,7 @@
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
if(!defined('NL')) define('NL',"\n");
require_once(DOKU_INC.'inc/html.php');

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/indexer.php');

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
if(!defined('NL')) define('NL',"\n");
require_once(DOKU_INC.'inc/parserutils.php');
require_once(DOKU_INC.'inc/form.php');

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_CONF.'dokuwiki.php');
require_once(DOKU_INC.'inc/io.php');
require_once(DOKU_INC.'inc/utf8.php');

View File

@ -5,7 +5,7 @@
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_MESSAGEURL')) define('DOKU_MESSAGEURL','http://update.dokuwiki.org/check/');
require_once(DOKU_INC.'inc/HTTPClient.php');

View File

@ -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 <richpageau at yahoo dot co dot uk>
* @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<sizeof($path); $i++) {
if ($path[$i]==='' || $path[$i]==='.') continue;
if ($path[$i]==='..') {
array_pop($newpath);
continue;
}
array_push($newpath, $path[$i]);
}
$finalpath="/".implode('/', $newpath);
// check then return valid path or filename
if (file_exists($finalpath)) {
return ($finalpath);
}
else return false;
}
//Setup VIM: ex: et ts=2 enc=utf-8 :

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/HTTPClient.php');
require_once(DOKU_INC.'inc/events.php');
@ -385,7 +385,7 @@ function io_mkdir_p($target){
//recursion
if (io_mkdir_p(substr($target,0,strrpos($target,'/')))){
if($conf['safemodehack']){
$dir = preg_replace('/^'.preg_quote(realpath($conf['ftp']['root']),'/').'/','', $target);
$dir = preg_replace('/^'.preg_quote(fullpath($conf['ftp']['root']),'/').'/','', $target);
return io_mkdir_ftp($dir);
}else{
$ret = @mkdir($target,$conf['dmode']); // crawl back up & create dir tree

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/utf8.php');
// end of line for mail lines - RFC822 says CRLF but postfix (and other MTAs?)

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
if(!defined('NL')) define('NL',"\n");
require_once(DOKU_INC.'inc/html.php');

View File

@ -1,5 +1,5 @@
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
class Doku_Handler {

View File

@ -13,7 +13,7 @@
/**
* Init path constant
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
/**#@+
* lexer mode constant

View File

@ -5,7 +5,7 @@
* @author Esther Brunner <wikidesign@gmail.com>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
if ( !defined('DOKU_LF') ) {
// Some whitespace to help View > Source

View File

@ -1,6 +1,6 @@
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
require_once DOKU_INC . 'inc/parser/lexer.php';
require_once DOKU_INC . 'inc/parser/handler.php';

View File

@ -5,7 +5,7 @@
* @author Harry Fuecks <hfuecks@gmail.com>
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
require_once DOKU_INC . 'inc/parser/renderer.php';
require_once DOKU_INC . 'inc/plugin.php';

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
if ( !defined('DOKU_LF') ) {
// Some whitespace to help View > Source

View File

@ -1,5 +1,5 @@
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
require_once DOKU_INC . 'inc/parser/xhtml.php';

View File

@ -7,7 +7,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/confutils.php');
require_once(DOKU_INC.'inc/pageutils.php');

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/common.php');
/**

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_CONF.'dokuwiki.php');
/**
@ -859,9 +859,9 @@ function tpl_pageinfo(){
$fn = $INFO['filepath'];
if(!$conf['fullpath']){
if($REV){
$fn = str_replace(realpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
$fn = str_replace(fullpath($conf['olddir']).DIRECTORY_SEPARATOR,'',$fn);
}else{
$fn = str_replace(realpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
$fn = str_replace(fullpath($conf['datadir']).DIRECTORY_SEPARATOR,'',$fn);
}
}
$fn = utf8_decodeFN($fn);

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../').'/');
require_once(DOKU_INC.'inc/JSON.php');

View File

@ -5,7 +5,7 @@
* @author Chris Smith <chris@jalakai.co.uk>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__)).'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__)).'/');
if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
if(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/');

View File

@ -11,7 +11,7 @@ if(!count($_POST) && $HTTP_RAW_POST_DATA){
parse_str($HTTP_RAW_POST_DATA, $_POST);
}
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/pageutils.php');

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/pageutils.php');

View File

@ -1,5 +1,5 @@
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
define('DOKU_MEDIADETAIL',1);
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
define('DOKU_DISABLE_GZIP_OUTPUT', 1);
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');

View File

@ -5,7 +5,7 @@
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
define('DOKU_DISABLE_GZIP_OUTPUT',1);
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/auth.php');

View File

@ -6,7 +6,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
if(!defined('NL')) define('NL',"\n");
require_once(DOKU_INC.'inc/init.php');

View File

@ -1,5 +1,5 @@
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
define('DOKU_MEDIAMANAGER',1);
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/lang/en/lang.php');

View File

@ -8,7 +8,7 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
if(!defined('NL')) define('NL',"\n");
require_once(DOKU_INC.'inc/init.php');

View File

@ -46,7 +46,7 @@ if(!count($_POST) && $HTTP_RAW_POST_DATA){
parse_str($HTTP_RAW_POST_DATA, $_POST);
}
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
require_once (DOKU_INC.'inc/init.php');
session_write_close();
require_once (DOKU_INC.'inc/utf8.php');

View File

@ -1,5 +1,5 @@
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_INC')) define('DOKU_INC',fullpath(dirname(__FILE__).'/../../').'/');
// fix when '<?xml' isn't on the very first line
if(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);