Commit e34d6e02 authored by Vincent Petry's avatar Vincent Petry Committed by GitHub

Merge pull request #27504 from owncloud/smb_remove_rename_permission

Adjust SMB permissions on the root
parents 2259f7f7 03ae5f1b
...@@ -242,7 +242,7 @@ class SMB extends \OCP\Files\Storage\StorageAdapter { ...@@ -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 $source the old name of the path
* @param string $target the new name of the path * @param string $target the new name of the path
...@@ -250,6 +250,12 @@ class SMB extends \OCP\Files\Storage\StorageAdapter { ...@@ -250,6 +250,12 @@ class SMB extends \OCP\Files\Storage\StorageAdapter {
*/ */
public function rename($source, $target) { public function rename($source, $target) {
$this->log("enter: rename('$source', '$target')", Util::DEBUG); $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 { try {
$result = $this->share->rename($this->root . $source, $this->root . $target); $result = $this->share->rename($this->root . $source, $this->root . $target);
$this->removeFromCache($this->root . $source); $this->removeFromCache($this->root . $source);
...@@ -330,6 +336,12 @@ class SMB extends \OCP\Files\Storage\StorageAdapter { ...@@ -330,6 +336,12 @@ class SMB extends \OCP\Files\Storage\StorageAdapter {
*/ */
public function unlink($path) { public function unlink($path) {
$this->log('enter: '.__FUNCTION__."($path)"); $this->log('enter: '.__FUNCTION__."($path)");
if ($this->isRootDir($path)) {
$this->log("refusing to unlink \"$path\"");
return $this->leave(__FUNCTION__, false);
}
$result = false; $result = false;
try { try {
if ($this->is_dir($path)) { if ($this->is_dir($path)) {
...@@ -442,6 +454,12 @@ class SMB extends \OCP\Files\Storage\StorageAdapter { ...@@ -442,6 +454,12 @@ class SMB extends \OCP\Files\Storage\StorageAdapter {
public function rmdir($path) { public function rmdir($path) {
$this->log('enter: '.__FUNCTION__."($path)"); $this->log('enter: '.__FUNCTION__."($path)");
if ($this->isRootDir($path)) {
$this->log("refusing to delete \"$path\"");
return $this->leave(__FUNCTION__, false);
}
$result = false; $result = false;
try { try {
$this->removeFromCache($path); $this->removeFromCache($path);
......
...@@ -87,4 +87,23 @@ class SmbTest extends \Test\Files\Storage\Storage { ...@@ -87,4 +87,23 @@ class SmbTest extends \Test\Files\Storage\Storage {
$this->assertEquals('smb::testuser@testhost//someshare//someroot/', $this->instance->getId()); $this->assertEquals('smb::testuser@testhost//someshare//someroot/', $this->instance->getId());
$this->instance = null; $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(''));
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment