/* create extra attribute shortcuts */ static void dsdb_setup_attribute_shortcuts(struct ldb_context *ldb, struct dsdb_schema *schema) { struct dsdb_attribute *attribute; /* setup fast access to one_way_link and DN format */ for (attribute=schema->attributes; attribute; attribute=attribute->next) { attribute->dn_format = dsdb_dn_oid_to_format(attribute->syntax->ldap_oid); if (attribute->dn_format == DSDB_INVALID_DN) { attribute->one_way_link = false; continue; } /* these are not considered to be one way links for the purpose of DN link fixups */ if (ldb_attr_cmp("distinguishedName", attribute->lDAPDisplayName) == 0 || ldb_attr_cmp("objectCategory", attribute->lDAPDisplayName) == 0) { attribute->one_way_link = false; continue; } if (attribute->linkID == 0) { attribute->one_way_link = true; continue; } /* handle attributes with a linkID but no backlink */ if ((attribute->linkID & 1) == 0 && dsdb_attribute_by_linkID(schema, attribute->linkID + 1) == NULL) { attribute->one_way_link = true; continue; } attribute->one_way_link = false; } }
/* 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_KeyError, "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); }