In the immortal words of Simon, Deborah:

> My question would be if you know of a way to, from Linux, ask the 
> network for a list of LDAP servers ... something like a service 
> location protocol??? I read a little about OpenSLP but I am not sure if 
> MS Active Directory supports this.

This is the code we use to look up a PDC for a particular domain using 
Net::DNS.  It assumes you have the _foo DNS glue records in place that 
AD wants.  You can remove the ".pdc" if you don't need to hit the PDC
(which would be the typical case, actually), and you could use
$rr->port instead of getservbyname if you aren't using SSL.  A more
complete version of this routine would also use the weight/priority of 
the SRV records for choosing the Right One to return (since we only
have one PDC per domain, we don't have to bother for our purposes).


use Net::DNS;
use Net::DNS::RR;

$domain = "myadforest.example.com";
my ($pdchost, $pdcport) = &lookup_pdc($domain)
  or die "SRV RR not found for domain $domain";

sub lookup_pdc {
  my ($domain) = @_;
  my $res = new Net::DNS::Resolver;
  my $query = $res->send("_ldap._tcp.pdc._msdcs.$domain", "SRV");
 
  if ($query) {
    foreach $rr ($query->answer) {
      next unless $rr->type eq 'SRV';
      # return first found; find ldaps port from services file since
      # there's no _ldaps SRV record
      return $rr->target, scalar getservbyname('ldaps', 'tcp');
    }
  } else {
    &note("SRV RR lookup failed: " . $res->errorstring);
  }
  return;
}

%%  Christopher A. Bongaarts  %%  [EMAIL PROTECTED]       %%
%%  Internet Services         %%  http://umn.edu/~cab  %%
%%  University of Minnesota   %%  +1 (612) 625-1809    %%

Reply via email to