diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-04-13 15:46:30 +0200 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2022-04-13 15:46:30 +0200 |
commit | f5c8fa4f11b70d84c593c6102f3100a94310fa34 (patch) | |
tree | 4766d7e1d8708d612c13eb33d4b1408b6f262842 /lib/private | |
parent | cd95fce105fe5f0e71b1bcac7685464f936b9749 (diff) | |
download | nextcloud-server-f5c8fa4f11b70d84c593c6102f3100a94310fa34.tar.gz nextcloud-server-f5c8fa4f11b70d84c593c6102f3100a94310fa34.zip |
Properly reset pw expiration
When requesting a new password for share by mail link, now we correctly
reset the expiration date.
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Share20/Manager.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 4e87c37fedb..a5d876e8015 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1148,11 +1148,18 @@ class Manager implements IManager { // If a password is set. Hash it! if (!empty($share->getPassword())) { $share->setPassword($this->hasher->hash($share->getPassword())); + if ($share->getShareType() === IShare::TYPE_EMAIL) { + // Shares shared by email have temporary passwords + $this->setSharePasswordExpirationTime($share); + } return true; } else { // Empty string and null are seen as NOT password protected $share->setPassword(null); + if ($share->getShareType() === IShare::TYPE_EMAIL) { + $share->setPasswordExpirationTime(null); + } return true; } } else { @@ -1165,6 +1172,36 @@ class Manager implements IManager { } /** + * Set the share's password expiration time + */ + private function setSharePasswordExpirationTime(IShare $share): void { + if ($this->config->getSystemValue('allow_mail_share_permanent_password')) { + // Sets password expiration date to NULL + $share->setPasswordExpirationTime(); + return; + } + // Sets password expiration date + $expirationTime = null; + try { + $now = new \DateTime(); + $expirationInterval = $this->config->getSystemValue('share_temporary_password_expiration_interval'); + if ($expirationInterval === '' || is_null($expirationInterval)) { + $expirationInterval = 'P0DT15M'; + } + $expirationTime = $now->add(new \DateInterval($expirationInterval)); + } catch (\Exception $e) { + // Catches invalid format for system value 'share_temporary_password_expiration_interval' + \OC::$server->getLogger()->logException($e, [ + 'message' => 'The \'share_temporary_password_expiration_interval\' system setting does not respect the DateInterval::__construct() format. Setting it to \'P0DT15M\'' + ]); + $expirationTime = $now->add(new \DateInterval('P0DT15M')); + } finally { + $share->setPasswordExpirationTime($expirationTime); + } + } + + + /** * Delete all the children of this share * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in * |