4 # update our DNS names using TSIG-GSS
6 # Copyright (C) Andrew Tridgell 2010
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 # ensure we get messages out immediately, so they get in the samba logs,
29 # and don't get swallowed by a timeout
30 os.environ['PYTHONUNBUFFERED'] = '1'
32 # forcing GMT avoids a problem in some timezones with kerberos. Both MIT
33 # heimdal can get mutual authentication errors due to the 24 second difference
34 # between UTC and GMT when using some zone files (eg. the PDT zone from
36 os.environ["TZ"] = "GMT"
38 # Find right directory when running from source tree
39 sys.path.insert(0, "bin/python")
43 from samba import getopt as options
44 from ldb import SCOPE_BASE
45 from samba import dsdb
46 from samba.auth import system_session
47 from samba.samdb import SamDB
48 from samba.dcerpc import netlogon, winbind
49 from samba.netcmd.dns import cmd_dns
50 from samba import gensec
52 samba.ensure_third_party_module("dns", "dnspython")
60 parser = optparse.OptionParser("samba_dnsupdate")
61 sambaopts = options.SambaOptions(parser)
62 parser.add_option_group(sambaopts)
63 parser.add_option_group(options.VersionOptions(parser))
64 parser.add_option("--verbose", action="store_true")
65 parser.add_option("--use-samba-tool", action="store_true", help="Use samba-tool to make updates over RPC, rather than over DNS")
66 parser.add_option("--use-nsupdate", action="store_true", help="Use nsupdate command to make updates over DNS (default, if kinit successful)")
67 parser.add_option("--all-names", action="store_true")
68 parser.add_option("--all-interfaces", action="store_true")
69 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=)")
70 parser.add_option("--rpc-server-ip", type="string", help="IP address of server to use with samba-tool (defaults to first --current-ip)")
71 parser.add_option("--use-file", type="string", help="Use a file, rather than real DNS calls")
72 parser.add_option("--add-ns", action="store_true", help="Add an NS record to the DNS file for self-tests. Can only be used with --use-file")
73 parser.add_option("--update-list", type="string", help="Add DNS names from the given file")
74 parser.add_option("--update-cache", type="string", help="Cache database of already registered records")
75 parser.add_option("--fail-immediately", action='store_true', help="Exit on first failure")
76 parser.add_option("--no-credentials", dest='nocreds', action='store_true', help="don't try and get credentials")
77 parser.add_option("--no-substitutions", dest='nosubs', action='store_true', help="don't try and expands variables in file specified by --update-list")
82 opts, args = parser.parse_args()
88 lp = sambaopts.get_loadparm()
90 domain = lp.get("realm")
91 host = lp.get("netbios name")
92 if opts.all_interfaces:
95 all_interfaces = False
100 IPs = samba.interface_ips(lp, all_interfaces)
102 nsupdate_cmd = lp.get('nsupdate command')
105 print "No IP interfaces - skipping DNS updates"
108 if opts.rpc_server_ip:
109 rpc_server_ip = opts.rpc_server_ip
111 rpc_server_ip = IPs[0]
116 if i.find(':') != -1:
123 print "IPs: %s" % IPs
126 def get_credentials(lp):
127 """# get credentials if we haven't got them already."""
128 from samba import credentials
130 creds = credentials.Credentials()
132 creds.set_machine_account(lp)
133 creds.set_krb_forwardable(credentials.NO_KRB_FORWARDABLE)
134 (tmp_fd, ccachename) = tempfile.mkstemp()
136 creds.get_named_ccache(lp, ccachename)
138 if opts.use_file is not None:
141 # Now confirm we can get a ticket to a DNS server
142 ans = check_one_dns_name(sub_vars['DNSDOMAIN'] + '.', 'NS')
143 for i in range(len(ans)):
144 target_hostname = str(ans[i].target).rstrip('.')
146 settings["lp_ctx"] = lp
147 settings["target_hostname"] = target_hostname
149 gensec_client = gensec.Security.start_client(settings)
150 gensec_client.set_credentials(creds)
151 gensec_client.set_target_service("DNS")
152 gensec_client.set_target_hostname(target_hostname)
153 gensec_client.want_feature(gensec.FEATURE_SEAL)
154 gensec_client.start_mech_by_sasl_name("GSSAPI")
155 server_to_client = ""
157 (client_finished, client_to_server) = gensec_client.update(server_to_client)
159 print "Successfully obtained Kerberos ticket to DNS/%s as %s" \
160 % (target_hostname, creds.get_username())
163 # Only raise an exception if they all failed
164 if i != len(ans) - 1:
168 except RuntimeError as e:
169 os.unlink(ccachename)
173 class dnsobj(object):
174 """an object to hold a parsed DNS line"""
176 def __init__(self, string_form):
177 list = string_form.split()
179 raise Exception("Invalid DNS entry %r" % string_form)
183 self.existing_port = None
184 self.existing_weight = None
185 self.existing_cname_target = None
194 self.nameservers = []
195 if self.type == 'SRV':
197 raise Exception("Invalid DNS entry %r" % string_form)
200 elif self.type in ['A', 'AAAA']:
201 self.ip = list[2] # usually $IP, which gets replaced
202 elif self.type == 'CNAME':
204 elif self.type == 'NS':
207 raise Exception("Received unexpected DNS reply of type %s: %s" % (self.type, string_form))
211 return "%s %s %s" % (self.type, self.name, self.ip)
212 if self.type == "AAAA":
213 return "%s %s %s" % (self.type, self.name, self.ip)
214 if self.type == "SRV":
215 return "%s %s %s %s" % (self.type, self.name, self.dest, self.port)
216 if self.type == "CNAME":
217 return "%s %s %s" % (self.type, self.name, self.dest)
218 if self.type == "NS":
219 return "%s %s %s" % (self.type, self.name, self.dest)
222 def parse_dns_line(line, sub_vars):
223 """parse a DNS line from."""
224 if line.startswith("SRV _ldap._tcp.pdc._msdcs.") and not samdb.am_pdc():
225 # We keep this as compat to the dns_update_list of 4.0/4.1
227 print "Skipping PDC entry (%s) as we are not a PDC" % line
229 subline = samba.substitute_var(line, sub_vars)
230 if subline == '' or subline[0] == "#":
232 return dnsobj(subline)
235 def hostname_match(h1, h2):
236 """see if two hostnames match."""
239 return h1.lower().rstrip('.') == h2.lower().rstrip('.')
241 def check_one_dns_name(name, name_type, d=None):
242 resolv_conf = os.getenv('RESOLV_CONF')
244 resolv_conf = '/etc/resolv.conf'
245 resolver = dns.resolver.Resolver(filename=resolv_conf, configure=True)
247 if d is not None and d.nameservers != []:
248 resolver.nameservers = d.nameservers
250 d.nameservers = resolver.nameservers
252 ans = resolver.query(name, name_type)
255 def check_dns_name(d):
256 """check that a DNS entry exists."""
257 normalised_name = d.name.rstrip('.') + '.'
259 print "Looking for DNS entry %s as %s" % (d, normalised_name)
261 if opts.use_file is not None:
263 dns_file = open(opts.use_file, "r")
267 for line in dns_file:
269 if line == '' or line[0] == "#":
271 if line.lower() == str(d).lower():
276 ans = check_one_dns_name(normalised_name, d.type, d)
277 except dns.exception.Timeout:
278 raise Exception("Timeout while waiting to contact a working DNS server while looking for %s as %s" % (d, normalised_name))
279 except dns.resolver.NoNameservers:
280 raise Exception("Unable to contact a working DNS server while looking for %s as %s" % (d, normalised_name))
281 except dns.resolver.NXDOMAIN:
283 print "The DNS entry %s, queried as %s does not exist" % (d, normalised_name)
285 except dns.resolver.NoAnswer:
287 print "The DNS entry %s, queried as %s does not hold this record type" % (d, normalised_name)
289 except dns.exception.DNSException:
290 raise Exception("Failure while trying to resolve %s as %s" % (d, normalised_name))
291 if d.type in ['A', 'AAAA']:
292 # we need to be sure that our IP is there
294 if str(rdata) == str(d.ip):
296 elif d.type == 'CNAME':
297 for i in range(len(ans)):
298 if hostname_match(ans[i].target, d.dest):
301 d.existing_cname_target = str(ans[i].target)
303 for i in range(len(ans)):
304 if hostname_match(ans[i].target, d.dest):
306 elif d.type == 'SRV':
309 print "Checking %s against %s" % (rdata, d)
310 if hostname_match(rdata.target, d.dest):
311 if str(rdata.port) == str(d.port):
314 d.existing_port = str(rdata.port)
315 d.existing_weight = str(rdata.weight)
318 print "Lookup of %s succeeded, but we failed to find a matching DNS entry for %s" % (normalised_name, d)
323 def get_subst_vars(samdb):
324 """get the list of substitution vars."""
328 vars['DNSDOMAIN'] = samdb.domain_dns_name()
329 vars['DNSFOREST'] = samdb.forest_dns_name()
330 vars['HOSTNAME'] = samdb.host_dns_name()
331 vars['NTDSGUID'] = samdb.get_ntds_GUID()
332 vars['SITE'] = samdb.server_site_name()
333 res = samdb.search(base=samdb.get_default_basedn(), scope=SCOPE_BASE, attrs=["objectGUID"])
334 guid = samdb.schema_format_value("objectGUID", res[0]['objectGUID'][0])
335 vars['DOMAINGUID'] = guid
338 vars['IF_RWDC'] = "# "
339 vars['IF_RODC'] = "# "
340 vars['IF_PDC'] = "# "
342 vars['IF_RWGC'] = "# "
343 vars['IF_ROGC'] = "# "
344 vars['IF_DNS_DOMAIN'] = "# "
345 vars['IF_RWDNS_DOMAIN'] = "# "
346 vars['IF_RODNS_DOMAIN'] = "# "
347 vars['IF_DNS_FOREST'] = "# "
348 vars['IF_RWDNS_FOREST'] = "# "
349 vars['IF_R0DNS_FOREST'] = "# "
351 am_rodc = samdb.am_rodc()
360 # check if we "are DNS server"
361 res = samdb.search(base=samdb.get_config_basedn(),
362 expression='(objectguid=%s)' % vars['NTDSGUID'],
363 attrs=["options", "msDS-hasMasterNCs"])
366 if "options" in res[0]:
367 options = int(res[0]["options"][0])
368 if (options & dsdb.DS_NTDSDSA_OPT_IS_GC) != 0:
375 basedn = str(samdb.get_default_basedn())
376 forestdn = str(samdb.get_root_basedn())
378 if "msDS-hasMasterNCs" in res[0]:
379 for e in res[0]["msDS-hasMasterNCs"]:
380 if str(e) == "DC=DomainDnsZones,%s" % basedn:
381 vars['IF_DNS_DOMAIN'] = ""
383 vars['IF_RODNS_DOMAIN'] = ""
385 vars['IF_RWDNS_DOMAIN'] = ""
386 if str(e) == "DC=ForestDnsZones,%s" % forestdn:
387 vars['IF_DNS_FOREST'] = ""
389 vars['IF_RODNS_FOREST'] = ""
391 vars['IF_RWDNS_FOREST'] = ""
396 def call_nsupdate(d, op="add"):
397 """call nsupdate for an entry."""
398 global ccachename, nsupdate_cmd, krb5conf
400 assert(op in ["add", "delete"])
403 print "Calling nsupdate for %s (%s)" % (d, op)
405 if opts.use_file is not None:
407 rfile = open(opts.use_file, 'r+')
410 rfile = open(opts.use_file, 'w+')
411 # Open it for reading again, in case someone else got to it first
412 rfile = open(opts.use_file, 'r+')
413 fcntl.lockf(rfile, fcntl.LOCK_EX)
414 (file_dir, file_name) = os.path.split(opts.use_file)
415 (tmp_fd, tmpfile) = tempfile.mkstemp(dir=file_dir, prefix=file_name, suffix="XXXXXX")
416 wfile = os.fdopen(tmp_fd, 'a')
420 l = parse_dns_line(line, {})
421 if str(l).lower() == str(d).lower():
425 wfile.write(str(d)+"\n")
426 os.rename(tmpfile, opts.use_file)
427 fcntl.lockf(rfile, fcntl.LOCK_UN)
430 normalised_name = d.name.rstrip('.') + '.'
432 (tmp_fd, tmpfile) = tempfile.mkstemp()
433 f = os.fdopen(tmp_fd, 'w')
434 if d.nameservers != []:
435 f.write('server %s\n' % d.nameservers[0])
437 f.write("update %s %s %u A %s\n" % (op, normalised_name, default_ttl, d.ip))
439 f.write("update %s %s %u AAAA %s\n" % (op, normalised_name, default_ttl, d.ip))
441 if op == "add" and d.existing_port is not None:
442 f.write("update delete %s SRV 0 %s %s %s\n" % (normalised_name, d.existing_weight,
443 d.existing_port, d.dest))
444 f.write("update %s %s %u SRV 0 100 %s %s\n" % (op, normalised_name, default_ttl, d.port, d.dest))
445 if d.type == "CNAME":
446 f.write("update %s %s %u CNAME %s\n" % (op, normalised_name, default_ttl, d.dest))
448 f.write("update %s %s %u NS %s\n" % (op, normalised_name, default_ttl, d.dest))
454 # Set a bigger MTU size to work around a bug in nsupdate's doio_send()
455 os.environ["SOCKET_WRAPPER_MTU"] = "2000"
459 os.environ["KRB5CCNAME"] = ccachename
461 cmd = nsupdate_cmd[:]
465 env["KRB5_CONFIG"] = krb5conf
467 env["KRB5CCNAME"] = ccachename
468 ret = subprocess.call(cmd, shell=False, env=env)
470 if opts.fail_immediately:
472 print("Failed update with %s" % tmpfile)
474 error_count = error_count + 1
476 print("Failed nsupdate: %d" % ret)
477 except Exception, estr:
478 if opts.fail_immediately:
480 error_count = error_count + 1
482 print("Failed nsupdate: %s : %s" % (str(d), estr))
485 # Let socket_wrapper set the default MTU size
486 os.environ["SOCKET_WRAPPER_MTU"] = "0"
489 def call_samba_tool(d, op="add", zone=None):
490 """call samba-tool dns to update an entry."""
492 assert(op in ["add", "delete"])
494 if (sub_vars['DNSFOREST'] != sub_vars['DNSDOMAIN']) and \
495 sub_vars['DNSFOREST'].endswith('.' + sub_vars['DNSDOMAIN']):
496 print "Refusing to use samba-tool when forest %s is under domain %s" \
497 % (sub_vars['DNSFOREST'], sub_vars['DNSDOMAIN'])
500 print "Calling samba-tool dns for %s (%s)" % (d, op)
502 normalised_name = d.name.rstrip('.') + '.'
504 if normalised_name == (sub_vars['DNSDOMAIN'] + '.'):
506 zone = sub_vars['DNSDOMAIN']
507 elif normalised_name == (sub_vars['DNSFOREST'] + '.'):
509 zone = sub_vars['DNSFOREST']
510 elif normalised_name == ('_msdcs.' + sub_vars['DNSFOREST'] + '.'):
512 zone = '_msdcs.' + sub_vars['DNSFOREST']
514 if not normalised_name.endswith('.' + sub_vars['DNSDOMAIN'] + '.'):
515 print "Not Calling samba-tool dns for %s (%s), %s not in %s" % (d, op, normalised_name, sub_vars['DNSDOMAIN'] + '.')
517 elif normalised_name.endswith('._msdcs.' + sub_vars['DNSFOREST'] + '.'):
518 zone = '_msdcs.' + sub_vars['DNSFOREST']
520 zone = sub_vars['DNSDOMAIN']
521 len_zone = len(zone)+2
522 short_name = normalised_name[:-len_zone]
524 len_zone = len(zone)+2
525 short_name = normalised_name[:-len_zone]
528 args = [rpc_server_ip, zone, short_name, "A", d.ip]
530 args = [rpc_server_ip, zone, short_name, "AAAA", d.ip]
532 if op == "add" and d.existing_port is not None:
533 print "Not handling modify of exising SRV %s using samba-tool" % d
536 args = [rpc_server_ip, zone, short_name, "SRV",
537 "%s %s %s %s" % (d.existing_weight,
538 d.existing_port, "0", "100"),
539 "%s %s %s %s" % (d.dest, d.port, "0", "100")]
541 args = [rpc_server_ip, zone, short_name, "SRV", "%s %s %s %s" % (d.dest, d.port, "0", "100")]
542 if d.type == "CNAME":
543 if d.existing_cname_target is None:
544 args = [rpc_server_ip, zone, short_name, "CNAME", d.dest]
547 args = [rpc_server_ip, zone, short_name, "CNAME",
548 d.existing_cname_target.rstrip('.'), d.dest]
551 args = [rpc_server_ip, zone, short_name, "NS", d.dest]
557 print "Calling samba-tool dns %s -k no -P %s" % (op, args)
558 cmd._run("dns", op, "-k", "no", "-P", *args)
559 except Exception, estr:
561 if opts.fail_immediately:
563 error_count = error_count + 1
565 print("Failed 'samba-tool dns' based update: %s : %s" % (str(d), estr))
567 def rodc_dns_update(d, t, op):
568 '''a single DNS update via the RODC netlogon call'''
571 assert(op in ["add", "delete"])
574 print "Calling netlogon RODC update for %s" % d
577 netlogon.NlDnsLdapAtSite : netlogon.NlDnsInfoTypeNone,
578 netlogon.NlDnsGcAtSite : netlogon.NlDnsDomainNameAlias,
579 netlogon.NlDnsDsaCname : netlogon.NlDnsDomainNameAlias,
580 netlogon.NlDnsKdcAtSite : netlogon.NlDnsInfoTypeNone,
581 netlogon.NlDnsDcAtSite : netlogon.NlDnsInfoTypeNone,
582 netlogon.NlDnsRfc1510KdcAtSite : netlogon.NlDnsInfoTypeNone,
583 netlogon.NlDnsGenericGcAtSite : netlogon.NlDnsDomainNameAlias
586 w = winbind.winbind("irpc:winbind_server", lp)
587 dns_names = netlogon.NL_DNS_NAME_INFO_ARRAY()
589 name = netlogon.NL_DNS_NAME_INFO()
591 name.dns_domain_info_type = typemap[t]
594 if d.port is not None:
595 name.port = int(d.port)
597 name.dns_register = True
599 name.dns_register = False
600 dns_names.names = [ name ]
601 site_name = sub_vars['SITE'].decode('utf-8')
606 ret_names = w.DsrUpdateReadOnlyServerDnsRecords(site_name, default_ttl, dns_names)
607 if ret_names.names[0].status != 0:
608 print("Failed to set DNS entry: %s (status %u)" % (d, ret_names.names[0].status))
609 error_count = error_count + 1
610 except RuntimeError, reason:
611 print("Error setting DNS entry of type %u: %s: %s" % (t, d, reason))
612 error_count = error_count + 1
614 if error_count != 0 and opts.fail_immediately:
618 def call_rodc_update(d, op="add"):
619 '''RODCs need to use the netlogon API for nsupdate'''
622 assert(op in ["add", "delete"])
624 # we expect failure for 3268 if we aren't a GC
625 if d.port is not None and int(d.port) == 3268:
628 # map the DNS request to a netlogon update type
630 netlogon.NlDnsLdapAtSite : '_ldap._tcp.${SITE}._sites.${DNSDOMAIN}',
631 netlogon.NlDnsGcAtSite : '_ldap._tcp.${SITE}._sites.gc._msdcs.${DNSDOMAIN}',
632 netlogon.NlDnsDsaCname : '${NTDSGUID}._msdcs.${DNSFOREST}',
633 netlogon.NlDnsKdcAtSite : '_kerberos._tcp.${SITE}._sites.dc._msdcs.${DNSDOMAIN}',
634 netlogon.NlDnsDcAtSite : '_ldap._tcp.${SITE}._sites.dc._msdcs.${DNSDOMAIN}',
635 netlogon.NlDnsRfc1510KdcAtSite : '_kerberos._tcp.${SITE}._sites.${DNSDOMAIN}',
636 netlogon.NlDnsGenericGcAtSite : '_gc._tcp.${SITE}._sites.${DNSFOREST}'
640 subname = samba.substitute_var(map[t], sub_vars)
641 if subname.lower() == d.name.lower():
642 # found a match - do the update
643 rodc_dns_update(d, t, op)
646 print("Unable to map to netlogon DNS update: %s" % d)
649 # get the list of DNS entries we should have
651 dns_update_list = opts.update_list
653 dns_update_list = lp.private_path('dns_update_list')
655 if opts.update_cache:
656 dns_update_cache = opts.update_cache
658 dns_update_cache = lp.private_path('dns_update_cache')
660 # use our private krb5.conf to avoid problems with the wrong domain
661 # bind9 nsupdate wants the default domain set
662 krb5conf = lp.private_path('krb5.conf')
663 os.environ['KRB5_CONFIG'] = krb5conf
665 file = open(dns_update_list, "r")
670 samdb = SamDB(url=lp.samdb_url(), session_info=system_session(), lp=lp)
672 # get the substitution dictionary
673 sub_vars = get_subst_vars(samdb)
675 # build up a list of update commands to pass to nsupdate
684 rebuild_cache = False
686 # Add an NS line if asked to ...
688 if opts.use_file is None:
689 print "Option --add-ns can only be used with --use-file"
692 dns_list.append(parse_dns_line("NS ${DNSDOMAIN} ${HOSTNAME}", sub_vars))
695 cfile = open(dns_update_cache, 'r+')
698 cfile = open(dns_update_cache, 'w+')
699 # Open it for reading again, in case someone else got to it first
700 cfile = open(dns_update_cache, 'r+')
701 fcntl.lockf(cfile, fcntl.LOCK_EX)
704 if line == '' or line[0] == "#":
706 c = parse_dns_line(line, {})
709 if str(c) not in cache_set:
711 cache_set.add(str(c))
713 # read each line, and check that the DNS name exists
716 if line == '' or line[0] == "#":
718 d = parse_dns_line(line, sub_vars)
721 if d.type == 'A' and len(IP4s) == 0:
723 if d.type == 'AAAA' and len(IP6s) == 0:
725 if str(d) not in dup_set:
729 # now expand the entries, if any are A record with ip set to $IP
730 # then replace with multiple entries, one for each interface IP
736 for i in range(len(IP4s)-1):
742 for i in range(len(IP6s)-1):
747 # now check if the entries already exist on the DNS server
751 if str(c).lower() == str(d).lower():
757 update_list.append(d)
759 print "force update: %s" % d
760 elif not check_dns_name(d):
761 update_list.append(d)
763 print "need update: %s" % d
769 if str(c).lower() == str(d).lower():
775 if not opts.all_names and not check_dns_name(c):
777 delete_list.append(c)
779 print "need delete: %s" % c
781 if len(delete_list) == 0 and len(update_list) == 0 and not rebuild_cache:
783 print "No DNS updates needed"
787 print "%d DNS updates and %d DNS deletes needed" % (len(update_list), len(delete_list))
789 use_samba_tool = opts.use_samba_tool
790 use_nsupdate = opts.use_nsupdate
792 if len(delete_list) != 0 or len(update_list) != 0 and not opts.nocreds:
794 creds = get_credentials(lp)
795 except RuntimeError as e:
798 if sub_vars['IF_RWDNS_DOMAIN'] == "# ":
804 print "Failed to get Kerberos credentials, falling back to samba-tool: %s" % e
805 use_samba_tool = True
808 # ask nsupdate to delete entries as needed
809 for d in delete_list:
810 if d.rpc or (not use_nsupdate and use_samba_tool):
812 print "update (samba-tool): %s" % d
813 call_samba_tool(d, op="delete", zone=d.zone)
816 if d.name.lower() == domain.lower():
818 print "skip delete (rodc): %s" % d
820 if not d.type in [ 'A', 'AAAA' ]:
822 print "delete (rodc): %s" % d
823 call_rodc_update(d, op="delete")
826 print "delete (nsupdate): %s" % d
827 call_nsupdate(d, op="delete")
830 print "delete (nsupdate): %s" % d
831 call_nsupdate(d, op="delete")
833 # ask nsupdate to add entries as needed
834 for d in update_list:
835 if d.rpc or (not use_nsupdate and use_samba_tool):
837 print "update (samba-tool): %s" % d
838 call_samba_tool(d, zone=d.zone)
841 if d.name.lower() == domain.lower():
843 print "skip (rodc): %s" % d
845 if not d.type in [ 'A', 'AAAA' ]:
847 print "update (rodc): %s" % d
851 print "update (nsupdate): %s" % d
855 print "update(nsupdate): %s" % d
859 print "Rebuilding cache at %s" % dns_update_cache
860 (file_dir, file_name) = os.path.split(dns_update_cache)
861 (tmp_fd, tmpfile) = tempfile.mkstemp(dir=file_dir, prefix=file_name, suffix="XXXXXX")
862 wfile = os.fdopen(tmp_fd, 'a')
865 print "Adding %s to %s" % (str(d), file_name)
866 wfile.write(str(d)+"\n")
867 os.rename(tmpfile, dns_update_cache)
868 fcntl.lockf(cfile, fcntl.LOCK_UN)
870 # delete the ccache if we created it
871 if ccachename is not None:
872 os.unlink(ccachename)
875 print("Failed update of %u entries" % error_count)
876 sys.exit(error_count)