1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
24 /* any value allowed */
35 unsigned char *u = in->bv_val;
37 for( count = in->bv_len; count > 0; count+=len, u+=len ) {
38 /* get the length indicated by the first byte */
39 len = LDAP_UTF8_CHARLEN( u );
41 /* should not be zero */
42 if( len == 0 ) return -1;
44 /* make sure len corresponds with the offset
45 to the next character */
46 if( LDAP_UTF8_OFFSET( u ) != len ) return -1;
49 if( count != 0 ) return -1;
59 struct berval **normalized )
61 struct berval *newval;
64 newval = ch_malloc( sizeof( struct berval ) );
68 /* Ignore initial whitespace */
69 while ( ldap_utf8_isspace( p ) ) {
78 newval->bv_val = ch_strdup( p );
79 p = q = newval->bv_val;
85 if ( ldap_utf8_isspace( p ) ) {
86 len = LDAP_UTF8_COPY(q,p);
91 /* Ignore the extra whitespace */
92 while ( ldap_utf8_isspace( p ) ) {
96 len = LDAP_UTF8_COPY(q,p);
103 assert( *newval->bv_val );
104 assert( newval->bv_val < p );
107 /* cannot start with a space */
108 assert( !ldap_utf8_isspace(newval->bv_val) );
111 * If the string ended in space, backup the pointer one
112 * position. One is enough because the above loop collapsed
113 * all whitespace to a single space.
120 /* cannot end with a space */
121 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
126 newval->bv_len = q - newval->bv_val;
127 normalized = &newval;
139 for(i=0; i < val->bv_len; i++) {
140 if( !isascii(val->bv_val[i]) ) return -1;
150 struct berval **out )
153 struct berval *bv = ch_malloc( sizeof(struct berval) );
154 bv->bv_len = (in->bv_len+1) * sizeof( ldap_unicode_t );
155 bv->bv_val = ch_malloc( bv->bv_len );
157 for(i=0; i < in->bv_len; i++ ) {
159 * IA5StringValidate should have been called to ensure
160 * input is limited to IA5.
162 bv->bv_val[i] = in->bv_val[i];
174 struct berval **normalized )
176 struct berval *newval;
179 newval = ch_malloc( sizeof( struct berval ) );
183 /* Ignore initial whitespace */
184 while ( isspace( *p++ ) ) {
193 newval->bv_val = ch_strdup( p );
194 p = q = newval->bv_val;
197 if ( isspace( *p ) ) {
200 /* Ignore the extra whitespace */
201 while ( isspace( *p++ ) ) {
209 assert( *newval->bv_val );
210 assert( newval->bv_val < p );
213 /* cannot start with a space */
214 assert( !isspace(*newval->bv_val) );
217 * If the string ended in space, backup the pointer one
218 * position. One is enough because the above loop collapsed
219 * all whitespace to a single space.
222 if ( isspace( q[-1] ) ) {
226 /* cannot end with a space */
227 assert( !isspace( q[-1] ) );
232 newval->bv_len = q - newval->bv_val;
233 normalized = &newval;
242 struct berval *value,
243 struct berval *assertedValue )
245 return strcmp( value->bv_val, assertedValue->bv_val );
252 struct berval *value,
253 struct berval *assertedValue )
255 return strcasecmp( value->bv_val, assertedValue->bv_val );
258 struct syntax_defs_rec {
261 slap_syntax_validate_func *sd_validate;
262 slap_syntax_transform_func *sd_ber2str;
263 slap_syntax_transform_func *sd_str2ber;
266 struct syntax_defs_rec syntax_defs[] = {
267 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'AttributeTypeDescription' )",
268 0, NULL, NULL, NULL},
269 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' )",
270 0, NULL, NULL, NULL},
271 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' )",
274 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'BitString' )",
275 0, NULL, NULL, NULL},
276 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
277 0, NULL, NULL, NULL},
278 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' )",
281 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'CertificateList' )",
284 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'CertificatePair' )",
287 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )",
288 0, NULL, NULL, NULL},
289 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'DeliveryMethod' )",
290 0, NULL, NULL, NULL},
291 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'DirectoryString' )",
292 0, UTF8StringValidate, NULL, NULL},
293 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DITContentRuleDescription' )",
294 0, NULL, NULL, NULL},
295 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DITStructureRuleDescription' )",
296 0, NULL, NULL, NULL},
297 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'EnhancedGuide' )",
298 0, NULL, NULL, NULL},
299 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'FacsimileTelephoneNumber' )",
300 0, NULL, NULL, NULL},
301 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'GeneralizedTime' )",
302 0, NULL, NULL, NULL},
303 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
304 0, NULL, NULL, NULL},
305 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5String' )",
306 0, IA5StringValidate, NULL, NULL},
307 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
308 0, NULL, NULL, NULL},
309 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' )",
310 0, NULL, NULL, NULL},
311 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'MatchingRuleDescription' )",
312 0, NULL, NULL, NULL},
313 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'MatchingRuleUseDescription' )",
314 0, NULL, NULL, NULL},
315 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'MailPreference' )",
316 0, NULL, NULL, NULL},
317 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'NameAndOptionalUID' )",
318 0, NULL, NULL, NULL},
319 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'NameFormDescription' )",
320 0, NULL, NULL, NULL},
321 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'NumericString' )",
322 0, NULL, NULL, NULL},
323 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'ObjectClassDescription' )",
324 0, NULL, NULL, NULL},
325 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
326 0, NULL, NULL, NULL},
327 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'OtherMailbox' )",
328 0, NULL, NULL, NULL},
329 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'OctetString' )",
330 0, octetStringValidate, NULL, NULL},
331 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'PostalAddress' )",
332 0, NULL, NULL, NULL},
333 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'ProtocolInformation' )",
334 0, NULL, NULL, NULL},
335 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'PresentationAddress' )",
336 0, NULL, NULL, NULL},
337 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'PrintableString' )",
338 0, NULL, NULL, NULL},
339 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'SupportedAlgorithm' )",
340 SLAP_SYNTAX_BINARY, NULL, NULL, NULL},
341 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'TelephoneNumber' )",
342 0, NULL, NULL, NULL},
343 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'TeletexTerminalIdentifier' )",
344 0, NULL, NULL, NULL},
345 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'TelexNumber' )",
346 0, NULL, NULL, NULL},
347 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTCTime' )",
348 0, NULL, NULL, NULL},
349 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAPSyntaxDescription' )",
350 0, NULL, NULL, NULL},
351 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'SubstringAssertion' )",
352 0, NULL, NULL, NULL},
354 {NULL, 0, NULL, NULL, NULL}
357 struct mrule_defs_rec {
359 slap_mr_convert_func * mrd_convert;
360 slap_mr_normalize_func * mrd_normalize;
361 slap_mr_match_func * mrd_match;
362 slap_mr_indexer_func * mrd_indexer;
363 slap_mr_filter_func * mrd_filter;
367 * Other matching rules in X.520 that we do not use:
369 * 2.5.13.9 numericStringOrderingMatch
370 * 2.5.13.12 caseIgnoreListSubstringsMatch
371 * 2.5.13.13 booleanMatch
372 * 2.5.13.15 integerOrderingMatch
373 * 2.5.13.18 octetStringOrderingMatch
374 * 2.5.13.19 octetStringSubstringsMatch
375 * 2.5.13.25 uTCTimeMatch
376 * 2.5.13.26 uTCTimeOrderingMatch
377 * 2.5.13.31 directoryStringFirstComponentMatch
378 * 2.5.13.32 wordMatch
379 * 2.5.13.33 keywordMatch
380 * 2.5.13.34 certificateExactMatch
381 * 2.5.13.35 certificateMatch
382 * 2.5.13.36 certificatePairExactMatch
383 * 2.5.13.37 certificatePairMatch
384 * 2.5.13.38 certificateListExactMatch
385 * 2.5.13.39 certificateListMatch
386 * 2.5.13.40 algorithmIdentifierMatch
387 * 2.5.13.41 storedPrefixMatch
388 * 2.5.13.42 attributeCertificateMatch
389 * 2.5.13.43 readerAndKeyIDMatch
390 * 2.5.13.44 attributeIntegrityMatch
393 /* recycled matching functions */
394 #define caseIgnoreMatch caseIgnoreIA5Match
395 #define caseExactMatch caseExactIA5Match
397 /* unimplemented matching functions */
398 #define objectIdentifierMatch NULL
399 #define distinguishedNameMatch NULL
400 #define caseIgnoreOrderingMatch NULL
401 #define caseIgnoreSubstringsMatch NULL
402 #define caseExactOrderingMatch NULL
403 #define caseExactSubstringsMatch NULL
404 #define numericStringMatch NULL
405 #define numericStringSubstringsMatch NULL
406 #define caseIgnoreListMatch NULL
407 #define integerMatch NULL
408 #define bitStringMatch NULL
409 #define octetStringMatch NULL
410 #define telephoneNumberMatch NULL
411 #define telephoneNumberSubstringsMatch NULL
412 #define presentationAddressMatch NULL
413 #define uniqueMemberMatch NULL
414 #define protocolInformationMatch NULL
415 #define generalizedTimeMatch NULL
416 #define generalizedTimeOrderingMatch NULL
417 #define integerFirstComponentMatch NULL
418 #define objectIdentifierFirstComponentMatch NULL
419 #define caseIgnoreIA5SubstringsMatch NULL
421 struct mrule_defs_rec mrule_defs[] = {
422 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
423 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
424 NULL, NULL, objectIdentifierMatch, NULL, NULL},
426 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
427 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
428 NULL, NULL, distinguishedNameMatch, NULL, NULL},
430 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
431 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
432 NULL, UTF8StringNormalize, caseIgnoreMatch, NULL, NULL},
434 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
435 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
436 NULL, UTF8StringNormalize, caseIgnoreOrderingMatch, NULL, NULL},
438 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
439 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
440 NULL, UTF8StringNormalize, caseIgnoreSubstringsMatch, NULL, NULL},
442 /* Next three are not in the RFC's, but are needed for compatibility */
443 {"( 2.5.13.5 NAME 'caseExactMatch' "
444 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
445 NULL, UTF8StringNormalize, caseExactMatch, NULL, NULL},
447 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
448 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
449 NULL, UTF8StringNormalize, caseExactOrderingMatch, NULL, NULL},
451 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
452 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
453 NULL, UTF8StringNormalize, caseExactSubstringsMatch, NULL, NULL},
455 {"( 2.5.13.8 NAME 'numericStringMatch' "
456 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
457 NULL, NULL, numericStringMatch, NULL, NULL},
459 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
460 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
461 NULL, NULL, numericStringSubstringsMatch, NULL, NULL},
463 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
464 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
465 NULL, NULL, caseIgnoreListMatch, NULL, NULL},
467 {"( 2.5.13.14 NAME 'integerMatch' "
468 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
469 NULL, NULL, integerMatch, NULL, NULL},
471 {"( 2.5.13.16 NAME 'bitStringMatch' "
472 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
473 NULL, NULL, bitStringMatch, NULL, NULL},
475 {"( 2.5.13.17 NAME 'octetStringMatch' "
476 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
477 NULL, NULL, octetStringMatch, NULL, NULL},
479 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
480 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
481 NULL, NULL, telephoneNumberMatch, NULL, NULL},
483 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
484 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
485 NULL, NULL, telephoneNumberSubstringsMatch, NULL, NULL},
487 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
488 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
489 NULL, NULL, presentationAddressMatch, NULL, NULL},
491 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
492 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
493 NULL, NULL, uniqueMemberMatch, NULL, NULL},
495 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
496 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
497 NULL, NULL, protocolInformationMatch, NULL, NULL},
499 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
500 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
501 NULL, NULL, generalizedTimeMatch, NULL, NULL},
503 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
504 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
505 NULL, NULL, generalizedTimeOrderingMatch, NULL, NULL},
507 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
508 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
509 NULL, NULL, integerFirstComponentMatch, NULL, NULL},
511 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
512 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
513 NULL, NULL, objectIdentifierFirstComponentMatch, NULL, NULL},
515 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
516 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
517 NULL, IA5StringNormalize, caseExactIA5Match, NULL, NULL},
519 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
520 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
521 NULL, IA5StringNormalize, caseIgnoreIA5Match, NULL, NULL},
523 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
524 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
525 NULL, IA5StringNormalize, caseIgnoreIA5SubstringsMatch, NULL, NULL},
527 {NULL, NULL, NULL, NULL}
535 static int schema_init_done = 0;
537 /* We are called from read_config that is recursive */
538 if ( schema_init_done )
541 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
542 res = register_syntax( syntax_defs[i].sd_desc,
543 syntax_defs[i].sd_flags,
544 syntax_defs[i].sd_validate,
545 syntax_defs[i].sd_ber2str,
546 syntax_defs[i].sd_str2ber );
549 fprintf( stderr, "schema_init: Error registering syntax %s\n",
550 syntax_defs[i].sd_desc );
551 exit( EXIT_FAILURE );
555 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
556 res = register_matching_rule(
557 mrule_defs[i].mrd_desc,
558 mrule_defs[i].mrd_convert,
559 mrule_defs[i].mrd_normalize,
560 mrule_defs[i].mrd_match,
561 mrule_defs[i].mrd_indexer,
562 mrule_defs[i].mrd_filter );
566 "schema_init: Error registering matching rule %s\n",
567 mrule_defs[i].mrd_desc );
568 exit( EXIT_FAILURE );
571 schema_init_done = 1;