From: Douglas Bagnall Date: Sun, 17 Mar 2024 01:24:03 +0000 (+1300) Subject: pyldb: add Dn.ldb accessor X-Git-Tag: tdb-1.4.11~1191 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8b6df2d0bca12fc33b60c5702b4afe36597cc775;p=thirdparty%2Fsamba.git pyldb: add Dn.ldb accessor This, and the next commit, might help in debugging when you see a traceback that ends like this: File "/data/samba/samba/bin/samba_upgradeprovision", line 664, in add_missing_object delta.dn = dn RuntimeError: DN is from the wrong LDB in this case you could force a solution with something like: delta.dn = ldb.dn(delta.ldb, str(dn)) Signed-off-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index dc877c8d767..67d4a4802c4 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -967,6 +967,28 @@ static PyMethodDef py_ldb_dn_methods[] = { {0} }; + +static PyObject *py_ldb_dn_get_ldb(PyLdbDnObject *self, void *closure) +{ + if (self->pyldb == NULL) { + Py_RETURN_NONE; + } + Py_INCREF(self->pyldb); + return (PyObject *)self->pyldb; +} + + +static PyGetSetDef py_ldb_dn_getset[] = { + { + .name = discard_const_p(char, "ldb"), + .get = (getter)py_ldb_dn_get_ldb, + .doc = discard_const_p( /* for Py 3.6; 3.7+ have const char* */ + char, "returns the associated ldb object (or None)") + }, + { .name = NULL }, +}; + + static Py_ssize_t py_ldb_dn_len(PyLdbDnObject *self) { struct ldb_dn *dn = pyldb_Dn_AS_DN(self); @@ -1122,6 +1144,7 @@ static PyTypeObject PyLdbDn = { .tp_repr = (reprfunc)py_ldb_dn_repr, .tp_richcompare = (richcmpfunc)py_ldb_dn_richcmp, .tp_as_sequence = &py_ldb_dn_seq, + .tp_getset = py_ldb_dn_getset, .tp_doc = "A LDB distinguished name.", .tp_new = py_ldb_dn_new, .tp_dealloc = (destructor)py_ldb_dn_dealloc,