summaryrefslogtreecommitdiffstats
path: root/lib/private/files
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-01-08 13:17:36 +0100
committerVincent Petry <pvince81@owncloud.com>2014-01-08 13:17:36 +0100
commitf642ad39614970de67358d80517bc1d76a006e0e (patch)
tree3606c38d2a8404307a03cb494e89e55c8206c293 /lib/private/files
parentbb443ae937bdbc9f50c352d34abeaa0eaa3fa890 (diff)
downloadnextcloud-server-f642ad39614970de67358d80517bc1d76a006e0e.tar.gz
nextcloud-server-f642ad39614970de67358d80517bc1d76a006e0e.zip
Prevent deleting storage root
Storage mount points are not deletable, so make sure that the unlink operation and its hooks aren't run in such cases. Note that some storages might recursively delete their contents when calling unlink on their root. This fix prevents that as well.
Diffstat (limited to 'lib/private/files')
-rw-r--r--lib/private/files/view.php13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index ac45a881331..8893911ed5d 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -336,6 +336,19 @@ class View {
}
public function unlink($path) {
+ if ($path === '' || $path === '/') {
+ // do not allow deleting the root
+ return false;
+ }
+ $postFix = (substr($path, -1, 1) === '/') ? '/' : '';
+ $absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
+ list($storage, $internalPath) = Filesystem::resolvePath($absolutePath . $postFix);
+ if (!$internalPath || $internalPath === '' || $internalPath === '/') {
+ // do not allow deleting the storage's root / the mount point
+ // because for some storages it might delete the whole contents
+ // but isn't supposed to work that way
+ return false;
+ }
return $this->basicOperation('unlink', $path, array('delete'));
}