s4-python: Add functions to get linkid and systemflags of an attribute
authorMatthieu Patou <mat@matws.net>
Wed, 6 Jul 2011 20:29:58 +0000 (00:29 +0400)
committerAndrew Tridgell <tridge@samba.org>
Mon, 11 Jul 2011 04:32:44 +0000 (14:32 +1000)
Signed-off-by: Andrew Tridgell <tridge@samba.org>
source4/dsdb/pydsdb.c
source4/scripting/python/samba/samdb.py

index 5ca6b02608aad0776d800d2a1f4204c238b7d14a..2440ac83d3c2a22564abd642308c9ee0d318ffec 100644 (file)
@@ -330,6 +330,70 @@ static PyObject *py_dsdb_get_attid_from_lDAPDisplayName(PyObject *self, PyObject
        return PyLong_FromUnsignedLong(attid);
 }
 
+/*
+  return the systemFlags as int from the attribute name
+ */
+static PyObject *py_dsdb_get_systemFlags_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;
+
+       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;
+       }
+
+       return PyInt_FromLong(attribute->systemFlags);
+}
+
+/*
+  return the linkID from the attribute name
+ */
+static PyObject *py_dsdb_get_linkId_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;
+
+       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;
+       }
+
+       return PyInt_FromLong(attribute->linkID);
+}
+
 /*
   return the attribute syntax oid as a string from the attribute name
  */
@@ -836,6 +900,10 @@ static PyMethodDef py_dsdb_methods[] = {
                METH_VARARGS, NULL },
        { "_dsdb_get_syntax_oid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_syntax_oid_from_lDAPDisplayName,
                METH_VARARGS, NULL },
+       { "_dsdb_get_systemFlags_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_systemFlags_from_lDAPDisplayName,
+               METH_VARARGS, NULL },
+       { "_dsdb_get_linkId_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_linkId_from_lDAPDisplayName,
+               METH_VARARGS, NULL },
        { "_dsdb_set_ntds_invocation_id",
                (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
                NULL },
index adb4eb08a5a8f290538494d2057ab3b15a45978c..ba0dd99cb72b2c32da24089a7ada883957c1a71b 100644 (file)
@@ -509,6 +509,14 @@ accountExpires: %u
         '''return the syntax OID for a LDAP attribute as a string'''
         return dsdb._dsdb_get_syntax_oid_from_lDAPDisplayName(self, ldap_display_name)
 
+    def get_systemFlags_from_lDAPDisplayName(self, ldap_display_name):
+        '''return the systemFlags for a LDAP attribute as a integer'''
+        return dsdb._dsdb_get_systemFlags_from_lDAPDisplayName(self, ldap_display_name)
+
+    def get_linkId_from_lDAPDisplayName(self, ldap_display_name):
+        '''return the linkID for a LDAP attribute as a integer'''
+        return dsdb._dsdb_get_linkId_from_lDAPDisplayName(self, ldap_display_name)
+
     def set_ntds_settings_dn(self, ntds_settings_dn):
         """Set the NTDS Settings DN, as would be returned on the dsServiceName
         rootDSE attribute.