schema_prep.c 36.4 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
				if( bvmatch( &ocvalues[k], &sup->soc_cname ) ) {
181
182
183
184
					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
		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 "
453
			"ORDERING octetStringOrderingMatch "
454
455
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{64} "
			"SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )",
456
457
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
458
459
		offsetof(struct slap_internal_schema, si_ad_entryCSN) },

460
	/* root DSE attributes */
461
462
463
	{ "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 )",
464
465
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
466
		offsetof(struct slap_internal_schema, si_ad_altServer) },
467
468
469
470
	{ "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 )",
471
472
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
473
		offsetof(struct slap_internal_schema, si_ad_namingContexts) },
474
475
	{ "supportedControl", "( 1.3.6.1.4.1.1466.101.120.13 "
			"NAME 'supportedControl' "
Kurt Zeilenga's avatar
Kurt Zeilenga committed
476
477
			"DESC 'RFC2252: supported controls' "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 USAGE dSAOperation )",
478
479
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
480
		offsetof(struct slap_internal_schema, si_ad_supportedControl) },
481
482
483
484
	{ "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 )",
485
486
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
487
		offsetof(struct slap_internal_schema, si_ad_supportedExtension) },
488
489
490
491
	{ "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 )",
492
493
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
494
		offsetof(struct slap_internal_schema, si_ad_supportedLDAPVersion) },
495
496
497
498
	{ "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 )",
499
500
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
501
		offsetof(struct slap_internal_schema, si_ad_supportedSASLMechanisms) },
502
503
504
505
506
507
	{ "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 )",
508
509
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
510
		offsetof(struct slap_internal_schema, si_ad_supportedFeatures) },
511
512
513
514
515
516
517
	{ "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 )",
518
519
		rootDseAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
520
		offsetof(struct slap_internal_schema, si_ad_monitorContext) },
521
522
	{ "vendorName", "( 1.3.6.1.1.4 NAME 'vendorName' "
			"DESC 'RFC3045: name of implementation vendor' "
523
			"EQUALITY caseExactMatch "
524
525
526
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
			"SINGLE-VALUE NO-USER-MODIFICATION "
			"USAGE dSAOperation )",
527
528
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
529
530
531
		offsetof(struct slap_internal_schema, si_ad_vendorName) },
	{ "vendorVersion", "( 1.3.6.1.1.5 NAME 'vendorVersion' "
			"DESC 'RFC3045: version of implementation' "
532
			"EQUALITY caseExactMatch "
533
534
535
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
			"SINGLE-VALUE NO-USER-MODIFICATION "
			"USAGE dSAOperation )",
536
537
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
538
539
540
541
542
543
544
		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 )",
545
546
		administrativeRoleAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
547
548
549
550
551
		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 )",
552
553
		subentryAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
554
		offsetof(struct slap_internal_schema, si_ad_subtreeSpecification) },
555

556
	/* subschema subentry attributes */
557
558
559
560
561
	{ "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 ) ",
562
563
		subentryAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
564
565
566
567
568
		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 )",
569
570
		subentryAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
571
		offsetof(struct slap_internal_schema, si_ad_ditContentRules) },
572
573
574
575
	{ "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 )",
576
577
		subentryAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
578
		offsetof(struct slap_internal_schema, si_ad_matchingRules) },
579
580
581
582
	{ "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 )",
583
584
		subentryAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
585
586
587
588
589
		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 )",
590
591
		subentryAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
592
		offsetof(struct slap_internal_schema, si_ad_objectClasses) },
593
594
595
596
	{ "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 )",
597
598
		subentryAttribute, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
599
		offsetof(struct slap_internal_schema, si_ad_nameForms) },
600
	{ "matchingRuleUse", "( 2.5.21.8 NAME 'matchingRuleUse' "
601
602
603
			"DESC 'RFC2252: matching rule uses' "
			"EQUALITY objectIdentifierFirstComponentMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.31 USAGE directoryOperation )",
604
		subentryAttribute, 0,
605
		NULL, NULL, NULL, NULL, NULL,
606
		offsetof(struct slap_internal_schema, si_ad_matchingRuleUse) },
607

608
609
610
611
	{ "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 )",
612
613
		subentryAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
614
615
		offsetof(struct slap_internal_schema, si_ad_ldapSyntaxes) },

616
	/* knowledge information */
617
618
619
620
621
	{ "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 )",
622
623
		aliasAttribute, SLAP_AT_FINAL,
		NULL, NULL, NULL, NULL, NULL,
624
		offsetof(struct slap_internal_schema, si_ad_aliasedObjectName) },
625
626
627
628
629
	{ "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 )",
630
631
		referralAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
632
633
		offsetof(struct slap_internal_schema, si_ad_ref) },

Kurt Zeilenga's avatar
Kurt Zeilenga committed
634
	/* access control internals */
635
636
637
638
639
	{ "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 )",
640
641
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
642
		offsetof(struct slap_internal_schema, si_ad_entry) },
643
644
645
646
647
	{ "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 )",
648
649
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
650
		offsetof(struct slap_internal_schema, si_ad_children) },
