]> source.dussan.org Git - nextcloud-server.git/commitdiff
use absolute path for file proxies
authorRobin Appelman <icewind@owncloud.com>
Sat, 9 Jun 2012 15:33:57 +0000 (17:33 +0200)
committerRobin Appelman <icewind@owncloud.com>
Wed, 20 Jun 2012 18:18:41 +0000 (20:18 +0200)
apps/files_encryption/lib/cryptstream.php
apps/files_encryption/lib/proxy.php
apps/files_encryption/tests/proxy.php
lib/filesystemview.php

index d6643f3268975eac740de12f8c0ca7389cec8cb6..a698ee00335297a0e498b9157bbe27fdb918b4e3 100644 (file)
@@ -35,8 +35,12 @@ class OC_CryptStream{
        private $meta=array();//header/meta for source stream
        private $count;
        private $writeCache;
+       private static $rootView;
 
        public function stream_open($path, $mode, $options, &$opened_path){
+               if(!self::$rootView){
+                       self::$rootView=new OC_FilesystemView('');
+               }
                $path=str_replace('crypt://','',$path);
                if(dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])){
                        $this->source=self::$sourceStreams[basename($path)]['stream'];
@@ -45,7 +49,7 @@ class OC_CryptStream{
                        $this->path=$path;
                        OCP\Util::writeLog('files_encryption','open encrypted '.$path. ' in '.$mode,OCP\Util::DEBUG);
                        OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file
-                       $this->source=OC_FileSystem::fopen($path,$mode);
+                       $this->source=self::$rootView->fopen($path,$mode);
                        OC_FileProxy::$enabled=true;
                        if(!is_resource($this->source)){
                                OCP\Util::writeLog('files_encryption','failed to open '.$path,OCP\Util::ERROR);
index 06f963fc98173626155420e923779e9effbf712b..9fd57c0f02bd6d8e6ee65082b6f28008476d1eef 100644 (file)
@@ -59,7 +59,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
         * @return bool
         */
        private static function isEncrypted($path){
-               $metadata=OC_FileCache::getCached($path);
+               $metadata=OC_FileCache::getCached($path,'');
                return isset($metadata['encrypted']) and (bool)$metadata['encrypted'];
        }
        
index 0450de82acb725e4e973182b6d305a1e5d9c93bf..f36b2193430b7a5a8a317bbda824143991df1c68 100644 (file)
@@ -30,6 +30,9 @@ class Test_CryptProxy extends UnitTestCase {
        }
 
        public function testSimple(){
+               $oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true');
+               OCP\Config::setAppValue('files_encryption','enable_encryption','true');
+       
                $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
                $original=file_get_contents($file);
 
@@ -42,5 +45,17 @@ class Test_CryptProxy extends UnitTestCase {
                $fromFile=OC_Filesystem::file_get_contents('/file');
                $this->assertNotEqual($original,$stored);
                $this->assertEqual($original,$fromFile);
+
+               $rootView=new OC_FilesystemView('');
+               $view=new OC_FilesystemView('/'.OC_User::getUser());
+               $userDir='/'.OC_User::getUser().'/files';
+
+               $fromFile=$rootView->file_get_contents($userDir.'/file');
+               $this->assertEqual($original,$fromFile);
+
+               $fromFile=$view->file_get_contents('files/file');
+               $this->assertEqual($original,$fromFile);
+
+               OCP\Config::setAppValue('files_encryption','enable_encryption',$oldConfig);
        }
 }
index d15f91be1ec16e7600326fdd736007e3ac68b326..7265b775ea91dacaf50ce2b027507104be98b63a 100644 (file)
@@ -74,6 +74,23 @@ class OC_FilesystemView {
                }
                return $this->internal_path_cache[$path];
        }
+
+       /**
+        * get path relative to the root of the view
+        * @param string path
+        * @return string
+        */
+       public function getRelativePath($path){
+               if($this->fakeRoot==''){
+                       return $path;
+               }
+               if(strpos($path,$this->fakeRoot)!==0){
+                       return null;
+               }else{
+                       return substr($path,strlen($this->fakeRoot));
+               }
+       }
+       
        /**
        * get the storage object for a path
        * @param string path
@@ -213,7 +230,14 @@ class OC_FilesystemView {
                return $this->basicOperation('unlink',$path,array('delete'));
        }
        public function rename($path1,$path2){
-               if(OC_FileProxy::runPreProxies('rename',$path1,$path2) and OC_Filesystem::isValidPath($path2)){
+               $absolutePath1=$this->getAbsolutePath($path1);
+               $absolutePath2=$this->getAbsolutePath($path2);
+               if(OC_FileProxy::runPreProxies('rename',$absolutePath1,$absolutePath2) and OC_Filesystem::isValidPath($path2)){
+                       $path1=$this->getRelativePath($absolutePath1);
+                       $path2=$this->getRelativePath($absolutePath2);
+                       if($path1==null or $path2==null){
+                               return false;
+                       }
                        $run=true;
                        OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2, OC_Filesystem::signal_param_run => &$run));
                        if($run){
@@ -237,7 +261,14 @@ class OC_FilesystemView {
                }
        }
        public function copy($path1,$path2){
-               if(OC_FileProxy::runPreProxies('copy',$path1,$path2) and $this->is_readable($path1) and OC_Filesystem::isValidPath($path2)){
+               $absolutePath1=$this->getAbsolutePath($path1);
+               $absolutePath2=$this->getAbsolutePath($path2);
+               if(OC_FileProxy::runPreProxies('copy',$absolutePath1,$absolutePath2) and OC_Filesystem::isValidPath($path2)){
+                       $path1=$this->getRelativePath($absolutePath1);
+                       $path2=$this->getRelativePath($absolutePath2);
+                       if($path1==null or $path2==null){
+                               return false;
+                       }
                        $run=true;
                        OC_Hook::emit( OC_Filesystem::CLASSNAME, OC_Filesystem::signal_copy, array( OC_Filesystem::signal_param_oldpath => $path1 , OC_Filesystem::signal_param_newpath=>$path2, OC_Filesystem::signal_param_run => &$run));
                        $exists=$this->file_exists($path2);
@@ -352,8 +383,13 @@ class OC_FilesystemView {
         * @return mixed
         */
        private function basicOperation($operation,$path,$hooks=array(),$extraParam=null){
-               if(OC_FileProxy::runPreProxies($operation,$path, $extraParam) and OC_Filesystem::isValidPath($path)){
-                       $interalPath=$this->getInternalPath($path);
+               $absolutePath=$this->getAbsolutePath($path);
+               if(OC_FileProxy::runPreProxies($operation,$absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)){
+                       $path=$this->getRelativePath($absolutePath);
+                       if($path==null){
+                               return false;
+                       }
+                       $internalPath=$this->getInternalPath($path);
                        $run=true;
                        if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){
                                foreach($hooks as $hook){
@@ -370,7 +406,7 @@ class OC_FilesystemView {
                                }else{
                                        $result=$storage->$operation($interalPath);
                                }
-                               $result=OC_FileProxy::runPostProxies($operation,$path,$result);
+                               $result=OC_FileProxy::runPostProxies($operation,$this->getAbsolutePath($path),$result);
                                if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){
                                        if($operation!='fopen'){//no post hooks for fopen, the file stream is still open
                                                foreach($hooks as $hook){