summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-09-01 08:48:31 +0200
committerGitHub <noreply@github.com>2020-09-01 08:48:31 +0200
commite0d767d3e17f9791ca1e9b3fe475123d915f2ae6 (patch)
tree4004122aa461cb24fe77687b22d20def565a6744
parent023d18bc40c9c704facdb3a4d19db81e60dbb1c2 (diff)
parentaf381a9a934f349d72af6b712811f98292cc2c38 (diff)
downloadnextcloud-server-e0d767d3e17f9791ca1e9b3fe475123d915f2ae6.tar.gz
nextcloud-server-e0d767d3e17f9791ca1e9b3fe475123d915f2ae6.zip
Merge pull request #16632 from nextcloud/bugfix/external-reshare
Set proper root path for single file shares originating from other storages
-rw-r--r--apps/files_sharing/lib/SharedStorage.php86
-rw-r--r--lib/private/Files/Storage/Wrapper/Jail.php6
2 files changed, 43 insertions, 49 deletions
diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php
index 7477e5601ff..a90d347593f 100644
--- a/apps/files_sharing/lib/SharedStorage.php
+++ b/apps/files_sharing/lib/SharedStorage.php
@@ -244,57 +244,55 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
}
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);
}
/**
diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php
index 7350c104ba8..449a238096d 100644
--- a/lib/private/Files/Storage/Wrapper/Jail.php
+++ b/lib/private/Files/Storage/Wrapper/Jail.php
@@ -56,11 +56,7 @@ class Jail extends Wrapper {
}
public function getUnjailedPath($path) {
- if ($path === '') {
- return $this->rootPath;
- } else {
- return Filesystem::normalizePath($this->rootPath . '/' . $path);
- }
+ return trim(Filesystem::normalizePath($this->rootPath . '/' . $path), '/');
}
/**