From 24bbc3db434d11804225fe330282ec837fad21e6 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Wed, 23 Nov 2022 11:37:49 +0100 Subject: [PATCH] Allow to set a custom timeout for ldap connections Signed-off-by: Louis Chemineau --- apps/user_ldap/lib/Configuration.php | 3 +++ apps/user_ldap/lib/Connection.php | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index c16823d39ee..fc620e00e30 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -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; } diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index 89b58b7ebfd..ab301cde5b5 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -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 . '.'); -- 2.39.5