Merge pull request #2485 from nextcloud/shared-storage-mask-10
[10] apply permissions mask for shared storage
This commit is contained in:
commit
cf752bea22
|
@ -34,6 +34,7 @@ namespace OC\Files\Storage;
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OC\Files\Cache\FailedCache;
|
use OC\Files\Cache\FailedCache;
|
||||||
use OCA\Files_Sharing\ISharedStorage;
|
use OCA\Files_Sharing\ISharedStorage;
|
||||||
|
use OC\Files\Storage\Wrapper\PermissionsMask;
|
||||||
use OCP\Constants;
|
use OCP\Constants;
|
||||||
use OCP\Files\Cache\ICacheEntry;
|
use OCP\Files\Cache\ICacheEntry;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
|
@ -70,6 +71,9 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage {
|
||||||
*/
|
*/
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
|
/** @var IStorage */
|
||||||
|
private $nonMaskedStorage;
|
||||||
|
|
||||||
public function __construct($arguments) {
|
public function __construct($arguments) {
|
||||||
$this->ownerView = $arguments['ownerView'];
|
$this->ownerView = $arguments['ownerView'];
|
||||||
$this->logger = \OC::$server->getLogger();
|
$this->logger = \OC::$server->getLogger();
|
||||||
|
@ -93,8 +97,12 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage {
|
||||||
try {
|
try {
|
||||||
Filesystem::initMountPoints($this->superShare->getShareOwner());
|
Filesystem::initMountPoints($this->superShare->getShareOwner());
|
||||||
$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
|
$sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
|
||||||
list($this->storage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath);
|
list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath);
|
||||||
$this->sourceRootInfo = $this->storage->getCache()->get($this->rootPath);
|
$this->storage = new PermissionsMask([
|
||||||
|
'storage' => $this->nonMaskedStorage,
|
||||||
|
'mask' => $this->superShare->getPermissions()
|
||||||
|
]);
|
||||||
|
$this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath);
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
$this->storage = new FailedStorage(['exception' => $e]);
|
$this->storage = new FailedStorage(['exception' => $e]);
|
||||||
$this->rootPath = '';
|
$this->rootPath = '';
|
||||||
|
@ -232,7 +240,7 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage {
|
||||||
'mode' => $mode,
|
'mode' => $mode,
|
||||||
);
|
);
|
||||||
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
|
\OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info);
|
||||||
return parent::fopen($path, $mode);
|
return $this->nonMaskedStorage->fopen($this->getSourcePath($path), $mode);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -245,6 +253,7 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function rename($path1, $path2) {
|
public function rename($path1, $path2) {
|
||||||
|
$this->init();
|
||||||
$isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
|
$isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part';
|
||||||
$targetExists = $this->file_exists($path2);
|
$targetExists = $this->file_exists($path2);
|
||||||
$sameFodler = dirname($path1) === dirname($path2);
|
$sameFodler = dirname($path1) === dirname($path2);
|
||||||
|
@ -259,7 +268,7 @@ class Shared extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::rename($path1, $path2);
|
return $this->nonMaskedStorage->rename($this->getSourcePath($path1), $this->getSourcePath($path2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -202,13 +202,13 @@ class SharedStorageTest extends TestCase {
|
||||||
$this->assertTrue(\OC\Files\Filesystem::is_dir($this->folder));
|
$this->assertTrue(\OC\Files\Filesystem::is_dir($this->folder));
|
||||||
|
|
||||||
// for the share root we expect:
|
// for the share root we expect:
|
||||||
// the shared permissions (1)
|
// the read permissions (1)
|
||||||
// the delete permission (8), to enable unshare
|
// the delete permission (8), to enable unshare
|
||||||
$rootInfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
$rootInfo = \OC\Files\Filesystem::getFileInfo($this->folder);
|
||||||
$this->assertSame(9, $rootInfo->getPermissions());
|
$this->assertSame(9, $rootInfo->getPermissions());
|
||||||
|
|
||||||
// for the file within the shared folder we expect:
|
// for the file within the shared folder we expect:
|
||||||
// the shared permissions (1)
|
// the read permissions (1)
|
||||||
$subfileInfo = \OC\Files\Filesystem::getFileInfo($this->folder . $this->filename);
|
$subfileInfo = \OC\Files\Filesystem::getFileInfo($this->folder . $this->filename);
|
||||||
$this->assertSame(1, $subfileInfo->getPermissions());
|
$this->assertSame(1, $subfileInfo->getPermissions());
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ class PermissionsMask extends Wrapper {
|
||||||
|
|
||||||
public function file_put_contents($path, $data) {
|
public function file_put_contents($path, $data) {
|
||||||
$permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
|
$permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE;
|
||||||
return $this->checkMask($permissions) and parent::file_put_contents($path, $data);
|
return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fopen($path, $mode) {
|
public function fopen($path, $mode) {
|
||||||
|
|
|
@ -77,7 +77,7 @@ class PermissionsMaskTest extends \Test\Files\Storage\Storage {
|
||||||
|
|
||||||
public function testPutContentsNewFileNoUpdate() {
|
public function testPutContentsNewFileNoUpdate() {
|
||||||
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
|
$storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
|
||||||
$this->assertTrue($storage->file_put_contents('foo', 'bar'));
|
$this->assertEquals(3, $storage->file_put_contents('foo', 'bar'));
|
||||||
$this->assertEquals('bar', $storage->file_get_contents('foo'));
|
$this->assertEquals('bar', $storage->file_get_contents('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue