1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-04 08:22:08 +03:00

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 <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Noel Power
2018-05-10 11:57:59 +01:00
committed by Andrew Bartlett
parent 94c982004f
commit 2a97996c0a
2 changed files with 12 additions and 13 deletions

View File

@ -50,6 +50,7 @@ from samba.dsdb import (
from samba.dcerpc.misc import SEC_CHAN_BDC from samba.dcerpc.misc import SEC_CHAN_BDC
from samba import gensec from samba import gensec
from samba import sd_utils from samba import sd_utils
from samba.compat import get_string
SLEEP_OVERHEAD = 3e-4 SLEEP_OVERHEAD = 3e-4
@ -436,8 +437,8 @@ class ReplayContext(object):
than that requested, but not significantly. than that requested, but not significantly.
""" """
if not failed_last_time: if not failed_last_time:
if (self.badpassword_frequency > 0 and if (self.badpassword_frequency and self.badpassword_frequency > 0
random.random() < self.badpassword_frequency): and random.random() < self.badpassword_frequency):
try: try:
f(bad) f(bad)
except: except:
@ -718,7 +719,7 @@ class ReplayContext(object):
def get_authenticator(self): def get_authenticator(self):
auth = self.machine_creds.new_client_authenticator() auth = self.machine_creds.new_client_authenticator()
current = netr_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"] current.timestamp = auth["timestamp"]
subsequent = netr_Authenticator() subsequent = netr_Authenticator()
@ -1658,9 +1659,8 @@ def create_machine_account(ldb, instance_id, netbios_name, machinepass):
ou = ou_name(ldb, instance_id) ou = ou_name(ldb, instance_id)
dn = "cn=%s,%s" % (netbios_name, ou) dn = "cn=%s,%s" % (netbios_name, ou)
utf16pw = unicode( utf16pw = ('"%s"' % get_string(machinepass)).encode('utf-16-le')
'"' + machinepass.encode('utf-8') + '"', 'utf-8'
).encode('utf-16-le')
start = time.time() start = time.time()
ldb.add({ ldb.add({
"dn": dn, "dn": dn,
@ -1678,9 +1678,7 @@ def create_user_account(ldb, instance_id, username, userpass):
"""Create a user account via ldap.""" """Create a user account via ldap."""
ou = ou_name(ldb, instance_id) ou = ou_name(ldb, instance_id)
user_dn = "cn=%s,%s" % (username, ou) user_dn = "cn=%s,%s" % (username, ou)
utf16pw = unicode( utf16pw = ('"%s"' % get_string(userpass)).encode('utf-16-le')
'"' + userpass.encode('utf-8') + '"', 'utf-8'
).encode('utf-16-le')
start = time.time() start = time.time()
ldb.add({ ldb.add({
"dn": user_dn, "dn": user_dn,

View File

@ -564,10 +564,10 @@ def packet_rpc_netlogon_30(packet, conversation, context):
# subsequent runs # subsequent runs
newpass = context.machine_creds.get_password().encode('utf-16-le') newpass = context.machine_creds.get_password().encode('utf-16-le')
pwd_len = len(newpass) 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 = netlogon.netr_CryptPassword()
pwd.length = pwd_len 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) context.machine_creds.encrypt_netr_crypt_password(pwd)
c.netr_ServerPasswordSet2(context.server, c.netr_ServerPasswordSet2(context.server,
# must ends with $, so use get_username instead # 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 = 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 = netlogon.netr_ChallengeResponse()
logon.nt.length = len(response["nt_response"]) 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() logon.identity_info = netlogon.netr_IdentityInfo()
(username, domain) = creds.get_ntlm_username_domain() (username, domain) = creds.get_ntlm_username_domain()