1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

pyldb: Raise an exception if ldb_dn_get_parent() fails

Such a failure could be caused by situations other than memory errors,
but a simple indication of failure is all that ldb_dn_get_parent() gives
us to work with.

We keep the old behaviour of returning None if the DN has no components,
which an existing test (ldb.python.api.DnTests.test_parent_nonexistent)
expects.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Joseph Sutton 2023-06-06 13:56:32 +12:00 committed by Andrew Bartlett
parent 49592b80f7
commit 5905a63307

View File

@ -608,12 +608,19 @@ static PyObject *py_ldb_dn_get_parent(PyLdbDnObject *self,
struct ldb_dn *dn = pyldb_Dn_AS_DN((PyObject *)self);
struct ldb_dn *parent;
PyLdbDnObject *py_ret;
TALLOC_CTX *mem_ctx = talloc_new(NULL);
TALLOC_CTX *mem_ctx = NULL;
if (ldb_dn_get_comp_num(dn) < 1) {
Py_RETURN_NONE;
}
mem_ctx = talloc_new(NULL);
parent = ldb_dn_get_parent(mem_ctx, dn);
if (parent == NULL) {
PyErr_NoMemory();
talloc_free(mem_ctx);
Py_RETURN_NONE;
return NULL;
}
py_ret = (PyLdbDnObject *)PyLdbDn.tp_alloc(&PyLdbDn, 0);