opts.format = "summary"
def print_header(txt):
- print "\n%s" % txt
- print "=" * len(txt)
+ print("\n%s" % txt)
+ print("=" * len(txt))
def print_samba3_policy(pol):
print_header("Account Policies")
- print "Min password length: %d" % pol['min password length']
- print "Password history length: %d" % pol['password history']
+ print("Min password length: %d" % pol['min password length'])
+ print("Password history length: %d" % pol['password history'])
if pol['user must logon to change password']:
- print "User must logon to change password: %d" % pol['user must logon to change password']
+ print("User must logon to change password: %d" % pol['user must logon to change password'])
if pol['maximum password age']:
- print "Maximum password age: %d" % pol['maximum password age']
+ print("Maximum password age: %d" % pol['maximum password age'])
if pol['minimum password age']:
- print "Minimum password age: %d" % pol['minimum password age']
+ print("Minimum password age: %d" % pol['minimum password age'])
if pol['lockout duration']:
- print "Lockout duration: %d" % pol['lockout duration']
+ print("Lockout duration: %d" % pol['lockout duration'])
if pol['reset count minutes']:
- print "Reset Count Minutes: %d" % pol['reset count minutes']
+ print("Reset Count Minutes: %d" % pol['reset count minutes'])
if pol['bad lockout attempt']:
- print "Bad Lockout Minutes: %d" % pol['bad lockout attempt']
+ print("Bad Lockout Minutes: %d" % pol['bad lockout attempt'])
if pol['disconnect time']:
- print "Disconnect Time: %d" % pol['disconnect time']
+ print("Disconnect Time: %d" % pol['disconnect time'])
if pol['refuse machine password change']:
- print "Refuse Machine Password Change: %d" % pol['refuse machine password change']
+ print("Refuse Machine Password Change: %d" % pol['refuse machine password change'])
def print_samba3_sam(samdb):
print_header("SAM Database")
for user in samdb.search_users(0):
- print "%s (%d): %s" % (user['account_name'], user['rid'], user['fullname'])
+ print("%s (%d): %s" % (user['account_name'], user['rid'], user['fullname']))
def print_samba3_shares(lp):
print_header("Configured shares")
for s in lp.services():
- print "--- %s ---" % s
+ print("--- %s ---" % s)
for p in ['path']:
- print "\t%s = %s" % (p, lp.get(p, s))
- print ""
+ print("\t%s = %s" % (p, lp.get(p, s)))
+ print("")
def print_samba3_secrets(secrets):
print_header("Secrets")
if secrets.get_auth_user():
- print "IPC Credentials:"
+ print("IPC Credentials:")
if secrets.get_auth_user():
- print " User: %s\n" % secrets.get_auth_user()
+ print(" User: %s\n" % secrets.get_auth_user())
if secrets.get_auth_password():
- print " Password: %s\n" % secrets.get_auth_password()
+ print(" Password: %s\n" % secrets.get_auth_password())
if secrets.get_auth_domain():
- print " Domain: %s\n" % secrets.get_auth_domain()
+ print(" Domain: %s\n" % secrets.get_auth_domain())
if len(list(secrets.ldap_dns())) > 0:
- print "LDAP passwords:"
+ print("LDAP passwords:")
for dn in secrets.ldap_dns():
- print "\t%s -> %s" % (dn, secrets.get_ldap_bind_pw(dn))
- print ""
+ print("\t%s -> %s" % (dn, secrets.get_ldap_bind_pw(dn)))
+ print("")
- print "Domains:"
+ print("Domains:")
for domain in secrets.domains():
- print "\t--- %s ---" % domain
- print "\tSID: %s" % secrets.get_sid(domain)
- print "\tGUID: %s" % secrets.get_domain_guid(domain)
- print "\tPlaintext pwd: %s" % secrets.get_machine_password(domain)
+ print("\t--- %s ---" % domain)
+ print("\tSID: %s" % secrets.get_sid(domain))
+ print("\tGUID: %s" % secrets.get_domain_guid(domain))
+ print("\tPlaintext pwd: %s" % secrets.get_machine_password(domain))
if secrets.get_machine_last_change_time(domain):
- print "\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain)
+ print("\tLast Changed: %lu" % secrets.get_machine_last_change_time(domain))
if secrets.get_machine_sec_channel_type(domain):
- print "\tSecure Channel Type: %d\n" % secrets.get_machine_sec_channel_type(domain)
+ print("\tSecure Channel Type: %d\n" % secrets.get_machine_sec_channel_type(domain))
- print "Trusted domains:"
+ print("Trusted domains:")
for td in secrets.trusted_domains():
- print td
+ print(td)
def print_samba3_regdb(regdb):
print_header("Registry")
from samba.registry import str_regtype
for k in regdb.keys():
- print "[%s]" % k
+ print("[%s]" % k)
for (value_name, (type, value)) in regdb.values(k).items():
- print "\"%s\"=%s:%s" % (value_name, str_regtype(type), value)
+ print("\"%s\"=%s:%s" % (value_name, str_regtype(type), value))
def print_samba3_winsdb(winsdb):
print_header("WINS Database")
for name in winsdb:
(ttl, ips, nb_flags) = winsdb[name]
- print "%s, nb_flags: %s, ttl: %lu, %d ips, fst: %s" % (name, nb_flags, ttl, len(ips), ips[0])
+ print("%s, nb_flags: %s, ttl: %lu, %d ips, fst: %s" % (name, nb_flags, ttl, len(ips), ips[0]))
def print_samba3_groupmappings(groupdb):
print_header("Group Mappings")
for g in groupdb.enum_group_mapping(samba.samba3.passdb.get_global_sam_sid(),
lsa.SID_NAME_DOM_GRP):
- print "\t--- Group: %s ---" % g.sid
+ print("\t--- Group: %s ---" % g.sid)
def print_samba3_aliases(groupdb):
for g in groupdb.enum_group_mapping(samba.samba3.passdb.get_global_sam_sid(),
lsa.SID_NAME_ALIAS):
- print "\t--- Alias: %s ---" % g.sid
+ print("\t--- Alias: %s ---" % g.sid)
def print_samba3_idmapdb(idmapdb):
print_header("Winbindd SID<->GID/UID mappings")
- print "User High Water Mark: %d" % idmapdb.get_user_hwm()
- print "Group High Water Mark: %d\n" % idmapdb.get_group_hwm()
+ print("User High Water Mark: %d" % idmapdb.get_user_hwm())
+ print("Group High Water Mark: %d\n" % idmapdb.get_group_hwm())
for uid in idmapdb.uids():
- print "%s -> UID %d" % (idmapdb.get_user_sid(uid), uid)
+ print("%s -> UID %d" % (idmapdb.get_user_sid(uid), uid))
for gid in idmapdb.gids():
- print "%s -> GID %d" % (idmapdb.get_group_sid(gid), gid)
+ print("%s -> GID %d" % (idmapdb.get_group_sid(gid), gid))
def print_samba3(samba3):
passdb = samba3.get_sam_db()
print_samba3_shares(samba3.lp)
def print_samba3_summary(samba3):
- print "WINS db entries: %d" % len(samba3.get_wins_db())
- print "Registry key count: %d" % len(samba3.get_registry())
+ print("WINS db entries: %d" % len(samba3.get_wins_db()))
+ print("Registry key count: %d" % len(samba3.get_registry()))
passdb = samba3.get_sam_db()
- print "Groupmap count: %d" % len(passdb.enum_group_mapping())
- print "Alias count: %d" % len(passdb.search_aliases())
+ print("Groupmap count: %d" % len(passdb.enum_group_mapping()))
+ print("Alias count: %d" % len(passdb.search_aliases()))
idmapdb = samba3.get_idmap_db()
- print "Idmap count: %d" % (len(list(idmapdb.uids())) + len(list(idmapdb.gids())))
+ print("Idmap count: %d" % (len(list(idmapdb.uids())) + len(list(idmapdb.gids()))))
if len(args) < 1:
parser.print_help()
dns_zone_scavenging = lp.get("dns zone scavenging")
if len(IPs) == 0:
- print "No IP interfaces - skipping DNS updates"
+ print("No IP interfaces - skipping DNS updates")
sys.exit(0)
if opts.rpc_server_ip:
if opts.verbose:
- print "IPs: %s" % IPs
+ print("IPs: %s" % IPs)
def get_possible_rw_dns_server(creds, domain):
"""Get a list of possible read-write DNS servers, starting with
try:
(client_finished, client_to_server) = gensec_client.update(server_to_client)
if opts.verbose:
- print "Successfully obtained Kerberos ticket to DNS/%s as %s" \
- % (target_hostname, creds.get_username())
+ print("Successfully obtained Kerberos ticket to DNS/%s as %s" \
+ % (target_hostname, creds.get_username()))
return target_hostname
except RuntimeError:
# Only raise an exception if they all failed
if line.startswith("SRV _ldap._tcp.pdc._msdcs.") and not samdb.am_pdc():
# We keep this as compat to the dns_update_list of 4.0/4.1
if opts.verbose:
- print "Skipping PDC entry (%s) as we are not a PDC" % line
+ print("Skipping PDC entry (%s) as we are not a PDC" % line)
return None
subline = samba.substitute_var(line, sub_vars)
if subline == '' or subline[0] == "#":
"""check that a DNS entry exists."""
normalised_name = d.name.rstrip('.') + '.'
if opts.verbose:
- print "Looking for DNS entry %s as %s" % (d, normalised_name)
+ print("Looking for DNS entry %s as %s" % (d, normalised_name))
if opts.use_file is not None:
try:
raise Exception("Unable to contact a working DNS server while looking for %s as %s" % (d, normalised_name))
except dns.resolver.NXDOMAIN:
if opts.verbose:
- print "The DNS entry %s, queried as %s does not exist" % (d, normalised_name)
+ print("The DNS entry %s, queried as %s does not exist" % (d, normalised_name))
return False
except dns.resolver.NoAnswer:
if opts.verbose:
- print "The DNS entry %s, queried as %s does not hold this record type" % (d, normalised_name)
+ print("The DNS entry %s, queried as %s does not hold this record type" % (d, normalised_name))
return False
except dns.exception.DNSException:
raise Exception("Failure while trying to resolve %s as %s" % (d, normalised_name))
elif d.type == 'SRV':
for rdata in ans:
if opts.verbose:
- print "Checking %s against %s" % (rdata, d)
+ print("Checking %s against %s" % (rdata, d))
if hostname_match(rdata.target, d.dest):
if str(rdata.port) == str(d.port):
return True
d.existing_weight = str(rdata.weight)
if opts.verbose:
- print "Lookup of %s succeeded, but we failed to find a matching DNS entry for %s" % (normalised_name, d)
+ print("Lookup of %s succeeded, but we failed to find a matching DNS entry for %s" % (normalised_name, d))
return False
assert(op in ["add", "delete"])
if opts.verbose:
- print "Calling nsupdate for %s (%s)" % (d, op)
+ print("Calling nsupdate for %s (%s)" % (d, op))
if opts.use_file is not None:
try:
if (sub_vars['DNSFOREST'] != sub_vars['DNSDOMAIN']) and \
sub_vars['DNSFOREST'].endswith('.' + sub_vars['DNSDOMAIN']):
- print "Refusing to use samba-tool when forest %s is under domain %s" \
- % (sub_vars['DNSFOREST'], sub_vars['DNSDOMAIN'])
+ print("Refusing to use samba-tool when forest %s is under domain %s" \
+ % (sub_vars['DNSFOREST'], sub_vars['DNSDOMAIN']))
if opts.verbose:
- print "Calling samba-tool dns for %s (%s)" % (d, op)
+ print("Calling samba-tool dns for %s (%s)" % (d, op))
normalised_name = d.name.rstrip('.') + '.'
if zone is None:
zone = '_msdcs.' + sub_vars['DNSFOREST']
else:
if not normalised_name.endswith('.' + sub_vars['DNSDOMAIN'] + '.'):
- print "Not Calling samba-tool dns for %s (%s), %s not in %s" % (d, op, normalised_name, sub_vars['DNSDOMAIN'] + '.')
+ print("Not Calling samba-tool dns for %s (%s), %s not in %s" % (d, op, normalised_name, sub_vars['DNSDOMAIN'] + '.'))
return False
elif normalised_name.endswith('._msdcs.' + sub_vars['DNSFOREST'] + '.'):
zone = '_msdcs.' + sub_vars['DNSFOREST']
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
+ print("Not handling modify of exising SRV %s using samba-tool" % d)
return False
op = "update"
args = [rpc_server_ip, zone, short_name, "SRV",
try:
cmd = cmd_dns()
if opts.verbose:
- print "Calling samba-tool dns %s -k no -P %s" % (op, args)
+ print("Calling samba-tool dns %s -k no -P %s" % (op, args))
ret = cmd._run("dns", op, "-k", "no", "-P", *args)
if ret == -1:
if opts.fail_immediately:
assert(op in ["add", "delete"])
if opts.verbose:
- print "Calling netlogon RODC update for %s" % d
+ print("Calling netlogon RODC update for %s" % d)
typemap = {
netlogon.NlDnsLdapAtSite : netlogon.NlDnsInfoTypeNone,
if not found:
rebuild_cache = True
if opts.verbose:
- print "need cache add: %s" % d
+ print("need cache add: %s" % d)
if dns_zone_scavenging:
update_list.append(d)
if opts.verbose:
- print "scavenging requires update: %s" % d
+ print("scavenging requires update: %s" % d)
elif opts.all_names:
update_list.append(d)
if opts.verbose:
- print "force update: %s" % d
+ print("force update: %s" % d)
elif not check_dns_name(d):
update_list.append(d)
if opts.verbose:
- print "need update: %s" % d
+ print("need update: %s" % d)
for c in cache_list:
found = False
continue
rebuild_cache = True
if opts.verbose:
- print "need cache remove: %s" % c
+ print("need cache remove: %s" % c)
if not opts.all_names and not check_dns_name(c):
continue
delete_list.append(c)
if opts.verbose:
- print "need delete: %s" % c
+ print("need delete: %s" % c)
if len(delete_list) == 0 and len(update_list) == 0 and not rebuild_cache:
if opts.verbose:
- print "No DNS updates needed"
+ print("No DNS updates needed")
sys.exit(0)
else:
if opts.verbose:
- print "%d DNS updates and %d DNS deletes needed" % (len(update_list), len(delete_list))
+ print("%d DNS updates and %d DNS deletes needed" % (len(update_list), len(delete_list)))
use_samba_tool = opts.use_samba_tool
use_nsupdate = opts.use_nsupdate
if use_nsupdate:
raise
- print "Failed to get Kerberos credentials, falling back to samba-tool: %s" % e
+ print("Failed to get Kerberos credentials, falling back to samba-tool: %s" % e)
use_samba_tool = True
for d in delete_list:
if d.rpc or (not use_nsupdate and use_samba_tool):
if opts.verbose:
- print "update (samba-tool): %s" % d
+ print("update (samba-tool): %s" % d)
call_samba_tool(d, op="delete", zone=d.zone)
elif am_rodc:
if d.name.lower() == domain.lower():
if opts.verbose:
- print "skip delete (rodc): %s" % d
+ print("skip delete (rodc): %s" % d)
continue
if not d.type in [ 'A', 'AAAA' ]:
if opts.verbose:
- print "delete (rodc): %s" % d
+ print("delete (rodc): %s" % d)
call_rodc_update(d, op="delete")
else:
if opts.verbose:
- print "delete (nsupdate): %s" % d
+ print("delete (nsupdate): %s" % d)
call_nsupdate(d, op="delete")
else:
if opts.verbose:
- print "delete (nsupdate): %s" % d
+ print("delete (nsupdate): %s" % d)
call_nsupdate(d, op="delete")
# ask nsupdate to add entries as needed
for d in update_list:
if d.rpc or (not use_nsupdate and use_samba_tool):
if opts.verbose:
- print "update (samba-tool): %s" % d
+ print("update (samba-tool): %s" % d)
call_samba_tool(d, zone=d.zone)
elif am_rodc:
if d.name.lower() == domain.lower():
if opts.verbose:
- print "skip (rodc): %s" % d
+ print("skip (rodc): %s" % d)
continue
if not d.type in [ 'A', 'AAAA' ]:
if opts.verbose:
- print "update (rodc): %s" % d
+ print("update (rodc): %s" % d)
call_rodc_update(d)
else:
if opts.verbose:
- print "update (nsupdate): %s" % d
+ print("update (nsupdate): %s" % d)
call_nsupdate(d)
else:
if opts.verbose:
- print "update(nsupdate): %s" % d
+ print("update(nsupdate): %s" % d)
call_nsupdate(d)
if rebuild_cache:
- print "Rebuilding cache at %s" % dns_update_cache
+ print("Rebuilding cache at %s" % dns_update_cache)
(file_dir, file_name) = os.path.split(dns_update_cache)
(tmp_fd, tmpfile) = tempfile.mkstemp(dir=file_dir, prefix=file_name, suffix="XXXXXX")
wfile = os.fdopen(tmp_fd, 'a')
for d in dns_list:
if opts.verbose:
- print "Adding %s to %s" % (str(d), file_name)
+ print("Adding %s to %s" % (str(d), file_name))
wfile.write(str(d)+"\n")
os.rename(tmpfile, dns_update_cache)
fcntl.lockf(cfile, fcntl.LOCK_UN)