From 7261ecd29d5db3446a23d68945c28a04c6664cc0 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 7 Dec 2009 18:43:09 -0800 Subject: [PATCH] Fix an infinite loop in getting LDAP error messages. Fixes bug #11296 --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/LDAPLink.pm | 11 +++++------ lib/WebGUI/Operation/LDAPLink.pm | 13 +++++++------ t/LDAPLink.t | 3 ++- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 8c2edff3b..94b8636a8 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - fixed #11289: Gallery with pending version tag causes search engine indexer to puke. - fixed #11292: Search function limited to onje search? - fixed #11286: Workflow Instance deleted when reaching an Activity that fails to load + - fixed #11296: listLDAPLinks op permissions problems 7.8.7 - fixed #11278: Wrong test for Template::Toolkit in testEnvironment.pl diff --git a/lib/WebGUI/LDAPLink.pm b/lib/WebGUI/LDAPLink.pm index 2d6008f04..cdb40e5d5 100644 --- a/lib/WebGUI/LDAPLink.pm +++ b/lib/WebGUI/LDAPLink.pm @@ -107,9 +107,10 @@ sub connectToLDAP { $self->{_uri} = $uri; my $ldap = Net::LDAP->new($uri->host, port => $uri->port, #Port will default to 389 or 636 - scheme => $uri->scheme + scheme => $uri->scheme, + timeout => 15, ); - + unless($ldap) { $self->{_error} = 103; return undef; @@ -167,7 +168,7 @@ A valid ldap error code. sub getErrorMessage { my $self = shift; - my $errorCode = shift || $self->getErrorMessage; + my $errorCode = shift || $self->getErrorCode; return "" unless $errorCode; my $i18nCode = "LDAPLink_".$errorCode; my $i18n = WebGUI::International->new($self->session,"AuthLDAP"); @@ -231,9 +232,7 @@ Disconnect cleanly from the current databaseLink. =cut sub unbind { - my ($self, $value); - $self = shift; - $value = shift; + my $self = shift; if (defined $self->{_connection}) { $self->{_connection}->unbind; } diff --git a/lib/WebGUI/Operation/LDAPLink.pm b/lib/WebGUI/Operation/LDAPLink.pm index 5d7e8690a..6d8f31f4e 100644 --- a/lib/WebGUI/Operation/LDAPLink.pm +++ b/lib/WebGUI/Operation/LDAPLink.pm @@ -380,13 +380,14 @@ sub www_listLDAPLinks { my $ldapLink = WebGUI::LDAPLink->new($session,$data->{ldapLinkId}); my $status = $i18n->get("LDAPLink_1078"); - if ($ldapLink->bind && $ldapLink->getErrorCode == 0) { - $status = $i18n->get("LDAPLink_1079"); - } else { - $session->errorHandler->warn($ldapLink->getErrorMessage()); + if ($ldapLink->bind && $ldapLink->getErrorCode == 0) { + $status = $i18n->get("LDAPLink_1079"); + $ldapLink->unbind; + } + else { + $session->errorHandler->warn($ldapLink->getErrorMessage()); $status .= ": ".$ldapLink->getErrorMessage(); - } - $ldapLink->unbind; + } $row[$i] .= ''.$status.''; $row[$i] .= ''; $i++; diff --git a/t/LDAPLink.t b/t/LDAPLink.t index f068a35eb..251832811 100644 --- a/t/LDAPLink.t +++ b/t/LDAPLink.t @@ -30,7 +30,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -plan tests => 8; # Increment this number for each test you create +plan tests => 9; # Increment this number for each test you create ########################################################################### @@ -79,4 +79,5 @@ plan tests => 8; # Increment this number for each test you create isa_ok $connection, 'Net::LDAP', 'returned by bind'; is $ldap->{_error}, 104, 'auth error due to bad identifier'; is $ldap->getErrorCode, 104, 'getErrorCode returns the stored error code'; + ok $ldap->getErrorMessage, 'getErrorMessage returns an error message'; }