1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-21 18:04:06 +03:00

netcmd: models: add SIDField field

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>
This commit is contained in:
Rob van der Linde 2023-11-21 12:42:03 +13:00 committed by Douglas Bagnall
parent 0ce9b75325
commit 91cc73352e

View File

@ -312,6 +312,31 @@ class GUIDField(Field):
return MessageElement(ndr_pack(GUID(value)), flags, self.name)
class SIDField(Field):
"""A SID field encodes and decodes SID data."""
def from_db_value(self, ldb, value):
"""Convert MessageElement with a GUID into a str or list of str."""
if value is None:
return
elif len(value) > 1 or self.many:
return [str(ndr_unpack(security.dom_sid, item)) for item in value]
else:
return str(ndr_unpack(security.dom_sid, value[0]))
def to_db_value(self, ldb, value, flags):
"""Convert str with GUID into MessageElement."""
if value is None:
return
elif isinstance(value, list):
return MessageElement(
[ndr_pack(security.dom_sid(item)) for item in value],
flags, self.name)
else:
return MessageElement(ndr_pack(security.dom_sid(value)),
flags, self.name)
class SDDLField(Field):
"""A SDDL field encodes and decodes SDDL data."""