Skip to content

Commit 7bf4a45

Browse files
CarlSchwanMichaIng
authored andcommitted
Fix permissions when copying from ObjectStorage
Make sure that when a user copy a file from a directory they don't have all permissions to a directory where they have more permissions, the permissions are correctly set to the one from the parent taget folder. This was caused by the ObjectStoreStorage::copyFromStorage using the jailed storage and cache entry instead of the unjailed one like other storages (the local one). Steps to reproduce + Use object storage + Create a groupfolder with one group having full permission and another one who can just read files. + With an user who is in the second group, copy a file from the groupfolder to the home folder of this user. + The file in the home folder of the user will be read only and can't be deleted even though it is in their home folder and they are the owner. In oc_filecache, the permissions stored for this file are 1 (READ) Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 331bf8e commit 7bf4a45

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/private/Files/Cache/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ public function normalize($path) {
10091009
* @param ICache $sourceCache
10101010
* @param ICacheEntry $sourceEntry
10111011
* @param string $targetPath
1012-
* @return int fileid of copied entry
1012+
* @return int fileId of copied entry
10131013
*/
10141014
public function copyFromCache(ICache $sourceCache, ICacheEntry $sourceEntry, string $targetPath): int {
10151015
if ($sourceEntry->getId() < 0) {

lib/private/Files/ObjectStore/ObjectStoreStorage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,15 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
539539
if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) {
540540
/** @var ObjectStoreStorage $sourceStorage */
541541
if ($sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) {
542+
/** @var CacheEntry $sourceEntry */
542543
$sourceEntry = $sourceStorage->getCache()->get($sourceInternalPath);
544+
$sourceEntryData = $sourceEntry->getData();
545+
// $sourceEntry['permissions'] here is the permissions from the jailed storage for the current
546+
// user. Instead we use $sourceEntryData['scan_permissions'] that are the permissions from the
547+
// unjailed storage.
548+
if (is_array($sourceEntryData) && array_key_exists('scan_permissions', $sourceEntryData)) {
549+
$sourceEntry['permissions'] = $sourceEntryData['scan_permissions'];
550+
}
543551
$this->copyInner($sourceEntry, $targetInternalPath);
544552
return true;
545553
}

0 commit comments

Comments
 (0)