dsdb: added get_lDAPDisplayName_by_attid
authorAndrew Tridgell <tridge@samba.org>
Mon, 11 Jul 2011 04:27:21 +0000 (14:27 +1000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 11 Jul 2011 04:32:45 +0000 (14:32 +1000)
this allows conversion from a DRS attribute ID to a LDAP display name

Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/dsdb/pydsdb.c
source4/scripting/python/samba/samdb.py

index 2440ac83d3c2a22564abd642308c9ee0d318ffec..463a2f99d9649fdee9da4ce4fd1f2cd53fe213e5 100644 (file)
@@ -394,6 +394,37 @@ static PyObject *py_dsdb_get_linkId_from_lDAPDisplayName(PyObject *self, PyObjec
        return PyInt_FromLong(attribute->linkID);
 }
 
+
+static PyObject *py_dsdb_get_lDAPDisplayName_by_attid(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb;
+       struct ldb_context *ldb;
+       struct dsdb_schema *schema;
+       const struct dsdb_attribute *a;
+       uint32_t attid;
+
+       if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &attid))
+               return NULL;
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       schema = dsdb_get_schema(ldb, NULL);
+
+       if (!schema) {
+               PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
+               return NULL;
+       }
+
+       a = dsdb_attribute_by_attributeID_id(schema, attid);
+       if (a == NULL) {
+               PyErr_Format(PyExc_RuntimeError, "Failed to find attribute '0x%08x'", attid);
+               return NULL;
+       }
+
+       return PyString_FromString(a->lDAPDisplayName);
+}
+
+
 /*
   return the attribute syntax oid as a string from the attribute name
  */
@@ -904,6 +935,8 @@ static PyMethodDef py_dsdb_methods[] = {
                METH_VARARGS, NULL },
        { "_dsdb_get_linkId_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_linkId_from_lDAPDisplayName,
                METH_VARARGS, NULL },
+       { "_dsdb_get_lDAPDisplayName_by_attid", (PyCFunction)py_dsdb_get_lDAPDisplayName_by_attid,
+               METH_VARARGS, NULL },
        { "_dsdb_set_ntds_invocation_id",
                (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
                NULL },
index ba0dd99cb72b2c32da24089a7ada883957c1a71b..f77ce1737db607df00d48c6e665991ed12c1586b 100644 (file)
@@ -517,6 +517,10 @@ accountExpires: %u
         '''return the linkID for a LDAP attribute as a integer'''
         return dsdb._dsdb_get_linkId_from_lDAPDisplayName(self, ldap_display_name)
 
+    def get_lDAPDisplayName_by_attid(self, attid):
+        '''return the lDAPDisplayName from an integer DRS attribute ID'''
+        return dsdb._dsdb_get_lDAPDisplayName_by_attid(self, attid)
+
     def set_ntds_settings_dn(self, ntds_settings_dn):
         """Set the NTDS Settings DN, as would be returned on the dsServiceName
         rootDSE attribute.