1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
15 #include <ac/string.h>
16 #include <ac/socket.h>
21 #include "ldap_utf8.h"
23 #include "lutil_hash.h"
24 #define HASH_BYTES LUTIL_HASH_BYTES
25 #define HASH_CONTEXT lutil_HASH_CTX
26 #define HASH_Init(c) lutil_HASHInit(c)
27 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
28 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
30 /* recycled validatation routines */
31 #define berValidate blobValidate
33 /* unimplemented pretters */
34 #define integerPretty NULL
36 /* recycled matching routines */
37 #define bitStringMatch octetStringMatch
38 #define numericStringMatch caseIgnoreIA5Match
39 #define objectIdentifierMatch caseIgnoreIA5Match
40 #define telephoneNumberMatch caseIgnoreIA5Match
41 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
42 #define generalizedTimeMatch caseIgnoreIA5Match
43 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
44 #define uniqueMemberMatch dnMatch
46 /* approx matching rules */
47 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
48 #define directoryStringApproxMatch approxMatch
49 #define directoryStringApproxIndexer approxIndexer
50 #define directoryStringApproxFilter approxFilter
51 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
52 #define IA5StringApproxMatch approxMatch
53 #define IA5StringApproxIndexer approxIndexer
54 #define IA5StringApproxFilter approxFilter
56 /* orderring matching rules */
57 #define caseIgnoreOrderingMatch caseIgnoreMatch
58 #define caseExactOrderingMatch caseExactMatch
60 /* unimplemented matching routines */
61 #define caseIgnoreListMatch NULL
62 #define caseIgnoreListSubstringsMatch NULL
63 #define protocolInformationMatch NULL
64 #define integerFirstComponentMatch NULL
66 #define OpenLDAPaciMatch NULL
67 #define authPasswordMatch NULL
69 /* recycled indexing/filtering routines */
70 #define dnIndexer caseExactIgnoreIndexer
71 #define dnFilter caseExactIgnoreFilter
72 #define bitStringFilter octetStringFilter
73 #define bitStringIndexer octetStringIndexer
75 #define telephoneNumberIndexer caseIgnoreIA5Indexer
76 #define telephoneNumberFilter caseIgnoreIA5Filter
77 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
78 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
80 /* must match OIDs below */
81 #define caseExactMatchOID "2.5.13.5"
82 #define caseExactSubstringsMatchOID "2.5.13.7"
84 static char *strcasechr( const char *str, int c )
86 char *lower = strchr( str, TOLOWER(c) );
87 char *upper = strchr( str, TOUPPER(c) );
89 if( lower && upper ) {
90 return lower < upper ? lower : upper;
104 struct berval *value,
105 void *assertedValue )
107 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
110 match = memcmp( value->bv_val,
111 ((struct berval *) assertedValue)->bv_val,
119 /* Index generation function */
120 static int octetStringIndexer(
125 struct berval *prefix,
132 HASH_CONTEXT HASHcontext;
133 unsigned char HASHdigest[HASH_BYTES];
134 struct berval digest;
135 digest.bv_val = HASHdigest;
136 digest.bv_len = sizeof(HASHdigest);
138 for( i=0; values[i].bv_val != NULL; i++ ) {
139 /* just count them */
142 /* we should have at least one value at this point */
145 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
147 slen = syntax->ssyn_oidlen;
148 mlen = mr->smr_oidlen;
150 for( i=0; values[i].bv_val != NULL; i++ ) {
151 HASH_Init( &HASHcontext );
152 if( prefix != NULL && prefix->bv_len > 0 ) {
153 HASH_Update( &HASHcontext,
154 prefix->bv_val, prefix->bv_len );
156 HASH_Update( &HASHcontext,
157 syntax->ssyn_oid, slen );
158 HASH_Update( &HASHcontext,
160 HASH_Update( &HASHcontext,
161 values[i].bv_val, values[i].bv_len );
162 HASH_Final( HASHdigest, &HASHcontext );
164 ber_dupbv( &keys[i], &digest );
167 keys[i].bv_val = NULL;
174 /* Index generation function */
175 static int octetStringFilter(
180 struct berval *prefix,
186 HASH_CONTEXT HASHcontext;
187 unsigned char HASHdigest[HASH_BYTES];
188 struct berval *value = (struct berval *) assertValue;
189 struct berval digest;
190 digest.bv_val = HASHdigest;
191 digest.bv_len = sizeof(HASHdigest);
193 slen = syntax->ssyn_oidlen;
194 mlen = mr->smr_oidlen;
196 keys = ch_malloc( sizeof( struct berval ) * 2 );
198 HASH_Init( &HASHcontext );
199 if( prefix != NULL && prefix->bv_len > 0 ) {
200 HASH_Update( &HASHcontext,
201 prefix->bv_val, prefix->bv_len );
203 HASH_Update( &HASHcontext,
204 syntax->ssyn_oid, slen );
205 HASH_Update( &HASHcontext,
207 HASH_Update( &HASHcontext,
208 value->bv_val, value->bv_len );
209 HASH_Final( HASHdigest, &HASHcontext );
211 ber_dupbv( keys, &digest );
212 keys[1].bv_val = NULL;
227 if( in->bv_len == 0 ) return LDAP_SUCCESS;
229 ber_dupbv( &dn, in );
230 if( !dn.bv_val ) return LDAP_OTHER;
232 if( dn.bv_val[dn.bv_len-1] == 'B'
233 && dn.bv_val[dn.bv_len-2] == '\'' )
235 /* assume presence of optional UID */
238 for(i=dn.bv_len-3; i>1; i--) {
239 if( dn.bv_val[i] != '0' && dn.bv_val[i] != '1' ) {
243 if( dn.bv_val[i] != '\'' ||
244 dn.bv_val[i-1] != '#' ) {
245 ber_memfree( dn.bv_val );
246 return LDAP_INVALID_SYNTAX;
249 /* trim the UID to allow use of dnValidate */
250 dn.bv_val[i-1] = '\0';
254 rc = dnValidate( NULL, &dn );
264 struct berval *normalized )
269 ber_dupbv( &out, val );
270 if( out.bv_len != 0 ) {
273 ber_len_t uidlen = 0;
275 if( out.bv_val[out.bv_len-1] == '\'' ) {
276 /* assume presence of optional UID */
277 uid = strrchr( out.bv_val, '#' );
281 return LDAP_INVALID_SYNTAX;
284 uidlen = out.bv_len - (uid - out.bv_val);
285 /* temporarily trim the UID */
287 out.bv_len -= uidlen;
290 #ifdef USE_DN_NORMALIZE
291 rc = dnNormalize2( NULL, &out, normalized );
293 rc = dnPretty2( NULL, &out, normalized );
296 if( rc != LDAP_SUCCESS ) {
298 return LDAP_INVALID_SYNTAX;
301 dnlen = normalized->bv_len;
305 b2.bv_val = ch_malloc(dnlen + uidlen + 1);
306 AC_MEMCPY( b2.bv_val, normalized->bv_val, dnlen );
308 /* restore the separator */
311 AC_MEMCPY( normalized->bv_val+dnlen, uid, uidlen );
312 b2.bv_len = dnlen + uidlen;
313 normalized->bv_val[dnlen+uidlen] = '\0';
314 free(normalized->bv_val);
328 /* any value allowed */
337 /* any value allowed */
348 /* very unforgiving validation, requires no normalization
349 * before simplistic matching
351 if( in->bv_len < 3 ) {
352 return LDAP_INVALID_SYNTAX;
356 * rfc 2252 section 6.3 Bit String
357 * bitstring = "'" *binary-digit "'"
358 * binary-digit = "0" / "1"
359 * example: '0101111101'B
362 if( in->bv_val[0] != '\'' ||
363 in->bv_val[in->bv_len-2] != '\'' ||
364 in->bv_val[in->bv_len-1] != 'B' )
366 return LDAP_INVALID_SYNTAX;
369 for( i=in->bv_len-3; i>0; i-- ) {
370 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
371 return LDAP_INVALID_SYNTAX;
382 struct berval *normalized )
385 * A normalized bitString is has no extaneous (leading) zero bits.
386 * That is, '00010'B is normalized to '10'B
387 * However, as a special case, '0'B requires no normalization.
391 /* start at the first bit */
394 /* Find the first non-zero bit */
395 while ( *p == '0' ) p++;
398 /* no non-zero bits */
399 ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
403 normalized->bv_val = ch_malloc( val->bv_len + 1 );
405 normalized->bv_val[0] = '\'';
406 normalized->bv_len = 1;
408 for( ; *p != '\0'; p++ ) {
409 normalized->bv_val[normalized->bv_len++] = *p;
412 normalized->bv_val[normalized->bv_len] = '\0';
419 * Handling boolean syntax and matching is quite rigid.
420 * A more flexible approach would be to allow a variety
421 * of strings to be normalized and prettied into TRUE
429 /* very unforgiving validation, requires no normalization
430 * before simplistic matching
433 if( in->bv_len == 4 ) {
434 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
437 } else if( in->bv_len == 5 ) {
438 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
443 return LDAP_INVALID_SYNTAX;
452 struct berval *value,
453 void *assertedValue )
455 /* simplistic matching allowed by rigid validation */
456 struct berval *asserted = (struct berval *) assertedValue;
457 *matchp = value->bv_len != asserted->bv_len;
468 unsigned char *u = in->bv_val;
470 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
472 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
473 /* get the length indicated by the first byte */
474 len = LDAP_UTF8_CHARLEN( u );
476 /* should not be zero */
477 if( len == 0 ) return LDAP_INVALID_SYNTAX;
479 /* make sure len corresponds with the offset
480 to the next character */
481 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
484 if( count != 0 ) return LDAP_INVALID_SYNTAX;
493 struct berval *normalized )
500 /* Ignore initial whitespace */
501 /* All space is ASCII. All ASCII is 1 byte */
502 while ( ASCII_SPACE( *p ) ) {
507 return LDAP_INVALID_SYNTAX;
510 ber_str2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
512 assert( normalized->bv_val );
514 p = q = normalized->bv_val;
519 if ( ASCII_SPACE( *p ) ) {
524 /* Ignore the extra whitespace */
525 while ( ASCII_SPACE( *p ) ) {
529 len = LDAP_UTF8_COPY(q,p);
535 assert( normalized->bv_val < p );
536 assert( q+len <= p );
538 /* cannot start with a space */
539 assert( !ASCII_SPACE(normalized->bv_val[0]) );
542 * If the string ended in space, backup the pointer one
543 * position. One is enough because the above loop collapsed
544 * all whitespace to a single space.
552 /* cannot end with a space */
553 assert( !ASCII_SPACE( *q ) );
560 normalized->bv_len = q - normalized->bv_val;
565 /* Returns Unicode canonically normalized copy of a substring assertion
566 * Skipping attribute description */
567 static SubstringsAssertion *
568 UTF8SubstringsassertionNormalize(
569 SubstringsAssertion *sa,
572 SubstringsAssertion *nsa;
575 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
580 if( sa->sa_initial.bv_val != NULL ) {
581 ber_str2bv( UTF8normalize( &sa->sa_initial, casefold ), 0,
582 0, &nsa->sa_initial );
583 if( nsa->sa_initial.bv_val == NULL ) {
588 if( sa->sa_any != NULL ) {
589 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
592 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
593 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
594 ber_str2bv( UTF8normalize( &sa->sa_any[i], casefold ),
595 0, 0, &nsa->sa_any[i] );
596 if( nsa->sa_any[i].bv_val == NULL ) {
600 nsa->sa_any[i].bv_val = NULL;
603 if( sa->sa_final.bv_val != NULL ) {
604 ber_str2bv( UTF8normalize( &sa->sa_final, casefold ), 0,
606 if( nsa->sa_final.bv_val == NULL ) {
614 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
615 if ( nsa->sa_any )bvarray_free( nsa->sa_any );
616 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
621 /* Strip characters with the 8th bit set */
634 while( *++q & 0x80 ) {
637 p = AC_MEMCPY(p, q, strlen(q) + 1);
645 #ifndef SLAPD_APPROX_OLDSINGLESTRING
647 #if defined(SLAPD_APPROX_INITIALS)
648 #define SLAPD_APPROX_DELIMITER "._ "
649 #define SLAPD_APPROX_WORDLEN 2
651 #define SLAPD_APPROX_DELIMITER " "
652 #define SLAPD_APPROX_WORDLEN 1
661 struct berval *value,
662 void *assertedValue )
664 char *val, *nval, *assertv, **values, **words, *c;
665 int i, count, len, nextchunk=0, nextavail=0;
668 /* Yes, this is necessary */
669 nval = UTF8normalize( value, LDAP_UTF8_NOCASEFOLD );
674 strip8bitChars( nval );
676 /* Yes, this is necessary */
677 assertv = UTF8normalize( ((struct berval *)assertedValue),
678 LDAP_UTF8_NOCASEFOLD );
679 if( assertv == NULL ) {
684 strip8bitChars( assertv );
685 avlen = strlen( assertv );
687 /* Isolate how many words there are */
688 for( c=nval,count=1; *c; c++ ) {
689 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
690 if ( c == NULL ) break;
695 /* Get a phonetic copy of each word */
696 words = (char **)ch_malloc( count * sizeof(char *) );
697 values = (char **)ch_malloc( count * sizeof(char *) );
698 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
700 values[i] = phonetic(c);
703 /* Work through the asserted value's words, to see if at least some
704 of the words are there, in the same order. */
706 while ( (size_t) nextchunk < avlen ) {
707 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
712 #if defined(SLAPD_APPROX_INITIALS)
713 else if( len == 1 ) {
714 /* Single letter words need to at least match one word's initial */
715 for( i=nextavail; i<count; i++ )
716 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
723 /* Isolate the next word in the asserted value and phonetic it */
724 assertv[nextchunk+len] = '\0';
725 val = phonetic( assertv + nextchunk );
727 /* See if this phonetic chunk is in the remaining words of *value */
728 for( i=nextavail; i<count; i++ ){
729 if( !strcmp( val, values[i] ) ){
737 /* This chunk in the asserted value was NOT within the *value. */
743 /* Go on to the next word in the asserted value */
747 /* If some of the words were seen, call it a match */
748 if( nextavail > 0 ) {
757 for( i=0; i<count; i++ ) {
758 ch_free( values[i] );
773 struct berval *prefix,
778 int i,j, len, wordcount, keycount=0;
779 struct berval *newkeys;
782 for( j=0; values[j].bv_val != NULL; j++ ) {
783 /* Yes, this is necessary */
784 val = UTF8normalize( &values[j], LDAP_UTF8_NOCASEFOLD );
785 strip8bitChars( val );
787 /* Isolate how many words there are. There will be a key for each */
788 for( wordcount=0,c=val; *c; c++) {
789 len = strcspn(c, SLAPD_APPROX_DELIMITER);
790 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
792 if (*c == '\0') break;
796 /* Allocate/increase storage to account for new keys */
797 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
798 * sizeof(struct berval) );
799 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
800 if( keys ) ch_free( keys );
803 /* Get a phonetic copy of each word */
804 for( c=val,i=0; i<wordcount; c+=len+1 ) {
806 if( len < SLAPD_APPROX_WORDLEN ) continue;
807 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
814 keys[keycount].bv_val = NULL;
826 struct berval *prefix,
834 /* Yes, this is necessary */
835 val = UTF8normalize( ((struct berval *)assertValue),
836 LDAP_UTF8_NOCASEFOLD );
838 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
839 keys[0].bv_val = NULL;
843 strip8bitChars( val );
845 /* Isolate how many words there are. There will be a key for each */
846 for( count=0,c=val; *c; c++) {
847 len = strcspn(c, SLAPD_APPROX_DELIMITER);
848 if( len >= SLAPD_APPROX_WORDLEN ) count++;
850 if (*c == '\0') break;
854 /* Allocate storage for new keys */
855 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
857 /* Get a phonetic copy of each word */
858 for( c=val,i=0; i<count; c+=len+1 ) {
860 if( len < SLAPD_APPROX_WORDLEN ) continue;
861 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
867 keys[count].bv_val = NULL;
875 /* No other form of Approximate Matching is defined */
883 struct berval *value,
884 void *assertedValue )
886 char *vapprox, *avapprox;
889 /* Yes, this is necessary */
890 s = UTF8normalize( value, UTF8_NOCASEFOLD );
896 /* Yes, this is necessary */
897 t = UTF8normalize( ((struct berval *)assertedValue),
905 vapprox = phonetic( strip8bitChars( s ) );
906 avapprox = phonetic( strip8bitChars( t ) );
911 *matchp = strcmp( vapprox, avapprox );
925 struct berval *prefix,
933 for( i=0; values[i].bv_val != NULL; i++ ) {
934 /* empty - just count them */
937 /* we should have at least one value at this point */
940 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
942 /* Copy each value and run it through phonetic() */
943 for( i=0; values[i].bv_val != NULL; i++ ) {
944 /* Yes, this is necessary */
945 s = UTF8normalize( &values[i], UTF8_NOCASEFOLD );
947 /* strip 8-bit chars and run through phonetic() */
948 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
951 keys[i].bv_val = NULL;
964 struct berval *prefix,
971 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
973 /* Yes, this is necessary */
974 s = UTF8normalize( ((struct berval *)assertValue),
979 /* strip 8-bit chars and run through phonetic() */
980 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
997 struct berval *value,
998 void *assertedValue )
1000 *matchp = UTF8normcmp( value->bv_val,
1001 ((struct berval *) assertedValue)->bv_val,
1002 LDAP_UTF8_NOCASEFOLD );
1003 return LDAP_SUCCESS;
1007 caseExactIgnoreSubstringsMatch(
1012 struct berval *value,
1013 void *assertedValue )
1016 SubstringsAssertion *sub = NULL;
1023 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1024 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1026 nav = UTF8normalize( value, casefold );
1032 left.bv_len = strlen( nav );
1034 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1040 /* Add up asserted input length */
1041 if( sub->sa_initial.bv_val ) {
1042 inlen += sub->sa_initial.bv_len;
1045 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1046 inlen += sub->sa_any[i].bv_len;
1049 if( sub->sa_final.bv_val ) {
1050 inlen += sub->sa_final.bv_len;
1053 if( sub->sa_initial.bv_val ) {
1054 if( inlen > left.bv_len ) {
1059 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
1060 sub->sa_initial.bv_len );
1066 left.bv_val += sub->sa_initial.bv_len;
1067 left.bv_len -= sub->sa_initial.bv_len;
1068 inlen -= sub->sa_initial.bv_len;
1071 if( sub->sa_final.bv_val ) {
1072 if( inlen > left.bv_len ) {
1077 match = strncmp( sub->sa_final.bv_val,
1078 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1079 sub->sa_final.bv_len );
1085 left.bv_len -= sub->sa_final.bv_len;
1086 inlen -= sub->sa_final.bv_len;
1090 for(i=0; sub->sa_any[i].bv_val; i++) {
1095 if( inlen > left.bv_len ) {
1096 /* not enough length */
1101 if( sub->sa_any[i].bv_len == 0 ) {
1105 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
1112 idx = p - left.bv_val;
1113 assert( idx < left.bv_len );
1115 if( idx >= left.bv_len ) {
1116 /* this shouldn't happen */
1118 if ( sub->sa_final.bv_val )
1119 ch_free( sub->sa_final.bv_val );
1121 bvarray_free( sub->sa_any );
1122 if ( sub->sa_initial.bv_val )
1123 ch_free( sub->sa_initial.bv_val );
1131 if( sub->sa_any[i].bv_len > left.bv_len ) {
1132 /* not enough left */
1137 match = strncmp( left.bv_val,
1138 sub->sa_any[i].bv_val,
1139 sub->sa_any[i].bv_len );
1147 left.bv_val += sub->sa_any[i].bv_len;
1148 left.bv_len -= sub->sa_any[i].bv_len;
1149 inlen -= sub->sa_any[i].bv_len;
1156 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1157 if ( sub->sa_any ) bvarray_free( sub->sa_any );
1158 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1162 return LDAP_SUCCESS;
1165 /* Index generation function */
1166 static int caseExactIgnoreIndexer(
1171 struct berval *prefix,
1179 HASH_CONTEXT HASHcontext;
1180 unsigned char HASHdigest[HASH_BYTES];
1181 struct berval digest;
1182 digest.bv_val = HASHdigest;
1183 digest.bv_len = sizeof(HASHdigest);
1185 for( i=0; values[i].bv_val != NULL; i++ ) {
1186 /* empty - just count them */
1189 /* we should have at least one value at this point */
1192 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1194 slen = syntax->ssyn_oidlen;
1195 mlen = mr->smr_oidlen;
1197 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1198 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1200 for( i=0; values[i].bv_val != NULL; i++ ) {
1201 struct berval value;
1202 ber_str2bv( UTF8normalize( &values[i], casefold ), 0, 0,
1205 HASH_Init( &HASHcontext );
1206 if( prefix != NULL && prefix->bv_len > 0 ) {
1207 HASH_Update( &HASHcontext,
1208 prefix->bv_val, prefix->bv_len );
1210 HASH_Update( &HASHcontext,
1211 syntax->ssyn_oid, slen );
1212 HASH_Update( &HASHcontext,
1213 mr->smr_oid, mlen );
1214 HASH_Update( &HASHcontext,
1215 value.bv_val, value.bv_len );
1216 HASH_Final( HASHdigest, &HASHcontext );
1218 free( value.bv_val );
1220 ber_dupbv( &keys[i], &digest );
1223 keys[i].bv_val = NULL;
1225 return LDAP_SUCCESS;
1228 /* Index generation function */
1229 static int caseExactIgnoreFilter(
1234 struct berval *prefix,
1241 HASH_CONTEXT HASHcontext;
1242 unsigned char HASHdigest[HASH_BYTES];
1243 struct berval value;
1244 struct berval digest;
1245 digest.bv_val = HASHdigest;
1246 digest.bv_len = sizeof(HASHdigest);
1248 slen = syntax->ssyn_oidlen;
1249 mlen = mr->smr_oidlen;
1251 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1252 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1254 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1256 /* This usually happens if filter contains bad UTF8 */
1257 if( value.bv_val == NULL ) {
1258 keys = ch_malloc( sizeof( struct berval ) );
1259 keys[0].bv_val = NULL;
1260 return LDAP_SUCCESS;
1263 keys = ch_malloc( sizeof( struct berval ) * 2 );
1265 HASH_Init( &HASHcontext );
1266 if( prefix != NULL && prefix->bv_len > 0 ) {
1267 HASH_Update( &HASHcontext,
1268 prefix->bv_val, prefix->bv_len );
1270 HASH_Update( &HASHcontext,
1271 syntax->ssyn_oid, slen );
1272 HASH_Update( &HASHcontext,
1273 mr->smr_oid, mlen );
1274 HASH_Update( &HASHcontext,
1275 value.bv_val, value.bv_len );
1276 HASH_Final( HASHdigest, &HASHcontext );
1278 ber_dupbv( keys, &digest );
1279 keys[1].bv_val = NULL;
1281 free( value.bv_val );
1284 return LDAP_SUCCESS;
1287 /* Substrings Index generation function */
1288 static int caseExactIgnoreSubstringsIndexer(
1293 struct berval *prefix,
1303 HASH_CONTEXT HASHcontext;
1304 unsigned char HASHdigest[HASH_BYTES];
1305 struct berval digest;
1306 digest.bv_val = HASHdigest;
1307 digest.bv_len = sizeof(HASHdigest);
1311 for( i=0; values[i].bv_val != NULL; i++ ) {
1312 /* empty - just count them */
1315 /* we should have at least one value at this point */
1318 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1319 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1321 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1322 for( i=0; values[i].bv_val != NULL; i++ ) {
1323 ber_str2bv( UTF8normalize( &values[i], casefold ),
1324 0, 0, &nvalues[i] );
1326 nvalues[i].bv_val = NULL;
1329 for( i=0; values[i].bv_val != NULL; i++ ) {
1330 /* count number of indices to generate */
1331 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1335 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1336 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1337 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1338 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1340 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1344 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1345 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1346 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1350 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1351 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1352 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1353 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1355 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1361 /* no keys to generate */
1363 bvarray_free( nvalues );
1364 return LDAP_SUCCESS;
1367 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1369 slen = syntax->ssyn_oidlen;
1370 mlen = mr->smr_oidlen;
1373 for( i=0; values[i].bv_val != NULL; i++ ) {
1376 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1378 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1379 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1381 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1382 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1384 for( j=0; j<max; j++ ) {
1385 HASH_Init( &HASHcontext );
1386 if( prefix != NULL && prefix->bv_len > 0 ) {
1387 HASH_Update( &HASHcontext,
1388 prefix->bv_val, prefix->bv_len );
1391 HASH_Update( &HASHcontext,
1392 &pre, sizeof( pre ) );
1393 HASH_Update( &HASHcontext,
1394 syntax->ssyn_oid, slen );
1395 HASH_Update( &HASHcontext,
1396 mr->smr_oid, mlen );
1397 HASH_Update( &HASHcontext,
1398 &values[i].bv_val[j],
1399 SLAP_INDEX_SUBSTR_MAXLEN );
1400 HASH_Final( HASHdigest, &HASHcontext );
1402 ber_dupbv( &keys[nkeys++], &digest );
1406 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1407 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1409 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1412 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1413 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1414 HASH_Init( &HASHcontext );
1415 if( prefix != NULL && prefix->bv_len > 0 ) {
1416 HASH_Update( &HASHcontext,
1417 prefix->bv_val, prefix->bv_len );
1419 HASH_Update( &HASHcontext,
1420 &pre, sizeof( pre ) );
1421 HASH_Update( &HASHcontext,
1422 syntax->ssyn_oid, slen );
1423 HASH_Update( &HASHcontext,
1424 mr->smr_oid, mlen );
1425 HASH_Update( &HASHcontext,
1426 values[i].bv_val, j );
1427 HASH_Final( HASHdigest, &HASHcontext );
1429 ber_dupbv( &keys[nkeys++], &digest );
1432 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1433 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1434 HASH_Init( &HASHcontext );
1435 if( prefix != NULL && prefix->bv_len > 0 ) {
1436 HASH_Update( &HASHcontext,
1437 prefix->bv_val, prefix->bv_len );
1439 HASH_Update( &HASHcontext,
1440 &pre, sizeof( pre ) );
1441 HASH_Update( &HASHcontext,
1442 syntax->ssyn_oid, slen );
1443 HASH_Update( &HASHcontext,
1444 mr->smr_oid, mlen );
1445 HASH_Update( &HASHcontext,
1446 &values[i].bv_val[values[i].bv_len-j], j );
1447 HASH_Final( HASHdigest, &HASHcontext );
1449 ber_dupbv( &keys[nkeys++], &digest );
1457 keys[nkeys].bv_val = NULL;
1464 bvarray_free( nvalues );
1466 return LDAP_SUCCESS;
1469 static int caseExactIgnoreSubstringsFilter(
1474 struct berval *prefix,
1478 SubstringsAssertion *sa;
1481 ber_len_t nkeys = 0;
1482 size_t slen, mlen, klen;
1484 HASH_CONTEXT HASHcontext;
1485 unsigned char HASHdigest[HASH_BYTES];
1486 struct berval *value;
1487 struct berval digest;
1489 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1490 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1492 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1495 return LDAP_SUCCESS;
1498 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1499 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1504 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1506 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1507 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1508 /* don't bother accounting for stepping */
1509 nkeys += sa->sa_any[i].bv_len -
1510 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1515 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1516 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1522 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1523 if ( sa->sa_any ) bvarray_free( sa->sa_any );
1524 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1527 return LDAP_SUCCESS;
1530 digest.bv_val = HASHdigest;
1531 digest.bv_len = sizeof(HASHdigest);
1533 slen = syntax->ssyn_oidlen;
1534 mlen = mr->smr_oidlen;
1536 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1539 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1540 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1542 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1543 value = &sa->sa_initial;
1545 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1546 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1548 HASH_Init( &HASHcontext );
1549 if( prefix != NULL && prefix->bv_len > 0 ) {
1550 HASH_Update( &HASHcontext,
1551 prefix->bv_val, prefix->bv_len );
1553 HASH_Update( &HASHcontext,
1554 &pre, sizeof( pre ) );
1555 HASH_Update( &HASHcontext,
1556 syntax->ssyn_oid, slen );
1557 HASH_Update( &HASHcontext,
1558 mr->smr_oid, mlen );
1559 HASH_Update( &HASHcontext,
1560 value->bv_val, klen );
1561 HASH_Final( HASHdigest, &HASHcontext );
1563 ber_dupbv( &keys[nkeys++], &digest );
1566 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1568 pre = SLAP_INDEX_SUBSTR_PREFIX;
1569 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1571 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1572 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1576 value = &sa->sa_any[i];
1579 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1580 j += SLAP_INDEX_SUBSTR_STEP )
1582 HASH_Init( &HASHcontext );
1583 if( prefix != NULL && prefix->bv_len > 0 ) {
1584 HASH_Update( &HASHcontext,
1585 prefix->bv_val, prefix->bv_len );
1587 HASH_Update( &HASHcontext,
1588 &pre, sizeof( pre ) );
1589 HASH_Update( &HASHcontext,
1590 syntax->ssyn_oid, slen );
1591 HASH_Update( &HASHcontext,
1592 mr->smr_oid, mlen );
1593 HASH_Update( &HASHcontext,
1594 &value->bv_val[j], klen );
1595 HASH_Final( HASHdigest, &HASHcontext );
1597 ber_dupbv( &keys[nkeys++], &digest );
1603 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1604 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1606 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1607 value = &sa->sa_final;
1609 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1610 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1612 HASH_Init( &HASHcontext );
1613 if( prefix != NULL && prefix->bv_len > 0 ) {
1614 HASH_Update( &HASHcontext,
1615 prefix->bv_val, prefix->bv_len );
1617 HASH_Update( &HASHcontext,
1618 &pre, sizeof( pre ) );
1619 HASH_Update( &HASHcontext,
1620 syntax->ssyn_oid, slen );
1621 HASH_Update( &HASHcontext,
1622 mr->smr_oid, mlen );
1623 HASH_Update( &HASHcontext,
1624 &value->bv_val[value->bv_len-klen], klen );
1625 HASH_Final( HASHdigest, &HASHcontext );
1627 ber_dupbv( &keys[nkeys++], &digest );
1631 keys[nkeys].bv_val = NULL;
1637 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1638 if ( sa->sa_any ) bvarray_free( sa->sa_any );
1639 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1642 return LDAP_SUCCESS;
1651 struct berval *value,
1652 void *assertedValue )
1654 *matchp = UTF8normcmp( value->bv_val,
1655 ((struct berval *) assertedValue)->bv_val,
1656 LDAP_UTF8_CASEFOLD );
1657 return LDAP_SUCCESS;
1663 struct berval *val )
1667 if( val->bv_len == 0 ) {
1668 /* disallow empty strings */
1669 return LDAP_INVALID_SYNTAX;
1672 if( OID_LEADCHAR(val->bv_val[0]) ) {
1674 for(i=1; i < val->bv_len; i++) {
1675 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1676 if( dot++ ) return 1;
1677 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1680 return LDAP_INVALID_SYNTAX;
1684 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1686 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1687 for(i=1; i < val->bv_len; i++) {
1688 if( !DESC_CHAR(val->bv_val[i] ) ) {
1689 return LDAP_INVALID_SYNTAX;
1693 return LDAP_SUCCESS;
1696 return LDAP_INVALID_SYNTAX;
1705 struct berval *value,
1706 void *assertedValue )
1709 int vsign=0, avsign=0;
1710 struct berval *asserted;
1711 ber_len_t vlen, avlen;
1714 /* Start off pessimistic */
1717 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1719 vlen = value->bv_len;
1721 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1722 /* empty -- skip spaces */
1724 else if ( *v == '+' ) {
1727 else if ( *v == '-' ) {
1730 else if ( ASCII_DIGIT(*v) ) {
1731 if ( vsign == 0 ) vsign = 1;
1739 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1741 asserted = (struct berval *) assertedValue;
1742 av = asserted->bv_val;
1743 avlen = asserted->bv_len;
1745 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1746 /* empty -- skip spaces */
1748 else if ( *av == '+' ) {
1751 else if ( *av == '-' ) {
1754 else if ( ASCII_DIGIT(*av) ) {
1755 if ( avsign == 0 ) avsign = 1;
1763 /* The two ?sign vars are now one of :
1764 -2 negative non-zero number
1766 0 0 collapse these three to 0
1768 +2 positive non-zero number
1770 if ( abs( vsign ) == 1 ) vsign = 0;
1771 if ( abs( avsign ) == 1 ) avsign = 0;
1773 if( vsign != avsign ) return LDAP_SUCCESS;
1775 /* Check the significant digits */
1776 while( vlen && avlen ) {
1777 if( *v != *av ) break;
1784 /* If all digits compared equal, the numbers are equal */
1785 if(( vlen == 0 ) && ( avlen == 0 )) {
1788 return LDAP_SUCCESS;
1794 struct berval *val )
1798 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1800 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1801 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1802 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1803 return LDAP_INVALID_SYNTAX;
1806 for( i=1; i < val->bv_len; i++ ) {
1807 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1810 return LDAP_SUCCESS;
1817 struct berval *normalized )
1827 /* Ignore leading spaces */
1828 while ( len && ( *p == ' ' )) {
1835 negative = ( *p == '-' );
1836 if(( *p == '-' ) || ( *p == '+' )) {
1842 /* Ignore leading zeros */
1843 while ( len && ( *p == '0' )) {
1848 /* If there are no non-zero digits left, the number is zero, otherwise
1849 allocate space for the number and copy it into the buffer */
1851 normalized->bv_val = ch_strdup("0");
1852 normalized->bv_len = 1;
1855 normalized->bv_len = len+negative;
1856 normalized->bv_val = ch_malloc( normalized->bv_len );
1858 normalized->bv_val[0] = '-';
1860 AC_MEMCPY( normalized->bv_val + negative, p, len );
1863 return LDAP_SUCCESS;
1866 /* Index generation function */
1867 static int integerIndexer(
1872 struct berval *prefix,
1879 /* we should have at least one value at this point */
1880 assert( values != NULL && values[0].bv_val != NULL );
1882 for( i=0; values[i].bv_val != NULL; i++ ) {
1883 /* empty -- just count them */
1886 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1888 for( i=0; values[i].bv_val != NULL; i++ ) {
1889 integerNormalize( syntax, &values[i], &keys[i] );
1892 keys[i].bv_val = NULL;
1894 return LDAP_SUCCESS;
1897 /* Index generation function */
1898 static int integerFilter(
1903 struct berval *prefix,
1909 keys = ch_malloc( sizeof( struct berval ) * 2 );
1910 integerNormalize( syntax, assertValue, &keys[0] );
1911 keys[1].bv_val = NULL;
1914 return LDAP_SUCCESS;
1919 countryStringValidate(
1921 struct berval *val )
1923 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1925 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1926 return LDAP_INVALID_SYNTAX;
1928 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1929 return LDAP_INVALID_SYNTAX;
1932 return LDAP_SUCCESS;
1936 printableStringValidate(
1938 struct berval *val )
1942 for(i=0; i < val->bv_len; i++) {
1943 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1944 return LDAP_INVALID_SYNTAX;
1948 return LDAP_SUCCESS;
1952 printablesStringValidate(
1954 struct berval *val )
1958 for(i=0; i < val->bv_len; i++) {
1959 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1960 return LDAP_INVALID_SYNTAX;
1964 return LDAP_SUCCESS;
1970 struct berval *val )
1974 for(i=0; i < val->bv_len; i++) {
1975 if( !LDAP_ASCII(val->bv_val[i]) ) {
1976 return LDAP_INVALID_SYNTAX;
1980 return LDAP_SUCCESS;
1987 struct berval *normalized )
1993 /* Ignore initial whitespace */
1994 while ( ASCII_SPACE( *p ) ) {
1998 normalized->bv_val = ch_strdup( p );
1999 p = q = normalized->bv_val;
2002 if ( ASCII_SPACE( *p ) ) {
2005 /* Ignore the extra whitespace */
2006 while ( ASCII_SPACE( *p ) ) {
2014 assert( normalized->bv_val <= p );
2018 * If the string ended in space, backup the pointer one
2019 * position. One is enough because the above loop collapsed
2020 * all whitespace to a single space.
2023 if ( ASCII_SPACE( q[-1] ) ) {
2027 /* null terminate */
2030 normalized->bv_len = q - normalized->bv_val;
2032 return LDAP_SUCCESS;
2041 struct berval *value,
2042 void *assertedValue )
2044 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2047 match = strncmp( value->bv_val,
2048 ((struct berval *) assertedValue)->bv_val,
2053 return LDAP_SUCCESS;
2057 caseExactIA5SubstringsMatch(
2062 struct berval *value,
2063 void *assertedValue )
2066 SubstringsAssertion *sub = assertedValue;
2067 struct berval left = *value;
2071 /* Add up asserted input length */
2072 if( sub->sa_initial.bv_val ) {
2073 inlen += sub->sa_initial.bv_len;
2076 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2077 inlen += sub->sa_any[i].bv_len;
2080 if( sub->sa_final.bv_val ) {
2081 inlen += sub->sa_final.bv_len;
2084 if( sub->sa_initial.bv_val ) {
2085 if( inlen > left.bv_len ) {
2090 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2091 sub->sa_initial.bv_len );
2097 left.bv_val += sub->sa_initial.bv_len;
2098 left.bv_len -= sub->sa_initial.bv_len;
2099 inlen -= sub->sa_initial.bv_len;
2102 if( sub->sa_final.bv_val ) {
2103 if( inlen > left.bv_len ) {
2108 match = strncmp( sub->sa_final.bv_val,
2109 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2110 sub->sa_final.bv_len );
2116 left.bv_len -= sub->sa_final.bv_len;
2117 inlen -= sub->sa_final.bv_len;
2121 for(i=0; sub->sa_any[i].bv_val; i++) {
2126 if( inlen > left.bv_len ) {
2127 /* not enough length */
2132 if( sub->sa_any[i].bv_len == 0 ) {
2136 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2143 idx = p - left.bv_val;
2144 assert( idx < left.bv_len );
2146 if( idx >= left.bv_len ) {
2147 /* this shouldn't happen */
2154 if( sub->sa_any[i].bv_len > left.bv_len ) {
2155 /* not enough left */
2160 match = strncmp( left.bv_val,
2161 sub->sa_any[i].bv_val,
2162 sub->sa_any[i].bv_len );
2170 left.bv_val += sub->sa_any[i].bv_len;
2171 left.bv_len -= sub->sa_any[i].bv_len;
2172 inlen -= sub->sa_any[i].bv_len;
2178 return LDAP_SUCCESS;
2181 /* Index generation function */
2182 static int caseExactIA5Indexer(
2187 struct berval *prefix,
2194 HASH_CONTEXT HASHcontext;
2195 unsigned char HASHdigest[HASH_BYTES];
2196 struct berval digest;
2197 digest.bv_val = HASHdigest;
2198 digest.bv_len = sizeof(HASHdigest);
2200 for( i=0; values[i].bv_val != NULL; i++ ) {
2201 /* empty - just count them */
2204 /* we should have at least one value at this point */
2207 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2209 slen = syntax->ssyn_oidlen;
2210 mlen = mr->smr_oidlen;
2212 for( i=0; values[i].bv_val != NULL; i++ ) {
2213 struct berval *value = &values[i];
2215 HASH_Init( &HASHcontext );
2216 if( prefix != NULL && prefix->bv_len > 0 ) {
2217 HASH_Update( &HASHcontext,
2218 prefix->bv_val, prefix->bv_len );
2220 HASH_Update( &HASHcontext,
2221 syntax->ssyn_oid, slen );
2222 HASH_Update( &HASHcontext,
2223 mr->smr_oid, mlen );
2224 HASH_Update( &HASHcontext,
2225 value->bv_val, value->bv_len );
2226 HASH_Final( HASHdigest, &HASHcontext );
2228 ber_dupbv( &keys[i], &digest );
2231 keys[i].bv_val = NULL;
2233 return LDAP_SUCCESS;
2236 /* Index generation function */
2237 static int caseExactIA5Filter(
2242 struct berval *prefix,
2248 HASH_CONTEXT HASHcontext;
2249 unsigned char HASHdigest[HASH_BYTES];
2250 struct berval *value;
2251 struct berval digest;
2252 digest.bv_val = HASHdigest;
2253 digest.bv_len = sizeof(HASHdigest);
2255 slen = syntax->ssyn_oidlen;
2256 mlen = mr->smr_oidlen;
2258 value = (struct berval *) assertValue;
2260 keys = ch_malloc( sizeof( struct berval ) * 2 );
2262 HASH_Init( &HASHcontext );
2263 if( prefix != NULL && prefix->bv_len > 0 ) {
2264 HASH_Update( &HASHcontext,
2265 prefix->bv_val, prefix->bv_len );
2267 HASH_Update( &HASHcontext,
2268 syntax->ssyn_oid, slen );
2269 HASH_Update( &HASHcontext,
2270 mr->smr_oid, mlen );
2271 HASH_Update( &HASHcontext,
2272 value->bv_val, value->bv_len );
2273 HASH_Final( HASHdigest, &HASHcontext );
2275 ber_dupbv( &keys[0], &digest );
2276 keys[1].bv_val = NULL;
2279 return LDAP_SUCCESS;
2282 /* Substrings Index generation function */
2283 static int caseExactIA5SubstringsIndexer(
2288 struct berval *prefix,
2295 HASH_CONTEXT HASHcontext;
2296 unsigned char HASHdigest[HASH_BYTES];
2297 struct berval digest;
2298 digest.bv_val = HASHdigest;
2299 digest.bv_len = sizeof(HASHdigest);
2301 /* we should have at least one value at this point */
2302 assert( values != NULL && values[0].bv_val != NULL );
2305 for( i=0; values[i].bv_val != NULL; i++ ) {
2306 /* count number of indices to generate */
2307 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2311 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2312 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2313 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2314 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2316 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2320 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2321 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2322 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2326 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2327 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2328 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2329 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2331 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2337 /* no keys to generate */
2339 return LDAP_SUCCESS;
2342 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2344 slen = syntax->ssyn_oidlen;
2345 mlen = mr->smr_oidlen;
2348 for( i=0; values[i].bv_val != NULL; i++ ) {
2350 struct berval *value;
2353 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2355 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2356 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2358 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2359 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2361 for( j=0; j<max; j++ ) {
2362 HASH_Init( &HASHcontext );
2363 if( prefix != NULL && prefix->bv_len > 0 ) {
2364 HASH_Update( &HASHcontext,
2365 prefix->bv_val, prefix->bv_len );
2368 HASH_Update( &HASHcontext,
2369 &pre, sizeof( pre ) );
2370 HASH_Update( &HASHcontext,
2371 syntax->ssyn_oid, slen );
2372 HASH_Update( &HASHcontext,
2373 mr->smr_oid, mlen );
2374 HASH_Update( &HASHcontext,
2376 SLAP_INDEX_SUBSTR_MAXLEN );
2377 HASH_Final( HASHdigest, &HASHcontext );
2379 ber_dupbv( &keys[nkeys++], &digest );
2383 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2384 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2386 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2389 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2390 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2391 HASH_Init( &HASHcontext );
2392 if( prefix != NULL && prefix->bv_len > 0 ) {
2393 HASH_Update( &HASHcontext,
2394 prefix->bv_val, prefix->bv_len );
2396 HASH_Update( &HASHcontext,
2397 &pre, sizeof( pre ) );
2398 HASH_Update( &HASHcontext,
2399 syntax->ssyn_oid, slen );
2400 HASH_Update( &HASHcontext,
2401 mr->smr_oid, mlen );
2402 HASH_Update( &HASHcontext,
2404 HASH_Final( HASHdigest, &HASHcontext );
2406 ber_dupbv( &keys[nkeys++], &digest );
2409 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2410 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2411 HASH_Init( &HASHcontext );
2412 if( prefix != NULL && prefix->bv_len > 0 ) {
2413 HASH_Update( &HASHcontext,
2414 prefix->bv_val, prefix->bv_len );
2416 HASH_Update( &HASHcontext,
2417 &pre, sizeof( pre ) );
2418 HASH_Update( &HASHcontext,
2419 syntax->ssyn_oid, slen );
2420 HASH_Update( &HASHcontext,
2421 mr->smr_oid, mlen );
2422 HASH_Update( &HASHcontext,
2423 &value->bv_val[value->bv_len-j], j );
2424 HASH_Final( HASHdigest, &HASHcontext );
2426 ber_dupbv( &keys[nkeys++], &digest );
2433 keys[nkeys].bv_val = NULL;
2440 return LDAP_SUCCESS;
2443 static int caseExactIA5SubstringsFilter(
2448 struct berval *prefix,
2452 SubstringsAssertion *sa = assertValue;
2454 ber_len_t nkeys = 0;
2455 size_t slen, mlen, klen;
2457 HASH_CONTEXT HASHcontext;
2458 unsigned char HASHdigest[HASH_BYTES];
2459 struct berval *value;
2460 struct berval digest;
2462 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2463 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2468 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2470 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2471 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2472 /* don't bother accounting for stepping */
2473 nkeys += sa->sa_any[i].bv_len -
2474 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2479 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2480 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2487 return LDAP_SUCCESS;
2490 digest.bv_val = HASHdigest;
2491 digest.bv_len = sizeof(HASHdigest);
2493 slen = syntax->ssyn_oidlen;
2494 mlen = mr->smr_oidlen;
2496 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2499 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2500 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2502 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2503 value = &sa->sa_initial;
2505 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2506 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2508 HASH_Init( &HASHcontext );
2509 if( prefix != NULL && prefix->bv_len > 0 ) {
2510 HASH_Update( &HASHcontext,
2511 prefix->bv_val, prefix->bv_len );
2513 HASH_Update( &HASHcontext,
2514 &pre, sizeof( pre ) );
2515 HASH_Update( &HASHcontext,
2516 syntax->ssyn_oid, slen );
2517 HASH_Update( &HASHcontext,
2518 mr->smr_oid, mlen );
2519 HASH_Update( &HASHcontext,
2520 value->bv_val, klen );
2521 HASH_Final( HASHdigest, &HASHcontext );
2523 ber_dupbv( &keys[nkeys++], &digest );
2526 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2528 pre = SLAP_INDEX_SUBSTR_PREFIX;
2529 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2531 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2532 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2536 value = &sa->sa_any[i];
2539 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2540 j += SLAP_INDEX_SUBSTR_STEP )
2542 HASH_Init( &HASHcontext );
2543 if( prefix != NULL && prefix->bv_len > 0 ) {
2544 HASH_Update( &HASHcontext,
2545 prefix->bv_val, prefix->bv_len );
2547 HASH_Update( &HASHcontext,
2548 &pre, sizeof( pre ) );
2549 HASH_Update( &HASHcontext,
2550 syntax->ssyn_oid, slen );
2551 HASH_Update( &HASHcontext,
2552 mr->smr_oid, mlen );
2553 HASH_Update( &HASHcontext,
2554 &value->bv_val[j], klen );
2555 HASH_Final( HASHdigest, &HASHcontext );
2557 ber_dupbv( &keys[nkeys++], &digest );
2562 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2563 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2565 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2566 value = &sa->sa_final;
2568 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2569 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2571 HASH_Init( &HASHcontext );
2572 if( prefix != NULL && prefix->bv_len > 0 ) {
2573 HASH_Update( &HASHcontext,
2574 prefix->bv_val, prefix->bv_len );
2576 HASH_Update( &HASHcontext,
2577 &pre, sizeof( pre ) );
2578 HASH_Update( &HASHcontext,
2579 syntax->ssyn_oid, slen );
2580 HASH_Update( &HASHcontext,
2581 mr->smr_oid, mlen );
2582 HASH_Update( &HASHcontext,
2583 &value->bv_val[value->bv_len-klen], klen );
2584 HASH_Final( HASHdigest, &HASHcontext );
2586 ber_dupbv( &keys[nkeys++], &digest );
2590 keys[nkeys].bv_val = NULL;
2597 return LDAP_SUCCESS;
2606 struct berval *value,
2607 void *assertedValue )
2609 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2611 if( match == 0 && value->bv_len ) {
2612 match = strncasecmp( value->bv_val,
2613 ((struct berval *) assertedValue)->bv_val,
2618 return LDAP_SUCCESS;
2622 caseIgnoreIA5SubstringsMatch(
2627 struct berval *value,
2628 void *assertedValue )
2631 SubstringsAssertion *sub = assertedValue;
2632 struct berval left = *value;
2636 /* Add up asserted input length */
2637 if( sub->sa_initial.bv_val ) {
2638 inlen += sub->sa_initial.bv_len;
2641 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2642 inlen += sub->sa_any[i].bv_len;
2645 if( sub->sa_final.bv_val ) {
2646 inlen += sub->sa_final.bv_len;
2649 if( sub->sa_initial.bv_val ) {
2650 if( inlen > left.bv_len ) {
2655 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2656 sub->sa_initial.bv_len );
2662 left.bv_val += sub->sa_initial.bv_len;
2663 left.bv_len -= sub->sa_initial.bv_len;
2664 inlen -= sub->sa_initial.bv_len;
2667 if( sub->sa_final.bv_val ) {
2668 if( inlen > left.bv_len ) {
2673 match = strncasecmp( sub->sa_final.bv_val,
2674 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2675 sub->sa_final.bv_len );
2681 left.bv_len -= sub->sa_final.bv_len;
2682 inlen -= sub->sa_final.bv_len;
2686 for(i=0; sub->sa_any[i].bv_val; i++) {
2691 if( inlen > left.bv_len ) {
2692 /* not enough length */
2697 if( sub->sa_any[i].bv_len == 0 ) {
2701 p = strcasechr( left.bv_val, *sub->sa_any[i].bv_val );
2708 idx = p - left.bv_val;
2709 assert( idx < left.bv_len );
2711 if( idx >= left.bv_len ) {
2712 /* this shouldn't happen */
2719 if( sub->sa_any[i].bv_len > left.bv_len ) {
2720 /* not enough left */
2725 match = strncasecmp( left.bv_val,
2726 sub->sa_any[i].bv_val,
2727 sub->sa_any[i].bv_len );
2736 left.bv_val += sub->sa_any[i].bv_len;
2737 left.bv_len -= sub->sa_any[i].bv_len;
2738 inlen -= sub->sa_any[i].bv_len;
2744 return LDAP_SUCCESS;
2747 /* Index generation function */
2748 static int caseIgnoreIA5Indexer(
2753 struct berval *prefix,
2760 HASH_CONTEXT HASHcontext;
2761 unsigned char HASHdigest[HASH_BYTES];
2762 struct berval digest;
2763 digest.bv_val = HASHdigest;
2764 digest.bv_len = sizeof(HASHdigest);
2766 /* we should have at least one value at this point */
2767 assert( values != NULL && values[0].bv_val != NULL );
2769 for( i=0; values[i].bv_val != NULL; i++ ) {
2770 /* just count them */
2773 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2775 slen = syntax->ssyn_oidlen;
2776 mlen = mr->smr_oidlen;
2778 for( i=0; values[i].bv_val != NULL; i++ ) {
2779 struct berval value;
2780 ber_dupbv( &value, &values[i] );
2781 ldap_pvt_str2upper( value.bv_val );
2783 HASH_Init( &HASHcontext );
2784 if( prefix != NULL && prefix->bv_len > 0 ) {
2785 HASH_Update( &HASHcontext,
2786 prefix->bv_val, prefix->bv_len );
2788 HASH_Update( &HASHcontext,
2789 syntax->ssyn_oid, slen );
2790 HASH_Update( &HASHcontext,
2791 mr->smr_oid, mlen );
2792 HASH_Update( &HASHcontext,
2793 value.bv_val, value.bv_len );
2794 HASH_Final( HASHdigest, &HASHcontext );
2796 free( value.bv_val );
2798 ber_dupbv( &keys[i], &digest );
2801 keys[i].bv_val = NULL;
2803 return LDAP_SUCCESS;
2806 /* Index generation function */
2807 static int caseIgnoreIA5Filter(
2812 struct berval *prefix,
2818 HASH_CONTEXT HASHcontext;
2819 unsigned char HASHdigest[HASH_BYTES];
2820 struct berval value;
2821 struct berval digest;
2822 digest.bv_val = HASHdigest;
2823 digest.bv_len = sizeof(HASHdigest);
2825 slen = syntax->ssyn_oidlen;
2826 mlen = mr->smr_oidlen;
2828 ber_dupbv( &value, (struct berval *) assertValue );
2829 ldap_pvt_str2upper( value.bv_val );
2831 keys = ch_malloc( sizeof( struct berval ) * 2 );
2833 HASH_Init( &HASHcontext );
2834 if( prefix != NULL && prefix->bv_len > 0 ) {
2835 HASH_Update( &HASHcontext,
2836 prefix->bv_val, prefix->bv_len );
2838 HASH_Update( &HASHcontext,
2839 syntax->ssyn_oid, slen );
2840 HASH_Update( &HASHcontext,
2841 mr->smr_oid, mlen );
2842 HASH_Update( &HASHcontext,
2843 value.bv_val, value.bv_len );
2844 HASH_Final( HASHdigest, &HASHcontext );
2846 ber_dupbv( &keys[0], &digest );
2847 keys[1].bv_val = NULL;
2849 free( value.bv_val );
2853 return LDAP_SUCCESS;
2856 /* Substrings Index generation function */
2857 static int caseIgnoreIA5SubstringsIndexer(
2862 struct berval *prefix,
2869 HASH_CONTEXT HASHcontext;
2870 unsigned char HASHdigest[HASH_BYTES];
2871 struct berval digest;
2872 digest.bv_val = HASHdigest;
2873 digest.bv_len = sizeof(HASHdigest);
2875 /* we should have at least one value at this point */
2876 assert( values != NULL && values[0].bv_val != NULL );
2879 for( i=0; values[i].bv_val != NULL; i++ ) {
2880 /* count number of indices to generate */
2881 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2885 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2886 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2887 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2888 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2890 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2894 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2895 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2896 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2900 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2901 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2902 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2903 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2905 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2911 /* no keys to generate */
2913 return LDAP_SUCCESS;
2916 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2918 slen = syntax->ssyn_oidlen;
2919 mlen = mr->smr_oidlen;
2922 for( i=0; values[i].bv_val != NULL; i++ ) {
2924 struct berval value;
2926 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2928 ber_dupbv( &value, &values[i] );
2929 ldap_pvt_str2upper( value.bv_val );
2931 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2932 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2934 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2935 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2937 for( j=0; j<max; j++ ) {
2938 HASH_Init( &HASHcontext );
2939 if( prefix != NULL && prefix->bv_len > 0 ) {
2940 HASH_Update( &HASHcontext,
2941 prefix->bv_val, prefix->bv_len );
2944 HASH_Update( &HASHcontext,
2945 &pre, sizeof( pre ) );
2946 HASH_Update( &HASHcontext,
2947 syntax->ssyn_oid, slen );
2948 HASH_Update( &HASHcontext,
2949 mr->smr_oid, mlen );
2950 HASH_Update( &HASHcontext,
2952 SLAP_INDEX_SUBSTR_MAXLEN );
2953 HASH_Final( HASHdigest, &HASHcontext );
2955 ber_dupbv( &keys[nkeys++], &digest );
2959 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2960 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2962 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2965 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2966 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
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,
2980 HASH_Final( HASHdigest, &HASHcontext );
2982 ber_dupbv( &keys[nkeys++], &digest );
2985 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2986 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2987 HASH_Init( &HASHcontext );
2988 if( prefix != NULL && prefix->bv_len > 0 ) {
2989 HASH_Update( &HASHcontext,
2990 prefix->bv_val, prefix->bv_len );
2992 HASH_Update( &HASHcontext,
2993 &pre, sizeof( pre ) );
2994 HASH_Update( &HASHcontext,
2995 syntax->ssyn_oid, slen );
2996 HASH_Update( &HASHcontext,
2997 mr->smr_oid, mlen );
2998 HASH_Update( &HASHcontext,
2999 &value.bv_val[value.bv_len-j], j );
3000 HASH_Final( HASHdigest, &HASHcontext );
3002 ber_dupbv( &keys[nkeys++], &digest );
3007 free( value.bv_val );
3011 keys[nkeys].bv_val = NULL;
3018 return LDAP_SUCCESS;
3021 static int caseIgnoreIA5SubstringsFilter(
3026 struct berval *prefix,
3030 SubstringsAssertion *sa = assertValue;
3032 ber_len_t nkeys = 0;
3033 size_t slen, mlen, klen;
3035 HASH_CONTEXT HASHcontext;
3036 unsigned char HASHdigest[HASH_BYTES];
3037 struct berval value;
3038 struct berval digest;
3040 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3041 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3046 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3048 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3049 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3050 /* don't bother accounting for stepping */
3051 nkeys += sa->sa_any[i].bv_len -
3052 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3057 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3058 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3065 return LDAP_SUCCESS;
3068 digest.bv_val = HASHdigest;
3069 digest.bv_len = sizeof(HASHdigest);
3071 slen = syntax->ssyn_oidlen;
3072 mlen = mr->smr_oidlen;
3074 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3077 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3078 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3080 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3081 ber_dupbv( &value, &sa->sa_initial );
3082 ldap_pvt_str2upper( value.bv_val );
3084 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3085 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3087 HASH_Init( &HASHcontext );
3088 if( prefix != NULL && prefix->bv_len > 0 ) {
3089 HASH_Update( &HASHcontext,
3090 prefix->bv_val, prefix->bv_len );
3092 HASH_Update( &HASHcontext,
3093 &pre, sizeof( pre ) );
3094 HASH_Update( &HASHcontext,
3095 syntax->ssyn_oid, slen );
3096 HASH_Update( &HASHcontext,
3097 mr->smr_oid, mlen );
3098 HASH_Update( &HASHcontext,
3099 value.bv_val, klen );
3100 HASH_Final( HASHdigest, &HASHcontext );
3102 free( value.bv_val );
3103 ber_dupbv( &keys[nkeys++], &digest );
3106 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3108 pre = SLAP_INDEX_SUBSTR_PREFIX;
3109 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3111 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3112 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3116 ber_dupbv( &value, &sa->sa_any[i] );
3117 ldap_pvt_str2upper( value.bv_val );
3120 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3121 j += SLAP_INDEX_SUBSTR_STEP )
3123 HASH_Init( &HASHcontext );
3124 if( prefix != NULL && prefix->bv_len > 0 ) {
3125 HASH_Update( &HASHcontext,
3126 prefix->bv_val, prefix->bv_len );
3128 HASH_Update( &HASHcontext,
3129 &pre, sizeof( pre ) );
3130 HASH_Update( &HASHcontext,
3131 syntax->ssyn_oid, slen );
3132 HASH_Update( &HASHcontext,
3133 mr->smr_oid, mlen );
3134 HASH_Update( &HASHcontext,
3135 &value.bv_val[j], klen );
3136 HASH_Final( HASHdigest, &HASHcontext );
3138 ber_dupbv( &keys[nkeys++], &digest );
3141 free( value.bv_val );
3145 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3146 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3148 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3149 ber_dupbv( &value, &sa->sa_final );
3150 ldap_pvt_str2upper( value.bv_val );
3152 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3153 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3155 HASH_Init( &HASHcontext );
3156 if( prefix != NULL && prefix->bv_len > 0 ) {
3157 HASH_Update( &HASHcontext,
3158 prefix->bv_val, prefix->bv_len );
3160 HASH_Update( &HASHcontext,
3161 &pre, sizeof( pre ) );
3162 HASH_Update( &HASHcontext,
3163 syntax->ssyn_oid, slen );
3164 HASH_Update( &HASHcontext,
3165 mr->smr_oid, mlen );
3166 HASH_Update( &HASHcontext,
3167 &value.bv_val[value.bv_len-klen], klen );
3168 HASH_Final( HASHdigest, &HASHcontext );
3170 free( value.bv_val );
3171 ber_dupbv( &keys[nkeys++], &digest );
3175 keys[nkeys].bv_val = NULL;
3182 return LDAP_SUCCESS;
3186 numericStringValidate(
3192 for(i=0; i < in->bv_len; i++) {
3193 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3194 return LDAP_INVALID_SYNTAX;
3198 return LDAP_SUCCESS;
3202 numericStringNormalize(
3205 struct berval *normalized )
3207 /* removal all spaces */
3210 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3213 q = normalized->bv_val;
3216 if ( ASCII_SPACE( *p ) ) {
3217 /* Ignore whitespace */
3224 /* we should have copied no more then is in val */
3225 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3227 /* null terminate */
3230 normalized->bv_len = q - normalized->bv_val;
3232 return LDAP_SUCCESS;
3236 objectIdentifierFirstComponentMatch(
3241 struct berval *value,
3242 void *assertedValue )
3244 int rc = LDAP_SUCCESS;
3246 struct berval *asserted = (struct berval *) assertedValue;
3250 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3251 return LDAP_INVALID_SYNTAX;
3254 /* trim leading white space */
3255 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3259 /* grab next word */
3260 oid.bv_val = &value->bv_val[i];
3261 oid.bv_len = value->bv_len - i;
3262 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3267 /* insert attributeTypes, objectclass check here */
3268 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3269 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3272 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3273 MatchingRule *asserted_mr = mr_bvfind( asserted );
3274 MatchingRule *stored_mr = mr_bvfind( &oid );
3276 if( asserted_mr == NULL ) {
3277 rc = SLAPD_COMPARE_UNDEFINED;
3279 match = asserted_mr != stored_mr;
3282 } else if ( !strcmp( syntax->ssyn_oid,
3283 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3285 AttributeType *asserted_at = at_bvfind( asserted );
3286 AttributeType *stored_at = at_bvfind( &oid );
3288 if( asserted_at == NULL ) {
3289 rc = SLAPD_COMPARE_UNDEFINED;
3291 match = asserted_at != stored_at;
3294 } else if ( !strcmp( syntax->ssyn_oid,
3295 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3297 ObjectClass *asserted_oc = oc_bvfind( asserted );
3298 ObjectClass *stored_oc = oc_bvfind( &oid );
3300 if( asserted_oc == NULL ) {
3301 rc = SLAPD_COMPARE_UNDEFINED;
3303 match = asserted_oc != stored_oc;
3309 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3310 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3311 match, value->bv_val, asserted->bv_val ));
3313 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3314 "%d\n\t\"%s\"\n\t\"%s\"\n",
3315 match, value->bv_val, asserted->bv_val );
3319 if( rc == LDAP_SUCCESS ) *matchp = match;
3329 struct berval *value,
3330 void *assertedValue )
3332 long lValue, lAssertedValue;
3334 /* safe to assume integers are NUL terminated? */
3335 lValue = strtoul(value->bv_val, NULL, 10);
3336 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3337 return LDAP_CONSTRAINT_VIOLATION;
3339 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3340 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3341 return LDAP_CONSTRAINT_VIOLATION;
3343 *matchp = (lValue & lAssertedValue);
3344 return LDAP_SUCCESS;
3353 struct berval *value,
3354 void *assertedValue )
3356 long lValue, lAssertedValue;
3358 /* safe to assume integers are NUL terminated? */
3359 lValue = strtoul(value->bv_val, NULL, 10);
3360 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3361 return LDAP_CONSTRAINT_VIOLATION;
3363 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3364 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3365 return LDAP_CONSTRAINT_VIOLATION;
3367 *matchp = (lValue | lAssertedValue);
3368 return LDAP_SUCCESS;
3372 #include <openssl/x509.h>
3373 #include <openssl/err.h>
3374 char digit[] = "0123456789";
3377 * Next function returns a string representation of a ASN1_INTEGER.
3378 * It works for unlimited lengths.
3381 static struct berval *
3382 asn1_integer2str(ASN1_INTEGER *a)
3387 /* We work backwards, make it fill from the end of buf */
3388 p = buf + sizeof(buf) - 1;
3391 if ( a == NULL || a->length == 0 ) {
3399 /* We want to preserve the original */
3400 copy = ch_malloc(n*sizeof(unsigned int));
3401 for (i = 0; i<n; i++) {
3402 copy[i] = a->data[i];
3406 * base indicates the index of the most significant
3407 * byte that might be nonzero. When it goes off the
3408 * end, we now there is nothing left to do.
3414 for (i = base; i<n; i++ ) {
3415 copy[i] += carry*256;
3416 carry = copy[i] % 10;
3421 * Way too large, we need to leave
3422 * room for sign if negative
3427 *--p = digit[carry];
3428 if (copy[base] == 0)
3434 if ( a->type == V_ASN1_NEG_INTEGER ) {
3438 return ber_bvstrdup(p);
3441 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3442 static struct berval *
3443 dn_openssl2ldap(X509_NAME *name)
3445 char issuer_dn[1024];
3448 bio = BIO_new(BIO_s_mem());
3451 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3452 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3453 ERR_error_string(ERR_get_error(),NULL)));
3455 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3456 "error creating BIO: %s\n",
3457 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3461 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3463 BIO_gets(bio, issuer_dn, 1024);
3466 return ber_bvstrdup(issuer_dn);
3470 * Given a certificate in DER format, extract the corresponding
3471 * assertion value for certificateExactMatch
3474 certificateExactConvert(
3476 struct berval * out )
3479 unsigned char *p = in->bv_val;
3480 struct berval *serial;
3481 struct berval *issuer_dn;
3482 struct berval *bv_tmp;
3484 xcert = d2i_X509(NULL, &p, in->bv_len);
3487 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3488 "certificateExactConvert: error parsing cert: %s\n",
3489 ERR_error_string(ERR_get_error(),NULL)));
3491 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3492 "error parsing cert: %s\n",
3493 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3495 return LDAP_INVALID_SYNTAX;
3498 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3501 return LDAP_INVALID_SYNTAX;
3503 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3507 return LDAP_INVALID_SYNTAX;
3509 /* Actually, dn_openssl2ldap returns in a normalized format, but
3510 it is different from our normalized format */
3512 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3516 return LDAP_INVALID_SYNTAX;
3522 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3523 out->bv_val = ch_malloc(out->bv_len);
3525 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3526 p += serial->bv_len;
3527 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3529 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3530 p += issuer_dn->bv_len;
3534 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3535 "certificateExactConvert: \n %s\n",
3538 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3540 out->bv_val, NULL, NULL );
3544 ber_bvfree(issuer_dn);
3546 return LDAP_SUCCESS;
3550 serial_and_issuer_parse(
3551 struct berval *assertion,
3552 struct berval **serial,
3553 struct berval **issuer_dn
3561 begin = assertion->bv_val;
3562 end = assertion->bv_val+assertion->bv_len-1;
3563 for (p=begin; p<=end && *p != '$'; p++)
3566 return LDAP_INVALID_SYNTAX;
3568 /* p now points at the $ sign, now use begin and end to delimit the
3570 while (ASCII_SPACE(*begin))
3573 while (ASCII_SPACE(*end))
3576 bv.bv_len = end-begin+1;
3578 *serial = ber_dupbv(NULL, &bv);
3580 /* now extract the issuer, remember p was at the dollar sign */
3582 end = assertion->bv_val+assertion->bv_len-1;
3583 while (ASCII_SPACE(*begin))
3585 /* should we trim spaces at the end too? is it safe always? */
3587 bv.bv_len = end-begin+1;
3589 dnNormalize( NULL, &bv, issuer_dn );
3591 return LDAP_SUCCESS;
3595 certificateExactMatch(
3600 struct berval *value,
3601 void *assertedValue )
3604 unsigned char *p = value->bv_val;
3605 struct berval *serial;
3606 struct berval *issuer_dn;
3607 struct berval *asserted_serial;
3608 struct berval *asserted_issuer_dn;
3611 xcert = d2i_X509(NULL, &p, value->bv_len);
3614 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3615 "certificateExactMatch: error parsing cert: %s\n",
3616 ERR_error_string(ERR_get_error(),NULL)));
3618 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3619 "error parsing cert: %s\n",
3620 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3622 return LDAP_INVALID_SYNTAX;
3625 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3626 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3630 serial_and_issuer_parse(assertedValue,
3632 &asserted_issuer_dn);
3637 slap_schema.si_syn_integer,
3638 slap_schema.si_mr_integerMatch,
3641 if ( ret == LDAP_SUCCESS ) {
3642 if ( *matchp == 0 ) {
3643 /* We need to normalize everything for dnMatch */
3647 slap_schema.si_syn_distinguishedName,
3648 slap_schema.si_mr_distinguishedNameMatch,
3650 asserted_issuer_dn);
3655 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3656 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3657 *matchp, serial->bv_val, issuer_dn->bv_val,
3658 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3660 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3661 "%d\n\t\"%s $ %s\"\n",
3662 *matchp, serial->bv_val, issuer_dn->bv_val );
3663 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3664 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3669 ber_bvfree(issuer_dn);
3670 ber_bvfree(asserted_serial);
3671 ber_bvfree(asserted_issuer_dn);
3677 * Index generation function
3678 * We just index the serials, in most scenarios the issuer DN is one of
3679 * a very small set of values.
3681 static int certificateExactIndexer(
3686 struct berval *prefix,
3694 struct berval * serial;
3696 /* we should have at least one value at this point */
3697 assert( values != NULL && values[0].bv_val != NULL );
3699 for( i=0; values[i].bv_val != NULL; i++ ) {
3700 /* empty -- just count them */
3703 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3705 for( i=0; values[i].bv_val != NULL; i++ ) {
3706 p = values[i].bv_val;
3707 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3710 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3711 "certificateExactIndexer: error parsing cert: %s\n",
3712 ERR_error_string(ERR_get_error(),NULL)));
3714 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3715 "error parsing cert: %s\n",
3716 ERR_error_string(ERR_get_error(),NULL),
3719 /* Do we leak keys on error? */
3720 return LDAP_INVALID_SYNTAX;
3723 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3725 integerNormalize( slap_schema.si_syn_integer,
3730 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3731 "certificateExactIndexer: returning: %s\n",
3734 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3741 keys[i].bv_val = NULL;
3743 return LDAP_SUCCESS;
3746 /* Index generation function */
3747 /* We think this is always called with a value in matching rule syntax */
3748 static int certificateExactFilter(
3753 struct berval *prefix,
3758 struct berval *asserted_serial;
3759 struct berval *asserted_issuer_dn;
3761 serial_and_issuer_parse(assertValue,
3763 &asserted_issuer_dn);
3765 keys = ch_malloc( sizeof( struct berval ) * 2 );
3766 integerNormalize( syntax, asserted_serial, &keys[0] );
3767 keys[1].bv_val = NULL;
3770 ber_bvfree(asserted_serial);
3771 ber_bvfree(asserted_issuer_dn);
3772 return LDAP_SUCCESS;
3777 check_time_syntax (struct berval *val,
3781 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3782 static int mdays[2][12] = {
3783 /* non-leap years */
3784 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3786 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3789 int part, c, tzoffset, leapyear = 0 ;
3791 if( val->bv_len == 0 ) {
3792 return LDAP_INVALID_SYNTAX;
3795 p = (char *)val->bv_val;
3796 e = p + val->bv_len;
3798 /* Ignore initial whitespace */
3799 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3803 if (e - p < 13 - (2 * start)) {
3804 return LDAP_INVALID_SYNTAX;
3807 for (part = 0; part < 9; part++) {
3811 for (part = start; part < 7; part++) {
3813 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3820 return LDAP_INVALID_SYNTAX;
3822 if (c < 0 || c > 9) {
3823 return LDAP_INVALID_SYNTAX;
3829 return LDAP_INVALID_SYNTAX;
3831 if (c < 0 || c > 9) {
3832 return LDAP_INVALID_SYNTAX;
3837 if (part == 2 || part == 3) {
3840 if (parts[part] < 0) {
3841 return LDAP_INVALID_SYNTAX;
3843 if (parts[part] > ceiling[part]) {
3844 return LDAP_INVALID_SYNTAX;
3848 /* leapyear check for the Gregorian calendar (year>1581) */
3849 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3850 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3855 if (parts[3] > mdays[leapyear][parts[2]]) {
3856 return LDAP_INVALID_SYNTAX;
3861 tzoffset = 0; /* UTC */
3862 } else if (c != '+' && c != '-') {
3863 return LDAP_INVALID_SYNTAX;
3867 } else /* c == '+' */ {
3872 return LDAP_INVALID_SYNTAX;
3875 for (part = 7; part < 9; part++) {
3877 if (c < 0 || c > 9) {
3878 return LDAP_INVALID_SYNTAX;
3883 if (c < 0 || c > 9) {
3884 return LDAP_INVALID_SYNTAX;
3888 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3889 return LDAP_INVALID_SYNTAX;
3894 /* Ignore trailing whitespace */
3895 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3899 return LDAP_INVALID_SYNTAX;
3902 switch ( tzoffset ) {
3903 case -1: /* negativ offset to UTC, ie west of Greenwich */
3904 parts[4] += parts[7];
3905 parts[5] += parts[8];
3906 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3910 c = mdays[leapyear][parts[2]];
3912 if (parts[part] > c) {
3913 parts[part] -= c + 1;
3918 case 1: /* positive offset to UTC, ie east of Greenwich */
3919 parts[4] -= parts[7];
3920 parts[5] -= parts[8];
3921 for (part = 6; --part > 0; ) {
3925 /* first arg to % needs to be non negativ */
3926 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3928 if (parts[part] < 0) {
3929 parts[part] += c + 1;
3934 case 0: /* already UTC */
3938 return LDAP_SUCCESS;
3945 struct berval *normalized )
3949 rc = check_time_syntax(val, 1, parts);
3950 if (rc != LDAP_SUCCESS) {
3954 normalized->bv_val = ch_malloc( 14 );
3955 if ( normalized->bv_val == NULL ) {
3956 return LBER_ERROR_MEMORY;
3959 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3960 parts[1], parts[2] + 1, parts[3] + 1,
3961 parts[4], parts[5], parts[6] );
3962 normalized->bv_len = 13;
3964 return LDAP_SUCCESS;
3974 return check_time_syntax(in, 1, parts);
3978 generalizedTimeValidate(
3984 return check_time_syntax(in, 0, parts);
3988 generalizedTimeNormalize(
3991 struct berval *normalized )
3995 rc = check_time_syntax(val, 0, parts);
3996 if (rc != LDAP_SUCCESS) {
4000 normalized->bv_val = ch_malloc( 16 );
4001 if ( normalized->bv_val == NULL ) {
4002 return LBER_ERROR_MEMORY;
4005 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4006 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4007 parts[4], parts[5], parts[6] );
4008 normalized->bv_len = 15;
4010 return LDAP_SUCCESS;
4014 nisNetgroupTripleValidate(
4016 struct berval *val )
4021 if ( val->bv_len == 0 ) {
4022 return LDAP_INVALID_SYNTAX;
4025 p = (char *)val->bv_val;
4026 e = p + val->bv_len;
4028 if ( *p != '(' /*')'*/ ) {
4029 return LDAP_INVALID_SYNTAX;
4032 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4036 return LDAP_INVALID_SYNTAX;
4039 } else if ( !ATTR_CHAR( *p ) ) {
4040 return LDAP_INVALID_SYNTAX;
4044 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4045 return LDAP_INVALID_SYNTAX;
4051 return LDAP_INVALID_SYNTAX;
4054 return LDAP_SUCCESS;
4058 bootParameterValidate(
4060 struct berval *val )
4064 if ( val->bv_len == 0 ) {
4065 return LDAP_INVALID_SYNTAX;
4068 p = (char *)val->bv_val;
4069 e = p + val->bv_len;
4072 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4073 if ( !ATTR_CHAR( *p ) ) {
4074 return LDAP_INVALID_SYNTAX;
4079 return LDAP_INVALID_SYNTAX;
4083 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4084 if ( !ATTR_CHAR( *p ) ) {
4085 return LDAP_INVALID_SYNTAX;
4090 return LDAP_INVALID_SYNTAX;
4094 for ( p++; p < e; p++ ) {
4095 if ( !ATTR_CHAR( *p ) ) {
4096 return LDAP_INVALID_SYNTAX;
4100 return LDAP_SUCCESS;
4103 static struct syntax_defs_rec {
4105 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4106 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4108 slap_syntax_validate_func *sd_validate;
4109 slap_syntax_transform_func *sd_normalize;
4110 slap_syntax_transform_func *sd_pretty;
4111 #ifdef SLAPD_BINARY_CONVERSION
4112 slap_syntax_transform_func *sd_ber2str;
4113 slap_syntax_transform_func *sd_str2ber;
4116 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4117 X_BINARY X_NOT_H_R ")",
4118 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4119 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4120 0, NULL, NULL, NULL},
4121 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4122 0, NULL, NULL, NULL},
4123 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4125 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4126 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4128 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4129 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4130 0, bitStringValidate, bitStringNormalize, NULL },
4131 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4132 0, booleanValidate, NULL, NULL},
4133 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4134 X_BINARY X_NOT_H_R ")",
4135 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4136 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4137 X_BINARY X_NOT_H_R ")",
4138 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4139 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4140 X_BINARY X_NOT_H_R ")",
4141 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4142 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4143 0, countryStringValidate, IA5StringNormalize, NULL},
4144 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4145 0, dnValidate, dnNormalize2, dnPretty2},
4146 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4147 0, NULL, NULL, NULL},
4148 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4149 0, NULL, NULL, NULL},
4150 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4151 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4152 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4153 0, NULL, NULL, NULL},
4154 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4155 0, NULL, NULL, NULL},
4156 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4157 0, NULL, NULL, NULL},
4158 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4159 0, NULL, NULL, NULL},
4160 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4161 0, NULL, NULL, NULL},
4162 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4163 0, printablesStringValidate, IA5StringNormalize, NULL},
4164 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4165 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4166 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4167 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4168 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4169 0, NULL, NULL, NULL},
4170 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4171 0, IA5StringValidate, IA5StringNormalize, NULL},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4173 0, integerValidate, integerNormalize, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4175 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4177 0, NULL, NULL, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4179 0, NULL, NULL, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4181 0, NULL, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4183 0, NULL, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4185 0, NULL, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4187 0, nameUIDValidate, nameUIDNormalize, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4189 0, NULL, NULL, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4191 0, numericStringValidate, numericStringNormalize, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4193 0, NULL, NULL, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4195 0, oidValidate, NULL, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4197 0, IA5StringValidate, IA5StringNormalize, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4199 0, blobValidate, NULL, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4201 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4203 0, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4205 0, NULL, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4207 0, printableStringValidate, IA5StringNormalize, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4209 X_BINARY X_NOT_H_R ")",
4210 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4212 X_BINARY X_NOT_H_R ")",
4213 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4215 0, printableStringValidate, IA5StringNormalize, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4217 0, NULL, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4219 0, printablesStringValidate, IA5StringNormalize, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4221 0, utcTimeValidate, utcTimeNormalize, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4223 0, NULL, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4225 0, NULL, NULL, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4227 0, NULL, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4229 0, NULL, NULL, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4231 0, NULL, NULL, NULL},
4233 /* RFC 2307 NIS Syntaxes */
4234 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4235 0, nisNetgroupTripleValidate, NULL, NULL},
4236 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4237 0, bootParameterValidate, NULL, NULL},
4241 /* These OIDs are not published yet, but will be in the next
4242 * I-D for PKIX LDAPv3 schema as have been advanced by David
4243 * Chadwick in private mail.
4245 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4246 0, NULL, NULL, NULL},
4249 /* OpenLDAP Experimental Syntaxes */
4250 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4252 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4255 /* needs updating */
4256 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4257 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4259 /* OpenLDAP Void Syntax */
4260 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4261 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4262 {NULL, 0, NULL, NULL, NULL}
4266 * Other matching rules in X.520 that we do not use (yet):
4268 * 2.5.13.9 numericStringOrderingMatch
4269 * 2.5.13.15 integerOrderingMatch
4270 * 2.5.13.18 octetStringOrderingMatch
4271 * 2.5.13.19 octetStringSubstringsMatch
4272 * 2.5.13.25 uTCTimeMatch
4273 * 2.5.13.26 uTCTimeOrderingMatch
4274 * 2.5.13.31 directoryStringFirstComponentMatch
4275 * 2.5.13.32 wordMatch
4276 * 2.5.13.33 keywordMatch
4277 * 2.5.13.35 certificateMatch
4278 * 2.5.13.36 certificatePairExactMatch
4279 * 2.5.13.37 certificatePairMatch
4280 * 2.5.13.38 certificateListExactMatch
4281 * 2.5.13.39 certificateListMatch
4282 * 2.5.13.40 algorithmIdentifierMatch
4283 * 2.5.13.41 storedPrefixMatch
4284 * 2.5.13.42 attributeCertificateMatch
4285 * 2.5.13.43 readerAndKeyIDMatch
4286 * 2.5.13.44 attributeIntegrityMatch
4288 static struct mrule_defs_rec {
4290 slap_mask_t mrd_usage;
4291 slap_mr_convert_func * mrd_convert;
4292 slap_mr_normalize_func * mrd_normalize;
4293 slap_mr_match_func * mrd_match;
4294 slap_mr_indexer_func * mrd_indexer;
4295 slap_mr_filter_func * mrd_filter;
4297 char * mrd_associated;
4300 * EQUALITY matching rules must be listed after associated APPROX
4301 * matching rules. So, we list all APPROX matching rules first.
4303 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4304 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4305 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4307 directoryStringApproxMatch,
4308 directoryStringApproxIndexer,
4309 directoryStringApproxFilter,
4312 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4313 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4314 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4316 IA5StringApproxMatch,
4317 IA5StringApproxIndexer,
4318 IA5StringApproxFilter,
4322 * Other matching rules
4325 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4326 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4327 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4329 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4332 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4333 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4334 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4336 dnMatch, dnIndexer, dnFilter,
4339 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4340 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4341 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4343 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4344 directoryStringApproxMatchOID },
4346 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4347 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4350 caseIgnoreOrderingMatch, NULL, NULL,
4353 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4354 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4355 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4357 caseExactIgnoreSubstringsMatch,
4358 caseExactIgnoreSubstringsIndexer,
4359 caseExactIgnoreSubstringsFilter,
4362 {"( 2.5.13.5 NAME 'caseExactMatch' "
4363 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4364 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4366 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4367 directoryStringApproxMatchOID },
4369 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4370 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4373 caseExactOrderingMatch, NULL, NULL,
4376 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4377 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4378 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4380 caseExactIgnoreSubstringsMatch,
4381 caseExactIgnoreSubstringsIndexer,
4382 caseExactIgnoreSubstringsFilter,
4385 {"( 2.5.13.8 NAME 'numericStringMatch' "
4386 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4387 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4390 caseIgnoreIA5Indexer,
4391 caseIgnoreIA5Filter,
4394 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4395 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4396 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4398 caseIgnoreIA5SubstringsMatch,
4399 caseIgnoreIA5SubstringsIndexer,
4400 caseIgnoreIA5SubstringsFilter,
4403 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4404 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4405 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4407 caseIgnoreListMatch, NULL, NULL,
4410 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4411 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4412 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4414 caseIgnoreListSubstringsMatch, NULL, NULL,
4417 {"( 2.5.13.13 NAME 'booleanMatch' "
4418 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4419 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4421 booleanMatch, NULL, NULL,
4424 {"( 2.5.13.14 NAME 'integerMatch' "
4425 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4426 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4428 integerMatch, integerIndexer, integerFilter,
4431 {"( 2.5.13.16 NAME 'bitStringMatch' "
4432 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4433 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4435 bitStringMatch, bitStringIndexer, bitStringFilter,
4438 {"( 2.5.13.17 NAME 'octetStringMatch' "
4439 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4440 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4442 octetStringMatch, octetStringIndexer, octetStringFilter,
4445 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4446 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4447 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4449 telephoneNumberMatch,
4450 telephoneNumberIndexer,
4451 telephoneNumberFilter,
4454 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4455 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4456 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4458 telephoneNumberSubstringsMatch,
4459 telephoneNumberSubstringsIndexer,
4460 telephoneNumberSubstringsFilter,
4463 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4464 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4465 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4470 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4471 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4472 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4474 uniqueMemberMatch, NULL, NULL,
4477 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4478 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4479 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4481 protocolInformationMatch, NULL, NULL,
4484 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4485 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4486 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4488 generalizedTimeMatch, NULL, NULL,
4491 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4492 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4495 generalizedTimeOrderingMatch, NULL, NULL,
4498 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4499 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4500 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4502 integerFirstComponentMatch, NULL, NULL,
4505 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4506 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4507 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4509 objectIdentifierFirstComponentMatch, NULL, NULL,
4513 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4514 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4515 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4516 certificateExactConvert, NULL,
4517 certificateExactMatch,
4518 certificateExactIndexer, certificateExactFilter,
4522 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4523 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4524 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4526 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4527 IA5StringApproxMatchOID },
4529 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4530 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4531 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4533 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4534 IA5StringApproxMatchOID },
4536 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4537 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4540 caseIgnoreIA5SubstringsMatch,
4541 caseIgnoreIA5SubstringsIndexer,
4542 caseIgnoreIA5SubstringsFilter,
4545 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4546 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4549 caseExactIA5SubstringsMatch,
4550 caseExactIA5SubstringsIndexer,
4551 caseExactIA5SubstringsFilter,
4554 /* needs updating */
4555 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4556 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4559 authPasswordMatch, NULL, NULL,
4562 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4563 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4566 OpenLDAPaciMatch, NULL, NULL,
4569 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4570 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4573 integerBitAndMatch, NULL, NULL,
4576 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4577 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4580 integerBitOrMatch, NULL, NULL,
4583 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4592 /* we should only be called once (from main) */
4593 assert( schema_init_done == 0 );
4595 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4596 res = register_syntax( syntax_defs[i].sd_desc,
4597 syntax_defs[i].sd_flags,
4598 syntax_defs[i].sd_validate,
4599 syntax_defs[i].sd_normalize,
4600 syntax_defs[i].sd_pretty
4601 #ifdef SLAPD_BINARY_CONVERSION
4603 syntax_defs[i].sd_ber2str,
4604 syntax_defs[i].sd_str2ber
4609 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4610 syntax_defs[i].sd_desc );
4615 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4616 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4618 "schema_init: Ingoring unusable matching rule %s\n",
4619 mrule_defs[i].mrd_desc );
4623 res = register_matching_rule(
4624 mrule_defs[i].mrd_desc,
4625 mrule_defs[i].mrd_usage,
4626 mrule_defs[i].mrd_convert,
4627 mrule_defs[i].mrd_normalize,
4628 mrule_defs[i].mrd_match,
4629 mrule_defs[i].mrd_indexer,
4630 mrule_defs[i].mrd_filter,
4631 mrule_defs[i].mrd_associated );
4635 "schema_init: Error registering matching rule %s\n",
4636 mrule_defs[i].mrd_desc );
4640 schema_init_done = 1;
4641 return LDAP_SUCCESS;
4645 schema_destroy( void )