Skip to content

Commit c77f583

Browse files
committed
fix: update "move into share" check to share manager
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 5ade764 commit c77f583

File tree

3 files changed

+31
-460
lines changed

3 files changed

+31
-460
lines changed

lib/private/Files/View.php

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@
6565
use OCP\Files\Mount\IMountPoint;
6666
use OCP\Files\NotFoundException;
6767
use OCP\Files\ReservedWordException;
68-
use OCP\Files\Storage\IStorage;
6968
use OCP\IUser;
7069
use OCP\Lock\ILockingProvider;
7170
use OCP\Lock\LockedException;
71+
use OCP\Server;
72+
use OCP\Share\IManager;
73+
use OCP\Share\IShare;
7274
use Psr\Log\LoggerInterface;
7375

7476
/**
@@ -731,6 +733,8 @@ public function deleteAll($directory) {
731733
public function rename($source, $target) {
732734
$absolutePath1 = Filesystem::normalizePath($this->getAbsolutePath($source));
733735
$absolutePath2 = Filesystem::normalizePath($this->getAbsolutePath($target));
736+
$targetParts = explode('/', $absolutePath2);
737+
$targetUser = $targetParts[1] ?? null;
734738
$result = false;
735739
if (
736740
Filesystem::isValidPath($target)
@@ -785,7 +789,7 @@ public function rename($source, $target) {
785789
if ($internalPath1 === '') {
786790
if ($mount1 instanceof MoveableMount) {
787791
$sourceParentMount = $this->getMount(dirname($source));
788-
if ($sourceParentMount === $mount2 && $this->targetIsNotShared($storage2, $internalPath2)) {
792+
if ($sourceParentMount === $mount2 && $this->targetIsNotShared($targetUser, $absolutePath2)) {
789793
/**
790794
* @var \OC\Files\Mount\MountPoint | \OC\Files\Mount\MoveableMount $mount1
791795
*/
@@ -1781,28 +1785,29 @@ private function assertPathLength($path): void {
17811785
* It is not allowed to move a mount point into a different mount point or
17821786
* into an already shared folder
17831787
*/
1784-
private function targetIsNotShared(IStorage $targetStorage, string $targetInternalPath): bool {
1785-
// note: cannot use the view because the target is already locked
1786-
$fileId = $targetStorage->getCache()->getId($targetInternalPath);
1787-
if ($fileId === -1) {
1788-
// target might not exist, need to check parent instead
1789-
$fileId = $targetStorage->getCache()->getId(dirname($targetInternalPath));
1790-
}
1791-
1792-
// check if any of the parents were shared by the current owner (include collections)
1793-
$shares = Share::getItemShared(
1794-
'folder',
1795-
(string)$fileId,
1796-
\OC\Share\Constants::FORMAT_NONE,
1797-
null,
1798-
true
1799-
);
1800-
1801-
if (count($shares) > 0) {
1802-
$this->logger->debug(
1803-
'It is not allowed to move one mount point into a shared folder',
1804-
['app' => 'files']);
1805-
return false;
1788+
private function targetIsNotShared(string $user, string $targetPath): bool {
1789+
$providers = [
1790+
IShare::TYPE_USER,
1791+
IShare::TYPE_GROUP,
1792+
IShare::TYPE_EMAIL,
1793+
IShare::TYPE_CIRCLE,
1794+
IShare::TYPE_ROOM,
1795+
IShare::TYPE_DECK,
1796+
IShare::TYPE_SCIENCEMESH
1797+
];
1798+
$shareManager = Server::get(IManager::class);
1799+
/** @var IShare[] $shares */
1800+
$shares = array_merge(...array_map(function (int $type) use ($shareManager, $user) {
1801+
return $shareManager->getSharesBy($user, $type);
1802+
}, $providers));
1803+
1804+
foreach ($shares as $share) {
1805+
if (str_starts_with($targetPath, $share->getNode()->getPath())) {
1806+
$this->logger->debug(
1807+
'It is not allowed to move one mount point into a shared folder',
1808+
['app' => 'files']);
1809+
return false;
1810+
}
18061811
}
18071812

18081813
return true;

0 commit comments

Comments
 (0)