aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-11-28 19:08:27 +0100
committerRobin Appelman <robin@icewind.nl>2025-01-03 15:36:32 +0100
commit16d03639373d77aa2c90cb7220319d57042b7376 (patch)
tree4fc9d7a548e0b44627a1d74630e05a7e1da7d7c3 /lib/private
parentb16f5a00435e9356cbbd757b7fadb5823d8f903a (diff)
downloadnextcloud-server-16d03639373d77aa2c90cb7220319d57042b7376.tar.gz
nextcloud-server-16d03639373d77aa2c90cb7220319d57042b7376.zip
fix: improve checks for moving shares/storages into other mounts
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Files/View.php66
1 files changed, 51 insertions, 15 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index e97cd75251d..e9a20fc4fba 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -24,6 +24,7 @@ use OCP\Files\ForbiddenException;
use OCP\Files\InvalidCharacterInPathException;
use OCP\Files\InvalidDirectoryException;
use OCP\Files\InvalidPathException;
+use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\Files\ReservedWordException;
@@ -707,6 +708,9 @@ class View {
throw new ForbiddenException('Moving a folder into a child folder is forbidden', false);
}
+ /** @var IMountManager $mountManager */
+ $mountManager = \OC::$server->get(IMountManager::class);
+
$targetParts = explode('/', $absolutePath2);
$targetUser = $targetParts[1] ?? null;
$result = false;
@@ -764,24 +768,25 @@ class View {
try {
$this->changeLock($target, ILockingProvider::LOCK_EXCLUSIVE, true);
+ $movedMounts = $mountManager->findIn($this->getAbsolutePath($source));
+
if ($internalPath1 === '') {
- if ($mount1 instanceof MoveableMount) {
- $sourceParentMount = $this->getMount(dirname($source));
- if ($sourceParentMount === $mount2 && $this->targetIsNotShared($targetUser, $absolutePath2)) {
- /**
- * @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1
- */
- $sourceMountPoint = $mount1->getMountPoint();
- $result = $mount1->moveMount($absolutePath2);
- $manager->moveMount($sourceMountPoint, $mount1->getMountPoint());
- } else {
- $result = false;
- }
- } else {
- $result = false;
- }
+ $sourceParentMount = $this->getMount(dirname($source));
+ $movedMounts[] = $mount1;
+ $this->validateMountMove($movedMounts, $sourceParentMount, $mount2, !$this->targetIsNotShared($targetUser, $absolutePath2));
+
+ /**
+ * @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1
+ */
+ $sourceMountPoint = $mount1->getMountPoint();
+ $result = $mount1->moveMount($absolutePath2);
+ $manager->moveMount($sourceMountPoint, $mount1->getMountPoint());
+
// moving a file/folder within the same mount point
} elseif ($storage1 === $storage2) {
+ if (count($movedMounts) > 0) {
+ $this->validateMountMove($movedMounts, $mount1, $mount2, !$this->targetIsNotShared($targetUser, $absolutePath2));
+ }
if ($storage1) {
$result = $storage1->rename($internalPath1, $internalPath2);
} else {
@@ -789,6 +794,9 @@ class View {
}
// moving a file/folder between storages (from $storage1 to $storage2)
} else {
+ if (count($movedMounts) > 0) {
+ $this->validateMountMove($movedMounts, $mount1, $mount2, !$this->targetIsNotShared($targetUser, $absolutePath2));
+ }
$result = $storage2->moveFromStorage($storage1, $internalPath1, $internalPath2);
}
@@ -838,6 +846,34 @@ class View {
return $result;
}
+ private function validateMountMove(array $mounts, IMountPoint $sourceMount, IMountPoint $targetMount, bool $targetIsShared): void {
+ $targetType = 'storage';
+ if ($targetMount instanceof SharedMount) {
+ $targetType = 'share';
+ }
+ $targetPath = rtrim($targetMount->getMountPoint(), '/');
+
+ foreach ($mounts as $mount) {
+ $sourcePath = rtrim($mount->getMountPoint(), '/');
+ $sourceType = 'storage';
+ if ($mount instanceof SharedMount) {
+ $sourceType = 'share';
+ }
+
+ if (!$mount instanceof MoveableMount) {
+ throw new ForbiddenException("Storage {$sourcePath} cannot be moved", false);
+ }
+
+ if ($targetIsShared) {
+ throw new ForbiddenException("Moving a $sourceType ($sourcePath) into shared folder is not allowed", false);
+ }
+
+ if ($sourceMount !== $targetMount) {
+ throw new ForbiddenException("Moving a $sourceType ($sourcePath) into another $targetType ($targetPath) is not allowed", false);
+ }
+ }
+ }
+
/**
* Copy a file/folder from the source path to target path
*