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 integerNormalize numericStringNormalize
32 #define nameUIDNormalize dnNormalize
34 /* unimplemented normalizers */
35 #define bitStringNormalize NULL
37 /* unimplemented pretters */
39 #define integerPretty NULL
41 /* recyclied pretters */
42 #define nameUIDPretty dnPretty
44 /* recycled matching routines */
45 #define numericStringMatch caseIgnoreMatch
46 #define objectIdentifierMatch numericStringMatch
47 #define integerMatch numericStringMatch
48 #define telephoneNumberMatch numericStringMatch
49 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
50 #define generalizedTimeMatch numericStringMatch
51 #define generalizedTimeOrderingMatch numericStringMatch
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 uniqueMemberMatch NULL
69 #define protocolInformationMatch NULL
70 #define integerFirstComponentMatch NULL
72 #define OpenLDAPaciMatch NULL
73 #define authPasswordMatch NULL
75 /* recycled indexing/filtering routines */
76 #define dnIndexer caseIgnoreIndexer
77 #define dnFilter caseIgnoreFilter
79 static char *strcasechr( const char *str, int c )
81 char *lower = strchr( str, TOLOWER(c) );
82 char *upper = strchr( str, TOUPPER(c) );
84 if( lower && upper ) {
85 return lower < upper ? lower : upper;
100 void *assertedValue )
102 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
105 match = memcmp( value->bv_val,
106 ((struct berval *) assertedValue)->bv_val,
114 /* Index generation function */
115 int octetStringIndexer(
120 struct berval *prefix,
121 struct berval **values,
122 struct berval ***keysp )
126 struct berval **keys;
127 lutil_MD5_CTX MD5context;
128 unsigned char MD5digest[16];
129 struct berval digest;
130 digest.bv_val = MD5digest;
131 digest.bv_len = sizeof(MD5digest);
133 for( i=0; values[i] != NULL; i++ ) {
134 /* just count them */
139 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
141 slen = strlen( syntax->ssyn_oid );
142 mlen = strlen( mr->smr_oid );
144 for( i=0; values[i] != NULL; i++ ) {
145 lutil_MD5Init( &MD5context );
146 if( prefix != NULL && prefix->bv_len > 0 ) {
147 lutil_MD5Update( &MD5context,
148 prefix->bv_val, prefix->bv_len );
150 lutil_MD5Update( &MD5context,
151 syntax->ssyn_oid, slen );
152 lutil_MD5Update( &MD5context,
154 lutil_MD5Update( &MD5context,
155 values[i]->bv_val, values[i]->bv_len );
156 lutil_MD5Final( MD5digest, &MD5context );
158 keys[i] = ber_bvdup( &digest );
168 /* Index generation function */
169 int octetStringFilter(
174 struct berval *prefix,
176 struct berval ***keysp )
179 struct berval **keys;
180 lutil_MD5_CTX MD5context;
181 unsigned char MD5digest[LUTIL_MD5_BYTES];
182 struct berval *value = (struct berval *) assertValue;
183 struct berval digest;
184 digest.bv_val = MD5digest;
185 digest.bv_len = sizeof(MD5digest);
187 slen = strlen( syntax->ssyn_oid );
188 mlen = strlen( mr->smr_oid );
190 keys = ch_malloc( sizeof( struct berval * ) * 2 );
192 lutil_MD5Init( &MD5context );
193 if( prefix != NULL && prefix->bv_len > 0 ) {
194 lutil_MD5Update( &MD5context,
195 prefix->bv_val, prefix->bv_len );
197 lutil_MD5Update( &MD5context,
198 syntax->ssyn_oid, slen );
199 lutil_MD5Update( &MD5context,
201 lutil_MD5Update( &MD5context,
202 value->bv_val, value->bv_len );
203 lutil_MD5Final( MD5digest, &MD5context );
205 keys[0] = ber_bvdup( &digest );
221 if( in->bv_len == 0 ) return LDAP_SUCCESS;
223 dn = ch_strdup( in->bv_val );
225 rc = dn_validate( dn ) == NULL
226 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
236 struct berval **normalized )
238 struct berval *out = ber_bvdup( val );
240 if( out->bv_len != 0 ) {
242 #ifdef USE_DN_NORMALIZE
243 dn = dn_normalize( out->bv_val );
245 dn = dn_validate( out->bv_val );
250 return LDAP_INVALID_SYNTAX;
254 out->bv_len = strlen( dn );
267 struct berval *value,
268 void *assertedValue )
271 struct berval *asserted = (struct berval *) assertedValue;
273 match = value->bv_len - asserted->bv_len;
276 #ifdef USE_DN_NORMALIZE
277 match = strcmp( value->bv_val, asserted->bv_val );
279 match = strcasecmp( value->bv_val, asserted->bv_val );
283 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
284 match, value->bv_val, asserted->bv_val );
295 /* any value allowed */
304 /* any value allowed */
309 * Handling boolean syntax and matching is quite rigid.
310 * A more flexible approach would be to allow a variety
311 * of strings to be normalized and prettied into TRUE
319 /* very unforgiving validation, requires no normalization
320 * before simplistic matching
323 if( in->bv_len == 4 ) {
324 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
327 } else if( in->bv_len == 5 ) {
328 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
333 return LDAP_INVALID_SYNTAX;
342 struct berval *value,
343 void *assertedValue )
345 /* simplistic matching allowed by rigid validation */
346 struct berval *asserted = (struct berval *) assertedValue;
347 *matchp = value->bv_len != asserted->bv_len;
354 struct berval *right,
355 struct berval *left )
359 ldap_unicode_t ru, lu;
360 ldap_unicode_t ruu, luu;
363 r < right->bv_len && l < left->bv_len;
367 * XXYYZ: we convert to ucs4 even though -llunicode
368 * expects ucs2 in an unsigned long
370 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
371 if( ru == LDAP_UCS4_INVALID ) {
375 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
376 if( lu == LDAP_UCS4_INVALID ) {
380 ruu = uctoupper( ru );
381 luu = uctoupper( lu );
385 } else if( luu > ruu ) {
389 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
390 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
393 if( r < right->bv_len ) {
398 if( l < left->bv_len ) {
414 unsigned char *u = in->bv_val;
416 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
418 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
419 /* get the length indicated by the first byte */
420 len = LDAP_UTF8_CHARLEN( u );
422 /* should not be zero */
423 if( len == 0 ) return LDAP_INVALID_SYNTAX;
425 /* make sure len corresponds with the offset
426 to the next character */
427 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
430 if( count != 0 ) return LDAP_INVALID_SYNTAX;
439 struct berval **normalized )
441 struct berval *newval;
444 newval = ch_malloc( sizeof( struct berval ) );
448 /* Ignore initial whitespace */
449 while ( ldap_utf8_isspace( p ) ) {
455 return LDAP_INVALID_SYNTAX;
458 newval->bv_val = ch_strdup( p );
459 p = q = newval->bv_val;
465 if ( ldap_utf8_isspace( p ) ) {
466 len = LDAP_UTF8_COPY(q,p);
471 /* Ignore the extra whitespace */
472 while ( ldap_utf8_isspace( p ) ) {
476 len = LDAP_UTF8_COPY(q,p);
483 assert( *newval->bv_val );
484 assert( newval->bv_val < p );
487 /* cannot start with a space */
488 assert( !ldap_utf8_isspace(newval->bv_val) );
491 * If the string ended in space, backup the pointer one
492 * position. One is enough because the above loop collapsed
493 * all whitespace to a single space.
500 /* cannot end with a space */
501 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
506 newval->bv_len = q - newval->bv_val;
507 *normalized = newval;
518 struct berval *value,
519 void *assertedValue )
521 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
524 match = strncmp( value->bv_val,
525 ((struct berval *) assertedValue)->bv_val,
534 caseExactSubstringsMatch(
539 struct berval *value,
540 void *assertedValue )
543 SubstringsAssertion *sub = assertedValue;
544 struct berval left = *value;
548 /* Add up asserted input length */
549 if( sub->sa_initial ) {
550 inlen += sub->sa_initial->bv_len;
553 for(i=0; sub->sa_any[i] != NULL; i++) {
554 inlen += sub->sa_any[i]->bv_len;
557 if( sub->sa_final ) {
558 inlen += sub->sa_final->bv_len;
561 if( sub->sa_initial ) {
562 if( inlen > left.bv_len ) {
567 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
568 sub->sa_initial->bv_len );
574 left.bv_val += sub->sa_initial->bv_len;
575 left.bv_len -= sub->sa_initial->bv_len;
576 inlen -= sub->sa_initial->bv_len;
579 if( sub->sa_final ) {
580 if( inlen > left.bv_len ) {
585 match = strncmp( sub->sa_final->bv_val,
586 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
587 sub->sa_final->bv_len );
593 left.bv_len -= sub->sa_final->bv_len;
594 inlen -= sub->sa_final->bv_len;
598 for(i=0; sub->sa_any[i]; i++) {
603 if( inlen > left.bv_len ) {
604 /* not enough length */
609 if( sub->sa_any[i]->bv_len == 0 ) {
613 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
620 idx = p - left.bv_val;
621 assert( idx < left.bv_len );
623 if( idx >= left.bv_len ) {
624 /* this shouldn't happen */
631 if( sub->sa_any[i]->bv_len > left.bv_len ) {
632 /* not enough left */
637 match = strncmp( left.bv_val,
638 sub->sa_any[i]->bv_val,
639 sub->sa_any[i]->bv_len );
647 left.bv_val += sub->sa_any[i]->bv_len;
648 left.bv_len -= sub->sa_any[i]->bv_len;
649 inlen -= sub->sa_any[i]->bv_len;
658 /* Index generation function */
659 int caseExactIndexer(
664 struct berval *prefix,
665 struct berval **values,
666 struct berval ***keysp )
670 struct berval **keys;
671 lutil_MD5_CTX MD5context;
672 unsigned char MD5digest[16];
673 struct berval digest;
674 digest.bv_val = MD5digest;
675 digest.bv_len = sizeof(MD5digest);
677 for( i=0; values[i] != NULL; i++ ) {
678 /* just count them */
683 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
685 slen = strlen( syntax->ssyn_oid );
686 mlen = strlen( mr->smr_oid );
688 for( i=0; values[i] != NULL; i++ ) {
689 struct berval *value = values[i];
691 lutil_MD5Init( &MD5context );
692 if( prefix != NULL && prefix->bv_len > 0 ) {
693 lutil_MD5Update( &MD5context,
694 prefix->bv_val, prefix->bv_len );
696 lutil_MD5Update( &MD5context,
697 syntax->ssyn_oid, slen );
698 lutil_MD5Update( &MD5context,
700 lutil_MD5Update( &MD5context,
701 value->bv_val, value->bv_len );
702 lutil_MD5Final( MD5digest, &MD5context );
704 keys[i] = ber_bvdup( &digest );
712 /* Index generation function */
718 struct berval *prefix,
720 struct berval ***keysp )
723 struct berval **keys;
724 lutil_MD5_CTX MD5context;
725 unsigned char MD5digest[LUTIL_MD5_BYTES];
726 struct berval *value;
727 struct berval digest;
728 digest.bv_val = MD5digest;
729 digest.bv_len = sizeof(MD5digest);
731 slen = strlen( syntax->ssyn_oid );
732 mlen = strlen( mr->smr_oid );
734 value = (struct berval *) assertValue;
736 keys = ch_malloc( sizeof( struct berval * ) * 2 );
738 lutil_MD5Init( &MD5context );
739 if( prefix != NULL && prefix->bv_len > 0 ) {
740 lutil_MD5Update( &MD5context,
741 prefix->bv_val, prefix->bv_len );
743 lutil_MD5Update( &MD5context,
744 syntax->ssyn_oid, slen );
745 lutil_MD5Update( &MD5context,
747 lutil_MD5Update( &MD5context,
748 value->bv_val, value->bv_len );
749 lutil_MD5Final( MD5digest, &MD5context );
751 keys[0] = ber_bvdup( &digest );
758 /* Substrings Index generation function */
759 int caseExactSubstringsIndexer(
764 struct berval *prefix,
765 struct berval **values,
766 struct berval ***keysp )
770 struct berval **keys;
771 lutil_MD5_CTX MD5context;
772 unsigned char MD5digest[16];
773 struct berval digest;
774 digest.bv_val = MD5digest;
775 digest.bv_len = sizeof(MD5digest);
778 for( i=0; values[i] != NULL; i++ ) {
779 /* count number of indices to generate */
780 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
784 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
785 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
786 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
787 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
789 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
793 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
794 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
795 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
799 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
800 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
801 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
802 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
804 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
811 /* no keys to generate */
816 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
818 slen = strlen( syntax->ssyn_oid );
819 mlen = strlen( mr->smr_oid );
822 for( i=0; values[i] != NULL; i++ ) {
824 struct berval *value;
827 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
829 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
830 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
832 char pre = SLAP_INDEX_SUBSTR_PREFIX;
833 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
835 for( j=0; j<max; j++ ) {
836 lutil_MD5Init( &MD5context );
837 if( prefix != NULL && prefix->bv_len > 0 ) {
838 lutil_MD5Update( &MD5context,
839 prefix->bv_val, prefix->bv_len );
842 lutil_MD5Update( &MD5context,
843 &pre, sizeof( pre ) );
844 lutil_MD5Update( &MD5context,
845 syntax->ssyn_oid, slen );
846 lutil_MD5Update( &MD5context,
848 lutil_MD5Update( &MD5context,
850 SLAP_INDEX_SUBSTR_MAXLEN );
851 lutil_MD5Final( MD5digest, &MD5context );
853 keys[nkeys++] = ber_bvdup( &digest );
857 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
858 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
860 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
863 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
864 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
865 lutil_MD5Init( &MD5context );
866 if( prefix != NULL && prefix->bv_len > 0 ) {
867 lutil_MD5Update( &MD5context,
868 prefix->bv_val, prefix->bv_len );
870 lutil_MD5Update( &MD5context,
871 &pre, sizeof( pre ) );
872 lutil_MD5Update( &MD5context,
873 syntax->ssyn_oid, slen );
874 lutil_MD5Update( &MD5context,
876 lutil_MD5Update( &MD5context,
878 lutil_MD5Final( MD5digest, &MD5context );
880 keys[nkeys++] = ber_bvdup( &digest );
883 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
884 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
885 lutil_MD5Init( &MD5context );
886 if( prefix != NULL && prefix->bv_len > 0 ) {
887 lutil_MD5Update( &MD5context,
888 prefix->bv_val, prefix->bv_len );
890 lutil_MD5Update( &MD5context,
891 &pre, sizeof( pre ) );
892 lutil_MD5Update( &MD5context,
893 syntax->ssyn_oid, slen );
894 lutil_MD5Update( &MD5context,
896 lutil_MD5Update( &MD5context,
897 &value->bv_val[value->bv_len-j], j );
898 lutil_MD5Final( MD5digest, &MD5context );
900 keys[nkeys++] = ber_bvdup( &digest );
917 int caseExactSubstringsFilter(
922 struct berval *prefix,
924 struct berval ***keysp )
926 SubstringsAssertion *sa = assertValue;
929 size_t slen, mlen, klen;
930 struct berval **keys;
931 lutil_MD5_CTX MD5context;
932 unsigned char MD5digest[LUTIL_MD5_BYTES];
933 struct berval *value;
934 struct berval digest;
936 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
937 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
942 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
944 for( i=0; sa->sa_any[i] != NULL; i++ ) {
945 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
946 /* don't bother accounting for stepping */
947 nkeys += sa->sa_any[i]->bv_len -
948 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
953 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
954 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
964 digest.bv_val = MD5digest;
965 digest.bv_len = sizeof(MD5digest);
967 slen = strlen( syntax->ssyn_oid );
968 mlen = strlen( mr->smr_oid );
970 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
973 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
974 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
976 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
977 value = sa->sa_initial;
979 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
980 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
982 lutil_MD5Init( &MD5context );
983 if( prefix != NULL && prefix->bv_len > 0 ) {
984 lutil_MD5Update( &MD5context,
985 prefix->bv_val, prefix->bv_len );
987 lutil_MD5Update( &MD5context,
988 &pre, sizeof( pre ) );
989 lutil_MD5Update( &MD5context,
990 syntax->ssyn_oid, slen );
991 lutil_MD5Update( &MD5context,
993 lutil_MD5Update( &MD5context,
994 value->bv_val, klen );
995 lutil_MD5Final( MD5digest, &MD5context );
997 keys[nkeys++] = ber_bvdup( &digest );
1000 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1002 pre = SLAP_INDEX_SUBSTR_PREFIX;
1003 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1005 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1006 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1010 value = sa->sa_any[i];
1013 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1014 j += SLAP_INDEX_SUBSTR_STEP )
1016 lutil_MD5Init( &MD5context );
1017 if( prefix != NULL && prefix->bv_len > 0 ) {
1018 lutil_MD5Update( &MD5context,
1019 prefix->bv_val, prefix->bv_len );
1021 lutil_MD5Update( &MD5context,
1022 &pre, sizeof( pre ) );
1023 lutil_MD5Update( &MD5context,
1024 syntax->ssyn_oid, slen );
1025 lutil_MD5Update( &MD5context,
1026 mr->smr_oid, mlen );
1027 lutil_MD5Update( &MD5context,
1028 &value->bv_val[j], klen );
1029 lutil_MD5Final( MD5digest, &MD5context );
1031 keys[nkeys++] = ber_bvdup( &digest );
1036 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1037 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1039 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1040 value = sa->sa_final;
1042 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1043 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1045 lutil_MD5Init( &MD5context );
1046 if( prefix != NULL && prefix->bv_len > 0 ) {
1047 lutil_MD5Update( &MD5context,
1048 prefix->bv_val, prefix->bv_len );
1050 lutil_MD5Update( &MD5context,
1051 &pre, sizeof( pre ) );
1052 lutil_MD5Update( &MD5context,
1053 syntax->ssyn_oid, slen );
1054 lutil_MD5Update( &MD5context,
1055 mr->smr_oid, mlen );
1056 lutil_MD5Update( &MD5context,
1057 &value->bv_val[value->bv_len-klen], klen );
1058 lutil_MD5Final( MD5digest, &MD5context );
1060 keys[nkeys++] = ber_bvdup( &digest );
1071 return LDAP_SUCCESS;
1080 struct berval *value,
1081 void *assertedValue )
1084 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1086 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1089 match = strncasecmp( value->bv_val,
1090 ((struct berval *) assertedValue)->bv_val,
1096 return LDAP_SUCCESS;
1100 caseIgnoreSubstringsMatch(
1105 struct berval *value,
1106 void *assertedValue )
1109 SubstringsAssertion *sub = assertedValue;
1110 struct berval left = *value;
1114 /* Add up asserted input length */
1115 if( sub->sa_initial ) {
1116 inlen += sub->sa_initial->bv_len;
1119 for(i=0; sub->sa_any[i] != NULL; i++) {
1120 inlen += sub->sa_any[i]->bv_len;
1123 if( sub->sa_final ) {
1124 inlen += sub->sa_final->bv_len;
1127 if( sub->sa_initial ) {
1128 if( inlen > left.bv_len ) {
1133 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1134 sub->sa_initial->bv_len );
1140 left.bv_val += sub->sa_initial->bv_len;
1141 left.bv_len -= sub->sa_initial->bv_len;
1142 inlen -= sub->sa_initial->bv_len;
1145 if( sub->sa_final ) {
1146 if( inlen > left.bv_len ) {
1151 match = strncasecmp( sub->sa_final->bv_val,
1152 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1153 sub->sa_final->bv_len );
1159 left.bv_len -= sub->sa_final->bv_len;
1160 inlen -= sub->sa_final->bv_len;
1164 for(i=0; sub->sa_any[i]; i++) {
1169 if( inlen > left.bv_len ) {
1170 /* not enough length */
1175 if( sub->sa_any[i]->bv_len == 0 ) {
1179 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1186 idx = p - left.bv_val;
1187 assert( idx < left.bv_len );
1189 if( idx >= left.bv_len ) {
1190 /* this shouldn't happen */
1197 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1198 /* not enough left */
1203 match = strncasecmp( left.bv_val,
1204 sub->sa_any[i]->bv_val,
1205 sub->sa_any[i]->bv_len );
1214 left.bv_val += sub->sa_any[i]->bv_len;
1215 left.bv_len -= sub->sa_any[i]->bv_len;
1216 inlen -= sub->sa_any[i]->bv_len;
1222 return LDAP_SUCCESS;
1225 /* Index generation function */
1226 int caseIgnoreIndexer(
1231 struct berval *prefix,
1232 struct berval **values,
1233 struct berval ***keysp )
1237 struct berval **keys;
1238 lutil_MD5_CTX MD5context;
1239 unsigned char MD5digest[16];
1240 struct berval digest;
1241 digest.bv_val = MD5digest;
1242 digest.bv_len = sizeof(MD5digest);
1244 for( i=0; values[i] != NULL; i++ ) {
1245 /* just count them */
1250 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1252 slen = strlen( syntax->ssyn_oid );
1253 mlen = strlen( mr->smr_oid );
1255 for( i=0; values[i] != NULL; i++ ) {
1256 struct berval *value = ber_bvdup( values[i] );
1257 ldap_pvt_str2upper( value->bv_val );
1259 lutil_MD5Init( &MD5context );
1260 if( prefix != NULL && prefix->bv_len > 0 ) {
1261 lutil_MD5Update( &MD5context,
1262 prefix->bv_val, prefix->bv_len );
1264 lutil_MD5Update( &MD5context,
1265 syntax->ssyn_oid, slen );
1266 lutil_MD5Update( &MD5context,
1267 mr->smr_oid, mlen );
1268 lutil_MD5Update( &MD5context,
1269 value->bv_val, value->bv_len );
1270 lutil_MD5Final( MD5digest, &MD5context );
1272 ber_bvfree( value );
1274 keys[i] = ber_bvdup( &digest );
1279 return LDAP_SUCCESS;
1282 /* Index generation function */
1283 int caseIgnoreFilter(
1288 struct berval *prefix,
1290 struct berval ***keysp )
1293 struct berval **keys;
1294 lutil_MD5_CTX MD5context;
1295 unsigned char MD5digest[LUTIL_MD5_BYTES];
1296 struct berval *value;
1297 struct berval digest;
1298 digest.bv_val = MD5digest;
1299 digest.bv_len = sizeof(MD5digest);
1301 slen = strlen( syntax->ssyn_oid );
1302 mlen = strlen( mr->smr_oid );
1304 value = ber_bvdup( (struct berval *) assertValue );
1305 ldap_pvt_str2upper( value->bv_val );
1307 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1309 lutil_MD5Init( &MD5context );
1310 if( prefix != NULL && prefix->bv_len > 0 ) {
1311 lutil_MD5Update( &MD5context,
1312 prefix->bv_val, prefix->bv_len );
1314 lutil_MD5Update( &MD5context,
1315 syntax->ssyn_oid, slen );
1316 lutil_MD5Update( &MD5context,
1317 mr->smr_oid, mlen );
1318 lutil_MD5Update( &MD5context,
1319 value->bv_val, value->bv_len );
1320 lutil_MD5Final( MD5digest, &MD5context );
1322 keys[0] = ber_bvdup( &digest );
1325 ber_bvfree( value );
1329 return LDAP_SUCCESS;
1332 /* Substrings Index generation function */
1333 int caseIgnoreSubstringsIndexer(
1338 struct berval *prefix,
1339 struct berval **values,
1340 struct berval ***keysp )
1344 struct berval **keys;
1345 lutil_MD5_CTX MD5context;
1346 unsigned char MD5digest[16];
1347 struct berval digest;
1348 digest.bv_val = MD5digest;
1349 digest.bv_len = sizeof(MD5digest);
1352 for( i=0; values[i] != NULL; i++ ) {
1353 /* count number of indices to generate */
1354 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1358 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1359 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1360 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1361 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1363 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1367 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1368 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1369 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1373 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1374 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1375 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1376 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1378 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1385 /* no keys to generate */
1387 return LDAP_SUCCESS;
1390 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1392 slen = strlen( syntax->ssyn_oid );
1393 mlen = strlen( mr->smr_oid );
1396 for( i=0; values[i] != NULL; i++ ) {
1398 struct berval *value;
1400 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1402 value = ber_bvdup( values[i] );
1403 ldap_pvt_str2upper( value->bv_val );
1405 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1406 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1408 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1409 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1411 for( j=0; j<max; j++ ) {
1412 lutil_MD5Init( &MD5context );
1413 if( prefix != NULL && prefix->bv_len > 0 ) {
1414 lutil_MD5Update( &MD5context,
1415 prefix->bv_val, prefix->bv_len );
1418 lutil_MD5Update( &MD5context,
1419 &pre, sizeof( pre ) );
1420 lutil_MD5Update( &MD5context,
1421 syntax->ssyn_oid, slen );
1422 lutil_MD5Update( &MD5context,
1423 mr->smr_oid, mlen );
1424 lutil_MD5Update( &MD5context,
1426 SLAP_INDEX_SUBSTR_MAXLEN );
1427 lutil_MD5Final( MD5digest, &MD5context );
1429 keys[nkeys++] = ber_bvdup( &digest );
1433 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1434 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1436 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1439 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1440 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1441 lutil_MD5Init( &MD5context );
1442 if( prefix != NULL && prefix->bv_len > 0 ) {
1443 lutil_MD5Update( &MD5context,
1444 prefix->bv_val, prefix->bv_len );
1446 lutil_MD5Update( &MD5context,
1447 &pre, sizeof( pre ) );
1448 lutil_MD5Update( &MD5context,
1449 syntax->ssyn_oid, slen );
1450 lutil_MD5Update( &MD5context,
1451 mr->smr_oid, mlen );
1452 lutil_MD5Update( &MD5context,
1454 lutil_MD5Final( MD5digest, &MD5context );
1456 keys[nkeys++] = ber_bvdup( &digest );
1459 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1460 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1461 lutil_MD5Init( &MD5context );
1462 if( prefix != NULL && prefix->bv_len > 0 ) {
1463 lutil_MD5Update( &MD5context,
1464 prefix->bv_val, prefix->bv_len );
1466 lutil_MD5Update( &MD5context,
1467 &pre, sizeof( pre ) );
1468 lutil_MD5Update( &MD5context,
1469 syntax->ssyn_oid, slen );
1470 lutil_MD5Update( &MD5context,
1471 mr->smr_oid, mlen );
1472 lutil_MD5Update( &MD5context,
1473 &value->bv_val[value->bv_len-j], j );
1474 lutil_MD5Final( MD5digest, &MD5context );
1476 keys[nkeys++] = ber_bvdup( &digest );
1481 ber_bvfree( value );
1492 return LDAP_SUCCESS;
1495 int caseIgnoreSubstringsFilter(
1500 struct berval *prefix,
1502 struct berval ***keysp )
1504 SubstringsAssertion *sa = assertValue;
1506 ber_len_t nkeys = 0;
1507 size_t slen, mlen, klen;
1508 struct berval **keys;
1509 lutil_MD5_CTX MD5context;
1510 unsigned char MD5digest[LUTIL_MD5_BYTES];
1511 struct berval *value;
1512 struct berval digest;
1514 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1515 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1520 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1522 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1523 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1524 /* don't bother accounting for stepping */
1525 nkeys += sa->sa_any[i]->bv_len -
1526 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1531 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1532 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1539 return LDAP_SUCCESS;
1542 digest.bv_val = MD5digest;
1543 digest.bv_len = sizeof(MD5digest);
1545 slen = strlen( syntax->ssyn_oid );
1546 mlen = strlen( mr->smr_oid );
1548 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1551 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1552 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1554 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1555 value = ber_bvdup( sa->sa_initial );
1556 ldap_pvt_str2upper( value->bv_val );
1558 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1559 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1561 lutil_MD5Init( &MD5context );
1562 if( prefix != NULL && prefix->bv_len > 0 ) {
1563 lutil_MD5Update( &MD5context,
1564 prefix->bv_val, prefix->bv_len );
1566 lutil_MD5Update( &MD5context,
1567 &pre, sizeof( pre ) );
1568 lutil_MD5Update( &MD5context,
1569 syntax->ssyn_oid, slen );
1570 lutil_MD5Update( &MD5context,
1571 mr->smr_oid, mlen );
1572 lutil_MD5Update( &MD5context,
1573 value->bv_val, klen );
1574 lutil_MD5Final( MD5digest, &MD5context );
1576 ber_bvfree( value );
1577 keys[nkeys++] = ber_bvdup( &digest );
1580 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1582 pre = SLAP_INDEX_SUBSTR_PREFIX;
1583 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1585 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1586 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1590 value = ber_bvdup( sa->sa_any[i] );
1591 ldap_pvt_str2upper( value->bv_val );
1594 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1595 j += SLAP_INDEX_SUBSTR_STEP )
1597 lutil_MD5Init( &MD5context );
1598 if( prefix != NULL && prefix->bv_len > 0 ) {
1599 lutil_MD5Update( &MD5context,
1600 prefix->bv_val, prefix->bv_len );
1602 lutil_MD5Update( &MD5context,
1603 &pre, sizeof( pre ) );
1604 lutil_MD5Update( &MD5context,
1605 syntax->ssyn_oid, slen );
1606 lutil_MD5Update( &MD5context,
1607 mr->smr_oid, mlen );
1608 lutil_MD5Update( &MD5context,
1609 &value->bv_val[j], klen );
1610 lutil_MD5Final( MD5digest, &MD5context );
1612 keys[nkeys++] = ber_bvdup( &digest );
1615 ber_bvfree( value );
1619 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1620 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1622 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1623 value = ber_bvdup( sa->sa_final );
1624 ldap_pvt_str2upper( value->bv_val );
1626 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1627 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1629 lutil_MD5Init( &MD5context );
1630 if( prefix != NULL && prefix->bv_len > 0 ) {
1631 lutil_MD5Update( &MD5context,
1632 prefix->bv_val, prefix->bv_len );
1634 lutil_MD5Update( &MD5context,
1635 &pre, sizeof( pre ) );
1636 lutil_MD5Update( &MD5context,
1637 syntax->ssyn_oid, slen );
1638 lutil_MD5Update( &MD5context,
1639 mr->smr_oid, mlen );
1640 lutil_MD5Update( &MD5context,
1641 &value->bv_val[value->bv_len-klen], klen );
1642 lutil_MD5Final( MD5digest, &MD5context );
1644 ber_bvfree( value );
1645 keys[nkeys++] = ber_bvdup( &digest );
1656 return LDAP_SUCCESS;
1662 struct berval *val )
1666 if( val->bv_len == 0 ) return 0;
1668 if( OID_LEADCHAR(val->bv_val[0]) ) {
1670 for(i=1; i < val->bv_len; i++) {
1671 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1672 if( dot++ ) return 1;
1673 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1676 return LDAP_INVALID_SYNTAX;
1680 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1682 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1683 for(i=1; i < val->bv_len; i++) {
1684 if( !DESC_CHAR(val->bv_val[i] ) ) {
1685 return LDAP_INVALID_SYNTAX;
1689 return LDAP_SUCCESS;
1692 return LDAP_INVALID_SYNTAX;
1698 struct berval *val )
1702 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1704 for(i=0; i < val->bv_len; i++) {
1705 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1708 return LDAP_SUCCESS;
1712 printableStringValidate(
1714 struct berval *val )
1718 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1720 for(i=0; i < val->bv_len; i++) {
1721 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1724 return LDAP_SUCCESS;
1730 struct berval *val )
1734 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1736 for(i=0; i < val->bv_len; i++) {
1737 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1740 return LDAP_SUCCESS;
1747 struct berval **out )
1750 ber_len_t i, len = in->bv_len;
1751 struct berval *bv = ch_malloc( sizeof(struct berval) );
1753 bv->bv_len = len * sizeof( ldap_unicode_t );
1754 u = (ldap_unicode_t *) ch_malloc( bv->bv_len + sizeof(ldap_unicode_t) );
1755 bv->bv_val = (char *) u;
1757 for(i=0; i < len; i++ ) {
1759 * IA5StringValidate should have been called to ensure
1760 * input is limited to IA5.
1762 u[i] = in->bv_val[i];
1767 return LDAP_SUCCESS;
1774 struct berval **normalized )
1776 struct berval *newval;
1779 newval = ch_malloc( sizeof( struct berval ) );
1783 /* Ignore initial whitespace */
1784 while ( ASCII_SPACE( *p ) ) {
1790 return LDAP_INVALID_SYNTAX;
1793 newval->bv_val = ch_strdup( p );
1794 p = q = newval->bv_val;
1797 if ( ASCII_SPACE( *p ) ) {
1800 /* Ignore the extra whitespace */
1801 while ( ASCII_SPACE( *p ) ) {
1809 assert( *newval->bv_val );
1810 assert( newval->bv_val < p );
1813 /* cannot start with a space */
1814 assert( !ASCII_SPACE(*newval->bv_val) );
1817 * If the string ended in space, backup the pointer one
1818 * position. One is enough because the above loop collapsed
1819 * all whitespace to a single space.
1822 if ( ASCII_SPACE( q[-1] ) ) {
1826 /* cannot end with a space */
1827 assert( !ASCII_SPACE( q[-1] ) );
1829 /* null terminate */
1832 newval->bv_len = q - newval->bv_val;
1833 *normalized = newval;
1835 return LDAP_SUCCESS;
1844 struct berval *value,
1845 void *assertedValue )
1847 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1850 match = strncmp( value->bv_val,
1851 ((struct berval *) assertedValue)->bv_val,
1856 return LDAP_SUCCESS;
1860 caseExactIA5SubstringsMatch(
1865 struct berval *value,
1866 void *assertedValue )
1869 SubstringsAssertion *sub = assertedValue;
1870 struct berval left = *value;
1874 /* Add up asserted input length */
1875 if( sub->sa_initial ) {
1876 inlen += sub->sa_initial->bv_len;
1879 for(i=0; sub->sa_any[i] != NULL; i++) {
1880 inlen += sub->sa_any[i]->bv_len;
1883 if( sub->sa_final ) {
1884 inlen += sub->sa_final->bv_len;
1887 if( sub->sa_initial ) {
1888 if( inlen > left.bv_len ) {
1893 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1894 sub->sa_initial->bv_len );
1900 left.bv_val += sub->sa_initial->bv_len;
1901 left.bv_len -= sub->sa_initial->bv_len;
1902 inlen -= sub->sa_initial->bv_len;
1905 if( sub->sa_final ) {
1906 if( inlen > left.bv_len ) {
1911 match = strncmp( sub->sa_final->bv_val,
1912 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1913 sub->sa_final->bv_len );
1919 left.bv_len -= sub->sa_final->bv_len;
1920 inlen -= sub->sa_final->bv_len;
1924 for(i=0; sub->sa_any[i]; i++) {
1929 if( inlen > left.bv_len ) {
1930 /* not enough length */
1935 if( sub->sa_any[i]->bv_len == 0 ) {
1939 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1946 idx = p - left.bv_val;
1947 assert( idx < left.bv_len );
1949 if( idx >= left.bv_len ) {
1950 /* this shouldn't happen */
1957 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1958 /* not enough left */
1963 match = strncmp( left.bv_val,
1964 sub->sa_any[i]->bv_val,
1965 sub->sa_any[i]->bv_len );
1973 left.bv_val += sub->sa_any[i]->bv_len;
1974 left.bv_len -= sub->sa_any[i]->bv_len;
1975 inlen -= sub->sa_any[i]->bv_len;
1981 return LDAP_SUCCESS;
1984 /* Index generation function */
1985 int caseExactIA5Indexer(
1990 struct berval *prefix,
1991 struct berval **values,
1992 struct berval ***keysp )
1996 struct berval **keys;
1997 lutil_MD5_CTX MD5context;
1998 unsigned char MD5digest[16];
1999 struct berval digest;
2000 digest.bv_val = MD5digest;
2001 digest.bv_len = sizeof(MD5digest);
2003 for( i=0; values[i] != NULL; i++ ) {
2004 /* just count them */
2009 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2011 slen = strlen( syntax->ssyn_oid );
2012 mlen = strlen( mr->smr_oid );
2014 for( i=0; values[i] != NULL; i++ ) {
2015 struct berval *value = values[i];
2017 lutil_MD5Init( &MD5context );
2018 if( prefix != NULL && prefix->bv_len > 0 ) {
2019 lutil_MD5Update( &MD5context,
2020 prefix->bv_val, prefix->bv_len );
2022 lutil_MD5Update( &MD5context,
2023 syntax->ssyn_oid, slen );
2024 lutil_MD5Update( &MD5context,
2025 mr->smr_oid, mlen );
2026 lutil_MD5Update( &MD5context,
2027 value->bv_val, value->bv_len );
2028 lutil_MD5Final( MD5digest, &MD5context );
2030 keys[i] = ber_bvdup( &digest );
2035 return LDAP_SUCCESS;
2038 /* Index generation function */
2039 int caseExactIA5Filter(
2044 struct berval *prefix,
2046 struct berval ***keysp )
2049 struct berval **keys;
2050 lutil_MD5_CTX MD5context;
2051 unsigned char MD5digest[LUTIL_MD5_BYTES];
2052 struct berval *value;
2053 struct berval digest;
2054 digest.bv_val = MD5digest;
2055 digest.bv_len = sizeof(MD5digest);
2057 slen = strlen( syntax->ssyn_oid );
2058 mlen = strlen( mr->smr_oid );
2060 value = (struct berval *) assertValue;
2062 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2064 lutil_MD5Init( &MD5context );
2065 if( prefix != NULL && prefix->bv_len > 0 ) {
2066 lutil_MD5Update( &MD5context,
2067 prefix->bv_val, prefix->bv_len );
2069 lutil_MD5Update( &MD5context,
2070 syntax->ssyn_oid, slen );
2071 lutil_MD5Update( &MD5context,
2072 mr->smr_oid, mlen );
2073 lutil_MD5Update( &MD5context,
2074 value->bv_val, value->bv_len );
2075 lutil_MD5Final( MD5digest, &MD5context );
2077 keys[0] = ber_bvdup( &digest );
2081 return LDAP_SUCCESS;
2084 /* Substrings Index generation function */
2085 int caseExactIA5SubstringsIndexer(
2090 struct berval *prefix,
2091 struct berval **values,
2092 struct berval ***keysp )
2096 struct berval **keys;
2097 lutil_MD5_CTX MD5context;
2098 unsigned char MD5digest[16];
2099 struct berval digest;
2100 digest.bv_val = MD5digest;
2101 digest.bv_len = sizeof(MD5digest);
2104 for( i=0; values[i] != NULL; i++ ) {
2105 /* count number of indices to generate */
2106 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2110 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2111 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2112 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2113 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2115 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2119 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2120 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2121 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2125 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2126 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2127 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2128 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2130 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2137 /* no keys to generate */
2139 return LDAP_SUCCESS;
2142 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2144 slen = strlen( syntax->ssyn_oid );
2145 mlen = strlen( mr->smr_oid );
2148 for( i=0; values[i] != NULL; i++ ) {
2150 struct berval *value;
2153 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2155 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2156 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2158 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2159 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2161 for( j=0; j<max; j++ ) {
2162 lutil_MD5Init( &MD5context );
2163 if( prefix != NULL && prefix->bv_len > 0 ) {
2164 lutil_MD5Update( &MD5context,
2165 prefix->bv_val, prefix->bv_len );
2168 lutil_MD5Update( &MD5context,
2169 &pre, sizeof( pre ) );
2170 lutil_MD5Update( &MD5context,
2171 syntax->ssyn_oid, slen );
2172 lutil_MD5Update( &MD5context,
2173 mr->smr_oid, mlen );
2174 lutil_MD5Update( &MD5context,
2176 SLAP_INDEX_SUBSTR_MAXLEN );
2177 lutil_MD5Final( MD5digest, &MD5context );
2179 keys[nkeys++] = ber_bvdup( &digest );
2183 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2184 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2186 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2189 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2190 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2191 lutil_MD5Init( &MD5context );
2192 if( prefix != NULL && prefix->bv_len > 0 ) {
2193 lutil_MD5Update( &MD5context,
2194 prefix->bv_val, prefix->bv_len );
2196 lutil_MD5Update( &MD5context,
2197 &pre, sizeof( pre ) );
2198 lutil_MD5Update( &MD5context,
2199 syntax->ssyn_oid, slen );
2200 lutil_MD5Update( &MD5context,
2201 mr->smr_oid, mlen );
2202 lutil_MD5Update( &MD5context,
2204 lutil_MD5Final( MD5digest, &MD5context );
2206 keys[nkeys++] = ber_bvdup( &digest );
2209 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2210 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2211 lutil_MD5Init( &MD5context );
2212 if( prefix != NULL && prefix->bv_len > 0 ) {
2213 lutil_MD5Update( &MD5context,
2214 prefix->bv_val, prefix->bv_len );
2216 lutil_MD5Update( &MD5context,
2217 &pre, sizeof( pre ) );
2218 lutil_MD5Update( &MD5context,
2219 syntax->ssyn_oid, slen );
2220 lutil_MD5Update( &MD5context,
2221 mr->smr_oid, mlen );
2222 lutil_MD5Update( &MD5context,
2223 &value->bv_val[value->bv_len-j], j );
2224 lutil_MD5Final( MD5digest, &MD5context );
2226 keys[nkeys++] = ber_bvdup( &digest );
2240 return LDAP_SUCCESS;
2243 int caseExactIA5SubstringsFilter(
2248 struct berval *prefix,
2250 struct berval ***keysp )
2252 SubstringsAssertion *sa = assertValue;
2254 ber_len_t nkeys = 0;
2255 size_t slen, mlen, klen;
2256 struct berval **keys;
2257 lutil_MD5_CTX MD5context;
2258 unsigned char MD5digest[LUTIL_MD5_BYTES];
2259 struct berval *value;
2260 struct berval digest;
2262 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2263 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2268 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2270 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2271 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2272 /* don't bother accounting for stepping */
2273 nkeys += sa->sa_any[i]->bv_len -
2274 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2279 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2280 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2287 return LDAP_SUCCESS;
2290 digest.bv_val = MD5digest;
2291 digest.bv_len = sizeof(MD5digest);
2293 slen = strlen( syntax->ssyn_oid );
2294 mlen = strlen( mr->smr_oid );
2296 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2299 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2300 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2302 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2303 value = sa->sa_initial;
2305 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2306 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2308 lutil_MD5Init( &MD5context );
2309 if( prefix != NULL && prefix->bv_len > 0 ) {
2310 lutil_MD5Update( &MD5context,
2311 prefix->bv_val, prefix->bv_len );
2313 lutil_MD5Update( &MD5context,
2314 &pre, sizeof( pre ) );
2315 lutil_MD5Update( &MD5context,
2316 syntax->ssyn_oid, slen );
2317 lutil_MD5Update( &MD5context,
2318 mr->smr_oid, mlen );
2319 lutil_MD5Update( &MD5context,
2320 value->bv_val, klen );
2321 lutil_MD5Final( MD5digest, &MD5context );
2323 keys[nkeys++] = ber_bvdup( &digest );
2326 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2328 pre = SLAP_INDEX_SUBSTR_PREFIX;
2329 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2331 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2332 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2336 value = sa->sa_any[i];
2339 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2340 j += SLAP_INDEX_SUBSTR_STEP )
2342 lutil_MD5Init( &MD5context );
2343 if( prefix != NULL && prefix->bv_len > 0 ) {
2344 lutil_MD5Update( &MD5context,
2345 prefix->bv_val, prefix->bv_len );
2347 lutil_MD5Update( &MD5context,
2348 &pre, sizeof( pre ) );
2349 lutil_MD5Update( &MD5context,
2350 syntax->ssyn_oid, slen );
2351 lutil_MD5Update( &MD5context,
2352 mr->smr_oid, mlen );
2353 lutil_MD5Update( &MD5context,
2354 &value->bv_val[j], klen );
2355 lutil_MD5Final( MD5digest, &MD5context );
2357 keys[nkeys++] = ber_bvdup( &digest );
2362 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2363 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2365 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2366 value = sa->sa_final;
2368 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2369 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2371 lutil_MD5Init( &MD5context );
2372 if( prefix != NULL && prefix->bv_len > 0 ) {
2373 lutil_MD5Update( &MD5context,
2374 prefix->bv_val, prefix->bv_len );
2376 lutil_MD5Update( &MD5context,
2377 &pre, sizeof( pre ) );
2378 lutil_MD5Update( &MD5context,
2379 syntax->ssyn_oid, slen );
2380 lutil_MD5Update( &MD5context,
2381 mr->smr_oid, mlen );
2382 lutil_MD5Update( &MD5context,
2383 &value->bv_val[value->bv_len-klen], klen );
2384 lutil_MD5Final( MD5digest, &MD5context );
2386 keys[nkeys++] = ber_bvdup( &digest );
2397 return LDAP_SUCCESS;
2406 struct berval *value,
2407 void *assertedValue )
2409 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2412 match = strncasecmp( value->bv_val,
2413 ((struct berval *) assertedValue)->bv_val,
2418 return LDAP_SUCCESS;
2422 caseIgnoreIA5SubstringsMatch(
2427 struct berval *value,
2428 void *assertedValue )
2431 SubstringsAssertion *sub = assertedValue;
2432 struct berval left = *value;
2436 /* Add up asserted input length */
2437 if( sub->sa_initial ) {
2438 inlen += sub->sa_initial->bv_len;
2441 for(i=0; sub->sa_any[i] != NULL; i++) {
2442 inlen += sub->sa_any[i]->bv_len;
2445 if( sub->sa_final ) {
2446 inlen += sub->sa_final->bv_len;
2449 if( sub->sa_initial ) {
2450 if( inlen > left.bv_len ) {
2455 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2456 sub->sa_initial->bv_len );
2462 left.bv_val += sub->sa_initial->bv_len;
2463 left.bv_len -= sub->sa_initial->bv_len;
2464 inlen -= sub->sa_initial->bv_len;
2467 if( sub->sa_final ) {
2468 if( inlen > left.bv_len ) {
2473 match = strncasecmp( sub->sa_final->bv_val,
2474 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2475 sub->sa_final->bv_len );
2481 left.bv_len -= sub->sa_final->bv_len;
2482 inlen -= sub->sa_final->bv_len;
2486 for(i=0; sub->sa_any[i]; i++) {
2491 if( inlen > left.bv_len ) {
2492 /* not enough length */
2497 if( sub->sa_any[i]->bv_len == 0 ) {
2501 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2508 idx = p - left.bv_val;
2509 assert( idx < left.bv_len );
2511 if( idx >= left.bv_len ) {
2512 /* this shouldn't happen */
2519 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2520 /* not enough left */
2525 match = strncasecmp( left.bv_val,
2526 sub->sa_any[i]->bv_val,
2527 sub->sa_any[i]->bv_len );
2536 left.bv_val += sub->sa_any[i]->bv_len;
2537 left.bv_len -= sub->sa_any[i]->bv_len;
2538 inlen -= sub->sa_any[i]->bv_len;
2544 return LDAP_SUCCESS;
2547 /* Index generation function */
2548 int caseIgnoreIA5Indexer(
2553 struct berval *prefix,
2554 struct berval **values,
2555 struct berval ***keysp )
2559 struct berval **keys;
2560 lutil_MD5_CTX MD5context;
2561 unsigned char MD5digest[16];
2562 struct berval digest;
2563 digest.bv_val = MD5digest;
2564 digest.bv_len = sizeof(MD5digest);
2566 for( i=0; values[i] != NULL; i++ ) {
2567 /* just count them */
2572 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2574 slen = strlen( syntax->ssyn_oid );
2575 mlen = strlen( mr->smr_oid );
2577 for( i=0; values[i] != NULL; i++ ) {
2578 struct berval *value = ber_bvdup( values[i] );
2579 ldap_pvt_str2upper( value->bv_val );
2581 lutil_MD5Init( &MD5context );
2582 if( prefix != NULL && prefix->bv_len > 0 ) {
2583 lutil_MD5Update( &MD5context,
2584 prefix->bv_val, prefix->bv_len );
2586 lutil_MD5Update( &MD5context,
2587 syntax->ssyn_oid, slen );
2588 lutil_MD5Update( &MD5context,
2589 mr->smr_oid, mlen );
2590 lutil_MD5Update( &MD5context,
2591 value->bv_val, value->bv_len );
2592 lutil_MD5Final( MD5digest, &MD5context );
2594 ber_bvfree( value );
2596 keys[i] = ber_bvdup( &digest );
2601 return LDAP_SUCCESS;
2604 /* Index generation function */
2605 int caseIgnoreIA5Filter(
2610 struct berval *prefix,
2612 struct berval ***keysp )
2615 struct berval **keys;
2616 lutil_MD5_CTX MD5context;
2617 unsigned char MD5digest[LUTIL_MD5_BYTES];
2618 struct berval *value;
2619 struct berval digest;
2620 digest.bv_val = MD5digest;
2621 digest.bv_len = sizeof(MD5digest);
2623 slen = strlen( syntax->ssyn_oid );
2624 mlen = strlen( mr->smr_oid );
2626 value = ber_bvdup( (struct berval *) assertValue );
2627 ldap_pvt_str2upper( value->bv_val );
2629 keys = ch_malloc( sizeof( struct berval * ) * 2 );
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 keys[0] = ber_bvdup( &digest );
2647 ber_bvfree( value );
2651 return LDAP_SUCCESS;
2654 /* Substrings Index generation function */
2655 int caseIgnoreIA5SubstringsIndexer(
2660 struct berval *prefix,
2661 struct berval **values,
2662 struct berval ***keysp )
2666 struct berval **keys;
2667 lutil_MD5_CTX MD5context;
2668 unsigned char MD5digest[16];
2669 struct berval digest;
2670 digest.bv_val = MD5digest;
2671 digest.bv_len = sizeof(MD5digest);
2674 for( i=0; values[i] != NULL; i++ ) {
2675 /* count number of indices to generate */
2676 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2680 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2681 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2682 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2683 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2685 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2689 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2690 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2691 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2695 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2696 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2697 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2698 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2700 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2707 /* no keys to generate */
2709 return LDAP_SUCCESS;
2712 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2714 slen = strlen( syntax->ssyn_oid );
2715 mlen = strlen( mr->smr_oid );
2718 for( i=0; values[i] != NULL; i++ ) {
2720 struct berval *value;
2722 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2724 value = ber_bvdup( values[i] );
2725 ldap_pvt_str2upper( value->bv_val );
2727 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2728 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2730 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2731 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2733 for( j=0; j<max; j++ ) {
2734 lutil_MD5Init( &MD5context );
2735 if( prefix != NULL && prefix->bv_len > 0 ) {
2736 lutil_MD5Update( &MD5context,
2737 prefix->bv_val, prefix->bv_len );
2740 lutil_MD5Update( &MD5context,
2741 &pre, sizeof( pre ) );
2742 lutil_MD5Update( &MD5context,
2743 syntax->ssyn_oid, slen );
2744 lutil_MD5Update( &MD5context,
2745 mr->smr_oid, mlen );
2746 lutil_MD5Update( &MD5context,
2748 SLAP_INDEX_SUBSTR_MAXLEN );
2749 lutil_MD5Final( MD5digest, &MD5context );
2751 keys[nkeys++] = ber_bvdup( &digest );
2755 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2756 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2758 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2761 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2762 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2763 lutil_MD5Init( &MD5context );
2764 if( prefix != NULL && prefix->bv_len > 0 ) {
2765 lutil_MD5Update( &MD5context,
2766 prefix->bv_val, prefix->bv_len );
2768 lutil_MD5Update( &MD5context,
2769 &pre, sizeof( pre ) );
2770 lutil_MD5Update( &MD5context,
2771 syntax->ssyn_oid, slen );
2772 lutil_MD5Update( &MD5context,
2773 mr->smr_oid, mlen );
2774 lutil_MD5Update( &MD5context,
2776 lutil_MD5Final( MD5digest, &MD5context );
2778 keys[nkeys++] = ber_bvdup( &digest );
2781 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2782 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2783 lutil_MD5Init( &MD5context );
2784 if( prefix != NULL && prefix->bv_len > 0 ) {
2785 lutil_MD5Update( &MD5context,
2786 prefix->bv_val, prefix->bv_len );
2788 lutil_MD5Update( &MD5context,
2789 &pre, sizeof( pre ) );
2790 lutil_MD5Update( &MD5context,
2791 syntax->ssyn_oid, slen );
2792 lutil_MD5Update( &MD5context,
2793 mr->smr_oid, mlen );
2794 lutil_MD5Update( &MD5context,
2795 &value->bv_val[value->bv_len-j], j );
2796 lutil_MD5Final( MD5digest, &MD5context );
2798 keys[nkeys++] = ber_bvdup( &digest );
2803 ber_bvfree( value );
2814 return LDAP_SUCCESS;
2817 int caseIgnoreIA5SubstringsFilter(
2822 struct berval *prefix,
2824 struct berval ***keysp )
2826 SubstringsAssertion *sa = assertValue;
2828 ber_len_t nkeys = 0;
2829 size_t slen, mlen, klen;
2830 struct berval **keys;
2831 lutil_MD5_CTX MD5context;
2832 unsigned char MD5digest[LUTIL_MD5_BYTES];
2833 struct berval *value;
2834 struct berval digest;
2836 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2837 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2842 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2844 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2845 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2846 /* don't bother accounting for stepping */
2847 nkeys += sa->sa_any[i]->bv_len -
2848 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2853 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2854 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2861 return LDAP_SUCCESS;
2864 digest.bv_val = MD5digest;
2865 digest.bv_len = sizeof(MD5digest);
2867 slen = strlen( syntax->ssyn_oid );
2868 mlen = strlen( mr->smr_oid );
2870 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2873 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2874 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2876 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2877 value = ber_bvdup( sa->sa_initial );
2878 ldap_pvt_str2upper( value->bv_val );
2880 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2881 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2883 lutil_MD5Init( &MD5context );
2884 if( prefix != NULL && prefix->bv_len > 0 ) {
2885 lutil_MD5Update( &MD5context,
2886 prefix->bv_val, prefix->bv_len );
2888 lutil_MD5Update( &MD5context,
2889 &pre, sizeof( pre ) );
2890 lutil_MD5Update( &MD5context,
2891 syntax->ssyn_oid, slen );
2892 lutil_MD5Update( &MD5context,
2893 mr->smr_oid, mlen );
2894 lutil_MD5Update( &MD5context,
2895 value->bv_val, klen );
2896 lutil_MD5Final( MD5digest, &MD5context );
2898 ber_bvfree( value );
2899 keys[nkeys++] = ber_bvdup( &digest );
2902 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2904 pre = SLAP_INDEX_SUBSTR_PREFIX;
2905 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2907 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2908 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2912 value = ber_bvdup( sa->sa_any[i] );
2913 ldap_pvt_str2upper( value->bv_val );
2916 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2917 j += SLAP_INDEX_SUBSTR_STEP )
2919 lutil_MD5Init( &MD5context );
2920 if( prefix != NULL && prefix->bv_len > 0 ) {
2921 lutil_MD5Update( &MD5context,
2922 prefix->bv_val, prefix->bv_len );
2924 lutil_MD5Update( &MD5context,
2925 &pre, sizeof( pre ) );
2926 lutil_MD5Update( &MD5context,
2927 syntax->ssyn_oid, slen );
2928 lutil_MD5Update( &MD5context,
2929 mr->smr_oid, mlen );
2930 lutil_MD5Update( &MD5context,
2931 &value->bv_val[j], klen );
2932 lutil_MD5Final( MD5digest, &MD5context );
2934 keys[nkeys++] = ber_bvdup( &digest );
2937 ber_bvfree( value );
2941 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2942 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2944 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2945 value = ber_bvdup( sa->sa_final );
2946 ldap_pvt_str2upper( value->bv_val );
2948 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2949 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2951 lutil_MD5Init( &MD5context );
2952 if( prefix != NULL && prefix->bv_len > 0 ) {
2953 lutil_MD5Update( &MD5context,
2954 prefix->bv_val, prefix->bv_len );
2956 lutil_MD5Update( &MD5context,
2957 &pre, sizeof( pre ) );
2958 lutil_MD5Update( &MD5context,
2959 syntax->ssyn_oid, slen );
2960 lutil_MD5Update( &MD5context,
2961 mr->smr_oid, mlen );
2962 lutil_MD5Update( &MD5context,
2963 &value->bv_val[value->bv_len-klen], klen );
2964 lutil_MD5Final( MD5digest, &MD5context );
2966 ber_bvfree( value );
2967 keys[nkeys++] = ber_bvdup( &digest );
2978 return LDAP_SUCCESS;
2982 numericStringNormalize(
2985 struct berval **normalized )
2987 /* similiar to IA5StringNormalize except removes all spaces */
2988 struct berval *newval;
2991 newval = ch_malloc( sizeof( struct berval ) );
2995 /* Ignore initial whitespace */
2996 while ( ASCII_SPACE( *p ) ) {
3002 return LDAP_INVALID_SYNTAX;
3005 newval->bv_val = ch_strdup( p );
3006 p = q = newval->bv_val;
3009 if ( ASCII_SPACE( *p ) ) {
3010 /* Ignore whitespace */
3017 assert( *newval->bv_val );
3018 assert( newval->bv_val < p );
3021 /* cannot start with a space */
3022 assert( !ASCII_SPACE(*newval->bv_val) );
3024 /* cannot end with a space */
3025 assert( !ASCII_SPACE( q[-1] ) );
3027 /* null terminate */
3030 newval->bv_len = q - newval->bv_val;
3031 *normalized = newval;
3033 return LDAP_SUCCESS;
3037 objectIdentifierFirstComponentMatch(
3042 struct berval *value,
3043 void *assertedValue )
3045 int rc = LDAP_SUCCESS;
3047 struct berval *asserted = (struct berval *) assertedValue;
3051 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3052 return LDAP_INVALID_SYNTAX;
3055 /* trim leading white space */
3056 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3060 /* grab next word */
3061 oid.bv_val = &value->bv_val[i];
3062 oid.bv_len = value->bv_len - i;
3063 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3068 /* insert attributeTypes, objectclass check here */
3069 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3070 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3073 char *stored = ch_malloc( oid.bv_len + 1 );
3074 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3075 stored[oid.bv_len] = '\0';
3077 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3078 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3079 MatchingRule *stored_mr = mr_find( stored );
3081 if( asserted_mr == NULL ) {
3082 rc = SLAPD_COMPARE_UNDEFINED;
3084 match = asserted_mr != stored_mr;
3087 } else if ( !strcmp( syntax->ssyn_oid,
3088 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3090 AttributeType *asserted_at = at_find( asserted->bv_val );
3091 AttributeType *stored_at = at_find( stored );
3093 if( asserted_at == NULL ) {
3094 rc = SLAPD_COMPARE_UNDEFINED;
3096 match = asserted_at != stored_at;
3099 } else if ( !strcmp( syntax->ssyn_oid,
3100 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3102 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3103 ObjectClass *stored_oc = oc_find( stored );
3105 if( asserted_oc == NULL ) {
3106 rc = SLAPD_COMPARE_UNDEFINED;
3108 match = asserted_oc != stored_oc;
3115 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3116 "%d\n\t\"%s\"\n\t\"%s\"\n",
3117 match, value->bv_val, asserted->bv_val );
3119 if( rc == LDAP_SUCCESS ) *matchp = match;
3124 check_time_syntax (struct berval *val,
3128 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3129 static int mdays[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
3131 int part, c, neg = 0;
3133 if( val->bv_len == 0 )
3134 return LDAP_INVALID_SYNTAX;
3136 p = (char *)val->bv_val;
3137 e = p + val->bv_len;
3139 /* Ignore initial whitespace */
3140 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3144 if (e - p < 13 - (2 * start))
3145 return LDAP_INVALID_SYNTAX;
3147 for (part = 0; part < 9; part++)
3150 for (part = start; part < 7; part++) {
3163 return LDAP_INVALID_SYNTAX;
3165 return LDAP_INVALID_SYNTAX;
3170 return LDAP_INVALID_SYNTAX;
3172 return LDAP_INVALID_SYNTAX;
3176 if (part == 2 || part == 3)
3178 if (parts[part] < 0)
3179 return LDAP_INVALID_SYNTAX;
3180 if (parts[part] > ceiling[part])
3181 return LDAP_INVALID_SYNTAX;
3183 if (parts[2] == 1) {
3184 if (parts[3] > mdays[parts[2]])
3185 return LDAP_INVALID_SYNTAX;
3186 if (parts[1] & 0x03) {
3187 /* FIXME: This is an incomplete leap-year
3188 * check that fails in 2100, 2200, 2300,
3189 * 2500, 2600, 2700, ...
3191 if (parts[3] > mdays[parts[2]] - 1)
3192 return LDAP_INVALID_SYNTAX;
3198 } else if (c != '+' && c != '-') {
3199 return LDAP_INVALID_SYNTAX;
3204 return LDAP_INVALID_SYNTAX;
3205 for (part = 7; part < 9; part++) {
3208 return LDAP_INVALID_SYNTAX;
3213 return LDAP_INVALID_SYNTAX;
3216 if (parts[part] < 0 || parts[part] > ceiling[part])
3217 return LDAP_INVALID_SYNTAX;
3221 /* Ignore trailing whitespace */
3222 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3226 return LDAP_INVALID_SYNTAX;
3229 parts[4] += parts[7];
3230 parts[5] += parts[8];
3231 for (part = 7; --part > 0; ) {
3235 /* FIXME: This is an incomplete leap-year
3236 * check that fails in 2100, 2200, 2300,
3237 * 2500, 2600, 2700, ...
3239 c = mdays[parts[2]];
3243 if (parts[part] > c) {
3244 parts[part] -= c + 1;
3249 parts[4] -= parts[7];
3250 parts[5] -= parts[8];
3251 for (part = 7; --part > 0; ) {
3255 /* FIXME: This is an incomplete leap-year
3256 * check that fails in 2100, 2200, 2300,
3257 * 2500, 2600, 2700, ...
3259 c = mdays[(parts[2] - 1) % 12];
3263 if (parts[part] < 0) {
3264 parts[part] += c + 1;
3270 return LDAP_SUCCESS;
3277 struct berval **normalized )
3282 rc = check_time_syntax(val, 1, parts);
3283 if (rc != LDAP_SUCCESS) {
3288 out = ch_malloc( sizeof(struct berval) );
3290 return LBER_ERROR_MEMORY;
3292 out->bv_val = ch_malloc( 14 );
3293 if ( out->bv_val == NULL ) {
3295 return LBER_ERROR_MEMORY;
3298 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3299 parts[1], parts[2] + 1, parts[3] + 1,
3300 parts[4], parts[5], parts[6] );
3304 return LDAP_SUCCESS;
3314 return check_time_syntax(in, 1, parts);
3318 generalizedTimeValidate(
3324 return check_time_syntax(in, 0, parts);
3328 generalizedTimeNormalize(
3331 struct berval **normalized )
3336 rc = check_time_syntax(val, 0, parts);
3337 if (rc != LDAP_SUCCESS) {
3342 out = ch_malloc( sizeof(struct berval) );
3344 return LBER_ERROR_MEMORY;
3346 out->bv_val = ch_malloc( 16 );
3347 if ( out->bv_val == NULL ) {
3349 return LBER_ERROR_MEMORY;
3352 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3353 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3354 parts[4], parts[5], parts[6] );
3358 return LDAP_SUCCESS;
3362 nisNetgroupTripleValidate(
3364 struct berval *val )
3369 if ( val->bv_len == 0 ) {
3370 return LDAP_INVALID_SYNTAX;
3373 p = (char *)val->bv_val;
3374 e = p + val->bv_len;
3377 /* syntax does not allow leading white space */
3378 /* Ignore initial whitespace */
3379 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3384 if ( *p != '(' /*')'*/ ) {
3385 return LDAP_INVALID_SYNTAX;
3388 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3392 return LDAP_INVALID_SYNTAX;
3395 } else if ( !ATTR_CHAR( *p ) ) {
3396 return LDAP_INVALID_SYNTAX;
3400 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3401 return LDAP_INVALID_SYNTAX;
3407 /* syntax does not allow trailing white space */
3408 /* Ignore trailing whitespace */
3409 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3415 return LDAP_INVALID_SYNTAX;
3418 return LDAP_SUCCESS;
3422 bootParameterValidate(
3424 struct berval *val )
3428 if ( val->bv_len == 0 ) {
3429 return LDAP_INVALID_SYNTAX;
3432 p = (char *)val->bv_val;
3433 e = p + val->bv_len;
3436 for (; ( p < e ) && ( *p != '=' ); p++ ) {
3437 if ( !ATTR_CHAR( *p ) ) {
3438 return LDAP_INVALID_SYNTAX;
3443 return LDAP_INVALID_SYNTAX;
3447 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
3448 if ( !ATTR_CHAR( *p ) ) {
3449 return LDAP_INVALID_SYNTAX;
3454 return LDAP_INVALID_SYNTAX;
3458 for ( p++; p < e; p++ ) {
3459 if ( !ATTR_CHAR( *p ) ) {
3460 return LDAP_INVALID_SYNTAX;
3464 return LDAP_SUCCESS;
3467 struct syntax_defs_rec {
3470 slap_syntax_validate_func *sd_validate;
3471 slap_syntax_transform_func *sd_normalize;
3472 slap_syntax_transform_func *sd_pretty;
3473 #ifdef SLAPD_BINARY_CONVERSION
3474 slap_syntax_transform_func *sd_ber2str;
3475 slap_syntax_transform_func *sd_str2ber;
3479 #define X_HIDE "X-HIDE 'TRUE' "
3480 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
3481 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
3483 struct syntax_defs_rec syntax_defs[] = {
3484 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
3485 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
3486 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
3487 0, NULL, NULL, NULL},
3488 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
3489 0, NULL, NULL, NULL},
3490 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
3491 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3492 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
3493 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3494 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
3495 0, bitStringValidate, bitStringNormalize, NULL },
3496 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
3497 0, booleanValidate, NULL, NULL},
3498 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
3499 X_BINARY X_NOT_H_R ")",
3500 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3501 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
3502 X_BINARY X_NOT_H_R ")",
3503 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3504 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
3505 X_BINARY X_NOT_H_R ")",
3506 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3507 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
3508 0, NULL, NULL, NULL},
3509 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
3510 0, dnValidate, dnNormalize, dnPretty},
3511 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
3512 0, NULL, NULL, NULL},
3513 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
3514 0, NULL, NULL, NULL},
3515 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
3516 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3517 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
3518 0, NULL, NULL, NULL},
3519 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
3520 0, NULL, NULL, NULL},
3521 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
3522 0, NULL, NULL, NULL},
3523 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
3524 0, NULL, NULL, NULL},
3525 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
3526 0, NULL, NULL, NULL},
3527 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
3528 0, IA5StringValidate, faxNumberNormalize, NULL},
3529 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
3530 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
3531 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
3532 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
3533 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
3534 0, NULL, NULL, NULL},
3535 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
3536 0, IA5StringValidate, IA5StringNormalize, NULL},
3537 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
3538 0, integerValidate, integerNormalize, integerPretty},
3539 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
3540 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3541 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
3542 0, NULL, NULL, NULL},
3543 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
3544 0, NULL, NULL, NULL},
3545 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
3546 0, NULL, NULL, NULL},
3547 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
3548 0, NULL, NULL, NULL},
3549 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
3550 0, NULL, NULL, NULL},
3551 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
3552 0, nameUIDValidate, nameUIDNormalize, nameUIDPretty},
3553 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
3554 0, NULL, NULL, NULL},
3555 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
3556 0, IA5StringValidate, numericStringNormalize, NULL},
3557 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
3558 0, NULL, NULL, NULL},
3559 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
3560 0, oidValidate, NULL, NULL},
3561 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
3562 0, NULL, NULL, NULL},
3563 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
3564 0, blobValidate, NULL, NULL},
3565 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
3566 0, blobValidate, NULL, NULL},
3567 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
3568 0, NULL, NULL, NULL},
3569 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
3570 0, NULL, NULL, NULL},
3571 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
3572 0, printableStringValidate, NULL, NULL},
3573 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
3574 X_BINARY X_NOT_H_R ")",
3575 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3576 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
3577 0, IA5StringValidate, phoneNumberNormalize, NULL},
3578 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
3579 0, NULL, NULL, NULL},
3580 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
3581 0, IA5StringValidate, telexNumberNormalize, NULL},
3582 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
3583 0, utcTimeValidate, utcTimeNormalize, NULL},
3584 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
3585 0, NULL, NULL, NULL},
3586 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
3587 0, NULL, NULL, NULL},
3588 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
3589 0, NULL, NULL, NULL},
3590 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
3591 0, NULL, NULL, NULL},
3592 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
3593 0, NULL, NULL, NULL},
3595 /* RFC 2307 NIS Syntaxes */
3596 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Triple' )",
3597 0, nisNetgroupTripleValidate, NULL, NULL},
3598 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
3599 0, bootParameterValidate, NULL, NULL},
3601 /* OpenLDAP Experimental Syntaxes */
3602 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
3603 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
3605 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
3606 0, NULL, NULL, NULL},
3608 /* OpenLDAP Void Syntax */
3609 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' " X_HIDE ")" ,
3610 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
3611 {NULL, 0, NULL, NULL, NULL}
3614 struct mrule_defs_rec {
3616 slap_mask_t mrd_usage;
3617 slap_mr_convert_func * mrd_convert;
3618 slap_mr_normalize_func * mrd_normalize;
3619 slap_mr_match_func * mrd_match;
3620 slap_mr_indexer_func * mrd_indexer;
3621 slap_mr_filter_func * mrd_filter;
3623 char * mrd_associated;
3627 * Other matching rules in X.520 that we do not use (yet):
3629 * 2.5.13.9 numericStringOrderingMatch
3630 * 2.5.13.13 booleanMatch
3631 * 2.5.13.15 integerOrderingMatch
3632 * 2.5.13.18 octetStringOrderingMatch
3633 * 2.5.13.19 octetStringSubstringsMatch
3634 * 2.5.13.25 uTCTimeMatch
3635 * 2.5.13.26 uTCTimeOrderingMatch
3636 * 2.5.13.31 directoryStringFirstComponentMatch
3637 * 2.5.13.32 wordMatch
3638 * 2.5.13.33 keywordMatch
3639 * 2.5.13.34 certificateExactMatch
3640 * 2.5.13.35 certificateMatch
3641 * 2.5.13.36 certificatePairExactMatch
3642 * 2.5.13.37 certificatePairMatch
3643 * 2.5.13.38 certificateListExactMatch
3644 * 2.5.13.39 certificateListMatch
3645 * 2.5.13.40 algorithmIdentifierMatch
3646 * 2.5.13.41 storedPrefixMatch
3647 * 2.5.13.42 attributeCertificateMatch
3648 * 2.5.13.43 readerAndKeyIDMatch
3649 * 2.5.13.44 attributeIntegrityMatch
3652 struct mrule_defs_rec mrule_defs[] = {
3654 * EQUALITY matching rules must be listed after associated APPROX
3655 * matching rules. So, we list all APPROX matching rules first.
3657 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
3658 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3659 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3661 directoryStringApproxMatch, NULL, NULL,
3664 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
3665 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3666 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3668 IA5StringApproxMatch, NULL, NULL,
3672 * Other matching rules
3675 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
3676 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3677 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3679 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
3682 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
3683 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
3684 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3686 dnMatch, dnIndexer, dnFilter,
3689 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
3690 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3691 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3693 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
3694 directoryStringApproxMatchOID },
3696 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
3697 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3700 caseIgnoreOrderingMatch, NULL, NULL,
3703 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
3704 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3705 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3707 caseIgnoreSubstringsMatch,
3708 caseIgnoreSubstringsIndexer,
3709 caseIgnoreSubstringsFilter,
3712 {"( 2.5.13.5 NAME 'caseExactMatch' "
3713 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3714 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3716 caseExactMatch, caseExactIndexer, caseExactFilter,
3717 directoryStringApproxMatchOID },
3719 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
3720 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3723 caseExactOrderingMatch, NULL, NULL,
3726 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
3727 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3728 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3730 caseExactSubstringsMatch,
3731 caseExactSubstringsIndexer,
3732 caseExactSubstringsFilter,
3735 {"( 2.5.13.8 NAME 'numericStringMatch' "
3736 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
3737 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3739 caseIgnoreIA5Match, NULL, NULL,
3742 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
3743 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3744 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3746 caseIgnoreIA5SubstringsMatch,
3747 caseIgnoreIA5SubstringsIndexer,
3748 caseIgnoreIA5SubstringsFilter,
3751 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
3752 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
3753 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3755 caseIgnoreListMatch, NULL, NULL,
3758 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
3759 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3760 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3762 caseIgnoreListSubstringsMatch, NULL, NULL,
3765 {"( 2.5.13.13 NAME 'booleanMatch' "
3766 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
3767 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3769 booleanMatch, NULL, NULL,
3772 {"( 2.5.13.14 NAME 'integerMatch' "
3773 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
3774 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3776 integerMatch, NULL, NULL,
3779 {"( 2.5.13.16 NAME 'bitStringMatch' "
3780 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
3781 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3783 bitStringMatch, NULL, NULL,
3786 {"( 2.5.13.17 NAME 'octetStringMatch' "
3787 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
3788 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3790 octetStringMatch, octetStringIndexer, octetStringFilter,
3793 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
3794 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
3795 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3797 telephoneNumberMatch, NULL, NULL,
3800 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
3801 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3802 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3804 telephoneNumberSubstringsMatch, NULL, NULL,
3807 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
3808 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
3809 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3811 presentationAddressMatch, NULL, NULL,
3814 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
3815 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
3816 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3818 uniqueMemberMatch, NULL, NULL,
3821 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
3822 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
3823 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3825 protocolInformationMatch, NULL, NULL,
3828 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
3829 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
3830 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3832 generalizedTimeMatch, NULL, NULL,
3835 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
3836 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
3839 generalizedTimeOrderingMatch, NULL, NULL,
3842 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
3843 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
3844 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3846 integerFirstComponentMatch, NULL, NULL,
3849 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
3850 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3851 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3853 objectIdentifierFirstComponentMatch, NULL, NULL,
3856 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
3857 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3858 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3860 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
3861 IA5StringApproxMatchOID },
3863 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
3864 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3865 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3867 caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
3868 IA5StringApproxMatchOID },
3870 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
3871 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3874 caseIgnoreIA5SubstringsMatch,
3875 caseIgnoreIA5SubstringsIndexer,
3876 caseIgnoreIA5SubstringsFilter,
3879 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
3880 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3883 caseExactIA5SubstringsMatch,
3884 caseExactIA5SubstringsIndexer,
3885 caseExactIA5SubstringsFilter,
3888 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
3889 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
3892 authPasswordMatch, NULL, NULL,
3895 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
3896 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
3899 OpenLDAPaciMatch, NULL, NULL,
3902 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
3911 /* we should only be called once (from main) */
3912 assert( schema_init_done == 0 );
3914 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
3915 res = register_syntax( syntax_defs[i].sd_desc,
3916 syntax_defs[i].sd_flags,
3917 syntax_defs[i].sd_validate,
3918 syntax_defs[i].sd_normalize,
3919 syntax_defs[i].sd_pretty
3920 #ifdef SLAPD_BINARY_CONVERSION
3922 syntax_defs[i].sd_ber2str,
3923 syntax_defs[i].sd_str2ber
3928 fprintf( stderr, "schema_init: Error registering syntax %s\n",
3929 syntax_defs[i].sd_desc );
3934 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
3935 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
3937 "schema_init: Ingoring unusable matching rule %s\n",
3938 mrule_defs[i].mrd_desc );
3942 res = register_matching_rule(
3943 mrule_defs[i].mrd_desc,
3944 mrule_defs[i].mrd_usage,
3945 mrule_defs[i].mrd_convert,
3946 mrule_defs[i].mrd_normalize,
3947 mrule_defs[i].mrd_match,
3948 mrule_defs[i].mrd_indexer,
3949 mrule_defs[i].mrd_filter,
3950 mrule_defs[i].mrd_associated );
3954 "schema_init: Error registering matching rule %s\n",
3955 mrule_defs[i].mrd_desc );
3959 schema_init_done = 1;
3960 return LDAP_SUCCESS;