From ab2e25b5a32d380c6a1c8066f81fd819f9ea9a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 26 Apr 2024 13:42:30 +0200 Subject: [PATCH] fix: Fix Encryption wrapper not seen by group folder cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Jail wrappers reuse the cache of the wrapped storage even if another storage is explicitly given. Due to that, when the cache is got from an storage and that storage has a Jail all the wrappers above it are not known to the cache, and only those wrapped by the Jail are taken into account. In general that works fine, as in most cases the cache does not need to know the details of a storage. However, it needs to know if an Encryption wrapper is present in the storage when moving files into it, as the file cache explicitly clears the "encrypted" flag when moving a file from an encrypted storage to a non encrypted storage. As the Encryption wrapper of groupfolders was not known to the cache all files moved from an encrypted storage to an encrypted groupfolder ended wrongly marked as not encrypted. To solve that now the Jail used by groupfolders does not reuse the inner cache when encryption is enabled, and instead passes the given storage. This is applied only when encryption is enabled, as reusing the inner cache was done as a performance optimization. Signed-off-by: Daniel Calviño Sánchez --- lib/Mount/GroupFolderEncryptionJail.php | 44 +++++++++++++++++++++++++ lib/Mount/MountProvider.php | 12 ++++--- 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 lib/Mount/GroupFolderEncryptionJail.php diff --git a/lib/Mount/GroupFolderEncryptionJail.php b/lib/Mount/GroupFolderEncryptionJail.php new file mode 100644 index 000000000..864347e79 --- /dev/null +++ b/lib/Mount/GroupFolderEncryptionJail.php @@ -0,0 +1,44 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\GroupFolders\Mount; + +use OC\Files\Cache\Wrapper\CacheJail; +use OC\Files\Storage\Wrapper\Jail; + +/** + * Jail with overridden behaviors specific to group folders when encryption is + * enabled. + */ +class GroupFolderEncryptionJail extends Jail { + public function getCache($path = '', $storage = null) { + if (!$storage) { + $storage = $this->getWrapperStorage(); + } + // By default the Jail reuses the inner cache, but when encryption is + // enabled the storage needs to be passed to the cache so it takes into + // account the outer Encryption wrapper. + $sourceCache = $this->getWrapperStorage()->getCache($this->getUnjailedPath($path), $storage); + return new CacheJail($sourceCache, $this->rootPath); + } +} diff --git a/lib/Mount/MountProvider.php b/lib/Mount/MountProvider.php index 4ce4e79c1..0e5918ce7 100644 --- a/lib/Mount/MountProvider.php +++ b/lib/Mount/MountProvider.php @@ -232,11 +232,11 @@ public function getMount( $cacheEntry['permissions'] &= $aclRootPermissions; } - $baseStorage = new Jail([ - 'storage' => $storage, - 'root' => $rootPath - ]); if ($this->enableEncryption) { + $baseStorage = new GroupFolderEncryptionJail([ + 'storage' => $storage, + 'root' => $rootPath + ]); $quotaStorage = new GroupFolderStorage([ 'storage' => $baseStorage, 'quota' => $quota, @@ -246,6 +246,10 @@ public function getMount( 'mountOwner' => $user, ]); } else { + $baseStorage = new Jail([ + 'storage' => $storage, + 'root' => $rootPath + ]); $quotaStorage = new GroupFolderNoEncryptionStorage([ 'storage' => $baseStorage, 'quota' => $quota,