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( sub->sa_initial ) {
553 if( inlen > left.bv_len ) {
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;
570 if( sub->sa_final ) {
571 if( inlen > left.bv_len ) {
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;
589 for(i=0; sub->sa_any[i]; i++) {
594 if( inlen > left.bv_len ) {
595 /* not enough length */
600 if( sub->sa_any[i]->bv_len == 0 ) {
604 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
611 idx = p - left.bv_val;
612 assert( idx < left.bv_len );
614 if( idx >= left.bv_len ) {
615 /* this shouldn't happen */
622 if( sub->sa_any[i]->bv_len > left.bv_len ) {
623 /* not enough left */
628 match = strncmp( left.bv_val,
629 sub->sa_any[i]->bv_val,
630 sub->sa_any[i]->bv_len );
638 left.bv_val += sub->sa_any[i]->bv_len;
639 left.bv_len -= sub->sa_any[i]->bv_len;
640 inlen -= sub->sa_any[i]->bv_len;
655 struct berval *value,
656 void *assertedValue )
658 *match = strcasecmp( value->bv_val,
659 ((struct berval *) assertedValue)->bv_val );
663 static char *strcasechr( const char *str, int c )
665 char *lower = strchr( str, TOLOWER(c) );
666 char *upper = strchr( str, TOUPPER(c) );
668 if( lower && upper ) {
669 return lower < upper ? lower : upper;
670 } else if ( lower ) {
678 caseIgnoreIA5SubstringsMatch(
683 struct berval *value,
684 void *assertedValue )
687 SubstringsAssertion *sub = assertedValue;
688 struct berval left = *value;
692 /* Add up asserted input length */
693 if( sub->sa_initial ) {
694 inlen += sub->sa_initial->bv_len;
697 for(i=0; sub->sa_any[i] != NULL; i++) {
698 inlen += sub->sa_any[i]->bv_len;
701 if( sub->sa_final ) {
702 inlen += sub->sa_final->bv_len;
705 if( sub->sa_initial ) {
706 if( inlen > left.bv_len ) {
711 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
712 sub->sa_initial->bv_len );
718 left.bv_val += sub->sa_initial->bv_len;
719 left.bv_len -= sub->sa_initial->bv_len;
720 inlen -= sub->sa_initial->bv_len;
723 if( sub->sa_final ) {
724 if( inlen > left.bv_len ) {
729 match = strncasecmp( sub->sa_final->bv_val,
730 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
731 sub->sa_final->bv_len );
737 left.bv_len -= sub->sa_final->bv_len;
738 inlen -= sub->sa_final->bv_len;
742 for(i=0; sub->sa_any[i]; i++) {
747 if( inlen > left.bv_len ) {
748 /* not enough length */
753 if( sub->sa_any[i]->bv_len == 0 ) {
757 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
764 idx = p - left.bv_val;
765 assert( idx < left.bv_len );
767 if( idx >= left.bv_len ) {
768 /* this shouldn't happen */
775 if( sub->sa_any[i]->bv_len > left.bv_len ) {
776 /* not enough left */
781 match = strncasecmp( left.bv_val,
782 sub->sa_any[i]->bv_val,
783 sub->sa_any[i]->bv_len );
792 left.bv_val += sub->sa_any[i]->bv_len;
793 left.bv_len -= sub->sa_any[i]->bv_len;
794 inlen -= sub->sa_any[i]->bv_len;
803 /* Index generation function */
804 int caseIgnoreIA5Indexer(
808 struct berval *prefix,
809 struct berval **values,
810 struct berval ***keysp )
814 struct berval **keys;
815 lutil_MD5_CTX MD5context;
816 unsigned char MD5digest[16];
817 struct berval digest;
818 digest.bv_val = MD5digest;
819 digest.bv_len = sizeof(MD5digest);
821 for( i=0; values[i] != NULL; i++ ) {
822 /* just count them */
827 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
829 slen = strlen( syntax->ssyn_oid );
830 mlen = strlen( mr->smr_oid );
832 for( i=0; values[i] != NULL; i++ ) {
833 struct berval *value = ber_bvdup( values[i] );
834 ldap_pvt_str2upper( value->bv_val );
836 lutil_MD5Init( &MD5context );
837 if( prefix != NULL && prefix->bv_len > 0 ) {
838 lutil_MD5Update( &MD5context,
839 prefix->bv_val, prefix->bv_len );
841 lutil_MD5Update( &MD5context,
842 syntax->ssyn_oid, slen );
843 lutil_MD5Update( &MD5context,
845 lutil_MD5Update( &MD5context,
846 value->bv_val, value->bv_len );
847 lutil_MD5Final( MD5digest, &MD5context );
851 keys[i] = ber_bvdup( &digest );
859 /* Index generation function */
860 int caseIgnoreIA5Filter(
864 struct berval *prefix,
866 struct berval ***keysp )
869 struct berval **keys;
870 lutil_MD5_CTX MD5context;
871 unsigned char MD5digest[LUTIL_MD5_BYTES];
872 struct berval *value;
873 struct berval digest;
874 digest.bv_val = MD5digest;
875 digest.bv_len = sizeof(MD5digest);
877 slen = strlen( syntax->ssyn_oid );
878 mlen = strlen( mr->smr_oid );
880 value = ber_bvdup( (struct berval *) assertValue );
881 ldap_pvt_str2upper( value->bv_val );
883 keys = ch_malloc( sizeof( struct berval * ) * 2 );
885 lutil_MD5Init( &MD5context );
886 if( prefix != NULL && prefix->bv_len > 0 ) {
887 lutil_MD5Update( &MD5context,
888 prefix->bv_val, prefix->bv_len );
890 lutil_MD5Update( &MD5context,
891 syntax->ssyn_oid, slen );
892 lutil_MD5Update( &MD5context,
894 lutil_MD5Update( &MD5context,
895 value->bv_val, value->bv_len );
896 lutil_MD5Final( MD5digest, &MD5context );
898 keys[0] = ber_bvdup( &digest );
908 numericStringNormalize(
911 struct berval **normalized )
913 /* similiar to IA5StringNormalize except removes all spaces */
914 struct berval *newval;
917 newval = ch_malloc( sizeof( struct berval ) );
921 /* Ignore initial whitespace */
922 while ( isspace( *p ) ) {
928 return LDAP_INVALID_SYNTAX;
931 newval->bv_val = ch_strdup( p );
932 p = q = newval->bv_val;
935 if ( isspace( *p ) ) {
936 /* Ignore whitespace */
943 assert( *newval->bv_val );
944 assert( newval->bv_val < p );
947 /* cannot start with a space */
948 assert( !isspace(*newval->bv_val) );
950 /* cannot end with a space */
951 assert( !isspace( q[-1] ) );
956 newval->bv_len = q - newval->bv_val;
957 *normalized = newval;
963 check_time_syntax (struct berval *val,
967 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
968 static int mdays[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
970 int part, c, neg = 0;
972 if( val->bv_len == 0 )
973 return LDAP_INVALID_SYNTAX;
975 p = (char *)val->bv_val;
978 /* Ignore initial whitespace */
979 while ( ( p < e ) && isspace( *p ) ) {
983 if (e - p < 13 - (2 * start))
984 return LDAP_INVALID_SYNTAX;
986 for (part = 0; part < 9; part++)
989 for (part = start; part < 7; part++) {
1002 return LDAP_INVALID_SYNTAX;
1004 return LDAP_INVALID_SYNTAX;
1009 return LDAP_INVALID_SYNTAX;
1011 return LDAP_INVALID_SYNTAX;
1015 if (part == 2 || part == 3)
1017 if (parts[part] < 0)
1018 return LDAP_INVALID_SYNTAX;
1019 if (parts[part] > ceiling[part])
1020 return LDAP_INVALID_SYNTAX;
1022 if (parts[2] == 1) {
1023 if (parts[3] > mdays[parts[2]])
1024 return LDAP_INVALID_SYNTAX;
1025 if (parts[1] & 0x03) {
1026 /* FIXME: This is an incomplete leap-year
1027 * check that fails in 2100, 2200, 2300,
1028 * 2500, 2600, 2700, ...
1030 if (parts[3] > mdays[parts[2]] - 1)
1031 return LDAP_INVALID_SYNTAX;
1037 } else if (c != '+' && c != '-') {
1038 return LDAP_INVALID_SYNTAX;
1043 return LDAP_INVALID_SYNTAX;
1044 for (part = 7; part < 9; part++) {
1047 return LDAP_INVALID_SYNTAX;
1052 return LDAP_INVALID_SYNTAX;
1055 if (parts[part] < 0 || parts[part] > ceiling[part])
1056 return LDAP_INVALID_SYNTAX;
1060 /* Ignore trailing whitespace */
1061 while ( ( p < e ) && isspace( *p ) ) {
1065 return LDAP_INVALID_SYNTAX;
1068 parts[4] += parts[7];
1069 parts[5] += parts[8];
1070 for (part = 7; --part > 0; ) {
1074 /* FIXME: This is an incomplete leap-year
1075 * check that fails in 2100, 2200, 2300,
1076 * 2500, 2600, 2700, ...
1078 c = mdays[parts[2]];
1082 if (parts[part] > c) {
1083 parts[part] -= c + 1;
1088 parts[4] -= parts[7];
1089 parts[5] -= parts[8];
1090 for (part = 7; --part > 0; ) {
1094 /* FIXME: This is an incomplete leap-year
1095 * check that fails in 2100, 2200, 2300,
1096 * 2500, 2600, 2700, ...
1098 c = mdays[(parts[2] - 1) % 12];
1102 if (parts[part] < 0) {
1103 parts[part] += c + 1;
1109 return LDAP_SUCCESS;
1116 struct berval **normalized )
1121 rc = check_time_syntax(val, 1, parts);
1122 if (rc != LDAP_SUCCESS) {
1127 out = ch_malloc( sizeof(struct berval) );
1129 return LBER_ERROR_MEMORY;
1131 out->bv_val = ch_malloc( 14 );
1132 if ( out->bv_val == NULL ) {
1134 return LBER_ERROR_MEMORY;
1137 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
1138 parts[1], parts[2] + 1, parts[3] + 1,
1139 parts[4], parts[5], parts[6] );
1143 return LDAP_SUCCESS;
1153 return check_time_syntax(in, 1, parts);
1157 generalizedTimeNormalize(
1160 struct berval **normalized )
1165 rc = check_time_syntax(val, 0, parts);
1166 if (rc != LDAP_SUCCESS) {
1171 out = ch_malloc( sizeof(struct berval) );
1173 return LBER_ERROR_MEMORY;
1175 out->bv_val = ch_malloc( 16 );
1176 if ( out->bv_val == NULL ) {
1178 return LBER_ERROR_MEMORY;
1181 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
1182 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
1183 parts[4], parts[5], parts[6] );
1187 return LDAP_SUCCESS;
1191 generalizedTimeValidate(
1197 return check_time_syntax(in, 0, parts);
1200 struct syntax_defs_rec {
1203 slap_syntax_validate_func *sd_validate;
1204 slap_syntax_transform_func *sd_normalize;
1205 slap_syntax_transform_func *sd_pretty;
1206 #ifdef SLAPD_BINARY_CONVERSION
1207 slap_syntax_transform_func *sd_ber2str;
1208 slap_syntax_transform_func *sd_str2ber;
1212 #define X_HIDE "X-HIDE 'TRUE' "
1213 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
1214 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
1216 #define faxNumberNormalize numericStringNormalize
1217 #define phoneNumberNormalize numericStringNormalize
1218 #define telexNumberNormalize numericStringNormalize
1220 struct syntax_defs_rec syntax_defs[] = {
1221 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
1222 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
1223 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
1224 0, NULL, NULL, NULL},
1225 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
1226 0, NULL, NULL, NULL},
1227 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
1228 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
1229 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
1230 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1231 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
1232 0, NULL, NULL, NULL},
1233 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
1234 0, NULL, NULL, NULL},
1235 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
1236 X_BINARY X_NOT_H_R ")",
1237 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1238 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
1239 X_BINARY X_NOT_H_R ")",
1240 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1241 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
1242 X_BINARY X_NOT_H_R ")",
1243 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1244 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
1245 0, NULL, NULL, NULL},
1246 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
1247 0, dnValidate, dnNormalize, NULL},
1248 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
1249 0, NULL, NULL, NULL},
1250 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
1251 0, NULL, NULL, NULL},
1252 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
1253 0, UTF8StringValidate, UTF8StringNormalize, NULL},
1254 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
1255 0, NULL, NULL, NULL},
1256 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
1257 0, NULL, NULL, NULL},
1258 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
1259 0, NULL, NULL, NULL},
1260 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
1261 0, NULL, NULL, NULL},
1262 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
1263 0, NULL, NULL, NULL},
1264 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
1265 0, IA5StringValidate, faxNumberNormalize, NULL},
1266 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
1267 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
1268 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
1269 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
1270 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
1271 0, NULL, NULL, NULL},
1272 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
1273 0, IA5StringValidate, IA5StringNormalize, NULL},
1274 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
1275 0, integerValidate, NULL, NULL},
1276 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
1277 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
1278 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
1279 0, NULL, NULL, NULL},
1280 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
1281 0, NULL, NULL, NULL},
1282 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
1283 0, NULL, NULL, NULL},
1284 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
1285 0, NULL, NULL, NULL},
1286 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
1287 0, NULL, NULL, NULL},
1288 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
1289 0, NULL, NULL, NULL},
1290 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
1291 0, NULL, NULL, NULL},
1292 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
1293 0, IA5StringValidate, numericStringNormalize, NULL},
1294 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
1295 0, NULL, NULL, NULL},
1296 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
1297 0, oidValidate, NULL, NULL},
1298 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
1299 0, NULL, NULL, NULL},
1300 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
1301 0, blobValidate, NULL, NULL},
1302 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
1303 0, blobValidate, NULL, NULL},
1304 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
1305 0, NULL, NULL, NULL},
1306 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
1307 0, NULL, NULL, NULL},
1308 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
1309 0, printableStringValidate, NULL, NULL},
1310 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
1311 X_BINARY X_NOT_H_R ")",
1312 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1313 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
1314 0, IA5StringValidate, phoneNumberNormalize, NULL},
1315 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
1316 0, NULL, NULL, NULL},
1317 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
1318 0, IA5StringValidate, telexNumberNormalize, NULL},
1319 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
1320 0, utcTimeValidate, utcTimeNormalize, NULL},
1321 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
1322 0, NULL, NULL, NULL},
1323 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
1324 0, NULL, NULL, NULL},
1325 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
1326 0, NULL, NULL, NULL},
1327 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
1328 0, NULL, NULL, NULL},
1329 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
1330 0, NULL, NULL, NULL},
1332 /* OpenLDAP Experimental Syntaxes */
1333 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
1334 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */, NULL, NULL},
1335 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
1336 0, NULL, NULL, NULL},
1337 {"( 1.3.6.1.4.1.4203.666.2.3 DESC 'OpenLDAP void' " X_HIDE ")" ,
1338 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
1339 #if 0 /* not needed */
1340 {"( 1.3.6.1.4.1.4203.666.2.4 DESC 'OpenLDAP DN' " X_HIDE ")" ,
1341 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
1344 {NULL, 0, NULL, NULL, NULL}
1347 struct mrule_defs_rec {
1350 slap_mr_convert_func * mrd_convert;
1351 slap_mr_normalize_func * mrd_normalize;
1352 slap_mr_match_func * mrd_match;
1353 slap_mr_indexer_func * mrd_indexer;
1354 slap_mr_filter_func * mrd_filter;
1358 * Other matching rules in X.520 that we do not use:
1360 * 2.5.13.9 numericStringOrderingMatch
1361 * 2.5.13.13 booleanMatch
1362 * 2.5.13.15 integerOrderingMatch
1363 * 2.5.13.18 octetStringOrderingMatch
1364 * 2.5.13.19 octetStringSubstringsMatch
1365 * 2.5.13.25 uTCTimeMatch
1366 * 2.5.13.26 uTCTimeOrderingMatch
1367 * 2.5.13.31 directoryStringFirstComponentMatch
1368 * 2.5.13.32 wordMatch
1369 * 2.5.13.33 keywordMatch
1370 * 2.5.13.34 certificateExactMatch
1371 * 2.5.13.35 certificateMatch
1372 * 2.5.13.36 certificatePairExactMatch
1373 * 2.5.13.37 certificatePairMatch
1374 * 2.5.13.38 certificateListExactMatch
1375 * 2.5.13.39 certificateListMatch
1376 * 2.5.13.40 algorithmIdentifierMatch
1377 * 2.5.13.41 storedPrefixMatch
1378 * 2.5.13.42 attributeCertificateMatch
1379 * 2.5.13.43 readerAndKeyIDMatch
1380 * 2.5.13.44 attributeIntegrityMatch
1384 /* recycled matching functions */
1385 #define caseIgnoreMatch caseIgnoreIA5Match
1386 #define caseIgnoreOrderingMatch caseIgnoreMatch
1387 #define caseIgnoreSubstringsMatch caseIgnoreIA5SubstringsMatch
1388 #define caseExactMatch caseExactIA5Match
1389 #define caseExactOrderingMatch caseExactMatch
1390 #define caseExactSubstringsMatch caseExactIA5SubstringsMatch
1392 /* unimplemented matching functions */
1393 #define objectIdentifierMatch NULL
1394 #define caseIgnoreListMatch NULL
1395 #define caseIgnoreListSubstringsMatch NULL
1396 #define integerMatch NULL
1397 #define bitStringMatch NULL
1398 #define octetStringMatch NULL
1399 #define telephoneNumberMatch NULL
1400 #define telephoneNumberSubstringsMatch NULL
1401 #define presentationAddressMatch NULL
1402 #define uniqueMemberMatch NULL
1403 #define protocolInformationMatch NULL
1404 #define generalizedTimeMatch caseExactIA5Match
1405 #define generalizedTimeOrderingMatch caseExactIA5Match
1406 #define integerFirstComponentMatch NULL
1407 #define objectIdentifierFirstComponentMatch NULL
1409 #define OpenLDAPaciMatch NULL
1410 #define authPasswordMatch NULL
1412 /* unimplied indexer/filter routines */
1413 #define dnIndexer NULL
1414 #define dnFilter NULL
1416 #define caseIgnoreIndexer caseIgnoreIA5Indexer
1417 #define caseIgnoreFilter caseIgnoreIA5Filter
1418 #define caseExactIndexer caseExactIA5Indexer
1419 #define caseExactFilter caseExactIA5Filter
1420 #define caseExactIA5Indexer caseIgnoreIA5Indexer
1421 #define caseExactIA5Filter caseIgnoreIA5Filter
1423 struct mrule_defs_rec mrule_defs[] = {
1424 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
1425 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1426 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1427 NULL, NULL, objectIdentifierMatch,
1428 caseIgnoreIA5Indexer, caseIgnoreIA5Filter},
1430 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
1431 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
1432 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1433 NULL, NULL, dnMatch, dnIndexer, dnFilter},
1435 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
1436 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1437 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1438 NULL, NULL, caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter},
1440 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
1441 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1443 NULL, NULL, caseIgnoreOrderingMatch, NULL, NULL},
1445 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
1446 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1447 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1448 NULL, NULL, caseIgnoreSubstringsMatch, NULL, NULL},
1450 /* Next three are not in the RFC's, but are needed for compatibility */
1451 {"( 2.5.13.5 NAME 'caseExactMatch' "
1452 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1453 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1454 NULL, NULL, caseExactMatch, caseExactIndexer, caseExactFilter},
1456 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
1457 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1459 NULL, NULL, caseExactOrderingMatch, NULL, NULL},
1461 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
1462 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1463 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1464 NULL, NULL, caseExactSubstringsMatch, NULL, NULL},
1466 {"( 2.5.13.8 NAME 'numericStringMatch' "
1467 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
1468 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1469 NULL, NULL, caseIgnoreIA5Match, NULL, NULL},
1471 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
1472 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1473 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1474 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1476 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
1477 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
1478 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1479 NULL, NULL, caseIgnoreListMatch, NULL, NULL},
1481 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
1482 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1483 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1484 NULL, NULL, caseIgnoreListSubstringsMatch, NULL, NULL},
1486 {"( 2.5.13.14 NAME 'integerMatch' "
1487 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1488 SLAP_MR_NONE | SLAP_MR_EXT,
1489 NULL, NULL, integerMatch, NULL, NULL},
1491 {"( 2.5.13.16 NAME 'bitStringMatch' "
1492 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
1493 SLAP_MR_NONE | SLAP_MR_EXT,
1494 NULL, NULL, bitStringMatch, NULL, NULL},
1496 {"( 2.5.13.17 NAME 'octetStringMatch' "
1497 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1498 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1499 NULL, NULL, octetStringMatch, octetStringIndexer, octetStringFilter},
1501 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
1502 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
1503 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1504 NULL, NULL, telephoneNumberMatch, NULL, NULL},
1506 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
1507 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1508 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1509 NULL, NULL, telephoneNumberSubstringsMatch, NULL, NULL},
1511 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
1512 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
1513 SLAP_MR_NONE | SLAP_MR_EXT,
1514 NULL, NULL, presentationAddressMatch, NULL, NULL},
1516 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
1517 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
1518 SLAP_MR_NONE | SLAP_MR_EXT,
1519 NULL, NULL, uniqueMemberMatch, NULL, NULL},
1521 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
1522 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
1523 SLAP_MR_NONE | SLAP_MR_EXT,
1524 NULL, NULL, protocolInformationMatch, NULL, NULL},
1526 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
1527 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1528 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1529 NULL, NULL, generalizedTimeMatch, NULL, NULL},
1531 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
1532 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1534 NULL, NULL, generalizedTimeOrderingMatch, NULL, NULL},
1536 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
1537 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1538 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1539 NULL, NULL, integerFirstComponentMatch, NULL, NULL},
1541 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
1542 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1543 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1544 NULL, NULL, objectIdentifierFirstComponentMatch, NULL, NULL},
1546 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
1547 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1548 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1549 NULL, NULL, caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1551 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
1552 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1553 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1554 NULL, NULL, caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1556 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
1557 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1559 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1561 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
1562 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1564 NULL, NULL, authPasswordMatch, NULL, NULL},
1566 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
1567 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
1569 NULL, NULL, OpenLDAPaciMatch, NULL, NULL},
1571 {NULL, SLAP_MR_NONE, NULL, NULL, NULL}
1580 /* we should only be called once (from main) */
1581 assert( schema_init_done == 0 );
1583 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1584 res = register_syntax( syntax_defs[i].sd_desc,
1585 syntax_defs[i].sd_flags,
1586 syntax_defs[i].sd_validate,
1587 syntax_defs[i].sd_normalize,
1588 syntax_defs[i].sd_pretty
1589 #ifdef SLAPD_BINARY_CONVERSION
1591 syntax_defs[i].sd_ber2str,
1592 syntax_defs[i].sd_str2ber
1597 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1598 syntax_defs[i].sd_desc );
1603 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1604 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
1606 "schema_init: Ingoring unusable matching rule %s\n",
1607 mrule_defs[i].mrd_desc );
1611 res = register_matching_rule(
1612 mrule_defs[i].mrd_desc,
1613 mrule_defs[i].mrd_usage,
1614 mrule_defs[i].mrd_convert,
1615 mrule_defs[i].mrd_normalize,
1616 mrule_defs[i].mrd_match,
1617 mrule_defs[i].mrd_indexer,
1618 mrule_defs[i].mrd_filter );
1622 "schema_init: Error registering matching rule %s\n",
1623 mrule_defs[i].mrd_desc );
1627 schema_init_done = 1;
1628 return LDAP_SUCCESS;