s4:resolve_oids LDB module - not really a change but a nicer method to call "talloc_r...
[Samba/nascimento.git] / source4 / dsdb / samdb / ldb_modules / validate_update.c
blob3615ff768a4a3b82471206f60255219109ff6959
1 /*
2 ldb database library
4 Copyright (C) Stefan Metzmacher <metze@samba.org> 2009
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "ldb_module.h"
22 #include "dsdb/samdb/samdb.h"
24 static int validate_update_message(struct ldb_context *ldb,
25 struct dsdb_schema *schema,
26 const struct ldb_message *msg)
28 int i;
30 for (i=0; i < msg->num_elements; i++) {
31 WERROR werr;
33 werr = dsdb_attribute_validate_ldb(ldb, schema,
34 &msg->elements[i]);
35 if (!W_ERROR_IS_OK(werr)) {
36 int j;
38 ldb_debug(ldb, LDB_DEBUG_ERROR,
39 "TODO: object[%s] add/modify attribute[%d|%s] num_values[%d] - %s\n",
40 ldb_dn_get_linearized(msg->dn),
41 i, msg->elements[i].name,
42 msg->elements[i].num_values,
43 win_errstr(werr));
45 for (j=0; j < msg->elements[i].num_values; j++) {
46 ldb_debug(ldb, LDB_DEBUG_ERROR,
47 "TODO: value[%lu] len[%lu]\n", (long unsigned int)j,
48 (long unsigned int)msg->elements[i].values[j].length);
49 dump_data(0,
50 msg->elements[i].values[j].data,
51 msg->elements[i].values[j].length);
54 return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
58 return LDB_SUCCESS;
61 static int validate_update_add(struct ldb_module *module, struct ldb_request *req)
63 struct ldb_context *ldb;
64 struct dsdb_schema *schema;
65 int ret;
67 ldb = ldb_module_get_ctx(module);
68 schema = dsdb_get_schema(ldb, NULL);
70 if (!schema) {
71 return ldb_next_request(module, req);
74 /* do not manipulate our control entries */
75 if (ldb_dn_is_special(req->op.add.message->dn)) {
76 return ldb_next_request(module, req);
79 ret = validate_update_message(ldb, schema,
80 req->op.add.message);
81 if (ret != LDB_SUCCESS) {
82 return ret;
85 return ldb_next_request(module, req);
88 static int validate_update_modify(struct ldb_module *module, struct ldb_request *req)
90 struct ldb_context *ldb;
91 struct dsdb_schema *schema;
92 int ret;
94 ldb = ldb_module_get_ctx(module);
95 schema = dsdb_get_schema(ldb, NULL);
97 if (!schema) {
98 return ldb_next_request(module, req);
101 /* do not manipulate our control entries */
102 if (ldb_dn_is_special(req->op.mod.message->dn)) {
103 return ldb_next_request(module, req);
106 ret = validate_update_message(ldb, schema,
107 req->op.mod.message);
108 if (ret != LDB_SUCCESS) {
109 return ret;
112 return ldb_next_request(module, req);
115 _PUBLIC_ const struct ldb_module_ops ldb_validate_update_module_ops = {
116 .name = "validate_update",
117 .add = validate_update_add,
118 .modify = validate_update_modify,