Skip to content

Commit 31024b7

Browse files
authored
Merge pull request #4329 from nextcloud/move-out-shared-folder
Fix moving files out of a shared folder
2 parents dccb892 + 8500deb commit 31024b7

File tree

5 files changed

+56
-49
lines changed

5 files changed

+56
-49
lines changed

apps/files_sharing/lib/Scanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getData($path) {
5151
if ($data === null) {
5252
return null;
5353
}
54-
$internalPath = $this->storage->getSourcePath($path);
54+
$internalPath = $this->storage->getUnjailedPath($path);
5555
$data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath);
5656
return $data;
5757
}

apps/files_sharing/lib/SharedStorage.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function isSharable($path) {
232232
}
233233

234234
public function fopen($path, $mode) {
235-
if ($source = $this->getSourcePath($path)) {
235+
if ($source = $this->getUnjailedPath($path)) {
236236
switch ($mode) {
237237
case 'r+':
238238
case 'rb+':
@@ -274,7 +274,7 @@ public function fopen($path, $mode) {
274274
'mode' => $mode,
275275
);
276276
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
277-
return $this->nonMaskedStorage->fopen($this->getSourcePath($path), $mode);
277+
return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode);
278278
}
279279
return false;
280280
}
@@ -302,7 +302,7 @@ public function rename($path1, $path2) {
302302
}
303303
}
304304

305-
return $this->nonMaskedStorage->rename($this->getSourcePath($path1), $this->getSourcePath($path2));
305+
return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
306306
}
307307

308308
/**
@@ -479,7 +479,7 @@ public function getWrapperStorage() {
479479
public function file_get_contents($path) {
480480
$info = [
481481
'target' => $this->getMountPoint() . '/' . $path,
482-
'source' => $this->getSourcePath($path),
482+
'source' => $this->getUnjailedPath($path),
483483
];
484484
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
485485
return parent::file_get_contents($path);
@@ -488,7 +488,7 @@ public function file_get_contents($path) {
488488
public function file_put_contents($path, $data) {
489489
$info = [
490490
'target' => $this->getMountPoint() . '/' . $path,
491-
'source' => $this->getSourcePath($path),
491+
'source' => $this->getUnjailedPath($path),
492492
];
493493
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
494494
return parent::file_put_contents($path, $data);

lib/private/Files/Node/Folder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ private function getAbsolutePath(IMountPoint $mount, $path) {
413413
$storage = $mount->getStorage();
414414
if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) {
415415
/** @var \OC\Files\Storage\Wrapper\Jail $storage */
416-
$jailRoot = $storage->getSourcePath('');
416+
$jailRoot = $storage->getUnjailedPath('');
417417
$rootLength = strlen($jailRoot) + 1;
418418
if ($path === $jailRoot) {
419419
return $mount->getMountPoint();

lib/private/Files/Storage/Local.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
namespace OC\Files\Storage;
3737

38+
use OC\Files\Storage\Wrapper\Jail;
3839
use OCP\Files\ForbiddenException;
3940

4041
/**
@@ -371,7 +372,7 @@ public function getSourcePath($path) {
371372
return $fullPath;
372373
}
373374

374-
\OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", \OCP\Util::ERROR);
375+
\OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", \OCP\Util::ERROR);
375376
throw new ForbiddenException('Following symlinks is not allowed', false);
376377
}
377378

@@ -427,7 +428,13 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern
427428
* @return bool
428429
*/
429430
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
430-
if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Local')) {
431+
if ($sourceStorage->instanceOfStorage(Local::class)) {
432+
if ($sourceStorage->instanceOfStorage(Jail::class)) {
433+
/**
434+
* @var \OC\Files\Storage\Wrapper\Jail $sourceStorage
435+
*/
436+
$sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath);
437+
}
431438
/**
432439
* @var \OC\Files\Storage\Local $sourceStorage
433440
*/

0 commit comments

Comments
 (0)