diff -urN ../roundcubemail-1.4.11.orig/vendor/kolab/net_ldap3/lib/Net/LDAP3.php ./vendor/kolab/net_ldap3/lib/Net/LDAP3.php --- ../roundcubemail-1.4.11.orig/vendor/kolab/net_ldap3/lib/Net/LDAP3.php 2019-10-21 14:18:59.000000000 +0300 +++ ./vendor/kolab/net_ldap3/lib/Net/LDAP3.php 2021-09-11 16:11:09.303801000 +0300 @@ -66,6 +66,8 @@ "v" => "read" ); + private $hosts_used = array(); + /* * Manipulate configuration through the config_set and config_get methods. * Available options: @@ -601,17 +603,29 @@ } if (is_resource($this->conn)) { - $this->_debug("Connection already exists"); - return true; + if ($this->_current_bind_dn) { + $this->_debug("Connection already exists"); + return true; + } else { + $hosts = (!empty($host) ? (is_array($host) ? $host : array($host)) : $this->config_get('hosts', array())); + $hosts = array_diff($hosts, $this->hosts_used); + if (count($hosts) == 0) { + $this->_debug("Connection already exists"); + return true; + } else { + $this->_debug(sprintf("C: Try next LDAP host %s", $hosts[0])); + } + } + } else { + $hosts = !empty($host) ? $host : $this->config_get('hosts', array()); } - - $hosts = !empty($host) ? $host : $this->config_get('hosts', array()); $port = $this->config_get('port', 389); foreach ((array) $hosts as $host) { $this->_debug("C: Connect [$host:$port]"); if ($lc = @ldap_connect($host, $port)) { + $this->hosts_used[] = $host; if ($this->config_get('use_tls', false) === true) { if (!ldap_start_tls($lc)) { $this->_debug("S: Could not start TLS. " . ldap_error($lc));