Skip to content

Commit

Permalink
fix permision mask applying outside home directory for cache entries
Browse files Browse the repository at this point in the history
fixes #113
  • Loading branch information
icewind1991 committed Jul 30, 2019
1 parent d042b2d commit 78a4ff7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Storage/DirMask.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace OCA\Guests\Storage;

use OC\Files\Cache\Wrapper\CachePermissionsMask;
use OC\Files\Storage\Wrapper\PermissionsMask;


Expand All @@ -41,6 +42,8 @@ class DirMask extends PermissionsMask {
*/
private $pathLength;

private $mask;

/**
* @param array $arguments ['storage' => $storage, 'mask' => $mask, 'path' => $path]
*
Expand All @@ -52,6 +55,7 @@ public function __construct($arguments) {
parent::__construct($arguments);
$this->path = $arguments['path'];
$this->pathLength = strlen($arguments['path']);
$this->mask = $arguments['mask'];
}

protected function checkPath($path) {
Expand Down Expand Up @@ -185,4 +189,12 @@ public function fopen($path, $mode) {
return $this->storage->fopen($path, $mode);
}
}

public function getCache($path = '', $storage = null) {
if (!$storage) {
$storage = $this;
}
$sourceCache = $this->storage->getCache($path, $storage);
return new DirMaskCache($sourceCache, $this->mask, [$this, 'checkPath']);
}
}
48 changes: 48 additions & 0 deletions lib/Storage/DirMaskCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 Robin Appelman <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Guests\Storage;


use OC\Files\Cache\Wrapper\CachePermissionsMask;

class DirMaskCache extends CachePermissionsMask {

private $checkPath;

/**
* @param \OCP\Files\Cache\ICache $cache
* @param int $mask
*/
public function __construct($cache, $mask, callable $checkPath) {
parent::__construct($cache, $mask);
$this->checkPath = $checkPath;
}

protected function formatCacheEntry($entry) {
$checkPath = $this->checkPath;
if ($checkPath($entry['path'])) {
return parent::formatCacheEntry($entry);
}
return $entry;
}

}

0 comments on commit 78a4ff7

Please sign in to comment.