Under LDAP, searching consists of three parts:
-
Binding to a directory server by name (or by other credentials, such
as Kerberos tokens) and port. You can provide a login and password
for the authentication or bind anonymously if you have permissions to
search or write a part of the directory.
-
Passing your search request to the directory server.
-
Unbinding from the directory server, thus closing the connection.
Let's say that you want to find a user called
nvp in the directory server
that's living on
ldap.your.server. With Net::LDAP, do the
following:
use Net::LDAP;
my $lsvr = 'ldap.your.domain';
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 => "(&(uid=nvp) (o=your.domain))"
);
if($results->code) {
die "received LDAP error: @{[$results->error]};
}
foreach my $entry ($results->all_entries) {
$entry->dump;
}
$ldap->unbind; # Unbind and close connection
 |  |  |
19. Lightweight Directory Access with Net::LDAP |  | 19.3. Adding an Entry to the Directory with Net::LDAP |