diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index f977bb1fe137f36a12d9b24d9f3b1ea04924cde8..a03324853ebecf7b5e2b19745227cf07b6a2ed9f 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -242,7 +242,7 @@ class SMB extends \OCP\Files\Storage\StorageAdapter { } /** - * Rename the files + * Rename the files. If the source or the target is the root, the rename won't happen. * * @param string $source the old name of the path * @param string $target the new name of the path @@ -250,6 +250,12 @@ class SMB extends \OCP\Files\Storage\StorageAdapter { */ public function rename($source, $target) { $this->log("enter: rename('$source', '$target')", Util::DEBUG); + + if ($this->isRootDir($source) || $this->isRootDir($target)) { + $this->log("refusing to rename \"$source\" to \"$target\""); + return $this->leave(__FUNCTION__, false); + } + try { $result = $this->share->rename($this->root . $source, $this->root . $target); $this->removeFromCache($this->root . $source); @@ -330,6 +336,12 @@ class SMB extends \OCP\Files\Storage\StorageAdapter { */ public function unlink($path) { $this->log('enter: '.__FUNCTION__."($path)"); + + if ($this->isRootDir($path)) { + $this->log("refusing to unlink \"$path\""); + return $this->leave(__FUNCTION__, false); + } + $result = false; try { if ($this->is_dir($path)) { @@ -442,6 +454,12 @@ class SMB extends \OCP\Files\Storage\StorageAdapter { public function rmdir($path) { $this->log('enter: '.__FUNCTION__."($path)"); + + if ($this->isRootDir($path)) { + $this->log("refusing to delete \"$path\""); + return $this->leave(__FUNCTION__, false); + } + $result = false; try { $this->removeFromCache($path); diff --git a/apps/files_external/tests/Storage/SmbTest.php b/apps/files_external/tests/Storage/SmbTest.php index 4cecb45d4163ed37931ff881ad208696e7238ec3..fdb7564a5e13c9bc76ed153ac5891b5b8fa6f6e1 100644 --- a/apps/files_external/tests/Storage/SmbTest.php +++ b/apps/files_external/tests/Storage/SmbTest.php @@ -87,4 +87,23 @@ class SmbTest extends \Test\Files\Storage\Storage { $this->assertEquals('smb::testuser@testhost//someshare//someroot/', $this->instance->getId()); $this->instance = null; } + + public function testRenameRoot() { + // root can't be renamed + $this->assertFalse($this->instance->rename('', 'foo1')); + + $this->instance->mkdir('foo2'); + $this->assertFalse($this->instance->rename('foo2', '')); + $this->instance->rmdir('foo2'); + } + + public function testUnlinkRoot() { + // root can't be deleted + $this->assertFalse($this->instance->unlink('')); + } + + public function testRmdirRoot() { + // root can't be deleted + $this->assertFalse($this->instance->rmdir('')); + } }