Need help with Perl

VeeDubbs

Limp Gawd
Joined
Dec 9, 2005
Messages
398
Hi all -

Using the open source help desk software Request Tracker 3.8.7 if that makes a difference to anyone.

One of the main files that drive RT is /opt/rt3/etc/RT_SiteConfig.pm. The comments at the top of the file state that it is a perl module and can include valid perl code.

I was working on getting authenticating our users via LDAP against Novell which I was able to do. RT can also map LDAP attributes to RT. Here is what that snippet of code looks like:

Code:
## RT ATTRIBUTE MATCHING SECTION
# The list of RT attributes that uniquely identify a user
# This example shows what you *can* specify.. I recommend reducing this
# to just the Name and EmailAddress to save encountering problems later.
'attr_match_list'           => [    'Name',
				    'EmailAddress',
				    'RealName',
			       ],

# The mapping of RT attributes on to LDAP attributes
'attr_map'                  =>  {   'Name' => 'uid',
				    'EmailAddress' => 'uid',
				    'RealName' => 'givenName',
				    'ExternalAuthId' => 'uid',
				    'Gecos' => 'uid',
				}

There is no problem with this code, the problem is with the ino that comes from LDAP. We use Novell eDirectory and do not fill in the EmailAddress field for any of our users.

So, what I'd like to do is maybe create EmailAddresses for anyone that authenticates via LDAP. As you can see, I am currently using the uid from LDAP to populate the EmailAddress of RT. If my uid is bsmith my e-mail address would be [email protected]. Is there any way to tack on the @school.edu to the LDAP value?

I'm hoping that since this is a perl file, there is some way of doing it in perl. I'm no expert in perl, in fact I no very little about it. But here is what I have tried thus far:


Code:
'EmailAddress' => 'uid'+'@school.edu',
'EmailAddress' => 'uid'&&'@school.edu',
'EmailAddress' => 'uid' . '@school.edu',

Those either crash RT or ignore everything except uid.

Can anyone point me in the right direction? Or tell me it's not possible so I stop wasting my time?

Thanks!!
 
In this context, you're sort of out of luck unless the application has something app-specific to handle doing string substutions. You're creating a mapping between the -names- of variables. You don't have the -values- available to you at this point.

I took a quick look at the code and I -think- you might be able to get away with a quick hack to get this in there. If you put the line
Code:
$params{'EmailAddy'} = ($entry->get_value('uid'))[0] . '@example.edu';
at around line 243 (that's in side sub CanonicalizeUserInfo) of RT::Authen::ExternalAuth::LDAP it might do what you want. Then again, it might cause the end of all life on earth.

Here's the line in context:
Code:
233         if ($ldap_msg->count == 1) {
234             my $entry = $ldap_msg->first_entry();
235             foreach my $key (keys(%{$config->{'attr_map'}})) {
236                 if ($RT::LdapAttrMap->{$key} eq 'dn') {
237                     $params{$key} = $entry->dn();
238                 } else {
239                     $params{$key} =
240                       ($entry->get_value($config->{'attr_map'}->{$key}))[0];
241                 }
242             }
243             $params{'EmailAddy'} = ($entry->get_value('uid'))[0] . '@example.edu';
244             $found = 1;
 
In this context, you're sort of out of luck unless the application has something app-specific to handle doing string substutions. You're creating a mapping between the -names- of variables. You don't have the -values- available to you at this point.

I took a quick look at the code and I -think- you might be able to get away with a quick hack to get this in there. If you put the line
Code:
$params{'EmailAddy'} = ($entry->get_value('uid'))[0] . '@example.edu';
at around line 243 (that's in side sub CanonicalizeUserInfo) of RT::Authen::ExternalAuth::LDAP it might do what you want. Then again, it might cause the end of all life on earth.

Here's the line in context:
Code:
233         if ($ldap_msg->count == 1) {
234             my $entry = $ldap_msg->first_entry();
235             foreach my $key (keys(%{$config->{'attr_map'}})) {
236                 if ($RT::LdapAttrMap->{$key} eq 'dn') {
237                     $params{$key} = $entry->dn();
238                 } else {
239                     $params{$key} =
240                       ($entry->get_value($config->{'attr_map'}->{$key}))[0];
241                 }
242             }
243             $params{'EmailAddy'} = ($entry->get_value('uid'))[0] . '@example.edu';
244             $found = 1;

Thank ameoba. But I can't seem to find the file you are speaking of. I have RT_SiteConfig.pm in /opt/rt3/etc and RT-Authen-ExternalAuth in /opt/rt3/local/plugins. Is that something from CPAN you are referring to?

I'd definitely like to give what you suggested a try though!!!
 
It's probably down in the plugins folder. The file can be grabbed through CPAN but I'm not sure if that's the preferred way of dealing with it.
 
Back
Top