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