summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-01-14 16:44:59 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-20 21:12:26 +0100
commite40d21673ea4dfc000ce81839e88a0e53ddd8baa (patch)
treecf49378b7a287a75700546f2b1f554c0e8d047d5
parent647d8ea5decad8140f9c280ae90039aa71c4eb93 (diff)
downloadnextcloud-server-e40d21673ea4dfc000ce81839e88a0e53ddd8baa.tar.gz
nextcloud-server-e40d21673ea4dfc000ce81839e88a0e53ddd8baa.zip
[Share 2.0] Add fetching link shares to share manager
-rw-r--r--lib/private/share20/defaultshareprovider.php35
-rw-r--r--lib/private/share20/ishareprovider.php8
-rw-r--r--lib/private/share20/manager.php40
3 files changed, 71 insertions, 12 deletions
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index a5afe9ff06b..d47919d21a3 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -284,7 +284,11 @@ class DefaultShareProvider implements IShareProvider {
throw new ShareNotFound();
}
- $share = $this->createShare($data);
+ try {
+ $share = $this->createShare($data);
+ } catch (InvalidShare $e) {
+ throw new ShareNotFound();
+ }
return $share;
}
@@ -328,13 +332,34 @@ class DefaultShareProvider implements IShareProvider {
}
/**
- * Get a share by token and if present verify the password
+ * Get a share by token
*
* @param string $token
- * @param string $password
- * @param Share
+ * @return IShare
+ * @throws ShareNotFound
*/
- public function getShareByToken($token, $password = null) {
+ public function getShareByToken($token) {
+ $qb = $this->dbConn->getQueryBuilder();
+
+ $cursor = $qb->select('*')
+ ->from('share')
+ ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
+ ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
+ ->execute();
+
+ $data = $cursor->fetch();
+
+ if ($data === false) {
+ throw new ShareNotFound();
+ }
+
+ try {
+ $share = $this->createShare($data);
+ } catch (InvalidShare $e) {
+ throw new ShareNotFound();
+ }
+
+ return $share;
}
/**
diff --git a/lib/private/share20/ishareprovider.php b/lib/private/share20/ishareprovider.php
index d1f82557a5f..81770a45874 100644
--- a/lib/private/share20/ishareprovider.php
+++ b/lib/private/share20/ishareprovider.php
@@ -103,11 +103,11 @@ interface IShareProvider {
public function getSharedWithMe(IUser $user, $shareType = null);
/**
- * Get a share by token and if present verify the password
+ * Get a share by token
*
* @param string $token
- * @param string $password
- * @param Share
+ * @return IShare
+ * @throws ShareNotFound
*/
- public function getShareByToken($token, $password = null);
+ public function getShareByToken($token);
}
diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php
index 035026b47ea..2be8fb5174d 100644
--- a/lib/private/share20/manager.php
+++ b/lib/private/share20/manager.php
@@ -665,13 +665,47 @@ class Manager {
* Get the share by token possible with password
*
* @param string $token
- * @param string $password
- *
* @return Share
*
* @throws ShareNotFound
*/
- public function getShareByToken($token, $password=null) {
+ public function getShareByToken($token) {
+ $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_LINK);
+
+ $share = $provider->getShareByToken($token);
+
+ //TODO check if share expired
+
+ return $share;
+ }
+
+ /**
+ * Verify the password of a public share
+ *
+ * @param IShare $share
+ * @param string $password
+ * @return bool
+ */
+ public function checkPassword(IShare $share, $password) {
+ if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK) {
+ //TODO maybe exception?
+ return false;
+ }
+
+ if ($password === null || $share->getPassword() === null) {
+ return false;
+ }
+
+ $newHash = '';
+ if (!$this->hasher->verify($password, $share->getPassword(), $newHash)) {
+ return false;
+ }
+
+ if (!empty($newHash)) {
+ //TODO update hash!
+ }
+
+ return true;
}
/**