From 325f84bd0d363d27e5e4634821fcc45c83deb70a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Tue, 14 Apr 2020 14:42:28 +0200 Subject: [PATCH 1/2] Add a wrapper to fall back to the share owner on public shares Else it might happen that we setup a storage that has no real owner and activities do boom etc (looking at you groupfolders and external storages!). Signed-off-by: Roeland Jago Douma --- apps/dav/appinfo/v1/publicwebdav.php | 4 +- .../composer/composer/autoload_classmap.php | 1 + .../dav/composer/composer/autoload_static.php | 1 + apps/dav/lib/Storage/PublicOwnerWrapper.php | 53 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 apps/dav/lib/Storage/PublicOwnerWrapper.php diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index 37fcebe605c30..35c903be918be 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -79,7 +79,9 @@ \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE)); }); - + \OC\Files\Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) { + return new \OCA\DAV\Storage\PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]); + }); \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); OC_Util::tearDownFS(); diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index 08f9d6cf0b1e3..e808b2916d106 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -205,6 +205,7 @@ 'OCA\\DAV\\RootCollection' => $baseDir . '/../lib/RootCollection.php', 'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php', + 'OCA\\DAV\\Storage\\PublicOwnerWrapper' => $baseDir . '/../lib/Storage/PublicOwnerWrapper.php', 'OCA\\DAV\\SystemTag\\SystemTagMappingNode' => $baseDir . '/../lib/SystemTag/SystemTagMappingNode.php', 'OCA\\DAV\\SystemTag\\SystemTagNode' => $baseDir . '/../lib/SystemTag/SystemTagNode.php', 'OCA\\DAV\\SystemTag\\SystemTagPlugin' => $baseDir . '/../lib/SystemTag/SystemTagPlugin.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index 87cd4189299e4..073c59174113f 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -220,6 +220,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\RootCollection' => __DIR__ . '/..' . '/../lib/RootCollection.php', 'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php', + 'OCA\\DAV\\Storage\\PublicOwnerWrapper' => __DIR__ . '/..' . '/../lib/Storage/PublicOwnerWrapper.php', 'OCA\\DAV\\SystemTag\\SystemTagMappingNode' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagMappingNode.php', 'OCA\\DAV\\SystemTag\\SystemTagNode' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagNode.php', 'OCA\\DAV\\SystemTag\\SystemTagPlugin' => __DIR__ . '/..' . '/../lib/SystemTag/SystemTagPlugin.php', diff --git a/apps/dav/lib/Storage/PublicOwnerWrapper.php b/apps/dav/lib/Storage/PublicOwnerWrapper.php new file mode 100644 index 0000000000000..a02a2e423418a --- /dev/null +++ b/apps/dav/lib/Storage/PublicOwnerWrapper.php @@ -0,0 +1,53 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\DAV\Storage; + +use OC\Files\Storage\Wrapper\Wrapper; + +class PublicOwnerWrapper extends Wrapper { + + /** @var string */ + private $owner; + + /** + * @param array $arguments ['storage' => $storage, 'owner' => $owner] + * + * $storage: The storage the permissions mask should be applied on + * $owner: The owner to use in case no owner is found + */ + public function __construct($arguments) { + parent::__construct($arguments); + $this->owner = $arguments['owner']; + } + + public function getOwner($path) { + $owner = parent::getOwner($path); + + if ($owner === null || $owner === false) { + return $this->owner; + } + } +} From 18eb25c50251a85d3d15fafb46aeb1c927963960 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 1 May 2020 10:50:26 +0200 Subject: [PATCH 2/2] Fix owner on publicownerwrapper Signed-off-by: Roeland Jago Douma --- apps/dav/lib/Storage/PublicOwnerWrapper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/dav/lib/Storage/PublicOwnerWrapper.php b/apps/dav/lib/Storage/PublicOwnerWrapper.php index a02a2e423418a..188323503ae2e 100644 --- a/apps/dav/lib/Storage/PublicOwnerWrapper.php +++ b/apps/dav/lib/Storage/PublicOwnerWrapper.php @@ -49,5 +49,7 @@ public function getOwner($path) { if ($owner === null || $owner === false) { return $this->owner; } + + return $owner; } }