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 = get_validated_dn( in->bv_val, 0, 0 );
238 rc = ( dn == NULL ) ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
250 struct berval **normalized )
254 if ( val->bv_len == 0 ) {
255 out = ber_bvdup( val );
258 #ifdef USE_DN_NORMALIZE
259 dn = get_validated_dn( val->bv_val, 1, 1 );
261 dn = get_validated_dn( val->bv_val, 0, 0 );
264 return LDAP_INVALID_SYNTAX;
267 out = (struct berval *)ch_malloc(sizeof(struct berval));
269 out->bv_len = strlen( dn );
282 struct berval *value,
283 void *assertedValue )
286 struct berval *asserted = (struct berval *) assertedValue;
288 match = value->bv_len - asserted->bv_len;
291 #ifdef USE_DN_NORMALIZE
292 match = strcmp( value->bv_val, asserted->bv_val );
294 match = strcasecmp( value->bv_val, asserted->bv_val );
299 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
300 "dnMatch: %d\n %s\n %s\n", match,
301 value->bv_val, asserted->bv_val ));
303 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
304 match, value->bv_val, asserted->bv_val );
320 if( in->bv_len == 0 ) return LDAP_SUCCESS;
322 dn = ber_bvdup( in );
324 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
325 /* assume presence of optional UID */
328 for(i=dn->bv_len-2; i>2; i--) {
329 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
333 if( dn->bv_val[i] != '\'' ) {
334 return LDAP_INVALID_SYNTAX;
336 if( dn->bv_val[i-1] != 'B' ) {
337 return LDAP_INVALID_SYNTAX;
339 if( dn->bv_val[i-2] != '#' ) {
340 return LDAP_INVALID_SYNTAX;
343 /* trim the UID to allow use of dn_validate */
344 dn->bv_val[i-2] = '\0';
347 rc = dn_validate( dn->bv_val ) == NULL
348 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
358 struct berval **normalized )
360 struct berval *out = ber_bvdup( val );
362 if( out->bv_len != 0 ) {
366 ber_len_t uidlen = 0;
368 if( out->bv_val[out->bv_len-1] == '\'' ) {
369 /* assume presence of optional UID */
370 uid = strrchr( out->bv_val, '#' );
374 return LDAP_INVALID_SYNTAX;
377 uidlen = out->bv_len - (out->bv_val - uid);
378 /* temporarily trim the UID */
382 #ifdef USE_DN_NORMALIZE
383 dn = dn_normalize( out->bv_val );
385 dn = dn_validate( out->bv_val );
390 return LDAP_INVALID_SYNTAX;
396 /* restore the separator */
399 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
403 out->bv_len = dnlen + uidlen;
415 /* any value allowed */
424 /* any value allowed */
435 /* very unforgiving validation, requires no normalization
436 * before simplistic matching
438 if( in->bv_len < 3 ) {
439 return LDAP_INVALID_SYNTAX;
442 if( in->bv_val[0] != 'B' ||
443 in->bv_val[1] != '\'' ||
444 in->bv_val[in->bv_len-1] != '\'' )
446 return LDAP_INVALID_SYNTAX;
449 for( i=in->bv_len-2; i>1; i-- ) {
450 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
451 return LDAP_INVALID_SYNTAX;
459 * Handling boolean syntax and matching is quite rigid.
460 * A more flexible approach would be to allow a variety
461 * of strings to be normalized and prettied into TRUE
469 /* very unforgiving validation, requires no normalization
470 * before simplistic matching
473 if( in->bv_len == 4 ) {
474 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
477 } else if( in->bv_len == 5 ) {
478 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
483 return LDAP_INVALID_SYNTAX;
492 struct berval *value,
493 void *assertedValue )
495 /* simplistic matching allowed by rigid validation */
496 struct berval *asserted = (struct berval *) assertedValue;
497 *matchp = value->bv_len != asserted->bv_len;
502 /* case insensitive UTF8 strncmp with offset for second string */
505 struct berval *right,
511 ber_len_t rlen, llen;
512 ber_len_t rslen, lslen;
513 ldap_unicode_t ru, lu;
514 ldap_unicode_t ruu, luu;
516 rslen = len < right->bv_len ? len : right->bv_len;
517 lslen = len + offset < left->bv_len ? len : left->bv_len;
519 for( r = 0, l = offset;
520 r < rslen && l < lslen;
524 * XXYYZ: we convert to ucs4 even though -llunicode
525 * expects ucs2 in an unsigned long
527 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
528 if( ru == LDAP_UCS4_INVALID ) {
532 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
533 if( lu == LDAP_UCS4_INVALID ) {
537 ruu = uctoupper( ru );
538 luu = uctoupper( lu );
542 } else if( luu > ruu ) {
546 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
547 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
563 static char *UTF8casechr( const char *str, const char *c )
565 char *p, *lower, *upper;
566 ldap_ucs4_t tch, ch = ldap_utf8_to_ucs4(c);
568 tch = uctolower ( ch );
569 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
570 if( ldap_utf8_to_ucs4( p ) == tch ) {
574 lower = *p != '\0' ? p : NULL;
576 tch = uctoupper ( ch );
577 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
578 if( ldap_utf8_to_ucs4( p ) == tch ) {
582 upper = *p != '\0' ? p : NULL;
584 if( lower && upper ) {
585 return lower < upper ? lower : upper;
586 } else if ( lower ) {
601 unsigned char *u = in->bv_val;
603 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
605 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
606 /* get the length indicated by the first byte */
607 len = LDAP_UTF8_CHARLEN( u );
609 /* should not be zero */
610 if( len == 0 ) return LDAP_INVALID_SYNTAX;
612 /* make sure len corresponds with the offset
613 to the next character */
614 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
617 if( count != 0 ) return LDAP_INVALID_SYNTAX;
626 struct berval **normalized )
628 struct berval *newval;
631 newval = ch_malloc( sizeof( struct berval ) );
635 /* Ignore initial whitespace */
636 while ( ldap_utf8_isspace( p ) ) {
642 return LDAP_INVALID_SYNTAX;
645 newval->bv_val = ch_strdup( p );
646 p = q = newval->bv_val;
652 if ( ldap_utf8_isspace( p ) ) {
653 len = LDAP_UTF8_COPY(q,p);
658 /* Ignore the extra whitespace */
659 while ( ldap_utf8_isspace( p ) ) {
663 len = LDAP_UTF8_COPY(q,p);
670 assert( *newval->bv_val );
671 assert( newval->bv_val < p );
674 /* cannot start with a space */
675 assert( !ldap_utf8_isspace(newval->bv_val) );
678 * If the string ended in space, backup the pointer one
679 * position. One is enough because the above loop collapsed
680 * all whitespace to a single space.
687 /* cannot end with a space */
688 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
693 newval->bv_len = q - newval->bv_val;
694 *normalized = newval;
699 #if defined(SLAPD_APPROX_MULTISTRING)
701 #if defined(SLAPD_APPROX_INITIALS)
702 #define SLAPD_APPROX_DELIMITER "._ "
703 #define SLAPD_APPROX_WORDLEN 2
705 #define SLAPD_APPROX_DELIMITER " "
706 #define SLAPD_APPROX_WORDLEN 1
715 struct berval *value,
716 void *assertedValue )
718 char *val, *assertv, **values, **words, *c;
719 int i, count, len, nextchunk=0, nextavail=0;
722 /* Isolate how many words there are */
723 val = ch_strdup( value->bv_val );
724 for( c=val,count=1; *c; c++ ) {
725 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
726 if ( c == NULL ) break;
731 /* Get a phonetic copy of each word */
732 words = (char **)ch_malloc( count * sizeof(char *) );
733 values = (char **)ch_malloc( count * sizeof(char *) );
734 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
736 values[i] = phonetic(c);
740 /* Work through the asserted value's words, to see if at least some
741 of the words are there, in the same order. */
742 assertv = ch_strdup( ((struct berval *)assertedValue)->bv_val );
744 while ( nextchunk < ((struct berval *)assertedValue)->bv_len ) {
745 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
750 #if defined(SLAPD_APPROX_INITIALS)
751 else if( len == 1 ) {
752 /* Single letter words need to at least match one word's initial */
753 for( i=nextavail; i<count; i++ )
754 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
761 /* Isolate the next word in the asserted value and phonetic it */
762 assertv[nextchunk+len] = '\0';
763 val = phonetic( assertv + nextchunk );
765 /* See if this phonetic chunk is in the remaining words of *value */
766 for( i=nextavail; i<count; i++ ){
767 if( !strcmp( val, values[i] ) ){
774 /* This chunk in the asserted value was NOT within the *value. */
780 /* Go on to the next word in the asserted value */
784 /* If some of the words were seen, call it a match */
785 if( nextavail > 0 ) {
794 for( i=0; i<count; i++ ) {
795 ch_free( values[i] );
811 struct berval *prefix,
812 struct berval **values,
813 struct berval ***keysp )
816 int i,j, len, wordcount, keycount=0;
817 struct berval **newkeys, **keys=NULL;
820 for( j=0; values[j] != NULL; j++ ) {
822 /* Isolate how many words there are. There will be a key for each */
823 val = ch_strdup( values[j]->bv_val );
824 for( wordcount=0,c=val; *c; c++) {
825 len = strcspn(c, SLAPD_APPROX_DELIMITER);
826 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
828 if (*c == '\0') break;
832 /* Allocate/increase storage to account for new keys */
833 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
834 * sizeof(struct berval *) );
835 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
836 if( keys ) ch_free( keys );
839 /* Get a phonetic copy of each word */
840 for( c=val,i=0; i<wordcount; c+=len+1 ) {
842 if( len < SLAPD_APPROX_WORDLEN ) continue;
843 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
844 keys[keycount]->bv_val = phonetic( c );
845 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
852 keys[keycount] = NULL;
865 struct berval *prefix,
867 struct berval ***keysp )
871 struct berval **keys;
874 /* Isolate how many words there are. There will be a key for each */
875 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
876 for( count=0,c=val; *c; c++) {
877 len = strcspn(c, SLAPD_APPROX_DELIMITER);
878 if( len >= SLAPD_APPROX_WORDLEN ) count++;
880 if (*c == '\0') break;
884 /* Allocate storage for new keys */
885 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
887 /* Get a phonetic copy of each word */
888 for( c=val,i=0; i<count; c+=len+1 ) {
890 if( len < SLAPD_APPROX_WORDLEN ) continue;
891 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
892 keys[i]->bv_val = phonetic( c );
893 keys[i]->bv_len = strlen( keys[i]->bv_val );
907 /* No other form of Approximate Matching is defined */
915 struct berval *value,
916 void *assertedValue )
918 char *vapprox, *avapprox;
920 vapprox = phonetic( value->bv_val );
921 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
923 *matchp = strcmp( vapprox, avapprox );
937 struct berval *prefix,
938 struct berval **values,
939 struct berval ***keysp )
942 struct berval **keys;
945 for( i=0; values[i] != NULL; i++ ) {
946 /* just count them */
950 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
952 /* Copy each value and run it through phonetic() */
953 for( i=0; values[i] != NULL; i++ ) {
954 keys[i] = ch_malloc( sizeof( struct berval * ) );
955 keys[i]->bv_val = phonetic( values[i]->bv_val );
956 keys[i]->bv_len = strlen( keys[i]->bv_val );
971 struct berval *prefix,
973 struct berval ***keysp )
975 struct berval **keys;
978 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
980 /* Copy the value and run it through phonetic() */
981 keys[0] = ch_malloc( sizeof( struct berval * ) );
982 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
983 keys[0]->bv_len = strlen( keys[0]->bv_val );
998 struct berval *value,
999 void *assertedValue )
1001 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1004 match = strncmp( value->bv_val,
1005 ((struct berval *) assertedValue)->bv_val,
1010 return LDAP_SUCCESS;
1014 caseExactSubstringsMatch(
1019 struct berval *value,
1020 void *assertedValue )
1023 SubstringsAssertion *sub = assertedValue;
1024 struct berval left = *value;
1028 /* Add up asserted input length */
1029 if( sub->sa_initial ) {
1030 inlen += sub->sa_initial->bv_len;
1033 for(i=0; sub->sa_any[i] != NULL; i++) {
1034 inlen += sub->sa_any[i]->bv_len;
1037 if( sub->sa_final ) {
1038 inlen += sub->sa_final->bv_len;
1041 if( sub->sa_initial ) {
1042 if( inlen > left.bv_len ) {
1047 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1048 sub->sa_initial->bv_len );
1054 left.bv_val += sub->sa_initial->bv_len;
1055 left.bv_len -= sub->sa_initial->bv_len;
1056 inlen -= sub->sa_initial->bv_len;
1059 if( sub->sa_final ) {
1060 if( inlen > left.bv_len ) {
1065 match = strncmp( sub->sa_final->bv_val,
1066 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1067 sub->sa_final->bv_len );
1073 left.bv_len -= sub->sa_final->bv_len;
1074 inlen -= sub->sa_final->bv_len;
1078 for(i=0; sub->sa_any[i]; i++) {
1083 if( inlen > left.bv_len ) {
1084 /* not enough length */
1089 if( sub->sa_any[i]->bv_len == 0 ) {
1093 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1100 idx = p - left.bv_val;
1101 assert( idx < left.bv_len );
1103 if( idx >= left.bv_len ) {
1104 /* this shouldn't happen */
1111 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1112 /* not enough left */
1117 match = strncmp( left.bv_val,
1118 sub->sa_any[i]->bv_val,
1119 sub->sa_any[i]->bv_len );
1127 left.bv_val += sub->sa_any[i]->bv_len;
1128 left.bv_len -= sub->sa_any[i]->bv_len;
1129 inlen -= sub->sa_any[i]->bv_len;
1135 return LDAP_SUCCESS;
1138 /* Index generation function */
1139 int caseExactIndexer(
1144 struct berval *prefix,
1145 struct berval **values,
1146 struct berval ***keysp )
1150 struct berval **keys;
1151 HASH_CONTEXT HASHcontext;
1152 unsigned char HASHdigest[HASH_BYTES];
1153 struct berval digest;
1154 digest.bv_val = HASHdigest;
1155 digest.bv_len = sizeof(HASHdigest);
1157 /* we should have at least one value at this point */
1158 assert( values != NULL && values[0] != NULL );
1160 for( i=0; values[i] != NULL; i++ ) {
1161 /* just count them */
1164 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1166 slen = strlen( syntax->ssyn_oid );
1167 mlen = strlen( mr->smr_oid );
1169 for( i=0; values[i] != NULL; i++ ) {
1170 struct berval *value;
1172 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
1177 HASH_Init( &HASHcontext );
1178 if( prefix != NULL && prefix->bv_len > 0 ) {
1179 HASH_Update( &HASHcontext,
1180 prefix->bv_val, prefix->bv_len );
1182 HASH_Update( &HASHcontext,
1183 syntax->ssyn_oid, slen );
1184 HASH_Update( &HASHcontext,
1185 mr->smr_oid, mlen );
1186 HASH_Update( &HASHcontext,
1187 value->bv_val, value->bv_len );
1188 HASH_Final( HASHdigest, &HASHcontext );
1191 ber_bvfree( value );
1194 keys[i] = ber_bvdup( &digest );
1199 return LDAP_SUCCESS;
1202 /* Index generation function */
1203 int caseExactFilter(
1208 struct berval *prefix,
1210 struct berval ***keysp )
1213 struct berval **keys;
1214 HASH_CONTEXT HASHcontext;
1215 unsigned char HASHdigest[HASH_BYTES];
1216 struct berval *value;
1217 struct berval digest;
1218 digest.bv_val = HASHdigest;
1219 digest.bv_len = sizeof(HASHdigest);
1221 slen = strlen( syntax->ssyn_oid );
1222 mlen = strlen( mr->smr_oid );
1225 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val,
1226 UTF8_NOCASEFOLD ) );
1227 /* This usually happens if filter contains bad UTF8 */
1228 if( value == NULL ) {
1229 keys = ch_malloc( sizeof( struct berval * ) );
1231 return LDAP_SUCCESS;
1234 value = (struct berval *) assertValue;
1237 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1239 HASH_Init( &HASHcontext );
1240 if( prefix != NULL && prefix->bv_len > 0 ) {
1241 HASH_Update( &HASHcontext,
1242 prefix->bv_val, prefix->bv_len );
1244 HASH_Update( &HASHcontext,
1245 syntax->ssyn_oid, slen );
1246 HASH_Update( &HASHcontext,
1247 mr->smr_oid, mlen );
1248 HASH_Update( &HASHcontext,
1249 value->bv_val, value->bv_len );
1250 HASH_Final( HASHdigest, &HASHcontext );
1252 keys[0] = ber_bvdup( &digest );
1256 ber_bvfree( value );
1260 return LDAP_SUCCESS;
1263 /* Substrings Index generation function */
1264 int caseExactSubstringsIndexer(
1269 struct berval *prefix,
1270 struct berval **values,
1271 struct berval ***keysp )
1275 struct berval **keys;
1276 HASH_CONTEXT HASHcontext;
1277 unsigned char HASHdigest[HASH_BYTES];
1278 struct berval digest;
1279 digest.bv_val = HASHdigest;
1280 digest.bv_len = sizeof(HASHdigest);
1282 /* we should have at least one value at this point */
1283 assert( values != NULL && values[0] != NULL );
1286 for( i=0; values[i] != NULL; i++ ) {
1287 /* count number of indices to generate */
1288 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1292 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1293 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1294 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1295 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1297 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1301 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1302 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1303 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1307 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1308 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1309 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1310 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1312 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1318 /* no keys to generate */
1320 return LDAP_SUCCESS;
1323 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1325 slen = strlen( syntax->ssyn_oid );
1326 mlen = strlen( mr->smr_oid );
1329 for( i=0; values[i] != NULL; i++ ) {
1331 struct berval *value;
1333 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1336 value = ber_bvstr( UTF8normalize( values[i]->bv_val,
1337 UTF8_NOCASEFOLD ) );
1342 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1343 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1345 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1346 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1348 for( j=0; j<max; j++ ) {
1349 HASH_Init( &HASHcontext );
1350 if( prefix != NULL && prefix->bv_len > 0 ) {
1351 HASH_Update( &HASHcontext,
1352 prefix->bv_val, prefix->bv_len );
1355 HASH_Update( &HASHcontext,
1356 &pre, sizeof( pre ) );
1357 HASH_Update( &HASHcontext,
1358 syntax->ssyn_oid, slen );
1359 HASH_Update( &HASHcontext,
1360 mr->smr_oid, mlen );
1361 HASH_Update( &HASHcontext,
1363 SLAP_INDEX_SUBSTR_MAXLEN );
1364 HASH_Final( HASHdigest, &HASHcontext );
1366 keys[nkeys++] = ber_bvdup( &digest );
1370 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1371 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1373 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1376 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1377 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1378 HASH_Init( &HASHcontext );
1379 if( prefix != NULL && prefix->bv_len > 0 ) {
1380 HASH_Update( &HASHcontext,
1381 prefix->bv_val, prefix->bv_len );
1383 HASH_Update( &HASHcontext,
1384 &pre, sizeof( pre ) );
1385 HASH_Update( &HASHcontext,
1386 syntax->ssyn_oid, slen );
1387 HASH_Update( &HASHcontext,
1388 mr->smr_oid, mlen );
1389 HASH_Update( &HASHcontext,
1391 HASH_Final( HASHdigest, &HASHcontext );
1393 keys[nkeys++] = ber_bvdup( &digest );
1396 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1397 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1398 HASH_Init( &HASHcontext );
1399 if( prefix != NULL && prefix->bv_len > 0 ) {
1400 HASH_Update( &HASHcontext,
1401 prefix->bv_val, prefix->bv_len );
1403 HASH_Update( &HASHcontext,
1404 &pre, sizeof( pre ) );
1405 HASH_Update( &HASHcontext,
1406 syntax->ssyn_oid, slen );
1407 HASH_Update( &HASHcontext,
1408 mr->smr_oid, mlen );
1409 HASH_Update( &HASHcontext,
1410 &value->bv_val[value->bv_len-j], j );
1411 HASH_Final( HASHdigest, &HASHcontext );
1413 keys[nkeys++] = ber_bvdup( &digest );
1419 ber_bvfree( value );
1431 return LDAP_SUCCESS;
1434 int caseExactSubstringsFilter(
1439 struct berval *prefix,
1441 struct berval ***keysp )
1443 SubstringsAssertion *sa = assertValue;
1445 ber_len_t nkeys = 0;
1446 size_t slen, mlen, klen;
1447 struct berval **keys;
1448 HASH_CONTEXT HASHcontext;
1449 unsigned char HASHdigest[HASH_BYTES];
1450 struct berval *value;
1451 struct berval digest;
1453 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1454 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1459 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1461 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1462 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1463 /* don't bother accounting for stepping */
1464 nkeys += sa->sa_any[i]->bv_len -
1465 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1470 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1471 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1478 return LDAP_SUCCESS;
1481 digest.bv_val = HASHdigest;
1482 digest.bv_len = sizeof(HASHdigest);
1484 slen = strlen( syntax->ssyn_oid );
1485 mlen = strlen( mr->smr_oid );
1487 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1490 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1491 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1493 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1495 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val,
1496 UTF8_NOCASEFOLD ) );
1498 value = sa->sa_initial;
1501 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1502 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1504 HASH_Init( &HASHcontext );
1505 if( prefix != NULL && prefix->bv_len > 0 ) {
1506 HASH_Update( &HASHcontext,
1507 prefix->bv_val, prefix->bv_len );
1509 HASH_Update( &HASHcontext,
1510 &pre, sizeof( pre ) );
1511 HASH_Update( &HASHcontext,
1512 syntax->ssyn_oid, slen );
1513 HASH_Update( &HASHcontext,
1514 mr->smr_oid, mlen );
1515 HASH_Update( &HASHcontext,
1516 value->bv_val, klen );
1517 HASH_Final( HASHdigest, &HASHcontext );
1520 ber_bvfree( value );
1522 keys[nkeys++] = ber_bvdup( &digest );
1525 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1527 pre = SLAP_INDEX_SUBSTR_PREFIX;
1528 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1530 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1531 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1536 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val,
1537 UTF8_NOCASEFOLD ) );
1539 value = sa->sa_any[i];
1543 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1544 j += SLAP_INDEX_SUBSTR_STEP )
1546 HASH_Init( &HASHcontext );
1547 if( prefix != NULL && prefix->bv_len > 0 ) {
1548 HASH_Update( &HASHcontext,
1549 prefix->bv_val, prefix->bv_len );
1551 HASH_Update( &HASHcontext,
1552 &pre, sizeof( pre ) );
1553 HASH_Update( &HASHcontext,
1554 syntax->ssyn_oid, slen );
1555 HASH_Update( &HASHcontext,
1556 mr->smr_oid, mlen );
1557 HASH_Update( &HASHcontext,
1558 &value->bv_val[j], klen );
1559 HASH_Final( HASHdigest, &HASHcontext );
1561 keys[nkeys++] = ber_bvdup( &digest );
1565 ber_bvfree( value );
1570 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1571 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1573 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1575 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val,
1576 UTF8_NOCASEFOLD ) );
1578 value = sa->sa_final;
1581 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1582 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1584 HASH_Init( &HASHcontext );
1585 if( prefix != NULL && prefix->bv_len > 0 ) {
1586 HASH_Update( &HASHcontext,
1587 prefix->bv_val, prefix->bv_len );
1589 HASH_Update( &HASHcontext,
1590 &pre, sizeof( pre ) );
1591 HASH_Update( &HASHcontext,
1592 syntax->ssyn_oid, slen );
1593 HASH_Update( &HASHcontext,
1594 mr->smr_oid, mlen );
1595 HASH_Update( &HASHcontext,
1596 &value->bv_val[value->bv_len-klen], klen );
1597 HASH_Final( HASHdigest, &HASHcontext );
1600 ber_bvfree( value );
1602 keys[nkeys++] = ber_bvdup( &digest );
1613 return LDAP_SUCCESS;
1622 struct berval *value,
1623 void *assertedValue )
1626 *matchp = UTF8normcmp( value->bv_val,
1627 ((struct berval *) assertedValue)->bv_val,
1630 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1633 match = strncasecmp( value->bv_val,
1634 ((struct berval *) assertedValue)->bv_val,
1640 return LDAP_SUCCESS;
1644 caseIgnoreSubstringsMatch(
1649 struct berval *value,
1650 void *assertedValue )
1653 SubstringsAssertion *sub = assertedValue;
1654 struct berval left = *value;
1658 /* Add up asserted input length */
1659 if( sub->sa_initial ) {
1660 inlen += sub->sa_initial->bv_len;
1663 for(i=0; sub->sa_any[i] != NULL; i++) {
1664 inlen += sub->sa_any[i]->bv_len;
1667 if( sub->sa_final ) {
1668 inlen += sub->sa_final->bv_len;
1671 if( sub->sa_initial ) {
1672 if( inlen > left.bv_len ) {
1678 match = UTF8oncasecmp( sub->sa_initial, &left,
1679 sub->sa_initial->bv_len, 0 );
1681 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1682 sub->sa_initial->bv_len );
1689 left.bv_val += sub->sa_initial->bv_len;
1690 left.bv_len -= sub->sa_initial->bv_len;
1691 inlen -= sub->sa_initial->bv_len;
1694 if( sub->sa_final ) {
1695 if( inlen > left.bv_len ) {
1701 match = UTF8oncasecmp( sub->sa_final, &left,
1702 sub->sa_final->bv_len,
1703 left.bv_len - sub->sa_final->bv_len );
1705 match = strncasecmp( sub->sa_final->bv_val,
1706 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1707 sub->sa_final->bv_len );
1714 left.bv_len -= sub->sa_final->bv_len;
1715 inlen -= sub->sa_final->bv_len;
1719 for(i=0; sub->sa_any[i]; i++) {
1724 if( inlen > left.bv_len ) {
1725 /* not enough length */
1730 if( sub->sa_any[i]->bv_len == 0 ) {
1735 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1737 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1745 idx = p - left.bv_val;
1746 assert( idx < left.bv_len );
1748 if( idx >= left.bv_len ) {
1749 /* this shouldn't happen */
1756 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1757 /* not enough left */
1763 match = UTF8oncasecmp( &left, sub->sa_any[i],
1764 sub->sa_any[i]->bv_len, 0 );
1767 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1773 match = strncasecmp( left.bv_val,
1774 sub->sa_any[i]->bv_val,
1775 sub->sa_any[i]->bv_len );
1785 left.bv_val += sub->sa_any[i]->bv_len;
1786 left.bv_len -= sub->sa_any[i]->bv_len;
1787 inlen -= sub->sa_any[i]->bv_len;
1793 return LDAP_SUCCESS;
1796 /* Index generation function */
1797 int caseIgnoreIndexer(
1802 struct berval *prefix,
1803 struct berval **values,
1804 struct berval ***keysp )
1808 struct berval **keys;
1809 HASH_CONTEXT HASHcontext;
1810 unsigned char HASHdigest[HASH_BYTES];
1811 struct berval digest;
1812 digest.bv_val = HASHdigest;
1813 digest.bv_len = sizeof(HASHdigest);
1815 /* we should have at least one value at this point */
1816 assert( values != NULL && values[0] != NULL );
1818 for( i=0; values[i] != NULL; i++ ) {
1819 /* just count them */
1822 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1824 slen = strlen( syntax->ssyn_oid );
1825 mlen = strlen( mr->smr_oid );
1827 for( i=0; values[i] != NULL; i++ ) {
1828 struct berval *value;
1830 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1832 value = ber_bvdup( values[i] );
1833 ldap_pvt_str2upper( value->bv_val );
1835 HASH_Init( &HASHcontext );
1836 if( prefix != NULL && prefix->bv_len > 0 ) {
1837 HASH_Update( &HASHcontext,
1838 prefix->bv_val, prefix->bv_len );
1840 HASH_Update( &HASHcontext,
1841 syntax->ssyn_oid, slen );
1842 HASH_Update( &HASHcontext,
1843 mr->smr_oid, mlen );
1844 HASH_Update( &HASHcontext,
1845 value->bv_val, value->bv_len );
1846 HASH_Final( HASHdigest, &HASHcontext );
1848 ber_bvfree( value );
1850 keys[i] = ber_bvdup( &digest );
1855 return LDAP_SUCCESS;
1858 /* Index generation function */
1859 int caseIgnoreFilter(
1864 struct berval *prefix,
1866 struct berval ***keysp )
1869 struct berval **keys;
1870 HASH_CONTEXT HASHcontext;
1871 unsigned char HASHdigest[HASH_BYTES];
1872 struct berval *value;
1873 struct berval digest;
1874 digest.bv_val = HASHdigest;
1875 digest.bv_len = sizeof(HASHdigest);
1877 slen = strlen( syntax->ssyn_oid );
1878 mlen = strlen( mr->smr_oid );
1881 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val,
1883 /* This usually happens if filter contains bad UTF8 */
1884 if( value == NULL ) {
1885 keys = ch_malloc( sizeof( struct berval * ) );
1887 return LDAP_SUCCESS;
1890 value = ber_bvdup( (struct berval *) assertValue );
1891 ldap_pvt_str2upper( value->bv_val );
1894 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1896 HASH_Init( &HASHcontext );
1897 if( prefix != NULL && prefix->bv_len > 0 ) {
1898 HASH_Update( &HASHcontext,
1899 prefix->bv_val, prefix->bv_len );
1901 HASH_Update( &HASHcontext,
1902 syntax->ssyn_oid, slen );
1903 HASH_Update( &HASHcontext,
1904 mr->smr_oid, mlen );
1905 HASH_Update( &HASHcontext,
1906 value->bv_val, value->bv_len );
1907 HASH_Final( HASHdigest, &HASHcontext );
1909 keys[0] = ber_bvdup( &digest );
1912 ber_bvfree( value );
1916 return LDAP_SUCCESS;
1919 /* Substrings Index generation function */
1920 int caseIgnoreSubstringsIndexer(
1925 struct berval *prefix,
1926 struct berval **values,
1927 struct berval ***keysp )
1931 struct berval **keys;
1932 HASH_CONTEXT HASHcontext;
1933 unsigned char HASHdigest[HASH_BYTES];
1934 struct berval digest;
1935 digest.bv_val = HASHdigest;
1936 digest.bv_len = sizeof(HASHdigest);
1938 /* we should have at least one value at this point */
1939 assert( values != NULL && values[0] != NULL );
1942 for( i=0; values[i] != NULL; i++ ) {
1943 /* count number of indices to generate */
1944 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1948 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1949 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1950 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1951 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1953 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1957 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1958 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1959 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1963 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1964 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1965 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1966 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1968 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1974 /* no keys to generate */
1976 return LDAP_SUCCESS;
1979 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1981 slen = strlen( syntax->ssyn_oid );
1982 mlen = strlen( mr->smr_oid );
1985 for( i=0; values[i] != NULL; i++ ) {
1987 struct berval *value;
1989 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1992 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1994 value = ber_bvdup( values[i] );
1995 ldap_pvt_str2upper( value->bv_val );
1998 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1999 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2001 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2002 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2004 for( j=0; j<max; j++ ) {
2005 HASH_Init( &HASHcontext );
2006 if( prefix != NULL && prefix->bv_len > 0 ) {
2007 HASH_Update( &HASHcontext,
2008 prefix->bv_val, prefix->bv_len );
2011 HASH_Update( &HASHcontext,
2012 &pre, sizeof( pre ) );
2013 HASH_Update( &HASHcontext,
2014 syntax->ssyn_oid, slen );
2015 HASH_Update( &HASHcontext,
2016 mr->smr_oid, mlen );
2017 HASH_Update( &HASHcontext,
2019 SLAP_INDEX_SUBSTR_MAXLEN );
2020 HASH_Final( HASHdigest, &HASHcontext );
2022 keys[nkeys++] = ber_bvdup( &digest );
2026 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2027 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2029 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2032 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2033 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2034 HASH_Init( &HASHcontext );
2035 if( prefix != NULL && prefix->bv_len > 0 ) {
2036 HASH_Update( &HASHcontext,
2037 prefix->bv_val, prefix->bv_len );
2039 HASH_Update( &HASHcontext,
2040 &pre, sizeof( pre ) );
2041 HASH_Update( &HASHcontext,
2042 syntax->ssyn_oid, slen );
2043 HASH_Update( &HASHcontext,
2044 mr->smr_oid, mlen );
2045 HASH_Update( &HASHcontext,
2047 HASH_Final( HASHdigest, &HASHcontext );
2049 keys[nkeys++] = ber_bvdup( &digest );
2052 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2053 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2054 HASH_Init( &HASHcontext );
2055 if( prefix != NULL && prefix->bv_len > 0 ) {
2056 HASH_Update( &HASHcontext,
2057 prefix->bv_val, prefix->bv_len );
2059 HASH_Update( &HASHcontext,
2060 &pre, sizeof( pre ) );
2061 HASH_Update( &HASHcontext,
2062 syntax->ssyn_oid, slen );
2063 HASH_Update( &HASHcontext,
2064 mr->smr_oid, mlen );
2065 HASH_Update( &HASHcontext,
2066 &value->bv_val[value->bv_len-j], j );
2067 HASH_Final( HASHdigest, &HASHcontext );
2069 keys[nkeys++] = ber_bvdup( &digest );
2074 ber_bvfree( value );
2085 return LDAP_SUCCESS;
2088 int caseIgnoreSubstringsFilter(
2093 struct berval *prefix,
2095 struct berval ***keysp )
2097 SubstringsAssertion *sa = assertValue;
2099 ber_len_t nkeys = 0;
2100 size_t slen, mlen, klen;
2101 struct berval **keys;
2102 HASH_CONTEXT HASHcontext;
2103 unsigned char HASHdigest[HASH_BYTES];
2104 struct berval *value;
2105 struct berval digest;
2107 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2108 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2113 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2115 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2116 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2117 /* don't bother accounting for stepping */
2118 nkeys += sa->sa_any[i]->bv_len -
2119 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2124 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2125 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2132 return LDAP_SUCCESS;
2135 digest.bv_val = HASHdigest;
2136 digest.bv_len = sizeof(HASHdigest);
2138 slen = strlen( syntax->ssyn_oid );
2139 mlen = strlen( mr->smr_oid );
2141 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2144 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2145 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2147 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2149 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_CASEFOLD ) );
2151 value = ber_bvdup( sa->sa_initial );
2152 ldap_pvt_str2upper( value->bv_val );
2155 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2156 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2158 HASH_Init( &HASHcontext );
2159 if( prefix != NULL && prefix->bv_len > 0 ) {
2160 HASH_Update( &HASHcontext,
2161 prefix->bv_val, prefix->bv_len );
2163 HASH_Update( &HASHcontext,
2164 &pre, sizeof( pre ) );
2165 HASH_Update( &HASHcontext,
2166 syntax->ssyn_oid, slen );
2167 HASH_Update( &HASHcontext,
2168 mr->smr_oid, mlen );
2169 HASH_Update( &HASHcontext,
2170 value->bv_val, klen );
2171 HASH_Final( HASHdigest, &HASHcontext );
2173 ber_bvfree( value );
2174 keys[nkeys++] = ber_bvdup( &digest );
2177 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2179 pre = SLAP_INDEX_SUBSTR_PREFIX;
2180 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2182 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2183 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2188 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_CASEFOLD ) );
2190 value = ber_bvdup( sa->sa_any[i] );
2191 ldap_pvt_str2upper( value->bv_val );
2195 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2196 j += SLAP_INDEX_SUBSTR_STEP )
2198 HASH_Init( &HASHcontext );
2199 if( prefix != NULL && prefix->bv_len > 0 ) {
2200 HASH_Update( &HASHcontext,
2201 prefix->bv_val, prefix->bv_len );
2203 HASH_Update( &HASHcontext,
2204 &pre, sizeof( pre ) );
2205 HASH_Update( &HASHcontext,
2206 syntax->ssyn_oid, slen );
2207 HASH_Update( &HASHcontext,
2208 mr->smr_oid, mlen );
2209 HASH_Update( &HASHcontext,
2210 &value->bv_val[j], klen );
2211 HASH_Final( HASHdigest, &HASHcontext );
2213 keys[nkeys++] = ber_bvdup( &digest );
2216 ber_bvfree( value );
2220 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2221 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2223 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2225 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_CASEFOLD ) );
2227 value = ber_bvdup( sa->sa_final );
2228 ldap_pvt_str2upper( value->bv_val );
2231 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2232 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2234 HASH_Init( &HASHcontext );
2235 if( prefix != NULL && prefix->bv_len > 0 ) {
2236 HASH_Update( &HASHcontext,
2237 prefix->bv_val, prefix->bv_len );
2239 HASH_Update( &HASHcontext,
2240 &pre, sizeof( pre ) );
2241 HASH_Update( &HASHcontext,
2242 syntax->ssyn_oid, slen );
2243 HASH_Update( &HASHcontext,
2244 mr->smr_oid, mlen );
2245 HASH_Update( &HASHcontext,
2246 &value->bv_val[value->bv_len-klen], klen );
2247 HASH_Final( HASHdigest, &HASHcontext );
2249 ber_bvfree( value );
2250 keys[nkeys++] = ber_bvdup( &digest );
2261 return LDAP_SUCCESS;
2267 struct berval *val )
2271 if( val->bv_len == 0 ) {
2272 /* disallow empty strings */
2273 return LDAP_INVALID_SYNTAX;
2276 if( OID_LEADCHAR(val->bv_val[0]) ) {
2278 for(i=1; i < val->bv_len; i++) {
2279 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2280 if( dot++ ) return 1;
2281 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2284 return LDAP_INVALID_SYNTAX;
2288 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2290 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2291 for(i=1; i < val->bv_len; i++) {
2292 if( !DESC_CHAR(val->bv_val[i] ) ) {
2293 return LDAP_INVALID_SYNTAX;
2297 return LDAP_SUCCESS;
2300 return LDAP_INVALID_SYNTAX;
2306 struct berval *val )
2310 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2312 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2313 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2314 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2315 return LDAP_INVALID_SYNTAX;
2318 for(i=1; i < val->bv_len; i++) {
2319 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2322 return LDAP_SUCCESS;
2329 struct berval **normalized )
2332 struct berval *newval;
2338 negative = ( *p == '-' );
2339 if( *p == '-' || *p == '+' ) p++;
2341 /* Ignore leading zeros */
2342 while ( *p == '0' ) p++;
2344 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2347 newval->bv_val = ch_strdup("0");
2352 newval->bv_val = ch_malloc( val->bv_len + 1 );
2356 newval->bv_val[newval->bv_len++] = '-';
2359 for( ; *p != '\0'; p++ ) {
2360 newval->bv_val[newval->bv_len++] = *p;
2364 *normalized = newval;
2365 return LDAP_SUCCESS;
2369 countryStringValidate(
2371 struct berval *val )
2373 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2375 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2376 return LDAP_INVALID_SYNTAX;
2378 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2379 return LDAP_INVALID_SYNTAX;
2382 return LDAP_SUCCESS;
2386 printableStringValidate(
2388 struct berval *val )
2392 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2394 for(i=0; i < val->bv_len; i++) {
2395 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2396 return LDAP_INVALID_SYNTAX;
2400 return LDAP_SUCCESS;
2404 printablesStringValidate(
2406 struct berval *val )
2410 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2412 for(i=0; i < val->bv_len; i++) {
2413 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2414 return LDAP_INVALID_SYNTAX;
2418 return LDAP_SUCCESS;
2424 struct berval *val )
2428 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2430 for(i=0; i < val->bv_len; i++) {
2431 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2434 return LDAP_SUCCESS;
2441 struct berval **normalized )
2443 struct berval *newval;
2446 newval = ch_malloc( sizeof( struct berval ) );
2450 /* Ignore initial whitespace */
2451 while ( ASCII_SPACE( *p ) ) {
2457 return LDAP_INVALID_SYNTAX;
2460 newval->bv_val = ch_strdup( p );
2461 p = q = newval->bv_val;
2464 if ( ASCII_SPACE( *p ) ) {
2467 /* Ignore the extra whitespace */
2468 while ( ASCII_SPACE( *p ) ) {
2476 assert( *newval->bv_val );
2477 assert( newval->bv_val < p );
2480 /* cannot start with a space */
2481 assert( !ASCII_SPACE(*newval->bv_val) );
2484 * If the string ended in space, backup the pointer one
2485 * position. One is enough because the above loop collapsed
2486 * all whitespace to a single space.
2489 if ( ASCII_SPACE( q[-1] ) ) {
2493 /* cannot end with a space */
2494 assert( !ASCII_SPACE( q[-1] ) );
2496 /* null terminate */
2499 newval->bv_len = q - newval->bv_val;
2500 *normalized = newval;
2502 return LDAP_SUCCESS;
2511 struct berval *value,
2512 void *assertedValue )
2514 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2517 match = strncmp( value->bv_val,
2518 ((struct berval *) assertedValue)->bv_val,
2523 return LDAP_SUCCESS;
2527 caseExactIA5SubstringsMatch(
2532 struct berval *value,
2533 void *assertedValue )
2536 SubstringsAssertion *sub = assertedValue;
2537 struct berval left = *value;
2541 /* Add up asserted input length */
2542 if( sub->sa_initial ) {
2543 inlen += sub->sa_initial->bv_len;
2546 for(i=0; sub->sa_any[i] != NULL; i++) {
2547 inlen += sub->sa_any[i]->bv_len;
2550 if( sub->sa_final ) {
2551 inlen += sub->sa_final->bv_len;
2554 if( sub->sa_initial ) {
2555 if( inlen > left.bv_len ) {
2560 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2561 sub->sa_initial->bv_len );
2567 left.bv_val += sub->sa_initial->bv_len;
2568 left.bv_len -= sub->sa_initial->bv_len;
2569 inlen -= sub->sa_initial->bv_len;
2572 if( sub->sa_final ) {
2573 if( inlen > left.bv_len ) {
2578 match = strncmp( sub->sa_final->bv_val,
2579 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2580 sub->sa_final->bv_len );
2586 left.bv_len -= sub->sa_final->bv_len;
2587 inlen -= sub->sa_final->bv_len;
2591 for(i=0; sub->sa_any[i]; i++) {
2596 if( inlen > left.bv_len ) {
2597 /* not enough length */
2602 if( sub->sa_any[i]->bv_len == 0 ) {
2606 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2613 idx = p - left.bv_val;
2614 assert( idx < left.bv_len );
2616 if( idx >= left.bv_len ) {
2617 /* this shouldn't happen */
2624 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2625 /* not enough left */
2630 match = strncmp( left.bv_val,
2631 sub->sa_any[i]->bv_val,
2632 sub->sa_any[i]->bv_len );
2640 left.bv_val += sub->sa_any[i]->bv_len;
2641 left.bv_len -= sub->sa_any[i]->bv_len;
2642 inlen -= sub->sa_any[i]->bv_len;
2648 return LDAP_SUCCESS;
2651 /* Index generation function */
2652 int caseExactIA5Indexer(
2657 struct berval *prefix,
2658 struct berval **values,
2659 struct berval ***keysp )
2663 struct berval **keys;
2664 HASH_CONTEXT HASHcontext;
2665 unsigned char HASHdigest[HASH_BYTES];
2666 struct berval digest;
2667 digest.bv_val = HASHdigest;
2668 digest.bv_len = sizeof(HASHdigest);
2670 /* we should have at least one value at this point */
2671 assert( values != NULL && values[0] != NULL );
2673 for( i=0; values[i] != NULL; i++ ) {
2674 /* just count them */
2677 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2679 slen = strlen( syntax->ssyn_oid );
2680 mlen = strlen( mr->smr_oid );
2682 for( i=0; values[i] != NULL; i++ ) {
2683 struct berval *value = values[i];
2685 HASH_Init( &HASHcontext );
2686 if( prefix != NULL && prefix->bv_len > 0 ) {
2687 HASH_Update( &HASHcontext,
2688 prefix->bv_val, prefix->bv_len );
2690 HASH_Update( &HASHcontext,
2691 syntax->ssyn_oid, slen );
2692 HASH_Update( &HASHcontext,
2693 mr->smr_oid, mlen );
2694 HASH_Update( &HASHcontext,
2695 value->bv_val, value->bv_len );
2696 HASH_Final( HASHdigest, &HASHcontext );
2698 keys[i] = ber_bvdup( &digest );
2703 return LDAP_SUCCESS;
2706 /* Index generation function */
2707 int caseExactIA5Filter(
2712 struct berval *prefix,
2714 struct berval ***keysp )
2717 struct berval **keys;
2718 HASH_CONTEXT HASHcontext;
2719 unsigned char HASHdigest[HASH_BYTES];
2720 struct berval *value;
2721 struct berval digest;
2722 digest.bv_val = HASHdigest;
2723 digest.bv_len = sizeof(HASHdigest);
2725 slen = strlen( syntax->ssyn_oid );
2726 mlen = strlen( mr->smr_oid );
2728 value = (struct berval *) assertValue;
2730 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2732 HASH_Init( &HASHcontext );
2733 if( prefix != NULL && prefix->bv_len > 0 ) {
2734 HASH_Update( &HASHcontext,
2735 prefix->bv_val, prefix->bv_len );
2737 HASH_Update( &HASHcontext,
2738 syntax->ssyn_oid, slen );
2739 HASH_Update( &HASHcontext,
2740 mr->smr_oid, mlen );
2741 HASH_Update( &HASHcontext,
2742 value->bv_val, value->bv_len );
2743 HASH_Final( HASHdigest, &HASHcontext );
2745 keys[0] = ber_bvdup( &digest );
2749 return LDAP_SUCCESS;
2752 /* Substrings Index generation function */
2753 int caseExactIA5SubstringsIndexer(
2758 struct berval *prefix,
2759 struct berval **values,
2760 struct berval ***keysp )
2764 struct berval **keys;
2765 HASH_CONTEXT HASHcontext;
2766 unsigned char HASHdigest[HASH_BYTES];
2767 struct berval digest;
2768 digest.bv_val = HASHdigest;
2769 digest.bv_len = sizeof(HASHdigest);
2771 /* we should have at least one value at this point */
2772 assert( values != NULL && values[0] != NULL );
2775 for( i=0; values[i] != NULL; i++ ) {
2776 /* count number of indices to generate */
2777 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2781 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2782 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2783 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2784 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2786 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2790 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2791 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2792 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2796 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2797 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2798 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2799 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2801 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2807 /* no keys to generate */
2809 return LDAP_SUCCESS;
2812 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2814 slen = strlen( syntax->ssyn_oid );
2815 mlen = strlen( mr->smr_oid );
2818 for( i=0; values[i] != NULL; i++ ) {
2820 struct berval *value;
2823 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2825 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2826 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2828 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2829 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2831 for( j=0; j<max; j++ ) {
2832 HASH_Init( &HASHcontext );
2833 if( prefix != NULL && prefix->bv_len > 0 ) {
2834 HASH_Update( &HASHcontext,
2835 prefix->bv_val, prefix->bv_len );
2838 HASH_Update( &HASHcontext,
2839 &pre, sizeof( pre ) );
2840 HASH_Update( &HASHcontext,
2841 syntax->ssyn_oid, slen );
2842 HASH_Update( &HASHcontext,
2843 mr->smr_oid, mlen );
2844 HASH_Update( &HASHcontext,
2846 SLAP_INDEX_SUBSTR_MAXLEN );
2847 HASH_Final( HASHdigest, &HASHcontext );
2849 keys[nkeys++] = ber_bvdup( &digest );
2853 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2854 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2856 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2859 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2860 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2861 HASH_Init( &HASHcontext );
2862 if( prefix != NULL && prefix->bv_len > 0 ) {
2863 HASH_Update( &HASHcontext,
2864 prefix->bv_val, prefix->bv_len );
2866 HASH_Update( &HASHcontext,
2867 &pre, sizeof( pre ) );
2868 HASH_Update( &HASHcontext,
2869 syntax->ssyn_oid, slen );
2870 HASH_Update( &HASHcontext,
2871 mr->smr_oid, mlen );
2872 HASH_Update( &HASHcontext,
2874 HASH_Final( HASHdigest, &HASHcontext );
2876 keys[nkeys++] = ber_bvdup( &digest );
2879 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2880 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2881 HASH_Init( &HASHcontext );
2882 if( prefix != NULL && prefix->bv_len > 0 ) {
2883 HASH_Update( &HASHcontext,
2884 prefix->bv_val, prefix->bv_len );
2886 HASH_Update( &HASHcontext,
2887 &pre, sizeof( pre ) );
2888 HASH_Update( &HASHcontext,
2889 syntax->ssyn_oid, slen );
2890 HASH_Update( &HASHcontext,
2891 mr->smr_oid, mlen );
2892 HASH_Update( &HASHcontext,
2893 &value->bv_val[value->bv_len-j], j );
2894 HASH_Final( HASHdigest, &HASHcontext );
2896 keys[nkeys++] = ber_bvdup( &digest );
2910 return LDAP_SUCCESS;
2913 int caseExactIA5SubstringsFilter(
2918 struct berval *prefix,
2920 struct berval ***keysp )
2922 SubstringsAssertion *sa = assertValue;
2924 ber_len_t nkeys = 0;
2925 size_t slen, mlen, klen;
2926 struct berval **keys;
2927 HASH_CONTEXT HASHcontext;
2928 unsigned char HASHdigest[HASH_BYTES];
2929 struct berval *value;
2930 struct berval digest;
2932 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2933 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2938 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2940 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2941 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2942 /* don't bother accounting for stepping */
2943 nkeys += sa->sa_any[i]->bv_len -
2944 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2949 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2950 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2957 return LDAP_SUCCESS;
2960 digest.bv_val = HASHdigest;
2961 digest.bv_len = sizeof(HASHdigest);
2963 slen = strlen( syntax->ssyn_oid );
2964 mlen = strlen( mr->smr_oid );
2966 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2969 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2970 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2972 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2973 value = sa->sa_initial;
2975 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2976 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2978 HASH_Init( &HASHcontext );
2979 if( prefix != NULL && prefix->bv_len > 0 ) {
2980 HASH_Update( &HASHcontext,
2981 prefix->bv_val, prefix->bv_len );
2983 HASH_Update( &HASHcontext,
2984 &pre, sizeof( pre ) );
2985 HASH_Update( &HASHcontext,
2986 syntax->ssyn_oid, slen );
2987 HASH_Update( &HASHcontext,
2988 mr->smr_oid, mlen );
2989 HASH_Update( &HASHcontext,
2990 value->bv_val, klen );
2991 HASH_Final( HASHdigest, &HASHcontext );
2993 keys[nkeys++] = ber_bvdup( &digest );
2996 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2998 pre = SLAP_INDEX_SUBSTR_PREFIX;
2999 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3001 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3002 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3006 value = sa->sa_any[i];
3009 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3010 j += SLAP_INDEX_SUBSTR_STEP )
3012 HASH_Init( &HASHcontext );
3013 if( prefix != NULL && prefix->bv_len > 0 ) {
3014 HASH_Update( &HASHcontext,
3015 prefix->bv_val, prefix->bv_len );
3017 HASH_Update( &HASHcontext,
3018 &pre, sizeof( pre ) );
3019 HASH_Update( &HASHcontext,
3020 syntax->ssyn_oid, slen );
3021 HASH_Update( &HASHcontext,
3022 mr->smr_oid, mlen );
3023 HASH_Update( &HASHcontext,
3024 &value->bv_val[j], klen );
3025 HASH_Final( HASHdigest, &HASHcontext );
3027 keys[nkeys++] = ber_bvdup( &digest );
3032 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3033 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3035 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3036 value = sa->sa_final;
3038 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3039 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3041 HASH_Init( &HASHcontext );
3042 if( prefix != NULL && prefix->bv_len > 0 ) {
3043 HASH_Update( &HASHcontext,
3044 prefix->bv_val, prefix->bv_len );
3046 HASH_Update( &HASHcontext,
3047 &pre, sizeof( pre ) );
3048 HASH_Update( &HASHcontext,
3049 syntax->ssyn_oid, slen );
3050 HASH_Update( &HASHcontext,
3051 mr->smr_oid, mlen );
3052 HASH_Update( &HASHcontext,
3053 &value->bv_val[value->bv_len-klen], klen );
3054 HASH_Final( HASHdigest, &HASHcontext );
3056 keys[nkeys++] = ber_bvdup( &digest );
3067 return LDAP_SUCCESS;
3076 struct berval *value,
3077 void *assertedValue )
3079 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3081 if( match == 0 && value->bv_len ) {
3082 match = strncasecmp( value->bv_val,
3083 ((struct berval *) assertedValue)->bv_val,
3088 return LDAP_SUCCESS;
3092 caseIgnoreIA5SubstringsMatch(
3097 struct berval *value,
3098 void *assertedValue )
3101 SubstringsAssertion *sub = assertedValue;
3102 struct berval left = *value;
3106 /* Add up asserted input length */
3107 if( sub->sa_initial ) {
3108 inlen += sub->sa_initial->bv_len;
3111 for(i=0; sub->sa_any[i] != NULL; i++) {
3112 inlen += sub->sa_any[i]->bv_len;
3115 if( sub->sa_final ) {
3116 inlen += sub->sa_final->bv_len;
3119 if( sub->sa_initial ) {
3120 if( inlen > left.bv_len ) {
3125 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3126 sub->sa_initial->bv_len );
3132 left.bv_val += sub->sa_initial->bv_len;
3133 left.bv_len -= sub->sa_initial->bv_len;
3134 inlen -= sub->sa_initial->bv_len;
3137 if( sub->sa_final ) {
3138 if( inlen > left.bv_len ) {
3143 match = strncasecmp( sub->sa_final->bv_val,
3144 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3145 sub->sa_final->bv_len );
3151 left.bv_len -= sub->sa_final->bv_len;
3152 inlen -= sub->sa_final->bv_len;
3156 for(i=0; sub->sa_any[i]; i++) {
3161 if( inlen > left.bv_len ) {
3162 /* not enough length */
3167 if( sub->sa_any[i]->bv_len == 0 ) {
3171 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3178 idx = p - left.bv_val;
3179 assert( idx < left.bv_len );
3181 if( idx >= left.bv_len ) {
3182 /* this shouldn't happen */
3189 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3190 /* not enough left */
3195 match = strncasecmp( left.bv_val,
3196 sub->sa_any[i]->bv_val,
3197 sub->sa_any[i]->bv_len );
3206 left.bv_val += sub->sa_any[i]->bv_len;
3207 left.bv_len -= sub->sa_any[i]->bv_len;
3208 inlen -= sub->sa_any[i]->bv_len;
3214 return LDAP_SUCCESS;
3217 /* Index generation function */
3218 int caseIgnoreIA5Indexer(
3223 struct berval *prefix,
3224 struct berval **values,
3225 struct berval ***keysp )
3229 struct berval **keys;
3230 HASH_CONTEXT HASHcontext;
3231 unsigned char HASHdigest[HASH_BYTES];
3232 struct berval digest;
3233 digest.bv_val = HASHdigest;
3234 digest.bv_len = sizeof(HASHdigest);
3236 /* we should have at least one value at this point */
3237 assert( values != NULL && values[0] != NULL );
3239 for( i=0; values[i] != NULL; i++ ) {
3240 /* just count them */
3243 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3245 slen = strlen( syntax->ssyn_oid );
3246 mlen = strlen( mr->smr_oid );
3248 for( i=0; values[i] != NULL; i++ ) {
3249 struct berval *value = ber_bvdup( values[i] );
3250 ldap_pvt_str2upper( value->bv_val );
3252 HASH_Init( &HASHcontext );
3253 if( prefix != NULL && prefix->bv_len > 0 ) {
3254 HASH_Update( &HASHcontext,
3255 prefix->bv_val, prefix->bv_len );
3257 HASH_Update( &HASHcontext,
3258 syntax->ssyn_oid, slen );
3259 HASH_Update( &HASHcontext,
3260 mr->smr_oid, mlen );
3261 HASH_Update( &HASHcontext,
3262 value->bv_val, value->bv_len );
3263 HASH_Final( HASHdigest, &HASHcontext );
3265 ber_bvfree( value );
3267 keys[i] = ber_bvdup( &digest );
3272 return LDAP_SUCCESS;
3275 /* Index generation function */
3276 int caseIgnoreIA5Filter(
3281 struct berval *prefix,
3283 struct berval ***keysp )
3286 struct berval **keys;
3287 HASH_CONTEXT HASHcontext;
3288 unsigned char HASHdigest[HASH_BYTES];
3289 struct berval *value;
3290 struct berval digest;
3291 digest.bv_val = HASHdigest;
3292 digest.bv_len = sizeof(HASHdigest);
3294 slen = strlen( syntax->ssyn_oid );
3295 mlen = strlen( mr->smr_oid );
3297 value = ber_bvdup( (struct berval *) assertValue );
3298 ldap_pvt_str2upper( value->bv_val );
3300 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3302 HASH_Init( &HASHcontext );
3303 if( prefix != NULL && prefix->bv_len > 0 ) {
3304 HASH_Update( &HASHcontext,
3305 prefix->bv_val, prefix->bv_len );
3307 HASH_Update( &HASHcontext,
3308 syntax->ssyn_oid, slen );
3309 HASH_Update( &HASHcontext,
3310 mr->smr_oid, mlen );
3311 HASH_Update( &HASHcontext,
3312 value->bv_val, value->bv_len );
3313 HASH_Final( HASHdigest, &HASHcontext );
3315 keys[0] = ber_bvdup( &digest );
3318 ber_bvfree( value );
3322 return LDAP_SUCCESS;
3325 /* Substrings Index generation function */
3326 int caseIgnoreIA5SubstringsIndexer(
3331 struct berval *prefix,
3332 struct berval **values,
3333 struct berval ***keysp )
3337 struct berval **keys;
3338 HASH_CONTEXT HASHcontext;
3339 unsigned char HASHdigest[HASH_BYTES];
3340 struct berval digest;
3341 digest.bv_val = HASHdigest;
3342 digest.bv_len = sizeof(HASHdigest);
3344 /* we should have at least one value at this point */
3345 assert( values != NULL && values[0] != NULL );
3348 for( i=0; values[i] != NULL; i++ ) {
3349 /* count number of indices to generate */
3350 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3354 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3355 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3356 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3357 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3359 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3363 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3364 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3365 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3369 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3370 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3371 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3372 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3374 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3380 /* no keys to generate */
3382 return LDAP_SUCCESS;
3385 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3387 slen = strlen( syntax->ssyn_oid );
3388 mlen = strlen( mr->smr_oid );
3391 for( i=0; values[i] != NULL; i++ ) {
3393 struct berval *value;
3395 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3397 value = ber_bvdup( values[i] );
3398 ldap_pvt_str2upper( value->bv_val );
3400 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3401 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3403 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3404 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3406 for( j=0; j<max; j++ ) {
3407 HASH_Init( &HASHcontext );
3408 if( prefix != NULL && prefix->bv_len > 0 ) {
3409 HASH_Update( &HASHcontext,
3410 prefix->bv_val, prefix->bv_len );
3413 HASH_Update( &HASHcontext,
3414 &pre, sizeof( pre ) );
3415 HASH_Update( &HASHcontext,
3416 syntax->ssyn_oid, slen );
3417 HASH_Update( &HASHcontext,
3418 mr->smr_oid, mlen );
3419 HASH_Update( &HASHcontext,
3421 SLAP_INDEX_SUBSTR_MAXLEN );
3422 HASH_Final( HASHdigest, &HASHcontext );
3424 keys[nkeys++] = ber_bvdup( &digest );
3428 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3429 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3431 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3434 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3435 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3436 HASH_Init( &HASHcontext );
3437 if( prefix != NULL && prefix->bv_len > 0 ) {
3438 HASH_Update( &HASHcontext,
3439 prefix->bv_val, prefix->bv_len );
3441 HASH_Update( &HASHcontext,
3442 &pre, sizeof( pre ) );
3443 HASH_Update( &HASHcontext,
3444 syntax->ssyn_oid, slen );
3445 HASH_Update( &HASHcontext,
3446 mr->smr_oid, mlen );
3447 HASH_Update( &HASHcontext,
3449 HASH_Final( HASHdigest, &HASHcontext );
3451 keys[nkeys++] = ber_bvdup( &digest );
3454 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3455 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3456 HASH_Init( &HASHcontext );
3457 if( prefix != NULL && prefix->bv_len > 0 ) {
3458 HASH_Update( &HASHcontext,
3459 prefix->bv_val, prefix->bv_len );
3461 HASH_Update( &HASHcontext,
3462 &pre, sizeof( pre ) );
3463 HASH_Update( &HASHcontext,
3464 syntax->ssyn_oid, slen );
3465 HASH_Update( &HASHcontext,
3466 mr->smr_oid, mlen );
3467 HASH_Update( &HASHcontext,
3468 &value->bv_val[value->bv_len-j], j );
3469 HASH_Final( HASHdigest, &HASHcontext );
3471 keys[nkeys++] = ber_bvdup( &digest );
3476 ber_bvfree( value );
3487 return LDAP_SUCCESS;
3490 int caseIgnoreIA5SubstringsFilter(
3495 struct berval *prefix,
3497 struct berval ***keysp )
3499 SubstringsAssertion *sa = assertValue;
3501 ber_len_t nkeys = 0;
3502 size_t slen, mlen, klen;
3503 struct berval **keys;
3504 HASH_CONTEXT HASHcontext;
3505 unsigned char HASHdigest[HASH_BYTES];
3506 struct berval *value;
3507 struct berval digest;
3509 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3510 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3515 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3517 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3518 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3519 /* don't bother accounting for stepping */
3520 nkeys += sa->sa_any[i]->bv_len -
3521 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3526 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3527 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3534 return LDAP_SUCCESS;
3537 digest.bv_val = HASHdigest;
3538 digest.bv_len = sizeof(HASHdigest);
3540 slen = strlen( syntax->ssyn_oid );
3541 mlen = strlen( mr->smr_oid );
3543 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3546 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3547 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3549 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3550 value = ber_bvdup( sa->sa_initial );
3551 ldap_pvt_str2upper( value->bv_val );
3553 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3554 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3556 HASH_Init( &HASHcontext );
3557 if( prefix != NULL && prefix->bv_len > 0 ) {
3558 HASH_Update( &HASHcontext,
3559 prefix->bv_val, prefix->bv_len );
3561 HASH_Update( &HASHcontext,
3562 &pre, sizeof( pre ) );
3563 HASH_Update( &HASHcontext,
3564 syntax->ssyn_oid, slen );
3565 HASH_Update( &HASHcontext,
3566 mr->smr_oid, mlen );
3567 HASH_Update( &HASHcontext,
3568 value->bv_val, klen );
3569 HASH_Final( HASHdigest, &HASHcontext );
3571 ber_bvfree( value );
3572 keys[nkeys++] = ber_bvdup( &digest );
3575 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3577 pre = SLAP_INDEX_SUBSTR_PREFIX;
3578 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3580 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3581 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3585 value = ber_bvdup( sa->sa_any[i] );
3586 ldap_pvt_str2upper( value->bv_val );
3589 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3590 j += SLAP_INDEX_SUBSTR_STEP )
3592 HASH_Init( &HASHcontext );
3593 if( prefix != NULL && prefix->bv_len > 0 ) {
3594 HASH_Update( &HASHcontext,
3595 prefix->bv_val, prefix->bv_len );
3597 HASH_Update( &HASHcontext,
3598 &pre, sizeof( pre ) );
3599 HASH_Update( &HASHcontext,
3600 syntax->ssyn_oid, slen );
3601 HASH_Update( &HASHcontext,
3602 mr->smr_oid, mlen );
3603 HASH_Update( &HASHcontext,
3604 &value->bv_val[j], klen );
3605 HASH_Final( HASHdigest, &HASHcontext );
3607 keys[nkeys++] = ber_bvdup( &digest );
3610 ber_bvfree( value );
3614 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3615 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3617 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3618 value = ber_bvdup( sa->sa_final );
3619 ldap_pvt_str2upper( value->bv_val );
3621 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3622 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3624 HASH_Init( &HASHcontext );
3625 if( prefix != NULL && prefix->bv_len > 0 ) {
3626 HASH_Update( &HASHcontext,
3627 prefix->bv_val, prefix->bv_len );
3629 HASH_Update( &HASHcontext,
3630 &pre, sizeof( pre ) );
3631 HASH_Update( &HASHcontext,
3632 syntax->ssyn_oid, slen );
3633 HASH_Update( &HASHcontext,
3634 mr->smr_oid, mlen );
3635 HASH_Update( &HASHcontext,
3636 &value->bv_val[value->bv_len-klen], klen );
3637 HASH_Final( HASHdigest, &HASHcontext );
3639 ber_bvfree( value );
3640 keys[nkeys++] = ber_bvdup( &digest );
3651 return LDAP_SUCCESS;
3655 numericStringValidate(
3661 for(i=0; i < in->bv_len; i++) {
3662 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3663 return LDAP_INVALID_SYNTAX;
3667 return LDAP_SUCCESS;
3671 numericStringNormalize(
3674 struct berval **normalized )
3676 /* removal all spaces */
3677 struct berval *newval;
3680 newval = ch_malloc( sizeof( struct berval ) );
3681 newval->bv_val = ch_malloc( val->bv_len + 1 );
3687 if ( ASCII_SPACE( *p ) ) {
3688 /* Ignore whitespace */
3695 assert( newval->bv_val <= p );
3698 /* null terminate */
3701 newval->bv_len = q - newval->bv_val;
3702 *normalized = newval;
3704 return LDAP_SUCCESS;
3708 objectIdentifierFirstComponentMatch(
3713 struct berval *value,
3714 void *assertedValue )
3716 int rc = LDAP_SUCCESS;
3718 struct berval *asserted = (struct berval *) assertedValue;
3722 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3723 return LDAP_INVALID_SYNTAX;
3726 /* trim leading white space */
3727 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3731 /* grab next word */
3732 oid.bv_val = &value->bv_val[i];
3733 oid.bv_len = value->bv_len - i;
3734 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3739 /* insert attributeTypes, objectclass check here */
3740 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3741 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3744 char *stored = ch_malloc( oid.bv_len + 1 );
3745 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3746 stored[oid.bv_len] = '\0';
3748 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3749 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3750 MatchingRule *stored_mr = mr_find( stored );
3752 if( asserted_mr == NULL ) {
3753 rc = SLAPD_COMPARE_UNDEFINED;
3755 match = asserted_mr != stored_mr;
3758 } else if ( !strcmp( syntax->ssyn_oid,
3759 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3761 AttributeType *asserted_at = at_find( asserted->bv_val );
3762 AttributeType *stored_at = at_find( stored );
3764 if( asserted_at == NULL ) {
3765 rc = SLAPD_COMPARE_UNDEFINED;
3767 match = asserted_at != stored_at;
3770 } else if ( !strcmp( syntax->ssyn_oid,
3771 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3773 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3774 ObjectClass *stored_oc = oc_find( stored );
3776 if( asserted_oc == NULL ) {
3777 rc = SLAPD_COMPARE_UNDEFINED;
3779 match = asserted_oc != stored_oc;
3787 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3788 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3789 match, value->bv_val, asserted->bv_val ));
3791 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3792 "%d\n\t\"%s\"\n\t\"%s\"\n",
3793 match, value->bv_val, asserted->bv_val );
3797 if( rc == LDAP_SUCCESS ) *matchp = match;
3802 check_time_syntax (struct berval *val,
3806 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3807 static int mdays[2][12] = {
3808 /* non-leap years */
3809 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3811 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3814 int part, c, tzoffset, leapyear = 0 ;
3816 if( val->bv_len == 0 ) {
3817 return LDAP_INVALID_SYNTAX;
3820 p = (char *)val->bv_val;
3821 e = p + val->bv_len;
3823 /* Ignore initial whitespace */
3824 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3828 if (e - p < 13 - (2 * start)) {
3829 return LDAP_INVALID_SYNTAX;
3832 for (part = 0; part < 9; part++) {
3836 for (part = start; part < 7; part++) {
3838 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3845 return LDAP_INVALID_SYNTAX;
3847 if (c < 0 || c > 9) {
3848 return LDAP_INVALID_SYNTAX;
3854 return LDAP_INVALID_SYNTAX;
3856 if (c < 0 || c > 9) {
3857 return LDAP_INVALID_SYNTAX;
3862 if (part == 2 || part == 3) {
3865 if (parts[part] < 0) {
3866 return LDAP_INVALID_SYNTAX;
3868 if (parts[part] > ceiling[part]) {
3869 return LDAP_INVALID_SYNTAX;
3873 /* leapyear check for the Gregorian calendar (year>1581) */
3874 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3875 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3880 if (parts[3] > mdays[leapyear][parts[2]]) {
3881 return LDAP_INVALID_SYNTAX;
3886 tzoffset = 0; /* UTC */
3887 } else if (c != '+' && c != '-') {
3888 return LDAP_INVALID_SYNTAX;
3892 } else /* c == '+' */ {
3897 return LDAP_INVALID_SYNTAX;
3900 for (part = 7; part < 9; part++) {
3902 if (c < 0 || c > 9) {
3903 return LDAP_INVALID_SYNTAX;
3908 if (c < 0 || c > 9) {
3909 return LDAP_INVALID_SYNTAX;
3913 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3914 return LDAP_INVALID_SYNTAX;
3919 /* Ignore trailing whitespace */
3920 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3924 return LDAP_INVALID_SYNTAX;
3927 switch ( tzoffset ) {
3928 case -1: /* negativ offset to UTC, ie west of Greenwich */
3929 parts[4] += parts[7];
3930 parts[5] += parts[8];
3931 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3935 c = mdays[leapyear][parts[2]];
3937 if (parts[part] > c) {
3938 parts[part] -= c + 1;
3943 case 1: /* positive offset to UTC, ie east of Greenwich */
3944 parts[4] -= parts[7];
3945 parts[5] -= parts[8];
3946 for (part = 6; --part > 0; ) {
3950 /* first arg to % needs to be non negativ */
3951 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3953 if (parts[part] < 0) {
3954 parts[part] += c + 1;
3959 case 0: /* already UTC */
3963 return LDAP_SUCCESS;
3970 struct berval **normalized )
3975 rc = check_time_syntax(val, 1, parts);
3976 if (rc != LDAP_SUCCESS) {
3981 out = ch_malloc( sizeof(struct berval) );
3983 return LBER_ERROR_MEMORY;
3986 out->bv_val = ch_malloc( 14 );
3987 if ( out->bv_val == NULL ) {
3989 return LBER_ERROR_MEMORY;
3992 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3993 parts[1], parts[2] + 1, parts[3] + 1,
3994 parts[4], parts[5], parts[6] );
3998 return LDAP_SUCCESS;
4008 return check_time_syntax(in, 1, parts);
4012 generalizedTimeValidate(
4018 return check_time_syntax(in, 0, parts);
4022 generalizedTimeNormalize(
4025 struct berval **normalized )
4030 rc = check_time_syntax(val, 0, parts);
4031 if (rc != LDAP_SUCCESS) {
4036 out = ch_malloc( sizeof(struct berval) );
4038 return LBER_ERROR_MEMORY;
4041 out->bv_val = ch_malloc( 16 );
4042 if ( out->bv_val == NULL ) {
4044 return LBER_ERROR_MEMORY;
4047 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4048 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4049 parts[4], parts[5], parts[6] );
4053 return LDAP_SUCCESS;
4057 nisNetgroupTripleValidate(
4059 struct berval *val )
4064 if ( val->bv_len == 0 ) {
4065 return LDAP_INVALID_SYNTAX;
4068 p = (char *)val->bv_val;
4069 e = p + val->bv_len;
4072 /* syntax does not allow leading white space */
4073 /* Ignore initial whitespace */
4074 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4079 if ( *p != '(' /*')'*/ ) {
4080 return LDAP_INVALID_SYNTAX;
4083 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4087 return LDAP_INVALID_SYNTAX;
4090 } else if ( !ATTR_CHAR( *p ) ) {
4091 return LDAP_INVALID_SYNTAX;
4095 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4096 return LDAP_INVALID_SYNTAX;
4102 /* syntax does not allow trailing white space */
4103 /* Ignore trailing whitespace */
4104 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4110 return LDAP_INVALID_SYNTAX;
4113 return LDAP_SUCCESS;
4117 bootParameterValidate(
4119 struct berval *val )
4123 if ( val->bv_len == 0 ) {
4124 return LDAP_INVALID_SYNTAX;
4127 p = (char *)val->bv_val;
4128 e = p + val->bv_len;
4131 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4132 if ( !ATTR_CHAR( *p ) ) {
4133 return LDAP_INVALID_SYNTAX;
4138 return LDAP_INVALID_SYNTAX;
4142 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4143 if ( !ATTR_CHAR( *p ) ) {
4144 return LDAP_INVALID_SYNTAX;
4149 return LDAP_INVALID_SYNTAX;
4153 for ( p++; p < e; p++ ) {
4154 if ( !ATTR_CHAR( *p ) ) {
4155 return LDAP_INVALID_SYNTAX;
4159 return LDAP_SUCCESS;
4162 struct syntax_defs_rec {
4165 slap_syntax_validate_func *sd_validate;
4166 slap_syntax_transform_func *sd_normalize;
4167 slap_syntax_transform_func *sd_pretty;
4168 #ifdef SLAPD_BINARY_CONVERSION
4169 slap_syntax_transform_func *sd_ber2str;
4170 slap_syntax_transform_func *sd_str2ber;
4174 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4175 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4177 struct syntax_defs_rec syntax_defs[] = {
4178 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4179 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4181 0, NULL, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4183 0, NULL, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4185 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4187 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4189 0, bitStringValidate, NULL, NULL },
4190 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4191 0, booleanValidate, NULL, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4193 X_BINARY X_NOT_H_R ")",
4194 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4196 X_BINARY X_NOT_H_R ")",
4197 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4199 X_BINARY X_NOT_H_R ")",
4200 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4202 0, countryStringValidate, IA5StringNormalize, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4204 0, dnValidate, dnNormalize, dnPretty},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4206 0, NULL, NULL, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4208 0, NULL, NULL, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4210 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4212 0, NULL, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4214 0, NULL, NULL, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4216 0, NULL, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4218 0, NULL, NULL, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4220 0, NULL, NULL, NULL},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4222 0, printablesStringValidate, IA5StringNormalize, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4224 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4225 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4226 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4227 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4228 0, NULL, NULL, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4230 0, IA5StringValidate, IA5StringNormalize, NULL},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4232 0, integerValidate, integerNormalize, integerPretty},
4233 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4234 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4236 0, NULL, NULL, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4238 0, NULL, NULL, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4240 0, NULL, NULL, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4242 0, NULL, NULL, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4244 0, NULL, NULL, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4246 0, nameUIDValidate, nameUIDNormalize, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4248 0, NULL, NULL, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4250 0, numericStringValidate, numericStringNormalize, NULL},
4251 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4252 0, NULL, NULL, NULL},
4253 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4254 0, oidValidate, NULL, NULL},
4255 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4256 0, IA5StringValidate, IA5StringNormalize, NULL},
4257 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4258 0, blobValidate, NULL, NULL},
4259 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4260 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4261 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4262 0, NULL, NULL, NULL},
4263 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4264 0, NULL, NULL, NULL},
4265 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4266 0, printableStringValidate, IA5StringNormalize, NULL},
4267 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4268 X_BINARY X_NOT_H_R ")",
4269 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4270 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4271 0, printableStringValidate, IA5StringNormalize, NULL},
4272 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4273 0, NULL, NULL, NULL},
4274 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4275 0, printableStringValidate, IA5StringNormalize, NULL},
4276 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4277 0, utcTimeValidate, utcTimeNormalize, NULL},
4278 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4279 0, NULL, NULL, NULL},
4280 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4281 0, NULL, NULL, NULL},
4282 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4283 0, NULL, NULL, NULL},
4284 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4285 0, NULL, NULL, NULL},
4286 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4287 0, NULL, NULL, NULL},
4289 /* RFC 2307 NIS Syntaxes */
4290 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4291 0, nisNetgroupTripleValidate, NULL, NULL},
4292 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4293 0, bootParameterValidate, NULL, NULL},
4295 /* OpenLDAP Experimental Syntaxes */
4296 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4297 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4299 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4300 0, NULL, NULL, NULL},
4302 /* OpenLDAP Void Syntax */
4303 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4304 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4305 {NULL, 0, NULL, NULL, NULL}
4308 struct mrule_defs_rec {
4310 slap_mask_t mrd_usage;
4311 slap_mr_convert_func * mrd_convert;
4312 slap_mr_normalize_func * mrd_normalize;
4313 slap_mr_match_func * mrd_match;
4314 slap_mr_indexer_func * mrd_indexer;
4315 slap_mr_filter_func * mrd_filter;
4317 char * mrd_associated;
4321 * Other matching rules in X.520 that we do not use (yet):
4323 * 2.5.13.9 numericStringOrderingMatch
4324 * 2.5.13.15 integerOrderingMatch
4325 * 2.5.13.18 octetStringOrderingMatch
4326 * 2.5.13.19 octetStringSubstringsMatch
4327 * 2.5.13.25 uTCTimeMatch
4328 * 2.5.13.26 uTCTimeOrderingMatch
4329 * 2.5.13.31 directoryStringFirstComponentMatch
4330 * 2.5.13.32 wordMatch
4331 * 2.5.13.33 keywordMatch
4332 * 2.5.13.34 certificateExactMatch
4333 * 2.5.13.35 certificateMatch
4334 * 2.5.13.36 certificatePairExactMatch
4335 * 2.5.13.37 certificatePairMatch
4336 * 2.5.13.38 certificateListExactMatch
4337 * 2.5.13.39 certificateListMatch
4338 * 2.5.13.40 algorithmIdentifierMatch
4339 * 2.5.13.41 storedPrefixMatch
4340 * 2.5.13.42 attributeCertificateMatch
4341 * 2.5.13.43 readerAndKeyIDMatch
4342 * 2.5.13.44 attributeIntegrityMatch
4345 struct mrule_defs_rec mrule_defs[] = {
4347 * EQUALITY matching rules must be listed after associated APPROX
4348 * matching rules. So, we list all APPROX matching rules first.
4350 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4351 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4352 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4354 directoryStringApproxMatch,
4355 directoryStringApproxIndexer,
4356 directoryStringApproxFilter,
4359 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4360 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4361 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4363 IA5StringApproxMatch,
4364 IA5StringApproxIndexer,
4365 IA5StringApproxFilter,
4369 * Other matching rules
4372 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4373 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4374 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4376 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4379 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4380 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4381 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4383 dnMatch, dnIndexer, dnFilter,
4386 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4387 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4388 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4390 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4391 directoryStringApproxMatchOID },
4393 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4394 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4397 caseIgnoreOrderingMatch, NULL, NULL,
4400 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4401 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4402 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4404 caseIgnoreSubstringsMatch,
4405 caseIgnoreSubstringsIndexer,
4406 caseIgnoreSubstringsFilter,
4409 {"( 2.5.13.5 NAME 'caseExactMatch' "
4410 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4411 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4413 caseExactMatch, caseExactIndexer, caseExactFilter,
4414 directoryStringApproxMatchOID },
4416 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4417 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4420 caseExactOrderingMatch, NULL, NULL,
4423 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4424 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4425 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4427 caseExactSubstringsMatch,
4428 caseExactSubstringsIndexer,
4429 caseExactSubstringsFilter,
4432 {"( 2.5.13.8 NAME 'numericStringMatch' "
4433 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4434 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4437 caseIgnoreIA5Indexer,
4438 caseIgnoreIA5Filter,
4441 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4442 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4443 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4445 caseIgnoreIA5SubstringsMatch,
4446 caseIgnoreIA5SubstringsIndexer,
4447 caseIgnoreIA5SubstringsFilter,
4450 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4451 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4452 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4454 caseIgnoreListMatch, NULL, NULL,
4457 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4458 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4459 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4461 caseIgnoreListSubstringsMatch, NULL, NULL,
4464 {"( 2.5.13.13 NAME 'booleanMatch' "
4465 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4466 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4468 booleanMatch, NULL, NULL,
4471 {"( 2.5.13.14 NAME 'integerMatch' "
4472 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4473 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4475 integerMatch, integerIndexer, integerFilter,
4478 {"( 2.5.13.16 NAME 'bitStringMatch' "
4479 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4480 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4482 bitStringMatch, NULL, NULL,
4485 {"( 2.5.13.17 NAME 'octetStringMatch' "
4486 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4487 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4489 octetStringMatch, octetStringIndexer, octetStringFilter,
4492 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4493 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4494 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4496 telephoneNumberMatch,
4497 telephoneNumberIndexer,
4498 telephoneNumberFilter,
4501 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4502 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4503 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4505 telephoneNumberSubstringsMatch,
4506 telephoneNumberSubstringsIndexer,
4507 telephoneNumberSubstringsFilter,
4510 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4511 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4512 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4517 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4518 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4519 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4521 uniqueMemberMatch, NULL, NULL,
4524 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4525 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4526 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4528 protocolInformationMatch, NULL, NULL,
4531 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4532 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4533 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4535 generalizedTimeMatch, NULL, NULL,
4538 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4539 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4542 generalizedTimeOrderingMatch, NULL, NULL,
4545 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4546 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4547 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4549 integerFirstComponentMatch, NULL, NULL,
4552 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4553 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4554 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4556 objectIdentifierFirstComponentMatch, NULL, NULL,
4559 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4560 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4561 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4563 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4564 IA5StringApproxMatchOID },
4566 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4567 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4568 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4570 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4571 IA5StringApproxMatchOID },
4573 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4574 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4577 caseIgnoreIA5SubstringsMatch,
4578 caseIgnoreIA5SubstringsIndexer,
4579 caseIgnoreIA5SubstringsFilter,
4582 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4583 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4586 caseExactIA5SubstringsMatch,
4587 caseExactIA5SubstringsIndexer,
4588 caseExactIA5SubstringsFilter,
4591 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4592 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4595 authPasswordMatch, NULL, NULL,
4598 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4599 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4602 OpenLDAPaciMatch, NULL, NULL,
4605 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4614 /* we should only be called once (from main) */
4615 assert( schema_init_done == 0 );
4617 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4618 res = register_syntax( syntax_defs[i].sd_desc,
4619 syntax_defs[i].sd_flags,
4620 syntax_defs[i].sd_validate,
4621 syntax_defs[i].sd_normalize,
4622 syntax_defs[i].sd_pretty
4623 #ifdef SLAPD_BINARY_CONVERSION
4625 syntax_defs[i].sd_ber2str,
4626 syntax_defs[i].sd_str2ber
4631 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4632 syntax_defs[i].sd_desc );
4637 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4638 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4640 "schema_init: Ingoring unusable matching rule %s\n",
4641 mrule_defs[i].mrd_desc );
4645 res = register_matching_rule(
4646 mrule_defs[i].mrd_desc,
4647 mrule_defs[i].mrd_usage,
4648 mrule_defs[i].mrd_convert,
4649 mrule_defs[i].mrd_normalize,
4650 mrule_defs[i].mrd_match,
4651 mrule_defs[i].mrd_indexer,
4652 mrule_defs[i].mrd_filter,
4653 mrule_defs[i].mrd_associated );
4657 "schema_init: Error registering matching rule %s\n",
4658 mrule_defs[i].mrd_desc );
4662 schema_init_done = 1;
4663 return LDAP_SUCCESS;