I am using Net::LDAP to search Active Directory for a certain user ID and return their cn and lastlogintime attributes. Here is my code:
foreach my $uid (keys %results){ $search = $ad_ldap->search( base => 'DC=company,DC=domain,DC=lan', scope => 'sub', filter => "(&(cn=".$uid.")(objectclass=user))", attrs => ['lastlogon', 'cn'] ); # if no results were returned, set ad_lastlogintime to 0 and g +o to next uid if ( $search->count == 0){ $results{$uid}{ad_lastlogintime}{0} = 1; next; } # store the AD last login time in the uid hash foreach my $entry ($search->entries){ $results{$uid}{ad_lastlogintime}{$entry->get_value('lastlo +gon')} = 1; } }
The problem is this: there is a uid in AD that when I search for it, the search does not return anything. $search->count is equal to 0, so I just set the lastlogintime to 0. The ID that I am searching for is definitely in AD but for some reason it does not find it at all when it searches for it. We think the issue may be the possibility that the ID is actually a reference. From what it looks like, I might be able to get the correct result if I just don't try to dereference the object (ID) when I search for it, however I don't know how to do this. I realize that are several Net::LDAP modules that deal with this and I looked at them but I really don't understand them. If anyone has any ideas, I would appreciate a little help. Also, I know the information is a little sketchy here so if you need more, please let me know. Thanks!

In reply to Can't get correct returns when querying Active Directory with Net::LDAP by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.