1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
18 #include "lutil_md5.h"
29 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
32 match = memcmp( value->bv_val,
33 ((struct berval *) assertedValue)->bv_val,
41 /* Index generation function */
42 int octetStringIndexer(
46 struct berval *prefix,
47 struct berval **values,
48 struct berval ***keysp )
53 lutil_MD5_CTX MD5context;
54 unsigned char MD5digest[16];
56 digest.bv_val = MD5digest;
57 digest.bv_len = sizeof(MD5digest);
59 for( i=0; values[i] != NULL; i++ ) {
65 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
67 slen = strlen( syntax->ssyn_oid );
68 mlen = strlen( mr->smr_oid );
70 for( i=0; values[i] != NULL; i++ ) {
71 lutil_MD5Init( &MD5context );
72 if( prefix != NULL && prefix->bv_len > 0 ) {
73 lutil_MD5Update( &MD5context,
74 prefix->bv_val, prefix->bv_len );
76 lutil_MD5Update( &MD5context,
77 syntax->ssyn_oid, slen );
78 lutil_MD5Update( &MD5context,
80 lutil_MD5Update( &MD5context,
81 values[i]->bv_val, values[i]->bv_len );
82 lutil_MD5Final( MD5digest, &MD5context );
84 keys[i] = ber_bvdup( &digest );
94 /* Index generation function */
95 int octetStringFilter(
99 struct berval *prefix,
101 struct berval ***keysp )
104 struct berval **keys;
105 lutil_MD5_CTX MD5context;
106 unsigned char MD5digest[LUTIL_MD5_BYTES];
107 struct berval *value = (struct berval *) assertValue;
108 struct berval digest;
109 digest.bv_val = MD5digest;
110 digest.bv_len = sizeof(MD5digest);
112 slen = strlen( syntax->ssyn_oid );
113 mlen = strlen( mr->smr_oid );
115 keys = ch_malloc( sizeof( struct berval * ) * 2 );
117 lutil_MD5Init( &MD5context );
118 if( prefix != NULL && prefix->bv_len > 0 ) {
119 lutil_MD5Update( &MD5context,
120 prefix->bv_val, prefix->bv_len );
122 lutil_MD5Update( &MD5context,
123 syntax->ssyn_oid, slen );
124 lutil_MD5Update( &MD5context,
126 lutil_MD5Update( &MD5context,
127 value->bv_val, value->bv_len );
128 lutil_MD5Final( MD5digest, &MD5context );
130 keys[0] = ber_bvdup( &digest );
146 if( in->bv_len == 0 ) return LDAP_SUCCESS;
148 dn = ch_strdup( in->bv_val );
150 rc = dn_validate( dn ) == NULL
151 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
161 struct berval **normalized )
163 struct berval *out = ber_bvdup( val );
165 if( out->bv_len != 0 ) {
167 #ifdef USE_DN_NORMALIZE
168 dn = dn_normalize( out->bv_val );
170 dn = dn_validate( out->bv_val );
175 return LDAP_INVALID_SYNTAX;
179 out->bv_len = strlen( dn );
192 struct berval *value,
193 void *assertedValue )
196 struct berval *asserted = (struct berval *) assertedValue;
198 match = value->bv_len - asserted->bv_len;
201 #ifdef USE_DN_NORMALIZE
202 match = strcmp( value->bv_val, asserted->bv_val );
204 match = strcasecmp( value->bv_val, asserted->bv_val );
208 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
209 match, value->bv_val, asserted->bv_val );
220 /* any value allowed */
229 /* any value allowed */
233 #define berValidate blobValidate
242 unsigned char *u = in->bv_val;
244 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
245 /* get the length indicated by the first byte */
246 len = LDAP_UTF8_CHARLEN( u );
248 /* should not be zero */
249 if( len == 0 ) return LDAP_INVALID_SYNTAX;
251 /* make sure len corresponds with the offset
252 to the next character */
253 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
256 if( count != 0 ) return LDAP_INVALID_SYNTAX;
265 struct berval **normalized )
267 struct berval *newval;
270 newval = ch_malloc( sizeof( struct berval ) );
274 /* Ignore initial whitespace */
275 while ( ldap_utf8_isspace( p ) ) {
281 return LDAP_INVALID_SYNTAX;
284 newval->bv_val = ch_strdup( p );
285 p = q = newval->bv_val;
291 if ( ldap_utf8_isspace( p ) ) {
292 len = LDAP_UTF8_COPY(q,p);
297 /* Ignore the extra whitespace */
298 while ( ldap_utf8_isspace( p ) ) {
302 len = LDAP_UTF8_COPY(q,p);
309 assert( *newval->bv_val );
310 assert( newval->bv_val < p );
313 /* cannot start with a space */
314 assert( !ldap_utf8_isspace(newval->bv_val) );
317 * If the string ended in space, backup the pointer one
318 * position. One is enough because the above loop collapsed
319 * all whitespace to a single space.
326 /* cannot end with a space */
327 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
332 newval->bv_len = q - newval->bv_val;
333 *normalized = newval;
345 if( val->bv_len == 0 ) return 0;
347 if( isdigit(val->bv_val[0]) ) {
349 for(i=1; i < val->bv_len; i++) {
350 if( val->bv_val[i] == '.' ) {
351 if( dot++ ) return 1;
352 } else if ( isdigit(val->bv_val[i]) ) {
355 return LDAP_INVALID_SYNTAX;
359 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
361 } else if( isalpha(val->bv_val[0]) ) {
362 for(i=1; i < val->bv_len; i++) {
363 if( !isalpha(val->bv_val[i] ) ) {
364 return LDAP_INVALID_SYNTAX;
371 return LDAP_INVALID_SYNTAX;
381 for(i=0; i < val->bv_len; i++) {
382 if( !isdigit(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
389 printableStringValidate(
395 for(i=0; i < val->bv_len; i++) {
396 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
409 for(i=0; i < val->bv_len; i++) {
410 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
420 struct berval **out )
423 ber_len_t i, len = in->bv_len;
424 struct berval *bv = ch_malloc( sizeof(struct berval) );
426 bv->bv_len = len * sizeof( ldap_unicode_t );
427 bv->bv_val = (char *) u = ch_malloc( bv->bv_len + sizeof( ldap_unicode_t ) );;
429 for(i=0; i < len; i++ ) {
431 * IA5StringValidate should have been called to ensure
432 * input is limited to IA5.
434 u[i] = in->bv_val[i];
446 struct berval **normalized )
448 struct berval *newval;
451 newval = ch_malloc( sizeof( struct berval ) );
455 /* Ignore initial whitespace */
456 while ( isspace( *p ) ) {
462 return LDAP_INVALID_SYNTAX;
465 newval->bv_val = ch_strdup( p );
466 p = q = newval->bv_val;
469 if ( isspace( *p ) ) {
472 /* Ignore the extra whitespace */
473 while ( isspace( *p ) ) {
481 assert( *newval->bv_val );
482 assert( newval->bv_val < p );
485 /* cannot start with a space */
486 assert( !isspace(*newval->bv_val) );
489 * If the string ended in space, backup the pointer one
490 * position. One is enough because the above loop collapsed
491 * all whitespace to a single space.
494 if ( isspace( q[-1] ) ) {
498 /* cannot end with a space */
499 assert( !isspace( q[-1] ) );
504 newval->bv_len = q - newval->bv_val;
505 *normalized = newval;
516 struct berval *value,
517 void *assertedValue )
519 *match = strcmp( value->bv_val,
520 ((struct berval *) assertedValue)->bv_val );
525 caseExactIA5SubstringsMatch(
530 struct berval *value,
531 void *assertedValue )
534 SubstringsAssertion *sub = assertedValue;
535 struct berval left = *value;
539 /* Add up asserted input length */
540 if( sub->sa_initial ) {
541 inlen += sub->sa_initial->bv_len;
544 for(i=0; sub->sa_any[i] != NULL; i++) {
545 inlen += sub->sa_any[i]->bv_len;
548 if( sub->sa_final ) {
549 inlen += sub->sa_final->bv_len;
552 if( inlen > left.bv_len ) {
557 if( sub->sa_initial ) {
558 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
559 sub->sa_initial->bv_len );
565 left.bv_val += sub->sa_initial->bv_len;
566 left.bv_len -= sub->sa_initial->bv_len;
567 inlen -= sub->sa_initial->bv_len;
569 if( inlen > left.bv_len ) {
575 if( sub->sa_final ) {
576 match = strncmp( sub->sa_final->bv_val,
577 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
578 sub->sa_final->bv_len );
584 left.bv_len -= sub->sa_final->bv_len;
585 inlen -= sub->sa_final->bv_len;
587 if( inlen > left.bv_len ) {
594 for(i=0; sub->sa_any[i]; i++) {
599 if( sub->sa_any[i]->bv_len == 0 ) {
603 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
610 idx = p - left.bv_val;
611 assert( idx < left.bv_len );
613 if( idx >= left.bv_len ) {
614 /* this shouldn't happen */
621 if( sub->sa_any[i]->bv_len > left.bv_len ) {
622 /* not enough left */
627 match = strncmp( left.bv_val,
628 sub->sa_any[i]->bv_val,
629 sub->sa_any[i]->bv_len );
635 left.bv_val += sub->sa_any[i]->bv_len;
636 left.bv_len -= sub->sa_any[i]->bv_len;
637 inlen -= sub->sa_any[i]->bv_len;
639 if( inlen > left.bv_len ) {
640 /* not enough length */
658 struct berval *value,
659 void *assertedValue )
661 *match = strcasecmp( value->bv_val,
662 ((struct berval *) assertedValue)->bv_val );
666 static char *strcasechr( const char *str, int c )
668 char *lower = strchr( str, TOLOWER(c) );
669 char *upper = strchr( str, TOUPPER(c) );
671 if( lower && upper ) {
672 return lower < upper ? lower : upper;
673 } else if ( lower ) {
681 caseIgnoreIA5SubstringsMatch(
686 struct berval *value,
687 void *assertedValue )
690 SubstringsAssertion *sub = assertedValue;
691 struct berval left = *value;
695 /* Add up asserted input length */
696 if( sub->sa_initial ) {
697 inlen += sub->sa_initial->bv_len;
700 for(i=0; sub->sa_any[i] != NULL; i++) {
701 inlen += sub->sa_any[i]->bv_len;
704 if( sub->sa_final ) {
705 inlen += sub->sa_final->bv_len;
708 if( inlen > left.bv_len ) {
713 if( sub->sa_initial ) {
714 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
715 sub->sa_initial->bv_len );
721 left.bv_val += sub->sa_initial->bv_len;
722 left.bv_len -= sub->sa_initial->bv_len;
723 inlen -= sub->sa_initial->bv_len;
725 if( inlen > left.bv_len ) {
731 if( sub->sa_final ) {
732 match = strncasecmp( sub->sa_final->bv_val,
733 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
734 sub->sa_final->bv_len );
740 left.bv_len -= sub->sa_final->bv_len;
741 inlen -= sub->sa_final->bv_len;
743 if( inlen > left.bv_len ) {
750 for(i=0; sub->sa_any[i]; i++) {
755 if( sub->sa_any[i]->bv_len == 0 ) {
759 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
766 idx = p - left.bv_val;
767 assert( idx < left.bv_len );
769 if( idx >= left.bv_len ) {
770 /* this shouldn't happen */
777 if( sub->sa_any[i]->bv_len > left.bv_len ) {
778 /* not enough left */
783 match = strncasecmp( left.bv_val,
784 sub->sa_any[i]->bv_val,
785 sub->sa_any[i]->bv_len );
791 left.bv_val += sub->sa_any[i]->bv_len;
792 left.bv_len -= sub->sa_any[i]->bv_len;
793 inlen -= sub->sa_any[i]->bv_len;
795 if( inlen > left.bv_len ) {
796 /* not enough length */
808 /* Index generation function */
809 int caseIgnoreIA5Indexer(
813 struct berval *prefix,
814 struct berval **values,
815 struct berval ***keysp )
819 struct berval **keys;
820 lutil_MD5_CTX MD5context;
821 unsigned char MD5digest[16];
822 struct berval digest;
823 digest.bv_val = MD5digest;
824 digest.bv_len = sizeof(MD5digest);
826 for( i=0; values[i] != NULL; i++ ) {
827 /* just count them */
832 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
834 slen = strlen( syntax->ssyn_oid );
835 mlen = strlen( mr->smr_oid );
837 for( i=0; values[i] != NULL; i++ ) {
838 struct berval *value = ber_bvdup( values[i] );
839 ldap_pvt_str2upper( value->bv_val );
841 lutil_MD5Init( &MD5context );
842 if( prefix != NULL && prefix->bv_len > 0 ) {
843 lutil_MD5Update( &MD5context,
844 prefix->bv_val, prefix->bv_len );
846 lutil_MD5Update( &MD5context,
847 syntax->ssyn_oid, slen );
848 lutil_MD5Update( &MD5context,
850 lutil_MD5Update( &MD5context,
851 value->bv_val, value->bv_len );
852 lutil_MD5Final( MD5digest, &MD5context );
856 keys[i] = ber_bvdup( &digest );
864 /* Index generation function */
865 int caseIgnoreIA5Filter(
869 struct berval *prefix,
871 struct berval ***keysp )
874 struct berval **keys;
875 lutil_MD5_CTX MD5context;
876 unsigned char MD5digest[LUTIL_MD5_BYTES];
877 struct berval *value;
878 struct berval digest;
879 digest.bv_val = MD5digest;
880 digest.bv_len = sizeof(MD5digest);
882 slen = strlen( syntax->ssyn_oid );
883 mlen = strlen( mr->smr_oid );
885 value = ber_bvdup( (struct berval *) assertValue );
886 ldap_pvt_str2upper( value->bv_val );
888 keys = ch_malloc( sizeof( struct berval * ) * 2 );
890 lutil_MD5Init( &MD5context );
891 if( prefix != NULL && prefix->bv_len > 0 ) {
892 lutil_MD5Update( &MD5context,
893 prefix->bv_val, prefix->bv_len );
895 lutil_MD5Update( &MD5context,
896 syntax->ssyn_oid, slen );
897 lutil_MD5Update( &MD5context,
899 lutil_MD5Update( &MD5context,
900 value->bv_val, value->bv_len );
901 lutil_MD5Final( MD5digest, &MD5context );
903 keys[0] = ber_bvdup( &digest );
913 NumericStringNormalize(
916 struct berval **normalized )
918 /* similiar to IA5StringNormalize except removes all spaces */
919 struct berval *newval;
922 newval = ch_malloc( sizeof( struct berval ) );
926 /* Ignore initial whitespace */
927 while ( isspace( *p ) ) {
933 return LDAP_INVALID_SYNTAX;
936 newval->bv_val = ch_strdup( p );
937 p = q = newval->bv_val;
940 if ( isspace( *p ) ) {
941 /* Ignore whitespace */
948 assert( *newval->bv_val );
949 assert( newval->bv_val < p );
952 /* cannot start with a space */
953 assert( !isspace(*newval->bv_val) );
955 /* cannot end with a space */
956 assert( !isspace( q[-1] ) );
961 newval->bv_len = q - newval->bv_val;
962 *normalized = newval;
968 check_time_syntax (struct berval *val,
972 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
973 static int mdays[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
975 int part, c, neg = 0;
977 if( val->bv_len == 0 )
978 return LDAP_INVALID_SYNTAX;
980 p = (char *)val->bv_val;
983 /* Ignore initial whitespace */
984 while ( ( p < e ) && isspace( *p ) ) {
988 if (e - p < 13 - (2 * start))
989 return LDAP_INVALID_SYNTAX;
991 for (part = 0; part < 9; part++)
994 for (part = start; part < 7; part++) {
1007 return LDAP_INVALID_SYNTAX;
1009 return LDAP_INVALID_SYNTAX;
1014 return LDAP_INVALID_SYNTAX;
1016 return LDAP_INVALID_SYNTAX;
1020 if (part == 2 || part == 3)
1022 if (parts[part] < 0)
1023 return LDAP_INVALID_SYNTAX;
1024 if (parts[part] > ceiling[part])
1025 return LDAP_INVALID_SYNTAX;
1027 if (parts[2] == 1) {
1028 if (parts[3] > mdays[parts[2]])
1029 return LDAP_INVALID_SYNTAX;
1030 if (parts[1] & 0x03) {
1031 /* FIXME: This is an incomplete leap-year
1032 * check that fails in 2100, 2200, 2300,
1033 * 2500, 2600, 2700, ...
1035 if (parts[3] > mdays[parts[2]] - 1)
1036 return LDAP_INVALID_SYNTAX;
1042 } else if (c != '+' && c != '-') {
1043 return LDAP_INVALID_SYNTAX;
1048 return LDAP_INVALID_SYNTAX;
1049 for (part = 7; part < 9; part++) {
1052 return LDAP_INVALID_SYNTAX;
1057 return LDAP_INVALID_SYNTAX;
1060 if (parts[part] < 0 || parts[part] > ceiling[part])
1061 return LDAP_INVALID_SYNTAX;
1065 /* Ignore trailing whitespace */
1066 while ( ( p < e ) && isspace( *p ) ) {
1070 return LDAP_INVALID_SYNTAX;
1073 parts[4] += parts[7];
1074 parts[5] += parts[8];
1075 for (part = 7; --part > 0; ) {
1079 /* FIXME: This is an incomplete leap-year
1080 * check that fails in 2100, 2200, 2300,
1081 * 2500, 2600, 2700, ...
1083 c = mdays[parts[2]];
1087 if (parts[part] > c) {
1088 parts[part] -= c + 1;
1093 parts[4] -= parts[7];
1094 parts[5] -= parts[8];
1095 for (part = 7; --part > 0; ) {
1099 /* FIXME: This is an incomplete leap-year
1100 * check that fails in 2100, 2200, 2300,
1101 * 2500, 2600, 2700, ...
1103 c = mdays[(parts[2] - 1) % 12];
1107 if (parts[part] < 0) {
1108 parts[part] += c + 1;
1114 return LDAP_SUCCESS;
1121 struct berval **normalized )
1126 rc = check_time_syntax(val, 1, parts);
1127 if (rc != LDAP_SUCCESS) {
1132 out = ch_malloc( sizeof(struct berval) );
1134 return LBER_ERROR_MEMORY;
1136 out->bv_val = ch_malloc( 14 );
1137 if ( out->bv_val == NULL ) {
1139 return LBER_ERROR_MEMORY;
1142 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
1143 parts[1], parts[2] + 1, parts[3] + 1,
1144 parts[4], parts[5], parts[6] );
1148 return LDAP_SUCCESS;
1158 return check_time_syntax(in, 1, parts);
1162 generalizedTimeNormalize(
1165 struct berval **normalized )
1170 rc = check_time_syntax(val, 0, parts);
1171 if (rc != LDAP_SUCCESS) {
1176 out = ch_malloc( sizeof(struct berval) );
1178 return LBER_ERROR_MEMORY;
1180 out->bv_val = ch_malloc( 16 );
1181 if ( out->bv_val == NULL ) {
1183 return LBER_ERROR_MEMORY;
1186 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
1187 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
1188 parts[4], parts[5], parts[6] );
1192 return LDAP_SUCCESS;
1196 generalizedTimeValidate(
1202 return check_time_syntax(in, 0, parts);
1205 struct syntax_defs_rec {
1208 slap_syntax_validate_func *sd_validate;
1209 slap_syntax_transform_func *sd_normalize;
1210 slap_syntax_transform_func *sd_pretty;
1211 #ifdef SLAPD_BINARY_CONVERSION
1212 slap_syntax_transform_func *sd_ber2str;
1213 slap_syntax_transform_func *sd_str2ber;
1217 #define X_HIDE "X-HIDE 'TRUE' "
1218 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
1219 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
1221 struct syntax_defs_rec syntax_defs[] = {
1222 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
1223 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
1224 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
1225 0, NULL, NULL, NULL},
1226 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
1227 0, NULL, NULL, NULL},
1228 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
1229 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
1230 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
1231 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1232 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
1233 0, NULL, NULL, NULL},
1234 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
1235 0, NULL, NULL, NULL},
1236 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
1237 X_BINARY X_NOT_H_R ")",
1238 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1239 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
1240 X_BINARY X_NOT_H_R ")",
1241 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1242 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
1243 X_BINARY X_NOT_H_R ")",
1244 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1245 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
1246 0, NULL, NULL, NULL},
1247 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
1248 0, dnValidate, dnNormalize, NULL},
1249 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
1250 0, NULL, NULL, NULL},
1251 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
1252 0, NULL, NULL, NULL},
1253 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
1254 0, UTF8StringValidate, UTF8StringNormalize, NULL},
1255 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
1256 0, NULL, NULL, NULL},
1257 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
1258 0, NULL, NULL, NULL},
1259 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
1260 0, NULL, NULL, NULL},
1261 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
1262 0, NULL, NULL, NULL},
1263 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
1264 0, NULL, NULL, NULL},
1265 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
1266 0, blobValidate, NULL, NULL},
1267 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
1268 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
1269 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
1270 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
1271 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
1272 0, NULL, NULL, NULL},
1273 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
1274 0, IA5StringValidate, IA5StringNormalize, NULL},
1275 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
1276 0, integerValidate, NULL, NULL},
1277 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
1278 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
1279 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
1280 0, NULL, NULL, NULL},
1281 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
1282 0, NULL, NULL, NULL},
1283 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
1284 0, NULL, NULL, NULL},
1285 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
1286 0, NULL, NULL, NULL},
1287 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
1288 0, NULL, NULL, NULL},
1289 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
1290 0, NULL, NULL, NULL},
1291 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
1292 0, NULL, NULL, NULL},
1293 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
1294 0, IA5StringValidate, NumericStringNormalize, NULL},
1295 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
1296 0, NULL, NULL, NULL},
1297 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
1298 0, oidValidate, NULL, NULL},
1299 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
1300 0, NULL, NULL, NULL},
1301 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
1302 0, blobValidate, NULL, NULL},
1303 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
1304 0, blobValidate, NULL, NULL},
1305 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
1306 0, NULL, NULL, NULL},
1307 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
1308 0, NULL, NULL, NULL},
1309 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
1310 0, printableStringValidate, NULL, NULL},
1311 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
1312 X_BINARY X_NOT_H_R ")",
1313 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1314 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
1315 0, blobValidate, NULL, NULL},
1316 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
1317 0, NULL, NULL, NULL},
1318 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
1319 0, NULL, NULL, NULL},
1320 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
1321 0, utcTimeValidate, utcTimeNormalize, NULL},
1322 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
1323 0, NULL, NULL, NULL},
1324 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
1325 0, NULL, NULL, NULL},
1326 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
1327 0, NULL, NULL, NULL},
1328 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
1329 0, NULL, NULL, NULL},
1330 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
1331 0, NULL, NULL, NULL},
1333 /* OpenLDAP Experimental Syntaxes */
1334 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
1335 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */, NULL, NULL},
1336 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
1337 0, NULL, NULL, NULL},
1338 {"( 1.3.6.1.4.1.4203.666.2.3 DESC 'OpenLDAP void' " X_HIDE ")" ,
1339 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
1340 #if 0 /* not needed */
1341 {"( 1.3.6.1.4.1.4203.666.2.4 DESC 'OpenLDAP DN' " X_HIDE ")" ,
1342 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
1345 {NULL, 0, NULL, NULL, NULL}
1348 struct mrule_defs_rec {
1351 slap_mr_convert_func * mrd_convert;
1352 slap_mr_normalize_func * mrd_normalize;
1353 slap_mr_match_func * mrd_match;
1354 slap_mr_indexer_func * mrd_indexer;
1355 slap_mr_filter_func * mrd_filter;
1359 * Other matching rules in X.520 that we do not use:
1361 * 2.5.13.9 numericStringOrderingMatch
1362 * 2.5.13.13 booleanMatch
1363 * 2.5.13.15 integerOrderingMatch
1364 * 2.5.13.18 octetStringOrderingMatch
1365 * 2.5.13.19 octetStringSubstringsMatch
1366 * 2.5.13.25 uTCTimeMatch
1367 * 2.5.13.26 uTCTimeOrderingMatch
1368 * 2.5.13.31 directoryStringFirstComponentMatch
1369 * 2.5.13.32 wordMatch
1370 * 2.5.13.33 keywordMatch
1371 * 2.5.13.34 certificateExactMatch
1372 * 2.5.13.35 certificateMatch
1373 * 2.5.13.36 certificatePairExactMatch
1374 * 2.5.13.37 certificatePairMatch
1375 * 2.5.13.38 certificateListExactMatch
1376 * 2.5.13.39 certificateListMatch
1377 * 2.5.13.40 algorithmIdentifierMatch
1378 * 2.5.13.41 storedPrefixMatch
1379 * 2.5.13.42 attributeCertificateMatch
1380 * 2.5.13.43 readerAndKeyIDMatch
1381 * 2.5.13.44 attributeIntegrityMatch
1385 /* recycled matching functions */
1386 #define caseIgnoreMatch caseIgnoreIA5Match
1387 #define caseIgnoreOrderingMatch caseIgnoreMatch
1388 #define caseIgnoreSubstringsMatch caseIgnoreIA5SubstringsMatch
1389 #define caseExactMatch caseExactIA5Match
1390 #define caseExactOrderingMatch caseExactMatch
1391 #define caseExactSubstringsMatch caseExactIA5SubstringsMatch
1393 /* unimplemented matching functions */
1394 #define objectIdentifierMatch NULL
1395 #define caseIgnoreListMatch NULL
1396 #define caseIgnoreListSubstringsMatch NULL
1397 #define integerMatch NULL
1398 #define bitStringMatch NULL
1399 #define octetStringMatch NULL
1400 #define telephoneNumberMatch NULL
1401 #define telephoneNumberSubstringsMatch NULL
1402 #define presentationAddressMatch NULL
1403 #define uniqueMemberMatch NULL
1404 #define protocolInformationMatch NULL
1405 #define generalizedTimeMatch caseExactIA5Match
1406 #define generalizedTimeOrderingMatch caseExactIA5Match
1407 #define integerFirstComponentMatch NULL
1408 #define objectIdentifierFirstComponentMatch NULL
1410 #define OpenLDAPaciMatch NULL
1411 #define authPasswordMatch NULL
1413 /* unimplied indexer/filter routines */
1414 #define dnIndexer NULL
1415 #define dnFilter NULL
1417 #define caseIgnoreIndexer caseIgnoreIA5Indexer
1418 #define caseIgnoreFilter caseIgnoreIA5Filter
1419 #define caseExactIndexer caseExactIA5Indexer
1420 #define caseExactFilter caseExactIA5Filter
1421 #define caseExactIA5Indexer caseIgnoreIA5Indexer
1422 #define caseExactIA5Filter caseIgnoreIA5Filter
1424 struct mrule_defs_rec mrule_defs[] = {
1425 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
1426 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1427 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1428 NULL, NULL, objectIdentifierMatch,
1429 caseIgnoreIA5Indexer, caseIgnoreIA5Filter},
1431 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
1432 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
1433 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1434 NULL, NULL, dnMatch, dnIndexer, dnFilter},
1436 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
1437 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1438 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1439 NULL, NULL, caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter},
1441 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
1442 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1444 NULL, NULL, caseIgnoreOrderingMatch, NULL, NULL},
1446 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
1447 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1448 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1449 NULL, NULL, caseIgnoreSubstringsMatch, NULL, NULL},
1451 /* Next three are not in the RFC's, but are needed for compatibility */
1452 {"( 2.5.13.5 NAME 'caseExactMatch' "
1453 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1454 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1455 NULL, NULL, caseExactMatch, caseExactIndexer, caseExactFilter},
1457 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
1458 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1460 NULL, NULL, caseExactOrderingMatch, NULL, NULL},
1462 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
1463 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1464 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1465 NULL, NULL, caseExactSubstringsMatch, NULL, NULL},
1467 {"( 2.5.13.8 NAME 'numericStringMatch' "
1468 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
1469 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1470 NULL, NULL, caseIgnoreIA5Match, NULL, NULL},
1472 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
1473 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1474 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1475 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1477 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
1478 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
1479 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1480 NULL, NULL, caseIgnoreListMatch, NULL, NULL},
1482 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
1483 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1484 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1485 NULL, NULL, caseIgnoreListSubstringsMatch, NULL, NULL},
1487 {"( 2.5.13.14 NAME 'integerMatch' "
1488 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1489 SLAP_MR_NONE | SLAP_MR_EXT,
1490 NULL, NULL, integerMatch, NULL, NULL},
1492 {"( 2.5.13.16 NAME 'bitStringMatch' "
1493 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
1494 SLAP_MR_NONE | SLAP_MR_EXT,
1495 NULL, NULL, bitStringMatch, NULL, NULL},
1497 {"( 2.5.13.17 NAME 'octetStringMatch' "
1498 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1499 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1500 NULL, NULL, octetStringMatch, octetStringIndexer, octetStringFilter},
1502 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
1503 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
1504 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1505 NULL, NULL, telephoneNumberMatch, NULL, NULL},
1507 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
1508 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1509 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1510 NULL, NULL, telephoneNumberSubstringsMatch, NULL, NULL},
1512 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
1513 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
1514 SLAP_MR_NONE | SLAP_MR_EXT,
1515 NULL, NULL, presentationAddressMatch, NULL, NULL},
1517 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
1518 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
1519 SLAP_MR_NONE | SLAP_MR_EXT,
1520 NULL, NULL, uniqueMemberMatch, NULL, NULL},
1522 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
1523 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
1524 SLAP_MR_NONE | SLAP_MR_EXT,
1525 NULL, NULL, protocolInformationMatch, NULL, NULL},
1527 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
1528 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1529 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1530 NULL, NULL, generalizedTimeMatch, NULL, NULL},
1532 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
1533 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1535 NULL, NULL, generalizedTimeOrderingMatch, NULL, NULL},
1537 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
1538 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1539 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1540 NULL, NULL, integerFirstComponentMatch, NULL, NULL},
1542 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
1543 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1544 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1545 NULL, NULL, objectIdentifierFirstComponentMatch, NULL, NULL},
1547 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
1548 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1549 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1550 NULL, NULL, caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1552 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
1553 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1554 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1555 NULL, NULL, caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1557 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
1558 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1560 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1562 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
1563 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1565 NULL, NULL, authPasswordMatch, NULL, NULL},
1567 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
1568 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
1570 NULL, NULL, OpenLDAPaciMatch, NULL, NULL},
1572 {NULL, SLAP_MR_NONE, NULL, NULL, NULL}
1581 /* we should only be called once (from main) */
1582 assert( schema_init_done == 0 );
1584 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1585 res = register_syntax( syntax_defs[i].sd_desc,
1586 syntax_defs[i].sd_flags,
1587 syntax_defs[i].sd_validate,
1588 syntax_defs[i].sd_normalize,
1589 syntax_defs[i].sd_pretty
1590 #ifdef SLAPD_BINARY_CONVERSION
1592 syntax_defs[i].sd_ber2str,
1593 syntax_defs[i].sd_str2ber
1598 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1599 syntax_defs[i].sd_desc );
1604 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1605 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
1607 "schema_init: Ingoring unusable matching rule %s\n",
1608 mrule_defs[i].mrd_desc );
1612 res = register_matching_rule(
1613 mrule_defs[i].mrd_desc,
1614 mrule_defs[i].mrd_usage,
1615 mrule_defs[i].mrd_convert,
1616 mrule_defs[i].mrd_normalize,
1617 mrule_defs[i].mrd_match,
1618 mrule_defs[i].mrd_indexer,
1619 mrule_defs[i].mrd_filter );
1623 "schema_init: Error registering matching rule %s\n",
1624 mrule_defs[i].mrd_desc );
1628 schema_init_done = 1;
1629 return LDAP_SUCCESS;