]> source.dussan.org Git - nextcloud-server.git/commitdiff
backport of https://github.com/owncloud/core/pull/5513
authorBjoern Schiessle <schiessle@owncloud.com>
Tue, 29 Oct 2013 14:08:12 +0000 (15:08 +0100)
committerBjoern Schiessle <schiessle@owncloud.com>
Tue, 29 Oct 2013 14:08:12 +0000 (15:08 +0100)
apps/files_encryption/hooks/hooks.php
apps/files_sharing/lib/updater.php
lib/private/files/cache/updater.php
tests/lib/files/cache/updater.php

index 6e2d360917bc1fc30525d69788c88616e318c36d..35574b8e5b9798c5755eb42bfc4aebe2f3fa50b0 100644 (file)
@@ -35,6 +35,12 @@ class Hooks {
         * @note This method should never be called for users using client side encryption\r
         */\r
        public static function login($params) {\r
+\r
+               if (\OCP\App::isEnabled('files_encryption') === false) {\r
+                       return true;\r
+               }\r
+\r
+\r
                $l = new \OC_L10N('files_encryption');\r
 \r
                $view = new \OC_FilesystemView('/');\r
@@ -117,11 +123,12 @@ class Hooks {
         * @note This method should never be called for users using client side encryption\r
         */\r
        public static function postCreateUser($params) {\r
-               $view = new \OC_FilesystemView('/');\r
-\r
-               $util = new Util($view, $params['uid']);\r
 \r
-               Helper::setupUser($util, $params['password']);\r
+               if (\OCP\App::isEnabled('files_encryption')) {\r
+                       $view = new \OC_FilesystemView('/');\r
+                       $util = new Util($view, $params['uid']);\r
+                       Helper::setupUser($util, $params['password']);\r
+               }\r
        }\r
 \r
        /**\r
@@ -129,26 +136,31 @@ class Hooks {
         * @note This method should never be called for users using client side encryption\r
         */\r
        public static function postDeleteUser($params) {\r
-               $view = new \OC_FilesystemView('/');\r
 \r
-               // cleanup public key\r
-               $publicKey = '/public-keys/' . $params['uid'] . '.public.key';\r
+               if (\OCP\App::isEnabled('files_encryption')) {\r
+                       $view = new \OC_FilesystemView('/');\r
 \r
-               // Disable encryption proxy to prevent recursive calls\r
-               $proxyStatus = \OC_FileProxy::$enabled;\r
-               \OC_FileProxy::$enabled = false;\r
+                       // cleanup public key\r
+                       $publicKey = '/public-keys/' . $params['uid'] . '.public.key';\r
 \r
-               $view->unlink($publicKey);\r
+                       // Disable encryption proxy to prevent recursive calls\r
+                       $proxyStatus = \OC_FileProxy::$enabled;\r
+                       \OC_FileProxy::$enabled = false;\r
 \r
-               \OC_FileProxy::$enabled = $proxyStatus;\r
+                       $view->unlink($publicKey);\r
+\r
+                       \OC_FileProxy::$enabled = $proxyStatus;\r
+               }\r
        }\r
 \r
        /**\r
         * @brief If the password can't be changed within ownCloud, than update the key password in advance.\r
         */\r
        public static function preSetPassphrase($params) {\r
-               if ( ! \OC_User::canUserChangePassword($params['uid']) ) {\r
-                       self::setPassphrase($params);\r
+               if (\OCP\App::isEnabled('files_encryption')) {\r
+                       if ( ! \OC_User::canUserChangePassword($params['uid']) ) {\r
+                               self::setPassphrase($params);\r
+                       }\r
                }\r
        }\r
 \r
@@ -157,6 +169,11 @@ class Hooks {
         * @param array $params keys: uid, password\r
         */\r
        public static function setPassphrase($params) {\r
+\r
+               if (\OCP\App::isEnabled('files_encryption') === false) {\r
+                       return true;\r
+               }\r
+\r
                // Only attempt to change passphrase if server-side encryption\r
                // is in use (client-side encryption does not have access to\r
                // the necessary keys)\r
@@ -227,6 +244,10 @@ class Hooks {
         */\r
        public static function preShared($params) {\r
 \r
+               if (\OCP\App::isEnabled('files_encryption') === false) {\r
+                       return true;\r
+               }\r
+\r
                $l = new \OC_L10N('files_encryption');\r
                $users = array();\r
                $view = new \OC\Files\View('/public-keys/');\r
@@ -278,6 +299,10 @@ class Hooks {
                // [run] => whether emitting script should continue to run\r
                // TODO: Should other kinds of item be encrypted too?\r
 \r
+               if (\OCP\App::isEnabled('files_encryption') === false) {\r
+                       return true;\r
+               }\r
+\r
                if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {\r
 \r
                        $view = new \OC_FilesystemView('/');\r
@@ -372,6 +397,10 @@ class Hooks {
                // [shareWith] => test1\r
                // [itemParent] =>\r
 \r
+               if (\OCP\App::isEnabled('files_encryption') === false) {\r
+                       return true;\r
+               }\r
+\r
                if ($params['itemType'] === 'file' || $params['itemType'] === 'folder') {\r
 \r
                        $view = new \OC_FilesystemView('/');\r
@@ -453,6 +482,11 @@ class Hooks {
         * of the stored versions along the actual file\r
         */\r
        public static function postRename($params) {\r
+\r
+               if (\OCP\App::isEnabled('files_encryption') === false) {\r
+                       return true;\r
+               }\r
+\r
                // Disable encryption proxy to prevent recursive calls\r
                $proxyStatus = \OC_FileProxy::$enabled;\r
                \OC_FileProxy::$enabled = false;\r
index 3381f75f16df6e1794c7a63aeeac50152ac0a533..171999ea6523e141b7d6e9eac3269a15216bd5ee 100644 (file)
@@ -49,13 +49,6 @@ class Shared_Updater {
                                }
                                $users = $reshareUsers;
                        }
-                       // Correct folders of shared file owner
-                       $target = substr($target, 8);
-                       if ($uidOwner !== $uid && $source = \OC_Share_Backend_File::getSource($target)) {
-                               \OC\Files\Filesystem::initMountPoints($uidOwner);
-                               $source = '/'.$uidOwner.'/'.$source['path'];
-                               \OC\Files\Cache\Updater::correctFolder($source, $info['mtime']);
-                       }
                }
        }
 
index 1f30173a8f8b18d1a1741e4171217d45813bb3b0..6d016f9deac4576f5c9efcb28286a236ba5dbc0f 100644 (file)
@@ -94,6 +94,24 @@ class Updater {
                }
        }
 
+       /**
+        * @brief get file owner and path
+        * @param string $filename
+        * @return array with the oweners uid and the owners path
+        */
+       public static function getUidAndFilename($filename) {
+
+               $uid = \OC\Files\Filesystem::getOwner($filename);
+               \OC\Files\Filesystem::initMountPoints($uid);
+
+               if ($uid != \OCP\User::getUser()) {
+                       $info = \OC\Files\Filesystem::getFileInfo($filename);
+                       $ownerView = new \OC\Files\View('/' . $uid . '/files');
+                       $filename = $ownerView->getPath($info['fileid']);
+               }
+               return array($uid, '/files/' . $filename);
+       }
+
        /**
         * Update the mtime and ETag of all parent folders
         *
@@ -102,23 +120,29 @@ class Updater {
         */
        static public function correctFolder($path, $time) {
                if ($path !== '' && $path !== '/') {
-                       $parent = dirname($path);
-                       if ($parent === '.' || $parent === '\\') {
-                               $parent = '';
-                       }
+
+                       list($owner, $realPath) = self::getUidAndFilename(dirname($path));
+
                        /**
                         * @var \OC\Files\Storage\Storage $storage
                         * @var string $internalPath
                         */
-                       list($storage, $internalPath) = self::resolvePath($parent);
-                       if ($storage) {
-                               $cache = $storage->getCache();
-                               $id = $cache->getId($internalPath);
-                               if ($id !== -1) {
-                                       $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath)));
-                                       self::correctFolder($parent, $time);
+                       $view = new \OC\Files\View('/' . $owner);
+
+                       list($storage, $internalPath) = $view->resolvePath($realPath);
+                       $cache = $storage->getCache();
+                       $id = $cache->getId($internalPath);
+
+                       while ($id !== -1) {
+                               $cache->update($id, array('mtime' => $time, 'etag' => $storage->getETag($internalPath)));
+                               $realPath = dirname($realPath);
+                               // check storage for parent in case we change the storage in this step
+                               list($storage, $internalPath) = $view->resolvePath($realPath);
+                               if ($internalPath) {
+                                       $cache = $storage->getCache();
+                                       $id = $cache->getId($internalPath);
                                } else {
-                                       Util::writeLog('core', 'Path not in cache: '.$internalPath, Util::ERROR);
+                                       $id = -1;
                                }
                        }
                }
index 5d7997b054481219d06867713f6c25d8bfa4b7c3..9c1c6f8d18f596c5fe8ca98a809230dc99135f51 100644 (file)
@@ -21,6 +21,8 @@ class Updater extends \PHPUnit_Framework_TestCase {
         */
        private $scanner;
 
+       private $stateFilesEncryption;
+
        /**
         * @var \OC\Files\Cache\Cache $cache
         */
@@ -29,6 +31,12 @@ class Updater extends \PHPUnit_Framework_TestCase {
        private static $user;
 
        public function setUp() {
+
+               // remember files_encryption state
+               $this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
+               // we want to tests with the encryption app disabled
+               \OC_App::disable('files_encryption');
+
                $this->storage = new \OC\Files\Storage\Temporary(array());
                $textData = "dummy file data\n";
                $imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
@@ -46,6 +54,10 @@ class Updater extends \PHPUnit_Framework_TestCase {
                if (!self::$user) {
                        self::$user = uniqid();
                }
+
+               \OC_User::createUser(self::$user, 'password');
+               \OC_User::setUserId(self::$user);
+
                \OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
 
                Filesystem::clearMounts();
@@ -63,7 +75,13 @@ class Updater extends \PHPUnit_Framework_TestCase {
                if ($this->cache) {
                        $this->cache->clear();
                }
+               $result = \OC_User::deleteUser(self::$user);
+               $this->assertTrue($result);
                Filesystem::tearDown();
+               // reset app files_encryption
+               if ($this->stateFilesEncryption) {
+                       \OC_App::enable('files_encryption');
+               }
        }
 
        public function testWrite() {