Skip to content

Commit ec00cf3

Browse files
authored
Merge pull request #2103 from nextcloud/groupfolder-encryption-23
[stable23] allow enabling encryption for groupfolders
2 parents 3f39fe1 + a4c8b45 commit ec00cf3

File tree

5 files changed

+58
-22
lines changed

5 files changed

+58
-22
lines changed

lib/AppInfo/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function register(IRegistrationContext $context): void {
7676
};
7777
$config = $c->get(IConfig::class);
7878
$allowRootShare = $config->getAppValue('groupfolders', 'allow_root_share', 'true') === 'true';
79+
$enableEncryption = $config->getAppValue('groupfolders', 'enable_encryption', 'false') === 'true';
7980

8081
return new MountProvider(
8182
$c->getServer()->getGroupManager(),
@@ -87,7 +88,8 @@ public function register(IRegistrationContext $context): void {
8788
$c->get(ISession::class),
8889
$c->get(IMountProviderCollection::class),
8990
$c->get(IDBConnection::class),
90-
$allowRootShare
91+
$allowRootShare,
92+
$enableEncryption
9193
);
9294
});
9395

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2022 Robin Appelman <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCA\GroupFolders\Mount;
25+
26+
use OCP\Files\Storage\IDisableEncryptionStorage;
27+
28+
class GroupFolderNoEncryptionStorage extends GroupFolderStorage implements IDisableEncryptionStorage {
29+
}

lib/Mount/GroupFolderStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use OCP\IUser;
3131
use OCP\IUserSession;
3232

33-
class GroupFolderStorage extends Quota implements IDisableEncryptionStorage {
33+
class GroupFolderStorage extends Quota {
3434
/** @var int */
3535
private $folderId;
3636

lib/Mount/GroupMountPoint.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,6 @@ public function getMountType() {
3636
return 'group';
3737
}
3838

39-
public function getOption($name, $default) {
40-
$options = $this->getOptions();
41-
return isset($options[$name]) ? $options[$name] : $default;
42-
}
43-
44-
public function getOptions() {
45-
$options = parent::getOptions();
46-
$options['encrypt'] = false;
47-
return $options;
48-
}
49-
5039
public function getFolderId(): int {
5140
return $this->folderId;
5241
}

lib/Mount/MountProvider.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class MountProvider implements IMountProvider {
6969
private $connection;
7070
private $allowRootShare;
7171

72+
/** @var bool */
73+
private $enableEncryption;
74+
7275
public function __construct(
7376
IGroupManager $groupProvider,
7477
FolderManager $folderManager,
@@ -79,7 +82,8 @@ public function __construct(
7982
ISession $session,
8083
IMountProviderCollection $mountProviderCollection,
8184
IDBConnection $connection,
82-
bool $allowRootShare
85+
bool $allowRootShare,
86+
bool $enableEncryption
8387
) {
8488
$this->groupProvider = $groupProvider;
8589
$this->folderManager = $folderManager;
@@ -91,6 +95,7 @@ public function __construct(
9195
$this->mountProviderCollection = $mountProviderCollection;
9296
$this->connection = $connection;
9397
$this->allowRootShare = $allowRootShare;
98+
$this->enableEncryption = $enableEncryption;
9499
}
95100

96101
/**
@@ -189,14 +194,25 @@ public function getMount(int $id, string $mountPoint, int $permissions, int $quo
189194
'storage' => $storage,
190195
'root' => $rootPath
191196
]);
192-
$quotaStorage = new GroupFolderStorage([
193-
'storage' => $baseStorage,
194-
'quota' => $quota,
195-
'folder_id' => $id,
196-
'rootCacheEntry' => $cacheEntry,
197-
'userSession' => $this->userSession,
198-
'mountOwner' => $user,
199-
]);
197+
if ($this->enableEncryption) {
198+
$quotaStorage = new GroupFolderStorage([
199+
'storage' => $baseStorage,
200+
'quota' => $quota,
201+
'folder_id' => $id,
202+
'rootCacheEntry' => $cacheEntry,
203+
'userSession' => $this->userSession,
204+
'mountOwner' => $user,
205+
]);
206+
} else {
207+
$quotaStorage = new GroupFolderNoEncryptionStorage([
208+
'storage' => $baseStorage,
209+
'quota' => $quota,
210+
'folder_id' => $id,
211+
'rootCacheEntry' => $cacheEntry,
212+
'userSession' => $this->userSession,
213+
'mountOwner' => $user,
214+
]);
215+
}
200216
$maskedStore = new PermissionsMask([
201217
'storage' => $quotaStorage,
202218
'mask' => $permissions

0 commit comments

Comments
 (0)