From 4ea7aa9265199e515d8f08ef849b69cfa3ee1955 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 11 Dec 2017 15:57:30 +1300 Subject: [PATCH] ldb: Show the last successful DN when failing to parse LDIF Signed-off-by: Andrew Bartlett Reviewed-by: Garming Sam --- lib/ldb/pyldb.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index e61b5b6a4f48..04b3f1b7d5f1 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -1669,6 +1669,7 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args) PyObject *list, *ret; struct ldb_ldif *ldif; const char *s; + struct ldb_dn *last_dn = NULL; TALLOC_CTX *mem_ctx; @@ -1686,8 +1687,29 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args) talloc_steal(mem_ctx, ldif); if (ldif) { PyList_Append(list, ldb_ldif_to_pyobject(ldif)); + last_dn = ldif->msg->dn; } else { - PyErr_SetString(PyExc_ValueError, "unable to parse ldif string"); + const char *last_dn_str = NULL; + const char *err_string = NULL; + if (last_dn == NULL) { + PyErr_SetString(PyExc_ValueError, + "unable to parse LDIF " + "string at first chunk"); + talloc_free(mem_ctx); + return NULL; + } + + last_dn_str + = ldb_dn_get_linearized(last_dn); + + err_string + = talloc_asprintf(mem_ctx, + "unable to parse ldif " + "string AFTER %s", + last_dn_str); + + PyErr_SetString(PyExc_ValueError, + err_string); talloc_free(mem_ctx); return NULL; } -- 2.34.1