]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(Files): Handle getOwner() returning false fix/storage/get-owner-false 48094/head
authorprovokateurin <kate@provokateurin.de>
Mon, 16 Sep 2024 14:00:46 +0000 (16:00 +0200)
committerprovokateurin <kate@provokateurin.de>
Tue, 17 Sep 2024 08:10:50 +0000 (10:10 +0200)
Signed-off-by: provokateurin <kate@provokateurin.de>
apps/dav/lib/Storage/PublicOwnerWrapper.php
apps/files_versions/lib/Versions/LegacyVersionsBackend.php
lib/private/Files/Node/Folder.php
lib/private/Files/Node/Root.php
lib/private/Files/View.php
lib/private/legacy/OC_Helper.php

index 40ef81ab06d54fb8bd59deaf880e0db9e407c46c..91c1916dc39b4d81f05bc47da4218d41bccb4789 100644 (file)
@@ -12,8 +12,7 @@ use OC\Files\Storage\Wrapper\Wrapper;
 
 class PublicOwnerWrapper extends Wrapper {
 
-       /** @var string */
-       private $owner;
+       private string $owner;
 
        /**
         * @param array $arguments ['storage' => $storage, 'owner' => $owner]
@@ -28,11 +27,10 @@ class PublicOwnerWrapper extends Wrapper {
 
        public function getOwner($path): string|false {
                $owner = parent::getOwner($path);
-
-               if ($owner === null || $owner === false) {
-                       return $this->owner;
+               if ($owner !== false) {
+                       return $owner;
                }
 
-               return $owner;
+               return $this->owner;
        }
 }
index fc37ecead95e9c21b7179f815cb68abfc4ed2354..bc46da857525ae54b5f14e0b443996fd58a723a7 100644 (file)
@@ -49,6 +49,10 @@ class LegacyVersionsBackend implements IVersionBackend, IDeletableVersionBackend
 
                if ($storage->instanceOfStorage(ISharedStorage::class)) {
                        $owner = $storage->getOwner('');
+                       if ($owner === false) {
+                               throw new NotFoundException('No owner for ' . $file->getPath());
+                       }
+
                        $user = $this->userManager->get($owner);
 
                        $fileId = $file->getId();
index ca256b09d336d28b6311308bd130264d6d884bb0..d8344f3d5bd16bf77edc0516f252d5e0fb293937 100644 (file)
@@ -253,7 +253,7 @@ class Folder extends Node implements \OCP\Files\Folder {
 
                $owner = null;
                $ownerId = $storage->getOwner($cacheEntry['internalPath']);
-               if (!empty($ownerId)) {
+               if ($ownerId !== false) {
                        // Cache the user manager (for performance)
                        if ($this->userManager === null) {
                                $this->userManager = \OCP\Server::get(IUserManager::class);
index 416adc7f374ac353cabfe377d6f8991e484e2e4c..dbe03a4cfbfb6a7d2ed543e6d773a2b0d65c632b 100644 (file)
@@ -28,6 +28,7 @@ use OCP\ICache;
 use OCP\ICacheFactory;
 use OCP\IUser;
 use OCP\IUserManager;
+use OCP\Server;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -477,9 +478,23 @@ class Root extends Folder implements IRootFolder {
                        $pathRelativeToMount = substr($internalPath, strlen($rootInternalPath));
                        $pathRelativeToMount = ltrim($pathRelativeToMount, '/');
                        $absolutePath = rtrim($mount->getMountPoint() . $pathRelativeToMount, '/');
+                       $storage = $mount->getStorage();
+                       if ($storage === null) {
+                               return null;
+                       }
+                       $ownerId = $storage->getOwner($pathRelativeToMount);
+                       if ($ownerId !== false) {
+                               $owner = Server::get(IUserManager::class)->get($ownerId);
+                       } else {
+                               $owner = null;
+                       }
                        return $this->createNode($absolutePath, new FileInfo(
-                               $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount,
-                               \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount))
+                               $absolutePath,
+                               $storage,
+                               $cacheEntry->getPath(),
+                               $cacheEntry,
+                               $mount,
+                               $owner,
                        ));
                }, $mountsContainingFile);
 
index 9ac74461ca81b558fecbe7bac762c9c493190c35..80679a9481fa5fce55cc93af72652b7c6ac22f1d 100644 (file)
@@ -28,6 +28,7 @@ use OCP\Files\Mount\IMountPoint;
 use OCP\Files\NotFoundException;
 use OCP\Files\ReservedWordException;
 use OCP\IUser;
+use OCP\IUserManager;
 use OCP\Lock\ILockingProvider;
 use OCP\Lock\LockedException;
 use OCP\Server;
@@ -1364,7 +1365,7 @@ class View {
 
                        $ownerId = $storage->getOwner($internalPath);
                        $owner = null;
-                       if ($ownerId !== null && $ownerId !== false) {
+                       if ($ownerId !== false) {
                                // ownerId might be null if files are accessed with an access token without file system access
                                $owner = $this->getUserObjectForOwner($ownerId);
                        }
@@ -1450,7 +1451,12 @@ class View {
                        if ($sharingDisabled) {
                                $content['permissions'] = $content['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
                        }
-                       $owner = $this->getUserObjectForOwner($storage->getOwner($content['path']));
+                       $ownerId = $storage->getOwner($content['path']);
+                       if ($ownerId !== false) {
+                               $owner = $this->getUserObjectForOwner($ownerId);
+                       } else {
+                               $owner = null;
+                       }
                        return new FileInfo($path . '/' . $content['name'], $storage, $content['path'], $content, $mount, $owner);
                }, $contents);
                $files = array_combine($fileNames, $fileInfos);
@@ -1527,7 +1533,12 @@ class View {
                                                        $rootEntry['permissions'] = $rootEntry['permissions'] & ~\OCP\Constants::PERMISSION_SHARE;
                                                }
 
-                                               $owner = $this->getUserObjectForOwner($subStorage->getOwner(''));
+                                               $ownerId = $subStorage->getOwner('');
+                                               if ($ownerId !== false) {
+                                                       $owner = $this->getUserObjectForOwner($ownerId);
+                                               } else {
+                                                       $owner = null;
+                                               }
                                                $files[$rootEntry->getName()] = new FileInfo($path . '/' . $rootEntry['name'], $subStorage, '', $rootEntry, $mount, $owner);
                                        }
                                }
@@ -1644,7 +1655,12 @@ class View {
                                        $internalPath = $result['path'];
                                        $path = $mountPoint . $result['path'];
                                        $result['path'] = substr($mountPoint . $result['path'], $rootLength);
-                                       $owner = $userManager->get($storage->getOwner($internalPath));
+                                       $ownerId = $storage->getOwner($internalPath);
+                                       if ($ownerId !== false) {
+                                               $owner = $userManager->get($ownerId);
+                                       } else {
+                                               $owner = null;
+                                       }
                                        $files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
                                }
                        }
@@ -1663,7 +1679,12 @@ class View {
                                                        $internalPath = $result['path'];
                                                        $result['path'] = rtrim($relativeMountPoint . $result['path'], '/');
                                                        $path = rtrim($mountPoint . $internalPath, '/');
-                                                       $owner = $userManager->get($storage->getOwner($internalPath));
+                                                       $ownerId = $storage->getOwner($internalPath);
+                                                       if ($ownerId !== false) {
+                                                               $owner = $userManager->get($ownerId);
+                                                       } else {
+                                                               $owner = null;
+                                                       }
                                                        $files[] = new FileInfo($path, $storage, $internalPath, $result, $mount, $owner);
                                                }
                                        }
@@ -1811,7 +1832,12 @@ class View {
                $mount = $this->getMount($path);
                $storage = $mount->getStorage();
                $internalPath = $mount->getInternalPath($this->getAbsolutePath($path));
-               $owner = \OC::$server->getUserManager()->get($storage->getOwner($internalPath));
+               $ownerId = $storage->getOwner($internalPath);
+               if ($ownerId !== false) {
+                       $owner = Server::get(IUserManager::class)->get($ownerId);
+               } else {
+                       $owner = null;
+               }
                return new FileInfo(
                        $this->getAbsolutePath($path),
                        $storage,
@@ -1846,7 +1872,7 @@ class View {
 
                // Short cut for read-only validation
                if ($readonly) {
-                       $validator = \OCP\Server::get(FilenameValidator::class);
+                       $validator = Server::get(FilenameValidator::class);
                        if ($validator->isForbidden($fileName)) {
                                $l = \OCP\Util::getL10N('lib');
                                throw new InvalidPathException($l->t('Filename is a reserved word'));
index 33cc966da2a6ed4c5206f5b6fe06a8ee4b1a6488..6da063ef2ce58d925b072a10976a38c049ca5ba0 100644 (file)
@@ -541,10 +541,9 @@ class OC_Helper {
                        $relative = 0;
                }
 
-               /** @var string $ownerId */
                $ownerId = $storage->getOwner($path);
                $ownerDisplayName = '';
-               if ($ownerId) {
+               if ($ownerId !== false) {
                        $ownerDisplayName = \OC::$server->getUserManager()->getDisplayName($ownerId) ?? '';
                }