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