I understand what you're saying but constructing a filter for a distinguished name does not appear to work. Here is a bit of test code I wrote.
sub getLDAPInfo { my $targetuser = shift; my $ldapuser = "SomeUser"; my $ldappassword = "SomePassword"; my $domain = "dc.mycompany.com"; my $fullname; my $ad = Net::LDAP->new($domain) or die "Could not connect!"; $ad->bind($ldapuser, password=>$ldappassword); my $searchbase = 'DC=mycompany,DC=com'; my $filter = "samaccountname=$targetuser"; my $results = $ad->search(base=>$searchbase,filter=>$filter); my $count = $results->count; if ($count) { my @entries = $results->entries; foreach my $entry (@entries) { $fullname = $entry->get_value('givenname'). " +" . $entry->get_value('sn'); return ($fullname); } else { return ""; } $ad->unbind; } my $fullname= &getLDAPInfo("JUSER"); print $fullname. "\n";
This works perfectly. However, if I change the filter like so:
my $filter = "distinguishedname=$targetuser";
And pass it a distinguished name like so:
my $fullname= &getLDAPInfo("CN=JUSER,OU=ACCT,DC=MYCOMPANY,DC=COM");
it returns nothing. I have tried to build the filter as both distinguishedname= and dn= to no avail.
If, as you say, I still need to do the search, please help me understand how to construct the filter to search for a distinguished name.
Thanks,
In reply to Re^6: Net::LDAP help with distinguished name
by Discreet Entity
in thread Net::LDAP help with distinguished name
by Discreet Entity
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |