lib/ldb: Ensure ldb.Dn can accept utf8 encoded unicode
authorNoel Power <noel.power@suse.com>
Mon, 24 Sep 2018 11:20:20 +0000 (12:20 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 26 Sep 2018 23:54:26 +0000 (01:54 +0200)
Additionally remove the associated known fail.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13616
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/pyldb.c
selftest/knownfail

index afc86300f3dbcf536794014417a68311d1fc5c8b..3ed9d303e44763bd4851ee486b40c1aa6467c704 100644 (file)
@@ -893,22 +893,22 @@ static PySequenceMethods py_ldb_dn_seq = {
 
 static PyObject *py_ldb_dn_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 {
-       struct ldb_dn *ret;
-       char *str;
-       PyObject *py_ldb;
-       struct ldb_context *ldb_ctx;
-       TALLOC_CTX *mem_ctx;
-       PyLdbDnObject *py_ret;
+       struct ldb_dn *ret = NULL;
+       char *str = NULL;
+       PyObject *py_ldb = NULL;
+       struct ldb_context *ldb_ctx = NULL;
+       TALLOC_CTX *mem_ctx = NULL;
+       PyLdbDnObject *py_ret = NULL;
        const char * const kwnames[] = { "ldb", "dn", NULL };
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os",
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Oes",
                                         discard_const_p(char *, kwnames),
-                                        &py_ldb, &str))
-               return NULL;
+                                        &py_ldb, "utf8", &str))
+               goto out;
 
        if (!PyLdb_Check(py_ldb)) {
                PyErr_SetString(PyExc_TypeError, "Expected Ldb");
-               return NULL;
+               goto out;
        }
 
        ldb_ctx = pyldb_Ldb_AsLdbContext(py_ldb);
@@ -916,24 +916,28 @@ static PyObject *py_ldb_dn_new(PyTypeObject *type, PyObject *args, PyObject *kwa
        mem_ctx = talloc_new(NULL);
        if (mem_ctx == NULL) {
                PyErr_NoMemory();
-               return NULL;
+               goto out;
        }
 
        ret = ldb_dn_new(mem_ctx, ldb_ctx, str);
        if (!ldb_dn_validate(ret)) {
                talloc_free(mem_ctx);
                PyErr_SetString(PyExc_ValueError, "unable to parse dn string");
-               return NULL;
+               goto out;
        }
 
        py_ret = (PyLdbDnObject *)type->tp_alloc(type, 0);
        if (py_ret == NULL) {
                talloc_free(mem_ctx);
                PyErr_NoMemory();
-               return NULL;
+               goto out;
        }
        py_ret->mem_ctx = mem_ctx;
        py_ret->dn = ret;
+out:
+       if (str != NULL) {
+               PyMem_Free(discard_const_p(char, str));
+       }
        return (PyObject *)py_ret;
 }
 
index 31da5dc2bf3a050020e2adb409b3dccd04640577..d6feefd91b0a7765eb0aaea7d23ee4daf894316c 100644 (file)
 ^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\)
 ^samba.tests.ntlmdisabled.python\(ktest\).python3.ntlmdisabled.NtlmDisabledTests.test_samr_change_password\(ktest\)
 ^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).python3.ntlmdisabled.NtlmDisabledTests.test_ntlm_connection\(ad_dc_no_ntlm\)
-# Ldb test api.SimpleLdb.test_utf8_ldb_Dn is expected to fail
-^ldb.python.api.SimpleLdb.test_utf8_ldb_Dn(none)