From: Noel Power Date: Thu, 10 May 2018 10:57:59 +0000 (+0100) Subject: python/samba/emulate: PY3 port of samba.tests.emulate.traffic_packet X-Git-Tag: tdb-1.3.17~1746 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a97996c0aa0aa40cb2280145327cb17bd08df49;p=thirdparty%2Fsamba.git python/samba/emulate: PY3 port of samba.tests.emulate.traffic_packet Fixes + None cannot be used with '<' or '>' operators + ord expects 'str' + unicode doesn't exist in py3 + bytes class does not have encode method Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py index 8f580428c9d..ca051084460 100644 --- a/python/samba/emulate/traffic.py +++ b/python/samba/emulate/traffic.py @@ -50,6 +50,7 @@ from samba.dsdb import ( from samba.dcerpc.misc import SEC_CHAN_BDC from samba import gensec from samba import sd_utils +from samba.compat import get_string SLEEP_OVERHEAD = 3e-4 @@ -436,8 +437,8 @@ class ReplayContext(object): than that requested, but not significantly. """ if not failed_last_time: - if (self.badpassword_frequency > 0 and - random.random() < self.badpassword_frequency): + if (self.badpassword_frequency and self.badpassword_frequency > 0 + and random.random() < self.badpassword_frequency): try: f(bad) except: @@ -718,7 +719,7 @@ class ReplayContext(object): def get_authenticator(self): auth = self.machine_creds.new_client_authenticator() current = netr_Authenticator() - current.cred.data = [ord(x) for x in auth["credential"]] + current.cred.data = [x if isinstance(x, int) else ord(x) for x in auth["credential"]] current.timestamp = auth["timestamp"] subsequent = netr_Authenticator() @@ -1658,9 +1659,8 @@ def create_machine_account(ldb, instance_id, netbios_name, machinepass): ou = ou_name(ldb, instance_id) dn = "cn=%s,%s" % (netbios_name, ou) - utf16pw = unicode( - '"' + machinepass.encode('utf-8') + '"', 'utf-8' - ).encode('utf-16-le') + utf16pw = ('"%s"' % get_string(machinepass)).encode('utf-16-le') + start = time.time() ldb.add({ "dn": dn, @@ -1678,9 +1678,7 @@ def create_user_account(ldb, instance_id, username, userpass): """Create a user account via ldap.""" ou = ou_name(ldb, instance_id) user_dn = "cn=%s,%s" % (username, ou) - utf16pw = unicode( - '"' + userpass.encode('utf-8') + '"', 'utf-8' - ).encode('utf-16-le') + utf16pw = ('"%s"' % get_string(userpass)).encode('utf-16-le') start = time.time() ldb.add({ "dn": user_dn, diff --git a/python/samba/emulate/traffic_packets.py b/python/samba/emulate/traffic_packets.py index aa1d9eeeb1f..2628727e65b 100644 --- a/python/samba/emulate/traffic_packets.py +++ b/python/samba/emulate/traffic_packets.py @@ -564,10 +564,10 @@ def packet_rpc_netlogon_30(packet, conversation, context): # subsequent runs newpass = context.machine_creds.get_password().encode('utf-16-le') pwd_len = len(newpass) - filler = [ord(x) for x in os.urandom(DATA_LEN - pwd_len)] + filler = [x if isinstance(x, int) else ord(x) for x in os.urandom(DATA_LEN - pwd_len)] pwd = netlogon.netr_CryptPassword() pwd.length = pwd_len - pwd.data = filler + [ord(x) for x in newpass] + pwd.data = filler + [x if isinstance(x, int) else ord(x) for x in newpass] context.machine_creds.encrypt_netr_crypt_password(pwd) c.netr_ServerPasswordSet2(context.server, # must ends with $, so use get_username instead @@ -645,10 +645,11 @@ def samlogon_logon_info(domain_name, computer_name, creds): logon = netlogon.netr_NetworkInfo() - logon.challenge = [ord(x) for x in challenge] + logon.challenge = [x if isinstance(x, int) else ord(x) for x in challenge] logon.nt = netlogon.netr_ChallengeResponse() logon.nt.length = len(response["nt_response"]) - logon.nt.data = [ord(x) for x in response["nt_response"]] + logon.nt.data = [x if isinstance(x, int) else ord(x) for x in response["nt_response"]] + logon.identity_info = netlogon.netr_IdentityInfo() (username, domain) = creds.get_ntlm_username_domain()