s4:dsdb Add 'lazy_commit' module to swallow the 'lazy commit' OID
authorAndrew Bartlett <abartlet@samba.org>
Fri, 25 Sep 2009 15:08:18 +0000 (08:08 -0700)
committerMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Fri, 2 Oct 2009 10:45:06 +0000 (12:45 +0200)
This allows this control to be specified as critical.  We support the
control because we choose to always be durable in our transactions.

We really, really need a 'duplicate request' API, as at the
moment we can't do this without a large, error-prone set of code that
cannot cope with new request fields or types.

Andrew Bartlett

source4/dsdb/samdb/ldb_modules/config.mk
source4/dsdb/samdb/ldb_modules/lazy_commit.c [new file with mode: 0644]
source4/lib/ldb/include/ldb.h
source4/scripting/python/samba/provision.py

index a49b238591d608d616dc95081a50ac8bfdf41638..456ff5756c6e00e6f78c31aee747203a7f5db9bb 100644 (file)
@@ -369,3 +369,15 @@ INIT_FUNCTION = LDB_MODULE(acl)
 ################################################
 
 ldb_acl_OBJ_FILES = $(dsdbsrcdir)/samdb/ldb_modules/acl.o
 ################################################
 
 ldb_acl_OBJ_FILES = $(dsdbsrcdir)/samdb/ldb_modules/acl.o
