Skip to content

Commit 1b577d3

Browse files
authored
Merge pull request #33500 from nextcloud/encryption-system-mount
add marker interface to mark system mount points for encryption
2 parents 5422051 + c2b206d commit 1b577d3

6 files changed

Lines changed: 71 additions & 44 deletions

File tree

apps/files_external/lib/Config/ConfigAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
163163
$storageConfig->getId()
164164
);
165165
} else {
166-
return new ExternalMountPoint(
166+
return new SystemMountPoint(
167167
$storageConfig,
168168
$storage,
169169
'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
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\Files_External\Config;
25+
26+
27+
use OCP\Files\Mount\ISystemMountPoint;
28+
29+
class SystemMountPoint extends ExternalMountPoint implements ISystemMountPoint {
30+
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@
314314
'OCP\\Files\\Lock\\OwnerLockedException' => $baseDir . '/lib/public/Files/Lock/OwnerLockedException.php',
315315
'OCP\\Files\\Mount\\IMountManager' => $baseDir . '/lib/public/Files/Mount/IMountManager.php',
316316
'OCP\\Files\\Mount\\IMountPoint' => $baseDir . '/lib/public/Files/Mount/IMountPoint.php',
317+
'OCP\\Files\\Mount\\ISystemMountPoint' => $baseDir . '/lib/public/Files/Mount/ISystemMountPoint.php',
317318
'OCP\\Files\\Node' => $baseDir . '/lib/public/Files/Node.php',
318319
'OCP\\Files\\NotEnoughSpaceException' => $baseDir . '/lib/public/Files/NotEnoughSpaceException.php',
319320
'OCP\\Files\\NotFoundException' => $baseDir . '/lib/public/Files/NotFoundException.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
347347
'OCP\\Files\\Lock\\OwnerLockedException' => __DIR__ . '/../../..' . '/lib/public/Files/Lock/OwnerLockedException.php',
348348
'OCP\\Files\\Mount\\IMountManager' => __DIR__ . '/../../..' . '/lib/public/Files/Mount/IMountManager.php',
349349
'OCP\\Files\\Mount\\IMountPoint' => __DIR__ . '/../../..' . '/lib/public/Files/Mount/IMountPoint.php',
350+
'OCP\\Files\\Mount\\ISystemMountPoint' => __DIR__ . '/../../..' . '/lib/public/Files/Mount/ISystemMountPoint.php',
350351
'OCP\\Files\\Node' => __DIR__ . '/../../..' . '/lib/public/Files/Node.php',
351352
'OCP\\Files\\NotEnoughSpaceException' => __DIR__ . '/../../..' . '/lib/public/Files/NotEnoughSpaceException.php',
352353
'OCP\\Files\\NotFoundException' => __DIR__ . '/../../..' . '/lib/public/Files/NotFoundException.php',

lib/private/Encryption/Util.php

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@
3232
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
3333
use OC\Files\Filesystem;
3434
use OC\Files\View;
35-
use OCA\Files_External\Lib\StorageConfig;
36-
use OCA\Files_External\Service\GlobalStoragesService;
37-
use OCP\App\IAppManager;
3835
use OCP\Encryption\IEncryptionModule;
36+
use OCP\Files\Mount\ISystemMountPoint;
3937
use OCP\IConfig;
4038
use OCP\IGroupManager;
4139
use OCP\IUser;
@@ -295,46 +293,9 @@ public function getUserWithAccessToMountPoint($users, $groups) {
295293
* @param string $uid
296294
* @return boolean
297295
*/
298-
public function isSystemWideMountPoint($path, $uid) {
299-
// No DI here as this initialise the db too soon
300-
if (\OCP\Server::get(IAppManager::class)->isEnabledForUser("files_external")) {
301-
/** @var GlobalStoragesService $storageService */
302-
$storageService = \OC::$server->get(GlobalStoragesService::class);
303-
$storages = $storageService->getAllStorages();
304-
foreach ($storages as $storage) {
305-
if (strpos($path, '/files/' . ltrim($storage->getMountPoint(), '/')) === 0) {
306-
if ($this->isMountPointApplicableToUser($storage, $uid)) {
307-
return true;
308-
}
309-
}
310-
}
311-
}
312-
return false;
313-
}
314-
315-
/**
316-
* check if mount point is applicable to user
317-
*
318-
* @param StorageConfig $mount
319-
* @param string $uid
320-
* @return boolean
321-
*/
322-
private function isMountPointApplicableToUser(StorageConfig $mount, string $uid) {
323-
if ($mount->getApplicableUsers() === [] && $mount->getApplicableGroups() === []) {
324-
// applicable for everyone
325-
return true;
326-
}
327-
// check if mount point is applicable for the user
328-
if (array_search($uid, $mount->getApplicableUsers()) !== false) {
329-
return true;
330-
}
331-
// check if mount point is applicable for group where the user is a member
332-
foreach ($mount->getApplicableGroups() as $gid) {
333-
if ($this->groupManager->isInGroup($uid, $gid)) {
334-
return true;
335-
}
336-
}
337-
return false;
296+
public function isSystemWideMountPoint(string $path, string $uid) {
297+
$mount = Filesystem::getMountManager()->find('/' . $uid . $path);
298+
return $mount instanceof ISystemMountPoint;
338299
}
339300

340301
/**
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
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 OCP\Files\Mount;
25+
26+
/**
27+
* Mark a mountpoint as containing system data, meaning that the data is not user specific
28+
*
29+
* Example use case is signaling to the encryption wrapper that system-wide keys should be used for a mountpoint
30+
*
31+
* @since 25.0.0
32+
*/
33+
interface ISystemMountPoint extends IMountPoint {
34+
}

0 commit comments

Comments
 (0)