From 458b7f9db5d4eb376213b61c9fe6fc3e1310fe4c Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 10 Apr 2018 15:28:59 +0100 Subject: [PATCH 01/57] python/samba: Port to py3 code exercised by samba.tests.dsdb_lock Signed-off-by: Noel Power --- python/samba/__init__.py | 1 - python/samba/idmap.py | 2 +- python/samba/ms_display_specifiers.py | 3 +- python/samba/ms_schema.py | 3 +- python/samba/provision/__init__.py | 58 ++++++++++++++++++----------------- python/samba/provision/sambadns.py | 12 ++++---- python/samba/samdb.py | 4 +-- python/samba/schema.py | 7 +++-- 8 files changed, 47 insertions(+), 43 deletions(-) diff --git a/python/samba/__init__.py b/python/samba/__init__.py index 20c7db2bc6c..1ae26cb2268 100644 --- a/python/samba/__init__.py +++ b/python/samba/__init__.py @@ -248,7 +248,6 @@ def substitute_var(text, values): :param text: Text in which to subsitute. :param values: Dictionary with keys and values. """ - for (name, value) in values.items(): assert isinstance(name, string_types), "%r is not a string" % name assert isinstance(value, string_types), "Value %r for %s is not a string" % (value, name) diff --git a/python/samba/idmap.py b/python/samba/idmap.py index 0cb729fbc29..a618347fa21 100644 --- a/python/samba/idmap.py +++ b/python/samba/idmap.py @@ -95,4 +95,4 @@ def setup_name_mapping(self, sid, type, unixid=None): cn: %s """ % (sid, unixid, sid, type_string, sid) - self.add(self.parse_ldif(mod).next()[1]) + self.add(next(self.parse_ldif(mod))[1]) diff --git a/python/samba/ms_display_specifiers.py b/python/samba/ms_display_specifiers.py index 0d7b39aaae9..3cba837c652 100644 --- a/python/samba/ms_display_specifiers.py +++ b/python/samba/ms_display_specifiers.py @@ -169,7 +169,8 @@ def read_ms_ldif(filename): out = [] - f = open(filename, "rU") + from io import open + f = open(filename, "r", encoding='latin-1') for entry in __read_raw_entries(f): out.append(__write_ldif_one(__transform_entry(entry))) diff --git a/python/samba/ms_schema.py b/python/samba/ms_schema.py index de6e4b28cdc..8961a22cdcf 100644 --- a/python/samba/ms_schema.py +++ b/python/samba/ms_schema.py @@ -287,8 +287,9 @@ def __parse_schema_file(filename, objectClass): """Load and transform a schema file.""" out = [] + from io import open + f = open(filename, "r", encoding='latin-1') - f = open(filename, "rU") for entry in __read_raw_entries(f): out.append(__write_ldif_one(__transform_entry(entry, objectClass))) diff --git a/python/samba/provision/__init__.py b/python/samba/provision/__init__.py index 43ccb0f8766..824277bfcd0 100644 --- a/python/samba/provision/__init__.py +++ b/python/samba/provision/__init__.py @@ -25,7 +25,8 @@ """Functions for setting up a Samba configuration.""" __docformat__ = "restructuredText" - +from samba.compat import string_types +from samba.compat import urllib_quote from base64 import b64encode import errno import os @@ -37,7 +38,6 @@ import time import uuid import socket -import urllib import string import tempfile import samba.dsdb @@ -1070,7 +1070,7 @@ def setup_encrypted_secrets_key(path): finally: os.umask(umask_original) - with os.fdopen(fd, 'w') as f: + with os.fdopen(fd, 'wb') as f: key = samba.generate_random_bytes(16) f.write(key) @@ -1144,7 +1144,7 @@ def setup_self_join(samdb, admin_session_info, names, fill, machinepass, "INVOCATIONID": invocationid, "NETBIOSNAME": names.netbiosname, "DNSNAME": "%s.%s" % (names.hostname, names.dnsdomain), - "MACHINEPASS_B64": b64encode(machinepass.encode('utf-16-le')), + "MACHINEPASS_B64": b64encode(machinepass.encode('utf-16-le')).decode('utf8'), "DOMAINSID": str(domainsid), "DCRID": str(dc_rid), "SAMBA_VERSION_STRING": version, @@ -1171,7 +1171,7 @@ def setup_self_join(samdb, admin_session_info, names, fill, machinepass, "INVOCATIONID": invocationid, "NETBIOSNAME": names.netbiosname, "DNSNAME": "%s.%s" % (names.hostname, names.dnsdomain), - "MACHINEPASS_B64": b64encode(machinepass.encode('utf-16-le')), + "MACHINEPASS_B64": b64encode(machinepass.encode('utf-16-le')).decode('utf8'), "DOMAINSID": str(domainsid), "DCRID": str(dc_rid), "SAMBA_VERSION_STRING": version, @@ -1367,7 +1367,7 @@ def fill_samdb(samdb, lp, names, logger, policyguid, else: domainguid_line = "" - descr = b64encode(get_domain_descriptor(names.domainsid)) + descr = b64encode(get_domain_descriptor(names.domainsid)).decode('utf8') setup_add_ldif(samdb, setup_path("provision_basedn.ldif"), { "DOMAINDN": names.domaindn, "DOMAINSID": str(names.domainsid), @@ -1390,7 +1390,7 @@ def fill_samdb(samdb, lp, names, logger, policyguid, # If we are setting up a subdomain, then this has been replicated in, so we don't need to add it if fill == FILL_FULL: logger.info("Adding configuration container") - descr = b64encode(get_config_descriptor(names.domainsid)) + descr = b64encode(get_config_descriptor(names.domainsid)).decode('utf8') setup_add_ldif(samdb, setup_path("provision_configuration_basedn.ldif"), { "CONFIGDN": names.configdn, "DESCRIPTOR": descr, @@ -1420,12 +1420,12 @@ def fill_samdb(samdb, lp, names, logger, policyguid, if fill == FILL_FULL: logger.info("Setting up sam.ldb configuration data") - partitions_descr = b64encode(get_config_partitions_descriptor(names.domainsid)) - sites_descr = b64encode(get_config_sites_descriptor(names.domainsid)) - ntdsquotas_descr = b64encode(get_config_ntds_quotas_descriptor(names.domainsid)) - protected1_descr = b64encode(get_config_delete_protected1_descriptor(names.domainsid)) - protected1wd_descr = b64encode(get_config_delete_protected1wd_descriptor(names.domainsid)) - protected2_descr = b64encode(get_config_delete_protected2_descriptor(names.domainsid)) + partitions_descr = b64encode(get_config_partitions_descriptor(names.domainsid)).decode('utf8') + sites_descr = b64encode(get_config_sites_descriptor(names.domainsid)).decode('utf8') + ntdsquotas_descr = b64encode(get_config_ntds_quotas_descriptor(names.domainsid)).decode('utf8') + protected1_descr = b64encode(get_config_delete_protected1_descriptor(names.domainsid)).decode('utf8') + protected1wd_descr = b64encode(get_config_delete_protected1wd_descriptor(names.domainsid)).decode('utf8') + protected2_descr = b64encode(get_config_delete_protected2_descriptor(names.domainsid)).decode('utf8') if "2008" in schema.base_schema: # exclude 2012-specific changes if we're using a 2008 schema @@ -1475,7 +1475,7 @@ def fill_samdb(samdb, lp, names, logger, policyguid, }) logger.info("Adding users container") - users_desc = b64encode(get_domain_users_descriptor(names.domainsid)) + users_desc = b64encode(get_domain_users_descriptor(names.domainsid)).decode('utf8') setup_add_ldif(samdb, setup_path("provision_users_add.ldif"), { "DOMAINDN": names.domaindn, "USERS_DESCRIPTOR": users_desc @@ -1484,7 +1484,7 @@ def fill_samdb(samdb, lp, names, logger, policyguid, setup_modify_ldif(samdb, setup_path("provision_users_modify.ldif"), { "DOMAINDN": names.domaindn}) logger.info("Adding computers container") - computers_desc = b64encode(get_domain_computers_descriptor(names.domainsid)) + computers_desc = b64encode(get_domain_computers_descriptor(names.domainsid)).decode('utf8') setup_add_ldif(samdb, setup_path("provision_computers_add.ldif"), { "DOMAINDN": names.domaindn, "COMPUTERS_DESCRIPTOR": computers_desc @@ -1494,11 +1494,11 @@ def fill_samdb(samdb, lp, names, logger, policyguid, setup_path("provision_computers_modify.ldif"), { "DOMAINDN": names.domaindn}) logger.info("Setting up sam.ldb data") - infrastructure_desc = b64encode(get_domain_infrastructure_descriptor(names.domainsid)) - lostandfound_desc = b64encode(get_domain_delete_protected2_descriptor(names.domainsid)) - system_desc = b64encode(get_domain_delete_protected1_descriptor(names.domainsid)) - builtin_desc = b64encode(get_domain_builtin_descriptor(names.domainsid)) - controllers_desc = b64encode(get_domain_controllers_descriptor(names.domainsid)) + infrastructure_desc = b64encode(get_domain_infrastructure_descriptor(names.domainsid)).decode('utf8') + lostandfound_desc = b64encode(get_domain_delete_protected2_descriptor(names.domainsid)).decode('utf8') + system_desc = b64encode(get_domain_delete_protected1_descriptor(names.domainsid)).decode('utf8') + builtin_desc = b64encode(get_domain_builtin_descriptor(names.domainsid)).decode('utf8') + controllers_desc = b64encode(get_domain_controllers_descriptor(names.domainsid)).decode('utf8') setup_add_ldif(samdb, setup_path("provision.ldif"), { "CREATTIME": str(samba.unix2nttime(int(time.time()))), "DOMAINDN": names.domaindn, @@ -1517,14 +1517,14 @@ def fill_samdb(samdb, lp, names, logger, policyguid, # If we are setting up a subdomain, then this has been replicated in, so we don't need to add it if fill == FILL_FULL: - managedservice_descr = b64encode(get_managed_service_accounts_descriptor(names.domainsid)) + managedservice_descr = b64encode(get_managed_service_accounts_descriptor(names.domainsid)).decode('utf8') setup_modify_ldif(samdb, setup_path("provision_configuration_references.ldif"), { "CONFIGDN": names.configdn, "SCHEMADN": names.schemadn}) logger.info("Setting up well known security principals") - protected1wd_descr = b64encode(get_config_delete_protected1wd_descriptor(names.domainsid)) + protected1wd_descr = b64encode(get_config_delete_protected1wd_descriptor(names.domainsid)).decode('utf8') setup_add_ldif(samdb, setup_path("provision_well_known_sec_princ.ldif"), { "CONFIGDN": names.configdn, "WELLKNOWNPRINCIPALS_DESCRIPTOR": protected1wd_descr, @@ -1541,8 +1541,8 @@ def fill_samdb(samdb, lp, names, logger, policyguid, setup_add_ldif(samdb, setup_path("provision_users.ldif"), { "DOMAINDN": names.domaindn, "DOMAINSID": str(names.domainsid), - "ADMINPASS_B64": b64encode(adminpass.encode('utf-16-le')), - "KRBTGTPASS_B64": b64encode(krbtgtpass.encode('utf-16-le')) + "ADMINPASS_B64": b64encode(adminpass.encode('utf-16-le')).decode('utf8'), + "KRBTGTPASS_B64": b64encode(krbtgtpass.encode('utf-16-le')).decode('utf8') }, controls=["relax:0", "provision:0"]) logger.info("Setting up self join") @@ -1562,7 +1562,9 @@ def fill_samdb(samdb, lp, names, logger, policyguid, ntds_dn = "CN=NTDS Settings,%s" % names.serverdn names.ntdsguid = samdb.searchone(basedn=ntds_dn, attribute="objectGUID", expression="", scope=ldb.SCOPE_BASE) - assert isinstance(names.ntdsguid, str) + + names.ntdsguid = names.ntdsguid.decode('utf8') + assert isinstance(names.ntdsguid, string_types) return samdb @@ -1938,8 +1940,8 @@ def provision_fill(samdb, secrets_ldb, logger, names, paths, backend_store=backend_store) domainguid = samdb.searchone(basedn=samdb.get_default_basedn(), - attribute="objectGUID") - assert isinstance(domainguid, str) + attribute="objectGUID").decode('utf8') + assert isinstance(domainguid, string_types) lastProvisionUSNs = get_last_provision_usn(samdb) maxUSN = get_max_usn(samdb, str(names.rootdn)) @@ -2189,7 +2191,7 @@ def provision(logger, session_info, smbconf=None, if paths.sysvol and not os.path.exists(paths.sysvol): os.makedirs(paths.sysvol, 0o775) - ldapi_url = "ldapi://%s" % urllib.quote(paths.s4_ldapi_path, safe="") + ldapi_url = "ldapi://%s" % urllib_quote(paths.s4_ldapi_path, safe="") schema = Schema(domainsid, invocationid=invocationid, schemadn=names.schemadn, base_schema=base_schema) diff --git a/python/samba/provision/sambadns.py b/python/samba/provision/sambadns.py index 3d59c701066..218f57fe679 100644 --- a/python/samba/provision/sambadns.py +++ b/python/samba/provision/sambadns.py @@ -247,12 +247,12 @@ def setup_dns_partitions(samdb, domainsid, domaindn, forestdn, configdn, setup_add_ldif(samdb, setup_path("provision_dnszones_partitions.ldif"), { "ZONE_DN": domainzone_dn, - "SECDESC" : b64encode(descriptor) + "SECDESC" : b64encode(descriptor).decode('utf8') }) if fill_level != FILL_SUBDOMAIN: setup_add_ldif(samdb, setup_path("provision_dnszones_partitions.ldif"), { "ZONE_DN": forestzone_dn, - "SECDESC" : b64encode(descriptor) + "SECDESC" : b64encode(descriptor).decode('utf8') }) domainzone_guid = get_domainguid(samdb, domainzone_dn) @@ -267,8 +267,8 @@ def setup_dns_partitions(samdb, domainsid, domaindn, forestdn, configdn, "ZONE_DNS": domainzone_dns, "CONFIGDN": configdn, "SERVERDN": serverdn, - "LOSTANDFOUND_DESCRIPTOR": b64encode(protected2_desc), - "INFRASTRUCTURE_DESCRIPTOR": b64encode(protected1_desc), + "LOSTANDFOUND_DESCRIPTOR": b64encode(protected2_desc).decode('utf8'), + "INFRASTRUCTURE_DESCRIPTOR": b64encode(protected1_desc).decode('utf8'), }) setup_modify_ldif(samdb, setup_path("provision_dnszones_modify.ldif"), { "CONFIGDN": configdn, @@ -287,8 +287,8 @@ def setup_dns_partitions(samdb, domainsid, domaindn, forestdn, configdn, "ZONE_DNS": forestzone_dns, "CONFIGDN": configdn, "SERVERDN": serverdn, - "LOSTANDFOUND_DESCRIPTOR": b64encode(protected2_desc), - "INFRASTRUCTURE_DESCRIPTOR": b64encode(protected1_desc), + "LOSTANDFOUND_DESCRIPTOR": b64encode(protected2_desc).decode('utf8'), + "INFRASTRUCTURE_DESCRIPTOR": b64encode(protected1_desc).decode('utf8'), }) setup_modify_ldif(samdb, setup_path("provision_dnszones_modify.ldif"), { "CONFIGDN": configdn, diff --git a/python/samba/samdb.py b/python/samba/samdb.py index b66afb7431c..a1a1f45b003 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -1024,12 +1024,12 @@ def sequence_number(self, seq_type): def get_dsServiceName(self): '''get the NTDS DN from the rootDSE''' res = self.search(base="", scope=ldb.SCOPE_BASE, attrs=["dsServiceName"]) - return res[0]["dsServiceName"][0] + return res[0]["dsServiceName"][0].decode('utf8') def get_serverName(self): '''get the server DN from the rootDSE''' res = self.search(base="", scope=ldb.SCOPE_BASE, attrs=["serverName"]) - return res[0]["serverName"][0] + return res[0]["serverName"][0].decode('utf8') def dns_lookup(self, dns_name, dns_partition=None): '''Do a DNS lookup in the database, returns the NDR database structures''' diff --git a/python/samba/schema.py b/python/samba/schema.py index 67ec357a285..e161aa8ca0b 100644 --- a/python/samba/schema.py +++ b/python/samba/schema.py @@ -122,7 +122,7 @@ def __init__(self, domain_sid, invocationid=None, schemadn=None, setup_path("provision_schema_basedn_modify.ldif"), {"SCHEMADN": schemadn, "OBJVERSION" : schema_version}) - descr = b64encode(get_schema_descriptor(domain_sid)) + descr = b64encode(get_schema_descriptor(domain_sid)).decode('utf8') self.schema_dn_add = read_and_sub_file( setup_path("provision_schema_basedn.ldif"), {"SCHEMADN": schemadn, "DESCRIPTOR": descr}) @@ -130,13 +130,14 @@ def __init__(self, domain_sid, invocationid=None, schemadn=None, if override_prefixmap is not None: self.prefixmap_data = override_prefixmap else: - self.prefixmap_data = open(setup_path("prefixMap.txt"), 'r').read() + self.prefixmap_data = open(setup_path("prefixMap.txt"), 'rb').read() if additional_prefixmap is not None: for map in additional_prefixmap: self.prefixmap_data += "%s\n" % map - self.prefixmap_data = b64encode(self.prefixmap_data) + #self.prefixmap_data = b64encode(self.prefixmap_data.encode('utf8')).decode('utf8') + self.prefixmap_data = b64encode(self.prefixmap_data).decode('utf8') # We don't actually add this ldif, just parse it prefixmap_ldif = "dn: %s\nprefixMap:: %s\n\n" % (self.schemadn, self.prefixmap_data) From 64194dacc8f8eac74d8e6b5197fe2b46f27bf559 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 10 Apr 2018 16:03:37 +0100 Subject: [PATCH 02/57] s4/selftest: enable samba.tests.dsdb_lock for python3 Signed-off-by: Noel Power --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index d1e5bc6a509..9d41e9eb77c 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -578,7 +578,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planoldpythontestsuite("none", "simple", extra_path=["%s/lib/tdb/python/tests" % srcdir()], name="tdb.python") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.sam", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dsdb", py3_compatible=True) -planpythontestsuite("none", "samba.tests.dsdb_lock") +planpythontestsuite("none", "samba.tests.dsdb_lock", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.bare", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.unix") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.srvsvc") From d3bdca82f1d00f4af62adccaa576a14633655477 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 17 Apr 2018 11:56:40 +0100 Subject: [PATCH 03/57] python/samba/tests: port samba.tests.unix for py3 Signed-off-by: Noel Power --- python/samba/tests/dcerpc/unix.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/python/samba/tests/dcerpc/unix.py b/python/samba/tests/dcerpc/unix.py index e8ef4da8630..ea128beca08 100644 --- a/python/samba/tests/dcerpc/unix.py +++ b/python/samba/tests/dcerpc/unix.py @@ -20,6 +20,9 @@ from samba.dcerpc import unixinfo from samba.tests import RpcInterfaceTestCase +from samba.compat import text_type as txt_type +from samba.compat import PY3 as is_py3 +import samba.compat class UnixinfoTests(RpcInterfaceTestCase): @@ -28,19 +31,21 @@ def setUp(self): self.conn = unixinfo.unixinfo("ncalrpc:", self.get_loadparm()) def test_getpwuid_int(self): - infos = self.conn.GetPWUid(range(512)) + infos = self.conn.GetPWUid(list(range(512))) self.assertEquals(512, len(infos)) self.assertEquals("/bin/false", infos[0].shell) - self.assertTrue(isinstance(infos[0].homedir, unicode)) + self.assertTrue(isinstance(infos[0].homedir, txt_type)) def test_getpwuid(self): - infos = self.conn.GetPWUid(map(long, range(512))) - self.assertEquals(512, len(infos)) - self.assertEquals("/bin/false", infos[0].shell) - self.assertTrue(isinstance(infos[0].homedir, unicode)) + # This test only relevant in PY2 + if not is_py3: + infos = self.conn.GetPWUid(map(long, range(512))) + self.assertEquals(512, len(infos)) + self.assertEquals("/bin/false", infos[0].shell) + self.assertTrue(isinstance(infos[0].homedir, txt_type)) def test_gidtosid(self): - self.conn.GidToSid(1000L) + self.conn.GidToSid(1000) def test_uidtosid(self): self.conn.UidToSid(1000) From 5f3712f5fe7f5af9670031b514812dce9874dcb3 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 16 Apr 2018 18:58:01 +0100 Subject: [PATCH 04/57] s4/selftest: enable samba.tests.dcerpc.unix for python3 Signed-off-by: Noel Power --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 9d41e9eb77c..de4bc2fb073 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -580,7 +580,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dsdb", py3_compatible=True) planpythontestsuite("none", "samba.tests.dsdb_lock", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.bare", py3_compatible=True) -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.unix") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.unix", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.srvsvc") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.timecmd") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.join") From 6bac50330b4d50d4eb6aceb5e7a21899b1c1f712 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 17 Apr 2018 13:53:39 +0100 Subject: [PATCH 05/57] some Py2/Py3 compatability porting --- python/samba/netcmd/nettime.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/samba/netcmd/nettime.py b/python/samba/netcmd/nettime.py index 694b6adda9b..7c16aec92f3 100644 --- a/python/samba/netcmd/nettime.py +++ b/python/samba/netcmd/nettime.py @@ -17,7 +17,7 @@ # import samba.getopt as options -import common +from . import common from samba.net import Net from samba.netcmd import ( From 5b20730a8c39d12d091b77c7b0fa98f730659bff Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 17 Apr 2018 14:14:12 +0100 Subject: [PATCH 06/57] python/samba/tests: port CStringIO usage for py2/py3 compatability --- python/samba/tests/samba_tool/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/samba/tests/samba_tool/base.py b/python/samba/tests/samba_tool/base.py index de257e3db09..9bffdabd229 100644 --- a/python/samba/tests/samba_tool/base.py +++ b/python/samba/tests/samba_tool/base.py @@ -25,7 +25,7 @@ import string from samba.auth import system_session from samba.samdb import SamDB -from cStringIO import StringIO +from samba.compat import StringIO from samba.netcmd.main import cmd_sambatool import samba.tests From 6071df055a575d5b1ecad2986ac9309cc0a3b5e8 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 17 Apr 2018 13:53:57 +0100 Subject: [PATCH 07/57] s4/selftest/tests: enable samba.tests.samba_tool.timecmd for python3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index de4bc2fb073..063b3965449 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -582,7 +582,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.bare", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.unix", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.srvsvc") -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.timecmd") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.timecmd", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.join") planpythontestsuite("none", "samba.tests.samba_tool.visualize") From b609e2c94449c9da17f6bf4b7de28a0846be363c Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 17 Apr 2018 15:17:36 +0100 Subject: [PATCH 08/57] python/samba: Bulk StringIO port for python3 --- python/samba/gpclass.py | 2 +- python/samba/tests/blackbox/samba_dnsupdate.py | 2 +- python/samba/tests/emulate/traffic.py | 2 +- python/samba/tests/netcmd.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/samba/gpclass.py b/python/samba/gpclass.py index 0966611b686..d9ffad2165f 100644 --- a/python/samba/gpclass.py +++ b/python/samba/gpclass.py @@ -21,7 +21,7 @@ sys.path.insert(0, "bin/python") from samba import NTSTATUSError from ConfigParser import ConfigParser -from StringIO import StringIO +from samba.compat import StringIO from abc import ABCMeta, abstractmethod import xml.etree.ElementTree as etree import re diff --git a/python/samba/tests/blackbox/samba_dnsupdate.py b/python/samba/tests/blackbox/samba_dnsupdate.py index e6cad3bbaba..1a659b0b423 100644 --- a/python/samba/tests/blackbox/samba_dnsupdate.py +++ b/python/samba/tests/blackbox/samba_dnsupdate.py @@ -17,7 +17,7 @@ # import samba.tests -from StringIO import StringIO +from samba.compat import StringIO from samba.netcmd.main import cmd_sambatool from samba.credentials import Credentials from samba.auth import system_session diff --git a/python/samba/tests/emulate/traffic.py b/python/samba/tests/emulate/traffic.py index a57c2f5bc4e..0cfae02bce0 100644 --- a/python/samba/tests/emulate/traffic.py +++ b/python/samba/tests/emulate/traffic.py @@ -16,7 +16,7 @@ # along with this program. If not, see . # from pprint import pprint -from cStringIO import StringIO +from samba.compat import StringIO import samba.tests diff --git a/python/samba/tests/netcmd.py b/python/samba/tests/netcmd.py index 2867c031a17..6f5ea88eb99 100644 --- a/python/samba/tests/netcmd.py +++ b/python/samba/tests/netcmd.py @@ -17,7 +17,7 @@ """Tests for samba.netcmd.""" -from cStringIO import StringIO +from samba.compat import StringIO from samba.netcmd import Command from samba.netcmd.testparm import cmd_testparm from samba.netcmd.main import cmd_sambatool From 069638381fafa5dc3359456b23cddbda999fc552 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 17 Apr 2018 16:48:03 +0100 Subject: [PATCH 09/57] python/samba: changes to make samba.tests.samba_tool.join run under py3 --- python/samba/join.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/samba/join.py b/python/samba/join.py index b35eb78e1c6..6a555d64f02 100644 --- a/python/samba/join.py +++ b/python/samba/join.py @@ -357,21 +357,21 @@ def get_behavior_version(ctx): def get_dnsHostName(ctx): res = ctx.samdb.search(base="", scope=ldb.SCOPE_BASE, attrs=["dnsHostName"]) - return res[0]["dnsHostName"][0] + return res[0]["dnsHostName"][0].decode('utf8') def get_domain_name(ctx): '''get netbios name of the domain from the partitions record''' partitions_dn = ctx.samdb.get_partitions_dn() res = ctx.samdb.search(base=partitions_dn, scope=ldb.SCOPE_ONELEVEL, attrs=["nETBIOSName"], expression='ncName=%s' % ldb.binary_encode(str(ctx.samdb.get_default_basedn()))) - return res[0]["nETBIOSName"][0] + return res[0]["nETBIOSName"][0].decode('utf8') def get_forest_domain_name(ctx): '''get netbios name of the domain from the partitions record''' partitions_dn = ctx.samdb.get_partitions_dn() res = ctx.samdb.search(base=partitions_dn, scope=ldb.SCOPE_ONELEVEL, attrs=["nETBIOSName"], expression='ncName=%s' % ldb.binary_encode(str(ctx.samdb.get_root_basedn()))) - return res[0]["nETBIOSName"][0] + return res[0]["nETBIOSName"][0].decode('utf8') def get_parent_partition_dn(ctx): '''get the parent domain partition DN from parent DNS name''' From 3457eb0a47dbd7a2a324faa6bb77b9bea463c99d Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 17 Apr 2018 16:48:56 +0100 Subject: [PATCH 10/57] s4/selftest: Enable samba.tests.samba_tool.join for py3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 063b3965449..d539870e4c1 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -583,7 +583,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.unix", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.srvsvc") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.timecmd", py3_compatible=True) -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.join") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.join", py3_compatible=True) planpythontestsuite("none", "samba.tests.samba_tool.visualize") From 3a3da2e54321a788457db86dd0065a4fcb67b7ee Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 18 Apr 2018 10:42:03 +0100 Subject: [PATCH 11/57] strings with utf content -> u (ensuring they are treated as unicode) --- python/samba/graph.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/samba/graph.py b/python/samba/graph.py index 7dfc19015e7..c1c83ffa525 100644 --- a/python/samba/graph.py +++ b/python/samba/graph.py @@ -203,8 +203,8 @@ def compile_graph_key(key_items, nodes_above=[], elisions=None, if short[0] == ',' and long[0] == ',': short = short[1:] long = long[1:] - elision_str += ('\nelision%d[shape=plaintext; style=solid; ' - 'label="\“%s” means “%s”\\r"]\n' + elision_str += (u'\nelision%d[shape=plaintext; style=solid; ' + u'label="\“%s” means “%s”\\r"]\n' % ((i, short, long))) above_lines = [] @@ -516,13 +516,13 @@ def distance_matrix(vertices, edges, write = lines.append if utf8: - vertical = '│' - horizontal = '─' - corner = '╭' + vertical = u'│' + horizontal = u'─' + corner = u'╭' #diagonal = '╲' - diagonal = '·' + diagonal = u'·' #missing = '🕱' - missing = '-' + missing = u'-' else: vertical, horizontal, corner, diagonal, missing = '|-,0-' From 418172bdd9cbb25e4109058ecb03db459a46af9c Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 24 Apr 2018 09:23:02 +0100 Subject: [PATCH 12/57] python/samba/tests: prefix expected with 'u' as graph funcs return unicode --- python/samba/tests/graph.py | 60 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/python/samba/tests/graph.py b/python/samba/tests/graph.py index 7ea53caa734..38590e91e8d 100644 --- a/python/samba/tests/graph.py +++ b/python/samba/tests/graph.py @@ -124,7 +124,7 @@ def test_simple_distance(self): ('cat', 'dog')] expected = { - "utf8 True, colour None": ''' + "utf8 True, colour None": u''' destination ╭────── ant │╭───── bat @@ -138,7 +138,7 @@ def test_simple_distance(self): dog ---·-- elephant 2311·- frog 23121·''', - 'utf8 True, colour ansi': ''' + 'utf8 True, colour ansi': u''' destination ╭────── ant │╭───── bat @@ -153,7 +153,7 @@ def test_simple_distance(self): elephant 2311·-  frog 23121· ''', - 'utf8 True, colour ansi-heatmap': ''' + 'utf8 True, colour ansi-heatmap': u''' destination ╭────── ant │╭───── bat @@ -168,7 +168,7 @@ def test_simple_distance(self): elephant 2311·-  frog 23121· ''', - 'utf8 True, colour xterm-256color': ''' + 'utf8 True, colour xterm-256color': u''' destination ╭────── ant │╭───── bat @@ -183,7 +183,7 @@ def test_simple_distance(self): elephant 2311·-  frog 23121· ''', -'utf8 True, colour xterm-256color-heatmap': ''' +'utf8 True, colour xterm-256color-heatmap': u''' destination ╭────── ant │╭───── bat @@ -198,7 +198,7 @@ def test_simple_distance(self): elephant 2311·-  frog 23121· ''', -'utf8 False, colour None': ''' +'utf8 False, colour None': u''' destination ,------ ant |,----- bat @@ -213,7 +213,7 @@ def test_simple_distance(self): elephant 23110- frog 231210 ''', -'utf8 False, colour ansi': ''' +'utf8 False, colour ansi': u''' destination ,------ ant |,----- bat @@ -228,7 +228,7 @@ def test_simple_distance(self): elephant 23110-  frog 231210 ''', -'utf8 False, colour ansi-heatmap': ''' +'utf8 False, colour ansi-heatmap': u''' destination ,------ ant |,----- bat @@ -243,7 +243,7 @@ def test_simple_distance(self): elephant 23110-  frog 231210 ''', -'utf8 False, colour xterm-256color': ''' +'utf8 False, colour xterm-256color': u''' destination ,------ ant |,----- bat @@ -258,7 +258,7 @@ def test_simple_distance(self): elephant 23110-  frog 231210 ''', -'utf8 False, colour xterm-256color-heatmap': ''' +'utf8 False, colour xterm-256color-heatmap': u''' destination ,------ ant |,----- bat @@ -288,7 +288,7 @@ def test_simple_distance2(self): ('bat', 'ant'), ('ant', 'cat')] expected = { - 'utf8 True, colour None': ''' + 'utf8 True, colour None': u''' destination ╭─── ant │╭── bat @@ -297,7 +297,7 @@ def test_simple_distance2(self): bat 1·2 cat 21· ''', - 'utf8 True, colour ansi': ''' + 'utf8 True, colour ansi': u''' destination ╭─── ant │╭── bat @@ -306,7 +306,7 @@ def test_simple_distance2(self):  bat 1·2  cat 21· ''', -'utf8 True, colour ansi-heatmap': ''' +'utf8 True, colour ansi-heatmap': u''' destination ╭─── ant │╭── bat @@ -315,7 +315,7 @@ def test_simple_distance2(self):  bat 1·2  cat 21· ''', -'utf8 True, colour xterm-256color': ''' +'utf8 True, colour xterm-256color': u''' destination ╭─── ant │╭── bat @@ -324,7 +324,7 @@ def test_simple_distance2(self):  bat 1·2  cat 21· ''', -'utf8 True, colour xterm-256color-heatmap': ''' +'utf8 True, colour xterm-256color-heatmap': u''' destination ╭─── ant │╭── bat @@ -333,7 +333,7 @@ def test_simple_distance2(self):  bat 1·2  cat 21· ''', -'utf8 False, colour None': ''' +'utf8 False, colour None': u''' destination ,--- ant |,-- bat @@ -342,7 +342,7 @@ def test_simple_distance2(self): bat 102 cat 210 ''', -'utf8 False, colour ansi': ''' +'utf8 False, colour ansi': u''' destination ,--- ant |,-- bat @@ -351,7 +351,7 @@ def test_simple_distance2(self):  bat 102  cat 210 ''', -'utf8 False, colour ansi-heatmap': ''' +'utf8 False, colour ansi-heatmap': u''' destination ,--- ant |,-- bat @@ -360,7 +360,7 @@ def test_simple_distance2(self):  bat 102  cat 210 ''', -'utf8 False, colour xterm-256color': ''' +'utf8 False, colour xterm-256color': u''' destination ,--- ant |,-- bat @@ -369,7 +369,7 @@ def test_simple_distance2(self):  bat 102  cat 210 ''', -'utf8 False, colour xterm-256color-heatmap': ''' +'utf8 False, colour xterm-256color-heatmap': u''' destination ,--- ant |,-- bat @@ -394,7 +394,7 @@ def test_simple_distance3(self): ('dog', 'ant'), ('dog', 'eel')] expected = { -'utf8 True, colour None': ''' +'utf8 True, colour None': u''' destination ╭───── ant │╭──── bat @@ -407,7 +407,7 @@ def test_simple_distance3(self): dog 123·1 eel ----· ''', -'utf8 True, colour ansi': ''' +'utf8 True, colour ansi': u''' destination ╭───── ant │╭──── bat @@ -420,7 +420,7 @@ def test_simple_distance3(self):  dog 123·1  eel ----· ''', -'utf8 True, colour ansi-heatmap': ''' +'utf8 True, colour ansi-heatmap': u''' destination ╭───── ant │╭──── bat @@ -433,7 +433,7 @@ def test_simple_distance3(self):  dog 123·1  eel ----· ''', -'utf8 True, colour xterm-256color': ''' +'utf8 True, colour xterm-256color': u''' destination ╭───── ant │╭──── bat @@ -446,7 +446,7 @@ def test_simple_distance3(self):  dog 123·1  eel ----· ''', -'utf8 True, colour xterm-256color-heatmap': ''' +'utf8 True, colour xterm-256color-heatmap': u''' destination ╭───── ant │╭──── bat @@ -459,7 +459,7 @@ def test_simple_distance3(self):  dog 123·1  eel ----· ''', -'utf8 False, colour None': ''' +'utf8 False, colour None': u''' destination ,----- ant |,---- bat @@ -472,7 +472,7 @@ def test_simple_distance3(self): dog 12301 eel ----0 ''', -'utf8 False, colour ansi': ''' +'utf8 False, colour ansi': u''' destination ,----- ant |,---- bat @@ -485,7 +485,7 @@ def test_simple_distance3(self):  dog 12301  eel ----0 ''', -'utf8 False, colour ansi-heatmap': ''' +'utf8 False, colour ansi-heatmap': u''' destination ,----- ant |,---- bat @@ -499,7 +499,7 @@ def test_simple_distance3(self):  eel ----0 ''', 'utf8 False, colour xterm-256color': -''' destination +u''' destination ,----- ant |,---- bat ||,--- cat @@ -511,7 +511,7 @@ def test_simple_distance3(self):  dog 12301  eel ----0 ''', -'utf8 False, colour xterm-256color-heatmap': ''' +'utf8 False, colour xterm-256color-heatmap': u''' destination ,----- ant |,---- bat From c55df59235c4fb0ec41fd9c232a301f6ba367914 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 18 Apr 2018 12:33:51 +0100 Subject: [PATCH 13/57] targeted p3 port use io.open to be able to specifiy encoding for text we write specify utf8 in write (hmmm maybe we should just be doing this anyway regardless) #TODO check again --- python/samba/netcmd/visualize.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/python/samba/netcmd/visualize.py b/python/samba/netcmd/visualize.py index 6f880ae61e8..d5f2c205fb0 100644 --- a/python/samba/netcmd/visualize.py +++ b/python/samba/netcmd/visualize.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Visualisation tools # # Copyright (C) Andrew Bartlett 2015, 2018 @@ -34,7 +35,7 @@ import time from samba.kcc import KCC from samba.kcc.kcc_utils import KCCError - +from io import open COMMON_OPTIONS = [ Option("-H", "--URL", help="LDB URL for database or target server", type=str, metavar="URL", dest="H"), @@ -94,7 +95,7 @@ def get_kcc_and_dsas(self, H, lp, creds): return kcc, dsas - def write(self, s, fn=None, suffix='.dot'): + def write(self, s, fn=None, suffix='.dot', utf8=None): """Decide whether we're dealing with a filename, a tempfile, or stdout, and write accordingly. @@ -106,18 +107,20 @@ def write(self, s, fn=None, suffix='.dot'): If fn is visualize.TEMP_FILE, write to a temporary file Otherwise fn should be a filename to write to. """ + encoding = None; + if utf8: + encoding = 'utf8'; if fn is None or fn == '-': # we're just using stdout (a.k.a self.outf) print(s, file=self.outf) return - if fn is TEMP_FILE: fd, fn = tempfile.mkstemp(prefix='samba-tool-visualise', suffix=suffix) - f = open(fn, 'w') + f = open(fn, 'w', encoding=encoding) os.close(fd) else: - f = open(fn, 'w') + f = open(fn, 'w', encoding=encoding) f.write(s) f.close() @@ -315,7 +318,7 @@ def run(self, H=None, output=None, shorten_names=False, generate_key=key) s = "\n%s\n%s" % (header_strings[direction] % part, s) - self.write(s, output) + self.write(s, output, utf8=utf8) return edge_colours = [] @@ -361,7 +364,7 @@ def run(self, H=None, output=None, shorten_names=False, shorten_names=shorten_names, key_items=key_items) - self.write(s, output) + self.write(s, output, utf8=utf8) class NTDSConn(object): @@ -509,7 +512,7 @@ def run(self, H=None, output=None, shorten_names=False, colour=color_scheme, shorten_names=shorten_names, generate_key=key) - self.write('\n%s\n%s\n%s' % (title, s, epilog), output) + self.write('\n%s\n%s\n%s' % (title, s, epilog), output, utf8=utf8) return dot_edges = [] @@ -566,7 +569,7 @@ def run(self, H=None, output=None, shorten_names=False, edge_styles=edge_styles, shorten_names=shorten_names, key_items=key_items) - self.write(s, output) + self.write(s, output, utf8=utf8) class cmd_visualize(SuperCommand): From 240ef5db0b2700802e23e8559a737db8d47653b3 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 18 Apr 2018 16:51:21 +0100 Subject: [PATCH 14/57] make sure only unicode is written to 'write' --- python/samba/netcmd/visualize.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/samba/netcmd/visualize.py b/python/samba/netcmd/visualize.py index d5f2c205fb0..0096380429d 100644 --- a/python/samba/netcmd/visualize.py +++ b/python/samba/netcmd/visualize.py @@ -121,7 +121,8 @@ def write(self, s, fn=None, suffix='.dot', utf8=None): os.close(fd) else: f = open(fn, 'w', encoding=encoding) - + if isinstance(s, str): + s = s.decode('utf8') f.write(s) f.close() return fn From 9f9b6050cbda60c8530886a3d22c4d1db03357f0 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 18 Apr 2018 17:56:53 +0100 Subject: [PATCH 15/57] python/samba/tests: more tweaks to get samba.tests.visualize to run Note: this is NOT to get the visualize tests to run via py2/py3 but rather get the tests to run post some changes that change the result of some functions e.g. get_dsServiceName() & get_serverName() in python/samba/samdb.py which now return unicode strings which was needed to ensure py2/py3 compatability when running samba.tests.dsdb_lock under py2/py3 --- python/samba/tests/samba_tool/visualize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/samba/tests/samba_tool/visualize.py b/python/samba/tests/samba_tool/visualize.py index a90c77364b7..25c56cc6ec6 100644 --- a/python/samba/tests/samba_tool/visualize.py +++ b/python/samba/tests/samba_tool/visualize.py @@ -200,7 +200,7 @@ def test_utf8(self): '-H', self.dburl, '--color=no', '-S') self.assertCmdSuccess(result, ascii, err) - for c in ('│', '─', '╭'): + for c in (u'│', u'─', u'╭'): self.assertTrue(c in utf8, 'UTF8 should contain %s' % c) self.assertTrue(c not in ascii, 'ASCII should not contain %s' % c) @@ -319,9 +319,9 @@ def test_dot_ntdsconn_disconnected(self): '-o', '-') self.assertCmdSuccess(result, dot, err) self.remove_files(dbfile) - print(dot) + print(dot.encode('utf8')) - self.assertStringsEqual(EXPECTED_DOT_NTDSCONN_DISCONNECTED, dot, + self.assertStringsEqual(EXPECTED_DOT_NTDSCONN_DISCONNECTED, dot.encode('utf8'), strip=True) def test_dot_ntdsconn_disconnected_to_file(self): From 50592c41f7ba063b824c74e3f79b1df6624a4f13 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Wed, 18 Apr 2018 19:44:23 +0100 Subject: [PATCH 16/57] tweak test and impl a little more to try and get it to run under py2 still py2 (but using unicode) --- python/samba/netcmd/visualize.py | 8 ++++---- python/samba/tests/samba_tool/visualize.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/python/samba/netcmd/visualize.py b/python/samba/netcmd/visualize.py index 0096380429d..9c0383f1f89 100644 --- a/python/samba/netcmd/visualize.py +++ b/python/samba/netcmd/visualize.py @@ -107,9 +107,11 @@ def write(self, s, fn=None, suffix='.dot', utf8=None): If fn is visualize.TEMP_FILE, write to a temporary file Otherwise fn should be a filename to write to. """ - encoding = None; + encoding = None if utf8: - encoding = 'utf8'; + encoding = 'utf8' + if isinstance(s, str): + s = s.decode('utf8') if fn is None or fn == '-': # we're just using stdout (a.k.a self.outf) print(s, file=self.outf) @@ -121,8 +123,6 @@ def write(self, s, fn=None, suffix='.dot', utf8=None): os.close(fd) else: f = open(fn, 'w', encoding=encoding) - if isinstance(s, str): - s = s.decode('utf8') f.write(s) f.close() return fn diff --git a/python/samba/tests/samba_tool/visualize.py b/python/samba/tests/samba_tool/visualize.py index 25c56cc6ec6..519ba3c9081 100644 --- a/python/samba/tests/samba_tool/visualize.py +++ b/python/samba/tests/samba_tool/visualize.py @@ -337,13 +337,14 @@ def test_dot_ntdsconn_disconnected_to_file(self): '--color=no', '-S', '--dot', '-o', dot_file) self.assertCmdSuccess(result, dot, err) + from io import open f = open(dot_file) dot = f.read() f.close() - self.assertStringsEqual(EXPECTED_DOT_NTDSCONN_DISCONNECTED, dot) + self.assertStringsEqual(EXPECTED_DOT_NTDSCONN_DISCONNECTED, dot.encode('utf8')) self.remove_files(dbfile, dot_file) - print(dot) + print(dot.encode('utf8')) EXPECTED_DOT_MULTISITE_NO_KEY = r"""/* generated by samba */ digraph A_samba_tool_production { From 9a33b03a0eb5c4bb41cbcdcffc9840771d800ca4 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 19 Apr 2018 16:05:14 +0100 Subject: [PATCH 17/57] python2 unicode support changes. Bit of a descrepency, it seems we write unicode when writing file but return when no output file or '-' is specified. Adjust test so that we don't use r"blah blah blah" raw string format as this will screw up when we use python3. python 2 dot type from file is unicode raw string is python3 dot type from file is raw string is This means for the test to pass running python2 we need to encode the return from the file (e.g. unicde) to convert to so we can compare. With python3 we can't do that (no encode method for ). We need the result and expected result types to match (in python2 & python3) --- python/samba/tests/samba_tool/visualize.py | 50 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/python/samba/tests/samba_tool/visualize.py b/python/samba/tests/samba_tool/visualize.py index 519ba3c9081..502bb8fda67 100644 --- a/python/samba/tests/samba_tool/visualize.py +++ b/python/samba/tests/samba_tool/visualize.py @@ -321,7 +321,7 @@ def test_dot_ntdsconn_disconnected(self): self.remove_files(dbfile) print(dot.encode('utf8')) - self.assertStringsEqual(EXPECTED_DOT_NTDSCONN_DISCONNECTED, dot.encode('utf8'), + self.assertStringsEqual(EXPECTED_DOT_NTDSCONN_DISCONNECTED, dot, strip=True) def test_dot_ntdsconn_disconnected_to_file(self): @@ -341,7 +341,7 @@ def test_dot_ntdsconn_disconnected_to_file(self): f = open(dot_file) dot = f.read() f.close() - self.assertStringsEqual(EXPECTED_DOT_NTDSCONN_DISCONNECTED, dot.encode('utf8')) + self.assertStringsEqual(EXPECTED_DOT_NTDSCONN_DISCONNECTED, dot) self.remove_files(dbfile, dot_file) print(dot.encode('utf8')) @@ -386,25 +386,25 @@ def test_dot_ntdsconn_disconnected_to_file(self): """ -EXPECTED_DOT_NTDSCONN_DISCONNECTED = r"""/* generated by samba */ +EXPECTED_DOT_NTDSCONN_DISCONNECTED = u"""/* generated by samba */ digraph A_samba_tool_production { label="NTDS Connections known to CN=LOCALDC,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com"; fontsize=10; node[fontname=Helvetica; fontsize=10]; -"CN=NTDS Settings,\nCN=CLIENT,\n..."; -"CN=NTDS Settings,\nCN=LOCALDC,\n..."; -"CN=NTDS Settings,\nCN=PROMOTEDVDC,\n..."; -"CN=NTDS Settings,\nCN=SERVER1,\n..."; -"CN=NTDS Settings,\nCN=SERVER2,\n..."; -"CN=NTDS Settings,\nCN=SERVER3,\n..."; -"CN=NTDS Settings,\nCN=SERVER4,\n..."; -"CN=NTDS Settings,\nCN=SERVER5,\n..."; -"CN=NTDS Settings,\nCN=LOCALDC,\n..." -> "CN=NTDS Settings,\nCN=PROMOTEDVDC,\n..." [color="#000000", ]; -"CN=NTDS Settings,\nCN=PROMOTEDVDC,\n..." -> "CN=NTDS Settings,\nCN=LOCALDC,\n..." [color="#000000", ]; -"CN=NTDS Settings,\nCN=SERVER2,\n..." -> "CN=NTDS Settings,\nCN=PROMOTEDVDC,\n..." [color="#000000", ]; -"CN=NTDS Settings,\nCN=SERVER3,\n..." -> "CN=NTDS Settings,\nCN=LOCALDC,\n..." [color="#000000", ]; +"CN=NTDS Settings,\\nCN=CLIENT,\\n..."; +"CN=NTDS Settings,\\nCN=LOCALDC,\\n..."; +"CN=NTDS Settings,\\nCN=PROMOTEDVDC,\\n..."; +"CN=NTDS Settings,\\nCN=SERVER1,\\n..."; +"CN=NTDS Settings,\\nCN=SERVER2,\\n..."; +"CN=NTDS Settings,\\nCN=SERVER3,\\n..."; +"CN=NTDS Settings,\\nCN=SERVER4,\\n..."; +"CN=NTDS Settings,\\nCN=SERVER5,\\n..."; +"CN=NTDS Settings,\\nCN=LOCALDC,\\n..." -> "CN=NTDS Settings,\\nCN=PROMOTEDVDC,\\n..." [color="#000000", ]; +"CN=NTDS Settings,\\nCN=PROMOTEDVDC,\\n..." -> "CN=NTDS Settings,\\nCN=LOCALDC,\\n..." [color="#000000", ]; +"CN=NTDS Settings,\\nCN=SERVER2,\\n..." -> "CN=NTDS Settings,\\nCN=PROMOTEDVDC,\\n..." [color="#000000", ]; +"CN=NTDS Settings,\\nCN=SERVER3,\\n..." -> "CN=NTDS Settings,\\nCN=LOCALDC,\\n..." [color="#000000", ]; subgraph cluster_key { label="Key"; subgraph cluster_key_nodes { @@ -419,22 +419,22 @@ def test_dot_ntdsconn_disconnected_to_file(self): key_0_e1[label=src; color="#000000"; group="key_0__g"] key_0_e2[label=dest; color="#000000"; group="key_0__g"] key_0_e1 -> key_0_e2 [constraint = false; color="#000000"] -key_0__label[shape=plaintext; style=solid; width=2.000000; label="NTDS Connection\r"] +key_0__label[shape=plaintext; style=solid; width=2.000000; label="NTDS Connection\\r"] } {key_0__label} } -elision0[shape=plaintext; style=solid; label="\“...” means “CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com”\r"] +elision0[shape=plaintext; style=solid; label="\\“...” means “CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=samba,DC=example,DC=com”\\r"] } -"CN=NTDS Settings,\nCN=CLIENT,\n..." -> key_0__label [style=invis]; -"CN=NTDS Settings,\nCN=LOCALDC,\n..." -> key_0__label [style=invis]; -"CN=NTDS Settings,\nCN=PROMOTEDVDC,\n..." -> key_0__label [style=invis]; -"CN=NTDS Settings,\nCN=SERVER1,\n..." -> key_0__label [style=invis]; -"CN=NTDS Settings,\nCN=SERVER2,\n..." -> key_0__label [style=invis]; -"CN=NTDS Settings,\nCN=SERVER3,\n..." -> key_0__label [style=invis]; -"CN=NTDS Settings,\nCN=SERVER4,\n..." -> key_0__label [style=invis]; -"CN=NTDS Settings,\nCN=SERVER5,\n..." -> key_0__label [style=invis] +"CN=NTDS Settings,\\nCN=CLIENT,\\n..." -> key_0__label [style=invis]; +"CN=NTDS Settings,\\nCN=LOCALDC,\\n..." -> key_0__label [style=invis]; +"CN=NTDS Settings,\\nCN=PROMOTEDVDC,\\n..." -> key_0__label [style=invis]; +"CN=NTDS Settings,\\nCN=SERVER1,\\n..." -> key_0__label [style=invis]; +"CN=NTDS Settings,\\nCN=SERVER2,\\n..." -> key_0__label [style=invis]; +"CN=NTDS Settings,\\nCN=SERVER3,\\n..." -> key_0__label [style=invis]; +"CN=NTDS Settings,\\nCN=SERVER4,\\n..." -> key_0__label [style=invis]; +"CN=NTDS Settings,\\nCN=SERVER5,\\n..." -> key_0__label [style=invis] key_0__label -> elision0 [style=invis; weight=9] } From f546aab853917d9bdb6fd9f30ce3056c897570b7 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 19 Apr 2018 16:15:58 +0100 Subject: [PATCH 18/57] python3: Ensure some attributes are coverted to string before use. --- python/samba/kcc/kcc_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/samba/kcc/kcc_utils.py b/python/samba/kcc/kcc_utils.py index 23fbd40e904..adc9d02c93c 100644 --- a/python/samba/kcc/kcc_utils.py +++ b/python/samba/kcc/kcc_utils.py @@ -993,7 +993,7 @@ def load_connection(self, samdb): self.schedule = ndr_unpack(drsblobs.schedule, msg["schedule"][0]) if "whenCreated" in msg: - self.whenCreated = ldb.string_to_time(msg["whenCreated"][0]) + self.whenCreated = ldb.string_to_time(msg["whenCreated"][0].decode('utf8')) if "fromServer" in msg: dsdn = dsdb_Dn(samdb, msg["fromServer"][0].decode('utf8')) @@ -1919,10 +1919,10 @@ def load_transport(self, samdb): self.options = int(msg["options"][0]) if "transportAddressAttribute" in msg: - self.address_attr = str(msg["transportAddressAttribute"][0]) + self.address_attr = msg["transportAddressAttribute"][0].decode('utf8') if "name" in msg: - self.name = str(msg["name"][0]) + self.name = msg["name"][0].decode('utf8') if "bridgeheadServerListBL" in msg: for value in msg["bridgeheadServerListBL"]: From 662ff0ffd1319cf7510a66597f19348d5408a0fc Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 19 Apr 2018 16:17:02 +0100 Subject: [PATCH 19/57] python3: couple of changes to ensure visualize works with py2/py3 * convert keys to list (is an iterator in py3) and since we are passing it as a param someone could try to find an item in it more than once (and that would fail) * make sure a bytes attribute is converted to string * make sure we handles a bytes in py3 or str in py2 and convert to str and unicode respectively --- python/samba/netcmd/visualize.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/samba/netcmd/visualize.py b/python/samba/netcmd/visualize.py index 9c0383f1f89..ad684e92413 100644 --- a/python/samba/netcmd/visualize.py +++ b/python/samba/netcmd/visualize.py @@ -35,6 +35,7 @@ import time from samba.kcc import KCC from samba.kcc.kcc_utils import KCCError +from samba.compat import text_type from io import open COMMON_OPTIONS = [ Option("-H", "--URL", help="LDB URL for database or target server", @@ -51,7 +52,7 @@ choices=['yes', 'no', 'auto']), Option("--color-scheme", help=("use this colour scheme " "(implies --color=yes)"), - choices=COLOUR_SETS.keys()), + choices=list(COLOUR_SETS.keys())), Option("-S", "--shorten-names", help="don't print long common suffixes", action='store_true', default=False), @@ -110,7 +111,7 @@ def write(self, s, fn=None, suffix='.dot', utf8=None): encoding = None if utf8: encoding = 'utf8' - if isinstance(s, str): + if not isinstance(s, text_type): s = s.decode('utf8') if fn is None or fn == '-': # we're just using stdout (a.k.a self.outf) @@ -434,7 +435,7 @@ def run(self, H=None, output=None, shorten_names=False, for msg in res: msgdn = str(msg.dn) dest_dn = msgdn[msgdn.index(',') + 1:] - attested_edges.append((msg['fromServer'][0], + attested_edges.append((msg['fromServer'][0].decode('utf8'), dest_dn, ntds_dn)) # now we overlay all the graphs and generate styles accordingly @@ -455,7 +456,7 @@ def run(self, H=None, output=None, shorten_names=False, if not talk_to_remote: # If we are not talking to remote servers, we list all # the connections. - graph_edges = edges.keys() + graph_edges = list(edges.keys()) title = 'NTDS Connections known to %s' % local_dsa_dn epilog = '' From 5bb6fdd5c3060a66e851b013606599373fec1810 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 20 Apr 2018 16:34:17 +0100 Subject: [PATCH 20/57] python2/python3 compat tweaks --- python/samba/netcmd/visualize.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/samba/netcmd/visualize.py b/python/samba/netcmd/visualize.py index ad684e92413..3a4c092c21f 100644 --- a/python/samba/netcmd/visualize.py +++ b/python/samba/netcmd/visualize.py @@ -166,7 +166,10 @@ def colour_hash(x): """Generate a randomish but consistent darkish colour based on the given object.""" from hashlib import md5 - c = int(md5(str(x)).hexdigest()[:6], base=16) & 0x7f7f7f + tmp_str = str(x) + if isinstance(tmp_str, text_type): + tmp_str = tmp_str.encode('utf8') + c = int(md5(tmp_str).hexdigest()[:6], base=16) & 0x7f7f7f return '#%06x' % c @@ -405,7 +408,7 @@ def run(self, H=None, output=None, shorten_names=False, res = local_kcc.samdb.search(dsa_dn, scope=SCOPE_BASE, attrs=["dNSHostName"]) - dns_name = res[0]["dNSHostName"][0] + dns_name = res[0]["dNSHostName"][0].decode('utf8') try: samdb = self.get_db("ldap://%s" % dns_name, sambaopts, credopts) From a774b62397ba58eeb75b6275d611f57f07c28c80 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 24 Apr 2018 20:34:38 +0100 Subject: [PATCH 21/57] python/samba/tests/samba_tool: fix a native string containing some non ascii "HIGH\xFFBYTE" is a string containing such text. In python2 we seem to get some problems when intermixing 'str' (e.g. bytes) with proper unicode. Note: some of the py2/py3 changes have peppered unicode around the place (where it wasn't before). --- python/samba/tests/samba_tool/dnscmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/samba/tests/samba_tool/dnscmd.py b/python/samba/tests/samba_tool/dnscmd.py index c44a3083716..2c3ced7d03c 100644 --- a/python/samba/tests/samba_tool/dnscmd.py +++ b/python/samba/tests/samba_tool/dnscmd.py @@ -48,7 +48,7 @@ def setUp(self): "EXAMPLE", "\n.COM", "!@#$%^&*()_", - "HIGH\xFFBYTE", + u"HIGH\xFFBYTE", "@.EXAMPLE.COM", "."] bad_dns = ["...", From ec34a76827ddb2dcc91a24b98d1fb20693fea976 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 20 Apr 2018 17:24:44 +0100 Subject: [PATCH 22/57] enable samba_tool.visualize_drs samba_tool.visualize_drs for py3 --- source4/selftest/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index d539870e4c1..f5d5d95e7e1 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -585,7 +585,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.timecmd", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.join", py3_compatible=True) -planpythontestsuite("none", "samba.tests.samba_tool.visualize") +planpythontestsuite("none", "samba.tests.samba_tool.visualize", py3_compatible=True) # test fsmo show @@ -1016,7 +1016,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex }, extra_path=[os.path.join(srcdir(), "samba/python"), ] ) - planpythontestsuite(env, "samba.tests.samba_tool.visualize_drs") + planpythontestsuite(env, "samba.tests.samba_tool.visualize_drs", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.kcc.kcc_utils") From 2bb82974a49228debf787dca4c365fe9e2d23b15 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 20 Apr 2018 17:42:41 +0100 Subject: [PATCH 23/57] enable samba.tests.dcerpc.srvsvc (even though it seemsnot run (dangerous test) --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index f5d5d95e7e1..80e9b14a619 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -581,7 +581,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("none", "samba.tests.dsdb_lock", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.bare", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.unix", py3_compatible=True) -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.srvsvc") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.srvsvc", py3_compatible=False) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.timecmd", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.join", py3_compatible=True) From 453d6748d575fe1a2e278a7474c1eab12194a633 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 Apr 2018 12:21:31 +0100 Subject: [PATCH 24/57] python/samba/tests: Port fsmo test to python3 --- python/samba/tests/samba_tool/fsmo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/samba/tests/samba_tool/fsmo.py b/python/samba/tests/samba_tool/fsmo.py index 7fd0ae2e033..847239d862d 100644 --- a/python/samba/tests/samba_tool/fsmo.py +++ b/python/samba/tests/samba_tool/fsmo.py @@ -36,7 +36,7 @@ def test_fsmoget(self): res = samdb.search(base=ldb.Dn(samdb, "CN=Infrastructure,DC=DomainDnsZones") + samdb.get_default_basedn(), scope=ldb.SCOPE_BASE, attrs=["fsmoRoleOwner"]) - self.assertTrue("DomainDnsZonesMasterRole owner: " + res[0]["fsmoRoleOwner"][0] in out) + self.assertTrue("DomainDnsZonesMasterRole owner: " + res[0]["fsmoRoleOwner"][0].decode('utf8') in out) except ldb.LdbError as e: (enum, string) = e.args if enum == ldb.ERR_NO_SUCH_OBJECT: @@ -47,4 +47,4 @@ def test_fsmoget(self): res = samdb.search(base=samdb.get_default_basedn(), scope=ldb.SCOPE_BASE, attrs=["fsmoRoleOwner"]) - self.assertTrue("DomainNamingMasterRole owner: " + res[0]["fsmoRoleOwner"][0] in out) + self.assertTrue("DomainNamingMasterRole owner: " + res[0]["fsmoRoleOwner"][0].decode('utf8') in out) From f7854a0760104abba0bb3253a2751b38ad1795fc Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 Apr 2018 12:21:53 +0100 Subject: [PATCH 25/57] s3/selftest: Enable samba.tests.samba_tool.fsmo for python3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 80e9b14a619..577e325b635 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -590,7 +590,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex # test fsmo show for env in ["ad_dc_ntvfs", "fl2000dc", "fl2003dc", "fl2008r2dc"]: - planpythontestsuite(env + ":local", "samba.tests.samba_tool.fsmo") + planpythontestsuite(env + ":local", "samba.tests.samba_tool.fsmo", py3_compatible=True) # test user.edit for env in ["ad_dc:local", "ad_dc_ntvfs:local", "fl2000dc:local", "fl2003dc:local", "fl2008r2dc:local"]: From 9e91be315d37d054c72c7875221aef1ec68234d8 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 Apr 2018 14:01:01 +0100 Subject: [PATCH 26/57] python/samba/netcmd: some changes to be python2/python3 compatable --- python/samba/netcmd/gpo.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/samba/netcmd/gpo.py b/python/samba/netcmd/gpo.py index cd946d9fa72..965dd3960d3 100644 --- a/python/samba/netcmd/gpo.py +++ b/python/samba/netcmd/gpo.py @@ -252,7 +252,7 @@ def copy_directory_remote_to_local(conn, remotedir, localdir): os.mkdir(l_name) else: data = conn.loadfile(r_name) - open(l_name, 'w').write(data) + open(l_name, 'wb').write(data) def copy_directory_local_to_remote(conn, localdir, remotedir): @@ -274,7 +274,7 @@ def copy_directory_local_to_remote(conn, localdir, remotedir): r_dirs.append(r_name) conn.mkdir(r_name) else: - data = open(l_name, 'r').read() + data = open(l_name, 'rb').read() conn.savefile(r_name, data) @@ -835,7 +835,7 @@ def run(self, gpo, H=None, tmpdir=None, sambaopts=None, credopts=None, versionop raise CommandError("GPO '%s' does not exist" % gpo) # verify UNC path - unc = msg['gPCFileSysPath'][0] + unc = msg['gPCFileSysPath'][0].decode('utf8') try: [dom_name, service, sharepath] = parse_unc(unc) except ValueError: @@ -1056,7 +1056,7 @@ def run(self, gpo, H=None, sambaopts=None, credopts=None, # Check if valid GPO try: msg = get_gpo_info(self.samdb, gpo=gpo)[0] - unc_path = msg['gPCFileSysPath'][0] + unc_path = msg['gPCFileSysPath'][0].decode('utf8') except Exception: raise CommandError("GPO '%s' does not exist" % gpo) @@ -1133,7 +1133,7 @@ def run(self, H=None, sambaopts=None, credopts=None, versionopts=None): for m in msg: # verify UNC path - unc = m['gPCFileSysPath'][0] + unc = m['gPCFileSysPath'][0].decode('utf8') try: [dom_name, service, sharepath] = parse_unc(unc) except ValueError: From 2f7e3c844081d7371dc34b49b002812135da2e58 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 Apr 2018 14:01:44 +0100 Subject: [PATCH 27/57] s4/selftest: enable samba.tests.samba_tool.gpo for python3 --- source4/selftest/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 577e325b635..291e4c9f56b 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -599,8 +599,8 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex # We run this test against both AD DC implemetnations because it is # the only test we have of GPO get/set behaviour, and this involves # the file server as well as the LDAP server. -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.gpo") -planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.gpo") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.gpo", py3_compatible=True) +planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.gpo",py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.processes") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.user") From b677b69ff75bc22398a505dd2dfee73ecfcb4555 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 Apr 2018 14:03:13 +0100 Subject: [PATCH 28/57] s4/selftest: enable samba.tests.samba_tool.gpo for python3 --- source4/selftest/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 291e4c9f56b..28835c29c74 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -599,8 +599,8 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex # We run this test against both AD DC implemetnations because it is # the only test we have of GPO get/set behaviour, and this involves # the file server as well as the LDAP server. -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.gpo", py3_compatible=True) -planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.gpo",py3_compatible=True) +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.gpo", py3_compatible=True) +planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.gpo", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.processes") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.user") From 2649032659e7fb39a22371f405f458a9f77981ba Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 Apr 2018 14:07:05 +0100 Subject: [PATCH 29/57] s4/selftest: enable samba.tests.samba_tool.processes for python3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 28835c29c74..12a7d2a940c 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -602,7 +602,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.gpo", py3_compatible=True) planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.gpo", py3_compatible=True) -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.processes") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.processes", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.user") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.user_wdigest") planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.user") From d04f1cebdcd3891c6603e64af848d0f7acca4c29 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 Apr 2018 15:16:11 +0100 Subject: [PATCH 30/57] python/samba/tests: use bytes for md5 --- python/samba/tests/password_hash.py | 4 ++++ python/samba/tests/samba_tool/user_wdigest.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/python/samba/tests/password_hash.py b/python/samba/tests/password_hash.py index a3a74aa25df..51703ef2e0f 100644 --- a/python/samba/tests/password_hash.py +++ b/python/samba/tests/password_hash.py @@ -34,6 +34,7 @@ import binascii from hashlib import md5 import crypt +from samba.compat import text_type USER_NAME = "PasswordHashTestUser" @@ -60,6 +61,9 @@ def get_package(sc, name): def calc_digest(user, realm, password): data = "%s:%s:%s" % (user, realm, password) + if isinstance(data, text_type): + data = data.encode('utf8') + return md5(data).hexdigest() diff --git a/python/samba/tests/samba_tool/user_wdigest.py b/python/samba/tests/samba_tool/user_wdigest.py index 35283ebfcb3..7156c2baf7e 100644 --- a/python/samba/tests/samba_tool/user_wdigest.py +++ b/python/samba/tests/samba_tool/user_wdigest.py @@ -33,6 +33,7 @@ from hashlib import md5 import random import string +from samba.compat import text_type USER_NAME = "WdigestTestUser" # Create a random 32 character password, containing only letters and @@ -45,6 +46,8 @@ # def calc_digest(user, realm, password): data = "%s:%s:%s" % (user, realm, password) + if isinstance(data, text_type): + data = data.encode('utf8') return "%s:%s:%s" % (user, realm, md5(data).hexdigest()) From 491375d817b0853d01c881bb5d7f4faf48a683e9 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 Apr 2018 18:21:05 +0100 Subject: [PATCH 31/57] python/samba/tests: samba.tests.samba_tool.user_wdigest py2/py3 compat --- python/samba/netcmd/user.py | 5 ++++- python/samba/tests/samba_tool/user_wdigest.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/python/samba/netcmd/user.py b/python/samba/netcmd/user.py index dfe167d8c7d..dbf6256fbb8 100644 --- a/python/samba/netcmd/user.py +++ b/python/samba/netcmd/user.py @@ -55,6 +55,7 @@ Option, ) +from samba.compat import string_types try: import io @@ -975,7 +976,7 @@ def get_account_attributes(self, samdb, username, basedn, filter, scope, unicodePwd = obj["unicodePwd"][0] if add_unicodePwd: del obj["unicodePwd"] - account_name = obj["sAMAccountName"][0] + account_name = obj["sAMAccountName"][0].decode('utf8') if add_sAMAcountName: del obj["sAMAccountName"] if "userPrincipalName" in obj: @@ -1157,6 +1158,8 @@ def get_wDigest(i, primary_wdigest, account_name, account_upn, primary_wdigest) try: digest = binascii.hexlify(bytearray(digests.hashes[i-1].hash)) + if not isinstance(digest, string_types): + digest = digest.decode('utf8') return "%s:%s:%s" % (user, realm, digest) except IndexError: return None diff --git a/python/samba/tests/samba_tool/user_wdigest.py b/python/samba/tests/samba_tool/user_wdigest.py index 7156c2baf7e..6937ecc3925 100644 --- a/python/samba/tests/samba_tool/user_wdigest.py +++ b/python/samba/tests/samba_tool/user_wdigest.py @@ -73,7 +73,7 @@ def setUp(self): base=self.samdb.get_config_basedn(), expression="ncName=%s" % self.samdb.get_default_basedn(), attrs=["nETBIOSName"]) - self.netbios_domain = res[0]["nETBIOSName"][0] + self.netbios_domain = res[0]["nETBIOSName"][0].decode('utf8') self.runsubcmd("user", "create", USER_NAME, From 0b83561469f533ea11e33a3fa69d1ae94e4e886e Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 Apr 2018 18:22:08 +0100 Subject: [PATCH 32/57] s4/selftest: enable samba.tests.samba_tool.user_wdigest for python3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 12a7d2a940c..5dad9a0c7fd 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -604,7 +604,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.processes", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.user") -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.user_wdigest") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.user_wdigest", py3_compatible=True) planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.user") planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.user_virtualCryptSHA") planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.user_check_password_script") From d6011c6913cc6e93b93ba84a455381c6cb8c5a1e Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 24 Apr 2018 16:37:18 +0100 Subject: [PATCH 33/57] python/samba/netcmd: Fix exception tuple assignment assigning a tuple to exception doesn't work in py3, for code to be py2/p3 compatable you assign to exception.args instead --- python/samba/netcmd/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/samba/netcmd/__init__.py b/python/samba/netcmd/__init__.py index 77976780150..9df096d5bd3 100644 --- a/python/samba/netcmd/__init__.py +++ b/python/samba/netcmd/__init__.py @@ -103,7 +103,7 @@ def show_command_error(self, e): force_traceback = True if isinstance(inner_exception, LdbError): - (ldb_ecode, ldb_emsg) = inner_exception + (ldb_ecode, ldb_emsg) = inner_exception.args self.errf.write("ERROR(ldb): %s - %s\n" % (message, ldb_emsg)) elif isinstance(inner_exception, AssertionError): self.errf.write("ERROR(assert): %s\n" % message) From 5b69e7ad4677c614facb1a64114fdb4e7e785e95 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 24 Apr 2018 16:40:00 +0100 Subject: [PATCH 34/57] python/samba/netcmd: Fix possible unicode error #TODO Check this This patch sortof replaces the change made with b86c29b1e6fb for this file. This change seems strange that a string would be encoded (e.g. converted to bytes) to be passed to an api that takes a string paramater. That is change_password takes a 'string' as a password. Alternatively change_password would take bytes and the previous change would be correct --- python/samba/netcmd/user.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/samba/netcmd/user.py b/python/samba/netcmd/user.py index dbf6256fbb8..d0ceb31f3c8 100644 --- a/python/samba/netcmd/user.py +++ b/python/samba/netcmd/user.py @@ -56,6 +56,7 @@ ) from samba.compat import string_types +from samba.compat import binary_type try: import io @@ -714,7 +715,9 @@ def run(self, credopts=None, sambaopts=None, versionopts=None, self.outf.write("Sorry, passwords do not match.\n") try: - net.change_password(password.encode('utf-8')) + if isinstance(password, binary_type): + password = password.decode('utf8') + net.change_password(password) except Exception as msg: # FIXME: catch more specific exception raise CommandError("Failed to change password : %s" % msg) From 0a6a0fb77e4b404997f9e59ee4d6e70906b1bf16 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 24 Apr 2018 16:55:49 +0100 Subject: [PATCH 35/57] s4/selftest: enable samba.tests.samba_tool.user_check_password_script py3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 5dad9a0c7fd..1366abbd331 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -607,7 +607,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.user_wdigest", py3_compatible=True) planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.user") planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.user_virtualCryptSHA") -planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.user_check_password_script") +planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.user_check_password_script", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.group") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.ou") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.computer") From d91c319c23f33311dde051fd61e379624c97a37e Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 24 Apr 2018 19:07:55 +0100 Subject: [PATCH 36/57] python/samba/netcmd: fix samba.test.group for py3 --- python/samba/netcmd/group.py | 4 ++-- python/samba/tests/samba_tool/group.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/samba/netcmd/group.py b/python/samba/netcmd/group.py index a4969cc6ba9..8213a2fe1d8 100644 --- a/python/samba/netcmd/group.py +++ b/python/samba/netcmd/group.py @@ -356,7 +356,7 @@ def run(self, sambaopts=None, credopts=None, versionopts=None, H=None, self.outf.write("\n") else: for msg in res: - self.outf.write("%s\n" % msg.get("samaccountname", idx=0)) + self.outf.write("%s\n" % msg.get("samaccountname", idx=0).decode('utf8')) class cmd_group_list_members(Command): """List all members of an AD group. @@ -416,7 +416,7 @@ def run(self, groupname, credopts=None, sambaopts=None, versionopts=None, H=None member_name = msg.get("samAccountName", idx=0) if member_name is None: member_name = msg.get("cn", idx=0) - self.outf.write("%s\n" % member_name) + self.outf.write("%s\n" % member_name.decode('utf8')) except Exception as e: raise CommandError('Failed to list members of "%s" group ' % groupname, e) diff --git a/python/samba/tests/samba_tool/group.py b/python/samba/tests/samba_tool/group.py index 914b8175d15..1ade63e4eb4 100644 --- a/python/samba/tests/samba_tool/group.py +++ b/python/samba/tests/samba_tool/group.py @@ -114,7 +114,7 @@ def test_list(self): self.assertTrue(len(grouplist) > 0, "no groups found in samdb") for groupobj in grouplist: - name = groupobj.get("samaccountname", idx=0) + name = groupobj.get("samaccountname", idx=0).decode('utf8') found = self.assertMatch(out, name, "group '%s' not found" % name) @@ -135,7 +135,7 @@ def test_listmembers(self): self.assertTrue(len(grouplist) > 0, "no groups found in samdb") for groupobj in grouplist: - name = groupobj.get("samAccountName", idx=0) + name = groupobj.get("samAccountName", idx=0).decode('utf8') found = self.assertMatch(out, name, "group '%s' not found" % name) def test_move(self): From ae74ee2390b61b245c991cd4d54b8b173f96992f Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 24 Apr 2018 19:08:27 +0100 Subject: [PATCH 37/57] s4/selftest: enable samba.tests.group for py3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 1366abbd331..bd82d457147 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -608,7 +608,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.user") planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.user_virtualCryptSHA") planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.user_check_password_script", py3_compatible=True) -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.group") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.group", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.ou") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.computer") planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl") From 5e44b60bbfa761958ca7772f8c2b426d4ec2c8b8 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 26 Apr 2018 15:47:19 +0100 Subject: [PATCH 38/57] s4/selftest: enable samba.tests.samba_tool.ou for py3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index bd82d457147..c1ee662e5db 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -609,7 +609,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.user_virtualCryptSHA") planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.user_check_password_script", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.group", py3_compatible=True) -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.ou") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.ou", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.computer") planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl") planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check") From 6682f2f64853316dc38231fdeeea03ed58ee6ee0 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 26 Apr 2018 16:02:10 +0100 Subject: [PATCH 39/57] python/samba: make Exception statment py3 compatible e.g. - except Exception, e: + except Exception as e: --- python/samba/netcmd/computer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/samba/netcmd/computer.py b/python/samba/netcmd/computer.py index 3b130b1fa25..9ca8904a70e 100644 --- a/python/samba/netcmd/computer.py +++ b/python/samba/netcmd/computer.py @@ -298,7 +298,7 @@ def run(self, computername, credopts=None, sambaopts=None, versionopts=None, samdb, hostname, dns_conn, change_owner_sd, samdb.host_dns_name(), ip_address_list, self.get_logger()) - except Exception, e: + except Exception as e: raise CommandError("Failed to create computer '%s': " % computername, e) @@ -394,7 +394,7 @@ def run(self, computername, credopts=None, sambaopts=None, remove_dns_references( samdb, self.get_logger(), computer_dns_host_name, ignore_no_name=True) - except Exception, e: + except Exception as e: raise CommandError('Failed to remove computer "%s"' % samaccountname, e) self.outf.write("Deleted computer %s\n" % computername) @@ -569,7 +569,7 @@ def run(self, computername, new_ou_dn, credopts=None, sambaopts=None, new_computer_dn.add_base(full_new_ou_dn) try: samdb.rename(computer_dn, new_computer_dn) - except Exception, e: + except Exception as e: raise CommandError('Failed to move computer "%s"' % computername, e) self.outf.write('Moved computer "%s" to "%s"\n' % (computername, new_ou_dn)) From 94e3300532a585cb213e78f80db47deb3867d348 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 26 Apr 2018 18:22:21 +0100 Subject: [PATCH 40/57] python/samba/netcmd: changes for samab.tests.samba_tool.computer --- python/samba/netcmd/computer.py | 4 ++-- python/samba/remove_dc.py | 2 +- python/samba/samdb.py | 2 +- python/samba/tests/samba_tool/computer.py | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/python/samba/netcmd/computer.py b/python/samba/netcmd/computer.py index 9ca8904a70e..e646cf4911b 100644 --- a/python/samba/netcmd/computer.py +++ b/python/samba/netcmd/computer.py @@ -281,7 +281,7 @@ def run(self, computername, credopts=None, sambaopts=None, versionopts=None, expression=filters, attrs=['primaryGroupID', 'objectSid']) - group = recs[0]['primaryGroupID'][0] + group = recs[0]['primaryGroupID'][0].decode('utf8') owner = ndr_unpack(security.dom_sid, recs[0]["objectSid"][0]) dns_conn = dnsserver.dnsserver( @@ -376,7 +376,7 @@ def run(self, computername, credopts=None, sambaopts=None, computer_dn = res[0].dn computer_ac = int(res[0]["userAccountControl"][0]) if "dNSHostName" in res[0]: - computer_dns_host_name = res[0]["dNSHostName"][0] + computer_dns_host_name = res[0]["dNSHostName"][0].decode('utf8') else: computer_dns_host_name = None except IndexError: diff --git a/python/samba/remove_dc.py b/python/samba/remove_dc.py index b9726f5b84f..7cff234c61e 100644 --- a/python/samba/remove_dc.py +++ b/python/samba/remove_dc.py @@ -135,7 +135,7 @@ def dns_name_from_dn(dn): # By using a set here, duplicates via (eg) example.com/Configuration # do not matter, they become just example.com a_names_to_remove_from \ - = set(dns_name_from_dn(dn) for dn in ncs) + = set(dns_name_from_dn(dn.decode('utf8')) for dn in ncs) def a_rec_to_remove(dnsRecord): if dnsRecord.wType == DNS_TYPE_A or dnsRecord.wType == DNS_TYPE_AAAA: diff --git a/python/samba/samdb.py b/python/samba/samdb.py index a1a1f45b003..9f5a1631890 100644 --- a/python/samba/samdb.py +++ b/python/samba/samdb.py @@ -733,7 +733,7 @@ def server_site_name(self): def host_dns_name(self): """return the DNS name of this host""" res = self.search(base='', scope=ldb.SCOPE_BASE, attrs=['dNSHostName']) - return res[0]['dNSHostName'][0] + return res[0]['dNSHostName'][0].decode('utf8') def domain_dns_name(self): """return the DNS name of the domain root""" diff --git a/python/samba/tests/samba_tool/computer.py b/python/samba/tests/samba_tool/computer.py index 4036d973c12..52583601613 100644 --- a/python/samba/tests/samba_tool/computer.py +++ b/python/samba/tests/samba_tool/computer.py @@ -186,7 +186,7 @@ def test_list(self): self.assertTrue(len(computerlist) > 0, "no computers found in samdb") for computerobj in computerlist: - name = computerobj.get("samaccountname", idx=0) + name = computerobj.get("samaccountname", idx=0).decode('utf8') found = self.assertMatch(out, name, "computer '%s' not found" % name) @@ -265,7 +265,7 @@ def _create_computer(self, computer): args += ' --service-principal-name={}'.format(service_principal_name) args = args.split() - + print ('#### args %s %s' % (type(args), args)) return self.runsubcmd('computer', 'create', *args) def _create_ou(self, ou): @@ -325,5 +325,5 @@ def _find_service_principal_name(self, name, expected_service_principal_names): names = set() for computer in computer_list: for name in computer.get('servicePrincipalName', []): - names.add(name) + names.add(name.decode('utf8')) return names == set(expected_service_principal_names) From 25c32886f580e1f027afbbcbf9ac789a76833694 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 26 Apr 2018 18:23:50 +0100 Subject: [PATCH 41/57] s4/selftest/tests: Enabled samba.tests.samba_tool.computer --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index c1ee662e5db..5b4d737389d 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -610,7 +610,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.user_check_password_script", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.group", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.ou", py3_compatible=True) -planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.computer") +planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.computer", py3_compatible=True) planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl") planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check") planpythontestsuite("none", "samba.tests.samba_tool.help") From 9e7553b48b0c5b2f4ce28de133cf99708c5af588 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 27 Apr 2018 13:02:50 +0100 Subject: [PATCH 42/57] python/samba/provision: remove use of str() func for binary data Python 2 code works with str(policy["nTSecurityDescriptor"]) however this cannot work with Python 3. One could argue even the str method doesn't make sense at all (returning a string) for data. Signed-off-by: Noel Power --- python/samba/provision/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/samba/provision/__init__.py b/python/samba/provision/__init__.py index 824277bfcd0..2b161a7f5d1 100644 --- a/python/samba/provision/__init__.py +++ b/python/samba/provision/__init__.py @@ -27,6 +27,7 @@ __docformat__ = "restructuredText" from samba.compat import string_types from samba.compat import urllib_quote +from samba.compat import text_type from base64 import b64encode import errno import os @@ -1607,7 +1608,7 @@ def set_gpos_acl(sysvol, dnsdomain, domainsid, domaindn, samdb, lp, use_ntvfs, p for policy in res: acl = ndr_unpack(security.descriptor, - str(policy["nTSecurityDescriptor"])).as_sddl() + policy["nTSecurityDescriptor"][0]).as_sddl() policy_path = getpolicypath(sysvol, dnsdomain, str(policy["cn"])) set_dir_acl(policy_path, dsacl2fsacl(acl, domainsid), lp, str(domainsid), use_ntvfs, @@ -1768,7 +1769,7 @@ def check_gpos_acl(sysvol, dnsdomain, domainsid, domaindn, samdb, lp, for policy in res: acl = ndr_unpack(security.descriptor, - str(policy["nTSecurityDescriptor"])).as_sddl() + policy["nTSecurityDescriptor"][0]).as_sddl() policy_path = getpolicypath(sysvol, dnsdomain, str(policy["cn"])) check_dir_acl(policy_path, dsacl2fsacl(acl, domainsid), lp, domainsid, direct_db_access) From ae9d2805a5cd66f48c9a47283e8fb7973e540f50 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 27 Apr 2018 13:05:15 +0100 Subject: [PATCH 43/57] s4/selftest: enable samba.tests.samba_tool.ntacl for Py3 Signed-off-by: Noel Power --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 5b4d737389d..51deaac498c 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -611,7 +611,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.group", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.ou", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.computer", py3_compatible=True) -planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl") +planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl", py3_compatible=True) planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check") planpythontestsuite("none", "samba.tests.samba_tool.help") From 94ba25ba451534142b36486c9848253fea01802c Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 27 Apr 2018 15:11:54 +0100 Subject: [PATCH 44/57] python/samba/netcmd: Fix password usage for py2/py3 compatability getpass returns str (e.g. bytes) in python2 and str (unicode) in py3. Adapt code to so we don't do illegal things (like try and decode) a string in python3 Signed-off-by: Noel Power --- python/samba/netcmd/domain.py | 7 +++++-- python/samba/provision/__init__.py | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/python/samba/netcmd/domain.py b/python/samba/netcmd/domain.py index 1e242dea62e..d4835ccc940 100644 --- a/python/samba/netcmd/domain.py +++ b/python/samba/netcmd/domain.py @@ -99,6 +99,8 @@ FILL_DRS ) +from samba.compat import binary_type + string_version_to_constant = { "2008_R2" : DS_DOMAIN_FUNCTION_2008_R2, "2012": DS_DOMAIN_FUNCTION_2012, @@ -540,8 +542,9 @@ def _get_nameserver_ip(self): def _adminpass_issue(self, adminpass): """Returns error string for a bad administrator password, or None if acceptable""" - - if len(adminpass.decode('utf-8')) < DEFAULT_MIN_PWD_LENGTH: + if isinstance(adminpass, binary_type): + adminpass = adminpass.decode('utf8') + if len(adminpass) < DEFAULT_MIN_PWD_LENGTH: return "Administrator password does not meet the default minimum" \ " password length requirement (%d characters)" \ % DEFAULT_MIN_PWD_LENGTH diff --git a/python/samba/provision/__init__.py b/python/samba/provision/__init__.py index 2b161a7f5d1..569595bfb4b 100644 --- a/python/samba/provision/__init__.py +++ b/python/samba/provision/__init__.py @@ -28,6 +28,7 @@ from samba.compat import string_types from samba.compat import urllib_quote from samba.compat import text_type +from samba.compat import binary_type from base64 import b64encode import errno import os @@ -2277,7 +2278,8 @@ def provision(logger, session_info, smbconf=None, adminpass = samba.generate_random_password(12, 32) adminpass_generated = True else: - adminpass = unicode(adminpass, 'utf-8') + if isinstance(adminpass, binary_type): + adminpass = unicode(adminpass, 'utf-8') adminpass_generated = False if samdb_fill == FILL_FULL: From 04da2acebfa4522607247b97f0b6fc7fb2326fde Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 27 Apr 2018 15:13:49 +0100 Subject: [PATCH 45/57] s4/selftest: Enable samba.tests.samba_tool.provision_password_check for py3 Signed-off-by: Noel Power --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 51deaac498c..69b28138a55 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -612,7 +612,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.ou", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.computer", py3_compatible=True) planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl", py3_compatible=True) -planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check") +planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check", py3_compatible=True) planpythontestsuite("none", "samba.tests.samba_tool.help") # Run these against chgdcpass to share the runtime load From ed3d340b23dec0da78f1deb6dfd53e8b7d62ebb8 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 27 Apr 2018 15:45:49 +0100 Subject: [PATCH 46/57] python/samba/tests: Py2/Py2 ensure bytes output is converted to text type Tests in python3 are intermingling bytes and strings types. Adjust code to ensure bytes are converted to str as appropriate --- python/samba/tests/samba_tool/help.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/samba/tests/samba_tool/help.py b/python/samba/tests/samba_tool/help.py index 62e0b3eaa23..853602c053c 100644 --- a/python/samba/tests/samba_tool/help.py +++ b/python/samba/tests/samba_tool/help.py @@ -20,7 +20,7 @@ import re from samba.tests.samba_tool.base import SambaToolCmdTest from samba.tests import BlackboxProcessError - +from samba.compat import binary_type class HelpTestCase(SambaToolCmdTest): """Tests for samba-tool help and --help @@ -47,7 +47,8 @@ def test_help_tree(self): except BlackboxProcessError as e: output = e.stdout failed_commands.append(c) - + if isinstance(output, binary_type): + output = output.decode('utf8') tail = output.partition('Available subcommands:')[2] subcommands = re.findall(r'^\s*([\w-]+)\s+-', tail, re.MULTILINE) @@ -61,7 +62,8 @@ def test_help_tree(self): except BlackboxProcessError as e: output2 = e.stdout failed_commands.append(c) - + if isinstance(output2, binary_type): + output2 = output2.decode('utf8') self.assertEqual(output, output2) if not new_commands: From 383a5c4f8954531f4567012a082151822e1831f5 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 27 Apr 2018 15:49:40 +0100 Subject: [PATCH 47/57] s4/selftest: enable samba.tests.samba_tool.help for py3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 69b28138a55..6f1c262611f 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -613,7 +613,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.samba_tool.computer", py3_compatible=True) planpythontestsuite("ad_dc:local", "samba.tests.samba_tool.ntacl", py3_compatible=True) planpythontestsuite("none", "samba.tests.samba_tool.provision_password_check", py3_compatible=True) -planpythontestsuite("none", "samba.tests.samba_tool.help") +planpythontestsuite("none", "samba.tests.samba_tool.help", py3_compatible=True) # Run these against chgdcpass to share the runtime load planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.sites") From 795ba88e2141a699546108a83631d7ddfea0fe00 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Apr 2018 15:46:04 +0100 Subject: [PATCH 48/57] python/samba: Fix py2/3 relative module import --- python/samba/subnets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/samba/subnets.py b/python/samba/subnets.py index 32865bc3bcd..5be2679374e 100644 --- a/python/samba/subnets.py +++ b/python/samba/subnets.py @@ -22,7 +22,7 @@ import ldb from ldb import FLAG_MOD_ADD, FLAG_MOD_REPLACE, LdbError -from sites import SiteNotFoundException +from .sites import SiteNotFoundException class SubnetException(Exception): """Base element for Subnet errors""" From 6ecd2a06cff08520e4a8f94b8da928378a04a1fd Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Apr 2018 15:47:05 +0100 Subject: [PATCH 49/57] s4/selftest: Enable samba.tests.samba_tool.sites for py3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 6f1c262611f..74b4c79c5c6 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -616,7 +616,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planpythontestsuite("none", "samba.tests.samba_tool.help", py3_compatible=True) # Run these against chgdcpass to share the runtime load -planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.sites") +planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.sites", py3_compatible=True) planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.dnscmd") planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.rpcecho", py3_compatible=True) From e7effee1d2328a4f15affb1de4f563dc707b2b3b Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Apr 2018 16:06:12 +0100 Subject: [PATCH 50/57] s4/selftest: enable samba.tests.samba_tool.dnscmd for py3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 74b4c79c5c6..845e49c5bde 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -617,7 +617,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex # Run these against chgdcpass to share the runtime load planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.sites", py3_compatible=True) -planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.dnscmd") +planpythontestsuite("chgdcpass:local", "samba.tests.samba_tool.dnscmd", py3_compatible=True) planpythontestsuite("ad_dc_ntvfs:local", "samba.tests.dcerpc.rpcecho", py3_compatible=True) From f46227a960df0b23682a9af2a8f2dacb8fc25614 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Apr 2018 16:20:05 +0100 Subject: [PATCH 51/57] s4/selftest: enable samba.tests.dcerpc.dnsserver for python3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 845e49c5bde..96eb4826c2a 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -630,7 +630,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex "ad_dc_ntvfs:local", "samba.tests.dcerpc.registry", extra_args=['-U"$USERNAME%$PASSWORD"'], py3_compatible=True) -planoldpythontestsuite("ad_dc_ntvfs", "samba.tests.dcerpc.dnsserver", extra_args=['-U"$USERNAME%$PASSWORD"']) +planoldpythontestsuite("ad_dc_ntvfs", "samba.tests.dcerpc.dnsserver", extra_args=['-U"$USERNAME%$PASSWORD"'], py3_compatible=True) planoldpythontestsuite("ad_dc", "samba.tests.dcerpc.dnsserver", extra_args=['-U"$USERNAME%$PASSWORD"']) planoldpythontestsuite("chgdcpass", "samba.tests.dcerpc.raw_protocol", extra_args=['-U"$USERNAME%$PASSWORD"']) if have_heimdal_support: From 5c8f43fcb212d8ca67b07a60d0b4e1a9feb27b4d Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Apr 2018 16:35:59 +0100 Subject: [PATCH 52/57] s4/selftest: enable samba.tests.dcerpc.dnsserver(ad_dc) for python3 --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 96eb4826c2a..a4aa95ea474 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -631,7 +631,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex extra_args=['-U"$USERNAME%$PASSWORD"'], py3_compatible=True) planoldpythontestsuite("ad_dc_ntvfs", "samba.tests.dcerpc.dnsserver", extra_args=['-U"$USERNAME%$PASSWORD"'], py3_compatible=True) -planoldpythontestsuite("ad_dc", "samba.tests.dcerpc.dnsserver", extra_args=['-U"$USERNAME%$PASSWORD"']) +planoldpythontestsuite("ad_dc", "samba.tests.dcerpc.dnsserver", extra_args=['-U"$USERNAME%$PASSWORD"'], py3_compatible=True) planoldpythontestsuite("chgdcpass", "samba.tests.dcerpc.raw_protocol", extra_args=['-U"$USERNAME%$PASSWORD"']) if have_heimdal_support: planoldpythontestsuite("ad_dc:local", "samba.tests.auth_log", extra_args=['-U"$USERNAME%$PASSWORD"'], From 18056292cab8a8be502e1bfea050e2a0dc8c119d Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Apr 2018 18:31:36 +0100 Subject: [PATCH 53/57] python/samba/tests: ensure byte content (not strings) --- python/samba/tests/dcerpc/raw_testcase.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/samba/tests/dcerpc/raw_testcase.py b/python/samba/tests/dcerpc/raw_testcase.py index 15bf92993b1..fc89f70f1d3 100644 --- a/python/samba/tests/dcerpc/raw_testcase.py +++ b/python/samba/tests/dcerpc/raw_testcase.py @@ -138,7 +138,7 @@ def do_generic_bind(self, ctx, auth_context=None, ctx_list = [ctx] if auth_context is not None: - from_server = "" + from_server = b"" (finished, to_server) = auth_context["gensec"].update(from_server) self.assertFalse(finished) @@ -147,7 +147,7 @@ def do_generic_bind(self, ctx, auth_context=None, auth_context_id=auth_context["auth_context_id"], auth_blob=to_server) else: - auth_info = "" + auth_info = b"" req = self.generate_bind(call_id=call_id, pfc_flags=pfc_flags, @@ -331,14 +331,14 @@ def do_single_request(self, call_id, ctx, io, else: sig_size = 16 - zero_sig = "\x00"*sig_size + zero_sig = b"\x00"*sig_size auth_info = self.generate_auth(auth_type=auth_context["auth_type"], auth_level=auth_context["auth_level"], auth_pad_length=auth_pad_length, auth_context_id=auth_context["auth_context_id"], auth_blob=zero_sig) else: - auth_info="" + auth_info=b"" pfc_flags = samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_FIRST pfc_flags |= samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_LAST @@ -613,7 +613,7 @@ def generate_auth(self, if hexdump: sys.stderr.write("generate_auth: %d\n%s" % (len(ai), self.hexdump(ai))) else: - ai = "" + ai = b"" return ai From 2d11675a2d2c375beed21a7a5c4ee2900b200b0c Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Apr 2018 18:43:54 +0100 Subject: [PATCH 54/57] python/samba/tests: Py2/Py3 allow import of ndr_(un)pack to work --- python/samba/tests/dcerpc/raw_testcase.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/samba/tests/dcerpc/raw_testcase.py b/python/samba/tests/dcerpc/raw_testcase.py index fc89f70f1d3..05ab560276f 100644 --- a/python/samba/tests/dcerpc/raw_testcase.py +++ b/python/samba/tests/dcerpc/raw_testcase.py @@ -26,7 +26,7 @@ from samba import gensec from samba.credentials import Credentials from samba.tests import TestCase - +from samba.ndr import ndr_pack, ndr_unpack class RawDCERPCTest(TestCase): """A raw DCE/RPC Test case.""" @@ -424,7 +424,7 @@ def do_single_request(self, call_id, ctx, io, if hexdump: sys.stderr.write("stub_out: %d\n%s" % (len(stub_out), self.hexdump(stub_out))) - samba.ndr.ndr_unpack_out(io, stub_out, bigendian=bigendian, ndr64=ndr64, + ndr_unpack_out(io, stub_out, bigendian=bigendian, ndr64=ndr64, allow_remaining=allow_remaining) if ndr_print: sys.stderr.write("out: %s" % samba.ndr.ndr_print_out(io)) @@ -441,7 +441,7 @@ def epmap_reconnect(self, abstract, transfer=None, object=None): ctx = self.prepare_presentation(samba.dcerpc.epmapper.abstract_syntax(), transfer, context_id=0) - data1 = samba.ndr.ndr_pack(abstract) + data1 = ndr_pack(abstract) lhs1 = samba.dcerpc.epmapper.epm_lhs() lhs1.protocol = samba.dcerpc.epmapper.EPM_PROTOCOL_UUID lhs1.lhs_data = data1[:18] @@ -450,7 +450,7 @@ def epmap_reconnect(self, abstract, transfer=None, object=None): floor1 = samba.dcerpc.epmapper.epm_floor() floor1.lhs = lhs1 floor1.rhs = rhs1 - data2 = samba.ndr.ndr_pack(transfer) + data2 = ndr_pack(transfer) lhs2 = samba.dcerpc.epmapper.epm_lhs() lhs2.protocol = samba.dcerpc.epmapper.EPM_PROTOCOL_UUID lhs2.lhs_data = data2[:18] @@ -515,7 +515,7 @@ def send_pdu(self, req, ndr_print=None, hexdump=None): if hexdump is None: hexdump = self.do_hexdump try: - req_pdu = samba.ndr.ndr_pack(req) + req_pdu = ndr_pack(req) if ndr_print: sys.stderr.write("send_pdu: %s" % samba.ndr.ndr_print(req)) if hexdump: @@ -573,7 +573,7 @@ def recv_pdu_raw(self, ndr_print=None, hexdump=None, timeout=None): rep_pdu = self.recv_raw(hexdump=hexdump, timeout=timeout) if rep_pdu is None: return (None,None) - rep = samba.ndr.ndr_unpack(samba.dcerpc.dcerpc.ncacn_packet, rep_pdu, allow_remaining=True) + rep = ndr_unpack(samba.dcerpc.dcerpc.ncacn_packet, rep_pdu, allow_remaining=True) if ndr_print: sys.stderr.write("recv_pdu: %s" % samba.ndr.ndr_print(rep)) self.assertEqual(rep.frag_length, len(rep_pdu)) @@ -607,7 +607,7 @@ def generate_auth(self, a.auth_context_id= auth_context_id a.credentials = auth_blob - ai = samba.ndr.ndr_pack(a) + ai = ndr_pack(a) if ndr_print: sys.stderr.write("generate_auth: %s" % samba.ndr.ndr_print(a)) if hexdump: @@ -628,7 +628,7 @@ def parse_auth(self, auth_info, ndr_print=None, hexdump=None): if hexdump: sys.stderr.write("parse_auth: %d\n%s" % (len(auth_info), self.hexdump(auth_info))) - a = samba.ndr.ndr_unpack(samba.dcerpc.dcerpc.auth, auth_info, allow_remaining=True) + a = ndr_unpack(samba.dcerpc.dcerpc.auth, auth_info, allow_remaining=True) if ndr_print: sys.stderr.write("parse_auth: %s" % samba.ndr.ndr_print(a)) @@ -661,7 +661,7 @@ def generate_pdu(self, ptype, call_id, payload, p.call_id = call_id p.u = payload - pdu = samba.ndr.ndr_pack(p) + pdu = ndr_pack(p) p.frag_length = len(pdu) return p From fa1708d85c2c96b2b9b6833a8b271b2b9bb62121 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 1 May 2018 12:24:47 +0100 Subject: [PATCH 55/57] python/samba/test/dcerpc: Py3 port of samba.tests.dcerpc.raw_protocol Port code to allow this test run with either py2 or py3 Signed-off-by: Noel Power --- python/samba/tests/dcerpc/raw_protocol.py | 339 +++++++++++++++--------------- python/samba/tests/dcerpc/raw_testcase.py | 31 +-- 2 files changed, 189 insertions(+), 181 deletions(-) diff --git a/python/samba/tests/dcerpc/raw_protocol.py b/python/samba/tests/dcerpc/raw_protocol.py index ff815e97ca6..ccd4102a95d 100755 --- a/python/samba/tests/dcerpc/raw_protocol.py +++ b/python/samba/tests/dcerpc/raw_protocol.py @@ -31,6 +31,7 @@ import struct from samba import gensec from samba.tests.dcerpc.raw_testcase import RawDCERPCTest +from samba.compat import binary_type global_ndr_print = False global_hexdump = False @@ -71,13 +72,13 @@ def _test_no_auth_request_bind_pfc_flags(self, req_pfc_flags, rep_pfc_flags): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # And now try a request req = self.generate_request(call_id = 1, context_id=ctx1.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -116,7 +117,7 @@ def _test_no_auth_request_alter_pfc_flags(self, req_pfc_flags, rep_pfc_flags): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # And now try a alter context req = self.generate_alter(call_id=0, pfc_flags=req_pfc_flags, ctx_list=[ctx1]) @@ -138,13 +139,13 @@ def _test_no_auth_request_alter_pfc_flags(self, req_pfc_flags, rep_pfc_flags): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # And now try a request req = self.generate_request(call_id = 1, context_id=ctx1.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -370,7 +371,7 @@ def test_no_auth_no_ctx(self): self.assertEquals(rep.u.versions[0].rpc_vers, req.rpc_vers) self.assertEquals(rep.u.versions[0].rpc_vers_minor, req.rpc_vers_minor) self.assertEquals(len(rep.u._pad), 3) - self.assertEquals(rep.u._pad, '\0' * 3) + self.assertEquals(rep.u._pad, b'\0' * 3) def test_invalid_auth_noctx(self): req = self.generate_bind(call_id=0) @@ -385,7 +386,7 @@ def test_invalid_auth_noctx(self): self.assertEquals(rep.u.versions[0].rpc_vers, req.rpc_vers) self.assertEquals(rep.u.versions[0].rpc_vers_minor, req.rpc_vers_minor) self.assertEquals(len(rep.u._pad), 3) - self.assertEquals(rep.u._pad, '\0' * 3) + self.assertEquals(rep.u._pad, b'\0' * 3) def test_no_auth_valid_valid_request(self): ndr32 = base.transfer_syntax_ndr() @@ -408,14 +409,14 @@ def test_no_auth_valid_valid_request(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_ACCEPTANCE) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # Send a bind again tsf2_list = [ndr32] @@ -436,7 +437,7 @@ def test_no_auth_valid_valid_request(self): self.assertEquals(rep.u.versions[0].rpc_vers, req.rpc_vers) self.assertEquals(rep.u.versions[0].rpc_vers_minor, req.rpc_vers_minor) self.assertEquals(len(rep.u._pad), 3) - self.assertEquals(rep.u._pad, '\0' * 3) + self.assertEquals(rep.u._pad, b'\0' * 3) # wait for a disconnect rep = self.recv_pdu() @@ -456,7 +457,7 @@ def test_no_auth_invalid_valid_request(self): self.assertEquals(rep.u.versions[0].rpc_vers, req.rpc_vers) self.assertEquals(rep.u.versions[0].rpc_vers_minor, req.rpc_vers_minor) self.assertEquals(len(rep.u._pad), 3) - self.assertEquals(rep.u._pad, '\0' * 3) + self.assertEquals(rep.u._pad, b'\0' * 3) # wait for a disconnect rep = self.recv_pdu() @@ -484,14 +485,14 @@ def test_alter_no_auth_no_ctx(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_ACCEPTANCE) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # Send a alter req = self.generate_alter(call_id=1, ctx_list=[]) @@ -537,14 +538,14 @@ def test_no_auth_presentation_ctx_valid1(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_ACCEPTANCE) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # Send a alter req = self.generate_alter(call_id=1, ctx_list=[ctx1]) @@ -564,12 +565,12 @@ def test_no_auth_presentation_ctx_valid1(self): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 2, context_id=ctx1.context_id, opnum=0xffff, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_FAULT, req.call_id, @@ -607,14 +608,14 @@ def test_no_auth_presentation_ctx_invalid1(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_PROVIDER_REJECTION) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_ABSTRACT_SYNTAX_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # Send a alter req = self.generate_alter(call_id=1, ctx_list=[ctx1]) @@ -634,12 +635,12 @@ def test_no_auth_presentation_ctx_invalid1(self): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_ABSTRACT_SYNTAX_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 2, context_id=12345, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_FAULT, req.call_id, @@ -672,7 +673,7 @@ def test_no_auth_presentation_ctx_invalid1(self): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_ABSTRACT_SYNTAX_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) def test_no_auth_presentation_ctx_invalid2(self): ndr32 = base.transfer_syntax_ndr() @@ -697,7 +698,7 @@ def test_no_auth_presentation_ctx_invalid2(self): self.assertEquals(rep.u.versions[0].rpc_vers, req.rpc_vers) self.assertEquals(rep.u.versions[0].rpc_vers_minor, req.rpc_vers_minor) self.assertEquals(len(rep.u._pad), 3) - self.assertEquals(rep.u._pad, '\0' * 3) + self.assertEquals(rep.u._pad, b'\0' * 3) # wait for a disconnect rep = self.recv_pdu() @@ -727,14 +728,14 @@ def test_no_auth_presentation_ctx_invalid3(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_ACCEPTANCE) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) tsf1b_list = [] ctx1b = dcerpc.ctx_list() @@ -788,14 +789,14 @@ def test_no_auth_presentation_ctx_invalid4(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_ACCEPTANCE) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # With a known but wrong syntax we get a protocol error # see test_no_auth_presentation_ctx_valid2 @@ -850,14 +851,14 @@ def test_no_auth_presentation_ctx_valid2(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_ACCEPTANCE) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # With a unknown but wrong syntaxes we get NO protocol error # see test_no_auth_presentation_ctx_invalid4 @@ -886,12 +887,12 @@ def test_no_auth_presentation_ctx_valid2(self): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_TRANSFER_SYNTAXES_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 2, context_id=ctx1a.context_id, opnum=0xffff, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_FAULT, req.call_id, @@ -928,14 +929,14 @@ def test_no_auth_presentation_ctx_no_ndr64(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_PROVIDER_REJECTION) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_ABSTRACT_SYNTAX_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) tsf0_list = [ndr32] ctx0 = dcerpc.ctx_list() @@ -961,12 +962,12 @@ def test_no_auth_presentation_ctx_no_ndr64(self): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 1, context_id=ctx0.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1000,12 +1001,12 @@ def test_no_auth_presentation_ctx_no_ndr64(self): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 1, context_id=ctx1.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1039,12 +1040,12 @@ def test_no_auth_presentation_ctx_no_ndr64(self): self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 1, context_id=ctx2.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1090,12 +1091,12 @@ def test_no_auth_presentation_ctx_no_ndr64(self): self.assertEquals(rep.u.ctx_list[1].reason, dcerpc.DCERPC_BIND_ACK_REASON_TRANSFER_SYNTAXES_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[1].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 1, context_id=ctx3.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1127,12 +1128,12 @@ def test_no_auth_presentation_ctx_no_ndr64(self): self.assertEquals(rep.u.ctx_list[1].reason, dcerpc.DCERPC_BIND_ACK_REASON_TRANSFER_SYNTAXES_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[1].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 1, context_id=ctx4.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1145,7 +1146,7 @@ def test_no_auth_presentation_ctx_no_ndr64(self): req = self.generate_request(call_id = 1, context_id=ctx3.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1177,12 +1178,12 @@ def test_no_auth_presentation_ctx_no_ndr64(self): self.assertEquals(rep.u.ctx_list[1].reason, dcerpc.DCERPC_BIND_ACK_REASON_TRANSFER_SYNTAXES_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[1].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 1, context_id=ctx4.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1195,7 +1196,7 @@ def test_no_auth_presentation_ctx_no_ndr64(self): req = self.generate_request(call_id = 1, context_id=ctx3.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1241,12 +1242,12 @@ def test_no_auth_presentation_ctx_no_ndr64(self): self.assertEquals(rep.u.ctx_list[1].reason, dcerpc.DCERPC_BIND_ACK_REASON_TRANSFER_SYNTAXES_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[1].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 1, context_id=ctx5mgmt.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1278,12 +1279,12 @@ def test_no_auth_presentation_ctx_no_ndr64(self): self.assertEquals(rep.u.ctx_list[1].reason, dcerpc.DCERPC_BIND_ACK_REASON_TRANSFER_SYNTAXES_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[1].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) req = self.generate_request(call_id = 1, context_id=ctx5mgmt.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1317,13 +1318,13 @@ def test_no_auth_bind_time_none_simple(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_NEGOTIATE_ACK) self.assertEquals(rep.u.ctx_list[0].reason, features) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) def test_no_auth_bind_time_none_ignore_additional(self): features1 = 0 @@ -1354,13 +1355,13 @@ def test_no_auth_bind_time_none_ignore_additional(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_NEGOTIATE_ACK) self.assertEquals(rep.u.ctx_list[0].reason, features1) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) def test_no_auth_bind_time_only_first(self): features1 = dcerpc.DCERPC_BIND_TIME_KEEP_CONNECTION_ON_ORPHAN @@ -1389,14 +1390,14 @@ def test_no_auth_bind_time_only_first(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_PROVIDER_REJECTION) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_ABSTRACT_SYNTAX_NOT_SUPPORTED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) def test_no_auth_bind_time_twice(self): features1 = dcerpc.DCERPC_BIND_TIME_KEEP_CONNECTION_ON_ORPHAN @@ -1432,7 +1433,7 @@ def test_no_auth_bind_time_twice(self): self.assertEquals(rep.u.versions[0].rpc_vers, req.rpc_vers) self.assertEquals(rep.u.versions[0].rpc_vers_minor, req.rpc_vers_minor) self.assertEquals(len(rep.u._pad), 3) - self.assertEquals(rep.u._pad, '\0' * 3) + self.assertEquals(rep.u._pad, b'\0' * 3) # wait for a disconnect rep = self.recv_pdu() @@ -1463,13 +1464,13 @@ def test_no_auth_bind_time_keep_on_orphan_simple(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_NEGOTIATE_ACK) self.assertEquals(rep.u.ctx_list[0].reason, features) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) def test_no_auth_bind_time_keep_on_orphan_ignore_additional(self): features1 = dcerpc.DCERPC_BIND_TIME_KEEP_CONNECTION_ON_ORPHAN @@ -1499,13 +1500,13 @@ def test_no_auth_bind_time_keep_on_orphan_ignore_additional(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_NEGOTIATE_ACK) self.assertEquals(rep.u.ctx_list[0].reason, features1) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, zero_syntax) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) def _test_auth_type_level_bind_nak(self, auth_type, auth_level, creds=None, reason=dcerpc.DCERPC_BIND_NAK_REASON_INVALID_AUTH_TYPE): @@ -1528,7 +1529,7 @@ def _test_auth_type_level_bind_nak(self, auth_type, auth_level, creds=None, auth_level=auth_level, auth_context_id=auth_context_id, g_auth_level=dcerpc.DCERPC_AUTH_LEVEL_INTEGRITY) - from_server = "" + from_server = b"" (finished, to_server) = auth_context["gensec"].update(from_server) self.assertFalse(finished) @@ -1537,7 +1538,7 @@ def _test_auth_type_level_bind_nak(self, auth_type, auth_level, creds=None, auth_context_id=auth_context["auth_context_id"], auth_blob=to_server) else: - to_server = "none" + to_server = b"none" auth_info = self.generate_auth(auth_type=auth_type, auth_level=auth_level, auth_context_id=auth_context_id, @@ -1555,7 +1556,7 @@ def _test_auth_type_level_bind_nak(self, auth_type, auth_level, creds=None, self.assertEquals(rep.u.versions[0].rpc_vers, req.rpc_vers) self.assertEquals(rep.u.versions[0].rpc_vers_minor, req.rpc_vers_minor) self.assertEquals(len(rep.u._pad), 3) - self.assertEquals(rep.u._pad, '\0' * 3) + self.assertEquals(rep.u._pad, b'\0' * 3) # wait for a disconnect rep = self.recv_pdu() @@ -1624,7 +1625,7 @@ def _test_auth_none_level_request(self, auth_level): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_ACCEPTANCE) @@ -1637,7 +1638,7 @@ def _test_auth_none_level_request(self, auth_level): req = self.generate_request(call_id = 2, context_id=ctx1.context_id, opnum=0, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1650,12 +1651,12 @@ def _test_auth_none_level_request(self, auth_level): auth_info = self.generate_auth(auth_type=auth_type, auth_level=auth_level, auth_context_id=auth_context_id, - auth_blob="none") + auth_blob=b"none") req = self.generate_request(call_id = 3, context_id=ctx1.context_id, opnum=0, - stub="", + stub=b"", auth_info=auth_info) self.send_pdu(req) rep = self.recv_pdu() @@ -1713,14 +1714,14 @@ def _test_neg_xmit_check_values(self, self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_ACCEPTANCE) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) assoc_group_id = rep.u.assoc_group_id if alter_xmit is None: @@ -1751,14 +1752,14 @@ def _test_neg_xmit_check_values(self, self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) chunk_size = rep_both - dcerpc.DCERPC_REQUEST_LENGTH req = self.generate_request(call_id = 2, context_id=ctx1.context_id, opnum=0, alloc_hint=0xffffffff, - stub="\00" * chunk_size) + stub=b"\00" * chunk_size) self.send_pdu(req,ndr_print=True,hexdump=True) rep = self.recv_pdu(ndr_print=True,hexdump=True) self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1773,7 +1774,7 @@ def _test_neg_xmit_check_values(self, context_id=ctx1.context_id, opnum=0, alloc_hint=0xffffffff, - stub="\00" * chunk_size) + stub=b"\00" * chunk_size) self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1788,7 +1789,7 @@ def _test_neg_xmit_check_values(self, context_id=ctx1.context_id, opnum=0, alloc_hint=0xffffffff, - stub="\00" * chunk_size) + stub=b"\00" * chunk_size) self.send_pdu(req) rep = self.recv_pdu() # We get a fault @@ -1871,21 +1872,21 @@ def test_alloc_hint(self): self.assertEquals(rep.u.secondary_address_size, 4) self.assertEquals(rep.u.secondary_address, "%d" % self.tcp_port) self.assertEquals(len(rep.u._pad1), 2) - self.assertEquals(rep.u._pad1, '\0' * 2) + self.assertEquals(rep.u._pad1, b'\0' * 2) self.assertEquals(rep.u.num_results, 1) self.assertEquals(rep.u.ctx_list[0].result, dcerpc.DCERPC_BIND_ACK_RESULT_ACCEPTANCE) self.assertEquals(rep.u.ctx_list[0].reason, dcerpc.DCERPC_BIND_ACK_REASON_NOT_SPECIFIED) self.assertNDRSyntaxEquals(rep.u.ctx_list[0].syntax, ndr32) - self.assertEquals(rep.u.auth_info, '\0' * 0) + self.assertEquals(rep.u.auth_info, b'\0' * 0) # And now try a request without auth_info req = self.generate_request(call_id = 2, context_id=ctx.context_id, opnum=0, alloc_hint=0xffffffff, - stub="") + stub=b"") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1899,7 +1900,7 @@ def test_alloc_hint(self): context_id=ctx.context_id, opnum=1, alloc_hint=0xffffffff, - stub="\04\00\00\00\00\00\00\00") + stub=b"\04\00\00\00\00\00\00\00") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1913,7 +1914,7 @@ def test_alloc_hint(self): context_id=ctx.context_id, opnum=1, alloc_hint=1, - stub="\04\00\00\00\00\00\00\00") + stub=b"\04\00\00\00\00\00\00\00") self.send_pdu(req) rep = self.recv_pdu() self.verify_pdu(rep, dcerpc.DCERPC_PKT_RESPONSE, req.call_id, @@ -1931,20 +1932,26 @@ def _get_netlogon_ctx(self): epmap=True, return_ack=True) server = '\\\\' + self.target_hostname - server_utf16 = unicode(server, 'utf-8').encode('utf-16-le') + if isinstance(server, binary_type): + server_utf16 = server.decode('utf-8').encode('utf-16-le') + else: + server_utf16 = server.encode('utf-16-le') computer = 'UNKNOWNCOMPUTER' - computer_utf16 = unicode(computer, 'utf-8').encode('utf-16-le') + if isinstance(server, binary_type): + computer_utf16 = computer.decode('utf-8').encode('utf-16-le') + else: + computer_utf16 = computer.encode('utf-16-le') real_stub = struct.pack(' 0: auth_pad_length = dcerpc.DCERPC_AUTH_PAD_ALIGNMENT - mod_len - stub_bin += '\x00' * auth_pad_length + stub_bin += b'\x00' * auth_pad_length if g_auth_level >= dcerpc.DCERPC_AUTH_LEVEL_INTEGRITY: sig_size = g.sig_size(len(stub_bin)) else: sig_size = 16 - zero_sig = "\x00"*sig_size + zero_sig = b"\x00"*sig_size auth_info = self.generate_auth(auth_type=auth_type, auth_level=auth_level, @@ -4645,15 +4652,15 @@ def _test_spnego_signing_auth_level_request(self, auth_level): auth_context_id=auth_context_id, ctx=ctx1) - stub_bin = '\x00' * 0 + stub_bin = b'\x00' * 0 mod_len = len(stub_bin) % dcerpc.DCERPC_AUTH_PAD_ALIGNMENT auth_pad_length = 0 if mod_len > 0: auth_pad_length = dcerpc.DCERPC_AUTH_PAD_ALIGNMENT - mod_len - stub_bin += '\x00' * auth_pad_length + stub_bin += b'\x00' * auth_pad_length sig_size = g.sig_size(len(stub_bin)) - zero_sig = "\x00"*sig_size + zero_sig = b"\x00"*sig_size auth_info = self.generate_auth(auth_type=auth_type, auth_level=auth_level, @@ -4711,15 +4718,15 @@ def _test_spnego_signing_auth_level_request(self, auth_level): g.check_packet(rep_data, rep_whole, rep_sig) - stub_bin = '\x00' * 17 + stub_bin = b'\x00' * 17 mod_len = len(stub_bin) % dcerpc.DCERPC_AUTH_PAD_ALIGNMENT auth_pad_length = 0 if mod_len > 0: auth_pad_length = dcerpc.DCERPC_AUTH_PAD_ALIGNMENT - mod_len - stub_bin += '\x00' * auth_pad_length + stub_bin += b'\x00' * auth_pad_length sig_size = g.sig_size(len(stub_bin)) - zero_sig = "\x00"*sig_size + zero_sig = b"\x00"*sig_size auth_info = self.generate_auth(auth_type=auth_type, auth_level=auth_level, @@ -4762,15 +4769,15 @@ def _test_spnego_signing_auth_level_request(self, auth_level): self.assertEquals(rep.u.reserved, 0) self.assertEquals(len(rep.u.error_and_verifier), 0) - stub_bin = '\x00' * 8 + stub_bin = b'\x00' * 8 mod_len = len(stub_bin) % dcerpc.DCERPC_AUTH_PAD_ALIGNMENT auth_pad_length = 0 if mod_len > 0: auth_pad_length = dcerpc.DCERPC_AUTH_PAD_ALIGNMENT - mod_len - stub_bin += '\x00' * auth_pad_length + stub_bin += b'\x00' * auth_pad_length sig_size = g.sig_size(len(stub_bin)) - zero_sig = "\x00"*sig_size + zero_sig = b"\x00"*sig_size auth_info = self.generate_auth(auth_type=auth_type, auth_level=auth_level, @@ -4827,15 +4834,15 @@ def _test_spnego_signing_auth_level_request(self, auth_level): g.check_packet(rep_data, rep_whole, rep_sig) - stub_bin = '\x00' * 8 + stub_bin = b'\x00' * 8 mod_len = len(stub_bin) % dcerpc.DCERPC_AUTH_PAD_ALIGNMENT auth_pad_length = 0 if mod_len > 0: auth_pad_length = dcerpc.DCERPC_AUTH_PAD_ALIGNMENT - mod_len - stub_bin += '\x00' * auth_pad_length + stub_bin += b'\x00' * auth_pad_length sig_size = g.sig_size(len(stub_bin)) - zero_sig = "\x00"*sig_size + zero_sig = b"\x00"*sig_size auth_info = self.generate_auth(auth_type=auth_type, auth_level=auth_level, diff --git a/python/samba/tests/dcerpc/raw_testcase.py b/python/samba/tests/dcerpc/raw_testcase.py index 05ab560276f..79736bf89e9 100644 --- a/python/samba/tests/dcerpc/raw_testcase.py +++ b/python/samba/tests/dcerpc/raw_testcase.py @@ -26,7 +26,8 @@ from samba import gensec from samba.credentials import Credentials from samba.tests import TestCase -from samba.ndr import ndr_pack, ndr_unpack +from samba.ndr import ndr_pack, ndr_unpack, ndr_unpack_out +from samba.compat import text_type class RawDCERPCTest(TestCase): """A raw DCE/RPC Test case.""" @@ -164,7 +165,7 @@ def do_generic_bind(self, ctx, auth_context=None, self.assertEquals(rep.u.versions[0].rpc_vers, req.rpc_vers) self.assertEquals(rep.u.versions[0].rpc_vers_minor, req.rpc_vers_minor) self.assertEquals(len(rep.u._pad), 3) - self.assertEquals(rep.u._pad, '\0' * 3) + self.assertEquals(rep.u._pad, b'\0' * 3) return self.verify_pdu(rep, samba.dcerpc.dcerpc.DCERPC_PKT_BIND_ACK, req.call_id, pfc_flags=pfc_flags) @@ -316,7 +317,7 @@ def do_single_request(self, call_id, ctx, io, sys.stderr.write("stub_in: %d\n%s" % (len(stub_in), self.hexdump(stub_in))) else: # only used for sig_size calculation - stub_in = '\xff' * samba.dcerpc.dcerpc.DCERPC_AUTH_PAD_ALIGNMENT + stub_in = b'\xff' * samba.dcerpc.dcerpc.DCERPC_AUTH_PAD_ALIGNMENT sig_size = 0 if auth_context is not None: @@ -324,7 +325,7 @@ def do_single_request(self, call_id, ctx, io, auth_pad_length = 0 if mod_len > 0: auth_pad_length = samba.dcerpc.dcerpc.DCERPC_AUTH_PAD_ALIGNMENT - mod_len - stub_in += '\x00' * auth_pad_length + stub_in += b'\x00' * auth_pad_length if auth_context["g_auth_level"] >= samba.dcerpc.dcerpc.DCERPC_AUTH_LEVEL_PACKET: sig_size = auth_context["gensec"].sig_size(len(stub_in)) @@ -461,19 +462,19 @@ def epmap_reconnect(self, abstract, transfer=None, object=None): floor2.rhs = rhs2 lhs3 = samba.dcerpc.epmapper.epm_lhs() lhs3.protocol = samba.dcerpc.epmapper.EPM_PROTOCOL_NCACN - lhs3.lhs_data = "" + lhs3.lhs_data = b"" floor3 = samba.dcerpc.epmapper.epm_floor() floor3.lhs = lhs3 floor3.rhs.minor_version = 0 lhs4 = samba.dcerpc.epmapper.epm_lhs() lhs4.protocol = samba.dcerpc.epmapper.EPM_PROTOCOL_TCP - lhs4.lhs_data = "" + lhs4.lhs_data = b"" floor4 = samba.dcerpc.epmapper.epm_floor() floor4.lhs = lhs4 floor4.rhs.port = self.tcp_port lhs5 = samba.dcerpc.epmapper.epm_lhs() lhs5.protocol = samba.dcerpc.epmapper.EPM_PROTOCOL_IP - lhs5.lhs_data = "" + lhs5.lhs_data = b"" floor5 = samba.dcerpc.epmapper.epm_floor() floor5.lhs = lhs5 floor5.rhs.ipaddr = "0.0.0.0" @@ -645,7 +646,7 @@ def generate_pdu(self, ptype, call_id, payload, if getattr(payload, 'auth_info', None): ai = payload.auth_info else: - ai = "" + ai = b"" p = samba.dcerpc.dcerpc.ncacn_packet() p.rpc_vers = rpc_vers @@ -679,7 +680,7 @@ def verify_pdu(self, p, ptype, call_id, if getattr(p.u, 'auth_info', None): ai = p.u.auth_info else: - ai = "" + ai = b"" self.assertEqual(p.rpc_vers, rpc_vers) self.assertEqual(p.rpc_vers_minor, rpc_vers_minor) @@ -706,7 +707,7 @@ def generate_bind(self, call_id, max_recv_frag=5840, assoc_group_id=0, ctx_list=[], - auth_info="", + auth_info=b"", ndr_print=None, hexdump=None): b = samba.dcerpc.dcerpc.bind() @@ -732,7 +733,7 @@ def generate_alter(self, call_id, max_recv_frag=5840, assoc_group_id=0, ctx_list=[], - auth_info="", + auth_info=b"", ndr_print=None, hexdump=None): a = samba.dcerpc.dcerpc.bind() @@ -754,7 +755,7 @@ def generate_alter(self, call_id, def generate_auth3(self, call_id, pfc_flags = samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_FIRST | samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_LAST, - auth_info="", + auth_info=b"", ndr_print=None, hexdump=None): a = samba.dcerpc.dcerpc.auth3() @@ -776,7 +777,7 @@ def generate_request(self, call_id, opnum=None, object=None, stub=None, - auth_info="", + auth_info=b"", ndr_print=None, hexdump=None): if alloc_hint is None: @@ -804,7 +805,7 @@ def generate_request(self, call_id, def generate_co_cancel(self, call_id, pfc_flags = samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_FIRST | samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_LAST, - auth_info="", + auth_info=b"", ndr_print=None, hexdump=None): c = samba.dcerpc.dcerpc.co_cancel() @@ -821,7 +822,7 @@ def generate_co_cancel(self, call_id, def generate_orphaned(self, call_id, pfc_flags = samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_FIRST | samba.dcerpc.dcerpc.DCERPC_PFC_FLAG_LAST, - auth_info="", + auth_info=b"", ndr_print=None, hexdump=None): o = samba.dcerpc.dcerpc.orphaned() From c81f6a635763dde4bee9e17a558481fb88806bda Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 1 May 2018 19:58:36 +0100 Subject: [PATCH 56/57] python/samba/tests: Py2/Py3 port for hexdump --- python/samba/tests/__init__.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/python/samba/tests/__init__.py b/python/samba/tests/__init__.py index bc8c185769b..0a8c06285fe 100644 --- a/python/samba/tests/__init__.py +++ b/python/samba/tests/__init__.py @@ -36,6 +36,7 @@ import samba.auth import samba.dcerpc.base from samba.compat import PY3, text_type +from samba.compat import PY3, string_types if not PY3: # Py2 only from samba.samdb import SamDB @@ -49,7 +50,7 @@ class SkipTest(Exception): """Test skipped.""" -HEXDUMP_FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)]) +HEXDUMP_FILTER=bytearray([x if ((len(repr(chr(x)))==3) and (x < 127)) else ord('.') for x in range(256)]) class TestCase(unittest.TestCase): """A Samba test case.""" @@ -79,16 +80,24 @@ def get_creds_ccache_name(self): def hexdump(self, src): N = 0 result = '' + is_string = isinstance(src, string_types) while src: ll = src[:8] lr = src[8:16] src = src[16:] - hl = ' '.join(["%02X" % ord(x) for x in ll]) - hr = ' '.join(["%02X" % ord(x) for x in lr]) - ll = ll.translate(HEXDUMP_FILTER) - lr = lr.translate(HEXDUMP_FILTER) + if is_string: + hl = ' '.join(["%02X" % ord(x) for x in ll]) + hr = ' '.join(["%02X" % ord(x) for x in lr]) + ll = ll.translate(HEXDUMP_FILTER) + lr = lr.translate(HEXDUMP_FILTER) + else: + hl = ' '.join(["%02X" % x for x in ll]) + hr = ' '.join(["%02X" % x for x in lr]) + ll = ll.translate(HEXDUMP_FILTER).decode('ascii') + lr = lr.translate(HEXDUMP_FILTER).decode('ascii') result += "[%04X] %-*s %-*s %s %s\n" % (N, 8*3, hl, 8*3, hr, ll, lr) N += 16 + print ('### DUMP %s' % result) return result def insta_creds(self, template=None, username=None, userpass=None, kerberos_state=None): From f7c91391d82885d6a7c9a0f9c937e3a2971eace2 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 1 May 2018 12:51:41 +0100 Subject: [PATCH 57/57] s4/selftest: enable samba.tests.dcerpc.raw_protocol for py3 Signed-off-by: Noel Power --- source4/selftest/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index a4aa95ea474..031bb659b5a 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -632,7 +632,7 @@ def planoldpythontestsuite(env, module, name=None, extra_path=[], environ={}, ex planoldpythontestsuite("ad_dc_ntvfs", "samba.tests.dcerpc.dnsserver", extra_args=['-U"$USERNAME%$PASSWORD"'], py3_compatible=True) planoldpythontestsuite("ad_dc", "samba.tests.dcerpc.dnsserver", extra_args=['-U"$USERNAME%$PASSWORD"'], py3_compatible=True) -planoldpythontestsuite("chgdcpass", "samba.tests.dcerpc.raw_protocol", extra_args=['-U"$USERNAME%$PASSWORD"']) +planoldpythontestsuite("chgdcpass", "samba.tests.dcerpc.raw_protocol", extra_args=['-U"$USERNAME%$PASSWORD"'], py3_compatible=True) if have_heimdal_support: planoldpythontestsuite("ad_dc:local", "samba.tests.auth_log", extra_args=['-U"$USERNAME%$PASSWORD"'], environ={'CLIENT_IP': '127.0.0.11',