schema_prep.c 36.3 KB
Newer Older
1
2
3
/* schema_init.c - init builtin schema */
/* $OpenLDAP$ */
/*
Kurt Zeilenga's avatar
Kurt Zeilenga committed
4
 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5
6
7
8
9
10
11
12
13
14
15
16
17
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */

#include "portable.h"

#include <stdio.h>

#include <ac/ctype.h>
#include <ac/string.h>
#include <ac/socket.h>

#include "slap.h"
#include "ldap_pvt.h"
Kurt Zeilenga's avatar
Kurt Zeilenga committed
18
#include "ldap_pvt_uc.h"
19

20
21
#define OCDEBUG 0

22
23
24
25
int schema_init_done = 0;

struct slap_internal_schema slap_schema;

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
static int objectClassNormalize(
	slap_mask_t use,
	struct slap_syntax *syntax, /* NULL if in is asserted value */
	struct slap_matching_rule *mr,
	struct berval * in,
	struct berval * out )
{
	ObjectClass *oc = oc_bvfind( in );

	if( oc != NULL ) {
		ber_dupbv( out, &oc->soc_cname );
	} else {
		ber_dupbv( out, in );
	}

41
#if OCDEBUG
42
43
44
45
46
47
48
49
50
51
52
53
#ifdef NEW_LOGGING
	LDAP_LOG( CONFIG, ENTRY, 
		"< objectClassNormalize(%s, %s)\n", in->bv_val, out->bv_val, 0 );
#else
	Debug( LDAP_DEBUG_TRACE, "< objectClassNormalize(%s,%s)\n",
		in->bv_val, out->bv_val, 0 );
#endif
#endif

	return LDAP_SUCCESS;
}

54
static int
55
objectSubClassMatch(
56
	int *matchp,
Kurt Zeilenga's avatar
Kurt Zeilenga committed
57
	slap_mask_t flags,
58
59
60
61
62
	Syntax *syntax,
	MatchingRule *mr,
	struct berval *value,
	void *assertedValue )
{
63
	struct berval *a = (struct berval *) assertedValue;
Howard Chu's avatar
Howard Chu committed
64
65
	ObjectClass *oc = oc_bvfind( value );
	ObjectClass *asserted = oc_bvfind( a );
66

67
#if OCDEBUG
68
#ifdef NEW_LOGGING
Julius Enarusai's avatar
   
Julius Enarusai committed
69
	LDAP_LOG( CONFIG, ENTRY, 
70
		"> objectSubClassMatch(%s, %s)\n", value->bv_val, a->bv_val, 0 );
71
#else
72
	Debug( LDAP_DEBUG_TRACE, "> objectSubClassMatch(%s,%s)\n",
73
74
75
76
		value->bv_val, a->bv_val, 0 );
#endif
#endif

77
	if( asserted == NULL ) {
78
		if( OID_LEADCHAR( *a->bv_val ) ) {
79
80
81
82
83
84
			/* OID form, return FALSE */
			*matchp = 1;
			return LDAP_SUCCESS;
		}

		/* desc form, return undefined */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
85
		return SLAPD_COMPARE_UNDEFINED;
86
87
88
	}

	if ( oc == NULL ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
89
90
		/* unrecognized stored value */
		return SLAPD_COMPARE_UNDEFINED;
91
92
	}

93
	if( SLAP_IS_MR_VALUE_SYNTAX_MATCH( flags ) ) {
94
95
96
97
98
		*matchp = ( asserted != oc );
	} else {
		*matchp = !is_object_subclass( asserted, oc );
	}

99
#if OCDEBUG
100
#ifdef NEW_LOGGING
Julius Enarusai's avatar
   
Julius Enarusai committed
101
	LDAP_LOG( CONFIG, ENTRY, 
102
		"< objectSubClassMatch(%s, %s) = %d\n",
Julius Enarusai's avatar
   
Julius Enarusai committed
103
		value->bv_val, a->bv_val, *matchp );
104
#else
105
	Debug( LDAP_DEBUG_TRACE, "< objectSubClassMatch(%s,%s) = %d\n",
106
		value->bv_val, a->bv_val, *matchp );
107
#endif
108
109
#endif

110
111
112
	return LDAP_SUCCESS;
}

113
114
115
116
117
118
119
120
static int objectSubClassIndexer( 
	slap_mask_t use,
	slap_mask_t mask,
	struct slap_syntax *syntax,
	struct slap_matching_rule *mr,
	struct berval *prefix,
	BerVarray values,
	BerVarray *keysp )
