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