The branch, master has been updated
       via  d575b2b samba-tool: disable validation on removing an empty 
attribute in dbcheck
       via  2320221 pyldb: make ldb operations more consistent
       via  8741f03 pyldb: added validate option to ldb.modify()
      from  8096b1a s3:smbd/quotas: add #include "system/filesys.h" (bug #8224)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit d575b2b0aba0aeaf73d82e2ed58150110db4025b
Author: Andrew Tridgell <[email protected]>
Date:   Tue Jun 14 16:43:10 2011 +1000

    samba-tool: disable validation on removing an empty attribute in dbcheck
    
    Autobuild-User: Andrew Tridgell <[email protected]>
    Autobuild-Date: Tue Jun 14 10:49:34 CEST 2011 on sn-devel-104

commit 23202211050b3b3d41632d2bf2795249644d7e8a
Author: Andrew Tridgell <[email protected]>
Date:   Tue Jun 14 16:41:35 2011 +1000

    pyldb: make ldb operations more consistent
    
    This changes the controls option on ldb operations to be a keyword
    argument, which is more consistent with general python
    conventions. This also fixes the pydoc output to include the controls
    option.

commit 8741f039955853c092c45cc7f2cedca2384b4c57
Author: Andrew Tridgell <[email protected]>
Date:   Tue Jun 14 16:39:49 2011 +1000

    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

-----------------------------------------------------------------------

Summary of changes:
 source4/lib/ldb/pyldb.c                          |   57 ++++++++++++++--------
 source4/scripting/python/samba/netcmd/dbcheck.py |    2 +-
 2 files changed, 37 insertions(+), 22 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c
index 68f9098..61662f6 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,
@@ -958,7 +964,7 @@ static struct ldb_message *PyDict_AsMessage(TALLOC_CTX 
*mem_ctx,
        return msg;
 }
 
-static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args)
+static PyObject *py_ldb_add(PyLdbObject *self, PyObject *args, PyObject 
*kwargs)
 {
        PyObject *py_obj;
        int ret;
@@ -968,8 +974,11 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject 
*args)
        PyObject *py_controls = Py_None;
        TALLOC_CTX *mem_ctx;
        struct ldb_control **parsed_controls;
+       const char * const kwnames[] = { "message", "controls", NULL };
 
-       if (!PyArg_ParseTuple(args, "O|O", &py_obj, &py_controls ))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
+                                        discard_const_p(char *, kwnames),
+                                        &py_obj, &py_controls))
                return NULL;
 
        mem_ctx = talloc_new(NULL);
@@ -1047,7 +1056,7 @@ static PyObject *py_ldb_add(PyLdbObject *self, PyObject 
*args)
        Py_RETURN_NONE;
 }
 
-static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args)
+static PyObject *py_ldb_delete(PyLdbObject *self, PyObject *args, PyObject 
*kwargs)
 {
        PyObject *py_dn;
        struct ldb_dn *dn;
@@ -1057,8 +1066,11 @@ static PyObject *py_ldb_delete(PyLdbObject *self, 
PyObject *args)
        PyObject *py_controls = Py_None;
        TALLOC_CTX *mem_ctx;
        struct ldb_control **parsed_controls;
+       const char * const kwnames[] = { "dn", "controls", NULL };
 
-       if (!PyArg_ParseTuple(args, "O|O", &py_dn, &py_controls))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O",
+                                        discard_const_p(char *, kwnames),
+                                        &py_dn, &py_controls))
                return NULL;
 
        mem_ctx = talloc_new(NULL);
@@ -1119,7 +1131,7 @@ static PyObject *py_ldb_delete(PyLdbObject *self, 
PyObject *args)
        Py_RETURN_NONE;
 }
 
-static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args)
+static PyObject *py_ldb_rename(PyLdbObject *self, PyObject *args, PyObject 
*kwargs)
 {
        PyObject *py_dn1, *py_dn2;
        struct ldb_dn *dn1, *dn2;
@@ -1130,10 +1142,13 @@ static PyObject *py_ldb_rename(PyLdbObject *self, 
PyObject *args)
        struct ldb_control **parsed_controls;
        struct ldb_context *ldb_ctx;
        struct ldb_request *req;
+       const char * const kwnames[] = { "dn1", "dn2", "controls", NULL };
 
        ldb_ctx = PyLdb_AsLdbContext(self);
 
-       if (!PyArg_ParseTuple(args, "OO|O", &py_dn1, &py_dn2, &py_controls))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|O",
+                                        discard_const_p(char *, kwnames),
+                                        &py_dn1, &py_dn2, &py_controls))
                return NULL;
 
 
@@ -1586,17 +1601,17 @@ 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"
+       { "add", (PyCFunction)py_ldb_add, METH_VARARGS|METH_KEYWORDS,
+               "S.add(message, controls=None) -> None\n"
                "Add an entry." },
-       { "delete", (PyCFunction)py_ldb_delete, METH_VARARGS,
-               "S.delete(dn) -> None\n"
+       { "delete", (PyCFunction)py_ldb_delete, METH_VARARGS|METH_KEYWORDS,
+               "S.delete(dn, controls=None) -> None\n"
                "Remove an entry." },
-       { "rename", (PyCFunction)py_ldb_rename, METH_VARARGS,
-               "S.rename(old_dn, new_dn) -> None\n"
+       { "rename", (PyCFunction)py_ldb_rename, METH_VARARGS|METH_KEYWORDS,
+               "S.rename(old_dn, new_dn, controls=None) -> None\n"
                "Rename an entry." },
        { "search", (PyCFunction)py_ldb_search, METH_VARARGS|METH_KEYWORDS,
                "S.search(base=None, scope=None, expression=None, attrs=None, 
controls=None) -> msgs\n"
diff --git a/source4/scripting/python/samba/netcmd/dbcheck.py 
b/source4/scripting/python/samba/netcmd/dbcheck.py
index 7bbd4d2..7af2101 100644
--- a/source4/scripting/python/samba/netcmd/dbcheck.py
+++ b/source4/scripting/python/samba/netcmd/dbcheck.py
@@ -51,7 +51,7 @@ def empty_attribute(self, dn, attrname):
     m.dn = dn
     m[attrname] = ldb.MessageElement('', ldb.FLAG_MOD_DELETE, attrname)
     try:
-        self.samdb.modify(m, ["relax:0"])
+        self.samdb.modify(m, controls=["relax:0"], validate=False)
     except Exception, msg:
         print("Failed to remove empty attribute %s : %s" % (attrname, msg))
         return


-- 
Samba Shared Repository

Reply via email to