mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
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>
This commit is contained in:
parent
aea433ee0c
commit
18a5afa6fb
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user