ldb: Show the last successful DN when failing to parse LDIF
authorAndrew Bartlett <abartlet@samba.org>
Mon, 11 Dec 2017 02:57:30 +0000 (15:57 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 14 Dec 2017 07:20:14 +0000 (08:20 +0100)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/pyldb.c

index e61b5b6a4f48927717311cc66fb1fe392ff8beba..04b3f1b7d5f1b52c2a641b66771bcd7976f392cd 100644 (file)
@@ -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;
                }