]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
netcmd: delegation: don't use assert but raise CommandError
authorRob van der Linde <rob@catalyst.net.nz>
Mon, 12 Feb 2024 03:13:13 +0000 (16:13 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 16 Feb 2024 02:41:36 +0000 (02:41 +0000)
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jo Sutton <josutton@catalyst.net.nz>
python/samba/netcmd/delegation.py

index a7a48813932551828c6e6d31e02fc76a495f838f..413dd0fd61cc9b02f90314606e0bd450154a357d 100644 (file)
@@ -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(