pyldb: add Dn.ldb accessor
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Sun, 17 Mar 2024 01:24:03 +0000 (14:24 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 10 Apr 2024 05:13:32 +0000 (05:13 +0000)
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 <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/pyldb.c

index dc877c8d7673048044a643fee02ada6f7deb45d2..67d4a4802c42d88f173cfbba2fa1133eeed161c6 100644 (file)
@@ -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,