diff --git a/python/samba/netcmd/domain/models/fields.py b/python/samba/netcmd/domain/models/fields.py index ceec9819119..36ebc9fdb4f 100644 --- a/python/samba/netcmd/domain/models/fields.py +++ b/python/samba/netcmd/domain/models/fields.py @@ -27,7 +27,7 @@ from abc import ABCMeta, abstractmethod from datetime import datetime from xml.etree import ElementTree -from ldb import Dn, MessageElement, string_to_time, timestring +from ldb import Dn, MessageElement, binary_encode, string_to_time, timestring from samba.dcerpc import security from samba.dcerpc.misc import GUID from samba.ndr import ndr_pack, ndr_unpack @@ -91,6 +91,10 @@ class Field(metaclass=ABCMeta): """ pass + def expression(self, value): + """Returns the ldb search expression for this field.""" + return f"({self.name}={binary_encode(value)})" + class IntegerField(Field): """A simple integer field, can be an int or list of int.""" diff --git a/python/samba/netcmd/domain/models/model.py b/python/samba/netcmd/domain/models/model.py index 2c63392caa8..3809d441ccb 100644 --- a/python/samba/netcmd/domain/models/model.py +++ b/python/samba/netcmd/domain/models/model.py @@ -25,7 +25,7 @@ from abc import ABCMeta, abstractmethod from ldb import (ERR_NO_SUCH_OBJECT, FLAG_MOD_ADD, FLAG_MOD_REPLACE, LdbError, Message, MessageElement, SCOPE_BASE, - SCOPE_SUBTREE, binary_encode) + SCOPE_SUBTREE) from samba.sd_utils import SDUtils from .exceptions import (DeleteError, DoesNotExist, FieldError, @@ -221,7 +221,7 @@ class Model(metaclass=ModelMeta): field = cls.fields.get(field_name) if field is None: raise ValueError(f"Unknown field '{field_name}'") - expression += f"({field.name}={binary_encode(value)})" + expression += field.expression(value) if num_fields > 1: expression += ")"