s4-dsdb: added get_attid_from_lDAPDisplayName() on samdb
authorAndrew Tridgell <tridge@samba.org>
Tue, 24 Aug 2010 12:08:27 +0000 (22:08 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 24 Aug 2010 22:40:04 +0000 (08:40 +1000)
This can be used to form the partial_attribute_set list for
GetNCChanges

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

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

index 1967b33e4a54c5b6537dbba40c89ba5b83478786..e51c3640c67f3669c194a47c350b915b25333ca4 100644 (file)
@@ -258,6 +258,50 @@ static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
        return ret;
 }
 
+
+static PyObject *py_dsdb_get_attid_from_lDAPDisplayName(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb, *is_schema_nc;
+       struct ldb_context *ldb;
+       struct dsdb_schema *schema;
+       const char *ldap_display_name;
+       bool schema_nc = false;
+       const struct dsdb_attribute *a;
+       uint32_t attid;
+
+       if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &is_schema_nc))
+               return NULL;
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       if (is_schema_nc) {
+               if (!PyBool_Check(is_schema_nc)) {
+                       PyErr_SetString(PyExc_TypeError, "Expected boolean is_schema_nc");
+                       return NULL;
+               }
+               if (is_schema_nc == Py_True) {
+                       schema_nc = true;
+               }
+       }
+
+       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_lDAPDisplayName(schema, ldap_display_name);
+       if (a == NULL) {
+               PyErr_Format(PyExc_RuntimeError, "Failed to find attribute '%s'", ldap_display_name);
+               return NULL;
+       }
+
+       attid = dsdb_attribute_get_attid(a, schema_nc);
+
+       return PyLong_FromUnsignedLong(attid);
+}
+
 static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
 {
        PyObject *py_ldb, *py_guid;
@@ -485,6 +529,8 @@ static PyMethodDef py_dsdb_methods[] = {
                "Set NTDS Settings DN for this LDB (allows it to be set before the DB fully exists)." },
        { "_dsdb_get_oid_from_attid", (PyCFunction)py_dsdb_get_oid_from_attid,
                METH_VARARGS, NULL },
+       { "_dsdb_get_attid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_attid_from_lDAPDisplayName,
+               METH_VARARGS, NULL },
        { "_dsdb_set_ntds_invocation_id",
                (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
                NULL },
index 14c21bc0b6d277bf08b0dccfd39d0f8078358e91..cc82e53907b93d12d2ccade1874e45dc09b5eba0 100644 (file)
@@ -440,6 +440,9 @@ accountExpires: %u
     def get_oid_from_attid(self, attid):
         return dsdb._dsdb_get_oid_from_attid(self, attid)
 
+    def get_attid_from_lDAPDisplayName(self, ldap_display_name, is_schema_nc=False):
+        return dsdb._dsdb_get_attid_from_lDAPDisplayName(self, ldap_display_name, is_schema_nc)
+
     def get_invocation_id(self):
         "Get the invocation_id id"
         return dsdb._samdb_ntds_invocation_id(self)