Skip to content

Commit 309f618

Browse files
authored
Merge pull request #44558 from nextcloud/backport/44339/stable23
[stable23] fix(share): use share owner to get ownership
2 parents a11eae4 + f9cf7d8 commit 309f618

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

lib/private/Share20/Manager.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ protected function verifyPassword($password) {
210210
*
211211
* @suppress PhanUndeclaredClassMethod
212212
*/
213-
protected function generalCreateChecks(IShare $share) {
213+
protected function generalCreateChecks(IShare $share, bool $isUpdate = false) {
214214
if ($share->getShareType() === IShare::TYPE_USER) {
215215
// We expect a valid user as sharedWith for user shares
216216
if (!$this->userManager->userExists($share->getSharedWith())) {
@@ -295,8 +295,14 @@ protected function generalCreateChecks(IShare $share) {
295295

296296
$isFederatedShare = $share->getNode()->getStorage()->instanceOfStorage('\OCA\Files_Sharing\External\Storage');
297297
$permissions = 0;
298+
299+
$isReshare = $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy();
300+
if (!$isReshare && $isUpdate) {
301+
// in case of update on owner-less filesystem, we use share owner to improve reshare detection
302+
$isReshare = $share->getShareOwner() !== $share->getSharedBy();
303+
}
298304

299-
if (!$isFederatedShare && $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy()) {
305+
if (!$isFederatedShare && $isReshare) {
300306
$userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) {
301307
// We need to filter since there might be other mountpoints that contain the file
302308
// e.g. if the user has access to the same external storage that the file is originating from
@@ -982,7 +988,7 @@ public function updateShare(IShare $share) {
982988
throw new \InvalidArgumentException('Cannot share with the share owner');
983989
}
984990

985-
$this->generalCreateChecks($share);
991+
$this->generalCreateChecks($share, true);
986992

987993
if ($share->getShareType() === IShare::TYPE_USER) {
988994
$this->userCreateChecks($share);

0 commit comments

Comments
 (0)