From: Noel Power Date: Wed, 28 Feb 2018 03:25:55 +0000 (+1300) Subject: s4/librpc: GUID should accept string or bytes in python3 X-Git-Tag: talloc-2.1.13~255 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=18a5afa6fb3ac016db23be072a69b0b1378209b3;p=thirdparty%2Fsamba.git s4/librpc: GUID should accept string or bytes in python3 In python3 you can't store a binary blob GUID in a string class, you need to use 'bytes'. This change ensures python2 code continues to use a string and in python3 both 'bytes' and 'string' are supported. Signed-off-by: Noel Power Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/source4/librpc/ndr/py_misc.c b/source4/librpc/ndr/py_misc.c index 6316b9b6704..849a11460a4 100644 --- a/source4/librpc/ndr/py_misc.c +++ b/source4/librpc/ndr/py_misc.c @@ -97,11 +97,19 @@ static int py_GUID_init(PyObject *self, PyObject *args, PyObject *kwargs) DATA_BLOB guid_val; Py_ssize_t _size; - if (!PyStr_Check(str)) { - PyErr_SetString(PyExc_TypeError, "Expected a string argument to GUID()"); + if (!IsPy3BytesOrString(str)) { + PyErr_SetString(PyExc_TypeError, "Expected a string or bytes argument to GUID()"); return -1; } - guid_val.data = (uint8_t *)PyStr_AsUTF8AndSize(str, &_size); + + if (!IsPy3Bytes(str)) { + guid_val.data = + (uint8_t *)PyStr_AsUTF8AndSize(str, + &_size); + } else { + guid_val.data = (uint8_t *)PyBytes_AsString(str); + _size = PyBytes_Size(str); + } guid_val.length = _size; status = GUID_from_data_blob(&guid_val, guid); if (!NT_STATUS_IS_OK(status)) {