121
{
122
123
124
125
	int rc, noc, i;
	BerVarray ocvalues;
	
	for( noc=0; values[noc].bv_val != NULL; noc++ ) {
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
		/* just count em */;
	}

	/* over allocate */
	ocvalues = ch_malloc( sizeof( struct berval ) * (noc+16) );

	/* copy listed values (and termination) */
	for( i=0; i<noc; i++ ) {
		ObjectClass *oc = oc_bvfind( &values[i] );
		if( oc ) {
			ocvalues[i] = oc->soc_cname;
		} else {
			ocvalues[i] = values[i];
		}
#if OCDEBUG
141
142
143
#ifdef NEW_LOGGING
		LDAP_LOG( CONFIG, ENTRY, 
			"> objectSubClassIndexer(%d, %s)\n",
144
			i, ocvalues[i].bv_val, 0 );
145
146
147
#else
		Debug( LDAP_DEBUG_TRACE,
			"> objectSubClassIndexer(%d, %s)\n",
148
			i, ocvalues[i].bv_val, 0 );
149
150
151
152
#endif
#endif
	}

153
154
155
	ocvalues[i].bv_val = NULL;
	ocvalues[i].bv_len = 0;

156
157
158
	/* expand values */
	for( i=0; i<noc; i++ ) {
		int j;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
159
		ObjectClass *oc = oc_bvfind( &ocvalues[i] );
160
161
162
163
164
165
166
167
168
169
		if( oc == NULL || oc->soc_sups == NULL ) continue;
		
		for( j=0; oc->soc_sups[j] != NULL; j++ ) {
			int found = 0;
			ObjectClass *sup = oc->soc_sups[j];
			int k;

			for( k=0; k<noc; k++ ) {

#if 0
170
#ifdef NEW_LOGGING
171
172
173
				LDAP_LOG( CONFIG, ENTRY, 
					"= objectSubClassIndexer(%d, %s, %s)\n",
					k, ocvalues[k].bv_val, sup->soc_cname.bv_val );
174
#else
175
176
177
				Debug( LDAP_DEBUG_TRACE,
					"= objectSubClassIndexer(%d, %s, %s)\n",
					k, ocvalues[k].bv_val, sup->soc_cname.bv_val );
178
179
#endif
#endif
180
181
182
183
184
				if( ber_bvcmp( &ocvalues[k], &sup->soc_cname ) == 0 ) {
					found++;
					break;
				}
			}
185

186
187
188
			if( !found ) {
				ocvalues = ch_realloc( ocvalues,
					sizeof( struct berval ) * (noc+2) );
189

190
				assert( k == noc );
191

192
193
194
195
				ocvalues[noc] = sup->soc_cname;

				assert( ocvalues[noc].bv_val );
				assert( ocvalues[noc].bv_len );
196

197
				noc++;
198

199
200
201
				ocvalues[noc].bv_len = 0;
				ocvalues[noc].bv_val = NULL;

202
#if OCDEBUG
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#ifdef NEW_LOGGING
				LDAP_LOG( CONFIG, ENTRY, 
					"< objectSubClassIndexer(%d, %d, %s)\n",
					i, k, sup->soc_cname.bv_val );
#else
				Debug( LDAP_DEBUG_TRACE,
					"< objectSubClassIndexer(%d, %d, %s)\n",
					i, k, sup->soc_cname.bv_val );
#endif
#endif
			}
		}
	}

#if 0
218
#ifdef NEW_LOGGING
Julius Enarusai's avatar
   
Julius Enarusai committed
219
	LDAP_LOG( CONFIG, ENTRY, 
220
		"< objectSubClassIndexer(%d)\n", noc, 0, 0 );
221
#else
222
223
	Debug( LDAP_DEBUG_TRACE, "< objectSubClassIndexer(%d)\n",
		noc, 0, 0 );
224
#endif
225
#endif
226

227
228
229
230
231
	rc = octetStringIndexer( use, mask, syntax, mr,
		prefix, ocvalues, keysp );

	ch_free( ocvalues );
	return rc;
232
}
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* Index generation function */
static int objectSubClassFilter(
	slap_mask_t use,
	slap_mask_t flags,
	Syntax *syntax,
	MatchingRule *mr,
	struct berval *prefix,
	void * assertedValue,
	BerVarray *keysp )
{
#if OCDEBUG
	struct berval *bv = (struct berval *) assertedValue;
	ObjectClass *oc = oc_bvfind( bv );
	if( oc ) {
		bv = &oc->soc_cname;
	}

#ifdef NEW_LOGGING
	LDAP_LOG( CONFIG, ENTRY, 
		"< objectSubClassFilter(%s)\n", bv->bv_val, 0, 0 );
#else
	Debug( LDAP_DEBUG_TRACE, "< objectSubClassFilter(%s)\n",
		bv->bv_val, 0, 0 );
#endif
#endif

	return octetStringFilter( use, flags, syntax, mr,
		prefix, assertedValue, keysp );
}
263

Kurt Zeilenga's avatar
Kurt Zeilenga committed
264
static ObjectClassSchemaCheckFN rootDseObjectClass;
265
266
static ObjectClassSchemaCheckFN aliasObjectClass;
static ObjectClassSchemaCheckFN referralObjectClass;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
267
static ObjectClassSchemaCheckFN subentryObjectClass;
268
static ObjectClassSchemaCheckFN dynamicObjectClass;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
269

Kurt Zeilenga's avatar
Kurt Zeilenga committed
270
static struct slap_schema_oc_map {
271
	char *ssom_name;
272
273
	char *ssom_defn;
	ObjectClassSchemaCheckFN *ssom_check;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
274
	slap_mask_t ssom_flags;
275
276
	size_t ssom_offset;
} oc_map[] = {
277
278
279
	{ "top", "( 2.5.6.0 NAME 'top' "
			"DESC 'top of the superclass chain' "
			"ABSTRACT MUST objectClass )",
Kurt Zeilenga's avatar
Kurt Zeilenga committed
280
		0, 0, offsetof(struct slap_internal_schema, si_oc_top) },
281
282
283
284
	{ "extensibleObject", "( 1.3.6.1.4.1.1466.101.120.111 "
			"NAME 'extensibleObject' "
			"DESC 'RFC2252: extensible object' "
			"SUP top AUXILIARY )",
285
286
		0, SLAP_OC_OPERATIONAL,
		offsetof(struct slap_internal_schema, si_oc_extensibleObject) },
287
288
289
290
	{ "alias", "( 2.5.6.1 NAME 'alias' "
			"DESC 'RFC2256: an alias' "
			"SUP top STRUCTURAL "
			"MUST aliasedObjectName )",
291
		aliasObjectClass, SLAP_OC_ALIAS|SLAP_OC_OPERATIONAL,
292
		offsetof(struct slap_internal_schema, si_oc_alias) },
293
294
295
	{ "referral", "( 2.16.840.1.113730.3.2.6 NAME 'referral' "
			"DESC 'namedref: named subordinate referral' "
			"SUP top STRUCTURAL MUST ref )",
296
		referralObjectClass, SLAP_OC_REFERRAL|SLAP_OC_OPERATIONAL,
297
		offsetof(struct slap_internal_schema, si_oc_referral) },
298
299
300
	{ "LDAProotDSE", "( 1.3.6.1.4.1.4203.1.4.1 "
			"NAME ( 'OpenLDAProotDSE' 'LDAProotDSE' ) "
			"DESC 'OpenLDAP Root DSE object' "
301
			"SUP top STRUCTURAL MAY cn )",
302
		rootDseObjectClass, SLAP_OC_OPERATIONAL,
Kurt Zeilenga's avatar
Kurt Zeilenga committed
303
		offsetof(struct slap_internal_schema, si_oc_rootdse) },
304
305
306
	{ "subentry", "( 2.5.20.0 NAME 'subentry' "
			"SUP top STRUCTURAL "
			"MUST ( cn $ subtreeSpecification ) )",
307
		subentryObjectClass, SLAP_OC_SUBENTRY|SLAP_OC_OPERATIONAL,
308
		offsetof(struct slap_internal_schema, si_oc_subentry) },
309
310
	{ "subschema", "( 2.5.20.1 NAME 'subschema' "
		"DESC 'RFC2252: controlling subschema (sub)entry' "
Kurt Zeilenga's avatar
Kurt Zeilenga committed
311
		"AUXILIARY "
312
313
		"MAY ( dITStructureRules $ nameForms $ ditContentRules $ "
			"objectClasses $ attributeTypes $ matchingRules $ "
314
			"matchingRuleUse ) )",
315
		subentryObjectClass, SLAP_OC_OPERATIONAL,
Kurt Zeilenga's avatar
Kurt Zeilenga committed
316
		offsetof(struct slap_internal_schema, si_oc_subschema) },
317
318
319
320
	{ "monitor", "( 1.3.6.1.4.1.4203.666.3.2 NAME 'monitor' "
		"DESC 'OpenLDAP system monitoring' "
		"STRUCTURAL "
		"MUST cn )",
321
322
		0, SLAP_OC_OPERATIONAL,
		offsetof(struct slap_internal_schema, si_oc_monitor) },
323
324
	{ "collectiveAttributeSubentry", "( 2.5.20.2 "
			"NAME 'collectiveAttributeSubentry' "
325
			"AUXILIARY )",
326
327
		subentryObjectClass,
		SLAP_OC_COLLECTIVEATTRIBUTESUBENTRY|SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
328
		offsetof(struct slap_internal_schema, si_oc_collectiveAttributeSubentry) },
329
330
331
332
	{ "dynamicObject", "( 1.3.6.1.4.1.1466.101.119.2 "
			"NAME 'dynamicObject' "
			"DESC 'RFC2589: Dynamic Object' "
			"SUP top AUXILIARY )",
333
		dynamicObjectClass, SLAP_OC_DYNAMICOBJECT,
334
		offsetof(struct slap_internal_schema, si_oc_dynamicObject) },
Kurt Zeilenga's avatar
Kurt Zeilenga committed
335
	{ NULL, NULL, NULL, 0, 0 }
336
337
};

