s4-dsdb: convert the rest of the ldb modules to the new module type
[samba.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 #include "dsdb/samdb/ldb_modules/util.h"
32
33 static int unlazy_op(struct ldb_module *module, struct ldb_request *req)
34 {
35         int ret;
36         struct ldb_request *new_req;
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, dsdb_next_callback,
52                                               req);
53                 LDB_REQ_SET_LOCATION(new_req);
54                 break;
55         case LDB_ADD:
56                 ret = ldb_build_add_req(&new_req, ldb_module_get_ctx(module), req,
57                                         req->op.add.message,
58                                         req->controls,
59                                         req, dsdb_next_callback,
60                                         req);
61                 LDB_REQ_SET_LOCATION(new_req);
62                 break;
63         case LDB_MODIFY:
64                 ret = ldb_build_mod_req(&new_req, ldb_module_get_ctx(module), req,
65                                         req->op.mod.message,
66                                         req->controls,
67                                         req, dsdb_next_callback,
68                                         req);
69                 LDB_REQ_SET_LOCATION(new_req);
70                 break;
71         case LDB_DELETE:
72                 ret = ldb_build_del_req(&new_req, ldb_module_get_ctx(module), req,
73                                         req->op.del.dn,
74                                         req->controls,
75                                         req, dsdb_next_callback,
76                                         req);
77                 LDB_REQ_SET_LOCATION(new_req);
78                 break;
79         case LDB_RENAME:
80                 ret = ldb_build_rename_req(&new_req, ldb_module_get_ctx(module), req,
81                                            req->op.rename.olddn,
82                                            req->op.rename.newdn,
83                                            req->controls,
84                                            req, dsdb_next_callback,
85                                            req);
86                 LDB_REQ_SET_LOCATION(new_req);
87                 break;
88         case LDB_EXTENDED:
89                 ret = ldb_build_extended_req(&new_req, ldb_module_get_ctx(module),
90                                              req,
91                                              req->op.extended.oid,
92                                              req->op.extended.data,
93                                              req->controls,
94                                              req, dsdb_next_callback,
95                                              req);
96                 LDB_REQ_SET_LOCATION(new_req);
97                 break;
98         default:
99                 ldb_set_errstring(ldb_module_get_ctx(module),
100                                   "Unsupported request type!");
101                 ret = LDB_ERR_UNWILLING_TO_PERFORM;
102         }
103
104         if (ret != LDB_SUCCESS) {
105                 return ret;
106         }
107
108         control->critical = 0;
109         return ldb_next_request(module, new_req);
110 }
111
112 static const struct ldb_module_ops ldb_lazy_commit_module_ops = {
113         .name              = "lazy_commit",
114         .search            = unlazy_op,
115         .add               = unlazy_op,
116         .modify            = unlazy_op,
117         .del               = unlazy_op,
118         .rename            = unlazy_op,
119         .request           = unlazy_op,
120         .extended          = unlazy_op,
121 };
122
123 int ldb_lazy_commit_module_init(const char *version)
124 {
125         return ldb_register_module(&ldb_lazy_commit_module_ops);
126 }