From fb62ce2eede0731cbddd753cb13275dad51cfca6 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 17 Feb 2021 11:45:39 +0100 Subject: [PATCH] Fix reconnectAs() calls --- src/includes/class/class.LSldap.php | 29 +++++++++++++------------- src/includes/class/class.LSsession.php | 12 +++++++++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/includes/class/class.LSldap.php b/src/includes/class/class.LSldap.php index f23bd06d..abc77bb8 100644 --- a/src/includes/class/class.LSldap.php +++ b/src/includes/class/class.LSldap.php @@ -81,26 +81,27 @@ class LSldap extends LSlog_staticLoggerClass { * @param[in] $dn string Bind DN * @param[in] $pwd array Bind password * @param[in] $config array LDAP configuration array in format of Net_LDAP2 + * (optional, default: keep current) * * @retval boolean true if connected, false instead */ - public static function reconnectAs($dn,$pwd,$config) { + public static function reconnectAs($dn, $pwd, $config=null) { if ($config) { self :: setConfig($config); } - if (self :: $cnx) { - self :: $cnx -> done(); - } - $config=self :: $config; - $config['binddn']=$dn; - $config['bindpw']=$pwd; - self :: $cnx = Net_LDAP2::connect($config); - if (Net_LDAP2::isError(self :: $cnx)) { - LSerror :: addErrorCode('LSldap_01',self :: $cnx -> getMessage()); - self :: $cnx = NULL; - return; - } - return true; + if (self :: $cnx) { + self :: $cnx -> done(); + } + $config = self :: $config; + $config['binddn'] = $dn; + $config['bindpw'] = $pwd; + self :: $cnx = Net_LDAP2::connect($config); + if (Net_LDAP2::isError(self :: $cnx)) { + LSerror :: addErrorCode('LSldap_01', self :: $cnx -> getMessage()); + self :: $cnx = NULL; + return; + } + return true; } /** diff --git a/src/includes/class/class.LSsession.php b/src/includes/class/class.LSsession.php index 163269ec..b2d16171 100644 --- a/src/includes/class/class.LSsession.php +++ b/src/includes/class/class.LSsession.php @@ -786,7 +786,11 @@ class LSsession { self :: $userLDAPcreds = false; return; } - if (!LSldap :: reconnectAs(self :: $userLDAPcreds['dn'],self :: $userLDAPcreds['pwd'])) { + if (!LSldap :: reconnectAs( + self :: $userLDAPcreds['dn'], + self :: $userLDAPcreds['pwd'], + self :: $ldapServer['ldap_config'] + )) { LSerror :: addErrorCode('LSsession_15'); return; } @@ -1239,7 +1243,11 @@ class LSsession { return; } if (self :: $dn && isset(self :: $ldapServer['useUserCredentials']) && self :: $ldapServer['useUserCredentials']) { - LSldap :: reconnectAs(self :: $userLDAPcreds['dn'], self :: $userLDAPcreds['pwd'],self :: $ldapServer['ldap_config']); + LSldap :: reconnectAs( + self :: $userLDAPcreds['dn'], + self :: $userLDAPcreds['pwd'], + self :: $ldapServer['ldap_config'] + ); } else { LSldap :: connect(self :: $ldapServer['ldap_config']);