]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python/samba/emulate: PY3 port of samba.tests.emulate.traffic_packet
authorNoel Power <noel.power@suse.com>
Thu, 10 May 2018 10:57:59 +0000 (11:57 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 5 Sep 2018 21:27:13 +0000 (23:27 +0200)
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 <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/emulate/traffic.py
python/samba/emulate/traffic_packets.py

index 8f580428c9d5506e55b1838e3c9cd5e94b8816e7..ca051084460595b512b79d3e364782e9cc254247 100644 (file)
@@ -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,
index aa1d9eeeb1fdd12dd989f51a72579bac657a560e..2628727e65beeffb58f7ec7659bed7d8a331d3e0 100644 (file)
@@ -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()