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 /* recycled normalization routines */
1217 #define faxNumberNormalize numericStringNormalize
1218 #define phoneNumberNormalize numericStringNormalize
1219 #define telexNumberNormalize numericStringNormalize
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, IA5StringValidate, faxNumberNormalize, 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, IA5StringValidate, phoneNumberNormalize, 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, IA5StringValidate, telexNumberNormalize, 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 routines */
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 #define numericStringMatch caseIgnoreMatch
1394 #define objectIdentifierMatch numericStringMatch
1395 #define integerMatch numericStringMatch
1396 #define telephoneNumberMatch numericStringMatch
1397 #define generalizedTimeMatch numericStringMatch
1398 #define generalizedTimeOrderingMatch numericStringMatch
1400 /* unimplemented matching routines */
1401 #define caseIgnoreListMatch NULL
1402 #define caseIgnoreListSubstringsMatch NULL
1403 #define bitStringMatch NULL
1404 #define telephoneNumberSubstringsMatch NULL
1405 #define presentationAddressMatch NULL
1406 #define uniqueMemberMatch NULL
1407 #define protocolInformationMatch NULL
1408 #define integerFirstComponentMatch NULL
1409 #define objectIdentifierFirstComponentMatch NULL
1411 #define OpenLDAPaciMatch NULL
1412 #define authPasswordMatch NULL
1414 /* unimplied indexer/filter routines */
1415 #define dnIndexer NULL
1416 #define dnFilter NULL
1418 /* recycled indexing/filtering routines */
1419 #define caseIgnoreIndexer caseIgnoreIA5Indexer
1420 #define caseIgnoreFilter caseIgnoreIA5Filter
1421 #define caseExactIndexer caseExactIA5Indexer
1422 #define caseExactFilter caseExactIA5Filter
1423 #define caseExactIA5Indexer caseIgnoreIA5Indexer
1424 #define caseExactIA5Filter caseIgnoreIA5Filter
1426 struct mrule_defs_rec mrule_defs[] = {
1427 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
1428 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1429 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1430 NULL, NULL, objectIdentifierMatch,
1431 caseIgnoreIA5Indexer, caseIgnoreIA5Filter},
1433 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
1434 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
1435 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1436 NULL, NULL, dnMatch, dnIndexer, dnFilter},
1438 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
1439 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1440 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1441 NULL, NULL, caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter},
1443 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
1444 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1446 NULL, NULL, caseIgnoreOrderingMatch, NULL, NULL},
1448 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
1449 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1450 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1451 NULL, NULL, caseIgnoreSubstringsMatch, NULL, NULL},
1453 /* Next three are not in the RFC's, but are needed for compatibility */
1454 {"( 2.5.13.5 NAME 'caseExactMatch' "
1455 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1456 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1457 NULL, NULL, caseExactMatch, caseExactIndexer, caseExactFilter},
1459 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
1460 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1462 NULL, NULL, caseExactOrderingMatch, NULL, NULL},
1464 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
1465 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1466 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1467 NULL, NULL, caseExactSubstringsMatch, NULL, NULL},
1469 {"( 2.5.13.8 NAME 'numericStringMatch' "
1470 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
1471 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1472 NULL, NULL, caseIgnoreIA5Match, NULL, NULL},
1474 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
1475 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1476 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1477 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1479 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
1480 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
1481 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1482 NULL, NULL, caseIgnoreListMatch, NULL, NULL},
1484 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
1485 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1486 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1487 NULL, NULL, caseIgnoreListSubstringsMatch, NULL, NULL},
1489 {"( 2.5.13.14 NAME 'integerMatch' "
1490 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1491 SLAP_MR_NONE | SLAP_MR_EXT,
1492 NULL, NULL, integerMatch, NULL, NULL},
1494 {"( 2.5.13.16 NAME 'bitStringMatch' "
1495 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
1496 SLAP_MR_NONE | SLAP_MR_EXT,
1497 NULL, NULL, bitStringMatch, NULL, NULL},
1499 {"( 2.5.13.17 NAME 'octetStringMatch' "
1500 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1501 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1502 NULL, NULL, octetStringMatch, octetStringIndexer, octetStringFilter},
1504 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
1505 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
1506 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1507 NULL, NULL, telephoneNumberMatch, NULL, NULL},
1509 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
1510 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1511 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1512 NULL, NULL, telephoneNumberSubstringsMatch, NULL, NULL},
1514 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
1515 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
1516 SLAP_MR_NONE | SLAP_MR_EXT,
1517 NULL, NULL, presentationAddressMatch, NULL, NULL},
1519 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
1520 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
1521 SLAP_MR_NONE | SLAP_MR_EXT,
1522 NULL, NULL, uniqueMemberMatch, NULL, NULL},
1524 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
1525 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
1526 SLAP_MR_NONE | SLAP_MR_EXT,
1527 NULL, NULL, protocolInformationMatch, NULL, NULL},
1529 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
1530 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1531 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1532 NULL, NULL, generalizedTimeMatch, NULL, NULL},
1534 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
1535 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1537 NULL, NULL, generalizedTimeOrderingMatch, NULL, NULL},
1539 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
1540 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1541 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1542 NULL, NULL, integerFirstComponentMatch, NULL, NULL},
1544 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
1545 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1546 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1547 NULL, NULL, objectIdentifierFirstComponentMatch, NULL, NULL},
1549 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
1550 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1551 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1552 NULL, NULL, caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1554 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
1555 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1556 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1557 NULL, NULL, caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1559 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
1560 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1562 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1564 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
1565 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1567 NULL, NULL, authPasswordMatch, NULL, NULL},
1569 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
1570 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
1572 NULL, NULL, OpenLDAPaciMatch, NULL, NULL},
1574 {NULL, SLAP_MR_NONE, NULL, NULL, NULL}
1583 /* we should only be called once (from main) */
1584 assert( schema_init_done == 0 );
1586 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1587 res = register_syntax( syntax_defs[i].sd_desc,
1588 syntax_defs[i].sd_flags,
1589 syntax_defs[i].sd_validate,
1590 syntax_defs[i].sd_normalize,
1591 syntax_defs[i].sd_pretty
1592 #ifdef SLAPD_BINARY_CONVERSION
1594 syntax_defs[i].sd_ber2str,
1595 syntax_defs[i].sd_str2ber
1600 fprintf( stderr, "schema_init: Error registering syntax %s\n",
1601 syntax_defs[i].sd_desc );
1606 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1607 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
1609 "schema_init: Ingoring unusable matching rule %s\n",
1610 mrule_defs[i].mrd_desc );
1614 res = register_matching_rule(
1615 mrule_defs[i].mrd_desc,
1616 mrule_defs[i].mrd_usage,
1617 mrule_defs[i].mrd_convert,
1618 mrule_defs[i].mrd_normalize,
1619 mrule_defs[i].mrd_match,
1620 mrule_defs[i].mrd_indexer,
1621 mrule_defs[i].mrd_filter );
1625 "schema_init: Error registering matching rule %s\n",
1626 mrule_defs[i].mrd_desc );
1630 schema_init_done = 1;
1631 return LDAP_SUCCESS;