]> git.sur5r.net Git - openldap/blob - servers/slapd/schema_prep.c
component cleanup
[openldap] / servers / slapd / schema_prep.c
1 /* schema_prep.c - load builtin schema */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2004 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/ctype.h>
22 #include <ac/string.h>
23 #include <ac/socket.h>
24
25 #include "slap.h"
26 #include "ldap_pvt.h"
27 #include "ldap_pvt_uc.h"
28
29 #define OCDEBUG 0
30
31 int schema_init_done = 0;
32
33 struct slap_internal_schema slap_schema;
34
35 static int
36 oidValidate(
37         Syntax *syntax,
38         struct berval *in )
39 {
40         struct berval val = *in;
41
42         if( val.bv_len == 0 ) {
43                 /* disallow empty strings */
44                 return LDAP_INVALID_SYNTAX;
45         }
46
47         if( DESC_LEADCHAR( val.bv_val[0] ) ) {
48                 val.bv_val++;
49                 val.bv_len--;
50                 if ( val.bv_len == 0 ) return LDAP_SUCCESS;
51
52                 while( DESC_CHAR( val.bv_val[0] ) ) {
53                         val.bv_val++;
54                         val.bv_len--;
55
56                         if ( val.bv_len == 0 ) return LDAP_SUCCESS;
57                 }
58
59         } else {
60                 int sep = 0;
61                 while( OID_LEADCHAR( val.bv_val[0] ) ) {
62                         val.bv_val++;
63                         val.bv_len--;
64
65                         if ( val.bv_val[-1] != '0' ) {
66                                 while ( OID_LEADCHAR( val.bv_val[0] )) {
67                                         val.bv_val++;
68                                         val.bv_len--;
69                                 }
70                         }
71
72                         if( val.bv_len == 0 ) {
73                                 if( sep == 0 ) break;
74                                 return LDAP_SUCCESS;
75                         }
76
77                         if( !OID_SEPARATOR( val.bv_val[0] )) break;
78
79                         sep++;
80                         val.bv_val++;
81                         val.bv_len--;
82                 }
83         }
84
85         return LDAP_INVALID_SYNTAX;
86 }
87
88
89 static int objectClassPretty(
90         struct slap_syntax *syntax,
91         struct berval * in,
92         struct berval * out,
93         void *ctx )
94 {
95         ObjectClass *oc;
96
97         if( oidValidate( NULL, in )) return LDAP_INVALID_SYNTAX;
98
99         oc = oc_bvfind( in );
100         if( oc == NULL ) return LDAP_INVALID_SYNTAX;
101
102         ber_dupbv_x( out, &oc->soc_cname, ctx );
103         return LDAP_SUCCESS;
104 }
105
106 static int
107 attributeTypeMatch(
108         int *matchp,
109         slap_mask_t flags,
110         Syntax *syntax,
111         MatchingRule *mr,
112         struct berval *value,
113         void *assertedValue )
114 {
115         struct berval *a = (struct berval *) assertedValue;
116         AttributeType *at = at_bvfind( value );
117         AttributeType *asserted = at_bvfind( a );
118
119         if( asserted == NULL ) {
120                 if( OID_LEADCHAR( *a->bv_val ) ) {
121                         /* OID form, return FALSE */
122                         *matchp = 1;
123                         return LDAP_SUCCESS;
124                 }
125
126                 /* desc form, return undefined */
127                 return LDAP_INVALID_SYNTAX;
128         }
129
130         if ( at == NULL ) {
131                 /* unrecognized stored value */
132                 return LDAP_INVALID_SYNTAX;
133         }
134
135         *matchp = ( asserted != at );
136         return LDAP_SUCCESS;
137 }
138
139 static int
140 matchingRuleMatch(
141         int *matchp,
142         slap_mask_t flags,
143         Syntax *syntax,
144         MatchingRule *mr,
145         struct berval *value,
146         void *assertedValue )
147 {
148         struct berval *a = (struct berval *) assertedValue;
149         MatchingRule *mrv = mr_bvfind( value );
150         MatchingRule *asserted = mr_bvfind( a );
151
152         if( asserted == NULL ) {
153                 if( OID_LEADCHAR( *a->bv_val ) ) {
154                         /* OID form, return FALSE */
155                         *matchp = 1;
156                         return LDAP_SUCCESS;
157                 }
158
159                 /* desc form, return undefined */
160                 return LDAP_INVALID_SYNTAX;
161         }
162
163         if ( mrv == NULL ) {
164                 /* unrecognized stored value */
165                 return LDAP_INVALID_SYNTAX;
166         }
167
168         *matchp = ( asserted != mrv );
169         return LDAP_SUCCESS;
170 }
171
172 static int
173 objectClassMatch(
174         int *matchp,
175         slap_mask_t flags,
176         Syntax *syntax,
177         MatchingRule *mr,
178         struct berval *value,
179         void *assertedValue )
180 {
181         struct berval *a = (struct berval *) assertedValue;
182         ObjectClass *oc = oc_bvfind( value );
183         ObjectClass *asserted = oc_bvfind( a );
184
185         if( asserted == NULL ) {
186                 if( OID_LEADCHAR( *a->bv_val ) ) {
187                         /* OID form, return FALSE */
188                         *matchp = 1;
189                         return LDAP_SUCCESS;
190                 }
191
192                 /* desc form, return undefined */
193                 return LDAP_INVALID_SYNTAX;
194         }
195
196         if ( oc == NULL ) {
197                 /* unrecognized stored value */
198                 return LDAP_INVALID_SYNTAX;
199         }
200
201         *matchp = ( asserted != oc );
202         return LDAP_SUCCESS;
203 }
204
205 static int
206 objectSubClassMatch(
207         int *matchp,
208         slap_mask_t flags,
209         Syntax *syntax,
210         MatchingRule *mr,
211         struct berval *value,
212         void *assertedValue )
213 {
214         struct berval *a = (struct berval *) assertedValue;
215         ObjectClass *oc = oc_bvfind( value );
216         ObjectClass *asserted = oc_bvfind( a );
217
218         if( asserted == NULL ) {
219                 if( OID_LEADCHAR( *a->bv_val ) ) {
220                         /* OID form, return FALSE */
221                         *matchp = 1;
222                         return LDAP_SUCCESS;
223                 }
224
225                 /* desc form, return undefined */
226                 return LDAP_INVALID_SYNTAX;
227         }
228
229         if ( oc == NULL ) {
230                 /* unrecognized stored value */
231                 return LDAP_INVALID_SYNTAX;
232         }
233
234         if( SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX( flags ) ) {
235                 *matchp = ( asserted != oc );
236         } else {
237                 *matchp = !is_object_subclass( asserted, oc );
238         }
239
240         return LDAP_SUCCESS;
241 }
242
243 static int objectSubClassIndexer( 
244         slap_mask_t use,
245         slap_mask_t mask,
246         struct slap_syntax *syntax,
247         struct slap_matching_rule *mr,
248         struct berval *prefix,
249         BerVarray values,
250         BerVarray *keysp,
251         void *ctx )
252 {
253         int rc, noc, i;
254         BerVarray ocvalues;
255         
256         for( noc=0; values[noc].bv_val != NULL; noc++ ) {
257                 /* just count em */;
258         }
259
260         /* over allocate */
261         ocvalues = slap_sl_malloc( sizeof( struct berval ) * (noc+16), ctx );
262
263         /* copy listed values (and termination) */
264         for( i=0; i<noc; i++ ) {
265                 ObjectClass *oc = oc_bvfind( &values[i] );
266                 if( oc ) {
267                         ocvalues[i] = oc->soc_cname;
268                 } else {
269                         ocvalues[i] = values[i];
270                 }
271         }
272
273         ocvalues[i].bv_val = NULL;
274         ocvalues[i].bv_len = 0;
275
276         /* expand values */
277         for( i=0; i<noc; i++ ) {
278                 int j;
279                 ObjectClass *oc = oc_bvfind( &ocvalues[i] );
280                 if( oc == NULL || oc->soc_sups == NULL ) continue;
281                 
282                 for( j=0; oc->soc_sups[j] != NULL; j++ ) {
283                         int found = 0;
284                         ObjectClass *sup = oc->soc_sups[j];
285                         int k;
286
287                         for( k=0; k<noc; k++ ) {
288                                 if( bvmatch( &ocvalues[k], &sup->soc_cname ) ) {
289                                         found++;
290                                         break;
291                                 }
292                         }
293
294                         if( !found ) {
295                                 ocvalues = slap_sl_realloc( ocvalues,
296                                         sizeof( struct berval ) * (noc+2), ctx );
297
298                                 assert( k == noc );
299
300                                 ocvalues[noc] = sup->soc_cname;
301
302                                 assert( ocvalues[noc].bv_val );
303                                 assert( ocvalues[noc].bv_len );
304
305                                 noc++;
306
307                                 ocvalues[noc].bv_len = 0;
308                                 ocvalues[noc].bv_val = NULL;
309                         }
310                 }
311         }
312
313         rc = octetStringIndexer( use, mask, syntax, mr,
314                 prefix, ocvalues, keysp, ctx );
315
316         slap_sl_free( ocvalues, ctx );
317         return rc;
318 }
319
320 #define objectSubClassFilter octetStringFilter
321
322 static ObjectClassSchemaCheckFN rootDseObjectClass;
323 static ObjectClassSchemaCheckFN aliasObjectClass;
324 static ObjectClassSchemaCheckFN referralObjectClass;
325 static ObjectClassSchemaCheckFN subentryObjectClass;
326 static ObjectClassSchemaCheckFN dynamicObjectClass;
327
328 static struct slap_schema_oc_map {
329         char *ssom_name;
330         char *ssom_defn;
331         ObjectClassSchemaCheckFN *ssom_check;
332         slap_mask_t ssom_flags;
333         size_t ssom_offset;
334 } oc_map[] = {
335         { "top", "( 2.5.6.0 NAME 'top' "
336                         "DESC 'top of the superclass chain' "
337                         "ABSTRACT MUST objectClass )",
338                 0, 0, offsetof(struct slap_internal_schema, si_oc_top) },
339         { "extensibleObject", "( 1.3.6.1.4.1.1466.101.120.111 "
340                         "NAME 'extensibleObject' "
341                         "DESC 'RFC2252: extensible object' "
342                         "SUP top AUXILIARY )",
343                 0, SLAP_OC_OPERATIONAL,
344                 offsetof(struct slap_internal_schema, si_oc_extensibleObject) },
345         { "alias", "( 2.5.6.1 NAME 'alias' "
346                         "DESC 'RFC2256: an alias' "
347                         "SUP top STRUCTURAL "
348                         "MUST aliasedObjectName )",
349                 aliasObjectClass, SLAP_OC_ALIAS|SLAP_OC_OPERATIONAL,
350                 offsetof(struct slap_internal_schema, si_oc_alias) },
351         { "referral", "( 2.16.840.1.113730.3.2.6 NAME 'referral' "
352                         "DESC 'namedref: named subordinate referral' "
353                         "SUP top STRUCTURAL MUST ref )",
354                 referralObjectClass, SLAP_OC_REFERRAL|SLAP_OC_OPERATIONAL,
355                 offsetof(struct slap_internal_schema, si_oc_referral) },
356         { "LDAProotDSE", "( 1.3.6.1.4.1.4203.1.4.1 "
357                         "NAME ( 'OpenLDAProotDSE' 'LDAProotDSE' ) "
358                         "DESC 'OpenLDAP Root DSE object' "
359                         "SUP top STRUCTURAL MAY cn )",
360                 rootDseObjectClass, SLAP_OC_OPERATIONAL,
361                 offsetof(struct slap_internal_schema, si_oc_rootdse) },
362         { "subentry", "( 2.5.17.0 NAME 'subentry' "
363                         "SUP top STRUCTURAL "
364                         "MUST ( cn $ subtreeSpecification ) )",
365                 subentryObjectClass, SLAP_OC_SUBENTRY|SLAP_OC_OPERATIONAL,
366                 offsetof(struct slap_internal_schema, si_oc_subentry) },
367         { "subschema", "( 2.5.20.1 NAME 'subschema' "
368                 "DESC 'RFC2252: controlling subschema (sub)entry' "
369                 "AUXILIARY "
370                 "MAY ( dITStructureRules $ nameForms $ ditContentRules $ "
371                         "objectClasses $ attributeTypes $ matchingRules $ "
372                         "matchingRuleUse ) )",
373                 subentryObjectClass, SLAP_OC_OPERATIONAL,
374                 offsetof(struct slap_internal_schema, si_oc_subschema) },
375 #ifdef LDAP_DEVEL
376         { "collectiveAttributeSubentry", "( 2.5.17.2 "
377                         "NAME 'collectiveAttributeSubentry' "
378                         "AUXILIARY )",
379                 subentryObjectClass,
380                 SLAP_OC_COLLECTIVEATTRIBUTESUBENTRY|SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
381                 offsetof(struct slap_internal_schema, si_oc_collectiveAttributeSubentry) },
382         { "dynamicObject", "( 1.3.6.1.4.1.1466.101.119.2 "
383                         "NAME 'dynamicObject' "
384                         "DESC 'RFC2589: Dynamic Object' "
385                         "SUP top AUXILIARY )",
386                 dynamicObjectClass, SLAP_OC_DYNAMICOBJECT,
387                 offsetof(struct slap_internal_schema, si_oc_dynamicObject) },
388 #endif
389         { "glue", "( 1.3.6.1.4.1.4203.666.3.4 "
390                         "NAME 'glue' "
391                         "DESC 'Glue Entry' "
392                         "SUP top STRUCTURAL )",
393                 0, SLAP_OC_GLUE|SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
394                 offsetof(struct slap_internal_schema, si_oc_glue) },
395         { "syncConsumerSubentry", "( 1.3.6.1.4.1.4203.666.3.5 "
396                         "NAME 'syncConsumerSubentry' "
397                         "DESC 'Persistent Info for SyncRepl Consumer' "
398                         "AUXILIARY "
399                         "MAY syncreplCookie )",
400                 0, SLAP_OC_SYNCCONSUMERSUBENTRY|SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
401                 offsetof(struct slap_internal_schema, si_oc_syncConsumerSubentry) },
402         { "syncProviderSubentry", "( 1.3.6.1.4.1.4203.666.3.6 "
403                         "NAME 'syncProviderSubentry' "
404                         "DESC 'Persistent Info for SyncRepl Producer' "
405                         "AUXILIARY "
406                         "MAY contextCSN )",
407                 0, SLAP_OC_SYNCPROVIDERSUBENTRY|SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
408                 offsetof(struct slap_internal_schema, si_oc_syncProviderSubentry) },
409
410         { NULL, NULL, NULL, 0, 0 }
411 };
412
413 static AttributeTypeSchemaCheckFN rootDseAttribute;
414 static AttributeTypeSchemaCheckFN aliasAttribute;
415 static AttributeTypeSchemaCheckFN referralAttribute;
416 static AttributeTypeSchemaCheckFN subentryAttribute;
417 static AttributeTypeSchemaCheckFN administrativeRoleAttribute;
418 static AttributeTypeSchemaCheckFN dynamicAttribute;
419
420 static struct slap_schema_ad_map {
421         char *ssam_name;
422         char *ssam_defn;
423         AttributeTypeSchemaCheckFN *ssam_check;
424         slap_mask_t ssam_flags;
425         slap_syntax_validate_func *ssam_syn_validate;
426         slap_syntax_transform_func *ssam_syn_pretty;
427         slap_mr_convert_func *ssam_mr_convert;
428         slap_mr_normalize_func *ssam_mr_normalize;
429         slap_mr_match_func *ssam_mr_match;
430         slap_mr_indexer_func *ssam_mr_indexer;
431         slap_mr_filter_func *ssam_mr_filter;
432         size_t ssam_offset;
433 } ad_map[] = {
434         { "objectClass", "( 2.5.4.0 NAME 'objectClass' "
435                         "DESC 'RFC2256: object classes of the entity' "
436                         "EQUALITY objectIdentifierMatch "
437                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
438                 NULL, SLAP_AT_FINAL,
439                 oidValidate, objectClassPretty,
440                 NULL, NULL, objectSubClassMatch,
441                         objectSubClassIndexer, objectSubClassFilter,
442                 offsetof(struct slap_internal_schema, si_ad_objectClass) },
443
444         /* user entry operational attributes */
445         { "structuralObjectClass", "( 2.5.21.9 NAME 'structuralObjectClass' "
446                         "DESC 'X.500(93): structural object class of entry' "
447                         "EQUALITY objectIdentifierMatch "
448                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
449                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
450                 NULL, 0,
451                 oidValidate, objectClassPretty,
452                 NULL, NULL, objectSubClassMatch,
453                         objectSubClassIndexer, objectSubClassFilter,
454                 offsetof(struct slap_internal_schema, si_ad_structuralObjectClass) },
455         { "createTimestamp", "( 2.5.18.1 NAME 'createTimestamp' "
456                         "DESC 'RFC2252: time which object was created' "
457                         "EQUALITY generalizedTimeMatch "
458                         "ORDERING generalizedTimeOrderingMatch "
459                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
460                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
461                 NULL, 0,
462                 NULL, NULL,
463                 NULL, NULL, NULL, NULL, NULL,
464                 offsetof(struct slap_internal_schema, si_ad_createTimestamp) },
465         { "modifyTimestamp", "( 2.5.18.2 NAME 'modifyTimestamp' "
466                         "DESC 'RFC2252: time which object was last modified' "
467                         "EQUALITY generalizedTimeMatch "
468                         "ORDERING generalizedTimeOrderingMatch "
469                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
470                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
471                 NULL, 0,
472                 NULL, NULL,
473                 NULL, NULL, NULL, NULL, NULL,
474                 offsetof(struct slap_internal_schema, si_ad_modifyTimestamp) },
475         { "creatorsName", "( 2.5.18.3 NAME 'creatorsName' "
476                         "DESC 'RFC2252: name of creator' "
477                         "EQUALITY distinguishedNameMatch "
478                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
479                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
480                 NULL, 0,
481                 NULL, NULL,
482                 NULL, NULL, NULL, NULL, NULL,
483                 offsetof(struct slap_internal_schema, si_ad_creatorsName) },
484         { "modifiersName", "( 2.5.18.4 NAME 'modifiersName' "
485                         "DESC 'RFC2252: name of last modifier' "
486                         "EQUALITY distinguishedNameMatch "
487                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
488                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
489                 NULL, 0,
490                 NULL, NULL,
491                 NULL, NULL, NULL, NULL, NULL,
492                 offsetof(struct slap_internal_schema, si_ad_modifiersName) },
493         { "hasSubordinates", "( 2.5.18.9 NAME 'hasSubordinates' "
494                         "DESC 'X.501: entry has children' "
495                         "EQUALITY booleanMatch "
496                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
497                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
498                 NULL, SLAP_AT_DYNAMIC,
499                 NULL, NULL,
500                 NULL, NULL, NULL, NULL, NULL,
501                 offsetof(struct slap_internal_schema, si_ad_hasSubordinates) },
502         { "subschemaSubentry", "( 2.5.18.10 NAME 'subschemaSubentry' "
503                         "DESC 'RFC2252: name of controlling subschema entry' "
504                         "EQUALITY distinguishedNameMatch "
505                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 SINGLE-VALUE "
506                         "NO-USER-MODIFICATION USAGE directoryOperation )",
507                 NULL, SLAP_AT_DYNAMIC,
508                 NULL, NULL,
509                 NULL, NULL, NULL, NULL, NULL,
510                 offsetof(struct slap_internal_schema, si_ad_subschemaSubentry) },
511 #ifdef LDAP_DEVEL
512         { "collectiveAttributeSubentries", "( 2.5.18.12 "
513                         "NAME 'collectiveAttributeSubentries' "
514                         "EQUALITY distinguishedNameMatch "
515                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
516                         "NO-USER-MODIFICATION USAGE directoryOperation )",
517                 NULL, SLAP_AT_HIDE,
518                 NULL, NULL,
519                 NULL, NULL, NULL, NULL, NULL,
520                 offsetof(struct slap_internal_schema, si_ad_collectiveSubentries) },
521         { "collectiveExclusions", "( 2.5.18.7 NAME 'collectiveExclusions' "
522                         "EQUALITY objectIdentifierMatch "
523                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
524                         "USAGE directoryOperation )",
525                 NULL, SLAP_AT_HIDE,
526                 NULL, NULL,
527                 NULL, NULL, NULL, NULL, NULL,
528                 offsetof(struct slap_internal_schema, si_ad_collectiveExclusions) },
529 #endif
530
531         { "entryDN", "( 1.3.6.1.4.1.4203.666.1.33 NAME 'entryDN' "   
532                         "DESC 'DN of the entry' "
533                         "EQUALITY distinguishedNameMatch "
534                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
535                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
536                 NULL, SLAP_AT_HIDE|SLAP_AT_DYNAMIC,
537                 NULL, NULL,
538                 NULL, NULL, NULL, NULL, NULL,
539                 offsetof(struct slap_internal_schema, si_ad_entryDN) },
540         { "entryUUID", "( 1.3.6.1.4.1.4203.666.1.6 NAME 'entryUUID' "   
541                         "DESC 'UUID of the entry' "
542                         "EQUALITY UUIDMatch "
543                         "ORDERING UUIDOrderingMatch "
544                         "SYNTAX 1.3.6.1.4.1.4203.666.2.6 "
545                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
546                 NULL, SLAP_AT_HIDE,
547                 NULL, NULL,
548                 NULL, NULL, NULL, NULL, NULL,
549                 offsetof(struct slap_internal_schema, si_ad_entryUUID) },
550         { "entryCSN", "( 1.3.6.1.4.1.4203.666.1.7 NAME 'entryCSN' "
551                         "DESC 'change sequence number of the entry content' "
552                         "EQUALITY octetStringMatch "
553                         "ORDERING octetStringOrderingMatch "
554                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
555                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
556                 NULL, SLAP_AT_HIDE,
557                 NULL, NULL,
558                 NULL, NULL, NULL, NULL, NULL,
559                 offsetof(struct slap_internal_schema, si_ad_entryCSN) },
560         { "namingCSN", "( 1.3.6.1.4.1.4203.666.1.13 NAME 'namingCSN' "
561                         "DESC 'change sequence number of the entry naming (RDN)' "
562                         "EQUALITY octetStringMatch "
563                         "ORDERING octetStringOrderingMatch "
564                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
565                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
566                 NULL, SLAP_AT_HIDE,
567                 NULL, NULL,
568                 NULL, NULL, NULL, NULL, NULL,
569                 offsetof(struct slap_internal_schema, si_ad_namingCSN) },
570
571 #if 0
572         { "superiorUUID", "( 1.3.6.1.4.1.4203.666.1.11 NAME 'superiorUUID' "   
573                         "DESC 'UUID of the superior entry' "
574                         "EQUALITY octetStringMatch "
575                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
576                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
577                 NULL, SLAP_AT_HIDE,
578                 NULL, NULL,
579                 NULL, NULL, NULL, NULL, NULL,
580                 offsetof(struct slap_internal_schema, si_ad_superiorUUID) },
581 #endif
582
583         { "syncreplCookie", "( 1.3.6.1.4.1.4203.666.1.23 "
584                         "NAME 'syncreplCookie' "
585                         "DESC 'syncrepl Cookie for shadow copy' "
586                         "EQUALITY octetStringMatch "
587                         "ORDERING octetStringOrderingMatch "
588                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 "
589                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE dSAOperation )",
590                 NULL, SLAP_AT_HIDE,
591                 NULL, NULL,
592                 NULL, NULL, NULL, NULL, NULL,
593                 offsetof(struct slap_internal_schema, si_ad_syncreplCookie) },
594
595         { "contextCSN", "( 1.3.6.1.4.1.4203.666.1.25 "
596                         "NAME 'contextCSN' "
597                         "DESC 'the largest committed CSN of a context' "
598                         "EQUALITY octetStringMatch "
599                         "ORDERING octetStringOrderingMatch "
600                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 "
601                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE dSAOperation )",
602                 NULL, SLAP_AT_HIDE,
603                 NULL, NULL,
604                 NULL, NULL, NULL, NULL, NULL,
605                 offsetof(struct slap_internal_schema, si_ad_contextCSN) },
606
607 #ifdef LDAP_DEVEL
608         { "syncTimestamp", "( 1.3.6.1.4.1.4203.666.1.26 NAME 'syncTimestamp' "
609                         "DESC 'Time which object was replicated' "
610                         "EQUALITY generalizedTimeMatch "
611                         "ORDERING generalizedTimeOrderingMatch "
612                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
613                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE dSAOperation )",
614                 NULL, 0,
615                 NULL, NULL,
616                 NULL, NULL, NULL, NULL, NULL,
617                 offsetof(struct slap_internal_schema, si_ad_syncTimestamp) },
618 #endif
619
620         /* root DSE attributes */
621         { "altServer", "( 1.3.6.1.4.1.1466.101.120.6 NAME 'altServer' "
622                         "DESC 'RFC2252: alternative servers' "
623                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 USAGE dSAOperation )",
624                 rootDseAttribute, 0,
625                 NULL, NULL,
626                 NULL, NULL, NULL, NULL, NULL,
627                 offsetof(struct slap_internal_schema, si_ad_altServer) },
628         { "namingContexts", "( 1.3.6.1.4.1.1466.101.120.5 "
629                         "NAME 'namingContexts' "
630                         "DESC 'RFC2252: naming contexts' "
631                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 USAGE dSAOperation )",
632                 rootDseAttribute, 0,
633                 NULL, NULL,
634                 NULL, NULL, NULL, NULL, NULL,
635                 offsetof(struct slap_internal_schema, si_ad_namingContexts) },
636         { "supportedControl", "( 1.3.6.1.4.1.1466.101.120.13 "
637                         "NAME 'supportedControl' "
638                         "DESC 'RFC2252: supported controls' "
639                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 USAGE dSAOperation )",
640                 rootDseAttribute, 0,
641                 NULL, NULL,
642                 NULL, NULL, NULL, NULL, NULL,
643                 offsetof(struct slap_internal_schema, si_ad_supportedControl) },
644         { "supportedExtension", "( 1.3.6.1.4.1.1466.101.120.7 "
645                         "NAME 'supportedExtension' "
646                         "DESC 'RFC2252: supported extended operations' "
647                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 USAGE dSAOperation )",
648                 rootDseAttribute, 0,
649                 NULL, NULL,
650                 NULL, NULL, NULL, NULL, NULL,
651                 offsetof(struct slap_internal_schema, si_ad_supportedExtension) },
652         { "supportedLDAPVersion", "( 1.3.6.1.4.1.1466.101.120.15 "
653                         "NAME 'supportedLDAPVersion' "
654                         "DESC 'RFC2252: supported LDAP versions' "
655                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 USAGE dSAOperation )",
656                 rootDseAttribute, 0,
657                 NULL, NULL,
658                 NULL, NULL, NULL, NULL, NULL,
659                 offsetof(struct slap_internal_schema, si_ad_supportedLDAPVersion) },
660         { "supportedSASLMechanisms", "( 1.3.6.1.4.1.1466.101.120.14 "
661                         "NAME 'supportedSASLMechanisms' "
662                         "DESC 'RFC2252: supported SASL mechanisms'"
663                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 USAGE dSAOperation )",
664                 rootDseAttribute, 0,
665                 NULL, NULL,
666                 NULL, NULL, NULL, NULL, NULL,
667                 offsetof(struct slap_internal_schema, si_ad_supportedSASLMechanisms) },
668         { "supportedFeatures", "( 1.3.6.1.4.1.4203.1.3.5 "
669                         "NAME 'supportedFeatures' "
670                         "DESC 'features supported by the server' "
671                         "EQUALITY objectIdentifierMatch "
672                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
673                         "USAGE dSAOperation )",
674                 rootDseAttribute, 0,
675                 NULL, NULL,
676                 NULL, NULL, NULL, NULL, NULL,
677                 offsetof(struct slap_internal_schema, si_ad_supportedFeatures) },
678         { "monitorContext", "( 1.3.6.1.4.1.4203.666.1.10 "
679                         "NAME 'monitorContext' "
680                         "DESC 'monitor context' "
681                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
682                         "SINGLE-VALUE NO-USER-MODIFICATION "
683                         "USAGE dSAOperation )",
684                 rootDseAttribute, SLAP_AT_HIDE,
685                 NULL, NULL,
686                 NULL, NULL, NULL, NULL, NULL,
687                 offsetof(struct slap_internal_schema, si_ad_monitorContext) },
688         { "vendorName", "( 1.3.6.1.1.4 NAME 'vendorName' "
689                         "DESC 'RFC3045: name of implementation vendor' "
690                         "EQUALITY caseExactMatch "
691                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
692                         "SINGLE-VALUE NO-USER-MODIFICATION "
693                         "USAGE dSAOperation )",
694                 rootDseAttribute, 0,
695                 NULL, NULL,
696                 NULL, NULL, NULL, NULL, NULL,
697                 offsetof(struct slap_internal_schema, si_ad_vendorName) },
698         { "vendorVersion", "( 1.3.6.1.1.5 NAME 'vendorVersion' "
699                         "DESC 'RFC3045: version of implementation' "
700                         "EQUALITY caseExactMatch "
701                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
702                         "SINGLE-VALUE NO-USER-MODIFICATION "
703                         "USAGE dSAOperation )",
704                 rootDseAttribute, 0,
705                 NULL, NULL,
706                 NULL, NULL, NULL, NULL, NULL,
707                 offsetof(struct slap_internal_schema, si_ad_vendorVersion) },
708
709         /* subentry attributes */
710         { "administrativeRole", "( 2.5.18.5 NAME 'administrativeRole' "
711                         "EQUALITY objectIdentifierMatch "
712                         "USAGE directoryOperation "
713                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
714                 administrativeRoleAttribute, SLAP_AT_HIDE,
715                 NULL, NULL,
716                 NULL, NULL, NULL, NULL, NULL,
717                 offsetof(struct slap_internal_schema, si_ad_administrativeRole) },
718         { "subtreeSpecification", "( 2.5.18.6 NAME 'subtreeSpecification' "
719                         "SINGLE-VALUE "
720                         "USAGE directoryOperation "
721                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.45 )",
722                 subentryAttribute, SLAP_AT_HIDE,
723                 NULL, NULL,
724                 NULL, NULL, NULL, NULL, NULL,
725                 offsetof(struct slap_internal_schema, si_ad_subtreeSpecification) },
726
727         /* subschema subentry attributes */
728         { "ditStructureRules", "( 2.5.21.1 NAME 'dITStructureRules' "
729                         "DESC 'RFC2252: DIT structure rules' "
730                         "EQUALITY integerFirstComponentMatch "
731                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.17 "
732                         "USAGE directoryOperation ) ",
733                 subentryAttribute, SLAP_AT_HIDE,
734                 NULL, NULL,
735                 NULL, NULL, NULL, NULL, NULL,
736                 offsetof(struct slap_internal_schema, si_ad_ditStructureRules) },
737         { "ditContentRules", "( 2.5.21.2 NAME 'dITContentRules' "
738                         "DESC 'RFC2252: DIT content rules' "
739                         "EQUALITY objectIdentifierFirstComponentMatch "
740                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.16 USAGE directoryOperation )",
741                 subentryAttribute, SLAP_AT_HIDE,
742                 oidValidate, NULL,
743                 NULL, NULL, objectClassMatch, NULL, NULL,
744                 offsetof(struct slap_internal_schema, si_ad_ditContentRules) },
745         { "matchingRules", "( 2.5.21.4 NAME 'matchingRules' "
746                         "DESC 'RFC2252: matching rules' "
747                         "EQUALITY objectIdentifierFirstComponentMatch "
748                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.30 USAGE directoryOperation )",
749                 subentryAttribute, 0,
750                 oidValidate, NULL,
751                 NULL, NULL, matchingRuleMatch, NULL, NULL,
752                 offsetof(struct slap_internal_schema, si_ad_matchingRules) },
753         { "attributeTypes", "( 2.5.21.5 NAME 'attributeTypes' "
754                         "DESC 'RFC2252: attribute types' "
755                         "EQUALITY objectIdentifierFirstComponentMatch "
756                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.3 USAGE directoryOperation )",
757                 subentryAttribute, 0,
758                 oidValidate, NULL,
759                 NULL, NULL, attributeTypeMatch, NULL, NULL,
760                 offsetof(struct slap_internal_schema, si_ad_attributeTypes) },
761         { "objectClasses", "( 2.5.21.6 NAME 'objectClasses' "
762                         "DESC 'RFC2252: object classes' "
763                         "EQUALITY objectIdentifierFirstComponentMatch "
764                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.37 USAGE directoryOperation )",
765                 subentryAttribute, 0,
766                 oidValidate, NULL,
767                 NULL, NULL, objectClassMatch, NULL, NULL,
768                 offsetof(struct slap_internal_schema, si_ad_objectClasses) },
769         { "nameForms", "( 2.5.21.7 NAME 'nameForms' "
770                         "DESC 'RFC2252: name forms ' "
771                         "EQUALITY objectIdentifierFirstComponentMatch "
772                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.35 USAGE directoryOperation )",
773                 subentryAttribute, SLAP_AT_HIDE,
774                 NULL, NULL,
775                 NULL, NULL, NULL, NULL, NULL,
776                 offsetof(struct slap_internal_schema, si_ad_nameForms) },
777         { "matchingRuleUse", "( 2.5.21.8 NAME 'matchingRuleUse' "
778                         "DESC 'RFC2252: matching rule uses' "
779                         "EQUALITY objectIdentifierFirstComponentMatch "
780                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.31 USAGE directoryOperation )",
781                 subentryAttribute, 0,
782                 oidValidate, NULL,
783                 NULL, NULL, matchingRuleMatch, NULL, NULL,
784                 offsetof(struct slap_internal_schema, si_ad_matchingRuleUse) },
785
786         { "ldapSyntaxes", "( 1.3.6.1.4.1.1466.101.120.16 NAME 'ldapSyntaxes' "
787                         "DESC 'RFC2252: LDAP syntaxes' "
788                         "EQUALITY objectIdentifierFirstComponentMatch "
789                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.54 USAGE directoryOperation )",
790                 subentryAttribute, 0,
791                 NULL, NULL,
792                 NULL, NULL, NULL, NULL, NULL,
793                 offsetof(struct slap_internal_schema, si_ad_ldapSyntaxes) },
794
795         /* knowledge information */
796         { "aliasedObjectName", "( 2.5.4.1 "
797                         "NAME ( 'aliasedObjectName' 'aliasedEntryName' ) "
798                         "DESC 'RFC2256: name of aliased object' "
799                         "EQUALITY distinguishedNameMatch "
800                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 SINGLE-VALUE )",
801                 aliasAttribute, SLAP_AT_FINAL,
802                 NULL, NULL,
803                 NULL, NULL, NULL, NULL, NULL,
804                 offsetof(struct slap_internal_schema, si_ad_aliasedObjectName) },
805         { "ref", "( 2.16.840.1.113730.3.1.34 NAME 'ref' "
806                         "DESC 'namedref: subordinate referral URL' "
807                         "EQUALITY caseExactMatch "
808                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
809                         "USAGE distributedOperation )",
810                 referralAttribute, 0,
811                 NULL, NULL,
812                 NULL, NULL, NULL, NULL, NULL,
813                 offsetof(struct slap_internal_schema, si_ad_ref) },
814
815         /* access control internals */
816         { "entry", "( 1.3.6.1.4.1.4203.1.3.1 "
817                         "NAME 'entry' "
818                         "DESC 'OpenLDAP ACL entry pseudo-attribute' "
819                         "SYNTAX 1.3.6.1.4.1.4203.1.1.1 "
820                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE dSAOperation )",
821                 NULL, SLAP_AT_HIDE,
822                 NULL, NULL,
823                 NULL, NULL, NULL, NULL, NULL,
824                 offsetof(struct slap_internal_schema, si_ad_entry) },
825         { "children", "( 1.3.6.1.4.1.4203.1.3.2 "
826                         "NAME 'children' "
827                         "DESC 'OpenLDAP ACL children pseudo-attribute' "
828                         "SYNTAX 1.3.6.1.4.1.4203.1.1.1 "
829                         "SINGLE-VALUE NO-USER-MODIFICATION USAGE dSAOperation )",
830                 NULL, SLAP_AT_HIDE,
831                 NULL, NULL,
832                 NULL, NULL, NULL, NULL, NULL,
833                 offsetof(struct slap_internal_schema, si_ad_children) },
834         { "authzTo", "( 1.3.6.1.4.1.4203.666.1.8 "
835                         "NAME ( 'authzTo' 'saslAuthzTo' ) "
836                         "DESC 'proxy authorization targets' "
837                         "EQUALITY caseExactMatch "
838                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
839                         "USAGE distributedOperation )",
840                 NULL, SLAP_AT_HIDE,
841                 NULL, NULL,
842                 NULL, NULL, NULL, NULL, NULL,
843                 offsetof(struct slap_internal_schema, si_ad_saslAuthzTo) },
844         { "authzFrom", "( 1.3.6.1.4.1.4203.666.1.9 "
845                         "NAME ( 'authzFrom' 'saslAuthzFrom' ) "
846                         "DESC 'proxy authorization sources' "
847                         "EQUALITY caseExactMatch "
848                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
849                         "USAGE distributedOperation )",
850                 NULL, SLAP_AT_HIDE,
851                 NULL, NULL,
852                 NULL, NULL, NULL, NULL, NULL,
853                 offsetof(struct slap_internal_schema, si_ad_saslAuthzFrom) },
854 #ifdef SLAPD_ACI_ENABLED
855         { "OpenLDAPaci", "( 1.3.6.1.4.1.4203.666.1.5 "
856                         "NAME 'OpenLDAPaci' "
857                         "DESC 'OpenLDAP access control information (experimental)' "
858                         "EQUALITY OpenLDAPaciMatch "
859                         "SYNTAX 1.3.6.1.4.1.4203.666.2.1 "
860                         "USAGE directoryOperation )",
861                 NULL, SLAP_AT_HIDE,
862                 NULL, NULL,
863                 NULL, NULL, NULL, NULL, NULL,
864                 offsetof(struct slap_internal_schema, si_ad_aci) },
865 #endif
866
867 #ifdef LDAP_DEVEL
868         { "entryTtl", "( 1.3.6.1.4.1.1466.101.119.3 NAME 'entryTtl' "
869                         "DESC 'RFC2589: entry time-to-live' "
870                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE "
871                         "NO-USER-MODIFICATION USAGE dSAOperation )",
872                 dynamicAttribute, 0,
873                 NULL, NULL,
874                 NULL, NULL, NULL, NULL, NULL,
875                 offsetof(struct slap_internal_schema, si_ad_entryTtl) },
876         { "dynamicSubtrees", "( 1.3.6.1.4.1.1466.101.119.4 "
877                         "NAME 'dynamicSubtrees' "
878                         "DESC 'RFC2589: dynamic subtrees' "
879                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 NO-USER-MODIFICATION "
880                         "USAGE dSAOperation )",
881                 rootDseAttribute, 0,
882                 NULL, NULL,
883                 NULL, NULL, NULL, NULL, NULL,
884                 offsetof(struct slap_internal_schema, si_ad_dynamicSubtrees) },
885 #endif
886
887         /* userApplication attributes (which system schema depends upon) */
888         { "distinguishedName", "( 2.5.4.49 NAME 'distinguishedName' "
889                         "DESC 'RFC2256: common supertype of DN attributes' "
890                         "EQUALITY distinguishedNameMatch "
891                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
892                 NULL, SLAP_AT_ABSTRACT,
893                 NULL, NULL,
894                 NULL, NULL, NULL, NULL, NULL,
895                 offsetof(struct slap_internal_schema, si_ad_distinguishedName) },
896         { "name", "( 2.5.4.41 NAME 'name' "
897                         "DESC 'RFC2256: common supertype of name attributes' "
898                         "EQUALITY caseIgnoreMatch "
899                         "SUBSTR caseIgnoreSubstringsMatch "
900                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )",
901                 NULL, SLAP_AT_ABSTRACT,
902                 NULL, NULL,
903                 NULL, NULL, NULL, NULL, NULL,
904                 offsetof(struct slap_internal_schema, si_ad_name) },
905         { "cn", "( 2.5.4.3 NAME ( 'cn' 'commonName' ) "
906                         "DESC 'RFC2256: common name(s) for which the entity is known by' "
907                         "SUP name )",
908                 NULL, 0,
909                 NULL, NULL,
910                 NULL, NULL, NULL, NULL, NULL,
911                 offsetof(struct slap_internal_schema, si_ad_cn) },
912         { "userPassword", "( 2.5.4.35 NAME 'userPassword' "
913                         "DESC 'RFC2256/2307: password of user' "
914                         "EQUALITY octetStringMatch "
915                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{128} )",
916                 NULL, 0,
917                 NULL, NULL,
918                 NULL, NULL, NULL, NULL, NULL,
919                 offsetof(struct slap_internal_schema, si_ad_userPassword) },
920
921         { "labeledURI", "(  1.3.6.1.4.1.250.1.57 NAME 'labeledURI' "
922                         "DESC 'RFC2079: Uniform Resource Identifier with optional label' "
923                         "EQUALITY caseExactMatch "
924                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
925                 NULL, 0,
926                 NULL, NULL,
927                 NULL, NULL, NULL, NULL, NULL,
928                 offsetof(struct slap_internal_schema, si_ad_labeledURI) },
929
930 #ifdef SLAPD_AUTHPASSWD
931         { "authPassword", "( 1.3.6.1.4.1.4203.1.3.4 "
932                         "NAME 'authPassword' "
933                         "DESC 'RFC3112: authentication password attribute' "
934                         "EQUALITY 1.3.6.1.4.1.4203.1.2.2 "
935                         "SYNTAX 1.3.6.1.4.1.4203.1.1.2 )",
936                 NULL, 0,
937                 NULL, NULL,
938                 NULL, NULL, NULL, NULL, NULL,
939                 offsetof(struct slap_internal_schema, si_ad_authPassword) },
940         { "supportedAuthPasswordSchemes", "( 1.3.6.1.4.1.4203.1.3.3 "
941                         "NAME 'supportedAuthPasswordSchemes' "
942                         "DESC 'RFC3112: supported authPassword schemes' "
943                         "EQUALITY caseExactIA5Match "
944                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{32} "
945                         "USAGE dSAOperation )",
946                 subschemaAttribute, 0,
947                 NULL, NULL,
948                 NULL, NULL, NULL, NULL, NULL,
949                 offsetof(struct slap_internal_schema, si_ad_authPassword) },
950 #endif
951 #ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
952         { "krbName", "( 1.3.6.1.4.1.250.1.32 "
953                         "NAME ( 'krbName' 'kerberosName' ) "
954                         "DESC 'Kerberos principal associated with object' "
955                         "EQUALITY caseIgnoreIA5Match "
956                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 "
957                         "SINGLE-VALUE )",
958                 NULL, 0,
959                 NULL, NULL,
960                 NULL, NULL, NULL, NULL, NULL,
961                 offsetof(struct slap_internal_schema, si_ad_krbName) },
962 #endif
963         { NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 }
964 };
965
966 static AttributeType slap_at_undefined = {
967         { "1.1.1", NULL, NULL, 1, NULL,
968                 NULL, NULL, NULL, NULL,
969                 0, 0, 0, 1, 3, NULL }, /* LDAPAttributeType */
970         { sizeof("UNDEFINED")-1, "UNDEFINED" }, /* cname */
971         NULL, /* sup */
972         NULL, /* subtypes */
973         NULL, NULL, NULL, NULL, /* matching rules routines */
974         NULL, /* syntax (this may need to be defined) */
975         (AttributeTypeSchemaCheckFN *) 0, /* schema check function */
976         SLAP_AT_ABSTRACT|SLAP_AT_FINAL, /* mask */
977         { NULL }, /* next */
978         NULL /* attribute description */
979         /* mutex (don't know how to initialize it :) */
980 };
981
982 static struct slap_schema_mr_map {
983         char *ssmm_name;
984         size_t ssmm_offset;
985 } mr_map[] = {
986         { "caseExactIA5Match",
987                 offsetof(struct slap_internal_schema, si_mr_caseExactIA5Match) },
988         { "caseExactMatch",
989                 offsetof(struct slap_internal_schema, si_mr_caseExactMatch) },
990         { "caseExactSubstringsMatch",
991                 offsetof(struct slap_internal_schema, si_mr_caseExactSubstringsMatch) },
992         { "distinguishedNameMatch",
993                 offsetof(struct slap_internal_schema, si_mr_distinguishedNameMatch) },
994         { "dnSubtreeMatch",
995                 offsetof(struct slap_internal_schema, si_mr_dnSubtreeMatch) },
996         { "dnOneLevelMatch",
997                 offsetof(struct slap_internal_schema, si_mr_dnOneLevelMatch) },
998         { "dnSubordinateMatch",
999                 offsetof(struct slap_internal_schema, si_mr_dnSubordinateMatch) },
1000         { "dnSuperiorMatch",
1001                 offsetof(struct slap_internal_schema, si_mr_dnSuperiorMatch) },
1002         { "integerMatch",
1003                 offsetof(struct slap_internal_schema, si_mr_integerMatch) },
1004         { "integerFirstComponentMatch",
1005                 offsetof(struct slap_internal_schema,
1006                         si_mr_integerFirstComponentMatch) },
1007         { "objectIdentifierFirstComponentMatch",
1008                 offsetof(struct slap_internal_schema,
1009                         si_mr_objectIdentifierFirstComponentMatch) },
1010         { NULL, 0 }
1011 };
1012
1013 static struct slap_schema_syn_map {
1014         char *sssm_name;
1015         size_t sssm_offset;
1016 } syn_map[] = {
1017         { "1.3.6.1.4.1.1466.115.121.1.15",
1018                 offsetof(struct slap_internal_schema, si_syn_directoryString) },
1019         { "1.3.6.1.4.1.1466.115.121.1.12",
1020                 offsetof(struct slap_internal_schema, si_syn_distinguishedName) },
1021         { "1.3.6.1.4.1.1466.115.121.1.27",
1022                 offsetof(struct slap_internal_schema, si_syn_integer) },
1023         { "1.3.6.1.4.1.1466.115.121.1.40",
1024                 offsetof(struct slap_internal_schema, si_syn_octetString) },
1025
1026         { "1.3.6.1.4.1.1466.115.121.1.3",
1027                 offsetof(struct slap_internal_schema, si_syn_attributeTypeDesc) },
1028         { "1.3.6.1.4.1.1466.115.121.1.16",
1029                 offsetof(struct slap_internal_schema, si_syn_ditContentRuleDesc) },
1030         { "1.3.6.1.4.1.1466.115.121.1.54",
1031                 offsetof(struct slap_internal_schema, si_syn_ldapSyntaxDesc) },
1032         { "1.3.6.1.4.1.1466.115.121.1.30",
1033                 offsetof(struct slap_internal_schema, si_syn_matchingRuleDesc) },
1034         { "1.3.6.1.4.1.1466.115.121.1.31",
1035                 offsetof(struct slap_internal_schema, si_syn_matchingRuleUseDesc) },
1036         { "1.3.6.1.4.1.1466.115.121.1.35",
1037                 offsetof(struct slap_internal_schema, si_syn_nameFormDesc) },
1038         { "1.3.6.1.4.1.1466.115.121.1.37",
1039                 offsetof(struct slap_internal_schema, si_syn_objectClassDesc) },
1040
1041         { "1.3.6.1.4.1.1466.115.121.1.17",
1042                 offsetof(struct slap_internal_schema, si_syn_ditStructureRuleDesc) },
1043
1044         { NULL, 0 }
1045 };
1046
1047 int
1048 slap_schema_load( void )
1049 {
1050         int i;
1051
1052         for( i=0; syn_map[i].sssm_name; i++ ) {
1053                 Syntax ** synp = (Syntax **)
1054                         &(((char *) &slap_schema)[syn_map[i].sssm_offset]);
1055
1056                 assert( *synp == NULL );
1057
1058                 *synp = syn_find( syn_map[i].sssm_name );
1059
1060                 if( *synp == NULL ) {
1061                         fprintf( stderr, "slap_schema_load: Syntax: "
1062                                 "No syntax \"%s\" defined in schema\n",
1063                                 syn_map[i].sssm_name );
1064                         return LDAP_INVALID_SYNTAX;
1065                 }
1066         }
1067
1068         for( i=0; mr_map[i].ssmm_name; i++ ) {
1069                 MatchingRule ** mrp = (MatchingRule **)
1070                         &(((char *) &slap_schema)[mr_map[i].ssmm_offset]);
1071
1072                 assert( *mrp == NULL );
1073
1074                 *mrp = mr_find( mr_map[i].ssmm_name );
1075
1076                 if( *mrp == NULL ) {
1077                         fprintf( stderr, "slap_schema_load: MatchingRule: "
1078                                 "No matching rule \"%s\" defined in schema\n",
1079                                 mr_map[i].ssmm_name );
1080                         return LDAP_INAPPROPRIATE_MATCHING;
1081                 }
1082         }
1083
1084         for( i=0; ad_map[i].ssam_name; i++ ) {
1085                 assert( ad_map[i].ssam_defn != NULL );
1086                 {
1087                         LDAPAttributeType *at;
1088                         int             code;
1089                         const char      *err;
1090
1091                         at = ldap_str2attributetype( ad_map[i].ssam_defn,
1092                                 &code, &err, LDAP_SCHEMA_ALLOW_ALL );
1093                         if ( !at ) {
1094                                 fprintf( stderr,
1095                                         "slap_schema_load: AttributeType \"%s\": %s before %s\n",
1096                                          ad_map[i].ssam_name, ldap_scherr2str(code), err );
1097                                 return code;
1098                         }
1099
1100                         if ( at->at_oid == NULL ) {
1101                                 fprintf( stderr, "slap_schema_load: "
1102                                         "AttributeType \"%s\": no OID\n",
1103                                         ad_map[i].ssam_name );
1104                                 return LDAP_OTHER;
1105                         }
1106
1107                         code = at_add( at, &err );
1108                         if ( code ) {
1109                                 fprintf( stderr, "slap_schema_load: AttributeType "
1110                                         "\"%s\": %s: \"%s\"\n",
1111                                          ad_map[i].ssam_name, scherr2str(code), err );
1112                                 return code;
1113                         }
1114                         ldap_memfree( at );
1115                 }
1116                 {
1117                         int rc;
1118                         const char *text;
1119                         Syntax *syntax = NULL;
1120
1121                         AttributeDescription ** adp = (AttributeDescription **)
1122                                 &(((char *) &slap_schema)[ad_map[i].ssam_offset]);
1123
1124                         assert( *adp == NULL );
1125
1126                         rc = slap_str2ad( ad_map[i].ssam_name, adp, &text );
1127                         if( rc != LDAP_SUCCESS ) {
1128                                 fprintf( stderr, "slap_schema_load: AttributeType \"%s\": "
1129                                         "not defined in schema\n",
1130                                         ad_map[i].ssam_name );
1131                                 return rc;
1132                         }
1133
1134                         if( ad_map[i].ssam_check ) {
1135                                 /* install check routine */
1136                                 (*adp)->ad_type->sat_check = ad_map[i].ssam_check;
1137                         }
1138                         /* install flags */
1139                         (*adp)->ad_type->sat_flags |= ad_map[i].ssam_flags;
1140
1141                         /* install custom syntax routines */
1142                         if( ad_map[i].ssam_syn_validate ||
1143                                 ad_map[i].ssam_syn_pretty )
1144                         {
1145                                 Syntax *syn;
1146
1147                                 syntax = (*adp)->ad_type->sat_syntax;
1148
1149                                 syn = ch_malloc( sizeof( Syntax ) );
1150                                 *syn = *syntax;
1151
1152                                 if( ad_map[i].ssam_syn_validate ) {
1153                                         syn->ssyn_validate = ad_map[i].ssam_syn_validate;
1154                                 }
1155                                 if( ad_map[i].ssam_syn_pretty ) {
1156                                         syn->ssyn_pretty = ad_map[i].ssam_syn_pretty;
1157                                 }
1158
1159                                 (*adp)->ad_type->sat_syntax = syn;
1160                         }
1161
1162                         /* install custom rule routines */
1163                         if( syntax != NULL ||
1164                                 ad_map[i].ssam_mr_convert ||
1165                                 ad_map[i].ssam_mr_normalize ||
1166                                 ad_map[i].ssam_mr_match ||
1167                                 ad_map[i].ssam_mr_indexer ||
1168                                 ad_map[i].ssam_mr_filter )
1169                         {
1170                                 MatchingRule *mr = ch_malloc( sizeof( MatchingRule ) );
1171                                 *mr = *(*adp)->ad_type->sat_equality;
1172
1173                                 if ( syntax != NULL ) {
1174                                         mr->smr_syntax = (*adp)->ad_type->sat_syntax;
1175                                 }
1176                                 if ( ad_map[i].ssam_mr_convert ) {
1177                                         mr->smr_convert = ad_map[i].ssam_mr_convert;
1178                                 }
1179                                 if ( ad_map[i].ssam_mr_normalize ) {
1180                                         mr->smr_normalize = ad_map[i].ssam_mr_normalize;
1181                                 }
1182                                 if ( ad_map[i].ssam_mr_match ) {
1183                                         mr->smr_match = ad_map[i].ssam_mr_match;
1184                                 }
1185                                 if ( ad_map[i].ssam_mr_indexer ) {
1186                                         mr->smr_indexer = ad_map[i].ssam_mr_indexer;
1187                                 }
1188                                 if ( ad_map[i].ssam_mr_filter ) {
1189                                         mr->smr_filter = ad_map[i].ssam_mr_filter;
1190                                 }
1191
1192                                 (*adp)->ad_type->sat_equality = mr;
1193                         }
1194                 }
1195         }
1196
1197         for( i=0; oc_map[i].ssom_name; i++ ) {
1198                 assert( oc_map[i].ssom_defn != NULL );
1199                 {
1200                         LDAPObjectClass *oc;
1201                         int             code;
1202                         const char      *err;
1203
1204                         oc = ldap_str2objectclass( oc_map[i].ssom_defn, &code, &err,
1205                                 LDAP_SCHEMA_ALLOW_ALL );
1206                         if ( !oc ) {
1207                                 fprintf( stderr, "slap_schema_load: ObjectClass "
1208                                         "\"%s\": %s before %s\n",
1209                                         oc_map[i].ssom_name, ldap_scherr2str(code), err );
1210                                 return code;
1211                         }
1212
1213                         if ( oc->oc_oid == NULL ) {
1214                                 fprintf( stderr, "slap_schema_load: ObjectClass "
1215                                         "\"%s\": no OID\n",
1216                                         oc_map[i].ssom_name );
1217                                 return LDAP_OTHER;
1218                         }
1219
1220                         code = oc_add(oc,0,&err);
1221                         if ( code ) {
1222                                 fprintf( stderr, "slap_schema_load: ObjectClass "
1223                                         "\"%s\": %s: \"%s\"\n",
1224                                         oc_map[i].ssom_name, scherr2str(code), err);
1225                                 return code;
1226                         }
1227
1228                         ldap_memfree(oc);
1229                 }
1230                 {
1231                         ObjectClass ** ocp = (ObjectClass **)
1232                                 &(((char *) &slap_schema)[oc_map[i].ssom_offset]);
1233
1234                         assert( *ocp == NULL );
1235
1236                         *ocp = oc_find( oc_map[i].ssom_name );
1237                         if( *ocp == NULL ) {
1238                                 fprintf( stderr, "slap_schema_load: "
1239                                         "ObjectClass \"%s\": not defined in schema\n",
1240                                         oc_map[i].ssom_name );
1241                                 return LDAP_OBJECT_CLASS_VIOLATION;
1242                         }
1243
1244                         if( oc_map[i].ssom_check ) {
1245                                 /* install check routine */
1246                                 (*ocp)->soc_check = oc_map[i].ssom_check;
1247                         }
1248                         /* install flags */
1249                         (*ocp)->soc_flags |= oc_map[i].ssom_flags;
1250                 }
1251         }
1252
1253         slap_at_undefined.sat_syntax = slap_schema.si_syn_distinguishedName;
1254         slap_schema.si_at_undefined = &slap_at_undefined;
1255
1256         return LDAP_SUCCESS;
1257 }
1258
1259 int
1260 slap_schema_check( void )
1261 {
1262         /* we should only be called once after schema_init() was called */
1263         assert( schema_init_done == 1 );
1264
1265         /*
1266          * cycle thru attributeTypes to build matchingRuleUse
1267          */
1268         if ( matching_rule_use_init() ) {
1269                 return LDAP_OTHER;
1270         }
1271
1272         ++schema_init_done;
1273         return LDAP_SUCCESS;
1274 }
1275
1276 static int rootDseObjectClass (
1277         Backend *be,
1278         Entry *e,
1279         ObjectClass *oc,
1280         const char** text,
1281         char *textbuf, size_t textlen )
1282 {
1283         *text = textbuf;
1284
1285         if( e->e_nname.bv_len ) {
1286                 snprintf( textbuf, textlen,
1287                         "objectClass \"%s\" only allowed in the root DSE",
1288                         oc->soc_oid );
1289                 return LDAP_OBJECT_CLASS_VIOLATION;
1290         }
1291
1292         /* we should not be called for the root DSE */
1293         assert( 0 );
1294         return LDAP_SUCCESS;
1295 }
1296
1297 static int aliasObjectClass (
1298         Backend *be,
1299         Entry *e,
1300         ObjectClass *oc,
1301         const char** text,
1302         char *textbuf, size_t textlen )
1303 {
1304         *text = textbuf;
1305
1306         if( !SLAP_ALIASES(be) ) {
1307                 snprintf( textbuf, textlen,
1308                         "objectClass \"%s\" not supported in context",
1309                         oc->soc_oid );
1310                 return LDAP_OBJECT_CLASS_VIOLATION;
1311         }
1312
1313         return LDAP_SUCCESS;
1314 }
1315
1316 static int referralObjectClass (
1317         Backend *be,
1318         Entry *e,
1319         ObjectClass *oc,
1320         const char** text,
1321         char *textbuf, size_t textlen )
1322 {
1323         *text = textbuf;
1324
1325         if( !SLAP_REFERRALS(be) ) {
1326                 snprintf( textbuf, textlen,
1327                         "objectClass \"%s\" not supported in context",
1328                         oc->soc_oid );
1329                 return LDAP_OBJECT_CLASS_VIOLATION;
1330         }
1331
1332         return LDAP_SUCCESS;
1333 }
1334
1335 static int subentryObjectClass (
1336         Backend *be,
1337         Entry *e,
1338         ObjectClass *oc,
1339         const char** text,
1340         char *textbuf, size_t textlen )
1341 {
1342         *text = textbuf;
1343
1344         if( !SLAP_SUBENTRIES(be) ) {
1345                 snprintf( textbuf, textlen,
1346                         "objectClass \"%s\" not supported in context",
1347                         oc->soc_oid );
1348                 return LDAP_OBJECT_CLASS_VIOLATION;
1349         }
1350
1351         if( oc != slap_schema.si_oc_subentry && !is_entry_subentry( e ) ) {
1352                 snprintf( textbuf, textlen,
1353                         "objectClass \"%s\" only allowed in subentries",
1354                         oc->soc_oid );
1355                 return LDAP_OBJECT_CLASS_VIOLATION;
1356         }
1357
1358         return LDAP_SUCCESS;
1359 }
1360
1361 static int dynamicObjectClass (
1362         Backend *be,
1363         Entry *e,
1364         ObjectClass *oc,
1365         const char** text,
1366         char *textbuf, size_t textlen )
1367 {
1368         *text = textbuf;
1369
1370         if( !SLAP_DYNAMIC(be) ) {
1371                 snprintf( textbuf, textlen,
1372                         "objectClass \"%s\" not supported in context",
1373                         oc->soc_oid );
1374                 return LDAP_OBJECT_CLASS_VIOLATION;
1375         }
1376
1377         return LDAP_SUCCESS;
1378 }
1379
1380 static int rootDseAttribute (
1381         Backend *be,
1382         Entry *e,
1383         Attribute *attr,
1384         const char** text,
1385         char *textbuf, size_t textlen )
1386 {
1387         *text = textbuf;
1388
1389         if( e->e_nname.bv_len ) {
1390                 snprintf( textbuf, textlen,
1391                         "attribute \"%s\" only allowed in the root DSE",
1392                         attr->a_desc->ad_cname.bv_val );
1393                 return LDAP_OBJECT_CLASS_VIOLATION;
1394         }
1395
1396         /* we should not be called for the root DSE */
1397         assert( 0 );
1398         return LDAP_SUCCESS;
1399 }
1400
1401 static int aliasAttribute (
1402         Backend *be,
1403         Entry *e,
1404         Attribute *attr,
1405         const char** text,
1406         char *textbuf, size_t textlen )
1407 {
1408         *text = textbuf;
1409
1410         if( !SLAP_ALIASES(be) ) {
1411                 snprintf( textbuf, textlen,
1412                         "attribute \"%s\" not supported in context",
1413                         attr->a_desc->ad_cname.bv_val );
1414                 return LDAP_OBJECT_CLASS_VIOLATION;
1415         }
1416
1417         if( !is_entry_alias( e ) ) {
1418                 snprintf( textbuf, textlen,
1419                         "attribute \"%s\" only allowed in the alias",
1420                         attr->a_desc->ad_cname.bv_val );
1421                 return LDAP_OBJECT_CLASS_VIOLATION;
1422         }
1423
1424         return LDAP_SUCCESS;
1425 }
1426
1427 static int referralAttribute (
1428         Backend *be,
1429         Entry *e,
1430         Attribute *attr,
1431         const char** text,
1432         char *textbuf, size_t textlen )
1433 {
1434         *text = textbuf;
1435
1436         if( !SLAP_REFERRALS(be) ) {
1437                 snprintf( textbuf, textlen,
1438                         "attribute \"%s\" not supported in context",
1439                         attr->a_desc->ad_cname.bv_val );
1440                 return LDAP_OBJECT_CLASS_VIOLATION;
1441         }
1442
1443         if( !is_entry_referral( e ) ) {
1444                 snprintf( textbuf, textlen,
1445                         "attribute \"%s\" only allowed in the referral",
1446                         attr->a_desc->ad_cname.bv_val );
1447                 return LDAP_OBJECT_CLASS_VIOLATION;
1448         }
1449
1450         return LDAP_SUCCESS;
1451 }
1452
1453 static int subentryAttribute (
1454         Backend *be,
1455         Entry *e,
1456         Attribute *attr,
1457         const char** text,
1458         char *textbuf, size_t textlen )
1459 {
1460         *text = textbuf;
1461
1462         if( !SLAP_SUBENTRIES(be) ) {
1463                 snprintf( textbuf, textlen,
1464                         "attribute \"%s\" not supported in context",
1465                         attr->a_desc->ad_cname.bv_val );
1466                 return LDAP_OBJECT_CLASS_VIOLATION;
1467         }
1468
1469         if( !is_entry_subentry( e ) ) {
1470                 snprintf( textbuf, textlen,
1471                         "attribute \"%s\" only allowed in the subentry",
1472                         attr->a_desc->ad_cname.bv_val );
1473                 return LDAP_OBJECT_CLASS_VIOLATION;
1474         }
1475
1476         return LDAP_SUCCESS;
1477 }
1478
1479 static int administrativeRoleAttribute (
1480         Backend *be,
1481         Entry *e,
1482         Attribute *attr,
1483         const char** text,
1484         char *textbuf, size_t textlen )
1485 {
1486         *text = textbuf;
1487
1488         if( !SLAP_SUBENTRIES(be) ) {
1489                 snprintf( textbuf, textlen,
1490                         "attribute \"%s\" not supported in context",
1491                         attr->a_desc->ad_cname.bv_val );
1492                 return LDAP_OBJECT_CLASS_VIOLATION;
1493         }
1494
1495         snprintf( textbuf, textlen,
1496                 "attribute \"%s\" not supported!",
1497                 attr->a_desc->ad_cname.bv_val );
1498         return LDAP_OBJECT_CLASS_VIOLATION;
1499 }
1500
1501 static int dynamicAttribute (
1502         Backend *be,
1503         Entry *e,
1504         Attribute *attr,
1505         const char** text,
1506         char *textbuf, size_t textlen )
1507 {
1508         *text = textbuf;
1509
1510         if( !SLAP_DYNAMIC(be) ) {
1511                 snprintf( textbuf, textlen,
1512                         "attribute \"%s\" not supported in context",
1513                         attr->a_desc->ad_cname.bv_val );
1514                 return LDAP_OBJECT_CLASS_VIOLATION;
1515         }
1516
1517         if( !is_entry_dynamicObject( e ) ) {
1518                 snprintf( textbuf, textlen,
1519                         "attribute \"%s\" only allowed in dynamic object",
1520                         attr->a_desc->ad_cname.bv_val );
1521                 return LDAP_OBJECT_CLASS_VIOLATION;
1522         }
1523
1524         return LDAP_SUCCESS;
1525 }