From 8438da96ba632671327506423239169402917c51 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 24 Aug 2010 22:08:27 +1000 Subject: s4-dsdb: added get_attid_from_lDAPDisplayName() on samdb This can be used to form the partial_attribute_set list for GetNCChanges Pair-Programmed-With: Andrew Bartlett --- source4/dsdb/pydsdb.c | 46 +++++++++++++++++++++++++++++++++ source4/scripting/python/samba/samdb.py | 3 +++ 2 files changed, 49 insertions(+) (limited to 'source4') diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c index 1967b33e4a..e51c3640c6 100644 --- a/source4/dsdb/pydsdb.c +++ b/source4/dsdb/pydsdb.c @@ -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 }, diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py index 14c21bc0b6..cc82e53907 100644 --- a/source4/scripting/python/samba/samdb.py +++ b/source4/scripting/python/samba/samdb.py @@ -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) -- cgit