From 7e3419f32f0a46cbd4926cbc98bf54da27749d31 Mon Sep 17 00:00:00 2001 From: Kamen Mazdrashki Date: Tue, 9 Nov 2010 00:21:57 +0200 Subject: s4-pyldb: Handle internal errors in py_ldb_contains() properly It is an exceptional condition for ldb_search() to return more than one results during SCOPE_BASE search on DN Autobuild-User: Kamen Mazdrashki Autobuild-Date: Wed Nov 10 09:02:00 UTC 2010 on sn-devel-104 --- source4/lib/ldb/pyldb.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index eddc56f777..1f5bd1e58d 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -1428,8 +1428,9 @@ static int py_ldb_contains(PyLdbObject *self, PyObject *obj) unsigned int count; int ret; - if (!PyObject_AsDn(ldb_ctx, obj, ldb_ctx, &dn)) + if (!PyObject_AsDn(ldb_ctx, obj, ldb_ctx, &dn)) { return -1; + } ret = ldb_search(ldb_ctx, ldb_ctx, &result, dn, LDB_SCOPE_BASE, NULL, NULL); @@ -1442,11 +1443,15 @@ static int py_ldb_contains(PyLdbObject *self, PyObject *obj) talloc_free(result); - if (count == 0) { - return 0; + if (count > 1) { + PyErr_Format(PyExc_RuntimeError, + "Searching for [%s] dn gave %u results!", + ldb_dn_get_linearized(dn), + count); + return -1; } - return 1; + return count; } static PySequenceMethods py_ldb_seq = { -- cgit