338
static AttributeTypeSchemaCheckFN rootDseAttribute;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
339
static AttributeTypeSchemaCheckFN aliasAttribute;
340
static AttributeTypeSchemaCheckFN referralAttribute;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
341
static AttributeTypeSchemaCheckFN subentryAttribute;
342
static AttributeTypeSchemaCheckFN administrativeRoleAttribute;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
343
static AttributeTypeSchemaCheckFN dynamicAttribute;
344

Kurt Zeilenga's avatar
Kurt Zeilenga committed
345
static struct slap_schema_ad_map {
346
	char *ssam_name;
347
348
	char *ssam_defn;
	AttributeTypeSchemaCheckFN *ssam_check;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
349
	slap_mask_t ssam_flags;
350
351
	slap_mr_convert_func *ssam_convert;
	slap_mr_normalize_func *ssam_normalize;
352
	slap_mr_match_func *ssam_match;
353
354
	slap_mr_indexer_func *ssam_indexer;
	slap_mr_filter_func *ssam_filter;
355
356
	size_t ssam_offset;
} ad_map[] = {
357
358
359
360
	{ "objectClass", "( 2.5.4.0 NAME 'objectClass' "
			"DESC 'RFC2256: object classes of the entity' "
			"EQUALITY objectIdentifierMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
361
362
		NULL, SLAP_AT_FINAL,
		NULL, objectClassNormalize, objectSubClassMatch,
363
			objectSubClassIndexer, objectSubClassFilter,
364
		offsetof(struct slap_internal_schema, si_ad_objectClass) },
365
366

	/* user entry operational attributes */
367
368
369
370
	{ "structuralObjectClass", "( 2.5.21.9 NAME 'structuralObjectClass' "
			"DESC 'X.500(93): structural object class of entry' "
			"EQUALITY objectIdentifierMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
Kurt Zeilenga's avatar
Kurt Zeilenga committed
371
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
372
373
		NULL, 0,
		NULL, objectClassNormalize, objectSubClassMatch,
374
			objectSubClassIndexer, objectSubClassFilter,
375
		offsetof(struct slap_internal_schema, si_ad_structuralObjectClass) },
376
377
378
379
380
381
	{ "createTimestamp", "( 2.5.18.1 NAME 'createTimestamp' "
			"DESC 'RFC2252: time which object was created' "
			"EQUALITY generalizedTimeMatch "
			"ORDERING generalizedTimeOrderingMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
382
383
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
384
		offsetof(struct slap_internal_schema, si_ad_createTimestamp) },
385
386
387
388
389
390
	{ "modifyTimestamp", "( 2.5.18.2 NAME 'modifyTimestamp' "
			"DESC 'RFC2252: time which object was last modified' "
			"EQUALITY generalizedTimeMatch "
			"ORDERING generalizedTimeOrderingMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
391
392
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
393
		offsetof(struct slap_internal_schema, si_ad_modifyTimestamp) },
394
395
396
397
398
	{ "creatorsName", "( 2.5.18.3 NAME 'creatorsName' "
			"DESC 'RFC2252: name of creator' "
			"EQUALITY distinguishedNameMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
399
400
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
401
402
403
404
405
406
		offsetof(struct slap_internal_schema, si_ad_creatorsName) },
	{ "modifiersName", "( 2.5.18.4 NAME 'modifiersName' "
			"DESC 'RFC2252: name of last modifier' "
			"EQUALITY distinguishedNameMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
407
408
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
409
410
411
412
413
414
		offsetof(struct slap_internal_schema, si_ad_modifiersName) },
	{ "hasSubordinates", "( 2.5.18.9 NAME 'hasSubordinates' "
			"DESC 'X.501: entry has children' "
			"EQUALITY booleanMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
415
416
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
417
		offsetof(struct slap_internal_schema, si_ad_hasSubordinates) },
418
419
420
	{ "subschemaSubentry", "( 2.5.18.10 NAME 'subschemaSubentry' "
			"DESC 'RFC2252: name of controlling subschema entry' "
			"EQUALITY distinguishedNameMatch "
Kurt Zeilenga's avatar
Kurt Zeilenga committed
421
422
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 SINGLE-VALUE "
			"NO-USER-MODIFICATION USAGE directoryOperation )",
423
424
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
425
		offsetof(struct slap_internal_schema, si_ad_subschemaSubentry) },
426
427
	{ "collectiveAttributeSubentries", "( 2.5.18.12 "
			"NAME 'collectiveAttributeSubentries' "
428
429
			"EQUALITY distinguishedNameMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
Kurt Zeilenga's avatar
Kurt Zeilenga committed
430
			"NO-USER-MODIFICATION USAGE directoryOperation )",
431
432
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
433
		offsetof(struct slap_internal_schema, si_ad_collectiveSubentries) },
434
435
436
437
	{ "collectiveExclusions", "( 2.5.18.7 NAME 'collectiveExclusions' "
			"EQUALITY objectIdentifierMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
			"USAGE directoryOperation )",
438
439
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
440
		offsetof(struct slap_internal_schema, si_ad_collectiveExclusions) },
441

442
443
444
445
446
	{ "entryUUID", "( 1.3.6.1.4.1.4203.666.1.6 NAME 'entryUUID' "   
			"DESC 'LCUP/LDUP: universally unique identifier' "
			"EQUALITY octetStringMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
447
448
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
449
450
451
452
453
454
		offsetof(struct slap_internal_schema, si_ad_entryUUID) },
	{ "entryCSN", "( 1.3.6.1.4.1.4203.666.1.7 NAME 'entryCSN' "
			"DESC 'LCUP/LDUP: change sequence number' "
			"EQUALITY octetStringMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
455
456
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
457
458
		offsetof(struct slap_internal_schema, si_ad_entryCSN) },

459
	/* root DSE attributes */
460
461
462
	{ "altServer", "( 1.3.6.1.4.1.1466.101.120.6 NAME 'altServer' "
			"DESC 'RFC2252: alternative servers' "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 USAGE dSAOperation )",
463
464
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
465
		offsetof(struct slap_internal_schema, si_ad_altServer) },
