summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2016-06-30 15:05:13 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2016-06-30 15:05:13 +0200
commit3491400261c1454a9a30d3ec96969573330120cc (patch)
tree8979fd7e5dfa26198809042abddcee1a935fc183 /apps
parent723cf78169e7dc7138dedf70fa694b202060d8f5 (diff)
downloadnextcloud-server-3491400261c1454a9a30d3ec96969573330120cc.tar.gz
nextcloud-server-3491400261c1454a9a30d3ec96969573330120cc.zip
add some additonal permission checks to the webdav backend
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/connector/sabre/objecttree.php33
-rw-r--r--apps/dav/tests/unit/connector/sabre/objecttree.php20
2 files changed, 48 insertions, 5 deletions
diff --git a/apps/dav/lib/connector/sabre/objecttree.php b/apps/dav/lib/connector/sabre/objecttree.php
index f38dfe679c7..c952a68e9a2 100644
--- a/apps/dav/lib/connector/sabre/objecttree.php
+++ b/apps/dav/lib/connector/sabre/objecttree.php
@@ -71,7 +71,7 @@ class ObjectTree extends \Sabre\DAV\Tree {
* is present.
*
* @param string $path chunk file path to convert
- *
+ *
* @return string path to real file
*/
private function resolveChunkFile($path) {
@@ -184,16 +184,29 @@ class ObjectTree extends \Sabre\DAV\Tree {
*
* @param string $sourcePath The path to the file which should be moved
* @param string $destinationPath The full destination path, so not just the destination parent node
- * @throws \Sabre\DAV\Exception\BadRequest
- * @throws \Sabre\DAV\Exception\ServiceUnavailable
- * @throws \Sabre\DAV\Exception\Forbidden
* @return int
+ * @throws FileLocked
+ * @throws Forbidden
+ * @throws InvalidPath
+ * @throws \Sabre\DAV\Exception\Forbidden
+ * @throws \Sabre\DAV\Exception\Locked
+ * @throws \Sabre\DAV\Exception\NotFound
+ * @throws \Sabre\DAV\Exception\ServiceUnavailable
*/
public function move($sourcePath, $destinationPath) {
if (!$this->fileView) {
throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
}
+ $infoDestination = $this->fileView->getFileInfo(dirname($destinationPath));
+ $infoSource = $this->fileView->getFileInfo($sourcePath);
+ $destinationPermission = $infoDestination && $infoDestination->isUpdateable();
+ $sourcePermission = $infoSource && $infoSource->isDeletable();
+
+ if (!$destinationPermission || !$sourcePermission) {
+ throw new Forbidden('No permissions to move object.');
+ }
+
$targetNodeExists = $this->nodeExists($destinationPath);
$sourceNode = $this->getNodeForPath($sourcePath);
if ($sourceNode instanceof \Sabre\DAV\ICollection && $targetNodeExists) {
@@ -263,14 +276,24 @@ class ObjectTree extends \Sabre\DAV\Tree {
*
* @param string $source
* @param string $destination
+ * @throws FileLocked
+ * @throws Forbidden
+ * @throws InvalidPath
+ * @throws \Exception
+ * @throws \Sabre\DAV\Exception\Locked
+ * @throws \Sabre\DAV\Exception\NotFound
* @throws \Sabre\DAV\Exception\ServiceUnavailable
- * @return void
*/
public function copy($source, $destination) {
if (!$this->fileView) {
throw new \Sabre\DAV\Exception\ServiceUnavailable('filesystem not setup');
}
+ $info = $this->fileView->getFileInfo(dirname($destination));
+ if ($info && !$info->isUpdateable()) {
+ throw new Forbidden('No permissions to copy object.');
+ }
+
// this will trigger existence check
$this->getNodeForPath($source);
diff --git a/apps/dav/tests/unit/connector/sabre/objecttree.php b/apps/dav/tests/unit/connector/sabre/objecttree.php
index e5e858ef17b..5b0dcae21b5 100644
--- a/apps/dav/tests/unit/connector/sabre/objecttree.php
+++ b/apps/dav/tests/unit/connector/sabre/objecttree.php
@@ -56,6 +56,11 @@ class TestDoubleFileView extends \OC\Files\View {
public function getRelativePath($path) {
return $path;
}
+
+ public function getFileInfo($path, $includeMountPoints = true) {
+ $objectTreeTest = new ObjectTreeTest();
+ return $objectTreeTest->getFileInfoMock();
+ }
}
/**
@@ -67,6 +72,21 @@ class TestDoubleFileView extends \OC\Files\View {
*/
class ObjectTree extends \Test\TestCase {
+ public function getFileInfoMock() {
+ $mock = $this->getMock('\OCP\Files\FileInfo');
+ $mock
+ ->expects($this->any())
+ ->method('isDeletable')
+ ->willReturn(true);
+ $mock
+ ->expects($this->any())
+ ->method('isUpdateable')
+ ->willReturn(true);
+
+ return $mock;
+ }
+
+
/**
* @dataProvider moveFailedProvider
* @expectedException \Sabre\DAV\Exception\Forbidden