From 4e2e592635af27c2a8665837769ea8e55acc091f Mon Sep 17 00:00:00 2001 From: Jarkko Lehtoranta Date: Tue, 13 Jun 2017 21:08:14 +0300 Subject: LDAP: Connect to backup server only if it exists + handle errors Signed-off-by: Jarkko Lehtoranta --- apps/user_ldap/lib/Connection.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'apps') diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index 10fbea7174b..d0cf87299aa 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -550,19 +550,23 @@ class Connection extends LDAPUtility { } //if LDAP server is not reachable, try the Backup (Replica!) Server - if( $error !== 0 + if( trim($this->configuration->ldapBackupHost) !== "" + && ($error !== 0 || $this->configuration->ldapOverrideMainServer || $this->getFromCache('overrideMainServer')) - { + ) { $this->doConnect($this->configuration->ldapBackupHost, $this->configuration->ldapBackupPort); $bindStatus = $this->bind(); - if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { + $error = $this->ldap->isResource($this->ldapConnectionRes) ? + $this->ldap->errno($this->ldapConnectionRes) : -1; + if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) { //when bind to backup server succeeded and failed to main server, //skip contacting him until next cache refresh $this->writeToCache('overrideMainServer', true); } } + return $bindStatus; } return null; -- cgit v1.2.3