summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Sutton <josephsutton@catalyst.net.nz>2021-09-25 14:39:59 +1200
committerStefan Metzmacher <metze@samba.org>2021-10-26 12:00:28 +0000
commite425abeb7d228615a2766ddd497b26af228a022b (patch)
tree2bab6fb5298babd64546ae23158808a203ac1456
parentfabd904977ab34244195fff424502672846413e1 (diff)
downloadsamba-e425abeb7d228615a2766ddd497b26af228a022b.tar.gz
pyldb: Make ldb.Message containment testing consistent with indexing
Previously, containment testing using the 'in' operator was handled by performing an equality comparison between the chosen object and each of the message's keys in turn. This behaviour was prone to errors due to not considering differences in case between otherwise equal elements, as the indexing operations do. Containment testing should now be more consistent with the indexing operations and with the get() method of ldb.Message. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14845 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> (cherry picked from commit 860d8902a9c502d4be83396598cf4a53c80fea69)
-rw-r--r--lib/ldb/pyldb.c21
-rw-r--r--selftest/knownfail.d/pyldb4
2 files changed, 21 insertions, 4 deletions
diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c
index 1b2f12adf5e..d093daedf5c 100644
--- a/lib/ldb/pyldb.c
+++ b/lib/ldb/pyldb.c
@@ -3433,6 +3433,22 @@ static PyObject *py_ldb_msg_keys(PyLdbMessageObject *self,
return obj;
}
+static int py_ldb_msg_contains(PyLdbMessageObject *self, PyObject *py_name)
+{
+ struct ldb_message_element *el = NULL;
+ const char *name = NULL;
+ struct ldb_message *msg = pyldb_Message_AsMessage(self);
+ name = PyUnicode_AsUTF8(py_name);
+ if (name == NULL) {
+ return -1;
+ }
+ if (!ldb_attr_cmp(name, "dn")) {
+ return 1;
+ }
+ el = ldb_msg_find_element(msg, name);
+ return el != NULL ? 1 : 0;
+}
+
static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name)
{
struct ldb_message_element *el = NULL;
@@ -3661,6 +3677,10 @@ static Py_ssize_t py_ldb_msg_length(PyLdbMessageObject *self)
return pyldb_Message_AsMessage(self)->num_elements;
}
+static PySequenceMethods py_ldb_msg_sequence = {
+ .sq_contains = (objobjproc)py_ldb_msg_contains,
+};
+
static PyMappingMethods py_ldb_msg_mapping = {
.mp_length = (lenfunc)py_ldb_msg_length,
.mp_subscript = (binaryfunc)py_ldb_msg_getitem,
@@ -3838,6 +3858,7 @@ static PyTypeObject PyLdbMessage = {
.tp_name = "ldb.Message",
.tp_methods = py_ldb_msg_methods,
.tp_getset = py_ldb_msg_getset,
+ .tp_as_sequence = &py_ldb_msg_sequence,
.tp_as_mapping = &py_ldb_msg_mapping,
.tp_basicsize = sizeof(PyLdbMessageObject),
.tp_dealloc = (destructor)py_ldb_msg_dealloc,
diff --git a/selftest/knownfail.d/pyldb b/selftest/knownfail.d/pyldb
deleted file mode 100644
index 34bdac4f682..00000000000
--- a/selftest/knownfail.d/pyldb
+++ /dev/null
@@ -1,4 +0,0 @@
-^ldb.python.api.LdbMsgTests.test_contains_case
-^ldb.python.api.LdbMsgTests.test_contains_dn
-^ldb.python.api.LdbMsgTests.test_contains_dn_case
-^ldb.python.api.LdbMsgTests.test_contains_invalid