Skip to content
Snippets Groups Projects
Commit 3bedb097 authored by Thomas Müller's avatar Thomas Müller
Browse files

Merge pull request #3843 from owncloud/sabre-exceptions

Sabre: throw exceptions when delete/create/write operations are not permitted
parents 6ddfe202 62087803
Branches
No related tags found
No related merge requests found
...@@ -45,9 +45,15 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa ...@@ -45,9 +45,15 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
* *
* @param string $name Name of the file * @param string $name Name of the file
* @param resource|string $data Initial payload * @param resource|string $data Initial payload
* @throws Sabre_DAV_Exception_Forbidden
* @return null|string * @return null|string
*/ */
public function createFile($name, $data = null) { public function createFile($name, $data = null) {
if (!\OC\Files\Filesystem::isCreatable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
if (isset($_SERVER['HTTP_OC_CHUNKED'])) { if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
$info = OC_FileChunking::decodeName($name); $info = OC_FileChunking::decodeName($name);
if (empty($info)) { if (empty($info)) {
...@@ -102,10 +108,15 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa ...@@ -102,10 +108,15 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
* Creates a new subdirectory * Creates a new subdirectory
* *
* @param string $name * @param string $name
* @throws Sabre_DAV_Exception_Forbidden
* @return void * @return void
*/ */
public function createDirectory($name) { public function createDirectory($name) {
if (!\OC\Files\Filesystem::isCreatable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
$newPath = $this->path . '/' . $name; $newPath = $this->path . '/' . $name;
if(!\OC\Files\Filesystem::mkdir($newPath)) { if(!\OC\Files\Filesystem::mkdir($newPath)) {
throw new Sabre_DAV_Exception_Forbidden('Could not create directory '.$newPath); throw new Sabre_DAV_Exception_Forbidden('Could not create directory '.$newPath);
...@@ -203,9 +214,13 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa ...@@ -203,9 +214,13 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
* Deletes all files in this directory, and then itself * Deletes all files in this directory, and then itself
* *
* @return void * @return void
* @throws Sabre_DAV_Exception_Forbidden
*/ */
public function delete() { public function delete() {
if (!\OC\Files\Filesystem::isDeletable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
if ($this->path != "/Shared") { if ($this->path != "/Shared") {
foreach($this->getChildren() as $child) $child->delete(); foreach($this->getChildren() as $child) $child->delete();
\OC\Files\Filesystem::rmdir($this->path); \OC\Files\Filesystem::rmdir($this->path);
......
...@@ -41,10 +41,15 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D ...@@ -41,10 +41,15 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
* return an ETag, and just return null. * return an ETag, and just return null.
* *
* @param resource $data * @param resource $data
* @throws Sabre_DAV_Exception_Forbidden
* @return string|null * @return string|null
*/ */
public function put($data) { public function put($data) {
if (!\OC\Files\Filesystem::isUpdatable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
// mark file as partial while uploading (ignored by the scanner) // mark file as partial while uploading (ignored by the scanner)
$partpath = $this->path . '.part'; $partpath = $this->path . '.part';
...@@ -92,9 +97,13 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D ...@@ -92,9 +97,13 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
* Delete the current file * Delete the current file
* *
* @return void * @return void
* @throws Sabre_DAV_Exception_Forbidden
*/ */
public function delete() { public function delete() {
if (!\OC\Files\Filesystem::isDeletable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
\OC\Files\Filesystem::unlink($this->path); \OC\Files\Filesystem::unlink($this->path);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment