samba-tool user readpasswords: avoid `assert` for validation
[samba.git] / source4 / dsdb / schema / schema.h
1 /* 
2    Unix SMB/CIFS Implementation.
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 enum dsdb_dn_format {
28         DSDB_NORMAL_DN,
29         DSDB_BINARY_DN,
30         DSDB_STRING_DN,
31         DSDB_INVALID_DN
32 };
33
34
35 struct dsdb_attribute;
36 struct dsdb_class;
37 struct dsdb_schema;
38 struct dsdb_dn;
39
40 struct dsdb_syntax_ctx {
41         struct ldb_context *ldb;
42         const struct dsdb_schema *schema;
43
44         /* set when converting objects under Schema NC */
45         bool is_schema_nc;
46
47         /* remote prefixMap to be used for drsuapi_to_ldb conversions */
48         const struct dsdb_schema_prefixmap *pfm_remote;
49 };
50
51
52 struct dsdb_syntax {
53         const char *name;
54         const char *ldap_oid;
55         uint32_t oMSyntax;
56         struct ldb_val oMObjectClass;
57         const char *attributeSyntax_oid;
58         const char *equality;
59         const char *substring;
60         const char *comment;
61         const char *ldb_syntax;
62
63         WERROR (*drsuapi_to_ldb)(const struct dsdb_syntax_ctx *ctx,
64                                  const struct dsdb_attribute *attr,
65                                  const struct drsuapi_DsReplicaAttribute *in,
66                                  TALLOC_CTX *mem_ctx,
67                                  struct ldb_message_element *out);
68         WERROR (*ldb_to_drsuapi)(const struct dsdb_syntax_ctx *ctx,
69                                  const struct dsdb_attribute *attr,
70                                  const struct ldb_message_element *in,
71                                  TALLOC_CTX *mem_ctx,
72                                  struct drsuapi_DsReplicaAttribute *out);
73         WERROR (*validate_ldb)(const struct dsdb_syntax_ctx *ctx,
74                                const struct dsdb_attribute *attr,
75                                const struct ldb_message_element *in);
76         bool auto_normalise;
77         bool userParameters; /* Indicates the syntax userParameters should be forced to */
78 };
79
80 struct dsdb_attribute {
81         struct dsdb_attribute *prev, *next;
82
83         const char *cn;
84         const char *lDAPDisplayName;
85         const char *attributeID_oid;
86         uint32_t attributeID_id;
87         struct GUID schemaIDGUID;
88         uint32_t mAPIID;
89         uint32_t msDS_IntId;
90
91         struct GUID attributeSecurityGUID;
92         struct GUID objectGUID;
93
94         uint32_t searchFlags;
95         uint32_t systemFlags;
96         bool isMemberOfPartialAttributeSet;
97         uint32_t linkID;
98
99         const char *attributeSyntax_oid;
100         uint32_t attributeSyntax_id;
101         uint32_t oMSyntax;
102         struct ldb_val oMObjectClass;
103
104         bool isSingleValued;
105         uint32_t *rangeLower;
106         uint32_t *rangeUpper;
107         bool extendedCharsAllowed;
108
109         uint32_t schemaFlagsEx;
110         struct ldb_val msDs_Schema_Extensions;
111
112         bool showInAdvancedViewOnly;
113         const char *adminDisplayName;
114         const char *adminDescription;
115         const char *classDisplayName;
116         bool isEphemeral;
117         bool isDefunct;
118         bool systemOnly;
119
120         bool one_way_link;
121         bool bl_maybe_invisible;
122         enum dsdb_dn_format dn_format;
123
124         /* internal stuff */
125         const struct dsdb_syntax *syntax;
126         const struct ldb_schema_attribute *ldb_schema_attribute;
127 };
128
129 struct dsdb_class {
130         struct dsdb_class *prev, *next;
131
132         const char *cn;
133         const char *lDAPDisplayName;
134         const char *governsID_oid;
135         uint32_t governsID_id;
136         struct GUID schemaIDGUID;
137         struct GUID objectGUID;
138
139         uint32_t objectClassCategory;
140         const char *rDNAttID;
141         const char *defaultObjectCategory;
142
143         const char *subClassOf;
144
145         const char **systemAuxiliaryClass;
146         const char **systemPossSuperiors;
147         const char **systemMustContain;
148         const char **systemMayContain;
149
150         const char **auxiliaryClass;
151         const char **possSuperiors;
152         const char **mustContain;
153         const char **mayContain;
154         const char **possibleInferiors;
155         const char **systemPossibleInferiors;
156
157         const char *defaultSecurityDescriptor;
158
159         uint32_t schemaFlagsEx;
160         uint32_t systemFlags;
161         struct ldb_val msDs_Schema_Extensions;
162
163         bool showInAdvancedViewOnly;
164         const char *adminDisplayName;
165         const char *adminDescription;
166         const char *classDisplayName;
167         bool defaultHidingValue;
168         bool isDefunct;
169         bool systemOnly;
170
171         uint32_t subClassOf_id;
172         uint32_t *systemAuxiliaryClass_ids;
173         uint32_t *auxiliaryClass_ids;
174         uint32_t *systemMayContain_ids;
175         uint32_t *systemMustContain_ids;
176         uint32_t *possSuperiors_ids;
177         uint32_t *mustContain_ids;
178         uint32_t *mayContain_ids;
179         uint32_t *systemPossSuperiors_ids;
180
181         /* An ordered index showing how this subClass fits into the
182          * subClass tree.  that is, an objectclass that is not
183          * subClassOf anything is 0 (just in case), and top is 1, and
184          * subClasses of top are 2, subclasses of those classes are
185          * 3 */ 
186         uint32_t subClass_order;
187
188         struct {
189                 const char **supclasses;
190                 const char **subclasses;
191                 const char **subclasses_direct;
192                 const char **posssuperiors;
193         } tmp;
194 };
195
196 enum schema_set_enum {
197         SCHEMA_MEMORY_ONLY = 0,
198         SCHEMA_WRITE = 1,
199         SCHEMA_COMPARE = 2,
200 };
201
202 /**
203  * data stored in schemaInfo attribute
204  */
205 struct dsdb_schema_info {
206         uint32_t        revision;
207         struct GUID     invocation_id;
208 };
209
210
211 struct dsdb_schema {
212         struct dsdb_schema_prefixmap *prefixmap;
213
214         /* 
215          * the last element of the prefix mapping table isn't a oid,
216          * it starts with 0xFF and has 21 bytes and is maybe a schema
217          * version number
218          *
219          * this is the content of the schemaInfo attribute of the
220          * Schema-Partition head object.
221          */
222         struct dsdb_schema_info *schema_info;
223
224         struct dsdb_attribute *attributes;
225         struct dsdb_class *classes;
226
227         struct dsdb_attribute **attributes_to_remove;
228         uint32_t attributes_to_remove_size;
229         struct dsdb_class **classes_to_remove;
230         uint32_t classes_to_remove_size;
231
232         /* lists of classes sorted by various attributes, for faster
233            access */
234         uint32_t num_classes;
235         struct dsdb_class **classes_by_lDAPDisplayName;
236         struct dsdb_class **classes_by_governsID_id;
237         struct dsdb_class **classes_by_governsID_oid;
238         struct dsdb_class **classes_by_cn;
239
240         /* lists of attributes sorted by various fields */
241         uint32_t num_attributes;
242         struct dsdb_attribute **attributes_by_lDAPDisplayName;
243         struct dsdb_attribute **attributes_by_attributeID_id;
244         struct dsdb_attribute **attributes_by_attributeID_oid;
245         struct dsdb_attribute **attributes_by_linkID;
246         struct dsdb_attribute **attributes_by_cn;
247         uint32_t num_int_id_attr;
248         struct dsdb_attribute **attributes_by_msDS_IntId;
249
250         struct {
251                 bool we_are_master;
252                 bool update_allowed;
253                 struct ldb_dn *master_dn;
254         } fsmo;
255
256         /* Was this schema loaded from ldb (if so, then we will reload it when we detect a change in ldb) */
257         bool refresh_in_progress;
258         time_t ts_last_change;
259         /* This 'opaque' is stored in the metadata and is used to check if the currently
260          * loaded schema needs a reload because another process has signaled that it has been
261          * requested to reload the schema (either due through DRS or via the schemaUpdateNow).
262          */
263         uint64_t metadata_usn;
264
265         /* Should the syntax handlers in this case handle all incoming OIDs automatically, assigning them as an OID if no text name is known? */
266         bool relax_OID_conversions;
267
268         /*
269          * we're currently trying to construct a working_schema
270          * in order to replicate the schema partition.
271          *
272          * We use this in order to avoid temporary failure DEBUG messages
273          */
274         bool resolving_in_progress;
275 };
276
277 #define DSDB_SCHEMA_COMMON_ATTRS                        \
278                 "objectClass",                          \
279                 "cn",                                   \
280                 "lDAPDisplayName",                      \
281                 "schemaIDGUID",                         \
282                 "objectGUID",                           \
283                 "systemFlags",                          \
284                 "schemaFlagsEx",                        \
285                 "msDs-Schema-Extensions",               \
286                 "showInAdvancedViewOnly",               \
287                 "adminDisplayName",                     \
288                 "adminDescription",                     \
289                 "isDefunct",                            \
290                 "systemOnly"
291
292 #define DSDB_SCHEMA_ATTR_ATTRS                          \
293                 "attributeID",                          \
294                 "msDS-IntId",                           \
295                 "mAPIID",                               \
296                 "attributeSecurityGUID",                \
297                 "searchFlags",                          \
298                 "isMemberOfPartialAttributeSet",        \
299                 "linkID",                               \
300                 "attributeSyntax",                      \
301                 "oMSyntax",                             \
302                 "oMObjectClass",                        \
303                 "isSingleValued",                       \
304                 "rangeLower",                           \
305                 "rangeUpper",                           \
306                 "extendedCharsAllowed",                 \
307                 "classDisplayName",                     \
308                 "isEphemeral"
309
310 #define DSDB_SCHEMA_CLASS_ATTRS                         \
311                 "governsID",                            \
312                 "objectClassCategory",                  \
313                 "rDNAttID",                             \
314                 "defaultObjectCategory",                \
315                 "subClassOf",                           \
316                 "systemAuxiliaryClass",                 \
317                 "auxiliaryClass",                       \
318                 "systemMustContain",                    \
319                 "systemMayContain",                     \
320                 "mustContain",                          \
321                 "mayContain",                           \
322                 "systemPossSuperiors",                  \
323                 "possSuperiors",                        \
324                 "defaultSecurityDescriptor",            \
325                 "classDisplayName",                     \
326                 "defaultHidingValue"
327
328 enum dsdb_attr_list_query {
329         DSDB_SCHEMA_ALL_MAY,
330         DSDB_SCHEMA_ALL_MUST,
331         DSDB_SCHEMA_SYS_MAY,
332         DSDB_SCHEMA_SYS_MUST,
333         DSDB_SCHEMA_MAY,
334         DSDB_SCHEMA_MUST,
335         DSDB_SCHEMA_ALL
336 };
337
338 enum dsdb_schema_convert_target {
339         TARGET_OPENLDAP,
340         TARGET_FEDORA_DS,
341         TARGET_AD_SCHEMA_SUBENTRY
342 };
343
344 struct ldb_module;
345
346 typedef struct dsdb_schema *(*dsdb_schema_refresh_fn)(struct ldb_module *module,
347                                                       struct tevent_context *ev,
348                                                       struct dsdb_schema *schema, bool is_global_schema);
349 #include "dsdb/schema/proto.h"
350
351 #endif /* _DSDB_SCHEMA_H */