summaryrefslogtreecommitdiff
path: root/source4/librpc
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2018-04-13 17:34:19 +0100
committerNoel Power <npower@samba.org>2018-04-30 15:43:19 +0200
commit5c129351cc6b6ebfec78747d8ab0709e45c196bb (patch)
treeb596c441d03e14db421ecb0da528bb3f401d11fe /source4/librpc
parent5055b54d4a67d695e6c8f61098358a759cc49888 (diff)
downloadsamba-5c129351cc6b6ebfec78747d8ab0709e45c196bb.tar.gz
s4/librpc: Additionally accept unicode as string param in Py2
With the changes to make samba python code Py2/Py3 compatible there now are many instances where string content is decoded. Decoded string variables in Py2 are returned as the unicode type. Many Py2 c-module functions that take string arguments only check for the string type. However now it's quite possibe the content formally passed as a string argument is now passed as unicode after being decoded, such arguments are rejected and code can fail subtly. This only affects places where the type is directly checked e.g. via PyStr_Check etc. arguments that are parsed by ParseTuple* functions generally already accept both string and unicode (if 's', 'z', 's*' format specifiers are used) Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Alexander Bokovoy <ab@samba.org>
Diffstat (limited to 'source4/librpc')
-rw-r--r--source4/librpc/rpc/pyrpc.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/source4/librpc/rpc/pyrpc.c b/source4/librpc/rpc/pyrpc.c
index 8b817b8b46d..e86ea0e94aa 100644
--- a/source4/librpc/rpc/pyrpc.c
+++ b/source4/librpc/rpc/pyrpc.c
@@ -50,28 +50,32 @@ static bool ndr_syntax_from_py_object(PyObject *object, struct ndr_syntax_id *sy
{
ZERO_STRUCTP(syntax_id);
- if (PyStr_Check(object)) {
+ if (PyStr_Check(object) || PyUnicode_Check(object)) {
return PyString_AsGUID(object, &syntax_id->uuid);
} else if (PyTuple_Check(object)) {
+ PyObject *item = NULL;
if (PyTuple_Size(object) < 1 || PyTuple_Size(object) > 2) {
PyErr_SetString(PyExc_ValueError, "Syntax ID tuple has invalid size");
return false;
}
- if (!PyStr_Check(PyTuple_GetItem(object, 0))) {
+ item = PyTuple_GetItem(object, 0);
+ if (!(PyStr_Check(item) || PyUnicode_Check(item))) {
PyErr_SetString(PyExc_ValueError, "Expected GUID as first element in tuple");
return false;
}
- if (!PyString_AsGUID(PyTuple_GetItem(object, 0), &syntax_id->uuid))
+ if (!PyString_AsGUID(item, &syntax_id->uuid)) {
return false;
+ }
- if (!PyInt_Check(PyTuple_GetItem(object, 1))) {
+ item = PyTuple_GetItem(object, 1);
+ if (!PyInt_Check(item)) {
PyErr_SetString(PyExc_ValueError, "Expected version as second element in tuple");
return false;
}
- syntax_id->if_version = PyInt_AsLong(PyTuple_GetItem(object, 1));
+ syntax_id->if_version = PyInt_AsLong(item);
return true;
}