Skip to content

Commit

Permalink
samba_dnsupdate: Allow admin to force a particular IP into samba_dnsu…
Browse files Browse the repository at this point in the history
…pdate

This should help in deployements beyind NAT.

It will also help in testing.

Andrew Bartlett

Signed-off-by: Andrew Bartlett <[email protected]>
Reviewed-by: Garming Sam <[email protected]>
  • Loading branch information
abartlet authored and GSam committed Jun 16, 2016
1 parent e382249 commit 72d5fa7
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions source4/scripting/bin/samba_dnsupdate
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ parser.add_option("--use-samba-tool", action="store_true", help="Use samba-tool
parser.add_option("--use-nsupdate", action="store_true", help="Use nsupdate command to make updates over DNS (default, if kinit successful)")
parser.add_option("--all-names", action="store_true")
parser.add_option("--all-interfaces", action="store_true")
parser.add_option("--current-ip", action="append", help="IP address to update DNS to match (helpful if behind NAT, valid multiple times, defaults to values from interfaces=)")
parser.add_option("--rpc-server-ip", type="string", help="IP address of server to use with samba-tool (defaults to first --current-ip)")
parser.add_option("--use-file", type="string", help="Use a file, rather than real DNS calls")
parser.add_option("--update-list", type="string", help="Add DNS names from the given file")
parser.add_option("--update-cache", type="string", help="Cache database of already registered records")
Expand All @@ -91,13 +93,22 @@ if opts.all_interfaces:
else:
all_interfaces = False

IPs = samba.interface_ips(lp, all_interfaces)
if opts.current_ip:
IPs = opts.current_ip
else:
IPs = samba.interface_ips(lp, all_interfaces)

nsupdate_cmd = lp.get('nsupdate command')

if len(IPs) == 0:
print "No IP interfaces - skipping DNS updates"
sys.exit(0)

if opts.rpc_server_ip:
rpc_server_ip = opts.rpc_server_ip
else:
rpc_server_ip = IPs[0]

IP6s = []
IP4s = []
for i in IPs:
Expand Down Expand Up @@ -488,30 +499,30 @@ def call_samba_tool(d, op="add"):
short_name = normalised_name[:-len_zone]

if d.type == "A":
args = [IPs[0], zone, short_name, "A", d.ip]
args = [rpc_server_ip, zone, short_name, "A", d.ip]
if d.type == "AAAA":
args = [IPs[0], zone, short_name, "AAAA", d.ip]
args = [rpc_server_ip, zone, short_name, "AAAA", d.ip]
if d.type == "SRV":
if op == "add" and d.existing_port is not None:
print "Not handling modify of exising SRV %s using samba-tool" % d
return False
op = "update"
args = [IPs[0], zone, short_name, "SRV",
args = [rpc_server_ip, zone, short_name, "SRV",
"%s %s %s %s" % (d.existing_weight,
d.existing_port, "0", "100"),
"%s %s %s %s" % (d.dest, d.port, "0", "100")]
else:
args = [IPs[0], zone, short_name, "SRV", "%s %s %s %s" % (d.dest, d.port, "0", "100")]
args = [rpc_server_ip, zone, short_name, "SRV", "%s %s %s %s" % (d.dest, d.port, "0", "100")]
if d.type == "CNAME":
if d.existing_cname_target is None:
args = [IPs[0], zone, short_name, "CNAME", d.dest]
args = [rpc_server_ip, zone, short_name, "CNAME", d.dest]
else:
op = "update"
args = [IPs[0], zone, short_name, "CNAME",
args = [rpc_server_ip, zone, short_name, "CNAME",
d.existing_cname_target.rstrip('.'), d.dest]

if d.type == "NS":
args = [IPs[0], zone, short_name, "NS", d.dest]
args = [rpc_server_ip, zone, short_name, "NS", d.dest]

global error_count
try:
Expand Down

0 comments on commit 72d5fa7

Please sign in to comment.