From: Noel Power Date: Mon, 14 May 2018 19:05:30 +0000 (+0100) Subject: s4/dsdb: py_dsdb_DsReplicaAttribute should deal with bytes in py3 X-Git-Tag: tdb-1.3.17~1610 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e21334d60c23178cbf13b5222c19cd38283e181;p=thirdparty%2Fsamba.git s4/dsdb: py_dsdb_DsReplicaAttribute should deal with bytes in py3 Seems the underlying c code expects binary blob, so.. we should handle str for py2 and byte for py3 Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett --- diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c index 62d2a9120a9..19fb75dfc8b 100644 --- a/source4/dsdb/pydsdb.c +++ b/source4/dsdb/pydsdb.c @@ -519,7 +519,6 @@ static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args) TALLOC_CTX *tmp_ctx; WERROR werr; Py_ssize_t i; - Py_ssize_t _size; if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) { return NULL; @@ -581,13 +580,17 @@ 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) || PyUnicode_Check(item))) { - PyErr_Format(PyExc_TypeError, "ldif_elements should be strings"); + if (!(PyBytes_Check(item))) { + PyErr_Format(PyExc_TypeError, + "ldif_element type should be " + PY_DESC_PY3_BYTES + ); talloc_free(tmp_ctx); return NULL; } - el->values[i].data = (uint8_t *)PyStr_AsUTF8AndSize(item, &_size); - el->values[i].length = _size; + el->values[i].data = + (uint8_t *)PyBytes_AsString(item); + el->values[i].length = PyBytes_Size(item); } }