Hello all. I am pretty new to perl and even newer to perl-ldap and I am having a problem trying to access Novell NDS/LDAP with a simple query. The script doesn't error out, but it does not display any results. I am unsure how to tell what is going on, and would appreciate any suggestions on script advice that anyone would be willing to share. My goal is to utilize our NDS tree for a simple employee search on our intranet. I have included the script that I am trying to use. Thanks for the help.
#!/usr/bin/perl -w
require "/home/httpd/cgi-bin/formlib.pl";
use Net::LDAP qw(:all);
use Net::LDAP::Util qw(ldap_error_name
ldap_error_text);
$| = 1;
&GetFormArgs();
$ENV{PATH_INFO} ne '' && &GetPathArgs($ENV{PATH_INFO});
$ldap = Net::LDAP->new("mail.hillcrest.com") or die "$@";
$mesg = $ldap->bind( version => 3 );
print "Content-Type: text/html\n\n";
print <<"EOM";
<HTML>
<HEAD>
<TITLE>Employee Database Search</TITLE>
</HEAD>
<P><HR<P>
</BODY>
</HTML>
EOM
unless ( $in{first} && ($in{last} )) {
print <<"EOM";
<H1>OOPS!</H1><P> You need to enter a first and last name</H1><P>
<A HREF="http://is.hillcrest.com/test.html">
Click Here</A> to return to the search form.
EOM
} else {
$first = ($in{first});
$last = ($in{last});{
if ( $result->code ) {
#
# if we've got an error... record it
#
LDAPerror("Searching",$result);
}
my @Attrs = (); # request all available attributes
# to be returned.
my $result = LDAPsearch($ldap,"sn=*",\@Attrs);
#------------
#
# handle each of the results independently
# ... i.e. using the walk through method
#
my @entries = $result->entries;
print @entries;
my $entr ;
foreach $entr ( @entries )
{
print "DN: ",$entr->dn,"\n";
#my @attrs = sort $entr->attributes;
my $attr;
foreach $attr ( sort $entr->attributes ){
#skip binary we can't handle
next if ( $attr =~ /;binary$/ );
print " $attr : ",$entr->get($attr),"\n";
}
#print "@attrs\n";
print "#-------------------------------\n";
}
#
# end of walk through method
#------------
sub LDAPsearch
{
my ($ldap,$last,$attrs,$base) = @_ ;
# if they don't pass a base... set it for them
if (!$base ) { $base = "his.hhs"; {
# if they don't pass an array of attributes...
# set up something for them
if (!$attrs ) { $attrs = ['cn','mail' ]; {
my $result = $ldap->search (
base => "$base",
scope => "sub",
filter => "$last",
attrs => "$attrs",
);
}
}
sub LDAPerror
{
my ($from,$mesg) = @_;
print "Return code: ",$mesg->code ;
print "\tMessage: ", ldap_error_name($mesg->code);
print " :", ldap_error_text($mesg->code);
print "MessageID: ",$mesg->mesg_id;
print "\tDN: ",$mesg->dn;
#---
# Programmer note:
#
# "$mesg->error" DOESN'T work!!!
#
#print "\tMessage: ", $mesg->error;
#-----
}
}
}
}
}
}
Cliff Cloyd
Systems Administrator
Hillcrest Healthcare Systems
918.579.7781
cc...@hi...
|