Merge pull request #4329 from nextcloud/move-out-shared-folder

Fix moving files out of a shared folder
This commit is contained in:
Morris Jobke 2017-04-12 11:44:26 -05:00 committed by GitHub
commit 31024b7700
5 changed files with 56 additions and 49 deletions

View File

@ -51,7 +51,7 @@ class Scanner extends \OC\Files\Cache\Scanner {
if ($data === null) { if ($data === null) {
return null; return null;
} }
$internalPath = $this->storage->getSourcePath($path); $internalPath = $this->storage->getUnjailedPath($path);
$data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath); $data['permissions'] = $this->storage->getSourceStorage()->getPermissions($internalPath);
return $data; return $data;
} }

View File

@ -232,7 +232,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
} }
public function fopen($path, $mode) { public function fopen($path, $mode) {
if ($source = $this->getSourcePath($path)) { if ($source = $this->getUnjailedPath($path)) {
switch ($mode) { switch ($mode) {
case 'r+': case 'r+':
case 'rb+': case 'rb+':
@ -274,7 +274,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
'mode' => $mode, 'mode' => $mode,
); );
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
return $this->nonMaskedStorage->fopen($this->getSourcePath($path), $mode); return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode);
} }
return false; return false;
} }
@ -302,7 +302,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
} }
} }
return $this->nonMaskedStorage->rename($this->getSourcePath($path1), $this->getSourcePath($path2)); return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
} }
/** /**
@ -479,7 +479,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
public function file_get_contents($path) { public function file_get_contents($path) {
$info = [ $info = [
'target' => $this->getMountPoint() . '/' . $path, 'target' => $this->getMountPoint() . '/' . $path,
'source' => $this->getSourcePath($path), 'source' => $this->getUnjailedPath($path),
]; ];
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info);
return parent::file_get_contents($path); return parent::file_get_contents($path);
@ -488,7 +488,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
public function file_put_contents($path, $data) { public function file_put_contents($path, $data) {
$info = [ $info = [
'target' => $this->getMountPoint() . '/' . $path, 'target' => $this->getMountPoint() . '/' . $path,
'source' => $this->getSourcePath($path), 'source' => $this->getUnjailedPath($path),
]; ];
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info);
return parent::file_put_contents($path, $data); return parent::file_put_contents($path, $data);

View File

@ -413,7 +413,7 @@ class Folder extends Node implements \OCP\Files\Folder {
$storage = $mount->getStorage(); $storage = $mount->getStorage();
if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) { if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) {
/** @var \OC\Files\Storage\Wrapper\Jail $storage */ /** @var \OC\Files\Storage\Wrapper\Jail $storage */
$jailRoot = $storage->getSourcePath(''); $jailRoot = $storage->getUnjailedPath('');
$rootLength = strlen($jailRoot) + 1; $rootLength = strlen($jailRoot) + 1;
if ($path === $jailRoot) { if ($path === $jailRoot) {
return $mount->getMountPoint(); return $mount->getMountPoint();

View File

@ -35,6 +35,7 @@
namespace OC\Files\Storage; namespace OC\Files\Storage;
use OC\Files\Storage\Wrapper\Jail;
use OCP\Files\ForbiddenException; use OCP\Files\ForbiddenException;
/** /**
@ -371,7 +372,7 @@ class Local extends \OC\Files\Storage\Common {
return $fullPath; return $fullPath;
} }
\OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", \OCP\Util::ERROR); \OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", \OCP\Util::ERROR);
throw new ForbiddenException('Following symlinks is not allowed', false); throw new ForbiddenException('Following symlinks is not allowed', false);
} }
@ -427,7 +428,13 @@ class Local extends \OC\Files\Storage\Common {
* @return bool * @return bool
*/ */
public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) {
if ($sourceStorage->instanceOfStorage('\OC\Files\Storage\Local')) { if ($sourceStorage->instanceOfStorage(Local::class)) {
if ($sourceStorage->instanceOfStorage(Jail::class)) {
/**
* @var \OC\Files\Storage\Wrapper\Jail $sourceStorage
*/
$sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath);
}
/** /**
* @var \OC\Files\Storage\Local $sourceStorage * @var \OC\Files\Storage\Local $sourceStorage
*/ */

View File

@ -49,7 +49,7 @@ class Jail extends Wrapper {
$this->rootPath = $arguments['root']; $this->rootPath = $arguments['root'];
} }
public function getSourcePath($path) { public function getUnjailedPath($path) {
if ($path === '') { if ($path === '') {
return $this->rootPath; return $this->rootPath;
} else { } else {
@ -68,7 +68,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function mkdir($path) { public function mkdir($path) {
return $this->getWrapperStorage()->mkdir($this->getSourcePath($path)); return $this->getWrapperStorage()->mkdir($this->getUnjailedPath($path));
} }
/** /**
@ -78,7 +78,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function rmdir($path) { public function rmdir($path) {
return $this->getWrapperStorage()->rmdir($this->getSourcePath($path)); return $this->getWrapperStorage()->rmdir($this->getUnjailedPath($path));
} }
/** /**
@ -88,7 +88,7 @@ class Jail extends Wrapper {
* @return resource * @return resource
*/ */
public function opendir($path) { public function opendir($path) {
return $this->getWrapperStorage()->opendir($this->getSourcePath($path)); return $this->getWrapperStorage()->opendir($this->getUnjailedPath($path));
} }
/** /**
@ -98,7 +98,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function is_dir($path) { public function is_dir($path) {
return $this->getWrapperStorage()->is_dir($this->getSourcePath($path)); return $this->getWrapperStorage()->is_dir($this->getUnjailedPath($path));
} }
/** /**
@ -108,7 +108,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function is_file($path) { public function is_file($path) {
return $this->getWrapperStorage()->is_file($this->getSourcePath($path)); return $this->getWrapperStorage()->is_file($this->getUnjailedPath($path));
} }
/** /**
@ -119,7 +119,7 @@ class Jail extends Wrapper {
* @return array * @return array
*/ */
public function stat($path) { public function stat($path) {
return $this->getWrapperStorage()->stat($this->getSourcePath($path)); return $this->getWrapperStorage()->stat($this->getUnjailedPath($path));
} }
/** /**
@ -129,7 +129,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function filetype($path) { public function filetype($path) {
return $this->getWrapperStorage()->filetype($this->getSourcePath($path)); return $this->getWrapperStorage()->filetype($this->getUnjailedPath($path));
} }
/** /**
@ -140,7 +140,7 @@ class Jail extends Wrapper {
* @return int * @return int
*/ */
public function filesize($path) { public function filesize($path) {
return $this->getWrapperStorage()->filesize($this->getSourcePath($path)); return $this->getWrapperStorage()->filesize($this->getUnjailedPath($path));
} }
/** /**
@ -150,7 +150,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function isCreatable($path) { public function isCreatable($path) {
return $this->getWrapperStorage()->isCreatable($this->getSourcePath($path)); return $this->getWrapperStorage()->isCreatable($this->getUnjailedPath($path));
} }
/** /**
@ -160,7 +160,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function isReadable($path) { public function isReadable($path) {
return $this->getWrapperStorage()->isReadable($this->getSourcePath($path)); return $this->getWrapperStorage()->isReadable($this->getUnjailedPath($path));
} }
/** /**
@ -170,7 +170,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function isUpdatable($path) { public function isUpdatable($path) {
return $this->getWrapperStorage()->isUpdatable($this->getSourcePath($path)); return $this->getWrapperStorage()->isUpdatable($this->getUnjailedPath($path));
} }
/** /**
@ -180,7 +180,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function isDeletable($path) { public function isDeletable($path) {
return $this->getWrapperStorage()->isDeletable($this->getSourcePath($path)); return $this->getWrapperStorage()->isDeletable($this->getUnjailedPath($path));
} }
/** /**
@ -190,7 +190,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function isSharable($path) { public function isSharable($path) {
return $this->getWrapperStorage()->isSharable($this->getSourcePath($path)); return $this->getWrapperStorage()->isSharable($this->getUnjailedPath($path));
} }
/** /**
@ -201,7 +201,7 @@ class Jail extends Wrapper {
* @return int * @return int
*/ */
public function getPermissions($path) { public function getPermissions($path) {
return $this->getWrapperStorage()->getPermissions($this->getSourcePath($path)); return $this->getWrapperStorage()->getPermissions($this->getUnjailedPath($path));
} }
/** /**
@ -211,7 +211,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function file_exists($path) { public function file_exists($path) {
return $this->getWrapperStorage()->file_exists($this->getSourcePath($path)); return $this->getWrapperStorage()->file_exists($this->getUnjailedPath($path));
} }
/** /**
@ -221,7 +221,7 @@ class Jail extends Wrapper {
* @return int * @return int
*/ */
public function filemtime($path) { public function filemtime($path) {
return $this->getWrapperStorage()->filemtime($this->getSourcePath($path)); return $this->getWrapperStorage()->filemtime($this->getUnjailedPath($path));
} }
/** /**
@ -231,7 +231,7 @@ class Jail extends Wrapper {
* @return string * @return string
*/ */
public function file_get_contents($path) { public function file_get_contents($path) {
return $this->getWrapperStorage()->file_get_contents($this->getSourcePath($path)); return $this->getWrapperStorage()->file_get_contents($this->getUnjailedPath($path));
} }
/** /**
@ -242,7 +242,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function file_put_contents($path, $data) { public function file_put_contents($path, $data) {
return $this->getWrapperStorage()->file_put_contents($this->getSourcePath($path), $data); return $this->getWrapperStorage()->file_put_contents($this->getUnjailedPath($path), $data);
} }
/** /**
@ -252,7 +252,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function unlink($path) { public function unlink($path) {
return $this->getWrapperStorage()->unlink($this->getSourcePath($path)); return $this->getWrapperStorage()->unlink($this->getUnjailedPath($path));
} }
/** /**
@ -263,7 +263,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function rename($path1, $path2) { public function rename($path1, $path2) {
return $this->getWrapperStorage()->rename($this->getSourcePath($path1), $this->getSourcePath($path2)); return $this->getWrapperStorage()->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
} }
/** /**
@ -274,7 +274,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function copy($path1, $path2) { public function copy($path1, $path2) {
return $this->getWrapperStorage()->copy($this->getSourcePath($path1), $this->getSourcePath($path2)); return $this->getWrapperStorage()->copy($this->getUnjailedPath($path1), $this->getUnjailedPath($path2));
} }
/** /**
@ -285,7 +285,7 @@ class Jail extends Wrapper {
* @return resource * @return resource
*/ */
public function fopen($path, $mode) { public function fopen($path, $mode) {
return $this->getWrapperStorage()->fopen($this->getSourcePath($path), $mode); return $this->getWrapperStorage()->fopen($this->getUnjailedPath($path), $mode);
} }
/** /**
@ -296,7 +296,7 @@ class Jail extends Wrapper {
* @return string * @return string
*/ */
public function getMimeType($path) { public function getMimeType($path) {
return $this->getWrapperStorage()->getMimeType($this->getSourcePath($path)); return $this->getWrapperStorage()->getMimeType($this->getUnjailedPath($path));
} }
/** /**
@ -308,7 +308,7 @@ class Jail extends Wrapper {
* @return string * @return string
*/ */
public function hash($type, $path, $raw = false) { public function hash($type, $path, $raw = false) {
return $this->getWrapperStorage()->hash($type, $this->getSourcePath($path), $raw); return $this->getWrapperStorage()->hash($type, $this->getUnjailedPath($path), $raw);
} }
/** /**
@ -318,7 +318,7 @@ class Jail extends Wrapper {
* @return int * @return int
*/ */
public function free_space($path) { public function free_space($path) {
return $this->getWrapperStorage()->free_space($this->getSourcePath($path)); return $this->getWrapperStorage()->free_space($this->getUnjailedPath($path));
} }
/** /**
@ -340,7 +340,7 @@ class Jail extends Wrapper {
* @return bool * @return bool
*/ */
public function touch($path, $mtime = null) { public function touch($path, $mtime = null) {
return $this->getWrapperStorage()->touch($this->getSourcePath($path), $mtime); return $this->getWrapperStorage()->touch($this->getUnjailedPath($path), $mtime);
} }
/** /**
@ -351,7 +351,7 @@ class Jail extends Wrapper {
* @return string * @return string
*/ */
public function getLocalFile($path) { public function getLocalFile($path) {
return $this->getWrapperStorage()->getLocalFile($this->getSourcePath($path)); return $this->getWrapperStorage()->getLocalFile($this->getUnjailedPath($path));
} }
/** /**
@ -365,7 +365,7 @@ class Jail extends Wrapper {
* returning true for other changes in the folder is optional * returning true for other changes in the folder is optional
*/ */
public function hasUpdated($path, $time) { public function hasUpdated($path, $time) {
return $this->getWrapperStorage()->hasUpdated($this->getSourcePath($path), $time); return $this->getWrapperStorage()->hasUpdated($this->getUnjailedPath($path), $time);
} }
/** /**
@ -379,7 +379,7 @@ class Jail extends Wrapper {
if (!$storage) { if (!$storage) {
$storage = $this->getWrapperStorage(); $storage = $this->getWrapperStorage();
} }
$sourceCache = $this->getWrapperStorage()->getCache($this->getSourcePath($path), $storage); $sourceCache = $this->getWrapperStorage()->getCache($this->getUnjailedPath($path), $storage);
return new CacheJail($sourceCache, $this->rootPath); return new CacheJail($sourceCache, $this->rootPath);
} }
@ -390,7 +390,7 @@ class Jail extends Wrapper {
* @return string * @return string
*/ */
public function getOwner($path) { public function getOwner($path) {
return $this->getWrapperStorage()->getOwner($this->getSourcePath($path)); return $this->getWrapperStorage()->getOwner($this->getUnjailedPath($path));
} }
/** /**
@ -404,7 +404,7 @@ class Jail extends Wrapper {
if (!$storage) { if (!$storage) {
$storage = $this; $storage = $this;
} }
return $this->getWrapperStorage()->getWatcher($this->getSourcePath($path), $storage); return $this->getWrapperStorage()->getWatcher($this->getUnjailedPath($path), $storage);
} }
/** /**
@ -414,7 +414,7 @@ class Jail extends Wrapper {
* @return string * @return string
*/ */
public function getETag($path) { public function getETag($path) {
return $this->getWrapperStorage()->getETag($this->getSourcePath($path)); return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path));
} }
/** /**
@ -422,7 +422,7 @@ class Jail extends Wrapper {
* @return array * @return array
*/ */
public function getMetaData($path) { public function getMetaData($path) {
return $this->getWrapperStorage()->getMetaData($this->getSourcePath($path)); return $this->getWrapperStorage()->getMetaData($this->getUnjailedPath($path));
} }
/** /**
@ -432,7 +432,7 @@ class Jail extends Wrapper {
* @throws \OCP\Lock\LockedException * @throws \OCP\Lock\LockedException
*/ */
public function acquireLock($path, $type, ILockingProvider $provider) { public function acquireLock($path, $type, ILockingProvider $provider) {
$this->getWrapperStorage()->acquireLock($this->getSourcePath($path), $type, $provider); $this->getWrapperStorage()->acquireLock($this->getUnjailedPath($path), $type, $provider);
} }
/** /**
@ -441,7 +441,7 @@ class Jail extends Wrapper {
* @param \OCP\Lock\ILockingProvider $provider * @param \OCP\Lock\ILockingProvider $provider
*/ */
public function releaseLock($path, $type, ILockingProvider $provider) { public function releaseLock($path, $type, ILockingProvider $provider) {
$this->getWrapperStorage()->releaseLock($this->getSourcePath($path), $type, $provider); $this->getWrapperStorage()->releaseLock($this->getUnjailedPath($path), $type, $provider);
} }
/** /**
@ -450,7 +450,7 @@ class Jail extends Wrapper {
* @param \OCP\Lock\ILockingProvider $provider * @param \OCP\Lock\ILockingProvider $provider
*/ */
public function changeLock($path, $type, ILockingProvider $provider) { public function changeLock($path, $type, ILockingProvider $provider) {
$this->getWrapperStorage()->changeLock($this->getSourcePath($path), $type, $provider); $this->getWrapperStorage()->changeLock($this->getUnjailedPath($path), $type, $provider);
} }
/** /**
@ -460,7 +460,7 @@ class Jail extends Wrapper {
* @return array * @return array
*/ */
public function resolvePath($path) { public function resolvePath($path) {
return [$this->getWrapperStorage(), $this->getSourcePath($path)]; return [$this->getWrapperStorage(), $this->getUnjailedPath($path)];
} }
/** /**
@ -473,7 +473,7 @@ class Jail extends Wrapper {
if ($sourceStorage === $this) { if ($sourceStorage === $this) {
return $this->copy($sourceInternalPath, $targetInternalPath); return $this->copy($sourceInternalPath, $targetInternalPath);
} }
return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath)); return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath));
} }
/** /**
@ -486,6 +486,6 @@ class Jail extends Wrapper {
if ($sourceStorage === $this) { if ($sourceStorage === $this) {
return $this->rename($sourceInternalPath, $targetInternalPath); return $this->rename($sourceInternalPath, $targetInternalPath);
} }
return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getSourcePath($targetInternalPath)); return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath));
} }
} }