diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-12-04 10:33:52 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-12-04 10:33:52 +0100 |
commit | 254fc41f2dc29bfbfbb8570782e6f6977e817281 (patch) | |
tree | 9baa399ca85cde3a853dddc9d5e736f4b78133db | |
parent | 3808618ae9d100104e85f473649261f88b701134 (diff) | |
parent | e92a0ff0e466edee28a15dd1e8aa9adf99c3ae10 (diff) | |
download | nextcloud-server-254fc41f2dc29bfbfbb8570782e6f6977e817281.tar.gz nextcloud-server-254fc41f2dc29bfbfbb8570782e6f6977e817281.zip |
Merge pull request #20363 from owncloud/backport-20271-stable8
[backport] [stable8] LDAP: attempt to connect to backup server again, if main server is no…
-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 7f7225ff141..2e9e6e05efd 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -520,30 +520,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; } |