]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
netcmd: gmsa: add_trustee and remove_trustee change argument to sid
authorRob van der Linde <rob@catalyst.net.nz>
Mon, 11 Mar 2024 23:38:13 +0000 (12:38 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 20 Mar 2024 03:49:35 +0000 (03:49 +0000)
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/domain/models/gmsa.py
python/samba/netcmd/service_account/group_msa_membership.py

index c5c27e3cf5141801e1aa64e80085ccbe44e6d16f..e13711f22d7542dd60e4d0cdaae2cbdffeb9891a 100644 (file)
@@ -28,7 +28,6 @@ from .constants import GROUP_MSA_MEMBERSHIP_DEFAULT
 from .exceptions import FieldError
 from .fields import BinaryField, EnumField, IntegerField, SDDLField, StringField
 from .types import SupportedEncryptionTypes
-from .user import User
 
 
 class GroupManagedServiceAccount(Computer):
@@ -79,17 +78,19 @@ class GroupManagedServiceAccount(Computer):
 
         return allowed
 
-    def add_trustee(self, trustee: User):
+    def add_trustee(self, trustee: str):
         """Adds the User `trustee` to group_msa_membership.
 
         Checking if the trustee already has access is the responsibility
         of the caller.
+
+        :param trustee: SID of trustee to add
         """
         aces = self.group_msa_membership.dacl.aces
 
         ace = security.ace()
         ace.type = security.SEC_ACE_TYPE_ACCESS_ALLOWED
-        ace.trustee = security.dom_sid(trustee.object_sid)
+        ace.trustee = security.dom_sid(trustee)
         ace.access_mask = security.SEC_ADS_GENERIC_ALL
         aces.append(ace)
 
@@ -97,14 +98,16 @@ class GroupManagedServiceAccount(Computer):
         self.group_msa_membership.dacl.aces = aces
         self.group_msa_membership.dacl.num_aces = len(aces)
 
-    def remove_trustee(self, trustee: User):
+    def remove_trustee(self, trustee: str):
         """Removes the User 'trustee' from group_msa_membership.
 
         If the trustee doesn't have access already then do nothing.
+
+        :param trustee: SID of trustee to remove
         """
         aces = self.group_msa_membership.dacl.aces
 
         for ace in aces:
-            if trustee.object_sid == str(ace.trustee):
+            if trustee == str(ace.trustee):
                 self.group_msa_membership.dacl_del_ace(ace)
                 break
index 099d5de21b4dcec8891afb52c75b73644a21b062..d90dbf29fabad3a74120d3803c0ff5cd92824ca7 100644 (file)
@@ -130,7 +130,7 @@ class cmd_service_account_group_msa_membership_add(Command):
             print(f"Trustee '{trustee}' is already allowed to show managed passwords for: {gmsa}",
                   file=self.outf)
         else:
-            gmsa.add_trustee(trustee)
+            gmsa.add_trustee(trustee.object_sid)
 
             try:
                 gmsa.save(ldb)
@@ -193,7 +193,7 @@ class cmd_service_account_group_msa_membership_remove(Command):
             print(f"Trustee '{trustee}' cannot currently show managed passwords for: {gmsa}",
                   file=self.outf)
         else:
-            gmsa.remove_trustee(trustee)
+            gmsa.remove_trustee(trustee.object_sid)
 
             try:
                 gmsa.save(ldb)