466
467
468
469
	{ "namingContexts", "( 1.3.6.1.4.1.1466.101.120.5 "
			"NAME 'namingContexts' "
			"DESC 'RFC2252: naming contexts' "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 USAGE dSAOperation )",
470
471
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
472
		offsetof(struct slap_internal_schema, si_ad_namingContexts) },
473
474
	{ "supportedControl", "( 1.3.6.1.4.1.1466.101.120.13 "
			"NAME 'supportedControl' "
Kurt Zeilenga's avatar
Kurt Zeilenga committed
475
476
			"DESC 'RFC2252: supported controls' "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 USAGE dSAOperation )",
477
478
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
479
		offsetof(struct slap_internal_schema, si_ad_supportedControl) },
480
481
482
483
	{ "supportedExtension", "( 1.3.6.1.4.1.1466.101.120.7 "
			"NAME 'supportedExtension' "
			"DESC 'RFC2252: supported extended operations' "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 USAGE dSAOperation )",
484
485
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
486
		offsetof(struct slap_internal_schema, si_ad_supportedExtension) },
487
488
489
490
	{ "supportedLDAPVersion", "( 1.3.6.1.4.1.1466.101.120.15 "
			"NAME 'supportedLDAPVersion' "
			"DESC 'RFC2252: supported LDAP versions' "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 USAGE dSAOperation )",
491
492
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
493
		offsetof(struct slap_internal_schema, si_ad_supportedLDAPVersion) },
494
495
496
497
	{ "supportedSASLMechanisms", "( 1.3.6.1.4.1.1466.101.120.14 "
			"NAME 'supportedSASLMechanisms' "
			"DESC 'RFC2252: supported SASL mechanisms'"
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 USAGE dSAOperation )",
498
499
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
500
		offsetof(struct slap_internal_schema, si_ad_supportedSASLMechanisms) },
501
502
503
504
505
506
	{ "supportedFeatures", "( 1.3.6.1.4.1.4203.1.3.5 "
			"NAME 'supportedFeatures' "
			"DESC 'features supported by the server' "
			"EQUALITY objectIdentifierMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
			"USAGE dSAOperation )",
507
508
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
509
		offsetof(struct slap_internal_schema, si_ad_supportedFeatures) },
510
511
512
513
514
515
516
	{ "monitorContext", "( 1.3.6.1.4.1.4203.666.1.10 "
			"NAME 'monitorContext' "
			"DESC 'monitor context' "
			"EQUALITY objectIdentifierMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 "
			"SINGLE-VALUE NO-USER-MODIFICATION "
			"USAGE dSAOperation )",
517
518
		rootDseAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
519
		offsetof(struct slap_internal_schema, si_ad_monitorContext) },
520
521
522
523
524
525
	{ "vendorName", "( 1.3.6.1.1.4 NAME 'vendorName' "
			"DESC 'RFC3045: name of implementation vendor' "
			"EQUALITY 1.3.6.1.4.1.1466.109.114.1 "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
			"SINGLE-VALUE NO-USER-MODIFICATION "
			"USAGE dSAOperation )",
526
527
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
528
529
530
531
532
533
534
		offsetof(struct slap_internal_schema, si_ad_vendorName) },
	{ "vendorVersion", "( 1.3.6.1.1.5 NAME 'vendorVersion' "
			"DESC 'RFC3045: version of implementation' "
			"EQUALITY 1.3.6.1.4.1.1466.109.114.1 "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
			"SINGLE-VALUE NO-USER-MODIFICATION "
			"USAGE dSAOperation )",
535
536
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
537
538
539
540
541
542
543
		offsetof(struct slap_internal_schema, si_ad_vendorVersion) },

	/* subentry attributes */
	{ "administrativeRole", "( 2.5.18.5 NAME 'administrativeRole' "
			"EQUALITY objectIdentifierMatch "
			"USAGE directoryOperation "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
544
545
		administrativeRoleAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
546
547
548
549
550
		offsetof(struct slap_internal_schema, si_ad_administrativeRole) },
	{ "subtreeSpecification", "( 2.5.18.6 NAME 'subtreeSpecification' "
			"SINGLE-VALUE "
			"USAGE directoryOperation "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.45 )",
551
552
		subentryAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
