From 7512dc2b34ace9adecd792ee9494e595273d8ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 1 Aug 2019 14:45:50 +0200 Subject: [PATCH 1/3] Set proper root path for single file shares originating from other storages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christoph Wurst Signed-off-by: Julius Härtl Signed-off-by: Christoph Wurst --- lib/private/Files/Storage/Wrapper/Jail.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 7350c104ba855..40ec3836b3a43 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -56,11 +56,7 @@ public function __construct($arguments) { } public function getUnjailedPath($path) { - if ($path === '') { - return $this->rootPath; - } else { - return Filesystem::normalizePath($this->rootPath . '/' . $path); - } + return Filesystem::normalizePath($this->rootPath . '/' . $path); } /** From 2879472f817031c811b33871309acd9b03458e16 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 28 Aug 2020 11:14:50 +0200 Subject: [PATCH 2/3] trim slashes Signed-off-by: Robin Appelman --- lib/private/Files/Storage/Wrapper/Jail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 40ec3836b3a43..449a238096d5e 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -56,7 +56,7 @@ public function __construct($arguments) { } public function getUnjailedPath($path) { - return Filesystem::normalizePath($this->rootPath . '/' . $path); + return trim(Filesystem::normalizePath($this->rootPath . '/' . $path), '/'); } /** From af381a9a934f349d72af6b712811f98292cc2c38 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 28 Aug 2020 11:43:23 +0200 Subject: [PATCH 3/3] remove unneeded if Signed-off-by: Robin Appelman --- apps/files_sharing/lib/SharedStorage.php | 86 ++++++++++++------------ 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 7477e5601ff36..a90d347593f90 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -244,57 +244,55 @@ public function isSharable($path) { } public function fopen($path, $mode) { - if ($source = $this->getUnjailedPath($path)) { - switch ($mode) { - case 'r+': - case 'rb+': - case 'w+': - case 'wb+': - case 'x+': - case 'xb+': - case 'a+': - case 'ab+': - case 'w': - case 'wb': - case 'x': - case 'xb': - case 'a': - case 'ab': - $creatable = $this->isCreatable(dirname($path)); - $updatable = $this->isUpdatable($path); - // if neither permissions given, no need to continue - if (!$creatable && !$updatable) { - if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { - $updatable = $this->isUpdatable(dirname($path)); - } - - if (!$updatable) { - return false; - } + $source = $this->getUnjailedPath($path); + switch ($mode) { + case 'r+': + case 'rb+': + case 'w+': + case 'wb+': + case 'x+': + case 'xb+': + case 'a+': + case 'ab+': + case 'w': + case 'wb': + case 'x': + case 'xb': + case 'a': + case 'ab': + $creatable = $this->isCreatable(dirname($path)); + $updatable = $this->isUpdatable($path); + // if neither permissions given, no need to continue + if (!$creatable && !$updatable) { + if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { + $updatable = $this->isUpdatable(dirname($path)); } - $exists = $this->file_exists($path); - // if a file exists, updatable permissions are required - if ($exists && !$updatable) { + if (!$updatable) { return false; } + } - // part file is allowed if !$creatable but the final file is $updatable - if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { - if (!$exists && !$creatable) { - return false; - } + $exists = $this->file_exists($path); + // if a file exists, updatable permissions are required + if ($exists && !$updatable) { + return false; + } + + // part file is allowed if !$creatable but the final file is $updatable + if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { + if (!$exists && !$creatable) { + return false; } - } - $info = [ - 'target' => $this->getMountPoint() . $path, - 'source' => $source, - 'mode' => $mode, - ]; - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); - return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); + } } - return false; + $info = [ + 'target' => $this->getMountPoint() . $path, + 'source' => $source, + 'mode' => $mode, + ]; + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); + return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); } /**