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, UTF8_NOCASEFOLD ) );
1227 value = (struct berval *) assertValue;
1230 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1232 HASH_Init( &HASHcontext );
1233 if( prefix != NULL && prefix->bv_len > 0 ) {
1234 HASH_Update( &HASHcontext,
1235 prefix->bv_val, prefix->bv_len );
1237 HASH_Update( &HASHcontext,
1238 syntax->ssyn_oid, slen );
1239 HASH_Update( &HASHcontext,
1240 mr->smr_oid, mlen );
1241 HASH_Update( &HASHcontext,
1242 value->bv_val, value->bv_len );
1243 HASH_Final( HASHdigest, &HASHcontext );
1245 keys[0] = ber_bvdup( &digest );
1249 ber_bvfree( value );
1253 return LDAP_SUCCESS;
1256 /* Substrings Index generation function */
1257 int caseExactSubstringsIndexer(
1262 struct berval *prefix,
1263 struct berval **values,
1264 struct berval ***keysp )
1268 struct berval **keys;
1269 HASH_CONTEXT HASHcontext;
1270 unsigned char HASHdigest[HASH_BYTES];
1271 struct berval digest;
1272 digest.bv_val = HASHdigest;
1273 digest.bv_len = sizeof(HASHdigest);
1275 /* we should have at least one value at this point */
1276 assert( values != NULL && values[0] != NULL );
1279 for( i=0; values[i] != NULL; i++ ) {
1280 /* count number of indices to generate */
1281 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1285 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1286 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1287 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1288 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1290 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1294 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1295 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1296 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1300 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1301 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1302 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1303 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1305 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1311 /* no keys to generate */
1313 return LDAP_SUCCESS;
1316 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1318 slen = strlen( syntax->ssyn_oid );
1319 mlen = strlen( mr->smr_oid );
1322 for( i=0; values[i] != NULL; i++ ) {
1324 struct berval *value;
1326 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1329 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
1334 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1335 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1337 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1338 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1340 for( j=0; j<max; j++ ) {
1341 HASH_Init( &HASHcontext );
1342 if( prefix != NULL && prefix->bv_len > 0 ) {
1343 HASH_Update( &HASHcontext,
1344 prefix->bv_val, prefix->bv_len );
1347 HASH_Update( &HASHcontext,
1348 &pre, sizeof( pre ) );
1349 HASH_Update( &HASHcontext,
1350 syntax->ssyn_oid, slen );
1351 HASH_Update( &HASHcontext,
1352 mr->smr_oid, mlen );
1353 HASH_Update( &HASHcontext,
1355 SLAP_INDEX_SUBSTR_MAXLEN );
1356 HASH_Final( HASHdigest, &HASHcontext );
1358 keys[nkeys++] = ber_bvdup( &digest );
1362 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1363 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1365 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1368 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1369 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1370 HASH_Init( &HASHcontext );
1371 if( prefix != NULL && prefix->bv_len > 0 ) {
1372 HASH_Update( &HASHcontext,
1373 prefix->bv_val, prefix->bv_len );
1375 HASH_Update( &HASHcontext,
1376 &pre, sizeof( pre ) );
1377 HASH_Update( &HASHcontext,
1378 syntax->ssyn_oid, slen );
1379 HASH_Update( &HASHcontext,
1380 mr->smr_oid, mlen );
1381 HASH_Update( &HASHcontext,
1383 HASH_Final( HASHdigest, &HASHcontext );
1385 keys[nkeys++] = ber_bvdup( &digest );
1388 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1389 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1390 HASH_Init( &HASHcontext );
1391 if( prefix != NULL && prefix->bv_len > 0 ) {
1392 HASH_Update( &HASHcontext,
1393 prefix->bv_val, prefix->bv_len );
1395 HASH_Update( &HASHcontext,
1396 &pre, sizeof( pre ) );
1397 HASH_Update( &HASHcontext,
1398 syntax->ssyn_oid, slen );
1399 HASH_Update( &HASHcontext,
1400 mr->smr_oid, mlen );
1401 HASH_Update( &HASHcontext,
1402 &value->bv_val[value->bv_len-j], j );
1403 HASH_Final( HASHdigest, &HASHcontext );
1405 keys[nkeys++] = ber_bvdup( &digest );
1411 ber_bvfree( value );
1424 return LDAP_SUCCESS;
1427 int caseExactSubstringsFilter(
1432 struct berval *prefix,
1434 struct berval ***keysp )
1436 SubstringsAssertion *sa = assertValue;
1438 ber_len_t nkeys = 0;
1439 size_t slen, mlen, klen;
1440 struct berval **keys;
1441 HASH_CONTEXT HASHcontext;
1442 unsigned char HASHdigest[HASH_BYTES];
1443 struct berval *value;
1444 struct berval digest;
1446 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1447 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1452 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1454 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1455 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1456 /* don't bother accounting for stepping */
1457 nkeys += sa->sa_any[i]->bv_len -
1458 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1463 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1464 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1471 return LDAP_SUCCESS;
1474 digest.bv_val = HASHdigest;
1475 digest.bv_len = sizeof(HASHdigest);
1477 slen = strlen( syntax->ssyn_oid );
1478 mlen = strlen( mr->smr_oid );
1480 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1483 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1484 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1486 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1488 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_NOCASEFOLD ) );
1490 value = sa->sa_initial;
1493 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1494 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1496 HASH_Init( &HASHcontext );
1497 if( prefix != NULL && prefix->bv_len > 0 ) {
1498 HASH_Update( &HASHcontext,
1499 prefix->bv_val, prefix->bv_len );
1501 HASH_Update( &HASHcontext,
1502 &pre, sizeof( pre ) );
1503 HASH_Update( &HASHcontext,
1504 syntax->ssyn_oid, slen );
1505 HASH_Update( &HASHcontext,
1506 mr->smr_oid, mlen );
1507 HASH_Update( &HASHcontext,
1508 value->bv_val, klen );
1509 HASH_Final( HASHdigest, &HASHcontext );
1512 ber_bvfree( value );
1514 keys[nkeys++] = ber_bvdup( &digest );
1517 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1519 pre = SLAP_INDEX_SUBSTR_PREFIX;
1520 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1522 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1523 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1528 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_NOCASEFOLD ) );
1530 value = sa->sa_any[i];
1534 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1535 j += SLAP_INDEX_SUBSTR_STEP )
1537 HASH_Init( &HASHcontext );
1538 if( prefix != NULL && prefix->bv_len > 0 ) {
1539 HASH_Update( &HASHcontext,
1540 prefix->bv_val, prefix->bv_len );
1542 HASH_Update( &HASHcontext,
1543 &pre, sizeof( pre ) );
1544 HASH_Update( &HASHcontext,
1545 syntax->ssyn_oid, slen );
1546 HASH_Update( &HASHcontext,
1547 mr->smr_oid, mlen );
1548 HASH_Update( &HASHcontext,
1549 &value->bv_val[j], klen );
1550 HASH_Final( HASHdigest, &HASHcontext );
1552 keys[nkeys++] = ber_bvdup( &digest );
1556 ber_bvfree( value );
1561 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1562 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1564 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1566 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_NOCASEFOLD ) );
1568 value = sa->sa_final;
1571 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1572 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1574 HASH_Init( &HASHcontext );
1575 if( prefix != NULL && prefix->bv_len > 0 ) {
1576 HASH_Update( &HASHcontext,
1577 prefix->bv_val, prefix->bv_len );
1579 HASH_Update( &HASHcontext,
1580 &pre, sizeof( pre ) );
1581 HASH_Update( &HASHcontext,
1582 syntax->ssyn_oid, slen );
1583 HASH_Update( &HASHcontext,
1584 mr->smr_oid, mlen );
1585 HASH_Update( &HASHcontext,
1586 &value->bv_val[value->bv_len-klen], klen );
1587 HASH_Final( HASHdigest, &HASHcontext );
1590 ber_bvfree( value );
1592 keys[nkeys++] = ber_bvdup( &digest );
1603 return LDAP_SUCCESS;
1612 struct berval *value,
1613 void *assertedValue )
1616 *matchp = UTF8normcmp( value->bv_val,
1617 ((struct berval *) assertedValue)->bv_val,
1620 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1623 match = strncasecmp( value->bv_val,
1624 ((struct berval *) assertedValue)->bv_val,
1630 return LDAP_SUCCESS;
1634 caseIgnoreSubstringsMatch(
1639 struct berval *value,
1640 void *assertedValue )
1643 SubstringsAssertion *sub = assertedValue;
1644 struct berval left = *value;
1648 /* Add up asserted input length */
1649 if( sub->sa_initial ) {
1650 inlen += sub->sa_initial->bv_len;
1653 for(i=0; sub->sa_any[i] != NULL; i++) {
1654 inlen += sub->sa_any[i]->bv_len;
1657 if( sub->sa_final ) {
1658 inlen += sub->sa_final->bv_len;
1661 if( sub->sa_initial ) {
1662 if( inlen > left.bv_len ) {
1668 match = UTF8oncasecmp( sub->sa_initial, &left,
1669 sub->sa_initial->bv_len, 0 );
1671 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1672 sub->sa_initial->bv_len );
1679 left.bv_val += sub->sa_initial->bv_len;
1680 left.bv_len -= sub->sa_initial->bv_len;
1681 inlen -= sub->sa_initial->bv_len;
1684 if( sub->sa_final ) {
1685 if( inlen > left.bv_len ) {
1691 match = UTF8oncasecmp( sub->sa_final, &left,
1692 sub->sa_final->bv_len,
1693 left.bv_len - sub->sa_final->bv_len );
1695 match = strncasecmp( sub->sa_final->bv_val,
1696 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1697 sub->sa_final->bv_len );
1704 left.bv_len -= sub->sa_final->bv_len;
1705 inlen -= sub->sa_final->bv_len;
1709 for(i=0; sub->sa_any[i]; i++) {
1714 if( inlen > left.bv_len ) {
1715 /* not enough length */
1720 if( sub->sa_any[i]->bv_len == 0 ) {
1725 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1727 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1735 idx = p - left.bv_val;
1736 assert( idx < left.bv_len );
1738 if( idx >= left.bv_len ) {
1739 /* this shouldn't happen */
1746 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1747 /* not enough left */
1753 match = UTF8oncasecmp( &left, sub->sa_any[i],
1754 sub->sa_any[i]->bv_len, 0 );
1757 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1763 match = strncasecmp( left.bv_val,
1764 sub->sa_any[i]->bv_val,
1765 sub->sa_any[i]->bv_len );
1775 left.bv_val += sub->sa_any[i]->bv_len;
1776 left.bv_len -= sub->sa_any[i]->bv_len;
1777 inlen -= sub->sa_any[i]->bv_len;
1783 return LDAP_SUCCESS;
1786 /* Index generation function */
1787 int caseIgnoreIndexer(
1792 struct berval *prefix,
1793 struct berval **values,
1794 struct berval ***keysp )
1798 struct berval **keys;
1799 HASH_CONTEXT HASHcontext;
1800 unsigned char HASHdigest[HASH_BYTES];
1801 struct berval digest;
1802 digest.bv_val = HASHdigest;
1803 digest.bv_len = sizeof(HASHdigest);
1805 /* we should have at least one value at this point */
1806 assert( values != NULL && values[0] != NULL );
1808 for( i=0; values[i] != NULL; i++ ) {
1809 /* just count them */
1812 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1814 slen = strlen( syntax->ssyn_oid );
1815 mlen = strlen( mr->smr_oid );
1817 for( i=0; values[i] != NULL; i++ ) {
1818 struct berval *value;
1820 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1822 value = ber_bvdup( values[i] );
1823 ldap_pvt_str2upper( value->bv_val );
1825 HASH_Init( &HASHcontext );
1826 if( prefix != NULL && prefix->bv_len > 0 ) {
1827 HASH_Update( &HASHcontext,
1828 prefix->bv_val, prefix->bv_len );
1830 HASH_Update( &HASHcontext,
1831 syntax->ssyn_oid, slen );
1832 HASH_Update( &HASHcontext,
1833 mr->smr_oid, mlen );
1834 HASH_Update( &HASHcontext,
1835 value->bv_val, value->bv_len );
1836 HASH_Final( HASHdigest, &HASHcontext );
1838 ber_bvfree( value );
1840 keys[i] = ber_bvdup( &digest );
1845 return LDAP_SUCCESS;
1848 /* Index generation function */
1849 int caseIgnoreFilter(
1854 struct berval *prefix,
1856 struct berval ***keysp )
1859 struct berval **keys;
1860 HASH_CONTEXT HASHcontext;
1861 unsigned char HASHdigest[HASH_BYTES];
1862 struct berval *value;
1863 struct berval digest;
1864 digest.bv_val = HASHdigest;
1865 digest.bv_len = sizeof(HASHdigest);
1867 slen = strlen( syntax->ssyn_oid );
1868 mlen = strlen( mr->smr_oid );
1871 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val, UTF8_CASEFOLD ) );
1872 /* This usually happens if filter contains bad UTF8 */
1873 if( value == NULL ) {
1874 keys = ch_malloc( sizeof( struct berval * ) );
1876 return LDAP_SUCCESS;
1879 value = ber_bvdup( (struct berval *) assertValue );
1880 ldap_pvt_str2upper( value->bv_val );
1883 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1885 HASH_Init( &HASHcontext );
1886 if( prefix != NULL && prefix->bv_len > 0 ) {
1887 HASH_Update( &HASHcontext,
1888 prefix->bv_val, prefix->bv_len );
1890 HASH_Update( &HASHcontext,
1891 syntax->ssyn_oid, slen );
1892 HASH_Update( &HASHcontext,
1893 mr->smr_oid, mlen );
1894 HASH_Update( &HASHcontext,
1895 value->bv_val, value->bv_len );
1896 HASH_Final( HASHdigest, &HASHcontext );
1898 keys[0] = ber_bvdup( &digest );
1901 ber_bvfree( value );
1905 return LDAP_SUCCESS;
1908 /* Substrings Index generation function */
1909 int caseIgnoreSubstringsIndexer(
1914 struct berval *prefix,
1915 struct berval **values,
1916 struct berval ***keysp )
1920 struct berval **keys;
1921 HASH_CONTEXT HASHcontext;
1922 unsigned char HASHdigest[HASH_BYTES];
1923 struct berval digest;
1924 digest.bv_val = HASHdigest;
1925 digest.bv_len = sizeof(HASHdigest);
1927 /* we should have at least one value at this point */
1928 assert( values != NULL && values[0] != NULL );
1931 for( i=0; values[i] != NULL; i++ ) {
1932 /* count number of indices to generate */
1933 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1937 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1938 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1939 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1940 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1942 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1946 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1947 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1948 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1952 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1953 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1954 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1955 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1957 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1963 /* no keys to generate */
1965 return LDAP_SUCCESS;
1968 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1970 slen = strlen( syntax->ssyn_oid );
1971 mlen = strlen( mr->smr_oid );
1974 for( i=0; values[i] != NULL; i++ ) {
1976 struct berval *value;
1978 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1981 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1983 value = ber_bvdup( values[i] );
1984 ldap_pvt_str2upper( value->bv_val );
1987 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1988 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1990 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1991 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1993 for( j=0; j<max; j++ ) {
1994 HASH_Init( &HASHcontext );
1995 if( prefix != NULL && prefix->bv_len > 0 ) {
1996 HASH_Update( &HASHcontext,
1997 prefix->bv_val, prefix->bv_len );
2000 HASH_Update( &HASHcontext,
2001 &pre, sizeof( pre ) );
2002 HASH_Update( &HASHcontext,
2003 syntax->ssyn_oid, slen );
2004 HASH_Update( &HASHcontext,
2005 mr->smr_oid, mlen );
2006 HASH_Update( &HASHcontext,
2008 SLAP_INDEX_SUBSTR_MAXLEN );
2009 HASH_Final( HASHdigest, &HASHcontext );
2011 keys[nkeys++] = ber_bvdup( &digest );
2015 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2016 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2018 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2021 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2022 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2023 HASH_Init( &HASHcontext );
2024 if( prefix != NULL && prefix->bv_len > 0 ) {
2025 HASH_Update( &HASHcontext,
2026 prefix->bv_val, prefix->bv_len );
2028 HASH_Update( &HASHcontext,
2029 &pre, sizeof( pre ) );
2030 HASH_Update( &HASHcontext,
2031 syntax->ssyn_oid, slen );
2032 HASH_Update( &HASHcontext,
2033 mr->smr_oid, mlen );
2034 HASH_Update( &HASHcontext,
2036 HASH_Final( HASHdigest, &HASHcontext );
2038 keys[nkeys++] = ber_bvdup( &digest );
2041 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2042 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2043 HASH_Init( &HASHcontext );
2044 if( prefix != NULL && prefix->bv_len > 0 ) {
2045 HASH_Update( &HASHcontext,
2046 prefix->bv_val, prefix->bv_len );
2048 HASH_Update( &HASHcontext,
2049 &pre, sizeof( pre ) );
2050 HASH_Update( &HASHcontext,
2051 syntax->ssyn_oid, slen );
2052 HASH_Update( &HASHcontext,
2053 mr->smr_oid, mlen );
2054 HASH_Update( &HASHcontext,
2055 &value->bv_val[value->bv_len-j], j );
2056 HASH_Final( HASHdigest, &HASHcontext );
2058 keys[nkeys++] = ber_bvdup( &digest );
2063 ber_bvfree( value );
2074 return LDAP_SUCCESS;
2077 int caseIgnoreSubstringsFilter(
2082 struct berval *prefix,
2084 struct berval ***keysp )
2086 SubstringsAssertion *sa = assertValue;
2088 ber_len_t nkeys = 0;
2089 size_t slen, mlen, klen;
2090 struct berval **keys;
2091 HASH_CONTEXT HASHcontext;
2092 unsigned char HASHdigest[HASH_BYTES];
2093 struct berval *value;
2094 struct berval digest;
2096 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2097 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2102 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2104 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2105 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2106 /* don't bother accounting for stepping */
2107 nkeys += sa->sa_any[i]->bv_len -
2108 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2113 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2114 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2121 return LDAP_SUCCESS;
2124 digest.bv_val = HASHdigest;
2125 digest.bv_len = sizeof(HASHdigest);
2127 slen = strlen( syntax->ssyn_oid );
2128 mlen = strlen( mr->smr_oid );
2130 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2133 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2134 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2136 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2138 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_CASEFOLD ) );
2140 value = ber_bvdup( sa->sa_initial );
2141 ldap_pvt_str2upper( value->bv_val );
2144 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2145 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2147 HASH_Init( &HASHcontext );
2148 if( prefix != NULL && prefix->bv_len > 0 ) {
2149 HASH_Update( &HASHcontext,
2150 prefix->bv_val, prefix->bv_len );
2152 HASH_Update( &HASHcontext,
2153 &pre, sizeof( pre ) );
2154 HASH_Update( &HASHcontext,
2155 syntax->ssyn_oid, slen );
2156 HASH_Update( &HASHcontext,
2157 mr->smr_oid, mlen );
2158 HASH_Update( &HASHcontext,
2159 value->bv_val, klen );
2160 HASH_Final( HASHdigest, &HASHcontext );
2162 ber_bvfree( value );
2163 keys[nkeys++] = ber_bvdup( &digest );
2166 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2168 pre = SLAP_INDEX_SUBSTR_PREFIX;
2169 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2171 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2172 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2177 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_CASEFOLD ) );
2179 value = ber_bvdup( sa->sa_any[i] );
2180 ldap_pvt_str2upper( value->bv_val );
2184 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2185 j += SLAP_INDEX_SUBSTR_STEP )
2187 HASH_Init( &HASHcontext );
2188 if( prefix != NULL && prefix->bv_len > 0 ) {
2189 HASH_Update( &HASHcontext,
2190 prefix->bv_val, prefix->bv_len );
2192 HASH_Update( &HASHcontext,
2193 &pre, sizeof( pre ) );
2194 HASH_Update( &HASHcontext,
2195 syntax->ssyn_oid, slen );
2196 HASH_Update( &HASHcontext,
2197 mr->smr_oid, mlen );
2198 HASH_Update( &HASHcontext,
2199 &value->bv_val[j], klen );
2200 HASH_Final( HASHdigest, &HASHcontext );
2202 keys[nkeys++] = ber_bvdup( &digest );
2205 ber_bvfree( value );
2209 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2210 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2212 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2214 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_CASEFOLD ) );
2216 value = ber_bvdup( sa->sa_final );
2217 ldap_pvt_str2upper( value->bv_val );
2220 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2221 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2223 HASH_Init( &HASHcontext );
2224 if( prefix != NULL && prefix->bv_len > 0 ) {
2225 HASH_Update( &HASHcontext,
2226 prefix->bv_val, prefix->bv_len );
2228 HASH_Update( &HASHcontext,
2229 &pre, sizeof( pre ) );
2230 HASH_Update( &HASHcontext,
2231 syntax->ssyn_oid, slen );
2232 HASH_Update( &HASHcontext,
2233 mr->smr_oid, mlen );
2234 HASH_Update( &HASHcontext,
2235 &value->bv_val[value->bv_len-klen], klen );
2236 HASH_Final( HASHdigest, &HASHcontext );
2238 ber_bvfree( value );
2239 keys[nkeys++] = ber_bvdup( &digest );
2250 return LDAP_SUCCESS;
2256 struct berval *val )
2260 if( val->bv_len == 0 ) {
2261 /* disallow empty strings */
2262 return LDAP_INVALID_SYNTAX;
2265 if( OID_LEADCHAR(val->bv_val[0]) ) {
2267 for(i=1; i < val->bv_len; i++) {
2268 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2269 if( dot++ ) return 1;
2270 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2273 return LDAP_INVALID_SYNTAX;
2277 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2279 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2280 for(i=1; i < val->bv_len; i++) {
2281 if( !DESC_CHAR(val->bv_val[i] ) ) {
2282 return LDAP_INVALID_SYNTAX;
2286 return LDAP_SUCCESS;
2289 return LDAP_INVALID_SYNTAX;
2295 struct berval *val )
2299 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2301 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2302 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2303 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2304 return LDAP_INVALID_SYNTAX;
2307 for(i=1; i < val->bv_len; i++) {
2308 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2311 return LDAP_SUCCESS;
2318 struct berval **normalized )
2321 struct berval *newval;
2327 negative = ( *p == '-' );
2328 if( *p == '-' || *p == '+' ) p++;
2330 /* Ignore leading zeros */
2331 while ( *p == '0' ) p++;
2333 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2336 newval->bv_val = ch_strdup("0");
2341 newval->bv_val = ch_malloc( val->bv_len + 1 );
2345 newval->bv_val[newval->bv_len++] = '-';
2348 for( ; *p != '\0'; p++ ) {
2349 newval->bv_val[newval->bv_len++] = *p;
2353 *normalized = newval;
2354 return LDAP_SUCCESS;
2358 countryStringValidate(
2360 struct berval *val )
2362 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2364 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2365 return LDAP_INVALID_SYNTAX;
2367 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2368 return LDAP_INVALID_SYNTAX;
2371 return LDAP_SUCCESS;
2375 printableStringValidate(
2377 struct berval *val )
2381 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2383 for(i=0; i < val->bv_len; i++) {
2384 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2385 return LDAP_INVALID_SYNTAX;
2389 return LDAP_SUCCESS;
2393 printablesStringValidate(
2395 struct berval *val )
2399 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2401 for(i=0; i < val->bv_len; i++) {
2402 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2403 return LDAP_INVALID_SYNTAX;
2407 return LDAP_SUCCESS;
2413 struct berval *val )
2417 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2419 for(i=0; i < val->bv_len; i++) {
2420 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2423 return LDAP_SUCCESS;
2430 struct berval **normalized )
2432 struct berval *newval;
2435 newval = ch_malloc( sizeof( struct berval ) );
2439 /* Ignore initial whitespace */
2440 while ( ASCII_SPACE( *p ) ) {
2446 return LDAP_INVALID_SYNTAX;
2449 newval->bv_val = ch_strdup( p );
2450 p = q = newval->bv_val;
2453 if ( ASCII_SPACE( *p ) ) {
2456 /* Ignore the extra whitespace */
2457 while ( ASCII_SPACE( *p ) ) {
2465 assert( *newval->bv_val );
2466 assert( newval->bv_val < p );
2469 /* cannot start with a space */
2470 assert( !ASCII_SPACE(*newval->bv_val) );
2473 * If the string ended in space, backup the pointer one
2474 * position. One is enough because the above loop collapsed
2475 * all whitespace to a single space.
2478 if ( ASCII_SPACE( q[-1] ) ) {
2482 /* cannot end with a space */
2483 assert( !ASCII_SPACE( q[-1] ) );
2485 /* null terminate */
2488 newval->bv_len = q - newval->bv_val;
2489 *normalized = newval;
2491 return LDAP_SUCCESS;
2500 struct berval *value,
2501 void *assertedValue )
2503 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2506 match = strncmp( value->bv_val,
2507 ((struct berval *) assertedValue)->bv_val,
2512 return LDAP_SUCCESS;
2516 caseExactIA5SubstringsMatch(
2521 struct berval *value,
2522 void *assertedValue )
2525 SubstringsAssertion *sub = assertedValue;
2526 struct berval left = *value;
2530 /* Add up asserted input length */
2531 if( sub->sa_initial ) {
2532 inlen += sub->sa_initial->bv_len;
2535 for(i=0; sub->sa_any[i] != NULL; i++) {
2536 inlen += sub->sa_any[i]->bv_len;
2539 if( sub->sa_final ) {
2540 inlen += sub->sa_final->bv_len;
2543 if( sub->sa_initial ) {
2544 if( inlen > left.bv_len ) {
2549 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2550 sub->sa_initial->bv_len );
2556 left.bv_val += sub->sa_initial->bv_len;
2557 left.bv_len -= sub->sa_initial->bv_len;
2558 inlen -= sub->sa_initial->bv_len;
2561 if( sub->sa_final ) {
2562 if( inlen > left.bv_len ) {
2567 match = strncmp( sub->sa_final->bv_val,
2568 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2569 sub->sa_final->bv_len );
2575 left.bv_len -= sub->sa_final->bv_len;
2576 inlen -= sub->sa_final->bv_len;
2580 for(i=0; sub->sa_any[i]; i++) {
2585 if( inlen > left.bv_len ) {
2586 /* not enough length */
2591 if( sub->sa_any[i]->bv_len == 0 ) {
2595 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2602 idx = p - left.bv_val;
2603 assert( idx < left.bv_len );
2605 if( idx >= left.bv_len ) {
2606 /* this shouldn't happen */
2613 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2614 /* not enough left */
2619 match = strncmp( left.bv_val,
2620 sub->sa_any[i]->bv_val,
2621 sub->sa_any[i]->bv_len );
2629 left.bv_val += sub->sa_any[i]->bv_len;
2630 left.bv_len -= sub->sa_any[i]->bv_len;
2631 inlen -= sub->sa_any[i]->bv_len;
2637 return LDAP_SUCCESS;
2640 /* Index generation function */
2641 int caseExactIA5Indexer(
2646 struct berval *prefix,
2647 struct berval **values,
2648 struct berval ***keysp )
2652 struct berval **keys;
2653 HASH_CONTEXT HASHcontext;
2654 unsigned char HASHdigest[HASH_BYTES];
2655 struct berval digest;
2656 digest.bv_val = HASHdigest;
2657 digest.bv_len = sizeof(HASHdigest);
2659 /* we should have at least one value at this point */
2660 assert( values != NULL && values[0] != NULL );
2662 for( i=0; values[i] != NULL; i++ ) {
2663 /* just count them */
2666 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2668 slen = strlen( syntax->ssyn_oid );
2669 mlen = strlen( mr->smr_oid );
2671 for( i=0; values[i] != NULL; i++ ) {
2672 struct berval *value = values[i];
2674 HASH_Init( &HASHcontext );
2675 if( prefix != NULL && prefix->bv_len > 0 ) {
2676 HASH_Update( &HASHcontext,
2677 prefix->bv_val, prefix->bv_len );
2679 HASH_Update( &HASHcontext,
2680 syntax->ssyn_oid, slen );
2681 HASH_Update( &HASHcontext,
2682 mr->smr_oid, mlen );
2683 HASH_Update( &HASHcontext,
2684 value->bv_val, value->bv_len );
2685 HASH_Final( HASHdigest, &HASHcontext );
2687 keys[i] = ber_bvdup( &digest );
2692 return LDAP_SUCCESS;
2695 /* Index generation function */
2696 int caseExactIA5Filter(
2701 struct berval *prefix,
2703 struct berval ***keysp )
2706 struct berval **keys;
2707 HASH_CONTEXT HASHcontext;
2708 unsigned char HASHdigest[HASH_BYTES];
2709 struct berval *value;
2710 struct berval digest;
2711 digest.bv_val = HASHdigest;
2712 digest.bv_len = sizeof(HASHdigest);
2714 slen = strlen( syntax->ssyn_oid );
2715 mlen = strlen( mr->smr_oid );
2717 value = (struct berval *) assertValue;
2719 keys = ch_malloc( sizeof( struct berval * ) * 2 );
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[0] = ber_bvdup( &digest );
2738 return LDAP_SUCCESS;
2741 /* Substrings Index generation function */
2742 int caseExactIA5SubstringsIndexer(
2747 struct berval *prefix,
2748 struct berval **values,
2749 struct berval ***keysp )
2753 struct berval **keys;
2754 HASH_CONTEXT HASHcontext;
2755 unsigned char HASHdigest[HASH_BYTES];
2756 struct berval digest;
2757 digest.bv_val = HASHdigest;
2758 digest.bv_len = sizeof(HASHdigest);
2760 /* we should have at least one value at this point */
2761 assert( values != NULL && values[0] != NULL );
2764 for( i=0; values[i] != NULL; i++ ) {
2765 /* count number of indices to generate */
2766 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2770 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2771 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2772 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2773 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2775 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2779 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2780 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2781 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2785 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2786 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2787 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2788 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2790 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2796 /* no keys to generate */
2798 return LDAP_SUCCESS;
2801 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2803 slen = strlen( syntax->ssyn_oid );
2804 mlen = strlen( mr->smr_oid );
2807 for( i=0; values[i] != NULL; i++ ) {
2809 struct berval *value;
2812 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2814 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2815 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2817 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2818 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2820 for( j=0; j<max; j++ ) {
2821 HASH_Init( &HASHcontext );
2822 if( prefix != NULL && prefix->bv_len > 0 ) {
2823 HASH_Update( &HASHcontext,
2824 prefix->bv_val, prefix->bv_len );
2827 HASH_Update( &HASHcontext,
2828 &pre, sizeof( pre ) );
2829 HASH_Update( &HASHcontext,
2830 syntax->ssyn_oid, slen );
2831 HASH_Update( &HASHcontext,
2832 mr->smr_oid, mlen );
2833 HASH_Update( &HASHcontext,
2835 SLAP_INDEX_SUBSTR_MAXLEN );
2836 HASH_Final( HASHdigest, &HASHcontext );
2838 keys[nkeys++] = ber_bvdup( &digest );
2842 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2843 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2845 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2848 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2849 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2850 HASH_Init( &HASHcontext );
2851 if( prefix != NULL && prefix->bv_len > 0 ) {
2852 HASH_Update( &HASHcontext,
2853 prefix->bv_val, prefix->bv_len );
2855 HASH_Update( &HASHcontext,
2856 &pre, sizeof( pre ) );
2857 HASH_Update( &HASHcontext,
2858 syntax->ssyn_oid, slen );
2859 HASH_Update( &HASHcontext,
2860 mr->smr_oid, mlen );
2861 HASH_Update( &HASHcontext,
2863 HASH_Final( HASHdigest, &HASHcontext );
2865 keys[nkeys++] = ber_bvdup( &digest );
2868 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2869 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2870 HASH_Init( &HASHcontext );
2871 if( prefix != NULL && prefix->bv_len > 0 ) {
2872 HASH_Update( &HASHcontext,
2873 prefix->bv_val, prefix->bv_len );
2875 HASH_Update( &HASHcontext,
2876 &pre, sizeof( pre ) );
2877 HASH_Update( &HASHcontext,
2878 syntax->ssyn_oid, slen );
2879 HASH_Update( &HASHcontext,
2880 mr->smr_oid, mlen );
2881 HASH_Update( &HASHcontext,
2882 &value->bv_val[value->bv_len-j], j );
2883 HASH_Final( HASHdigest, &HASHcontext );
2885 keys[nkeys++] = ber_bvdup( &digest );
2899 return LDAP_SUCCESS;
2902 int caseExactIA5SubstringsFilter(
2907 struct berval *prefix,
2909 struct berval ***keysp )
2911 SubstringsAssertion *sa = assertValue;
2913 ber_len_t nkeys = 0;
2914 size_t slen, mlen, klen;
2915 struct berval **keys;
2916 HASH_CONTEXT HASHcontext;
2917 unsigned char HASHdigest[HASH_BYTES];
2918 struct berval *value;
2919 struct berval digest;
2921 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2922 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2927 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2929 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2930 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2931 /* don't bother accounting for stepping */
2932 nkeys += sa->sa_any[i]->bv_len -
2933 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2938 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2939 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2946 return LDAP_SUCCESS;
2949 digest.bv_val = HASHdigest;
2950 digest.bv_len = sizeof(HASHdigest);
2952 slen = strlen( syntax->ssyn_oid );
2953 mlen = strlen( mr->smr_oid );
2955 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2958 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2959 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2961 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2962 value = sa->sa_initial;
2964 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2965 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2967 HASH_Init( &HASHcontext );
2968 if( prefix != NULL && prefix->bv_len > 0 ) {
2969 HASH_Update( &HASHcontext,
2970 prefix->bv_val, prefix->bv_len );
2972 HASH_Update( &HASHcontext,
2973 &pre, sizeof( pre ) );
2974 HASH_Update( &HASHcontext,
2975 syntax->ssyn_oid, slen );
2976 HASH_Update( &HASHcontext,
2977 mr->smr_oid, mlen );
2978 HASH_Update( &HASHcontext,
2979 value->bv_val, klen );
2980 HASH_Final( HASHdigest, &HASHcontext );
2982 keys[nkeys++] = ber_bvdup( &digest );
2985 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2987 pre = SLAP_INDEX_SUBSTR_PREFIX;
2988 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2990 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2991 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2995 value = sa->sa_any[i];
2998 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2999 j += SLAP_INDEX_SUBSTR_STEP )
3001 HASH_Init( &HASHcontext );
3002 if( prefix != NULL && prefix->bv_len > 0 ) {
3003 HASH_Update( &HASHcontext,
3004 prefix->bv_val, prefix->bv_len );
3006 HASH_Update( &HASHcontext,
3007 &pre, sizeof( pre ) );
3008 HASH_Update( &HASHcontext,
3009 syntax->ssyn_oid, slen );
3010 HASH_Update( &HASHcontext,
3011 mr->smr_oid, mlen );
3012 HASH_Update( &HASHcontext,
3013 &value->bv_val[j], klen );
3014 HASH_Final( HASHdigest, &HASHcontext );
3016 keys[nkeys++] = ber_bvdup( &digest );
3021 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3022 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3024 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3025 value = sa->sa_final;
3027 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3028 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3030 HASH_Init( &HASHcontext );
3031 if( prefix != NULL && prefix->bv_len > 0 ) {
3032 HASH_Update( &HASHcontext,
3033 prefix->bv_val, prefix->bv_len );
3035 HASH_Update( &HASHcontext,
3036 &pre, sizeof( pre ) );
3037 HASH_Update( &HASHcontext,
3038 syntax->ssyn_oid, slen );
3039 HASH_Update( &HASHcontext,
3040 mr->smr_oid, mlen );
3041 HASH_Update( &HASHcontext,
3042 &value->bv_val[value->bv_len-klen], klen );
3043 HASH_Final( HASHdigest, &HASHcontext );
3045 keys[nkeys++] = ber_bvdup( &digest );
3056 return LDAP_SUCCESS;
3065 struct berval *value,
3066 void *assertedValue )
3068 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3070 if( match == 0 && value->bv_len ) {
3071 match = strncasecmp( value->bv_val,
3072 ((struct berval *) assertedValue)->bv_val,
3077 return LDAP_SUCCESS;
3081 caseIgnoreIA5SubstringsMatch(
3086 struct berval *value,
3087 void *assertedValue )
3090 SubstringsAssertion *sub = assertedValue;
3091 struct berval left = *value;
3095 /* Add up asserted input length */
3096 if( sub->sa_initial ) {
3097 inlen += sub->sa_initial->bv_len;
3100 for(i=0; sub->sa_any[i] != NULL; i++) {
3101 inlen += sub->sa_any[i]->bv_len;
3104 if( sub->sa_final ) {
3105 inlen += sub->sa_final->bv_len;
3108 if( sub->sa_initial ) {
3109 if( inlen > left.bv_len ) {
3114 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3115 sub->sa_initial->bv_len );
3121 left.bv_val += sub->sa_initial->bv_len;
3122 left.bv_len -= sub->sa_initial->bv_len;
3123 inlen -= sub->sa_initial->bv_len;
3126 if( sub->sa_final ) {
3127 if( inlen > left.bv_len ) {
3132 match = strncasecmp( sub->sa_final->bv_val,
3133 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3134 sub->sa_final->bv_len );
3140 left.bv_len -= sub->sa_final->bv_len;
3141 inlen -= sub->sa_final->bv_len;
3145 for(i=0; sub->sa_any[i]; i++) {
3150 if( inlen > left.bv_len ) {
3151 /* not enough length */
3156 if( sub->sa_any[i]->bv_len == 0 ) {
3160 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3167 idx = p - left.bv_val;
3168 assert( idx < left.bv_len );
3170 if( idx >= left.bv_len ) {
3171 /* this shouldn't happen */
3178 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3179 /* not enough left */
3184 match = strncasecmp( left.bv_val,
3185 sub->sa_any[i]->bv_val,
3186 sub->sa_any[i]->bv_len );
3195 left.bv_val += sub->sa_any[i]->bv_len;
3196 left.bv_len -= sub->sa_any[i]->bv_len;
3197 inlen -= sub->sa_any[i]->bv_len;
3203 return LDAP_SUCCESS;
3206 /* Index generation function */
3207 int caseIgnoreIA5Indexer(
3212 struct berval *prefix,
3213 struct berval **values,
3214 struct berval ***keysp )
3218 struct berval **keys;
3219 HASH_CONTEXT HASHcontext;
3220 unsigned char HASHdigest[HASH_BYTES];
3221 struct berval digest;
3222 digest.bv_val = HASHdigest;
3223 digest.bv_len = sizeof(HASHdigest);
3225 /* we should have at least one value at this point */
3226 assert( values != NULL && values[0] != NULL );
3228 for( i=0; values[i] != NULL; i++ ) {
3229 /* just count them */
3232 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3234 slen = strlen( syntax->ssyn_oid );
3235 mlen = strlen( mr->smr_oid );
3237 for( i=0; values[i] != NULL; i++ ) {
3238 struct berval *value = ber_bvdup( values[i] );
3239 ldap_pvt_str2upper( value->bv_val );
3241 HASH_Init( &HASHcontext );
3242 if( prefix != NULL && prefix->bv_len > 0 ) {
3243 HASH_Update( &HASHcontext,
3244 prefix->bv_val, prefix->bv_len );
3246 HASH_Update( &HASHcontext,
3247 syntax->ssyn_oid, slen );
3248 HASH_Update( &HASHcontext,
3249 mr->smr_oid, mlen );
3250 HASH_Update( &HASHcontext,
3251 value->bv_val, value->bv_len );
3252 HASH_Final( HASHdigest, &HASHcontext );
3254 ber_bvfree( value );
3256 keys[i] = ber_bvdup( &digest );
3261 return LDAP_SUCCESS;
3264 /* Index generation function */
3265 int caseIgnoreIA5Filter(
3270 struct berval *prefix,
3272 struct berval ***keysp )
3275 struct berval **keys;
3276 HASH_CONTEXT HASHcontext;
3277 unsigned char HASHdigest[HASH_BYTES];
3278 struct berval *value;
3279 struct berval digest;
3280 digest.bv_val = HASHdigest;
3281 digest.bv_len = sizeof(HASHdigest);
3283 slen = strlen( syntax->ssyn_oid );
3284 mlen = strlen( mr->smr_oid );
3286 value = ber_bvdup( (struct berval *) assertValue );
3287 ldap_pvt_str2upper( value->bv_val );
3289 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3291 HASH_Init( &HASHcontext );
3292 if( prefix != NULL && prefix->bv_len > 0 ) {
3293 HASH_Update( &HASHcontext,
3294 prefix->bv_val, prefix->bv_len );
3296 HASH_Update( &HASHcontext,
3297 syntax->ssyn_oid, slen );
3298 HASH_Update( &HASHcontext,
3299 mr->smr_oid, mlen );
3300 HASH_Update( &HASHcontext,
3301 value->bv_val, value->bv_len );
3302 HASH_Final( HASHdigest, &HASHcontext );
3304 keys[0] = ber_bvdup( &digest );
3307 ber_bvfree( value );
3311 return LDAP_SUCCESS;
3314 /* Substrings Index generation function */
3315 int caseIgnoreIA5SubstringsIndexer(
3320 struct berval *prefix,
3321 struct berval **values,
3322 struct berval ***keysp )
3326 struct berval **keys;
3327 HASH_CONTEXT HASHcontext;
3328 unsigned char HASHdigest[HASH_BYTES];
3329 struct berval digest;
3330 digest.bv_val = HASHdigest;
3331 digest.bv_len = sizeof(HASHdigest);
3333 /* we should have at least one value at this point */
3334 assert( values != NULL && values[0] != NULL );
3337 for( i=0; values[i] != NULL; i++ ) {
3338 /* count number of indices to generate */
3339 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3343 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3344 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3345 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3346 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3348 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3352 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3353 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3354 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3358 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3359 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3360 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3361 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3363 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3369 /* no keys to generate */
3371 return LDAP_SUCCESS;
3374 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3376 slen = strlen( syntax->ssyn_oid );
3377 mlen = strlen( mr->smr_oid );
3380 for( i=0; values[i] != NULL; i++ ) {
3382 struct berval *value;
3384 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3386 value = ber_bvdup( values[i] );
3387 ldap_pvt_str2upper( value->bv_val );
3389 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3390 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3392 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3393 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3395 for( j=0; j<max; j++ ) {
3396 HASH_Init( &HASHcontext );
3397 if( prefix != NULL && prefix->bv_len > 0 ) {
3398 HASH_Update( &HASHcontext,
3399 prefix->bv_val, prefix->bv_len );
3402 HASH_Update( &HASHcontext,
3403 &pre, sizeof( pre ) );
3404 HASH_Update( &HASHcontext,
3405 syntax->ssyn_oid, slen );
3406 HASH_Update( &HASHcontext,
3407 mr->smr_oid, mlen );
3408 HASH_Update( &HASHcontext,
3410 SLAP_INDEX_SUBSTR_MAXLEN );
3411 HASH_Final( HASHdigest, &HASHcontext );
3413 keys[nkeys++] = ber_bvdup( &digest );
3417 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3418 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3420 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3423 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3424 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3425 HASH_Init( &HASHcontext );
3426 if( prefix != NULL && prefix->bv_len > 0 ) {
3427 HASH_Update( &HASHcontext,
3428 prefix->bv_val, prefix->bv_len );
3430 HASH_Update( &HASHcontext,
3431 &pre, sizeof( pre ) );
3432 HASH_Update( &HASHcontext,
3433 syntax->ssyn_oid, slen );
3434 HASH_Update( &HASHcontext,
3435 mr->smr_oid, mlen );
3436 HASH_Update( &HASHcontext,
3438 HASH_Final( HASHdigest, &HASHcontext );
3440 keys[nkeys++] = ber_bvdup( &digest );
3443 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3444 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3445 HASH_Init( &HASHcontext );
3446 if( prefix != NULL && prefix->bv_len > 0 ) {
3447 HASH_Update( &HASHcontext,
3448 prefix->bv_val, prefix->bv_len );
3450 HASH_Update( &HASHcontext,
3451 &pre, sizeof( pre ) );
3452 HASH_Update( &HASHcontext,
3453 syntax->ssyn_oid, slen );
3454 HASH_Update( &HASHcontext,
3455 mr->smr_oid, mlen );
3456 HASH_Update( &HASHcontext,
3457 &value->bv_val[value->bv_len-j], j );
3458 HASH_Final( HASHdigest, &HASHcontext );
3460 keys[nkeys++] = ber_bvdup( &digest );
3465 ber_bvfree( value );
3476 return LDAP_SUCCESS;
3479 int caseIgnoreIA5SubstringsFilter(
3484 struct berval *prefix,
3486 struct berval ***keysp )
3488 SubstringsAssertion *sa = assertValue;
3490 ber_len_t nkeys = 0;
3491 size_t slen, mlen, klen;
3492 struct berval **keys;
3493 HASH_CONTEXT HASHcontext;
3494 unsigned char HASHdigest[HASH_BYTES];
3495 struct berval *value;
3496 struct berval digest;
3498 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3499 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3504 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3506 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3507 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3508 /* don't bother accounting for stepping */
3509 nkeys += sa->sa_any[i]->bv_len -
3510 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3515 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3516 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3523 return LDAP_SUCCESS;
3526 digest.bv_val = HASHdigest;
3527 digest.bv_len = sizeof(HASHdigest);
3529 slen = strlen( syntax->ssyn_oid );
3530 mlen = strlen( mr->smr_oid );
3532 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3535 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3536 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3538 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3539 value = ber_bvdup( sa->sa_initial );
3540 ldap_pvt_str2upper( value->bv_val );
3542 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3543 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3545 HASH_Init( &HASHcontext );
3546 if( prefix != NULL && prefix->bv_len > 0 ) {
3547 HASH_Update( &HASHcontext,
3548 prefix->bv_val, prefix->bv_len );
3550 HASH_Update( &HASHcontext,
3551 &pre, sizeof( pre ) );
3552 HASH_Update( &HASHcontext,
3553 syntax->ssyn_oid, slen );
3554 HASH_Update( &HASHcontext,
3555 mr->smr_oid, mlen );
3556 HASH_Update( &HASHcontext,
3557 value->bv_val, klen );
3558 HASH_Final( HASHdigest, &HASHcontext );
3560 ber_bvfree( value );
3561 keys[nkeys++] = ber_bvdup( &digest );
3564 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3566 pre = SLAP_INDEX_SUBSTR_PREFIX;
3567 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3569 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3570 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3574 value = ber_bvdup( sa->sa_any[i] );
3575 ldap_pvt_str2upper( value->bv_val );
3578 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3579 j += SLAP_INDEX_SUBSTR_STEP )
3581 HASH_Init( &HASHcontext );
3582 if( prefix != NULL && prefix->bv_len > 0 ) {
3583 HASH_Update( &HASHcontext,
3584 prefix->bv_val, prefix->bv_len );
3586 HASH_Update( &HASHcontext,
3587 &pre, sizeof( pre ) );
3588 HASH_Update( &HASHcontext,
3589 syntax->ssyn_oid, slen );
3590 HASH_Update( &HASHcontext,
3591 mr->smr_oid, mlen );
3592 HASH_Update( &HASHcontext,
3593 &value->bv_val[j], klen );
3594 HASH_Final( HASHdigest, &HASHcontext );
3596 keys[nkeys++] = ber_bvdup( &digest );
3599 ber_bvfree( value );
3603 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3604 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3606 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3607 value = ber_bvdup( sa->sa_final );
3608 ldap_pvt_str2upper( value->bv_val );
3610 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3611 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3613 HASH_Init( &HASHcontext );
3614 if( prefix != NULL && prefix->bv_len > 0 ) {
3615 HASH_Update( &HASHcontext,
3616 prefix->bv_val, prefix->bv_len );
3618 HASH_Update( &HASHcontext,
3619 &pre, sizeof( pre ) );
3620 HASH_Update( &HASHcontext,
3621 syntax->ssyn_oid, slen );
3622 HASH_Update( &HASHcontext,
3623 mr->smr_oid, mlen );
3624 HASH_Update( &HASHcontext,
3625 &value->bv_val[value->bv_len-klen], klen );
3626 HASH_Final( HASHdigest, &HASHcontext );
3628 ber_bvfree( value );
3629 keys[nkeys++] = ber_bvdup( &digest );
3640 return LDAP_SUCCESS;
3644 numericStringValidate(
3650 for(i=0; i < in->bv_len; i++) {
3651 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3652 return LDAP_INVALID_SYNTAX;
3656 return LDAP_SUCCESS;
3660 numericStringNormalize(
3663 struct berval **normalized )
3665 /* removal all spaces */
3666 struct berval *newval;
3669 newval = ch_malloc( sizeof( struct berval ) );
3670 newval->bv_val = ch_malloc( val->bv_len + 1 );
3676 if ( ASCII_SPACE( *p ) ) {
3677 /* Ignore whitespace */
3684 assert( newval->bv_val <= p );
3687 /* null terminate */
3690 newval->bv_len = q - newval->bv_val;
3691 *normalized = newval;
3693 return LDAP_SUCCESS;
3697 objectIdentifierFirstComponentMatch(
3702 struct berval *value,
3703 void *assertedValue )
3705 int rc = LDAP_SUCCESS;
3707 struct berval *asserted = (struct berval *) assertedValue;
3711 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3712 return LDAP_INVALID_SYNTAX;
3715 /* trim leading white space */
3716 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3720 /* grab next word */
3721 oid.bv_val = &value->bv_val[i];
3722 oid.bv_len = value->bv_len - i;
3723 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3728 /* insert attributeTypes, objectclass check here */
3729 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3730 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3733 char *stored = ch_malloc( oid.bv_len + 1 );
3734 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3735 stored[oid.bv_len] = '\0';
3737 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3738 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3739 MatchingRule *stored_mr = mr_find( stored );
3741 if( asserted_mr == NULL ) {
3742 rc = SLAPD_COMPARE_UNDEFINED;
3744 match = asserted_mr != stored_mr;
3747 } else if ( !strcmp( syntax->ssyn_oid,
3748 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3750 AttributeType *asserted_at = at_find( asserted->bv_val );
3751 AttributeType *stored_at = at_find( stored );
3753 if( asserted_at == NULL ) {
3754 rc = SLAPD_COMPARE_UNDEFINED;
3756 match = asserted_at != stored_at;
3759 } else if ( !strcmp( syntax->ssyn_oid,
3760 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3762 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3763 ObjectClass *stored_oc = oc_find( stored );
3765 if( asserted_oc == NULL ) {
3766 rc = SLAPD_COMPARE_UNDEFINED;
3768 match = asserted_oc != stored_oc;
3776 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3777 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3778 match, value->bv_val, asserted->bv_val ));
3780 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3781 "%d\n\t\"%s\"\n\t\"%s\"\n",
3782 match, value->bv_val, asserted->bv_val );
3786 if( rc == LDAP_SUCCESS ) *matchp = match;
3791 check_time_syntax (struct berval *val,
3795 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3796 static int mdays[2][12] = {
3797 /* non-leap years */
3798 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3800 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3803 int part, c, tzoffset, leapyear = 0 ;
3805 if( val->bv_len == 0 ) {
3806 return LDAP_INVALID_SYNTAX;
3809 p = (char *)val->bv_val;
3810 e = p + val->bv_len;
3812 /* Ignore initial whitespace */
3813 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3817 if (e - p < 13 - (2 * start)) {
3818 return LDAP_INVALID_SYNTAX;
3821 for (part = 0; part < 9; part++) {
3825 for (part = start; part < 7; part++) {
3827 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3834 return LDAP_INVALID_SYNTAX;
3836 if (c < 0 || c > 9) {
3837 return LDAP_INVALID_SYNTAX;
3843 return LDAP_INVALID_SYNTAX;
3845 if (c < 0 || c > 9) {
3846 return LDAP_INVALID_SYNTAX;
3851 if (part == 2 || part == 3) {
3854 if (parts[part] < 0) {
3855 return LDAP_INVALID_SYNTAX;
3857 if (parts[part] > ceiling[part]) {
3858 return LDAP_INVALID_SYNTAX;
3862 /* leapyear check for the Gregorian calendar (year>1581) */
3863 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3864 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3869 if (parts[3] > mdays[leapyear][parts[2]]) {
3870 return LDAP_INVALID_SYNTAX;
3875 tzoffset = 0; /* UTC */
3876 } else if (c != '+' && c != '-') {
3877 return LDAP_INVALID_SYNTAX;
3881 } else /* c == '+' */ {
3886 return LDAP_INVALID_SYNTAX;
3889 for (part = 7; part < 9; part++) {
3891 if (c < 0 || c > 9) {
3892 return LDAP_INVALID_SYNTAX;
3897 if (c < 0 || c > 9) {
3898 return LDAP_INVALID_SYNTAX;
3902 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3903 return LDAP_INVALID_SYNTAX;
3908 /* Ignore trailing whitespace */
3909 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3913 return LDAP_INVALID_SYNTAX;
3916 switch ( tzoffset ) {
3917 case -1: /* negativ offset to UTC, ie west of Greenwich */
3918 parts[4] += parts[7];
3919 parts[5] += parts[8];
3920 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3924 c = mdays[leapyear][parts[2]];
3926 if (parts[part] > c) {
3927 parts[part] -= c + 1;
3932 case 1: /* positive offset to UTC, ie east of Greenwich */
3933 parts[4] -= parts[7];
3934 parts[5] -= parts[8];
3935 for (part = 6; --part > 0; ) {
3939 /* first arg to % needs to be non negativ */
3940 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3942 if (parts[part] < 0) {
3943 parts[part] += c + 1;
3948 case 0: /* already UTC */
3952 return LDAP_SUCCESS;
3959 struct berval **normalized )
3964 rc = check_time_syntax(val, 1, parts);
3965 if (rc != LDAP_SUCCESS) {
3970 out = ch_malloc( sizeof(struct berval) );
3972 return LBER_ERROR_MEMORY;
3975 out->bv_val = ch_malloc( 14 );
3976 if ( out->bv_val == NULL ) {
3978 return LBER_ERROR_MEMORY;
3981 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3982 parts[1], parts[2] + 1, parts[3] + 1,
3983 parts[4], parts[5], parts[6] );
3987 return LDAP_SUCCESS;
3997 return check_time_syntax(in, 1, parts);
4001 generalizedTimeValidate(
4007 return check_time_syntax(in, 0, parts);
4011 generalizedTimeNormalize(
4014 struct berval **normalized )
4019 rc = check_time_syntax(val, 0, parts);
4020 if (rc != LDAP_SUCCESS) {
4025 out = ch_malloc( sizeof(struct berval) );
4027 return LBER_ERROR_MEMORY;
4030 out->bv_val = ch_malloc( 16 );
4031 if ( out->bv_val == NULL ) {
4033 return LBER_ERROR_MEMORY;
4036 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4037 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4038 parts[4], parts[5], parts[6] );
4042 return LDAP_SUCCESS;
4046 nisNetgroupTripleValidate(
4048 struct berval *val )
4053 if ( val->bv_len == 0 ) {
4054 return LDAP_INVALID_SYNTAX;
4057 p = (char *)val->bv_val;
4058 e = p + val->bv_len;
4061 /* syntax does not allow leading white space */
4062 /* Ignore initial whitespace */
4063 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4068 if ( *p != '(' /*')'*/ ) {
4069 return LDAP_INVALID_SYNTAX;
4072 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4076 return LDAP_INVALID_SYNTAX;
4079 } else if ( !ATTR_CHAR( *p ) ) {
4080 return LDAP_INVALID_SYNTAX;
4084 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4085 return LDAP_INVALID_SYNTAX;
4091 /* syntax does not allow trailing white space */
4092 /* Ignore trailing whitespace */
4093 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4099 return LDAP_INVALID_SYNTAX;
4102 return LDAP_SUCCESS;
4106 bootParameterValidate(
4108 struct berval *val )
4112 if ( val->bv_len == 0 ) {
4113 return LDAP_INVALID_SYNTAX;
4116 p = (char *)val->bv_val;
4117 e = p + val->bv_len;
4120 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4121 if ( !ATTR_CHAR( *p ) ) {
4122 return LDAP_INVALID_SYNTAX;
4127 return LDAP_INVALID_SYNTAX;
4131 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4132 if ( !ATTR_CHAR( *p ) ) {
4133 return LDAP_INVALID_SYNTAX;
4138 return LDAP_INVALID_SYNTAX;
4142 for ( p++; p < e; p++ ) {
4143 if ( !ATTR_CHAR( *p ) ) {
4144 return LDAP_INVALID_SYNTAX;
4148 return LDAP_SUCCESS;
4151 struct syntax_defs_rec {
4154 slap_syntax_validate_func *sd_validate;
4155 slap_syntax_transform_func *sd_normalize;
4156 slap_syntax_transform_func *sd_pretty;
4157 #ifdef SLAPD_BINARY_CONVERSION
4158 slap_syntax_transform_func *sd_ber2str;
4159 slap_syntax_transform_func *sd_str2ber;
4163 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4164 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4166 struct syntax_defs_rec syntax_defs[] = {
4167 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4168 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4170 0, NULL, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4172 0, NULL, NULL, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4174 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4176 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4178 0, bitStringValidate, NULL, NULL },
4179 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4180 0, booleanValidate, NULL, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4182 X_BINARY X_NOT_H_R ")",
4183 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4185 X_BINARY X_NOT_H_R ")",
4186 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4188 X_BINARY X_NOT_H_R ")",
4189 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4191 0, countryStringValidate, IA5StringNormalize, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4193 0, dnValidate, dnNormalize, dnPretty},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4195 0, NULL, NULL, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4197 0, NULL, NULL, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4199 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4201 0, NULL, NULL, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4203 0, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4205 0, NULL, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4207 0, NULL, NULL, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4209 0, NULL, NULL, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4211 0, printablesStringValidate, IA5StringNormalize, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4213 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4215 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4217 0, NULL, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4219 0, IA5StringValidate, IA5StringNormalize, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4221 0, integerValidate, integerNormalize, integerPretty},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4223 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4225 0, NULL, NULL, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4227 0, NULL, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4229 0, NULL, NULL, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4231 0, NULL, NULL, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4233 0, NULL, NULL, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4235 0, nameUIDValidate, nameUIDNormalize, NULL},
4236 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4237 0, NULL, NULL, NULL},
4238 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4239 0, numericStringValidate, numericStringNormalize, NULL},
4240 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4241 0, NULL, NULL, NULL},
4242 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4243 0, oidValidate, NULL, NULL},
4244 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4245 0, IA5StringValidate, IA5StringNormalize, NULL},
4246 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4247 0, blobValidate, NULL, NULL},
4248 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4249 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4250 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4251 0, NULL, NULL, NULL},
4252 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4253 0, NULL, NULL, NULL},
4254 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4255 0, printableStringValidate, IA5StringNormalize, NULL},
4256 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4257 X_BINARY X_NOT_H_R ")",
4258 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4259 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4260 0, printableStringValidate, IA5StringNormalize, NULL},
4261 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4262 0, NULL, NULL, NULL},
4263 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4264 0, printableStringValidate, IA5StringNormalize, NULL},
4265 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4266 0, utcTimeValidate, utcTimeNormalize, NULL},
4267 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4268 0, NULL, NULL, NULL},
4269 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4270 0, NULL, NULL, NULL},
4271 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4272 0, NULL, NULL, NULL},
4273 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4274 0, NULL, NULL, NULL},
4275 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4276 0, NULL, NULL, NULL},
4278 /* RFC 2307 NIS Syntaxes */
4279 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4280 0, nisNetgroupTripleValidate, NULL, NULL},
4281 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4282 0, bootParameterValidate, NULL, NULL},
4284 /* OpenLDAP Experimental Syntaxes */
4285 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4286 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4288 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4289 0, NULL, NULL, NULL},
4291 /* OpenLDAP Void Syntax */
4292 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4293 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4294 {NULL, 0, NULL, NULL, NULL}
4297 struct mrule_defs_rec {
4299 slap_mask_t mrd_usage;
4300 slap_mr_convert_func * mrd_convert;
4301 slap_mr_normalize_func * mrd_normalize;
4302 slap_mr_match_func * mrd_match;
4303 slap_mr_indexer_func * mrd_indexer;
4304 slap_mr_filter_func * mrd_filter;
4306 char * mrd_associated;
4310 * Other matching rules in X.520 that we do not use (yet):
4312 * 2.5.13.9 numericStringOrderingMatch
4313 * 2.5.13.15 integerOrderingMatch
4314 * 2.5.13.18 octetStringOrderingMatch
4315 * 2.5.13.19 octetStringSubstringsMatch
4316 * 2.5.13.25 uTCTimeMatch
4317 * 2.5.13.26 uTCTimeOrderingMatch
4318 * 2.5.13.31 directoryStringFirstComponentMatch
4319 * 2.5.13.32 wordMatch
4320 * 2.5.13.33 keywordMatch
4321 * 2.5.13.34 certificateExactMatch
4322 * 2.5.13.35 certificateMatch
4323 * 2.5.13.36 certificatePairExactMatch
4324 * 2.5.13.37 certificatePairMatch
4325 * 2.5.13.38 certificateListExactMatch
4326 * 2.5.13.39 certificateListMatch
4327 * 2.5.13.40 algorithmIdentifierMatch
4328 * 2.5.13.41 storedPrefixMatch
4329 * 2.5.13.42 attributeCertificateMatch
4330 * 2.5.13.43 readerAndKeyIDMatch
4331 * 2.5.13.44 attributeIntegrityMatch
4334 struct mrule_defs_rec mrule_defs[] = {
4336 * EQUALITY matching rules must be listed after associated APPROX
4337 * matching rules. So, we list all APPROX matching rules first.
4339 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4340 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4341 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4343 directoryStringApproxMatch,
4344 directoryStringApproxIndexer,
4345 directoryStringApproxFilter,
4348 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4349 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4350 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4352 IA5StringApproxMatch,
4353 IA5StringApproxIndexer,
4354 IA5StringApproxFilter,
4358 * Other matching rules
4361 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4362 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4363 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4365 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4368 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4369 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4370 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4372 dnMatch, dnIndexer, dnFilter,
4375 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4376 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4377 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4379 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4380 directoryStringApproxMatchOID },
4382 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4383 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4386 caseIgnoreOrderingMatch, NULL, NULL,
4389 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4390 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4391 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4393 caseIgnoreSubstringsMatch,
4394 caseIgnoreSubstringsIndexer,
4395 caseIgnoreSubstringsFilter,
4398 {"( 2.5.13.5 NAME 'caseExactMatch' "
4399 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4400 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4402 caseExactMatch, caseExactIndexer, caseExactFilter,
4403 directoryStringApproxMatchOID },
4405 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4406 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4409 caseExactOrderingMatch, NULL, NULL,
4412 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4413 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4414 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4416 caseExactSubstringsMatch,
4417 caseExactSubstringsIndexer,
4418 caseExactSubstringsFilter,
4421 {"( 2.5.13.8 NAME 'numericStringMatch' "
4422 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4423 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4426 caseIgnoreIA5Indexer,
4427 caseIgnoreIA5Filter,
4430 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4431 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4432 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4434 caseIgnoreIA5SubstringsMatch,
4435 caseIgnoreIA5SubstringsIndexer,
4436 caseIgnoreIA5SubstringsFilter,
4439 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4440 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4441 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4443 caseIgnoreListMatch, NULL, NULL,
4446 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4447 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4448 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4450 caseIgnoreListSubstringsMatch, NULL, NULL,
4453 {"( 2.5.13.13 NAME 'booleanMatch' "
4454 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4455 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4457 booleanMatch, NULL, NULL,
4460 {"( 2.5.13.14 NAME 'integerMatch' "
4461 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4462 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4464 integerMatch, integerIndexer, integerFilter,
4467 {"( 2.5.13.16 NAME 'bitStringMatch' "
4468 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4469 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4471 bitStringMatch, NULL, NULL,
4474 {"( 2.5.13.17 NAME 'octetStringMatch' "
4475 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4476 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4478 octetStringMatch, octetStringIndexer, octetStringFilter,
4481 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4482 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4483 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4485 telephoneNumberMatch,
4486 telephoneNumberIndexer,
4487 telephoneNumberFilter,
4490 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4491 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4492 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4494 telephoneNumberSubstringsMatch,
4495 telephoneNumberSubstringsIndexer,
4496 telephoneNumberSubstringsFilter,
4499 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4500 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4501 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4506 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4507 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4508 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4510 uniqueMemberMatch, NULL, NULL,
4513 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4514 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4515 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4517 protocolInformationMatch, NULL, NULL,
4520 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4521 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4522 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4524 generalizedTimeMatch, NULL, NULL,
4527 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4528 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4531 generalizedTimeOrderingMatch, NULL, NULL,
4534 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4535 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4536 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4538 integerFirstComponentMatch, NULL, NULL,
4541 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4542 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4543 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4545 objectIdentifierFirstComponentMatch, NULL, NULL,
4548 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4549 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4550 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4552 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4553 IA5StringApproxMatchOID },
4555 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4556 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4557 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4559 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4560 IA5StringApproxMatchOID },
4562 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4563 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4566 caseIgnoreIA5SubstringsMatch,
4567 caseIgnoreIA5SubstringsIndexer,
4568 caseIgnoreIA5SubstringsFilter,
4571 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4572 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4575 caseExactIA5SubstringsMatch,
4576 caseExactIA5SubstringsIndexer,
4577 caseExactIA5SubstringsFilter,
4580 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4581 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4584 authPasswordMatch, NULL, NULL,
4587 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4588 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4591 OpenLDAPaciMatch, NULL, NULL,
4594 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4603 /* we should only be called once (from main) */
4604 assert( schema_init_done == 0 );
4606 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4607 res = register_syntax( syntax_defs[i].sd_desc,
4608 syntax_defs[i].sd_flags,
4609 syntax_defs[i].sd_validate,
4610 syntax_defs[i].sd_normalize,
4611 syntax_defs[i].sd_pretty
4612 #ifdef SLAPD_BINARY_CONVERSION
4614 syntax_defs[i].sd_ber2str,
4615 syntax_defs[i].sd_str2ber
4620 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4621 syntax_defs[i].sd_desc );
4626 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4627 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4629 "schema_init: Ingoring unusable matching rule %s\n",
4630 mrule_defs[i].mrd_desc );
4634 res = register_matching_rule(
4635 mrule_defs[i].mrd_desc,
4636 mrule_defs[i].mrd_usage,
4637 mrule_defs[i].mrd_convert,
4638 mrule_defs[i].mrd_normalize,
4639 mrule_defs[i].mrd_match,
4640 mrule_defs[i].mrd_indexer,
4641 mrule_defs[i].mrd_filter,
4642 mrule_defs[i].mrd_associated );
4646 "schema_init: Error registering matching rule %s\n",
4647 mrule_defs[i].mrd_desc );
4651 schema_init_done = 1;
4652 return LDAP_SUCCESS;