553
		offsetof(struct slap_internal_schema, si_ad_subtreeSpecification) },
554

555
	/* subschema subentry attributes */
556
557
558
559
560
	{ "ditStructureRules", "( 2.5.21.1 NAME 'dITStructureRules' "
			"DESC 'RFC2252: DIT structure rules' "
			"EQUALITY integerFirstComponentMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.17 "
			"USAGE directoryOperation ) ",
561
562
		subentryAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
563
564
565
566
567
		offsetof(struct slap_internal_schema, si_ad_ditStructureRules) },
	{ "ditContentRules", "( 2.5.21.2 NAME 'dITContentRules' "
			"DESC 'RFC2252: DIT content rules' "
			"EQUALITY objectIdentifierFirstComponentMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.16 USAGE directoryOperation )",
568
569
		subentryAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
570
		offsetof(struct slap_internal_schema, si_ad_ditContentRules) },
571
572
573
574
	{ "matchingRules", "( 2.5.21.4 NAME 'matchingRules' "
			"DESC 'RFC2252: matching rules' "
			"EQUALITY objectIdentifierFirstComponentMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.30 USAGE directoryOperation )",
575
576
		subentryAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
577
		offsetof(struct slap_internal_schema, si_ad_matchingRules) },
578
579
580
581
	{ "attributeTypes", "( 2.5.21.5 NAME 'attributeTypes' "
			"DESC 'RFC2252: attribute types' "
			"EQUALITY objectIdentifierFirstComponentMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.3 USAGE directoryOperation )",
582
583
		subentryAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
584
585
586
587
588
		offsetof(struct slap_internal_schema, si_ad_attributeTypes) },
	{ "objectClasses", "( 2.5.21.6 NAME 'objectClasses' "
			"DESC 'RFC2252: object classes' "
			"EQUALITY objectIdentifierFirstComponentMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.37 USAGE directoryOperation )",
589
590
		subentryAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
591
		offsetof(struct slap_internal_schema, si_ad_objectClasses) },
592
593
594
595
	{ "nameForms", "( 2.5.21.7 NAME 'nameForms' "
			"DESC 'RFC2252: name forms ' "
			"EQUALITY objectIdentifierFirstComponentMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.35 USAGE directoryOperation )",
596
597
		subentryAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
598
		offsetof(struct slap_internal_schema, si_ad_nameForms) },
599
	{ "matchingRuleUse", "( 2.5.21.8 NAME 'matchingRuleUse' "
600
601
602
			"DESC 'RFC2252: matching rule uses' "
			"EQUALITY objectIdentifierFirstComponentMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.31 USAGE directoryOperation )",
603
604
		subentryAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
605
		offsetof(struct slap_internal_schema, si_ad_matchingRuleUse) },
606

607
608
609
610
	{ "ldapSyntaxes", "( 1.3.6.1.4.1.1466.101.120.16 NAME 'ldapSyntaxes' "
			"DESC 'RFC2252: LDAP syntaxes' "
			"EQUALITY objectIdentifierFirstComponentMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.54 USAGE directoryOperation )",
611
612
		subentryAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
613
614
		offsetof(struct slap_internal_schema, si_ad_ldapSyntaxes) },

615
	/* knowledge information */
616
617
618
619
620
	{ "aliasedObjectName", "( 2.5.4.1 "
			"NAME ( 'aliasedObjectName' 'aliasedEntryName' ) "
			"DESC 'RFC2256: name of aliased object' "
			"EQUALITY distinguishedNameMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 SINGLE-VALUE )",
621
622
		aliasAttribute, SLAP_AT_FINAL,
		NULL, NULL, NULL, NULL, NULL,
623
		offsetof(struct slap_internal_schema, si_ad_aliasedObjectName) },
624
625
626
627
628
	{ "ref", "( 2.16.840.1.113730.3.1.34 NAME 'ref' "
			"DESC 'namedref: subordinate referral URL' "
			"EQUALITY caseExactMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
			"USAGE distributedOperation )",
629
630
		referralAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
631
632
		offsetof(struct slap_internal_schema, si_ad_ref) },

Kurt Zeilenga's avatar
Kurt Zeilenga committed
633
	/* access control internals */
634
635
636
637
638
	{ "entry", "( 1.3.6.1.4.1.4203.1.3.1 "
			"NAME 'entry' "
			"DESC 'OpenLDAP ACL entry pseudo-attribute' "
			"SYNTAX 1.3.6.1.4.1.4203.1.1.1 "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE dSAOperation )",
639
640
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
641
		offsetof(struct slap_internal_schema, si_ad_entry) },
642
643
644
645
646
	{ "children", "( 1.3.6.1.4.1.4203.1.3.2 "
			"NAME 'children' "
			"DESC 'OpenLDAP ACL children pseudo-attribute' "
			"SYNTAX 1.3.6.1.4.1.4203.1.1.1 "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE dSAOperation )",
647
648
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
649
		offsetof(struct slap_internal_schema, si_ad_children) },
650
	{ "saslAuthzTo", "( 1.3.6.1.4.1.4203.666.1.8 "
651
652
653
654
			"NAME 'saslAuthzTo' "
			"DESC 'SASL proxy authorization targets' "
			"EQUALITY caseExactMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
655
			"USAGE distributedOperation )",
656
657
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
658
		offsetof(struct slap_internal_schema, si_ad_saslAuthzTo) },
659
	{ "saslAuthzFrom", "( 1.3.6.1.4.1.4203.666.1.9 "
660
661
662
663
			"NAME 'saslAuthzFrom' "
			"DESC 'SASL proxy authorization sources' "
			"EQUALITY caseExactMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
664
			"USAGE distributedOperation )",
665
666
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
667
		offsetof(struct slap_internal_schema, si_ad_saslAuthzFrom) },
668
#ifdef SLAPD_ACI_ENABLED
669
670
671
672
673
674
	{ "OpenLDAPaci", "( 1.3.6.1.4.1.4203.666.1.5 "
			"NAME 'OpenLDAPaci' "
			"DESC 'OpenLDAP access control information (experimental)' "
			"EQUALITY OpenLDAPaciMatch "
			"SYNTAX 1.3.6.1.4.1.4203.666.2.1 "
			"USAGE directoryOperation )",
675
676
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
677
678
		offsetof(struct slap_internal_schema, si_ad_aci) },
