]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4/librpc: GUID should accept string or bytes in python3
authorNoel Power <noel.power@suse.com>
Wed, 28 Feb 2018 03:25:55 +0000 (16:25 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 23 Mar 2018 06:28:25 +0000 (07:28 +0100)
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>
source4/librpc/ndr/py_misc.c

index 6316b9b6704d72a5bf728ca1ad4bf0736dcfe95a..849a11460a4054302bbb6612862c171eee193042 100644 (file)
@@ -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)) {