From 8741f039955853c092c45cc7f2cedca2384b4c57 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 14 Jun 2011 16:39:49 +1000 Subject: pyldb: added validate option to ldb.modify() This allows validation of ldb messages in a ldb modify operation to be bypassed, by setting validate=False. This is useful in the dbcheck tool to allow for removing invalid empty attributes from the database --- source4/lib/ldb/pyldb.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 68f909858d..58a63950b1 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -819,7 +819,7 @@ static PyObject *py_ldb_connect(PyLdbObject *self, PyObject *args, PyObject *kwa Py_RETURN_NONE; } -static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args) +static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args, PyObject *kwargs) { PyObject *py_msg; PyObject *py_controls = Py_None; @@ -829,8 +829,12 @@ static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args) struct ldb_message *msg; int ret; TALLOC_CTX *mem_ctx; + bool validate=true; + const char * const kwnames[] = { "message", "controls", "validate", NULL }; - if (!PyArg_ParseTuple(args, "O|O", &py_msg, &py_controls)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Ob", + discard_const_p(char *, kwnames), + &py_msg, &py_controls, &validate)) return NULL; mem_ctx = talloc_new(NULL); @@ -855,11 +859,13 @@ static PyObject *py_ldb_modify(PyLdbObject *self, PyObject *args) } msg = PyLdbMessage_AsMessage(py_msg); - ret = ldb_msg_sanity_check(ldb_ctx, msg); - if (ret != LDB_SUCCESS) { - PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx); - talloc_free(mem_ctx); - return NULL; + if (validate) { + ret = ldb_msg_sanity_check(ldb_ctx, msg); + if (ret != LDB_SUCCESS) { + PyErr_LDB_ERROR_IS_ERR_RAISE(PyExc_LdbError, ret, ldb_ctx); + talloc_free(mem_ctx); + return NULL; + } } ret = ldb_build_mod_req(&req, ldb_ctx, mem_ctx, msg, parsed_controls, @@ -1586,8 +1592,8 @@ static PyMethodDef py_ldb_methods[] = { { "connect", (PyCFunction)py_ldb_connect, METH_VARARGS|METH_KEYWORDS, "S.connect(url, flags=0, options=None) -> None\n" "Connect to a LDB URL." }, - { "modify", (PyCFunction)py_ldb_modify, METH_VARARGS, - "S.modify(message) -> None\n" + { "modify", (PyCFunction)py_ldb_modify, METH_VARARGS|METH_KEYWORDS, + "S.modify(message, controls=None, validate=False) -> None\n" "Modify an entry." }, { "add", (PyCFunction)py_ldb_add, METH_VARARGS, "S.add(message) -> None\n" -- cgit