From: Rob van der Linde Date: Thu, 22 Feb 2024 03:03:38 +0000 (+1300) Subject: netcmd: models: gmsa move find method to Computer model X-Git-Tag: tdb-1.4.11~1586 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6834a1bdc9e4a96cbba5dbabb68d1666a9dc1bb2;p=thirdparty%2Fsamba.git netcmd: models: gmsa move find method to Computer model 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 Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/netcmd/domain/models/computer.py b/python/samba/netcmd/domain/models/computer.py index 1b1b014b9f8..5f715db3c09 100644 --- a/python/samba/netcmd/domain/models/computer.py +++ b/python/samba/netcmd/domain/models/computer.py @@ -20,6 +20,8 @@ # along with this program. If not, see . # +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) diff --git a/python/samba/netcmd/domain/models/gmsa.py b/python/samba/netcmd/domain/models/gmsa.py index 4c429c6c9db..f742ae857ad 100644 --- a/python/samba/netcmd/domain/models/gmsa.py +++ b/python/samba/netcmd/domain/models/gmsa.py @@ -20,8 +20,6 @@ # along with this program. If not, see . # -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)