+
+################################################
+# Start MODULE ldb_lazy_commit
+[MODULE::ldb_lazy_commit]
+PRIVATE_DEPENDENCIES = SAMDB
+SUBSYSTEM = LIBLDB
+INIT_FUNCTION = LDB_MODULE(lazy_commit)
+
+# End MODULE ldb_lazy_commit
+################################################
+
+ldb_lazy_commit_OBJ_FILES = $(dsdbsrcdir)/samdb/ldb_modules/lazy_commit.o
diff --git a/source4/dsdb/samdb/ldb_modules/lazy_commit.c b/source4/dsdb/samdb/ldb_modules/lazy_commit.c
new file mode 100644 (file)
index 0000000..69ac99e
--- /dev/null
@@ -0,0 +1,132 @@
+/* 
+   ldb database library
+
+   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+ *  Name: ldb
+ *
+ *  Component: ldb lazy_commit module
+ *
+ *  Description: module to pretend to support the 'lazy commit' control
+ *
+ *  Author: Andrew Bartlett
+ */
+
+#include "ldb_module.h"
+
+static int unlazy_op(struct ldb_module *module, struct ldb_request *req)
+{
+       int ret;
+       struct ldb_request *new_req;
+       struct ldb_control **saved_controls;
+       struct ldb_control *control = ldb_request_get_control(req, LDB_CONTROL_SERVER_LAZY_COMMIT);
+       if (!control) {
+               return ldb_next_request(module, req);
+       } 
+       
+       switch (req->operation) {
+       case LDB_SEARCH:
+               ret = ldb_build_search_req_ex(&new_req, ldb_module_get_ctx(module),
+                                             req,
+                                             req->op.search.base,
+                                             req->op.search.scope,
+                                             req->op.search.tree,
+                                             req->op.search.attrs,
+                                             req->controls,
+                                             req->context, req->callback,
+                                             req);
+               break;
+       case LDB_ADD:
+               ret = ldb_build_add_req(&new_req, ldb_module_get_ctx(module), req,
+                                       req->op.add.message,
+                                       req->controls,
+                                       req->context, req->callback,
+                                       req);
+               break;
+       case LDB_MODIFY:
+               ret = ldb_build_mod_req(&new_req, ldb_module_get_ctx(module), req,
+                                       req->op.mod.message,
+                                       req->controls,
+                                       req->context, req->callback,
+                                       req);
+               break;
+       case LDB_DELETE:
+               ret = ldb_build_del_req(&new_req, ldb_module_get_ctx(module), req,
+                                       req->op.del.dn,
+                                       req->controls,
+                                       req->context, req->callback,
+                                       req);
+               break;
+       case LDB_RENAME:
+               ret = ldb_build_rename_req(&new_req, ldb_module_get_ctx(module), req,
+                                          req->op.rename.olddn,
+                                          req->op.rename.newdn,
+                                          req->controls,
+                                          req->context, req->callback,
+                                          req);
+               break;
+       case LDB_EXTENDED:
+               ret = ldb_build_extended_req(&new_req, ldb_module_get_ctx(module),
+                                            req,
+                                            req->op.extended.oid,
+                                            req->op.extended.data,
+                                            req->controls,
+                                            req->context, req->callback,
+                                            req);
+               break;
+       default:
+               ldb_set_errstring(ldb_module_get_ctx(module),
+                                 "Unsupported request type!");
+               ret = LDB_ERR_UNWILLING_TO_PERFORM;
+       }
+
+       if (ret != LDB_SUCCESS) {
+               return ret;
+       }
+
+       save_controls(control, req, &saved_controls);
+       return ldb_next_request(module, new_req);
+}
+
+static int unlazy_init(struct ldb_module *module)
+{
+       int ret;
+       struct ldb_context *ldb;
+       ldb = ldb_module_get_ctx(module);
+
+       ret = ldb_mod_register_control(module, LDB_CONTROL_SHOW_DELETED_OID);
+       if (ret != LDB_SUCCESS) {
+               ldb_debug(ldb, LDB_DEBUG_ERROR,
+                       "lazy_commit: Unable to register control with rootdse!\n");
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       return ldb_next_init(module);
+}
+
+const struct ldb_module_ops ldb_lazy_commit_module_ops = {
+       .name              = "lazy_commit",
+       .search            = unlazy_op,
+       .add               = unlazy_op,
+       .modify            = unlazy_op,
+       .del               = unlazy_op,
+       .rename            = unlazy_op,
+       .request           = unlazy_op,
+       .extended          = unlazy_op,
+       .init_context      = unlazy_init,
+};
index d4af95b394c7be235cffd90bc78dac66b52ed576..23db309ee706c8e3efefbdbc395cf1c1af25bbd3 100644 (file)
@@ -596,6 +596,14 @@ typedef int (*ldb_qsort_cmp_fn_t) (void *v1, void *v2, void *opaque);
 */
 #define LDB_CONTROL_PERMISSIVE_MODIFY_OID      "1.2.840.113556.1.4.1413"
 
 */
 #define LDB_CONTROL_PERMISSIVE_MODIFY_OID      "1.2.840.113556.1.4.1413"
 
+/** 
+    OID to allow the server to be more 'fast and loose' with the data being added.  
+
+    \sa 
+
+*/
+#define LDB_CONTROL_SERVER_LAZY_COMMIT   "1.2.840.113556.1.4.619"
+
 /**
    OID for LDAP Extended Operation START_TLS.
 
 /**
    OID for LDAP Extended Operation START_TLS.
 
@@ -612,6 +620,7 @@ typedef int (*ldb_qsort_cmp_fn_t) (void *v1, void *v2, void *opaque);
 */
 #define LDB_EXTENDED_FAST_BIND_OID     "1.2.840.113556.1.4.1781"
 
 */
 #define LDB_EXTENDED_FAST_BIND_OID     "1.2.840.113556.1.4.1781"
 
+
 struct ldb_sd_flags_control {
        /*
         * request the owner    0x00000001
 struct ldb_sd_flags_control {
        /*
         * request the owner    0x00000001
index 06b828896959f9bb12557ae11b2869ec4b36410f..e830870bb093ec2e89c93ae2f790b8f063a870f9 100644 (file)
@@ -616,6 +616,7 @@ def setup_samdb_partitions(samdb_path, setup_path, message, lp, session_info,
     # - each partition has its own module list then
     modules_list = ["resolve_oids",
                     "rootdse",
     # - each partition has its own module list then
     modules_list = ["resolve_oids",
                     "rootdse",
+                    "lazy_commit",
                     "acl",
                     "paged_results",
                     "ranged_results",
                     "acl",
                     "paged_results",
                     "ranged_results",