#endif
679

680
681
682
683
	{ "entryTtl", "( 1.3.6.1.4.1.1466.101.119.3 NAME 'entryTtl' "
			"DESC 'RFC2589: entry time-to-live' "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE "
			"NO-USER-MODIFICATION USAGE dSAOperation )",
684
685
		dynamicAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
686
687
688
689
690
691
		offsetof(struct slap_internal_schema, si_ad_entryTtl) },
	{ "dynamicSubtrees", "( 1.3.6.1.4.1.1466.101.119.4 "
			"NAME 'dynamicSubtrees' "
			"DESC 'RFC2589: dynamic subtrees' "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 NO-USER-MODIFICATION "
			"USAGE dSAOperation )",
692
693
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
694
695
		offsetof(struct slap_internal_schema, si_ad_dynamicSubtrees) },

696
	/* userApplication attributes (which system schema depends upon) */
697
698
699
700
	{ "distinguishedName", "( 2.5.4.49 NAME 'distinguishedName' "
			"DESC 'RFC2256: common supertype of DN attributes' "
			"EQUALITY distinguishedNameMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
701
702
		NULL, SLAP_AT_ABSTRACT,
		NULL, NULL, NULL, NULL, NULL,
703
		offsetof(struct slap_internal_schema, si_ad_distinguishedName) },
704
705
706
707
708
	{ "name", "( 2.5.4.41 NAME 'name' "
			"DESC 'RFC2256: common supertype of name attributes' "
			"EQUALITY caseIgnoreMatch "
			"SUBSTR caseIgnoreSubstringsMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )",
709
710
		NULL, SLAP_AT_ABSTRACT,
		NULL, NULL, NULL, NULL, NULL,
711
712
713
714
		offsetof(struct slap_internal_schema, si_ad_name) },
	{ "cn", "( 2.5.4.3 NAME ( 'cn' 'commonName' ) "
			"DESC 'RFC2256: common name(s) for which the entity is known by' "
			"SUP name )",
715
716
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
717
718
719
720
721
		offsetof(struct slap_internal_schema, si_ad_cn) },
	{ "userPassword", "( 2.5.4.35 NAME 'userPassword' "
			"DESC 'RFC2256/2307: password of user' "
			"EQUALITY octetStringMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{128} )",
722
723
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
724
		offsetof(struct slap_internal_schema, si_ad_userPassword) },
725
726

#ifdef SLAPD_AUTHPASSWD
727
728
729
730
731
	{ "authPassword", "( 1.3.6.1.4.1.4203.1.3.4 "
			"NAME 'authPassword' "
			"DESC 'RFC3112: authentication password attribute' "
			"EQUALITY 1.3.6.1.4.1.4203.1.2.2 "
			"SYNTAX 1.3.6.1.4.1.4203.1.1.2 )",
732
		NULL, 0,
733
		NULL, NULL, NULL, NULL, NULL,
734
735
736
737
738
739
740
		offsetof(struct slap_internal_schema, si_ad_authPassword) },
	{ "supportedAuthPasswordSchemes", "( 1.3.6.1.4.1.4203.1.3.3 "
			"NAME 'supportedAuthPasswordSchemes' "
			"DESC 'RFC3112: supported authPassword schemes' "
			"EQUALITY caseExactIA5Match "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{32} "
			"USAGE dSAOperation )",
741
742
		subschemaAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
743
		offsetof(struct slap_internal_schema, si_ad_authPassword) },
744
#endif
745
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
746
747
748
749
750
751
	{ "krbName", "( 1.3.6.1.4.1.250.1.32 "
			"NAME ( 'krbName' 'kerberosName' ) "
			"DESC 'Kerberos principal associated with object' "
			"EQUALITY caseIgnoreIA5Match "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 "
			"SINGLE-VALUE )",
752
753
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
754
755
756
		offsetof(struct slap_internal_schema, si_ad_krbName) },
#endif

Kurt Zeilenga's avatar
Kurt Zeilenga committed
757
	{ NULL, NULL, NULL, 0, NULL, NULL, NULL, 0 }
758
759
};

760
761
762
static AttributeType slap_at_undefined = {
	{ "1.1.1", NULL, NULL, 1, NULL,
		NULL, NULL, NULL, NULL,
763
		0, 0, 0, 1, 3 }, /* LDAPAttributeType */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
764
	{ sizeof("UNDEFINED")-1, "UNDEFINED" }, /* cname */
765
766
767
768
	NULL, /* sup */
	NULL, /* subtypes */
	NULL, NULL, NULL, NULL,	/* matching rules */
	NULL, /* syntax (this may need to be defined) */
769
770
	(AttributeTypeSchemaCheckFN *) 0, /* schema check function */
	SLAP_AT_ABSTRACT|SLAP_AT_FINAL,	/* mask */
Kurt Zeilenga's avatar
Kurt Zeilenga committed
771
772
	NULL, /* next */
	NULL /* attribute description */
773
	/* mutex (don't know how to initialize it :) */
774
};
775

Kurt Zeilenga's avatar
Kurt Zeilenga committed
776
static struct slap_schema_mr_map {
777
778
779
780
781
782
783
784
785
786
	char *ssmm_name;
	size_t ssmm_offset;
} mr_map[] = {
	{ "distinguishedNameMatch",
		offsetof(struct slap_internal_schema, si_mr_distinguishedNameMatch) },
	{ "integerMatch",
		offsetof(struct slap_internal_schema, si_mr_integerMatch) },
	{ NULL, 0 }
};

Kurt Zeilenga's avatar
Kurt Zeilenga committed
787
static struct slap_schema_syn_map {
788
789
790
	char *sssm_name;
	size_t sssm_offset;
} syn_map[] = {
791
792
	{ "1.3.6.1.4.1.1466.115.121.1.40",
		offsetof(struct slap_internal_schema, si_syn_octetString) },
793
794
795
796
797
798
799
	{ "1.3.6.1.4.1.1466.115.121.1.12",
		offsetof(struct slap_internal_schema, si_syn_distinguishedName) },
	{ "1.3.6.1.4.1.1466.115.121.1.27",
		offsetof(struct slap_internal_schema, si_syn_integer) },
	{ NULL, 0 }
};

