]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python:samdb: Add get_searchFlags_from_lDAPDisplayName() method
authorJennifer Sutton <jennifersutton@catalyst.net.nz>
Tue, 6 Aug 2024 01:54:56 +0000 (13:54 +1200)
committerJo Sutton <jsutton@samba.org>
Mon, 26 May 2025 02:41:36 +0000 (02:41 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15852

Signed-off-by: Jennifer Sutton <jennifersutton@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/samdb.py
source4/dsdb/pydsdb.c

index 58144386b239d2d40b20d51e7981bb21aba8f562..18297dc7cb3aecd439fe736e1cfbf254d9fb42ad 100644 (file)
@@ -1099,6 +1099,10 @@ accountExpires: %u
         """return the syntax OID for a LDAP attribute as a string"""
         return dsdb._dsdb_get_syntax_oid_from_lDAPDisplayName(self, ldap_display_name)
 
+    def get_searchFlags_from_lDAPDisplayName(self, ldap_display_name):
+        """return the searchFlags for a LDAP attribute as a integer"""
+        return dsdb._dsdb_get_searchFlags_from_lDAPDisplayName(self, ldap_display_name)
+
     def get_systemFlags_from_lDAPDisplayName(self, ldap_display_name):
         """return the systemFlags for a LDAP attribute as a integer"""
         return dsdb._dsdb_get_systemFlags_from_lDAPDisplayName(self, ldap_display_name)
index 33b27bfaa87113b07ca7e0a45fcef7daa64a988b..e3ebd3f4349f505a3e6ea0af42c23ea13f24742f 100644 (file)
@@ -314,6 +314,38 @@ static PyObject *py_dsdb_get_attid_from_lDAPDisplayName(PyObject *self, PyObject
        return PyLong_FromUnsignedLong(attid);
 }
 
+/*
+  return the searchFlags as int from the attribute name
+ */
+static PyObject *py_dsdb_get_searchFlags_from_lDAPDisplayName(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb = NULL;
+       struct ldb_context *ldb = NULL;
+       struct dsdb_schema *schema = NULL;
+       const char *ldap_display_name = NULL;
+       const struct dsdb_attribute *attribute = NULL;
+
+       if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name)) {
+               return NULL;
+       }
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       schema = dsdb_get_schema(ldb, NULL);
+       if (schema == NULL) {
+               PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
+               return NULL;
+       }
+
+       attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
+       if (attribute == NULL) {
+               PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
+               return NULL;
+       }
+
+       return PyLong_FromLong(attribute->searchFlags);
+}
+
 /*
   return the systemFlags as int from the attribute name
  */
@@ -1702,6 +1734,8 @@ static PyMethodDef py_dsdb_methods[] = {
                METH_VARARGS, NULL },
        { "_dsdb_get_syntax_oid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_syntax_oid_from_lDAPDisplayName,
                METH_VARARGS, NULL },
+       { "_dsdb_get_searchFlags_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_searchFlags_from_lDAPDisplayName,
+               METH_VARARGS, NULL },
        { "_dsdb_get_systemFlags_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_systemFlags_from_lDAPDisplayName,
                METH_VARARGS, NULL },
        { "_dsdb_get_linkId_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_linkId_from_lDAPDisplayName,