651
	{ "saslAuthzTo", "( 1.3.6.1.4.1.4203.666.1.8 "
652
653
654
655
			"NAME 'saslAuthzTo' "
			"DESC 'SASL proxy authorization targets' "
			"EQUALITY caseExactMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
656
			"USAGE distributedOperation )",
657
658
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
659
		offsetof(struct slap_internal_schema, si_ad_saslAuthzTo) },
660
	{ "saslAuthzFrom", "( 1.3.6.1.4.1.4203.666.1.9 "
661
662
663
664
			"NAME 'saslAuthzFrom' "
			"DESC 'SASL proxy authorization sources' "
			"EQUALITY caseExactMatch "
			"SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 "
665
			"USAGE distributedOperation )",
666
667
		NULL, SLAP_AT_HIDE,
		NULL, NULL, NULL, NULL, NULL,
668
		offsetof(struct slap_internal_schema, si_ad_saslAuthzFrom) },
669
#ifdef SLAPD_ACI_ENABLED
670
671
672
673
674
675
	{ "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 )",
676
677
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
678
679
		offsetof(struct slap_internal_schema, si_ad_aci) },
#endif
680

681
682
683
684
	{ "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 )",
685
686
		dynamicAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
687
688
689
690
691
692
		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 )",
693
694
		rootDseAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
695
696
		offsetof(struct slap_internal_schema, si_ad_dynamicSubtrees) },

697
	/* userApplication attributes (which system schema depends upon) */
698
699
700
701
	{ "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 )",
702
703
		NULL, SLAP_AT_ABSTRACT,
		NULL, NULL, NULL, NULL, NULL,
704
		offsetof(struct slap_internal_schema, si_ad_distinguishedName) },
705
706
707
708
709
	{ "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} )",
710
711
		NULL, SLAP_AT_ABSTRACT,
		NULL, NULL, NULL, NULL, NULL,
712
713
714
715
		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 )",
716
717
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
718
719
720
721
722
		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} )",
723
724
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
725
		offsetof(struct slap_internal_schema, si_ad_userPassword) },
726
727

#ifdef SLAPD_AUTHPASSWD
728
729
730
731
732
	{ "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 )",
733
		NULL, 0,
734
		NULL, NULL, NULL, NULL, NULL,
735
736
737
738
739
740
741
		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 )",
742
743
		subschemaAttribute, 0,
		NULL, NULL, NULL, NULL, NULL,
744
		offsetof(struct slap_internal_schema, si_ad_authPassword) },
745
#endif
746
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND
747
748
749
750
751
752
	{ "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 )",
753
754
		NULL, 0,
		NULL, NULL, NULL, NULL, NULL,
755
756
757
		offsetof(struct slap_internal_schema, si_ad_krbName) },
#endif

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

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

Kurt Zeilenga's avatar
Kurt Zeilenga committed
777
static struct slap_schema_mr_map {
778
779
780
781
782
783
784
785
786
787
	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
788
static struct slap_schema_syn_map {
789
790
791
	char *sssm_name;
	size_t sssm_offset;
} syn_map[] = {
792
793
	{ "1.3.6.1.4.1.1466.115.121.1.40",
		offsetof(struct slap_internal_schema, si_syn_octetString) },
794
795
796
797
798
799
800
	{ "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 }
};

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

	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 ) {
815
			fprintf( stderr, "slap_schema_load: Syntax: "
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
				"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 ) {
831
			fprintf( stderr, "slap_schema_load: MatchingRule: "
832
833
834
835
836
837
				"No matching rule \"%s\" defined in schema\n",
				mr_map[i].ssmm_name );
			return LDAP_INAPPROPRIATE_MATCHING;
		}
	}

838
	for( i=0; ad_map[i].ssam_name; i++ ) {
839
840
		assert( ad_map[i].ssam_defn != NULL );
		{
841
842
843
844
845
846
847
848
			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,
849
					"slap_schema_load: AttributeType \"%s\": %s before %s\n",
850
851
852
853
854
855
					 ad_map[i].ssam_name, ldap_scherr2str(code), err );
				return code;
			}

			if ( at->at_oid == NULL ) {
				fprintf( stderr, "slap_schema_load: "
856
					"AttributeType \"%s\": no OID\n",
857
858
859
860
861
862
					ad_map[i].ssam_name );
				return LDAP_OTHER;
			}

			code = at_add( at, &err );
			if ( code ) {
863
864
				fprintf( stderr, "slap_schema_load: AttributeType "
					"\"%s\": %s: \"%s\"\n",
865
866
867
868
869
					 ad_map[i].ssam_name, scherr2str(code), err );
				return code;
			}
			ldap_memfree( at );
		}
870
871
872
873
874
875
876
877
878
879
880
		{
			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 ) {
881
882
				fprintf( stderr, "slap_schema_load: AttributeType \"%s\": "
					"not defined in schema\n",
883
884
885
886
887
888
889
890
891
892
893
					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;

894
			/* install custom rule routine */
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
			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;
				}
920
921
			}
		}
922
	}
923
924

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

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

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

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

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

961
			assert( *ocp == NULL );
962

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

971
972
973
974
975
976
			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;
977
978
979
		}
	}

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

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

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

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

999
1000
	++schema_init_done;
	return LDAP_SUCCESS;
For faster browsing, not all history is shown. View entire blame