Merge pull request #35602 from nextcloud/backport/stable25/35355

[stable25] Allow to set a custom timeout for ldap connections
This commit is contained in:
Vincent Petry 2022-12-16 16:39:18 +01:00 committed by GitHub
commit 25a8dd8a2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -120,6 +120,7 @@ class Configuration {
'ldapDefaultPPolicyDN' => null,
'ldapExtStorageHomeAttribute' => null,
'ldapMatchingRuleInChainState' => self::LDAP_SERVER_FEATURE_UNKNOWN,
'ldapConnectionTimeout' => 15,
];
public function __construct(string $configPrefix, bool $autoRead = true) {
@ -463,6 +464,7 @@ class Configuration {
'ldap_user_avatar_rule' => 'default',
'ldap_ext_storage_home_attribute' => '',
'ldap_matching_rule_in_chain_state' => self::LDAP_SERVER_FEATURE_UNKNOWN,
'ldap_connection_timeout' => 15,
];
}
@ -526,6 +528,7 @@ class Configuration {
'ldap_ext_storage_home_attribute' => 'ldapExtStorageHomeAttribute',
'ldap_matching_rule_in_chain_state' => 'ldapMatchingRuleInChainState',
'ldapIgnoreNamingRules' => 'ldapIgnoreNamingRules', // sysconfig
'ldap_connection_timeout' => 'ldapConnectionTimeout',
];
return $array;
}

View file

@ -649,6 +649,10 @@ class Connection extends LDAPUtility {
throw new ServerNotAvailableException('Could not disable LDAP referrals.');
}
if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_NETWORK_TIMEOUT, $this->configuration->ldapConnectionTimeout)) {
throw new ServerNotAvailableException('Could not set network timeout');
}
if ($this->configuration->ldapTLS) {
if (!$this->ldap->startTls($this->ldapConnectionRes)) {
throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.');