Greetings,
 
I am trying to use perl-ldap to search an Active Directory. I am able to
connect and bind, but when I attempt to search I am not getting any usable
results back. I am hoping someone can spot what I am doing wrong and help me
out a bit. I have removed some content from the script replacing it with
notes about what the content was surrounded by []. So the [] are not really
part of the script just place holds for the content. 
 
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use strict;
use Net::LDAP;
 
my $ad = Net::LDAP->new("[the address I am connecting to]:389") or die
(print "connection failed\n");
 
$ad->bind("[EMAIL PROTECTED] ur]l", password =>'[the password using single
quotes due to the use of special characters]');
 
#Up to this point everything seems to be working based on my error checking.
 
# Declare the necessary search variables
 
# What is the search base?
 
my $searchbase = 'OU=[This is the folder I am looking in. It's three words
separated by a space between each word],DC=[url part],DC=[url part],DC=[url
part]';
 
# What are we searching for?
 
my $filter = "CN=[name of one of our users that I know is in the AD]";
 
# Which attributes should be returned?
 
my $attrs = "sn, givenname, mail";
 
# Execute the search
 
my $results = $ad->search(base=>$searchbase,filter=>$filter,attrs=>$attrs);
 
# Display entries
 
my $entry;
 
$entry = $results->entry(0);
 
print $entry->get_value('sn').", ".$entry->get_value('givenname')."\n";
print "Email: ".$entry->get_value('mail')."\n";
 
 
# Unbind from the server
$ad->unbind;
 
The error messages I am getting are: 
Can't call method "get_value" on an undefined value at test-get.pl line 38,
<DATA> line 225.
 
To me, this sounds like the search results are not coming back in a useful
manor.
 
This is what the results look like:
Net::LDAP::Search=HASH(0x8345f68)
 
Any suggestions would be greatly appreciated.
 
Thanks
--John
 

Reply via email to