summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-02-26 13:58:32 +1100
committerAndrew Tridgell <tridge@samba.org>2010-02-26 13:59:17 +1100
commit721bcfa01c28996891893e56a303c42d495c9fcd (patch)
treee585f398ec2ceb869c07c0039d4b64cb92b59f91 /source4
parentab4f170216c5bdd8b6f46df562d0a21ba8321a4b (diff)
downloadsamba-721bcfa01c28996891893e56a303c42d495c9fcd.tar.gz
samba-721bcfa01c28996891893e56a303c42d495c9fcd.tar.bz2
samba-721bcfa01c28996891893e56a303c42d495c9fcd.zip
dns: auto-delete incorrect SRV entries for our hostname
Diffstat (limited to 'source4')
-rwxr-xr-xsource4/scripting/bin/samba_dnsupdate23
1 files changed, 15 insertions, 8 deletions
diff --git a/source4/scripting/bin/samba_dnsupdate b/source4/scripting/bin/samba_dnsupdate
index c5af17a759..9a90eac9dc 100755
--- a/source4/scripting/bin/samba_dnsupdate
+++ b/source4/scripting/bin/samba_dnsupdate
@@ -94,6 +94,8 @@ class dnsobj(object):
self.dest = None
self.port = None
self.ip = None
+ self.existing_port = None
+ self.existing_weight = None
def __str__(self):
if d.type == "A": return "%s:%s:%s" % (self.type, self.name, self.ip)
if d.type == "SRV": return "%s:%s:%s:%s" % (self.type, self.name, self.dest, self.port)
@@ -131,10 +133,11 @@ def hostname_match(h1, h2):
############################################
# check that a DNS entry exists
def check_dns_name(d):
+ normalised_name = d.name.rstrip('.') + '.'
if opts.verbose:
- print "Looking for DNS entry %s" % d
+ print "Looking for DNS entry %s as %s" % (d, normalised_name)
try:
- ans = dns.resolver.query(d.name, d.type)
+ ans = dns.resolver.query(normalised_name, d.type)
except dns.resolver.NXDOMAIN:
return False
if d.type == 'A':
@@ -147,14 +150,15 @@ def check_dns_name(d):
if hostname_match(ans[i].target, d.dest):
return True
if d.type == 'SRV':
- if opts.verbose:
- print "Got %u replies in SRV lookup for %s" % (len(ans), d.name)
- for i in range(len(ans)):
- rdata = ans[i]
+ for rdata in ans:
if opts.verbose:
print "Checking %s against %s" % (rdata, d)
- if str(rdata.port) == str(d.port) and hostname_match(rdata.target, d.dest):
- return True
+ if hostname_match(rdata.target, d.dest):
+ if str(rdata.port) == str(d.port):
+ return True
+ else:
+ d.existing_port = str(rdata.port)
+ d.existing_weight = str(rdata.weight)
if opts.verbose:
print "Failed to find DNS entry %s" % d
return False
@@ -190,6 +194,9 @@ def call_nsupdate(d):
if d.type == "A":
f.write("update add %s %u A %s\n" % (d.name, default_ttl, d.ip))
if d.type == "SRV":
+ if d.existing_port is not None:
+ f.write("update delete %s SRV 0 %s %s %s\n" % (d.name, d.existing_weight,
+ d.existing_port, d.dest))
f.write("update add %s %u SRV 0 100 %s %s\n" % (d.name, default_ttl, d.port, d.dest))
if d.type == "CNAME":
f.write("update add %s %u SRV %s\n" % (d.name, default_ttl, d.dest))