summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/CalDAV/Calendar.php2
-rw-r--r--apps/dav/lib/CardDAV/AddressBook.php2
-rw-r--r--apps/dav/lib/Command/RemoveInvalidShares.php82
-rw-r--r--apps/dav/lib/Connector/Sabre/Principal.php7
-rw-r--r--apps/dav/lib/DAV/Sharing/Backend.php12
-rw-r--r--apps/dav/lib/Server.php48
6 files changed, 131 insertions, 22 deletions
diff --git a/apps/dav/lib/CalDAV/Calendar.php b/apps/dav/lib/CalDAV/Calendar.php
index 02808ab5662..a07bbe93218 100644
--- a/apps/dav/lib/CalDAV/Calendar.php
+++ b/apps/dav/lib/CalDAV/Calendar.php
@@ -203,7 +203,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
}
$this->caldavBackend->updateShares($this, [], [
- 'href' => $principal
+ $principal
]);
return;
}
diff --git a/apps/dav/lib/CardDAV/AddressBook.php b/apps/dav/lib/CardDAV/AddressBook.php
index a034f8b9426..71202319874 100644
--- a/apps/dav/lib/CardDAV/AddressBook.php
+++ b/apps/dav/lib/CardDAV/AddressBook.php
@@ -181,7 +181,7 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable {
}
$this->carddavBackend->updateShares($this, [], [
- 'href' => $principal
+ $principal
]);
return;
}
diff --git a/apps/dav/lib/Command/RemoveInvalidShares.php b/apps/dav/lib/Command/RemoveInvalidShares.php
new file mode 100644
index 00000000000..12a5ee43d47
--- /dev/null
+++ b/apps/dav/lib/Command/RemoveInvalidShares.php
@@ -0,0 +1,82 @@
+<?php
+declare(strict_types=1);
+/**
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @copyright Copyright (c) 2018, ownCloud GmbH
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\DAV\Command;
+
+use OCA\DAV\Connector\Sabre\Principal;
+use OCP\IDBConnection;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class RemoveInvalidShares - removes shared calendars and addressbook which
+ * have no matching principal. Happened because of a bug in the calendar app.
+ */
+class RemoveInvalidShares extends Command {
+
+ /** @var IDBConnection */
+ private $connection;
+ /** @var Principal */
+ private $principalBackend;
+
+ public function __construct(IDBConnection $connection,
+ Principal $principalBackend) {
+ parent::__construct();
+
+ $this->connection = $connection;
+ $this->principalBackend = $principalBackend;
+ }
+
+ protected function configure() {
+ $this
+ ->setName('dav:remove-invalid-shares')
+ ->setDescription('Remove invalid dav shares');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $query = $this->connection->getQueryBuilder();
+ $result = $query->selectDistinct('principaluri')
+ ->from('dav_shares')
+ ->execute();
+
+ while($row = $result->fetch()) {
+ $principaluri = $row['principaluri'];
+ $p = $this->principalBackend->getPrincipalByPath($principaluri);
+ if ($p === null) {
+ $this->deleteSharesForPrincipal($principaluri);
+ }
+ }
+
+ $result->closeCursor();
+ }
+
+ /**
+ * @param string $principaluri
+ */
+ private function deleteSharesForPrincipal($principaluri) {
+ $delete = $this->connection->getQueryBuilder();
+ $delete->delete('dav_shares')
+ ->where($delete->expr()->eq('principaluri', $delete->createNamedParameter($principaluri)));
+ $delete->execute();
+ }
+}
diff --git a/apps/dav/lib/Connector/Sabre/Principal.php b/apps/dav/lib/Connector/Sabre/Principal.php
index b2f57cf715c..b94b093ab50 100644
--- a/apps/dav/lib/Connector/Sabre/Principal.php
+++ b/apps/dav/lib/Connector/Sabre/Principal.php
@@ -324,6 +324,13 @@ class Principal implements BackendInterface {
return $this->principalPrefix . '/' . $user->getUID();
}
}
+ if (substr($uri, 0, 10) === 'principal:') {
+ $principal = substr($uri, 10);
+ $principal = $this->getPrincipalByPath($principal);
+ if ($principal !== null) {
+ return $principal['uri'];
+ }
+ }
return null;
}
diff --git a/apps/dav/lib/DAV/Sharing/Backend.php b/apps/dav/lib/DAV/Sharing/Backend.php
index 87c094c6d62..433d9db9c08 100644
--- a/apps/dav/lib/DAV/Sharing/Backend.php
+++ b/apps/dav/lib/DAV/Sharing/Backend.php
@@ -67,12 +67,18 @@ class Backend {
* @param string[] $add
* @param string[] $remove
*/
- public function updateShares($shareable, $add, $remove) {
+ public function updateShares(IShareable $shareable, array $add, array $remove) {
foreach($add as $element) {
- $this->shareWith($shareable, $element);
+ $principal = $this->principalBackend->findByUri($element['href'], '');
+ if ($principal !== '') {
+ $this->shareWith($shareable, $element);
+ }
}
foreach($remove as $element) {
- $this->unshare($shareable, $element);
+ $principal = $this->principalBackend->findByUri($element, '');
+ if ($principal !== '') {
+ $this->unshare($shareable, $element);
+ }
}
}
diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php
index 7fbd7671e8d..82978711156 100644
--- a/apps/dav/lib/Server.php
+++ b/apps/dav/lib/Server.php
@@ -71,14 +71,13 @@ class Server {
private $baseUri;
/** @var Connector\Sabre\Server */
- private $server;
+ public $server;
public function __construct(IRequest $request, $baseUri) {
$this->request = $request;
$this->baseUri = $baseUri;
$logger = \OC::$server->getLogger();
$dispatcher = \OC::$server->getEventDispatcher();
- $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes';
$root = new RootCollection();
$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
@@ -137,24 +136,29 @@ class Server {
$this->server->addPlugin($acl);
// calendar plugins
- $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
- $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
- $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
- if ($sendInvitations) {
- $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
+ if ($this->requestIsForSubtree(['calendars', 'principals'])) {
+ $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
+ $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
+ $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin());
+ if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
+ $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class));
+ }
+ $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
+ $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
+ $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
+ $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
+ \OC::$server->getConfig(),
+ \OC::$server->getURLGenerator()
+ ));
}
- $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
- $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
- $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
- $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin(
- \OC::$server->getConfig(),
- \OC::$server->getURLGenerator()
- ));
// addressbook plugins
- $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
- $this->server->addPlugin(new VCFExportPlugin());
- $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
+ if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
+ $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
+ $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
+ $this->server->addPlugin(new VCFExportPlugin());
+ $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
+ }
// system tags plugins
$this->server->addPlugin(new SystemTagPlugin(
@@ -280,4 +284,14 @@ class Server {
public function exec() {
$this->server->exec();
}
+
+ private function requestIsForSubtree(array $subTrees): bool {
+ foreach ($subTrees as $subTree) {
+ $subTree = trim($subTree, ' /');
+ if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) {
+ return true;
+ }
+ }
+ return false;
+ }
}