1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2000 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 dn = ber_bvdup( in );
230 if( !dn ) 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] != '#' ) {
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 SAFEMEMCPY( b2.bv_val, normalized->bv_val, dnlen );
308 /* restore the separator */
311 SAFEMEMCPY( 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 = memmove(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, UTF8_NOCASEFOLD );
674 strip8bitChars( nval );
676 /* Yes, this is necessary */
677 assertv = UTF8normalize( ((struct berval *)assertedValue),
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], 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 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),
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,
1003 return LDAP_SUCCESS;
1007 caseExactIgnoreSubstringsMatch(
1012 struct berval *value,
1013 void *assertedValue )
1016 SubstringsAssertion *sub = NULL;
1020 char *nav, casefold;
1022 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1023 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1025 nav = UTF8normalize( value, casefold );
1031 left.bv_len = strlen( nav );
1033 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1039 /* Add up asserted input length */
1040 if( sub->sa_initial.bv_val ) {
1041 inlen += sub->sa_initial.bv_len;
1044 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1045 inlen += sub->sa_any[i].bv_len;
1048 if( sub->sa_final.bv_val ) {
1049 inlen += sub->sa_final.bv_len;
1052 if( sub->sa_initial.bv_val ) {
1053 if( inlen > left.bv_len ) {
1058 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
1059 sub->sa_initial.bv_len );
1065 left.bv_val += sub->sa_initial.bv_len;
1066 left.bv_len -= sub->sa_initial.bv_len;
1067 inlen -= sub->sa_initial.bv_len;
1070 if( sub->sa_final.bv_val ) {
1071 if( inlen > left.bv_len ) {
1076 match = strncmp( sub->sa_final.bv_val,
1077 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1078 sub->sa_final.bv_len );
1084 left.bv_len -= sub->sa_final.bv_len;
1085 inlen -= sub->sa_final.bv_len;
1089 for(i=0; sub->sa_any[i].bv_val; i++) {
1094 if( inlen > left.bv_len ) {
1095 /* not enough length */
1100 if( sub->sa_any[i].bv_len == 0 ) {
1104 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
1111 idx = p - left.bv_val;
1112 assert( idx < left.bv_len );
1114 if( idx >= left.bv_len ) {
1115 /* this shouldn't happen */
1117 if ( sub->sa_final.bv_val )
1118 ch_free( sub->sa_final.bv_val );
1120 bvarray_free( sub->sa_any );
1121 if ( sub->sa_initial.bv_val )
1122 ch_free( sub->sa_initial.bv_val );
1130 if( sub->sa_any[i].bv_len > left.bv_len ) {
1131 /* not enough left */
1136 match = strncmp( left.bv_val,
1137 sub->sa_any[i].bv_val,
1138 sub->sa_any[i].bv_len );
1146 left.bv_val += sub->sa_any[i].bv_len;
1147 left.bv_len -= sub->sa_any[i].bv_len;
1148 inlen -= sub->sa_any[i].bv_len;
1155 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1156 if ( sub->sa_any ) bvarray_free( sub->sa_any );
1157 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1161 return LDAP_SUCCESS;
1164 /* Index generation function */
1165 static int caseExactIgnoreIndexer(
1170 struct berval *prefix,
1178 HASH_CONTEXT HASHcontext;
1179 unsigned char HASHdigest[HASH_BYTES];
1180 struct berval digest;
1181 digest.bv_val = HASHdigest;
1182 digest.bv_len = sizeof(HASHdigest);
1184 for( i=0; values[i].bv_val != NULL; i++ ) {
1185 /* empty - just count them */
1188 /* we should have at least one value at this point */
1191 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1193 slen = syntax->ssyn_oidlen;
1194 mlen = mr->smr_oidlen;
1196 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1197 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1199 for( i=0; values[i].bv_val != NULL; i++ ) {
1200 struct berval value;
1201 ber_str2bv( UTF8normalize( &values[i], casefold ), 0, 0,
1204 HASH_Init( &HASHcontext );
1205 if( prefix != NULL && prefix->bv_len > 0 ) {
1206 HASH_Update( &HASHcontext,
1207 prefix->bv_val, prefix->bv_len );
1209 HASH_Update( &HASHcontext,
1210 syntax->ssyn_oid, slen );
1211 HASH_Update( &HASHcontext,
1212 mr->smr_oid, mlen );
1213 HASH_Update( &HASHcontext,
1214 value.bv_val, value.bv_len );
1215 HASH_Final( HASHdigest, &HASHcontext );
1217 free( value.bv_val );
1219 ber_dupbv( &keys[i], &digest );
1222 keys[i].bv_val = NULL;
1224 return LDAP_SUCCESS;
1227 /* Index generation function */
1228 static int caseExactIgnoreFilter(
1233 struct berval *prefix,
1240 HASH_CONTEXT HASHcontext;
1241 unsigned char HASHdigest[HASH_BYTES];
1242 struct berval value;
1243 struct berval digest;
1244 digest.bv_val = HASHdigest;
1245 digest.bv_len = sizeof(HASHdigest);
1247 slen = syntax->ssyn_oidlen;
1248 mlen = mr->smr_oidlen;
1250 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1251 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1253 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1255 /* This usually happens if filter contains bad UTF8 */
1256 if( value.bv_val == NULL ) {
1257 keys = ch_malloc( sizeof( struct berval ) );
1258 keys[0].bv_val = NULL;
1259 return LDAP_SUCCESS;
1262 keys = ch_malloc( sizeof( struct berval ) * 2 );
1264 HASH_Init( &HASHcontext );
1265 if( prefix != NULL && prefix->bv_len > 0 ) {
1266 HASH_Update( &HASHcontext,
1267 prefix->bv_val, prefix->bv_len );
1269 HASH_Update( &HASHcontext,
1270 syntax->ssyn_oid, slen );
1271 HASH_Update( &HASHcontext,
1272 mr->smr_oid, mlen );
1273 HASH_Update( &HASHcontext,
1274 value.bv_val, value.bv_len );
1275 HASH_Final( HASHdigest, &HASHcontext );
1277 ber_dupbv( keys, &digest );
1278 keys[1].bv_val = NULL;
1280 free( value.bv_val );
1283 return LDAP_SUCCESS;
1286 /* Substrings Index generation function */
1287 static int caseExactIgnoreSubstringsIndexer(
1292 struct berval *prefix,
1302 HASH_CONTEXT HASHcontext;
1303 unsigned char HASHdigest[HASH_BYTES];
1304 struct berval digest;
1305 digest.bv_val = HASHdigest;
1306 digest.bv_len = sizeof(HASHdigest);
1310 for( i=0; values[i].bv_val != NULL; i++ ) {
1311 /* empty - just count them */
1314 /* we should have at least one value at this point */
1317 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1318 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1320 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1321 for( i=0; values[i].bv_val != NULL; i++ ) {
1322 ber_str2bv( UTF8normalize( &values[i], casefold ),
1323 0, 0, &nvalues[i] );
1325 nvalues[i].bv_val = NULL;
1328 for( i=0; values[i].bv_val != NULL; i++ ) {
1329 /* count number of indices to generate */
1330 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1334 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1335 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1336 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1337 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1339 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1343 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1344 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1345 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1349 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1350 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1351 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1352 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1354 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1360 /* no keys to generate */
1362 bvarray_free( nvalues );
1363 return LDAP_SUCCESS;
1366 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1368 slen = syntax->ssyn_oidlen;
1369 mlen = mr->smr_oidlen;
1372 for( i=0; values[i].bv_val != NULL; i++ ) {
1375 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1377 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1378 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1380 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1381 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1383 for( j=0; j<max; j++ ) {
1384 HASH_Init( &HASHcontext );
1385 if( prefix != NULL && prefix->bv_len > 0 ) {
1386 HASH_Update( &HASHcontext,
1387 prefix->bv_val, prefix->bv_len );
1390 HASH_Update( &HASHcontext,
1391 &pre, sizeof( pre ) );
1392 HASH_Update( &HASHcontext,
1393 syntax->ssyn_oid, slen );
1394 HASH_Update( &HASHcontext,
1395 mr->smr_oid, mlen );
1396 HASH_Update( &HASHcontext,
1397 &values[i].bv_val[j],
1398 SLAP_INDEX_SUBSTR_MAXLEN );
1399 HASH_Final( HASHdigest, &HASHcontext );
1401 ber_dupbv( &keys[nkeys++], &digest );
1405 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1406 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1408 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1411 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1412 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1413 HASH_Init( &HASHcontext );
1414 if( prefix != NULL && prefix->bv_len > 0 ) {
1415 HASH_Update( &HASHcontext,
1416 prefix->bv_val, prefix->bv_len );
1418 HASH_Update( &HASHcontext,
1419 &pre, sizeof( pre ) );
1420 HASH_Update( &HASHcontext,
1421 syntax->ssyn_oid, slen );
1422 HASH_Update( &HASHcontext,
1423 mr->smr_oid, mlen );
1424 HASH_Update( &HASHcontext,
1425 values[i].bv_val, j );
1426 HASH_Final( HASHdigest, &HASHcontext );
1428 ber_dupbv( &keys[nkeys++], &digest );
1431 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1432 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1433 HASH_Init( &HASHcontext );
1434 if( prefix != NULL && prefix->bv_len > 0 ) {
1435 HASH_Update( &HASHcontext,
1436 prefix->bv_val, prefix->bv_len );
1438 HASH_Update( &HASHcontext,
1439 &pre, sizeof( pre ) );
1440 HASH_Update( &HASHcontext,
1441 syntax->ssyn_oid, slen );
1442 HASH_Update( &HASHcontext,
1443 mr->smr_oid, mlen );
1444 HASH_Update( &HASHcontext,
1445 &values[i].bv_val[values[i].bv_len-j], j );
1446 HASH_Final( HASHdigest, &HASHcontext );
1448 ber_dupbv( &keys[nkeys++], &digest );
1456 keys[nkeys].bv_val = NULL;
1463 bvarray_free( nvalues );
1465 return LDAP_SUCCESS;
1468 static int caseExactIgnoreSubstringsFilter(
1473 struct berval *prefix,
1477 SubstringsAssertion *sa;
1479 ber_len_t nkeys = 0;
1480 size_t slen, mlen, klen;
1482 HASH_CONTEXT HASHcontext;
1483 unsigned char HASHdigest[HASH_BYTES];
1484 struct berval *value;
1485 struct berval digest;
1487 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1488 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1490 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1493 return LDAP_SUCCESS;
1496 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1497 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1502 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1504 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1505 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1506 /* don't bother accounting for stepping */
1507 nkeys += sa->sa_any[i].bv_len -
1508 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1513 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1514 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1520 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1521 if ( sa->sa_any ) bvarray_free( sa->sa_any );
1522 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1525 return LDAP_SUCCESS;
1528 digest.bv_val = HASHdigest;
1529 digest.bv_len = sizeof(HASHdigest);
1531 slen = syntax->ssyn_oidlen;
1532 mlen = mr->smr_oidlen;
1534 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1537 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1538 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1540 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1541 value = &sa->sa_initial;
1543 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1544 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1546 HASH_Init( &HASHcontext );
1547 if( prefix != NULL && prefix->bv_len > 0 ) {
1548 HASH_Update( &HASHcontext,
1549 prefix->bv_val, prefix->bv_len );
1551 HASH_Update( &HASHcontext,
1552 &pre, sizeof( pre ) );
1553 HASH_Update( &HASHcontext,
1554 syntax->ssyn_oid, slen );
1555 HASH_Update( &HASHcontext,
1556 mr->smr_oid, mlen );
1557 HASH_Update( &HASHcontext,
1558 value->bv_val, klen );
1559 HASH_Final( HASHdigest, &HASHcontext );
1561 ber_dupbv( &keys[nkeys++], &digest );
1564 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1566 pre = SLAP_INDEX_SUBSTR_PREFIX;
1567 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1569 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1570 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1574 value = &sa->sa_any[i];
1577 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1578 j += SLAP_INDEX_SUBSTR_STEP )
1580 HASH_Init( &HASHcontext );
1581 if( prefix != NULL && prefix->bv_len > 0 ) {
1582 HASH_Update( &HASHcontext,
1583 prefix->bv_val, prefix->bv_len );
1585 HASH_Update( &HASHcontext,
1586 &pre, sizeof( pre ) );
1587 HASH_Update( &HASHcontext,
1588 syntax->ssyn_oid, slen );
1589 HASH_Update( &HASHcontext,
1590 mr->smr_oid, mlen );
1591 HASH_Update( &HASHcontext,
1592 &value->bv_val[j], klen );
1593 HASH_Final( HASHdigest, &HASHcontext );
1595 ber_dupbv( &keys[nkeys++], &digest );
1601 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1602 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1604 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1605 value = &sa->sa_final;
1607 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1608 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1610 HASH_Init( &HASHcontext );
1611 if( prefix != NULL && prefix->bv_len > 0 ) {
1612 HASH_Update( &HASHcontext,
1613 prefix->bv_val, prefix->bv_len );
1615 HASH_Update( &HASHcontext,
1616 &pre, sizeof( pre ) );
1617 HASH_Update( &HASHcontext,
1618 syntax->ssyn_oid, slen );
1619 HASH_Update( &HASHcontext,
1620 mr->smr_oid, mlen );
1621 HASH_Update( &HASHcontext,
1622 &value->bv_val[value->bv_len-klen], klen );
1623 HASH_Final( HASHdigest, &HASHcontext );
1625 ber_dupbv( &keys[nkeys++], &digest );
1629 keys[nkeys].bv_val = NULL;
1635 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1636 if ( sa->sa_any ) bvarray_free( sa->sa_any );
1637 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1640 return LDAP_SUCCESS;
1649 struct berval *value,
1650 void *assertedValue )
1652 *matchp = UTF8normcmp( value->bv_val,
1653 ((struct berval *) assertedValue)->bv_val,
1655 return LDAP_SUCCESS;
1661 struct berval *val )
1665 if( val->bv_len == 0 ) {
1666 /* disallow empty strings */
1667 return LDAP_INVALID_SYNTAX;
1670 if( OID_LEADCHAR(val->bv_val[0]) ) {
1672 for(i=1; i < val->bv_len; i++) {
1673 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1674 if( dot++ ) return 1;
1675 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1678 return LDAP_INVALID_SYNTAX;
1682 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1684 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1685 for(i=1; i < val->bv_len; i++) {
1686 if( !DESC_CHAR(val->bv_val[i] ) ) {
1687 return LDAP_INVALID_SYNTAX;
1691 return LDAP_SUCCESS;
1694 return LDAP_INVALID_SYNTAX;
1703 struct berval *value,
1704 void *assertedValue )
1707 int vsign=0, avsign=0;
1708 struct berval *asserted;
1709 ber_len_t vlen, avlen;
1712 /* Start off pessimistic */
1715 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1717 vlen = value->bv_len;
1719 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1720 /* empty -- skip spaces */
1722 else if ( *v == '+' ) {
1725 else if ( *v == '-' ) {
1728 else if ( ASCII_DIGIT(*v) ) {
1729 if ( vsign == 0 ) vsign = 1;
1737 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1739 asserted = (struct berval *) assertedValue;
1740 av = asserted->bv_val;
1741 avlen = asserted->bv_len;
1743 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1744 /* empty -- skip spaces */
1746 else if ( *av == '+' ) {
1749 else if ( *av == '-' ) {
1752 else if ( ASCII_DIGIT(*av) ) {
1753 if ( avsign == 0 ) avsign = 1;
1761 /* The two ?sign vars are now one of :
1762 -2 negative non-zero number
1764 0 0 collapse these three to 0
1766 +2 positive non-zero number
1768 if ( abs( vsign ) == 1 ) vsign = 0;
1769 if ( abs( avsign ) == 1 ) avsign = 0;
1771 if( vsign != avsign ) return LDAP_SUCCESS;
1773 /* Check the significant digits */
1774 while( vlen && avlen ) {
1775 if( *v != *av ) break;
1782 /* If all digits compared equal, the numbers are equal */
1783 if(( vlen == 0 ) && ( avlen == 0 )) {
1786 return LDAP_SUCCESS;
1792 struct berval *val )
1796 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1798 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1799 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1800 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1801 return LDAP_INVALID_SYNTAX;
1804 for( i=1; i < val->bv_len; i++ ) {
1805 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1808 return LDAP_SUCCESS;
1815 struct berval *normalized )
1825 /* Ignore leading spaces */
1826 while ( len && ( *p == ' ' )) {
1833 negative = ( *p == '-' );
1834 if(( *p == '-' ) || ( *p == '+' )) {
1840 /* Ignore leading zeros */
1841 while ( len && ( *p == '0' )) {
1846 /* If there are no non-zero digits left, the number is zero, otherwise
1847 allocate space for the number and copy it into the buffer */
1849 normalized->bv_val = ch_strdup("0");
1850 normalized->bv_len = 1;
1853 normalized->bv_len = len+negative;
1854 normalized->bv_val = ch_malloc( normalized->bv_len );
1856 normalized->bv_val[0] = '-';
1858 memcpy( normalized->bv_val + negative, p, len );
1861 return LDAP_SUCCESS;
1864 /* Index generation function */
1865 static int integerIndexer(
1870 struct berval *prefix,
1877 /* we should have at least one value at this point */
1878 assert( values != NULL && values[0].bv_val != NULL );
1880 for( i=0; values[i].bv_val != NULL; i++ ) {
1881 /* empty -- just count them */
1884 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1886 for( i=0; values[i].bv_val != NULL; i++ ) {
1887 integerNormalize( syntax, &values[i], &keys[i] );
1890 keys[i].bv_val = NULL;
1892 return LDAP_SUCCESS;
1895 /* Index generation function */
1896 static int integerFilter(
1901 struct berval *prefix,
1907 keys = ch_malloc( sizeof( struct berval ) * 2 );
1908 integerNormalize( syntax, assertValue, &keys[0] );
1909 keys[1].bv_val = NULL;
1912 return LDAP_SUCCESS;
1917 countryStringValidate(
1919 struct berval *val )
1921 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1923 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1924 return LDAP_INVALID_SYNTAX;
1926 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1927 return LDAP_INVALID_SYNTAX;
1930 return LDAP_SUCCESS;
1934 printableStringValidate(
1936 struct berval *val )
1940 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
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 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1960 for(i=0; i < val->bv_len; i++) {
1961 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1962 return LDAP_INVALID_SYNTAX;
1966 return LDAP_SUCCESS;
1972 struct berval *val )
1976 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1978 for(i=0; i < val->bv_len; i++) {
1979 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1982 return LDAP_SUCCESS;
1989 struct berval *normalized )
1995 /* Ignore initial whitespace */
1996 while ( ASCII_SPACE( *p ) ) {
2001 return LDAP_INVALID_SYNTAX;
2004 normalized->bv_val = ch_strdup( p );
2005 p = q = normalized->bv_val;
2008 if ( ASCII_SPACE( *p ) ) {
2011 /* Ignore the extra whitespace */
2012 while ( ASCII_SPACE( *p ) ) {
2020 assert( normalized->bv_val < p );
2023 /* cannot start with a space */
2024 assert( !ASCII_SPACE(*normalized->bv_val) );
2027 * If the string ended in space, backup the pointer one
2028 * position. One is enough because the above loop collapsed
2029 * all whitespace to a single space.
2032 if ( ASCII_SPACE( q[-1] ) ) {
2036 /* cannot end with a space */
2037 assert( !ASCII_SPACE( q[-1] ) );
2039 /* null terminate */
2042 normalized->bv_len = q - normalized->bv_val;
2044 return LDAP_SUCCESS;
2053 struct berval *value,
2054 void *assertedValue )
2056 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2059 match = strncmp( value->bv_val,
2060 ((struct berval *) assertedValue)->bv_val,
2065 return LDAP_SUCCESS;
2069 caseExactIA5SubstringsMatch(
2074 struct berval *value,
2075 void *assertedValue )
2078 SubstringsAssertion *sub = assertedValue;
2079 struct berval left = *value;
2083 /* Add up asserted input length */
2084 if( sub->sa_initial.bv_val ) {
2085 inlen += sub->sa_initial.bv_len;
2088 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2089 inlen += sub->sa_any[i].bv_len;
2092 if( sub->sa_final.bv_val ) {
2093 inlen += sub->sa_final.bv_len;
2096 if( sub->sa_initial.bv_val ) {
2097 if( inlen > left.bv_len ) {
2102 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2103 sub->sa_initial.bv_len );
2109 left.bv_val += sub->sa_initial.bv_len;
2110 left.bv_len -= sub->sa_initial.bv_len;
2111 inlen -= sub->sa_initial.bv_len;
2114 if( sub->sa_final.bv_val ) {
2115 if( inlen > left.bv_len ) {
2120 match = strncmp( sub->sa_final.bv_val,
2121 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2122 sub->sa_final.bv_len );
2128 left.bv_len -= sub->sa_final.bv_len;
2129 inlen -= sub->sa_final.bv_len;
2133 for(i=0; sub->sa_any[i].bv_val; i++) {
2138 if( inlen > left.bv_len ) {
2139 /* not enough length */
2144 if( sub->sa_any[i].bv_len == 0 ) {
2148 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2155 idx = p - left.bv_val;
2156 assert( idx < left.bv_len );
2158 if( idx >= left.bv_len ) {
2159 /* this shouldn't happen */
2166 if( sub->sa_any[i].bv_len > left.bv_len ) {
2167 /* not enough left */
2172 match = strncmp( left.bv_val,
2173 sub->sa_any[i].bv_val,
2174 sub->sa_any[i].bv_len );
2182 left.bv_val += sub->sa_any[i].bv_len;
2183 left.bv_len -= sub->sa_any[i].bv_len;
2184 inlen -= sub->sa_any[i].bv_len;
2190 return LDAP_SUCCESS;
2193 /* Index generation function */
2194 static int caseExactIA5Indexer(
2199 struct berval *prefix,
2206 HASH_CONTEXT HASHcontext;
2207 unsigned char HASHdigest[HASH_BYTES];
2208 struct berval digest;
2209 digest.bv_val = HASHdigest;
2210 digest.bv_len = sizeof(HASHdigest);
2212 for( i=0; values[i].bv_val != NULL; i++ ) {
2213 /* empty - just count them */
2216 /* we should have at least one value at this point */
2219 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2221 slen = syntax->ssyn_oidlen;
2222 mlen = mr->smr_oidlen;
2224 for( i=0; values[i].bv_val != NULL; i++ ) {
2225 struct berval *value = &values[i];
2227 HASH_Init( &HASHcontext );
2228 if( prefix != NULL && prefix->bv_len > 0 ) {
2229 HASH_Update( &HASHcontext,
2230 prefix->bv_val, prefix->bv_len );
2232 HASH_Update( &HASHcontext,
2233 syntax->ssyn_oid, slen );
2234 HASH_Update( &HASHcontext,
2235 mr->smr_oid, mlen );
2236 HASH_Update( &HASHcontext,
2237 value->bv_val, value->bv_len );
2238 HASH_Final( HASHdigest, &HASHcontext );
2240 ber_dupbv( &keys[i], &digest );
2243 keys[i].bv_val = NULL;
2245 return LDAP_SUCCESS;
2248 /* Index generation function */
2249 static int caseExactIA5Filter(
2254 struct berval *prefix,
2260 HASH_CONTEXT HASHcontext;
2261 unsigned char HASHdigest[HASH_BYTES];
2262 struct berval *value;
2263 struct berval digest;
2264 digest.bv_val = HASHdigest;
2265 digest.bv_len = sizeof(HASHdigest);
2267 slen = syntax->ssyn_oidlen;
2268 mlen = mr->smr_oidlen;
2270 value = (struct berval *) assertValue;
2272 keys = ch_malloc( sizeof( struct berval ) * 2 );
2274 HASH_Init( &HASHcontext );
2275 if( prefix != NULL && prefix->bv_len > 0 ) {
2276 HASH_Update( &HASHcontext,
2277 prefix->bv_val, prefix->bv_len );
2279 HASH_Update( &HASHcontext,
2280 syntax->ssyn_oid, slen );
2281 HASH_Update( &HASHcontext,
2282 mr->smr_oid, mlen );
2283 HASH_Update( &HASHcontext,
2284 value->bv_val, value->bv_len );
2285 HASH_Final( HASHdigest, &HASHcontext );
2287 ber_dupbv( &keys[0], &digest );
2288 keys[1].bv_val = NULL;
2291 return LDAP_SUCCESS;
2294 /* Substrings Index generation function */
2295 static int caseExactIA5SubstringsIndexer(
2300 struct berval *prefix,
2307 HASH_CONTEXT HASHcontext;
2308 unsigned char HASHdigest[HASH_BYTES];
2309 struct berval digest;
2310 digest.bv_val = HASHdigest;
2311 digest.bv_len = sizeof(HASHdigest);
2313 /* we should have at least one value at this point */
2314 assert( values != NULL && values[0].bv_val != NULL );
2317 for( i=0; values[i].bv_val != NULL; i++ ) {
2318 /* count number of indices to generate */
2319 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2323 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2324 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2325 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2326 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2328 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2332 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2333 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2334 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2338 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2339 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2340 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2341 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2343 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2349 /* no keys to generate */
2351 return LDAP_SUCCESS;
2354 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2356 slen = syntax->ssyn_oidlen;
2357 mlen = mr->smr_oidlen;
2360 for( i=0; values[i].bv_val != NULL; i++ ) {
2362 struct berval *value;
2365 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2367 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2368 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2370 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2371 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2373 for( j=0; j<max; j++ ) {
2374 HASH_Init( &HASHcontext );
2375 if( prefix != NULL && prefix->bv_len > 0 ) {
2376 HASH_Update( &HASHcontext,
2377 prefix->bv_val, prefix->bv_len );
2380 HASH_Update( &HASHcontext,
2381 &pre, sizeof( pre ) );
2382 HASH_Update( &HASHcontext,
2383 syntax->ssyn_oid, slen );
2384 HASH_Update( &HASHcontext,
2385 mr->smr_oid, mlen );
2386 HASH_Update( &HASHcontext,
2388 SLAP_INDEX_SUBSTR_MAXLEN );
2389 HASH_Final( HASHdigest, &HASHcontext );
2391 ber_dupbv( &keys[nkeys++], &digest );
2395 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2396 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2398 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2401 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2402 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2403 HASH_Init( &HASHcontext );
2404 if( prefix != NULL && prefix->bv_len > 0 ) {
2405 HASH_Update( &HASHcontext,
2406 prefix->bv_val, prefix->bv_len );
2408 HASH_Update( &HASHcontext,
2409 &pre, sizeof( pre ) );
2410 HASH_Update( &HASHcontext,
2411 syntax->ssyn_oid, slen );
2412 HASH_Update( &HASHcontext,
2413 mr->smr_oid, mlen );
2414 HASH_Update( &HASHcontext,
2416 HASH_Final( HASHdigest, &HASHcontext );
2418 ber_dupbv( &keys[nkeys++], &digest );
2421 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2422 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2423 HASH_Init( &HASHcontext );
2424 if( prefix != NULL && prefix->bv_len > 0 ) {
2425 HASH_Update( &HASHcontext,
2426 prefix->bv_val, prefix->bv_len );
2428 HASH_Update( &HASHcontext,
2429 &pre, sizeof( pre ) );
2430 HASH_Update( &HASHcontext,
2431 syntax->ssyn_oid, slen );
2432 HASH_Update( &HASHcontext,
2433 mr->smr_oid, mlen );
2434 HASH_Update( &HASHcontext,
2435 &value->bv_val[value->bv_len-j], j );
2436 HASH_Final( HASHdigest, &HASHcontext );
2438 ber_dupbv( &keys[nkeys++], &digest );
2445 keys[nkeys].bv_val = NULL;
2452 return LDAP_SUCCESS;
2455 static int caseExactIA5SubstringsFilter(
2460 struct berval *prefix,
2464 SubstringsAssertion *sa = assertValue;
2466 ber_len_t nkeys = 0;
2467 size_t slen, mlen, klen;
2469 HASH_CONTEXT HASHcontext;
2470 unsigned char HASHdigest[HASH_BYTES];
2471 struct berval *value;
2472 struct berval digest;
2474 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2475 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2480 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2482 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2483 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2484 /* don't bother accounting for stepping */
2485 nkeys += sa->sa_any[i].bv_len -
2486 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2491 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2492 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2499 return LDAP_SUCCESS;
2502 digest.bv_val = HASHdigest;
2503 digest.bv_len = sizeof(HASHdigest);
2505 slen = syntax->ssyn_oidlen;
2506 mlen = mr->smr_oidlen;
2508 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2511 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2512 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2514 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2515 value = &sa->sa_initial;
2517 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2518 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2520 HASH_Init( &HASHcontext );
2521 if( prefix != NULL && prefix->bv_len > 0 ) {
2522 HASH_Update( &HASHcontext,
2523 prefix->bv_val, prefix->bv_len );
2525 HASH_Update( &HASHcontext,
2526 &pre, sizeof( pre ) );
2527 HASH_Update( &HASHcontext,
2528 syntax->ssyn_oid, slen );
2529 HASH_Update( &HASHcontext,
2530 mr->smr_oid, mlen );
2531 HASH_Update( &HASHcontext,
2532 value->bv_val, klen );
2533 HASH_Final( HASHdigest, &HASHcontext );
2535 ber_dupbv( &keys[nkeys++], &digest );
2538 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2540 pre = SLAP_INDEX_SUBSTR_PREFIX;
2541 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2543 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2544 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2548 value = &sa->sa_any[i];
2551 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2552 j += SLAP_INDEX_SUBSTR_STEP )
2554 HASH_Init( &HASHcontext );
2555 if( prefix != NULL && prefix->bv_len > 0 ) {
2556 HASH_Update( &HASHcontext,
2557 prefix->bv_val, prefix->bv_len );
2559 HASH_Update( &HASHcontext,
2560 &pre, sizeof( pre ) );
2561 HASH_Update( &HASHcontext,
2562 syntax->ssyn_oid, slen );
2563 HASH_Update( &HASHcontext,
2564 mr->smr_oid, mlen );
2565 HASH_Update( &HASHcontext,
2566 &value->bv_val[j], klen );
2567 HASH_Final( HASHdigest, &HASHcontext );
2569 ber_dupbv( &keys[nkeys++], &digest );
2574 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2575 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2577 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2578 value = &sa->sa_final;
2580 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2581 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2583 HASH_Init( &HASHcontext );
2584 if( prefix != NULL && prefix->bv_len > 0 ) {
2585 HASH_Update( &HASHcontext,
2586 prefix->bv_val, prefix->bv_len );
2588 HASH_Update( &HASHcontext,
2589 &pre, sizeof( pre ) );
2590 HASH_Update( &HASHcontext,
2591 syntax->ssyn_oid, slen );
2592 HASH_Update( &HASHcontext,
2593 mr->smr_oid, mlen );
2594 HASH_Update( &HASHcontext,
2595 &value->bv_val[value->bv_len-klen], klen );
2596 HASH_Final( HASHdigest, &HASHcontext );
2598 ber_dupbv( &keys[nkeys++], &digest );
2602 keys[nkeys].bv_val = NULL;
2609 return LDAP_SUCCESS;
2618 struct berval *value,
2619 void *assertedValue )
2621 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2623 if( match == 0 && value->bv_len ) {
2624 match = strncasecmp( value->bv_val,
2625 ((struct berval *) assertedValue)->bv_val,
2630 return LDAP_SUCCESS;
2634 caseIgnoreIA5SubstringsMatch(
2639 struct berval *value,
2640 void *assertedValue )
2643 SubstringsAssertion *sub = assertedValue;
2644 struct berval left = *value;
2648 /* Add up asserted input length */
2649 if( sub->sa_initial.bv_val ) {
2650 inlen += sub->sa_initial.bv_len;
2653 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2654 inlen += sub->sa_any[i].bv_len;
2657 if( sub->sa_final.bv_val ) {
2658 inlen += sub->sa_final.bv_len;
2661 if( sub->sa_initial.bv_val ) {
2662 if( inlen > left.bv_len ) {
2667 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2668 sub->sa_initial.bv_len );
2674 left.bv_val += sub->sa_initial.bv_len;
2675 left.bv_len -= sub->sa_initial.bv_len;
2676 inlen -= sub->sa_initial.bv_len;
2679 if( sub->sa_final.bv_val ) {
2680 if( inlen > left.bv_len ) {
2685 match = strncasecmp( sub->sa_final.bv_val,
2686 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2687 sub->sa_final.bv_len );
2693 left.bv_len -= sub->sa_final.bv_len;
2694 inlen -= sub->sa_final.bv_len;
2698 for(i=0; sub->sa_any[i].bv_val; i++) {
2703 if( inlen > left.bv_len ) {
2704 /* not enough length */
2709 if( sub->sa_any[i].bv_len == 0 ) {
2713 p = strcasechr( left.bv_val, *sub->sa_any[i].bv_val );
2720 idx = p - left.bv_val;
2721 assert( idx < left.bv_len );
2723 if( idx >= left.bv_len ) {
2724 /* this shouldn't happen */
2731 if( sub->sa_any[i].bv_len > left.bv_len ) {
2732 /* not enough left */
2737 match = strncasecmp( left.bv_val,
2738 sub->sa_any[i].bv_val,
2739 sub->sa_any[i].bv_len );
2748 left.bv_val += sub->sa_any[i].bv_len;
2749 left.bv_len -= sub->sa_any[i].bv_len;
2750 inlen -= sub->sa_any[i].bv_len;
2756 return LDAP_SUCCESS;
2759 /* Index generation function */
2760 static int caseIgnoreIA5Indexer(
2765 struct berval *prefix,
2772 HASH_CONTEXT HASHcontext;
2773 unsigned char HASHdigest[HASH_BYTES];
2774 struct berval digest;
2775 digest.bv_val = HASHdigest;
2776 digest.bv_len = sizeof(HASHdigest);
2778 /* we should have at least one value at this point */
2779 assert( values != NULL && values[0].bv_val != NULL );
2781 for( i=0; values[i].bv_val != NULL; i++ ) {
2782 /* just count them */
2785 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2787 slen = syntax->ssyn_oidlen;
2788 mlen = mr->smr_oidlen;
2790 for( i=0; values[i].bv_val != NULL; i++ ) {
2791 struct berval value;
2792 ber_dupbv( &value, &values[i] );
2793 ldap_pvt_str2upper( value.bv_val );
2795 HASH_Init( &HASHcontext );
2796 if( prefix != NULL && prefix->bv_len > 0 ) {
2797 HASH_Update( &HASHcontext,
2798 prefix->bv_val, prefix->bv_len );
2800 HASH_Update( &HASHcontext,
2801 syntax->ssyn_oid, slen );
2802 HASH_Update( &HASHcontext,
2803 mr->smr_oid, mlen );
2804 HASH_Update( &HASHcontext,
2805 value.bv_val, value.bv_len );
2806 HASH_Final( HASHdigest, &HASHcontext );
2808 free( value.bv_val );
2810 ber_dupbv( &keys[i], &digest );
2813 keys[i].bv_val = NULL;
2815 return LDAP_SUCCESS;
2818 /* Index generation function */
2819 static int caseIgnoreIA5Filter(
2824 struct berval *prefix,
2830 HASH_CONTEXT HASHcontext;
2831 unsigned char HASHdigest[HASH_BYTES];
2832 struct berval value;
2833 struct berval digest;
2834 digest.bv_val = HASHdigest;
2835 digest.bv_len = sizeof(HASHdigest);
2837 slen = syntax->ssyn_oidlen;
2838 mlen = mr->smr_oidlen;
2840 ber_dupbv( &value, (struct berval *) assertValue );
2841 ldap_pvt_str2upper( value.bv_val );
2843 keys = ch_malloc( sizeof( struct berval ) * 2 );
2845 HASH_Init( &HASHcontext );
2846 if( prefix != NULL && prefix->bv_len > 0 ) {
2847 HASH_Update( &HASHcontext,
2848 prefix->bv_val, prefix->bv_len );
2850 HASH_Update( &HASHcontext,
2851 syntax->ssyn_oid, slen );
2852 HASH_Update( &HASHcontext,
2853 mr->smr_oid, mlen );
2854 HASH_Update( &HASHcontext,
2855 value.bv_val, value.bv_len );
2856 HASH_Final( HASHdigest, &HASHcontext );
2858 ber_dupbv( &keys[0], &digest );
2859 keys[1].bv_val = NULL;
2861 free( value.bv_val );
2865 return LDAP_SUCCESS;
2868 /* Substrings Index generation function */
2869 static int caseIgnoreIA5SubstringsIndexer(
2874 struct berval *prefix,
2881 HASH_CONTEXT HASHcontext;
2882 unsigned char HASHdigest[HASH_BYTES];
2883 struct berval digest;
2884 digest.bv_val = HASHdigest;
2885 digest.bv_len = sizeof(HASHdigest);
2887 /* we should have at least one value at this point */
2888 assert( values != NULL && values[0].bv_val != NULL );
2891 for( i=0; values[i].bv_val != NULL; i++ ) {
2892 /* count number of indices to generate */
2893 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2897 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2898 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2899 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2900 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2902 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2906 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2907 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2908 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2912 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2913 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2914 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2915 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2917 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2923 /* no keys to generate */
2925 return LDAP_SUCCESS;
2928 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2930 slen = syntax->ssyn_oidlen;
2931 mlen = mr->smr_oidlen;
2934 for( i=0; values[i].bv_val != NULL; i++ ) {
2936 struct berval value;
2938 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2940 ber_dupbv( &value, &values[i] );
2941 ldap_pvt_str2upper( value.bv_val );
2943 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2944 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2946 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2947 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2949 for( j=0; j<max; j++ ) {
2950 HASH_Init( &HASHcontext );
2951 if( prefix != NULL && prefix->bv_len > 0 ) {
2952 HASH_Update( &HASHcontext,
2953 prefix->bv_val, prefix->bv_len );
2956 HASH_Update( &HASHcontext,
2957 &pre, sizeof( pre ) );
2958 HASH_Update( &HASHcontext,
2959 syntax->ssyn_oid, slen );
2960 HASH_Update( &HASHcontext,
2961 mr->smr_oid, mlen );
2962 HASH_Update( &HASHcontext,
2964 SLAP_INDEX_SUBSTR_MAXLEN );
2965 HASH_Final( HASHdigest, &HASHcontext );
2967 ber_dupbv( &keys[nkeys++], &digest );
2971 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2972 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2974 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2977 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2978 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2979 HASH_Init( &HASHcontext );
2980 if( prefix != NULL && prefix->bv_len > 0 ) {
2981 HASH_Update( &HASHcontext,
2982 prefix->bv_val, prefix->bv_len );
2984 HASH_Update( &HASHcontext,
2985 &pre, sizeof( pre ) );
2986 HASH_Update( &HASHcontext,
2987 syntax->ssyn_oid, slen );
2988 HASH_Update( &HASHcontext,
2989 mr->smr_oid, mlen );
2990 HASH_Update( &HASHcontext,
2992 HASH_Final( HASHdigest, &HASHcontext );
2994 ber_dupbv( &keys[nkeys++], &digest );
2997 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2998 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2999 HASH_Init( &HASHcontext );
3000 if( prefix != NULL && prefix->bv_len > 0 ) {
3001 HASH_Update( &HASHcontext,
3002 prefix->bv_val, prefix->bv_len );
3004 HASH_Update( &HASHcontext,
3005 &pre, sizeof( pre ) );
3006 HASH_Update( &HASHcontext,
3007 syntax->ssyn_oid, slen );
3008 HASH_Update( &HASHcontext,
3009 mr->smr_oid, mlen );
3010 HASH_Update( &HASHcontext,
3011 &value.bv_val[value.bv_len-j], j );
3012 HASH_Final( HASHdigest, &HASHcontext );
3014 ber_dupbv( &keys[nkeys++], &digest );
3019 free( value.bv_val );
3023 keys[nkeys].bv_val = NULL;
3030 return LDAP_SUCCESS;
3033 static int caseIgnoreIA5SubstringsFilter(
3038 struct berval *prefix,
3042 SubstringsAssertion *sa = assertValue;
3044 ber_len_t nkeys = 0;
3045 size_t slen, mlen, klen;
3047 HASH_CONTEXT HASHcontext;
3048 unsigned char HASHdigest[HASH_BYTES];
3049 struct berval value;
3050 struct berval digest;
3052 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3053 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3058 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3060 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3061 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3062 /* don't bother accounting for stepping */
3063 nkeys += sa->sa_any[i].bv_len -
3064 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3069 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3070 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3077 return LDAP_SUCCESS;
3080 digest.bv_val = HASHdigest;
3081 digest.bv_len = sizeof(HASHdigest);
3083 slen = syntax->ssyn_oidlen;
3084 mlen = mr->smr_oidlen;
3086 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3089 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3090 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3092 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3093 ber_dupbv( &value, &sa->sa_initial );
3094 ldap_pvt_str2upper( value.bv_val );
3096 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3097 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3099 HASH_Init( &HASHcontext );
3100 if( prefix != NULL && prefix->bv_len > 0 ) {
3101 HASH_Update( &HASHcontext,
3102 prefix->bv_val, prefix->bv_len );
3104 HASH_Update( &HASHcontext,
3105 &pre, sizeof( pre ) );
3106 HASH_Update( &HASHcontext,
3107 syntax->ssyn_oid, slen );
3108 HASH_Update( &HASHcontext,
3109 mr->smr_oid, mlen );
3110 HASH_Update( &HASHcontext,
3111 value.bv_val, klen );
3112 HASH_Final( HASHdigest, &HASHcontext );
3114 free( value.bv_val );
3115 ber_dupbv( &keys[nkeys++], &digest );
3118 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3120 pre = SLAP_INDEX_SUBSTR_PREFIX;
3121 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3123 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3124 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3128 ber_dupbv( &value, &sa->sa_any[i] );
3129 ldap_pvt_str2upper( value.bv_val );
3132 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3133 j += SLAP_INDEX_SUBSTR_STEP )
3135 HASH_Init( &HASHcontext );
3136 if( prefix != NULL && prefix->bv_len > 0 ) {
3137 HASH_Update( &HASHcontext,
3138 prefix->bv_val, prefix->bv_len );
3140 HASH_Update( &HASHcontext,
3141 &pre, sizeof( pre ) );
3142 HASH_Update( &HASHcontext,
3143 syntax->ssyn_oid, slen );
3144 HASH_Update( &HASHcontext,
3145 mr->smr_oid, mlen );
3146 HASH_Update( &HASHcontext,
3147 &value.bv_val[j], klen );
3148 HASH_Final( HASHdigest, &HASHcontext );
3150 ber_dupbv( &keys[nkeys++], &digest );
3153 free( value.bv_val );
3157 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3158 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3160 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3161 ber_dupbv( &value, &sa->sa_final );
3162 ldap_pvt_str2upper( value.bv_val );
3164 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3165 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3167 HASH_Init( &HASHcontext );
3168 if( prefix != NULL && prefix->bv_len > 0 ) {
3169 HASH_Update( &HASHcontext,
3170 prefix->bv_val, prefix->bv_len );
3172 HASH_Update( &HASHcontext,
3173 &pre, sizeof( pre ) );
3174 HASH_Update( &HASHcontext,
3175 syntax->ssyn_oid, slen );
3176 HASH_Update( &HASHcontext,
3177 mr->smr_oid, mlen );
3178 HASH_Update( &HASHcontext,
3179 &value.bv_val[value.bv_len-klen], klen );
3180 HASH_Final( HASHdigest, &HASHcontext );
3182 free( value.bv_val );
3183 ber_dupbv( &keys[nkeys++], &digest );
3187 keys[nkeys].bv_val = NULL;
3194 return LDAP_SUCCESS;
3198 numericStringValidate(
3204 for(i=0; i < in->bv_len; i++) {
3205 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3206 return LDAP_INVALID_SYNTAX;
3210 return LDAP_SUCCESS;
3214 numericStringNormalize(
3217 struct berval *normalized )
3219 /* removal all spaces */
3222 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3225 q = normalized->bv_val;
3228 if ( ASCII_SPACE( *p ) ) {
3229 /* Ignore whitespace */
3236 /* we should have copied no more then is in val */
3237 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3239 /* null terminate */
3242 normalized->bv_len = q - normalized->bv_val;
3244 return LDAP_SUCCESS;
3248 objectIdentifierFirstComponentMatch(
3253 struct berval *value,
3254 void *assertedValue )
3256 int rc = LDAP_SUCCESS;
3258 struct berval *asserted = (struct berval *) assertedValue;
3262 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3263 return LDAP_INVALID_SYNTAX;
3266 /* trim leading white space */
3267 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3271 /* grab next word */
3272 oid.bv_val = &value->bv_val[i];
3273 oid.bv_len = value->bv_len - i;
3274 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3279 /* insert attributeTypes, objectclass check here */
3280 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3281 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3284 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3285 MatchingRule *asserted_mr = mr_bvfind( asserted );
3286 MatchingRule *stored_mr = mr_bvfind( &oid );
3288 if( asserted_mr == NULL ) {
3289 rc = SLAPD_COMPARE_UNDEFINED;
3291 match = asserted_mr != stored_mr;
3294 } else if ( !strcmp( syntax->ssyn_oid,
3295 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3297 AttributeType *asserted_at = at_bvfind( asserted );
3298 AttributeType *stored_at = at_bvfind( &oid );
3300 if( asserted_at == NULL ) {
3301 rc = SLAPD_COMPARE_UNDEFINED;
3303 match = asserted_at != stored_at;
3306 } else if ( !strcmp( syntax->ssyn_oid,
3307 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3309 ObjectClass *asserted_oc = oc_bvfind( asserted );
3310 ObjectClass *stored_oc = oc_bvfind( &oid );
3312 if( asserted_oc == NULL ) {
3313 rc = SLAPD_COMPARE_UNDEFINED;
3315 match = asserted_oc != stored_oc;
3321 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3322 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3323 match, value->bv_val, asserted->bv_val ));
3325 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3326 "%d\n\t\"%s\"\n\t\"%s\"\n",
3327 match, value->bv_val, asserted->bv_val );
3331 if( rc == LDAP_SUCCESS ) *matchp = match;
3341 struct berval *value,
3342 void *assertedValue )
3344 long lValue, lAssertedValue;
3346 /* safe to assume integers are NUL terminated? */
3347 lValue = strtoul(value->bv_val, NULL, 10);
3348 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3349 return LDAP_CONSTRAINT_VIOLATION;
3351 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3352 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3353 return LDAP_CONSTRAINT_VIOLATION;
3355 *matchp = (lValue & lAssertedValue);
3356 return LDAP_SUCCESS;
3365 struct berval *value,
3366 void *assertedValue )
3368 long lValue, lAssertedValue;
3370 /* safe to assume integers are NUL terminated? */
3371 lValue = strtoul(value->bv_val, NULL, 10);
3372 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3373 return LDAP_CONSTRAINT_VIOLATION;
3375 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3376 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3377 return LDAP_CONSTRAINT_VIOLATION;
3379 *matchp = (lValue | lAssertedValue);
3380 return LDAP_SUCCESS;
3384 #include <openssl/x509.h>
3385 #include <openssl/err.h>
3386 char digit[] = "0123456789";
3389 * Next function returns a string representation of a ASN1_INTEGER.
3390 * It works for unlimited lengths.
3393 static struct berval *
3394 asn1_integer2str(ASN1_INTEGER *a)
3399 /* We work backwards, make it fill from the end of buf */
3400 p = buf + sizeof(buf) - 1;
3403 if ( a == NULL || a->length == 0 ) {
3411 /* We want to preserve the original */
3412 copy = ch_malloc(n*sizeof(unsigned int));
3413 for (i = 0; i<n; i++) {
3414 copy[i] = a->data[i];
3418 * base indicates the index of the most significant
3419 * byte that might be nonzero. When it goes off the
3420 * end, we now there is nothing left to do.
3426 for (i = base; i<n; i++ ) {
3427 copy[i] += carry*256;
3428 carry = copy[i] % 10;
3433 * Way too large, we need to leave
3434 * room for sign if negative
3439 *--p = digit[carry];
3440 if (copy[base] == 0)
3446 if ( a->type == V_ASN1_NEG_INTEGER ) {
3450 return ber_bvstrdup(p);
3453 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3454 static struct berval *
3455 dn_openssl2ldap(X509_NAME *name)
3457 char issuer_dn[1024];
3460 bio = BIO_new(BIO_s_mem());
3463 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3464 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3465 ERR_error_string(ERR_get_error(),NULL)));
3467 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3468 "error creating BIO: %s\n",
3469 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3473 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3475 BIO_gets(bio, issuer_dn, 1024);
3478 return ber_bvstrdup(issuer_dn);
3482 * Given a certificate in DER format, extract the corresponding
3483 * assertion value for certificateExactMatch
3486 certificateExactConvert(
3488 struct berval * out )
3491 unsigned char *p = in->bv_val;
3492 struct berval *serial;
3493 struct berval *issuer_dn;
3494 struct berval *bv_tmp;
3496 xcert = d2i_X509(NULL, &p, in->bv_len);
3499 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3500 "certificateExactConvert: error parsing cert: %s\n",
3501 ERR_error_string(ERR_get_error(),NULL)));
3503 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3504 "error parsing cert: %s\n",
3505 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3507 return LDAP_INVALID_SYNTAX;
3510 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3513 return LDAP_INVALID_SYNTAX;
3515 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3519 return LDAP_INVALID_SYNTAX;
3521 /* Actually, dn_openssl2ldap returns in a normalized format, but
3522 it is different from our normalized format */
3524 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3528 return LDAP_INVALID_SYNTAX;
3534 out->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3535 out->bv_val = ch_malloc(out->bv_len);
3537 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3538 p += serial->bv_len;
3539 AC_MEMCPY(p, " $ ", 3);
3541 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3542 p += issuer_dn->bv_len;
3546 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3547 "certificateExactConvert: \n %s\n",
3550 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3552 out->bv_val, NULL, NULL );
3556 ber_bvfree(issuer_dn);
3558 return LDAP_SUCCESS;
3562 serial_and_issuer_parse(
3563 struct berval *assertion,
3564 struct berval **serial,
3565 struct berval **issuer_dn
3573 begin = assertion->bv_val;
3574 end = assertion->bv_val+assertion->bv_len-1;
3575 for (p=begin; p<=end && *p != '$'; p++)
3578 return LDAP_INVALID_SYNTAX;
3580 /* p now points at the $ sign, now use begin and end to delimit the
3582 while (ASCII_SPACE(*begin))
3585 while (ASCII_SPACE(*end))
3588 bv.bv_len = end-begin+1;
3590 *serial = ber_bvdup(&bv);
3592 /* now extract the issuer, remember p was at the dollar sign */
3594 end = assertion->bv_val+assertion->bv_len-1;
3595 while (ASCII_SPACE(*begin))
3597 /* should we trim spaces at the end too? is it safe always? */
3599 bv.bv_len = end-begin+1;
3601 dnNormalize( NULL, &bv, issuer_dn );
3603 return LDAP_SUCCESS;
3607 certificateExactMatch(
3612 struct berval *value,
3613 void *assertedValue )
3616 unsigned char *p = value->bv_val;
3617 struct berval *serial;
3618 struct berval *issuer_dn;
3619 struct berval *asserted_serial;
3620 struct berval *asserted_issuer_dn;
3623 xcert = d2i_X509(NULL, &p, value->bv_len);
3626 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3627 "certificateExactMatch: error parsing cert: %s\n",
3628 ERR_error_string(ERR_get_error(),NULL)));
3630 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3631 "error parsing cert: %s\n",
3632 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3634 return LDAP_INVALID_SYNTAX;
3637 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3638 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3642 serial_and_issuer_parse(assertedValue,
3644 &asserted_issuer_dn);
3649 slap_schema.si_syn_integer,
3650 slap_schema.si_mr_integerMatch,
3653 if ( ret == LDAP_SUCCESS ) {
3654 if ( *matchp == 0 ) {
3655 /* We need to normalize everything for dnMatch */
3659 slap_schema.si_syn_distinguishedName,
3660 slap_schema.si_mr_distinguishedNameMatch,
3662 asserted_issuer_dn);
3667 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3668 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3669 *matchp, serial->bv_val, issuer_dn->bv_val,
3670 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3672 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3673 "%d\n\t\"%s $ %s\"\n",
3674 *matchp, serial->bv_val, issuer_dn->bv_val );
3675 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3676 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3681 ber_bvfree(issuer_dn);
3682 ber_bvfree(asserted_serial);
3683 ber_bvfree(asserted_issuer_dn);
3689 * Index generation function
3690 * We just index the serials, in most scenarios the issuer DN is one of
3691 * a very small set of values.
3693 static int certificateExactIndexer(
3698 struct berval *prefix,
3706 struct berval * serial;
3708 /* we should have at least one value at this point */
3709 assert( values != NULL && values[0].bv_val != NULL );
3711 for( i=0; values[i].bv_val != NULL; i++ ) {
3712 /* empty -- just count them */
3715 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3717 for( i=0; values[i].bv_val != NULL; i++ ) {
3718 p = values[i].bv_val;
3719 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3722 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3723 "certificateExactIndexer: error parsing cert: %s\n",
3724 ERR_error_string(ERR_get_error(),NULL)));
3726 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3727 "error parsing cert: %s\n",
3728 ERR_error_string(ERR_get_error(),NULL),
3731 /* Do we leak keys on error? */
3732 return LDAP_INVALID_SYNTAX;
3735 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3737 integerNormalize( slap_schema.si_syn_integer,
3742 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3743 "certificateExactIndexer: returning: %s\n",
3746 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3753 keys[i].bv_val = NULL;
3755 return LDAP_SUCCESS;
3758 /* Index generation function */
3759 /* We think this is always called with a value in matching rule syntax */
3760 static int certificateExactFilter(
3765 struct berval *prefix,
3770 struct berval *asserted_serial;
3771 struct berval *asserted_issuer_dn;
3773 serial_and_issuer_parse(assertValue,
3775 &asserted_issuer_dn);
3777 keys = ch_malloc( sizeof( struct berval ) * 2 );
3778 integerNormalize( syntax, asserted_serial, &keys[0] );
3779 keys[1].bv_val = NULL;
3782 ber_bvfree(asserted_serial);
3783 ber_bvfree(asserted_issuer_dn);
3784 return LDAP_SUCCESS;
3789 check_time_syntax (struct berval *val,
3793 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3794 static int mdays[2][12] = {
3795 /* non-leap years */
3796 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3798 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3801 int part, c, tzoffset, leapyear = 0 ;
3803 if( val->bv_len == 0 ) {
3804 return LDAP_INVALID_SYNTAX;
3807 p = (char *)val->bv_val;
3808 e = p + val->bv_len;
3810 /* Ignore initial whitespace */
3811 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3815 if (e - p < 13 - (2 * start)) {
3816 return LDAP_INVALID_SYNTAX;
3819 for (part = 0; part < 9; part++) {
3823 for (part = start; part < 7; part++) {
3825 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3832 return LDAP_INVALID_SYNTAX;
3834 if (c < 0 || c > 9) {
3835 return LDAP_INVALID_SYNTAX;
3841 return LDAP_INVALID_SYNTAX;
3843 if (c < 0 || c > 9) {
3844 return LDAP_INVALID_SYNTAX;
3849 if (part == 2 || part == 3) {
3852 if (parts[part] < 0) {
3853 return LDAP_INVALID_SYNTAX;
3855 if (parts[part] > ceiling[part]) {
3856 return LDAP_INVALID_SYNTAX;
3860 /* leapyear check for the Gregorian calendar (year>1581) */
3861 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3862 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3867 if (parts[3] > mdays[leapyear][parts[2]]) {
3868 return LDAP_INVALID_SYNTAX;
3873 tzoffset = 0; /* UTC */
3874 } else if (c != '+' && c != '-') {
3875 return LDAP_INVALID_SYNTAX;
3879 } else /* c == '+' */ {
3884 return LDAP_INVALID_SYNTAX;
3887 for (part = 7; part < 9; part++) {
3889 if (c < 0 || c > 9) {
3890 return LDAP_INVALID_SYNTAX;
3895 if (c < 0 || c > 9) {
3896 return LDAP_INVALID_SYNTAX;
3900 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3901 return LDAP_INVALID_SYNTAX;
3906 /* Ignore trailing whitespace */
3907 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3911 return LDAP_INVALID_SYNTAX;
3914 switch ( tzoffset ) {
3915 case -1: /* negativ offset to UTC, ie west of Greenwich */
3916 parts[4] += parts[7];
3917 parts[5] += parts[8];
3918 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3922 c = mdays[leapyear][parts[2]];
3924 if (parts[part] > c) {
3925 parts[part] -= c + 1;
3930 case 1: /* positive offset to UTC, ie east of Greenwich */
3931 parts[4] -= parts[7];
3932 parts[5] -= parts[8];
3933 for (part = 6; --part > 0; ) {
3937 /* first arg to % needs to be non negativ */
3938 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3940 if (parts[part] < 0) {
3941 parts[part] += c + 1;
3946 case 0: /* already UTC */
3950 return LDAP_SUCCESS;
3957 struct berval *normalized )
3961 rc = check_time_syntax(val, 1, parts);
3962 if (rc != LDAP_SUCCESS) {
3966 normalized->bv_val = ch_malloc( 14 );
3967 if ( normalized->bv_val == NULL ) {
3968 return LBER_ERROR_MEMORY;
3971 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3972 parts[1], parts[2] + 1, parts[3] + 1,
3973 parts[4], parts[5], parts[6] );
3974 normalized->bv_len = 13;
3976 return LDAP_SUCCESS;
3986 return check_time_syntax(in, 1, parts);
3990 generalizedTimeValidate(
3996 return check_time_syntax(in, 0, parts);
4000 generalizedTimeNormalize(
4003 struct berval *normalized )
4007 rc = check_time_syntax(val, 0, parts);
4008 if (rc != LDAP_SUCCESS) {
4012 normalized->bv_val = ch_malloc( 16 );
4013 if ( normalized->bv_val == NULL ) {
4014 return LBER_ERROR_MEMORY;
4017 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4018 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4019 parts[4], parts[5], parts[6] );
4020 normalized->bv_len = 15;
4022 return LDAP_SUCCESS;
4026 nisNetgroupTripleValidate(
4028 struct berval *val )
4033 if ( val->bv_len == 0 ) {
4034 return LDAP_INVALID_SYNTAX;
4037 p = (char *)val->bv_val;
4038 e = p + val->bv_len;
4040 if ( *p != '(' /*')'*/ ) {
4041 return LDAP_INVALID_SYNTAX;
4044 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4048 return LDAP_INVALID_SYNTAX;
4051 } else if ( !ATTR_CHAR( *p ) ) {
4052 return LDAP_INVALID_SYNTAX;
4056 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4057 return LDAP_INVALID_SYNTAX;
4063 return LDAP_INVALID_SYNTAX;
4066 return LDAP_SUCCESS;
4070 bootParameterValidate(
4072 struct berval *val )
4076 if ( val->bv_len == 0 ) {
4077 return LDAP_INVALID_SYNTAX;
4080 p = (char *)val->bv_val;
4081 e = p + val->bv_len;
4084 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4085 if ( !ATTR_CHAR( *p ) ) {
4086 return LDAP_INVALID_SYNTAX;
4091 return LDAP_INVALID_SYNTAX;
4095 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4096 if ( !ATTR_CHAR( *p ) ) {
4097 return LDAP_INVALID_SYNTAX;
4102 return LDAP_INVALID_SYNTAX;
4106 for ( p++; p < e; p++ ) {
4107 if ( !ATTR_CHAR( *p ) ) {
4108 return LDAP_INVALID_SYNTAX;
4112 return LDAP_SUCCESS;
4115 static struct syntax_defs_rec {
4117 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4118 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4120 slap_syntax_validate_func *sd_validate;
4121 slap_syntax_transform_func *sd_normalize;
4122 slap_syntax_transform_func *sd_pretty;
4123 #ifdef SLAPD_BINARY_CONVERSION
4124 slap_syntax_transform_func *sd_ber2str;
4125 slap_syntax_transform_func *sd_str2ber;
4128 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4129 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4130 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4131 0, NULL, NULL, NULL},
4132 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4133 0, NULL, NULL, NULL},
4134 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4135 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4136 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4137 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4138 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4139 0, bitStringValidate, bitStringNormalize, NULL },
4140 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4141 0, booleanValidate, NULL, NULL},
4142 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4143 X_BINARY X_NOT_H_R ")",
4144 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4146 X_BINARY X_NOT_H_R ")",
4147 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4148 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4149 X_BINARY X_NOT_H_R ")",
4150 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4151 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4152 0, countryStringValidate, IA5StringNormalize, NULL},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4154 0, dnValidate, dnNormalize2, dnPretty2},
4155 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4156 0, NULL, NULL, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4158 0, NULL, NULL, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4160 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4161 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4162 0, NULL, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4164 0, NULL, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4166 0, NULL, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4168 0, NULL, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4170 0, NULL, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4172 0, printablesStringValidate, IA5StringNormalize, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4174 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4176 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4178 0, NULL, NULL, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4180 0, IA5StringValidate, IA5StringNormalize, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4182 0, integerValidate, integerNormalize, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4184 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4185 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4186 0, NULL, NULL, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4188 0, NULL, NULL, NULL},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4190 0, NULL, NULL, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4192 0, NULL, NULL, NULL},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4194 0, NULL, NULL, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4196 0, nameUIDValidate, nameUIDNormalize, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4198 0, NULL, NULL, NULL},
4199 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4200 0, numericStringValidate, numericStringNormalize, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4202 0, NULL, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4204 0, oidValidate, NULL, NULL},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4206 0, IA5StringValidate, IA5StringNormalize, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4208 0, blobValidate, NULL, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4210 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4212 0, NULL, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4214 0, NULL, NULL, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4216 0, printableStringValidate, IA5StringNormalize, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4218 X_BINARY X_NOT_H_R ")",
4219 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4221 0, printableStringValidate, IA5StringNormalize, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4223 0, NULL, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4225 0, printablesStringValidate, IA5StringNormalize, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4227 0, utcTimeValidate, utcTimeNormalize, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4229 0, NULL, NULL, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4231 0, NULL, NULL, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4233 0, NULL, NULL, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4235 0, NULL, NULL, NULL},
4236 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4237 0, NULL, NULL, NULL},
4239 /* RFC 2307 NIS Syntaxes */
4240 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4241 0, nisNetgroupTripleValidate, NULL, NULL},
4242 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4243 0, bootParameterValidate, NULL, NULL},
4247 /* These OIDs are not published yet, but will be in the next
4248 * I-D for PKIX LDAPv3 schema as have been advanced by David
4249 * Chadwick in private mail.
4251 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4252 0, NULL, NULL, NULL},
4255 /* OpenLDAP Experimental Syntaxes */
4256 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4258 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4261 /* needs updating */
4262 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4263 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4265 /* OpenLDAP Void Syntax */
4266 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4267 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4268 {NULL, 0, NULL, NULL, NULL}
4272 * Other matching rules in X.520 that we do not use (yet):
4274 * 2.5.13.9 numericStringOrderingMatch
4275 * 2.5.13.15 integerOrderingMatch
4276 * 2.5.13.18 octetStringOrderingMatch
4277 * 2.5.13.19 octetStringSubstringsMatch
4278 * 2.5.13.25 uTCTimeMatch
4279 * 2.5.13.26 uTCTimeOrderingMatch
4280 * 2.5.13.31 directoryStringFirstComponentMatch
4281 * 2.5.13.32 wordMatch
4282 * 2.5.13.33 keywordMatch
4283 * 2.5.13.35 certificateMatch
4284 * 2.5.13.36 certificatePairExactMatch
4285 * 2.5.13.37 certificatePairMatch
4286 * 2.5.13.38 certificateListExactMatch
4287 * 2.5.13.39 certificateListMatch
4288 * 2.5.13.40 algorithmIdentifierMatch
4289 * 2.5.13.41 storedPrefixMatch
4290 * 2.5.13.42 attributeCertificateMatch
4291 * 2.5.13.43 readerAndKeyIDMatch
4292 * 2.5.13.44 attributeIntegrityMatch
4294 static struct mrule_defs_rec {
4296 slap_mask_t mrd_usage;
4297 slap_mr_convert_func * mrd_convert;
4298 slap_mr_normalize_func * mrd_normalize;
4299 slap_mr_match_func * mrd_match;
4300 slap_mr_indexer_func * mrd_indexer;
4301 slap_mr_filter_func * mrd_filter;
4303 char * mrd_associated;
4306 * EQUALITY matching rules must be listed after associated APPROX
4307 * matching rules. So, we list all APPROX matching rules first.
4309 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4310 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4311 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4313 directoryStringApproxMatch,
4314 directoryStringApproxIndexer,
4315 directoryStringApproxFilter,
4318 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4319 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4320 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4322 IA5StringApproxMatch,
4323 IA5StringApproxIndexer,
4324 IA5StringApproxFilter,
4328 * Other matching rules
4331 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4332 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4333 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4335 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4338 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4339 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4340 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4342 dnMatch, dnIndexer, dnFilter,
4345 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4346 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4347 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4349 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4350 directoryStringApproxMatchOID },
4352 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4353 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4356 caseIgnoreOrderingMatch, NULL, NULL,
4359 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4360 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4361 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4363 caseExactIgnoreSubstringsMatch,
4364 caseExactIgnoreSubstringsIndexer,
4365 caseExactIgnoreSubstringsFilter,
4368 {"( 2.5.13.5 NAME 'caseExactMatch' "
4369 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4370 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4372 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4373 directoryStringApproxMatchOID },
4375 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4376 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4379 caseExactOrderingMatch, NULL, NULL,
4382 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4383 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4384 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4386 caseExactIgnoreSubstringsMatch,
4387 caseExactIgnoreSubstringsIndexer,
4388 caseExactIgnoreSubstringsFilter,
4391 {"( 2.5.13.8 NAME 'numericStringMatch' "
4392 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4393 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4396 caseIgnoreIA5Indexer,
4397 caseIgnoreIA5Filter,
4400 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4401 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4402 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4404 caseIgnoreIA5SubstringsMatch,
4405 caseIgnoreIA5SubstringsIndexer,
4406 caseIgnoreIA5SubstringsFilter,
4409 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4410 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4411 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4413 caseIgnoreListMatch, NULL, NULL,
4416 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4417 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4418 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4420 caseIgnoreListSubstringsMatch, NULL, NULL,
4423 {"( 2.5.13.13 NAME 'booleanMatch' "
4424 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4425 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4427 booleanMatch, NULL, NULL,
4430 {"( 2.5.13.14 NAME 'integerMatch' "
4431 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4432 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4434 integerMatch, integerIndexer, integerFilter,
4437 {"( 2.5.13.16 NAME 'bitStringMatch' "
4438 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4439 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4441 bitStringMatch, bitStringIndexer, bitStringFilter,
4444 {"( 2.5.13.17 NAME 'octetStringMatch' "
4445 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4446 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4448 octetStringMatch, octetStringIndexer, octetStringFilter,
4451 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4452 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4453 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4455 telephoneNumberMatch,
4456 telephoneNumberIndexer,
4457 telephoneNumberFilter,
4460 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4461 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4462 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4464 telephoneNumberSubstringsMatch,
4465 telephoneNumberSubstringsIndexer,
4466 telephoneNumberSubstringsFilter,
4469 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4470 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4471 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4476 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4477 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4478 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4480 uniqueMemberMatch, NULL, NULL,
4483 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4484 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4485 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4487 protocolInformationMatch, NULL, NULL,
4490 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4491 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4492 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4494 generalizedTimeMatch, NULL, NULL,
4497 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4498 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4501 generalizedTimeOrderingMatch, NULL, NULL,
4504 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4505 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4506 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4508 integerFirstComponentMatch, NULL, NULL,
4511 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4512 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4513 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4515 objectIdentifierFirstComponentMatch, NULL, NULL,
4519 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4520 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4521 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4522 certificateExactConvert, NULL,
4523 certificateExactMatch,
4524 certificateExactIndexer, certificateExactFilter,
4528 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4529 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4530 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4532 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4533 IA5StringApproxMatchOID },
4535 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4536 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4537 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4539 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4540 IA5StringApproxMatchOID },
4542 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4543 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4546 caseIgnoreIA5SubstringsMatch,
4547 caseIgnoreIA5SubstringsIndexer,
4548 caseIgnoreIA5SubstringsFilter,
4551 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4552 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4555 caseExactIA5SubstringsMatch,
4556 caseExactIA5SubstringsIndexer,
4557 caseExactIA5SubstringsFilter,
4560 /* needs updating */
4561 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4562 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4565 authPasswordMatch, NULL, NULL,
4568 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4569 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4572 OpenLDAPaciMatch, NULL, NULL,
4575 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4576 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4579 integerBitAndMatch, NULL, NULL,
4582 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4583 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4586 integerBitOrMatch, NULL, NULL,
4589 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4598 /* we should only be called once (from main) */
4599 assert( schema_init_done == 0 );
4601 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4602 res = register_syntax( syntax_defs[i].sd_desc,
4603 syntax_defs[i].sd_flags,
4604 syntax_defs[i].sd_validate,
4605 syntax_defs[i].sd_normalize,
4606 syntax_defs[i].sd_pretty
4607 #ifdef SLAPD_BINARY_CONVERSION
4609 syntax_defs[i].sd_ber2str,
4610 syntax_defs[i].sd_str2ber
4615 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4616 syntax_defs[i].sd_desc );
4621 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4622 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4624 "schema_init: Ingoring unusable matching rule %s\n",
4625 mrule_defs[i].mrd_desc );
4629 res = register_matching_rule(
4630 mrule_defs[i].mrd_desc,
4631 mrule_defs[i].mrd_usage,
4632 mrule_defs[i].mrd_convert,
4633 mrule_defs[i].mrd_normalize,
4634 mrule_defs[i].mrd_match,
4635 mrule_defs[i].mrd_indexer,
4636 mrule_defs[i].mrd_filter,
4637 mrule_defs[i].mrd_associated );
4641 "schema_init: Error registering matching rule %s\n",
4642 mrule_defs[i].mrd_desc );
4646 schema_init_done = 1;
4647 return LDAP_SUCCESS;
4651 schema_destroy( void )