diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-12-19 12:23:13 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2022-12-19 14:15:48 +0100 |
commit | 6b7ffcd6a8ee5c451c33ddd34ec11f45e9632c84 (patch) | |
tree | 85070149e079651254e60bd682c08b7355a7d832 /apps/user_ldap/lib | |
parent | 406750552e1332f4419cd0c8b77891c1e8b4aee1 (diff) | |
download | nextcloud-server-6b7ffcd6a8ee5c451c33ddd34ec11f45e9632c84.tar.gz nextcloud-server-6b7ffcd6a8ee5c451c33ddd34ec11f45e9632c84.zip |
Fixed backup host logic
Now forcing backup host applies to both main and background.
And background will fallback to backup if not responding.
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/Connection.php | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index 1cde3bc3960..95ddd3fc51c 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -598,25 +598,26 @@ class Connection extends LDAPUtility { } } - $forceBackupHost = ($this->configuration->ldapOverrideMainServer || $this->getFromCache('overrideMainServer')); $hasBackupHost = (trim($this->configuration->ldapBackupHost ?? '') !== ''); $hasBackgroundHost = (trim($this->configuration->ldapBackgroundHost ?? '') !== ''); - $useBackupHost = $hasBackupHost && (!\OC::$CLI || !$hasBackgroundHost); + $useBackgroundHost = (\OC::$CLI && $hasBackgroundHost); + $overrideCacheKey = ($useBackgroundHost ? 'overrideBackgroundServer' : 'overrideMainServer'); + $forceBackupHost = ($this->configuration->ldapOverrideMainServer || $this->getFromCache($overrideCacheKey)); $bindStatus = false; - try { - if (!$forceBackupHost) { - $host = $this->configuration->ldapHost; - $port = $this->configuration->ldapPort; - if (\OC::$CLI && $hasBackgroundHost) { - $host = $this->configuration->ldapBackgroundHost; - $port = $this->configuration->ldapBackgroundPort; + if (!$forceBackupHost) { + try { + $host = $this->configuration->ldapHost ?? ''; + $port = $this->configuration->ldapPort ?? ''; + if ($useBackgroundHost) { + $host = $this->configuration->ldapBackgroundHost ?? ''; + $port = $this->configuration->ldapBackgroundPort ?? ''; } $this->doConnect($host, $port); return $this->bind(); - } - } catch (ServerNotAvailableException $e) { - if (!$useBackupHost) { - throw $e; + } catch (ServerNotAvailableException $e) { + if (!$hasBackupHost) { + throw $e; + } } $this->logger->warning( 'Main LDAP not reachable, connecting to backup', @@ -626,19 +627,16 @@ class Connection extends LDAPUtility { ); } - //if LDAP server is not reachable, try the Backup (Replica!) Server - if ($useBackupHost || $forceBackupHost) { - $this->doConnect($this->configuration->ldapBackupHost, - $this->configuration->ldapBackupPort); - $this->bindResult = []; - $bindStatus = $this->bind(); - $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); - } + // if LDAP server is not reachable, try the Backup (Replica!) Server + $this->doConnect($this->configuration->ldapBackupHost ?? '', $this->configuration->ldapBackupPort ?? ''); + $this->bindResult = []; + $bindStatus = $this->bind(); + $error = $this->ldap->isResource($this->ldapConnectionRes) ? + $this->ldap->errno($this->ldapConnectionRes) : -1; + if ($bindStatus && $error === 0 && !$forceBackupHost) { + //when bind to backup server succeeded and failed to main server, + //skip contacting him until next cache refresh + $this->writeToCache($overrideCacheKey, true); } return $bindStatus; |