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 ) );
1873 value = ber_bvdup( (struct berval *) assertValue );
1874 ldap_pvt_str2upper( value->bv_val );
1877 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1879 HASH_Init( &HASHcontext );
1880 if( prefix != NULL && prefix->bv_len > 0 ) {
1881 HASH_Update( &HASHcontext,
1882 prefix->bv_val, prefix->bv_len );
1884 HASH_Update( &HASHcontext,
1885 syntax->ssyn_oid, slen );
1886 HASH_Update( &HASHcontext,
1887 mr->smr_oid, mlen );
1888 HASH_Update( &HASHcontext,
1889 value->bv_val, value->bv_len );
1890 HASH_Final( HASHdigest, &HASHcontext );
1892 keys[0] = ber_bvdup( &digest );
1895 ber_bvfree( value );
1899 return LDAP_SUCCESS;
1902 /* Substrings Index generation function */
1903 int caseIgnoreSubstringsIndexer(
1908 struct berval *prefix,
1909 struct berval **values,
1910 struct berval ***keysp )
1914 struct berval **keys;
1915 HASH_CONTEXT HASHcontext;
1916 unsigned char HASHdigest[HASH_BYTES];
1917 struct berval digest;
1918 digest.bv_val = HASHdigest;
1919 digest.bv_len = sizeof(HASHdigest);
1921 /* we should have at least one value at this point */
1922 assert( values != NULL && values[0] != NULL );
1925 for( i=0; values[i] != NULL; i++ ) {
1926 /* count number of indices to generate */
1927 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1931 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1932 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1933 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1934 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1936 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1940 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1941 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1942 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1946 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1947 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1948 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1949 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1951 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1957 /* no keys to generate */
1959 return LDAP_SUCCESS;
1962 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1964 slen = strlen( syntax->ssyn_oid );
1965 mlen = strlen( mr->smr_oid );
1968 for( i=0; values[i] != NULL; i++ ) {
1970 struct berval *value;
1972 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1975 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1977 value = ber_bvdup( values[i] );
1978 ldap_pvt_str2upper( value->bv_val );
1981 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1982 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1984 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1985 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1987 for( j=0; j<max; j++ ) {
1988 HASH_Init( &HASHcontext );
1989 if( prefix != NULL && prefix->bv_len > 0 ) {
1990 HASH_Update( &HASHcontext,
1991 prefix->bv_val, prefix->bv_len );
1994 HASH_Update( &HASHcontext,
1995 &pre, sizeof( pre ) );
1996 HASH_Update( &HASHcontext,
1997 syntax->ssyn_oid, slen );
1998 HASH_Update( &HASHcontext,
1999 mr->smr_oid, mlen );
2000 HASH_Update( &HASHcontext,
2002 SLAP_INDEX_SUBSTR_MAXLEN );
2003 HASH_Final( HASHdigest, &HASHcontext );
2005 keys[nkeys++] = ber_bvdup( &digest );
2009 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2010 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2012 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2015 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2016 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2017 HASH_Init( &HASHcontext );
2018 if( prefix != NULL && prefix->bv_len > 0 ) {
2019 HASH_Update( &HASHcontext,
2020 prefix->bv_val, prefix->bv_len );
2022 HASH_Update( &HASHcontext,
2023 &pre, sizeof( pre ) );
2024 HASH_Update( &HASHcontext,
2025 syntax->ssyn_oid, slen );
2026 HASH_Update( &HASHcontext,
2027 mr->smr_oid, mlen );
2028 HASH_Update( &HASHcontext,
2030 HASH_Final( HASHdigest, &HASHcontext );
2032 keys[nkeys++] = ber_bvdup( &digest );
2035 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2036 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2037 HASH_Init( &HASHcontext );
2038 if( prefix != NULL && prefix->bv_len > 0 ) {
2039 HASH_Update( &HASHcontext,
2040 prefix->bv_val, prefix->bv_len );
2042 HASH_Update( &HASHcontext,
2043 &pre, sizeof( pre ) );
2044 HASH_Update( &HASHcontext,
2045 syntax->ssyn_oid, slen );
2046 HASH_Update( &HASHcontext,
2047 mr->smr_oid, mlen );
2048 HASH_Update( &HASHcontext,
2049 &value->bv_val[value->bv_len-j], j );
2050 HASH_Final( HASHdigest, &HASHcontext );
2052 keys[nkeys++] = ber_bvdup( &digest );
2057 ber_bvfree( value );
2068 return LDAP_SUCCESS;
2071 int caseIgnoreSubstringsFilter(
2076 struct berval *prefix,
2078 struct berval ***keysp )
2080 SubstringsAssertion *sa = assertValue;
2082 ber_len_t nkeys = 0;
2083 size_t slen, mlen, klen;
2084 struct berval **keys;
2085 HASH_CONTEXT HASHcontext;
2086 unsigned char HASHdigest[HASH_BYTES];
2087 struct berval *value;
2088 struct berval digest;
2090 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2091 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2096 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2098 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2099 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2100 /* don't bother accounting for stepping */
2101 nkeys += sa->sa_any[i]->bv_len -
2102 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2107 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2108 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2115 return LDAP_SUCCESS;
2118 digest.bv_val = HASHdigest;
2119 digest.bv_len = sizeof(HASHdigest);
2121 slen = strlen( syntax->ssyn_oid );
2122 mlen = strlen( mr->smr_oid );
2124 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2127 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2128 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2130 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2132 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_CASEFOLD ) );
2134 value = ber_bvdup( sa->sa_initial );
2135 ldap_pvt_str2upper( value->bv_val );
2138 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2139 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2141 HASH_Init( &HASHcontext );
2142 if( prefix != NULL && prefix->bv_len > 0 ) {
2143 HASH_Update( &HASHcontext,
2144 prefix->bv_val, prefix->bv_len );
2146 HASH_Update( &HASHcontext,
2147 &pre, sizeof( pre ) );
2148 HASH_Update( &HASHcontext,
2149 syntax->ssyn_oid, slen );
2150 HASH_Update( &HASHcontext,
2151 mr->smr_oid, mlen );
2152 HASH_Update( &HASHcontext,
2153 value->bv_val, klen );
2154 HASH_Final( HASHdigest, &HASHcontext );
2156 ber_bvfree( value );
2157 keys[nkeys++] = ber_bvdup( &digest );
2160 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2162 pre = SLAP_INDEX_SUBSTR_PREFIX;
2163 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2165 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2166 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2171 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_CASEFOLD ) );
2173 value = ber_bvdup( sa->sa_any[i] );
2174 ldap_pvt_str2upper( value->bv_val );
2178 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2179 j += SLAP_INDEX_SUBSTR_STEP )
2181 HASH_Init( &HASHcontext );
2182 if( prefix != NULL && prefix->bv_len > 0 ) {
2183 HASH_Update( &HASHcontext,
2184 prefix->bv_val, prefix->bv_len );
2186 HASH_Update( &HASHcontext,
2187 &pre, sizeof( pre ) );
2188 HASH_Update( &HASHcontext,
2189 syntax->ssyn_oid, slen );
2190 HASH_Update( &HASHcontext,
2191 mr->smr_oid, mlen );
2192 HASH_Update( &HASHcontext,
2193 &value->bv_val[j], klen );
2194 HASH_Final( HASHdigest, &HASHcontext );
2196 keys[nkeys++] = ber_bvdup( &digest );
2199 ber_bvfree( value );
2203 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2204 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2206 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2208 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_CASEFOLD ) );
2210 value = ber_bvdup( sa->sa_final );
2211 ldap_pvt_str2upper( value->bv_val );
2214 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2215 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2217 HASH_Init( &HASHcontext );
2218 if( prefix != NULL && prefix->bv_len > 0 ) {
2219 HASH_Update( &HASHcontext,
2220 prefix->bv_val, prefix->bv_len );
2222 HASH_Update( &HASHcontext,
2223 &pre, sizeof( pre ) );
2224 HASH_Update( &HASHcontext,
2225 syntax->ssyn_oid, slen );
2226 HASH_Update( &HASHcontext,
2227 mr->smr_oid, mlen );
2228 HASH_Update( &HASHcontext,
2229 &value->bv_val[value->bv_len-klen], klen );
2230 HASH_Final( HASHdigest, &HASHcontext );
2232 ber_bvfree( value );
2233 keys[nkeys++] = ber_bvdup( &digest );
2244 return LDAP_SUCCESS;
2250 struct berval *val )
2254 if( val->bv_len == 0 ) {
2255 /* disallow empty strings */
2256 return LDAP_INVALID_SYNTAX;
2259 if( OID_LEADCHAR(val->bv_val[0]) ) {
2261 for(i=1; i < val->bv_len; i++) {
2262 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2263 if( dot++ ) return 1;
2264 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2267 return LDAP_INVALID_SYNTAX;
2271 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2273 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2274 for(i=1; i < val->bv_len; i++) {
2275 if( !DESC_CHAR(val->bv_val[i] ) ) {
2276 return LDAP_INVALID_SYNTAX;
2280 return LDAP_SUCCESS;
2283 return LDAP_INVALID_SYNTAX;
2289 struct berval *val )
2293 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2295 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2296 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2297 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2298 return LDAP_INVALID_SYNTAX;
2301 for(i=1; i < val->bv_len; i++) {
2302 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2305 return LDAP_SUCCESS;
2312 struct berval **normalized )
2315 struct berval *newval;
2321 negative = ( *p == '-' );
2322 if( *p == '-' || *p == '+' ) p++;
2324 /* Ignore leading zeros */
2325 while ( *p == '0' ) p++;
2327 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2330 newval->bv_val = ch_strdup("0");
2335 newval->bv_val = ch_malloc( val->bv_len + 1 );
2339 newval->bv_val[newval->bv_len++] = '-';
2342 for( ; *p != '\0'; p++ ) {
2343 newval->bv_val[newval->bv_len++] = *p;
2347 *normalized = newval;
2348 return LDAP_SUCCESS;
2352 countryStringValidate(
2354 struct berval *val )
2356 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2358 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2359 return LDAP_INVALID_SYNTAX;
2361 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2362 return LDAP_INVALID_SYNTAX;
2365 return LDAP_SUCCESS;
2369 printableStringValidate(
2371 struct berval *val )
2375 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2377 for(i=0; i < val->bv_len; i++) {
2378 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2379 return LDAP_INVALID_SYNTAX;
2383 return LDAP_SUCCESS;
2387 printablesStringValidate(
2389 struct berval *val )
2393 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2395 for(i=0; i < val->bv_len; i++) {
2396 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2397 return LDAP_INVALID_SYNTAX;
2401 return LDAP_SUCCESS;
2407 struct berval *val )
2411 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2413 for(i=0; i < val->bv_len; i++) {
2414 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2417 return LDAP_SUCCESS;
2424 struct berval **normalized )
2426 struct berval *newval;
2429 newval = ch_malloc( sizeof( struct berval ) );
2433 /* Ignore initial whitespace */
2434 while ( ASCII_SPACE( *p ) ) {
2440 return LDAP_INVALID_SYNTAX;
2443 newval->bv_val = ch_strdup( p );
2444 p = q = newval->bv_val;
2447 if ( ASCII_SPACE( *p ) ) {
2450 /* Ignore the extra whitespace */
2451 while ( ASCII_SPACE( *p ) ) {
2459 assert( *newval->bv_val );
2460 assert( newval->bv_val < p );
2463 /* cannot start with a space */
2464 assert( !ASCII_SPACE(*newval->bv_val) );
2467 * If the string ended in space, backup the pointer one
2468 * position. One is enough because the above loop collapsed
2469 * all whitespace to a single space.
2472 if ( ASCII_SPACE( q[-1] ) ) {
2476 /* cannot end with a space */
2477 assert( !ASCII_SPACE( q[-1] ) );
2479 /* null terminate */
2482 newval->bv_len = q - newval->bv_val;
2483 *normalized = newval;
2485 return LDAP_SUCCESS;
2494 struct berval *value,
2495 void *assertedValue )
2497 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2500 match = strncmp( value->bv_val,
2501 ((struct berval *) assertedValue)->bv_val,
2506 return LDAP_SUCCESS;
2510 caseExactIA5SubstringsMatch(
2515 struct berval *value,
2516 void *assertedValue )
2519 SubstringsAssertion *sub = assertedValue;
2520 struct berval left = *value;
2524 /* Add up asserted input length */
2525 if( sub->sa_initial ) {
2526 inlen += sub->sa_initial->bv_len;
2529 for(i=0; sub->sa_any[i] != NULL; i++) {
2530 inlen += sub->sa_any[i]->bv_len;
2533 if( sub->sa_final ) {
2534 inlen += sub->sa_final->bv_len;
2537 if( sub->sa_initial ) {
2538 if( inlen > left.bv_len ) {
2543 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2544 sub->sa_initial->bv_len );
2550 left.bv_val += sub->sa_initial->bv_len;
2551 left.bv_len -= sub->sa_initial->bv_len;
2552 inlen -= sub->sa_initial->bv_len;
2555 if( sub->sa_final ) {
2556 if( inlen > left.bv_len ) {
2561 match = strncmp( sub->sa_final->bv_val,
2562 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2563 sub->sa_final->bv_len );
2569 left.bv_len -= sub->sa_final->bv_len;
2570 inlen -= sub->sa_final->bv_len;
2574 for(i=0; sub->sa_any[i]; i++) {
2579 if( inlen > left.bv_len ) {
2580 /* not enough length */
2585 if( sub->sa_any[i]->bv_len == 0 ) {
2589 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2596 idx = p - left.bv_val;
2597 assert( idx < left.bv_len );
2599 if( idx >= left.bv_len ) {
2600 /* this shouldn't happen */
2607 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2608 /* not enough left */
2613 match = strncmp( left.bv_val,
2614 sub->sa_any[i]->bv_val,
2615 sub->sa_any[i]->bv_len );
2623 left.bv_val += sub->sa_any[i]->bv_len;
2624 left.bv_len -= sub->sa_any[i]->bv_len;
2625 inlen -= sub->sa_any[i]->bv_len;
2631 return LDAP_SUCCESS;
2634 /* Index generation function */
2635 int caseExactIA5Indexer(
2640 struct berval *prefix,
2641 struct berval **values,
2642 struct berval ***keysp )
2646 struct berval **keys;
2647 HASH_CONTEXT HASHcontext;
2648 unsigned char HASHdigest[HASH_BYTES];
2649 struct berval digest;
2650 digest.bv_val = HASHdigest;
2651 digest.bv_len = sizeof(HASHdigest);
2653 /* we should have at least one value at this point */
2654 assert( values != NULL && values[0] != NULL );
2656 for( i=0; values[i] != NULL; i++ ) {
2657 /* just count them */
2660 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2662 slen = strlen( syntax->ssyn_oid );
2663 mlen = strlen( mr->smr_oid );
2665 for( i=0; values[i] != NULL; i++ ) {
2666 struct berval *value = values[i];
2668 HASH_Init( &HASHcontext );
2669 if( prefix != NULL && prefix->bv_len > 0 ) {
2670 HASH_Update( &HASHcontext,
2671 prefix->bv_val, prefix->bv_len );
2673 HASH_Update( &HASHcontext,
2674 syntax->ssyn_oid, slen );
2675 HASH_Update( &HASHcontext,
2676 mr->smr_oid, mlen );
2677 HASH_Update( &HASHcontext,
2678 value->bv_val, value->bv_len );
2679 HASH_Final( HASHdigest, &HASHcontext );
2681 keys[i] = ber_bvdup( &digest );
2686 return LDAP_SUCCESS;
2689 /* Index generation function */
2690 int caseExactIA5Filter(
2695 struct berval *prefix,
2697 struct berval ***keysp )
2700 struct berval **keys;
2701 HASH_CONTEXT HASHcontext;
2702 unsigned char HASHdigest[HASH_BYTES];
2703 struct berval *value;
2704 struct berval digest;
2705 digest.bv_val = HASHdigest;
2706 digest.bv_len = sizeof(HASHdigest);
2708 slen = strlen( syntax->ssyn_oid );
2709 mlen = strlen( mr->smr_oid );
2711 value = (struct berval *) assertValue;
2713 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2715 HASH_Init( &HASHcontext );
2716 if( prefix != NULL && prefix->bv_len > 0 ) {
2717 HASH_Update( &HASHcontext,
2718 prefix->bv_val, prefix->bv_len );
2720 HASH_Update( &HASHcontext,
2721 syntax->ssyn_oid, slen );
2722 HASH_Update( &HASHcontext,
2723 mr->smr_oid, mlen );
2724 HASH_Update( &HASHcontext,
2725 value->bv_val, value->bv_len );
2726 HASH_Final( HASHdigest, &HASHcontext );
2728 keys[0] = ber_bvdup( &digest );
2732 return LDAP_SUCCESS;
2735 /* Substrings Index generation function */
2736 int caseExactIA5SubstringsIndexer(
2741 struct berval *prefix,
2742 struct berval **values,
2743 struct berval ***keysp )
2747 struct berval **keys;
2748 HASH_CONTEXT HASHcontext;
2749 unsigned char HASHdigest[HASH_BYTES];
2750 struct berval digest;
2751 digest.bv_val = HASHdigest;
2752 digest.bv_len = sizeof(HASHdigest);
2754 /* we should have at least one value at this point */
2755 assert( values != NULL && values[0] != NULL );
2758 for( i=0; values[i] != NULL; i++ ) {
2759 /* count number of indices to generate */
2760 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2764 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2765 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2766 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2767 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2769 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2773 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2774 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2775 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2779 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2780 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2781 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2782 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2784 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2790 /* no keys to generate */
2792 return LDAP_SUCCESS;
2795 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2797 slen = strlen( syntax->ssyn_oid );
2798 mlen = strlen( mr->smr_oid );
2801 for( i=0; values[i] != NULL; i++ ) {
2803 struct berval *value;
2806 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2808 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2809 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2811 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2812 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2814 for( j=0; j<max; j++ ) {
2815 HASH_Init( &HASHcontext );
2816 if( prefix != NULL && prefix->bv_len > 0 ) {
2817 HASH_Update( &HASHcontext,
2818 prefix->bv_val, prefix->bv_len );
2821 HASH_Update( &HASHcontext,
2822 &pre, sizeof( pre ) );
2823 HASH_Update( &HASHcontext,
2824 syntax->ssyn_oid, slen );
2825 HASH_Update( &HASHcontext,
2826 mr->smr_oid, mlen );
2827 HASH_Update( &HASHcontext,
2829 SLAP_INDEX_SUBSTR_MAXLEN );
2830 HASH_Final( HASHdigest, &HASHcontext );
2832 keys[nkeys++] = ber_bvdup( &digest );
2836 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2837 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2839 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2842 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2843 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2844 HASH_Init( &HASHcontext );
2845 if( prefix != NULL && prefix->bv_len > 0 ) {
2846 HASH_Update( &HASHcontext,
2847 prefix->bv_val, prefix->bv_len );
2849 HASH_Update( &HASHcontext,
2850 &pre, sizeof( pre ) );
2851 HASH_Update( &HASHcontext,
2852 syntax->ssyn_oid, slen );
2853 HASH_Update( &HASHcontext,
2854 mr->smr_oid, mlen );
2855 HASH_Update( &HASHcontext,
2857 HASH_Final( HASHdigest, &HASHcontext );
2859 keys[nkeys++] = ber_bvdup( &digest );
2862 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2863 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2864 HASH_Init( &HASHcontext );
2865 if( prefix != NULL && prefix->bv_len > 0 ) {
2866 HASH_Update( &HASHcontext,
2867 prefix->bv_val, prefix->bv_len );
2869 HASH_Update( &HASHcontext,
2870 &pre, sizeof( pre ) );
2871 HASH_Update( &HASHcontext,
2872 syntax->ssyn_oid, slen );
2873 HASH_Update( &HASHcontext,
2874 mr->smr_oid, mlen );
2875 HASH_Update( &HASHcontext,
2876 &value->bv_val[value->bv_len-j], j );
2877 HASH_Final( HASHdigest, &HASHcontext );
2879 keys[nkeys++] = ber_bvdup( &digest );
2893 return LDAP_SUCCESS;
2896 int caseExactIA5SubstringsFilter(
2901 struct berval *prefix,
2903 struct berval ***keysp )
2905 SubstringsAssertion *sa = assertValue;
2907 ber_len_t nkeys = 0;
2908 size_t slen, mlen, klen;
2909 struct berval **keys;
2910 HASH_CONTEXT HASHcontext;
2911 unsigned char HASHdigest[HASH_BYTES];
2912 struct berval *value;
2913 struct berval digest;
2915 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2916 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2921 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2923 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2924 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2925 /* don't bother accounting for stepping */
2926 nkeys += sa->sa_any[i]->bv_len -
2927 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2932 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2933 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2940 return LDAP_SUCCESS;
2943 digest.bv_val = HASHdigest;
2944 digest.bv_len = sizeof(HASHdigest);
2946 slen = strlen( syntax->ssyn_oid );
2947 mlen = strlen( mr->smr_oid );
2949 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2952 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2953 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2955 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2956 value = sa->sa_initial;
2958 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2959 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2961 HASH_Init( &HASHcontext );
2962 if( prefix != NULL && prefix->bv_len > 0 ) {
2963 HASH_Update( &HASHcontext,
2964 prefix->bv_val, prefix->bv_len );
2966 HASH_Update( &HASHcontext,
2967 &pre, sizeof( pre ) );
2968 HASH_Update( &HASHcontext,
2969 syntax->ssyn_oid, slen );
2970 HASH_Update( &HASHcontext,
2971 mr->smr_oid, mlen );
2972 HASH_Update( &HASHcontext,
2973 value->bv_val, klen );
2974 HASH_Final( HASHdigest, &HASHcontext );
2976 keys[nkeys++] = ber_bvdup( &digest );
2979 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2981 pre = SLAP_INDEX_SUBSTR_PREFIX;
2982 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2984 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2985 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2989 value = sa->sa_any[i];
2992 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2993 j += SLAP_INDEX_SUBSTR_STEP )
2995 HASH_Init( &HASHcontext );
2996 if( prefix != NULL && prefix->bv_len > 0 ) {
2997 HASH_Update( &HASHcontext,
2998 prefix->bv_val, prefix->bv_len );
3000 HASH_Update( &HASHcontext,
3001 &pre, sizeof( pre ) );
3002 HASH_Update( &HASHcontext,
3003 syntax->ssyn_oid, slen );
3004 HASH_Update( &HASHcontext,
3005 mr->smr_oid, mlen );
3006 HASH_Update( &HASHcontext,
3007 &value->bv_val[j], klen );
3008 HASH_Final( HASHdigest, &HASHcontext );
3010 keys[nkeys++] = ber_bvdup( &digest );
3015 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3016 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3018 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3019 value = sa->sa_final;
3021 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3022 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3024 HASH_Init( &HASHcontext );
3025 if( prefix != NULL && prefix->bv_len > 0 ) {
3026 HASH_Update( &HASHcontext,
3027 prefix->bv_val, prefix->bv_len );
3029 HASH_Update( &HASHcontext,
3030 &pre, sizeof( pre ) );
3031 HASH_Update( &HASHcontext,
3032 syntax->ssyn_oid, slen );
3033 HASH_Update( &HASHcontext,
3034 mr->smr_oid, mlen );
3035 HASH_Update( &HASHcontext,
3036 &value->bv_val[value->bv_len-klen], klen );
3037 HASH_Final( HASHdigest, &HASHcontext );
3039 keys[nkeys++] = ber_bvdup( &digest );
3050 return LDAP_SUCCESS;
3059 struct berval *value,
3060 void *assertedValue )
3062 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3064 if( match == 0 && value->bv_len ) {
3065 match = strncasecmp( value->bv_val,
3066 ((struct berval *) assertedValue)->bv_val,
3071 return LDAP_SUCCESS;
3075 caseIgnoreIA5SubstringsMatch(
3080 struct berval *value,
3081 void *assertedValue )
3084 SubstringsAssertion *sub = assertedValue;
3085 struct berval left = *value;
3089 /* Add up asserted input length */
3090 if( sub->sa_initial ) {
3091 inlen += sub->sa_initial->bv_len;
3094 for(i=0; sub->sa_any[i] != NULL; i++) {
3095 inlen += sub->sa_any[i]->bv_len;
3098 if( sub->sa_final ) {
3099 inlen += sub->sa_final->bv_len;
3102 if( sub->sa_initial ) {
3103 if( inlen > left.bv_len ) {
3108 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3109 sub->sa_initial->bv_len );
3115 left.bv_val += sub->sa_initial->bv_len;
3116 left.bv_len -= sub->sa_initial->bv_len;
3117 inlen -= sub->sa_initial->bv_len;
3120 if( sub->sa_final ) {
3121 if( inlen > left.bv_len ) {
3126 match = strncasecmp( sub->sa_final->bv_val,
3127 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3128 sub->sa_final->bv_len );
3134 left.bv_len -= sub->sa_final->bv_len;
3135 inlen -= sub->sa_final->bv_len;
3139 for(i=0; sub->sa_any[i]; i++) {
3144 if( inlen > left.bv_len ) {
3145 /* not enough length */
3150 if( sub->sa_any[i]->bv_len == 0 ) {
3154 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3161 idx = p - left.bv_val;
3162 assert( idx < left.bv_len );
3164 if( idx >= left.bv_len ) {
3165 /* this shouldn't happen */
3172 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3173 /* not enough left */
3178 match = strncasecmp( left.bv_val,
3179 sub->sa_any[i]->bv_val,
3180 sub->sa_any[i]->bv_len );
3189 left.bv_val += sub->sa_any[i]->bv_len;
3190 left.bv_len -= sub->sa_any[i]->bv_len;
3191 inlen -= sub->sa_any[i]->bv_len;
3197 return LDAP_SUCCESS;
3200 /* Index generation function */
3201 int caseIgnoreIA5Indexer(
3206 struct berval *prefix,
3207 struct berval **values,
3208 struct berval ***keysp )
3212 struct berval **keys;
3213 HASH_CONTEXT HASHcontext;
3214 unsigned char HASHdigest[HASH_BYTES];
3215 struct berval digest;
3216 digest.bv_val = HASHdigest;
3217 digest.bv_len = sizeof(HASHdigest);
3219 /* we should have at least one value at this point */
3220 assert( values != NULL && values[0] != NULL );
3222 for( i=0; values[i] != NULL; i++ ) {
3223 /* just count them */
3226 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3228 slen = strlen( syntax->ssyn_oid );
3229 mlen = strlen( mr->smr_oid );
3231 for( i=0; values[i] != NULL; i++ ) {
3232 struct berval *value = ber_bvdup( values[i] );
3233 ldap_pvt_str2upper( value->bv_val );
3235 HASH_Init( &HASHcontext );
3236 if( prefix != NULL && prefix->bv_len > 0 ) {
3237 HASH_Update( &HASHcontext,
3238 prefix->bv_val, prefix->bv_len );
3240 HASH_Update( &HASHcontext,
3241 syntax->ssyn_oid, slen );
3242 HASH_Update( &HASHcontext,
3243 mr->smr_oid, mlen );
3244 HASH_Update( &HASHcontext,
3245 value->bv_val, value->bv_len );
3246 HASH_Final( HASHdigest, &HASHcontext );
3248 ber_bvfree( value );
3250 keys[i] = ber_bvdup( &digest );
3255 return LDAP_SUCCESS;
3258 /* Index generation function */
3259 int caseIgnoreIA5Filter(
3264 struct berval *prefix,
3266 struct berval ***keysp )
3269 struct berval **keys;
3270 HASH_CONTEXT HASHcontext;
3271 unsigned char HASHdigest[HASH_BYTES];
3272 struct berval *value;
3273 struct berval digest;
3274 digest.bv_val = HASHdigest;
3275 digest.bv_len = sizeof(HASHdigest);
3277 slen = strlen( syntax->ssyn_oid );
3278 mlen = strlen( mr->smr_oid );
3280 value = ber_bvdup( (struct berval *) assertValue );
3281 ldap_pvt_str2upper( value->bv_val );
3283 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3285 HASH_Init( &HASHcontext );
3286 if( prefix != NULL && prefix->bv_len > 0 ) {
3287 HASH_Update( &HASHcontext,
3288 prefix->bv_val, prefix->bv_len );
3290 HASH_Update( &HASHcontext,
3291 syntax->ssyn_oid, slen );
3292 HASH_Update( &HASHcontext,
3293 mr->smr_oid, mlen );
3294 HASH_Update( &HASHcontext,
3295 value->bv_val, value->bv_len );
3296 HASH_Final( HASHdigest, &HASHcontext );
3298 keys[0] = ber_bvdup( &digest );
3301 ber_bvfree( value );
3305 return LDAP_SUCCESS;
3308 /* Substrings Index generation function */
3309 int caseIgnoreIA5SubstringsIndexer(
3314 struct berval *prefix,
3315 struct berval **values,
3316 struct berval ***keysp )
3320 struct berval **keys;
3321 HASH_CONTEXT HASHcontext;
3322 unsigned char HASHdigest[HASH_BYTES];
3323 struct berval digest;
3324 digest.bv_val = HASHdigest;
3325 digest.bv_len = sizeof(HASHdigest);
3327 /* we should have at least one value at this point */
3328 assert( values != NULL && values[0] != NULL );
3331 for( i=0; values[i] != NULL; i++ ) {
3332 /* count number of indices to generate */
3333 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3337 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3338 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3339 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3340 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3342 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3346 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3347 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3348 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3352 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3353 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3354 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3355 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3357 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3363 /* no keys to generate */
3365 return LDAP_SUCCESS;
3368 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3370 slen = strlen( syntax->ssyn_oid );
3371 mlen = strlen( mr->smr_oid );
3374 for( i=0; values[i] != NULL; i++ ) {
3376 struct berval *value;
3378 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3380 value = ber_bvdup( values[i] );
3381 ldap_pvt_str2upper( value->bv_val );
3383 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3384 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3386 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3387 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3389 for( j=0; j<max; j++ ) {
3390 HASH_Init( &HASHcontext );
3391 if( prefix != NULL && prefix->bv_len > 0 ) {
3392 HASH_Update( &HASHcontext,
3393 prefix->bv_val, prefix->bv_len );
3396 HASH_Update( &HASHcontext,
3397 &pre, sizeof( pre ) );
3398 HASH_Update( &HASHcontext,
3399 syntax->ssyn_oid, slen );
3400 HASH_Update( &HASHcontext,
3401 mr->smr_oid, mlen );
3402 HASH_Update( &HASHcontext,
3404 SLAP_INDEX_SUBSTR_MAXLEN );
3405 HASH_Final( HASHdigest, &HASHcontext );
3407 keys[nkeys++] = ber_bvdup( &digest );
3411 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3412 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3414 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3417 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3418 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3419 HASH_Init( &HASHcontext );
3420 if( prefix != NULL && prefix->bv_len > 0 ) {
3421 HASH_Update( &HASHcontext,
3422 prefix->bv_val, prefix->bv_len );
3424 HASH_Update( &HASHcontext,
3425 &pre, sizeof( pre ) );
3426 HASH_Update( &HASHcontext,
3427 syntax->ssyn_oid, slen );
3428 HASH_Update( &HASHcontext,
3429 mr->smr_oid, mlen );
3430 HASH_Update( &HASHcontext,
3432 HASH_Final( HASHdigest, &HASHcontext );
3434 keys[nkeys++] = ber_bvdup( &digest );
3437 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3438 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3439 HASH_Init( &HASHcontext );
3440 if( prefix != NULL && prefix->bv_len > 0 ) {
3441 HASH_Update( &HASHcontext,
3442 prefix->bv_val, prefix->bv_len );
3444 HASH_Update( &HASHcontext,
3445 &pre, sizeof( pre ) );
3446 HASH_Update( &HASHcontext,
3447 syntax->ssyn_oid, slen );
3448 HASH_Update( &HASHcontext,
3449 mr->smr_oid, mlen );
3450 HASH_Update( &HASHcontext,
3451 &value->bv_val[value->bv_len-j], j );
3452 HASH_Final( HASHdigest, &HASHcontext );
3454 keys[nkeys++] = ber_bvdup( &digest );
3459 ber_bvfree( value );
3470 return LDAP_SUCCESS;
3473 int caseIgnoreIA5SubstringsFilter(
3478 struct berval *prefix,
3480 struct berval ***keysp )
3482 SubstringsAssertion *sa = assertValue;
3484 ber_len_t nkeys = 0;
3485 size_t slen, mlen, klen;
3486 struct berval **keys;
3487 HASH_CONTEXT HASHcontext;
3488 unsigned char HASHdigest[HASH_BYTES];
3489 struct berval *value;
3490 struct berval digest;
3492 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3493 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3498 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3500 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3501 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3502 /* don't bother accounting for stepping */
3503 nkeys += sa->sa_any[i]->bv_len -
3504 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3509 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3510 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3517 return LDAP_SUCCESS;
3520 digest.bv_val = HASHdigest;
3521 digest.bv_len = sizeof(HASHdigest);
3523 slen = strlen( syntax->ssyn_oid );
3524 mlen = strlen( mr->smr_oid );
3526 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3529 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3530 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3532 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3533 value = ber_bvdup( sa->sa_initial );
3534 ldap_pvt_str2upper( value->bv_val );
3536 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3537 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3539 HASH_Init( &HASHcontext );
3540 if( prefix != NULL && prefix->bv_len > 0 ) {
3541 HASH_Update( &HASHcontext,
3542 prefix->bv_val, prefix->bv_len );
3544 HASH_Update( &HASHcontext,
3545 &pre, sizeof( pre ) );
3546 HASH_Update( &HASHcontext,
3547 syntax->ssyn_oid, slen );
3548 HASH_Update( &HASHcontext,
3549 mr->smr_oid, mlen );
3550 HASH_Update( &HASHcontext,
3551 value->bv_val, klen );
3552 HASH_Final( HASHdigest, &HASHcontext );
3554 ber_bvfree( value );
3555 keys[nkeys++] = ber_bvdup( &digest );
3558 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3560 pre = SLAP_INDEX_SUBSTR_PREFIX;
3561 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3563 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3564 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3568 value = ber_bvdup( sa->sa_any[i] );
3569 ldap_pvt_str2upper( value->bv_val );
3572 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3573 j += SLAP_INDEX_SUBSTR_STEP )
3575 HASH_Init( &HASHcontext );
3576 if( prefix != NULL && prefix->bv_len > 0 ) {
3577 HASH_Update( &HASHcontext,
3578 prefix->bv_val, prefix->bv_len );
3580 HASH_Update( &HASHcontext,
3581 &pre, sizeof( pre ) );
3582 HASH_Update( &HASHcontext,
3583 syntax->ssyn_oid, slen );
3584 HASH_Update( &HASHcontext,
3585 mr->smr_oid, mlen );
3586 HASH_Update( &HASHcontext,
3587 &value->bv_val[j], klen );
3588 HASH_Final( HASHdigest, &HASHcontext );
3590 keys[nkeys++] = ber_bvdup( &digest );
3593 ber_bvfree( value );
3597 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3598 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3600 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3601 value = ber_bvdup( sa->sa_final );
3602 ldap_pvt_str2upper( value->bv_val );
3604 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3605 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3607 HASH_Init( &HASHcontext );
3608 if( prefix != NULL && prefix->bv_len > 0 ) {
3609 HASH_Update( &HASHcontext,
3610 prefix->bv_val, prefix->bv_len );
3612 HASH_Update( &HASHcontext,
3613 &pre, sizeof( pre ) );
3614 HASH_Update( &HASHcontext,
3615 syntax->ssyn_oid, slen );
3616 HASH_Update( &HASHcontext,
3617 mr->smr_oid, mlen );
3618 HASH_Update( &HASHcontext,
3619 &value->bv_val[value->bv_len-klen], klen );
3620 HASH_Final( HASHdigest, &HASHcontext );
3622 ber_bvfree( value );
3623 keys[nkeys++] = ber_bvdup( &digest );
3634 return LDAP_SUCCESS;
3638 numericStringValidate(
3644 for(i=0; i < in->bv_len; i++) {
3645 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3646 return LDAP_INVALID_SYNTAX;
3650 return LDAP_SUCCESS;
3654 numericStringNormalize(
3657 struct berval **normalized )
3659 /* removal all spaces */
3660 struct berval *newval;
3663 newval = ch_malloc( sizeof( struct berval ) );
3664 newval->bv_val = ch_malloc( val->bv_len + 1 );
3670 if ( ASCII_SPACE( *p ) ) {
3671 /* Ignore whitespace */
3678 assert( newval->bv_val <= p );
3681 /* null terminate */
3684 newval->bv_len = q - newval->bv_val;
3685 *normalized = newval;
3687 return LDAP_SUCCESS;
3691 objectIdentifierFirstComponentMatch(
3696 struct berval *value,
3697 void *assertedValue )
3699 int rc = LDAP_SUCCESS;
3701 struct berval *asserted = (struct berval *) assertedValue;
3705 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3706 return LDAP_INVALID_SYNTAX;
3709 /* trim leading white space */
3710 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3714 /* grab next word */
3715 oid.bv_val = &value->bv_val[i];
3716 oid.bv_len = value->bv_len - i;
3717 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3722 /* insert attributeTypes, objectclass check here */
3723 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3724 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3727 char *stored = ch_malloc( oid.bv_len + 1 );
3728 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3729 stored[oid.bv_len] = '\0';
3731 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3732 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3733 MatchingRule *stored_mr = mr_find( stored );
3735 if( asserted_mr == NULL ) {
3736 rc = SLAPD_COMPARE_UNDEFINED;
3738 match = asserted_mr != stored_mr;
3741 } else if ( !strcmp( syntax->ssyn_oid,
3742 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3744 AttributeType *asserted_at = at_find( asserted->bv_val );
3745 AttributeType *stored_at = at_find( stored );
3747 if( asserted_at == NULL ) {
3748 rc = SLAPD_COMPARE_UNDEFINED;
3750 match = asserted_at != stored_at;
3753 } else if ( !strcmp( syntax->ssyn_oid,
3754 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3756 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3757 ObjectClass *stored_oc = oc_find( stored );
3759 if( asserted_oc == NULL ) {
3760 rc = SLAPD_COMPARE_UNDEFINED;
3762 match = asserted_oc != stored_oc;
3770 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3771 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3772 match, value->bv_val, asserted->bv_val ));
3774 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3775 "%d\n\t\"%s\"\n\t\"%s\"\n",
3776 match, value->bv_val, asserted->bv_val );
3780 if( rc == LDAP_SUCCESS ) *matchp = match;
3785 check_time_syntax (struct berval *val,
3789 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3790 static int mdays[2][12] = {
3791 /* non-leap years */
3792 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3794 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3797 int part, c, tzoffset, leapyear = 0 ;
3799 if( val->bv_len == 0 ) {
3800 return LDAP_INVALID_SYNTAX;
3803 p = (char *)val->bv_val;
3804 e = p + val->bv_len;
3806 /* Ignore initial whitespace */
3807 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3811 if (e - p < 13 - (2 * start)) {
3812 return LDAP_INVALID_SYNTAX;
3815 for (part = 0; part < 9; part++) {
3819 for (part = start; part < 7; part++) {
3821 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3828 return LDAP_INVALID_SYNTAX;
3830 if (c < 0 || c > 9) {
3831 return LDAP_INVALID_SYNTAX;
3837 return LDAP_INVALID_SYNTAX;
3839 if (c < 0 || c > 9) {
3840 return LDAP_INVALID_SYNTAX;
3845 if (part == 2 || part == 3) {
3848 if (parts[part] < 0) {
3849 return LDAP_INVALID_SYNTAX;
3851 if (parts[part] > ceiling[part]) {
3852 return LDAP_INVALID_SYNTAX;
3856 /* leapyear check for the Gregorian calendar (year>1581) */
3857 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3858 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3863 if (parts[3] > mdays[leapyear][parts[2]]) {
3864 return LDAP_INVALID_SYNTAX;
3869 tzoffset = 0; /* UTC */
3870 } else if (c != '+' && c != '-') {
3871 return LDAP_INVALID_SYNTAX;
3875 } else /* c == '+' */ {
3880 return LDAP_INVALID_SYNTAX;
3883 for (part = 7; part < 9; part++) {
3885 if (c < 0 || c > 9) {
3886 return LDAP_INVALID_SYNTAX;
3891 if (c < 0 || c > 9) {
3892 return LDAP_INVALID_SYNTAX;
3896 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3897 return LDAP_INVALID_SYNTAX;
3902 /* Ignore trailing whitespace */
3903 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3907 return LDAP_INVALID_SYNTAX;
3910 switch ( tzoffset ) {
3911 case -1: /* negativ offset to UTC, ie west of Greenwich */
3912 parts[4] += parts[7];
3913 parts[5] += parts[8];
3914 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3918 c = mdays[leapyear][parts[2]];
3920 if (parts[part] > c) {
3921 parts[part] -= c + 1;
3926 case 1: /* positive offset to UTC, ie east of Greenwich */
3927 parts[4] -= parts[7];
3928 parts[5] -= parts[8];
3929 for (part = 6; --part > 0; ) {
3933 /* first arg to % needs to be non negativ */
3934 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3936 if (parts[part] < 0) {
3937 parts[part] += c + 1;
3942 case 0: /* already UTC */
3946 return LDAP_SUCCESS;
3953 struct berval **normalized )
3958 rc = check_time_syntax(val, 1, parts);
3959 if (rc != LDAP_SUCCESS) {
3964 out = ch_malloc( sizeof(struct berval) );
3966 return LBER_ERROR_MEMORY;
3969 out->bv_val = ch_malloc( 14 );
3970 if ( out->bv_val == NULL ) {
3972 return LBER_ERROR_MEMORY;
3975 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3976 parts[1], parts[2] + 1, parts[3] + 1,
3977 parts[4], parts[5], parts[6] );
3981 return LDAP_SUCCESS;
3991 return check_time_syntax(in, 1, parts);
3995 generalizedTimeValidate(
4001 return check_time_syntax(in, 0, parts);
4005 generalizedTimeNormalize(
4008 struct berval **normalized )
4013 rc = check_time_syntax(val, 0, parts);
4014 if (rc != LDAP_SUCCESS) {
4019 out = ch_malloc( sizeof(struct berval) );
4021 return LBER_ERROR_MEMORY;
4024 out->bv_val = ch_malloc( 16 );
4025 if ( out->bv_val == NULL ) {
4027 return LBER_ERROR_MEMORY;
4030 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4031 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4032 parts[4], parts[5], parts[6] );
4036 return LDAP_SUCCESS;
4040 nisNetgroupTripleValidate(
4042 struct berval *val )
4047 if ( val->bv_len == 0 ) {
4048 return LDAP_INVALID_SYNTAX;
4051 p = (char *)val->bv_val;
4052 e = p + val->bv_len;
4055 /* syntax does not allow leading white space */
4056 /* Ignore initial whitespace */
4057 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4062 if ( *p != '(' /*')'*/ ) {
4063 return LDAP_INVALID_SYNTAX;
4066 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4070 return LDAP_INVALID_SYNTAX;
4073 } else if ( !ATTR_CHAR( *p ) ) {
4074 return LDAP_INVALID_SYNTAX;
4078 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4079 return LDAP_INVALID_SYNTAX;
4085 /* syntax does not allow trailing white space */
4086 /* Ignore trailing whitespace */
4087 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4093 return LDAP_INVALID_SYNTAX;
4096 return LDAP_SUCCESS;
4100 bootParameterValidate(
4102 struct berval *val )
4106 if ( val->bv_len == 0 ) {
4107 return LDAP_INVALID_SYNTAX;
4110 p = (char *)val->bv_val;
4111 e = p + val->bv_len;
4114 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4115 if ( !ATTR_CHAR( *p ) ) {
4116 return LDAP_INVALID_SYNTAX;
4121 return LDAP_INVALID_SYNTAX;
4125 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4126 if ( !ATTR_CHAR( *p ) ) {
4127 return LDAP_INVALID_SYNTAX;
4132 return LDAP_INVALID_SYNTAX;
4136 for ( p++; p < e; p++ ) {
4137 if ( !ATTR_CHAR( *p ) ) {
4138 return LDAP_INVALID_SYNTAX;
4142 return LDAP_SUCCESS;
4145 struct syntax_defs_rec {
4148 slap_syntax_validate_func *sd_validate;
4149 slap_syntax_transform_func *sd_normalize;
4150 slap_syntax_transform_func *sd_pretty;
4151 #ifdef SLAPD_BINARY_CONVERSION
4152 slap_syntax_transform_func *sd_ber2str;
4153 slap_syntax_transform_func *sd_str2ber;
4157 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4158 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4160 struct syntax_defs_rec syntax_defs[] = {
4161 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4162 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4164 0, NULL, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4166 0, NULL, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4168 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4170 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4172 0, bitStringValidate, NULL, NULL },
4173 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4174 0, booleanValidate, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4176 X_BINARY X_NOT_H_R ")",
4177 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4179 X_BINARY X_NOT_H_R ")",
4180 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
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.11 DESC 'Country String' )",
4185 0, countryStringValidate, IA5StringNormalize, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4187 0, dnValidate, dnNormalize, dnPretty},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4189 0, NULL, NULL, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4191 0, NULL, NULL, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4193 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4195 0, NULL, NULL, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4197 0, NULL, NULL, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4199 0, NULL, NULL, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4201 0, NULL, NULL, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4203 0, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4205 0, printablesStringValidate, IA5StringNormalize, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4207 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4209 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4211 0, NULL, NULL, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4213 0, IA5StringValidate, IA5StringNormalize, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4215 0, integerValidate, integerNormalize, integerPretty},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4217 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4219 0, NULL, NULL, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4221 0, NULL, NULL, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4223 0, NULL, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4225 0, NULL, NULL, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4227 0, NULL, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4229 0, nameUIDValidate, nameUIDNormalize, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4231 0, NULL, NULL, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4233 0, numericStringValidate, numericStringNormalize, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4235 0, NULL, NULL, NULL},
4236 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4237 0, oidValidate, NULL, NULL},
4238 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4239 0, IA5StringValidate, IA5StringNormalize, NULL},
4240 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4241 0, blobValidate, NULL, NULL},
4242 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4243 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4244 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4245 0, NULL, NULL, NULL},
4246 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4247 0, NULL, NULL, NULL},
4248 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4249 0, printableStringValidate, IA5StringNormalize, NULL},
4250 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4251 X_BINARY X_NOT_H_R ")",
4252 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4253 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4254 0, printableStringValidate, IA5StringNormalize, NULL},
4255 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4256 0, NULL, NULL, NULL},
4257 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4258 0, printableStringValidate, IA5StringNormalize, NULL},
4259 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4260 0, utcTimeValidate, utcTimeNormalize, NULL},
4261 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4262 0, NULL, NULL, NULL},
4263 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4264 0, NULL, NULL, NULL},
4265 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4266 0, NULL, NULL, NULL},
4267 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4268 0, NULL, NULL, NULL},
4269 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4270 0, NULL, NULL, NULL},
4272 /* RFC 2307 NIS Syntaxes */
4273 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4274 0, nisNetgroupTripleValidate, NULL, NULL},
4275 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4276 0, bootParameterValidate, NULL, NULL},
4278 /* OpenLDAP Experimental Syntaxes */
4279 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4280 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4282 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4283 0, NULL, NULL, NULL},
4285 /* OpenLDAP Void Syntax */
4286 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4287 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4288 {NULL, 0, NULL, NULL, NULL}
4291 struct mrule_defs_rec {
4293 slap_mask_t mrd_usage;
4294 slap_mr_convert_func * mrd_convert;
4295 slap_mr_normalize_func * mrd_normalize;
4296 slap_mr_match_func * mrd_match;
4297 slap_mr_indexer_func * mrd_indexer;
4298 slap_mr_filter_func * mrd_filter;
4300 char * mrd_associated;
4304 * Other matching rules in X.520 that we do not use (yet):
4306 * 2.5.13.9 numericStringOrderingMatch
4307 * 2.5.13.15 integerOrderingMatch
4308 * 2.5.13.18 octetStringOrderingMatch
4309 * 2.5.13.19 octetStringSubstringsMatch
4310 * 2.5.13.25 uTCTimeMatch
4311 * 2.5.13.26 uTCTimeOrderingMatch
4312 * 2.5.13.31 directoryStringFirstComponentMatch
4313 * 2.5.13.32 wordMatch
4314 * 2.5.13.33 keywordMatch
4315 * 2.5.13.34 certificateExactMatch
4316 * 2.5.13.35 certificateMatch
4317 * 2.5.13.36 certificatePairExactMatch
4318 * 2.5.13.37 certificatePairMatch
4319 * 2.5.13.38 certificateListExactMatch
4320 * 2.5.13.39 certificateListMatch
4321 * 2.5.13.40 algorithmIdentifierMatch
4322 * 2.5.13.41 storedPrefixMatch
4323 * 2.5.13.42 attributeCertificateMatch
4324 * 2.5.13.43 readerAndKeyIDMatch
4325 * 2.5.13.44 attributeIntegrityMatch
4328 struct mrule_defs_rec mrule_defs[] = {
4330 * EQUALITY matching rules must be listed after associated APPROX
4331 * matching rules. So, we list all APPROX matching rules first.
4333 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4334 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4335 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4337 directoryStringApproxMatch,
4338 directoryStringApproxIndexer,
4339 directoryStringApproxFilter,
4342 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4343 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4344 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4346 IA5StringApproxMatch,
4347 IA5StringApproxIndexer,
4348 IA5StringApproxFilter,
4352 * Other matching rules
4355 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4356 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4357 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4359 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4362 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4363 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4364 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4366 dnMatch, dnIndexer, dnFilter,
4369 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4370 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4371 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4373 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4374 directoryStringApproxMatchOID },
4376 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4377 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4380 caseIgnoreOrderingMatch, NULL, NULL,
4383 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4384 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4385 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4387 caseIgnoreSubstringsMatch,
4388 caseIgnoreSubstringsIndexer,
4389 caseIgnoreSubstringsFilter,
4392 {"( 2.5.13.5 NAME 'caseExactMatch' "
4393 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4394 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4396 caseExactMatch, caseExactIndexer, caseExactFilter,
4397 directoryStringApproxMatchOID },
4399 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4400 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4403 caseExactOrderingMatch, NULL, NULL,
4406 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4407 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4408 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4410 caseExactSubstringsMatch,
4411 caseExactSubstringsIndexer,
4412 caseExactSubstringsFilter,
4415 {"( 2.5.13.8 NAME 'numericStringMatch' "
4416 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4417 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4420 caseIgnoreIA5Indexer,
4421 caseIgnoreIA5Filter,
4424 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4425 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4426 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4428 caseIgnoreIA5SubstringsMatch,
4429 caseIgnoreIA5SubstringsIndexer,
4430 caseIgnoreIA5SubstringsFilter,
4433 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4434 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4435 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4437 caseIgnoreListMatch, NULL, NULL,
4440 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4441 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4442 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4444 caseIgnoreListSubstringsMatch, NULL, NULL,
4447 {"( 2.5.13.13 NAME 'booleanMatch' "
4448 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4449 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4451 booleanMatch, NULL, NULL,
4454 {"( 2.5.13.14 NAME 'integerMatch' "
4455 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4456 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4458 integerMatch, integerIndexer, integerFilter,
4461 {"( 2.5.13.16 NAME 'bitStringMatch' "
4462 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4463 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4465 bitStringMatch, NULL, NULL,
4468 {"( 2.5.13.17 NAME 'octetStringMatch' "
4469 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4470 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4472 octetStringMatch, octetStringIndexer, octetStringFilter,
4475 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4476 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4477 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4479 telephoneNumberMatch,
4480 telephoneNumberIndexer,
4481 telephoneNumberFilter,
4484 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4485 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4486 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4488 telephoneNumberSubstringsMatch,
4489 telephoneNumberSubstringsIndexer,
4490 telephoneNumberSubstringsFilter,
4493 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4494 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4495 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4500 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4501 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4502 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4504 uniqueMemberMatch, NULL, NULL,
4507 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4508 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4509 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4511 protocolInformationMatch, NULL, NULL,
4514 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4515 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4516 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4518 generalizedTimeMatch, NULL, NULL,
4521 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4522 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4525 generalizedTimeOrderingMatch, NULL, NULL,
4528 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4529 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4530 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4532 integerFirstComponentMatch, NULL, NULL,
4535 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4536 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4537 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4539 objectIdentifierFirstComponentMatch, NULL, NULL,
4542 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4543 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4544 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4546 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4547 IA5StringApproxMatchOID },
4549 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4550 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4551 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4553 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4554 IA5StringApproxMatchOID },
4556 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4557 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4560 caseIgnoreIA5SubstringsMatch,
4561 caseIgnoreIA5SubstringsIndexer,
4562 caseIgnoreIA5SubstringsFilter,
4565 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4566 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4569 caseExactIA5SubstringsMatch,
4570 caseExactIA5SubstringsIndexer,
4571 caseExactIA5SubstringsFilter,
4574 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4575 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4578 authPasswordMatch, NULL, NULL,
4581 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4582 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4585 OpenLDAPaciMatch, NULL, NULL,
4588 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4597 /* we should only be called once (from main) */
4598 assert( schema_init_done == 0 );
4600 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4601 res = register_syntax( syntax_defs[i].sd_desc,
4602 syntax_defs[i].sd_flags,
4603 syntax_defs[i].sd_validate,
4604 syntax_defs[i].sd_normalize,
4605 syntax_defs[i].sd_pretty
4606 #ifdef SLAPD_BINARY_CONVERSION
4608 syntax_defs[i].sd_ber2str,
4609 syntax_defs[i].sd_str2ber
4614 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4615 syntax_defs[i].sd_desc );
4620 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4621 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4623 "schema_init: Ingoring unusable matching rule %s\n",
4624 mrule_defs[i].mrd_desc );
4628 res = register_matching_rule(
4629 mrule_defs[i].mrd_desc,
4630 mrule_defs[i].mrd_usage,
4631 mrule_defs[i].mrd_convert,
4632 mrule_defs[i].mrd_normalize,
4633 mrule_defs[i].mrd_match,
4634 mrule_defs[i].mrd_indexer,
4635 mrule_defs[i].mrd_filter,
4636 mrule_defs[i].mrd_associated );
4640 "schema_init: Error registering matching rule %s\n",
4641 mrule_defs[i].mrd_desc );
4645 schema_init_done = 1;
4646 return LDAP_SUCCESS;