diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-05-29 21:34:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-29 21:34:52 +0200 |
commit | c31b2d6ce15a71b681eabadcc4fce6d0f98f5cb2 (patch) | |
tree | bad9290390d58e8fcc5f94148cd8ee51f271c175 /lib | |
parent | bb107a1f6fa02fd81e2aee31332f6e65c678bfb0 (diff) | |
parent | b5ffa2ea3d3d38dcf68b1ba3cd65998621256512 (diff) | |
download | nextcloud-server-c31b2d6ce15a71b681eabadcc4fce6d0f98f5cb2.tar.gz nextcloud-server-c31b2d6ce15a71b681eabadcc4fce6d0f98f5cb2.zip |
Merge pull request #21152 from nextcloud/backport/21143/stable18
[stable18] Fix password changes in link and mail shares
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Share20/Manager.php | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 73860fd39f4..fead605eb03 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -972,8 +972,14 @@ class Manager implements IManager { } else if ($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); @@ -981,11 +987,9 @@ class Manager implements IManager { } } else if ($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()) { @@ -993,6 +997,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'); } } @@ -1079,8 +1085,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()); @@ -1090,6 +1102,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; |