Skip to content

Commit ef19f1f

Browse files
authored
Merge pull request #3484 from nextcloud/backport/3481/stable29
[stable29] Encryption trash fixes
2 parents 2468718 + 1366597 commit ef19f1f

File tree

6 files changed

+927
-182
lines changed

6 files changed

+927
-182
lines changed

β€Žlib/AppInfo/Application.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ public function register(IRegistrationContext $context): void {
142142
$c->get(MountProvider::class),
143143
$c->get(ACLManagerFactory::class),
144144
$c->get(IRootFolder::class),
145-
$c->get(LoggerInterface::class)
145+
$c->get(LoggerInterface::class),
146+
$c->get(IUserSession::class),
146147
);
147148
$hasVersionApp = interface_exists(\OCA\Files_Versions\Versions\IVersionBackend::class);
148149
if ($hasVersionApp) {

β€Žlib/Mount/GroupFolderStorage.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@
2525
use OC\Files\ObjectStore\ObjectStoreScanner;
2626
use OC\Files\ObjectStore\ObjectStoreStorage;
2727
use OC\Files\Storage\Wrapper\Quota;
28+
use OCP\Files\Cache\ICache;
2829
use OCP\Files\Cache\ICacheEntry;
2930
use OCP\IUser;
3031
use OCP\IUserSession;
3132

3233
class GroupFolderStorage extends Quota {
3334
private int $folderId;
34-
private ICacheEntry $rootEntry;
35+
private ?ICacheEntry $rootEntry;
3536
private IUserSession $userSession;
36-
private ?IUser $mountOwner = null;
37-
/** @var RootEntryCache|null */
37+
private ?IUser $mountOwner;
38+
/** @var ICache|null */
3839
public $cache = null;
3940

4041
public function __construct($parameters) {
@@ -68,7 +69,12 @@ public function getCache($path = '', $storage = null) {
6869
$storage = $this;
6970
}
7071

71-
$this->cache = new RootEntryCache(parent::getCache($path, $storage), $this->rootEntry);
72+
$cache = parent::getCache($path, $storage);
73+
if ($this->rootEntry !== null) {
74+
$cache = new RootEntryCache($cache, $this->rootEntry);
75+
}
76+
$this->cache = $cache;
77+
7278
return $this->cache;
7379
}
7480

β€Žlib/Mount/MountProvider.php

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

143-
return array_values(array_filter(array_map(function ($folder) use ($user, $loader, $conflicts, $aclManager, $rootRules) {
143+
return array_merge(...array_filter(array_map(function (array $folder) use ($user, $loader, $conflicts, $aclManager, $rootRules): ?array {
144144
// check for existing files in the user home and rename them if needed
145145
$originalFolderName = $folder['mount_point'];
146146
if (in_array($originalFolderName, $conflicts)) {
@@ -159,7 +159,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
159159
$userStorage->getPropagator()->propagateChange("files/$folderName", time());
160160
}
161161

162-
return $this->getMount(
162+
$mount = $this->getMount(
163163
$folder['folder_id'],
164164
'/' . $user->getUID() . '/files/' . $folder['mount_point'],
165165
$folder['permissions'],
@@ -171,6 +171,22 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
171171
$aclManager,
172172
$rootRules
173173
);
174+
if (!$mount) {
175+
return null;
176+
}
177+
$trashMount = $this->getTrashMount(
178+
$folder['folder_id'],
179+
'/' . $user->getUID() . '/files_trashbin/groupfolders/' . $folder['folder_id'],
180+
$folder['quota'],
181+
$loader,
182+
$user
183+
);
184+
185+
return [
186+
$mount,
187+
$trashMount,
188+
];
189+
174190
}, $folders)));
175191
}
176192

@@ -193,16 +209,16 @@ private function getCurrentUID(): ?string {
193209
}
194210

195211
public function getMount(
196-
int $id,
197-
string $mountPoint,
198-
int $permissions,
199-
int $quota,
200-
?ICacheEntry $cacheEntry = null,
212+
int $id,
213+
string $mountPoint,
214+
int $permissions,
215+
int $quota,
216+
?ICacheEntry $cacheEntry = null,
201217
?IStorageFactory $loader = null,
202-
bool $acl = false,
203-
?IUser $user = null,
204-
?ACLManager $aclManager = null,
205-
array $rootRules = []
218+
bool $acl = false,
219+
?IUser $user = null,
220+
?ACLManager $aclManager = null,
221+
array $rootRules = []
206222
): ?IMountPoint {
207223
if (!$cacheEntry) {
208224
// trigger folder creation
@@ -230,52 +246,91 @@ public function getMount(
230246
$cacheEntry['permissions'] &= $aclRootPermissions;
231247
}
232248

249+
$quotaStorage = $this->getGroupFolderStorage($id, $storage, $user, $rootPath, $quota, $cacheEntry);
250+
251+
$maskedStore = new PermissionsMask([
252+
'storage' => $quotaStorage,
253+
'mask' => $permissions,
254+
]);
255+
256+
if (!$this->allowRootShare) {
257+
$maskedStore = new RootPermissionsMask([
258+
'storage' => $maskedStore,
259+
'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
260+
]);
261+
}
262+
263+
return new GroupMountPoint(
264+
$id,
265+
$maskedStore,
266+
$mountPoint,
267+
null,
268+
$loader
269+
);
270+
}
271+
272+
public function getTrashMount(
273+
int $id,
274+
string $mountPoint,
275+
int $quota,
276+
IStorageFactory $loader,
277+
IUser $user,
278+
): IMountPoint {
279+
280+
$storage = $this->getRootFolder()->getStorage();
281+
282+
$storage->setOwner($user->getUID());
283+
284+
$trashPath = $this->getRootFolder()->getInternalPath() . '/trash/' . $id;
285+
286+
$trashStorage = $this->getGroupFolderStorage($id, $storage, $user, $trashPath, $quota, null);
287+
288+
return new GroupMountPoint(
289+
$id,
290+
$trashStorage,
291+
$mountPoint,
292+
null,
293+
$loader
294+
);
295+
}
296+
297+
public function getGroupFolderStorage(
298+
int $id,
299+
IStorage $rootStorage,
300+
?IUser $user,
301+
string $rootPath,
302+
int $quota,
303+
?ICacheEntry $rootCacheEntry,
304+
): IStorage {
233305
if ($this->enableEncryption) {
234306
$baseStorage = new GroupFolderEncryptionJail([
235-
'storage' => $storage,
236-
'root' => $rootPath
307+
'storage' => $rootStorage,
308+
'root' => $rootPath,
237309
]);
238310
$quotaStorage = new GroupFolderStorage([
239311
'storage' => $baseStorage,
240312
'quota' => $quota,
241313
'folder_id' => $id,
242-
'rootCacheEntry' => $cacheEntry,
314+
'rootCacheEntry' => $rootCacheEntry,
243315
'userSession' => $this->userSession,
244316
'mountOwner' => $user,
245317
]);
246318
} else {
247319
$baseStorage = new Jail([
248-
'storage' => $storage,
249-
'root' => $rootPath
320+
'storage' => $rootStorage,
321+
'root' => $rootPath,
250322
]);
251323
$quotaStorage = new GroupFolderNoEncryptionStorage([
252324
'storage' => $baseStorage,
253325
'quota' => $quota,
254326
'folder_id' => $id,
255-
'rootCacheEntry' => $cacheEntry,
327+
'rootCacheEntry' => $rootCacheEntry,
256328
'userSession' => $this->userSession,
257329
'mountOwner' => $user,
258330
]);
259331
}
260-
$maskedStore = new PermissionsMask([
261-
'storage' => $quotaStorage,
262-
'mask' => $permissions
263-
]);
264-
265-
if (!$this->allowRootShare) {
266-
$maskedStore = new RootPermissionsMask([
267-
'storage' => $maskedStore,
268-
'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
269-
]);
270-
}
271332

272-
return new GroupMountPoint(
273-
$id,
274-
$maskedStore,
275-
$mountPoint,
276-
null,
277-
$loader
278-
);
333+
return $quotaStorage;
279334
}
280335

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

β€Žlib/Trash/GroupTrashItem.php

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

2222
namespace OCA\GroupFolders\Trash;
2323

24-
use OC\Files\Storage\Wrapper\Jail;
2524
use OCA\Files_Trashbin\Trash\ITrashBackend;
2625
use OCA\Files_Trashbin\Trash\TrashItem;
2726
use OCP\Files\FileInfo;
@@ -59,18 +58,7 @@ public function getTitle(): string {
5958
return $this->getGroupFolderMountPoint() . '/' . $this->getOriginalLocation();
6059
}
6160

62-
public function getStorage() {
63-
// get the unjailed storage, since the trash item is outside the jail
64-
// (the internal path is also unjailed)
65-
$groupFolderStorage = parent::getStorage();
66-
if ($groupFolderStorage->instanceOfStorage(Jail::class)) {
67-
/** @var Jail $groupFolderStorage */
68-
return $groupFolderStorage->getUnjailedStorage();
69-
}
70-
return $groupFolderStorage;
71-
}
72-
73-
public function getMtime() {
61+
public function getMtime(): int {
7462
// trashbin is currently (incorrectly) assuming these to be the same
7563
return $this->getDeletedTime();
7664
}

0 commit comments

Comments
Β (0)