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.h"
37 #include "ldb/include/ldb_errors.h"
38 #include "ldb/include/ldb_private.h"
39 #include "dsdb/samdb/samdb.h"
42 struct show_deleted_search_request {
44 struct ldb_module *module;
45 struct ldb_request *req;
48 static int show_deleted_search_callback(struct ldb_request *req,
49 struct ldb_reply *ares)
51 struct show_deleted_search_request *ar;
53 ar = talloc_get_type(req->context, struct show_deleted_search_request);
56 return ldb_module_done(ar->req, NULL, NULL,
57 LDB_ERR_OPERATIONS_ERROR);
59 if (ares->error != LDB_SUCCESS) {
60 return ldb_module_done(ar->req, ares->controls,
61 ares->response, ares->error);
67 return ldb_module_send_entry(ar->req, ares->message);
69 case LDB_REPLY_REFERRAL:
70 return ldb_module_send_referral(ar->req, ares->referral);
73 return ldb_module_done(ar->req, ares->controls,
74 ares->response, LDB_SUCCESS);
80 static int show_deleted_search(struct ldb_module *module, struct ldb_request *req)
82 struct ldb_control *control;
83 struct ldb_control **saved_controls;
84 struct show_deleted_search_request *ar;
85 struct ldb_request *down_req;
90 ar = talloc_zero(req, struct show_deleted_search_request);
92 return LDB_ERR_OPERATIONS_ERROR;
97 /* check if there's a show deleted control */
98 control = ldb_request_get_control(req, LDB_CONTROL_SHOW_DELETED_OID);
101 old_filter = ldb_filter_from_tree(ar, req->op.search.tree);
102 new_filter = talloc_asprintf(ar, "(&(!(isDeleted=TRUE))%s)",
105 ret = ldb_build_search_req(&down_req, module->ldb, ar,
107 req->op.search.scope,
109 req->op.search.attrs,
111 ar, show_deleted_search_callback,
115 ret = ldb_build_search_req_ex(&down_req, module->ldb, ar,
117 req->op.search.scope,
119 req->op.search.attrs,
121 ar, show_deleted_search_callback,
124 if (ret != LDB_SUCCESS) {
128 /* if a control is there remove if from the modified request */
129 if (control && !save_controls(control, down_req, &saved_controls)) {
130 return LDB_ERR_OPERATIONS_ERROR;
133 /* perform the search */
134 return ldb_next_request(module, down_req);
137 static int show_deleted_init(struct ldb_module *module)
141 ret = ldb_mod_register_control(module, LDB_CONTROL_SHOW_DELETED_OID);
142 if (ret != LDB_SUCCESS) {
143 ldb_debug(module->ldb, LDB_DEBUG_ERROR,
144 "extended_dn: Unable to register control with rootdse!\n");
145 return LDB_ERR_OPERATIONS_ERROR;
148 return ldb_next_init(module);
151 _PUBLIC_ const struct ldb_module_ops ldb_show_deleted_module_ops = {
152 .name = "show_deleted",
153 .search = show_deleted_search,
154 .init_context = show_deleted_init