summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-08-01 12:39:48 +1000
committerAndrew Bartlett <abartlet@samba.org>2011-08-03 14:25:38 +1000
commita7f3545b825de86f7b551d8b517031998327a92d (patch)
tree03a74f574f0f51f1d79a627b6c31be903458cf65 /lib
parent785c65e875a58707dacadd493ec26665467d9259 (diff)
downloadsamba-a7f3545b825de86f7b551d8b517031998327a92d.tar.gz
samba-a7f3545b825de86f7b551d8b517031998327a92d.tar.bz2
samba-a7f3545b825de86f7b551d8b517031998327a92d.zip
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 <amitay@gmail.com> Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org> Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/ldb/pyldb.c25
1 files changed, 21 insertions, 4 deletions
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,