summaryrefslogtreecommitdiffstats
path: root/lib/filesystem.php
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-01-04 16:31:06 +0000
committerTom Needham <needham.thomas@gmail.com>2012-01-04 16:31:06 +0000
commit6dcabdc61c20ab926af15411c326d13cd49f041b (patch)
tree88c2fc778df014a28ce9ff59c885d4ba9cfddf9e /lib/filesystem.php
parentebe3ae58cffa8c16ef2b1b74c5b7a9228a5495ff (diff)
parente0a058c732cc9d1f279cd6604623d9bf7c196744 (diff)
downloadnextcloud-server-6dcabdc61c20ab926af15411c326d13cd49f041b.tar.gz
nextcloud-server-6dcabdc61c20ab926af15411c326d13cd49f041b.zip
Fixed merge conflict in /files/ajax/move.php
Diffstat (limited to 'lib/filesystem.php')
-rw-r--r--lib/filesystem.php58
1 files changed, 22 insertions, 36 deletions
diff --git a/lib/filesystem.php b/lib/filesystem.php
index cae8ead5b16..44401260c5e 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -131,35 +131,6 @@ class OC_Filesystem{
}
/**
- * check if the current users has the right premissions to read a file
- * @param string path
- * @return bool
- */
- static private function canRead($path){
- if(substr($path,0,1)!=='/'){
- $path='/'.$path;
- }
- if(strstr($path,'/../') || strrchr($path, '/') === '/..' ){
- return false;
- }
- return true;//dummy untill premissions are correctly implemented, also the correcty value because for now users are locked in their seperate data dir and can read/write everything in there
- }
- /**
- * check if the current users has the right premissions to write a file
- * @param string path
- * @return bool
- */
- static private function canWrite($path){
- if(substr($path,0,1)!=='/'){
- $path='/'.$path;
- }
- if(strstr($path,'/../') || strrchr($path, '/') === '/..' ){
- return false;
- }
- return true;//dummy untill premissions are correctly implemented, also the correcty value because for now users are locked in their seperate data dir and can read/write everything in there
- }
-
- /**
* mount an OC_Filestorage in our virtual filesystem
* @param OC_Filestorage storage
* @param string mountpoint
@@ -228,11 +199,26 @@ class OC_Filesystem{
*/
static public function getLocalFile($path){
$parent=substr($path,0,strrpos($path,'/'));
- if(self::canRead($parent) and $storage=self::getStorage($path)){
+ if(self::isValidPath($parent) and $storage=self::getStorage($path)){
return $storage->getLocalFile(self::getInternalPath($path));
}
}
+ /**
+ * check if the requested path is valid
+ * @param string path
+ * @return bool
+ */
+ static public function isValidPath($path){
+ if(substr($path,0,1)!=='/'){
+ $path='/'.$path;
+ }
+ if(strstr($path,'/../') || strrchr($path, '/') === '/..' ){
+ return false;
+ }
+ return true;
+ }
+
static public function mkdir($path){
return self::basicOperation('mkdir',$path,array('create','write'));
}
@@ -297,7 +283,7 @@ class OC_Filesystem{
return self::basicOperation('unlink',$path,array('delete'));
}
static public function rename($path1,$path2){
- if(OC_FileProxy::runPreProxies('rename',$path1,$path2) and self::canWrite($path1) and self::canWrite($path2)){
+ if(OC_FileProxy::runPreProxies('rename',$path1,$path2) and self::is_writeable($path1) and self::isValidPath($path2)){
$run=true;
OC_Hook::emit( 'OC_Filesystem', 'rename', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run));
if($run){
@@ -318,7 +304,7 @@ class OC_Filesystem{
}
}
static public function copy($path1,$path2){
- if(OC_FileProxy::runPreProxies('copy',$path1,$path2) and self::canRead($path1) and self::canWrite($path2)){
+ if(OC_FileProxy::runPreProxies('copy',$path1,$path2) and self::is_readable($path1) and self::isValidPath($path2)){
$run=true;
OC_Hook::emit( 'OC_Filesystem', 'copy', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run));
$exists=self::file_exists($path2);
@@ -373,13 +359,13 @@ class OC_Filesystem{
return self::basicOperation('fopen',$path,$hooks,$mode);
}
static public function toTmpFile($path){
- if(OC_FileProxy::runPreProxies('toTmpFile',$path) and self::canRead($path) and $storage=self::getStorage($path)){
+ if(OC_FileProxy::runPreProxies('toTmpFile',$path) and self::isValidPath($path) and $storage=self::getStorage($path)){
OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path));
return $storage->toTmpFile(self::getInternalPath($path));
}
}
static public function fromTmpFile($tmpFile,$path){
- if(OC_FileProxy::runPreProxies('copy',$tmpFile,$path) and self::canWrite($path) and $storage=self::getStorage($path)){
+ if(OC_FileProxy::runPreProxies('copy',$tmpFile,$path) and self::isValidPath($path) and $storage=self::getStorage($path)){
$run=true;
$exists=self::file_exists($path);
if(!$exists){
@@ -399,7 +385,7 @@ class OC_Filesystem{
}
}
static public function fromUploadedFile($tmpFile,$path){
- if(OC_FileProxy::runPreProxies('fromUploadedFile',$tmpFile,$path) and self::canWrite($path) and $storage=self::getStorage($path)){
+ if(OC_FileProxy::runPreProxies('fromUploadedFile',$tmpFile,$path) and self::isValidPath($path) and $storage=self::getStorage($path)){
$run=true;
$exists=self::file_exists($path);
if(!$exists){
@@ -462,7 +448,7 @@ class OC_Filesystem{
* @return mixed
*/
private static function basicOperation($operation,$path,$hooks=array(),$extraParam=null){
- if(OC_FileProxy::runPreProxies($operation,$path, $extraParam) and self::canRead($path) and $storage=self::getStorage($path)){
+ if(OC_FileProxy::runPreProxies($operation,$path, $extraParam) and self::isValidPath($path) and $storage=self::getStorage($path)){
$interalPath=self::getInternalPath($path);
$run=true;
foreach($hooks as $hook){