From cddd54e8654c94dedd57c08af1987ce03212ce20 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 24 Sep 2018 12:20:20 +0100 Subject: [PATCH] lib/ldb: Ensure ldb.Dn can accept utf8 encoded unicode Additionally remove the associated known fail. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13616 Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett --- lib/ldb/pyldb.c | 30 +++++++++++++++++------------- selftest/knownfail | 2 -- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index afc86300f3d..3ed9d303e44 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -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; } diff --git a/selftest/knownfail b/selftest/knownfail index 31da5dc2bf3..d6feefd91b0 100644 --- a/selftest/knownfail +++ b/selftest/knownfail @@ -356,5 +356,3 @@ ^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)