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;
1277 struct berval **nvalues;
1280 HASH_CONTEXT HASHcontext;
1281 unsigned char HASHdigest[HASH_BYTES];
1282 struct berval digest;
1283 digest.bv_val = HASHdigest;
1284 digest.bv_len = sizeof(HASHdigest);
1286 /* we should have at least one value at this point */
1287 assert( values != NULL && values[0] != NULL );
1292 /* create normalized copy of values */
1293 for( i=0; values[i] != NULL; i++ ) {
1296 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1297 for( i=0; values[i] != NULL; i++ ) {
1298 nvalues[i] = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
1304 for( i=0; values[i] != NULL; i++ ) {
1305 /* count number of indices to generate */
1306 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1310 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1311 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1312 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1313 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1315 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1319 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1320 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1321 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1325 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1326 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1327 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1328 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1330 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1336 /* no keys to generate */
1338 return LDAP_SUCCESS;
1341 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1343 slen = strlen( syntax->ssyn_oid );
1344 mlen = strlen( mr->smr_oid );
1347 for( i=0; values[i] != NULL; i++ ) {
1349 struct berval *value;
1351 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1355 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1356 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1358 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1359 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1361 for( j=0; j<max; j++ ) {
1362 HASH_Init( &HASHcontext );
1363 if( prefix != NULL && prefix->bv_len > 0 ) {
1364 HASH_Update( &HASHcontext,
1365 prefix->bv_val, prefix->bv_len );
1368 HASH_Update( &HASHcontext,
1369 &pre, sizeof( pre ) );
1370 HASH_Update( &HASHcontext,
1371 syntax->ssyn_oid, slen );
1372 HASH_Update( &HASHcontext,
1373 mr->smr_oid, mlen );
1374 HASH_Update( &HASHcontext,
1376 SLAP_INDEX_SUBSTR_MAXLEN );
1377 HASH_Final( HASHdigest, &HASHcontext );
1379 keys[nkeys++] = ber_bvdup( &digest );
1383 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1384 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1386 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1389 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1390 pre = SLAP_INDEX_SUBSTR_INITIAL_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,
1404 HASH_Final( HASHdigest, &HASHcontext );
1406 keys[nkeys++] = ber_bvdup( &digest );
1409 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1410 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1411 HASH_Init( &HASHcontext );
1412 if( prefix != NULL && prefix->bv_len > 0 ) {
1413 HASH_Update( &HASHcontext,
1414 prefix->bv_val, prefix->bv_len );
1416 HASH_Update( &HASHcontext,
1417 &pre, sizeof( pre ) );
1418 HASH_Update( &HASHcontext,
1419 syntax->ssyn_oid, slen );
1420 HASH_Update( &HASHcontext,
1421 mr->smr_oid, mlen );
1422 HASH_Update( &HASHcontext,
1423 &value->bv_val[value->bv_len-j], j );
1424 HASH_Final( HASHdigest, &HASHcontext );
1426 keys[nkeys++] = ber_bvdup( &digest );
1442 ber_bvecfree( nvalues );
1445 return LDAP_SUCCESS;
1448 int caseExactSubstringsFilter(
1453 struct berval *prefix,
1455 struct berval ***keysp )
1457 SubstringsAssertion *sa = assertValue;
1459 ber_len_t nkeys = 0;
1460 size_t slen, mlen, klen;
1461 struct berval **keys;
1462 HASH_CONTEXT HASHcontext;
1463 unsigned char HASHdigest[HASH_BYTES];
1464 struct berval *value;
1465 struct berval digest;
1467 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1468 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1473 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1475 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1476 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1477 /* don't bother accounting for stepping */
1478 nkeys += sa->sa_any[i]->bv_len -
1479 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1484 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1485 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1492 return LDAP_SUCCESS;
1495 digest.bv_val = HASHdigest;
1496 digest.bv_len = sizeof(HASHdigest);
1498 slen = strlen( syntax->ssyn_oid );
1499 mlen = strlen( mr->smr_oid );
1501 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1504 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1505 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1507 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1509 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val,
1510 UTF8_NOCASEFOLD ) );
1512 value = sa->sa_initial;
1515 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1516 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1518 HASH_Init( &HASHcontext );
1519 if( prefix != NULL && prefix->bv_len > 0 ) {
1520 HASH_Update( &HASHcontext,
1521 prefix->bv_val, prefix->bv_len );
1523 HASH_Update( &HASHcontext,
1524 &pre, sizeof( pre ) );
1525 HASH_Update( &HASHcontext,
1526 syntax->ssyn_oid, slen );
1527 HASH_Update( &HASHcontext,
1528 mr->smr_oid, mlen );
1529 HASH_Update( &HASHcontext,
1530 value->bv_val, klen );
1531 HASH_Final( HASHdigest, &HASHcontext );
1534 ber_bvfree( value );
1536 keys[nkeys++] = ber_bvdup( &digest );
1539 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1541 pre = SLAP_INDEX_SUBSTR_PREFIX;
1542 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1544 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1545 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1550 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val,
1551 UTF8_NOCASEFOLD ) );
1553 value = sa->sa_any[i];
1557 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1558 j += SLAP_INDEX_SUBSTR_STEP )
1560 HASH_Init( &HASHcontext );
1561 if( prefix != NULL && prefix->bv_len > 0 ) {
1562 HASH_Update( &HASHcontext,
1563 prefix->bv_val, prefix->bv_len );
1565 HASH_Update( &HASHcontext,
1566 &pre, sizeof( pre ) );
1567 HASH_Update( &HASHcontext,
1568 syntax->ssyn_oid, slen );
1569 HASH_Update( &HASHcontext,
1570 mr->smr_oid, mlen );
1571 HASH_Update( &HASHcontext,
1572 &value->bv_val[j], klen );
1573 HASH_Final( HASHdigest, &HASHcontext );
1575 keys[nkeys++] = ber_bvdup( &digest );
1579 ber_bvfree( value );
1584 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1585 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1587 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1589 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val,
1590 UTF8_NOCASEFOLD ) );
1592 value = sa->sa_final;
1595 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1596 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1598 HASH_Init( &HASHcontext );
1599 if( prefix != NULL && prefix->bv_len > 0 ) {
1600 HASH_Update( &HASHcontext,
1601 prefix->bv_val, prefix->bv_len );
1603 HASH_Update( &HASHcontext,
1604 &pre, sizeof( pre ) );
1605 HASH_Update( &HASHcontext,
1606 syntax->ssyn_oid, slen );
1607 HASH_Update( &HASHcontext,
1608 mr->smr_oid, mlen );
1609 HASH_Update( &HASHcontext,
1610 &value->bv_val[value->bv_len-klen], klen );
1611 HASH_Final( HASHdigest, &HASHcontext );
1614 ber_bvfree( value );
1616 keys[nkeys++] = ber_bvdup( &digest );
1627 return LDAP_SUCCESS;
1636 struct berval *value,
1637 void *assertedValue )
1640 *matchp = UTF8normcmp( value->bv_val,
1641 ((struct berval *) assertedValue)->bv_val,
1644 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1647 match = strncasecmp( value->bv_val,
1648 ((struct berval *) assertedValue)->bv_val,
1654 return LDAP_SUCCESS;
1658 caseIgnoreSubstringsMatch(
1663 struct berval *value,
1664 void *assertedValue )
1667 SubstringsAssertion *sub = assertedValue;
1668 struct berval left = *value;
1672 /* Add up asserted input length */
1673 if( sub->sa_initial ) {
1674 inlen += sub->sa_initial->bv_len;
1677 for(i=0; sub->sa_any[i] != NULL; i++) {
1678 inlen += sub->sa_any[i]->bv_len;
1681 if( sub->sa_final ) {
1682 inlen += sub->sa_final->bv_len;
1685 if( sub->sa_initial ) {
1686 if( inlen > left.bv_len ) {
1692 match = UTF8oncasecmp( sub->sa_initial, &left,
1693 sub->sa_initial->bv_len, 0 );
1695 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1696 sub->sa_initial->bv_len );
1703 left.bv_val += sub->sa_initial->bv_len;
1704 left.bv_len -= sub->sa_initial->bv_len;
1705 inlen -= sub->sa_initial->bv_len;
1708 if( sub->sa_final ) {
1709 if( inlen > left.bv_len ) {
1715 match = UTF8oncasecmp( sub->sa_final, &left,
1716 sub->sa_final->bv_len,
1717 left.bv_len - sub->sa_final->bv_len );
1719 match = strncasecmp( sub->sa_final->bv_val,
1720 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1721 sub->sa_final->bv_len );
1728 left.bv_len -= sub->sa_final->bv_len;
1729 inlen -= sub->sa_final->bv_len;
1733 for(i=0; sub->sa_any[i]; i++) {
1738 if( inlen > left.bv_len ) {
1739 /* not enough length */
1744 if( sub->sa_any[i]->bv_len == 0 ) {
1749 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1751 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1759 idx = p - left.bv_val;
1760 assert( idx < left.bv_len );
1762 if( idx >= left.bv_len ) {
1763 /* this shouldn't happen */
1770 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1771 /* not enough left */
1777 match = UTF8oncasecmp( &left, sub->sa_any[i],
1778 sub->sa_any[i]->bv_len, 0 );
1781 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1787 match = strncasecmp( left.bv_val,
1788 sub->sa_any[i]->bv_val,
1789 sub->sa_any[i]->bv_len );
1799 left.bv_val += sub->sa_any[i]->bv_len;
1800 left.bv_len -= sub->sa_any[i]->bv_len;
1801 inlen -= sub->sa_any[i]->bv_len;
1807 return LDAP_SUCCESS;
1810 /* Index generation function */
1811 int caseIgnoreIndexer(
1816 struct berval *prefix,
1817 struct berval **values,
1818 struct berval ***keysp )
1822 struct berval **keys;
1823 HASH_CONTEXT HASHcontext;
1824 unsigned char HASHdigest[HASH_BYTES];
1825 struct berval digest;
1826 digest.bv_val = HASHdigest;
1827 digest.bv_len = sizeof(HASHdigest);
1829 /* we should have at least one value at this point */
1830 assert( values != NULL && values[0] != NULL );
1832 for( i=0; values[i] != NULL; i++ ) {
1833 /* just count them */
1836 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1838 slen = strlen( syntax->ssyn_oid );
1839 mlen = strlen( mr->smr_oid );
1841 for( i=0; values[i] != NULL; i++ ) {
1842 struct berval *value;
1844 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1846 value = ber_bvdup( values[i] );
1847 ldap_pvt_str2upper( value->bv_val );
1849 HASH_Init( &HASHcontext );
1850 if( prefix != NULL && prefix->bv_len > 0 ) {
1851 HASH_Update( &HASHcontext,
1852 prefix->bv_val, prefix->bv_len );
1854 HASH_Update( &HASHcontext,
1855 syntax->ssyn_oid, slen );
1856 HASH_Update( &HASHcontext,
1857 mr->smr_oid, mlen );
1858 HASH_Update( &HASHcontext,
1859 value->bv_val, value->bv_len );
1860 HASH_Final( HASHdigest, &HASHcontext );
1862 ber_bvfree( value );
1864 keys[i] = ber_bvdup( &digest );
1869 return LDAP_SUCCESS;
1872 /* Index generation function */
1873 int caseIgnoreFilter(
1878 struct berval *prefix,
1880 struct berval ***keysp )
1883 struct berval **keys;
1884 HASH_CONTEXT HASHcontext;
1885 unsigned char HASHdigest[HASH_BYTES];
1886 struct berval *value;
1887 struct berval digest;
1888 digest.bv_val = HASHdigest;
1889 digest.bv_len = sizeof(HASHdigest);
1891 slen = strlen( syntax->ssyn_oid );
1892 mlen = strlen( mr->smr_oid );
1895 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val,
1897 /* This usually happens if filter contains bad UTF8 */
1898 if( value == NULL ) {
1899 keys = ch_malloc( sizeof( struct berval * ) );
1901 return LDAP_SUCCESS;
1904 value = ber_bvdup( (struct berval *) assertValue );
1905 ldap_pvt_str2upper( value->bv_val );
1908 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1910 HASH_Init( &HASHcontext );
1911 if( prefix != NULL && prefix->bv_len > 0 ) {
1912 HASH_Update( &HASHcontext,
1913 prefix->bv_val, prefix->bv_len );
1915 HASH_Update( &HASHcontext,
1916 syntax->ssyn_oid, slen );
1917 HASH_Update( &HASHcontext,
1918 mr->smr_oid, mlen );
1919 HASH_Update( &HASHcontext,
1920 value->bv_val, value->bv_len );
1921 HASH_Final( HASHdigest, &HASHcontext );
1923 keys[0] = ber_bvdup( &digest );
1926 ber_bvfree( value );
1930 return LDAP_SUCCESS;
1933 /* Substrings Index generation function */
1934 int caseIgnoreSubstringsIndexer(
1939 struct berval *prefix,
1940 struct berval **values,
1941 struct berval ***keysp )
1945 struct berval **keys;
1947 struct berval **nvalues;
1950 HASH_CONTEXT HASHcontext;
1951 unsigned char HASHdigest[HASH_BYTES];
1952 struct berval digest;
1953 digest.bv_val = HASHdigest;
1954 digest.bv_len = sizeof(HASHdigest);
1956 /* we should have at least one value at this point */
1957 assert( values != NULL && values[0] != NULL );
1962 /* create normalized copy of values */
1963 for( i=0; values[i] != NULL; i++ ) {
1966 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1967 for( i=0; values[i] != NULL; i++ ) {
1968 nvalues[i] = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1974 for( i=0; values[i] != NULL; i++ ) {
1975 /* count number of indices to generate */
1976 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1980 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1981 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1982 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1983 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1985 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1989 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1990 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1991 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1995 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1996 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1997 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1998 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2000 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2006 /* no keys to generate */
2008 return LDAP_SUCCESS;
2011 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2013 slen = strlen( syntax->ssyn_oid );
2014 mlen = strlen( mr->smr_oid );
2017 for( i=0; values[i] != NULL; i++ ) {
2019 struct berval *value;
2021 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2026 value = ber_bvdup( values[i] );
2027 ldap_pvt_str2upper( value->bv_val );
2030 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2031 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2033 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2034 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2036 for( j=0; j<max; j++ ) {
2037 HASH_Init( &HASHcontext );
2038 if( prefix != NULL && prefix->bv_len > 0 ) {
2039 HASH_Update( &HASHcontext,
2040 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,
2051 SLAP_INDEX_SUBSTR_MAXLEN );
2052 HASH_Final( HASHdigest, &HASHcontext );
2054 keys[nkeys++] = ber_bvdup( &digest );
2058 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2059 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2061 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2064 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2065 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2066 HASH_Init( &HASHcontext );
2067 if( prefix != NULL && prefix->bv_len > 0 ) {
2068 HASH_Update( &HASHcontext,
2069 prefix->bv_val, prefix->bv_len );
2071 HASH_Update( &HASHcontext,
2072 &pre, sizeof( pre ) );
2073 HASH_Update( &HASHcontext,
2074 syntax->ssyn_oid, slen );
2075 HASH_Update( &HASHcontext,
2076 mr->smr_oid, mlen );
2077 HASH_Update( &HASHcontext,
2079 HASH_Final( HASHdigest, &HASHcontext );
2081 keys[nkeys++] = ber_bvdup( &digest );
2084 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2085 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2086 HASH_Init( &HASHcontext );
2087 if( prefix != NULL && prefix->bv_len > 0 ) {
2088 HASH_Update( &HASHcontext,
2089 prefix->bv_val, prefix->bv_len );
2091 HASH_Update( &HASHcontext,
2092 &pre, sizeof( pre ) );
2093 HASH_Update( &HASHcontext,
2094 syntax->ssyn_oid, slen );
2095 HASH_Update( &HASHcontext,
2096 mr->smr_oid, mlen );
2097 HASH_Update( &HASHcontext,
2098 &value->bv_val[value->bv_len-j], j );
2099 HASH_Final( HASHdigest, &HASHcontext );
2101 keys[nkeys++] = ber_bvdup( &digest );
2106 ber_bvfree( value );
2119 ber_bvecfree( nvalues );
2121 return LDAP_SUCCESS;
2124 int caseIgnoreSubstringsFilter(
2129 struct berval *prefix,
2131 struct berval ***keysp )
2133 SubstringsAssertion *sa = assertValue;
2135 ber_len_t nkeys = 0;
2136 size_t slen, mlen, klen;
2137 struct berval **keys;
2138 HASH_CONTEXT HASHcontext;
2139 unsigned char HASHdigest[HASH_BYTES];
2140 struct berval *value;
2141 struct berval digest;
2143 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2144 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2149 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2151 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2152 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2153 /* don't bother accounting for stepping */
2154 nkeys += sa->sa_any[i]->bv_len -
2155 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2160 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2161 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2168 return LDAP_SUCCESS;
2171 digest.bv_val = HASHdigest;
2172 digest.bv_len = sizeof(HASHdigest);
2174 slen = strlen( syntax->ssyn_oid );
2175 mlen = strlen( mr->smr_oid );
2177 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2180 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2181 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2183 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2185 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_CASEFOLD ) );
2187 value = ber_bvdup( sa->sa_initial );
2188 ldap_pvt_str2upper( value->bv_val );
2191 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2192 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2194 HASH_Init( &HASHcontext );
2195 if( prefix != NULL && prefix->bv_len > 0 ) {
2196 HASH_Update( &HASHcontext,
2197 prefix->bv_val, prefix->bv_len );
2199 HASH_Update( &HASHcontext,
2200 &pre, sizeof( pre ) );
2201 HASH_Update( &HASHcontext,
2202 syntax->ssyn_oid, slen );
2203 HASH_Update( &HASHcontext,
2204 mr->smr_oid, mlen );
2205 HASH_Update( &HASHcontext,
2206 value->bv_val, klen );
2207 HASH_Final( HASHdigest, &HASHcontext );
2209 ber_bvfree( value );
2210 keys[nkeys++] = ber_bvdup( &digest );
2213 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2215 pre = SLAP_INDEX_SUBSTR_PREFIX;
2216 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2218 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2219 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2224 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_CASEFOLD ) );
2226 value = ber_bvdup( sa->sa_any[i] );
2227 ldap_pvt_str2upper( value->bv_val );
2231 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2232 j += SLAP_INDEX_SUBSTR_STEP )
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[j], klen );
2247 HASH_Final( HASHdigest, &HASHcontext );
2249 keys[nkeys++] = ber_bvdup( &digest );
2252 ber_bvfree( value );
2256 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2257 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2259 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2261 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_CASEFOLD ) );
2263 value = ber_bvdup( sa->sa_final );
2264 ldap_pvt_str2upper( value->bv_val );
2267 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2268 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2270 HASH_Init( &HASHcontext );
2271 if( prefix != NULL && prefix->bv_len > 0 ) {
2272 HASH_Update( &HASHcontext,
2273 prefix->bv_val, prefix->bv_len );
2275 HASH_Update( &HASHcontext,
2276 &pre, sizeof( pre ) );
2277 HASH_Update( &HASHcontext,
2278 syntax->ssyn_oid, slen );
2279 HASH_Update( &HASHcontext,
2280 mr->smr_oid, mlen );
2281 HASH_Update( &HASHcontext,
2282 &value->bv_val[value->bv_len-klen], klen );
2283 HASH_Final( HASHdigest, &HASHcontext );
2285 ber_bvfree( value );
2286 keys[nkeys++] = ber_bvdup( &digest );
2297 return LDAP_SUCCESS;
2303 struct berval *val )
2307 if( val->bv_len == 0 ) {
2308 /* disallow empty strings */
2309 return LDAP_INVALID_SYNTAX;
2312 if( OID_LEADCHAR(val->bv_val[0]) ) {
2314 for(i=1; i < val->bv_len; i++) {
2315 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2316 if( dot++ ) return 1;
2317 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2320 return LDAP_INVALID_SYNTAX;
2324 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2326 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2327 for(i=1; i < val->bv_len; i++) {
2328 if( !DESC_CHAR(val->bv_val[i] ) ) {
2329 return LDAP_INVALID_SYNTAX;
2333 return LDAP_SUCCESS;
2336 return LDAP_INVALID_SYNTAX;
2342 struct berval *val )
2346 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2348 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2349 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2350 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2351 return LDAP_INVALID_SYNTAX;
2354 for(i=1; i < val->bv_len; i++) {
2355 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2358 return LDAP_SUCCESS;
2365 struct berval **normalized )
2368 struct berval *newval;
2374 negative = ( *p == '-' );
2375 if( *p == '-' || *p == '+' ) p++;
2377 /* Ignore leading zeros */
2378 while ( *p == '0' ) p++;
2380 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2383 newval->bv_val = ch_strdup("0");
2388 newval->bv_val = ch_malloc( val->bv_len + 1 );
2392 newval->bv_val[newval->bv_len++] = '-';
2395 for( ; *p != '\0'; p++ ) {
2396 newval->bv_val[newval->bv_len++] = *p;
2400 *normalized = newval;
2401 return LDAP_SUCCESS;
2405 countryStringValidate(
2407 struct berval *val )
2409 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2411 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2412 return LDAP_INVALID_SYNTAX;
2414 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2415 return LDAP_INVALID_SYNTAX;
2418 return LDAP_SUCCESS;
2422 printableStringValidate(
2424 struct berval *val )
2428 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2430 for(i=0; i < val->bv_len; i++) {
2431 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2432 return LDAP_INVALID_SYNTAX;
2436 return LDAP_SUCCESS;
2440 printablesStringValidate(
2442 struct berval *val )
2446 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2448 for(i=0; i < val->bv_len; i++) {
2449 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2450 return LDAP_INVALID_SYNTAX;
2454 return LDAP_SUCCESS;
2460 struct berval *val )
2464 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2466 for(i=0; i < val->bv_len; i++) {
2467 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2470 return LDAP_SUCCESS;
2477 struct berval **normalized )
2479 struct berval *newval;
2482 newval = ch_malloc( sizeof( struct berval ) );
2486 /* Ignore initial whitespace */
2487 while ( ASCII_SPACE( *p ) ) {
2493 return LDAP_INVALID_SYNTAX;
2496 newval->bv_val = ch_strdup( p );
2497 p = q = newval->bv_val;
2500 if ( ASCII_SPACE( *p ) ) {
2503 /* Ignore the extra whitespace */
2504 while ( ASCII_SPACE( *p ) ) {
2512 assert( *newval->bv_val );
2513 assert( newval->bv_val < p );
2516 /* cannot start with a space */
2517 assert( !ASCII_SPACE(*newval->bv_val) );
2520 * If the string ended in space, backup the pointer one
2521 * position. One is enough because the above loop collapsed
2522 * all whitespace to a single space.
2525 if ( ASCII_SPACE( q[-1] ) ) {
2529 /* cannot end with a space */
2530 assert( !ASCII_SPACE( q[-1] ) );
2532 /* null terminate */
2535 newval->bv_len = q - newval->bv_val;
2536 *normalized = newval;
2538 return LDAP_SUCCESS;
2547 struct berval *value,
2548 void *assertedValue )
2550 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2553 match = strncmp( value->bv_val,
2554 ((struct berval *) assertedValue)->bv_val,
2559 return LDAP_SUCCESS;
2563 caseExactIA5SubstringsMatch(
2568 struct berval *value,
2569 void *assertedValue )
2572 SubstringsAssertion *sub = assertedValue;
2573 struct berval left = *value;
2577 /* Add up asserted input length */
2578 if( sub->sa_initial ) {
2579 inlen += sub->sa_initial->bv_len;
2582 for(i=0; sub->sa_any[i] != NULL; i++) {
2583 inlen += sub->sa_any[i]->bv_len;
2586 if( sub->sa_final ) {
2587 inlen += sub->sa_final->bv_len;
2590 if( sub->sa_initial ) {
2591 if( inlen > left.bv_len ) {
2596 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2597 sub->sa_initial->bv_len );
2603 left.bv_val += sub->sa_initial->bv_len;
2604 left.bv_len -= sub->sa_initial->bv_len;
2605 inlen -= sub->sa_initial->bv_len;
2608 if( sub->sa_final ) {
2609 if( inlen > left.bv_len ) {
2614 match = strncmp( sub->sa_final->bv_val,
2615 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2616 sub->sa_final->bv_len );
2622 left.bv_len -= sub->sa_final->bv_len;
2623 inlen -= sub->sa_final->bv_len;
2627 for(i=0; sub->sa_any[i]; i++) {
2632 if( inlen > left.bv_len ) {
2633 /* not enough length */
2638 if( sub->sa_any[i]->bv_len == 0 ) {
2642 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2649 idx = p - left.bv_val;
2650 assert( idx < left.bv_len );
2652 if( idx >= left.bv_len ) {
2653 /* this shouldn't happen */
2660 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2661 /* not enough left */
2666 match = strncmp( left.bv_val,
2667 sub->sa_any[i]->bv_val,
2668 sub->sa_any[i]->bv_len );
2676 left.bv_val += sub->sa_any[i]->bv_len;
2677 left.bv_len -= sub->sa_any[i]->bv_len;
2678 inlen -= sub->sa_any[i]->bv_len;
2684 return LDAP_SUCCESS;
2687 /* Index generation function */
2688 int caseExactIA5Indexer(
2693 struct berval *prefix,
2694 struct berval **values,
2695 struct berval ***keysp )
2699 struct berval **keys;
2700 HASH_CONTEXT HASHcontext;
2701 unsigned char HASHdigest[HASH_BYTES];
2702 struct berval digest;
2703 digest.bv_val = HASHdigest;
2704 digest.bv_len = sizeof(HASHdigest);
2706 /* we should have at least one value at this point */
2707 assert( values != NULL && values[0] != NULL );
2709 for( i=0; values[i] != NULL; i++ ) {
2710 /* just count them */
2713 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2715 slen = strlen( syntax->ssyn_oid );
2716 mlen = strlen( mr->smr_oid );
2718 for( i=0; values[i] != NULL; i++ ) {
2719 struct berval *value = values[i];
2721 HASH_Init( &HASHcontext );
2722 if( prefix != NULL && prefix->bv_len > 0 ) {
2723 HASH_Update( &HASHcontext,
2724 prefix->bv_val, prefix->bv_len );
2726 HASH_Update( &HASHcontext,
2727 syntax->ssyn_oid, slen );
2728 HASH_Update( &HASHcontext,
2729 mr->smr_oid, mlen );
2730 HASH_Update( &HASHcontext,
2731 value->bv_val, value->bv_len );
2732 HASH_Final( HASHdigest, &HASHcontext );
2734 keys[i] = ber_bvdup( &digest );
2739 return LDAP_SUCCESS;
2742 /* Index generation function */
2743 int caseExactIA5Filter(
2748 struct berval *prefix,
2750 struct berval ***keysp )
2753 struct berval **keys;
2754 HASH_CONTEXT HASHcontext;
2755 unsigned char HASHdigest[HASH_BYTES];
2756 struct berval *value;
2757 struct berval digest;
2758 digest.bv_val = HASHdigest;
2759 digest.bv_len = sizeof(HASHdigest);
2761 slen = strlen( syntax->ssyn_oid );
2762 mlen = strlen( mr->smr_oid );
2764 value = (struct berval *) assertValue;
2766 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2768 HASH_Init( &HASHcontext );
2769 if( prefix != NULL && prefix->bv_len > 0 ) {
2770 HASH_Update( &HASHcontext,
2771 prefix->bv_val, prefix->bv_len );
2773 HASH_Update( &HASHcontext,
2774 syntax->ssyn_oid, slen );
2775 HASH_Update( &HASHcontext,
2776 mr->smr_oid, mlen );
2777 HASH_Update( &HASHcontext,
2778 value->bv_val, value->bv_len );
2779 HASH_Final( HASHdigest, &HASHcontext );
2781 keys[0] = ber_bvdup( &digest );
2785 return LDAP_SUCCESS;
2788 /* Substrings Index generation function */
2789 int caseExactIA5SubstringsIndexer(
2794 struct berval *prefix,
2795 struct berval **values,
2796 struct berval ***keysp )
2800 struct berval **keys;
2801 HASH_CONTEXT HASHcontext;
2802 unsigned char HASHdigest[HASH_BYTES];
2803 struct berval digest;
2804 digest.bv_val = HASHdigest;
2805 digest.bv_len = sizeof(HASHdigest);
2807 /* we should have at least one value at this point */
2808 assert( values != NULL && values[0] != NULL );
2811 for( i=0; values[i] != NULL; i++ ) {
2812 /* count number of indices to generate */
2813 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2817 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2818 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2819 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2820 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2822 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2826 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2827 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2828 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2832 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2833 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2834 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2835 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2837 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2843 /* no keys to generate */
2845 return LDAP_SUCCESS;
2848 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2850 slen = strlen( syntax->ssyn_oid );
2851 mlen = strlen( mr->smr_oid );
2854 for( i=0; values[i] != NULL; i++ ) {
2856 struct berval *value;
2859 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2861 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2862 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2864 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2865 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2867 for( j=0; j<max; j++ ) {
2868 HASH_Init( &HASHcontext );
2869 if( prefix != NULL && prefix->bv_len > 0 ) {
2870 HASH_Update( &HASHcontext,
2871 prefix->bv_val, prefix->bv_len );
2874 HASH_Update( &HASHcontext,
2875 &pre, sizeof( pre ) );
2876 HASH_Update( &HASHcontext,
2877 syntax->ssyn_oid, slen );
2878 HASH_Update( &HASHcontext,
2879 mr->smr_oid, mlen );
2880 HASH_Update( &HASHcontext,
2882 SLAP_INDEX_SUBSTR_MAXLEN );
2883 HASH_Final( HASHdigest, &HASHcontext );
2885 keys[nkeys++] = ber_bvdup( &digest );
2889 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2890 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2892 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2895 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2896 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2897 HASH_Init( &HASHcontext );
2898 if( prefix != NULL && prefix->bv_len > 0 ) {
2899 HASH_Update( &HASHcontext,
2900 prefix->bv_val, prefix->bv_len );
2902 HASH_Update( &HASHcontext,
2903 &pre, sizeof( pre ) );
2904 HASH_Update( &HASHcontext,
2905 syntax->ssyn_oid, slen );
2906 HASH_Update( &HASHcontext,
2907 mr->smr_oid, mlen );
2908 HASH_Update( &HASHcontext,
2910 HASH_Final( HASHdigest, &HASHcontext );
2912 keys[nkeys++] = ber_bvdup( &digest );
2915 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2916 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2917 HASH_Init( &HASHcontext );
2918 if( prefix != NULL && prefix->bv_len > 0 ) {
2919 HASH_Update( &HASHcontext,
2920 prefix->bv_val, prefix->bv_len );
2922 HASH_Update( &HASHcontext,
2923 &pre, sizeof( pre ) );
2924 HASH_Update( &HASHcontext,
2925 syntax->ssyn_oid, slen );
2926 HASH_Update( &HASHcontext,
2927 mr->smr_oid, mlen );
2928 HASH_Update( &HASHcontext,
2929 &value->bv_val[value->bv_len-j], j );
2930 HASH_Final( HASHdigest, &HASHcontext );
2932 keys[nkeys++] = ber_bvdup( &digest );
2946 return LDAP_SUCCESS;
2949 int caseExactIA5SubstringsFilter(
2954 struct berval *prefix,
2956 struct berval ***keysp )
2958 SubstringsAssertion *sa = assertValue;
2960 ber_len_t nkeys = 0;
2961 size_t slen, mlen, klen;
2962 struct berval **keys;
2963 HASH_CONTEXT HASHcontext;
2964 unsigned char HASHdigest[HASH_BYTES];
2965 struct berval *value;
2966 struct berval digest;
2968 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2969 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2974 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2976 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2977 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2978 /* don't bother accounting for stepping */
2979 nkeys += sa->sa_any[i]->bv_len -
2980 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2985 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2986 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2993 return LDAP_SUCCESS;
2996 digest.bv_val = HASHdigest;
2997 digest.bv_len = sizeof(HASHdigest);
2999 slen = strlen( syntax->ssyn_oid );
3000 mlen = strlen( mr->smr_oid );
3002 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3005 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
3006 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3008 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3009 value = sa->sa_initial;
3011 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3012 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3014 HASH_Init( &HASHcontext );
3015 if( prefix != NULL && prefix->bv_len > 0 ) {
3016 HASH_Update( &HASHcontext,
3017 prefix->bv_val, prefix->bv_len );
3019 HASH_Update( &HASHcontext,
3020 &pre, sizeof( pre ) );
3021 HASH_Update( &HASHcontext,
3022 syntax->ssyn_oid, slen );
3023 HASH_Update( &HASHcontext,
3024 mr->smr_oid, mlen );
3025 HASH_Update( &HASHcontext,
3026 value->bv_val, klen );
3027 HASH_Final( HASHdigest, &HASHcontext );
3029 keys[nkeys++] = ber_bvdup( &digest );
3032 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
3034 pre = SLAP_INDEX_SUBSTR_PREFIX;
3035 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3037 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3038 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3042 value = sa->sa_any[i];
3045 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3046 j += SLAP_INDEX_SUBSTR_STEP )
3048 HASH_Init( &HASHcontext );
3049 if( prefix != NULL && prefix->bv_len > 0 ) {
3050 HASH_Update( &HASHcontext,
3051 prefix->bv_val, prefix->bv_len );
3053 HASH_Update( &HASHcontext,
3054 &pre, sizeof( pre ) );
3055 HASH_Update( &HASHcontext,
3056 syntax->ssyn_oid, slen );
3057 HASH_Update( &HASHcontext,
3058 mr->smr_oid, mlen );
3059 HASH_Update( &HASHcontext,
3060 &value->bv_val[j], klen );
3061 HASH_Final( HASHdigest, &HASHcontext );
3063 keys[nkeys++] = ber_bvdup( &digest );
3068 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3069 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3071 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3072 value = sa->sa_final;
3074 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3075 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3077 HASH_Init( &HASHcontext );
3078 if( prefix != NULL && prefix->bv_len > 0 ) {
3079 HASH_Update( &HASHcontext,
3080 prefix->bv_val, prefix->bv_len );
3082 HASH_Update( &HASHcontext,
3083 &pre, sizeof( pre ) );
3084 HASH_Update( &HASHcontext,
3085 syntax->ssyn_oid, slen );
3086 HASH_Update( &HASHcontext,
3087 mr->smr_oid, mlen );
3088 HASH_Update( &HASHcontext,
3089 &value->bv_val[value->bv_len-klen], klen );
3090 HASH_Final( HASHdigest, &HASHcontext );
3092 keys[nkeys++] = ber_bvdup( &digest );
3103 return LDAP_SUCCESS;
3112 struct berval *value,
3113 void *assertedValue )
3115 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3117 if( match == 0 && value->bv_len ) {
3118 match = strncasecmp( value->bv_val,
3119 ((struct berval *) assertedValue)->bv_val,
3124 return LDAP_SUCCESS;
3128 caseIgnoreIA5SubstringsMatch(
3133 struct berval *value,
3134 void *assertedValue )
3137 SubstringsAssertion *sub = assertedValue;
3138 struct berval left = *value;
3142 /* Add up asserted input length */
3143 if( sub->sa_initial ) {
3144 inlen += sub->sa_initial->bv_len;
3147 for(i=0; sub->sa_any[i] != NULL; i++) {
3148 inlen += sub->sa_any[i]->bv_len;
3151 if( sub->sa_final ) {
3152 inlen += sub->sa_final->bv_len;
3155 if( sub->sa_initial ) {
3156 if( inlen > left.bv_len ) {
3161 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3162 sub->sa_initial->bv_len );
3168 left.bv_val += sub->sa_initial->bv_len;
3169 left.bv_len -= sub->sa_initial->bv_len;
3170 inlen -= sub->sa_initial->bv_len;
3173 if( sub->sa_final ) {
3174 if( inlen > left.bv_len ) {
3179 match = strncasecmp( sub->sa_final->bv_val,
3180 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3181 sub->sa_final->bv_len );
3187 left.bv_len -= sub->sa_final->bv_len;
3188 inlen -= sub->sa_final->bv_len;
3192 for(i=0; sub->sa_any[i]; i++) {
3197 if( inlen > left.bv_len ) {
3198 /* not enough length */
3203 if( sub->sa_any[i]->bv_len == 0 ) {
3207 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3214 idx = p - left.bv_val;
3215 assert( idx < left.bv_len );
3217 if( idx >= left.bv_len ) {
3218 /* this shouldn't happen */
3225 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3226 /* not enough left */
3231 match = strncasecmp( left.bv_val,
3232 sub->sa_any[i]->bv_val,
3233 sub->sa_any[i]->bv_len );
3242 left.bv_val += sub->sa_any[i]->bv_len;
3243 left.bv_len -= sub->sa_any[i]->bv_len;
3244 inlen -= sub->sa_any[i]->bv_len;
3250 return LDAP_SUCCESS;
3253 /* Index generation function */
3254 int caseIgnoreIA5Indexer(
3259 struct berval *prefix,
3260 struct berval **values,
3261 struct berval ***keysp )
3265 struct berval **keys;
3266 HASH_CONTEXT HASHcontext;
3267 unsigned char HASHdigest[HASH_BYTES];
3268 struct berval digest;
3269 digest.bv_val = HASHdigest;
3270 digest.bv_len = sizeof(HASHdigest);
3272 /* we should have at least one value at this point */
3273 assert( values != NULL && values[0] != NULL );
3275 for( i=0; values[i] != NULL; i++ ) {
3276 /* just count them */
3279 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3281 slen = strlen( syntax->ssyn_oid );
3282 mlen = strlen( mr->smr_oid );
3284 for( i=0; values[i] != NULL; i++ ) {
3285 struct berval *value = ber_bvdup( values[i] );
3286 ldap_pvt_str2upper( value->bv_val );
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 ber_bvfree( value );
3303 keys[i] = ber_bvdup( &digest );
3308 return LDAP_SUCCESS;
3311 /* Index generation function */
3312 int caseIgnoreIA5Filter(
3317 struct berval *prefix,
3319 struct berval ***keysp )
3322 struct berval **keys;
3323 HASH_CONTEXT HASHcontext;
3324 unsigned char HASHdigest[HASH_BYTES];
3325 struct berval *value;
3326 struct berval digest;
3327 digest.bv_val = HASHdigest;
3328 digest.bv_len = sizeof(HASHdigest);
3330 slen = strlen( syntax->ssyn_oid );
3331 mlen = strlen( mr->smr_oid );
3333 value = ber_bvdup( (struct berval *) assertValue );
3334 ldap_pvt_str2upper( value->bv_val );
3336 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3338 HASH_Init( &HASHcontext );
3339 if( prefix != NULL && prefix->bv_len > 0 ) {
3340 HASH_Update( &HASHcontext,
3341 prefix->bv_val, prefix->bv_len );
3343 HASH_Update( &HASHcontext,
3344 syntax->ssyn_oid, slen );
3345 HASH_Update( &HASHcontext,
3346 mr->smr_oid, mlen );
3347 HASH_Update( &HASHcontext,
3348 value->bv_val, value->bv_len );
3349 HASH_Final( HASHdigest, &HASHcontext );
3351 keys[0] = ber_bvdup( &digest );
3354 ber_bvfree( value );
3358 return LDAP_SUCCESS;
3361 /* Substrings Index generation function */
3362 int caseIgnoreIA5SubstringsIndexer(
3367 struct berval *prefix,
3368 struct berval **values,
3369 struct berval ***keysp )
3373 struct berval **keys;
3374 HASH_CONTEXT HASHcontext;
3375 unsigned char HASHdigest[HASH_BYTES];
3376 struct berval digest;
3377 digest.bv_val = HASHdigest;
3378 digest.bv_len = sizeof(HASHdigest);
3380 /* we should have at least one value at this point */
3381 assert( values != NULL && values[0] != NULL );
3384 for( i=0; values[i] != NULL; i++ ) {
3385 /* count number of indices to generate */
3386 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3390 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3391 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3392 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3393 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3395 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3399 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3400 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3401 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3405 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3406 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3407 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3408 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3410 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3416 /* no keys to generate */
3418 return LDAP_SUCCESS;
3421 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3423 slen = strlen( syntax->ssyn_oid );
3424 mlen = strlen( mr->smr_oid );
3427 for( i=0; values[i] != NULL; i++ ) {
3429 struct berval *value;
3431 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3433 value = ber_bvdup( values[i] );
3434 ldap_pvt_str2upper( value->bv_val );
3436 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3437 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3439 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3440 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3442 for( j=0; j<max; j++ ) {
3443 HASH_Init( &HASHcontext );
3444 if( prefix != NULL && prefix->bv_len > 0 ) {
3445 HASH_Update( &HASHcontext,
3446 prefix->bv_val, prefix->bv_len );
3449 HASH_Update( &HASHcontext,
3450 &pre, sizeof( pre ) );
3451 HASH_Update( &HASHcontext,
3452 syntax->ssyn_oid, slen );
3453 HASH_Update( &HASHcontext,
3454 mr->smr_oid, mlen );
3455 HASH_Update( &HASHcontext,
3457 SLAP_INDEX_SUBSTR_MAXLEN );
3458 HASH_Final( HASHdigest, &HASHcontext );
3460 keys[nkeys++] = ber_bvdup( &digest );
3464 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3465 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3467 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3470 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3471 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3472 HASH_Init( &HASHcontext );
3473 if( prefix != NULL && prefix->bv_len > 0 ) {
3474 HASH_Update( &HASHcontext,
3475 prefix->bv_val, prefix->bv_len );
3477 HASH_Update( &HASHcontext,
3478 &pre, sizeof( pre ) );
3479 HASH_Update( &HASHcontext,
3480 syntax->ssyn_oid, slen );
3481 HASH_Update( &HASHcontext,
3482 mr->smr_oid, mlen );
3483 HASH_Update( &HASHcontext,
3485 HASH_Final( HASHdigest, &HASHcontext );
3487 keys[nkeys++] = ber_bvdup( &digest );
3490 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3491 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3492 HASH_Init( &HASHcontext );
3493 if( prefix != NULL && prefix->bv_len > 0 ) {
3494 HASH_Update( &HASHcontext,
3495 prefix->bv_val, prefix->bv_len );
3497 HASH_Update( &HASHcontext,
3498 &pre, sizeof( pre ) );
3499 HASH_Update( &HASHcontext,
3500 syntax->ssyn_oid, slen );
3501 HASH_Update( &HASHcontext,
3502 mr->smr_oid, mlen );
3503 HASH_Update( &HASHcontext,
3504 &value->bv_val[value->bv_len-j], j );
3505 HASH_Final( HASHdigest, &HASHcontext );
3507 keys[nkeys++] = ber_bvdup( &digest );
3512 ber_bvfree( value );
3523 return LDAP_SUCCESS;
3526 int caseIgnoreIA5SubstringsFilter(
3531 struct berval *prefix,
3533 struct berval ***keysp )
3535 SubstringsAssertion *sa = assertValue;
3537 ber_len_t nkeys = 0;
3538 size_t slen, mlen, klen;
3539 struct berval **keys;
3540 HASH_CONTEXT HASHcontext;
3541 unsigned char HASHdigest[HASH_BYTES];
3542 struct berval *value;
3543 struct berval digest;
3545 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3546 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3551 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3553 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3554 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3555 /* don't bother accounting for stepping */
3556 nkeys += sa->sa_any[i]->bv_len -
3557 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3562 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3563 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3570 return LDAP_SUCCESS;
3573 digest.bv_val = HASHdigest;
3574 digest.bv_len = sizeof(HASHdigest);
3576 slen = strlen( syntax->ssyn_oid );
3577 mlen = strlen( mr->smr_oid );
3579 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3582 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3583 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3585 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3586 value = ber_bvdup( sa->sa_initial );
3587 ldap_pvt_str2upper( value->bv_val );
3589 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3590 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
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, klen );
3605 HASH_Final( HASHdigest, &HASHcontext );
3607 ber_bvfree( value );
3608 keys[nkeys++] = ber_bvdup( &digest );
3611 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3613 pre = SLAP_INDEX_SUBSTR_PREFIX;
3614 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3616 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3617 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3621 value = ber_bvdup( sa->sa_any[i] );
3622 ldap_pvt_str2upper( value->bv_val );
3625 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3626 j += SLAP_INDEX_SUBSTR_STEP )
3628 HASH_Init( &HASHcontext );
3629 if( prefix != NULL && prefix->bv_len > 0 ) {
3630 HASH_Update( &HASHcontext,
3631 prefix->bv_val, prefix->bv_len );
3633 HASH_Update( &HASHcontext,
3634 &pre, sizeof( pre ) );
3635 HASH_Update( &HASHcontext,
3636 syntax->ssyn_oid, slen );
3637 HASH_Update( &HASHcontext,
3638 mr->smr_oid, mlen );
3639 HASH_Update( &HASHcontext,
3640 &value->bv_val[j], klen );
3641 HASH_Final( HASHdigest, &HASHcontext );
3643 keys[nkeys++] = ber_bvdup( &digest );
3646 ber_bvfree( value );
3650 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3651 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3653 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3654 value = ber_bvdup( sa->sa_final );
3655 ldap_pvt_str2upper( value->bv_val );
3657 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3658 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3660 HASH_Init( &HASHcontext );
3661 if( prefix != NULL && prefix->bv_len > 0 ) {
3662 HASH_Update( &HASHcontext,
3663 prefix->bv_val, prefix->bv_len );
3665 HASH_Update( &HASHcontext,
3666 &pre, sizeof( pre ) );
3667 HASH_Update( &HASHcontext,
3668 syntax->ssyn_oid, slen );
3669 HASH_Update( &HASHcontext,
3670 mr->smr_oid, mlen );
3671 HASH_Update( &HASHcontext,
3672 &value->bv_val[value->bv_len-klen], klen );
3673 HASH_Final( HASHdigest, &HASHcontext );
3675 ber_bvfree( value );
3676 keys[nkeys++] = ber_bvdup( &digest );
3687 return LDAP_SUCCESS;
3691 numericStringValidate(
3697 for(i=0; i < in->bv_len; i++) {
3698 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3699 return LDAP_INVALID_SYNTAX;
3703 return LDAP_SUCCESS;
3707 numericStringNormalize(
3710 struct berval **normalized )
3712 /* removal all spaces */
3713 struct berval *newval;
3716 newval = ch_malloc( sizeof( struct berval ) );
3717 newval->bv_val = ch_malloc( val->bv_len + 1 );
3723 if ( ASCII_SPACE( *p ) ) {
3724 /* Ignore whitespace */
3731 assert( newval->bv_val <= p );
3734 /* null terminate */
3737 newval->bv_len = q - newval->bv_val;
3738 *normalized = newval;
3740 return LDAP_SUCCESS;
3744 objectIdentifierFirstComponentMatch(
3749 struct berval *value,
3750 void *assertedValue )
3752 int rc = LDAP_SUCCESS;
3754 struct berval *asserted = (struct berval *) assertedValue;
3758 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3759 return LDAP_INVALID_SYNTAX;
3762 /* trim leading white space */
3763 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3767 /* grab next word */
3768 oid.bv_val = &value->bv_val[i];
3769 oid.bv_len = value->bv_len - i;
3770 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3775 /* insert attributeTypes, objectclass check here */
3776 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3777 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3780 char *stored = ch_malloc( oid.bv_len + 1 );
3781 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3782 stored[oid.bv_len] = '\0';
3784 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3785 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3786 MatchingRule *stored_mr = mr_find( stored );
3788 if( asserted_mr == NULL ) {
3789 rc = SLAPD_COMPARE_UNDEFINED;
3791 match = asserted_mr != stored_mr;
3794 } else if ( !strcmp( syntax->ssyn_oid,
3795 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3797 AttributeType *asserted_at = at_find( asserted->bv_val );
3798 AttributeType *stored_at = at_find( stored );
3800 if( asserted_at == NULL ) {
3801 rc = SLAPD_COMPARE_UNDEFINED;
3803 match = asserted_at != stored_at;
3806 } else if ( !strcmp( syntax->ssyn_oid,
3807 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3809 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3810 ObjectClass *stored_oc = oc_find( stored );
3812 if( asserted_oc == NULL ) {
3813 rc = SLAPD_COMPARE_UNDEFINED;
3815 match = asserted_oc != stored_oc;
3823 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3824 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3825 match, value->bv_val, asserted->bv_val ));
3827 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3828 "%d\n\t\"%s\"\n\t\"%s\"\n",
3829 match, value->bv_val, asserted->bv_val );
3833 if( rc == LDAP_SUCCESS ) *matchp = match;
3838 check_time_syntax (struct berval *val,
3842 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3843 static int mdays[2][12] = {
3844 /* non-leap years */
3845 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3847 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3850 int part, c, tzoffset, leapyear = 0 ;
3852 if( val->bv_len == 0 ) {
3853 return LDAP_INVALID_SYNTAX;
3856 p = (char *)val->bv_val;
3857 e = p + val->bv_len;
3859 /* Ignore initial whitespace */
3860 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3864 if (e - p < 13 - (2 * start)) {
3865 return LDAP_INVALID_SYNTAX;
3868 for (part = 0; part < 9; part++) {
3872 for (part = start; part < 7; part++) {
3874 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3881 return LDAP_INVALID_SYNTAX;
3883 if (c < 0 || c > 9) {
3884 return LDAP_INVALID_SYNTAX;
3890 return LDAP_INVALID_SYNTAX;
3892 if (c < 0 || c > 9) {
3893 return LDAP_INVALID_SYNTAX;
3898 if (part == 2 || part == 3) {
3901 if (parts[part] < 0) {
3902 return LDAP_INVALID_SYNTAX;
3904 if (parts[part] > ceiling[part]) {
3905 return LDAP_INVALID_SYNTAX;
3909 /* leapyear check for the Gregorian calendar (year>1581) */
3910 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3911 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3916 if (parts[3] > mdays[leapyear][parts[2]]) {
3917 return LDAP_INVALID_SYNTAX;
3922 tzoffset = 0; /* UTC */
3923 } else if (c != '+' && c != '-') {
3924 return LDAP_INVALID_SYNTAX;
3928 } else /* c == '+' */ {
3933 return LDAP_INVALID_SYNTAX;
3936 for (part = 7; part < 9; part++) {
3938 if (c < 0 || c > 9) {
3939 return LDAP_INVALID_SYNTAX;
3944 if (c < 0 || c > 9) {
3945 return LDAP_INVALID_SYNTAX;
3949 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3950 return LDAP_INVALID_SYNTAX;
3955 /* Ignore trailing whitespace */
3956 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3960 return LDAP_INVALID_SYNTAX;
3963 switch ( tzoffset ) {
3964 case -1: /* negativ offset to UTC, ie west of Greenwich */
3965 parts[4] += parts[7];
3966 parts[5] += parts[8];
3967 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3971 c = mdays[leapyear][parts[2]];
3973 if (parts[part] > c) {
3974 parts[part] -= c + 1;
3979 case 1: /* positive offset to UTC, ie east of Greenwich */
3980 parts[4] -= parts[7];
3981 parts[5] -= parts[8];
3982 for (part = 6; --part > 0; ) {
3986 /* first arg to % needs to be non negativ */
3987 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3989 if (parts[part] < 0) {
3990 parts[part] += c + 1;
3995 case 0: /* already UTC */
3999 return LDAP_SUCCESS;
4006 struct berval **normalized )
4011 rc = check_time_syntax(val, 1, parts);
4012 if (rc != LDAP_SUCCESS) {
4017 out = ch_malloc( sizeof(struct berval) );
4019 return LBER_ERROR_MEMORY;
4022 out->bv_val = ch_malloc( 14 );
4023 if ( out->bv_val == NULL ) {
4025 return LBER_ERROR_MEMORY;
4028 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
4029 parts[1], parts[2] + 1, parts[3] + 1,
4030 parts[4], parts[5], parts[6] );
4034 return LDAP_SUCCESS;
4044 return check_time_syntax(in, 1, parts);
4048 generalizedTimeValidate(
4054 return check_time_syntax(in, 0, parts);
4058 generalizedTimeNormalize(
4061 struct berval **normalized )
4066 rc = check_time_syntax(val, 0, parts);
4067 if (rc != LDAP_SUCCESS) {
4072 out = ch_malloc( sizeof(struct berval) );
4074 return LBER_ERROR_MEMORY;
4077 out->bv_val = ch_malloc( 16 );
4078 if ( out->bv_val == NULL ) {
4080 return LBER_ERROR_MEMORY;
4083 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4084 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4085 parts[4], parts[5], parts[6] );
4089 return LDAP_SUCCESS;
4093 nisNetgroupTripleValidate(
4095 struct berval *val )
4100 if ( val->bv_len == 0 ) {
4101 return LDAP_INVALID_SYNTAX;
4104 p = (char *)val->bv_val;
4105 e = p + val->bv_len;
4108 /* syntax does not allow leading white space */
4109 /* Ignore initial whitespace */
4110 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4115 if ( *p != '(' /*')'*/ ) {
4116 return LDAP_INVALID_SYNTAX;
4119 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4123 return LDAP_INVALID_SYNTAX;
4126 } else if ( !ATTR_CHAR( *p ) ) {
4127 return LDAP_INVALID_SYNTAX;
4131 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4132 return LDAP_INVALID_SYNTAX;
4138 /* syntax does not allow trailing white space */
4139 /* Ignore trailing whitespace */
4140 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4146 return LDAP_INVALID_SYNTAX;
4149 return LDAP_SUCCESS;
4153 bootParameterValidate(
4155 struct berval *val )
4159 if ( val->bv_len == 0 ) {
4160 return LDAP_INVALID_SYNTAX;
4163 p = (char *)val->bv_val;
4164 e = p + val->bv_len;
4167 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4168 if ( !ATTR_CHAR( *p ) ) {
4169 return LDAP_INVALID_SYNTAX;
4174 return LDAP_INVALID_SYNTAX;
4178 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4179 if ( !ATTR_CHAR( *p ) ) {
4180 return LDAP_INVALID_SYNTAX;
4185 return LDAP_INVALID_SYNTAX;
4189 for ( p++; p < e; p++ ) {
4190 if ( !ATTR_CHAR( *p ) ) {
4191 return LDAP_INVALID_SYNTAX;
4195 return LDAP_SUCCESS;
4198 struct syntax_defs_rec {
4201 slap_syntax_validate_func *sd_validate;
4202 slap_syntax_transform_func *sd_normalize;
4203 slap_syntax_transform_func *sd_pretty;
4204 #ifdef SLAPD_BINARY_CONVERSION
4205 slap_syntax_transform_func *sd_ber2str;
4206 slap_syntax_transform_func *sd_str2ber;
4210 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4211 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4213 struct syntax_defs_rec syntax_defs[] = {
4214 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4215 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4217 0, NULL, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4219 0, NULL, NULL, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4221 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4223 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4225 0, bitStringValidate, NULL, NULL },
4226 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4227 0, booleanValidate, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4229 X_BINARY X_NOT_H_R ")",
4230 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4232 X_BINARY X_NOT_H_R ")",
4233 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4235 X_BINARY X_NOT_H_R ")",
4236 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4238 0, countryStringValidate, IA5StringNormalize, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4240 0, dnValidate, dnNormalize, dnPretty},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4242 0, NULL, NULL, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4244 0, NULL, NULL, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4246 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4248 0, NULL, NULL, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4250 0, NULL, NULL, NULL},
4251 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4252 0, NULL, NULL, NULL},
4253 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4254 0, NULL, NULL, NULL},
4255 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4256 0, NULL, NULL, NULL},
4257 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4258 0, printablesStringValidate, IA5StringNormalize, NULL},
4259 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4260 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4261 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4262 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4263 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4264 0, NULL, NULL, NULL},
4265 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4266 0, IA5StringValidate, IA5StringNormalize, NULL},
4267 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4268 0, integerValidate, integerNormalize, integerPretty},
4269 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4270 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4271 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4272 0, NULL, NULL, NULL},
4273 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4274 0, NULL, NULL, NULL},
4275 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4276 0, NULL, NULL, NULL},
4277 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4278 0, NULL, NULL, NULL},
4279 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4280 0, NULL, NULL, NULL},
4281 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4282 0, nameUIDValidate, nameUIDNormalize, NULL},
4283 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4284 0, NULL, NULL, NULL},
4285 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4286 0, numericStringValidate, numericStringNormalize, NULL},
4287 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4288 0, NULL, NULL, NULL},
4289 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4290 0, oidValidate, NULL, NULL},
4291 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4292 0, IA5StringValidate, IA5StringNormalize, NULL},
4293 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4294 0, blobValidate, NULL, NULL},
4295 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4296 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4297 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4298 0, NULL, NULL, NULL},
4299 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4300 0, NULL, NULL, NULL},
4301 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4302 0, printableStringValidate, IA5StringNormalize, NULL},
4303 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4304 X_BINARY X_NOT_H_R ")",
4305 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4306 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4307 0, printableStringValidate, IA5StringNormalize, NULL},
4308 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4309 0, NULL, NULL, NULL},
4310 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4311 0, printableStringValidate, IA5StringNormalize, NULL},
4312 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4313 0, utcTimeValidate, utcTimeNormalize, NULL},
4314 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4315 0, NULL, NULL, NULL},
4316 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4317 0, NULL, NULL, NULL},
4318 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4319 0, NULL, NULL, NULL},
4320 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4321 0, NULL, NULL, NULL},
4322 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4323 0, NULL, NULL, NULL},
4325 /* RFC 2307 NIS Syntaxes */
4326 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4327 0, nisNetgroupTripleValidate, NULL, NULL},
4328 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4329 0, bootParameterValidate, NULL, NULL},
4331 /* OpenLDAP Experimental Syntaxes */
4332 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4333 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4335 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4336 0, NULL, NULL, NULL},
4338 /* OpenLDAP Void Syntax */
4339 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4340 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4341 {NULL, 0, NULL, NULL, NULL}
4344 struct mrule_defs_rec {
4346 slap_mask_t mrd_usage;
4347 slap_mr_convert_func * mrd_convert;
4348 slap_mr_normalize_func * mrd_normalize;
4349 slap_mr_match_func * mrd_match;
4350 slap_mr_indexer_func * mrd_indexer;
4351 slap_mr_filter_func * mrd_filter;
4353 char * mrd_associated;
4357 * Other matching rules in X.520 that we do not use (yet):
4359 * 2.5.13.9 numericStringOrderingMatch
4360 * 2.5.13.15 integerOrderingMatch
4361 * 2.5.13.18 octetStringOrderingMatch
4362 * 2.5.13.19 octetStringSubstringsMatch
4363 * 2.5.13.25 uTCTimeMatch
4364 * 2.5.13.26 uTCTimeOrderingMatch
4365 * 2.5.13.31 directoryStringFirstComponentMatch
4366 * 2.5.13.32 wordMatch
4367 * 2.5.13.33 keywordMatch
4368 * 2.5.13.34 certificateExactMatch
4369 * 2.5.13.35 certificateMatch
4370 * 2.5.13.36 certificatePairExactMatch
4371 * 2.5.13.37 certificatePairMatch
4372 * 2.5.13.38 certificateListExactMatch
4373 * 2.5.13.39 certificateListMatch
4374 * 2.5.13.40 algorithmIdentifierMatch
4375 * 2.5.13.41 storedPrefixMatch
4376 * 2.5.13.42 attributeCertificateMatch
4377 * 2.5.13.43 readerAndKeyIDMatch
4378 * 2.5.13.44 attributeIntegrityMatch
4381 struct mrule_defs_rec mrule_defs[] = {
4383 * EQUALITY matching rules must be listed after associated APPROX
4384 * matching rules. So, we list all APPROX matching rules first.
4386 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4387 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4388 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4390 directoryStringApproxMatch,
4391 directoryStringApproxIndexer,
4392 directoryStringApproxFilter,
4395 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4396 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4397 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4399 IA5StringApproxMatch,
4400 IA5StringApproxIndexer,
4401 IA5StringApproxFilter,
4405 * Other matching rules
4408 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4409 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4410 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4412 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4415 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4416 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4417 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4419 dnMatch, dnIndexer, dnFilter,
4422 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4423 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4424 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4426 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4427 directoryStringApproxMatchOID },
4429 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4430 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4433 caseIgnoreOrderingMatch, NULL, NULL,
4436 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4437 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4438 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4440 caseIgnoreSubstringsMatch,
4441 caseIgnoreSubstringsIndexer,
4442 caseIgnoreSubstringsFilter,
4445 {"( 2.5.13.5 NAME 'caseExactMatch' "
4446 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4447 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4449 caseExactMatch, caseExactIndexer, caseExactFilter,
4450 directoryStringApproxMatchOID },
4452 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4453 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4456 caseExactOrderingMatch, NULL, NULL,
4459 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4460 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4461 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4463 caseExactSubstringsMatch,
4464 caseExactSubstringsIndexer,
4465 caseExactSubstringsFilter,
4468 {"( 2.5.13.8 NAME 'numericStringMatch' "
4469 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4470 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4473 caseIgnoreIA5Indexer,
4474 caseIgnoreIA5Filter,
4477 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4478 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4479 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4481 caseIgnoreIA5SubstringsMatch,
4482 caseIgnoreIA5SubstringsIndexer,
4483 caseIgnoreIA5SubstringsFilter,
4486 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4487 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4488 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4490 caseIgnoreListMatch, NULL, NULL,
4493 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4494 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4495 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4497 caseIgnoreListSubstringsMatch, NULL, NULL,
4500 {"( 2.5.13.13 NAME 'booleanMatch' "
4501 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4502 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4504 booleanMatch, NULL, NULL,
4507 {"( 2.5.13.14 NAME 'integerMatch' "
4508 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4509 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4511 integerMatch, integerIndexer, integerFilter,
4514 {"( 2.5.13.16 NAME 'bitStringMatch' "
4515 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4516 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4518 bitStringMatch, NULL, NULL,
4521 {"( 2.5.13.17 NAME 'octetStringMatch' "
4522 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4523 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4525 octetStringMatch, octetStringIndexer, octetStringFilter,
4528 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4529 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4530 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4532 telephoneNumberMatch,
4533 telephoneNumberIndexer,
4534 telephoneNumberFilter,
4537 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4538 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4539 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4541 telephoneNumberSubstringsMatch,
4542 telephoneNumberSubstringsIndexer,
4543 telephoneNumberSubstringsFilter,
4546 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4547 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4548 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4553 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4554 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4555 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4557 uniqueMemberMatch, NULL, NULL,
4560 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4561 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4562 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4564 protocolInformationMatch, NULL, NULL,
4567 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4568 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4569 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4571 generalizedTimeMatch, NULL, NULL,
4574 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4575 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4578 generalizedTimeOrderingMatch, NULL, NULL,
4581 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4582 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4583 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4585 integerFirstComponentMatch, NULL, NULL,
4588 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4589 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4590 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4592 objectIdentifierFirstComponentMatch, NULL, NULL,
4595 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4596 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4597 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4599 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4600 IA5StringApproxMatchOID },
4602 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4603 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4604 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4606 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4607 IA5StringApproxMatchOID },
4609 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4610 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4613 caseIgnoreIA5SubstringsMatch,
4614 caseIgnoreIA5SubstringsIndexer,
4615 caseIgnoreIA5SubstringsFilter,
4618 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4619 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4622 caseExactIA5SubstringsMatch,
4623 caseExactIA5SubstringsIndexer,
4624 caseExactIA5SubstringsFilter,
4627 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4628 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4631 authPasswordMatch, NULL, NULL,
4634 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4635 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4638 OpenLDAPaciMatch, NULL, NULL,
4641 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4650 /* we should only be called once (from main) */
4651 assert( schema_init_done == 0 );
4653 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4654 res = register_syntax( syntax_defs[i].sd_desc,
4655 syntax_defs[i].sd_flags,
4656 syntax_defs[i].sd_validate,
4657 syntax_defs[i].sd_normalize,
4658 syntax_defs[i].sd_pretty
4659 #ifdef SLAPD_BINARY_CONVERSION
4661 syntax_defs[i].sd_ber2str,
4662 syntax_defs[i].sd_str2ber
4667 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4668 syntax_defs[i].sd_desc );
4673 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4674 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4676 "schema_init: Ingoring unusable matching rule %s\n",
4677 mrule_defs[i].mrd_desc );
4681 res = register_matching_rule(
4682 mrule_defs[i].mrd_desc,
4683 mrule_defs[i].mrd_usage,
4684 mrule_defs[i].mrd_convert,
4685 mrule_defs[i].mrd_normalize,
4686 mrule_defs[i].mrd_match,
4687 mrule_defs[i].mrd_indexer,
4688 mrule_defs[i].mrd_filter,
4689 mrule_defs[i].mrd_associated );
4693 "schema_init: Error registering matching rule %s\n",
4694 mrule_defs[i].mrd_desc );
4698 schema_init_done = 1;
4699 return LDAP_SUCCESS;