How to query AD RootDSE with Net::LDAP? 
Author Message
 How to query AD RootDSE with Net::LDAP?

Hey everyone,

I have taken some sample PERL code and customized it to query user
objects and attributes, which worked fine. Then, I took this working
code and tried to query the RooDSE of an AD server, but cannot make it
work. It seems to bind, but finds no entries. According to the MS
documentation, I should be able to query the RootDSE by leaving the
base of the LDAP query blank.  Ultimately, I am looking for the value
of highestCommittedUsn.

Have any of you done this successfully?

Here is the code in its current state. Any help would be appreciated.

Charlie

--- GetHighestCommittedUsn.pl ---------------

use Net::LDAP;

$LdapServer='pbswis00013.corp.pep.pvt';  # FQDN of LDAP server
$BindAs = 'cn=MyUserName,ou=Infrastructure
Resources,dc=corp,dc=pep,dc=pvt';
$passwd='MyPassword';
$hqbase="";
$LdapFilter="objectClass=*";    # Define LDAP query

# Connecting
$ldap = Net::LDAP->new($LdapServer) or die ("No LDAP server\n");
# ABOVE WORKS.

$mesg = $ldap->bind (
  dn       => $BindAs,
  password => $passwd);

if ( $mesg->code()) {
    die ("error:", $mesg->code(),"\n");
  }

# Searching
$mesg = $ldap->search (base   => $hqbase,
                       filter => $LdapFilter,
                       attrs  => "*");
$ldap->unbind;

$entries = $mesg->count;
print "Number of Entries: $entries\n";
# *** I GET 0 ENTRIES HERE. ***

# Dumbing output
%wanted = (name                => 'Name',
           dn                  => 'DN',
           highestCommittedUsn => 'USN');

# Print results
for ($i = 0 ; $i < $entries ; $i++)
{
   $entry = $mesg->entry($i);
   print "\n";
   foreach my $attr ($entry->attributes)
   {
      if ($wanted{$attr})
      {
         # Some attributes contain mutiple values so we read into an
array.

         # Now we join the multiple values into a scalar for printing.

         print "[" . $wanted{$attr} . "] " . $Result . "\n\n";
      }
   }
   print "\n";

Quote:
}

---- END OF SCRIPT ---------------------------


Tue, 31 Aug 2004 04:56:45 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Net::LDAP + URI::ldap -> referrals

2. LDAP queries

3. web server and LDAP queries

4. web server and LDAP queries

5. help with perl-ldap query

6. windows 2000 ldap perl script active directory query

7. RFD: Net::LDAP::Schema module

8. NET::LDAP

9. Net::LDAP

10. using Net::LDAP and printing search in a readable way

11. Net:LDAP Search (sorted by multiple attributes)

12. Problem with win32::NetAdmin and Net::LDAP on NT4

 

 
Powered by phpBB® Forum Software