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 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
78 static char *strcasechr( const char *str, int c )
80 char *lower = strchr( str, TOLOWER(c) );
81 char *upper = strchr( str, TOUPPER(c) );
83 if( lower && upper ) {
84 return lower < upper ? lower : upper;
101 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
104 match = memcmp( value->bv_val,
105 ((struct berval *) assertedValue)->bv_val,
113 /* Index generation function */
114 int octetStringIndexer(
119 struct berval *prefix,
120 struct berval **values,
121 struct berval ***keysp )
125 struct berval **keys;
126 lutil_MD5_CTX MD5context;
127 unsigned char MD5digest[16];
128 struct berval digest;
129 digest.bv_val = MD5digest;
130 digest.bv_len = sizeof(MD5digest);
132 for( i=0; values[i] != NULL; i++ ) {
133 /* just count them */
138 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
140 slen = strlen( syntax->ssyn_oid );
141 mlen = strlen( mr->smr_oid );
143 for( i=0; values[i] != NULL; i++ ) {
144 lutil_MD5Init( &MD5context );
145 if( prefix != NULL && prefix->bv_len > 0 ) {
146 lutil_MD5Update( &MD5context,
147 prefix->bv_val, prefix->bv_len );
149 lutil_MD5Update( &MD5context,
150 syntax->ssyn_oid, slen );
151 lutil_MD5Update( &MD5context,
153 lutil_MD5Update( &MD5context,
154 values[i]->bv_val, values[i]->bv_len );
155 lutil_MD5Final( MD5digest, &MD5context );
157 keys[i] = ber_bvdup( &digest );
167 /* Index generation function */
168 int octetStringFilter(
173 struct berval *prefix,
175 struct berval ***keysp )
178 struct berval **keys;
179 lutil_MD5_CTX MD5context;
180 unsigned char MD5digest[LUTIL_MD5_BYTES];
181 struct berval *value = (struct berval *) assertValue;
182 struct berval digest;
183 digest.bv_val = MD5digest;
184 digest.bv_len = sizeof(MD5digest);
186 slen = strlen( syntax->ssyn_oid );
187 mlen = strlen( mr->smr_oid );
189 keys = ch_malloc( sizeof( struct berval * ) * 2 );
191 lutil_MD5Init( &MD5context );
192 if( prefix != NULL && prefix->bv_len > 0 ) {
193 lutil_MD5Update( &MD5context,
194 prefix->bv_val, prefix->bv_len );
196 lutil_MD5Update( &MD5context,
197 syntax->ssyn_oid, slen );
198 lutil_MD5Update( &MD5context,
200 lutil_MD5Update( &MD5context,
201 value->bv_val, value->bv_len );
202 lutil_MD5Final( MD5digest, &MD5context );
204 keys[0] = ber_bvdup( &digest );
220 if( in->bv_len == 0 ) return LDAP_SUCCESS;
222 dn = ch_strdup( in->bv_val );
224 rc = dn_validate( dn ) == NULL
225 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
235 struct berval **normalized )
237 struct berval *out = ber_bvdup( val );
239 if( out->bv_len != 0 ) {
241 #ifdef USE_DN_NORMALIZE
242 dn = dn_normalize( out->bv_val );
244 dn = dn_validate( out->bv_val );
249 return LDAP_INVALID_SYNTAX;
253 out->bv_len = strlen( dn );
266 struct berval *value,
267 void *assertedValue )
270 struct berval *asserted = (struct berval *) assertedValue;
272 match = value->bv_len - asserted->bv_len;
275 #ifdef USE_DN_NORMALIZE
276 match = strcmp( value->bv_val, asserted->bv_val );
278 match = strcasecmp( value->bv_val, asserted->bv_val );
282 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
283 match, value->bv_val, asserted->bv_val );
294 /* any value allowed */
303 /* any value allowed */
308 * Handling boolean syntax and matching is quite rigid.
309 * A more flexible approach would be to allow a variety
310 * of strings to be normalized and prettied into TRUE
318 /* very unforgiving validation, requires no normalization
319 * before simplistic matching
322 if( in->bv_len == 4 ) {
323 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
326 } else if( in->bv_len == 5 ) {
327 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
332 return LDAP_INVALID_SYNTAX;
341 struct berval *value,
342 void *assertedValue )
344 /* simplistic matching allowed by rigid validation */
345 struct berval *asserted = (struct berval *) assertedValue;
346 *matchp = value->bv_len != asserted->bv_len;
353 struct berval *right,
354 struct berval *left )
358 ldap_unicode_t ru, lu;
359 ldap_unicode_t ruu, luu;
362 r < right->bv_len && l < left->bv_len;
366 * XXYYZ: we convert to ucs4 even though -llunicode
367 * expects ucs2 in an unsigned long
369 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
370 if( ru == LDAP_UCS4_INVALID ) {
374 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
375 if( lu == LDAP_UCS4_INVALID ) {
379 ruu = uctoupper( ru );
380 luu = uctoupper( lu );
384 } else if( luu > ruu ) {
388 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
389 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
392 if( r < right->bv_len ) {
397 if( l < left->bv_len ) {
413 unsigned char *u = in->bv_val;
415 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
417 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
418 /* get the length indicated by the first byte */
419 len = LDAP_UTF8_CHARLEN( u );
421 /* should not be zero */
422 if( len == 0 ) return LDAP_INVALID_SYNTAX;
424 /* make sure len corresponds with the offset
425 to the next character */
426 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
429 if( count != 0 ) return LDAP_INVALID_SYNTAX;
438 struct berval **normalized )
440 struct berval *newval;
443 newval = ch_malloc( sizeof( struct berval ) );
447 /* Ignore initial whitespace */
448 while ( ldap_utf8_isspace( p ) ) {
454 return LDAP_INVALID_SYNTAX;
457 newval->bv_val = ch_strdup( p );
458 p = q = newval->bv_val;
464 if ( ldap_utf8_isspace( p ) ) {
465 len = LDAP_UTF8_COPY(q,p);
470 /* Ignore the extra whitespace */
471 while ( ldap_utf8_isspace( p ) ) {
475 len = LDAP_UTF8_COPY(q,p);
482 assert( *newval->bv_val );
483 assert( newval->bv_val < p );
486 /* cannot start with a space */
487 assert( !ldap_utf8_isspace(newval->bv_val) );
490 * If the string ended in space, backup the pointer one
491 * position. One is enough because the above loop collapsed
492 * all whitespace to a single space.
499 /* cannot end with a space */
500 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
505 newval->bv_len = q - newval->bv_val;
506 *normalized = newval;
517 struct berval *value,
518 void *assertedValue )
520 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
523 match = strncmp( value->bv_val,
524 ((struct berval *) assertedValue)->bv_val,
533 caseExactSubstringsMatch(
538 struct berval *value,
539 void *assertedValue )
542 SubstringsAssertion *sub = assertedValue;
543 struct berval left = *value;
547 /* Add up asserted input length */
548 if( sub->sa_initial ) {
549 inlen += sub->sa_initial->bv_len;
552 for(i=0; sub->sa_any[i] != NULL; i++) {
553 inlen += sub->sa_any[i]->bv_len;
556 if( sub->sa_final ) {
557 inlen += sub->sa_final->bv_len;
560 if( sub->sa_initial ) {
561 if( inlen > left.bv_len ) {
566 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
567 sub->sa_initial->bv_len );
573 left.bv_val += sub->sa_initial->bv_len;
574 left.bv_len -= sub->sa_initial->bv_len;
575 inlen -= sub->sa_initial->bv_len;
578 if( sub->sa_final ) {
579 if( inlen > left.bv_len ) {
584 match = strncmp( sub->sa_final->bv_val,
585 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
586 sub->sa_final->bv_len );
592 left.bv_len -= sub->sa_final->bv_len;
593 inlen -= sub->sa_final->bv_len;
597 for(i=0; sub->sa_any[i]; i++) {
602 if( inlen > left.bv_len ) {
603 /* not enough length */
608 if( sub->sa_any[i]->bv_len == 0 ) {
612 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
619 idx = p - left.bv_val;
620 assert( idx < left.bv_len );
622 if( idx >= left.bv_len ) {
623 /* this shouldn't happen */
630 if( sub->sa_any[i]->bv_len > left.bv_len ) {
631 /* not enough left */
636 match = strncmp( left.bv_val,
637 sub->sa_any[i]->bv_val,
638 sub->sa_any[i]->bv_len );
646 left.bv_val += sub->sa_any[i]->bv_len;
647 left.bv_len -= sub->sa_any[i]->bv_len;
648 inlen -= sub->sa_any[i]->bv_len;
657 /* Index generation function */
658 int caseExactIndexer(
663 struct berval *prefix,
664 struct berval **values,
665 struct berval ***keysp )
669 struct berval **keys;
670 lutil_MD5_CTX MD5context;
671 unsigned char MD5digest[16];
672 struct berval digest;
673 digest.bv_val = MD5digest;
674 digest.bv_len = sizeof(MD5digest);
676 for( i=0; values[i] != NULL; i++ ) {
677 /* just count them */
682 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
684 slen = strlen( syntax->ssyn_oid );
685 mlen = strlen( mr->smr_oid );
687 for( i=0; values[i] != NULL; i++ ) {
688 struct berval *value = values[i];
690 lutil_MD5Init( &MD5context );
691 if( prefix != NULL && prefix->bv_len > 0 ) {
692 lutil_MD5Update( &MD5context,
693 prefix->bv_val, prefix->bv_len );
695 lutil_MD5Update( &MD5context,
696 syntax->ssyn_oid, slen );
697 lutil_MD5Update( &MD5context,
699 lutil_MD5Update( &MD5context,
700 value->bv_val, value->bv_len );
701 lutil_MD5Final( MD5digest, &MD5context );
703 keys[i] = ber_bvdup( &digest );
711 /* Index generation function */
717 struct berval *prefix,
719 struct berval ***keysp )
722 struct berval **keys;
723 lutil_MD5_CTX MD5context;
724 unsigned char MD5digest[LUTIL_MD5_BYTES];
725 struct berval *value;
726 struct berval digest;
727 digest.bv_val = MD5digest;
728 digest.bv_len = sizeof(MD5digest);
730 slen = strlen( syntax->ssyn_oid );
731 mlen = strlen( mr->smr_oid );
733 value = (struct berval *) assertValue;
735 keys = ch_malloc( sizeof( struct berval * ) * 2 );
737 lutil_MD5Init( &MD5context );
738 if( prefix != NULL && prefix->bv_len > 0 ) {
739 lutil_MD5Update( &MD5context,
740 prefix->bv_val, prefix->bv_len );
742 lutil_MD5Update( &MD5context,
743 syntax->ssyn_oid, slen );
744 lutil_MD5Update( &MD5context,
746 lutil_MD5Update( &MD5context,
747 value->bv_val, value->bv_len );
748 lutil_MD5Final( MD5digest, &MD5context );
750 keys[0] = ber_bvdup( &digest );
757 /* Substrings Index generation function */
758 int caseExactSubstringsIndexer(
763 struct berval *prefix,
764 struct berval **values,
765 struct berval ***keysp )
769 struct berval **keys;
770 lutil_MD5_CTX MD5context;
771 unsigned char MD5digest[16];
772 struct berval digest;
773 digest.bv_val = MD5digest;
774 digest.bv_len = sizeof(MD5digest);
777 for( i=0; values[i] != NULL; i++ ) {
778 /* count number of indices to generate */
779 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
783 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
784 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
785 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
786 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
788 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
792 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
793 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
794 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
798 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
799 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
800 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
801 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
803 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
810 /* no keys to generate */
815 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
817 slen = strlen( syntax->ssyn_oid );
818 mlen = strlen( mr->smr_oid );
821 for( i=0; values[i] != NULL; i++ ) {
823 struct berval *value;
826 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
828 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
829 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
831 char pre = SLAP_INDEX_SUBSTR_PREFIX;
832 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
834 for( j=0; j<max; j++ ) {
835 lutil_MD5Init( &MD5context );
836 if( prefix != NULL && prefix->bv_len > 0 ) {
837 lutil_MD5Update( &MD5context,
838 prefix->bv_val, prefix->bv_len );
841 lutil_MD5Update( &MD5context,
842 &pre, sizeof( pre ) );
843 lutil_MD5Update( &MD5context,
844 syntax->ssyn_oid, slen );
845 lutil_MD5Update( &MD5context,
847 lutil_MD5Update( &MD5context,
849 SLAP_INDEX_SUBSTR_MAXLEN );
850 lutil_MD5Final( MD5digest, &MD5context );
852 keys[nkeys++] = ber_bvdup( &digest );
856 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
857 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
859 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
862 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
863 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
864 lutil_MD5Init( &MD5context );
865 if( prefix != NULL && prefix->bv_len > 0 ) {
866 lutil_MD5Update( &MD5context,
867 prefix->bv_val, prefix->bv_len );
869 lutil_MD5Update( &MD5context,
870 &pre, sizeof( pre ) );
871 lutil_MD5Update( &MD5context,
872 syntax->ssyn_oid, slen );
873 lutil_MD5Update( &MD5context,
875 lutil_MD5Update( &MD5context,
877 lutil_MD5Final( MD5digest, &MD5context );
879 keys[nkeys++] = ber_bvdup( &digest );
882 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
883 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
884 lutil_MD5Init( &MD5context );
885 if( prefix != NULL && prefix->bv_len > 0 ) {
886 lutil_MD5Update( &MD5context,
887 prefix->bv_val, prefix->bv_len );
889 lutil_MD5Update( &MD5context,
890 &pre, sizeof( pre ) );
891 lutil_MD5Update( &MD5context,
892 syntax->ssyn_oid, slen );
893 lutil_MD5Update( &MD5context,
895 lutil_MD5Update( &MD5context,
896 &value->bv_val[value->bv_len-j], j );
897 lutil_MD5Final( MD5digest, &MD5context );
899 keys[nkeys++] = ber_bvdup( &digest );
916 int caseExactSubstringsFilter(
921 struct berval *prefix,
923 struct berval ***keysp )
925 SubstringsAssertion *sa = assertValue;
928 size_t slen, mlen, klen;
929 struct berval **keys;
930 lutil_MD5_CTX MD5context;
931 unsigned char MD5digest[LUTIL_MD5_BYTES];
932 struct berval *value;
933 struct berval digest;
935 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
936 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
941 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
943 for( i=0; sa->sa_any[i] != NULL; i++ ) {
944 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
945 /* don't bother accounting for stepping */
946 nkeys += sa->sa_any[i]->bv_len -
947 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
952 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
953 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
963 digest.bv_val = MD5digest;
964 digest.bv_len = sizeof(MD5digest);
966 slen = strlen( syntax->ssyn_oid );
967 mlen = strlen( mr->smr_oid );
969 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
972 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
973 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
975 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
976 value = sa->sa_initial;
978 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
979 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
981 lutil_MD5Init( &MD5context );
982 if( prefix != NULL && prefix->bv_len > 0 ) {
983 lutil_MD5Update( &MD5context,
984 prefix->bv_val, prefix->bv_len );
986 lutil_MD5Update( &MD5context,
987 &pre, sizeof( pre ) );
988 lutil_MD5Update( &MD5context,
989 syntax->ssyn_oid, slen );
990 lutil_MD5Update( &MD5context,
992 lutil_MD5Update( &MD5context,
993 value->bv_val, klen );
994 lutil_MD5Final( MD5digest, &MD5context );
996 keys[nkeys++] = ber_bvdup( &digest );
999 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1001 pre = SLAP_INDEX_SUBSTR_PREFIX;
1002 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1004 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1005 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1009 value = sa->sa_any[i];
1012 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1013 j += SLAP_INDEX_SUBSTR_STEP )
1015 lutil_MD5Init( &MD5context );
1016 if( prefix != NULL && prefix->bv_len > 0 ) {
1017 lutil_MD5Update( &MD5context,
1018 prefix->bv_val, prefix->bv_len );
1020 lutil_MD5Update( &MD5context,
1021 &pre, sizeof( pre ) );
1022 lutil_MD5Update( &MD5context,
1023 syntax->ssyn_oid, slen );
1024 lutil_MD5Update( &MD5context,
1025 mr->smr_oid, mlen );
1026 lutil_MD5Update( &MD5context,
1027 &value->bv_val[j], klen );
1028 lutil_MD5Final( MD5digest, &MD5context );
1030 keys[nkeys++] = ber_bvdup( &digest );
1035 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1036 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1038 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1039 value = sa->sa_final;
1041 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1042 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1044 lutil_MD5Init( &MD5context );
1045 if( prefix != NULL && prefix->bv_len > 0 ) {
1046 lutil_MD5Update( &MD5context,
1047 prefix->bv_val, prefix->bv_len );
1049 lutil_MD5Update( &MD5context,
1050 &pre, sizeof( pre ) );
1051 lutil_MD5Update( &MD5context,
1052 syntax->ssyn_oid, slen );
1053 lutil_MD5Update( &MD5context,
1054 mr->smr_oid, mlen );
1055 lutil_MD5Update( &MD5context,
1056 &value->bv_val[value->bv_len-klen], klen );
1057 lutil_MD5Final( MD5digest, &MD5context );
1059 keys[nkeys++] = ber_bvdup( &digest );
1070 return LDAP_SUCCESS;
1079 struct berval *value,
1080 void *assertedValue )
1083 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1085 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1088 match = strncasecmp( value->bv_val,
1089 ((struct berval *) assertedValue)->bv_val,
1095 return LDAP_SUCCESS;
1099 caseIgnoreSubstringsMatch(
1104 struct berval *value,
1105 void *assertedValue )
1108 SubstringsAssertion *sub = assertedValue;
1109 struct berval left = *value;
1113 /* Add up asserted input length */
1114 if( sub->sa_initial ) {
1115 inlen += sub->sa_initial->bv_len;
1118 for(i=0; sub->sa_any[i] != NULL; i++) {
1119 inlen += sub->sa_any[i]->bv_len;
1122 if( sub->sa_final ) {
1123 inlen += sub->sa_final->bv_len;
1126 if( sub->sa_initial ) {
1127 if( inlen > left.bv_len ) {
1132 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1133 sub->sa_initial->bv_len );
1139 left.bv_val += sub->sa_initial->bv_len;
1140 left.bv_len -= sub->sa_initial->bv_len;
1141 inlen -= sub->sa_initial->bv_len;
1144 if( sub->sa_final ) {
1145 if( inlen > left.bv_len ) {
1150 match = strncasecmp( sub->sa_final->bv_val,
1151 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1152 sub->sa_final->bv_len );
1158 left.bv_len -= sub->sa_final->bv_len;
1159 inlen -= sub->sa_final->bv_len;
1163 for(i=0; sub->sa_any[i]; i++) {
1168 if( inlen > left.bv_len ) {
1169 /* not enough length */
1174 if( sub->sa_any[i]->bv_len == 0 ) {
1178 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1185 idx = p - left.bv_val;
1186 assert( idx < left.bv_len );
1188 if( idx >= left.bv_len ) {
1189 /* this shouldn't happen */
1196 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1197 /* not enough left */
1202 match = strncasecmp( left.bv_val,
1203 sub->sa_any[i]->bv_val,
1204 sub->sa_any[i]->bv_len );
1213 left.bv_val += sub->sa_any[i]->bv_len;
1214 left.bv_len -= sub->sa_any[i]->bv_len;
1215 inlen -= sub->sa_any[i]->bv_len;
1221 return LDAP_SUCCESS;
1224 /* Index generation function */
1225 int caseIgnoreIndexer(
1230 struct berval *prefix,
1231 struct berval **values,
1232 struct berval ***keysp )
1236 struct berval **keys;
1237 lutil_MD5_CTX MD5context;
1238 unsigned char MD5digest[16];
1239 struct berval digest;
1240 digest.bv_val = MD5digest;
1241 digest.bv_len = sizeof(MD5digest);
1243 for( i=0; values[i] != NULL; i++ ) {
1244 /* just count them */
1249 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1251 slen = strlen( syntax->ssyn_oid );
1252 mlen = strlen( mr->smr_oid );
1254 for( i=0; values[i] != NULL; i++ ) {
1255 struct berval *value = ber_bvdup( values[i] );
1256 ldap_pvt_str2upper( value->bv_val );
1258 lutil_MD5Init( &MD5context );
1259 if( prefix != NULL && prefix->bv_len > 0 ) {
1260 lutil_MD5Update( &MD5context,
1261 prefix->bv_val, prefix->bv_len );
1263 lutil_MD5Update( &MD5context,
1264 syntax->ssyn_oid, slen );
1265 lutil_MD5Update( &MD5context,
1266 mr->smr_oid, mlen );
1267 lutil_MD5Update( &MD5context,
1268 value->bv_val, value->bv_len );
1269 lutil_MD5Final( MD5digest, &MD5context );
1271 ber_bvfree( value );
1273 keys[i] = ber_bvdup( &digest );
1278 return LDAP_SUCCESS;
1281 /* Index generation function */
1282 int caseIgnoreFilter(
1287 struct berval *prefix,
1289 struct berval ***keysp )
1292 struct berval **keys;
1293 lutil_MD5_CTX MD5context;
1294 unsigned char MD5digest[LUTIL_MD5_BYTES];
1295 struct berval *value;
1296 struct berval digest;
1297 digest.bv_val = MD5digest;
1298 digest.bv_len = sizeof(MD5digest);
1300 slen = strlen( syntax->ssyn_oid );
1301 mlen = strlen( mr->smr_oid );
1303 value = ber_bvdup( (struct berval *) assertValue );
1304 ldap_pvt_str2upper( value->bv_val );
1306 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1308 lutil_MD5Init( &MD5context );
1309 if( prefix != NULL && prefix->bv_len > 0 ) {
1310 lutil_MD5Update( &MD5context,
1311 prefix->bv_val, prefix->bv_len );
1313 lutil_MD5Update( &MD5context,
1314 syntax->ssyn_oid, slen );
1315 lutil_MD5Update( &MD5context,
1316 mr->smr_oid, mlen );
1317 lutil_MD5Update( &MD5context,
1318 value->bv_val, value->bv_len );
1319 lutil_MD5Final( MD5digest, &MD5context );
1321 keys[0] = ber_bvdup( &digest );
1324 ber_bvfree( value );
1328 return LDAP_SUCCESS;
1331 /* Substrings Index generation function */
1332 int caseIgnoreSubstringsIndexer(
1337 struct berval *prefix,
1338 struct berval **values,
1339 struct berval ***keysp )
1343 struct berval **keys;
1344 lutil_MD5_CTX MD5context;
1345 unsigned char MD5digest[16];
1346 struct berval digest;
1347 digest.bv_val = MD5digest;
1348 digest.bv_len = sizeof(MD5digest);
1351 for( i=0; values[i] != NULL; i++ ) {
1352 /* count number of indices to generate */
1353 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1357 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1358 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1359 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1360 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1362 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1366 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1367 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1368 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1372 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1373 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1374 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1375 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1377 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1384 /* no keys to generate */
1386 return LDAP_SUCCESS;
1389 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1391 slen = strlen( syntax->ssyn_oid );
1392 mlen = strlen( mr->smr_oid );
1395 for( i=0; values[i] != NULL; i++ ) {
1397 struct berval *value;
1399 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1401 value = ber_bvdup( values[i] );
1402 ldap_pvt_str2upper( value->bv_val );
1404 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1405 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1407 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1408 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1410 for( j=0; j<max; j++ ) {
1411 lutil_MD5Init( &MD5context );
1412 if( prefix != NULL && prefix->bv_len > 0 ) {
1413 lutil_MD5Update( &MD5context,
1414 prefix->bv_val, prefix->bv_len );
1417 lutil_MD5Update( &MD5context,
1418 &pre, sizeof( pre ) );
1419 lutil_MD5Update( &MD5context,
1420 syntax->ssyn_oid, slen );
1421 lutil_MD5Update( &MD5context,
1422 mr->smr_oid, mlen );
1423 lutil_MD5Update( &MD5context,
1425 SLAP_INDEX_SUBSTR_MAXLEN );
1426 lutil_MD5Final( MD5digest, &MD5context );
1428 keys[nkeys++] = ber_bvdup( &digest );
1432 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1433 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1435 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1438 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1439 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1440 lutil_MD5Init( &MD5context );
1441 if( prefix != NULL && prefix->bv_len > 0 ) {
1442 lutil_MD5Update( &MD5context,
1443 prefix->bv_val, prefix->bv_len );
1445 lutil_MD5Update( &MD5context,
1446 &pre, sizeof( pre ) );
1447 lutil_MD5Update( &MD5context,
1448 syntax->ssyn_oid, slen );
1449 lutil_MD5Update( &MD5context,
1450 mr->smr_oid, mlen );
1451 lutil_MD5Update( &MD5context,
1453 lutil_MD5Final( MD5digest, &MD5context );
1455 keys[nkeys++] = ber_bvdup( &digest );
1458 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1459 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1460 lutil_MD5Init( &MD5context );
1461 if( prefix != NULL && prefix->bv_len > 0 ) {
1462 lutil_MD5Update( &MD5context,
1463 prefix->bv_val, prefix->bv_len );
1465 lutil_MD5Update( &MD5context,
1466 &pre, sizeof( pre ) );
1467 lutil_MD5Update( &MD5context,
1468 syntax->ssyn_oid, slen );
1469 lutil_MD5Update( &MD5context,
1470 mr->smr_oid, mlen );
1471 lutil_MD5Update( &MD5context,
1472 &value->bv_val[value->bv_len-j], j );
1473 lutil_MD5Final( MD5digest, &MD5context );
1475 keys[nkeys++] = ber_bvdup( &digest );
1480 ber_bvfree( value );
1491 return LDAP_SUCCESS;
1494 int caseIgnoreSubstringsFilter(
1499 struct berval *prefix,
1501 struct berval ***keysp )
1503 SubstringsAssertion *sa = assertValue;
1505 ber_len_t nkeys = 0;
1506 size_t slen, mlen, klen;
1507 struct berval **keys;
1508 lutil_MD5_CTX MD5context;
1509 unsigned char MD5digest[LUTIL_MD5_BYTES];
1510 struct berval *value;
1511 struct berval digest;
1513 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1514 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1519 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1521 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1522 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1523 /* don't bother accounting for stepping */
1524 nkeys += sa->sa_any[i]->bv_len -
1525 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1530 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1531 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1538 return LDAP_SUCCESS;
1541 digest.bv_val = MD5digest;
1542 digest.bv_len = sizeof(MD5digest);
1544 slen = strlen( syntax->ssyn_oid );
1545 mlen = strlen( mr->smr_oid );
1547 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1550 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1551 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1553 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1554 value = ber_bvdup( sa->sa_initial );
1555 ldap_pvt_str2upper( value->bv_val );
1557 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1558 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1560 lutil_MD5Init( &MD5context );
1561 if( prefix != NULL && prefix->bv_len > 0 ) {
1562 lutil_MD5Update( &MD5context,
1563 prefix->bv_val, prefix->bv_len );
1565 lutil_MD5Update( &MD5context,
1566 &pre, sizeof( pre ) );
1567 lutil_MD5Update( &MD5context,
1568 syntax->ssyn_oid, slen );
1569 lutil_MD5Update( &MD5context,
1570 mr->smr_oid, mlen );
1571 lutil_MD5Update( &MD5context,
1572 value->bv_val, klen );
1573 lutil_MD5Final( MD5digest, &MD5context );
1575 ber_bvfree( value );
1576 keys[nkeys++] = ber_bvdup( &digest );
1579 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1581 pre = SLAP_INDEX_SUBSTR_PREFIX;
1582 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1584 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1585 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1589 value = ber_bvdup( sa->sa_any[i] );
1590 ldap_pvt_str2upper( value->bv_val );
1593 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1594 j += SLAP_INDEX_SUBSTR_STEP )
1596 lutil_MD5Init( &MD5context );
1597 if( prefix != NULL && prefix->bv_len > 0 ) {
1598 lutil_MD5Update( &MD5context,
1599 prefix->bv_val, prefix->bv_len );
1601 lutil_MD5Update( &MD5context,
1602 &pre, sizeof( pre ) );
1603 lutil_MD5Update( &MD5context,
1604 syntax->ssyn_oid, slen );
1605 lutil_MD5Update( &MD5context,
1606 mr->smr_oid, mlen );
1607 lutil_MD5Update( &MD5context,
1608 &value->bv_val[j], klen );
1609 lutil_MD5Final( MD5digest, &MD5context );
1611 keys[nkeys++] = ber_bvdup( &digest );
1614 ber_bvfree( value );
1618 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1619 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1621 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1622 value = ber_bvdup( sa->sa_final );
1623 ldap_pvt_str2upper( value->bv_val );
1625 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1626 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1628 lutil_MD5Init( &MD5context );
1629 if( prefix != NULL && prefix->bv_len > 0 ) {
1630 lutil_MD5Update( &MD5context,
1631 prefix->bv_val, prefix->bv_len );
1633 lutil_MD5Update( &MD5context,
1634 &pre, sizeof( pre ) );
1635 lutil_MD5Update( &MD5context,
1636 syntax->ssyn_oid, slen );
1637 lutil_MD5Update( &MD5context,
1638 mr->smr_oid, mlen );
1639 lutil_MD5Update( &MD5context,
1640 &value->bv_val[value->bv_len-klen], klen );
1641 lutil_MD5Final( MD5digest, &MD5context );
1643 ber_bvfree( value );
1644 keys[nkeys++] = ber_bvdup( &digest );
1655 return LDAP_SUCCESS;
1661 struct berval *val )
1665 if( val->bv_len == 0 ) return 0;
1667 if( OID_LEADCHAR(val->bv_val[0]) ) {
1669 for(i=1; i < val->bv_len; i++) {
1670 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1671 if( dot++ ) return 1;
1672 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1675 return LDAP_INVALID_SYNTAX;
1679 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1681 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1682 for(i=1; i < val->bv_len; i++) {
1683 if( !DESC_CHAR(val->bv_val[i] ) ) {
1684 return LDAP_INVALID_SYNTAX;
1688 return LDAP_SUCCESS;
1691 return LDAP_INVALID_SYNTAX;
1697 struct berval *val )
1701 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1703 for(i=0; i < val->bv_len; i++) {
1704 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1707 return LDAP_SUCCESS;
1716 struct berval *value,
1717 void *assertedValue )
1720 char *vb, *ve, *avb, *ave;
1723 ve = vb + value->bv_len - 1;
1724 avb = ((struct berval *) assertedValue)->bv_val;
1725 ave = avb + ((struct berval *) assertedValue)->bv_len - 1;
1727 /* Is '0' safe? Should we ignore whitespace too? Can they be
1728 * negative? RFC2252 does not suggest so, and integerValidate
1729 * above doesn't either. */
1731 while ( *vb == '0' && vb <= ve )
1734 while ( *avb == '0' && avb <= ave )
1737 match = (ve - vb) - (ave - avb);
1740 while ( *vb == *avb && vb < ve ) {
1744 match = (unsigned char)*vb - (unsigned char)*avb;
1748 return LDAP_SUCCESS;
1751 /* Index generation function */
1757 struct berval *prefix,
1758 struct berval **values,
1759 struct berval ***keysp )
1763 struct berval **keys;
1764 lutil_MD5_CTX MD5context;
1765 unsigned char MD5digest[16];
1766 struct berval digest;
1767 digest.bv_val = MD5digest;
1768 digest.bv_len = sizeof(MD5digest);
1770 for( i=0; values[i] != NULL; i++ ) {
1771 /* just count them */
1776 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1778 slen = strlen( syntax->ssyn_oid );
1779 mlen = strlen( mr->smr_oid );
1781 for( i=0; values[i] != NULL; i++ ) {
1782 struct berval *value = values[i];
1786 ve = vb + value->bv_len - 1;
1787 while ( *vb == '0' && vb <= ve )
1790 lutil_MD5Init( &MD5context );
1791 if( prefix != NULL && prefix->bv_len > 0 ) {
1792 lutil_MD5Update( &MD5context,
1793 prefix->bv_val, prefix->bv_len );
1795 lutil_MD5Update( &MD5context,
1796 syntax->ssyn_oid, slen );
1797 lutil_MD5Update( &MD5context,
1798 mr->smr_oid, mlen );
1799 lutil_MD5Update( &MD5context,
1801 lutil_MD5Final( MD5digest, &MD5context );
1803 keys[i] = ber_bvdup( &digest );
1808 return LDAP_SUCCESS;
1811 /* Index generation function */
1817 struct berval *prefix,
1819 struct berval ***keysp )
1822 struct berval **keys;
1823 lutil_MD5_CTX MD5context;
1824 unsigned char MD5digest[LUTIL_MD5_BYTES];
1825 struct berval *value;
1827 struct berval digest;
1828 digest.bv_val = MD5digest;
1829 digest.bv_len = sizeof(MD5digest);
1831 slen = strlen( syntax->ssyn_oid );
1832 mlen = strlen( mr->smr_oid );
1834 value = (struct berval *) assertValue;
1837 ve = vb + value->bv_len - 1;
1838 while ( *vb == '0' && vb <= ve )
1841 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1843 lutil_MD5Init( &MD5context );
1844 if( prefix != NULL && prefix->bv_len > 0 ) {
1845 lutil_MD5Update( &MD5context,
1846 prefix->bv_val, prefix->bv_len );
1848 lutil_MD5Update( &MD5context,
1849 syntax->ssyn_oid, slen );
1850 lutil_MD5Update( &MD5context,
1851 mr->smr_oid, mlen );
1852 lutil_MD5Update( &MD5context,
1854 lutil_MD5Final( MD5digest, &MD5context );
1856 keys[0] = ber_bvdup( &digest );
1860 return LDAP_SUCCESS;
1864 printableStringValidate(
1866 struct berval *val )
1870 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1872 for(i=0; i < val->bv_len; i++) {
1873 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1876 return LDAP_SUCCESS;
1882 struct berval *val )
1886 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1888 for(i=0; i < val->bv_len; i++) {
1889 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1892 return LDAP_SUCCESS;
1899 struct berval **out )
1902 ber_len_t i, len = in->bv_len;
1903 struct berval *bv = ch_malloc( sizeof(struct berval) );
1905 bv->bv_len = len * sizeof( ldap_unicode_t );
1906 u = (ldap_unicode_t *) ch_malloc( bv->bv_len + sizeof(ldap_unicode_t) );
1907 bv->bv_val = (char *) u;
1909 for(i=0; i < len; i++ ) {
1911 * IA5StringValidate should have been called to ensure
1912 * input is limited to IA5.
1914 u[i] = in->bv_val[i];
1919 return LDAP_SUCCESS;
1926 struct berval **normalized )
1928 struct berval *newval;
1931 newval = ch_malloc( sizeof( struct berval ) );
1935 /* Ignore initial whitespace */
1936 while ( ASCII_SPACE( *p ) ) {
1942 return LDAP_INVALID_SYNTAX;
1945 newval->bv_val = ch_strdup( p );
1946 p = q = newval->bv_val;
1949 if ( ASCII_SPACE( *p ) ) {
1952 /* Ignore the extra whitespace */
1953 while ( ASCII_SPACE( *p ) ) {
1961 assert( *newval->bv_val );
1962 assert( newval->bv_val < p );
1965 /* cannot start with a space */
1966 assert( !ASCII_SPACE(*newval->bv_val) );
1969 * If the string ended in space, backup the pointer one
1970 * position. One is enough because the above loop collapsed
1971 * all whitespace to a single space.
1974 if ( ASCII_SPACE( q[-1] ) ) {
1978 /* cannot end with a space */
1979 assert( !ASCII_SPACE( q[-1] ) );
1981 /* null terminate */
1984 newval->bv_len = q - newval->bv_val;
1985 *normalized = newval;
1987 return LDAP_SUCCESS;
1996 struct berval *value,
1997 void *assertedValue )
1999 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2002 match = strncmp( value->bv_val,
2003 ((struct berval *) assertedValue)->bv_val,
2008 return LDAP_SUCCESS;
2012 caseExactIA5SubstringsMatch(
2017 struct berval *value,
2018 void *assertedValue )
2021 SubstringsAssertion *sub = assertedValue;
2022 struct berval left = *value;
2026 /* Add up asserted input length */
2027 if( sub->sa_initial ) {
2028 inlen += sub->sa_initial->bv_len;
2031 for(i=0; sub->sa_any[i] != NULL; i++) {
2032 inlen += sub->sa_any[i]->bv_len;
2035 if( sub->sa_final ) {
2036 inlen += sub->sa_final->bv_len;
2039 if( sub->sa_initial ) {
2040 if( inlen > left.bv_len ) {
2045 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2046 sub->sa_initial->bv_len );
2052 left.bv_val += sub->sa_initial->bv_len;
2053 left.bv_len -= sub->sa_initial->bv_len;
2054 inlen -= sub->sa_initial->bv_len;
2057 if( sub->sa_final ) {
2058 if( inlen > left.bv_len ) {
2063 match = strncmp( sub->sa_final->bv_val,
2064 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2065 sub->sa_final->bv_len );
2071 left.bv_len -= sub->sa_final->bv_len;
2072 inlen -= sub->sa_final->bv_len;
2076 for(i=0; sub->sa_any[i]; i++) {
2081 if( inlen > left.bv_len ) {
2082 /* not enough length */
2087 if( sub->sa_any[i]->bv_len == 0 ) {
2091 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2098 idx = p - left.bv_val;
2099 assert( idx < left.bv_len );
2101 if( idx >= left.bv_len ) {
2102 /* this shouldn't happen */
2109 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2110 /* not enough left */
2115 match = strncmp( left.bv_val,
2116 sub->sa_any[i]->bv_val,
2117 sub->sa_any[i]->bv_len );
2125 left.bv_val += sub->sa_any[i]->bv_len;
2126 left.bv_len -= sub->sa_any[i]->bv_len;
2127 inlen -= sub->sa_any[i]->bv_len;
2133 return LDAP_SUCCESS;
2136 /* Index generation function */
2137 int caseExactIA5Indexer(
2142 struct berval *prefix,
2143 struct berval **values,
2144 struct berval ***keysp )
2148 struct berval **keys;
2149 lutil_MD5_CTX MD5context;
2150 unsigned char MD5digest[16];
2151 struct berval digest;
2152 digest.bv_val = MD5digest;
2153 digest.bv_len = sizeof(MD5digest);
2155 for( i=0; values[i] != NULL; i++ ) {
2156 /* just count them */
2161 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2163 slen = strlen( syntax->ssyn_oid );
2164 mlen = strlen( mr->smr_oid );
2166 for( i=0; values[i] != NULL; i++ ) {
2167 struct berval *value = values[i];
2169 lutil_MD5Init( &MD5context );
2170 if( prefix != NULL && prefix->bv_len > 0 ) {
2171 lutil_MD5Update( &MD5context,
2172 prefix->bv_val, prefix->bv_len );
2174 lutil_MD5Update( &MD5context,
2175 syntax->ssyn_oid, slen );
2176 lutil_MD5Update( &MD5context,
2177 mr->smr_oid, mlen );
2178 lutil_MD5Update( &MD5context,
2179 value->bv_val, value->bv_len );
2180 lutil_MD5Final( MD5digest, &MD5context );
2182 keys[i] = ber_bvdup( &digest );
2187 return LDAP_SUCCESS;
2190 /* Index generation function */
2191 int caseExactIA5Filter(
2196 struct berval *prefix,
2198 struct berval ***keysp )
2201 struct berval **keys;
2202 lutil_MD5_CTX MD5context;
2203 unsigned char MD5digest[LUTIL_MD5_BYTES];
2204 struct berval *value;
2205 struct berval digest;
2206 digest.bv_val = MD5digest;
2207 digest.bv_len = sizeof(MD5digest);
2209 slen = strlen( syntax->ssyn_oid );
2210 mlen = strlen( mr->smr_oid );
2212 value = (struct berval *) assertValue;
2214 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2216 lutil_MD5Init( &MD5context );
2217 if( prefix != NULL && prefix->bv_len > 0 ) {
2218 lutil_MD5Update( &MD5context,
2219 prefix->bv_val, prefix->bv_len );
2221 lutil_MD5Update( &MD5context,
2222 syntax->ssyn_oid, slen );
2223 lutil_MD5Update( &MD5context,
2224 mr->smr_oid, mlen );
2225 lutil_MD5Update( &MD5context,
2226 value->bv_val, value->bv_len );
2227 lutil_MD5Final( MD5digest, &MD5context );
2229 keys[0] = ber_bvdup( &digest );
2233 return LDAP_SUCCESS;
2236 /* Substrings Index generation function */
2237 int caseExactIA5SubstringsIndexer(
2242 struct berval *prefix,
2243 struct berval **values,
2244 struct berval ***keysp )
2248 struct berval **keys;
2249 lutil_MD5_CTX MD5context;
2250 unsigned char MD5digest[16];
2251 struct berval digest;
2252 digest.bv_val = MD5digest;
2253 digest.bv_len = sizeof(MD5digest);
2256 for( i=0; values[i] != NULL; i++ ) {
2257 /* count number of indices to generate */
2258 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2262 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2263 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2264 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2265 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2267 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2271 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2272 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2273 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2277 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2278 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2279 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2280 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2282 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2289 /* no keys to generate */
2291 return LDAP_SUCCESS;
2294 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2296 slen = strlen( syntax->ssyn_oid );
2297 mlen = strlen( mr->smr_oid );
2300 for( i=0; values[i] != NULL; i++ ) {
2302 struct berval *value;
2305 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2307 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2308 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2310 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2311 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2313 for( j=0; j<max; j++ ) {
2314 lutil_MD5Init( &MD5context );
2315 if( prefix != NULL && prefix->bv_len > 0 ) {
2316 lutil_MD5Update( &MD5context,
2317 prefix->bv_val, prefix->bv_len );
2320 lutil_MD5Update( &MD5context,
2321 &pre, sizeof( pre ) );
2322 lutil_MD5Update( &MD5context,
2323 syntax->ssyn_oid, slen );
2324 lutil_MD5Update( &MD5context,
2325 mr->smr_oid, mlen );
2326 lutil_MD5Update( &MD5context,
2328 SLAP_INDEX_SUBSTR_MAXLEN );
2329 lutil_MD5Final( MD5digest, &MD5context );
2331 keys[nkeys++] = ber_bvdup( &digest );
2335 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2336 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2338 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2341 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2342 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2343 lutil_MD5Init( &MD5context );
2344 if( prefix != NULL && prefix->bv_len > 0 ) {
2345 lutil_MD5Update( &MD5context,
2346 prefix->bv_val, prefix->bv_len );
2348 lutil_MD5Update( &MD5context,
2349 &pre, sizeof( pre ) );
2350 lutil_MD5Update( &MD5context,
2351 syntax->ssyn_oid, slen );
2352 lutil_MD5Update( &MD5context,
2353 mr->smr_oid, mlen );
2354 lutil_MD5Update( &MD5context,
2356 lutil_MD5Final( MD5digest, &MD5context );
2358 keys[nkeys++] = ber_bvdup( &digest );
2361 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2362 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2363 lutil_MD5Init( &MD5context );
2364 if( prefix != NULL && prefix->bv_len > 0 ) {
2365 lutil_MD5Update( &MD5context,
2366 prefix->bv_val, prefix->bv_len );
2368 lutil_MD5Update( &MD5context,
2369 &pre, sizeof( pre ) );
2370 lutil_MD5Update( &MD5context,
2371 syntax->ssyn_oid, slen );
2372 lutil_MD5Update( &MD5context,
2373 mr->smr_oid, mlen );
2374 lutil_MD5Update( &MD5context,
2375 &value->bv_val[value->bv_len-j], j );
2376 lutil_MD5Final( MD5digest, &MD5context );
2378 keys[nkeys++] = ber_bvdup( &digest );
2392 return LDAP_SUCCESS;
2395 int caseExactIA5SubstringsFilter(
2400 struct berval *prefix,
2402 struct berval ***keysp )
2404 SubstringsAssertion *sa = assertValue;
2406 ber_len_t nkeys = 0;
2407 size_t slen, mlen, klen;
2408 struct berval **keys;
2409 lutil_MD5_CTX MD5context;
2410 unsigned char MD5digest[LUTIL_MD5_BYTES];
2411 struct berval *value;
2412 struct berval digest;
2414 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2415 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2420 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2422 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2423 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2424 /* don't bother accounting for stepping */
2425 nkeys += sa->sa_any[i]->bv_len -
2426 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2431 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2432 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2439 return LDAP_SUCCESS;
2442 digest.bv_val = MD5digest;
2443 digest.bv_len = sizeof(MD5digest);
2445 slen = strlen( syntax->ssyn_oid );
2446 mlen = strlen( mr->smr_oid );
2448 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2451 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2452 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2454 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2455 value = sa->sa_initial;
2457 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2458 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2460 lutil_MD5Init( &MD5context );
2461 if( prefix != NULL && prefix->bv_len > 0 ) {
2462 lutil_MD5Update( &MD5context,
2463 prefix->bv_val, prefix->bv_len );
2465 lutil_MD5Update( &MD5context,
2466 &pre, sizeof( pre ) );
2467 lutil_MD5Update( &MD5context,
2468 syntax->ssyn_oid, slen );
2469 lutil_MD5Update( &MD5context,
2470 mr->smr_oid, mlen );
2471 lutil_MD5Update( &MD5context,
2472 value->bv_val, klen );
2473 lutil_MD5Final( MD5digest, &MD5context );
2475 keys[nkeys++] = ber_bvdup( &digest );
2478 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2480 pre = SLAP_INDEX_SUBSTR_PREFIX;
2481 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2483 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2484 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2488 value = sa->sa_any[i];
2491 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2492 j += SLAP_INDEX_SUBSTR_STEP )
2494 lutil_MD5Init( &MD5context );
2495 if( prefix != NULL && prefix->bv_len > 0 ) {
2496 lutil_MD5Update( &MD5context,
2497 prefix->bv_val, prefix->bv_len );
2499 lutil_MD5Update( &MD5context,
2500 &pre, sizeof( pre ) );
2501 lutil_MD5Update( &MD5context,
2502 syntax->ssyn_oid, slen );
2503 lutil_MD5Update( &MD5context,
2504 mr->smr_oid, mlen );
2505 lutil_MD5Update( &MD5context,
2506 &value->bv_val[j], klen );
2507 lutil_MD5Final( MD5digest, &MD5context );
2509 keys[nkeys++] = ber_bvdup( &digest );
2514 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2515 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2517 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2518 value = sa->sa_final;
2520 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2521 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2523 lutil_MD5Init( &MD5context );
2524 if( prefix != NULL && prefix->bv_len > 0 ) {
2525 lutil_MD5Update( &MD5context,
2526 prefix->bv_val, prefix->bv_len );
2528 lutil_MD5Update( &MD5context,
2529 &pre, sizeof( pre ) );
2530 lutil_MD5Update( &MD5context,
2531 syntax->ssyn_oid, slen );
2532 lutil_MD5Update( &MD5context,
2533 mr->smr_oid, mlen );
2534 lutil_MD5Update( &MD5context,
2535 &value->bv_val[value->bv_len-klen], klen );
2536 lutil_MD5Final( MD5digest, &MD5context );
2538 keys[nkeys++] = ber_bvdup( &digest );
2549 return LDAP_SUCCESS;
2558 struct berval *value,
2559 void *assertedValue )
2561 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2564 match = strncasecmp( value->bv_val,
2565 ((struct berval *) assertedValue)->bv_val,
2570 return LDAP_SUCCESS;
2574 caseIgnoreIA5SubstringsMatch(
2579 struct berval *value,
2580 void *assertedValue )
2583 SubstringsAssertion *sub = assertedValue;
2584 struct berval left = *value;
2588 /* Add up asserted input length */
2589 if( sub->sa_initial ) {
2590 inlen += sub->sa_initial->bv_len;
2593 for(i=0; sub->sa_any[i] != NULL; i++) {
2594 inlen += sub->sa_any[i]->bv_len;
2597 if( sub->sa_final ) {
2598 inlen += sub->sa_final->bv_len;
2601 if( sub->sa_initial ) {
2602 if( inlen > left.bv_len ) {
2607 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2608 sub->sa_initial->bv_len );
2614 left.bv_val += sub->sa_initial->bv_len;
2615 left.bv_len -= sub->sa_initial->bv_len;
2616 inlen -= sub->sa_initial->bv_len;
2619 if( sub->sa_final ) {
2620 if( inlen > left.bv_len ) {
2625 match = strncasecmp( sub->sa_final->bv_val,
2626 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2627 sub->sa_final->bv_len );
2633 left.bv_len -= sub->sa_final->bv_len;
2634 inlen -= sub->sa_final->bv_len;
2638 for(i=0; sub->sa_any[i]; i++) {
2643 if( inlen > left.bv_len ) {
2644 /* not enough length */
2649 if( sub->sa_any[i]->bv_len == 0 ) {
2653 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2660 idx = p - left.bv_val;
2661 assert( idx < left.bv_len );
2663 if( idx >= left.bv_len ) {
2664 /* this shouldn't happen */
2671 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2672 /* not enough left */
2677 match = strncasecmp( left.bv_val,
2678 sub->sa_any[i]->bv_val,
2679 sub->sa_any[i]->bv_len );
2688 left.bv_val += sub->sa_any[i]->bv_len;
2689 left.bv_len -= sub->sa_any[i]->bv_len;
2690 inlen -= sub->sa_any[i]->bv_len;
2696 return LDAP_SUCCESS;
2699 /* Index generation function */
2700 int caseIgnoreIA5Indexer(
2705 struct berval *prefix,
2706 struct berval **values,
2707 struct berval ***keysp )
2711 struct berval **keys;
2712 lutil_MD5_CTX MD5context;
2713 unsigned char MD5digest[16];
2714 struct berval digest;
2715 digest.bv_val = MD5digest;
2716 digest.bv_len = sizeof(MD5digest);
2718 for( i=0; values[i] != NULL; i++ ) {
2719 /* just count them */
2724 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2726 slen = strlen( syntax->ssyn_oid );
2727 mlen = strlen( mr->smr_oid );
2729 for( i=0; values[i] != NULL; i++ ) {
2730 struct berval *value = ber_bvdup( values[i] );
2731 ldap_pvt_str2upper( value->bv_val );
2733 lutil_MD5Init( &MD5context );
2734 if( prefix != NULL && prefix->bv_len > 0 ) {
2735 lutil_MD5Update( &MD5context,
2736 prefix->bv_val, prefix->bv_len );
2738 lutil_MD5Update( &MD5context,
2739 syntax->ssyn_oid, slen );
2740 lutil_MD5Update( &MD5context,
2741 mr->smr_oid, mlen );
2742 lutil_MD5Update( &MD5context,
2743 value->bv_val, value->bv_len );
2744 lutil_MD5Final( MD5digest, &MD5context );
2746 ber_bvfree( value );
2748 keys[i] = ber_bvdup( &digest );
2753 return LDAP_SUCCESS;
2756 /* Index generation function */
2757 int caseIgnoreIA5Filter(
2762 struct berval *prefix,
2764 struct berval ***keysp )
2767 struct berval **keys;
2768 lutil_MD5_CTX MD5context;
2769 unsigned char MD5digest[LUTIL_MD5_BYTES];
2770 struct berval *value;
2771 struct berval digest;
2772 digest.bv_val = MD5digest;
2773 digest.bv_len = sizeof(MD5digest);
2775 slen = strlen( syntax->ssyn_oid );
2776 mlen = strlen( mr->smr_oid );
2778 value = ber_bvdup( (struct berval *) assertValue );
2779 ldap_pvt_str2upper( value->bv_val );
2781 keys = ch_malloc( sizeof( struct berval * ) * 2 );
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 syntax->ssyn_oid, slen );
2790 lutil_MD5Update( &MD5context,
2791 mr->smr_oid, mlen );
2792 lutil_MD5Update( &MD5context,
2793 value->bv_val, value->bv_len );
2794 lutil_MD5Final( MD5digest, &MD5context );
2796 keys[0] = ber_bvdup( &digest );
2799 ber_bvfree( value );
2803 return LDAP_SUCCESS;
2806 /* Substrings Index generation function */
2807 int caseIgnoreIA5SubstringsIndexer(
2812 struct berval *prefix,
2813 struct berval **values,
2814 struct berval ***keysp )
2818 struct berval **keys;
2819 lutil_MD5_CTX MD5context;
2820 unsigned char MD5digest[16];
2821 struct berval digest;
2822 digest.bv_val = MD5digest;
2823 digest.bv_len = sizeof(MD5digest);
2826 for( i=0; values[i] != NULL; i++ ) {
2827 /* count number of indices to generate */
2828 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2832 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2833 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2834 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2835 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2837 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2841 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2842 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2843 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2847 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2848 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2849 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2850 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2852 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2859 /* no keys to generate */
2861 return LDAP_SUCCESS;
2864 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2866 slen = strlen( syntax->ssyn_oid );
2867 mlen = strlen( mr->smr_oid );
2870 for( i=0; values[i] != NULL; i++ ) {
2872 struct berval *value;
2874 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2876 value = ber_bvdup( values[i] );
2877 ldap_pvt_str2upper( value->bv_val );
2879 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2880 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2882 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2883 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2885 for( j=0; j<max; j++ ) {
2886 lutil_MD5Init( &MD5context );
2887 if( prefix != NULL && prefix->bv_len > 0 ) {
2888 lutil_MD5Update( &MD5context,
2889 prefix->bv_val, prefix->bv_len );
2892 lutil_MD5Update( &MD5context,
2893 &pre, sizeof( pre ) );
2894 lutil_MD5Update( &MD5context,
2895 syntax->ssyn_oid, slen );
2896 lutil_MD5Update( &MD5context,
2897 mr->smr_oid, mlen );
2898 lutil_MD5Update( &MD5context,
2900 SLAP_INDEX_SUBSTR_MAXLEN );
2901 lutil_MD5Final( MD5digest, &MD5context );
2903 keys[nkeys++] = ber_bvdup( &digest );
2907 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2908 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2910 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2913 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2914 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2915 lutil_MD5Init( &MD5context );
2916 if( prefix != NULL && prefix->bv_len > 0 ) {
2917 lutil_MD5Update( &MD5context,
2918 prefix->bv_val, prefix->bv_len );
2920 lutil_MD5Update( &MD5context,
2921 &pre, sizeof( pre ) );
2922 lutil_MD5Update( &MD5context,
2923 syntax->ssyn_oid, slen );
2924 lutil_MD5Update( &MD5context,
2925 mr->smr_oid, mlen );
2926 lutil_MD5Update( &MD5context,
2928 lutil_MD5Final( MD5digest, &MD5context );
2930 keys[nkeys++] = ber_bvdup( &digest );
2933 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2934 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2935 lutil_MD5Init( &MD5context );
2936 if( prefix != NULL && prefix->bv_len > 0 ) {
2937 lutil_MD5Update( &MD5context,
2938 prefix->bv_val, prefix->bv_len );
2940 lutil_MD5Update( &MD5context,
2941 &pre, sizeof( pre ) );
2942 lutil_MD5Update( &MD5context,
2943 syntax->ssyn_oid, slen );
2944 lutil_MD5Update( &MD5context,
2945 mr->smr_oid, mlen );
2946 lutil_MD5Update( &MD5context,
2947 &value->bv_val[value->bv_len-j], j );
2948 lutil_MD5Final( MD5digest, &MD5context );
2950 keys[nkeys++] = ber_bvdup( &digest );
2955 ber_bvfree( value );
2966 return LDAP_SUCCESS;
2969 int caseIgnoreIA5SubstringsFilter(
2974 struct berval *prefix,
2976 struct berval ***keysp )
2978 SubstringsAssertion *sa = assertValue;
2980 ber_len_t nkeys = 0;
2981 size_t slen, mlen, klen;
2982 struct berval **keys;
2983 lutil_MD5_CTX MD5context;
2984 unsigned char MD5digest[LUTIL_MD5_BYTES];
2985 struct berval *value;
2986 struct berval digest;
2988 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2989 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2994 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2996 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2997 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2998 /* don't bother accounting for stepping */
2999 nkeys += sa->sa_any[i]->bv_len -
3000 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3005 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3006 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3013 return LDAP_SUCCESS;
3016 digest.bv_val = MD5digest;
3017 digest.bv_len = sizeof(MD5digest);
3019 slen = strlen( syntax->ssyn_oid );
3020 mlen = strlen( mr->smr_oid );
3022 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3025 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3026 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3028 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3029 value = ber_bvdup( sa->sa_initial );
3030 ldap_pvt_str2upper( value->bv_val );
3032 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3033 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3035 lutil_MD5Init( &MD5context );
3036 if( prefix != NULL && prefix->bv_len > 0 ) {
3037 lutil_MD5Update( &MD5context,
3038 prefix->bv_val, prefix->bv_len );
3040 lutil_MD5Update( &MD5context,
3041 &pre, sizeof( pre ) );
3042 lutil_MD5Update( &MD5context,
3043 syntax->ssyn_oid, slen );
3044 lutil_MD5Update( &MD5context,
3045 mr->smr_oid, mlen );
3046 lutil_MD5Update( &MD5context,
3047 value->bv_val, klen );
3048 lutil_MD5Final( MD5digest, &MD5context );
3050 ber_bvfree( value );
3051 keys[nkeys++] = ber_bvdup( &digest );
3054 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3056 pre = SLAP_INDEX_SUBSTR_PREFIX;
3057 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3059 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3060 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3064 value = ber_bvdup( sa->sa_any[i] );
3065 ldap_pvt_str2upper( value->bv_val );
3068 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3069 j += SLAP_INDEX_SUBSTR_STEP )
3071 lutil_MD5Init( &MD5context );
3072 if( prefix != NULL && prefix->bv_len > 0 ) {
3073 lutil_MD5Update( &MD5context,
3074 prefix->bv_val, prefix->bv_len );
3076 lutil_MD5Update( &MD5context,
3077 &pre, sizeof( pre ) );
3078 lutil_MD5Update( &MD5context,
3079 syntax->ssyn_oid, slen );
3080 lutil_MD5Update( &MD5context,
3081 mr->smr_oid, mlen );
3082 lutil_MD5Update( &MD5context,
3083 &value->bv_val[j], klen );
3084 lutil_MD5Final( MD5digest, &MD5context );
3086 keys[nkeys++] = ber_bvdup( &digest );
3089 ber_bvfree( value );
3093 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3094 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3096 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3097 value = ber_bvdup( sa->sa_final );
3098 ldap_pvt_str2upper( value->bv_val );
3100 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3101 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3103 lutil_MD5Init( &MD5context );
3104 if( prefix != NULL && prefix->bv_len > 0 ) {
3105 lutil_MD5Update( &MD5context,
3106 prefix->bv_val, prefix->bv_len );
3108 lutil_MD5Update( &MD5context,
3109 &pre, sizeof( pre ) );
3110 lutil_MD5Update( &MD5context,
3111 syntax->ssyn_oid, slen );
3112 lutil_MD5Update( &MD5context,
3113 mr->smr_oid, mlen );
3114 lutil_MD5Update( &MD5context,
3115 &value->bv_val[value->bv_len-klen], klen );
3116 lutil_MD5Final( MD5digest, &MD5context );
3118 ber_bvfree( value );
3119 keys[nkeys++] = ber_bvdup( &digest );
3130 return LDAP_SUCCESS;
3134 numericStringNormalize(
3137 struct berval **normalized )
3139 /* similiar to IA5StringNormalize except removes all spaces */
3140 struct berval *newval;
3143 newval = ch_malloc( sizeof( struct berval ) );
3147 /* Ignore initial whitespace */
3148 while ( ASCII_SPACE( *p ) ) {
3154 return LDAP_INVALID_SYNTAX;
3157 newval->bv_val = ch_strdup( p );
3158 p = q = newval->bv_val;
3161 if ( ASCII_SPACE( *p ) ) {
3162 /* Ignore whitespace */
3169 assert( *newval->bv_val );
3170 assert( newval->bv_val < p );
3173 /* cannot start with a space */
3174 assert( !ASCII_SPACE(*newval->bv_val) );
3176 /* cannot end with a space */
3177 assert( !ASCII_SPACE( q[-1] ) );
3179 /* null terminate */
3182 newval->bv_len = q - newval->bv_val;
3183 *normalized = newval;
3185 return LDAP_SUCCESS;
3189 objectIdentifierFirstComponentMatch(
3194 struct berval *value,
3195 void *assertedValue )
3197 int rc = LDAP_SUCCESS;
3199 struct berval *asserted = (struct berval *) assertedValue;
3203 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3204 return LDAP_INVALID_SYNTAX;
3207 /* trim leading white space */
3208 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3212 /* grab next word */
3213 oid.bv_val = &value->bv_val[i];
3214 oid.bv_len = value->bv_len - i;
3215 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3220 /* insert attributeTypes, objectclass check here */
3221 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3222 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3225 char *stored = ch_malloc( oid.bv_len + 1 );
3226 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3227 stored[oid.bv_len] = '\0';
3229 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3230 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3231 MatchingRule *stored_mr = mr_find( stored );
3233 if( asserted_mr == NULL ) {
3234 rc = SLAPD_COMPARE_UNDEFINED;
3236 match = asserted_mr != stored_mr;
3239 } else if ( !strcmp( syntax->ssyn_oid,
3240 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3242 AttributeType *asserted_at = at_find( asserted->bv_val );
3243 AttributeType *stored_at = at_find( stored );
3245 if( asserted_at == NULL ) {
3246 rc = SLAPD_COMPARE_UNDEFINED;
3248 match = asserted_at != stored_at;
3251 } else if ( !strcmp( syntax->ssyn_oid,
3252 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3254 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3255 ObjectClass *stored_oc = oc_find( stored );
3257 if( asserted_oc == NULL ) {
3258 rc = SLAPD_COMPARE_UNDEFINED;
3260 match = asserted_oc != stored_oc;
3267 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3268 "%d\n\t\"%s\"\n\t\"%s\"\n",
3269 match, value->bv_val, asserted->bv_val );
3271 if( rc == LDAP_SUCCESS ) *matchp = match;
3276 check_time_syntax (struct berval *val,
3280 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3281 static int mdays[2][12] = {
3282 /* non-leap years */
3283 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3285 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3288 int part, c, tzoffset, leapyear = 0 ;
3290 if( val->bv_len == 0 ) {
3291 return LDAP_INVALID_SYNTAX;
3294 p = (char *)val->bv_val;
3295 e = p + val->bv_len;
3297 /* Ignore initial whitespace */
3298 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3302 if (e - p < 13 - (2 * start)) {
3303 return LDAP_INVALID_SYNTAX;
3306 for (part = 0; part < 9; part++) {
3310 for (part = start; part < 7; part++) {
3312 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3319 return LDAP_INVALID_SYNTAX;
3321 if (c < 0 || c > 9) {
3322 return LDAP_INVALID_SYNTAX;
3328 return LDAP_INVALID_SYNTAX;
3330 if (c < 0 || c > 9) {
3331 return LDAP_INVALID_SYNTAX;
3336 if (part == 2 || part == 3) {
3339 if (parts[part] < 0) {
3340 return LDAP_INVALID_SYNTAX;
3342 if (parts[part] > ceiling[part]) {
3343 return LDAP_INVALID_SYNTAX;
3347 /* leapyear check for the Gregorian calendar (year>1581) */
3348 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3349 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3354 if (parts[3] > mdays[leapyear][parts[2]]) {
3355 return LDAP_INVALID_SYNTAX;
3360 tzoffset = 0; /* UTC */
3361 } else if (c != '+' && c != '-') {
3362 return LDAP_INVALID_SYNTAX;
3366 } else /* c == '+' */ {
3371 return LDAP_INVALID_SYNTAX;
3374 for (part = 7; part < 9; part++) {
3376 if (c < 0 || c > 9) {
3377 return LDAP_INVALID_SYNTAX;
3382 if (c < 0 || c > 9) {
3383 return LDAP_INVALID_SYNTAX;
3387 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3388 return LDAP_INVALID_SYNTAX;
3393 /* Ignore trailing whitespace */
3394 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3398 return LDAP_INVALID_SYNTAX;
3401 switch ( tzoffset ) {
3402 case -1: /* negativ offset to UTC, ie west of Greenwich */
3403 parts[4] += parts[7];
3404 parts[5] += parts[8];
3405 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3409 c = mdays[leapyear][parts[2]];
3411 if (parts[part] > c) {
3412 parts[part] -= c + 1;
3417 case 1: /* positive offset to UTC, ie east of Greenwich */
3418 parts[4] -= parts[7];
3419 parts[5] -= parts[8];
3420 for (part = 6; --part > 0; ) {
3424 /* first arg to % needs to be non negativ */
3425 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3427 if (parts[part] < 0) {
3428 parts[part] += c + 1;
3433 case 0: /* already UTC */
3437 return LDAP_SUCCESS;
3444 struct berval **normalized )
3449 rc = check_time_syntax(val, 1, parts);
3450 if (rc != LDAP_SUCCESS) {
3455 out = ch_malloc( sizeof(struct berval) );
3457 return LBER_ERROR_MEMORY;
3460 out->bv_val = ch_malloc( 14 );
3461 if ( out->bv_val == NULL ) {
3463 return LBER_ERROR_MEMORY;
3466 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3467 parts[1], parts[2] + 1, parts[3] + 1,
3468 parts[4], parts[5], parts[6] );
3472 return LDAP_SUCCESS;
3482 return check_time_syntax(in, 1, parts);
3486 generalizedTimeValidate(
3492 return check_time_syntax(in, 0, parts);
3496 generalizedTimeNormalize(
3499 struct berval **normalized )
3504 rc = check_time_syntax(val, 0, parts);
3505 if (rc != LDAP_SUCCESS) {
3510 out = ch_malloc( sizeof(struct berval) );
3512 return LBER_ERROR_MEMORY;
3515 out->bv_val = ch_malloc( 16 );
3516 if ( out->bv_val == NULL ) {
3518 return LBER_ERROR_MEMORY;
3521 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3522 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3523 parts[4], parts[5], parts[6] );
3527 return LDAP_SUCCESS;
3531 nisNetgroupTripleValidate(
3533 struct berval *val )
3538 if ( val->bv_len == 0 ) {
3539 return LDAP_INVALID_SYNTAX;
3542 p = (char *)val->bv_val;
3543 e = p + val->bv_len;
3546 /* syntax does not allow leading white space */
3547 /* Ignore initial whitespace */
3548 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3553 if ( *p != '(' /*')'*/ ) {
3554 return LDAP_INVALID_SYNTAX;
3557 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3561 return LDAP_INVALID_SYNTAX;
3564 } else if ( !ATTR_CHAR( *p ) ) {
3565 return LDAP_INVALID_SYNTAX;
3569 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3570 return LDAP_INVALID_SYNTAX;
3576 /* syntax does not allow trailing white space */
3577 /* Ignore trailing whitespace */
3578 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3584 return LDAP_INVALID_SYNTAX;
3587 return LDAP_SUCCESS;
3591 bootParameterValidate(
3593 struct berval *val )
3597 if ( val->bv_len == 0 ) {
3598 return LDAP_INVALID_SYNTAX;
3601 p = (char *)val->bv_val;
3602 e = p + val->bv_len;
3605 for (; ( p < e ) && ( *p != '=' ); p++ ) {
3606 if ( !ATTR_CHAR( *p ) ) {
3607 return LDAP_INVALID_SYNTAX;
3612 return LDAP_INVALID_SYNTAX;
3616 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
3617 if ( !ATTR_CHAR( *p ) ) {
3618 return LDAP_INVALID_SYNTAX;
3623 return LDAP_INVALID_SYNTAX;
3627 for ( p++; p < e; p++ ) {
3628 if ( !ATTR_CHAR( *p ) ) {
3629 return LDAP_INVALID_SYNTAX;
3633 return LDAP_SUCCESS;
3636 struct syntax_defs_rec {
3639 slap_syntax_validate_func *sd_validate;
3640 slap_syntax_transform_func *sd_normalize;
3641 slap_syntax_transform_func *sd_pretty;
3642 #ifdef SLAPD_BINARY_CONVERSION
3643 slap_syntax_transform_func *sd_ber2str;
3644 slap_syntax_transform_func *sd_str2ber;
3648 #define X_HIDE "X-HIDE 'TRUE' "
3649 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
3650 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
3652 struct syntax_defs_rec syntax_defs[] = {
3653 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
3654 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
3655 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
3656 0, NULL, NULL, NULL},
3657 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
3658 0, NULL, NULL, NULL},
3659 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
3660 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3661 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
3662 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3663 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
3664 0, bitStringValidate, bitStringNormalize, NULL },
3665 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
3666 0, booleanValidate, NULL, NULL},
3667 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
3668 X_BINARY X_NOT_H_R ")",
3669 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3670 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
3671 X_BINARY X_NOT_H_R ")",
3672 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3673 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
3674 X_BINARY X_NOT_H_R ")",
3675 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3676 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
3677 0, NULL, NULL, NULL},
3678 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
3679 0, dnValidate, dnNormalize, dnPretty},
3680 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
3681 0, NULL, NULL, NULL},
3682 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
3683 0, NULL, NULL, NULL},
3684 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
3685 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3686 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
3687 0, NULL, NULL, NULL},
3688 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
3689 0, NULL, NULL, NULL},
3690 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
3691 0, NULL, NULL, NULL},
3692 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
3693 0, NULL, NULL, NULL},
3694 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
3695 0, NULL, NULL, NULL},
3696 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
3697 0, IA5StringValidate, faxNumberNormalize, NULL},
3698 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
3699 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
3700 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
3701 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
3702 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
3703 0, NULL, NULL, NULL},
3704 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
3705 0, IA5StringValidate, IA5StringNormalize, NULL},
3706 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
3707 0, integerValidate, integerNormalize, integerPretty},
3708 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
3709 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3710 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
3711 0, NULL, NULL, NULL},
3712 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
3713 0, NULL, NULL, NULL},
3714 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
3715 0, NULL, NULL, NULL},
3716 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
3717 0, NULL, NULL, NULL},
3718 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
3719 0, NULL, NULL, NULL},
3720 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
3721 0, nameUIDValidate, nameUIDNormalize, nameUIDPretty},
3722 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
3723 0, NULL, NULL, NULL},
3724 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
3725 0, IA5StringValidate, numericStringNormalize, NULL},
3726 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
3727 0, NULL, NULL, NULL},
3728 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
3729 0, oidValidate, NULL, NULL},
3730 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
3731 0, NULL, NULL, NULL},
3732 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
3733 0, blobValidate, NULL, NULL},
3734 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
3735 0, blobValidate, NULL, NULL},
3736 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
3737 0, NULL, NULL, NULL},
3738 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
3739 0, NULL, NULL, NULL},
3740 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
3741 0, printableStringValidate, NULL, NULL},
3742 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
3743 X_BINARY X_NOT_H_R ")",
3744 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3745 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
3746 0, IA5StringValidate, phoneNumberNormalize, NULL},
3747 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
3748 0, NULL, NULL, NULL},
3749 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
3750 0, IA5StringValidate, telexNumberNormalize, NULL},
3751 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
3752 0, utcTimeValidate, utcTimeNormalize, NULL},
3753 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
3754 0, NULL, NULL, NULL},
3755 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
3756 0, NULL, NULL, NULL},
3757 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
3758 0, NULL, NULL, NULL},
3759 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
3760 0, NULL, NULL, NULL},
3761 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
3762 0, NULL, NULL, NULL},
3764 /* RFC 2307 NIS Syntaxes */
3765 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Triple' )",
3766 0, nisNetgroupTripleValidate, NULL, NULL},
3767 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
3768 0, bootParameterValidate, NULL, NULL},
3770 /* OpenLDAP Experimental Syntaxes */
3771 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
3772 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
3774 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
3775 0, NULL, NULL, NULL},
3777 /* OpenLDAP Void Syntax */
3778 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' " X_HIDE ")" ,
3779 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
3780 {NULL, 0, NULL, NULL, NULL}
3783 struct mrule_defs_rec {
3785 slap_mask_t mrd_usage;
3786 slap_mr_convert_func * mrd_convert;
3787 slap_mr_normalize_func * mrd_normalize;
3788 slap_mr_match_func * mrd_match;
3789 slap_mr_indexer_func * mrd_indexer;
3790 slap_mr_filter_func * mrd_filter;
3792 char * mrd_associated;
3796 * Other matching rules in X.520 that we do not use (yet):
3798 * 2.5.13.9 numericStringOrderingMatch
3799 * 2.5.13.13 booleanMatch
3800 * 2.5.13.15 integerOrderingMatch
3801 * 2.5.13.18 octetStringOrderingMatch
3802 * 2.5.13.19 octetStringSubstringsMatch
3803 * 2.5.13.25 uTCTimeMatch
3804 * 2.5.13.26 uTCTimeOrderingMatch
3805 * 2.5.13.31 directoryStringFirstComponentMatch
3806 * 2.5.13.32 wordMatch
3807 * 2.5.13.33 keywordMatch
3808 * 2.5.13.34 certificateExactMatch
3809 * 2.5.13.35 certificateMatch
3810 * 2.5.13.36 certificatePairExactMatch
3811 * 2.5.13.37 certificatePairMatch
3812 * 2.5.13.38 certificateListExactMatch
3813 * 2.5.13.39 certificateListMatch
3814 * 2.5.13.40 algorithmIdentifierMatch
3815 * 2.5.13.41 storedPrefixMatch
3816 * 2.5.13.42 attributeCertificateMatch
3817 * 2.5.13.43 readerAndKeyIDMatch
3818 * 2.5.13.44 attributeIntegrityMatch
3821 struct mrule_defs_rec mrule_defs[] = {
3823 * EQUALITY matching rules must be listed after associated APPROX
3824 * matching rules. So, we list all APPROX matching rules first.
3826 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
3827 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3828 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3830 directoryStringApproxMatch, NULL, NULL,
3833 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
3834 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3835 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3837 IA5StringApproxMatch, NULL, NULL,
3841 * Other matching rules
3844 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
3845 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3846 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3848 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
3851 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
3852 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
3853 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3855 dnMatch, dnIndexer, dnFilter,
3858 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
3859 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3860 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3862 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
3863 directoryStringApproxMatchOID },
3865 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
3866 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3869 caseIgnoreOrderingMatch, NULL, NULL,
3872 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
3873 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3874 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3876 caseIgnoreSubstringsMatch,
3877 caseIgnoreSubstringsIndexer,
3878 caseIgnoreSubstringsFilter,
3881 {"( 2.5.13.5 NAME 'caseExactMatch' "
3882 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3883 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3885 caseExactMatch, caseExactIndexer, caseExactFilter,
3886 directoryStringApproxMatchOID },
3888 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
3889 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3892 caseExactOrderingMatch, NULL, NULL,
3895 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
3896 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3897 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3899 caseExactSubstringsMatch,
3900 caseExactSubstringsIndexer,
3901 caseExactSubstringsFilter,
3904 {"( 2.5.13.8 NAME 'numericStringMatch' "
3905 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
3906 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3908 caseIgnoreIA5Match, NULL, NULL,
3911 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
3912 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3913 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3915 caseIgnoreIA5SubstringsMatch,
3916 caseIgnoreIA5SubstringsIndexer,
3917 caseIgnoreIA5SubstringsFilter,
3920 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
3921 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
3922 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3924 caseIgnoreListMatch, NULL, NULL,
3927 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
3928 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3929 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3931 caseIgnoreListSubstringsMatch, NULL, NULL,
3934 {"( 2.5.13.13 NAME 'booleanMatch' "
3935 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
3936 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3938 booleanMatch, NULL, NULL,
3941 {"( 2.5.13.14 NAME 'integerMatch' "
3942 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
3943 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3945 integerMatch, integerIndexer, integerFilter,
3948 {"( 2.5.13.16 NAME 'bitStringMatch' "
3949 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
3950 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3952 bitStringMatch, NULL, NULL,
3955 {"( 2.5.13.17 NAME 'octetStringMatch' "
3956 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
3957 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3959 octetStringMatch, octetStringIndexer, octetStringFilter,
3962 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
3963 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
3964 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3966 telephoneNumberMatch, NULL, NULL,
3969 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
3970 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3971 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3973 telephoneNumberSubstringsMatch, NULL, NULL,
3976 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
3977 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
3978 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3980 presentationAddressMatch, NULL, NULL,
3983 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
3984 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
3985 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3987 uniqueMemberMatch, NULL, NULL,
3990 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
3991 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
3992 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3994 protocolInformationMatch, NULL, NULL,
3997 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
3998 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
3999 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4001 generalizedTimeMatch, NULL, NULL,
4004 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4005 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4008 generalizedTimeOrderingMatch, NULL, NULL,
4011 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4012 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4013 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4015 integerFirstComponentMatch, NULL, NULL,
4018 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4019 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4020 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4022 objectIdentifierFirstComponentMatch, NULL, NULL,
4025 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4026 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4027 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4029 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4030 IA5StringApproxMatchOID },
4032 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4033 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4034 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4036 caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4037 IA5StringApproxMatchOID },
4039 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4040 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4043 caseIgnoreIA5SubstringsMatch,
4044 caseIgnoreIA5SubstringsIndexer,
4045 caseIgnoreIA5SubstringsFilter,
4048 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4049 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4052 caseExactIA5SubstringsMatch,
4053 caseExactIA5SubstringsIndexer,
4054 caseExactIA5SubstringsFilter,
4057 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4058 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4061 authPasswordMatch, NULL, NULL,
4064 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4065 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4068 OpenLDAPaciMatch, NULL, NULL,
4071 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4080 /* we should only be called once (from main) */
4081 assert( schema_init_done == 0 );
4083 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4084 res = register_syntax( syntax_defs[i].sd_desc,
4085 syntax_defs[i].sd_flags,
4086 syntax_defs[i].sd_validate,
4087 syntax_defs[i].sd_normalize,
4088 syntax_defs[i].sd_pretty
4089 #ifdef SLAPD_BINARY_CONVERSION
4091 syntax_defs[i].sd_ber2str,
4092 syntax_defs[i].sd_str2ber
4097 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4098 syntax_defs[i].sd_desc );
4103 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4104 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4106 "schema_init: Ingoring unusable matching rule %s\n",
4107 mrule_defs[i].mrd_desc );
4111 res = register_matching_rule(
4112 mrule_defs[i].mrd_desc,
4113 mrule_defs[i].mrd_usage,
4114 mrule_defs[i].mrd_convert,
4115 mrule_defs[i].mrd_normalize,
4116 mrule_defs[i].mrd_match,
4117 mrule_defs[i].mrd_indexer,
4118 mrule_defs[i].mrd_filter,
4119 mrule_defs[i].mrd_associated );
4123 "schema_init: Error registering matching rule %s\n",
4124 mrule_defs[i].mrd_desc );
4128 schema_init_done = 1;
4129 return LDAP_SUCCESS;