s4:dsdb Remove partition_extended_schema_update_now
[ira/wip.git] / source4 / dsdb / samdb / ldb_modules / lazy_commit.c
1 /* 
2    ldb database library
3
4    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /*
21  *  Name: ldb
22  *
23  *  Component: ldb lazy_commit module
24  *
25  *  Description: module to pretend to support the 'lazy commit' control
26  *
27  *  Author: Andrew Bartlett
28  */
29
30 #include "ldb_module.h"
31
32 static int unlazy_op(struct ldb_module *module, struct ldb_request *req)
33 {
34         int ret;
35         struct ldb_request *new_req;
36         struct ldb_control **saved_controls;
37         struct ldb_control *control = ldb_request_get_control(req, LDB_CONTROL_SERVER_LAZY_COMMIT);
38         if (!control) {
39                 return ldb_next_request(module, req);
40         } 
41         
42         switch (req->operation) {
43         case LDB_SEARCH:
44                 ret = ldb_build_search_req_ex(&new_req, ldb_module_get_ctx(module),
45                                               req,
46                                               req->op.search.base,
47                                               req->op.search.scope,
48                                               req->op.search.tree,
49                                               req->op.search.attrs,
50                                               req->controls,
51                                               req->context, req->callback,
52                                               req);
53                 break;
54         case LDB_ADD:
55                 ret = ldb_build_add_req(&new_req, ldb_module_get_ctx(module), req,
56                                         req->op.add.message,
57                                         req->controls,
58                                         req->context, req->callback,
59                                         req);
60                 break;
61         case LDB_MODIFY:
62                 ret = ldb_build_mod_req(&new_req, ldb_module_get_ctx(module), req,
63                                         req->op.mod.message,
64                                         req->controls,
65                                         req->context, req->callback,
66                                         req);
67                 break;
68         case LDB_DELETE:
69                 ret = ldb_build_del_req(&new_req, ldb_module_get_ctx(module), req,
70                                         req->op.del.dn,
71                                         req->controls,
72                                         req->context, req->callback,
73                                         req);
74                 break;
75         case LDB_RENAME:
76                 ret = ldb_build_rename_req(&new_req, ldb_module_get_ctx(module), req,
77                                            req->op.rename.olddn,
78                                            req->op.rename.newdn,
79                                            req->controls,
80                                            req->context, req->callback,
81                                            req);
82                 break;
83         case LDB_EXTENDED:
84                 ret = ldb_build_extended_req(&new_req, ldb_module_get_ctx(module),
85                                              req,
86                                              req->op.extended.oid,
87                                              req->op.extended.data,
88                                              req->controls,
89                                              req->context, req->callback,
90                                              req);
91                 break;
92         default:
93                 ldb_set_errstring(ldb_module_get_ctx(module),
94                                   "Unsupported request type!");
95                 ret = LDB_ERR_UNWILLING_TO_PERFORM;
96         }
97
98         if (ret != LDB_SUCCESS) {
99                 return ret;
100         }
101
102         save_controls(control, req, &saved_controls);
103         return ldb_next_request(module, new_req);
104 }
105
106 static int unlazy_init(struct ldb_module *module)
107 {
108         int ret;
109         struct ldb_context *ldb;
110         ldb = ldb_module_get_ctx(module);
111
112         ret = ldb_mod_register_control(module, LDB_CONTROL_SHOW_DELETED_OID);
113         if (ret != LDB_SUCCESS) {
114                 ldb_debug(ldb, LDB_DEBUG_ERROR,
115                         "lazy_commit: Unable to register control with rootdse!\n");
116                 return LDB_ERR_OPERATIONS_ERROR;
117         }
118
119         return ldb_next_init(module);
120 }
121
122 const struct ldb_module_ops ldb_lazy_commit_module_ops = {
123         .name              = "lazy_commit",
124         .search            = unlazy_op,
125         .add               = unlazy_op,
126         .modify            = unlazy_op,
127         .del               = unlazy_op,
128         .rename            = unlazy_op,
129         .request           = unlazy_op,
130         .extended          = unlazy_op,
131         .init_context      = unlazy_init,
132 };