From 96204d0facde64655cc268bb1fac6465cd823982 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 (cherry picked from commit d786e1fca95395e793867278bc0408e33c19908b) --- 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 110ec8e60ad..696200291b5 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -891,7 +891,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 2cfce348a128676c0f7faf485131a998a3becd10 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 (cherry picked from commit d1492ab919b19d1ca72f1d7c97ac0ca3bee13a2a) --- 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 e4010960697..0a883961c00 100755 --- a/lib/ldb/tests/python/api.py +++ b/lib/ldb/tests/python/api.py @@ -137,6 +137,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 baf3d57a31a..a122b27ad21 100644 --- a/selftest/knownfail +++ b/selftest/knownfail @@ -349,3 +349,5 @@ # Disabling NTLM means you can't use samr to change the password ^samba.tests.ntlmdisabled.python\(ktest\).ntlmdisabled.NtlmDisabledTests.test_samr_change_password\(ktest\) ^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).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 67f81152e7696d74adadf69b366d13f2e0f2ed70 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 (cherry picked from commit cddd54e8654c94dedd57c08af1987ce03212ce20) --- 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 696200291b5..a6290d9db09 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -857,22 +857,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); @@ -880,24 +880,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 a122b27ad21..baf3d57a31a 100644 --- a/selftest/knownfail +++ b/selftest/knownfail @@ -349,5 +349,3 @@ # Disabling NTLM means you can't use samr to change the password ^samba.tests.ntlmdisabled.python\(ktest\).ntlmdisabled.NtlmDisabledTests.test_samr_change_password\(ktest\) ^samba.tests.ntlmdisabled.python\(ad_dc_no_ntlm\).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