Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sabre: throw exceptions when delete/create/write operations are not permitted #3843

Merged
merged 1 commit into from
Jun 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/connector/sabre/directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
*
* @param string $name Name of the file
* @param resource|string $data Initial payload
* @throws Sabre_DAV_Exception_Forbidden
* @return null|string
*/
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'])) {
$info = OC_FileChunking::decodeName($name);
if (empty($info)) {
Expand Down Expand Up @@ -102,10 +108,15 @@ public function createFile($name, $data = null) {
* Creates a new subdirectory
*
* @param string $name
* @throws Sabre_DAV_Exception_Forbidden
* @return void
*/
public function createDirectory($name) {

if (!\OC\Files\Filesystem::isCreatable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}

$newPath = $this->path . '/' . $name;
if(!\OC\Files\Filesystem::mkdir($newPath)) {
throw new Sabre_DAV_Exception_Forbidden('Could not create directory '.$newPath);
Expand Down Expand Up @@ -203,9 +214,13 @@ public function childExists($name) {
* Deletes all files in this directory, and then itself
*
* @return void
* @throws Sabre_DAV_Exception_Forbidden
*/
public function delete() {

if (!\OC\Files\Filesystem::isDeletable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
if ($this->path != "/Shared") {
foreach($this->getChildren() as $child) $child->delete();
\OC\Files\Filesystem::rmdir($this->path);
Expand Down
15 changes: 12 additions & 3 deletions lib/connector/sabre/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,29 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
* return an ETag, and just return null.
*
* @param resource $data
* @throws Sabre_DAV_Exception_Forbidden
* @return string|null
*/
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)
$partpath = $this->path . '.part';

\OC\Files\Filesystem::file_put_contents($partpath, $data);

//detect aborted upload
if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
if (isset($_SERVER['CONTENT_LENGTH'])) {
$expected = $_SERVER['CONTENT_LENGTH'];
$actual = \OC\Files\Filesystem::filesize($partpath);
if ($actual != $expected) {
\OC\Files\Filesystem::unlink($partpath);
throw new Sabre_DAV_Exception_BadRequest(
'expected filesize ' . $expected . ' got ' . $actual);
'expected filesize ' . $expected . ' got ' . $actual);
}
}
}
Expand All @@ -69,7 +74,7 @@ public function put($data) {
//allow sync clients to send the mtime along in a header
$mtime = OC_Request::hasModificationTime();
if ($mtime !== false) {
if(\OC\Files\Filesystem::touch($this->path, $mtime)) {
if (\OC\Files\Filesystem::touch($this->path, $mtime)) {
header('X-OC-MTime: accepted');
}
}
Expand All @@ -92,9 +97,13 @@ public function get() {
* Delete the current file
*
* @return void
* @throws Sabre_DAV_Exception_Forbidden
*/
public function delete() {

if (!\OC\Files\Filesystem::isDeletable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
\OC\Files\Filesystem::unlink($this->path);

}
Expand Down