summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-06-14 16:39:49 +1000
committerAndrew Tridgell <tridge@samba.org>2011-06-14 09:39:24 +0200
commit8741f039955853c092c45cc7f2cedca2384b4c57 (patch)
tree6bb65a0b02dcc719f68f7007f450d233761e1937
parent8096b1a9a4b1518467e7a85bb9000904a76c1ac4 (diff)
downloadsamba-8741f039955853c092c45cc7f2cedca2384b4c57.tar.gz
samba-8741f039955853c092c45cc7f2cedca2384b4c57.tar.xz
samba-8741f039955853c092c45cc7f2cedca2384b4c57.zip
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
-rw-r--r--source4/lib/ldb/pyldb.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index 68f909858de..58a63950b10 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"