summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-08-03 18:15:16 +0200
committerJelmer Vernooij <jelmer@samba.org>2009-08-03 18:15:16 +0200
commitbb944dcf64aeb308991d6e7fa4da0550b1c86489 (patch)
tree37acfc4eb3004a70579daf368a2f52e8ecc0c19f /source4/lib
parent20225d83dd1d09274bd913d1713c56268a069628 (diff)
downloadsamba-bb944dcf64aeb308991d6e7fa4da0550b1c86489.tar.gz
samba-bb944dcf64aeb308991d6e7fa4da0550b1c86489.tar.bz2
samba-bb944dcf64aeb308991d6e7fa4da0550b1c86489.zip
pyldb: Raise proper exception when attempting to assign a string to a dn
attribute.
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/pyldb.c23
-rwxr-xr-xsource4/lib/ldb/tests/python/api.py6
2 files changed, 24 insertions, 5 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index bcca70eb82..c7b9b458cd 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -1747,6 +1747,7 @@ static PyObject *py_ldb_msg_new(PyTypeObject *type, PyObject *args, PyObject *kw
{
const char * const kwnames[] = { "dn", NULL };
struct ldb_message *ret;
+ TALLOC_CTX *mem_ctx;
PyObject *pydn = NULL;
PyLdbMessageObject *py_ret;
@@ -1755,8 +1756,15 @@ static PyObject *py_ldb_msg_new(PyTypeObject *type, PyObject *args, PyObject *kw
&pydn))
return NULL;
- ret = ldb_msg_new(NULL);
+ mem_ctx = talloc_new(NULL);
+ if (mem_ctx == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ ret = ldb_msg_new(mem_ctx);
if (ret == NULL) {
+ talloc_free(mem_ctx);
PyErr_NoMemory();
return NULL;
}
@@ -1764,7 +1772,7 @@ static PyObject *py_ldb_msg_new(PyTypeObject *type, PyObject *args, PyObject *kw
if (pydn != NULL) {
struct ldb_dn *dn;
if (!PyObject_AsDn(NULL, pydn, NULL, &dn)) {
- talloc_free(ret);
+ talloc_free(mem_ctx);
return NULL;
}
ret->dn = talloc_reference(ret, dn);
@@ -1773,12 +1781,12 @@ static PyObject *py_ldb_msg_new(PyTypeObject *type, PyObject *args, PyObject *kw
py_ret = (PyLdbMessageObject *)type->tp_alloc(type, 0);
if (py_ret == NULL) {
PyErr_NoMemory();
- talloc_free(ret);
+ talloc_free(mem_ctx);
return NULL;
}
- py_ret->mem_ctx = talloc_new(NULL);
- py_ret->msg = talloc_steal(py_ret->mem_ctx, ret);
+ py_ret->mem_ctx = mem_ctx;
+ py_ret->msg = ret;
return (PyObject *)py_ret;
}
@@ -1805,6 +1813,11 @@ static PyObject *py_ldb_msg_get_dn(PyLdbMessageObject *self, void *closure)
static int py_ldb_msg_set_dn(PyLdbMessageObject *self, PyObject *value, void *closure)
{
struct ldb_message *msg = PyLdbMessage_AsMessage(self);
+ if (!PyLdbDn_Check(value)) {
+ PyErr_SetNone(PyExc_TypeError);
+ return -1;
+ }
+
msg->dn = talloc_reference(msg, PyLdbDn_AsDn(value));
return 0;
}
diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py
index 05e3da782e..110b1cabfe 100755
--- a/source4/lib/ldb/tests/python/api.py
+++ b/source4/lib/ldb/tests/python/api.py
@@ -279,6 +279,12 @@ class DnTests(unittest.TestCase):
def setUp(self):
self.ldb = ldb.Ldb(filename())
+ def test_set_dn_invalid(self):
+ x = ldb.Message()
+ def assign():
+ x.dn = "astring"
+ self.assertRaises(TypeError, assign)
+
def test_eq(self):
x = ldb.Dn(self.ldb, "dc=foo11,bar=bloe")
y = ldb.Dn(self.ldb, "dc=foo11,bar=bloe")