3
#if you define this, debugging output will be printed to STDERR.
6
#to force using some DC for some domains, fill in this hash.
7
#the key is a regexp matched against the domain name
8
# the value is an array ref with PDC and BDC.
9
# the order the names are matched in is UNDEFINED.
11
# %controllers = ( "domain" => ["pdc","bdc"]);
13
#%controllers = ( ".*" => ["tlc5",undef]);
15
#define this if you wish to use a WINS server. If undefined, broadcast
17
$wins_server="c0wins";
20
# Some servers (at least mine) really really want to be called by address.
21
# If this variable is defined, we'll ask nmblookup to do a reverse DNS on the
22
# DC addresses. It might fail though, for instance because you have a crappy
23
# DNS with no reverse zones or records. If it doesn't work, you'll have to
24
# fall back to the %controllers hack.
27
# Soem servers (at least mine) don't like to be called by their fully
28
# qualified name. define this if you wish to call them ONLY by their
32
#no more user-serviceable parts
36
# %pdc used to cache the domain -> pdc_ip values. IT NEVER EXPIRES!
40
if (! m;([^\\]+)(\\|/)(\S+)\s(.*); ) { #parse the line
47
print STDERR "domain: $domain, user: $user, pass=$pass\n"
48
if (defined ($debug));
49
# check out that we know the PDC address
51
($pdc,$bdc)=&discover_dc($domain);
62
print STDERR "No PDC found\n" if (defined($debug));
66
print STDERR "querying '$pdc' and '$bdc' for user '$domain\\$user', ".
67
"pass $pass\n" if (defined($debug));
68
$result=Authen::Smb::authen($user,$pass,$pdc,$bdc,$domain);
69
print STDERR "result is: $nt_results{$result} ($result)\n"
71
if ($result == NTV_NO_ERROR) {
72
print STDERR ("OK for user '$domain\\$user'\n") if (defined($debug));
75
print STDERR "Could not authenticate user '$domain\\$user'\n";
80
#why do Microsoft servers have to be so damn picky and convoluted?
82
my $domain = shift @_;
83
my ($pdc, $bdc, $lookupstring, $datum);
85
foreach (keys %controllers) {
86
if ($domain =~ /$_/) {
87
print STDERR "DCs forced by user: $_ => ".
88
join(',',@{$controllers{$_}}).
89
"\n" if (defined($debug));
90
return @{$controllers{$_}};
93
$lookupstring="nmblookup";
94
$lookupstring.=" -R -U $wins_server" if (defined($wins_server));
95
$lookupstring.=" -T" if (defined($try_reverse_dns));
96
$lookupstring.=" '$domain#1c'";
97
print STDERR "Discovering PDC: $lookupstring\n"
99
#discover the PDC address
100
open(PDC,"$lookupstring|");
102
print STDERR "response line: $_" if (defined($debug));
103
if (m|(.*), (\d+\.\d+\.\d+\.\d+)|) {
105
print STDERR "matched $datum\n" if (defined($debug));
106
if (defined($dont_use_fqdn) && $datum =~ /^([^.]+)\..*/) {
108
print STDERR "stripped domain name: $datum\n" if (defined($debug));
110
} elsif (m|^(\d+\.\d+\.\d+\.\d+)|) {
113
#no data here, go to next line
119
print STDERR "BDC is $datum\n" if (defined($debug));
123
print STDERR "PDC is $datum\n" if (defined($debug));
129
return ($pdc,$bdc) if ($pdc);