From 4ea840c3a50557a5c084694d5d30fc3d0532f4ff Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 30 Nov 2010 15:59:04 +1100 Subject: s4-librpc Handle all types of GUID in the GUID() initialiser By taking a length-limited string, we can parse binary and string GUID values, which is particularly useful when reading from ldb. Andrew Bartlett --- source4/librpc/ndr/py_misc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source4/librpc') diff --git a/source4/librpc/ndr/py_misc.c b/source4/librpc/ndr/py_misc.c index 5d5b881b38..184029b59b 100644 --- a/source4/librpc/ndr/py_misc.c +++ b/source4/librpc/ndr/py_misc.c @@ -61,16 +61,24 @@ static PyObject *py_GUID_repr(PyObject *py_self) static int py_GUID_init(PyObject *self, PyObject *args, PyObject *kwargs) { - char *str = NULL; + PyObject *str = NULL; NTSTATUS status; struct GUID *guid = py_talloc_get_ptr(self); const char *kwnames[] = { "str", NULL }; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", discard_const_p(char *, kwnames), &str)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", discard_const_p(char *, kwnames), &str)) return -1; if (str != NULL) { - status = GUID_from_string(str, guid); + DATA_BLOB guid_val; + + if (!PyString_Check(str)) { + PyErr_SetString(PyExc_TypeError, "Expected a string argument to GUID()"); + return -1; + } + guid_val.data = (uint8_t *)PyString_AsString(str); + guid_val.length = PyString_Size(str); + status = GUID_from_data_blob(&guid_val, guid); if (!NT_STATUS_IS_OK(status)) { PyErr_SetNTSTATUS(status); return -1; -- cgit