Skip to content

Commit 53923d9

Browse files
authored
Merge pull request #44559 from nextcloud/backport/44339/stable25
[stable25] fix(share): use share owner to get ownership
2 parents 35baf71 + e6c1ff1 commit 53923d9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/private/Share20/Manager.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ protected function verifyPassword($password) {
209209
*
210210
* @suppress PhanUndeclaredClassMethod
211211
*/
212-
protected function generalCreateChecks(IShare $share) {
212+
protected function generalCreateChecks(IShare $share, bool $isUpdate = false) {
213213
if ($share->getShareType() === IShare::TYPE_USER) {
214214
// We expect a valid user as sharedWith for user shares
215215
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
@@ -988,7 +994,7 @@ public function updateShare(IShare $share) {
988994
throw new \InvalidArgumentException('Cannot share with the share owner');
989995
}
990996

991-
$this->generalCreateChecks($share);
997+
$this->generalCreateChecks($share, true);
992998

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

0 commit comments

Comments
 (0)