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/>.
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
)
30 for (i
=0; i
< msg
->num_elements
; i
++) {
33 werr
= dsdb_attribute_validate_ldb(ldb
, schema
,
35 if (!W_ERROR_IS_OK(werr
)) {
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
,
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
);
50 msg
->elements
[i
].values
[j
].data
,
51 msg
->elements
[i
].values
[j
].length
);
54 return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX
;
61 static int validate_update_add(struct ldb_module
*module
, struct ldb_request
*req
)
63 struct ldb_context
*ldb
;
64 struct dsdb_schema
*schema
;
67 ldb
= ldb_module_get_ctx(module
);
68 schema
= dsdb_get_schema(ldb
, NULL
);
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
,
81 if (ret
!= LDB_SUCCESS
) {
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
;
94 ldb
= ldb_module_get_ctx(module
);
95 schema
= dsdb_get_schema(ldb
, NULL
);
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
) {
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
,