summaryrefslogtreecommitdiffstats
path: root/lib/private/connector
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/connector')
-rw-r--r--lib/private/connector/sabre/directory.php17
-rw-r--r--lib/private/connector/sabre/file.php6
-rw-r--r--lib/private/connector/sabre/filesplugin.php73
-rw-r--r--lib/private/connector/sabre/node.php23
4 files changed, 114 insertions, 5 deletions
diff --git a/lib/private/connector/sabre/directory.php b/lib/private/connector/sabre/directory.php
index c51f84bf67c..02d1a9f4ba2 100644
--- a/lib/private/connector/sabre/directory.php
+++ b/lib/private/connector/sabre/directory.php
@@ -50,6 +50,10 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
*/
public function createFile($name, $data = null) {
+ if ($name === 'Shared' && empty($this->path)) {
+ throw new \Sabre_DAV_Exception_Forbidden();
+ }
+
// for chunked upload also updating a existing file is a "createFile"
// because we create all the chunks before reasamble them to the existing file.
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
@@ -82,6 +86,10 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
*/
public function createDirectory($name) {
+ if ($name === 'Shared' && empty($this->path)) {
+ throw new \Sabre_DAV_Exception_Forbidden();
+ }
+
if (!\OC\Files\Filesystem::isCreatable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
@@ -187,13 +195,16 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
*/
public function delete() {
- if (!\OC\Files\Filesystem::isDeletable($this->path)) {
+ if ($this->path === 'Shared') {
throw new \Sabre_DAV_Exception_Forbidden();
}
- if ($this->path != "/Shared") {
- \OC\Files\Filesystem::rmdir($this->path);
+
+ if (!\OC\Files\Filesystem::isDeletable($this->path)) {
+ throw new \Sabre_DAV_Exception_Forbidden();
}
+ \OC\Files\Filesystem::rmdir($this->path);
+
}
/**
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 6ace8d14484..919bb1fc6f4 100644
--- a/lib/private/connector/sabre/file.php
+++ b/lib/private/connector/sabre/file.php
@@ -143,6 +143,10 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
*/
public function delete() {
+ if ($this->path === 'Shared') {
+ throw new \Sabre_DAV_Exception_Forbidden();
+ }
+
if (!\OC\Files\Filesystem::isDeletable($this->path)) {
throw new \Sabre_DAV_Exception_Forbidden();
}
@@ -218,7 +222,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
if (isset($_SERVER['CONTENT_LENGTH'])) {
$expected = $_SERVER['CONTENT_LENGTH'];
if ($bytesWritten != $expected) {
- $chunk_handler->cleanup();
+ $chunk_handler->remove($info['index']);
throw new Sabre_DAV_Exception_BadRequest(
'expected filesize ' . $expected . ' got ' . $bytesWritten);
}
diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php
new file mode 100644
index 00000000000..ac781825672
--- /dev/null
+++ b/lib/private/connector/sabre/filesplugin.php
@@ -0,0 +1,73 @@
+<?php
+
+/**
+ * ownCloud
+ *
+ * @author Thomas Müller
+ * @copyright 2013 Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @license AGPL3
+ */
+
+class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin
+{
+
+ // namespace
+ const NS_OWNCLOUD = 'http://owncloud.org/ns';
+
+ /**
+ * Reference to main server object
+ *
+ * @var Sabre_DAV_Server
+ */
+ private $server;
+
+ /**
+ * This initializes the plugin.
+ *
+ * This function is called by Sabre_DAV_Server, after
+ * addPlugin is called.
+ *
+ * This method should set up the required event subscriptions.
+ *
+ * @param Sabre_DAV_Server $server
+ * @return void
+ */
+ public function initialize(Sabre_DAV_Server $server) {
+
+ $server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc';
+ $server->protectedProperties[] = '{' . self::NS_OWNCLOUD . '}id';
+
+ $this->server = $server;
+ $this->server->subscribeEvent('beforeGetProperties', array($this, 'beforeGetProperties'));
+ }
+
+ /**
+ * Adds all ownCloud-specific properties
+ *
+ * @param string $path
+ * @param Sabre_DAV_INode $node
+ * @param array $requestedProperties
+ * @param array $returnedProperties
+ * @return void
+ */
+ public function beforeGetProperties($path, Sabre_DAV_INode $node, array &$requestedProperties, array &$returnedProperties) {
+
+ if ($node instanceof OC_Connector_Sabre_Node) {
+
+ $fileid_propertyname = '{' . self::NS_OWNCLOUD . '}id';
+ if (array_search($fileid_propertyname, $requestedProperties)) {
+ unset($requestedProperties[array_search($fileid_propertyname, $requestedProperties)]);
+ }
+
+ /** @var $node OC_Connector_Sabre_Node */
+ $fileId = $node->getFileId();
+ if (!is_null($fileId)) {
+ $returnedProperties[200][$fileid_propertyname] = $fileId;
+ }
+
+ }
+
+ }
+
+}
diff --git a/lib/private/connector/sabre/node.php b/lib/private/connector/sabre/node.php
index 3c2ad60f1dd..76fbc251100 100644
--- a/lib/private/connector/sabre/node.php
+++ b/lib/private/connector/sabre/node.php
@@ -45,6 +45,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
* @var string
*/
protected $path;
+
/**
* node fileinfo cache
* @var array
@@ -211,6 +212,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
* properties should be returned
*/
public function getProperties($properties) {
+
if (is_null($this->property_cache)) {
$sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?';
$result = OC_DB::executeAudited( $sql, array( OC_User::getUser(), $this->path ) );
@@ -236,8 +238,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
$props = array();
foreach($properties as $property) {
- if (isset($this->property_cache[$property])) $props[$property] = $this->property_cache[$property];
+ if (isset($this->property_cache[$property])) {
+ $props[$property] = $this->property_cache[$property];
+ }
}
+
return $props;
}
@@ -260,4 +265,20 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
}
return $this->fileView;
}
+
+ /**
+ * @return mixed
+ */
+ public function getFileId()
+ {
+ $this->getFileinfoCache();
+
+ if (isset($this->fileinfo_cache['fileid'])) {
+ $instanceId = OC_Util::getInstanceId();
+ $id = sprintf('%08d', $this->fileinfo_cache['fileid']);
+ return $instanceId . $id;
+ }
+
+ return null;
+ }
}