s4:subtree_delete - "NULL" as format string isn't allowed on FreeBSD
[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 "ldb_module.h"
34 #include "dsdb/samdb/ldb_modules/util.h"
35
36
37 static int subtree_delete(struct ldb_module *module, struct ldb_request *req)
38 {
39         static const char * const attrs[] = { NULL };
40         int ret;
41         struct ldb_result *res = NULL;
42
43         if (ldb_dn_is_special(req->op.del.dn)) {
44                 /* do not manipulate our control entries */
45                 return ldb_next_request(module, req);
46         }
47
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) {
53                 talloc_free(res);
54                 return ret;
55         }
56         if (res->count > 0) {
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),
61                                        res->count);
62                 talloc_free(res);
63                 return LDB_ERR_NOT_ALLOWED_ON_NON_LEAF;
64         }
65         talloc_free(res);
66
67         return ldb_next_request(module, req);
68 }
69
70 const struct ldb_module_ops ldb_subtree_delete_module_ops = {
71         .name              = "subtree_delete",
72         .del               = subtree_delete,
73 };