Skip to content

Commit

Permalink
Merge pull request #16632 from nextcloud/bugfix/external-reshare
Browse files Browse the repository at this point in the history
Set proper root path for single file shares originating from other storages
  • Loading branch information
rullzer committed Sep 1, 2020
2 parents 023d18b + af381a9 commit e0d767d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 49 deletions.
86 changes: 42 additions & 44 deletions apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions lib/private/Files/Storage/Wrapper/Jail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 trim(Filesystem::normalizePath($this->rootPath . '/' . $path), '/');
}

/**
Expand Down

0 comments on commit e0d767d

Please sign in to comment.