4 Copyright (C) Simo Sorce 2005
5 Copyright (C) Stefa Metzmacher <metze@samba.org> 2007
7 ** NOTE! The following LGPL license applies to the ldb
8 ** library. This does NOT imply that all of Samba is released
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 3 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, see <http://www.gnu.org/licenses/>.
28 * Component: ldb deleted objects control module
30 * Description: this module hides deleted objects, and returns them if the right control is there
32 * Author: Stefan Metzmacher
36 #include "ldb/include/ldb_module.h"
37 #include "dsdb/samdb/samdb.h"
40 struct show_deleted_search_request {
42 struct ldb_module *module;
43 struct ldb_request *req;
46 static int show_deleted_search_callback(struct ldb_request *req,
47 struct ldb_reply *ares)
49 struct show_deleted_search_request *ar;
51 ar = talloc_get_type(req->context, struct show_deleted_search_request);
54 return ldb_module_done(ar->req, NULL, NULL,
55 LDB_ERR_OPERATIONS_ERROR);
57 if (ares->error != LDB_SUCCESS) {
58 return ldb_module_done(ar->req, ares->controls,
59 ares->response, ares->error);
65 return ldb_module_send_entry(ar->req, ares->message, ares->controls);
67 case LDB_REPLY_REFERRAL:
68 return ldb_module_send_referral(ar->req, ares->referral);
71 return ldb_module_done(ar->req, ares->controls,
72 ares->response, LDB_SUCCESS);
78 static int show_deleted_search(struct ldb_module *module, struct ldb_request *req)
80 struct ldb_context *ldb;
81 struct ldb_control *control;
82 struct ldb_control **saved_controls;
83 struct show_deleted_search_request *ar;
84 struct ldb_request *down_req;
89 ldb = ldb_module_get_ctx(module);
91 ar = talloc_zero(req, struct show_deleted_search_request);
93 return LDB_ERR_OPERATIONS_ERROR;
98 /* check if there's a show deleted control */
99 control = ldb_request_get_control(req, LDB_CONTROL_SHOW_DELETED_OID);
102 old_filter = ldb_filter_from_tree(ar, req->op.search.tree);
103 new_filter = talloc_asprintf(ar, "(&(!(isDeleted=TRUE))%s)",
106 ret = ldb_build_search_req(&down_req, ldb, ar,
108 req->op.search.scope,
110 req->op.search.attrs,
112 ar, show_deleted_search_callback,
116 ret = ldb_build_search_req_ex(&down_req, ldb, ar,
118 req->op.search.scope,
120 req->op.search.attrs,
122 ar, show_deleted_search_callback,
125 if (ret != LDB_SUCCESS) {
129 /* if a control is there remove if from the modified request */
130 if (control && !save_controls(control, down_req, &saved_controls)) {
131 return LDB_ERR_OPERATIONS_ERROR;
134 /* perform the search */
135 return ldb_next_request(module, down_req);
138 static int show_deleted_init(struct ldb_module *module)
140 struct ldb_context *ldb;
143 ldb = ldb_module_get_ctx(module);
145 ret = ldb_mod_register_control(module, LDB_CONTROL_SHOW_DELETED_OID);
146 if (ret != LDB_SUCCESS) {
147 ldb_debug(ldb, LDB_DEBUG_ERROR,
148 "show_deleted: Unable to register control with rootdse!\n");
149 return LDB_ERR_OPERATIONS_ERROR;
152 return ldb_next_init(module);
155 _PUBLIC_ const struct ldb_module_ops ldb_show_deleted_module_ops = {
156 .name = "show_deleted",
157 .search = show_deleted_search,
158 .init_context = show_deleted_init