Fix reconnectAs() calls

This commit is contained in:
Benjamin Renard 2021-02-17 11:45:39 +01:00
parent d27a59f807
commit fb62ce2eed
2 changed files with 25 additions and 16 deletions

View file

@ -81,26 +81,27 @@ class LSldap extends LSlog_staticLoggerClass {
* @param[in] $dn string Bind DN * @param[in] $dn string Bind DN
* @param[in] $pwd array Bind password * @param[in] $pwd array Bind password
* @param[in] $config array LDAP configuration array in format of Net_LDAP2 * @param[in] $config array LDAP configuration array in format of Net_LDAP2
* (optional, default: keep current)
* *
* @retval boolean true if connected, false instead * @retval boolean true if connected, false instead
*/ */
public static function reconnectAs($dn,$pwd,$config) { public static function reconnectAs($dn, $pwd, $config=null) {
if ($config) { if ($config) {
self :: setConfig($config); self :: setConfig($config);
} }
if (self :: $cnx) { if (self :: $cnx) {
self :: $cnx -> done(); self :: $cnx -> done();
} }
$config=self :: $config; $config = self :: $config;
$config['binddn']=$dn; $config['binddn'] = $dn;
$config['bindpw']=$pwd; $config['bindpw'] = $pwd;
self :: $cnx = Net_LDAP2::connect($config); self :: $cnx = Net_LDAP2::connect($config);
if (Net_LDAP2::isError(self :: $cnx)) { if (Net_LDAP2::isError(self :: $cnx)) {
LSerror :: addErrorCode('LSldap_01',self :: $cnx -> getMessage()); LSerror :: addErrorCode('LSldap_01', self :: $cnx -> getMessage());
self :: $cnx = NULL; self :: $cnx = NULL;
return; return;
} }
return true; return true;
} }
/** /**

View file

@ -786,7 +786,11 @@ class LSsession {
self :: $userLDAPcreds = false; self :: $userLDAPcreds = false;
return; 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'); LSerror :: addErrorCode('LSsession_15');
return; return;
} }
@ -1239,7 +1243,11 @@ class LSsession {
return; return;
} }
if (self :: $dn && isset(self :: $ldapServer['useUserCredentials']) && self :: $ldapServer['useUserCredentials']) { 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 { else {
LSldap :: connect(self :: $ldapServer['ldap_config']); LSldap :: connect(self :: $ldapServer['ldap_config']);