summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
authorFernando J V da Silva <fernandojvsilva@yahoo.com.br>2010-02-04 16:58:31 -0200
committerAndrew Tridgell <tridge@samba.org>2010-02-15 21:57:08 +1100
commitcf1ed0678acaf1a802d4b90c464edb638ab1364f (patch)
treea7f83300eee20ebbd9397d308e4601adb7347f12 /source4/scripting/python
parent5aa42f8010d0895b5bc5018567c431f79c40f8f6 (diff)
downloadsamba-cf1ed0678acaf1a802d4b90c464edb638ab1364f.tar.gz
samba-cf1ed0678acaf1a802d4b90c464edb638ab1364f.tar.bz2
samba-cf1ed0678acaf1a802d4b90c464edb638ab1364f.zip
s4-drs: Function for accessing dsdb_load_partition_usn from Python
Returns both uSNHighest and uSNUrgent as a dict object in Python from a given partition dn. Signed-off-by: Andrew Tridgell <tridge@samba.org>
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/pyglue.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/source4/scripting/python/pyglue.c b/source4/scripting/python/pyglue.c
index 5279a0b295..57e6043eb2 100644
--- a/source4/scripting/python/pyglue.c
+++ b/source4/scripting/python/pyglue.c
@@ -438,6 +438,54 @@ static PyObject *py_dsdb_make_schema_global(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
+{
+ PyObject *py_dn, *py_ldb, *result;
+ struct ldb_dn *dn;
+ uint64_t highest_uSN, urgent_uSN;
+ struct ldb_context *ldb;
+ TALLOC_CTX *mem_ctx;
+ int ret;
+
+ mem_ctx = talloc_new(NULL);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+ if (!PyObject_AsDn(mem_ctx, py_dn, ldb, &dn)) {
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ ret = dsdb_load_partition_usn(ldb, dn, &highest_uSN, &urgent_uSN);
+ if (ret != LDB_SUCCESS) {
+ char *errstr = talloc_asprintf(mem_ctx, "Failed to load partition uSN - %s", ldb_errstring(ldb));
+ PyErr_SetString(PyExc_RuntimeError, errstr);
+ talloc_free(mem_ctx);
+ return NULL;
+ }
+
+ talloc_free(mem_ctx);
+
+ result = PyDict_New();
+
+ PyDict_SetItemString(result, "uSNHighest", PyInt_FromLong((uint64_t)highest_uSN));
+ PyDict_SetItemString(result, "uSNUrgent", PyInt_FromLong((uint64_t)urgent_uSN));
+
+
+ return result;
+
+}
+
+
static PyMethodDef py_misc_methods[] = {
{ "generate_random_str", (PyCFunction)py_generate_random_str, METH_VARARGS,
"random_password(len) -> string\n"
@@ -483,6 +531,8 @@ static PyMethodDef py_misc_methods[] = {
NULL },
{ "set_debug_level", (PyCFunction)py_set_debug_level, METH_VARARGS,
"set debug level" },
+ { "dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn, METH_VARARGS,
+ "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
{ NULL }
};