s4 python: fix glues functions manipulating NTTIME
authorMatthieu Patou <mat@matws.net>
Wed, 14 Apr 2010 20:18:14 +0000 (00:18 +0400)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 2 May 2010 13:59:49 +0000 (15:59 +0200)
The fix include reverse function (from NTTIME to timestamp) + fix
on the transformation of a NTTIME to a PyLong object

source4/scripting/python/pyglue.c

index f08571463526950402f6212a40ddd776c7610c5f..b2a9d2c9fd5d591b61d3421da805874018f7bc04 100644 (file)
@@ -105,7 +105,37 @@ static PyObject *py_unix2nttime(PyObject *self, PyObject *args)
 
        unix_to_nt_time(&nt, t);
 
-       return PyInt_FromLong((uint64_t)nt);
+       return PyLong_FromLongLong((uint64_t)nt);
+}
+
+static PyObject *py_nttime2unix(PyObject *self, PyObject *args)
+{
+       time_t t;
+       NTTIME nt;
+       if (!PyArg_ParseTuple(args, "K", &nt))
+               return NULL;
+
+       t = nt_time_to_unix(nt);
+
+       return PyInt_FromLong((uint64_t)t);
+}
+
+static PyObject *py_nttime2string(PyObject *self, PyObject *args)
+{
+       PyObject *ret;
+       NTTIME nt, nt2;
+       TALLOC_CTX *tmp_ctx;
+       const char *string;
+
+       if (!PyArg_ParseTuple(args, "K", &nt))
+               return NULL;
+       tmp_ctx = talloc_new(NULL);
+
+       string = nt_time_string(tmp_ctx, nt);
+       ret =  PyString_FromString(string);
+
+       talloc_free(tmp_ctx);
+       return ret;
 }
 
 static PyObject *py_set_debug_level(PyObject *self, PyObject *args)
@@ -249,6 +279,10 @@ static PyMethodDef py_misc_methods[] = {
                "Generate random password with a length >= min and <= max." },
        { "unix2nttime", (PyCFunction)py_unix2nttime, METH_VARARGS,
                "unix2nttime(timestamp) -> nttime" },
+       { "nttime2unix", (PyCFunction)py_nttime2unix, METH_VARARGS,
+               "nttime2unix(nttime) -> timestamp" },
+       { "nttime2string", (PyCFunction)py_nttime2string, METH_VARARGS,
+               "nttime2string(nttime) -> string" },
        { "dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
                NULL },
        { "dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,