samdb: added get_ntds_GUID() method
authorAndrew Tridgell <tridge@samba.org>
Thu, 25 Feb 2010 23:15:43 +0000 (10:15 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 26 Feb 2010 02:59:17 +0000 (13:59 +1100)
source4/scripting/python/pyglue.c
source4/scripting/python/samba/__init__.py

index c9e8f1414eb1cbb60a81d049cd00ef2b99122787..136b121bc023a2009bc2cc80ec650da114769758 100644 (file)
@@ -522,6 +522,39 @@ static PyObject *py_samdb_ntds_invocation_id(PyObject *self, PyObject *args)
 }
 
 
+static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb, *result;
+       struct ldb_context *ldb;
+       TALLOC_CTX *mem_ctx;
+       const struct GUID *guid;
+
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
+               talloc_free(mem_ctx);
+               return NULL;
+       }
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       guid = samdb_ntds_objectGUID(ldb);
+       if (guid == NULL) {
+               PyErr_SetStringError("Failed to find NTDS GUID");
+               talloc_free(mem_ctx);
+               return NULL;
+       }
+
+       result = PyString_FromString(GUID_string(mem_ctx, guid));
+       talloc_free(mem_ctx);
+       return result;
+}
+
+
 static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
 {
        PyObject *py_ldb, *result;
@@ -650,6 +683,8 @@ static PyMethodDef py_misc_methods[] = {
                "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
        { "samdb_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id, METH_VARARGS,
                "get the NTDS invocation ID GUID as a string"},
+       { "samdb_ntds_objectGUID", (PyCFunction)py_samdb_ntds_objectGUID, METH_VARARGS,
+               "get the NTDS objectGUID as a string"},
        { "samdb_server_site_name", (PyCFunction)py_samdb_server_site_name, METH_VARARGS,
                "get the server site name as a string"},
        { "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
index b2b7dcecb4db257aaa13285820d60cf94630ec0c..3544c494590afb8ec04ec7079ca3becc1063053d 100644 (file)
@@ -296,6 +296,10 @@ class Ldb(ldb.Ldb):
         "Get the invocation_id id"
         return glue.samdb_ntds_invocation_id(self)
 
+    def get_ntds_GUID(self):
+        "Get the NTDS objectGUID"
+        return glue.samdb_ntds_objectGUID(self)
+
     def server_site_name(self):
         "Get the server site name"
         return glue.samdb_server_site_name(self)