s4/dsdb: python3 api should take 'bytes'
authorNoel Power <noel.power@suse.com>
Thu, 22 Feb 2018 12:49:36 +0000 (12:49 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 23 Mar 2018 06:28:25 +0000 (07:28 +0100)
Attributes are properly represented by 'bytes' and *maybe* can be
converted into strings (if they are text).
py_dsdb_normalise_attributes currently expects strings, this is fine
in python2 however in python3 we need to actually pass a 'bytes'
class.

Signed-off-by: Noel Power <noel.power@suse.com>
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/pydsdb.c

index d38d7095efae3875357cd98b7354aab5511d0bba..8d84a16dd18e2ccbcb7de776a4ee0be3a641c8c0 100644 (file)
@@ -625,7 +625,6 @@ static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
        TALLOC_CTX *tmp_ctx;
        WERROR werr;
        Py_ssize_t i;
-       Py_ssize_t _size;
        PyTypeObject *py_type = NULL;
        PyObject *module = NULL;
 
@@ -688,13 +687,16 @@ static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
 
                for (i = 0; i < el->num_values; i++) {
                        PyObject *item = PyList_GetItem(el_list, i);
-                       if (!PyStr_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);
                }
        }