Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encryption trash fixes #3425

Merged
merged 9 commits into from
Dec 6, 2024
10 changes: 7 additions & 3 deletions lib/Mount/GroupFolderStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

class GroupFolderStorage extends Quota implements IConstructableStorage {
private int $folderId;
private ICacheEntry $rootEntry;
private ?ICacheEntry $rootEntry;
private IUserSession $userSession;
private ?IUser $mountOwner;
/** @var RootEntryCache|null */
/** @var ICache|null */
public $cache;

public function __construct($parameters) {
Expand Down Expand Up @@ -59,7 +59,11 @@ public function getCache(string $path = '', ?IStorage $storage = null): ICache {
$storage = $this;
}

$this->cache = new RootEntryCache(parent::getCache($path, $storage), $this->rootEntry);
$cache = parent::getCache($path, $storage);
if ($this->rootEntry !== null) {
$cache = new RootEntryCache($cache, $this->rootEntry);
}
$this->cache = $cache;

return $this->cache;
}
Expand Down
108 changes: 81 additions & 27 deletions lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader): array {
$aclManager = $this->aclManagerFactory->getACLManager($user, $this->getRootStorageId());
$rootRules = $aclManager->getRelevantRulesForPath($aclRootPaths);

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

return $this->getMount(
$mount = $this->getMount(
$folder['folder_id'],
'/' . $user->getUID() . '/files/' . $folder['mount_point'],
$folder['permissions'],
Expand All @@ -114,6 +114,22 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader): array {
$aclManager,
$rootRules
);
if (!$mount) {
return null;
}
$trashMount = $this->getTrashMount(
$folder['folder_id'],
'/' . $user->getUID() . '/files_trashbin/groupfolders/' . $folder['folder_id'],
$folder['quota'],
$loader,
$user
);

return [
$mount,
$trashMount,
];

}, $folders)));
}

Expand Down Expand Up @@ -180,53 +196,91 @@ public function getMount(
$cacheEntry['permissions'] &= $aclRootPermissions;
}

$quotaStorage = $this->getGroupFolderStorage($id, $storage, $user, $rootPath, $quota, $cacheEntry);

$maskedStore = new PermissionsMask([
'storage' => $quotaStorage,
'mask' => $permissions,
]);

if (!$this->allowRootShare) {
$maskedStore = new RootPermissionsMask([
'storage' => $maskedStore,
'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
]);
}

return new GroupMountPoint(
$id,
$maskedStore,
$mountPoint,
null,
$loader
);
}

public function getTrashMount(
int $id,
string $mountPoint,
int $quota,
IStorageFactory $loader,
IUser $user,
): IMountPoint {

$storage = $this->getRootFolder()->getStorage();

$storage->setOwner($user->getUID());

$trashPath = $this->getRootFolder()->getInternalPath() . '/trash/' . $id;

$trashStorage = $this->getGroupFolderStorage($id, $storage, $user, $trashPath, $quota, null);

return new GroupMountPoint(
$id,
$trashStorage,
$mountPoint,
null,
$loader
);
}

public function getGroupFolderStorage(
int $id,
IStorage $rootStorage,
?IUser $user,
string $rootPath,
int $quota,
?ICacheEntry $rootCacheEntry,
): IStorage {
if ($this->enableEncryption) {
$baseStorage = new GroupFolderEncryptionJail([
'storage' => $storage,
'root' => $rootPath
'storage' => $rootStorage,
'root' => $rootPath,
]);
$quotaStorage = new GroupFolderStorage([
'storage' => $baseStorage,
'quota' => $quota,
'folder_id' => $id,
'rootCacheEntry' => $cacheEntry,
'rootCacheEntry' => $rootCacheEntry,
'userSession' => $this->userSession,
'mountOwner' => $user,
]);
} else {
$baseStorage = new Jail([
'storage' => $storage,
'root' => $rootPath
'storage' => $rootStorage,
'root' => $rootPath,
]);
$quotaStorage = new GroupFolderNoEncryptionStorage([
'storage' => $baseStorage,
'quota' => $quota,
'folder_id' => $id,
'rootCacheEntry' => $cacheEntry,
'rootCacheEntry' => $rootCacheEntry,
'userSession' => $this->userSession,
'mountOwner' => $user,
]);
}

$maskedStore = new PermissionsMask([
'storage' => $quotaStorage,
'mask' => $permissions
]);

if (!$this->allowRootShare) {
$maskedStore = new RootPermissionsMask([
'storage' => $maskedStore,
'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
]);
}

return new GroupMountPoint(
$id,
$maskedStore,
$mountPoint,
null,
$loader
);
return $quotaStorage;
}

public function getJailPath(int $folderId): string {
Expand Down
14 changes: 0 additions & 14 deletions lib/Trash/GroupTrashItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

namespace OCA\GroupFolders\Trash;

use OC\Files\Storage\Wrapper\Jail;
use OCA\Files_Trashbin\Trash\ITrashBackend;
use OCA\Files_Trashbin\Trash\TrashItem;
use OCP\Files\FileInfo;
use OCP\Files\Storage\IStorage;
use OCP\IUser;

class GroupTrashItem extends TrashItem {
Expand Down Expand Up @@ -43,18 +41,6 @@ public function getTitle(): string {
return $this->getGroupFolderMountPoint() . '/' . $this->getOriginalLocation();
}

public function getStorage(): IStorage {
// get the unjailed storage, since the trash item is outside the jail
// (the internal path is also unjailed)
$groupFolderStorage = parent::getStorage();
if ($groupFolderStorage->instanceOfStorage(Jail::class)) {
/** @var Jail $groupFolderStorage */
return $groupFolderStorage->getUnjailedStorage();
}

return $groupFolderStorage;
}

public function getMtime(): int {
// trashbin is currently (incorrectly) assuming these to be the same
return $this->getDeletedTime();
Expand Down
Loading
Loading