s4/dsdb: py_dsdb_DsReplicaAttribute should deal with bytes in py3
authorNoel Power <noel.power@suse.com>
Mon, 14 May 2018 19:05:30 +0000 (20:05 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Sat, 15 Sep 2018 13:18:25 +0000 (15:18 +0200)
Seems the underlying c code expects binary blob, so.. we should
handle str for py2 and byte for py3

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/pydsdb.c

index 62d2a9120a91f620710d2ac0661c72d4cb2efed6..19fb75dfc8b3ecda9c1afd907f1a34c2e135006e 100644 (file)
@@ -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);
                }
        }