summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-05-29 13:36:09 +0200
committerGitHub <noreply@github.com>2020-05-29 13:36:09 +0200
commit251a4d30978383fdac355cfd5623a58b74b68768 (patch)
treeee8983dd8aefaf4c294216df296f075203bf7ba4 /lib
parentefd025cbc34db9468822954052c7452c5a4e48ba (diff)
parentb192c04dc22e54e4fab7a70331ec605068b4a4e4 (diff)
downloadnextcloud-server-251a4d30978383fdac355cfd5623a58b74b68768.tar.gz
nextcloud-server-251a4d30978383fdac355cfd5623a58b74b68768.zip
Merge pull request #21143 from nextcloud/fix-password-changes-in-link-and-mail-shares
Fix password changes in link and mail shares
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Share20/Manager.php26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 36cbd511b8d..86b34a4b9f0 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -968,8 +968,14 @@ class Manager implements IManager {
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
$this->linkCreateChecks($share);
+ $plainTextPassword = $share->getPassword();
+
$this->updateSharePasswordIfNeeded($share, $originalShare);
+ if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) {
+ throw new \InvalidArgumentException('Can’t enable sending the password by Talk with an empty password');
+ }
+
if ($share->getExpirationDate() != $originalShare->getExpirationDate()) {
//Verify the expiration date
$this->validateExpirationDate($share);
@@ -977,11 +983,9 @@ class Manager implements IManager {
}
} elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
// The new password is not set again if it is the same as the old
- // one, unless when switching from sending by Talk to sending by
- // mail.
+ // one.
$plainTextPassword = $share->getPassword();
- if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare) &&
- !($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk())) {
+ if (!empty($plainTextPassword) && !$this->updateSharePasswordIfNeeded($share, $originalShare)) {
$plainTextPassword = null;
}
if (empty($plainTextPassword) && !$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) {
@@ -989,6 +993,8 @@ class Manager implements IManager {
// would already have access to the share without having to call
// the sharer to verify her identity
throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password');
+ } elseif (empty($plainTextPassword) && $originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) {
+ throw new \InvalidArgumentException('Can’t disable sending the password by Talk without setting a new password');
}
}
@@ -1075,8 +1081,14 @@ class Manager implements IManager {
* @return boolean whether the password was updated or not.
*/
private function updateSharePasswordIfNeeded(\OCP\Share\IShare $share, \OCP\Share\IShare $originalShare) {
+ $passwordsAreDifferent = ($share->getPassword() !== $originalShare->getPassword()) &&
+ (($share->getPassword() !== null && $originalShare->getPassword() === null) ||
+ ($share->getPassword() === null && $originalShare->getPassword() !== null) ||
+ ($share->getPassword() !== null && $originalShare->getPassword() !== null &&
+ !$this->hasher->verify($share->getPassword(), $originalShare->getPassword())));
+
// Password updated.
- if ($share->getPassword() !== $originalShare->getPassword()) {
+ if ($passwordsAreDifferent) {
//Verify the password
$this->verifyPassword($share->getPassword());
@@ -1086,6 +1098,10 @@ class Manager implements IManager {
return true;
}
+ } else {
+ // Reset the password to the original one, as it is either the same
+ // as the "new" password or a hashed version of it.
+ $share->setPassword($originalShare->getPassword());
}
return false;