we don't allow to share a folder if it contains a share mount point
This commit is contained in:
parent
b712393e72
commit
652d417a58
|
@ -411,7 +411,7 @@ class Shared_Cache extends Cache {
|
|||
}
|
||||
|
||||
/**
|
||||
* get the path of a file on this storage by it's id
|
||||
* get the path of a file on this storage relative to the mount point by it's id
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $pathEnd (optional) used internally for recursive calls
|
||||
|
@ -419,8 +419,9 @@ class Shared_Cache extends Cache {
|
|||
*/
|
||||
public function getPathById($id, $pathEnd = '') {
|
||||
// direct shares are easy
|
||||
if ($path = $this->getShareById($id)) {
|
||||
return $path . $pathEnd;
|
||||
$path = $this->getShareById($id);
|
||||
if (is_string($path)) {
|
||||
return ltrim($pathEnd, '/');
|
||||
} else {
|
||||
// if the item is a direct share we try and get the path of the parent and append the name of the item to it
|
||||
list($parent, $name) = $this->getParentInfo($id);
|
||||
|
|
|
@ -347,6 +347,7 @@ class Shared extends \OC\Files\Storage\Common {
|
|||
$mountManager->addMount($mount);
|
||||
$mountManager->removeMount($sourcePath . '/');
|
||||
$this->setUniqueName();
|
||||
$this->setMountPoint($relTargetPath);
|
||||
|
||||
} else {
|
||||
\OCP\Util::writeLog('file sharing',
|
||||
|
@ -500,6 +501,10 @@ class Shared extends \OC\Files\Storage\Common {
|
|||
return $this->share['share_type'];
|
||||
}
|
||||
|
||||
private function setMountPoint($path) {
|
||||
$this->share['file_target'] = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief does the group share already has a user specific unique name
|
||||
* @return bool
|
||||
|
|
|
@ -866,6 +866,66 @@ class Test_Files_Sharing_Api extends Test_Files_Sharing_Base {
|
|||
|
||||
$this->assertTrue($result3->succeeded());
|
||||
|
||||
// cleanup
|
||||
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
$result = \OCP\Share::unshare('folder', $fileInfo1['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief share a folder which contains a share mount point, should be forbidden
|
||||
*/
|
||||
public function testShareFolderWithAMountPoint() {
|
||||
// user 1 shares a folder with user2
|
||||
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
$fileInfo = $this->view->getFileInfo($this->folder);
|
||||
|
||||
$result = \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2, 31);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
// user2 shares a file from the folder as link
|
||||
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
|
||||
|
||||
$view = new \OC\Files\View('/' . \Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2 . '/files');
|
||||
$view->mkdir("localDir");
|
||||
|
||||
// move mount point to the folder "localDir"
|
||||
$result = $view->rename($this->folder, 'localDir/'.$this->folder);
|
||||
$this->assertTrue($result !== false);
|
||||
|
||||
// try to share "localDir"
|
||||
$fileInfo2 = $view->getFileInfo('localDir');
|
||||
|
||||
$this->assertTrue($fileInfo2 instanceof \OC\Files\FileInfo);
|
||||
|
||||
try {
|
||||
$result2 = \OCP\Share::shareItem('folder', $fileInfo2['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER3, 31);
|
||||
} catch (\Exception $e) {
|
||||
$result2 = false;
|
||||
}
|
||||
|
||||
$this->assertFalse($result2);
|
||||
|
||||
//cleanup
|
||||
|
||||
$result = $view->rename('localDir/' . $this->folder, $this->folder);
|
||||
$this->assertTrue($result !== false);
|
||||
$view->unlink('localDir');
|
||||
|
||||
\Test_Files_Sharing_Api::loginHelper(\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER1);
|
||||
|
||||
\OCP\Share::unshare('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER,
|
||||
\Test_Files_Sharing_Api::TEST_FILES_SHARING_API_USER2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base {
|
|||
*/
|
||||
|
||||
$sharedCache = $sharedStorage->getCache();
|
||||
$this->assertEquals('test.txt', $sharedCache->getPathById($info->getId()));
|
||||
$this->assertEquals('', $sharedCache->getPathById($info->getId()));
|
||||
}
|
||||
|
||||
public function testGetPathByIdShareSubFolder() {
|
||||
|
@ -276,7 +276,7 @@ class Test_Files_Sharing_Cache extends Test_Files_Sharing_Base {
|
|||
*/
|
||||
|
||||
$sharedCache = $sharedStorage->getCache();
|
||||
$this->assertEquals('foo', $sharedCache->getPathById($folderInfo->getId()));
|
||||
$this->assertEquals('foo/bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
|
||||
$this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
|
||||
$this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1168,7 +1168,8 @@ class View {
|
|||
* @var \OC\Files\Mount\Mount $mount
|
||||
*/
|
||||
$cache = $mount->getStorage()->getCache();
|
||||
if ($internalPath = $cache->getPathById($id)) {
|
||||
$internalPath = $cache->getPathById($id);
|
||||
if (is_string($internalPath)) {
|
||||
$fullPath = $mount->getMountPoint() . $internalPath;
|
||||
if (!is_null($path = $this->getRelativePath($fullPath))) {
|
||||
return $path;
|
||||
|
|
|
@ -489,6 +489,7 @@ class Share extends \OC\Share\Constants {
|
|||
$itemSourceName = $itemSource;
|
||||
}
|
||||
|
||||
|
||||
// verify that the file exists before we try to share it
|
||||
if ($itemType === 'file' or $itemType === 'folder') {
|
||||
$path = \OC\Files\Filesystem::getPath($itemSource);
|
||||
|
@ -499,6 +500,21 @@ class Share extends \OC\Share\Constants {
|
|||
}
|
||||
}
|
||||
|
||||
//verify that we don't share a folder which already contains a share mount point
|
||||
if ($itemType === 'folder') {
|
||||
$path = '/' . $uidOwner . '/files' . \OC\Files\Filesystem::getPath($itemSource) . '/';
|
||||
$mountManager = \OC\Files\Filesystem::getMountManager();
|
||||
$mounts = $mountManager->getAll();
|
||||
foreach ($mounts as $mountPoint => $mount) {
|
||||
if ($mount->getStorage() instanceof \OC\Files\Storage\Shared && strpos($mountPoint, $path) === 0) {
|
||||
$message = 'Sharing "' . $itemSourceName . '" failed, because it contains files shared with you!';
|
||||
\OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
|
||||
throw new \Exception($message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Verify share type and sharing conditions are met
|
||||
if ($shareType === self::SHARE_TYPE_USER) {
|
||||
if ($shareWith == $uidOwner) {
|
||||
|
|
Loading…
Reference in New Issue