From: Noel Power Date: Fri, 13 Apr 2018 16:33:47 +0000 (+0100) Subject: s4/dsdb: Additionally accept unicode as string param in Py2 X-Git-Tag: ldb-1.4.0~512 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5055b54d4a67d695e6c8f61098358a759cc49888;p=thirdparty%2Fsamba.git s4/dsdb: 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 Reviewed-by: Alexander Bokovoy --- diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c index 8d84a16dd18..d9177bbd1d7 100644 --- a/source4/dsdb/pydsdb.c +++ b/source4/dsdb/pydsdb.c @@ -580,7 +580,7 @@ static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args) for (i = 0; i < el->num_values; i++) { PyObject *item = PyList_GetItem(el_list, i); - if (!PyStr_Check(item)) { + if (!(PyStr_Check(item) || PyUnicode_Check(item))) { PyErr_Format(PyExc_TypeError, "ldif_elements should be strings"); talloc_free(tmp_ctx); return NULL;