Thank you for replying. It appears you took the time to actually read my request.
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,
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.