From a7f3545b825de86f7b551d8b517031998327a92d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Aug 2011 12:39:48 +1000 Subject: pyldb: return a copy of key constant DNs via python interface this prevents an easy coding error where the caller modifies one of the key DNs for the database, by using an add_child function or similar Pair-Programmed-With: Amitay Isaacs Pair-Programmed-With: Andrew Bartlett Signed-off-by: Andrew Bartlett --- lib/ldb/pyldb.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'lib/ldb/pyldb.c') diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index c92d64dd12..e9af22775e 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -589,6 +589,23 @@ static Py_ssize_t py_ldb_dn_len(PyLdbDnObject *self) return ldb_dn_get_comp_num(PyLdbDn_AsDn((PyObject *)self)); } +/* + copy a DN as a python object + */ +static PyObject *py_ldb_dn_copy(struct ldb_dn *dn) +{ + PyLdbDnObject *py_ret; + + py_ret = (PyLdbDnObject *)PyLdbDn.tp_alloc(&PyLdbDn, 0); + if (py_ret == NULL) { + PyErr_NoMemory(); + return NULL; + } + py_ret->mem_ctx = talloc_new(NULL); + py_ret->dn = ldb_dn_copy(py_ret->mem_ctx, dn); + return (PyObject *)py_ret; +} + static PyObject *py_ldb_dn_concat(PyLdbDnObject *self, PyObject *py_other) { struct ldb_dn *dn = PyLdbDn_AsDn((PyObject *)self), @@ -759,7 +776,7 @@ static PyObject *py_ldb_get_root_basedn(PyLdbObject *self) struct ldb_dn *dn = ldb_get_root_basedn(PyLdb_AsLdbContext(self)); if (dn == NULL) Py_RETURN_NONE; - return PyLdbDn_FromDn(dn); + return py_ldb_dn_copy(dn); } @@ -768,7 +785,7 @@ static PyObject *py_ldb_get_schema_basedn(PyLdbObject *self) struct ldb_dn *dn = ldb_get_schema_basedn(PyLdb_AsLdbContext(self)); if (dn == NULL) Py_RETURN_NONE; - return PyLdbDn_FromDn(dn); + return py_ldb_dn_copy(dn); } static PyObject *py_ldb_get_config_basedn(PyLdbObject *self) @@ -776,7 +793,7 @@ static PyObject *py_ldb_get_config_basedn(PyLdbObject *self) struct ldb_dn *dn = ldb_get_config_basedn(PyLdb_AsLdbContext(self)); if (dn == NULL) Py_RETURN_NONE; - return PyLdbDn_FromDn(dn); + return py_ldb_dn_copy(dn); } static PyObject *py_ldb_get_default_basedn(PyLdbObject *self) @@ -784,7 +801,7 @@ static PyObject *py_ldb_get_default_basedn(PyLdbObject *self) struct ldb_dn *dn = ldb_get_default_basedn(PyLdb_AsLdbContext(self)); if (dn == NULL) Py_RETURN_NONE; - return PyLdbDn_FromDn(dn); + return py_ldb_dn_copy(dn); } static const char **PyList_AsStringList(TALLOC_CTX *mem_ctx, PyObject *list, -- cgit