From: Rob van der Linde Date: Mon, 12 Feb 2024 03:13:13 +0000 (+1300) Subject: netcmd: delegation: don't use assert but raise CommandError X-Git-Tag: tdb-1.4.11~1768 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ca05ec28ce9c3b45ad72b6df2a0aa72da3e2e26;p=thirdparty%2Fsamba.git netcmd: delegation: don't use assert but raise CommandError Signed-off-by: Rob van der Linde Reviewed-by: Andrew Bartlett Reviewed-by: Jo Sutton --- diff --git a/python/samba/netcmd/delegation.py b/python/samba/netcmd/delegation.py index a7a48813932..413dd0fd61c 100644 --- a/python/samba/netcmd/delegation.py +++ b/python/samba/netcmd/delegation.py @@ -159,7 +159,8 @@ class cmd_delegation_show(Command): "msDS-AllowedToActOnBehalfOfOtherIdentity"]) if len(res) == 0: raise CommandError("Unable to find account name '%s'" % accountname) - assert(len(res) == 1) + elif len(res) != 1: + raise CommandError("Found multiple accounts.") uac = int(res[0].get("userAccountControl")[0]) allowed = res[0].get("msDS-AllowedToDelegateTo") @@ -335,7 +336,8 @@ class cmd_delegation_add_service(Command): attrs=["msDS-AllowedToDelegateTo"]) if len(res) == 0: raise CommandError("Unable to find account name '%s'" % accountname) - assert(len(res) == 1) + elif len(res) != 1: + raise CommandError("Found multiple accounts.") msg = ldb.Message() msg.dn = res[0].dn @@ -390,7 +392,8 @@ class cmd_delegation_del_service(Command): attrs=["msDS-AllowedToDelegateTo"]) if len(res) == 0: raise CommandError("Unable to find account name '%s'" % accountname) - assert(len(res) == 1) + elif len(res) != 1: + raise CommandError("Found multiple accounts.") msg = ldb.Message() msg.dn = res[0].dn @@ -445,7 +448,8 @@ class cmd_delegation_add_principal(Command): attrs=["msDS-AllowedToActOnBehalfOfOtherIdentity"]) if len(account_res) == 0: raise CommandError(f"Unable to find account name '{accountname}'") - assert(len(account_res) == 1) + elif len(account_res) != 1: + raise CommandError("Found multiple accounts.") data = account_res[0].get( "msDS-AllowedToActOnBehalfOfOtherIdentity", idx=0) @@ -487,7 +491,8 @@ class cmd_delegation_add_principal(Command): attrs=["objectSid"]) if len(princ_res) == 0: raise CommandError(f"Unable to find principal name '{principal}'") - assert(len(princ_res) == 1) + elif len(princ_res) != 1: + raise CommandError("Found multiple accounts.") princ_sid = security.dom_sid( sam.schema_format_value( @@ -588,7 +593,8 @@ class cmd_delegation_del_principal(Command): attrs=["msDS-AllowedToActOnBehalfOfOtherIdentity"]) if len(account_res) == 0: raise CommandError("Unable to find account name '%s'" % accountname) - assert(len(account_res) == 1) + elif len(account_res) != 1: + raise CommandError("Found multiple accounts.") data = account_res[0].get( "msDS-AllowedToActOnBehalfOfOtherIdentity", idx=0) @@ -622,7 +628,8 @@ class cmd_delegation_del_principal(Command): attrs=["objectSid"]) if len(princ_res) == 0: raise CommandError(f"Unable to find principal name '{principal}'") - assert(len(princ_res) == 1) + elif len(princ_res) != 1: + raise CommandError("Found multiple accounts.") princ_sid = security.dom_sid( sam.schema_format_value(