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
22 #define nameUIDValidate dnValidate
24 /* unimplemented validators */
25 #define bitStringValidate NULL
27 /* recycled normalization routines */
28 #define faxNumberNormalize numericStringNormalize
29 #define phoneNumberNormalize numericStringNormalize
30 #define telexNumberNormalize numericStringNormalize
31 #define nameUIDNormalize dnNormalize
33 /* unimplemented normalizers */
34 #define bitStringNormalize NULL
36 /* unimplemented pretters */
38 #define integerPretty NULL
40 /* recyclied pretters */
41 #define nameUIDPretty dnPretty
43 /* recycled matching routines */
44 #define integerMatch caseIgnoreIA5Match
45 #define numericStringMatch caseIgnoreMatch
46 #define objectIdentifierMatch numericStringMatch
47 #define telephoneNumberMatch numericStringMatch
48 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
49 #define generalizedTimeMatch numericStringMatch
50 #define generalizedTimeOrderingMatch numericStringMatch
51 #define uniqueMemberMatch dnMatch
53 /* approx matching rules */
54 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
55 #define directoryStringApproxMatch NULL
56 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
57 #define IA5StringApproxMatch NULL
59 /* orderring matching rules */
60 #define caseIgnoreOrderingMatch caseIgnoreMatch
61 #define caseExactOrderingMatch caseExactMatch
63 /* unimplemented matching routines */
64 #define caseIgnoreListMatch NULL
65 #define caseIgnoreListSubstringsMatch NULL
66 #define bitStringMatch NULL
67 #define presentationAddressMatch NULL
68 #define protocolInformationMatch NULL
69 #define integerFirstComponentMatch NULL
71 #define OpenLDAPaciMatch NULL
72 #define authPasswordMatch NULL
74 /* recycled indexing/filtering routines */
75 #define dnIndexer caseIgnoreIndexer
76 #define dnFilter caseIgnoreFilter
77 #define integerIndexer caseIgnoreIA5Indexer
78 #define integerFilter caseIgnoreIA5Filter
80 static char *strcasechr( const char *str, int c )
82 char *lower = strchr( str, TOLOWER(c) );
83 char *upper = strchr( str, TOUPPER(c) );
85 if( lower && upper ) {
86 return lower < upper ? lower : upper;
100 struct berval *value,
101 void *assertedValue )
103 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
106 match = memcmp( value->bv_val,
107 ((struct berval *) assertedValue)->bv_val,
115 /* Index generation function */
116 int octetStringIndexer(
121 struct berval *prefix,
122 struct berval **values,
123 struct berval ***keysp )
127 struct berval **keys;
128 lutil_MD5_CTX MD5context;
129 unsigned char MD5digest[16];
130 struct berval digest;
131 digest.bv_val = MD5digest;
132 digest.bv_len = sizeof(MD5digest);
134 for( i=0; values[i] != NULL; i++ ) {
135 /* just count them */
140 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
142 slen = strlen( syntax->ssyn_oid );
143 mlen = strlen( mr->smr_oid );
145 for( i=0; values[i] != NULL; i++ ) {
146 lutil_MD5Init( &MD5context );
147 if( prefix != NULL && prefix->bv_len > 0 ) {
148 lutil_MD5Update( &MD5context,
149 prefix->bv_val, prefix->bv_len );
151 lutil_MD5Update( &MD5context,
152 syntax->ssyn_oid, slen );
153 lutil_MD5Update( &MD5context,
155 lutil_MD5Update( &MD5context,
156 values[i]->bv_val, values[i]->bv_len );
157 lutil_MD5Final( MD5digest, &MD5context );
159 keys[i] = ber_bvdup( &digest );
169 /* Index generation function */
170 int octetStringFilter(
175 struct berval *prefix,
177 struct berval ***keysp )
180 struct berval **keys;
181 lutil_MD5_CTX MD5context;
182 unsigned char MD5digest[LUTIL_MD5_BYTES];
183 struct berval *value = (struct berval *) assertValue;
184 struct berval digest;
185 digest.bv_val = MD5digest;
186 digest.bv_len = sizeof(MD5digest);
188 slen = strlen( syntax->ssyn_oid );
189 mlen = strlen( mr->smr_oid );
191 keys = ch_malloc( sizeof( struct berval * ) * 2 );
193 lutil_MD5Init( &MD5context );
194 if( prefix != NULL && prefix->bv_len > 0 ) {
195 lutil_MD5Update( &MD5context,
196 prefix->bv_val, prefix->bv_len );
198 lutil_MD5Update( &MD5context,
199 syntax->ssyn_oid, slen );
200 lutil_MD5Update( &MD5context,
202 lutil_MD5Update( &MD5context,
203 value->bv_val, value->bv_len );
204 lutil_MD5Final( MD5digest, &MD5context );
206 keys[0] = ber_bvdup( &digest );
222 if( in->bv_len == 0 ) return LDAP_SUCCESS;
224 dn = ch_strdup( in->bv_val );
226 rc = dn_validate( dn ) == NULL
227 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
237 struct berval **normalized )
239 struct berval *out = ber_bvdup( val );
241 if( out->bv_len != 0 ) {
243 #ifdef USE_DN_NORMALIZE
244 dn = dn_normalize( out->bv_val );
246 dn = dn_validate( out->bv_val );
251 return LDAP_INVALID_SYNTAX;
255 out->bv_len = strlen( dn );
268 struct berval *value,
269 void *assertedValue )
272 struct berval *asserted = (struct berval *) assertedValue;
274 match = value->bv_len - asserted->bv_len;
277 #ifdef USE_DN_NORMALIZE
278 match = strcmp( value->bv_val, asserted->bv_val );
280 match = strcasecmp( value->bv_val, asserted->bv_val );
284 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
285 match, value->bv_val, asserted->bv_val );
296 /* any value allowed */
305 /* any value allowed */
310 * Handling boolean syntax and matching is quite rigid.
311 * A more flexible approach would be to allow a variety
312 * of strings to be normalized and prettied into TRUE
320 /* very unforgiving validation, requires no normalization
321 * before simplistic matching
324 if( in->bv_len == 4 ) {
325 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
328 } else if( in->bv_len == 5 ) {
329 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
334 return LDAP_INVALID_SYNTAX;
343 struct berval *value,
344 void *assertedValue )
346 /* simplistic matching allowed by rigid validation */
347 struct berval *asserted = (struct berval *) assertedValue;
348 *matchp = value->bv_len != asserted->bv_len;
355 struct berval *right,
356 struct berval *left )
360 ldap_unicode_t ru, lu;
361 ldap_unicode_t ruu, luu;
364 r < right->bv_len && l < left->bv_len;
368 * XXYYZ: we convert to ucs4 even though -llunicode
369 * expects ucs2 in an unsigned long
371 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
372 if( ru == LDAP_UCS4_INVALID ) {
376 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
377 if( lu == LDAP_UCS4_INVALID ) {
381 ruu = uctoupper( ru );
382 luu = uctoupper( lu );
386 } else if( luu > ruu ) {
390 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
391 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
394 if( r < right->bv_len ) {
399 if( l < left->bv_len ) {
415 unsigned char *u = in->bv_val;
417 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
419 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
420 /* get the length indicated by the first byte */
421 len = LDAP_UTF8_CHARLEN( u );
423 /* should not be zero */
424 if( len == 0 ) return LDAP_INVALID_SYNTAX;
426 /* make sure len corresponds with the offset
427 to the next character */
428 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
431 if( count != 0 ) return LDAP_INVALID_SYNTAX;
440 struct berval **normalized )
442 struct berval *newval;
445 newval = ch_malloc( sizeof( struct berval ) );
449 /* Ignore initial whitespace */
450 while ( ldap_utf8_isspace( p ) ) {
456 return LDAP_INVALID_SYNTAX;
459 newval->bv_val = ch_strdup( p );
460 p = q = newval->bv_val;
466 if ( ldap_utf8_isspace( p ) ) {
467 len = LDAP_UTF8_COPY(q,p);
472 /* Ignore the extra whitespace */
473 while ( ldap_utf8_isspace( p ) ) {
477 len = LDAP_UTF8_COPY(q,p);
484 assert( *newval->bv_val );
485 assert( newval->bv_val < p );
488 /* cannot start with a space */
489 assert( !ldap_utf8_isspace(newval->bv_val) );
492 * If the string ended in space, backup the pointer one
493 * position. One is enough because the above loop collapsed
494 * all whitespace to a single space.
501 /* cannot end with a space */
502 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
507 newval->bv_len = q - newval->bv_val;
508 *normalized = newval;
519 struct berval *value,
520 void *assertedValue )
522 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
525 match = strncmp( value->bv_val,
526 ((struct berval *) assertedValue)->bv_val,
535 caseExactSubstringsMatch(
540 struct berval *value,
541 void *assertedValue )
544 SubstringsAssertion *sub = assertedValue;
545 struct berval left = *value;
549 /* Add up asserted input length */
550 if( sub->sa_initial ) {
551 inlen += sub->sa_initial->bv_len;
554 for(i=0; sub->sa_any[i] != NULL; i++) {
555 inlen += sub->sa_any[i]->bv_len;
558 if( sub->sa_final ) {
559 inlen += sub->sa_final->bv_len;
562 if( sub->sa_initial ) {
563 if( inlen > left.bv_len ) {
568 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
569 sub->sa_initial->bv_len );
575 left.bv_val += sub->sa_initial->bv_len;
576 left.bv_len -= sub->sa_initial->bv_len;
577 inlen -= sub->sa_initial->bv_len;
580 if( sub->sa_final ) {
581 if( inlen > left.bv_len ) {
586 match = strncmp( sub->sa_final->bv_val,
587 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
588 sub->sa_final->bv_len );
594 left.bv_len -= sub->sa_final->bv_len;
595 inlen -= sub->sa_final->bv_len;
599 for(i=0; sub->sa_any[i]; i++) {
604 if( inlen > left.bv_len ) {
605 /* not enough length */
610 if( sub->sa_any[i]->bv_len == 0 ) {
614 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
621 idx = p - left.bv_val;
622 assert( idx < left.bv_len );
624 if( idx >= left.bv_len ) {
625 /* this shouldn't happen */
632 if( sub->sa_any[i]->bv_len > left.bv_len ) {
633 /* not enough left */
638 match = strncmp( left.bv_val,
639 sub->sa_any[i]->bv_val,
640 sub->sa_any[i]->bv_len );
648 left.bv_val += sub->sa_any[i]->bv_len;
649 left.bv_len -= sub->sa_any[i]->bv_len;
650 inlen -= sub->sa_any[i]->bv_len;
659 /* Index generation function */
660 int caseExactIndexer(
665 struct berval *prefix,
666 struct berval **values,
667 struct berval ***keysp )
671 struct berval **keys;
672 lutil_MD5_CTX MD5context;
673 unsigned char MD5digest[16];
674 struct berval digest;
675 digest.bv_val = MD5digest;
676 digest.bv_len = sizeof(MD5digest);
678 for( i=0; values[i] != NULL; i++ ) {
679 /* just count them */
684 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
686 slen = strlen( syntax->ssyn_oid );
687 mlen = strlen( mr->smr_oid );
689 for( i=0; values[i] != NULL; i++ ) {
690 struct berval *value = values[i];
692 lutil_MD5Init( &MD5context );
693 if( prefix != NULL && prefix->bv_len > 0 ) {
694 lutil_MD5Update( &MD5context,
695 prefix->bv_val, prefix->bv_len );
697 lutil_MD5Update( &MD5context,
698 syntax->ssyn_oid, slen );
699 lutil_MD5Update( &MD5context,
701 lutil_MD5Update( &MD5context,
702 value->bv_val, value->bv_len );
703 lutil_MD5Final( MD5digest, &MD5context );
705 keys[i] = ber_bvdup( &digest );
713 /* Index generation function */
719 struct berval *prefix,
721 struct berval ***keysp )
724 struct berval **keys;
725 lutil_MD5_CTX MD5context;
726 unsigned char MD5digest[LUTIL_MD5_BYTES];
727 struct berval *value;
728 struct berval digest;
729 digest.bv_val = MD5digest;
730 digest.bv_len = sizeof(MD5digest);
732 slen = strlen( syntax->ssyn_oid );
733 mlen = strlen( mr->smr_oid );
735 value = (struct berval *) assertValue;
737 keys = ch_malloc( sizeof( struct berval * ) * 2 );
739 lutil_MD5Init( &MD5context );
740 if( prefix != NULL && prefix->bv_len > 0 ) {
741 lutil_MD5Update( &MD5context,
742 prefix->bv_val, prefix->bv_len );
744 lutil_MD5Update( &MD5context,
745 syntax->ssyn_oid, slen );
746 lutil_MD5Update( &MD5context,
748 lutil_MD5Update( &MD5context,
749 value->bv_val, value->bv_len );
750 lutil_MD5Final( MD5digest, &MD5context );
752 keys[0] = ber_bvdup( &digest );
759 /* Substrings Index generation function */
760 int caseExactSubstringsIndexer(
765 struct berval *prefix,
766 struct berval **values,
767 struct berval ***keysp )
771 struct berval **keys;
772 lutil_MD5_CTX MD5context;
773 unsigned char MD5digest[16];
774 struct berval digest;
775 digest.bv_val = MD5digest;
776 digest.bv_len = sizeof(MD5digest);
779 for( i=0; values[i] != NULL; i++ ) {
780 /* count number of indices to generate */
781 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
785 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
786 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
787 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
788 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
790 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
794 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
795 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
796 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
800 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
801 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
802 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
803 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
805 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
812 /* no keys to generate */
817 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
819 slen = strlen( syntax->ssyn_oid );
820 mlen = strlen( mr->smr_oid );
823 for( i=0; values[i] != NULL; i++ ) {
825 struct berval *value;
828 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
830 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
831 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
833 char pre = SLAP_INDEX_SUBSTR_PREFIX;
834 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
836 for( j=0; j<max; j++ ) {
837 lutil_MD5Init( &MD5context );
838 if( prefix != NULL && prefix->bv_len > 0 ) {
839 lutil_MD5Update( &MD5context,
840 prefix->bv_val, prefix->bv_len );
843 lutil_MD5Update( &MD5context,
844 &pre, sizeof( pre ) );
845 lutil_MD5Update( &MD5context,
846 syntax->ssyn_oid, slen );
847 lutil_MD5Update( &MD5context,
849 lutil_MD5Update( &MD5context,
851 SLAP_INDEX_SUBSTR_MAXLEN );
852 lutil_MD5Final( MD5digest, &MD5context );
854 keys[nkeys++] = ber_bvdup( &digest );
858 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
859 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
861 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
864 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
865 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
866 lutil_MD5Init( &MD5context );
867 if( prefix != NULL && prefix->bv_len > 0 ) {
868 lutil_MD5Update( &MD5context,
869 prefix->bv_val, prefix->bv_len );
871 lutil_MD5Update( &MD5context,
872 &pre, sizeof( pre ) );
873 lutil_MD5Update( &MD5context,
874 syntax->ssyn_oid, slen );
875 lutil_MD5Update( &MD5context,
877 lutil_MD5Update( &MD5context,
879 lutil_MD5Final( MD5digest, &MD5context );
881 keys[nkeys++] = ber_bvdup( &digest );
884 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
885 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
886 lutil_MD5Init( &MD5context );
887 if( prefix != NULL && prefix->bv_len > 0 ) {
888 lutil_MD5Update( &MD5context,
889 prefix->bv_val, prefix->bv_len );
891 lutil_MD5Update( &MD5context,
892 &pre, sizeof( pre ) );
893 lutil_MD5Update( &MD5context,
894 syntax->ssyn_oid, slen );
895 lutil_MD5Update( &MD5context,
897 lutil_MD5Update( &MD5context,
898 &value->bv_val[value->bv_len-j], j );
899 lutil_MD5Final( MD5digest, &MD5context );
901 keys[nkeys++] = ber_bvdup( &digest );
918 int caseExactSubstringsFilter(
923 struct berval *prefix,
925 struct berval ***keysp )
927 SubstringsAssertion *sa = assertValue;
930 size_t slen, mlen, klen;
931 struct berval **keys;
932 lutil_MD5_CTX MD5context;
933 unsigned char MD5digest[LUTIL_MD5_BYTES];
934 struct berval *value;
935 struct berval digest;
937 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
938 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
943 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
945 for( i=0; sa->sa_any[i] != NULL; i++ ) {
946 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
947 /* don't bother accounting for stepping */
948 nkeys += sa->sa_any[i]->bv_len -
949 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
954 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
955 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
965 digest.bv_val = MD5digest;
966 digest.bv_len = sizeof(MD5digest);
968 slen = strlen( syntax->ssyn_oid );
969 mlen = strlen( mr->smr_oid );
971 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
974 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
975 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
977 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
978 value = sa->sa_initial;
980 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
981 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
983 lutil_MD5Init( &MD5context );
984 if( prefix != NULL && prefix->bv_len > 0 ) {
985 lutil_MD5Update( &MD5context,
986 prefix->bv_val, prefix->bv_len );
988 lutil_MD5Update( &MD5context,
989 &pre, sizeof( pre ) );
990 lutil_MD5Update( &MD5context,
991 syntax->ssyn_oid, slen );
992 lutil_MD5Update( &MD5context,
994 lutil_MD5Update( &MD5context,
995 value->bv_val, klen );
996 lutil_MD5Final( MD5digest, &MD5context );
998 keys[nkeys++] = ber_bvdup( &digest );
1001 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1003 pre = SLAP_INDEX_SUBSTR_PREFIX;
1004 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1006 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1007 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1011 value = sa->sa_any[i];
1014 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1015 j += SLAP_INDEX_SUBSTR_STEP )
1017 lutil_MD5Init( &MD5context );
1018 if( prefix != NULL && prefix->bv_len > 0 ) {
1019 lutil_MD5Update( &MD5context,
1020 prefix->bv_val, prefix->bv_len );
1022 lutil_MD5Update( &MD5context,
1023 &pre, sizeof( pre ) );
1024 lutil_MD5Update( &MD5context,
1025 syntax->ssyn_oid, slen );
1026 lutil_MD5Update( &MD5context,
1027 mr->smr_oid, mlen );
1028 lutil_MD5Update( &MD5context,
1029 &value->bv_val[j], klen );
1030 lutil_MD5Final( MD5digest, &MD5context );
1032 keys[nkeys++] = ber_bvdup( &digest );
1037 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1038 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1040 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1041 value = sa->sa_final;
1043 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1044 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1046 lutil_MD5Init( &MD5context );
1047 if( prefix != NULL && prefix->bv_len > 0 ) {
1048 lutil_MD5Update( &MD5context,
1049 prefix->bv_val, prefix->bv_len );
1051 lutil_MD5Update( &MD5context,
1052 &pre, sizeof( pre ) );
1053 lutil_MD5Update( &MD5context,
1054 syntax->ssyn_oid, slen );
1055 lutil_MD5Update( &MD5context,
1056 mr->smr_oid, mlen );
1057 lutil_MD5Update( &MD5context,
1058 &value->bv_val[value->bv_len-klen], klen );
1059 lutil_MD5Final( MD5digest, &MD5context );
1061 keys[nkeys++] = ber_bvdup( &digest );
1072 return LDAP_SUCCESS;
1081 struct berval *value,
1082 void *assertedValue )
1085 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1087 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1090 match = strncasecmp( value->bv_val,
1091 ((struct berval *) assertedValue)->bv_val,
1097 return LDAP_SUCCESS;
1101 caseIgnoreSubstringsMatch(
1106 struct berval *value,
1107 void *assertedValue )
1110 SubstringsAssertion *sub = assertedValue;
1111 struct berval left = *value;
1115 /* Add up asserted input length */
1116 if( sub->sa_initial ) {
1117 inlen += sub->sa_initial->bv_len;
1120 for(i=0; sub->sa_any[i] != NULL; i++) {
1121 inlen += sub->sa_any[i]->bv_len;
1124 if( sub->sa_final ) {
1125 inlen += sub->sa_final->bv_len;
1128 if( sub->sa_initial ) {
1129 if( inlen > left.bv_len ) {
1134 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1135 sub->sa_initial->bv_len );
1141 left.bv_val += sub->sa_initial->bv_len;
1142 left.bv_len -= sub->sa_initial->bv_len;
1143 inlen -= sub->sa_initial->bv_len;
1146 if( sub->sa_final ) {
1147 if( inlen > left.bv_len ) {
1152 match = strncasecmp( sub->sa_final->bv_val,
1153 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1154 sub->sa_final->bv_len );
1160 left.bv_len -= sub->sa_final->bv_len;
1161 inlen -= sub->sa_final->bv_len;
1165 for(i=0; sub->sa_any[i]; i++) {
1170 if( inlen > left.bv_len ) {
1171 /* not enough length */
1176 if( sub->sa_any[i]->bv_len == 0 ) {
1180 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1187 idx = p - left.bv_val;
1188 assert( idx < left.bv_len );
1190 if( idx >= left.bv_len ) {
1191 /* this shouldn't happen */
1198 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1199 /* not enough left */
1204 match = strncasecmp( left.bv_val,
1205 sub->sa_any[i]->bv_val,
1206 sub->sa_any[i]->bv_len );
1215 left.bv_val += sub->sa_any[i]->bv_len;
1216 left.bv_len -= sub->sa_any[i]->bv_len;
1217 inlen -= sub->sa_any[i]->bv_len;
1223 return LDAP_SUCCESS;
1226 /* Index generation function */
1227 int caseIgnoreIndexer(
1232 struct berval *prefix,
1233 struct berval **values,
1234 struct berval ***keysp )
1238 struct berval **keys;
1239 lutil_MD5_CTX MD5context;
1240 unsigned char MD5digest[16];
1241 struct berval digest;
1242 digest.bv_val = MD5digest;
1243 digest.bv_len = sizeof(MD5digest);
1245 for( i=0; values[i] != NULL; i++ ) {
1246 /* just count them */
1251 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1253 slen = strlen( syntax->ssyn_oid );
1254 mlen = strlen( mr->smr_oid );
1256 for( i=0; values[i] != NULL; i++ ) {
1257 struct berval *value = ber_bvdup( values[i] );
1258 ldap_pvt_str2upper( value->bv_val );
1260 lutil_MD5Init( &MD5context );
1261 if( prefix != NULL && prefix->bv_len > 0 ) {
1262 lutil_MD5Update( &MD5context,
1263 prefix->bv_val, prefix->bv_len );
1265 lutil_MD5Update( &MD5context,
1266 syntax->ssyn_oid, slen );
1267 lutil_MD5Update( &MD5context,
1268 mr->smr_oid, mlen );
1269 lutil_MD5Update( &MD5context,
1270 value->bv_val, value->bv_len );
1271 lutil_MD5Final( MD5digest, &MD5context );
1273 ber_bvfree( value );
1275 keys[i] = ber_bvdup( &digest );
1280 return LDAP_SUCCESS;
1283 /* Index generation function */
1284 int caseIgnoreFilter(
1289 struct berval *prefix,
1291 struct berval ***keysp )
1294 struct berval **keys;
1295 lutil_MD5_CTX MD5context;
1296 unsigned char MD5digest[LUTIL_MD5_BYTES];
1297 struct berval *value;
1298 struct berval digest;
1299 digest.bv_val = MD5digest;
1300 digest.bv_len = sizeof(MD5digest);
1302 slen = strlen( syntax->ssyn_oid );
1303 mlen = strlen( mr->smr_oid );
1305 value = ber_bvdup( (struct berval *) assertValue );
1306 ldap_pvt_str2upper( value->bv_val );
1308 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1310 lutil_MD5Init( &MD5context );
1311 if( prefix != NULL && prefix->bv_len > 0 ) {
1312 lutil_MD5Update( &MD5context,
1313 prefix->bv_val, prefix->bv_len );
1315 lutil_MD5Update( &MD5context,
1316 syntax->ssyn_oid, slen );
1317 lutil_MD5Update( &MD5context,
1318 mr->smr_oid, mlen );
1319 lutil_MD5Update( &MD5context,
1320 value->bv_val, value->bv_len );
1321 lutil_MD5Final( MD5digest, &MD5context );
1323 keys[0] = ber_bvdup( &digest );
1326 ber_bvfree( value );
1330 return LDAP_SUCCESS;
1333 /* Substrings Index generation function */
1334 int caseIgnoreSubstringsIndexer(
1339 struct berval *prefix,
1340 struct berval **values,
1341 struct berval ***keysp )
1345 struct berval **keys;
1346 lutil_MD5_CTX MD5context;
1347 unsigned char MD5digest[16];
1348 struct berval digest;
1349 digest.bv_val = MD5digest;
1350 digest.bv_len = sizeof(MD5digest);
1353 for( i=0; values[i] != NULL; i++ ) {
1354 /* count number of indices to generate */
1355 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1359 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1360 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1361 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1362 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1364 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1368 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1369 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1370 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1374 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1375 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1376 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1377 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1379 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1386 /* no keys to generate */
1388 return LDAP_SUCCESS;
1391 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1393 slen = strlen( syntax->ssyn_oid );
1394 mlen = strlen( mr->smr_oid );
1397 for( i=0; values[i] != NULL; i++ ) {
1399 struct berval *value;
1401 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1403 value = ber_bvdup( values[i] );
1404 ldap_pvt_str2upper( value->bv_val );
1406 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1407 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1409 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1410 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1412 for( j=0; j<max; j++ ) {
1413 lutil_MD5Init( &MD5context );
1414 if( prefix != NULL && prefix->bv_len > 0 ) {
1415 lutil_MD5Update( &MD5context,
1416 prefix->bv_val, prefix->bv_len );
1419 lutil_MD5Update( &MD5context,
1420 &pre, sizeof( pre ) );
1421 lutil_MD5Update( &MD5context,
1422 syntax->ssyn_oid, slen );
1423 lutil_MD5Update( &MD5context,
1424 mr->smr_oid, mlen );
1425 lutil_MD5Update( &MD5context,
1427 SLAP_INDEX_SUBSTR_MAXLEN );
1428 lutil_MD5Final( MD5digest, &MD5context );
1430 keys[nkeys++] = ber_bvdup( &digest );
1434 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1435 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1437 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1440 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1441 pre = SLAP_INDEX_SUBSTR_INITIAL_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,
1455 lutil_MD5Final( MD5digest, &MD5context );
1457 keys[nkeys++] = ber_bvdup( &digest );
1460 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1461 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1462 lutil_MD5Init( &MD5context );
1463 if( prefix != NULL && prefix->bv_len > 0 ) {
1464 lutil_MD5Update( &MD5context,
1465 prefix->bv_val, prefix->bv_len );
1467 lutil_MD5Update( &MD5context,
1468 &pre, sizeof( pre ) );
1469 lutil_MD5Update( &MD5context,
1470 syntax->ssyn_oid, slen );
1471 lutil_MD5Update( &MD5context,
1472 mr->smr_oid, mlen );
1473 lutil_MD5Update( &MD5context,
1474 &value->bv_val[value->bv_len-j], j );
1475 lutil_MD5Final( MD5digest, &MD5context );
1477 keys[nkeys++] = ber_bvdup( &digest );
1482 ber_bvfree( value );
1493 return LDAP_SUCCESS;
1496 int caseIgnoreSubstringsFilter(
1501 struct berval *prefix,
1503 struct berval ***keysp )
1505 SubstringsAssertion *sa = assertValue;
1507 ber_len_t nkeys = 0;
1508 size_t slen, mlen, klen;
1509 struct berval **keys;
1510 lutil_MD5_CTX MD5context;
1511 unsigned char MD5digest[LUTIL_MD5_BYTES];
1512 struct berval *value;
1513 struct berval digest;
1515 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1516 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1521 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1523 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1524 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1525 /* don't bother accounting for stepping */
1526 nkeys += sa->sa_any[i]->bv_len -
1527 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1532 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1533 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1540 return LDAP_SUCCESS;
1543 digest.bv_val = MD5digest;
1544 digest.bv_len = sizeof(MD5digest);
1546 slen = strlen( syntax->ssyn_oid );
1547 mlen = strlen( mr->smr_oid );
1549 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1552 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1553 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1555 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1556 value = ber_bvdup( sa->sa_initial );
1557 ldap_pvt_str2upper( value->bv_val );
1559 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1560 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1562 lutil_MD5Init( &MD5context );
1563 if( prefix != NULL && prefix->bv_len > 0 ) {
1564 lutil_MD5Update( &MD5context,
1565 prefix->bv_val, prefix->bv_len );
1567 lutil_MD5Update( &MD5context,
1568 &pre, sizeof( pre ) );
1569 lutil_MD5Update( &MD5context,
1570 syntax->ssyn_oid, slen );
1571 lutil_MD5Update( &MD5context,
1572 mr->smr_oid, mlen );
1573 lutil_MD5Update( &MD5context,
1574 value->bv_val, klen );
1575 lutil_MD5Final( MD5digest, &MD5context );
1577 ber_bvfree( value );
1578 keys[nkeys++] = ber_bvdup( &digest );
1581 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1583 pre = SLAP_INDEX_SUBSTR_PREFIX;
1584 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1586 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1587 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1591 value = ber_bvdup( sa->sa_any[i] );
1592 ldap_pvt_str2upper( value->bv_val );
1595 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1596 j += SLAP_INDEX_SUBSTR_STEP )
1598 lutil_MD5Init( &MD5context );
1599 if( prefix != NULL && prefix->bv_len > 0 ) {
1600 lutil_MD5Update( &MD5context,
1601 prefix->bv_val, prefix->bv_len );
1603 lutil_MD5Update( &MD5context,
1604 &pre, sizeof( pre ) );
1605 lutil_MD5Update( &MD5context,
1606 syntax->ssyn_oid, slen );
1607 lutil_MD5Update( &MD5context,
1608 mr->smr_oid, mlen );
1609 lutil_MD5Update( &MD5context,
1610 &value->bv_val[j], klen );
1611 lutil_MD5Final( MD5digest, &MD5context );
1613 keys[nkeys++] = ber_bvdup( &digest );
1616 ber_bvfree( value );
1620 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1621 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1623 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1624 value = ber_bvdup( sa->sa_final );
1625 ldap_pvt_str2upper( value->bv_val );
1627 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1628 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1630 lutil_MD5Init( &MD5context );
1631 if( prefix != NULL && prefix->bv_len > 0 ) {
1632 lutil_MD5Update( &MD5context,
1633 prefix->bv_val, prefix->bv_len );
1635 lutil_MD5Update( &MD5context,
1636 &pre, sizeof( pre ) );
1637 lutil_MD5Update( &MD5context,
1638 syntax->ssyn_oid, slen );
1639 lutil_MD5Update( &MD5context,
1640 mr->smr_oid, mlen );
1641 lutil_MD5Update( &MD5context,
1642 &value->bv_val[value->bv_len-klen], klen );
1643 lutil_MD5Final( MD5digest, &MD5context );
1645 ber_bvfree( value );
1646 keys[nkeys++] = ber_bvdup( &digest );
1657 return LDAP_SUCCESS;
1663 struct berval *val )
1667 if( val->bv_len == 0 ) return 0;
1669 if( OID_LEADCHAR(val->bv_val[0]) ) {
1671 for(i=1; i < val->bv_len; i++) {
1672 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1673 if( dot++ ) return 1;
1674 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1677 return LDAP_INVALID_SYNTAX;
1681 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1683 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1684 for(i=1; i < val->bv_len; i++) {
1685 if( !DESC_CHAR(val->bv_val[i] ) ) {
1686 return LDAP_INVALID_SYNTAX;
1690 return LDAP_SUCCESS;
1693 return LDAP_INVALID_SYNTAX;
1699 struct berval *val )
1703 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1705 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
1706 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1707 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1708 return LDAP_INVALID_SYNTAX;
1711 for(i=1; i < val->bv_len; i++) {
1712 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1715 return LDAP_SUCCESS;
1722 struct berval **normalized )
1725 struct berval *newval;
1731 negative = ( *p == '-' );
1732 if( *p == '-' || *p == '+' ) p++;
1734 /* Ignore leading zeros */
1735 while ( *p == '0' ) p++;
1737 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
1740 newval->bv_val = ch_strdup("0");
1745 newval->bv_val = ch_malloc( val->bv_len + 1 );
1749 newval->bv_val[newval->bv_len++] = '-';
1752 for( ; *p != '\0'; p++ ) {
1753 newval->bv_val[newval->bv_len++] = *p;
1757 *normalized = newval;
1758 return LDAP_SUCCESS;
1762 printableStringValidate(
1764 struct berval *val )
1768 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1770 for(i=0; i < val->bv_len; i++) {
1771 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1774 return LDAP_SUCCESS;
1780 struct berval *val )
1784 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1786 for(i=0; i < val->bv_len; i++) {
1787 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1790 return LDAP_SUCCESS;
1797 struct berval **out )
1800 ber_len_t i, len = in->bv_len;
1801 struct berval *bv = ch_malloc( sizeof(struct berval) );
1803 bv->bv_len = len * sizeof( ldap_unicode_t );
1804 u = (ldap_unicode_t *) ch_malloc( bv->bv_len + sizeof(ldap_unicode_t) );
1805 bv->bv_val = (char *) u;
1807 for(i=0; i < len; i++ ) {
1809 * IA5StringValidate should have been called to ensure
1810 * input is limited to IA5.
1812 u[i] = in->bv_val[i];
1817 return LDAP_SUCCESS;
1824 struct berval **normalized )
1826 struct berval *newval;
1829 newval = ch_malloc( sizeof( struct berval ) );
1833 /* Ignore initial whitespace */
1834 while ( ASCII_SPACE( *p ) ) {
1840 return LDAP_INVALID_SYNTAX;
1843 newval->bv_val = ch_strdup( p );
1844 p = q = newval->bv_val;
1847 if ( ASCII_SPACE( *p ) ) {
1850 /* Ignore the extra whitespace */
1851 while ( ASCII_SPACE( *p ) ) {
1859 assert( *newval->bv_val );
1860 assert( newval->bv_val < p );
1863 /* cannot start with a space */
1864 assert( !ASCII_SPACE(*newval->bv_val) );
1867 * If the string ended in space, backup the pointer one
1868 * position. One is enough because the above loop collapsed
1869 * all whitespace to a single space.
1872 if ( ASCII_SPACE( q[-1] ) ) {
1876 /* cannot end with a space */
1877 assert( !ASCII_SPACE( q[-1] ) );
1879 /* null terminate */
1882 newval->bv_len = q - newval->bv_val;
1883 *normalized = newval;
1885 return LDAP_SUCCESS;
1894 struct berval *value,
1895 void *assertedValue )
1897 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1900 match = strncmp( value->bv_val,
1901 ((struct berval *) assertedValue)->bv_val,
1906 return LDAP_SUCCESS;
1910 caseExactIA5SubstringsMatch(
1915 struct berval *value,
1916 void *assertedValue )
1919 SubstringsAssertion *sub = assertedValue;
1920 struct berval left = *value;
1924 /* Add up asserted input length */
1925 if( sub->sa_initial ) {
1926 inlen += sub->sa_initial->bv_len;
1929 for(i=0; sub->sa_any[i] != NULL; i++) {
1930 inlen += sub->sa_any[i]->bv_len;
1933 if( sub->sa_final ) {
1934 inlen += sub->sa_final->bv_len;
1937 if( sub->sa_initial ) {
1938 if( inlen > left.bv_len ) {
1943 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1944 sub->sa_initial->bv_len );
1950 left.bv_val += sub->sa_initial->bv_len;
1951 left.bv_len -= sub->sa_initial->bv_len;
1952 inlen -= sub->sa_initial->bv_len;
1955 if( sub->sa_final ) {
1956 if( inlen > left.bv_len ) {
1961 match = strncmp( sub->sa_final->bv_val,
1962 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1963 sub->sa_final->bv_len );
1969 left.bv_len -= sub->sa_final->bv_len;
1970 inlen -= sub->sa_final->bv_len;
1974 for(i=0; sub->sa_any[i]; i++) {
1979 if( inlen > left.bv_len ) {
1980 /* not enough length */
1985 if( sub->sa_any[i]->bv_len == 0 ) {
1989 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1996 idx = p - left.bv_val;
1997 assert( idx < left.bv_len );
1999 if( idx >= left.bv_len ) {
2000 /* this shouldn't happen */
2007 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2008 /* not enough left */
2013 match = strncmp( left.bv_val,
2014 sub->sa_any[i]->bv_val,
2015 sub->sa_any[i]->bv_len );
2023 left.bv_val += sub->sa_any[i]->bv_len;
2024 left.bv_len -= sub->sa_any[i]->bv_len;
2025 inlen -= sub->sa_any[i]->bv_len;
2031 return LDAP_SUCCESS;
2034 /* Index generation function */
2035 int caseExactIA5Indexer(
2040 struct berval *prefix,
2041 struct berval **values,
2042 struct berval ***keysp )
2046 struct berval **keys;
2047 lutil_MD5_CTX MD5context;
2048 unsigned char MD5digest[16];
2049 struct berval digest;
2050 digest.bv_val = MD5digest;
2051 digest.bv_len = sizeof(MD5digest);
2053 for( i=0; values[i] != NULL; i++ ) {
2054 /* just count them */
2059 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2061 slen = strlen( syntax->ssyn_oid );
2062 mlen = strlen( mr->smr_oid );
2064 for( i=0; values[i] != NULL; i++ ) {
2065 struct berval *value = values[i];
2067 lutil_MD5Init( &MD5context );
2068 if( prefix != NULL && prefix->bv_len > 0 ) {
2069 lutil_MD5Update( &MD5context,
2070 prefix->bv_val, prefix->bv_len );
2072 lutil_MD5Update( &MD5context,
2073 syntax->ssyn_oid, slen );
2074 lutil_MD5Update( &MD5context,
2075 mr->smr_oid, mlen );
2076 lutil_MD5Update( &MD5context,
2077 value->bv_val, value->bv_len );
2078 lutil_MD5Final( MD5digest, &MD5context );
2080 keys[i] = ber_bvdup( &digest );
2085 return LDAP_SUCCESS;
2088 /* Index generation function */
2089 int caseExactIA5Filter(
2094 struct berval *prefix,
2096 struct berval ***keysp )
2099 struct berval **keys;
2100 lutil_MD5_CTX MD5context;
2101 unsigned char MD5digest[LUTIL_MD5_BYTES];
2102 struct berval *value;
2103 struct berval digest;
2104 digest.bv_val = MD5digest;
2105 digest.bv_len = sizeof(MD5digest);
2107 slen = strlen( syntax->ssyn_oid );
2108 mlen = strlen( mr->smr_oid );
2110 value = (struct berval *) assertValue;
2112 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2114 lutil_MD5Init( &MD5context );
2115 if( prefix != NULL && prefix->bv_len > 0 ) {
2116 lutil_MD5Update( &MD5context,
2117 prefix->bv_val, prefix->bv_len );
2119 lutil_MD5Update( &MD5context,
2120 syntax->ssyn_oid, slen );
2121 lutil_MD5Update( &MD5context,
2122 mr->smr_oid, mlen );
2123 lutil_MD5Update( &MD5context,
2124 value->bv_val, value->bv_len );
2125 lutil_MD5Final( MD5digest, &MD5context );
2127 keys[0] = ber_bvdup( &digest );
2131 return LDAP_SUCCESS;
2134 /* Substrings Index generation function */
2135 int caseExactIA5SubstringsIndexer(
2140 struct berval *prefix,
2141 struct berval **values,
2142 struct berval ***keysp )
2146 struct berval **keys;
2147 lutil_MD5_CTX MD5context;
2148 unsigned char MD5digest[16];
2149 struct berval digest;
2150 digest.bv_val = MD5digest;
2151 digest.bv_len = sizeof(MD5digest);
2154 for( i=0; values[i] != NULL; i++ ) {
2155 /* count number of indices to generate */
2156 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2160 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2161 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2162 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2163 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2165 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2169 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2170 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2171 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2175 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2176 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2177 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2178 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2180 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2187 /* no keys to generate */
2189 return LDAP_SUCCESS;
2192 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2194 slen = strlen( syntax->ssyn_oid );
2195 mlen = strlen( mr->smr_oid );
2198 for( i=0; values[i] != NULL; i++ ) {
2200 struct berval *value;
2203 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2205 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2206 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2208 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2209 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2211 for( j=0; j<max; j++ ) {
2212 lutil_MD5Init( &MD5context );
2213 if( prefix != NULL && prefix->bv_len > 0 ) {
2214 lutil_MD5Update( &MD5context,
2215 prefix->bv_val, prefix->bv_len );
2218 lutil_MD5Update( &MD5context,
2219 &pre, sizeof( pre ) );
2220 lutil_MD5Update( &MD5context,
2221 syntax->ssyn_oid, slen );
2222 lutil_MD5Update( &MD5context,
2223 mr->smr_oid, mlen );
2224 lutil_MD5Update( &MD5context,
2226 SLAP_INDEX_SUBSTR_MAXLEN );
2227 lutil_MD5Final( MD5digest, &MD5context );
2229 keys[nkeys++] = ber_bvdup( &digest );
2233 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2234 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2236 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2239 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2240 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2241 lutil_MD5Init( &MD5context );
2242 if( prefix != NULL && prefix->bv_len > 0 ) {
2243 lutil_MD5Update( &MD5context,
2244 prefix->bv_val, prefix->bv_len );
2246 lutil_MD5Update( &MD5context,
2247 &pre, sizeof( pre ) );
2248 lutil_MD5Update( &MD5context,
2249 syntax->ssyn_oid, slen );
2250 lutil_MD5Update( &MD5context,
2251 mr->smr_oid, mlen );
2252 lutil_MD5Update( &MD5context,
2254 lutil_MD5Final( MD5digest, &MD5context );
2256 keys[nkeys++] = ber_bvdup( &digest );
2259 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2260 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2261 lutil_MD5Init( &MD5context );
2262 if( prefix != NULL && prefix->bv_len > 0 ) {
2263 lutil_MD5Update( &MD5context,
2264 prefix->bv_val, prefix->bv_len );
2266 lutil_MD5Update( &MD5context,
2267 &pre, sizeof( pre ) );
2268 lutil_MD5Update( &MD5context,
2269 syntax->ssyn_oid, slen );
2270 lutil_MD5Update( &MD5context,
2271 mr->smr_oid, mlen );
2272 lutil_MD5Update( &MD5context,
2273 &value->bv_val[value->bv_len-j], j );
2274 lutil_MD5Final( MD5digest, &MD5context );
2276 keys[nkeys++] = ber_bvdup( &digest );
2290 return LDAP_SUCCESS;
2293 int caseExactIA5SubstringsFilter(
2298 struct berval *prefix,
2300 struct berval ***keysp )
2302 SubstringsAssertion *sa = assertValue;
2304 ber_len_t nkeys = 0;
2305 size_t slen, mlen, klen;
2306 struct berval **keys;
2307 lutil_MD5_CTX MD5context;
2308 unsigned char MD5digest[LUTIL_MD5_BYTES];
2309 struct berval *value;
2310 struct berval digest;
2312 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2313 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2318 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2320 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2321 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2322 /* don't bother accounting for stepping */
2323 nkeys += sa->sa_any[i]->bv_len -
2324 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2329 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2330 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2337 return LDAP_SUCCESS;
2340 digest.bv_val = MD5digest;
2341 digest.bv_len = sizeof(MD5digest);
2343 slen = strlen( syntax->ssyn_oid );
2344 mlen = strlen( mr->smr_oid );
2346 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2349 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2350 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2352 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2353 value = sa->sa_initial;
2355 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2356 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2358 lutil_MD5Init( &MD5context );
2359 if( prefix != NULL && prefix->bv_len > 0 ) {
2360 lutil_MD5Update( &MD5context,
2361 prefix->bv_val, prefix->bv_len );
2363 lutil_MD5Update( &MD5context,
2364 &pre, sizeof( pre ) );
2365 lutil_MD5Update( &MD5context,
2366 syntax->ssyn_oid, slen );
2367 lutil_MD5Update( &MD5context,
2368 mr->smr_oid, mlen );
2369 lutil_MD5Update( &MD5context,
2370 value->bv_val, klen );
2371 lutil_MD5Final( MD5digest, &MD5context );
2373 keys[nkeys++] = ber_bvdup( &digest );
2376 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2378 pre = SLAP_INDEX_SUBSTR_PREFIX;
2379 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2381 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2382 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2386 value = sa->sa_any[i];
2389 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2390 j += SLAP_INDEX_SUBSTR_STEP )
2392 lutil_MD5Init( &MD5context );
2393 if( prefix != NULL && prefix->bv_len > 0 ) {
2394 lutil_MD5Update( &MD5context,
2395 prefix->bv_val, prefix->bv_len );
2397 lutil_MD5Update( &MD5context,
2398 &pre, sizeof( pre ) );
2399 lutil_MD5Update( &MD5context,
2400 syntax->ssyn_oid, slen );
2401 lutil_MD5Update( &MD5context,
2402 mr->smr_oid, mlen );
2403 lutil_MD5Update( &MD5context,
2404 &value->bv_val[j], klen );
2405 lutil_MD5Final( MD5digest, &MD5context );
2407 keys[nkeys++] = ber_bvdup( &digest );
2412 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2413 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2415 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2416 value = sa->sa_final;
2418 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2419 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2421 lutil_MD5Init( &MD5context );
2422 if( prefix != NULL && prefix->bv_len > 0 ) {
2423 lutil_MD5Update( &MD5context,
2424 prefix->bv_val, prefix->bv_len );
2426 lutil_MD5Update( &MD5context,
2427 &pre, sizeof( pre ) );
2428 lutil_MD5Update( &MD5context,
2429 syntax->ssyn_oid, slen );
2430 lutil_MD5Update( &MD5context,
2431 mr->smr_oid, mlen );
2432 lutil_MD5Update( &MD5context,
2433 &value->bv_val[value->bv_len-klen], klen );
2434 lutil_MD5Final( MD5digest, &MD5context );
2436 keys[nkeys++] = ber_bvdup( &digest );
2447 return LDAP_SUCCESS;
2456 struct berval *value,
2457 void *assertedValue )
2459 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2462 match = strncasecmp( value->bv_val,
2463 ((struct berval *) assertedValue)->bv_val,
2468 return LDAP_SUCCESS;
2472 caseIgnoreIA5SubstringsMatch(
2477 struct berval *value,
2478 void *assertedValue )
2481 SubstringsAssertion *sub = assertedValue;
2482 struct berval left = *value;
2486 /* Add up asserted input length */
2487 if( sub->sa_initial ) {
2488 inlen += sub->sa_initial->bv_len;
2491 for(i=0; sub->sa_any[i] != NULL; i++) {
2492 inlen += sub->sa_any[i]->bv_len;
2495 if( sub->sa_final ) {
2496 inlen += sub->sa_final->bv_len;
2499 if( sub->sa_initial ) {
2500 if( inlen > left.bv_len ) {
2505 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2506 sub->sa_initial->bv_len );
2512 left.bv_val += sub->sa_initial->bv_len;
2513 left.bv_len -= sub->sa_initial->bv_len;
2514 inlen -= sub->sa_initial->bv_len;
2517 if( sub->sa_final ) {
2518 if( inlen > left.bv_len ) {
2523 match = strncasecmp( sub->sa_final->bv_val,
2524 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2525 sub->sa_final->bv_len );
2531 left.bv_len -= sub->sa_final->bv_len;
2532 inlen -= sub->sa_final->bv_len;
2536 for(i=0; sub->sa_any[i]; i++) {
2541 if( inlen > left.bv_len ) {
2542 /* not enough length */
2547 if( sub->sa_any[i]->bv_len == 0 ) {
2551 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2558 idx = p - left.bv_val;
2559 assert( idx < left.bv_len );
2561 if( idx >= left.bv_len ) {
2562 /* this shouldn't happen */
2569 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2570 /* not enough left */
2575 match = strncasecmp( left.bv_val,
2576 sub->sa_any[i]->bv_val,
2577 sub->sa_any[i]->bv_len );
2586 left.bv_val += sub->sa_any[i]->bv_len;
2587 left.bv_len -= sub->sa_any[i]->bv_len;
2588 inlen -= sub->sa_any[i]->bv_len;
2594 return LDAP_SUCCESS;
2597 /* Index generation function */
2598 int caseIgnoreIA5Indexer(
2603 struct berval *prefix,
2604 struct berval **values,
2605 struct berval ***keysp )
2609 struct berval **keys;
2610 lutil_MD5_CTX MD5context;
2611 unsigned char MD5digest[16];
2612 struct berval digest;
2613 digest.bv_val = MD5digest;
2614 digest.bv_len = sizeof(MD5digest);
2616 for( i=0; values[i] != NULL; i++ ) {
2617 /* just count them */
2622 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2624 slen = strlen( syntax->ssyn_oid );
2625 mlen = strlen( mr->smr_oid );
2627 for( i=0; values[i] != NULL; i++ ) {
2628 struct berval *value = ber_bvdup( values[i] );
2629 ldap_pvt_str2upper( value->bv_val );
2631 lutil_MD5Init( &MD5context );
2632 if( prefix != NULL && prefix->bv_len > 0 ) {
2633 lutil_MD5Update( &MD5context,
2634 prefix->bv_val, prefix->bv_len );
2636 lutil_MD5Update( &MD5context,
2637 syntax->ssyn_oid, slen );
2638 lutil_MD5Update( &MD5context,
2639 mr->smr_oid, mlen );
2640 lutil_MD5Update( &MD5context,
2641 value->bv_val, value->bv_len );
2642 lutil_MD5Final( MD5digest, &MD5context );
2644 ber_bvfree( value );
2646 keys[i] = ber_bvdup( &digest );
2651 return LDAP_SUCCESS;
2654 /* Index generation function */
2655 int caseIgnoreIA5Filter(
2660 struct berval *prefix,
2662 struct berval ***keysp )
2665 struct berval **keys;
2666 lutil_MD5_CTX MD5context;
2667 unsigned char MD5digest[LUTIL_MD5_BYTES];
2668 struct berval *value;
2669 struct berval digest;
2670 digest.bv_val = MD5digest;
2671 digest.bv_len = sizeof(MD5digest);
2673 slen = strlen( syntax->ssyn_oid );
2674 mlen = strlen( mr->smr_oid );
2676 value = ber_bvdup( (struct berval *) assertValue );
2677 ldap_pvt_str2upper( value->bv_val );
2679 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2681 lutil_MD5Init( &MD5context );
2682 if( prefix != NULL && prefix->bv_len > 0 ) {
2683 lutil_MD5Update( &MD5context,
2684 prefix->bv_val, prefix->bv_len );
2686 lutil_MD5Update( &MD5context,
2687 syntax->ssyn_oid, slen );
2688 lutil_MD5Update( &MD5context,
2689 mr->smr_oid, mlen );
2690 lutil_MD5Update( &MD5context,
2691 value->bv_val, value->bv_len );
2692 lutil_MD5Final( MD5digest, &MD5context );
2694 keys[0] = ber_bvdup( &digest );
2697 ber_bvfree( value );
2701 return LDAP_SUCCESS;
2704 /* Substrings Index generation function */
2705 int caseIgnoreIA5SubstringsIndexer(
2710 struct berval *prefix,
2711 struct berval **values,
2712 struct berval ***keysp )
2716 struct berval **keys;
2717 lutil_MD5_CTX MD5context;
2718 unsigned char MD5digest[16];
2719 struct berval digest;
2720 digest.bv_val = MD5digest;
2721 digest.bv_len = sizeof(MD5digest);
2724 for( i=0; values[i] != NULL; i++ ) {
2725 /* count number of indices to generate */
2726 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2730 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2731 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2732 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2733 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2735 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2739 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2740 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2741 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2745 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2746 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2747 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2748 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2750 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2757 /* no keys to generate */
2759 return LDAP_SUCCESS;
2762 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2764 slen = strlen( syntax->ssyn_oid );
2765 mlen = strlen( mr->smr_oid );
2768 for( i=0; values[i] != NULL; i++ ) {
2770 struct berval *value;
2772 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2774 value = ber_bvdup( values[i] );
2775 ldap_pvt_str2upper( value->bv_val );
2777 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2778 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2780 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2781 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2783 for( j=0; j<max; j++ ) {
2784 lutil_MD5Init( &MD5context );
2785 if( prefix != NULL && prefix->bv_len > 0 ) {
2786 lutil_MD5Update( &MD5context,
2787 prefix->bv_val, prefix->bv_len );
2790 lutil_MD5Update( &MD5context,
2791 &pre, sizeof( pre ) );
2792 lutil_MD5Update( &MD5context,
2793 syntax->ssyn_oid, slen );
2794 lutil_MD5Update( &MD5context,
2795 mr->smr_oid, mlen );
2796 lutil_MD5Update( &MD5context,
2798 SLAP_INDEX_SUBSTR_MAXLEN );
2799 lutil_MD5Final( MD5digest, &MD5context );
2801 keys[nkeys++] = ber_bvdup( &digest );
2805 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2806 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2808 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2811 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2812 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2813 lutil_MD5Init( &MD5context );
2814 if( prefix != NULL && prefix->bv_len > 0 ) {
2815 lutil_MD5Update( &MD5context,
2816 prefix->bv_val, prefix->bv_len );
2818 lutil_MD5Update( &MD5context,
2819 &pre, sizeof( pre ) );
2820 lutil_MD5Update( &MD5context,
2821 syntax->ssyn_oid, slen );
2822 lutil_MD5Update( &MD5context,
2823 mr->smr_oid, mlen );
2824 lutil_MD5Update( &MD5context,
2826 lutil_MD5Final( MD5digest, &MD5context );
2828 keys[nkeys++] = ber_bvdup( &digest );
2831 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2832 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2833 lutil_MD5Init( &MD5context );
2834 if( prefix != NULL && prefix->bv_len > 0 ) {
2835 lutil_MD5Update( &MD5context,
2836 prefix->bv_val, prefix->bv_len );
2838 lutil_MD5Update( &MD5context,
2839 &pre, sizeof( pre ) );
2840 lutil_MD5Update( &MD5context,
2841 syntax->ssyn_oid, slen );
2842 lutil_MD5Update( &MD5context,
2843 mr->smr_oid, mlen );
2844 lutil_MD5Update( &MD5context,
2845 &value->bv_val[value->bv_len-j], j );
2846 lutil_MD5Final( MD5digest, &MD5context );
2848 keys[nkeys++] = ber_bvdup( &digest );
2853 ber_bvfree( value );
2864 return LDAP_SUCCESS;
2867 int caseIgnoreIA5SubstringsFilter(
2872 struct berval *prefix,
2874 struct berval ***keysp )
2876 SubstringsAssertion *sa = assertValue;
2878 ber_len_t nkeys = 0;
2879 size_t slen, mlen, klen;
2880 struct berval **keys;
2881 lutil_MD5_CTX MD5context;
2882 unsigned char MD5digest[LUTIL_MD5_BYTES];
2883 struct berval *value;
2884 struct berval digest;
2886 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2887 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2892 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2894 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2895 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2896 /* don't bother accounting for stepping */
2897 nkeys += sa->sa_any[i]->bv_len -
2898 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2903 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2904 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2911 return LDAP_SUCCESS;
2914 digest.bv_val = MD5digest;
2915 digest.bv_len = sizeof(MD5digest);
2917 slen = strlen( syntax->ssyn_oid );
2918 mlen = strlen( mr->smr_oid );
2920 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2923 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2924 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2926 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2927 value = ber_bvdup( sa->sa_initial );
2928 ldap_pvt_str2upper( value->bv_val );
2930 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2931 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2933 lutil_MD5Init( &MD5context );
2934 if( prefix != NULL && prefix->bv_len > 0 ) {
2935 lutil_MD5Update( &MD5context,
2936 prefix->bv_val, prefix->bv_len );
2938 lutil_MD5Update( &MD5context,
2939 &pre, sizeof( pre ) );
2940 lutil_MD5Update( &MD5context,
2941 syntax->ssyn_oid, slen );
2942 lutil_MD5Update( &MD5context,
2943 mr->smr_oid, mlen );
2944 lutil_MD5Update( &MD5context,
2945 value->bv_val, klen );
2946 lutil_MD5Final( MD5digest, &MD5context );
2948 ber_bvfree( value );
2949 keys[nkeys++] = ber_bvdup( &digest );
2952 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2954 pre = SLAP_INDEX_SUBSTR_PREFIX;
2955 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2957 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2958 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2962 value = ber_bvdup( sa->sa_any[i] );
2963 ldap_pvt_str2upper( value->bv_val );
2966 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2967 j += SLAP_INDEX_SUBSTR_STEP )
2969 lutil_MD5Init( &MD5context );
2970 if( prefix != NULL && prefix->bv_len > 0 ) {
2971 lutil_MD5Update( &MD5context,
2972 prefix->bv_val, prefix->bv_len );
2974 lutil_MD5Update( &MD5context,
2975 &pre, sizeof( pre ) );
2976 lutil_MD5Update( &MD5context,
2977 syntax->ssyn_oid, slen );
2978 lutil_MD5Update( &MD5context,
2979 mr->smr_oid, mlen );
2980 lutil_MD5Update( &MD5context,
2981 &value->bv_val[j], klen );
2982 lutil_MD5Final( MD5digest, &MD5context );
2984 keys[nkeys++] = ber_bvdup( &digest );
2987 ber_bvfree( value );
2991 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2992 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2994 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2995 value = ber_bvdup( sa->sa_final );
2996 ldap_pvt_str2upper( value->bv_val );
2998 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2999 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3001 lutil_MD5Init( &MD5context );
3002 if( prefix != NULL && prefix->bv_len > 0 ) {
3003 lutil_MD5Update( &MD5context,
3004 prefix->bv_val, prefix->bv_len );
3006 lutil_MD5Update( &MD5context,
3007 &pre, sizeof( pre ) );
3008 lutil_MD5Update( &MD5context,
3009 syntax->ssyn_oid, slen );
3010 lutil_MD5Update( &MD5context,
3011 mr->smr_oid, mlen );
3012 lutil_MD5Update( &MD5context,
3013 &value->bv_val[value->bv_len-klen], klen );
3014 lutil_MD5Final( MD5digest, &MD5context );
3016 ber_bvfree( value );
3017 keys[nkeys++] = ber_bvdup( &digest );
3028 return LDAP_SUCCESS;
3032 numericStringNormalize(
3035 struct berval **normalized )
3037 /* similiar to IA5StringNormalize except removes all spaces */
3038 struct berval *newval;
3041 newval = ch_malloc( sizeof( struct berval ) );
3045 /* Ignore initial whitespace */
3046 while ( ASCII_SPACE( *p ) ) {
3052 return LDAP_INVALID_SYNTAX;
3055 newval->bv_val = ch_strdup( p );
3056 p = q = newval->bv_val;
3059 if ( ASCII_SPACE( *p ) ) {
3060 /* Ignore whitespace */
3067 assert( *newval->bv_val );
3068 assert( newval->bv_val < p );
3071 /* cannot start with a space */
3072 assert( !ASCII_SPACE(*newval->bv_val) );
3074 /* cannot end with a space */
3075 assert( !ASCII_SPACE( q[-1] ) );
3077 /* null terminate */
3080 newval->bv_len = q - newval->bv_val;
3081 *normalized = newval;
3083 return LDAP_SUCCESS;
3087 objectIdentifierFirstComponentMatch(
3092 struct berval *value,
3093 void *assertedValue )
3095 int rc = LDAP_SUCCESS;
3097 struct berval *asserted = (struct berval *) assertedValue;
3101 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3102 return LDAP_INVALID_SYNTAX;
3105 /* trim leading white space */
3106 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3110 /* grab next word */
3111 oid.bv_val = &value->bv_val[i];
3112 oid.bv_len = value->bv_len - i;
3113 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3118 /* insert attributeTypes, objectclass check here */
3119 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3120 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3123 char *stored = ch_malloc( oid.bv_len + 1 );
3124 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3125 stored[oid.bv_len] = '\0';
3127 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3128 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3129 MatchingRule *stored_mr = mr_find( stored );
3131 if( asserted_mr == NULL ) {
3132 rc = SLAPD_COMPARE_UNDEFINED;
3134 match = asserted_mr != stored_mr;
3137 } else if ( !strcmp( syntax->ssyn_oid,
3138 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3140 AttributeType *asserted_at = at_find( asserted->bv_val );
3141 AttributeType *stored_at = at_find( stored );
3143 if( asserted_at == NULL ) {
3144 rc = SLAPD_COMPARE_UNDEFINED;
3146 match = asserted_at != stored_at;
3149 } else if ( !strcmp( syntax->ssyn_oid,
3150 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3152 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3153 ObjectClass *stored_oc = oc_find( stored );
3155 if( asserted_oc == NULL ) {
3156 rc = SLAPD_COMPARE_UNDEFINED;
3158 match = asserted_oc != stored_oc;
3165 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3166 "%d\n\t\"%s\"\n\t\"%s\"\n",
3167 match, value->bv_val, asserted->bv_val );
3169 if( rc == LDAP_SUCCESS ) *matchp = match;
3174 check_time_syntax (struct berval *val,
3178 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3179 static int mdays[2][12] = {
3180 /* non-leap years */
3181 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3183 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3186 int part, c, tzoffset, leapyear = 0 ;
3188 if( val->bv_len == 0 ) {
3189 return LDAP_INVALID_SYNTAX;
3192 p = (char *)val->bv_val;
3193 e = p + val->bv_len;
3195 /* Ignore initial whitespace */
3196 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3200 if (e - p < 13 - (2 * start)) {
3201 return LDAP_INVALID_SYNTAX;
3204 for (part = 0; part < 9; part++) {
3208 for (part = start; part < 7; part++) {
3210 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3217 return LDAP_INVALID_SYNTAX;
3219 if (c < 0 || c > 9) {
3220 return LDAP_INVALID_SYNTAX;
3226 return LDAP_INVALID_SYNTAX;
3228 if (c < 0 || c > 9) {
3229 return LDAP_INVALID_SYNTAX;
3234 if (part == 2 || part == 3) {
3237 if (parts[part] < 0) {
3238 return LDAP_INVALID_SYNTAX;
3240 if (parts[part] > ceiling[part]) {
3241 return LDAP_INVALID_SYNTAX;
3245 /* leapyear check for the Gregorian calendar (year>1581) */
3246 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3247 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3252 if (parts[3] > mdays[leapyear][parts[2]]) {
3253 return LDAP_INVALID_SYNTAX;
3258 tzoffset = 0; /* UTC */
3259 } else if (c != '+' && c != '-') {
3260 return LDAP_INVALID_SYNTAX;
3264 } else /* c == '+' */ {
3269 return LDAP_INVALID_SYNTAX;
3272 for (part = 7; part < 9; part++) {
3274 if (c < 0 || c > 9) {
3275 return LDAP_INVALID_SYNTAX;
3280 if (c < 0 || c > 9) {
3281 return LDAP_INVALID_SYNTAX;
3285 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3286 return LDAP_INVALID_SYNTAX;
3291 /* Ignore trailing whitespace */
3292 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3296 return LDAP_INVALID_SYNTAX;
3299 switch ( tzoffset ) {
3300 case -1: /* negativ offset to UTC, ie west of Greenwich */
3301 parts[4] += parts[7];
3302 parts[5] += parts[8];
3303 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3307 c = mdays[leapyear][parts[2]];
3309 if (parts[part] > c) {
3310 parts[part] -= c + 1;
3315 case 1: /* positive offset to UTC, ie east of Greenwich */
3316 parts[4] -= parts[7];
3317 parts[5] -= parts[8];
3318 for (part = 6; --part > 0; ) {
3322 /* first arg to % needs to be non negativ */
3323 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3325 if (parts[part] < 0) {
3326 parts[part] += c + 1;
3331 case 0: /* already UTC */
3335 return LDAP_SUCCESS;
3342 struct berval **normalized )
3347 rc = check_time_syntax(val, 1, parts);
3348 if (rc != LDAP_SUCCESS) {
3353 out = ch_malloc( sizeof(struct berval) );
3355 return LBER_ERROR_MEMORY;
3358 out->bv_val = ch_malloc( 14 );
3359 if ( out->bv_val == NULL ) {
3361 return LBER_ERROR_MEMORY;
3364 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3365 parts[1], parts[2] + 1, parts[3] + 1,
3366 parts[4], parts[5], parts[6] );
3370 return LDAP_SUCCESS;
3380 return check_time_syntax(in, 1, parts);
3384 generalizedTimeValidate(
3390 return check_time_syntax(in, 0, parts);
3394 generalizedTimeNormalize(
3397 struct berval **normalized )
3402 rc = check_time_syntax(val, 0, parts);
3403 if (rc != LDAP_SUCCESS) {
3408 out = ch_malloc( sizeof(struct berval) );
3410 return LBER_ERROR_MEMORY;
3413 out->bv_val = ch_malloc( 16 );
3414 if ( out->bv_val == NULL ) {
3416 return LBER_ERROR_MEMORY;
3419 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3420 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3421 parts[4], parts[5], parts[6] );
3425 return LDAP_SUCCESS;
3429 nisNetgroupTripleValidate(
3431 struct berval *val )
3436 if ( val->bv_len == 0 ) {
3437 return LDAP_INVALID_SYNTAX;
3440 p = (char *)val->bv_val;
3441 e = p + val->bv_len;
3444 /* syntax does not allow leading white space */
3445 /* Ignore initial whitespace */
3446 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3451 if ( *p != '(' /*')'*/ ) {
3452 return LDAP_INVALID_SYNTAX;
3455 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3459 return LDAP_INVALID_SYNTAX;
3462 } else if ( !ATTR_CHAR( *p ) ) {
3463 return LDAP_INVALID_SYNTAX;
3467 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3468 return LDAP_INVALID_SYNTAX;
3474 /* syntax does not allow trailing white space */
3475 /* Ignore trailing whitespace */
3476 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3482 return LDAP_INVALID_SYNTAX;
3485 return LDAP_SUCCESS;
3489 bootParameterValidate(
3491 struct berval *val )
3495 if ( val->bv_len == 0 ) {
3496 return LDAP_INVALID_SYNTAX;
3499 p = (char *)val->bv_val;
3500 e = p + val->bv_len;
3503 for (; ( p < e ) && ( *p != '=' ); p++ ) {
3504 if ( !ATTR_CHAR( *p ) ) {
3505 return LDAP_INVALID_SYNTAX;
3510 return LDAP_INVALID_SYNTAX;
3514 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
3515 if ( !ATTR_CHAR( *p ) ) {
3516 return LDAP_INVALID_SYNTAX;
3521 return LDAP_INVALID_SYNTAX;
3525 for ( p++; p < e; p++ ) {
3526 if ( !ATTR_CHAR( *p ) ) {
3527 return LDAP_INVALID_SYNTAX;
3531 return LDAP_SUCCESS;
3534 struct syntax_defs_rec {
3537 slap_syntax_validate_func *sd_validate;
3538 slap_syntax_transform_func *sd_normalize;
3539 slap_syntax_transform_func *sd_pretty;
3540 #ifdef SLAPD_BINARY_CONVERSION
3541 slap_syntax_transform_func *sd_ber2str;
3542 slap_syntax_transform_func *sd_str2ber;
3546 #define X_HIDE "X-HIDE 'TRUE' "
3547 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
3548 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
3550 struct syntax_defs_rec syntax_defs[] = {
3551 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
3552 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
3553 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
3554 0, NULL, NULL, NULL},
3555 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
3556 0, NULL, NULL, NULL},
3557 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
3558 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3559 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
3560 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3561 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
3562 0, bitStringValidate, bitStringNormalize, NULL },
3563 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
3564 0, booleanValidate, NULL, NULL},
3565 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
3566 X_BINARY X_NOT_H_R ")",
3567 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3568 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
3569 X_BINARY X_NOT_H_R ")",
3570 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3571 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
3572 X_BINARY X_NOT_H_R ")",
3573 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3574 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
3575 0, NULL, NULL, NULL},
3576 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
3577 0, dnValidate, dnNormalize, dnPretty},
3578 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
3579 0, NULL, NULL, NULL},
3580 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
3581 0, NULL, NULL, NULL},
3582 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
3583 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3584 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
3585 0, NULL, NULL, NULL},
3586 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
3587 0, NULL, NULL, NULL},
3588 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
3589 0, NULL, NULL, NULL},
3590 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
3591 0, NULL, NULL, NULL},
3592 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
3593 0, NULL, NULL, NULL},
3594 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
3595 0, IA5StringValidate, faxNumberNormalize, NULL},
3596 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
3597 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
3598 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
3599 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
3600 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
3601 0, NULL, NULL, NULL},
3602 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
3603 0, IA5StringValidate, IA5StringNormalize, NULL},
3604 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
3605 0, integerValidate, integerNormalize, integerPretty},
3606 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
3607 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3608 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
3609 0, NULL, NULL, NULL},
3610 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
3611 0, NULL, NULL, NULL},
3612 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
3613 0, NULL, NULL, NULL},
3614 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
3615 0, NULL, NULL, NULL},
3616 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
3617 0, NULL, NULL, NULL},
3618 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
3619 0, nameUIDValidate, nameUIDNormalize, nameUIDPretty},
3620 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
3621 0, NULL, NULL, NULL},
3622 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
3623 0, IA5StringValidate, numericStringNormalize, NULL},
3624 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
3625 0, NULL, NULL, NULL},
3626 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
3627 0, oidValidate, NULL, NULL},
3628 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
3629 0, NULL, NULL, NULL},
3630 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
3631 0, blobValidate, NULL, NULL},
3632 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
3633 0, blobValidate, NULL, NULL},
3634 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
3635 0, NULL, NULL, NULL},
3636 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
3637 0, NULL, NULL, NULL},
3638 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
3639 0, printableStringValidate, NULL, NULL},
3640 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
3641 X_BINARY X_NOT_H_R ")",
3642 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3643 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
3644 0, IA5StringValidate, phoneNumberNormalize, NULL},
3645 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
3646 0, NULL, NULL, NULL},
3647 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
3648 0, IA5StringValidate, telexNumberNormalize, NULL},
3649 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
3650 0, utcTimeValidate, utcTimeNormalize, NULL},
3651 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
3652 0, NULL, NULL, NULL},
3653 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
3654 0, NULL, NULL, NULL},
3655 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
3656 0, NULL, NULL, NULL},
3657 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
3658 0, NULL, NULL, NULL},
3659 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
3660 0, NULL, NULL, NULL},
3662 /* RFC 2307 NIS Syntaxes */
3663 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Triple' )",
3664 0, nisNetgroupTripleValidate, NULL, NULL},
3665 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
3666 0, bootParameterValidate, NULL, NULL},
3668 /* OpenLDAP Experimental Syntaxes */
3669 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
3670 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
3672 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
3673 0, NULL, NULL, NULL},
3675 /* OpenLDAP Void Syntax */
3676 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' " X_HIDE ")" ,
3677 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
3678 {NULL, 0, NULL, NULL, NULL}
3681 struct mrule_defs_rec {
3683 slap_mask_t mrd_usage;
3684 slap_mr_convert_func * mrd_convert;
3685 slap_mr_normalize_func * mrd_normalize;
3686 slap_mr_match_func * mrd_match;
3687 slap_mr_indexer_func * mrd_indexer;
3688 slap_mr_filter_func * mrd_filter;
3690 char * mrd_associated;
3694 * Other matching rules in X.520 that we do not use (yet):
3696 * 2.5.13.9 numericStringOrderingMatch
3697 * 2.5.13.13 booleanMatch
3698 * 2.5.13.15 integerOrderingMatch
3699 * 2.5.13.18 octetStringOrderingMatch
3700 * 2.5.13.19 octetStringSubstringsMatch
3701 * 2.5.13.25 uTCTimeMatch
3702 * 2.5.13.26 uTCTimeOrderingMatch
3703 * 2.5.13.31 directoryStringFirstComponentMatch
3704 * 2.5.13.32 wordMatch
3705 * 2.5.13.33 keywordMatch
3706 * 2.5.13.34 certificateExactMatch
3707 * 2.5.13.35 certificateMatch
3708 * 2.5.13.36 certificatePairExactMatch
3709 * 2.5.13.37 certificatePairMatch
3710 * 2.5.13.38 certificateListExactMatch
3711 * 2.5.13.39 certificateListMatch
3712 * 2.5.13.40 algorithmIdentifierMatch
3713 * 2.5.13.41 storedPrefixMatch
3714 * 2.5.13.42 attributeCertificateMatch
3715 * 2.5.13.43 readerAndKeyIDMatch
3716 * 2.5.13.44 attributeIntegrityMatch
3719 struct mrule_defs_rec mrule_defs[] = {
3721 * EQUALITY matching rules must be listed after associated APPROX
3722 * matching rules. So, we list all APPROX matching rules first.
3724 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
3725 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3726 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3728 directoryStringApproxMatch, NULL, NULL,
3731 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
3732 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3733 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3735 IA5StringApproxMatch, NULL, NULL,
3739 * Other matching rules
3742 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
3743 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3744 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3746 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
3749 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
3750 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
3751 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3753 dnMatch, dnIndexer, dnFilter,
3756 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
3757 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3758 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3760 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
3761 directoryStringApproxMatchOID },
3763 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
3764 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3767 caseIgnoreOrderingMatch, NULL, NULL,
3770 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
3771 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3772 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3774 caseIgnoreSubstringsMatch,
3775 caseIgnoreSubstringsIndexer,
3776 caseIgnoreSubstringsFilter,
3779 {"( 2.5.13.5 NAME 'caseExactMatch' "
3780 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3781 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3783 caseExactMatch, caseExactIndexer, caseExactFilter,
3784 directoryStringApproxMatchOID },
3786 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
3787 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3790 caseExactOrderingMatch, NULL, NULL,
3793 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
3794 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3795 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3797 caseExactSubstringsMatch,
3798 caseExactSubstringsIndexer,
3799 caseExactSubstringsFilter,
3802 {"( 2.5.13.8 NAME 'numericStringMatch' "
3803 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
3804 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3806 caseIgnoreIA5Match, NULL, NULL,
3809 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
3810 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3811 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3813 caseIgnoreIA5SubstringsMatch,
3814 caseIgnoreIA5SubstringsIndexer,
3815 caseIgnoreIA5SubstringsFilter,
3818 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
3819 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
3820 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3822 caseIgnoreListMatch, NULL, NULL,
3825 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
3826 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3827 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3829 caseIgnoreListSubstringsMatch, NULL, NULL,
3832 {"( 2.5.13.13 NAME 'booleanMatch' "
3833 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
3834 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3836 booleanMatch, NULL, NULL,
3839 {"( 2.5.13.14 NAME 'integerMatch' "
3840 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
3841 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3843 integerMatch, integerIndexer, integerFilter,
3846 {"( 2.5.13.16 NAME 'bitStringMatch' "
3847 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
3848 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3850 bitStringMatch, NULL, NULL,
3853 {"( 2.5.13.17 NAME 'octetStringMatch' "
3854 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
3855 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3857 octetStringMatch, octetStringIndexer, octetStringFilter,
3860 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
3861 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
3862 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3864 telephoneNumberMatch, NULL, NULL,
3867 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
3868 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3869 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3871 telephoneNumberSubstringsMatch, NULL, NULL,
3874 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
3875 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
3876 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3878 presentationAddressMatch, NULL, NULL,
3881 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
3882 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
3883 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3885 uniqueMemberMatch, NULL, NULL,
3888 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
3889 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
3890 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3892 protocolInformationMatch, NULL, NULL,
3895 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
3896 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
3897 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3899 generalizedTimeMatch, NULL, NULL,
3902 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
3903 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
3906 generalizedTimeOrderingMatch, NULL, NULL,
3909 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
3910 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
3911 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3913 integerFirstComponentMatch, NULL, NULL,
3916 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
3917 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3918 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3920 objectIdentifierFirstComponentMatch, NULL, NULL,
3923 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
3924 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3925 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3927 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
3928 IA5StringApproxMatchOID },
3930 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
3931 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3932 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3934 caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
3935 IA5StringApproxMatchOID },
3937 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
3938 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3941 caseIgnoreIA5SubstringsMatch,
3942 caseIgnoreIA5SubstringsIndexer,
3943 caseIgnoreIA5SubstringsFilter,
3946 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
3947 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3950 caseExactIA5SubstringsMatch,
3951 caseExactIA5SubstringsIndexer,
3952 caseExactIA5SubstringsFilter,
3955 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
3956 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
3959 authPasswordMatch, NULL, NULL,
3962 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
3963 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
3966 OpenLDAPaciMatch, NULL, NULL,
3969 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
3978 /* we should only be called once (from main) */
3979 assert( schema_init_done == 0 );
3981 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
3982 res = register_syntax( syntax_defs[i].sd_desc,
3983 syntax_defs[i].sd_flags,
3984 syntax_defs[i].sd_validate,
3985 syntax_defs[i].sd_normalize,
3986 syntax_defs[i].sd_pretty
3987 #ifdef SLAPD_BINARY_CONVERSION
3989 syntax_defs[i].sd_ber2str,
3990 syntax_defs[i].sd_str2ber
3995 fprintf( stderr, "schema_init: Error registering syntax %s\n",
3996 syntax_defs[i].sd_desc );
4001 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4002 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4004 "schema_init: Ingoring unusable matching rule %s\n",
4005 mrule_defs[i].mrd_desc );
4009 res = register_matching_rule(
4010 mrule_defs[i].mrd_desc,
4011 mrule_defs[i].mrd_usage,
4012 mrule_defs[i].mrd_convert,
4013 mrule_defs[i].mrd_normalize,
4014 mrule_defs[i].mrd_match,
4015 mrule_defs[i].mrd_indexer,
4016 mrule_defs[i].mrd_filter,
4017 mrule_defs[i].mrd_associated );
4021 "schema_init: Error registering matching rule %s\n",
4022 mrule_defs[i].mrd_desc );
4026 schema_init_done = 1;
4027 return LDAP_SUCCESS;