mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
pyldb: Raise TypeError for an invalid ldb.Message index
Previously, a TypeError was raised and subsequently overridden by a
KeyError.
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 22353767ca
)
This commit is contained in:
parent
a78c94440b
commit
588749ba7b
@ -3433,33 +3433,25 @@ static PyObject *py_ldb_msg_keys(PyLdbMessageObject *self,
|
||||
return obj;
|
||||
}
|
||||
|
||||
static PyObject *py_ldb_msg_getitem_helper(PyLdbMessageObject *self, PyObject *py_name)
|
||||
static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name)
|
||||
{
|
||||
struct ldb_message_element *el;
|
||||
const char *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) {
|
||||
PyErr_SetNone(PyExc_TypeError);
|
||||
return NULL;
|
||||
}
|
||||
if (!ldb_attr_cmp(name, "dn"))
|
||||
if (!ldb_attr_cmp(name, "dn")) {
|
||||
return pyldb_Dn_FromDn(msg->dn);
|
||||
}
|
||||
el = ldb_msg_find_element(msg, name);
|
||||
if (el == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return (PyObject *)PyLdbMessageElement_FromMessageElement(el, msg->elements);
|
||||
}
|
||||
|
||||
static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name)
|
||||
{
|
||||
PyObject *ret = py_ldb_msg_getitem_helper(self, py_name);
|
||||
if (ret == NULL) {
|
||||
PyErr_SetString(PyExc_KeyError, "No such element");
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
|
||||
return PyLdbMessageElement_FromMessageElement(el, msg->elements);
|
||||
}
|
||||
|
||||
static PyObject *py_ldb_msg_get(PyLdbMessageObject *self, PyObject *args, PyObject *kwargs)
|
||||
|
@ -1 +0,0 @@
|
||||
^ldb.python.api.LdbMsgTests.test_invalid
|
Loading…
Reference in New Issue
Block a user