800
int
801
802
slap_schema_load( void )
{
803
	int i;
804
805
806
807
808
809
810
811
812
813

	for( i=0; syn_map[i].sssm_name; i++ ) {
		Syntax ** synp = (Syntax **)
			&(((char *) &slap_schema)[syn_map[i].sssm_offset]);

		assert( *synp == NULL );

		*synp = syn_find( syn_map[i].sssm_name );

		if( *synp == NULL ) {
814
			fprintf( stderr, "slap_schema_load: "
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
				"No syntax \"%s\" defined in schema\n",
				syn_map[i].sssm_name );
			return LDAP_INVALID_SYNTAX;
		}
	}

	for( i=0; mr_map[i].ssmm_name; i++ ) {
		MatchingRule ** mrp = (MatchingRule **)
			&(((char *) &slap_schema)[mr_map[i].ssmm_offset]);

		assert( *mrp == NULL );

		*mrp = mr_find( mr_map[i].ssmm_name );

		if( *mrp == NULL ) {
830
			fprintf( stderr, "slap_schema_load: "
831
832
833
834
835
836
				"No matching rule \"%s\" defined in schema\n",
				mr_map[i].ssmm_name );
			return LDAP_INAPPROPRIATE_MATCHING;
		}
	}

837
	for( i=0; ad_map[i].ssam_name; i++ ) {
838
839
		assert( ad_map[i].ssam_defn != NULL );
		{
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
			LDAPAttributeType *at;
			int		code;
			const char	*err;

			at = ldap_str2attributetype( ad_map[i].ssam_defn,
				&code, &err, LDAP_SCHEMA_ALLOW_ALL );
			if ( !at ) {
				fprintf( stderr,
					"slap_schema_load: %s: %s before %s\n",
					 ad_map[i].ssam_name, ldap_scherr2str(code), err );
				return code;
			}

			if ( at->at_oid == NULL ) {
				fprintf( stderr, "slap_schema_load: "
					"attributeType \"%s\" has no OID\n",
					ad_map[i].ssam_name );
				return LDAP_OTHER;
			}

			code = at_add( at, &err );
			if ( code ) {
				fprintf( stderr, "slap_schema_load: "
					"%s: %s: \"%s\"\n",
					 ad_map[i].ssam_name, scherr2str(code), err );
				return code;
			}
			ldap_memfree( at );
		}
869
870
871
872
873
874
875
876
877
878
879
		{
			int rc;
			const char *text;

			AttributeDescription ** adp = (AttributeDescription **)
				&(((char *) &slap_schema)[ad_map[i].ssam_offset]);

			assert( *adp == NULL );

			rc = slap_str2ad( ad_map[i].ssam_name, adp, &text );
			if( rc != LDAP_SUCCESS ) {
880
				fprintf( stderr, "slap_schema_load: "
881
882
883
884
885
886
887
888
889
890
891
892
					"No attribute \"%s\" defined in schema\n",
					ad_map[i].ssam_name );
				return rc;
			}

			if( ad_map[i].ssam_check ) {
				/* install check routine */
				(*adp)->ad_type->sat_check = ad_map[i].ssam_check;
			}
			/* install flags */
			(*adp)->ad_type->sat_flags |= ad_map[i].ssam_flags;

893
			/* install custom rule routine */
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
			if( ad_map[i].ssam_convert ||
				ad_map[i].ssam_normalize ||
				ad_map[i].ssam_match ||
				ad_map[i].ssam_indexer ||
				ad_map[i].ssam_filter )
			{
				MatchingRule *mr = ch_malloc( sizeof( MatchingRule ) );
				*mr = *(*adp)->ad_type->sat_equality;
				(*adp)->ad_type->sat_equality = mr;
				
				if( ad_map[i].ssam_convert ) {
					mr->smr_convert = ad_map[i].ssam_convert;
				}
				if( ad_map[i].ssam_normalize ) {
					mr->smr_normalize = ad_map[i].ssam_normalize;
				}
				if( ad_map[i].ssam_match ) {
					mr->smr_match = ad_map[i].ssam_match;
				}
				if( ad_map[i].ssam_indexer ) {
					mr->smr_indexer = ad_map[i].ssam_indexer;
				}
				if( ad_map[i].ssam_filter ) {
					mr->smr_filter = ad_map[i].ssam_filter;
				}
919
920
			}
		}
921
	}
922
923

	for( i=0; oc_map[i].ssom_name; i++ ) {
924
925
		assert( oc_map[i].ssom_defn != NULL );
		{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
926
927
928
			LDAPObjectClass *oc;
			int		code;
			const char	*err;
929

Kurt Zeilenga's avatar
Kurt Zeilenga committed
930
931
932
933
934
935
936
937
			oc = ldap_str2objectclass( oc_map[i].ssom_defn, &code, &err,
				LDAP_SCHEMA_ALLOW_ALL );
			if ( !oc ) {
				fprintf( stderr, "slap_schema_load: "
					"%s: %s before %s\n",
				 	oc_map[i].ssom_name, ldap_scherr2str(code), err );
				return code;
			}
938

Kurt Zeilenga's avatar
Kurt Zeilenga committed
939
940
941
942
943
944
			if ( oc->oc_oid == NULL ) {
				fprintf( stderr, "slap_schema_load: "
					"%s: objectclass has no OID\n",
					oc_map[i].ssom_name );
				return LDAP_OTHER;
			}
945

946
			code = oc_add(oc,0,&err);
Kurt Zeilenga's avatar
Kurt Zeilenga committed
947
948
949
950
951
952
953
954
955
			if ( code ) {
				fprintf( stderr, "slap_schema_load: "
					"%s: %s: \"%s\"\n",
				 	oc_map[i].ssom_name, scherr2str(code), err);
				return code;
			}

			ldap_memfree(oc);
		}
956
957
958
		{
			ObjectClass ** ocp = (ObjectClass **)
				&(((char *) &slap_schema)[oc_map[i].ssom_offset]);
959

960
			assert( *ocp == NULL );
961

962
963
			*ocp = oc_find( oc_map[i].ssom_name );
			if( *ocp == NULL ) {
964
				fprintf( stderr, "slap_schema_load: "
965
966
967
968
					"No objectClass \"%s\" defined in schema\n",
					oc_map[i].ssom_name );
				return LDAP_OBJECT_CLASS_VIOLATION;
			}
969

970
971
972
973
974
975
			if( oc_map[i].ssom_check ) {
				/* install check routine */
				(*ocp)->soc_check = oc_map[i].ssom_check;
			}
			/* install flags */
			(*ocp)->soc_flags |= oc_map[i].ssom_flags;
976
977
978
		}
	}

979
	slap_at_undefined.sat_syntax = slap_schema.si_syn_distinguishedName;
980
981
	slap_schema.si_at_undefined = &slap_at_undefined;

982
983
	return LDAP_SUCCESS;
}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
984

