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
35 #include <ldb_module.h>
36 #include "dsdb/samdb/ldb_modules/util.h"
39 static int subtree_delete(struct ldb_module *module, struct ldb_request *req)
41 static const char * const attrs[] = { NULL };
43 struct ldb_result *res = NULL;
45 if (ldb_dn_is_special(req->op.del.dn)) {
46 /* do not manipulate our control entries */
47 return ldb_next_request(module, req);
50 /* see if we have any children */
51 ret = dsdb_module_search(module, req, &res, req->op.del.dn,
52 LDB_SCOPE_ONELEVEL, attrs,
53 DSDB_SEARCH_SHOW_DELETED, "(objectClass=*)");
54 if (ret != LDB_SUCCESS) {
59 ldb_asprintf_errstring(ldb_module_get_ctx(module),
60 "Cannot delete %s, not a leaf node "
61 "(has %d children)\n",
62 ldb_dn_get_linearized(req->op.del.dn),
65 return LDB_ERR_NOT_ALLOWED_ON_NON_LEAF;
69 return ldb_next_request(module, req);
72 _PUBLIC_ const struct ldb_module_ops ldb_subtree_delete_module_ops = {
73 .name = "subtree_delete",
74 .del = subtree_delete,