]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
python:samdb: Add get_lDAPDisplayName_by_governsID_id() method
authorJennifer Sutton <jennifersutton@catalyst.net.nz>
Tue, 4 Feb 2025 05:50:32 +0000 (18:50 +1300)
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 0545aed98ebac2fec13d2c1196181fe7af553d81..bc818b8b83c542db10548eb6a8502c2521077582 100644 (file)
@@ -1116,6 +1116,10 @@ accountExpires: %u
         of a forward link attribute. If there is no backlink return None"""
         return dsdb._dsdb_get_backlink_from_lDAPDisplayName(self, ldap_display_name)
 
+    def get_lDAPDisplayName_by_governsID_id(self, governs_idns_id):
+        """return the lDAPDisplayName from an integer DRS governsID"""
+        return dsdb._dsdb_get_lDAPDisplayName_by_governsID_id(self, governs_idns_id)
+
     def set_ntds_settings_dn(self, ntds_settings_dn):
         """Set the NTDS Settings DN, as would be returned on the dsServiceName
         rootDSE attribute.
index 2ae569b2749d7291703c5be45e2100d9343565bd..2529fc3229f1608d69cc362217e2636d88c6a9b5 100644 (file)
@@ -451,6 +451,39 @@ static PyObject *py_dsdb_get_lDAPDisplayName_by_attid(PyObject *self, PyObject *
        return PyUnicode_FromString(a->lDAPDisplayName);
 }
 
+static PyObject *py_dsdb_get_lDAPDisplayName_by_governsID_id(PyObject *self,
+                                                            PyObject *args)
+{
+       PyObject *py_ldb = NULL;
+       struct ldb_context *ldb = NULL;
+       struct dsdb_schema *schema = NULL;
+       const struct dsdb_class *c = NULL;
+       uint32_t governs_id;
+
+       if (!PyArg_ParseTuple(args, "OI", &py_ldb, &governs_id)) {
+               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;
+       }
+
+       c = dsdb_class_by_governsID_id(schema, governs_id);
+       if (c == NULL) {
+               PyErr_Format(PyExc_KeyError,
+                            "Failed to find class '0x%08x'",
+                            governs_id);
+               return NULL;
+       }
+
+       return PyUnicode_FromString(c->lDAPDisplayName);
+}
+
 
 /*
   return the attribute syntax oid as a string from the attribute name
@@ -1590,6 +1623,8 @@ static PyMethodDef py_dsdb_methods[] = {
                METH_VARARGS, NULL },
        { "_dsdb_get_backlink_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_backlink_from_lDAPDisplayName,
                METH_VARARGS, NULL },
+       { "_dsdb_get_lDAPDisplayName_by_governsID_id", (PyCFunction)py_dsdb_get_lDAPDisplayName_by_governsID_id,
+               METH_VARARGS, NULL },
        { "_dsdb_set_ntds_invocation_id",
                (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
                NULL },