From c423290c20a482c6984df52999eacf2a5242d7f3 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Thu, 8 Mar 2007 02:43:43 +0000 Subject: Bug 367480: [LDAP] Try a list of servers in order until we connect successfully Patch By Tony Bajan r=mkanat, a=mkanat --- Bugzilla/Auth/Verify/LDAP.pm | 13 +++++++++---- template/en/default/admin/params/ldap.html.tmpl | 4 +++- template/en/default/global/code-error.html.tmpl | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Bugzilla/Auth/Verify/LDAP.pm b/Bugzilla/Auth/Verify/LDAP.pm index 343f7952c..0176abdcb 100644 --- a/Bugzilla/Auth/Verify/LDAP.pm +++ b/Bugzilla/Auth/Verify/LDAP.pm @@ -37,6 +37,7 @@ use fields qw( use Bugzilla::Constants; use Bugzilla::Error; +use Bugzilla::Util; use Net::LDAP; @@ -134,11 +135,15 @@ sub ldap { my ($self) = @_; return $self->{ldap} if $self->{ldap}; - my $server = Bugzilla->params->{"LDAPserver"}; - ThrowCodeError("ldap_server_not_defined") unless $server; + my @servers = split(/[\s,]+]/, Bugzilla->params->{"LDAPserver"}); + ThrowCodeError("ldap_server_not_defined") unless @servers; - $self->{ldap} = new Net::LDAP($server) - || ThrowCodeError("ldap_connect_failed", { server => $server }); + foreach (@servers) { + $self->{ldap} = new Net::LDAP(trim($_)); + last if $self->{ldap}; + } + ThrowCodeError("ldap_connect_failed", { server => join(", ", @servers) }) + unless $self->{ldap}; # try to start TLS if needed if (Bugzilla->params->{"LDAPstarttls"}) { diff --git a/template/en/default/admin/params/ldap.html.tmpl b/template/en/default/admin/params/ldap.html.tmpl index a3c7e4643..22375cdf7 100644 --- a/template/en/default/admin/params/ldap.html.tmpl +++ b/template/en/default/admin/params/ldap.html.tmpl @@ -30,7 +30,9 @@ "URI syntax can also be used, such as "_ "ldaps://ldap.company.com (for a secure connection) or " _ "ldapi://%2fvar%2flib%2fldap_sock (for a socket-based " _ - "local connection.", + "local connection. Multiple hostnames or URIs can be comma " _ + "separated; each will be tried in turn until a connection is " _ + "established.", LDAPstartls => "Whether to require encrypted communication once normal " _ "LDAP connection achieved with the server.", diff --git a/template/en/default/global/code-error.html.tmpl b/template/en/default/global/code-error.html.tmpl index 2de8bd6a2..91044064d 100644 --- a/template/en/default/global/code-error.html.tmpl +++ b/template/en/default/global/code-error.html.tmpl @@ -279,7 +279,7 @@ The specified LDAP attribute [% attr FILTER html %] was not found. [% ELSIF error == "ldap_connect_failed" %] - Could not connect to the LDAP server [% server FILTER html %]. + Could not connect to the LDAP server(s) [% server FILTER html %]. [% ELSIF error == "ldap_start_tls_failed" %] Could not start TLS with LDAP server: [% error FILTER html %]. -- cgit v1.2.3-24-g4f1b