]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow to set a custom timeout for ldap connections 35520/head
authorLouis Chemineau <louis@chmn.me>
Wed, 23 Nov 2022 10:37:49 +0000 (11:37 +0100)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Wed, 30 Nov 2022 13:50:43 +0000 (13:50 +0000)
Signed-off-by: Louis Chemineau <louis@chmn.me>
apps/user_ldap/lib/Configuration.php
apps/user_ldap/lib/Connection.php

index c16823d39eefa460ffc8afad2ddba66e6d1a7a82..fc620e00e3032745a0b63cbbf47bfd731c1b681e 100644 (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;
        }
index 89b58b7ebfd5b0a7781b8de483515181b8c542e5..ab301cde5b50beaaaef6969aede5e3fa48145727 100644 (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 . '.');