LDAP: attempt to connect to backup server again, if main server is not available. Fixes #18701
This commit is contained in:
parent
5a25f1c2a0
commit
6b866fa917
|
@ -526,30 +526,41 @@ class Connection extends LDAPUtility {
|
||||||
\OCP\Util::WARN);
|
\OCP\Util::WARN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!$this->configuration->ldapOverrideMainServer
|
|
||||||
&& !$this->getFromCache('overrideMainServer')) {
|
$bindStatus = false;
|
||||||
$this->doConnect($this->configuration->ldapHost,
|
$error = null;
|
||||||
$this->configuration->ldapPort);
|
try {
|
||||||
$bindStatus = $this->bind();
|
if (!$this->configuration->ldapOverrideMainServer
|
||||||
$error = $this->ldap->isResource($this->ldapConnectionRes) ?
|
&& !$this->getFromCache('overrideMainServer')
|
||||||
$this->ldap->errno($this->ldapConnectionRes) : -1;
|
) {
|
||||||
} else {
|
$this->doConnect($this->configuration->ldapHost,
|
||||||
$bindStatus = false;
|
$this->configuration->ldapPort);
|
||||||
$error = null;
|
$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 LDAP server is not reachable, try the Backup (Replica!) Server
|
||||||
if((!$bindStatus && ($error !== 0))
|
if( $error !== 0
|
||||||
|| $this->configuration->ldapOverrideMainServer
|
|| $this->configuration->ldapOverrideMainServer
|
||||||
|| $this->getFromCache('overrideMainServer')) {
|
|| $this->getFromCache('overrideMainServer'))
|
||||||
$this->doConnect($this->configuration->ldapBackupHost,
|
{
|
||||||
$this->configuration->ldapBackupPort);
|
$this->doConnect($this->configuration->ldapBackupHost,
|
||||||
$bindStatus = $this->bind();
|
$this->configuration->ldapBackupPort);
|
||||||
if(!$bindStatus && $error === -1) {
|
$bindStatus = $this->bind();
|
||||||
//when bind to backup server succeeded and failed to main server,
|
if($bindStatus && $error === -1) {
|
||||||
//skip contacting him until next cache refresh
|
//when bind to backup server succeeded and failed to main server,
|
||||||
$this->writeToCache('overrideMainServer', true);
|
//skip contacting him until next cache refresh
|
||||||
}
|
$this->writeToCache('overrideMainServer', true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $bindStatus;
|
return $bindStatus;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue