From: Noel Power Date: Thu, 27 Sep 2018 17:15:49 +0000 (+0100) Subject: s4/scripting/bin: PY3 Make sure print statements are enclosed by '()' X-Git-Tag: tdb-1.3.17~1263 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5f8676b630e595532e188a559448478c0702ec7;p=thirdparty%2Fsamba.git s4/scripting/bin: PY3 Make sure print statements are enclosed by '()' Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett --- diff --git a/source4/scripting/bin/samba3dump b/source4/scripting/bin/samba3dump index a1a893a754e..2cb65f5ffd0 100755 --- a/source4/scripting/bin/samba3dump +++ b/source4/scripting/bin/samba3dump @@ -26,115 +26,115 @@ if opts.format is None: 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() @@ -149,13 +149,13 @@ def print_samba3(samba3): 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() diff --git a/source4/scripting/bin/samba_dnsupdate b/source4/scripting/bin/samba_dnsupdate index fda3beb631b..ccf44c5995d 100755 --- a/source4/scripting/bin/samba_dnsupdate +++ b/source4/scripting/bin/samba_dnsupdate @@ -105,7 +105,7 @@ nsupdate_cmd = lp.get('nsupdate command') 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: @@ -123,7 +123,7 @@ for i in IPs: 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 @@ -175,8 +175,8 @@ def get_krb5_rw_dns_server(creds, domain): 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 @@ -262,7 +262,7 @@ def parse_dns_line(line, sub_vars): 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] == "#": @@ -299,7 +299,7 @@ def check_dns_name(d): """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: @@ -323,11 +323,11 @@ def check_dns_name(d): 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)) @@ -349,7 +349,7 @@ def check_dns_name(d): 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 @@ -358,7 +358,7 @@ def check_dns_name(d): 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 @@ -443,7 +443,7 @@ def call_nsupdate(d, op="add"): 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: @@ -562,11 +562,11 @@ def call_samba_tool(d, op="add", zone=None): 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: @@ -581,7 +581,7 @@ def call_samba_tool(d, op="add", zone=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'] @@ -599,7 +599,7 @@ def call_samba_tool(d, op="add", zone=None): 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", @@ -623,7 +623,7 @@ def call_samba_tool(d, op="add", zone=None): 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: @@ -646,7 +646,7 @@ def rodc_dns_update(d, t, op): 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, @@ -848,19 +848,19 @@ for d in dns_list: 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 @@ -872,20 +872,20 @@ for c in cache_list: 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 @@ -902,7 +902,7 @@ if len(delete_list) != 0 or len(update_list) != 0 and not opts.nocreds: 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 @@ -910,60 +910,60 @@ if len(delete_list) != 0 or len(update_list) != 0 and not opts.nocreds: 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) diff --git a/source4/scripting/bin/samba_kcc b/source4/scripting/bin/samba_kcc index dd9630fe9c2..78cd0f46047 100755 --- a/source4/scripting/bin/samba_kcc +++ b/source4/scripting/bin/samba_kcc @@ -20,6 +20,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import print_function import os import sys @@ -278,7 +279,7 @@ if opts.now: pass else: # else happens if break doesn't --> no match - print >> sys.stderr, "could not parse time '%s'" % opts.now + print("could not parse time '%s'" % (opts.now), file = sys.stderr) sys.exit(1) unix_now = int(time.mktime(now_tuple)) else: @@ -328,7 +329,7 @@ if opts.test_all_reps_from: sys.exit() if opts.list_valid_dsas: - print '\n'.join(kcc.list_dsas()) + print('\n'.join(kcc.list_dsas())) sys.exit() try: @@ -338,5 +339,5 @@ try: sys.exit(rc) except GraphError as e: - print e + print( e) sys.exit(1) diff --git a/source4/scripting/bin/samba_spnupdate b/source4/scripting/bin/samba_spnupdate index 9bc85567186..8b84216fe6a 100755 --- a/source4/scripting/bin/samba_spnupdate +++ b/source4/scripting/bin/samba_spnupdate @@ -244,7 +244,7 @@ def call_rodc_update(d): req1.spn_names = spn_names (level, res) = drs.DsWriteAccountSpn(drs_handle, 1, req1) if (res.status != (0, 'WERR_OK')): - print "WriteAccountSpn has failed with error %s" % str(res.status) + print("WriteAccountSpn has failed with error %s" % str(res.status)) if samdb.am_rodc(): call_rodc_update(add_list) diff --git a/source4/scripting/bin/samba_upgradeprovision b/source4/scripting/bin/samba_upgradeprovision index df7a8e01721..20cd09fc240 100755 --- a/source4/scripting/bin/samba_upgradeprovision +++ b/source4/scripting/bin/samba_upgradeprovision @@ -308,13 +308,13 @@ def sanitychecks(samdb, names): scope=SCOPE_SUBTREE, attrs=["dn"], controls=["search_options:1:2"]) if len(res) == 0: - print "No DC found. Your provision is most probably broken!" + print("No DC found. Your provision is most probably broken!") return False elif len(res) != 1: - print "Found %d domain controllers. For the moment " \ + print("Found %d domain controllers. For the moment " \ "upgradeprovision is not able to handle an upgrade on a " \ "domain with more than one DC. Please demote the other " \ - "DC(s) before upgrading" % len(res) + "DC(s) before upgrading") % len(res) return False else: return True