s4-dsdb: Use dsdb_syntax_ctx in *_validate_ldb functions
[samba.git] / source4 / dsdb / schema / schema.h
1 /* 
2    Unix SMB/CIFS mplementation.
3    DSDB schema header
4    
5    Copyright (C) Stefan Metzmacher <metze@samba.org> 2006
6     
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19    
20 */
21
22 #ifndef _DSDB_SCHEMA_H
23 #define _DSDB_SCHEMA_H
24
25 #include "prefixmap.h"
26
27 struct dsdb_attribute;
28 struct dsdb_class;
29 struct dsdb_schema;
30
31 struct dsdb_syntax_ctx {
32         struct ldb_context *ldb;
33         const struct dsdb_schema *schema;
34 };
35
36
37 struct dsdb_syntax {
38         const char *name;
39         const char *ldap_oid;
40         uint32_t oMSyntax;
41         struct ldb_val oMObjectClass;
42         const char *attributeSyntax_oid;
43         const char *equality;
44         const char *substring;
45         const char *comment;
46         const char *ldb_syntax;
47
48         WERROR (*drsuapi_to_ldb)(struct ldb_context *ldb, 
49                                  const struct dsdb_schema *schema,
50                                  const struct dsdb_attribute *attr,
51                                  const struct drsuapi_DsReplicaAttribute *in,
52                                  TALLOC_CTX *mem_ctx,
53                                  struct ldb_message_element *out);
54         WERROR (*ldb_to_drsuapi)(struct ldb_context *ldb, 
55                                  const struct dsdb_schema *schema,
56                                  const struct dsdb_attribute *attr,
57                                  const struct ldb_message_element *in,
58                                  TALLOC_CTX *mem_ctx,
59                                  struct drsuapi_DsReplicaAttribute *out);
60         WERROR (*validate_ldb)(const struct dsdb_syntax_ctx *ctx,
61                                const struct dsdb_attribute *attr,
62                                const struct ldb_message_element *in);
63 };
64
65 struct dsdb_attribute {
66         struct dsdb_attribute *prev, *next;
67
68         const char *cn;
69         const char *lDAPDisplayName;
70         const char *attributeID_oid;
71         uint32_t attributeID_id;
72         struct GUID schemaIDGUID;
73         uint32_t mAPIID;
74         uint32_t msDS_IntId;
75
76         struct GUID attributeSecurityGUID;
77         struct GUID objectGUID;
78
79         uint32_t searchFlags;
80         uint32_t systemFlags;
81         bool isMemberOfPartialAttributeSet;
82         uint32_t linkID;
83
84         const char *attributeSyntax_oid;
85         uint32_t attributeSyntax_id;
86         uint32_t oMSyntax;
87         struct ldb_val oMObjectClass;
88
89         bool isSingleValued;
90         uint32_t *rangeLower;
91         uint32_t *rangeUpper;
92         bool extendedCharsAllowed;
93
94         uint32_t schemaFlagsEx;
95         struct ldb_val msDs_Schema_Extensions;
96
97         bool showInAdvancedViewOnly;
98         const char *adminDisplayName;
99         const char *adminDescription;
100         const char *classDisplayName;
101         bool isEphemeral;
102         bool isDefunct;
103         bool systemOnly;
104
105         /* internal stuff */
106         const struct dsdb_syntax *syntax;
107         const struct ldb_schema_attribute *ldb_schema_attribute;
108 };
109
110 struct dsdb_class {
111         struct dsdb_class *prev, *next;
112
113         const char *cn;
114         const char *lDAPDisplayName;
115         const char *governsID_oid;
116         uint32_t governsID_id;
117         struct GUID schemaIDGUID;
118         struct GUID objectGUID;
119
120         uint32_t objectClassCategory;
121         const char *rDNAttID;
122         const char *defaultObjectCategory;
123
124         const char *subClassOf;
125
126         const char **systemAuxiliaryClass;
127         const char **systemPossSuperiors;
128         const char **systemMustContain;
129         const char **systemMayContain;
130
131         const char **auxiliaryClass;
132         const char **possSuperiors;
133         const char **mustContain;
134         const char **mayContain;
135         const char **possibleInferiors;
136         const char **systemPossibleInferiors;
137
138         const char *defaultSecurityDescriptor;
139
140         uint32_t schemaFlagsEx;
141         struct ldb_val msDs_Schema_Extensions;
142
143         bool showInAdvancedViewOnly;
144         const char *adminDisplayName;
145         const char *adminDescription;
146         const char *classDisplayName;
147         bool defaultHidingValue;
148         bool isDefunct;
149         bool systemOnly;
150
151         const char **supclasses;
152         const char **subclasses;
153         const char **subclasses_direct;
154         const char **posssuperiors;
155         uint32_t subClassOf_id;
156         uint32_t *systemAuxiliaryClass_ids;
157         uint32_t *auxiliaryClass_ids;
158         uint32_t *systemMayContain_ids;
159         uint32_t *systemMustContain_ids;
160         uint32_t *possSuperiors_ids;
161         uint32_t *mustContain_ids;
162         uint32_t *mayContain_ids;
163         uint32_t *systemPossSuperiors_ids;
164
165         /* An ordered index showing how this subClass fits into the
166          * subClass tree.  that is, an objectclass that is not
167          * subClassOf anything is 0 (just in case), and top is 1, and
168          * subClasses of top are 2, subclasses of those classes are
169          * 3 */ 
170         uint32_t subClass_order;
171 };
172
173 /**
174  * data stored in schemaInfo attribute
175  */
176 struct dsdb_schema_info {
177         uint32_t        revision;
178         struct GUID     invocation_id;
179 };
180
181
182 struct dsdb_schema {
183         struct ldb_dn *base_dn;
184
185         struct dsdb_schema_prefixmap *prefixmap;
186
187         /* 
188          * the last element of the prefix mapping table isn't a oid,
189          * it starts with 0xFF and has 21 bytes and is maybe a schema
190          * version number
191          *
192          * this is the content of the schemaInfo attribute of the
193          * Schema-Partition head object.
194          */
195         const char *schema_info;
196
197         /* We can also tell the schema version from the USN on the partition */
198         uint64_t loaded_usn;
199
200         struct dsdb_attribute *attributes;
201         struct dsdb_class *classes;
202
203         /* lists of classes sorted by various attributes, for faster
204            access */
205         uint32_t num_classes;
206         struct dsdb_class **classes_by_lDAPDisplayName;
207         struct dsdb_class **classes_by_governsID_id;
208         struct dsdb_class **classes_by_governsID_oid;
209         struct dsdb_class **classes_by_cn;
210
211         /* lists of attributes sorted by various fields */
212         uint32_t num_attributes;
213         struct dsdb_attribute **attributes_by_lDAPDisplayName;
214         struct dsdb_attribute **attributes_by_attributeID_id;
215         struct dsdb_attribute **attributes_by_attributeID_oid;
216         struct dsdb_attribute **attributes_by_linkID;
217         uint32_t num_int_id_attr;
218         struct dsdb_attribute **attributes_by_msDS_IntId;
219
220         struct {
221                 bool we_are_master;
222                 struct ldb_dn *master_dn;
223         } fsmo;
224
225         /* Was this schema loaded from ldb (if so, then we will reload it when we detect a change in ldb) */
226         struct ldb_module *loaded_from_module;
227         struct dsdb_schema *(*refresh_fn)(struct ldb_module *module, struct dsdb_schema *schema, bool is_global_schema);
228         bool refresh_in_progress;
229         /* an 'opaque' sequence number that the reload function may also wish to use */
230         uint64_t reload_seq_number;
231
232         /* Should the syntax handlers in this case handle all incoming OIDs automatically, assigning them as an OID if no text name is known? */
233         bool relax_OID_conversions;
234 };
235
236 enum dsdb_attr_list_query {
237         DSDB_SCHEMA_ALL_MAY,
238         DSDB_SCHEMA_ALL_MUST,
239         DSDB_SCHEMA_SYS_MAY,
240         DSDB_SCHEMA_SYS_MUST,
241         DSDB_SCHEMA_MAY,
242         DSDB_SCHEMA_MUST,
243         DSDB_SCHEMA_ALL
244 };
245
246 enum dsdb_schema_convert_target {
247         TARGET_OPENLDAP,
248         TARGET_FEDORA_DS,
249         TARGET_AD_SCHEMA_SUBENTRY
250 };
251
252 #include "dsdb/schema/proto.h"
253
254 #endif /* _DSDB_SCHEMA_H */