985
986
987
988
989
int
slap_schema_check( void )
{
	/* we should only be called once after schema_init() was called */
	assert( schema_init_done == 1 );
990

991
992
993
994
995
996
997
	/*
	 * cycle thru attributeTypes to build matchingRuleUse
	 */
	if ( matching_rule_use_init() ) {
		return LDAP_OTHER;
	}

998
999
1000
	++schema_init_done;
	return LDAP_SUCCESS;
}
1001

Kurt Zeilenga's avatar
Kurt Zeilenga committed
1002
static int rootDseObjectClass (
1003
	Backend *be,
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1004
1005
1006
1007
1008
1009
	Entry *e,
	ObjectClass *oc,
	const char** text,
	char *textbuf, size_t textlen )
{
	*text = textbuf;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1010

Kurt Zeilenga's avatar
Kurt Zeilenga committed
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
	if( e->e_nname.bv_len ) {
		snprintf( textbuf, textlen,
			"objectClass \"%s\" only allowed in the root DSE",
			oc->soc_oid );
		return LDAP_OBJECT_CLASS_VIOLATION;
	}

	/* we should not be called for the root DSE */
	assert( 0 );
	return LDAP_SUCCESS;
}

1023
1024
1025
1026
1027
1028
1029
static int aliasObjectClass (
	Backend *be,
	Entry *e,
	ObjectClass *oc,
	const char** text,
	char *textbuf, size_t textlen )
{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1030
1031
	*text = textbuf;

1032
1033
1034
1035
1036
1037
	if( !SLAP_ALIASES(be) ) {
		snprintf( textbuf, textlen,
			"objectClass \"%s\" not supported in context",
			oc->soc_oid );
		return LDAP_OBJECT_CLASS_VIOLATION;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1038

1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
	return LDAP_SUCCESS;
}

static int referralObjectClass (
	Backend *be,
	Entry *e,
	ObjectClass *oc,
	const char** text,
	char *textbuf, size_t textlen )
{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1049
1050
	*text = textbuf;

1051
1052
1053
1054
1055
1056
	if( !SLAP_REFERRALS(be) ) {
		snprintf( textbuf, textlen,
			"objectClass \"%s\" not supported in context",
			oc->soc_oid );
		return LDAP_OBJECT_CLASS_VIOLATION;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1057

1058
1059
1060
	return LDAP_SUCCESS;
}

Kurt Zeilenga's avatar
Kurt Zeilenga committed
1061
static int subentryObjectClass (
1062
	Backend *be,
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1063
1064
1065
1066
1067
	Entry *e,
	ObjectClass *oc,
	const char** text,
	char *textbuf, size_t textlen )
{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1068
1069
	*text = textbuf;

1070
1071
1072
1073
1074
1075
1076
1077
	if( !SLAP_SUBENTRIES(be) ) {
		snprintf( textbuf, textlen,
			"objectClass \"%s\" not supported in context",
			oc->soc_oid );
		return LDAP_OBJECT_CLASS_VIOLATION;
	}

	if( oc != slap_schema.si_oc_subentry && !is_entry_subentry( e ) ) {
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1078
1079
1080
1081
1082
		snprintf( textbuf, textlen,
			"objectClass \"%s\" only allowed in subentries",
			oc->soc_oid );
		return LDAP_OBJECT_CLASS_VIOLATION;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1083

Kurt Zeilenga's avatar
Kurt Zeilenga committed
1084
1085
1086
	return LDAP_SUCCESS;
}

1087
1088
1089
1090
1091
1092
1093
static int dynamicObjectClass (
	Backend *be,
	Entry *e,
	ObjectClass *oc,
	const char** text,
	char *textbuf, size_t textlen )
{
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1094
1095
	*text = textbuf;

1096
1097
1098
1099
1100
1101
	if( !SLAP_DYNAMIC(be) ) {
		snprintf( textbuf, textlen,
			"objectClass \"%s\" not supported in context",
			oc->soc_oid );
		return LDAP_OBJECT_CLASS_VIOLATION;
	}
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1102

1103
1104
1105
	return LDAP_SUCCESS;
}

1106
static int rootDseAttribute (
1107
	Backend *be,
1108
1109
1110
1111
1112
1113
	Entry *e,
	Attribute *attr,
	const char** text,
	char *textbuf, size_t textlen )
{
	*text = textbuf;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1114

1115
1116
	if( e->e_nname.bv_len ) {
		snprintf( textbuf, textlen,
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1117
			"attribute \"%s\" only allowed in the root DSE",
1118
1119
1120
1121
1122
1123
1124
1125
1126
			attr->a_desc->ad_cname.bv_val );
		return LDAP_OBJECT_CLASS_VIOLATION;
	}

	/* we should not be called for the root DSE */
	assert( 0 );
	return LDAP_SUCCESS;
}

Kurt Zeilenga's avatar
Kurt Zeilenga committed
1127
static int aliasAttribute (
1128
	Backend *be,
1129
1130
1131
1132
1133
1134
	Entry *e,
	Attribute *attr,
	const char** text,
	char *textbuf, size_t textlen )
{
	*text = textbuf;
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1135
1136

	if( !SLAP_ALIASES(be) ) {
1137
		snprintf( textbuf, textlen,
Kurt Zeilenga's avatar
Kurt Zeilenga committed
1138
1139
1140
1141
1142
1143
1144
1145
			"attribute \"%s\" not supported in context",
			attr->a_desc->ad_cname.bv_val );
		return LDAP_OBJECT_CLASS_VIOLATION;
	}

	if( !is_entry_alias( e ) ) {
		snprintf( textbuf, textlen,
			"attribute \"