diff options
author | Noel Power <noel.power@suse.com> | 2018-02-28 16:25:55 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2018-03-23 07:28:25 +0100 |
commit | 18a5afa6fb3ac016db23be072a69b0b1378209b3 (patch) | |
tree | 1e4d738e1b65402bc7fc37bfea23e28972169c7f /source4/librpc/ndr/py_misc.c | |
parent | aea433ee0c87d42f670aa8b9e068b80cf2d9ef09 (diff) | |
download | samba-18a5afa6fb3ac016db23be072a69b0b1378209b3.tar.gz |
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 <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/librpc/ndr/py_misc.c')
-rw-r--r-- | source4/librpc/ndr/py_misc.c | 14 |
1 files changed, 11 insertions, 3 deletions
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)) { |