From: Edward S. H. L. 2358-6. <lbs...@us...> - 2000-10-03 07:24:07
|
I am trying to run a search on our LDAP server and use the results to automatically fill out certain fields in our forms. I am stumped trying to assign specific LDAP attribute values to form variables. I am certainly doing something fundamentally wrong. Any help would be greatly appreciated. I am working with Solaris 2.6 on a Sun workstation, with Perl 5.005 and Net::LDAP 0.22 Our Library has about 15-20 online forms which our users can fill out to request various services, from asking Reference questions to requesting Interlibrary Loan of books and journals. All of these forms require the user to authenticate using HTTP 'basic' authentication. Our Apache web server matches their username/password combination against the campus LDAP server for authorization to access the form(s). That places their username into the HTTP environment variable 'REMOTE_USER'. The form then asks the suer to fill out various other personal information fields, including their name, department, position, etc. All of that personal information is also contained in their LDAP record, so I am trying to modify the scripts so that a Net::LDAP search can be done against their already authenticated username, and to retrieve the values the form requires so that the user does not have to enter them manually, and to assure that we have accurate and consistent formatting of the results (as consistent as the data in the LDAP records anyway). So I am writing a subroutine which will be called by the script which generates the form, which will do this search and retrieval. The script will then use the retrieved variables to fill in the personal information fields of the form. But I am not doing it right. Here is the subroutine I am calling: sub ldapcheck { use Net::LDAP; # Get username from authenticated environment variable my $username = $ENV{'REMOTE_USER'}; my $host = "ldap.ust.hk"; my $base = "o=ust.hk"; my $ldap = Net::LDAP->new($host) or die "$@"; # LDAP SEARCH my $result = $ldap->search( base => $base, filter => "uid=$username" ); # ERROR TRAP use Net::LDAP::Util qw(ldap_error_text); die ldap_error_text($result->code) if $result->code; # TEST FOR UNIQUENESS die "Your LDAP entry is not unique." if $result->count() != 1; # ASSIGN VARIABLES TO ATTRIBUTES WANTED -- THIS IS Definitely WRONG... $perstitle = $result->personaltitle; $pname = $result->sn; $gname = $result->givenname; $jobtitle = $result->title; $dept = $result->ou; $email = $result->mail; $phone = $result->telephonenumber; $position = $result->userclass; } I then try to print "$perstitle"; and other variables in the generated form, but this is not working. This subroutine is called here: #!/usr/local/bin/perl require "cgi-lib.pl"; MAIN: { my ($pname, $gname, $dept, $position, $perstitle, $email, $phone, $jobtitle); &ldapcheck; # Read in all the variables set by the form if (&ReadParse(*input)) { &ProcessForm; } else { &PrintForm; } } Presently, trying to run this script yields the following error: "Can't locate object method "personaltitle" via package "Net::LDAP::Entry" at req-book2.pl line 480." Line 480 is the $perstitle = $result->personaltitle; line from the above subroutine. Once I get the LDAP retrieval working, I will be rewriting these old forms to use CGI.pm instead of cgi-lib.pl, and also to fix the tainted variables left from the earlier programming. As to the ldap field names, I have been provided with a copy of my ldap record, so that I can be sure I have the attribute names correct: uid=lbspodic,ou=people,o=ust.hk cn: SPODICK Edward F cn;lang-zh-tw: ¬v¬ï¬ºw departmentcode: LIB facsimiletelephonenumber: 2358-1043 givenname: Edward F labeleduri: http://home.ust.hk/~lbspodic/ mail: lbs...@us... mailhost: uxmail.ust.hk maillocaladdress: lbs...@us... mailquota: 100000000 mailroutingaddress: lbs...@ux... objectclass: top person organizationalPerson inetOrgPerson ustPerson inetLocalMailRecipient ou: Library personaltitle: Mr roomnumber: 1358 sn: SPODICK telephonenumber: 23586743 title: Systems Librarian uid: lbspodic userclass: staff I am not skilled at Perl (probably very obviously). I suspect there is something fundamentally wrong with some aspect of my approach. Hoping for assistance, I remain, -Edward Spodick, lbs...@us... - - - - - Edward F Spodick, Systems Librarian - lbs...@us... Hong Kong University of Science & Technology Library tel: 852-2358-6743 fax: 852-2358-1043 |