in reply to Re^5: Net::LDAP help with distinguished name
in thread Net::LDAP help with distinguished name
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,
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^7: Net::LDAP help with distinguished name
by Sinistral (Monsignor) on Feb 04, 2012 at 20:35 UTC | |
by Discreet Entity (Initiate) on Feb 04, 2012 at 23:27 UTC | |
by Anonymous Monk on Feb 05, 2012 at 16:08 UTC |