From 0fc6bf9e3b21df18dc1a51cdca0d6932202dcad4 Mon Sep 17 00:00:00 2001 From: David Coutadeur Date: Wed, 16 Oct 2024 17:48:13 +0200 Subject: [PATCH] add disabling account function (#44) --- src/Ltb/Directory/OpenLDAP.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Ltb/Directory/OpenLDAP.php b/src/Ltb/Directory/OpenLDAP.php index 64d3dbe..ae5f64d 100644 --- a/src/Ltb/Directory/OpenLDAP.php +++ b/src/Ltb/Directory/OpenLDAP.php @@ -226,7 +226,7 @@ public function enableAccount($ldap, $dn) : bool { $update = \Ltb\PhpLDAP::ldap_mod_replace($ldap, $dn, $attrsToDelete); $errno = \Ltb\PhpLDAP::ldap_errno($ldap); - + if ($errno) { error_log("LDAP - Enabling account error $errno (".\Ltb\PhpLDAP::ldap_error($ldap).")"); return false; @@ -237,8 +237,23 @@ public function enableAccount($ldap, $dn) : bool { } public function disableAccount($ldap, $dn) : bool { - // Not implemented + + # Date of disabling + $currentDate = gmdate("YmdHis")."Z"; + + $attrs = array( 'pwdAccountDisabled' => array($currentDate) ); + + $update = \Ltb\PhpLDAP::ldap_mod_replace($ldap, $dn, $attrs); + $errno = \Ltb\PhpLDAP::ldap_errno($ldap); + + if ($errno) { + error_log("LDAP - Disabling account error $errno (".\Ltb\PhpLDAP::ldap_error($ldap).")"); + return false; + } else { + return true; + } return false; + } public function isAccountEnabled($ldap, $dn) : bool {