Subject: | fix for enable user and LDAP update user info warnings |
Date: | Tue, 24 May 2011 19:24:00 +0000 |
To: | "bug-RT-Authen-ExternalAuth [...] rt.cpan.org" <bug-RT-Authen-ExternalAuth [...] rt.cpan.org> |
From: | "Daugherity, Andrew W" <adaugherity [...] tamu.edu> |
First of all, thanks for this module, it's much nicer than the old User_Local.pm LDAP auth we had been using.
I have fixed a couple bugs that generated warnings every time a user logged in. With RT 3.8 only the "Couldn't enable user" warning is logged, but RT 4.0 apparently uses a stricter warning level and also logs several "Use of uninitialized value" warnings.
Here is what is logged every time a user logs in (RT 4.0.0, RT::Authen::ExternalAuth 0.09, using an eDirectory LDAP server):
====
[Thu May 19 22:01:43 2011] [info]: RT::Authen::ExternalAuth::LDAP::GetAuth External Auth OK ( eDir_LDAP ): adaugherity (/opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth/LDAP.pm:139)
[Thu May 19 22:01:43 2011] [warning]: Couldn't enable user 93751 (/opt/rt4/sbin/../lib/RT/User.pm:1065)
[Thu May 19 22:01:43 2011] [warning]: Use of uninitialized value $val in concatenation (.) or string at /opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth.pm line 274. (/opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth.pm:274)
[Thu May 19 22:01:43 2011] [warning]: Use of uninitialized value $message in concatenation (.) or string at /opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth.pm line 274. (/opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth.pm:274)
[Thu May 19 22:01:43 2011] [info]: User marked as ENABLED ( ADaugherity ) per External Service (, ) (/opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth.pm:274)
[Thu May 19 22:01:43 2011] [warning]: Use of uninitialized value in string eq at /opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth/LDAP.pm line 236. (/opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth/LDAP.pm:236)
[Thu May 19 22:01:43 2011] [warning]: Use of uninitialized value in string eq at /opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth/LDAP.pm line 236. (/opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth/LDAP.pm:236)
< a lot more "uninitialized value in string eq" errors, apparently one for each LDAP attribute >
[Thu May 19 22:01:43 2011] [info]: RT::Authen::ExternalAuth::CanonicalizeUserInfo returning Address1: [$address], City: College Station, Country: US, EmailAddress: [$email], ExternalAuthId: ADaugherity, Gecos: [$gecos], Name: ADaugherity, Organization: Systems, RealName: Andrew Daugherity, State: TX, WorkPhone: [$phone], Zip: 77843 (/opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth.pm:536)
< previous line sanitized a bit; actual values are properly returned >
[Thu May 19 22:01:43 2011] [info]: Successful login for ADaugherity from 10.95.0.228 (/opt/rt4/local/plugins/RT-Authen-ExternalAuth/lib/RT/Authen/ExternalAuth.pm:219)
====
There are two bugs here:
1) Calling RT::User::SetDisabled() with the current disabled state (e.g. attempting to enable an already-enabled user) fails, returning undef. This means that
my ($val, $message) = $UserObj->SetDisabled(0);
results in $val being undef and the subsequent $RT::Logger call using $val and $message generating the "Use of uninitialized value" warning.
FYI, RT::User::SetDisabled in turn calls RT::Principal::SetDisabled(), which returns (0, "That is already the current value") in this case.
2) LDAP::CanonicalizeUserInfo() is testing $RT::LdapAttrMap->{$key}, but $RT::LdapAttrMap is not defined anywhere (in fact, this is the only occurrence of that name anywhere). A simple one-line patch fixes that:
foreach my $key (keys(%{$config->{'attr_map'}})) {
- if ($RT::LdapAttrMap->{$key} eq 'dn') {
+ if ($config->{'attr_map'}->{$key} eq 'dn') {
I wasn't using dn for anything, but I tested assigning it to FreeformContactInfo in the attr_map and it works now. Also, no more uninitialized value errors every time through the loop!
A patch for both issues is attached. I also fixed some nearby typos (s/principle/principal/).
Thanks,
Andrew Daugherity
Message body is not shown because sender requested not to inline it.