diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Files/Cache/Wrapper/CacheJail.php | 54 | ||||
-rw-r--r-- | lib/private/Share20/Share.php | 5 |
2 files changed, 38 insertions, 21 deletions
diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index 2f873a65cfe..97700156d08 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -46,6 +46,7 @@ class CacheJail extends CacheWrapper { * @var string */ protected $root; + protected $unjailedRoot; /** * @param \OCP\Files\Cache\ICache $cache @@ -56,12 +57,27 @@ class CacheJail extends CacheWrapper { $this->root = $root; $this->connection = \OC::$server->getDatabaseConnection(); $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); + + if ($cache instanceof CacheJail) { + $this->unjailedRoot = $cache->getSourcePath($root); + } else { + $this->unjailedRoot = $root; + } } protected function getRoot() { return $this->root; } + /** + * Get the root path with any nested jails resolved + * + * @return string + */ + protected function getGetUnjailedRoot() { + return $this->unjailedRoot; + } + protected function getSourcePath($path) { if ($path === '') { return $this->getRoot(); @@ -72,16 +88,20 @@ class CacheJail extends CacheWrapper { /** * @param string $path + * @param null|string $root * @return null|string the jailed path or null if the path is outside the jail */ - protected function getJailedPath($path) { - if ($this->getRoot() === '') { + protected function getJailedPath(string $path, string $root = null) { + if ($root === null) { + $root = $this->getRoot(); + } + if ($root === '') { return $path; } - $rootLength = strlen($this->getRoot()) + 1; - if ($path === $this->getRoot()) { + $rootLength = strlen($root) + 1; + if ($path === $root) { return ''; - } elseif (substr($path, 0, $rootLength) === $this->getRoot() . '/') { + } elseif (substr($path, 0, $rootLength) === $root . '/') { return substr($path, $rootLength); } else { return null; @@ -99,11 +119,6 @@ class CacheJail extends CacheWrapper { return $entry; } - protected function filterCacheEntry($entry) { - $rootLength = strlen($this->getRoot()) + 1; - return $rootLength === 1 || ($entry['path'] === $this->getRoot()) || (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/'); - } - /** * get the stored metadata of a file or folder * @@ -216,9 +231,10 @@ class CacheJail extends CacheWrapper { } private function formatSearchResults($results) { - $results = array_filter($results, [$this, 'filterCacheEntry']); - $results = array_values($results); - return array_map([$this, 'formatCacheEntry'], $results); + return array_map(function($entry) { + $entry['path'] = $this->getJailedPath($entry['path'], $this->getGetUnjailedRoot()); + return $entry; + }, $results); } /** @@ -239,8 +255,8 @@ class CacheJail extends CacheWrapper { $query->selectFileCache() ->whereStorageId() ->andWhere($query->expr()->orX( - $query->expr()->like('path', $query->createNamedParameter($this->getRoot() . '/%')), - $query->expr()->eq('path_hash', $query->createNamedParameter(md5($this->getRoot()))), + $query->expr()->like('path', $query->createNamedParameter($this->getGetUnjailedRoot() . '/%')), + $query->expr()->eq('path_hash', $query->createNamedParameter(md5($this->getGetUnjailedRoot()))), )) ->andWhere($query->expr()->iLike('name', $query->createNamedParameter($pattern))); @@ -267,8 +283,8 @@ class CacheJail extends CacheWrapper { $query->selectFileCache() ->whereStorageId() ->andWhere($query->expr()->orX( - $query->expr()->like('path', $query->createNamedParameter($this->getRoot() . '/%')), - $query->expr()->eq('path_hash', $query->createNamedParameter(md5($this->getRoot()))), + $query->expr()->like('path', $query->createNamedParameter($this->getGetUnjailedRoot() . '/%')), + $query->expr()->eq('path_hash', $query->createNamedParameter(md5($this->getGetUnjailedRoot()))), )); if (strpos($mimetype, '/')) { @@ -291,12 +307,12 @@ class CacheJail extends CacheWrapper { $prefixFilter = new SearchComparison( ISearchComparison::COMPARE_LIKE, 'path', - $this->getRoot() . '/%' + $this->getGetUnjailedRoot() . '/%' ); $rootFilter = new SearchComparison( ISearchComparison::COMPARE_EQUAL, 'path', - $this->getRoot() + $this->getGetUnjailedRoot() ); $operation = new SearchBinaryOperator( ISearchBinaryOperator::OPERATOR_AND, diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php index 69f36edf4f3..9b782d5a446 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -32,6 +32,7 @@ namespace OC\Share20; use OCP\Files\Cache\ICacheEntry; use OCP\Files\File; +use OCP\Files\FileInfo; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; @@ -233,8 +234,8 @@ class Share implements \OCP\Share\IShare { */ public function getNodeType() { if ($this->nodeType === null) { - $node = $this->getNode(); - $this->nodeType = $node instanceof File ? 'file' : 'folder'; + $info = $this->getNodeCacheEntry(); + $this->nodeType = $info->getMimeType() === FileInfo::MIMETYPE_FOLDER ? 'folder' : 'file'; } return $this->nodeType; |