]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
netcmd: models: gmsa move find method to Computer model
authorRob van der Linde <rob@catalyst.net.nz>
Thu, 22 Feb 2024 03:03:38 +0000 (16:03 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 1 Mar 2024 04:45:36 +0000 (04:45 +0000)
The find method is the same as the find method from the User model, with the exception of adding "$".

This means it is actually logic that belongs in the parent class of GroupManagedServiceAccount, which is Computer.

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/netcmd/domain/models/computer.py
python/samba/netcmd/domain/models/gmsa.py

index 1b1b014b9f802eec3d7fceb9d909b7975ef17c89..5f715db3c09be81ec61ba733911d3e84175831bb 100644 (file)
@@ -20,6 +20,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from ldb import Dn
+
 from samba.dsdb import DS_GUID_COMPUTERS_CONTAINER
 
 from .user import User
@@ -41,3 +43,19 @@ class Computer(User):
     @staticmethod
     def get_object_class():
         return "computer"
+
+    @classmethod
+    def find(cls, ldb, name):
+        """Helper function to find a service account first by Dn then username.
+
+        If the Dn can't be parsed use sAMAccountName, automatically add the $.
+        """
+        try:
+            query = {"dn": Dn(ldb, name)}
+        except ValueError:
+            if name.endswith("$"):
+                query = {"username": name}
+            else:
+                query = {"username": name + "$"}
+
+        return cls.get(ldb, **query)
index 4c429c6c9db795af0df31db2574aee1f3ac644c0..f742ae857ad544fb410ee9c8e1b3469cc75b45a3 100644 (file)
@@ -20,8 +20,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-from ldb import Dn
-
 from samba.dcerpc import security
 from samba.dsdb import DS_GUID_MANAGED_SERVICE_ACCOUNTS_CONTAINER
 
@@ -77,19 +75,3 @@ class GroupManagedServiceAccount(Computer):
                     field=GroupManagedServiceAccount.group_msa_membership)
 
         return allowed
-
-    @classmethod
-    def find(cls, ldb, name):
-        """Helper function to find a service account first by Dn then username.
-
-        If the Dn can't be parsed use sAMAccountName, automatically add the $.
-        """
-        try:
-            query = {"dn": Dn(ldb, name)}
-        except ValueError:
-            if name.endswith("$"):
-                query = {"username": name}
-            else:
-                query = {"username": name + "$"}
-
-        return cls.get(ldb, **query)