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