diff --git a/include/class_Lock.inc b/include/class_Lock.inc index 0e370eefcf7732b36bb2cce725b5a1f9fb5d4fb0..4e3c06f1d945099e3d1b9c76021ce46bdfbc882f 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)) {