dsdb: Fix includes when building against system ldb.
[samba.git] / source4 / dsdb / samdb / ldb_modules / subtree_delete.c
1 /* 
2    ldb database library
3
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
8
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.
13    
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.
18    
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/>.
21 */
22
23 /*
24  *  Name: ldb
25  *
26  *  Component: ldb subtree delete (prevention) module
27  *
28  *  Description: Prevent deletion of a subtree in LDB
29  *
30  *  Author: Andrew Bartlett
31  */
32
33 #include "includes.h"
34 #include <ldb.h>
35 #include <ldb_module.h>
36 #include "dsdb/samdb/ldb_modules/util.h"
37
38
39 static int subtree_delete(struct ldb_module *module, struct ldb_request *req)
40 {
41         static const char * const attrs[] = { NULL };
42         int ret;
43         struct ldb_result *res = NULL;
44
45         if (ldb_dn_is_special(req->op.del.dn)) {
46                 /* do not manipulate our control entries */
47                 return ldb_next_request(module, req);
48         }
49
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) {
55                 talloc_free(res);
56                 return ret;
57         }
58         if (res->count > 0) {
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),
63                                        res->count);
64                 talloc_free(res);
65                 return LDB_ERR_NOT_ALLOWED_ON_NON_LEAF;
66         }
67         talloc_free(res);
68
69         return ldb_next_request(module, req);
70 }
71
72 _PUBLIC_ const struct ldb_module_ops ldb_subtree_delete_module_ops = {
73         .name              = "subtree_delete",
74         .del               = subtree_delete,
75 };