LDAP search
Paul Fontenot <[email protected]> Tue, 1 Oct 2013 11:38:47 -0700
| Newsgroups | gmane.comp.lang.perl.modules.ldap |
|---|---|
| Message-ID | <CAOXg1PJfV8BzFtgHqrac_n0ycf6_s6HnFq8wU+YHoh5uWSMBmA@mail.gmail.com> |
I am just beginning my foray into Perl with LDAP and I'm not getting what I
expected to get from the LDAP server. If I use ldapsearch like this:
ldapsearch -h ldap.example.com -p 389 -x -b "c=us"
Then I recieve what I expect - everything below the basedn, however when I
attempt the same thing ( I *think* I've written this correctly) in Perl I
get the following error:
"received LDAP error: No such object at ldap_crl.pl line 16, <DATA> line
749."
Any direction would be greatly appreciated.
#!/usr/bin/perl
#
use Net::LDAP;
my $lsvr = 'ldap.example.com';
my $ldap = Net::LDAP->new($lsvr)
or die "error connecting to $lsvr: $@";
$ldap->bind; # Bind anonymously, that is, no login and pass
my $results = $ldap->search ( # Perform a
search for 'nvp'
filter => "(&(c=US))"
);
if($results->code) {
die "received LDAP error: @{[$results->error]}";
}
foreach my $entry ($results->all_entries) {
$entry->dump;
}
$ldap->unbind; # Unbind and close connection