From 71012b3432239eba6746fdcee0f3fc6fb6622e33 Mon Sep 17 00:00:00 2001 From: Juan Pablo Villafáñez Date: Mon, 27 Mar 2017 08:50:03 +0200 Subject: Adjust SMB permissions on the root --- apps/files_external/lib/Lib/Storage/SMB.php | 63 +++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-) (limited to 'apps/files_external/lib') diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index cc4cd641ce5..859fceb50aa 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -162,10 +162,48 @@ class SMB extends Common implements INotifyStorage { * @return array */ protected function formatInfo($info) { - return array( + $result = [ 'size' => $info->getSize(), - 'mtime' => $info->getMTime() - ); + 'mtime' => $info->getMTime(), + ]; + if ($info->isDirectory()) { + $result['type'] = 'dir'; + } else { + $result['type'] = 'file'; + } + return $result; + } + + /** + * 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 + * @return bool true if the rename is successful, false otherwise + */ + 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); + $this->removeFromCache($this->root . $target); + } catch (AlreadyExistsException $e) { + $this->unlink($target); + $result = $this->share->rename($this->root . $source, $this->root . $target); + $this->removeFromCache($this->root . $source); + $this->removeFromCache($this->root . $target); + $this->swallow(__FUNCTION__, $e); + } catch (\Exception $e) { + $this->swallow(__FUNCTION__, $e); + $result = false; + } + return $this->leave(__FUNCTION__, $result); } /** @@ -220,6 +258,13 @@ class SMB extends Common implements INotifyStorage { * @return bool */ public function unlink($path) { + $this->log('enter: '.__FUNCTION__."($path)"); + + if ($this->isRootDir($path)) { + $this->log("refusing to unlink \"$path\""); + return $this->leave(__FUNCTION__, false); + } + try { if ($this->is_dir($path)) { return $this->rmdir($path); @@ -343,6 +388,13 @@ class SMB extends Common implements INotifyStorage { } public function rmdir($path) { + $this->log('enter: '.__FUNCTION__."($path)"); + + if ($this->isRootDir($path)) { + $this->log("refusing to delete \"$path\""); + return $this->leave(__FUNCTION__, false); + } + try { $this->statCache = array(); $content = $this->share->dir($this->buildPath($path)); @@ -439,6 +491,8 @@ class SMB extends Common implements INotifyStorage { } public function isUpdatable($path) { + $this->log('enter: '.__FUNCTION__."($path)"); + $result = false; try { $info = $this->getFileInfo($path); // following windows behaviour for read-only folders: they can be written into @@ -449,9 +503,12 @@ class SMB extends Common implements INotifyStorage { } catch (ForbiddenException $e) { return false; } + return $this->leave(__FUNCTION__, $result); } public function isDeletable($path) { + $this->log('enter: '.__FUNCTION__."($path)"); + $result = false; try { $info = $this->getFileInfo($path); return !$info->isHidden() && !$info->isReadOnly(); -- cgit v1.2.3 From 43970b93d137f06d64f58819a3c4f48dac07fea1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 26 Apr 2017 16:41:48 +0200 Subject: remove excessive logging Signed-off-by: Robin Appelman --- apps/files_external/lib/Lib/Storage/SMB.php | 33 +++++++---------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'apps/files_external/lib') diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 859fceb50aa..8f595f05bc1 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -31,6 +31,7 @@ namespace OCA\Files_External\Lib\Storage; +use Icewind\SMB\Exception\AlreadyExistsException; use Icewind\SMB\Exception\ConnectException; use Icewind\SMB\Exception\Exception; use Icewind\SMB\Exception\ForbiddenException; @@ -182,28 +183,21 @@ class SMB extends Common implements INotifyStorage { * @return bool true if the rename is successful, false otherwise */ 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); + return false; } try { $result = $this->share->rename($this->root . $source, $this->root . $target); - $this->removeFromCache($this->root . $source); - $this->removeFromCache($this->root . $target); + unset($this->statCache[$this->root . $source], $this->statCache[$this->root . $target]); } catch (AlreadyExistsException $e) { $this->unlink($target); $result = $this->share->rename($this->root . $source, $this->root . $target); - $this->removeFromCache($this->root . $source); - $this->removeFromCache($this->root . $target); - $this->swallow(__FUNCTION__, $e); + unset($this->statCache[$this->root . $source], $this->statCache[$this->root . $target]); } catch (\Exception $e) { - $this->swallow(__FUNCTION__, $e); $result = false; } - return $this->leave(__FUNCTION__, $result); + return $result; } /** @@ -258,11 +252,8 @@ class SMB extends Common implements INotifyStorage { * @return bool */ public function unlink($path) { - $this->log('enter: '.__FUNCTION__."($path)"); - if ($this->isRootDir($path)) { - $this->log("refusing to unlink \"$path\""); - return $this->leave(__FUNCTION__, false); + return false; } try { @@ -311,7 +302,7 @@ class SMB extends Common implements INotifyStorage { * @return bool */ public function hasUpdated($path, $time) { - if (!$path and $this->root == '/') { + if (!$path and $this->root === '/') { // mtime doesn't work for shares, but giving the nature of the backend, // doing a full update is still just fast enough return true; @@ -388,11 +379,8 @@ class SMB extends Common implements INotifyStorage { } public function rmdir($path) { - $this->log('enter: '.__FUNCTION__."($path)"); - if ($this->isRootDir($path)) { - $this->log("refusing to delete \"$path\""); - return $this->leave(__FUNCTION__, false); + return false; } try { @@ -491,8 +479,6 @@ class SMB extends Common implements INotifyStorage { } public function isUpdatable($path) { - $this->log('enter: '.__FUNCTION__."($path)"); - $result = false; try { $info = $this->getFileInfo($path); // following windows behaviour for read-only folders: they can be written into @@ -503,12 +489,9 @@ class SMB extends Common implements INotifyStorage { } catch (ForbiddenException $e) { return false; } - return $this->leave(__FUNCTION__, $result); } public function isDeletable($path) { - $this->log('enter: '.__FUNCTION__."($path)"); - $result = false; try { $info = $this->getFileInfo($path); return !$info->isHidden() && !$info->isReadOnly(); -- cgit v1.2.3 From acb0903514f1a34480589197655281bdc1a16de9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 26 Apr 2017 16:45:04 +0200 Subject: remove duplicate method Signed-off-by: Robin Appelman --- apps/files_external/lib/Lib/Storage/SMB.php | 34 +++++++---------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'apps/files_external/lib') diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 8f595f05bc1..7afdb746a98 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -91,6 +91,7 @@ class SMB extends Common implements INotifyStorage { throw new \Exception('Invalid configuration'); } $this->statCache = new CappedMemoryCache(); + parent::__construct($params); } /** @@ -187,16 +188,17 @@ class SMB extends Common implements INotifyStorage { return false; } + $absoluteSource = $this->buildPath($source); + $absoluteTarget = $this->buildPath($target); try { - $result = $this->share->rename($this->root . $source, $this->root . $target); - unset($this->statCache[$this->root . $source], $this->statCache[$this->root . $target]); + $result = $this->share->rename($absoluteSource, $absoluteTarget); } catch (AlreadyExistsException $e) { - $this->unlink($target); - $result = $this->share->rename($this->root . $source, $this->root . $target); - unset($this->statCache[$this->root . $source], $this->statCache[$this->root . $target]); + $this->remove($target); + $result = $this->share->rename($absoluteSource, $absoluteTarget); } catch (\Exception $e) { - $result = false; + return false; } + unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]); return $result; } @@ -274,26 +276,6 @@ class SMB extends Common implements INotifyStorage { } } - /** - * @param string $path1 the old name - * @param string $path2 the new name - * @return bool - */ - public function rename($path1, $path2) { - try { - $this->remove($path2); - $path1 = $this->buildPath($path1); - $path2 = $this->buildPath($path2); - return $this->share->rename($path1, $path2); - } catch (NotFoundException $e) { - return false; - } catch (ForbiddenException $e) { - return false; - } catch (ConnectException $e) { - throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e); - } - } - /** * check if a file or folder has been updated since $time * -- cgit v1.2.3