diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-08-31 13:16:46 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 13:16:46 +0300 |
commit | 56b30df8efc57b94700af4ccce018933d28c2b83 (patch) | |
tree | 53319dfa8bc7494b62f61cd31a01be1fb57b6f40 | |
parent | ffde3e6bb1495913473d769cfac83f5e8b4780be (diff) | |
parent | 74230a99c455d0cbb230f3171db7d85f8f9ddbda (diff) |
Merge pull request #2068 from nextcloud/groupfolder-encryption-24
[24] allow enabling encryption for groupfolders
-rw-r--r-- | lib/AppInfo/Application.php | 4 | ||||
-rw-r--r-- | lib/Mount/GroupFolderNoEncryptionStorage.php | 29 | ||||
-rw-r--r-- | lib/Mount/GroupFolderStorage.php | 2 | ||||
-rw-r--r-- | lib/Mount/GroupMountPoint.php | 11 | ||||
-rw-r--r-- | lib/Mount/MountProvider.php | 32 | ||||
-rw-r--r-- | tests/stub.phpstub | 42 |
6 files changed, 79 insertions, 41 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 890ea3e2..f6b448fa 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -78,6 +78,7 @@ class Application extends App implements IBootstrap { }; $config = $c->get(IConfig::class); $allowRootShare = $config->getAppValue('groupfolders', 'allow_root_share', 'true') === 'true'; + $enableEncryption = $config->getAppValue('groupfolders', 'enable_encryption', 'false') === 'true'; return new MountProvider( $c->getServer()->getGroupManager(), @@ -90,7 +91,8 @@ class Application extends App implements IBootstrap { $c->get(IMountProviderCollection::class), $c->get(IDBConnection::class), $c->get(ICacheFactory::class)->createLocal("groupfolders"), - $allowRootShare + $allowRootShare, + $enableEncryption ); }); diff --git a/lib/Mount/GroupFolderNoEncryptionStorage.php b/lib/Mount/GroupFolderNoEncryptionStorage.php new file mode 100644 index 00000000..cab74cf3 --- /dev/null +++ b/lib/Mount/GroupFolderNoEncryptionStorage.php @@ -0,0 +1,29 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\GroupFolders\Mount; + +use OCP\Files\Storage\IDisableEncryptionStorage; + +class GroupFolderNoEncryptionStorage extends GroupFolderStorage implements IDisableEncryptionStorage { +} diff --git a/lib/Mount/GroupFolderStorage.php b/lib/Mount/GroupFolderStorage.php index d3215137..de9c674b 100644 --- a/lib/Mount/GroupFolderStorage.php +++ b/lib/Mount/GroupFolderStorage.php @@ -30,7 +30,7 @@ use OCP\Files\Storage\IDisableEncryptionStorage; use OCP\IUser; use OCP\IUserSession; -class GroupFolderStorage extends Quota implements IDisableEncryptionStorage { +class GroupFolderStorage extends Quota { private int $folderId; private ICacheEntry $rootEntry; private IUserSession $userSession; diff --git a/lib/Mount/GroupMountPoint.php b/lib/Mount/GroupMountPoint.php index 9aaa41e0..b2684bb7 100644 --- a/lib/Mount/GroupMountPoint.php +++ b/lib/Mount/GroupMountPoint.php @@ -36,17 +36,6 @@ class GroupMountPoint extends MountPoint { return 'group'; } - public function getOption($name, $default) { - $options = $this->getOptions(); - return isset($options[$name]) ? $options[$name] : $default; - } - - public function getOptions() { - $options = parent::getOptions(); - $options['encrypt'] = false; - return $options; - } - public function getFolderId(): int { return $this->folderId; } diff --git a/lib/Mount/MountProvider.php b/lib/Mount/MountProvider.php index 9f5c09dd..474ab12e 100644 --- a/lib/Mount/MountProvider.php +++ b/lib/Mount/MountProvider.php @@ -71,6 +71,7 @@ class MountProvider implements IMountProvider { private ICache $cache; private ?int $rootStorageId = null; private bool $allowRootShare; + private bool $enableEncryption; public function __construct( IGroupManager $groupProvider, @@ -83,7 +84,8 @@ class MountProvider implements IMountProvider { IMountProviderCollection $mountProviderCollection, IDBConnection $connection, ICache $cache, - bool $allowRootShare + bool $allowRootShare, + bool $enableEncryption ) { $this->groupProvider = $groupProvider; $this->folderManager = $folderManager; @@ -96,6 +98,7 @@ class MountProvider implements IMountProvider { $this->connection = $connection; $this->cache = $cache; $this->allowRootShare = $allowRootShare; + $this->enableEncryption = $enableEncryption; } private function getRootStorageId(): int { @@ -208,14 +211,25 @@ class MountProvider implements IMountProvider { 'storage' => $storage, 'root' => $rootPath ]); - $quotaStorage = new GroupFolderStorage([ - 'storage' => $baseStorage, - 'quota' => $quota, - 'folder_id' => $id, - 'rootCacheEntry' => $cacheEntry, - 'userSession' => $this->userSession, - 'mountOwner' => $user, - ]); + if ($this->enableEncryption) { + $quotaStorage = new GroupFolderStorage([ + 'storage' => $baseStorage, + 'quota' => $quota, + 'folder_id' => $id, + 'rootCacheEntry' => $cacheEntry, + 'userSession' => $this->userSession, + 'mountOwner' => $user, + ]); + } else { + $quotaStorage = new GroupFolderNoEncryptionStorage([ + 'storage' => $baseStorage, + 'quota' => $quota, + 'folder_id' => $id, + 'rootCacheEntry' => $cacheEntry, + 'userSession' => $this->userSession, + 'mountOwner' => $user, + ]); + } $maskedStore = new PermissionsMask([ 'storage' => $quotaStorage, 'mask' => $permissions diff --git a/tests/stub.phpstub b/tests/stub.phpstub index 0b6a2762..98622c62 100644 --- a/tests/stub.phpstub +++ b/tests/stub.phpstub @@ -61,15 +61,15 @@ namespace OCA\Files_Trashbin\Trash { interface ITrashItem extends FileInfo { public function getTrashBackend(): ITrashBackend; - + public function getOriginalLocation(): string; - + public function getDeletedTime(): int; - + public function getTrashPath(): string; - + public function isRootItem(): bool; - + public function getUser(): IUser; public function getTitle(): string; @@ -603,10 +603,10 @@ namespace OC\Files\Mount { protected $class; protected $storageId; protected $rootId = null; - + /** @var int|null */ protected $mountId; - + /** * @param string|\OCP\Files\Storage\IStorage $storage * @param string $mountpoint @@ -619,7 +619,7 @@ namespace OC\Files\Mount { public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { throw new \Exception('stub'); } - + /** * get complete path to the mount point, relative to data/ * @@ -628,7 +628,7 @@ namespace OC\Files\Mount { public function getMountPoint() { throw new \Exception('stub'); } - + /** * Sets the mount point path, relative to data/ * @@ -637,28 +637,28 @@ namespace OC\Files\Mount { public function setMountPoint($mountPoint) { throw new \Exception('stub'); } - + /** * @return \OCP\Files\Storage\IStorage */ public function getStorage() { throw new \Exception('stub'); } - + /** * @return string */ public function getStorageId() { throw new \Exception('stub'); } - + /** * @return int */ public function getNumericStorageId() { throw new \Exception('stub'); } - + /** * @param string $path * @return string @@ -666,14 +666,14 @@ namespace OC\Files\Mount { public function getInternalPath($path) { throw new \Exception('stub'); } - + /** * @param callable $wrapper */ public function wrapStorage($wrapper) { throw new \Exception('stub'); } - + /** * Get a mount option * @@ -684,7 +684,7 @@ namespace OC\Files\Mount { public function getOption($name, $default) { throw new \Exception('stub'); } - + /** * Get all options for the mount * @@ -693,18 +693,18 @@ namespace OC\Files\Mount { public function getOptions() { throw new \Exception('stub'); } - + /** * @return int */ public function getStorageRootId() { throw new \Exception('stub'); } - + public function getMountId() { throw new \Exception('stub'); } - + public function getMountType() { throw new \Exception('stub'); } @@ -915,3 +915,7 @@ namespace OC\Files\Storage\Wrapper{ public function getQuota() {} } } + +namespace OCP\Files\Mount\ISystemMountPoint { + interface ISystemMountPoint {} +} |