Use a dedicated LDAP host and port for background jobs if configured

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2022-11-17 14:55:55 +01:00
parent 75e369d306
commit 4758bdc476
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A
2 changed files with 18 additions and 6 deletions

View file

@ -68,6 +68,8 @@ class Configuration {
'ldapPort' => null,
'ldapBackupHost' => null,
'ldapBackupPort' => null,
'ldapBackgroundHost' => null,
'ldapBackgroundPort' => null,
'ldapBase' => null,
'ldapBaseUsers' => null,
'ldapBaseGroups' => null,
@ -278,7 +280,7 @@ class Configuration {
$value = implode("\n", $value);
}
break;
//following options are not stored but detected, skip them
//following options are not stored but detected, skip them
case 'ldapIgnoreNamingRules':
case 'ldapUuidUserAttribute':
case 'ldapUuidGroupAttribute':
@ -367,8 +369,8 @@ class Configuration {
$defaults = $this->getDefaults();
}
return \OC::$server->getConfig()->getAppValue('user_ldap',
$this->configPrefix.$varName,
$defaults[$varName]);
$this->configPrefix.$varName,
$defaults[$varName]);
}
/**
@ -413,6 +415,8 @@ class Configuration {
'ldap_port' => '',
'ldap_backup_host' => '',
'ldap_backup_port' => '',
'ldap_background_host' => '',
'ldap_background_port' => '',
'ldap_override_main_server' => '',
'ldap_dn' => '',
'ldap_agent_password' => '',
@ -478,6 +482,8 @@ class Configuration {
'ldap_port' => 'ldapPort',
'ldap_backup_host' => 'ldapBackupHost',
'ldap_backup_port' => 'ldapBackupPort',
'ldap_background_host' => 'ldapBackgroundHost',
'ldap_background_port' => 'ldapBackgroundPort',
'ldap_override_main_server' => 'ldapOverrideMainServer',
'ldap_dn' => 'ldapAgentName',
'ldap_agent_password' => 'ldapAgentPassword',

View file

@ -600,12 +600,18 @@ class Connection extends LDAPUtility {
$isOverrideMainServer = ($this->configuration->ldapOverrideMainServer
|| $this->getFromCache('overrideMainServer'));
$isBackupHost = (trim($this->configuration->ldapBackupHost) !== "");
$isBackupHost = (trim($this->configuration->ldapBackupHost) !== "")
&& (!\OC::$CLI || !$this->configuration->ldapBackgroundHost);
$bindStatus = false;
try {
if (!$isOverrideMainServer) {
$this->doConnect($this->configuration->ldapHost,
$this->configuration->ldapPort);
$host = $this->configuration->ldapHost;
$port = $this->configuration->ldapPort;
if (\OC::$CLI && $this->configuration->ldapBackgroundHost) {
$host = $this->configuration->ldapBackgroundHost;
$port = $this->configuration->ldapBackgroundPort;
}
$this->doConnect($host, $port);
return $this->bind();
}
} catch (ServerNotAvailableException $e) {