diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-06 10:01:06 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-06 10:01:06 +0100 |
commit | bf941032a39047cc948af5887e43f664d05e1e40 (patch) | |
tree | 98a4402109c8754b14a389a50e6a526182529d43 /apps/user_ldap/lib | |
parent | f2b19333b902075b730d0fee7691a9709dd59e9d (diff) | |
parent | 253e4bcf6320a1994f2db2912f450a2d9a16a895 (diff) | |
download | nextcloud-server-bf941032a39047cc948af5887e43f664d05e1e40.tar.gz nextcloud-server-bf941032a39047cc948af5887e43f664d05e1e40.zip |
Merge pull request #20271 from owncloud/fix-18701
LDAP: attempt to connect to backup server again, if main server is no…
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/connection.php | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index f6b123babd0..3f3953bb28b 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -526,30 +526,41 @@ class Connection extends LDAPUtility { \OCP\Util::WARN); } } - if(!$this->configuration->ldapOverrideMainServer - && !$this->getFromCache('overrideMainServer')) { - $this->doConnect($this->configuration->ldapHost, - $this->configuration->ldapPort); - $bindStatus = $this->bind(); - $error = $this->ldap->isResource($this->ldapConnectionRes) ? - $this->ldap->errno($this->ldapConnectionRes) : -1; - } else { - $bindStatus = false; - $error = null; + + $bindStatus = false; + $error = null; + try { + if (!$this->configuration->ldapOverrideMainServer + && !$this->getFromCache('overrideMainServer') + ) { + $this->doConnect($this->configuration->ldapHost, + $this->configuration->ldapPort); + $bindStatus = $this->bind(); + $error = $this->ldap->isResource($this->ldapConnectionRes) ? + $this->ldap->errno($this->ldapConnectionRes) : -1; + } + if($bindStatus === true) { + return $bindStatus; + } + } catch (\OC\ServerNotAvailableException $e) { + if(trim($this->configuration->ldapBackupHost) === "") { + throw $e; + } } //if LDAP server is not reachable, try the Backup (Replica!) Server - if((!$bindStatus && ($error !== 0)) + if( $error !== 0 || $this->configuration->ldapOverrideMainServer - || $this->getFromCache('overrideMainServer')) { - $this->doConnect($this->configuration->ldapBackupHost, - $this->configuration->ldapBackupPort); - $bindStatus = $this->bind(); - if(!$bindStatus && $error === -1) { - //when bind to backup server succeeded and failed to main server, - //skip contacting him until next cache refresh - $this->writeToCache('overrideMainServer', true); - } + || $this->getFromCache('overrideMainServer')) + { + $this->doConnect($this->configuration->ldapBackupHost, + $this->configuration->ldapBackupPort); + $bindStatus = $this->bind(); + if($bindStatus && $error === -1) { + //when bind to backup server succeeded and failed to main server, + //skip contacting him until next cache refresh + $this->writeToCache('overrideMainServer', true); + } } return $bindStatus; } |