Skip to content

Commit 208c87c

Browse files
authored
Merge pull request #3481 from nextcloud/backport/3425/stable30
[stable30] Encryption trash fixes
2 parents 7771396 + 61a1818 commit 208c87c

File tree

5 files changed

+236
-83
lines changed

5 files changed

+236
-83
lines changed

β€Žlib/Mount/GroupFolderStorage.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
use OC\Files\ObjectStore\ObjectStoreScanner;
1111
use OC\Files\ObjectStore\ObjectStoreStorage;
1212
use OC\Files\Storage\Wrapper\Quota;
13+
use OCP\Files\Cache\ICache;
1314
use OCP\Files\Cache\ICacheEntry;
1415
use OCP\IUser;
1516
use OCP\IUserSession;
1617

1718
class GroupFolderStorage extends Quota {
1819
private int $folderId;
19-
private ICacheEntry $rootEntry;
20+
private ?ICacheEntry $rootEntry;
2021
private IUserSession $userSession;
21-
private ?IUser $mountOwner = null;
22-
/** @var RootEntryCache|null */
22+
private ?IUser $mountOwner;
23+
/** @var ICache|null */
2324
public $cache = null;
2425

2526
public function __construct($parameters) {
@@ -53,7 +54,12 @@ public function getCache($path = '', $storage = null) {
5354
$storage = $this;
5455
}
5556

56-
$this->cache = new RootEntryCache(parent::getCache($path, $storage), $this->rootEntry);
57+
$cache = parent::getCache($path, $storage);
58+
if ($this->rootEntry !== null) {
59+
$cache = new RootEntryCache($cache, $this->rootEntry);
60+
}
61+
$this->cache = $cache;
62+
5763
return $this->cache;
5864
}
5965

β€Žlib/Mount/MountProvider.php

+90-35
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
128128
$aclManager = $this->aclManagerFactory->getACLManager($user, $this->getRootStorageId());
129129
$rootRules = $aclManager->getRelevantRulesForPath($aclRootPaths);
130130

131-
return array_values(array_filter(array_map(function ($folder) use ($user, $loader, $conflicts, $aclManager, $rootRules) {
131+
return array_merge(...array_filter(array_map(function (array $folder) use ($user, $loader, $conflicts, $aclManager, $rootRules): ?array {
132132
// check for existing files in the user home and rename them if needed
133133
$originalFolderName = $folder['mount_point'];
134134
if (in_array($originalFolderName, $conflicts)) {
@@ -147,7 +147,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
147147
$userStorage->getPropagator()->propagateChange("files/$folderName", time());
148148
}
149149

150-
return $this->getMount(
150+
$mount = $this->getMount(
151151
$folder['folder_id'],
152152
'/' . $user->getUID() . '/files/' . $folder['mount_point'],
153153
$folder['permissions'],
@@ -159,6 +159,22 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
159159
$aclManager,
160160
$rootRules
161161
);
162+
if (!$mount) {
163+
return null;
164+
}
165+
$trashMount = $this->getTrashMount(
166+
$folder['folder_id'],
167+
'/' . $user->getUID() . '/files_trashbin/groupfolders/' . $folder['folder_id'],
168+
$folder['quota'],
169+
$loader,
170+
$user
171+
);
172+
173+
return [
174+
$mount,
175+
$trashMount,
176+
];
177+
162178
}, $folders)));
163179
}
164180

@@ -181,16 +197,16 @@ private function getCurrentUID(): ?string {
181197
}
182198

183199
public function getMount(
184-
int $id,
185-
string $mountPoint,
186-
int $permissions,
187-
int $quota,
188-
?ICacheEntry $cacheEntry = null,
200+
int $id,
201+
string $mountPoint,
202+
int $permissions,
203+
int $quota,
204+
?ICacheEntry $cacheEntry = null,
189205
?IStorageFactory $loader = null,
190-
bool $acl = false,
191-
?IUser $user = null,
192-
?ACLManager $aclManager = null,
193-
array $rootRules = []
206+
bool $acl = false,
207+
?IUser $user = null,
208+
?ACLManager $aclManager = null,
209+
array $rootRules = []
194210
): ?IMountPoint {
195211
if (!$cacheEntry) {
196212
// trigger folder creation
@@ -220,52 +236,91 @@ public function getMount(
220236
$cacheEntry['permissions'] &= $aclRootPermissions;
221237
}
222238

239+
$quotaStorage = $this->getGroupFolderStorage($id, $storage, $user, $rootPath, $quota, $cacheEntry);
240+
241+
$maskedStore = new PermissionsMask([
242+
'storage' => $quotaStorage,
243+
'mask' => $permissions,
244+
]);
245+
246+
if (!$this->allowRootShare) {
247+
$maskedStore = new RootPermissionsMask([
248+
'storage' => $maskedStore,
249+
'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
250+
]);
251+
}
252+
253+
return new GroupMountPoint(
254+
$id,
255+
$maskedStore,
256+
$mountPoint,
257+
null,
258+
$loader
259+
);
260+
}
261+
262+
public function getTrashMount(
263+
int $id,
264+
string $mountPoint,
265+
int $quota,
266+
IStorageFactory $loader,
267+
IUser $user,
268+
): IMountPoint {
269+
270+
$storage = $this->getRootFolder()->getStorage();
271+
272+
$storage->setOwner($user->getUID());
273+
274+
$trashPath = $this->getRootFolder()->getInternalPath() . '/trash/' . $id;
275+
276+
$trashStorage = $this->getGroupFolderStorage($id, $storage, $user, $trashPath, $quota, null);
277+
278+
return new GroupMountPoint(
279+
$id,
280+
$trashStorage,
281+
$mountPoint,
282+
null,
283+
$loader
284+
);
285+
}
286+
287+
public function getGroupFolderStorage(
288+
int $id,
289+
IStorage $rootStorage,
290+
?IUser $user,
291+
string $rootPath,
292+
int $quota,
293+
?ICacheEntry $rootCacheEntry,
294+
): IStorage {
223295
if ($this->enableEncryption) {
224296
$baseStorage = new GroupFolderEncryptionJail([
225-
'storage' => $storage,
226-
'root' => $rootPath
297+
'storage' => $rootStorage,
298+
'root' => $rootPath,
227299
]);
228300
$quotaStorage = new GroupFolderStorage([
229301
'storage' => $baseStorage,
230302
'quota' => $quota,
231303
'folder_id' => $id,
232-
'rootCacheEntry' => $cacheEntry,
304+
'rootCacheEntry' => $rootCacheEntry,
233305
'userSession' => $this->userSession,
234306
'mountOwner' => $user,
235307
]);
236308
} else {
237309
$baseStorage = new Jail([
238-
'storage' => $storage,
239-
'root' => $rootPath
310+
'storage' => $rootStorage,
311+
'root' => $rootPath,
240312
]);
241313
$quotaStorage = new GroupFolderNoEncryptionStorage([
242314
'storage' => $baseStorage,
243315
'quota' => $quota,
244316
'folder_id' => $id,
245-
'rootCacheEntry' => $cacheEntry,
317+
'rootCacheEntry' => $rootCacheEntry,
246318
'userSession' => $this->userSession,
247319
'mountOwner' => $user,
248320
]);
249321
}
250-
$maskedStore = new PermissionsMask([
251-
'storage' => $quotaStorage,
252-
'mask' => $permissions
253-
]);
254-
255-
if (!$this->allowRootShare) {
256-
$maskedStore = new RootPermissionsMask([
257-
'storage' => $maskedStore,
258-
'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
259-
]);
260-
}
261322

262-
return new GroupMountPoint(
263-
$id,
264-
$maskedStore,
265-
$mountPoint,
266-
null,
267-
$loader
268-
);
323+
return $quotaStorage;
269324
}
270325

271326
public function getJailPath(int $folderId): string {

β€Žlib/Trash/GroupTrashItem.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace OCA\GroupFolders\Trash;
88

9-
use OC\Files\Storage\Wrapper\Jail;
109
use OCA\Files_Trashbin\Trash\ITrashBackend;
1110
use OCA\Files_Trashbin\Trash\TrashItem;
1211
use OCP\Files\FileInfo;
@@ -45,18 +44,7 @@ public function getTitle(): string {
4544
return $this->getGroupFolderMountPoint() . '/' . $this->getOriginalLocation();
4645
}
4746

48-
public function getStorage() {
49-
// get the unjailed storage, since the trash item is outside the jail
50-
// (the internal path is also unjailed)
51-
$groupFolderStorage = parent::getStorage();
52-
if ($groupFolderStorage->instanceOfStorage(Jail::class)) {
53-
/** @var Jail $groupFolderStorage */
54-
return $groupFolderStorage->getUnjailedStorage();
55-
}
56-
return $groupFolderStorage;
57-
}
58-
59-
public function getMtime() {
47+
public function getMtime(): int {
6048
// trashbin is currently (incorrectly) assuming these to be the same
6149
return $this->getDeletedTime();
6250
}

0 commit comments

Comments
Β (0)