From 0c1e57075cbc8cbb9211b5c203811e85dfa48773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come.chilliet@fusiondirectory.org> Date: Thu, 21 Jan 2021 14:58:15 +0100 Subject: [PATCH] :sparkles: feat(locks) Ignore and delete locks older than session lifetime issue #6143 --- include/class_Lock.inc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/include/class_Lock.inc b/include/class_Lock.inc index 0e370eefc..4e3c06f1d 100644 --- a/include/class_Lock.inc +++ b/include/class_Lock.inc @@ -242,13 +242,23 @@ class Lock } $locks = []; + $sessionLifetime = $config->get_cfg_value('sessionLifetime', 1800); + if ($sessionLifetime > 0) { + $expirationDate = (new DateTime())->sub(new DateInterval('PT'.$sessionLifetime.'S')); + } while ($attrs = $ldap->fetch()) { - $locks[] = new Lock( - $attrs['dn'], - base64_decode($attrs['fdObjectDn'][0]), - $attrs['fdUserDn'][0], - LdapGeneralizedTime::fromString($attrs['fdLockTimestamp'][0]) - ); + $date = LdapGeneralizedTime::fromString($attrs['fdLockTimestamp'][0]); + if (isset($expirationDate) && ($date < $expirationDate)) { + /* Delete expired locks */ + $ldap->rmdir($attrs['dn']); + } else { + $locks[] = new Lock( + $attrs['dn'], + base64_decode($attrs['fdObjectDn'][0]), + $attrs['fdUserDn'][0], + $date + ); + } } if (!is_array($objects) && (count($locks) > 1)) { -- GitLab