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"
20 /* recycled validatation routines */
21 #define berValidate blobValidate
23 /* unimplemented validators */
24 #define bitStringValidate NULL
26 /* recycled normalization routines */
27 #define faxNumberNormalize numericStringNormalize
28 #define phoneNumberNormalize numericStringNormalize
29 #define telexNumberNormalize numericStringNormalize
30 #define integerNormalize numericStringNormalize
32 /* unimplemented normalizers */
33 #define bitStringNormalize NULL
35 /* unimplemented pretters */
37 #define integerPretty NULL
39 /* recycled matching routines */
40 #define caseIgnoreMatch caseIgnoreIA5Match
41 #define caseIgnoreOrderingMatch caseIgnoreMatch
42 #define caseIgnoreSubstringsMatch caseIgnoreIA5SubstringsMatch
44 #define caseExactMatch caseExactIA5Match
45 #define caseExactOrderingMatch caseExactMatch
46 #define caseExactSubstringsMatch caseExactIA5SubstringsMatch
48 #define numericStringMatch caseIgnoreMatch
49 #define objectIdentifierMatch numericStringMatch
50 #define integerMatch numericStringMatch
51 #define telephoneNumberMatch numericStringMatch
52 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
53 #define generalizedTimeMatch numericStringMatch
54 #define generalizedTimeOrderingMatch numericStringMatch
56 /* approx matching rules */
57 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
58 #define directoryStringApproxMatch NULL
59 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
60 #define IA5StringApproxMatch NULL
62 /* unimplemented matching routines */
63 #define caseIgnoreListMatch NULL
64 #define caseIgnoreListSubstringsMatch NULL
65 #define bitStringMatch NULL
66 #define presentationAddressMatch NULL
67 #define uniqueMemberMatch NULL
68 #define protocolInformationMatch NULL
69 #define integerFirstComponentMatch NULL
71 #define OpenLDAPaciMatch NULL
72 #define authPasswordMatch NULL
74 /* recycled indexing/filtering routines */
75 #define caseIgnoreIndexer caseIgnoreIA5Indexer
76 #define caseIgnoreFilter caseIgnoreIA5Filter
77 #define caseExactIndexer caseExactIA5Indexer
78 #define caseExactFilter caseExactIA5Filter
79 #define dnIndexer caseIgnoreIndexer
80 #define dnFilter caseIgnoreFilter
82 #define caseIgnoreSubstringsIndexer caseIgnoreIA5SubstringsIndexer
83 #define caseIgnoreSubstringsFilter caseIgnoreIA5SubstringsFilter
84 #define caseExactSubstringsIndexer caseExactIA5SubstringsIndexer
85 #define caseExactSubstringsFilter caseExactIA5SubstringsFilter
97 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
100 match = memcmp( value->bv_val,
101 ((struct berval *) assertedValue)->bv_val,
109 /* Index generation function */
110 int octetStringIndexer(
114 struct berval *prefix,
115 struct berval **values,
116 struct berval ***keysp )
120 struct berval **keys;
121 lutil_MD5_CTX MD5context;
122 unsigned char MD5digest[16];
123 struct berval digest;
124 digest.bv_val = MD5digest;
125 digest.bv_len = sizeof(MD5digest);
127 for( i=0; values[i] != NULL; i++ ) {
128 /* just count them */
133 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
135 slen = strlen( syntax->ssyn_oid );
136 mlen = strlen( mr->smr_oid );
138 for( i=0; values[i] != NULL; i++ ) {
139 lutil_MD5Init( &MD5context );
140 if( prefix != NULL && prefix->bv_len > 0 ) {
141 lutil_MD5Update( &MD5context,
142 prefix->bv_val, prefix->bv_len );
144 lutil_MD5Update( &MD5context,
145 syntax->ssyn_oid, slen );
146 lutil_MD5Update( &MD5context,
148 lutil_MD5Update( &MD5context,
149 values[i]->bv_val, values[i]->bv_len );
150 lutil_MD5Final( MD5digest, &MD5context );
152 keys[i] = ber_bvdup( &digest );
162 /* Index generation function */
163 int octetStringFilter(
167 struct berval *prefix,
169 struct berval ***keysp )
172 struct berval **keys;
173 lutil_MD5_CTX MD5context;
174 unsigned char MD5digest[LUTIL_MD5_BYTES];
175 struct berval *value = (struct berval *) assertValue;
176 struct berval digest;
177 digest.bv_val = MD5digest;
178 digest.bv_len = sizeof(MD5digest);
180 slen = strlen( syntax->ssyn_oid );
181 mlen = strlen( mr->smr_oid );
183 keys = ch_malloc( sizeof( struct berval * ) * 2 );
185 lutil_MD5Init( &MD5context );
186 if( prefix != NULL && prefix->bv_len > 0 ) {
187 lutil_MD5Update( &MD5context,
188 prefix->bv_val, prefix->bv_len );
190 lutil_MD5Update( &MD5context,
191 syntax->ssyn_oid, slen );
192 lutil_MD5Update( &MD5context,
194 lutil_MD5Update( &MD5context,
195 value->bv_val, value->bv_len );
196 lutil_MD5Final( MD5digest, &MD5context );
198 keys[0] = ber_bvdup( &digest );
214 if( in->bv_len == 0 ) return LDAP_SUCCESS;
216 dn = ch_strdup( in->bv_val );
218 rc = dn_validate( dn ) == NULL
219 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
229 struct berval **normalized )
231 struct berval *out = ber_bvdup( val );
233 if( out->bv_len != 0 ) {
235 #ifdef USE_DN_NORMALIZE
236 dn = dn_normalize( out->bv_val );
238 dn = dn_validate( out->bv_val );
243 return LDAP_INVALID_SYNTAX;
247 out->bv_len = strlen( dn );
260 struct berval *value,
261 void *assertedValue )
264 struct berval *asserted = (struct berval *) assertedValue;
266 match = value->bv_len - asserted->bv_len;
269 #ifdef USE_DN_NORMALIZE
270 match = strcmp( value->bv_val, asserted->bv_val );
272 match = strcasecmp( value->bv_val, asserted->bv_val );
276 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
277 match, value->bv_val, asserted->bv_val );
288 /* any value allowed */
297 /* any value allowed */
302 * Handling boolean syntax and matching is quite rigid.
303 * A more flexible approach would be to allow a variety
304 * of strings to be normalized and prettied into TRUE
312 /* very unforgiving validation, requires no normalization
313 * before simplistic matching
316 if( in->bv_len == 4 ) {
317 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
320 } else if( in->bv_len == 5 ) {
321 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
326 return LDAP_INVALID_SYNTAX;
335 struct berval *value,
336 void *assertedValue )
338 /* simplistic matching allowed by rigid validation */
339 struct berval *asserted = (struct berval *) assertedValue;
340 *matchp = value->bv_len != asserted->bv_len;
351 unsigned char *u = in->bv_val;
353 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
355 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
356 /* get the length indicated by the first byte */
357 len = LDAP_UTF8_CHARLEN( u );
359 /* should not be zero */
360 if( len == 0 ) return LDAP_INVALID_SYNTAX;
362 /* make sure len corresponds with the offset
363 to the next character */
364 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
367 if( count != 0 ) return LDAP_INVALID_SYNTAX;
376 struct berval **normalized )
378 struct berval *newval;
381 newval = ch_malloc( sizeof( struct berval ) );
385 /* Ignore initial whitespace */
386 while ( ldap_utf8_isspace( p ) ) {
392 return LDAP_INVALID_SYNTAX;
395 newval->bv_val = ch_strdup( p );
396 p = q = newval->bv_val;
402 if ( ldap_utf8_isspace( p ) ) {
403 len = LDAP_UTF8_COPY(q,p);
408 /* Ignore the extra whitespace */
409 while ( ldap_utf8_isspace( p ) ) {
413 len = LDAP_UTF8_COPY(q,p);
420 assert( *newval->bv_val );
421 assert( newval->bv_val < p );
424 /* cannot start with a space */
425 assert( !ldap_utf8_isspace(newval->bv_val) );
428 * If the string ended in space, backup the pointer one
429 * position. One is enough because the above loop collapsed
430 * all whitespace to a single space.
437 /* cannot end with a space */
438 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
443 newval->bv_len = q - newval->bv_val;
444 *normalized = newval;
456 if( val->bv_len == 0 ) return 0;
458 if( OID_LEADCHAR(val->bv_val[0]) ) {
460 for(i=1; i < val->bv_len; i++) {
461 if( OID_SEPARATOR( val->bv_val[i] ) ) {
462 if( dot++ ) return 1;
463 } else if ( OID_CHAR( val->bv_val[i] ) ) {
466 return LDAP_INVALID_SYNTAX;
470 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
472 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
473 for(i=1; i < val->bv_len; i++) {
474 if( !DESC_CHAR(val->bv_val[i] ) ) {
475 return LDAP_INVALID_SYNTAX;
482 return LDAP_INVALID_SYNTAX;
492 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
494 for(i=0; i < val->bv_len; i++) {
495 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
502 printableStringValidate(
508 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
510 for(i=0; i < val->bv_len; i++) {
511 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
524 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
526 for(i=0; i < val->bv_len; i++) {
527 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
537 struct berval **out )
540 ber_len_t i, len = in->bv_len;
541 struct berval *bv = ch_malloc( sizeof(struct berval) );
543 bv->bv_len = len * sizeof( ldap_unicode_t );
544 u = (ldap_unicode_t *) ch_malloc( bv->bv_len + sizeof(ldap_unicode_t) );
545 bv->bv_val = (char *) u;
547 for(i=0; i < len; i++ ) {
549 * IA5StringValidate should have been called to ensure
550 * input is limited to IA5.
552 u[i] = in->bv_val[i];
564 struct berval **normalized )
566 struct berval *newval;
569 newval = ch_malloc( sizeof( struct berval ) );
573 /* Ignore initial whitespace */
574 while ( ASCII_SPACE( *p ) ) {
580 return LDAP_INVALID_SYNTAX;
583 newval->bv_val = ch_strdup( p );
584 p = q = newval->bv_val;
587 if ( ASCII_SPACE( *p ) ) {
590 /* Ignore the extra whitespace */
591 while ( ASCII_SPACE( *p ) ) {
599 assert( *newval->bv_val );
600 assert( newval->bv_val < p );
603 /* cannot start with a space */
604 assert( !ASCII_SPACE(*newval->bv_val) );
607 * If the string ended in space, backup the pointer one
608 * position. One is enough because the above loop collapsed
609 * all whitespace to a single space.
612 if ( ASCII_SPACE( q[-1] ) ) {
616 /* cannot end with a space */
617 assert( !ASCII_SPACE( q[-1] ) );
622 newval->bv_len = q - newval->bv_val;
623 *normalized = newval;
634 struct berval *value,
635 void *assertedValue )
637 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
640 match = strncmp( value->bv_val,
641 ((struct berval *) assertedValue)->bv_val,
650 caseExactIA5SubstringsMatch(
655 struct berval *value,
656 void *assertedValue )
659 SubstringsAssertion *sub = assertedValue;
660 struct berval left = *value;
664 /* Add up asserted input length */
665 if( sub->sa_initial ) {
666 inlen += sub->sa_initial->bv_len;
669 for(i=0; sub->sa_any[i] != NULL; i++) {
670 inlen += sub->sa_any[i]->bv_len;
673 if( sub->sa_final ) {
674 inlen += sub->sa_final->bv_len;
677 if( sub->sa_initial ) {
678 if( inlen > left.bv_len ) {
683 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
684 sub->sa_initial->bv_len );
690 left.bv_val += sub->sa_initial->bv_len;
691 left.bv_len -= sub->sa_initial->bv_len;
692 inlen -= sub->sa_initial->bv_len;
695 if( sub->sa_final ) {
696 if( inlen > left.bv_len ) {
701 match = strncmp( sub->sa_final->bv_val,
702 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
703 sub->sa_final->bv_len );
709 left.bv_len -= sub->sa_final->bv_len;
710 inlen -= sub->sa_final->bv_len;
714 for(i=0; sub->sa_any[i]; i++) {
719 if( inlen > left.bv_len ) {
720 /* not enough length */
725 if( sub->sa_any[i]->bv_len == 0 ) {
729 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
736 idx = p - left.bv_val;
737 assert( idx < left.bv_len );
739 if( idx >= left.bv_len ) {
740 /* this shouldn't happen */
747 if( sub->sa_any[i]->bv_len > left.bv_len ) {
748 /* not enough left */
753 match = strncmp( left.bv_val,
754 sub->sa_any[i]->bv_val,
755 sub->sa_any[i]->bv_len );
763 left.bv_val += sub->sa_any[i]->bv_len;
764 left.bv_len -= sub->sa_any[i]->bv_len;
765 inlen -= sub->sa_any[i]->bv_len;
774 /* Index generation function */
775 int caseExactIA5Indexer(
779 struct berval *prefix,
780 struct berval **values,
781 struct berval ***keysp )
785 struct berval **keys;
786 lutil_MD5_CTX MD5context;
787 unsigned char MD5digest[16];
788 struct berval digest;
789 digest.bv_val = MD5digest;
790 digest.bv_len = sizeof(MD5digest);
792 for( i=0; values[i] != NULL; i++ ) {
793 /* just count them */
798 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
800 slen = strlen( syntax->ssyn_oid );
801 mlen = strlen( mr->smr_oid );
803 for( i=0; values[i] != NULL; i++ ) {
804 struct berval *value = values[i];
806 lutil_MD5Init( &MD5context );
807 if( prefix != NULL && prefix->bv_len > 0 ) {
808 lutil_MD5Update( &MD5context,
809 prefix->bv_val, prefix->bv_len );
811 lutil_MD5Update( &MD5context,
812 syntax->ssyn_oid, slen );
813 lutil_MD5Update( &MD5context,
815 lutil_MD5Update( &MD5context,
816 value->bv_val, value->bv_len );
817 lutil_MD5Final( MD5digest, &MD5context );
819 keys[i] = ber_bvdup( &digest );
827 /* Index generation function */
828 int caseExactIA5Filter(
832 struct berval *prefix,
834 struct berval ***keysp )
837 struct berval **keys;
838 lutil_MD5_CTX MD5context;
839 unsigned char MD5digest[LUTIL_MD5_BYTES];
840 struct berval *value;
841 struct berval digest;
842 digest.bv_val = MD5digest;
843 digest.bv_len = sizeof(MD5digest);
845 slen = strlen( syntax->ssyn_oid );
846 mlen = strlen( mr->smr_oid );
848 value = (struct berval *) assertValue;
850 keys = ch_malloc( sizeof( struct berval * ) * 2 );
852 lutil_MD5Init( &MD5context );
853 if( prefix != NULL && prefix->bv_len > 0 ) {
854 lutil_MD5Update( &MD5context,
855 prefix->bv_val, prefix->bv_len );
857 lutil_MD5Update( &MD5context,
858 syntax->ssyn_oid, slen );
859 lutil_MD5Update( &MD5context,
861 lutil_MD5Update( &MD5context,
862 value->bv_val, value->bv_len );
863 lutil_MD5Final( MD5digest, &MD5context );
865 keys[0] = ber_bvdup( &digest );
871 /* Substrings Index generation function */
872 int caseExactIA5SubstringsIndexer(
876 struct berval *prefix,
877 struct berval **values,
878 struct berval ***keysp )
882 struct berval **keys;
883 lutil_MD5_CTX MD5context;
884 unsigned char MD5digest[16];
885 struct berval digest;
886 digest.bv_val = MD5digest;
887 digest.bv_len = sizeof(MD5digest);
890 if( flags & SLAP_MR_SUBSTR_INITIAL ) types++;
891 if( flags & SLAP_MR_SUBSTR_FINAL ) types++;
892 /* no SUBSTR_ANY indexing */
895 for( i=0; values[i] != NULL; i++ ) {
896 /* count number of indices to generate */
897 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
901 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
902 nkeys += SLAP_INDEX_SUBSTR_MAXLEN - ( SLAP_INDEX_SUBSTR_MINLEN - 1);
904 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
910 /* no keys to generate */
915 nkeys *= types; /* We need to generate keys for each type */
916 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
918 slen = strlen( syntax->ssyn_oid );
919 mlen = strlen( mr->smr_oid );
922 for( i=0; values[i] != NULL; i++ ) {
924 struct berval *value;
926 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
928 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
929 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
933 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
936 if( flags & SLAP_MR_SUBSTR_INITIAL ) {
937 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
938 lutil_MD5Init( &MD5context );
939 if( prefix != NULL && prefix->bv_len > 0 ) {
940 lutil_MD5Update( &MD5context,
941 prefix->bv_val, prefix->bv_len );
943 lutil_MD5Update( &MD5context,
944 &pre, sizeof( pre ) );
945 lutil_MD5Update( &MD5context,
946 syntax->ssyn_oid, slen );
947 lutil_MD5Update( &MD5context,
949 lutil_MD5Update( &MD5context,
951 lutil_MD5Final( MD5digest, &MD5context );
953 keys[nkeys++] = ber_bvdup( &digest );
956 if( flags & SLAP_MR_SUBSTR_FINAL ) {
957 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
958 lutil_MD5Init( &MD5context );
959 if( prefix != NULL && prefix->bv_len > 0 ) {
960 lutil_MD5Update( &MD5context,
961 prefix->bv_val, prefix->bv_len );
963 lutil_MD5Update( &MD5context,
964 &pre, sizeof( pre ) );
965 lutil_MD5Update( &MD5context,
966 syntax->ssyn_oid, slen );
967 lutil_MD5Update( &MD5context,
969 lutil_MD5Update( &MD5context,
970 &value->bv_val[value->bv_len-j], j );
971 lutil_MD5Final( MD5digest, &MD5context );
973 keys[nkeys++] = ber_bvdup( &digest );
984 int caseExactIA5SubstringsFilter(
988 struct berval *prefix,
990 struct berval ***keysp )
992 SubstringsAssertion *sa = assertValue;
995 size_t slen, mlen, klen;
996 struct berval **keys;
997 lutil_MD5_CTX MD5context;
998 unsigned char MD5digest[LUTIL_MD5_BYTES];
999 struct berval *value;
1000 struct berval digest;
1002 if( sa->sa_initial != NULL &&
1003 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1007 if( sa->sa_final != NULL &&
1008 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1015 return LDAP_SUCCESS;
1018 digest.bv_val = MD5digest;
1019 digest.bv_len = sizeof(MD5digest);
1021 slen = strlen( syntax->ssyn_oid );
1022 mlen = strlen( mr->smr_oid );
1024 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1027 if( sa->sa_initial != NULL &&
1028 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1030 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1031 value = sa->sa_initial;
1033 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1034 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1036 lutil_MD5Init( &MD5context );
1037 if( prefix != NULL && prefix->bv_len > 0 ) {
1038 lutil_MD5Update( &MD5context,
1039 prefix->bv_val, prefix->bv_len );
1041 lutil_MD5Update( &MD5context,
1042 &pre, sizeof( pre ) );
1043 lutil_MD5Update( &MD5context,
1044 syntax->ssyn_oid, slen );
1045 lutil_MD5Update( &MD5context,
1046 mr->smr_oid, mlen );
1047 lutil_MD5Update( &MD5context,
1048 value->bv_val, klen );
1049 lutil_MD5Final( MD5digest, &MD5context );
1051 ber_bvfree( value );
1052 keys[nkeys++] = ber_bvdup( &digest );
1055 if( sa->sa_final != NULL &&
1056 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1058 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1059 value = sa->sa_final;
1061 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1062 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1064 lutil_MD5Init( &MD5context );
1065 if( prefix != NULL && prefix->bv_len > 0 ) {
1066 lutil_MD5Update( &MD5context,
1067 prefix->bv_val, prefix->bv_len );
1069 lutil_MD5Update( &MD5context,
1070 &pre, sizeof( pre ) );
1071 lutil_MD5Update( &MD5context,
1072 syntax->ssyn_oid, slen );
1073 lutil_MD5Update( &MD5context,
1074 mr->smr_oid, mlen );
1075 lutil_MD5Update( &MD5context,
1076 &value->bv_val[value->bv_len-klen], klen );
1077 lutil_MD5Final( MD5digest, &MD5context );
1079 ber_bvfree( value );
1080 keys[nkeys++] = ber_bvdup( &digest );
1086 return LDAP_SUCCESS;
1095 struct berval *value,
1096 void *assertedValue )
1098 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1101 match = strncasecmp( value->bv_val,
1102 ((struct berval *) assertedValue)->bv_val,
1107 return LDAP_SUCCESS;
1110 static char *strcasechr( const char *str, int c )
1112 char *lower = strchr( str, TOLOWER(c) );
1113 char *upper = strchr( str, TOUPPER(c) );
1115 if( lower && upper ) {
1116 return lower < upper ? lower : upper;
1117 } else if ( lower ) {
1125 caseIgnoreIA5SubstringsMatch(
1130 struct berval *value,
1131 void *assertedValue )
1134 SubstringsAssertion *sub = assertedValue;
1135 struct berval left = *value;
1139 /* Add up asserted input length */
1140 if( sub->sa_initial ) {
1141 inlen += sub->sa_initial->bv_len;
1144 for(i=0; sub->sa_any[i] != NULL; i++) {
1145 inlen += sub->sa_any[i]->bv_len;
1148 if( sub->sa_final ) {
1149 inlen += sub->sa_final->bv_len;
1152 if( sub->sa_initial ) {
1153 if( inlen > left.bv_len ) {
1158 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1159 sub->sa_initial->bv_len );
1165 left.bv_val += sub->sa_initial->bv_len;
1166 left.bv_len -= sub->sa_initial->bv_len;
1167 inlen -= sub->sa_initial->bv_len;
1170 if( sub->sa_final ) {
1171 if( inlen > left.bv_len ) {
1176 match = strncasecmp( sub->sa_final->bv_val,
1177 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1178 sub->sa_final->bv_len );
1184 left.bv_len -= sub->sa_final->bv_len;
1185 inlen -= sub->sa_final->bv_len;
1189 for(i=0; sub->sa_any[i]; i++) {
1194 if( inlen > left.bv_len ) {
1195 /* not enough length */
1200 if( sub->sa_any[i]->bv_len == 0 ) {
1204 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1211 idx = p - left.bv_val;
1212 assert( idx < left.bv_len );
1214 if( idx >= left.bv_len ) {
1215 /* this shouldn't happen */
1222 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1223 /* not enough left */
1228 match = strncasecmp( left.bv_val,
1229 sub->sa_any[i]->bv_val,
1230 sub->sa_any[i]->bv_len );
1239 left.bv_val += sub->sa_any[i]->bv_len;
1240 left.bv_len -= sub->sa_any[i]->bv_len;
1241 inlen -= sub->sa_any[i]->bv_len;
1247 return LDAP_SUCCESS;
1250 /* Index generation function */
1251 int caseIgnoreIA5Indexer(
1255 struct berval *prefix,
1256 struct berval **values,
1257 struct berval ***keysp )
1261 struct berval **keys;
1262 lutil_MD5_CTX MD5context;
1263 unsigned char MD5digest[16];
1264 struct berval digest;
1265 digest.bv_val = MD5digest;
1266 digest.bv_len = sizeof(MD5digest);
1268 for( i=0; values[i] != NULL; i++ ) {
1269 /* just count them */
1274 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1276 slen = strlen( syntax->ssyn_oid );
1277 mlen = strlen( mr->smr_oid );
1279 for( i=0; values[i] != NULL; i++ ) {
1280 struct berval *value = ber_bvdup( values[i] );
1281 ldap_pvt_str2upper( value->bv_val );
1283 lutil_MD5Init( &MD5context );
1284 if( prefix != NULL && prefix->bv_len > 0 ) {
1285 lutil_MD5Update( &MD5context,
1286 prefix->bv_val, prefix->bv_len );
1288 lutil_MD5Update( &MD5context,
1289 syntax->ssyn_oid, slen );
1290 lutil_MD5Update( &MD5context,
1291 mr->smr_oid, mlen );
1292 lutil_MD5Update( &MD5context,
1293 value->bv_val, value->bv_len );
1294 lutil_MD5Final( MD5digest, &MD5context );
1296 ber_bvfree( value );
1298 keys[i] = ber_bvdup( &digest );
1303 return LDAP_SUCCESS;
1306 /* Index generation function */
1307 int caseIgnoreIA5Filter(
1311 struct berval *prefix,
1313 struct berval ***keysp )
1316 struct berval **keys;
1317 lutil_MD5_CTX MD5context;
1318 unsigned char MD5digest[LUTIL_MD5_BYTES];
1319 struct berval *value;
1320 struct berval digest;
1321 digest.bv_val = MD5digest;
1322 digest.bv_len = sizeof(MD5digest);
1324 slen = strlen( syntax->ssyn_oid );
1325 mlen = strlen( mr->smr_oid );
1327 value = ber_bvdup( (struct berval *) assertValue );
1328 ldap_pvt_str2upper( value->bv_val );
1330 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1332 lutil_MD5Init( &MD5context );
1333 if( prefix != NULL && prefix->bv_len > 0 ) {
1334 lutil_MD5Update( &MD5context,
1335 prefix->bv_val, prefix->bv_len );
1337 lutil_MD5Update( &MD5context,
1338 syntax->ssyn_oid, slen );
1339 lutil_MD5Update( &MD5context,
1340 mr->smr_oid, mlen );
1341 lutil_MD5Update( &MD5context,
1342 value->bv_val, value->bv_len );
1343 lutil_MD5Final( MD5digest, &MD5context );
1345 keys[0] = ber_bvdup( &digest );
1348 ber_bvfree( value );
1351 return LDAP_SUCCESS;
1354 /* Substrings Index generation function */
1355 int caseIgnoreIA5SubstringsIndexer(
1359 struct berval *prefix,
1360 struct berval **values,
1361 struct berval ***keysp )
1363 int i, nkeys, types;
1365 struct berval **keys;
1366 lutil_MD5_CTX MD5context;
1367 unsigned char MD5digest[16];
1368 struct berval digest;
1369 digest.bv_val = MD5digest;
1370 digest.bv_len = sizeof(MD5digest);
1373 if( flags & SLAP_MR_SUBSTR_INITIAL ) types++;
1374 if( flags & SLAP_MR_SUBSTR_FINAL ) types++;
1375 /* no SUBSTR_ANY indexing */
1378 for( i=0; values[i] != NULL; i++ ) {
1379 /* count number of indices to generate */
1380 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1384 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1385 nkeys += SLAP_INDEX_SUBSTR_MAXLEN - ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1387 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1393 /* no keys to generate */
1395 return LDAP_SUCCESS;
1398 nkeys *= types; /* We need to generate keys for each type */
1399 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1401 slen = strlen( syntax->ssyn_oid );
1402 mlen = strlen( mr->smr_oid );
1405 for( i=0; values[i] != NULL; i++ ) {
1407 struct berval *value;
1409 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1411 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i]->bv_len
1412 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i]->bv_len;
1414 value = ber_bvdup( values[i] );
1415 ldap_pvt_str2upper( value->bv_val );
1417 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1420 if( flags & SLAP_MR_SUBSTR_INITIAL ) {
1421 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1422 lutil_MD5Init( &MD5context );
1423 if( prefix != NULL && prefix->bv_len > 0 ) {
1424 lutil_MD5Update( &MD5context,
1425 prefix->bv_val, prefix->bv_len );
1427 lutil_MD5Update( &MD5context,
1428 &pre, sizeof( pre ) );
1429 lutil_MD5Update( &MD5context,
1430 syntax->ssyn_oid, slen );
1431 lutil_MD5Update( &MD5context,
1432 mr->smr_oid, mlen );
1433 lutil_MD5Update( &MD5context,
1435 lutil_MD5Final( MD5digest, &MD5context );
1437 keys[nkeys++] = ber_bvdup( &digest );
1440 if( flags & SLAP_MR_SUBSTR_FINAL ) {
1441 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1442 lutil_MD5Init( &MD5context );
1443 if( prefix != NULL && prefix->bv_len > 0 ) {
1444 lutil_MD5Update( &MD5context,
1445 prefix->bv_val, prefix->bv_len );
1447 lutil_MD5Update( &MD5context,
1448 &pre, sizeof( pre ) );
1449 lutil_MD5Update( &MD5context,
1450 syntax->ssyn_oid, slen );
1451 lutil_MD5Update( &MD5context,
1452 mr->smr_oid, mlen );
1453 lutil_MD5Update( &MD5context,
1454 &value->bv_val[value->bv_len-j], j );
1455 lutil_MD5Final( MD5digest, &MD5context );
1457 keys[nkeys++] = ber_bvdup( &digest );
1462 ber_bvfree( value );
1467 return LDAP_SUCCESS;
1470 int caseIgnoreIA5SubstringsFilter(
1474 struct berval *prefix,
1476 struct berval ***keysp )
1478 SubstringsAssertion *sa = assertValue;
1481 size_t slen, mlen, klen;
1482 struct berval **keys;
1483 lutil_MD5_CTX MD5context;
1484 unsigned char MD5digest[LUTIL_MD5_BYTES];
1485 struct berval *value;
1486 struct berval digest;
1488 if( sa->sa_initial != NULL &&
1489 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1493 if( sa->sa_final != NULL &&
1494 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1501 return LDAP_SUCCESS;
1504 digest.bv_val = MD5digest;
1505 digest.bv_len = sizeof(MD5digest);
1507 slen = strlen( syntax->ssyn_oid );
1508 mlen = strlen( mr->smr_oid );
1510 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1513 if( sa->sa_initial != NULL &&
1514 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1516 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1517 value = ber_bvdup( sa->sa_initial );
1518 ldap_pvt_str2upper( value->bv_val );
1520 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1521 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1523 lutil_MD5Init( &MD5context );
1524 if( prefix != NULL && prefix->bv_len > 0 ) {
1525 lutil_MD5Update( &MD5context,
1526 prefix->bv_val, prefix->bv_len );
1528 lutil_MD5Update( &MD5context,
1529 &pre, sizeof( pre ) );
1530 lutil_MD5Update( &MD5context,
1531 syntax->ssyn_oid, slen );
1532 lutil_MD5Update( &MD5context,
1533 mr->smr_oid, mlen );
1534 lutil_MD5Update( &MD5context,
1535 value->bv_val, klen );
1536 lutil_MD5Final( MD5digest, &MD5context );
1538 ber_bvfree( value );
1539 keys[nkeys++] = ber_bvdup( &digest );
1542 if( sa->sa_final != NULL &&
1543 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1545 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1546 value = ber_bvdup( sa->sa_final );
1547 ldap_pvt_str2upper( value->bv_val );
1549 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1550 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1552 lutil_MD5Init( &MD5context );
1553 if( prefix != NULL && prefix->bv_len > 0 ) {
1554 lutil_MD5Update( &MD5context,
1555 prefix->bv_val, prefix->bv_len );
1557 lutil_MD5Update( &MD5context,
1558 &pre, sizeof( pre ) );
1559 lutil_MD5Update( &MD5context,
1560 syntax->ssyn_oid, slen );
1561 lutil_MD5Update( &MD5context,
1562 mr->smr_oid, mlen );
1563 lutil_MD5Update( &MD5context,
1564 &value->bv_val[value->bv_len-klen], klen );
1565 lutil_MD5Final( MD5digest, &MD5context );
1567 ber_bvfree( value );
1568 keys[nkeys++] = ber_bvdup( &digest );
1574 return LDAP_SUCCESS;
1578 numericStringNormalize(
1581 struct berval **normalized )
1583 /* similiar to IA5StringNormalize except removes all spaces */
1584 struct berval *newval;
1587 newval = ch_malloc( sizeof( struct berval ) );
1591 /* Ignore initial whitespace */
1592 while ( ASCII_SPACE( *p ) ) {
1598 return LDAP_INVALID_SYNTAX;
1601 newval->bv_val = ch_strdup( p );
1602 p = q = newval->bv_val;
1605 if ( ASCII_SPACE( *p ) ) {
1606 /* Ignore whitespace */
1613 assert( *newval->bv_val );
1614 assert( newval->bv_val < p );
1617 /* cannot start with a space */
1618 assert( !ASCII_SPACE(*newval->bv_val) );
1620 /* cannot end with a space */
1621 assert( !ASCII_SPACE( q[-1] ) );
1623 /* null terminate */
1626 newval->bv_len = q - newval->bv_val;
1627 *normalized = newval;
1629 return LDAP_SUCCESS;
1633 objectIdentifierFirstComponentMatch(
1638 struct berval *value,
1639 void *assertedValue )
1641 int rc = LDAP_SUCCESS;
1643 struct berval *asserted = (struct berval *) assertedValue;
1647 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
1648 return LDAP_INVALID_SYNTAX;
1651 /* trim leading white space */
1652 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
1656 /* grab next word */
1657 oid.bv_val = &value->bv_val[i];
1658 oid.bv_len = value->bv_len - i;
1659 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
1664 /* insert attributeTypes, objectclass check here */
1665 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
1666 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
1669 char *stored = ch_malloc( oid.bv_len + 1 );
1670 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
1671 stored[oid.bv_len] = '\0';
1673 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
1674 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
1675 MatchingRule *stored_mr = mr_find( stored );
1677 if( asserted_mr == NULL ) {
1678 rc = SLAPD_COMPARE_UNDEFINED;
1680 match = asserted_mr != stored_mr;
1683 } else if ( !strcmp( syntax->ssyn_oid,
1684 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
1686 AttributeType *asserted_at = at_find( asserted->bv_val );
1687 AttributeType *stored_at = at_find( stored );
1689 if( asserted_at == NULL ) {
1690 rc = SLAPD_COMPARE_UNDEFINED;
1692 match = asserted_at != stored_at;
1695 } else if ( !strcmp( syntax->ssyn_oid,
1696 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
1698 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
1699 ObjectClass *stored_oc = oc_find( stored );
1701 if( asserted_oc == NULL ) {
1702 rc = SLAPD_COMPARE_UNDEFINED;
1704 match = asserted_oc != stored_oc;
1711 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
1712 "%d\n\t\"%s\"\n\t\"%s\"\n",
1713 match, value->bv_val, asserted->bv_val );
1715 if( rc == LDAP_SUCCESS ) *matchp = match;
1720 check_time_syntax (struct berval *val,
1724 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
1725 static int mdays[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
1727 int part, c, neg = 0;
1729 if( val->bv_len == 0 )
1730 return LDAP_INVALID_SYNTAX;
1732 p = (char *)val->bv_val;
1733 e = p + val->bv_len;
1735 /* Ignore initial whitespace */
1736 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
1740 if (e - p < 13 - (2 * start))
1741 return LDAP_INVALID_SYNTAX;
1743 for (part = 0; part < 9; part++)
1746 for (part = start; part < 7; part++) {
1759 return LDAP_INVALID_SYNTAX;
1761 return LDAP_INVALID_SYNTAX;
1766 return LDAP_INVALID_SYNTAX;
1768 return LDAP_INVALID_SYNTAX;
1772 if (part == 2 || part == 3)
1774 if (parts[part] < 0)
1775 return LDAP_INVALID_SYNTAX;
1776 if (parts[part] > ceiling[part])
1777 return LDAP_INVALID_SYNTAX;
1779 if (parts[2] == 1) {
1780 if (parts[3] > mdays[parts[2]])
1781 return LDAP_INVALID_SYNTAX;
1782 if (parts[1] & 0x03) {
1783 /* FIXME: This is an incomplete leap-year
1784 * check that fails in 2100, 2200, 2300,
1785 * 2500, 2600, 2700, ...
1787 if (parts[3] > mdays[parts[2]] - 1)
1788 return LDAP_INVALID_SYNTAX;
1794 } else if (c != '+' && c != '-') {
1795 return LDAP_INVALID_SYNTAX;
1800 return LDAP_INVALID_SYNTAX;
1801 for (part = 7; part < 9; part++) {
1804 return LDAP_INVALID_SYNTAX;
1809 return LDAP_INVALID_SYNTAX;
1812 if (parts[part] < 0 || parts[part] > ceiling[part])
1813 return LDAP_INVALID_SYNTAX;
1817 /* Ignore trailing whitespace */
1818 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
1822 return LDAP_INVALID_SYNTAX;
1825 parts[4] += parts[7];
1826 parts[5] += parts[8];
1827 for (part = 7; --part > 0; ) {
1831 /* FIXME: This is an incomplete leap-year
1832 * check that fails in 2100, 2200, 2300,
1833 * 2500, 2600, 2700, ...
1835 c = mdays[parts[2]];
1839 if (parts[part] > c) {
1840 parts[part] -= c + 1;
1845 parts[4] -= parts[7];
1846 parts[5] -= parts[8];
1847 for (part = 7; --part > 0; ) {
1851 /* FIXME: This is an incomplete leap-year
1852 * check that fails in 2100, 2200, 2300,
1853 * 2500, 2600, 2700, ...
1855 c = mdays[(parts[2] - 1) % 12];
1859 if (parts[part] < 0) {
1860 parts[part] += c + 1;
1866 return LDAP_SUCCESS;
1873 struct berval **normalized )
1878 rc = check_time_syntax(val, 1, parts);
1879 if (rc != LDAP_SUCCESS) {
1884 out = ch_malloc( sizeof(struct berval) );
1886 return LBER_ERROR_MEMORY;
1888 out->bv_val = ch_malloc( 14 );
1889 if ( out->bv_val == NULL ) {
1891 return LBER_ERROR_MEMORY;
1894 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
1895 parts[1], parts[2] + 1, parts[3] + 1,
1896 parts[4], parts[5], parts[6] );
1900 return LDAP_SUCCESS;
1910 return check_time_syntax(in, 1, parts);
1914 generalizedTimeValidate(
1920 return check_time_syntax(in, 0, parts);
1924 generalizedTimeNormalize(
1927 struct berval **normalized )
1932 rc = check_time_syntax(val, 0, parts);
1933 if (rc != LDAP_SUCCESS) {
1938 out = ch_malloc( sizeof(struct berval) );
1940 return LBER_ERROR_MEMORY;
1942 out->bv_val = ch_malloc( 16 );
1943 if ( out->bv_val == NULL ) {
1945 return LBER_ERROR_MEMORY;
1948 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
1949 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
1950 parts[4], parts[5], parts[6] );
1954 return LDAP_SUCCESS;
1957 struct syntax_defs_rec {
1960 slap_syntax_validate_func *sd_validate;
1961 slap_syntax_transform_func *sd_normalize;
1962 slap_syntax_transform_func *sd_pretty;
1963 #ifdef SLAPD_BINARY_CONVERSION
1964 slap_syntax_transform_func *sd_ber2str;
1965 slap_syntax_transform_func *sd_str2ber;
1969 #define X_HIDE "X-HIDE 'TRUE' "
1970 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
1971 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
1973 struct syntax_defs_rec syntax_defs[] = {
1974 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
1975 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
1976 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
1977 0, NULL, NULL, NULL},
1978 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
1979 0, NULL, NULL, NULL},
1980 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
1981 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
1982 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
1983 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1984 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
1985 0, bitStringValidate, bitStringNormalize, NULL },
1986 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
1987 0, booleanValidate, NULL, NULL},
1988 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
1989 X_BINARY X_NOT_H_R ")",
1990 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1991 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
1992 X_BINARY X_NOT_H_R ")",
1993 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1994 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
1995 X_BINARY X_NOT_H_R ")",
1996 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1997 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
1998 0, NULL, NULL, NULL},
1999 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
2000 0, dnValidate, dnNormalize, dnPretty},
2001 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
2002 0, NULL, NULL, NULL},
2003 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
2004 0, NULL, NULL, NULL},
2005 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
2006 0, UTF8StringValidate, UTF8StringNormalize, NULL},
2007 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
2008 0, NULL, NULL, NULL},
2009 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
2010 0, NULL, NULL, NULL},
2011 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
2012 0, NULL, NULL, NULL},
2013 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
2014 0, NULL, NULL, NULL},
2015 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
2016 0, NULL, NULL, NULL},
2017 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
2018 0, IA5StringValidate, faxNumberNormalize, NULL},
2019 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
2020 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
2021 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
2022 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
2023 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
2024 0, NULL, NULL, NULL},
2025 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
2026 0, IA5StringValidate, IA5StringNormalize, NULL},
2027 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
2028 0, integerValidate, integerNormalize, integerPretty},
2029 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
2030 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
2031 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
2032 0, NULL, NULL, NULL},
2033 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
2034 0, NULL, NULL, NULL},
2035 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
2036 0, NULL, NULL, NULL},
2037 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
2038 0, NULL, NULL, NULL},
2039 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
2040 0, NULL, NULL, NULL},
2041 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
2042 0, NULL, NULL, NULL},
2043 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
2044 0, NULL, NULL, NULL},
2045 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
2046 0, IA5StringValidate, numericStringNormalize, NULL},
2047 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
2048 0, NULL, NULL, NULL},
2049 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
2050 0, oidValidate, NULL, NULL},
2051 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
2052 0, NULL, NULL, NULL},
2053 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
2054 0, blobValidate, NULL, NULL},
2055 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
2056 0, blobValidate, NULL, NULL},
2057 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
2058 0, NULL, NULL, NULL},
2059 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
2060 0, NULL, NULL, NULL},
2061 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
2062 0, printableStringValidate, NULL, NULL},
2063 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
2064 X_BINARY X_NOT_H_R ")",
2065 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
2066 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
2067 0, IA5StringValidate, phoneNumberNormalize, NULL},
2068 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
2069 0, NULL, NULL, NULL},
2070 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
2071 0, IA5StringValidate, telexNumberNormalize, NULL},
2072 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
2073 0, utcTimeValidate, utcTimeNormalize, NULL},
2074 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
2075 0, NULL, NULL, NULL},
2076 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
2077 0, NULL, NULL, NULL},
2078 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
2079 0, NULL, NULL, NULL},
2080 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
2081 0, NULL, NULL, NULL},
2082 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
2083 0, NULL, NULL, NULL},
2085 /* OpenLDAP Experimental Syntaxes */
2086 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
2087 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */, NULL, NULL},
2088 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
2089 0, NULL, NULL, NULL},
2090 {"( 1.3.6.1.4.1.4203.666.2.3 DESC 'OpenLDAP void' " X_HIDE ")" ,
2091 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
2092 #if 0 /* not needed */
2093 {"( 1.3.6.1.4.1.4203.666.2.4 DESC 'OpenLDAP DN' " X_HIDE ")" ,
2094 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
2097 {NULL, 0, NULL, NULL, NULL}
2100 struct mrule_defs_rec {
2103 slap_mr_convert_func * mrd_convert;
2104 slap_mr_normalize_func * mrd_normalize;
2105 slap_mr_match_func * mrd_match;
2106 slap_mr_indexer_func * mrd_indexer;
2107 slap_mr_filter_func * mrd_filter;
2109 char * mrd_associated;
2113 * Other matching rules in X.520 that we do not use (yet):
2115 * 2.5.13.9 numericStringOrderingMatch
2116 * 2.5.13.13 booleanMatch
2117 * 2.5.13.15 integerOrderingMatch
2118 * 2.5.13.18 octetStringOrderingMatch
2119 * 2.5.13.19 octetStringSubstringsMatch
2120 * 2.5.13.25 uTCTimeMatch
2121 * 2.5.13.26 uTCTimeOrderingMatch
2122 * 2.5.13.31 directoryStringFirstComponentMatch
2123 * 2.5.13.32 wordMatch
2124 * 2.5.13.33 keywordMatch
2125 * 2.5.13.34 certificateExactMatch
2126 * 2.5.13.35 certificateMatch
2127 * 2.5.13.36 certificatePairExactMatch
2128 * 2.5.13.37 certificatePairMatch
2129 * 2.5.13.38 certificateListExactMatch
2130 * 2.5.13.39 certificateListMatch
2131 * 2.5.13.40 algorithmIdentifierMatch
2132 * 2.5.13.41 storedPrefixMatch
2133 * 2.5.13.42 attributeCertificateMatch
2134 * 2.5.13.43 readerAndKeyIDMatch
2135 * 2.5.13.44 attributeIntegrityMatch
2138 struct mrule_defs_rec mrule_defs[] = {
2140 * EQUALITY matching rules must be listed after associated APPROX
2141 * matching rules. So, we list all APPROX matching rules first.
2143 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
2144 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2145 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
2147 directoryStringApproxMatch, NULL, NULL,
2150 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
2151 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2152 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
2154 IA5StringApproxMatch, NULL, NULL,
2158 * Other matching rules
2161 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
2162 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
2163 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2165 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
2168 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
2169 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
2170 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2172 dnMatch, dnIndexer, dnFilter,
2175 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
2176 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2177 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2179 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
2180 directoryStringApproxMatchOID },
2182 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
2183 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2186 caseIgnoreOrderingMatch, NULL, NULL,
2189 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
2190 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2191 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2193 caseIgnoreSubstringsMatch,
2194 caseIgnoreSubstringsIndexer,
2195 caseIgnoreSubstringsFilter,
2198 {"( 2.5.13.5 NAME 'caseExactMatch' "
2199 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2200 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2202 caseExactMatch, caseExactIndexer, caseExactFilter,
2203 directoryStringApproxMatchOID },
2205 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
2206 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2209 caseExactOrderingMatch, NULL, NULL,
2212 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
2213 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2214 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2216 caseExactSubstringsMatch,
2217 caseExactSubstringsIndexer,
2218 caseExactSubstringsFilter,
2221 {"( 2.5.13.8 NAME 'numericStringMatch' "
2222 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
2223 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2225 caseIgnoreIA5Match, NULL, NULL,
2228 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
2229 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2230 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2232 caseIgnoreIA5SubstringsMatch,
2233 caseIgnoreIA5SubstringsIndexer,
2234 caseIgnoreIA5SubstringsFilter,
2237 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
2238 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
2239 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2241 caseIgnoreListMatch, NULL, NULL,
2244 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
2245 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2246 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2248 caseIgnoreListSubstringsMatch, NULL, NULL,
2251 {"( 2.5.13.13 NAME 'booleanMatch' "
2252 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
2253 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2255 booleanMatch, NULL, NULL,
2258 {"( 2.5.13.14 NAME 'integerMatch' "
2259 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
2260 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2262 integerMatch, NULL, NULL,
2265 {"( 2.5.13.16 NAME 'bitStringMatch' "
2266 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
2267 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2269 bitStringMatch, NULL, NULL,
2272 {"( 2.5.13.17 NAME 'octetStringMatch' "
2273 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
2274 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2276 octetStringMatch, octetStringIndexer, octetStringFilter,
2279 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
2280 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
2281 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2283 telephoneNumberMatch, NULL, NULL,
2286 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
2287 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2288 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2290 telephoneNumberSubstringsMatch, NULL, NULL,
2293 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
2294 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
2295 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2297 presentationAddressMatch, NULL, NULL,
2300 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
2301 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
2302 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2304 uniqueMemberMatch, NULL, NULL,
2307 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
2308 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
2309 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2311 protocolInformationMatch, NULL, NULL,
2314 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
2315 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
2316 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2318 generalizedTimeMatch, NULL, NULL,
2321 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
2322 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
2325 generalizedTimeOrderingMatch, NULL, NULL,
2328 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
2329 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
2330 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2332 integerFirstComponentMatch, NULL, NULL,
2335 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
2336 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
2337 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2339 objectIdentifierFirstComponentMatch, NULL, NULL,
2342 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
2343 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2344 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2346 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
2347 IA5StringApproxMatchOID },
2349 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
2350 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2351 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2353 caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
2354 IA5StringApproxMatchOID },
2356 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
2357 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2360 caseIgnoreIA5SubstringsMatch,
2361 caseIgnoreIA5SubstringsIndexer,
2362 caseIgnoreIA5SubstringsFilter,
2365 {"( 1.3.6.1.4.1.4203.666.4.3 NAME 'caseExactIA5SubstringsMatch' "
2366 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2369 caseExactIA5SubstringsMatch,
2370 caseExactIA5SubstringsIndexer,
2371 caseExactIA5SubstringsFilter,
2374 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
2375 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
2378 authPasswordMatch, NULL, NULL,
2381 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
2382 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
2385 OpenLDAPaciMatch, NULL, NULL,
2388 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
2397 /* we should only be called once (from main) */
2398 assert( schema_init_done == 0 );
2400 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
2401 res = register_syntax( syntax_defs[i].sd_desc,
2402 syntax_defs[i].sd_flags,
2403 syntax_defs[i].sd_validate,
2404 syntax_defs[i].sd_normalize,
2405 syntax_defs[i].sd_pretty
2406 #ifdef SLAPD_BINARY_CONVERSION
2408 syntax_defs[i].sd_ber2str,
2409 syntax_defs[i].sd_str2ber
2414 fprintf( stderr, "schema_init: Error registering syntax %s\n",
2415 syntax_defs[i].sd_desc );
2420 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
2421 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
2423 "schema_init: Ingoring unusable matching rule %s\n",
2424 mrule_defs[i].mrd_desc );
2428 res = register_matching_rule(
2429 mrule_defs[i].mrd_desc,
2430 mrule_defs[i].mrd_usage,
2431 mrule_defs[i].mrd_convert,
2432 mrule_defs[i].mrd_normalize,
2433 mrule_defs[i].mrd_match,
2434 mrule_defs[i].mrd_indexer,
2435 mrule_defs[i].mrd_filter,
2436 mrule_defs[i].mrd_associated );
2440 "schema_init: Error registering matching rule %s\n",
2441 mrule_defs[i].mrd_desc );
2445 schema_init_done = 1;
2446 return LDAP_SUCCESS;