4 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006-2007
5 Copyright (C) Andrew Tridgell <tridge@samba.org> 2009
6 Copyright (C) Stefan Metzmacher <metze@samba.org> 2007
7 Copyright (C) Simo Sorce <idra@samba.org> 2008
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 * Component: ldb subtree delete (prevention) module
28 * Description: Prevent deletion of a subtree in LDB
30 * Author: Andrew Bartlett
33 #include "ldb_module.h"
34 #include "dsdb/samdb/ldb_modules/util.h"
37 static int subtree_delete(struct ldb_module *module, struct ldb_request *req)
39 static const char * const attrs[] = { NULL };
41 struct ldb_result *res = NULL;
43 if (ldb_dn_is_special(req->op.del.dn)) {
44 /* do not manipulate our control entries */
45 return ldb_next_request(module, req);
48 /* see if we have any children */
49 ret = dsdb_module_search(module, req, &res, req->op.del.dn,
50 LDB_SCOPE_ONELEVEL, attrs,
51 DSDB_SEARCH_SHOW_DELETED, "(objectClass=*)");
52 if (ret != LDB_SUCCESS) {
57 ldb_asprintf_errstring(ldb_module_get_ctx(module),
58 "Cannot delete %s, not a leaf node "
59 "(has %d children)\n",
60 ldb_dn_get_linearized(req->op.del.dn),
63 return LDB_ERR_NOT_ALLOWED_ON_NON_LEAF;
67 return ldb_next_request(module, req);
70 const struct ldb_module_ops ldb_subtree_delete_module_ops = {
71 .name = "subtree_delete",
72 .del = subtree_delete,