summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-08-26 15:01:12 +1000
committerAndrew Bartlett <abartlet@samba.org>2009-08-26 15:07:50 +1000
commit3ed33813bb6aa1ca932372c2a2ce36152b6af50b (patch)
tree80b8c725fa331fcb9603bebe99fb45c9c732704e /source4/lib/ldb
parent74218726e89c297eb957b9df989dd42fd1601742 (diff)
downloadsamba-3ed33813bb6aa1ca932372c2a2ce36152b6af50b.tar.gz
samba-3ed33813bb6aa1ca932372c2a2ce36152b6af50b.tar.bz2
samba-3ed33813bb6aa1ca932372c2a2ce36152b6af50b.zip
s4:ldb Add hooks to get/set the flags on a ldb_message_element
Also add tests to prove that we got this correct, and correct the existing tests which used the wrong constants. Andrew Bartlett
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/pyldb.c26
-rwxr-xr-xsource4/lib/ldb/tests/python/api.py44
2 files changed, 65 insertions, 5 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index 67e1d5c9e0..94415c8c31 100644
--- a/source4/lib/ldb/pyldb.c
+++ b/source4/lib/ldb/pyldb.c
@@ -1493,8 +1493,30 @@ static PyObject *py_ldb_msg_element_get(PyLdbMessageElementObject *self, PyObjec
&(PyLdbMessageElement_AsMessageElement(self)->values[i]));
}
+static PyObject *py_ldb_msg_element_flags(PyLdbMessageElementObject *self, PyObject *args)
+{
+ struct ldb_message_element *el;
+
+ el = PyLdbMessageElement_AsMessageElement(self);
+ return PyInt_FromLong(el->flags);
+}
+
+static PyObject *py_ldb_msg_element_set_flags(PyLdbMessageElementObject *self, PyObject *args)
+{
+ int flags;
+ struct ldb_message_element *el;
+ if (!PyArg_ParseTuple(args, "i", &flags))
+ return NULL;
+
+ el = PyLdbMessageElement_AsMessageElement(self);
+ el->flags = flags;
+ Py_RETURN_NONE;
+}
+
static PyMethodDef py_ldb_msg_element_methods[] = {
{ "get", (PyCFunction)py_ldb_msg_element_get, METH_VARARGS, NULL },
+ { "set_flags", (PyCFunction)py_ldb_msg_element_set_flags, METH_VARARGS, NULL },
+ { "flags", (PyCFunction)py_ldb_msg_element_flags, METH_NOARGS, NULL },
{ NULL },
};
@@ -2326,6 +2348,10 @@ void initldb(void)
PyModule_AddObject(m, "CHANGETYPE_DELETE", PyInt_FromLong(LDB_CHANGETYPE_DELETE));
PyModule_AddObject(m, "CHANGETYPE_MODIFY", PyInt_FromLong(LDB_CHANGETYPE_MODIFY));
+ PyModule_AddObject(m, "FLAG_MOD_ADD", PyInt_FromLong(LDB_FLAG_MOD_ADD));
+ PyModule_AddObject(m, "FLAG_MOD_REPLACE", PyInt_FromLong(LDB_FLAG_MOD_REPLACE));
+ PyModule_AddObject(m, "FLAG_MOD_DELETE", PyInt_FromLong(LDB_FLAG_MOD_DELETE));
+
PyModule_AddObject(m, "SUCCESS", PyInt_FromLong(LDB_SUCCESS));
PyModule_AddObject(m, "ERR_OPERATIONS_ERROR", PyInt_FromLong(LDB_ERR_OPERATIONS_ERROR));
PyModule_AddObject(m, "ERR_PROTOCOL_ERROR", PyInt_FromLong(LDB_ERR_PROTOCOL_ERROR));
diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py
index d946bf06a5..9bcb225190 100755
--- a/source4/lib/ldb/tests/python/api.py
+++ b/source4/lib/ldb/tests/python/api.py
@@ -195,10 +195,13 @@ class SimpleLdb(unittest.TestCase):
try:
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=modifydelete")
- m["bla"] = ldb.MessageElement([], ldb.CHANGETYPE_DELETE, "bla")
+ m["bla"] = ldb.MessageElement([], ldb.FLAG_MOD_DELETE, "bla")
+ self.assertEquals(ldb.FLAG_MOD_DELETE, m["bla"].flags())
l.modify(m)
rm = l.search(m.dn)[0]
self.assertEquals(1, len(rm))
+ rm = l.search(m.dn, attrs=["bla"])[0]
+ self.assertEquals(0, len(rm))
finally:
l.delete(ldb.Dn(l, "dc=modifydelete"))
@@ -211,7 +214,8 @@ class SimpleLdb(unittest.TestCase):
try:
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=add")
- m["bla"] = ldb.MessageElement(["456"], ldb.CHANGETYPE_ADD, "bla")
+ m["bla"] = ldb.MessageElement(["456"], ldb.FLAG_MOD_ADD, "bla")
+ self.assertEquals(ldb.FLAG_MOD_ADD, m["bla"].flags())
l.modify(m)
rm = l.search(m.dn)[0]
self.assertEquals(2, len(rm))
@@ -219,7 +223,7 @@ class SimpleLdb(unittest.TestCase):
finally:
l.delete(ldb.Dn(l, "dc=add"))
- def test_modify_modify(self):
+ def test_modify_replace(self):
l = ldb.Ldb(filename())
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=modify2")
@@ -228,14 +232,44 @@ class SimpleLdb(unittest.TestCase):
try:
m = ldb.Message()
m.dn = ldb.Dn(l, "dc=modify2")
- m["bla"] = ldb.MessageElement(["456"], ldb.CHANGETYPE_MODIFY, "bla")
+ m["bla"] = ldb.MessageElement(["789"], ldb.FLAG_MOD_REPLACE, "bla")
+ self.assertEquals(ldb.FLAG_MOD_REPLACE, m["bla"].flags())
l.modify(m)
rm = l.search(m.dn)[0]
self.assertEquals(2, len(rm))
- self.assertEquals(["1234"], list(rm["bla"]))
+ self.assertEquals(["789"], list(rm["bla"]))
+ rm = l.search(m.dn, attrs=["bla"])[0]
+ self.assertEquals(1, len(rm))
finally:
l.delete(ldb.Dn(l, "dc=modify2"))
+ def test_modify_flags_change(self):
+ l = ldb.Ldb(filename())
+ m = ldb.Message()
+ m.dn = ldb.Dn(l, "dc=add")
+ m["bla"] = ["1234"]
+ l.add(m)
+ try:
+ m = ldb.Message()
+ m.dn = ldb.Dn(l, "dc=add")
+ m["bla"] = ldb.MessageElement(["456"], ldb.FLAG_MOD_ADD, "bla")
+ self.assertEquals(ldb.FLAG_MOD_ADD, m["bla"].flags())
+ l.modify(m)
+ rm = l.search(m.dn)[0]
+ self.assertEquals(2, len(rm))
+ self.assertEquals(["1234", "456"], list(rm["bla"]))
+
+ #Now create another modify, but switch the flags before we do it
+ m["bla"] = ldb.MessageElement(["456"], ldb.FLAG_MOD_ADD, "bla")
+ m["bla"].set_flags(ldb.FLAG_MOD_DELETE)
+ l.modify(m)
+ rm = l.search(m.dn, attrs=["bla"])[0]
+ self.assertEquals(1, len(rm))
+ self.assertEquals(["1234"], list(rm["bla"]))
+
+ finally:
+ l.delete(ldb.Dn(l, "dc=add"))
+
def test_transaction_commit(self):
l = ldb.Ldb(filename())
l.transaction_start()