From d786e1fca95395e793867278bc0408e33c19908b Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 24 Sep 2018 11:28:47 +0100 Subject: [PATCH 1/3] lib/ldb: Test correct variable for no mem condition Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett --- lib/ldb/pyldb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index 66bc2021fb4..afc86300f3d 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -927,7 +927,7 @@ static PyObject *py_ldb_dn_new(PyTypeObject *type, PyObject *args, PyObject *kwa } py_ret = (PyLdbDnObject *)type->tp_alloc(type, 0); - if (ret == NULL) { + if (py_ret == NULL) { talloc_free(mem_ctx); PyErr_NoMemory(); return NULL; -- 2.16.4 From d1492ab919b19d1ca72f1d7c97ac0ca3bee13a2a Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 24 Sep 2018 14:37:50 +0100 Subject: [PATCH 2/3] lib/ldb/tests: add test for ldb.Dn passed utf8 unicode object dn format should be a utf8 encoded string Note: Currently this fails in python2 as the c python binding for the dn string param uses PyArg_ParseTupleAndKeywords() with 's' format, this will accept str *or* unicode in the default encoding. The default encoding in python2 is... ascii. Also adding here a knownfail to squash the error produced by the test. Signed-off-by: Noel Power Reviewed-by: Andrew Bartlett --- lib/ldb/tests/python/api.py | 4 ++++ selftest/knownfail | 2 ++ 2 files changed, 6 insertions(+) diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py index 37e8f4da656..f9e2fa5f73a 100755 --- a/lib/ldb/tests/python/api.py +++ b/lib/ldb/tests/python/api.py @@ -138,6 +138,10 @@ class SimpleLdb(LdbBaseTest): l = ldb.Ldb(self.url(), flags=self.flags()) self.assertEqual(len(l.search(controls=["paged_results:0:5"])), 0) + def test_utf8_ldb_Dn(self): + l = ldb.Ldb(self.url(), flags=self.flags()) + dn = ldb.Dn(l, (b'a=' + b'\xc4\x85\xc4\x87\xc4\x99\xc5\x82\xc5\x84\xc3\xb3\xc5\x9b\xc5\xba\xc5\xbc').decode('utf8')) + def test_search_attrs(self): l = ldb.Ldb(self.url(), flags=self.flags()) self.assertEqual(len(l.search(ldb.Dn(l, ""), ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0) diff --git a/selftest/knownfail b/selftest/knownfail index d6feefd91b0..31da5dc2bf3 100644 --- a/selftest/knownfail +++ b/selftest/knownfail @@ -356,3 +356,5 @@ ^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) -- 2.16.4 From cddd54e8654c94dedd57c08af1987ce03212ce20 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 24 Sep 2018 12:20:20 +0100 Subject: [PATCH 3/3] 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) -- 2.16.4