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>
22 #include "lutil_md5.h"
23 /* We should replace MD5 with a faster hash */
24 #define HASH_BYTES LUTIL_MD5_BYTES
25 #define HASH_CONTEXT lutil_MD5_CTX
26 #define HASH_Init(c) lutil_MD5Init(c)
27 #define HASH_Update(c,buf,len) lutil_MD5Update(c,buf,len)
28 #define HASH_Final(d,c) lutil_MD5Final(d,c)
30 #include "lutil_hash.h"
31 /* We should replace MD5 with a faster hash */
32 #define HASH_BYTES LUTIL_HASH_BYTES
33 #define HASH_CONTEXT lutil_HASH_CTX
34 #define HASH_Init(c) lutil_HASHInit(c)
35 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
36 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
39 /* recycled validatation routines */
40 #define berValidate blobValidate
42 /* unimplemented pretters */
44 #define integerPretty NULL
46 /* recycled matching routines */
47 #define bitStringMatch octetStringMatch
48 #define integerMatch caseIgnoreIA5Match
49 #define numericStringMatch caseIgnoreIA5Match
50 #define objectIdentifierMatch caseIgnoreIA5Match
51 #define telephoneNumberMatch caseIgnoreIA5Match
52 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
53 #define generalizedTimeMatch caseIgnoreIA5Match
54 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
55 #define uniqueMemberMatch dnMatch
57 /* approx matching rules */
58 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
59 #define directoryStringApproxMatch approxMatch
60 #define directoryStringApproxIndexer approxIndexer
61 #define directoryStringApproxFilter approxFilter
62 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
63 #define IA5StringApproxMatch approxMatch
64 #define IA5StringApproxIndexer approxIndexer
65 #define IA5StringApproxFilter approxFilter
67 /* orderring matching rules */
68 #define caseIgnoreOrderingMatch caseIgnoreMatch
69 #define caseExactOrderingMatch caseExactMatch
71 /* unimplemented matching routines */
72 #define caseIgnoreListMatch NULL
73 #define caseIgnoreListSubstringsMatch NULL
74 #define protocolInformationMatch NULL
75 #define integerFirstComponentMatch NULL
77 #define OpenLDAPaciMatch NULL
78 #define authPasswordMatch NULL
80 /* recycled indexing/filtering routines */
81 #define dnIndexer caseIgnoreIndexer
82 #define dnFilter caseIgnoreFilter
83 #define integerIndexer caseIgnoreIA5Indexer
84 #define integerFilter caseIgnoreIA5Filter
86 #define telephoneNumberIndexer caseIgnoreIA5Indexer
87 #define telephoneNumberFilter caseIgnoreIA5Filter
88 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
89 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
91 static char *strcasechr( const char *str, int c )
93 char *lower = strchr( str, TOLOWER(c) );
94 char *upper = strchr( str, TOUPPER(c) );
96 if( lower && upper ) {
97 return lower < upper ? lower : upper;
111 struct berval *value,
112 void *assertedValue )
114 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
117 match = memcmp( value->bv_val,
118 ((struct berval *) assertedValue)->bv_val,
126 /* Index generation function */
127 int octetStringIndexer(
132 struct berval *prefix,
133 struct berval **values,
134 struct berval ***keysp )
138 struct berval **keys;
139 HASH_CONTEXT HASHcontext;
140 unsigned char HASHdigest[HASH_BYTES];
141 struct berval digest;
142 digest.bv_val = HASHdigest;
143 digest.bv_len = sizeof(HASHdigest);
145 /* we should have at least one value at this point */
146 assert( values != NULL && values[0] != NULL );
148 for( i=0; values[i] != NULL; i++ ) {
149 /* just count them */
152 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
154 slen = strlen( syntax->ssyn_oid );
155 mlen = strlen( mr->smr_oid );
157 for( i=0; values[i] != NULL; i++ ) {
158 HASH_Init( &HASHcontext );
159 if( prefix != NULL && prefix->bv_len > 0 ) {
160 HASH_Update( &HASHcontext,
161 prefix->bv_val, prefix->bv_len );
163 HASH_Update( &HASHcontext,
164 syntax->ssyn_oid, slen );
165 HASH_Update( &HASHcontext,
167 HASH_Update( &HASHcontext,
168 values[i]->bv_val, values[i]->bv_len );
169 HASH_Final( HASHdigest, &HASHcontext );
171 keys[i] = ber_bvdup( &digest );
181 /* Index generation function */
182 int octetStringFilter(
187 struct berval *prefix,
189 struct berval ***keysp )
192 struct berval **keys;
193 HASH_CONTEXT HASHcontext;
194 unsigned char HASHdigest[HASH_BYTES];
195 struct berval *value = (struct berval *) assertValue;
196 struct berval digest;
197 digest.bv_val = HASHdigest;
198 digest.bv_len = sizeof(HASHdigest);
200 slen = strlen( syntax->ssyn_oid );
201 mlen = strlen( mr->smr_oid );
203 keys = ch_malloc( sizeof( struct berval * ) * 2 );
205 HASH_Init( &HASHcontext );
206 if( prefix != NULL && prefix->bv_len > 0 ) {
207 HASH_Update( &HASHcontext,
208 prefix->bv_val, prefix->bv_len );
210 HASH_Update( &HASHcontext,
211 syntax->ssyn_oid, slen );
212 HASH_Update( &HASHcontext,
214 HASH_Update( &HASHcontext,
215 value->bv_val, value->bv_len );
216 HASH_Final( HASHdigest, &HASHcontext );
218 keys[0] = ber_bvdup( &digest );
234 if( in->bv_len == 0 ) return LDAP_SUCCESS;
236 dn = ch_strdup( in->bv_val );
238 rc = dn_validate( dn ) == NULL
239 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
249 struct berval **normalized )
253 if ( val->bv_len != 0 ) {
255 #ifdef USE_DN_NORMALIZE
256 out = ber_bvstr( UTF8normalize( val->bv_val, UTF8_CASEFOLD ) );
258 out = ber_bvdup( val );
259 ldap_pvt_str2upper( out->bv_val );
261 dn = dn_validate( out->bv_val );
265 return LDAP_INVALID_SYNTAX;
269 out->bv_len = strlen( dn );
271 out = ber_bvdup( val );
284 struct berval *value,
285 void *assertedValue )
288 struct berval *asserted = (struct berval *) assertedValue;
290 match = value->bv_len - asserted->bv_len;
293 #ifdef USE_DN_NORMALIZE
294 match = strcmp( value->bv_val, asserted->bv_val );
296 match = strcasecmp( value->bv_val, asserted->bv_val );
301 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
302 "dnMatch: %d\n %s\n %s\n", match,
303 value->bv_val, asserted->bv_val ));
305 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
306 match, value->bv_val, asserted->bv_val );
322 if( in->bv_len == 0 ) return LDAP_SUCCESS;
324 dn = ber_bvdup( in );
326 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
327 /* assume presence of optional UID */
330 for(i=dn->bv_len-2; i>2; i--) {
331 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
335 if( dn->bv_val[i] != '\'' ) {
336 return LDAP_INVALID_SYNTAX;
338 if( dn->bv_val[i-1] != 'B' ) {
339 return LDAP_INVALID_SYNTAX;
341 if( dn->bv_val[i-2] != '#' ) {
342 return LDAP_INVALID_SYNTAX;
345 /* trim the UID to allow use of dn_validate */
346 dn->bv_val[i-2] = '\0';
349 rc = dn_validate( dn->bv_val ) == NULL
350 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
360 struct berval **normalized )
362 struct berval *out = ber_bvdup( val );
364 if( out->bv_len != 0 ) {
368 ber_len_t uidlen = 0;
370 if( out->bv_val[out->bv_len-1] == '\'' ) {
371 /* assume presence of optional UID */
372 uid = strrchr( out->bv_val, '#' );
376 return LDAP_INVALID_SYNTAX;
379 uidlen = out->bv_len - (out->bv_val - uid);
380 /* temporarily trim the UID */
384 #ifdef USE_DN_NORMALIZE
385 dn = dn_normalize( out->bv_val );
387 dn = dn_validate( out->bv_val );
392 return LDAP_INVALID_SYNTAX;
398 /* restore the separator */
401 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
405 out->bv_len = dnlen + uidlen;
417 /* any value allowed */
426 /* any value allowed */
437 /* very unforgiving validation, requires no normalization
438 * before simplistic matching
440 if( in->bv_len < 3 ) {
441 return LDAP_INVALID_SYNTAX;
443 if( in->bv_val[0] != 'B' ||
444 in->bv_val[1] != '\'' ||
445 in->bv_val[in->bv_len-1] != '\'' )
447 return LDAP_INVALID_SYNTAX;
450 for( i=in->bv_len-2; i>1; i-- ) {
451 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
452 return LDAP_INVALID_SYNTAX;
460 * Handling boolean syntax and matching is quite rigid.
461 * A more flexible approach would be to allow a variety
462 * of strings to be normalized and prettied into TRUE
470 /* very unforgiving validation, requires no normalization
471 * before simplistic matching
474 if( in->bv_len == 4 ) {
475 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
478 } else if( in->bv_len == 5 ) {
479 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
484 return LDAP_INVALID_SYNTAX;
493 struct berval *value,
494 void *assertedValue )
496 /* simplistic matching allowed by rigid validation */
497 struct berval *asserted = (struct berval *) assertedValue;
498 *matchp = value->bv_len != asserted->bv_len;
503 /* case insensitive UTF8 strncmp with offset for second string */
506 struct berval *right,
514 ldap_unicode_t ru, lu;
515 ldap_unicode_t ruu, luu;
517 rslen = len < right->bv_len ? len : right->bv_len;
518 lslen = len + offset < left->bv_len ? len : left->bv_len;
520 for( r = 0, l = offset;
521 r < rslen && l < lslen;
525 * XXYYZ: we convert to ucs4 even though -llunicode
526 * expects ucs2 in an unsigned long
528 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
529 if( ru == LDAP_UCS4_INVALID ) {
533 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
534 if( lu == LDAP_UCS4_INVALID ) {
538 ruu = uctoupper( ru );
539 luu = uctoupper( lu );
543 } else if( luu > ruu ) {
547 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
548 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
564 static char *UTF8casechr( const char *str, const char *c )
566 char *p, *lower, *upper;
567 ldap_ucs4_t tch, ch = ldap_utf8_to_ucs4(c);
569 tch = uctolower ( ch );
570 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
571 if( ldap_utf8_to_ucs4( p ) == tch ) {
575 lower = *p != '\0' ? p : NULL;
577 tch = uctoupper ( ch );
578 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
579 if( ldap_utf8_to_ucs4( p ) == tch ) {
583 upper = *p != '\0' ? p : NULL;
585 if( lower && upper ) {
586 return lower < upper ? lower : upper;
587 } else if ( lower ) {
602 unsigned char *u = in->bv_val;
604 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
606 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
607 /* get the length indicated by the first byte */
608 len = LDAP_UTF8_CHARLEN( u );
610 /* should not be zero */
611 if( len == 0 ) return LDAP_INVALID_SYNTAX;
613 /* make sure len corresponds with the offset
614 to the next character */
615 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
618 if( count != 0 ) return LDAP_INVALID_SYNTAX;
627 struct berval **normalized )
629 struct berval *newval;
632 newval = ch_malloc( sizeof( struct berval ) );
636 /* Ignore initial whitespace */
637 while ( ldap_utf8_isspace( p ) ) {
643 return LDAP_INVALID_SYNTAX;
646 newval->bv_val = ch_strdup( p );
647 p = q = newval->bv_val;
653 if ( ldap_utf8_isspace( p ) ) {
654 len = LDAP_UTF8_COPY(q,p);
659 /* Ignore the extra whitespace */
660 while ( ldap_utf8_isspace( p ) ) {
664 len = LDAP_UTF8_COPY(q,p);
671 assert( *newval->bv_val );
672 assert( newval->bv_val < p );
675 /* cannot start with a space */
676 assert( !ldap_utf8_isspace(newval->bv_val) );
679 * If the string ended in space, backup the pointer one
680 * position. One is enough because the above loop collapsed
681 * all whitespace to a single space.
688 /* cannot end with a space */
689 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
694 newval->bv_len = q - newval->bv_val;
695 *normalized = newval;
700 #if defined(SLAPD_APPROX_MULTISTRING)
702 #if defined(SLAPD_APPROX_INITIALS)
703 #define SLAPD_APPROX_DELIMITER "._ "
704 #define SLAPD_APPROX_WORDLEN 2
706 #define SLAPD_APPROX_DELIMITER " "
707 #define SLAPD_APPROX_WORDLEN 1
716 struct berval *value,
717 void *assertedValue )
719 char *val, *assertv, **values, **words, *c;
720 int i, count, len, nextchunk=0, nextavail=0;
723 /* Isolate how many words there are */
724 val = ch_strdup( value->bv_val );
725 for( c=val,count=1; *c; c++ ) {
726 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
727 if ( c == NULL ) break;
732 /* Get a phonetic copy of each word */
733 words = (char **)ch_malloc( count * sizeof(char *) );
734 values = (char **)ch_malloc( count * sizeof(char *) );
735 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
737 values[i] = phonetic(c);
741 /* Work through the asserted value's words, to see if at least some
742 of the words are there, in the same order. */
743 assertv = ch_strdup( ((struct berval *)assertedValue)->bv_val );
745 while ( nextchunk < ((struct berval *)assertedValue)->bv_len ) {
746 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
751 #if defined(SLAPD_APPROX_INITIALS)
752 else if( len == 1 ) {
753 /* Single letter words need to at least match one word's initial */
754 for( i=nextavail; i<count; i++ )
755 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
762 /* Isolate the next word in the asserted value and phonetic it */
763 assertv[nextchunk+len] = '\0';
764 val = phonetic( assertv + nextchunk );
766 /* See if this phonetic chunk is in the remaining words of *value */
767 for( i=nextavail; i<count; i++ ){
768 if( !strcmp( val, values[i] ) ){
775 /* This chunk in the asserted value was NOT within the *value. */
781 /* Go on to the next word in the asserted value */
785 /* If some of the words were seen, call it a match */
786 if( nextavail > 0 ) {
795 for( i=0; i<count; i++ ) {
796 ch_free( values[i] );
812 struct berval *prefix,
813 struct berval **values,
814 struct berval ***keysp )
817 int i,j, len, wordcount, keycount=0;
818 struct berval **newkeys, **keys=NULL;
821 for( j=0; values[j] != NULL; j++ ) {
823 /* Isolate how many words there are. There will be a key for each */
824 val = ch_strdup( values[j]->bv_val );
825 for( wordcount=0,c=val; *c; c++) {
826 len = strcspn(c, SLAPD_APPROX_DELIMITER);
827 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
829 if (*c == '\0') break;
833 /* Allocate/increase storage to account for new keys */
834 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
835 * sizeof(struct berval *) );
836 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
837 if( keys ) ch_free( keys );
840 /* Get a phonetic copy of each word */
841 for( c=val,i=0; i<wordcount; c+=len+1 ) {
843 if( len < SLAPD_APPROX_WORDLEN ) continue;
844 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
845 keys[keycount]->bv_val = phonetic( c );
846 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
853 keys[keycount] = NULL;
866 struct berval *prefix,
868 struct berval ***keysp )
872 struct berval **keys;
875 /* Isolate how many words there are. There will be a key for each */
876 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
877 for( count=0,c=val; *c; c++) {
878 len = strcspn(c, SLAPD_APPROX_DELIMITER);
879 if( len >= SLAPD_APPROX_WORDLEN ) count++;
881 if (*c == '\0') break;
885 /* Allocate storage for new keys */
886 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
888 /* Get a phonetic copy of each word */
889 for( c=val,i=0; i<count; c+=len+1 ) {
891 if( len < SLAPD_APPROX_WORDLEN ) continue;
892 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
893 keys[i]->bv_val = phonetic( c );
894 keys[i]->bv_len = strlen( keys[i]->bv_val );
908 /* No other form of Approximate Matching is defined */
916 struct berval *value,
917 void *assertedValue )
919 char *vapprox, *avapprox;
921 vapprox = phonetic( value->bv_val );
922 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
924 *matchp = strcmp( vapprox, avapprox );
938 struct berval *prefix,
939 struct berval **values,
940 struct berval ***keysp )
943 struct berval **keys;
946 for( i=0; values[i] != NULL; i++ ) {
947 /* just count them */
951 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
953 /* Copy each value and run it through phonetic() */
954 for( i=0; values[i] != NULL; i++ ) {
955 keys[i] = ch_malloc( sizeof( struct berval * ) );
956 keys[i]->bv_val = phonetic( values[i]->bv_val );
957 keys[i]->bv_len = strlen( keys[i]->bv_val );
972 struct berval *prefix,
974 struct berval ***keysp )
976 struct berval **keys;
979 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
981 /* Copy the value and run it through phonetic() */
982 keys[0] = ch_malloc( sizeof( struct berval * ) );
983 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
984 keys[0]->bv_len = strlen( keys[0]->bv_val );
999 struct berval *value,
1000 void *assertedValue )
1002 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1005 match = strncmp( value->bv_val,
1006 ((struct berval *) assertedValue)->bv_val,
1011 return LDAP_SUCCESS;
1015 caseExactSubstringsMatch(
1020 struct berval *value,
1021 void *assertedValue )
1024 SubstringsAssertion *sub = assertedValue;
1025 struct berval left = *value;
1029 /* Add up asserted input length */
1030 if( sub->sa_initial ) {
1031 inlen += sub->sa_initial->bv_len;
1034 for(i=0; sub->sa_any[i] != NULL; i++) {
1035 inlen += sub->sa_any[i]->bv_len;
1038 if( sub->sa_final ) {
1039 inlen += sub->sa_final->bv_len;
1042 if( sub->sa_initial ) {
1043 if( inlen > left.bv_len ) {
1048 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1049 sub->sa_initial->bv_len );
1055 left.bv_val += sub->sa_initial->bv_len;
1056 left.bv_len -= sub->sa_initial->bv_len;
1057 inlen -= sub->sa_initial->bv_len;
1060 if( sub->sa_final ) {
1061 if( inlen > left.bv_len ) {
1066 match = strncmp( sub->sa_final->bv_val,
1067 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1068 sub->sa_final->bv_len );
1074 left.bv_len -= sub->sa_final->bv_len;
1075 inlen -= sub->sa_final->bv_len;
1079 for(i=0; sub->sa_any[i]; i++) {
1084 if( inlen > left.bv_len ) {
1085 /* not enough length */
1090 if( sub->sa_any[i]->bv_len == 0 ) {
1094 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1101 idx = p - left.bv_val;
1102 assert( idx < left.bv_len );
1104 if( idx >= left.bv_len ) {
1105 /* this shouldn't happen */
1112 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1113 /* not enough left */
1118 match = strncmp( left.bv_val,
1119 sub->sa_any[i]->bv_val,
1120 sub->sa_any[i]->bv_len );
1128 left.bv_val += sub->sa_any[i]->bv_len;
1129 left.bv_len -= sub->sa_any[i]->bv_len;
1130 inlen -= sub->sa_any[i]->bv_len;
1136 return LDAP_SUCCESS;
1139 /* Index generation function */
1140 int caseExactIndexer(
1145 struct berval *prefix,
1146 struct berval **values,
1147 struct berval ***keysp )
1151 struct berval **keys;
1152 HASH_CONTEXT HASHcontext;
1153 unsigned char HASHdigest[HASH_BYTES];
1154 struct berval digest;
1155 digest.bv_val = HASHdigest;
1156 digest.bv_len = sizeof(HASHdigest);
1158 /* we should have at least one value at this point */
1159 assert( values != NULL && values[0] != NULL );
1161 for( i=0; values[i] != NULL; i++ ) {
1162 /* just count them */
1165 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1167 slen = strlen( syntax->ssyn_oid );
1168 mlen = strlen( mr->smr_oid );
1170 for( i=0; values[i] != NULL; i++ ) {
1171 struct berval *value;
1173 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
1178 HASH_Init( &HASHcontext );
1179 if( prefix != NULL && prefix->bv_len > 0 ) {
1180 HASH_Update( &HASHcontext,
1181 prefix->bv_val, prefix->bv_len );
1183 HASH_Update( &HASHcontext,
1184 syntax->ssyn_oid, slen );
1185 HASH_Update( &HASHcontext,
1186 mr->smr_oid, mlen );
1187 HASH_Update( &HASHcontext,
1188 value->bv_val, value->bv_len );
1189 HASH_Final( HASHdigest, &HASHcontext );
1192 ber_bvfree( value );
1195 keys[i] = ber_bvdup( &digest );
1200 return LDAP_SUCCESS;
1203 /* Index generation function */
1204 int caseExactFilter(
1209 struct berval *prefix,
1211 struct berval ***keysp )
1214 struct berval **keys;
1215 HASH_CONTEXT HASHcontext;
1216 unsigned char HASHdigest[HASH_BYTES];
1217 struct berval *value;
1218 struct berval digest;
1219 digest.bv_val = HASHdigest;
1220 digest.bv_len = sizeof(HASHdigest);
1222 slen = strlen( syntax->ssyn_oid );
1223 mlen = strlen( mr->smr_oid );
1226 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val, UTF8_NOCASEFOLD ) );
1228 value = (struct berval *) assertValue;
1231 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1233 HASH_Init( &HASHcontext );
1234 if( prefix != NULL && prefix->bv_len > 0 ) {
1235 HASH_Update( &HASHcontext,
1236 prefix->bv_val, prefix->bv_len );
1238 HASH_Update( &HASHcontext,
1239 syntax->ssyn_oid, slen );
1240 HASH_Update( &HASHcontext,
1241 mr->smr_oid, mlen );
1242 HASH_Update( &HASHcontext,
1243 value->bv_val, value->bv_len );
1244 HASH_Final( HASHdigest, &HASHcontext );
1246 keys[0] = ber_bvdup( &digest );
1250 ber_bvfree( value );
1254 return LDAP_SUCCESS;
1257 /* Substrings Index generation function */
1258 int caseExactSubstringsIndexer(
1263 struct berval *prefix,
1264 struct berval **values,
1265 struct berval ***keysp )
1269 struct berval **keys;
1270 HASH_CONTEXT HASHcontext;
1271 unsigned char HASHdigest[HASH_BYTES];
1272 struct berval digest;
1273 digest.bv_val = HASHdigest;
1274 digest.bv_len = sizeof(HASHdigest);
1276 /* we should have at least one value at this point */
1277 assert( values != NULL && values[0] != NULL );
1280 for( i=0; values[i] != NULL; i++ ) {
1281 /* count number of indices to generate */
1282 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1286 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1287 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1288 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1289 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1291 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1295 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1296 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1297 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1301 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1302 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1303 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1304 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1306 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1312 /* no keys to generate */
1314 return LDAP_SUCCESS;
1317 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1319 slen = strlen( syntax->ssyn_oid );
1320 mlen = strlen( mr->smr_oid );
1323 for( i=0; values[i] != NULL; i++ ) {
1325 struct berval *value;
1327 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1330 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
1335 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1336 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1338 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1339 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1341 for( j=0; j<max; j++ ) {
1342 HASH_Init( &HASHcontext );
1343 if( prefix != NULL && prefix->bv_len > 0 ) {
1344 HASH_Update( &HASHcontext,
1345 prefix->bv_val, prefix->bv_len );
1348 HASH_Update( &HASHcontext,
1349 &pre, sizeof( pre ) );
1350 HASH_Update( &HASHcontext,
1351 syntax->ssyn_oid, slen );
1352 HASH_Update( &HASHcontext,
1353 mr->smr_oid, mlen );
1354 HASH_Update( &HASHcontext,
1356 SLAP_INDEX_SUBSTR_MAXLEN );
1357 HASH_Final( HASHdigest, &HASHcontext );
1359 keys[nkeys++] = ber_bvdup( &digest );
1363 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1364 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1366 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1369 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1370 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1371 HASH_Init( &HASHcontext );
1372 if( prefix != NULL && prefix->bv_len > 0 ) {
1373 HASH_Update( &HASHcontext,
1374 prefix->bv_val, prefix->bv_len );
1376 HASH_Update( &HASHcontext,
1377 &pre, sizeof( pre ) );
1378 HASH_Update( &HASHcontext,
1379 syntax->ssyn_oid, slen );
1380 HASH_Update( &HASHcontext,
1381 mr->smr_oid, mlen );
1382 HASH_Update( &HASHcontext,
1384 HASH_Final( HASHdigest, &HASHcontext );
1386 keys[nkeys++] = ber_bvdup( &digest );
1389 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1390 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1391 HASH_Init( &HASHcontext );
1392 if( prefix != NULL && prefix->bv_len > 0 ) {
1393 HASH_Update( &HASHcontext,
1394 prefix->bv_val, prefix->bv_len );
1396 HASH_Update( &HASHcontext,
1397 &pre, sizeof( pre ) );
1398 HASH_Update( &HASHcontext,
1399 syntax->ssyn_oid, slen );
1400 HASH_Update( &HASHcontext,
1401 mr->smr_oid, mlen );
1402 HASH_Update( &HASHcontext,
1403 &value->bv_val[value->bv_len-j], j );
1404 HASH_Final( HASHdigest, &HASHcontext );
1406 keys[nkeys++] = ber_bvdup( &digest );
1412 ber_bvfree( value );
1425 return LDAP_SUCCESS;
1428 int caseExactSubstringsFilter(
1433 struct berval *prefix,
1435 struct berval ***keysp )
1437 SubstringsAssertion *sa = assertValue;
1439 ber_len_t nkeys = 0;
1440 size_t slen, mlen, klen;
1441 struct berval **keys;
1442 HASH_CONTEXT HASHcontext;
1443 unsigned char HASHdigest[HASH_BYTES];
1444 struct berval *value;
1445 struct berval digest;
1447 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1448 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1453 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1455 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1456 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1457 /* don't bother accounting for stepping */
1458 nkeys += sa->sa_any[i]->bv_len -
1459 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1464 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1465 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1472 return LDAP_SUCCESS;
1475 digest.bv_val = HASHdigest;
1476 digest.bv_len = sizeof(HASHdigest);
1478 slen = strlen( syntax->ssyn_oid );
1479 mlen = strlen( mr->smr_oid );
1481 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1484 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1485 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1487 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1489 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_NOCASEFOLD ) );
1491 value = sa->sa_initial;
1494 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1495 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1497 HASH_Init( &HASHcontext );
1498 if( prefix != NULL && prefix->bv_len > 0 ) {
1499 HASH_Update( &HASHcontext,
1500 prefix->bv_val, prefix->bv_len );
1502 HASH_Update( &HASHcontext,
1503 &pre, sizeof( pre ) );
1504 HASH_Update( &HASHcontext,
1505 syntax->ssyn_oid, slen );
1506 HASH_Update( &HASHcontext,
1507 mr->smr_oid, mlen );
1508 HASH_Update( &HASHcontext,
1509 value->bv_val, klen );
1510 HASH_Final( HASHdigest, &HASHcontext );
1513 ber_bvfree( value );
1515 keys[nkeys++] = ber_bvdup( &digest );
1518 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1520 pre = SLAP_INDEX_SUBSTR_PREFIX;
1521 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1523 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1524 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1529 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_NOCASEFOLD ) );
1531 value = sa->sa_any[i];
1535 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1536 j += SLAP_INDEX_SUBSTR_STEP )
1538 HASH_Init( &HASHcontext );
1539 if( prefix != NULL && prefix->bv_len > 0 ) {
1540 HASH_Update( &HASHcontext,
1541 prefix->bv_val, prefix->bv_len );
1543 HASH_Update( &HASHcontext,
1544 &pre, sizeof( pre ) );
1545 HASH_Update( &HASHcontext,
1546 syntax->ssyn_oid, slen );
1547 HASH_Update( &HASHcontext,
1548 mr->smr_oid, mlen );
1549 HASH_Update( &HASHcontext,
1550 &value->bv_val[j], klen );
1551 HASH_Final( HASHdigest, &HASHcontext );
1553 keys[nkeys++] = ber_bvdup( &digest );
1557 ber_bvfree( value );
1562 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1563 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1565 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1567 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_NOCASEFOLD ) );
1569 value = sa->sa_final;
1572 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1573 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1575 HASH_Init( &HASHcontext );
1576 if( prefix != NULL && prefix->bv_len > 0 ) {
1577 HASH_Update( &HASHcontext,
1578 prefix->bv_val, prefix->bv_len );
1580 HASH_Update( &HASHcontext,
1581 &pre, sizeof( pre ) );
1582 HASH_Update( &HASHcontext,
1583 syntax->ssyn_oid, slen );
1584 HASH_Update( &HASHcontext,
1585 mr->smr_oid, mlen );
1586 HASH_Update( &HASHcontext,
1587 &value->bv_val[value->bv_len-klen], klen );
1588 HASH_Final( HASHdigest, &HASHcontext );
1591 ber_bvfree( value );
1593 keys[nkeys++] = ber_bvdup( &digest );
1604 return LDAP_SUCCESS;
1613 struct berval *value,
1614 void *assertedValue )
1617 *matchp = UTF8normcmp( value->bv_val,
1618 ((struct berval *) assertedValue)->bv_val,
1621 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1624 match = strncasecmp( value->bv_val,
1625 ((struct berval *) assertedValue)->bv_val,
1631 return LDAP_SUCCESS;
1635 caseIgnoreSubstringsMatch(
1640 struct berval *value,
1641 void *assertedValue )
1644 SubstringsAssertion *sub = assertedValue;
1645 struct berval left = *value;
1649 /* Add up asserted input length */
1650 if( sub->sa_initial ) {
1651 inlen += sub->sa_initial->bv_len;
1654 for(i=0; sub->sa_any[i] != NULL; i++) {
1655 inlen += sub->sa_any[i]->bv_len;
1658 if( sub->sa_final ) {
1659 inlen += sub->sa_final->bv_len;
1662 if( sub->sa_initial ) {
1663 if( inlen > left.bv_len ) {
1669 match = UTF8oncasecmp( sub->sa_initial, &left,
1670 sub->sa_initial->bv_len, 0 );
1672 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1673 sub->sa_initial->bv_len );
1680 left.bv_val += sub->sa_initial->bv_len;
1681 left.bv_len -= sub->sa_initial->bv_len;
1682 inlen -= sub->sa_initial->bv_len;
1685 if( sub->sa_final ) {
1686 if( inlen > left.bv_len ) {
1692 match = UTF8oncasecmp( sub->sa_final, &left,
1693 sub->sa_final->bv_len,
1694 left.bv_len - sub->sa_final->bv_len );
1696 match = strncasecmp( sub->sa_final->bv_val,
1697 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1698 sub->sa_final->bv_len );
1705 left.bv_len -= sub->sa_final->bv_len;
1706 inlen -= sub->sa_final->bv_len;
1710 for(i=0; sub->sa_any[i]; i++) {
1715 if( inlen > left.bv_len ) {
1716 /* not enough length */
1721 if( sub->sa_any[i]->bv_len == 0 ) {
1726 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1728 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1736 idx = p - left.bv_val;
1737 assert( idx < left.bv_len );
1739 if( idx >= left.bv_len ) {
1740 /* this shouldn't happen */
1747 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1748 /* not enough left */
1754 match = UTF8oncasecmp( &left, sub->sa_any[i],
1755 sub->sa_any[i]->bv_len, 0 );
1758 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1764 match = strncasecmp( left.bv_val,
1765 sub->sa_any[i]->bv_val,
1766 sub->sa_any[i]->bv_len );
1776 left.bv_val += sub->sa_any[i]->bv_len;
1777 left.bv_len -= sub->sa_any[i]->bv_len;
1778 inlen -= sub->sa_any[i]->bv_len;
1784 return LDAP_SUCCESS;
1787 /* Index generation function */
1788 int caseIgnoreIndexer(
1793 struct berval *prefix,
1794 struct berval **values,
1795 struct berval ***keysp )
1799 struct berval **keys;
1800 HASH_CONTEXT HASHcontext;
1801 unsigned char HASHdigest[HASH_BYTES];
1802 struct berval digest;
1803 digest.bv_val = HASHdigest;
1804 digest.bv_len = sizeof(HASHdigest);
1806 /* we should have at least one value at this point */
1807 assert( values != NULL && values[0] != NULL );
1809 for( i=0; values[i] != NULL; i++ ) {
1810 /* just count them */
1813 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1815 slen = strlen( syntax->ssyn_oid );
1816 mlen = strlen( mr->smr_oid );
1818 for( i=0; values[i] != NULL; i++ ) {
1819 struct berval *value;
1821 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1823 value = ber_bvdup( values[i] );
1824 ldap_pvt_str2upper( value->bv_val );
1826 HASH_Init( &HASHcontext );
1827 if( prefix != NULL && prefix->bv_len > 0 ) {
1828 HASH_Update( &HASHcontext,
1829 prefix->bv_val, prefix->bv_len );
1831 HASH_Update( &HASHcontext,
1832 syntax->ssyn_oid, slen );
1833 HASH_Update( &HASHcontext,
1834 mr->smr_oid, mlen );
1835 HASH_Update( &HASHcontext,
1836 value->bv_val, value->bv_len );
1837 HASH_Final( HASHdigest, &HASHcontext );
1839 ber_bvfree( value );
1841 keys[i] = ber_bvdup( &digest );
1846 return LDAP_SUCCESS;
1849 /* Index generation function */
1850 int caseIgnoreFilter(
1855 struct berval *prefix,
1857 struct berval ***keysp )
1860 struct berval **keys;
1861 HASH_CONTEXT HASHcontext;
1862 unsigned char HASHdigest[HASH_BYTES];
1863 struct berval *value;
1864 struct berval digest;
1865 digest.bv_val = HASHdigest;
1866 digest.bv_len = sizeof(HASHdigest);
1868 slen = strlen( syntax->ssyn_oid );
1869 mlen = strlen( mr->smr_oid );
1872 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val, UTF8_CASEFOLD ) );
1874 value = ber_bvdup( (struct berval *) assertValue );
1875 ldap_pvt_str2upper( value->bv_val );
1878 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1880 HASH_Init( &HASHcontext );
1881 if( prefix != NULL && prefix->bv_len > 0 ) {
1882 HASH_Update( &HASHcontext,
1883 prefix->bv_val, prefix->bv_len );
1885 HASH_Update( &HASHcontext,
1886 syntax->ssyn_oid, slen );
1887 HASH_Update( &HASHcontext,
1888 mr->smr_oid, mlen );
1889 HASH_Update( &HASHcontext,
1890 value->bv_val, value->bv_len );
1891 HASH_Final( HASHdigest, &HASHcontext );
1893 keys[0] = ber_bvdup( &digest );
1896 ber_bvfree( value );
1900 return LDAP_SUCCESS;
1903 /* Substrings Index generation function */
1904 int caseIgnoreSubstringsIndexer(
1909 struct berval *prefix,
1910 struct berval **values,
1911 struct berval ***keysp )
1915 struct berval **keys;
1916 HASH_CONTEXT HASHcontext;
1917 unsigned char HASHdigest[HASH_BYTES];
1918 struct berval digest;
1919 digest.bv_val = HASHdigest;
1920 digest.bv_len = sizeof(HASHdigest);
1922 /* we should have at least one value at this point */
1923 assert( values != NULL && values[0] != NULL );
1926 for( i=0; values[i] != NULL; i++ ) {
1927 /* count number of indices to generate */
1928 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1932 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1933 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1934 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1935 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1937 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1941 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1942 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1943 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1947 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1948 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1949 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1950 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1952 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1958 /* no keys to generate */
1960 return LDAP_SUCCESS;
1963 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1965 slen = strlen( syntax->ssyn_oid );
1966 mlen = strlen( mr->smr_oid );
1969 for( i=0; values[i] != NULL; i++ ) {
1971 struct berval *value;
1973 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1976 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1978 value = ber_bvdup( values[i] );
1979 ldap_pvt_str2upper( value->bv_val );
1982 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1983 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1985 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1986 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1988 for( j=0; j<max; j++ ) {
1989 HASH_Init( &HASHcontext );
1990 if( prefix != NULL && prefix->bv_len > 0 ) {
1991 HASH_Update( &HASHcontext,
1992 prefix->bv_val, prefix->bv_len );
1995 HASH_Update( &HASHcontext,
1996 &pre, sizeof( pre ) );
1997 HASH_Update( &HASHcontext,
1998 syntax->ssyn_oid, slen );
1999 HASH_Update( &HASHcontext,
2000 mr->smr_oid, mlen );
2001 HASH_Update( &HASHcontext,
2003 SLAP_INDEX_SUBSTR_MAXLEN );
2004 HASH_Final( HASHdigest, &HASHcontext );
2006 keys[nkeys++] = ber_bvdup( &digest );
2010 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2011 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2013 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2016 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2017 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2018 HASH_Init( &HASHcontext );
2019 if( prefix != NULL && prefix->bv_len > 0 ) {
2020 HASH_Update( &HASHcontext,
2021 prefix->bv_val, prefix->bv_len );
2023 HASH_Update( &HASHcontext,
2024 &pre, sizeof( pre ) );
2025 HASH_Update( &HASHcontext,
2026 syntax->ssyn_oid, slen );
2027 HASH_Update( &HASHcontext,
2028 mr->smr_oid, mlen );
2029 HASH_Update( &HASHcontext,
2031 HASH_Final( HASHdigest, &HASHcontext );
2033 keys[nkeys++] = ber_bvdup( &digest );
2036 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2037 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2038 HASH_Init( &HASHcontext );
2039 if( prefix != NULL && prefix->bv_len > 0 ) {
2040 HASH_Update( &HASHcontext,
2041 prefix->bv_val, prefix->bv_len );
2043 HASH_Update( &HASHcontext,
2044 &pre, sizeof( pre ) );
2045 HASH_Update( &HASHcontext,
2046 syntax->ssyn_oid, slen );
2047 HASH_Update( &HASHcontext,
2048 mr->smr_oid, mlen );
2049 HASH_Update( &HASHcontext,
2050 &value->bv_val[value->bv_len-j], j );
2051 HASH_Final( HASHdigest, &HASHcontext );
2053 keys[nkeys++] = ber_bvdup( &digest );
2058 ber_bvfree( value );
2069 return LDAP_SUCCESS;
2072 int caseIgnoreSubstringsFilter(
2077 struct berval *prefix,
2079 struct berval ***keysp )
2081 SubstringsAssertion *sa = assertValue;
2083 ber_len_t nkeys = 0;
2084 size_t slen, mlen, klen;
2085 struct berval **keys;
2086 HASH_CONTEXT HASHcontext;
2087 unsigned char HASHdigest[HASH_BYTES];
2088 struct berval *value;
2089 struct berval digest;
2091 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2092 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2097 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2099 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2100 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2101 /* don't bother accounting for stepping */
2102 nkeys += sa->sa_any[i]->bv_len -
2103 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2108 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2109 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2116 return LDAP_SUCCESS;
2119 digest.bv_val = HASHdigest;
2120 digest.bv_len = sizeof(HASHdigest);
2122 slen = strlen( syntax->ssyn_oid );
2123 mlen = strlen( mr->smr_oid );
2125 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2128 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2129 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2131 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2133 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_CASEFOLD ) );
2135 value = ber_bvdup( sa->sa_initial );
2136 ldap_pvt_str2upper( value->bv_val );
2139 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2140 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2142 HASH_Init( &HASHcontext );
2143 if( prefix != NULL && prefix->bv_len > 0 ) {
2144 HASH_Update( &HASHcontext,
2145 prefix->bv_val, prefix->bv_len );
2147 HASH_Update( &HASHcontext,
2148 &pre, sizeof( pre ) );
2149 HASH_Update( &HASHcontext,
2150 syntax->ssyn_oid, slen );
2151 HASH_Update( &HASHcontext,
2152 mr->smr_oid, mlen );
2153 HASH_Update( &HASHcontext,
2154 value->bv_val, klen );
2155 HASH_Final( HASHdigest, &HASHcontext );
2157 ber_bvfree( value );
2158 keys[nkeys++] = ber_bvdup( &digest );
2161 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2163 pre = SLAP_INDEX_SUBSTR_PREFIX;
2164 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2166 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2167 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2172 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_CASEFOLD ) );
2174 value = ber_bvdup( sa->sa_any[i] );
2175 ldap_pvt_str2upper( value->bv_val );
2179 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2180 j += SLAP_INDEX_SUBSTR_STEP )
2182 HASH_Init( &HASHcontext );
2183 if( prefix != NULL && prefix->bv_len > 0 ) {
2184 HASH_Update( &HASHcontext,
2185 prefix->bv_val, prefix->bv_len );
2187 HASH_Update( &HASHcontext,
2188 &pre, sizeof( pre ) );
2189 HASH_Update( &HASHcontext,
2190 syntax->ssyn_oid, slen );
2191 HASH_Update( &HASHcontext,
2192 mr->smr_oid, mlen );
2193 HASH_Update( &HASHcontext,
2194 &value->bv_val[j], klen );
2195 HASH_Final( HASHdigest, &HASHcontext );
2197 keys[nkeys++] = ber_bvdup( &digest );
2200 ber_bvfree( value );
2204 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2205 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2207 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2209 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_CASEFOLD ) );
2211 value = ber_bvdup( sa->sa_final );
2212 ldap_pvt_str2upper( value->bv_val );
2215 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2216 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2218 HASH_Init( &HASHcontext );
2219 if( prefix != NULL && prefix->bv_len > 0 ) {
2220 HASH_Update( &HASHcontext,
2221 prefix->bv_val, prefix->bv_len );
2223 HASH_Update( &HASHcontext,
2224 &pre, sizeof( pre ) );
2225 HASH_Update( &HASHcontext,
2226 syntax->ssyn_oid, slen );
2227 HASH_Update( &HASHcontext,
2228 mr->smr_oid, mlen );
2229 HASH_Update( &HASHcontext,
2230 &value->bv_val[value->bv_len-klen], klen );
2231 HASH_Final( HASHdigest, &HASHcontext );
2233 ber_bvfree( value );
2234 keys[nkeys++] = ber_bvdup( &digest );
2245 return LDAP_SUCCESS;
2251 struct berval *val )
2255 if( val->bv_len == 0 ) {
2256 /* disallow empty strings */
2257 return LDAP_INVALID_SYNTAX;
2260 if( OID_LEADCHAR(val->bv_val[0]) ) {
2262 for(i=1; i < val->bv_len; i++) {
2263 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2264 if( dot++ ) return 1;
2265 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2268 return LDAP_INVALID_SYNTAX;
2272 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2274 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2275 for(i=1; i < val->bv_len; i++) {
2276 if( !DESC_CHAR(val->bv_val[i] ) ) {
2277 return LDAP_INVALID_SYNTAX;
2281 return LDAP_SUCCESS;
2284 return LDAP_INVALID_SYNTAX;
2290 struct berval *val )
2294 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2296 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2297 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2298 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2299 return LDAP_INVALID_SYNTAX;
2302 for(i=1; i < val->bv_len; i++) {
2303 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2306 return LDAP_SUCCESS;
2313 struct berval **normalized )
2316 struct berval *newval;
2322 negative = ( *p == '-' );
2323 if( *p == '-' || *p == '+' ) p++;
2325 /* Ignore leading zeros */
2326 while ( *p == '0' ) p++;
2328 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2331 newval->bv_val = ch_strdup("0");
2336 newval->bv_val = ch_malloc( val->bv_len + 1 );
2340 newval->bv_val[newval->bv_len++] = '-';
2343 for( ; *p != '\0'; p++ ) {
2344 newval->bv_val[newval->bv_len++] = *p;
2348 *normalized = newval;
2349 return LDAP_SUCCESS;
2353 countryStringValidate(
2355 struct berval *val )
2359 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2361 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2362 return LDAP_INVALID_SYNTAX;
2364 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2365 return LDAP_INVALID_SYNTAX;
2368 return LDAP_SUCCESS;
2372 printableStringValidate(
2374 struct berval *val )
2378 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2380 for(i=0; i < val->bv_len; i++) {
2381 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2382 return LDAP_INVALID_SYNTAX;
2386 return LDAP_SUCCESS;
2390 printablesStringValidate(
2392 struct berval *val )
2396 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2398 for(i=0; i < val->bv_len; i++) {
2399 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2400 return LDAP_INVALID_SYNTAX;
2404 return LDAP_SUCCESS;
2410 struct berval *val )
2414 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2416 for(i=0; i < val->bv_len; i++) {
2417 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2420 return LDAP_SUCCESS;
2427 struct berval **normalized )
2429 struct berval *newval;
2432 newval = ch_malloc( sizeof( struct berval ) );
2436 /* Ignore initial whitespace */
2437 while ( ASCII_SPACE( *p ) ) {
2443 return LDAP_INVALID_SYNTAX;
2446 newval->bv_val = ch_strdup( p );
2447 p = q = newval->bv_val;
2450 if ( ASCII_SPACE( *p ) ) {
2453 /* Ignore the extra whitespace */
2454 while ( ASCII_SPACE( *p ) ) {
2462 assert( *newval->bv_val );
2463 assert( newval->bv_val < p );
2466 /* cannot start with a space */
2467 assert( !ASCII_SPACE(*newval->bv_val) );
2470 * If the string ended in space, backup the pointer one
2471 * position. One is enough because the above loop collapsed
2472 * all whitespace to a single space.
2475 if ( ASCII_SPACE( q[-1] ) ) {
2479 /* cannot end with a space */
2480 assert( !ASCII_SPACE( q[-1] ) );
2482 /* null terminate */
2485 newval->bv_len = q - newval->bv_val;
2486 *normalized = newval;
2488 return LDAP_SUCCESS;
2497 struct berval *value,
2498 void *assertedValue )
2500 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2503 match = strncmp( value->bv_val,
2504 ((struct berval *) assertedValue)->bv_val,
2509 return LDAP_SUCCESS;
2513 caseExactIA5SubstringsMatch(
2518 struct berval *value,
2519 void *assertedValue )
2522 SubstringsAssertion *sub = assertedValue;
2523 struct berval left = *value;
2527 /* Add up asserted input length */
2528 if( sub->sa_initial ) {
2529 inlen += sub->sa_initial->bv_len;
2532 for(i=0; sub->sa_any[i] != NULL; i++) {
2533 inlen += sub->sa_any[i]->bv_len;
2536 if( sub->sa_final ) {
2537 inlen += sub->sa_final->bv_len;
2540 if( sub->sa_initial ) {
2541 if( inlen > left.bv_len ) {
2546 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2547 sub->sa_initial->bv_len );
2553 left.bv_val += sub->sa_initial->bv_len;
2554 left.bv_len -= sub->sa_initial->bv_len;
2555 inlen -= sub->sa_initial->bv_len;
2558 if( sub->sa_final ) {
2559 if( inlen > left.bv_len ) {
2564 match = strncmp( sub->sa_final->bv_val,
2565 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2566 sub->sa_final->bv_len );
2572 left.bv_len -= sub->sa_final->bv_len;
2573 inlen -= sub->sa_final->bv_len;
2577 for(i=0; sub->sa_any[i]; i++) {
2582 if( inlen > left.bv_len ) {
2583 /* not enough length */
2588 if( sub->sa_any[i]->bv_len == 0 ) {
2592 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2599 idx = p - left.bv_val;
2600 assert( idx < left.bv_len );
2602 if( idx >= left.bv_len ) {
2603 /* this shouldn't happen */
2610 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2611 /* not enough left */
2616 match = strncmp( left.bv_val,
2617 sub->sa_any[i]->bv_val,
2618 sub->sa_any[i]->bv_len );
2626 left.bv_val += sub->sa_any[i]->bv_len;
2627 left.bv_len -= sub->sa_any[i]->bv_len;
2628 inlen -= sub->sa_any[i]->bv_len;
2634 return LDAP_SUCCESS;
2637 /* Index generation function */
2638 int caseExactIA5Indexer(
2643 struct berval *prefix,
2644 struct berval **values,
2645 struct berval ***keysp )
2649 struct berval **keys;
2650 HASH_CONTEXT HASHcontext;
2651 unsigned char HASHdigest[HASH_BYTES];
2652 struct berval digest;
2653 digest.bv_val = HASHdigest;
2654 digest.bv_len = sizeof(HASHdigest);
2656 /* we should have at least one value at this point */
2657 assert( values != NULL && values[0] != NULL );
2659 for( i=0; values[i] != NULL; i++ ) {
2660 /* just count them */
2663 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2665 slen = strlen( syntax->ssyn_oid );
2666 mlen = strlen( mr->smr_oid );
2668 for( i=0; values[i] != NULL; i++ ) {
2669 struct berval *value = values[i];
2671 HASH_Init( &HASHcontext );
2672 if( prefix != NULL && prefix->bv_len > 0 ) {
2673 HASH_Update( &HASHcontext,
2674 prefix->bv_val, prefix->bv_len );
2676 HASH_Update( &HASHcontext,
2677 syntax->ssyn_oid, slen );
2678 HASH_Update( &HASHcontext,
2679 mr->smr_oid, mlen );
2680 HASH_Update( &HASHcontext,
2681 value->bv_val, value->bv_len );
2682 HASH_Final( HASHdigest, &HASHcontext );
2684 keys[i] = ber_bvdup( &digest );
2689 return LDAP_SUCCESS;
2692 /* Index generation function */
2693 int caseExactIA5Filter(
2698 struct berval *prefix,
2700 struct berval ***keysp )
2703 struct berval **keys;
2704 HASH_CONTEXT HASHcontext;
2705 unsigned char HASHdigest[HASH_BYTES];
2706 struct berval *value;
2707 struct berval digest;
2708 digest.bv_val = HASHdigest;
2709 digest.bv_len = sizeof(HASHdigest);
2711 slen = strlen( syntax->ssyn_oid );
2712 mlen = strlen( mr->smr_oid );
2714 value = (struct berval *) assertValue;
2716 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2718 HASH_Init( &HASHcontext );
2719 if( prefix != NULL && prefix->bv_len > 0 ) {
2720 HASH_Update( &HASHcontext,
2721 prefix->bv_val, prefix->bv_len );
2723 HASH_Update( &HASHcontext,
2724 syntax->ssyn_oid, slen );
2725 HASH_Update( &HASHcontext,
2726 mr->smr_oid, mlen );
2727 HASH_Update( &HASHcontext,
2728 value->bv_val, value->bv_len );
2729 HASH_Final( HASHdigest, &HASHcontext );
2731 keys[0] = ber_bvdup( &digest );
2735 return LDAP_SUCCESS;
2738 /* Substrings Index generation function */
2739 int caseExactIA5SubstringsIndexer(
2744 struct berval *prefix,
2745 struct berval **values,
2746 struct berval ***keysp )
2750 struct berval **keys;
2751 HASH_CONTEXT HASHcontext;
2752 unsigned char HASHdigest[HASH_BYTES];
2753 struct berval digest;
2754 digest.bv_val = HASHdigest;
2755 digest.bv_len = sizeof(HASHdigest);
2757 /* we should have at least one value at this point */
2758 assert( values != NULL && values[0] != NULL );
2761 for( i=0; values[i] != NULL; i++ ) {
2762 /* count number of indices to generate */
2763 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2767 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2768 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2769 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2770 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2772 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2776 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2777 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2778 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2782 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2783 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2784 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2785 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2787 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2793 /* no keys to generate */
2795 return LDAP_SUCCESS;
2798 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2800 slen = strlen( syntax->ssyn_oid );
2801 mlen = strlen( mr->smr_oid );
2804 for( i=0; values[i] != NULL; i++ ) {
2806 struct berval *value;
2809 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2811 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2812 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2814 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2815 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2817 for( j=0; j<max; j++ ) {
2818 HASH_Init( &HASHcontext );
2819 if( prefix != NULL && prefix->bv_len > 0 ) {
2820 HASH_Update( &HASHcontext,
2821 prefix->bv_val, prefix->bv_len );
2824 HASH_Update( &HASHcontext,
2825 &pre, sizeof( pre ) );
2826 HASH_Update( &HASHcontext,
2827 syntax->ssyn_oid, slen );
2828 HASH_Update( &HASHcontext,
2829 mr->smr_oid, mlen );
2830 HASH_Update( &HASHcontext,
2832 SLAP_INDEX_SUBSTR_MAXLEN );
2833 HASH_Final( HASHdigest, &HASHcontext );
2835 keys[nkeys++] = ber_bvdup( &digest );
2839 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2840 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2842 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2845 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2846 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2847 HASH_Init( &HASHcontext );
2848 if( prefix != NULL && prefix->bv_len > 0 ) {
2849 HASH_Update( &HASHcontext,
2850 prefix->bv_val, prefix->bv_len );
2852 HASH_Update( &HASHcontext,
2853 &pre, sizeof( pre ) );
2854 HASH_Update( &HASHcontext,
2855 syntax->ssyn_oid, slen );
2856 HASH_Update( &HASHcontext,
2857 mr->smr_oid, mlen );
2858 HASH_Update( &HASHcontext,
2860 HASH_Final( HASHdigest, &HASHcontext );
2862 keys[nkeys++] = ber_bvdup( &digest );
2865 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2866 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2867 HASH_Init( &HASHcontext );
2868 if( prefix != NULL && prefix->bv_len > 0 ) {
2869 HASH_Update( &HASHcontext,
2870 prefix->bv_val, prefix->bv_len );
2872 HASH_Update( &HASHcontext,
2873 &pre, sizeof( pre ) );
2874 HASH_Update( &HASHcontext,
2875 syntax->ssyn_oid, slen );
2876 HASH_Update( &HASHcontext,
2877 mr->smr_oid, mlen );
2878 HASH_Update( &HASHcontext,
2879 &value->bv_val[value->bv_len-j], j );
2880 HASH_Final( HASHdigest, &HASHcontext );
2882 keys[nkeys++] = ber_bvdup( &digest );
2896 return LDAP_SUCCESS;
2899 int caseExactIA5SubstringsFilter(
2904 struct berval *prefix,
2906 struct berval ***keysp )
2908 SubstringsAssertion *sa = assertValue;
2910 ber_len_t nkeys = 0;
2911 size_t slen, mlen, klen;
2912 struct berval **keys;
2913 HASH_CONTEXT HASHcontext;
2914 unsigned char HASHdigest[HASH_BYTES];
2915 struct berval *value;
2916 struct berval digest;
2918 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2919 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2924 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2926 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2927 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2928 /* don't bother accounting for stepping */
2929 nkeys += sa->sa_any[i]->bv_len -
2930 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2935 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2936 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2943 return LDAP_SUCCESS;
2946 digest.bv_val = HASHdigest;
2947 digest.bv_len = sizeof(HASHdigest);
2949 slen = strlen( syntax->ssyn_oid );
2950 mlen = strlen( mr->smr_oid );
2952 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2955 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2956 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2958 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2959 value = sa->sa_initial;
2961 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2962 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2964 HASH_Init( &HASHcontext );
2965 if( prefix != NULL && prefix->bv_len > 0 ) {
2966 HASH_Update( &HASHcontext,
2967 prefix->bv_val, prefix->bv_len );
2969 HASH_Update( &HASHcontext,
2970 &pre, sizeof( pre ) );
2971 HASH_Update( &HASHcontext,
2972 syntax->ssyn_oid, slen );
2973 HASH_Update( &HASHcontext,
2974 mr->smr_oid, mlen );
2975 HASH_Update( &HASHcontext,
2976 value->bv_val, klen );
2977 HASH_Final( HASHdigest, &HASHcontext );
2979 keys[nkeys++] = ber_bvdup( &digest );
2982 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2984 pre = SLAP_INDEX_SUBSTR_PREFIX;
2985 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2987 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2988 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2992 value = sa->sa_any[i];
2995 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2996 j += SLAP_INDEX_SUBSTR_STEP )
2998 HASH_Init( &HASHcontext );
2999 if( prefix != NULL && prefix->bv_len > 0 ) {
3000 HASH_Update( &HASHcontext,
3001 prefix->bv_val, prefix->bv_len );
3003 HASH_Update( &HASHcontext,
3004 &pre, sizeof( pre ) );
3005 HASH_Update( &HASHcontext,
3006 syntax->ssyn_oid, slen );
3007 HASH_Update( &HASHcontext,
3008 mr->smr_oid, mlen );
3009 HASH_Update( &HASHcontext,
3010 &value->bv_val[j], klen );
3011 HASH_Final( HASHdigest, &HASHcontext );
3013 keys[nkeys++] = ber_bvdup( &digest );
3018 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3019 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3021 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3022 value = sa->sa_final;
3024 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3025 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3027 HASH_Init( &HASHcontext );
3028 if( prefix != NULL && prefix->bv_len > 0 ) {
3029 HASH_Update( &HASHcontext,
3030 prefix->bv_val, prefix->bv_len );
3032 HASH_Update( &HASHcontext,
3033 &pre, sizeof( pre ) );
3034 HASH_Update( &HASHcontext,
3035 syntax->ssyn_oid, slen );
3036 HASH_Update( &HASHcontext,
3037 mr->smr_oid, mlen );
3038 HASH_Update( &HASHcontext,
3039 &value->bv_val[value->bv_len-klen], klen );
3040 HASH_Final( HASHdigest, &HASHcontext );
3042 keys[nkeys++] = ber_bvdup( &digest );
3053 return LDAP_SUCCESS;
3062 struct berval *value,
3063 void *assertedValue )
3065 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3067 if( match == 0 && value->bv_len ) {
3068 match = strncasecmp( value->bv_val,
3069 ((struct berval *) assertedValue)->bv_val,
3074 return LDAP_SUCCESS;
3078 caseIgnoreIA5SubstringsMatch(
3083 struct berval *value,
3084 void *assertedValue )
3087 SubstringsAssertion *sub = assertedValue;
3088 struct berval left = *value;
3092 /* Add up asserted input length */
3093 if( sub->sa_initial ) {
3094 inlen += sub->sa_initial->bv_len;
3097 for(i=0; sub->sa_any[i] != NULL; i++) {
3098 inlen += sub->sa_any[i]->bv_len;
3101 if( sub->sa_final ) {
3102 inlen += sub->sa_final->bv_len;
3105 if( sub->sa_initial ) {
3106 if( inlen > left.bv_len ) {
3111 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3112 sub->sa_initial->bv_len );
3118 left.bv_val += sub->sa_initial->bv_len;
3119 left.bv_len -= sub->sa_initial->bv_len;
3120 inlen -= sub->sa_initial->bv_len;
3123 if( sub->sa_final ) {
3124 if( inlen > left.bv_len ) {
3129 match = strncasecmp( sub->sa_final->bv_val,
3130 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3131 sub->sa_final->bv_len );
3137 left.bv_len -= sub->sa_final->bv_len;
3138 inlen -= sub->sa_final->bv_len;
3142 for(i=0; sub->sa_any[i]; i++) {
3147 if( inlen > left.bv_len ) {
3148 /* not enough length */
3153 if( sub->sa_any[i]->bv_len == 0 ) {
3157 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3164 idx = p - left.bv_val;
3165 assert( idx < left.bv_len );
3167 if( idx >= left.bv_len ) {
3168 /* this shouldn't happen */
3175 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3176 /* not enough left */
3181 match = strncasecmp( left.bv_val,
3182 sub->sa_any[i]->bv_val,
3183 sub->sa_any[i]->bv_len );
3192 left.bv_val += sub->sa_any[i]->bv_len;
3193 left.bv_len -= sub->sa_any[i]->bv_len;
3194 inlen -= sub->sa_any[i]->bv_len;
3200 return LDAP_SUCCESS;
3203 /* Index generation function */
3204 int caseIgnoreIA5Indexer(
3209 struct berval *prefix,
3210 struct berval **values,
3211 struct berval ***keysp )
3215 struct berval **keys;
3216 HASH_CONTEXT HASHcontext;
3217 unsigned char HASHdigest[HASH_BYTES];
3218 struct berval digest;
3219 digest.bv_val = HASHdigest;
3220 digest.bv_len = sizeof(HASHdigest);
3222 /* we should have at least one value at this point */
3223 assert( values != NULL && values[0] != NULL );
3225 for( i=0; values[i] != NULL; i++ ) {
3226 /* just count them */
3229 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3231 slen = strlen( syntax->ssyn_oid );
3232 mlen = strlen( mr->smr_oid );
3234 for( i=0; values[i] != NULL; i++ ) {
3235 struct berval *value = ber_bvdup( values[i] );
3236 ldap_pvt_str2upper( value->bv_val );
3238 HASH_Init( &HASHcontext );
3239 if( prefix != NULL && prefix->bv_len > 0 ) {
3240 HASH_Update( &HASHcontext,
3241 prefix->bv_val, prefix->bv_len );
3243 HASH_Update( &HASHcontext,
3244 syntax->ssyn_oid, slen );
3245 HASH_Update( &HASHcontext,
3246 mr->smr_oid, mlen );
3247 HASH_Update( &HASHcontext,
3248 value->bv_val, value->bv_len );
3249 HASH_Final( HASHdigest, &HASHcontext );
3251 ber_bvfree( value );
3253 keys[i] = ber_bvdup( &digest );
3258 return LDAP_SUCCESS;
3261 /* Index generation function */
3262 int caseIgnoreIA5Filter(
3267 struct berval *prefix,
3269 struct berval ***keysp )
3272 struct berval **keys;
3273 HASH_CONTEXT HASHcontext;
3274 unsigned char HASHdigest[HASH_BYTES];
3275 struct berval *value;
3276 struct berval digest;
3277 digest.bv_val = HASHdigest;
3278 digest.bv_len = sizeof(HASHdigest);
3280 slen = strlen( syntax->ssyn_oid );
3281 mlen = strlen( mr->smr_oid );
3283 value = ber_bvdup( (struct berval *) assertValue );
3284 ldap_pvt_str2upper( value->bv_val );
3286 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3288 HASH_Init( &HASHcontext );
3289 if( prefix != NULL && prefix->bv_len > 0 ) {
3290 HASH_Update( &HASHcontext,
3291 prefix->bv_val, prefix->bv_len );
3293 HASH_Update( &HASHcontext,
3294 syntax->ssyn_oid, slen );
3295 HASH_Update( &HASHcontext,
3296 mr->smr_oid, mlen );
3297 HASH_Update( &HASHcontext,
3298 value->bv_val, value->bv_len );
3299 HASH_Final( HASHdigest, &HASHcontext );
3301 keys[0] = ber_bvdup( &digest );
3304 ber_bvfree( value );
3308 return LDAP_SUCCESS;
3311 /* Substrings Index generation function */
3312 int caseIgnoreIA5SubstringsIndexer(
3317 struct berval *prefix,
3318 struct berval **values,
3319 struct berval ***keysp )
3323 struct berval **keys;
3324 HASH_CONTEXT HASHcontext;
3325 unsigned char HASHdigest[HASH_BYTES];
3326 struct berval digest;
3327 digest.bv_val = HASHdigest;
3328 digest.bv_len = sizeof(HASHdigest);
3330 /* we should have at least one value at this point */
3331 assert( values != NULL && values[0] != NULL );
3334 for( i=0; values[i] != NULL; i++ ) {
3335 /* count number of indices to generate */
3336 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3340 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3341 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3342 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3343 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3345 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3349 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3350 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3351 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3355 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3356 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3357 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3358 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3360 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3366 /* no keys to generate */
3368 return LDAP_SUCCESS;
3371 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3373 slen = strlen( syntax->ssyn_oid );
3374 mlen = strlen( mr->smr_oid );
3377 for( i=0; values[i] != NULL; i++ ) {
3379 struct berval *value;
3381 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3383 value = ber_bvdup( values[i] );
3384 ldap_pvt_str2upper( value->bv_val );
3386 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3387 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3389 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3390 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3392 for( j=0; j<max; j++ ) {
3393 HASH_Init( &HASHcontext );
3394 if( prefix != NULL && prefix->bv_len > 0 ) {
3395 HASH_Update( &HASHcontext,
3396 prefix->bv_val, prefix->bv_len );
3399 HASH_Update( &HASHcontext,
3400 &pre, sizeof( pre ) );
3401 HASH_Update( &HASHcontext,
3402 syntax->ssyn_oid, slen );
3403 HASH_Update( &HASHcontext,
3404 mr->smr_oid, mlen );
3405 HASH_Update( &HASHcontext,
3407 SLAP_INDEX_SUBSTR_MAXLEN );
3408 HASH_Final( HASHdigest, &HASHcontext );
3410 keys[nkeys++] = ber_bvdup( &digest );
3414 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3415 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3417 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3420 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3421 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3422 HASH_Init( &HASHcontext );
3423 if( prefix != NULL && prefix->bv_len > 0 ) {
3424 HASH_Update( &HASHcontext,
3425 prefix->bv_val, prefix->bv_len );
3427 HASH_Update( &HASHcontext,
3428 &pre, sizeof( pre ) );
3429 HASH_Update( &HASHcontext,
3430 syntax->ssyn_oid, slen );
3431 HASH_Update( &HASHcontext,
3432 mr->smr_oid, mlen );
3433 HASH_Update( &HASHcontext,
3435 HASH_Final( HASHdigest, &HASHcontext );
3437 keys[nkeys++] = ber_bvdup( &digest );
3440 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3441 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3442 HASH_Init( &HASHcontext );
3443 if( prefix != NULL && prefix->bv_len > 0 ) {
3444 HASH_Update( &HASHcontext,
3445 prefix->bv_val, prefix->bv_len );
3447 HASH_Update( &HASHcontext,
3448 &pre, sizeof( pre ) );
3449 HASH_Update( &HASHcontext,
3450 syntax->ssyn_oid, slen );
3451 HASH_Update( &HASHcontext,
3452 mr->smr_oid, mlen );
3453 HASH_Update( &HASHcontext,
3454 &value->bv_val[value->bv_len-j], j );
3455 HASH_Final( HASHdigest, &HASHcontext );
3457 keys[nkeys++] = ber_bvdup( &digest );
3462 ber_bvfree( value );
3473 return LDAP_SUCCESS;
3476 int caseIgnoreIA5SubstringsFilter(
3481 struct berval *prefix,
3483 struct berval ***keysp )
3485 SubstringsAssertion *sa = assertValue;
3487 ber_len_t nkeys = 0;
3488 size_t slen, mlen, klen;
3489 struct berval **keys;
3490 HASH_CONTEXT HASHcontext;
3491 unsigned char HASHdigest[HASH_BYTES];
3492 struct berval *value;
3493 struct berval digest;
3495 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3496 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3501 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3503 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3504 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3505 /* don't bother accounting for stepping */
3506 nkeys += sa->sa_any[i]->bv_len -
3507 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3512 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3513 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3520 return LDAP_SUCCESS;
3523 digest.bv_val = HASHdigest;
3524 digest.bv_len = sizeof(HASHdigest);
3526 slen = strlen( syntax->ssyn_oid );
3527 mlen = strlen( mr->smr_oid );
3529 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3532 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3533 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3535 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3536 value = ber_bvdup( sa->sa_initial );
3537 ldap_pvt_str2upper( value->bv_val );
3539 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3540 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3542 HASH_Init( &HASHcontext );
3543 if( prefix != NULL && prefix->bv_len > 0 ) {
3544 HASH_Update( &HASHcontext,
3545 prefix->bv_val, prefix->bv_len );
3547 HASH_Update( &HASHcontext,
3548 &pre, sizeof( pre ) );
3549 HASH_Update( &HASHcontext,
3550 syntax->ssyn_oid, slen );
3551 HASH_Update( &HASHcontext,
3552 mr->smr_oid, mlen );
3553 HASH_Update( &HASHcontext,
3554 value->bv_val, klen );
3555 HASH_Final( HASHdigest, &HASHcontext );
3557 ber_bvfree( value );
3558 keys[nkeys++] = ber_bvdup( &digest );
3561 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3563 pre = SLAP_INDEX_SUBSTR_PREFIX;
3564 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3566 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3567 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3571 value = ber_bvdup( sa->sa_any[i] );
3572 ldap_pvt_str2upper( value->bv_val );
3575 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3576 j += SLAP_INDEX_SUBSTR_STEP )
3578 HASH_Init( &HASHcontext );
3579 if( prefix != NULL && prefix->bv_len > 0 ) {
3580 HASH_Update( &HASHcontext,
3581 prefix->bv_val, prefix->bv_len );
3583 HASH_Update( &HASHcontext,
3584 &pre, sizeof( pre ) );
3585 HASH_Update( &HASHcontext,
3586 syntax->ssyn_oid, slen );
3587 HASH_Update( &HASHcontext,
3588 mr->smr_oid, mlen );
3589 HASH_Update( &HASHcontext,
3590 &value->bv_val[j], klen );
3591 HASH_Final( HASHdigest, &HASHcontext );
3593 keys[nkeys++] = ber_bvdup( &digest );
3596 ber_bvfree( value );
3600 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3601 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3603 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3604 value = ber_bvdup( sa->sa_final );
3605 ldap_pvt_str2upper( value->bv_val );
3607 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3608 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3610 HASH_Init( &HASHcontext );
3611 if( prefix != NULL && prefix->bv_len > 0 ) {
3612 HASH_Update( &HASHcontext,
3613 prefix->bv_val, prefix->bv_len );
3615 HASH_Update( &HASHcontext,
3616 &pre, sizeof( pre ) );
3617 HASH_Update( &HASHcontext,
3618 syntax->ssyn_oid, slen );
3619 HASH_Update( &HASHcontext,
3620 mr->smr_oid, mlen );
3621 HASH_Update( &HASHcontext,
3622 &value->bv_val[value->bv_len-klen], klen );
3623 HASH_Final( HASHdigest, &HASHcontext );
3625 ber_bvfree( value );
3626 keys[nkeys++] = ber_bvdup( &digest );
3637 return LDAP_SUCCESS;
3641 numericStringValidate(
3647 /* disallow empty numeric strings */
3649 for(i=0; i < in->bv_len; i++) {
3650 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3651 return LDAP_INVALID_SYNTAX;
3655 return LDAP_SUCCESS;
3659 numericStringNormalize(
3662 struct berval **normalized )
3664 /* removal all spaces */
3665 struct berval *newval;
3668 newval = ch_malloc( sizeof( struct berval ) );
3669 newval->bv_val = ch_malloc( val->bv_len + 1 );
3675 if ( ASCII_SPACE( *p ) ) {
3676 /* Ignore whitespace */
3683 assert( newval->bv_val < p );
3686 /* null terminate */
3689 newval->bv_len = q - newval->bv_val;
3690 *normalized = newval;
3692 return LDAP_SUCCESS;
3696 objectIdentifierFirstComponentMatch(
3701 struct berval *value,
3702 void *assertedValue )
3704 int rc = LDAP_SUCCESS;
3706 struct berval *asserted = (struct berval *) assertedValue;
3710 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3711 return LDAP_INVALID_SYNTAX;
3714 /* trim leading white space */
3715 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3719 /* grab next word */
3720 oid.bv_val = &value->bv_val[i];
3721 oid.bv_len = value->bv_len - i;
3722 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3727 /* insert attributeTypes, objectclass check here */
3728 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3729 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3732 char *stored = ch_malloc( oid.bv_len + 1 );
3733 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3734 stored[oid.bv_len] = '\0';
3736 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3737 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3738 MatchingRule *stored_mr = mr_find( stored );
3740 if( asserted_mr == NULL ) {
3741 rc = SLAPD_COMPARE_UNDEFINED;
3743 match = asserted_mr != stored_mr;
3746 } else if ( !strcmp( syntax->ssyn_oid,
3747 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3749 AttributeType *asserted_at = at_find( asserted->bv_val );
3750 AttributeType *stored_at = at_find( stored );
3752 if( asserted_at == NULL ) {
3753 rc = SLAPD_COMPARE_UNDEFINED;
3755 match = asserted_at != stored_at;
3758 } else if ( !strcmp( syntax->ssyn_oid,
3759 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3761 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3762 ObjectClass *stored_oc = oc_find( stored );
3764 if( asserted_oc == NULL ) {
3765 rc = SLAPD_COMPARE_UNDEFINED;
3767 match = asserted_oc != stored_oc;
3775 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3776 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3777 match, value->bv_val, asserted->bv_val ));
3779 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3780 "%d\n\t\"%s\"\n\t\"%s\"\n",
3781 match, value->bv_val, asserted->bv_val );
3785 if( rc == LDAP_SUCCESS ) *matchp = match;
3790 check_time_syntax (struct berval *val,
3794 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3795 static int mdays[2][12] = {
3796 /* non-leap years */
3797 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3799 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3802 int part, c, tzoffset, leapyear = 0 ;
3804 if( val->bv_len == 0 ) {
3805 return LDAP_INVALID_SYNTAX;
3808 p = (char *)val->bv_val;
3809 e = p + val->bv_len;
3811 /* Ignore initial whitespace */
3812 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3816 if (e - p < 13 - (2 * start)) {
3817 return LDAP_INVALID_SYNTAX;
3820 for (part = 0; part < 9; part++) {
3824 for (part = start; part < 7; part++) {
3826 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3833 return LDAP_INVALID_SYNTAX;
3835 if (c < 0 || c > 9) {
3836 return LDAP_INVALID_SYNTAX;
3842 return LDAP_INVALID_SYNTAX;
3844 if (c < 0 || c > 9) {
3845 return LDAP_INVALID_SYNTAX;
3850 if (part == 2 || part == 3) {
3853 if (parts[part] < 0) {
3854 return LDAP_INVALID_SYNTAX;
3856 if (parts[part] > ceiling[part]) {
3857 return LDAP_INVALID_SYNTAX;
3861 /* leapyear check for the Gregorian calendar (year>1581) */
3862 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3863 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3868 if (parts[3] > mdays[leapyear][parts[2]]) {
3869 return LDAP_INVALID_SYNTAX;
3874 tzoffset = 0; /* UTC */
3875 } else if (c != '+' && c != '-') {
3876 return LDAP_INVALID_SYNTAX;
3880 } else /* c == '+' */ {
3885 return LDAP_INVALID_SYNTAX;
3888 for (part = 7; part < 9; part++) {
3890 if (c < 0 || c > 9) {
3891 return LDAP_INVALID_SYNTAX;
3896 if (c < 0 || c > 9) {
3897 return LDAP_INVALID_SYNTAX;
3901 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3902 return LDAP_INVALID_SYNTAX;
3907 /* Ignore trailing whitespace */
3908 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3912 return LDAP_INVALID_SYNTAX;
3915 switch ( tzoffset ) {
3916 case -1: /* negativ offset to UTC, ie west of Greenwich */
3917 parts[4] += parts[7];
3918 parts[5] += parts[8];
3919 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3923 c = mdays[leapyear][parts[2]];
3925 if (parts[part] > c) {
3926 parts[part] -= c + 1;
3931 case 1: /* positive offset to UTC, ie east of Greenwich */
3932 parts[4] -= parts[7];
3933 parts[5] -= parts[8];
3934 for (part = 6; --part > 0; ) {
3938 /* first arg to % needs to be non negativ */
3939 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3941 if (parts[part] < 0) {
3942 parts[part] += c + 1;
3947 case 0: /* already UTC */
3951 return LDAP_SUCCESS;
3958 struct berval **normalized )
3963 rc = check_time_syntax(val, 1, parts);
3964 if (rc != LDAP_SUCCESS) {
3969 out = ch_malloc( sizeof(struct berval) );
3971 return LBER_ERROR_MEMORY;
3974 out->bv_val = ch_malloc( 14 );
3975 if ( out->bv_val == NULL ) {
3977 return LBER_ERROR_MEMORY;
3980 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3981 parts[1], parts[2] + 1, parts[3] + 1,
3982 parts[4], parts[5], parts[6] );
3986 return LDAP_SUCCESS;
3996 return check_time_syntax(in, 1, parts);
4000 generalizedTimeValidate(
4006 return check_time_syntax(in, 0, parts);
4010 generalizedTimeNormalize(
4013 struct berval **normalized )
4018 rc = check_time_syntax(val, 0, parts);
4019 if (rc != LDAP_SUCCESS) {
4024 out = ch_malloc( sizeof(struct berval) );
4026 return LBER_ERROR_MEMORY;
4029 out->bv_val = ch_malloc( 16 );
4030 if ( out->bv_val == NULL ) {
4032 return LBER_ERROR_MEMORY;
4035 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4036 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4037 parts[4], parts[5], parts[6] );
4041 return LDAP_SUCCESS;
4045 nisNetgroupTripleValidate(
4047 struct berval *val )
4052 if ( val->bv_len == 0 ) {
4053 return LDAP_INVALID_SYNTAX;
4056 p = (char *)val->bv_val;
4057 e = p + val->bv_len;
4060 /* syntax does not allow leading white space */
4061 /* Ignore initial whitespace */
4062 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4067 if ( *p != '(' /*')'*/ ) {
4068 return LDAP_INVALID_SYNTAX;
4071 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4075 return LDAP_INVALID_SYNTAX;
4078 } else if ( !ATTR_CHAR( *p ) ) {
4079 return LDAP_INVALID_SYNTAX;
4083 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4084 return LDAP_INVALID_SYNTAX;
4090 /* syntax does not allow trailing white space */
4091 /* Ignore trailing whitespace */
4092 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4098 return LDAP_INVALID_SYNTAX;
4101 return LDAP_SUCCESS;
4105 bootParameterValidate(
4107 struct berval *val )
4111 if ( val->bv_len == 0 ) {
4112 return LDAP_INVALID_SYNTAX;
4115 p = (char *)val->bv_val;
4116 e = p + val->bv_len;
4119 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4120 if ( !ATTR_CHAR( *p ) ) {
4121 return LDAP_INVALID_SYNTAX;
4126 return LDAP_INVALID_SYNTAX;
4130 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4131 if ( !ATTR_CHAR( *p ) ) {
4132 return LDAP_INVALID_SYNTAX;
4137 return LDAP_INVALID_SYNTAX;
4141 for ( p++; p < e; p++ ) {
4142 if ( !ATTR_CHAR( *p ) ) {
4143 return LDAP_INVALID_SYNTAX;
4147 return LDAP_SUCCESS;
4150 struct syntax_defs_rec {
4153 slap_syntax_validate_func *sd_validate;
4154 slap_syntax_transform_func *sd_normalize;
4155 slap_syntax_transform_func *sd_pretty;
4156 #ifdef SLAPD_BINARY_CONVERSION
4157 slap_syntax_transform_func *sd_ber2str;
4158 slap_syntax_transform_func *sd_str2ber;
4162 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4163 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4165 struct syntax_defs_rec syntax_defs[] = {
4166 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4167 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4168 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4169 0, NULL, NULL, NULL},
4170 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4171 0, NULL, NULL, NULL},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4173 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4175 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4177 0, bitStringValidate, NULL, NULL },
4178 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4179 0, booleanValidate, NULL, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4181 X_BINARY X_NOT_H_R ")",
4182 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4184 X_BINARY X_NOT_H_R ")",
4185 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4187 X_BINARY X_NOT_H_R ")",
4188 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4190 0, countryStringValidate, IA5StringNormalize, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4192 0, dnValidate, dnNormalize, dnPretty},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4194 0, NULL, NULL, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4196 0, NULL, NULL, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4198 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4199 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4200 0, NULL, NULL, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4202 0, NULL, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4204 0, NULL, NULL, NULL},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4206 0, NULL, NULL, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4208 0, NULL, NULL, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4210 0, printablesStringValidate, IA5StringNormalize, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4212 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4214 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4216 0, NULL, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4218 0, IA5StringValidate, IA5StringNormalize, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4220 0, integerValidate, integerNormalize, integerPretty},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4222 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4224 0, NULL, NULL, NULL},
4225 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4226 0, NULL, NULL, NULL},
4227 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4228 0, NULL, NULL, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4230 0, NULL, NULL, NULL},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4232 0, NULL, NULL, NULL},
4233 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4234 0, nameUIDValidate, nameUIDNormalize, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4236 0, NULL, NULL, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4238 0, numericStringValidate, numericStringNormalize, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4240 0, NULL, NULL, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4242 0, oidValidate, NULL, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4244 0, IA5StringValidate, IA5StringNormalize, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4246 0, blobValidate, NULL, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4248 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4250 0, NULL, NULL, NULL},
4251 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4252 0, NULL, NULL, NULL},
4253 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4254 0, printableStringValidate, IA5StringNormalize, NULL},
4255 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4256 X_BINARY X_NOT_H_R ")",
4257 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4258 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4259 0, printableStringValidate, IA5StringNormalize, NULL},
4260 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4261 0, NULL, NULL, NULL},
4262 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4263 0, printableStringValidate, IA5StringNormalize, NULL},
4264 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4265 0, utcTimeValidate, utcTimeNormalize, NULL},
4266 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4267 0, NULL, NULL, NULL},
4268 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4269 0, NULL, NULL, NULL},
4270 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4271 0, NULL, NULL, NULL},
4272 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4273 0, NULL, NULL, NULL},
4274 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4275 0, NULL, NULL, NULL},
4277 /* RFC 2307 NIS Syntaxes */
4278 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4279 0, nisNetgroupTripleValidate, NULL, NULL},
4280 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4281 0, bootParameterValidate, NULL, NULL},
4283 /* OpenLDAP Experimental Syntaxes */
4284 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4285 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4287 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4288 0, NULL, NULL, NULL},
4290 /* OpenLDAP Void Syntax */
4291 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4292 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4293 {NULL, 0, NULL, NULL, NULL}
4296 struct mrule_defs_rec {
4298 slap_mask_t mrd_usage;
4299 slap_mr_convert_func * mrd_convert;
4300 slap_mr_normalize_func * mrd_normalize;
4301 slap_mr_match_func * mrd_match;
4302 slap_mr_indexer_func * mrd_indexer;
4303 slap_mr_filter_func * mrd_filter;
4305 char * mrd_associated;
4309 * Other matching rules in X.520 that we do not use (yet):
4311 * 2.5.13.9 numericStringOrderingMatch
4312 * 2.5.13.15 integerOrderingMatch
4313 * 2.5.13.18 octetStringOrderingMatch
4314 * 2.5.13.19 octetStringSubstringsMatch
4315 * 2.5.13.25 uTCTimeMatch
4316 * 2.5.13.26 uTCTimeOrderingMatch
4317 * 2.5.13.31 directoryStringFirstComponentMatch
4318 * 2.5.13.32 wordMatch
4319 * 2.5.13.33 keywordMatch
4320 * 2.5.13.34 certificateExactMatch
4321 * 2.5.13.35 certificateMatch
4322 * 2.5.13.36 certificatePairExactMatch
4323 * 2.5.13.37 certificatePairMatch
4324 * 2.5.13.38 certificateListExactMatch
4325 * 2.5.13.39 certificateListMatch
4326 * 2.5.13.40 algorithmIdentifierMatch
4327 * 2.5.13.41 storedPrefixMatch
4328 * 2.5.13.42 attributeCertificateMatch
4329 * 2.5.13.43 readerAndKeyIDMatch
4330 * 2.5.13.44 attributeIntegrityMatch
4333 struct mrule_defs_rec mrule_defs[] = {
4335 * EQUALITY matching rules must be listed after associated APPROX
4336 * matching rules. So, we list all APPROX matching rules first.
4338 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4339 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4340 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4342 directoryStringApproxMatch,
4343 directoryStringApproxIndexer,
4344 directoryStringApproxFilter,
4347 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4348 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4349 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4351 IA5StringApproxMatch,
4352 IA5StringApproxIndexer,
4353 IA5StringApproxFilter,
4357 * Other matching rules
4360 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4361 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4362 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4364 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4367 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4368 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4369 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4371 dnMatch, dnIndexer, dnFilter,
4374 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4375 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4376 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4378 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4379 directoryStringApproxMatchOID },
4381 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4382 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4385 caseIgnoreOrderingMatch, NULL, NULL,
4388 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4389 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4390 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4392 caseIgnoreSubstringsMatch,
4393 caseIgnoreSubstringsIndexer,
4394 caseIgnoreSubstringsFilter,
4397 {"( 2.5.13.5 NAME 'caseExactMatch' "
4398 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4399 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4401 caseExactMatch, caseExactIndexer, caseExactFilter,
4402 directoryStringApproxMatchOID },
4404 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4405 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4408 caseExactOrderingMatch, NULL, NULL,
4411 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4412 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4413 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4415 caseExactSubstringsMatch,
4416 caseExactSubstringsIndexer,
4417 caseExactSubstringsFilter,
4420 {"( 2.5.13.8 NAME 'numericStringMatch' "
4421 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4422 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4425 caseIgnoreIA5Indexer,
4426 caseIgnoreIA5Filter,
4429 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4430 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4431 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4433 caseIgnoreIA5SubstringsMatch,
4434 caseIgnoreIA5SubstringsIndexer,
4435 caseIgnoreIA5SubstringsFilter,
4438 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4439 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4440 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4442 caseIgnoreListMatch, NULL, NULL,
4445 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4446 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4447 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4449 caseIgnoreListSubstringsMatch, NULL, NULL,
4452 {"( 2.5.13.13 NAME 'booleanMatch' "
4453 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4454 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4456 booleanMatch, NULL, NULL,
4459 {"( 2.5.13.14 NAME 'integerMatch' "
4460 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4461 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4463 integerMatch, integerIndexer, integerFilter,
4466 {"( 2.5.13.16 NAME 'bitStringMatch' "
4467 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4468 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4470 bitStringMatch, NULL, NULL,
4473 {"( 2.5.13.17 NAME 'octetStringMatch' "
4474 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4475 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4477 octetStringMatch, octetStringIndexer, octetStringFilter,
4480 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4481 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4482 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4484 telephoneNumberMatch,
4485 telephoneNumberIndexer,
4486 telephoneNumberFilter,
4489 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4490 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4491 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4493 telephoneNumberSubstringsMatch,
4494 telephoneNumberSubstringsIndexer,
4495 telephoneNumberSubstringsFilter,
4498 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4499 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4500 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4505 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4506 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4507 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4509 uniqueMemberMatch, NULL, NULL,
4512 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4513 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4514 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4516 protocolInformationMatch, NULL, NULL,
4519 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4520 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4521 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4523 generalizedTimeMatch, NULL, NULL,
4526 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4527 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4530 generalizedTimeOrderingMatch, NULL, NULL,
4533 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4534 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4535 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4537 integerFirstComponentMatch, NULL, NULL,
4540 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4541 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4542 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4544 objectIdentifierFirstComponentMatch, NULL, NULL,
4547 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4548 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4549 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4551 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4552 IA5StringApproxMatchOID },
4554 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4555 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4556 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4558 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4559 IA5StringApproxMatchOID },
4561 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4562 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4565 caseIgnoreIA5SubstringsMatch,
4566 caseIgnoreIA5SubstringsIndexer,
4567 caseIgnoreIA5SubstringsFilter,
4570 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4571 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4574 caseExactIA5SubstringsMatch,
4575 caseExactIA5SubstringsIndexer,
4576 caseExactIA5SubstringsFilter,
4579 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4580 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4583 authPasswordMatch, NULL, NULL,
4586 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4587 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4590 OpenLDAPaciMatch, NULL, NULL,
4593 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4602 /* we should only be called once (from main) */
4603 assert( schema_init_done == 0 );
4605 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4606 res = register_syntax( syntax_defs[i].sd_desc,
4607 syntax_defs[i].sd_flags,
4608 syntax_defs[i].sd_validate,
4609 syntax_defs[i].sd_normalize,
4610 syntax_defs[i].sd_pretty
4611 #ifdef SLAPD_BINARY_CONVERSION
4613 syntax_defs[i].sd_ber2str,
4614 syntax_defs[i].sd_str2ber
4619 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4620 syntax_defs[i].sd_desc );
4625 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4626 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4628 "schema_init: Ingoring unusable matching rule %s\n",
4629 mrule_defs[i].mrd_desc );
4633 res = register_matching_rule(
4634 mrule_defs[i].mrd_desc,
4635 mrule_defs[i].mrd_usage,
4636 mrule_defs[i].mrd_convert,
4637 mrule_defs[i].mrd_normalize,
4638 mrule_defs[i].mrd_match,
4639 mrule_defs[i].mrd_indexer,
4640 mrule_defs[i].mrd_filter,
4641 mrule_defs[i].mrd_associated );
4645 "schema_init: Error registering matching rule %s\n",
4646 mrule_defs[i].mrd_desc );
4650 schema_init_done = 1;
4651 return LDAP_SUCCESS;