Re: Need help to search all dc's available

Graham Barr <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.ldap
Message-ID <[email protected]>
On Jan 6, 2009, at 4:12 AM, omkar kulkarni wrote:
> ok Let me tell you my actual Use Case:
>
> I am developing one tool called ldaphelper.
> what this tool will do is :
> ldaphelper -discover : this will connect to local machine and try to  
> find
> out all available domains (DC Objects) in that ldap DIR and write to  
> XML
> with som attributes those I needed for another project, that project  
> pick up
> that XML and add that domain as LDAP domain in
> my project for Authenticvation purpose.

OK, from this description I assume you also do not know a base DN to  
start
the search from. to get that you will need to get the namingContexts  
from
the root DSE. Try something like (untested and you will need to add  
error
handling)

my $ldap = Net::LDAP->new( 'localhost' );
my $dse = $ldap->root_dse;
foreach my $base ($dse->get_value('namingContexts')) {
   my $search = $ldap->search(
     base => $base,
     filter => '(objectclass=dcObject)',
   );
   foreach my $entry ($search->entries) {
     $entry->dump;
   }
}

Graham.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.