Merge pull request #16632 from nextcloud/bugfix/external-reshare

Set proper root path for single file shares originating from other storages
This commit is contained in:
Roeland Jago Douma 2020-09-01 08:48:31 +02:00 committed by GitHub
commit e0d767d3e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 49 deletions

View File

@ -244,57 +244,55 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
} }
public function fopen($path, $mode) { public function fopen($path, $mode) {
if ($source = $this->getUnjailedPath($path)) { $source = $this->getUnjailedPath($path);
switch ($mode) { switch ($mode) {
case 'r+': case 'r+':
case 'rb+': case 'rb+':
case 'w+': case 'w+':
case 'wb+': case 'wb+':
case 'x+': case 'x+':
case 'xb+': case 'xb+':
case 'a+': case 'a+':
case 'ab+': case 'ab+':
case 'w': case 'w':
case 'wb': case 'wb':
case 'x': case 'x':
case 'xb': case 'xb':
case 'a': case 'a':
case 'ab': case 'ab':
$creatable = $this->isCreatable(dirname($path)); $creatable = $this->isCreatable(dirname($path));
$updatable = $this->isUpdatable($path); $updatable = $this->isUpdatable($path);
// if neither permissions given, no need to continue // if neither permissions given, no need to continue
if (!$creatable && !$updatable) { if (!$creatable && !$updatable) {
if (pathinfo($path, PATHINFO_EXTENSION) === 'part') { if (pathinfo($path, PATHINFO_EXTENSION) === 'part') {
$updatable = $this->isUpdatable(dirname($path)); $updatable = $this->isUpdatable(dirname($path));
}
if (!$updatable) {
return false;
}
} }
$exists = $this->file_exists($path); if (!$updatable) {
// if a file exists, updatable permissions are required
if ($exists && !$updatable) {
return false; return false;
} }
}
// part file is allowed if !$creatable but the final file is $updatable $exists = $this->file_exists($path);
if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { // if a file exists, updatable permissions are required
if (!$exists && !$creatable) { if ($exists && !$updatable) {
return false; 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);
} }
/** /**

View File

@ -56,11 +56,7 @@ class Jail extends Wrapper {
} }
public function getUnjailedPath($path) { public function getUnjailedPath($path) {
if ($path === '') { return trim(Filesystem::normalizePath($this->rootPath . '/' . $path), '/');
return $this->rootPath;
} else {
return Filesystem::normalizePath($this->rootPath . '/' . $path);
}
} }
/** /**