summaryrefslogtreecommitdiff
path: root/source4/dsdb/pydsdb.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-07-11 16:55:11 +1000
committerAndrew Tridgell <tridge@samba.org>2011-07-13 12:51:05 +0200
commit94b820af56f841ae755822a421a5c7066b7921d0 (patch)
treef563943dad3480ae40c65dbb8691a19179c4a9d3 /source4/dsdb/pydsdb.c
parent0214b7f20cfcecd3d51aa12ae4e31cc4e095d73b (diff)
downloadsamba-94b820af56f841ae755822a421a5c7066b7921d0.tar.gz
samba-94b820af56f841ae755822a421a5c7066b7921d0.tar.bz2
samba-94b820af56f841ae755822a421a5c7066b7921d0.zip
pydsdb: added get_backlink_from_lDAPDisplayName()
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org> Pair-Programmed-With: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'source4/dsdb/pydsdb.c')
-rw-r--r--source4/dsdb/pydsdb.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c
index 463a2f99d9..e74f2bb584 100644
--- a/source4/dsdb/pydsdb.c
+++ b/source4/dsdb/pydsdb.c
@@ -394,6 +394,49 @@ static PyObject *py_dsdb_get_linkId_from_lDAPDisplayName(PyObject *self, PyObjec
return PyInt_FromLong(attribute->linkID);
}
+/*
+ return the backlink attribute name (if any) for an attribute
+ */
+static PyObject *py_dsdb_get_backlink_from_lDAPDisplayName(PyObject *self, PyObject *args)
+{
+ PyObject *py_ldb;
+ struct ldb_context *ldb;
+ struct dsdb_schema *schema;
+ const char *ldap_display_name;
+ const struct dsdb_attribute *attribute, *target_attr;
+
+ 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) {
+ 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_RuntimeError, "Failed to find attribute '%s'", ldap_display_name);
+ return NULL;
+ }
+
+ if (attribute->linkID == 0) {
+ Py_RETURN_NONE;
+ }
+
+ target_attr = dsdb_attribute_by_linkID(schema, attribute->linkID ^ 1);
+ if (target_attr == NULL) {
+ /* when we add pseudo-backlinks we'll need to handle
+ them here */
+ Py_RETURN_NONE;
+ }
+
+ return PyString_FromString(target_attr->lDAPDisplayName);
+}
+
static PyObject *py_dsdb_get_lDAPDisplayName_by_attid(PyObject *self, PyObject *args)
{
@@ -937,6 +980,8 @@ static PyMethodDef py_dsdb_methods[] = {
METH_VARARGS, NULL },
{ "_dsdb_get_lDAPDisplayName_by_attid", (PyCFunction)py_dsdb_get_lDAPDisplayName_by_attid,
METH_VARARGS, NULL },
+ { "_dsdb_get_backlink_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_backlink_from_lDAPDisplayName,
+ METH_VARARGS, NULL },
{ "_dsdb_set_ntds_invocation_id",
(PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
NULL },