4 Copyright (C) Simo Sorce 2005
5 Copyright (C) Stefan Metzmacher <metze@samba.org> 2007
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * Component: ldb deleted objects control module
27 * Description: this module hides deleted objects, and returns them if the right control is there
29 * Author: Stefan Metzmacher
33 #include "ldb/include/ldb_module.h"
34 #include "dsdb/samdb/samdb.h"
35 #include "dsdb/samdb/ldb_modules/util.h"
37 static int show_deleted_search(struct ldb_module
*module
, struct ldb_request
*req
)
39 struct ldb_context
*ldb
;
40 struct ldb_control
*control
;
41 struct ldb_request
*down_req
;
42 struct ldb_parse_tree
*new_tree
= req
->op
.search
.tree
;
45 ldb
= ldb_module_get_ctx(module
);
47 /* check if there's a show deleted control */
48 control
= ldb_request_get_control(req
, LDB_CONTROL_SHOW_DELETED_OID
);
51 /* FIXME: we could use a constant tree here once we
52 are sure that no ldb modules modify trees
54 new_tree
= talloc(req
, struct ldb_parse_tree
);
57 return LDB_ERR_OPERATIONS_ERROR
;
59 new_tree
->operation
= LDB_OP_AND
;
60 new_tree
->u
.list
.num_elements
= 2;
61 new_tree
->u
.list
.elements
= talloc_array(new_tree
, struct ldb_parse_tree
*, 2);
62 if (!new_tree
->u
.list
.elements
) {
64 return LDB_ERR_OPERATIONS_ERROR
;
66 new_tree
->u
.list
.elements
[0] = talloc(new_tree
->u
.list
.elements
, struct ldb_parse_tree
);
67 new_tree
->u
.list
.elements
[0]->operation
= LDB_OP_NOT
;
68 new_tree
->u
.list
.elements
[0]->u
.isnot
.child
=
69 talloc(new_tree
->u
.list
.elements
, struct ldb_parse_tree
);
70 if (!new_tree
->u
.list
.elements
[0]->u
.isnot
.child
) {
72 return LDB_ERR_OPERATIONS_ERROR
;
74 new_tree
->u
.list
.elements
[0]->u
.isnot
.child
->operation
= LDB_OP_EQUALITY
;
75 new_tree
->u
.list
.elements
[0]->u
.isnot
.child
->u
.equality
.attr
= "isDeleted";
76 new_tree
->u
.list
.elements
[0]->u
.isnot
.child
->u
.equality
.value
= data_blob_string_const("TRUE");
77 new_tree
->u
.list
.elements
[1] = req
->op
.search
.tree
;
80 ret
= ldb_build_search_req_ex(&down_req
, ldb
, req
,
86 req
, dsdb_next_callback
,
88 if (ret
!= LDB_SUCCESS
) {
92 /* mark the control as done */
94 control
->critical
= 0;
97 /* perform the search */
98 return ldb_next_request(module
, down_req
);
101 static int show_deleted_init(struct ldb_module
*module
)
103 struct ldb_context
*ldb
;
106 ldb
= ldb_module_get_ctx(module
);
108 ret
= ldb_mod_register_control(module
, LDB_CONTROL_SHOW_DELETED_OID
);
109 if (ret
!= LDB_SUCCESS
) {
110 ldb_debug(ldb
, LDB_DEBUG_ERROR
,
111 "show_deleted: Unable to register control with rootdse!\n");
112 return LDB_ERR_OPERATIONS_ERROR
;
115 return ldb_next_init(module
);
118 _PUBLIC_
const struct ldb_module_ops ldb_show_deleted_module_ops
= {
119 .name
= "show_deleted",
120 .search
= show_deleted_search
,
121 .init_context
= show_deleted_init