Skip to content

Commit

Permalink
python/samba/emulate: Fix some more missed exception tuple assignments
Browse files Browse the repository at this point in the history
In python3 we need to change

    except LdbError as e:
-        (status, _) = e
to
    except LdbError as e:
+        (status, _) = e.args

Signed-off-by: Noel Power <[email protected]>
Reviewed-by: Andreas Schneider <[email protected]>
Reviewed-by: Douglas Bagnall <[email protected]>
  • Loading branch information
noelpower authored and abartlet committed Jul 12, 2018
1 parent d5cd9af commit 7d43571
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions python/samba/emulate/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,15 +1568,15 @@ def create_ou(ldb, instance_id):
ldb.add({"dn": ou.split(',', 1)[1],
"objectclass": "organizationalunit"})
except LdbError as e:
(status, _) = e
(status, _) = e.args
# ignore already exists
if status != 68:
raise
try:
ldb.add({"dn": ou,
"objectclass": "organizationalunit"})
except LdbError as e:
(status, _) = e
(status, _) = e.args
# ignore already exists
if status != 68:
raise
Expand Down Expand Up @@ -1626,7 +1626,7 @@ def generate_traffic_accounts(ldb, instance_id, number, password):
create_machine_account(ldb, instance_id, netbios_name, password)
added += 1
except LdbError as e:
(status, _) = e
(status, _) = e.args
if status == 68:
break
else:
Expand All @@ -1642,7 +1642,7 @@ def generate_traffic_accounts(ldb, instance_id, number, password):
create_user_account(ldb, instance_id, username, password)
added += 1
except LdbError as e:
(status, _) = e
(status, _) = e.args
if status == 68:
break
else:
Expand Down Expand Up @@ -1728,7 +1728,7 @@ def generate_users(ldb, instance_id, number, password):
create_user_account(ldb, instance_id, username, password)
users += 1
except LdbError as e:
(status, _) = e
(status, _) = e.args
# Stop if entry exists
if status == 68:
break
Expand All @@ -1752,7 +1752,7 @@ def generate_groups(ldb, instance_id, number):
create_group(ldb, instance_id, name)
groups += 1
except LdbError as e:
(status, _) = e
(status, _) = e.args
# Stop if entry exists
if status == 68:
break
Expand All @@ -1767,7 +1767,7 @@ def clean_up_accounts(ldb, instance_id):
try:
ldb.delete(ou, ["tree_delete:1"])
except LdbError as e:
(status, _) = e
(status, _) = e.args
# ignore does not exist
if status != 32:
raise
Expand Down
14 changes: 7 additions & 7 deletions python/samba/netcmd/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1715,32 +1715,32 @@ def check_runtime_error(self, runtime, val):
if runtime is None:
return False

err32 = self._uint32(runtime[0])
err32 = self._uint32(runtime.args[0])
if err32 == val:
return True

return False

class LocalRuntimeError(CommandError):
def __init__(exception_self, self, runtime, message):
err32 = self._uint32(runtime[0])
errstr = runtime[1]
err32 = self._uint32(runtime.args[0])
errstr = runtime.args[1]
msg = "LOCAL_DC[%s]: %s - ERROR(0x%08X) - %s" % (
self.local_server, message, err32, errstr)
CommandError.__init__(exception_self, msg)

class RemoteRuntimeError(CommandError):
def __init__(exception_self, self, runtime, message):
err32 = self._uint32(runtime[0])
errstr = runtime[1]
err32 = self._uint32(runtime.args[0])
errstr = runtime.args[1]
msg = "REMOTE_DC[%s]: %s - ERROR(0x%08X) - %s" % (
self.remote_server, message, err32, errstr)
CommandError.__init__(exception_self, msg)

class LocalLdbError(CommandError):
def __init__(exception_self, self, ldb_error, message):
errval = ldb_error[0]
errstr = ldb_error[1]
errval = ldb_error.args[0]
errstr = ldb_error.args[1]
msg = "LOCAL_DC[%s]: %s - ERROR(%d) - %s" % (
self.local_server, message, errval, errstr)
CommandError.__init__(exception_self, msg)
Expand Down
2 changes: 1 addition & 1 deletion python/samba/tests/net_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_net_join(self):
self.domain, netbios_name, LIBNET_JOIN_AUTOMATIC,
machinepass=machinepass)
except NTSTATUSError as e:
code = ctypes.c_uint32(e[0]).value
code = ctypes.c_uint32(e.args[0]).value
if code == ntstatus.NT_STATUS_CONNECTION_DISCONNECTED:
self.fail("Connection failure")
raise
Expand Down
2 changes: 1 addition & 1 deletion python/samba/tests/netlogonsvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_have_netlogon_connection(self):
except NTSTATUSError as e:
# On non-DC test environments, netlogon should not be running on
# the server, so we expect the test to fail here
enum = ctypes.c_uint32(e[0]).value
enum = ctypes.c_uint32(e.args[0]).value
if enum == ntstatus.NT_STATUS_OBJECT_NAME_NOT_FOUND:
self.fail("netlogon service is not running")
else:
Expand Down
4 changes: 2 additions & 2 deletions python/samba/tests/ntlmdisabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_ntlm_connection(self):
self.assertIsNotNone(conn)
except NTSTATUSError as e:
# NTLM might be blocked on this server
enum = ctypes.c_uint32(e[0]).value
enum = ctypes.c_uint32(e.args[0]).value
if enum == ntstatus.NT_STATUS_NTLM_BLOCKED:
self.fail("NTLM is disabled on this server")
else:
Expand All @@ -77,7 +77,7 @@ def test_samr_change_password(self):
conn.ChangePasswordUser2(server, username, None, None, True, None, None)
except NTSTATUSError as e:
# changing passwords should be rejected when NTLM is disabled
enum = ctypes.c_uint32(e[0]).value
enum = ctypes.c_uint32(e.args[0]).value
if enum == ntstatus.NT_STATUS_NTLM_BLOCKED:
self.fail("NTLM is disabled on this server")
elif enum == ntstatus.NT_STATUS_WRONG_PASSWORD:
Expand Down

0 comments on commit 7d43571

Please sign in to comment.