1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

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 <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
Rob van der Linde 2024-02-22 16:03:38 +13:00 committed by Andrew Bartlett
parent e1d61746c3
commit 6834a1bdc9
2 changed files with 18 additions and 18 deletions

View 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)

View 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)