samba_dnsupdate: Allow admin to force a particular IP into samba_dnsupdate
authorAndrew Bartlett <abartlet@samba.org>
Fri, 7 Aug 2015 02:57:20 +0000 (14:57 +1200)
committerGarming Sam <garming@samba.org>
Thu, 16 Jun 2016 02:40:13 +0000 (04:40 +0200)
This should help in deployements beyind NAT.

It will also help in testing.

Andrew Bartlett

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
source4/scripting/bin/samba_dnsupdate

index d9bf726d37fb696fb0b81c469f3d5934555f2549..e974c401d994410801a99ec9bab14022cda0d02c 100755 (executable)
@@ -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")
@@ -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:
@@ -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: