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 *bvcasechr( struct berval *bv, int c, ber_len_t *len )
87 int lower = TOLOWER( c );
88 int upper = TOUPPER( c );
90 if( c == 0 ) return NULL;
92 for( i=0; i < bv->bv_len; i++ ) {
93 if( upper == bv->bv_val[i] || lower == bv->bv_val[i] ) {
95 return &bv->bv_val[i];
108 struct berval *value,
109 void *assertedValue )
111 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
114 match = memcmp( value->bv_val,
115 ((struct berval *) assertedValue)->bv_val,
123 /* Index generation function */
124 static int octetStringIndexer(
129 struct berval *prefix,
136 HASH_CONTEXT HASHcontext;
137 unsigned char HASHdigest[HASH_BYTES];
138 struct berval digest;
139 digest.bv_val = HASHdigest;
140 digest.bv_len = sizeof(HASHdigest);
142 for( i=0; values[i].bv_val != NULL; i++ ) {
143 /* just count them */
146 /* we should have at least one value at this point */
149 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
151 slen = syntax->ssyn_oidlen;
152 mlen = mr->smr_oidlen;
154 for( i=0; values[i].bv_val != NULL; i++ ) {
155 HASH_Init( &HASHcontext );
156 if( prefix != NULL && prefix->bv_len > 0 ) {
157 HASH_Update( &HASHcontext,
158 prefix->bv_val, prefix->bv_len );
160 HASH_Update( &HASHcontext,
161 syntax->ssyn_oid, slen );
162 HASH_Update( &HASHcontext,
164 HASH_Update( &HASHcontext,
165 values[i].bv_val, values[i].bv_len );
166 HASH_Final( HASHdigest, &HASHcontext );
168 ber_dupbv( &keys[i], &digest );
171 keys[i].bv_val = NULL;
178 /* Index generation function */
179 static int octetStringFilter(
184 struct berval *prefix,
190 HASH_CONTEXT HASHcontext;
191 unsigned char HASHdigest[HASH_BYTES];
192 struct berval *value = (struct berval *) assertValue;
193 struct berval digest;
194 digest.bv_val = HASHdigest;
195 digest.bv_len = sizeof(HASHdigest);
197 slen = syntax->ssyn_oidlen;
198 mlen = mr->smr_oidlen;
200 keys = ch_malloc( sizeof( struct berval ) * 2 );
202 HASH_Init( &HASHcontext );
203 if( prefix != NULL && prefix->bv_len > 0 ) {
204 HASH_Update( &HASHcontext,
205 prefix->bv_val, prefix->bv_len );
207 HASH_Update( &HASHcontext,
208 syntax->ssyn_oid, slen );
209 HASH_Update( &HASHcontext,
211 HASH_Update( &HASHcontext,
212 value->bv_val, value->bv_len );
213 HASH_Final( HASHdigest, &HASHcontext );
215 ber_dupbv( keys, &digest );
216 keys[1].bv_val = NULL;
231 if( in->bv_len == 0 ) return LDAP_SUCCESS;
233 ber_dupbv( &dn, in );
234 if( !dn.bv_val ) return LDAP_OTHER;
236 if( dn.bv_val[dn.bv_len-1] == 'B'
237 && dn.bv_val[dn.bv_len-2] == '\'' )
239 /* assume presence of optional UID */
242 for(i=dn.bv_len-3; i>1; i--) {
243 if( dn.bv_val[i] != '0' && dn.bv_val[i] != '1' ) {
247 if( dn.bv_val[i] != '\'' ||
248 dn.bv_val[i-1] != '#' ) {
249 ber_memfree( dn.bv_val );
250 return LDAP_INVALID_SYNTAX;
253 /* trim the UID to allow use of dnValidate */
254 dn.bv_val[i-1] = '\0';
258 rc = dnValidate( NULL, &dn );
268 struct berval *normalized )
273 ber_dupbv( &out, val );
274 if( out.bv_len != 0 ) {
277 ber_len_t uidlen = 0;
279 if( out.bv_val[out.bv_len-1] == '\'' ) {
280 /* assume presence of optional UID */
281 uid = strrchr( out.bv_val, '#' );
285 return LDAP_INVALID_SYNTAX;
288 uidlen = out.bv_len - (uid - out.bv_val);
289 /* temporarily trim the UID */
291 out.bv_len -= uidlen;
294 #ifdef USE_DN_NORMALIZE
295 rc = dnNormalize2( NULL, &out, normalized );
297 rc = dnPretty2( NULL, &out, normalized );
300 if( rc != LDAP_SUCCESS ) {
302 return LDAP_INVALID_SYNTAX;
305 dnlen = normalized->bv_len;
309 b2.bv_val = ch_malloc(dnlen + uidlen + 1);
310 AC_MEMCPY( b2.bv_val, normalized->bv_val, dnlen );
312 /* restore the separator */
315 AC_MEMCPY( normalized->bv_val+dnlen, uid, uidlen );
316 b2.bv_len = dnlen + uidlen;
317 normalized->bv_val[dnlen+uidlen] = '\0';
318 free(normalized->bv_val);
332 /* any value allowed */
341 /* any value allowed */
352 /* very unforgiving validation, requires no normalization
353 * before simplistic matching
355 if( in->bv_len < 3 ) {
356 return LDAP_INVALID_SYNTAX;
360 * rfc 2252 section 6.3 Bit String
361 * bitstring = "'" *binary-digit "'"
362 * binary-digit = "0" / "1"
363 * example: '0101111101'B
366 if( in->bv_val[0] != '\'' ||
367 in->bv_val[in->bv_len-2] != '\'' ||
368 in->bv_val[in->bv_len-1] != 'B' )
370 return LDAP_INVALID_SYNTAX;
373 for( i=in->bv_len-3; i>0; i-- ) {
374 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
375 return LDAP_INVALID_SYNTAX;
386 struct berval *normalized )
389 * A normalized bitString is has no extaneous (leading) zero bits.
390 * That is, '00010'B is normalized to '10'B
391 * However, as a special case, '0'B requires no normalization.
395 /* start at the first bit */
398 /* Find the first non-zero bit */
399 while ( *p == '0' ) p++;
402 /* no non-zero bits */
403 ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
407 normalized->bv_val = ch_malloc( val->bv_len + 1 );
409 normalized->bv_val[0] = '\'';
410 normalized->bv_len = 1;
412 for( ; *p != '\0'; p++ ) {
413 normalized->bv_val[normalized->bv_len++] = *p;
416 normalized->bv_val[normalized->bv_len] = '\0';
423 * Handling boolean syntax and matching is quite rigid.
424 * A more flexible approach would be to allow a variety
425 * of strings to be normalized and prettied into TRUE
433 /* very unforgiving validation, requires no normalization
434 * before simplistic matching
437 if( in->bv_len == 4 ) {
438 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
441 } else if( in->bv_len == 5 ) {
442 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
447 return LDAP_INVALID_SYNTAX;
456 struct berval *value,
457 void *assertedValue )
459 /* simplistic matching allowed by rigid validation */
460 struct berval *asserted = (struct berval *) assertedValue;
461 *matchp = value->bv_len != asserted->bv_len;
472 unsigned char *u = in->bv_val;
474 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
476 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
477 /* get the length indicated by the first byte */
478 len = LDAP_UTF8_CHARLEN2( u, len );
480 /* very basic checks */
483 if( (u[5] & 0xC0) != 0x80 ) {
484 return LDAP_INVALID_SYNTAX;
487 if( (u[4] & 0xC0) != 0x80 ) {
488 return LDAP_INVALID_SYNTAX;
491 if( (u[3] & 0xC0) != 0x80 ) {
492 return LDAP_INVALID_SYNTAX;
495 if( (u[2] & 0xC0 )!= 0x80 ) {
496 return LDAP_INVALID_SYNTAX;
499 if( (u[1] & 0xC0) != 0x80 ) {
500 return LDAP_INVALID_SYNTAX;
503 /* CHARLEN already validated it */
506 return LDAP_INVALID_SYNTAX;
509 /* make sure len corresponds with the offset
510 to the next character */
511 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
514 if( count != 0 ) return LDAP_INVALID_SYNTAX;
523 struct berval *normalized )
530 /* Ignore initial whitespace */
531 /* All space is ASCII. All ASCII is 1 byte */
532 while ( ASCII_SPACE( *p ) ) {
537 return LDAP_INVALID_SYNTAX;
540 ber_str2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
542 assert( normalized->bv_val );
544 p = q = normalized->bv_val;
549 if ( ASCII_SPACE( *p ) ) {
554 /* Ignore the extra whitespace */
555 while ( ASCII_SPACE( *p ) ) {
559 len = LDAP_UTF8_COPY(q,p);
565 assert( normalized->bv_val < p );
566 assert( q+len <= p );
568 /* cannot start with a space */
569 assert( !ASCII_SPACE(normalized->bv_val[0]) );
572 * If the string ended in space, backup the pointer one
573 * position. One is enough because the above loop collapsed
574 * all whitespace to a single space.
582 /* cannot end with a space */
583 assert( !ASCII_SPACE( *q ) );
590 normalized->bv_len = q - normalized->bv_val;
595 /* Returns Unicode canonically normalized copy of a substring assertion
596 * Skipping attribute description */
597 static SubstringsAssertion *
598 UTF8SubstringsassertionNormalize(
599 SubstringsAssertion *sa,
602 SubstringsAssertion *nsa;
605 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
610 if( sa->sa_initial.bv_val != NULL ) {
611 ber_str2bv( UTF8normalize( &sa->sa_initial, casefold ), 0,
612 0, &nsa->sa_initial );
613 if( nsa->sa_initial.bv_val == NULL ) {
618 if( sa->sa_any != NULL ) {
619 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
622 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
623 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
624 ber_str2bv( UTF8normalize( &sa->sa_any[i], casefold ),
625 0, 0, &nsa->sa_any[i] );
626 if( nsa->sa_any[i].bv_val == NULL ) {
630 nsa->sa_any[i].bv_val = NULL;
633 if( sa->sa_final.bv_val != NULL ) {
634 ber_str2bv( UTF8normalize( &sa->sa_final, casefold ), 0,
636 if( nsa->sa_final.bv_val == NULL ) {
644 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
645 if ( nsa->sa_any )ber_bvarray_free( nsa->sa_any );
646 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
651 /* Strip characters with the 8th bit set */
664 while( *++q & 0x80 ) {
667 p = AC_MEMCPY(p, q, strlen(q) + 1);
675 #ifndef SLAPD_APPROX_OLDSINGLESTRING
677 #if defined(SLAPD_APPROX_INITIALS)
678 #define SLAPD_APPROX_DELIMITER "._ "
679 #define SLAPD_APPROX_WORDLEN 2
681 #define SLAPD_APPROX_DELIMITER " "
682 #define SLAPD_APPROX_WORDLEN 1
691 struct berval *value,
692 void *assertedValue )
694 char *val, *nval, *assertv, **values, **words, *c;
695 int i, count, len, nextchunk=0, nextavail=0;
698 /* Yes, this is necessary */
699 nval = UTF8normalize( value, LDAP_UTF8_NOCASEFOLD );
704 strip8bitChars( nval );
706 /* Yes, this is necessary */
707 assertv = UTF8normalize( ((struct berval *)assertedValue),
708 LDAP_UTF8_NOCASEFOLD );
709 if( assertv == NULL ) {
714 strip8bitChars( assertv );
715 avlen = strlen( assertv );
717 /* Isolate how many words there are */
718 for( c=nval,count=1; *c; c++ ) {
719 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
720 if ( c == NULL ) break;
725 /* Get a phonetic copy of each word */
726 words = (char **)ch_malloc( count * sizeof(char *) );
727 values = (char **)ch_malloc( count * sizeof(char *) );
728 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
730 values[i] = phonetic(c);
733 /* Work through the asserted value's words, to see if at least some
734 of the words are there, in the same order. */
736 while ( (size_t) nextchunk < avlen ) {
737 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
742 #if defined(SLAPD_APPROX_INITIALS)
743 else if( len == 1 ) {
744 /* Single letter words need to at least match one word's initial */
745 for( i=nextavail; i<count; i++ )
746 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
753 /* Isolate the next word in the asserted value and phonetic it */
754 assertv[nextchunk+len] = '\0';
755 val = phonetic( assertv + nextchunk );
757 /* See if this phonetic chunk is in the remaining words of *value */
758 for( i=nextavail; i<count; i++ ){
759 if( !strcmp( val, values[i] ) ){
767 /* This chunk in the asserted value was NOT within the *value. */
773 /* Go on to the next word in the asserted value */
777 /* If some of the words were seen, call it a match */
778 if( nextavail > 0 ) {
787 for( i=0; i<count; i++ ) {
788 ch_free( values[i] );
803 struct berval *prefix,
808 int i,j, len, wordcount, keycount=0;
809 struct berval *newkeys;
812 for( j=0; values[j].bv_val != NULL; j++ ) {
813 /* Yes, this is necessary */
814 val = UTF8normalize( &values[j], LDAP_UTF8_NOCASEFOLD );
815 strip8bitChars( val );
817 /* Isolate how many words there are. There will be a key for each */
818 for( wordcount=0,c=val; *c; c++) {
819 len = strcspn(c, SLAPD_APPROX_DELIMITER);
820 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
822 if (*c == '\0') break;
826 /* Allocate/increase storage to account for new keys */
827 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
828 * sizeof(struct berval) );
829 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
830 if( keys ) ch_free( keys );
833 /* Get a phonetic copy of each word */
834 for( c=val,i=0; i<wordcount; c+=len+1 ) {
836 if( len < SLAPD_APPROX_WORDLEN ) continue;
837 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
844 keys[keycount].bv_val = NULL;
856 struct berval *prefix,
864 /* Yes, this is necessary */
865 val = UTF8normalize( ((struct berval *)assertValue),
866 LDAP_UTF8_NOCASEFOLD );
868 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
869 keys[0].bv_val = NULL;
873 strip8bitChars( val );
875 /* Isolate how many words there are. There will be a key for each */
876 for( count=0,c=val; *c; c++) {
877 len = strcspn(c, SLAPD_APPROX_DELIMITER);
878 if( len >= SLAPD_APPROX_WORDLEN ) count++;
880 if (*c == '\0') break;
884 /* Allocate storage for new keys */
885 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
887 /* Get a phonetic copy of each word */
888 for( c=val,i=0; i<count; c+=len+1 ) {
890 if( len < SLAPD_APPROX_WORDLEN ) continue;
891 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
897 keys[count].bv_val = NULL;
905 /* No other form of Approximate Matching is defined */
913 struct berval *value,
914 void *assertedValue )
916 char *vapprox, *avapprox;
919 /* Yes, this is necessary */
920 s = UTF8normalize( value, UTF8_NOCASEFOLD );
926 /* Yes, this is necessary */
927 t = UTF8normalize( ((struct berval *)assertedValue),
935 vapprox = phonetic( strip8bitChars( s ) );
936 avapprox = phonetic( strip8bitChars( t ) );
941 *matchp = strcmp( vapprox, avapprox );
955 struct berval *prefix,
963 for( i=0; values[i].bv_val != NULL; i++ ) {
964 /* empty - just count them */
967 /* we should have at least one value at this point */
970 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
972 /* Copy each value and run it through phonetic() */
973 for( i=0; values[i].bv_val != NULL; i++ ) {
974 /* Yes, this is necessary */
975 s = UTF8normalize( &values[i], UTF8_NOCASEFOLD );
977 /* strip 8-bit chars and run through phonetic() */
978 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
981 keys[i].bv_val = NULL;
994 struct berval *prefix,
1001 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
1003 /* Yes, this is necessary */
1004 s = UTF8normalize( ((struct berval *)assertValue),
1009 /* strip 8-bit chars and run through phonetic() */
1010 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1016 return LDAP_SUCCESS;
1027 struct berval *value,
1028 void *assertedValue )
1030 *matchp = UTF8normcmp( value->bv_val,
1031 ((struct berval *) assertedValue)->bv_val,
1032 LDAP_UTF8_NOCASEFOLD );
1033 return LDAP_SUCCESS;
1037 caseExactIgnoreSubstringsMatch(
1042 struct berval *value,
1043 void *assertedValue )
1046 SubstringsAssertion *sub = NULL;
1053 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1054 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1056 nav = UTF8normalize( value, casefold );
1062 left.bv_len = strlen( nav );
1064 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1070 /* Add up asserted input length */
1071 if( sub->sa_initial.bv_val ) {
1072 inlen += sub->sa_initial.bv_len;
1075 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1076 inlen += sub->sa_any[i].bv_len;
1079 if( sub->sa_final.bv_val ) {
1080 inlen += sub->sa_final.bv_len;
1083 if( sub->sa_initial.bv_val ) {
1084 if( inlen > left.bv_len ) {
1089 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
1090 sub->sa_initial.bv_len );
1096 left.bv_val += sub->sa_initial.bv_len;
1097 left.bv_len -= sub->sa_initial.bv_len;
1098 inlen -= sub->sa_initial.bv_len;
1101 if( sub->sa_final.bv_val ) {
1102 if( inlen > left.bv_len ) {
1107 match = strncmp( sub->sa_final.bv_val,
1108 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1109 sub->sa_final.bv_len );
1115 left.bv_len -= sub->sa_final.bv_len;
1116 inlen -= sub->sa_final.bv_len;
1120 for(i=0; sub->sa_any[i].bv_val; i++) {
1125 if( inlen > left.bv_len ) {
1126 /* not enough length */
1131 if( sub->sa_any[i].bv_len == 0 ) {
1135 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
1142 idx = p - left.bv_val;
1144 if( idx >= left.bv_len ) {
1145 /* this shouldn't happen */
1147 if ( sub->sa_final.bv_val )
1148 ch_free( sub->sa_final.bv_val );
1150 ber_bvarray_free( sub->sa_any );
1151 if ( sub->sa_initial.bv_val )
1152 ch_free( sub->sa_initial.bv_val );
1160 if( sub->sa_any[i].bv_len > left.bv_len ) {
1161 /* not enough left */
1166 match = strncmp( left.bv_val,
1167 sub->sa_any[i].bv_val,
1168 sub->sa_any[i].bv_len );
1176 left.bv_val += sub->sa_any[i].bv_len;
1177 left.bv_len -= sub->sa_any[i].bv_len;
1178 inlen -= sub->sa_any[i].bv_len;
1185 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1186 if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
1187 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1191 return LDAP_SUCCESS;
1194 /* Index generation function */
1195 static int caseExactIgnoreIndexer(
1200 struct berval *prefix,
1208 HASH_CONTEXT HASHcontext;
1209 unsigned char HASHdigest[HASH_BYTES];
1210 struct berval digest;
1211 digest.bv_val = HASHdigest;
1212 digest.bv_len = sizeof(HASHdigest);
1214 for( i=0; values[i].bv_val != NULL; i++ ) {
1215 /* empty - just count them */
1218 /* we should have at least one value at this point */
1221 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1223 slen = syntax->ssyn_oidlen;
1224 mlen = mr->smr_oidlen;
1226 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1227 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1229 for( i=0; values[i].bv_val != NULL; i++ ) {
1230 struct berval value;
1231 ber_str2bv( UTF8normalize( &values[i], casefold ), 0, 0,
1234 HASH_Init( &HASHcontext );
1235 if( prefix != NULL && prefix->bv_len > 0 ) {
1236 HASH_Update( &HASHcontext,
1237 prefix->bv_val, prefix->bv_len );
1239 HASH_Update( &HASHcontext,
1240 syntax->ssyn_oid, slen );
1241 HASH_Update( &HASHcontext,
1242 mr->smr_oid, mlen );
1243 HASH_Update( &HASHcontext,
1244 value.bv_val, value.bv_len );
1245 HASH_Final( HASHdigest, &HASHcontext );
1247 free( value.bv_val );
1249 ber_dupbv( &keys[i], &digest );
1252 keys[i].bv_val = NULL;
1254 return LDAP_SUCCESS;
1257 /* Index generation function */
1258 static int caseExactIgnoreFilter(
1263 struct berval *prefix,
1270 HASH_CONTEXT HASHcontext;
1271 unsigned char HASHdigest[HASH_BYTES];
1272 struct berval value;
1273 struct berval digest;
1274 digest.bv_val = HASHdigest;
1275 digest.bv_len = sizeof(HASHdigest);
1277 slen = syntax->ssyn_oidlen;
1278 mlen = mr->smr_oidlen;
1280 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1281 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1283 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1285 /* This usually happens if filter contains bad UTF8 */
1286 if( value.bv_val == NULL ) {
1287 keys = ch_malloc( sizeof( struct berval ) );
1288 keys[0].bv_val = NULL;
1289 return LDAP_SUCCESS;
1292 keys = ch_malloc( sizeof( struct berval ) * 2 );
1294 HASH_Init( &HASHcontext );
1295 if( prefix != NULL && prefix->bv_len > 0 ) {
1296 HASH_Update( &HASHcontext,
1297 prefix->bv_val, prefix->bv_len );
1299 HASH_Update( &HASHcontext,
1300 syntax->ssyn_oid, slen );
1301 HASH_Update( &HASHcontext,
1302 mr->smr_oid, mlen );
1303 HASH_Update( &HASHcontext,
1304 value.bv_val, value.bv_len );
1305 HASH_Final( HASHdigest, &HASHcontext );
1307 ber_dupbv( keys, &digest );
1308 keys[1].bv_val = NULL;
1310 free( value.bv_val );
1313 return LDAP_SUCCESS;
1316 /* Substrings Index generation function */
1317 static int caseExactIgnoreSubstringsIndexer(
1322 struct berval *prefix,
1332 HASH_CONTEXT HASHcontext;
1333 unsigned char HASHdigest[HASH_BYTES];
1334 struct berval digest;
1335 digest.bv_val = HASHdigest;
1336 digest.bv_len = sizeof(HASHdigest);
1340 for( i=0; values[i].bv_val != NULL; i++ ) {
1341 /* empty - just count them */
1344 /* we should have at least one value at this point */
1347 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1348 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1350 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1351 for( i=0; values[i].bv_val != NULL; i++ ) {
1352 ber_str2bv( UTF8normalize( &values[i], casefold ),
1353 0, 0, &nvalues[i] );
1355 nvalues[i].bv_val = NULL;
1358 for( i=0; values[i].bv_val != NULL; i++ ) {
1359 /* count number of indices to generate */
1360 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1364 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1365 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1366 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1367 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1369 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1373 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1374 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1375 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1379 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1380 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1381 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1382 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1384 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1390 /* no keys to generate */
1392 ber_bvarray_free( nvalues );
1393 return LDAP_SUCCESS;
1396 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1398 slen = syntax->ssyn_oidlen;
1399 mlen = mr->smr_oidlen;
1402 for( i=0; values[i].bv_val != NULL; i++ ) {
1405 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1407 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1408 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1410 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1411 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1413 for( j=0; j<max; j++ ) {
1414 HASH_Init( &HASHcontext );
1415 if( prefix != NULL && prefix->bv_len > 0 ) {
1416 HASH_Update( &HASHcontext,
1417 prefix->bv_val, prefix->bv_len );
1420 HASH_Update( &HASHcontext,
1421 &pre, sizeof( pre ) );
1422 HASH_Update( &HASHcontext,
1423 syntax->ssyn_oid, slen );
1424 HASH_Update( &HASHcontext,
1425 mr->smr_oid, mlen );
1426 HASH_Update( &HASHcontext,
1427 &values[i].bv_val[j],
1428 SLAP_INDEX_SUBSTR_MAXLEN );
1429 HASH_Final( HASHdigest, &HASHcontext );
1431 ber_dupbv( &keys[nkeys++], &digest );
1435 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1436 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1438 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1441 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1442 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1443 HASH_Init( &HASHcontext );
1444 if( prefix != NULL && prefix->bv_len > 0 ) {
1445 HASH_Update( &HASHcontext,
1446 prefix->bv_val, prefix->bv_len );
1448 HASH_Update( &HASHcontext,
1449 &pre, sizeof( pre ) );
1450 HASH_Update( &HASHcontext,
1451 syntax->ssyn_oid, slen );
1452 HASH_Update( &HASHcontext,
1453 mr->smr_oid, mlen );
1454 HASH_Update( &HASHcontext,
1455 values[i].bv_val, j );
1456 HASH_Final( HASHdigest, &HASHcontext );
1458 ber_dupbv( &keys[nkeys++], &digest );
1461 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1462 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1463 HASH_Init( &HASHcontext );
1464 if( prefix != NULL && prefix->bv_len > 0 ) {
1465 HASH_Update( &HASHcontext,
1466 prefix->bv_val, prefix->bv_len );
1468 HASH_Update( &HASHcontext,
1469 &pre, sizeof( pre ) );
1470 HASH_Update( &HASHcontext,
1471 syntax->ssyn_oid, slen );
1472 HASH_Update( &HASHcontext,
1473 mr->smr_oid, mlen );
1474 HASH_Update( &HASHcontext,
1475 &values[i].bv_val[values[i].bv_len-j], j );
1476 HASH_Final( HASHdigest, &HASHcontext );
1478 ber_dupbv( &keys[nkeys++], &digest );
1486 keys[nkeys].bv_val = NULL;
1493 ber_bvarray_free( nvalues );
1495 return LDAP_SUCCESS;
1498 static int caseExactIgnoreSubstringsFilter(
1503 struct berval *prefix,
1507 SubstringsAssertion *sa;
1510 ber_len_t nkeys = 0;
1511 size_t slen, mlen, klen;
1513 HASH_CONTEXT HASHcontext;
1514 unsigned char HASHdigest[HASH_BYTES];
1515 struct berval *value;
1516 struct berval digest;
1518 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1519 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1521 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1524 return LDAP_SUCCESS;
1527 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1528 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1533 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1535 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1536 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1537 /* don't bother accounting for stepping */
1538 nkeys += sa->sa_any[i].bv_len -
1539 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1544 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1545 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1551 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1552 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1553 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1556 return LDAP_SUCCESS;
1559 digest.bv_val = HASHdigest;
1560 digest.bv_len = sizeof(HASHdigest);
1562 slen = syntax->ssyn_oidlen;
1563 mlen = mr->smr_oidlen;
1565 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1568 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1569 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1571 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1572 value = &sa->sa_initial;
1574 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1575 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1577 HASH_Init( &HASHcontext );
1578 if( prefix != NULL && prefix->bv_len > 0 ) {
1579 HASH_Update( &HASHcontext,
1580 prefix->bv_val, prefix->bv_len );
1582 HASH_Update( &HASHcontext,
1583 &pre, sizeof( pre ) );
1584 HASH_Update( &HASHcontext,
1585 syntax->ssyn_oid, slen );
1586 HASH_Update( &HASHcontext,
1587 mr->smr_oid, mlen );
1588 HASH_Update( &HASHcontext,
1589 value->bv_val, klen );
1590 HASH_Final( HASHdigest, &HASHcontext );
1592 ber_dupbv( &keys[nkeys++], &digest );
1595 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1597 pre = SLAP_INDEX_SUBSTR_PREFIX;
1598 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1600 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1601 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1605 value = &sa->sa_any[i];
1608 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1609 j += SLAP_INDEX_SUBSTR_STEP )
1611 HASH_Init( &HASHcontext );
1612 if( prefix != NULL && prefix->bv_len > 0 ) {
1613 HASH_Update( &HASHcontext,
1614 prefix->bv_val, prefix->bv_len );
1616 HASH_Update( &HASHcontext,
1617 &pre, sizeof( pre ) );
1618 HASH_Update( &HASHcontext,
1619 syntax->ssyn_oid, slen );
1620 HASH_Update( &HASHcontext,
1621 mr->smr_oid, mlen );
1622 HASH_Update( &HASHcontext,
1623 &value->bv_val[j], klen );
1624 HASH_Final( HASHdigest, &HASHcontext );
1626 ber_dupbv( &keys[nkeys++], &digest );
1632 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1633 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1635 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1636 value = &sa->sa_final;
1638 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1639 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1641 HASH_Init( &HASHcontext );
1642 if( prefix != NULL && prefix->bv_len > 0 ) {
1643 HASH_Update( &HASHcontext,
1644 prefix->bv_val, prefix->bv_len );
1646 HASH_Update( &HASHcontext,
1647 &pre, sizeof( pre ) );
1648 HASH_Update( &HASHcontext,
1649 syntax->ssyn_oid, slen );
1650 HASH_Update( &HASHcontext,
1651 mr->smr_oid, mlen );
1652 HASH_Update( &HASHcontext,
1653 &value->bv_val[value->bv_len-klen], klen );
1654 HASH_Final( HASHdigest, &HASHcontext );
1656 ber_dupbv( &keys[nkeys++], &digest );
1660 keys[nkeys].bv_val = NULL;
1666 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1667 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1668 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1671 return LDAP_SUCCESS;
1680 struct berval *value,
1681 void *assertedValue )
1683 *matchp = UTF8normcmp( value->bv_val,
1684 ((struct berval *) assertedValue)->bv_val,
1685 LDAP_UTF8_CASEFOLD );
1686 return LDAP_SUCCESS;
1692 struct berval *val )
1696 if( val->bv_len == 0 ) {
1697 /* disallow empty strings */
1698 return LDAP_INVALID_SYNTAX;
1701 if( OID_LEADCHAR(val->bv_val[0]) ) {
1703 for(i=1; i < val->bv_len; i++) {
1704 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1705 if( dot++ ) return 1;
1706 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1709 return LDAP_INVALID_SYNTAX;
1713 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1715 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1716 for(i=1; i < val->bv_len; i++) {
1717 if( !DESC_CHAR(val->bv_val[i] ) ) {
1718 return LDAP_INVALID_SYNTAX;
1722 return LDAP_SUCCESS;
1725 return LDAP_INVALID_SYNTAX;
1734 struct berval *value,
1735 void *assertedValue )
1738 int vsign=0, avsign=0;
1739 struct berval *asserted;
1740 ber_len_t vlen, avlen;
1743 /* Start off pessimistic */
1746 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1748 vlen = value->bv_len;
1750 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1751 /* empty -- skip spaces */
1753 else if ( *v == '+' ) {
1756 else if ( *v == '-' ) {
1759 else if ( ASCII_DIGIT(*v) ) {
1760 if ( vsign == 0 ) vsign = 1;
1768 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1770 asserted = (struct berval *) assertedValue;
1771 av = asserted->bv_val;
1772 avlen = asserted->bv_len;
1774 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1775 /* empty -- skip spaces */
1777 else if ( *av == '+' ) {
1780 else if ( *av == '-' ) {
1783 else if ( ASCII_DIGIT(*av) ) {
1784 if ( avsign == 0 ) avsign = 1;
1792 /* The two ?sign vars are now one of :
1793 -2 negative non-zero number
1795 0 0 collapse these three to 0
1797 +2 positive non-zero number
1799 if ( abs( vsign ) == 1 ) vsign = 0;
1800 if ( abs( avsign ) == 1 ) avsign = 0;
1802 if( vsign != avsign ) return LDAP_SUCCESS;
1804 /* Check the significant digits */
1805 while( vlen && avlen ) {
1806 if( *v != *av ) break;
1813 /* If all digits compared equal, the numbers are equal */
1814 if(( vlen == 0 ) && ( avlen == 0 )) {
1817 return LDAP_SUCCESS;
1823 struct berval *val )
1827 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1829 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1830 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1831 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1832 return LDAP_INVALID_SYNTAX;
1835 for( i=1; i < val->bv_len; i++ ) {
1836 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1839 return LDAP_SUCCESS;
1846 struct berval *normalized )
1856 /* Ignore leading spaces */
1857 while ( len && ( *p == ' ' )) {
1864 negative = ( *p == '-' );
1865 if(( *p == '-' ) || ( *p == '+' )) {
1871 /* Ignore leading zeros */
1872 while ( len && ( *p == '0' )) {
1877 /* If there are no non-zero digits left, the number is zero, otherwise
1878 allocate space for the number and copy it into the buffer */
1880 normalized->bv_val = ch_strdup("0");
1881 normalized->bv_len = 1;
1884 normalized->bv_len = len+negative;
1885 normalized->bv_val = ch_malloc( normalized->bv_len );
1887 normalized->bv_val[0] = '-';
1889 AC_MEMCPY( normalized->bv_val + negative, p, len );
1892 return LDAP_SUCCESS;
1895 /* Index generation function */
1896 static int integerIndexer(
1901 struct berval *prefix,
1908 /* we should have at least one value at this point */
1909 assert( values != NULL && values[0].bv_val != NULL );
1911 for( i=0; values[i].bv_val != NULL; i++ ) {
1912 /* empty -- just count them */
1915 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1917 for( i=0; values[i].bv_val != NULL; i++ ) {
1918 integerNormalize( syntax, &values[i], &keys[i] );
1921 keys[i].bv_val = NULL;
1923 return LDAP_SUCCESS;
1926 /* Index generation function */
1927 static int integerFilter(
1932 struct berval *prefix,
1938 keys = ch_malloc( sizeof( struct berval ) * 2 );
1939 integerNormalize( syntax, assertValue, &keys[0] );
1940 keys[1].bv_val = NULL;
1943 return LDAP_SUCCESS;
1948 countryStringValidate(
1950 struct berval *val )
1952 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1954 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1955 return LDAP_INVALID_SYNTAX;
1957 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1958 return LDAP_INVALID_SYNTAX;
1961 return LDAP_SUCCESS;
1965 printableStringValidate(
1967 struct berval *val )
1971 for(i=0; i < val->bv_len; i++) {
1972 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1973 return LDAP_INVALID_SYNTAX;
1977 return LDAP_SUCCESS;
1981 printablesStringValidate(
1983 struct berval *val )
1987 for(i=0; i < val->bv_len; i++) {
1988 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1989 return LDAP_INVALID_SYNTAX;
1993 return LDAP_SUCCESS;
1999 struct berval *val )
2003 for(i=0; i < val->bv_len; i++) {
2004 if( !LDAP_ASCII(val->bv_val[i]) ) {
2005 return LDAP_INVALID_SYNTAX;
2009 return LDAP_SUCCESS;
2016 struct berval *normalized )
2022 /* Ignore initial whitespace */
2023 while ( ASCII_SPACE( *p ) ) {
2027 normalized->bv_val = ch_strdup( p );
2028 p = q = normalized->bv_val;
2031 if ( ASCII_SPACE( *p ) ) {
2034 /* Ignore the extra whitespace */
2035 while ( ASCII_SPACE( *p ) ) {
2043 assert( normalized->bv_val <= p );
2047 * If the string ended in space, backup the pointer one
2048 * position. One is enough because the above loop collapsed
2049 * all whitespace to a single space.
2052 if ( ASCII_SPACE( q[-1] ) ) {
2056 /* null terminate */
2059 normalized->bv_len = q - normalized->bv_val;
2061 return LDAP_SUCCESS;
2070 struct berval *value,
2071 void *assertedValue )
2073 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2076 match = strncmp( value->bv_val,
2077 ((struct berval *) assertedValue)->bv_val,
2082 return LDAP_SUCCESS;
2086 caseExactIA5SubstringsMatch(
2091 struct berval *value,
2092 void *assertedValue )
2095 SubstringsAssertion *sub = assertedValue;
2096 struct berval left = *value;
2100 /* Add up asserted input length */
2101 if( sub->sa_initial.bv_val ) {
2102 inlen += sub->sa_initial.bv_len;
2105 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2106 inlen += sub->sa_any[i].bv_len;
2109 if( sub->sa_final.bv_val ) {
2110 inlen += sub->sa_final.bv_len;
2113 if( sub->sa_initial.bv_val ) {
2114 if( inlen > left.bv_len ) {
2119 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2120 sub->sa_initial.bv_len );
2126 left.bv_val += sub->sa_initial.bv_len;
2127 left.bv_len -= sub->sa_initial.bv_len;
2128 inlen -= sub->sa_initial.bv_len;
2131 if( sub->sa_final.bv_val ) {
2132 if( inlen > left.bv_len ) {
2137 match = strncmp( sub->sa_final.bv_val,
2138 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2139 sub->sa_final.bv_len );
2145 left.bv_len -= sub->sa_final.bv_len;
2146 inlen -= sub->sa_final.bv_len;
2150 for(i=0; sub->sa_any[i].bv_val; i++) {
2155 if( inlen > left.bv_len ) {
2156 /* not enough length */
2161 if( sub->sa_any[i].bv_len == 0 ) {
2165 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2172 idx = p - left.bv_val;
2174 if( idx >= left.bv_len ) {
2175 /* this shouldn't happen */
2182 if( sub->sa_any[i].bv_len > left.bv_len ) {
2183 /* not enough left */
2188 match = strncmp( left.bv_val,
2189 sub->sa_any[i].bv_val,
2190 sub->sa_any[i].bv_len );
2198 left.bv_val += sub->sa_any[i].bv_len;
2199 left.bv_len -= sub->sa_any[i].bv_len;
2200 inlen -= sub->sa_any[i].bv_len;
2206 return LDAP_SUCCESS;
2209 /* Index generation function */
2210 static int caseExactIA5Indexer(
2215 struct berval *prefix,
2222 HASH_CONTEXT HASHcontext;
2223 unsigned char HASHdigest[HASH_BYTES];
2224 struct berval digest;
2225 digest.bv_val = HASHdigest;
2226 digest.bv_len = sizeof(HASHdigest);
2228 for( i=0; values[i].bv_val != NULL; i++ ) {
2229 /* empty - just count them */
2232 /* we should have at least one value at this point */
2235 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2237 slen = syntax->ssyn_oidlen;
2238 mlen = mr->smr_oidlen;
2240 for( i=0; values[i].bv_val != NULL; i++ ) {
2241 struct berval *value = &values[i];
2243 HASH_Init( &HASHcontext );
2244 if( prefix != NULL && prefix->bv_len > 0 ) {
2245 HASH_Update( &HASHcontext,
2246 prefix->bv_val, prefix->bv_len );
2248 HASH_Update( &HASHcontext,
2249 syntax->ssyn_oid, slen );
2250 HASH_Update( &HASHcontext,
2251 mr->smr_oid, mlen );
2252 HASH_Update( &HASHcontext,
2253 value->bv_val, value->bv_len );
2254 HASH_Final( HASHdigest, &HASHcontext );
2256 ber_dupbv( &keys[i], &digest );
2259 keys[i].bv_val = NULL;
2261 return LDAP_SUCCESS;
2264 /* Index generation function */
2265 static int caseExactIA5Filter(
2270 struct berval *prefix,
2276 HASH_CONTEXT HASHcontext;
2277 unsigned char HASHdigest[HASH_BYTES];
2278 struct berval *value;
2279 struct berval digest;
2280 digest.bv_val = HASHdigest;
2281 digest.bv_len = sizeof(HASHdigest);
2283 slen = syntax->ssyn_oidlen;
2284 mlen = mr->smr_oidlen;
2286 value = (struct berval *) assertValue;
2288 keys = ch_malloc( sizeof( struct berval ) * 2 );
2290 HASH_Init( &HASHcontext );
2291 if( prefix != NULL && prefix->bv_len > 0 ) {
2292 HASH_Update( &HASHcontext,
2293 prefix->bv_val, prefix->bv_len );
2295 HASH_Update( &HASHcontext,
2296 syntax->ssyn_oid, slen );
2297 HASH_Update( &HASHcontext,
2298 mr->smr_oid, mlen );
2299 HASH_Update( &HASHcontext,
2300 value->bv_val, value->bv_len );
2301 HASH_Final( HASHdigest, &HASHcontext );
2303 ber_dupbv( &keys[0], &digest );
2304 keys[1].bv_val = NULL;
2307 return LDAP_SUCCESS;
2310 /* Substrings Index generation function */
2311 static int caseExactIA5SubstringsIndexer(
2316 struct berval *prefix,
2323 HASH_CONTEXT HASHcontext;
2324 unsigned char HASHdigest[HASH_BYTES];
2325 struct berval digest;
2326 digest.bv_val = HASHdigest;
2327 digest.bv_len = sizeof(HASHdigest);
2329 /* we should have at least one value at this point */
2330 assert( values != NULL && values[0].bv_val != NULL );
2333 for( i=0; values[i].bv_val != NULL; i++ ) {
2334 /* count number of indices to generate */
2335 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2339 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2340 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2341 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2342 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2344 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2348 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2349 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2350 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2354 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2355 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2356 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2357 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2359 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2365 /* no keys to generate */
2367 return LDAP_SUCCESS;
2370 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2372 slen = syntax->ssyn_oidlen;
2373 mlen = mr->smr_oidlen;
2376 for( i=0; values[i].bv_val != NULL; i++ ) {
2378 struct berval *value;
2381 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2383 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2384 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2386 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2387 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2389 for( j=0; j<max; j++ ) {
2390 HASH_Init( &HASHcontext );
2391 if( prefix != NULL && prefix->bv_len > 0 ) {
2392 HASH_Update( &HASHcontext,
2393 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 SLAP_INDEX_SUBSTR_MAXLEN );
2405 HASH_Final( HASHdigest, &HASHcontext );
2407 ber_dupbv( &keys[nkeys++], &digest );
2411 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2412 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2414 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2417 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2418 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2419 HASH_Init( &HASHcontext );
2420 if( prefix != NULL && prefix->bv_len > 0 ) {
2421 HASH_Update( &HASHcontext,
2422 prefix->bv_val, prefix->bv_len );
2424 HASH_Update( &HASHcontext,
2425 &pre, sizeof( pre ) );
2426 HASH_Update( &HASHcontext,
2427 syntax->ssyn_oid, slen );
2428 HASH_Update( &HASHcontext,
2429 mr->smr_oid, mlen );
2430 HASH_Update( &HASHcontext,
2432 HASH_Final( HASHdigest, &HASHcontext );
2434 ber_dupbv( &keys[nkeys++], &digest );
2437 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2438 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2439 HASH_Init( &HASHcontext );
2440 if( prefix != NULL && prefix->bv_len > 0 ) {
2441 HASH_Update( &HASHcontext,
2442 prefix->bv_val, prefix->bv_len );
2444 HASH_Update( &HASHcontext,
2445 &pre, sizeof( pre ) );
2446 HASH_Update( &HASHcontext,
2447 syntax->ssyn_oid, slen );
2448 HASH_Update( &HASHcontext,
2449 mr->smr_oid, mlen );
2450 HASH_Update( &HASHcontext,
2451 &value->bv_val[value->bv_len-j], j );
2452 HASH_Final( HASHdigest, &HASHcontext );
2454 ber_dupbv( &keys[nkeys++], &digest );
2461 keys[nkeys].bv_val = NULL;
2468 return LDAP_SUCCESS;
2471 static int caseExactIA5SubstringsFilter(
2476 struct berval *prefix,
2480 SubstringsAssertion *sa = assertValue;
2482 ber_len_t nkeys = 0;
2483 size_t slen, mlen, klen;
2485 HASH_CONTEXT HASHcontext;
2486 unsigned char HASHdigest[HASH_BYTES];
2487 struct berval *value;
2488 struct berval digest;
2490 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2491 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2496 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2498 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2499 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2500 /* don't bother accounting for stepping */
2501 nkeys += sa->sa_any[i].bv_len -
2502 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2507 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2508 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2515 return LDAP_SUCCESS;
2518 digest.bv_val = HASHdigest;
2519 digest.bv_len = sizeof(HASHdigest);
2521 slen = syntax->ssyn_oidlen;
2522 mlen = mr->smr_oidlen;
2524 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2527 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2528 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2530 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2531 value = &sa->sa_initial;
2533 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2534 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2536 HASH_Init( &HASHcontext );
2537 if( prefix != NULL && prefix->bv_len > 0 ) {
2538 HASH_Update( &HASHcontext,
2539 prefix->bv_val, prefix->bv_len );
2541 HASH_Update( &HASHcontext,
2542 &pre, sizeof( pre ) );
2543 HASH_Update( &HASHcontext,
2544 syntax->ssyn_oid, slen );
2545 HASH_Update( &HASHcontext,
2546 mr->smr_oid, mlen );
2547 HASH_Update( &HASHcontext,
2548 value->bv_val, klen );
2549 HASH_Final( HASHdigest, &HASHcontext );
2551 ber_dupbv( &keys[nkeys++], &digest );
2554 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2556 pre = SLAP_INDEX_SUBSTR_PREFIX;
2557 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2559 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2560 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2564 value = &sa->sa_any[i];
2567 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2568 j += SLAP_INDEX_SUBSTR_STEP )
2570 HASH_Init( &HASHcontext );
2571 if( prefix != NULL && prefix->bv_len > 0 ) {
2572 HASH_Update( &HASHcontext,
2573 prefix->bv_val, prefix->bv_len );
2575 HASH_Update( &HASHcontext,
2576 &pre, sizeof( pre ) );
2577 HASH_Update( &HASHcontext,
2578 syntax->ssyn_oid, slen );
2579 HASH_Update( &HASHcontext,
2580 mr->smr_oid, mlen );
2581 HASH_Update( &HASHcontext,
2582 &value->bv_val[j], klen );
2583 HASH_Final( HASHdigest, &HASHcontext );
2585 ber_dupbv( &keys[nkeys++], &digest );
2590 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2591 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2593 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2594 value = &sa->sa_final;
2596 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2597 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2599 HASH_Init( &HASHcontext );
2600 if( prefix != NULL && prefix->bv_len > 0 ) {
2601 HASH_Update( &HASHcontext,
2602 prefix->bv_val, prefix->bv_len );
2604 HASH_Update( &HASHcontext,
2605 &pre, sizeof( pre ) );
2606 HASH_Update( &HASHcontext,
2607 syntax->ssyn_oid, slen );
2608 HASH_Update( &HASHcontext,
2609 mr->smr_oid, mlen );
2610 HASH_Update( &HASHcontext,
2611 &value->bv_val[value->bv_len-klen], klen );
2612 HASH_Final( HASHdigest, &HASHcontext );
2614 ber_dupbv( &keys[nkeys++], &digest );
2618 keys[nkeys].bv_val = NULL;
2625 return LDAP_SUCCESS;
2634 struct berval *value,
2635 void *assertedValue )
2637 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2639 if( match == 0 && value->bv_len ) {
2640 match = strncasecmp( value->bv_val,
2641 ((struct berval *) assertedValue)->bv_val,
2646 return LDAP_SUCCESS;
2650 caseIgnoreIA5SubstringsMatch(
2655 struct berval *value,
2656 void *assertedValue )
2659 SubstringsAssertion *sub = assertedValue;
2660 struct berval left = *value;
2664 /* Add up asserted input length */
2665 if( sub->sa_initial.bv_val ) {
2666 inlen += sub->sa_initial.bv_len;
2669 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2670 inlen += sub->sa_any[i].bv_len;
2673 if( sub->sa_final.bv_val ) {
2674 inlen += sub->sa_final.bv_len;
2677 if( sub->sa_initial.bv_val ) {
2678 if( inlen > left.bv_len ) {
2683 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2684 sub->sa_initial.bv_len );
2690 left.bv_val += sub->sa_initial.bv_len;
2691 left.bv_len -= sub->sa_initial.bv_len;
2692 inlen -= sub->sa_initial.bv_len;
2695 if( sub->sa_final.bv_val ) {
2696 if( inlen > left.bv_len ) {
2701 match = strncasecmp( sub->sa_final.bv_val,
2702 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2703 sub->sa_final.bv_len );
2709 left.bv_len -= sub->sa_final.bv_len;
2710 inlen -= sub->sa_final.bv_len;
2714 for(i=0; sub->sa_any[i].bv_val; i++) {
2719 if( inlen > left.bv_len ) {
2720 /* not enough length */
2725 if( sub->sa_any[i].bv_len == 0 ) {
2729 p = bvcasechr( &left, *sub->sa_any[i].bv_val, &idx );
2736 assert( idx < left.bv_len );
2737 if( idx >= left.bv_len ) {
2738 /* this shouldn't happen */
2745 if( sub->sa_any[i].bv_len > left.bv_len ) {
2746 /* not enough left */
2751 match = strncasecmp( left.bv_val,
2752 sub->sa_any[i].bv_val,
2753 sub->sa_any[i].bv_len );
2762 left.bv_val += sub->sa_any[i].bv_len;
2763 left.bv_len -= sub->sa_any[i].bv_len;
2764 inlen -= sub->sa_any[i].bv_len;
2770 return LDAP_SUCCESS;
2773 /* Index generation function */
2774 static int caseIgnoreIA5Indexer(
2779 struct berval *prefix,
2786 HASH_CONTEXT HASHcontext;
2787 unsigned char HASHdigest[HASH_BYTES];
2788 struct berval digest;
2789 digest.bv_val = HASHdigest;
2790 digest.bv_len = sizeof(HASHdigest);
2792 /* we should have at least one value at this point */
2793 assert( values != NULL && values[0].bv_val != NULL );
2795 for( i=0; values[i].bv_val != NULL; i++ ) {
2796 /* just count them */
2799 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2801 slen = syntax->ssyn_oidlen;
2802 mlen = mr->smr_oidlen;
2804 for( i=0; values[i].bv_val != NULL; i++ ) {
2805 struct berval value;
2806 ber_dupbv( &value, &values[i] );
2807 ldap_pvt_str2upper( value.bv_val );
2809 HASH_Init( &HASHcontext );
2810 if( prefix != NULL && prefix->bv_len > 0 ) {
2811 HASH_Update( &HASHcontext,
2812 prefix->bv_val, prefix->bv_len );
2814 HASH_Update( &HASHcontext,
2815 syntax->ssyn_oid, slen );
2816 HASH_Update( &HASHcontext,
2817 mr->smr_oid, mlen );
2818 HASH_Update( &HASHcontext,
2819 value.bv_val, value.bv_len );
2820 HASH_Final( HASHdigest, &HASHcontext );
2822 free( value.bv_val );
2824 ber_dupbv( &keys[i], &digest );
2827 keys[i].bv_val = NULL;
2829 return LDAP_SUCCESS;
2832 /* Index generation function */
2833 static int caseIgnoreIA5Filter(
2838 struct berval *prefix,
2844 HASH_CONTEXT HASHcontext;
2845 unsigned char HASHdigest[HASH_BYTES];
2846 struct berval value;
2847 struct berval digest;
2848 digest.bv_val = HASHdigest;
2849 digest.bv_len = sizeof(HASHdigest);
2851 slen = syntax->ssyn_oidlen;
2852 mlen = mr->smr_oidlen;
2854 ber_dupbv( &value, (struct berval *) assertValue );
2855 ldap_pvt_str2upper( value.bv_val );
2857 keys = ch_malloc( sizeof( struct berval ) * 2 );
2859 HASH_Init( &HASHcontext );
2860 if( prefix != NULL && prefix->bv_len > 0 ) {
2861 HASH_Update( &HASHcontext,
2862 prefix->bv_val, prefix->bv_len );
2864 HASH_Update( &HASHcontext,
2865 syntax->ssyn_oid, slen );
2866 HASH_Update( &HASHcontext,
2867 mr->smr_oid, mlen );
2868 HASH_Update( &HASHcontext,
2869 value.bv_val, value.bv_len );
2870 HASH_Final( HASHdigest, &HASHcontext );
2872 ber_dupbv( &keys[0], &digest );
2873 keys[1].bv_val = NULL;
2875 free( value.bv_val );
2879 return LDAP_SUCCESS;
2882 /* Substrings Index generation function */
2883 static int caseIgnoreIA5SubstringsIndexer(
2888 struct berval *prefix,
2895 HASH_CONTEXT HASHcontext;
2896 unsigned char HASHdigest[HASH_BYTES];
2897 struct berval digest;
2898 digest.bv_val = HASHdigest;
2899 digest.bv_len = sizeof(HASHdigest);
2901 /* we should have at least one value at this point */
2902 assert( values != NULL && values[0].bv_val != NULL );
2905 for( i=0; values[i].bv_val != NULL; i++ ) {
2906 /* count number of indices to generate */
2907 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2911 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2912 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2913 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2914 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2916 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2920 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2921 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2922 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2926 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2927 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2928 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2929 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2931 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2937 /* no keys to generate */
2939 return LDAP_SUCCESS;
2942 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2944 slen = syntax->ssyn_oidlen;
2945 mlen = mr->smr_oidlen;
2948 for( i=0; values[i].bv_val != NULL; i++ ) {
2950 struct berval value;
2952 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2954 ber_dupbv( &value, &values[i] );
2955 ldap_pvt_str2upper( value.bv_val );
2957 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2958 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2960 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2961 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2963 for( j=0; j<max; j++ ) {
2964 HASH_Init( &HASHcontext );
2965 if( prefix != NULL && prefix->bv_len > 0 ) {
2966 HASH_Update( &HASHcontext,
2967 prefix->bv_val, prefix->bv_len );
2970 HASH_Update( &HASHcontext,
2971 &pre, sizeof( pre ) );
2972 HASH_Update( &HASHcontext,
2973 syntax->ssyn_oid, slen );
2974 HASH_Update( &HASHcontext,
2975 mr->smr_oid, mlen );
2976 HASH_Update( &HASHcontext,
2978 SLAP_INDEX_SUBSTR_MAXLEN );
2979 HASH_Final( HASHdigest, &HASHcontext );
2981 ber_dupbv( &keys[nkeys++], &digest );
2985 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2986 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2988 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2991 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2992 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2993 HASH_Init( &HASHcontext );
2994 if( prefix != NULL && prefix->bv_len > 0 ) {
2995 HASH_Update( &HASHcontext,
2996 prefix->bv_val, prefix->bv_len );
2998 HASH_Update( &HASHcontext,
2999 &pre, sizeof( pre ) );
3000 HASH_Update( &HASHcontext,
3001 syntax->ssyn_oid, slen );
3002 HASH_Update( &HASHcontext,
3003 mr->smr_oid, mlen );
3004 HASH_Update( &HASHcontext,
3006 HASH_Final( HASHdigest, &HASHcontext );
3008 ber_dupbv( &keys[nkeys++], &digest );
3011 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3012 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3013 HASH_Init( &HASHcontext );
3014 if( prefix != NULL && prefix->bv_len > 0 ) {
3015 HASH_Update( &HASHcontext,
3016 prefix->bv_val, prefix->bv_len );
3018 HASH_Update( &HASHcontext,
3019 &pre, sizeof( pre ) );
3020 HASH_Update( &HASHcontext,
3021 syntax->ssyn_oid, slen );
3022 HASH_Update( &HASHcontext,
3023 mr->smr_oid, mlen );
3024 HASH_Update( &HASHcontext,
3025 &value.bv_val[value.bv_len-j], j );
3026 HASH_Final( HASHdigest, &HASHcontext );
3028 ber_dupbv( &keys[nkeys++], &digest );
3033 free( value.bv_val );
3037 keys[nkeys].bv_val = NULL;
3044 return LDAP_SUCCESS;
3047 static int caseIgnoreIA5SubstringsFilter(
3052 struct berval *prefix,
3056 SubstringsAssertion *sa = assertValue;
3058 ber_len_t nkeys = 0;
3059 size_t slen, mlen, klen;
3061 HASH_CONTEXT HASHcontext;
3062 unsigned char HASHdigest[HASH_BYTES];
3063 struct berval value;
3064 struct berval digest;
3066 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3067 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3072 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3074 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3075 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3076 /* don't bother accounting for stepping */
3077 nkeys += sa->sa_any[i].bv_len -
3078 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3083 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3084 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3091 return LDAP_SUCCESS;
3094 digest.bv_val = HASHdigest;
3095 digest.bv_len = sizeof(HASHdigest);
3097 slen = syntax->ssyn_oidlen;
3098 mlen = mr->smr_oidlen;
3100 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3103 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3104 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3106 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3107 ber_dupbv( &value, &sa->sa_initial );
3108 ldap_pvt_str2upper( value.bv_val );
3110 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3111 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3113 HASH_Init( &HASHcontext );
3114 if( prefix != NULL && prefix->bv_len > 0 ) {
3115 HASH_Update( &HASHcontext,
3116 prefix->bv_val, prefix->bv_len );
3118 HASH_Update( &HASHcontext,
3119 &pre, sizeof( pre ) );
3120 HASH_Update( &HASHcontext,
3121 syntax->ssyn_oid, slen );
3122 HASH_Update( &HASHcontext,
3123 mr->smr_oid, mlen );
3124 HASH_Update( &HASHcontext,
3125 value.bv_val, klen );
3126 HASH_Final( HASHdigest, &HASHcontext );
3128 free( value.bv_val );
3129 ber_dupbv( &keys[nkeys++], &digest );
3132 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3134 pre = SLAP_INDEX_SUBSTR_PREFIX;
3135 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3137 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3138 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3142 ber_dupbv( &value, &sa->sa_any[i] );
3143 ldap_pvt_str2upper( value.bv_val );
3146 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3147 j += SLAP_INDEX_SUBSTR_STEP )
3149 HASH_Init( &HASHcontext );
3150 if( prefix != NULL && prefix->bv_len > 0 ) {
3151 HASH_Update( &HASHcontext,
3152 prefix->bv_val, prefix->bv_len );
3154 HASH_Update( &HASHcontext,
3155 &pre, sizeof( pre ) );
3156 HASH_Update( &HASHcontext,
3157 syntax->ssyn_oid, slen );
3158 HASH_Update( &HASHcontext,
3159 mr->smr_oid, mlen );
3160 HASH_Update( &HASHcontext,
3161 &value.bv_val[j], klen );
3162 HASH_Final( HASHdigest, &HASHcontext );
3164 ber_dupbv( &keys[nkeys++], &digest );
3167 free( value.bv_val );
3171 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3172 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3174 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3175 ber_dupbv( &value, &sa->sa_final );
3176 ldap_pvt_str2upper( value.bv_val );
3178 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3179 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3181 HASH_Init( &HASHcontext );
3182 if( prefix != NULL && prefix->bv_len > 0 ) {
3183 HASH_Update( &HASHcontext,
3184 prefix->bv_val, prefix->bv_len );
3186 HASH_Update( &HASHcontext,
3187 &pre, sizeof( pre ) );
3188 HASH_Update( &HASHcontext,
3189 syntax->ssyn_oid, slen );
3190 HASH_Update( &HASHcontext,
3191 mr->smr_oid, mlen );
3192 HASH_Update( &HASHcontext,
3193 &value.bv_val[value.bv_len-klen], klen );
3194 HASH_Final( HASHdigest, &HASHcontext );
3196 free( value.bv_val );
3197 ber_dupbv( &keys[nkeys++], &digest );
3201 keys[nkeys].bv_val = NULL;
3208 return LDAP_SUCCESS;
3212 numericStringValidate(
3218 for(i=0; i < in->bv_len; i++) {
3219 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3220 return LDAP_INVALID_SYNTAX;
3224 return LDAP_SUCCESS;
3228 numericStringNormalize(
3231 struct berval *normalized )
3233 /* removal all spaces */
3236 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3239 q = normalized->bv_val;
3242 if ( ASCII_SPACE( *p ) ) {
3243 /* Ignore whitespace */
3250 /* we should have copied no more then is in val */
3251 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3253 /* null terminate */
3256 normalized->bv_len = q - normalized->bv_val;
3258 return LDAP_SUCCESS;
3262 objectIdentifierFirstComponentMatch(
3267 struct berval *value,
3268 void *assertedValue )
3270 int rc = LDAP_SUCCESS;
3272 struct berval *asserted = (struct berval *) assertedValue;
3276 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3277 return LDAP_INVALID_SYNTAX;
3280 /* trim leading white space */
3281 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3285 /* grab next word */
3286 oid.bv_val = &value->bv_val[i];
3287 oid.bv_len = value->bv_len - i;
3288 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3293 /* insert attributeTypes, objectclass check here */
3294 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3295 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3298 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3299 MatchingRule *asserted_mr = mr_bvfind( asserted );
3300 MatchingRule *stored_mr = mr_bvfind( &oid );
3302 if( asserted_mr == NULL ) {
3303 rc = SLAPD_COMPARE_UNDEFINED;
3305 match = asserted_mr != stored_mr;
3308 } else if ( !strcmp( syntax->ssyn_oid,
3309 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3311 AttributeType *asserted_at = at_bvfind( asserted );
3312 AttributeType *stored_at = at_bvfind( &oid );
3314 if( asserted_at == NULL ) {
3315 rc = SLAPD_COMPARE_UNDEFINED;
3317 match = asserted_at != stored_at;
3320 } else if ( !strcmp( syntax->ssyn_oid,
3321 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3323 ObjectClass *asserted_oc = oc_bvfind( asserted );
3324 ObjectClass *stored_oc = oc_bvfind( &oid );
3326 if( asserted_oc == NULL ) {
3327 rc = SLAPD_COMPARE_UNDEFINED;
3329 match = asserted_oc != stored_oc;
3335 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3336 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3337 match, value->bv_val, asserted->bv_val ));
3339 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3340 "%d\n\t\"%s\"\n\t\"%s\"\n",
3341 match, value->bv_val, asserted->bv_val );
3345 if( rc == LDAP_SUCCESS ) *matchp = match;
3355 struct berval *value,
3356 void *assertedValue )
3358 long lValue, lAssertedValue;
3360 /* safe to assume integers are NUL terminated? */
3361 lValue = strtoul(value->bv_val, NULL, 10);
3362 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3363 return LDAP_CONSTRAINT_VIOLATION;
3365 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3366 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3367 return LDAP_CONSTRAINT_VIOLATION;
3369 *matchp = (lValue & lAssertedValue);
3370 return LDAP_SUCCESS;
3379 struct berval *value,
3380 void *assertedValue )
3382 long lValue, lAssertedValue;
3384 /* safe to assume integers are NUL terminated? */
3385 lValue = strtoul(value->bv_val, NULL, 10);
3386 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3387 return LDAP_CONSTRAINT_VIOLATION;
3389 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3390 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3391 return LDAP_CONSTRAINT_VIOLATION;
3393 *matchp = (lValue | lAssertedValue);
3394 return LDAP_SUCCESS;
3398 #include <openssl/x509.h>
3399 #include <openssl/err.h>
3400 char digit[] = "0123456789";
3403 * Next function returns a string representation of a ASN1_INTEGER.
3404 * It works for unlimited lengths.
3407 static struct berval *
3408 asn1_integer2str(ASN1_INTEGER *a)
3413 /* We work backwards, make it fill from the end of buf */
3414 p = buf + sizeof(buf) - 1;
3417 if ( a == NULL || a->length == 0 ) {
3425 /* We want to preserve the original */
3426 copy = ch_malloc(n*sizeof(unsigned int));
3427 for (i = 0; i<n; i++) {
3428 copy[i] = a->data[i];
3432 * base indicates the index of the most significant
3433 * byte that might be nonzero. When it goes off the
3434 * end, we now there is nothing left to do.
3440 for (i = base; i<n; i++ ) {
3441 copy[i] += carry*256;
3442 carry = copy[i] % 10;
3447 * Way too large, we need to leave
3448 * room for sign if negative
3453 *--p = digit[carry];
3454 if (copy[base] == 0)
3460 if ( a->type == V_ASN1_NEG_INTEGER ) {
3464 return ber_bvstrdup(p);
3467 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3468 static struct berval *
3469 dn_openssl2ldap(X509_NAME *name)
3471 char issuer_dn[1024];
3474 bio = BIO_new(BIO_s_mem());
3477 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3478 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3479 ERR_error_string(ERR_get_error(),NULL)));
3481 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3482 "error creating BIO: %s\n",
3483 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3487 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3489 BIO_gets(bio, issuer_dn, 1024);
3492 return ber_bvstrdup(issuer_dn);
3496 * Given a certificate in DER format, extract the corresponding
3497 * assertion value for certificateExactMatch
3500 certificateExactConvert(
3502 struct berval * out )
3505 unsigned char *p = in->bv_val;
3506 struct berval *serial;
3507 struct berval *issuer_dn;
3508 struct berval *bv_tmp;
3510 xcert = d2i_X509(NULL, &p, in->bv_len);
3513 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3514 "certificateExactConvert: error parsing cert: %s\n",
3515 ERR_error_string(ERR_get_error(),NULL)));
3517 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3518 "error parsing cert: %s\n",
3519 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3521 return LDAP_INVALID_SYNTAX;
3524 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3527 return LDAP_INVALID_SYNTAX;
3529 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3533 return LDAP_INVALID_SYNTAX;
3535 /* Actually, dn_openssl2ldap returns in a normalized format, but
3536 it is different from our normalized format */
3538 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3542 return LDAP_INVALID_SYNTAX;
3548 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3549 out->bv_val = ch_malloc(out->bv_len);
3551 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3552 p += serial->bv_len;
3553 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3555 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3556 p += issuer_dn->bv_len;
3560 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3561 "certificateExactConvert: \n %s\n",
3564 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3566 out->bv_val, NULL, NULL );
3570 ber_bvfree(issuer_dn);
3572 return LDAP_SUCCESS;
3576 serial_and_issuer_parse(
3577 struct berval *assertion,
3578 struct berval **serial,
3579 struct berval **issuer_dn
3587 begin = assertion->bv_val;
3588 end = assertion->bv_val+assertion->bv_len-1;
3589 for (p=begin; p<=end && *p != '$'; p++)
3592 return LDAP_INVALID_SYNTAX;
3594 /* p now points at the $ sign, now use begin and end to delimit the
3596 while (ASCII_SPACE(*begin))
3599 while (ASCII_SPACE(*end))
3602 bv.bv_len = end-begin+1;
3604 *serial = ber_dupbv(NULL, &bv);
3606 /* now extract the issuer, remember p was at the dollar sign */
3608 end = assertion->bv_val+assertion->bv_len-1;
3609 while (ASCII_SPACE(*begin))
3611 /* should we trim spaces at the end too? is it safe always? */
3613 bv.bv_len = end-begin+1;
3615 dnNormalize( NULL, &bv, issuer_dn );
3617 return LDAP_SUCCESS;
3621 certificateExactMatch(
3626 struct berval *value,
3627 void *assertedValue )
3630 unsigned char *p = value->bv_val;
3631 struct berval *serial;
3632 struct berval *issuer_dn;
3633 struct berval *asserted_serial;
3634 struct berval *asserted_issuer_dn;
3637 xcert = d2i_X509(NULL, &p, value->bv_len);
3640 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3641 "certificateExactMatch: error parsing cert: %s\n",
3642 ERR_error_string(ERR_get_error(),NULL)));
3644 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3645 "error parsing cert: %s\n",
3646 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3648 return LDAP_INVALID_SYNTAX;
3651 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3652 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3656 serial_and_issuer_parse(assertedValue,
3658 &asserted_issuer_dn);
3663 slap_schema.si_syn_integer,
3664 slap_schema.si_mr_integerMatch,
3667 if ( ret == LDAP_SUCCESS ) {
3668 if ( *matchp == 0 ) {
3669 /* We need to normalize everything for dnMatch */
3673 slap_schema.si_syn_distinguishedName,
3674 slap_schema.si_mr_distinguishedNameMatch,
3676 asserted_issuer_dn);
3681 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3682 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3683 *matchp, serial->bv_val, issuer_dn->bv_val,
3684 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3686 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3687 "%d\n\t\"%s $ %s\"\n",
3688 *matchp, serial->bv_val, issuer_dn->bv_val );
3689 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3690 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3695 ber_bvfree(issuer_dn);
3696 ber_bvfree(asserted_serial);
3697 ber_bvfree(asserted_issuer_dn);
3703 * Index generation function
3704 * We just index the serials, in most scenarios the issuer DN is one of
3705 * a very small set of values.
3707 static int certificateExactIndexer(
3712 struct berval *prefix,
3720 struct berval * serial;
3722 /* we should have at least one value at this point */
3723 assert( values != NULL && values[0].bv_val != NULL );
3725 for( i=0; values[i].bv_val != NULL; i++ ) {
3726 /* empty -- just count them */
3729 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3731 for( i=0; values[i].bv_val != NULL; i++ ) {
3732 p = values[i].bv_val;
3733 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3736 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3737 "certificateExactIndexer: error parsing cert: %s\n",
3738 ERR_error_string(ERR_get_error(),NULL)));
3740 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3741 "error parsing cert: %s\n",
3742 ERR_error_string(ERR_get_error(),NULL),
3745 /* Do we leak keys on error? */
3746 return LDAP_INVALID_SYNTAX;
3749 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3751 integerNormalize( slap_schema.si_syn_integer,
3756 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3757 "certificateExactIndexer: returning: %s\n",
3760 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3767 keys[i].bv_val = NULL;
3769 return LDAP_SUCCESS;
3772 /* Index generation function */
3773 /* We think this is always called with a value in matching rule syntax */
3774 static int certificateExactFilter(
3779 struct berval *prefix,
3784 struct berval *asserted_serial;
3785 struct berval *asserted_issuer_dn;
3787 serial_and_issuer_parse(assertValue,
3789 &asserted_issuer_dn);
3791 keys = ch_malloc( sizeof( struct berval ) * 2 );
3792 integerNormalize( syntax, asserted_serial, &keys[0] );
3793 keys[1].bv_val = NULL;
3796 ber_bvfree(asserted_serial);
3797 ber_bvfree(asserted_issuer_dn);
3798 return LDAP_SUCCESS;
3803 check_time_syntax (struct berval *val,
3807 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3808 static int mdays[2][12] = {
3809 /* non-leap years */
3810 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3812 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3815 int part, c, tzoffset, leapyear = 0 ;
3817 if( val->bv_len == 0 ) {
3818 return LDAP_INVALID_SYNTAX;
3821 p = (char *)val->bv_val;
3822 e = p + val->bv_len;
3824 /* Ignore initial whitespace */
3825 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3829 if (e - p < 13 - (2 * start)) {
3830 return LDAP_INVALID_SYNTAX;
3833 for (part = 0; part < 9; part++) {
3837 for (part = start; part < 7; part++) {
3839 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3846 return LDAP_INVALID_SYNTAX;
3848 if (c < 0 || c > 9) {
3849 return LDAP_INVALID_SYNTAX;
3855 return LDAP_INVALID_SYNTAX;
3857 if (c < 0 || c > 9) {
3858 return LDAP_INVALID_SYNTAX;
3863 if (part == 2 || part == 3) {
3866 if (parts[part] < 0) {
3867 return LDAP_INVALID_SYNTAX;
3869 if (parts[part] > ceiling[part]) {
3870 return LDAP_INVALID_SYNTAX;
3874 /* leapyear check for the Gregorian calendar (year>1581) */
3875 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3876 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3881 if (parts[3] > mdays[leapyear][parts[2]]) {
3882 return LDAP_INVALID_SYNTAX;
3887 tzoffset = 0; /* UTC */
3888 } else if (c != '+' && c != '-') {
3889 return LDAP_INVALID_SYNTAX;
3893 } else /* c == '+' */ {
3898 return LDAP_INVALID_SYNTAX;
3901 for (part = 7; part < 9; part++) {
3903 if (c < 0 || c > 9) {
3904 return LDAP_INVALID_SYNTAX;
3909 if (c < 0 || c > 9) {
3910 return LDAP_INVALID_SYNTAX;
3914 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3915 return LDAP_INVALID_SYNTAX;
3920 /* Ignore trailing whitespace */
3921 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3925 return LDAP_INVALID_SYNTAX;
3928 switch ( tzoffset ) {
3929 case -1: /* negativ offset to UTC, ie west of Greenwich */
3930 parts[4] += parts[7];
3931 parts[5] += parts[8];
3932 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3936 c = mdays[leapyear][parts[2]];
3938 if (parts[part] > c) {
3939 parts[part] -= c + 1;
3944 case 1: /* positive offset to UTC, ie east of Greenwich */
3945 parts[4] -= parts[7];
3946 parts[5] -= parts[8];
3947 for (part = 6; --part > 0; ) {
3951 /* first arg to % needs to be non negativ */
3952 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3954 if (parts[part] < 0) {
3955 parts[part] += c + 1;
3960 case 0: /* already UTC */
3964 return LDAP_SUCCESS;
3971 struct berval *normalized )
3975 rc = check_time_syntax(val, 1, parts);
3976 if (rc != LDAP_SUCCESS) {
3980 normalized->bv_val = ch_malloc( 14 );
3981 if ( normalized->bv_val == NULL ) {
3982 return LBER_ERROR_MEMORY;
3985 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3986 parts[1], parts[2] + 1, parts[3] + 1,
3987 parts[4], parts[5], parts[6] );
3988 normalized->bv_len = 13;
3990 return LDAP_SUCCESS;
4000 return check_time_syntax(in, 1, parts);
4004 generalizedTimeValidate(
4010 return check_time_syntax(in, 0, parts);
4014 generalizedTimeNormalize(
4017 struct berval *normalized )
4021 rc = check_time_syntax(val, 0, parts);
4022 if (rc != LDAP_SUCCESS) {
4026 normalized->bv_val = ch_malloc( 16 );
4027 if ( normalized->bv_val == NULL ) {
4028 return LBER_ERROR_MEMORY;
4031 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4032 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4033 parts[4], parts[5], parts[6] );
4034 normalized->bv_len = 15;
4036 return LDAP_SUCCESS;
4040 nisNetgroupTripleValidate(
4042 struct berval *val )
4047 if ( val->bv_len == 0 ) {
4048 return LDAP_INVALID_SYNTAX;
4051 p = (char *)val->bv_val;
4052 e = p + val->bv_len;
4054 if ( *p != '(' /*')'*/ ) {
4055 return LDAP_INVALID_SYNTAX;
4058 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4062 return LDAP_INVALID_SYNTAX;
4065 } else if ( !ATTR_CHAR( *p ) ) {
4066 return LDAP_INVALID_SYNTAX;
4070 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4071 return LDAP_INVALID_SYNTAX;
4077 return LDAP_INVALID_SYNTAX;
4080 return LDAP_SUCCESS;
4084 bootParameterValidate(
4086 struct berval *val )
4090 if ( val->bv_len == 0 ) {
4091 return LDAP_INVALID_SYNTAX;
4094 p = (char *)val->bv_val;
4095 e = p + val->bv_len;
4098 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4099 if ( !ATTR_CHAR( *p ) ) {
4100 return LDAP_INVALID_SYNTAX;
4105 return LDAP_INVALID_SYNTAX;
4109 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4110 if ( !ATTR_CHAR( *p ) ) {
4111 return LDAP_INVALID_SYNTAX;
4116 return LDAP_INVALID_SYNTAX;
4120 for ( p++; p < e; p++ ) {
4121 if ( !ATTR_CHAR( *p ) ) {
4122 return LDAP_INVALID_SYNTAX;
4126 return LDAP_SUCCESS;
4129 static struct syntax_defs_rec {
4131 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4132 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4134 slap_syntax_validate_func *sd_validate;
4135 slap_syntax_transform_func *sd_normalize;
4136 slap_syntax_transform_func *sd_pretty;
4137 #ifdef SLAPD_BINARY_CONVERSION
4138 slap_syntax_transform_func *sd_ber2str;
4139 slap_syntax_transform_func *sd_str2ber;
4142 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4143 X_BINARY X_NOT_H_R ")",
4144 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4146 0, NULL, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4148 0, NULL, NULL, NULL},
4149 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4151 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4152 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4154 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4155 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4156 0, bitStringValidate, bitStringNormalize, NULL },
4157 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4158 0, booleanValidate, NULL, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4160 X_BINARY X_NOT_H_R ")",
4161 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4162 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4163 X_BINARY X_NOT_H_R ")",
4164 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4166 X_BINARY X_NOT_H_R ")",
4167 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4168 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4169 0, countryStringValidate, IA5StringNormalize, NULL},
4170 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4171 0, dnValidate, dnNormalize2, dnPretty2},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4173 0, NULL, NULL, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4175 0, NULL, NULL, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4177 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4179 0, NULL, NULL, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4181 0, NULL, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4183 0, NULL, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4185 0, NULL, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4187 0, NULL, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4189 0, printablesStringValidate, IA5StringNormalize, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4191 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4193 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4195 0, NULL, NULL, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4197 0, IA5StringValidate, IA5StringNormalize, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4199 0, integerValidate, integerNormalize, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4201 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4203 0, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4205 0, NULL, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4207 0, NULL, NULL, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4209 0, NULL, NULL, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4211 0, NULL, NULL, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4213 0, nameUIDValidate, nameUIDNormalize, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4215 0, NULL, NULL, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4217 0, numericStringValidate, numericStringNormalize, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4219 0, NULL, NULL, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4221 0, oidValidate, NULL, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4223 0, IA5StringValidate, IA5StringNormalize, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4225 0, blobValidate, NULL, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4227 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4229 0, NULL, NULL, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4231 0, NULL, NULL, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4233 0, printableStringValidate, IA5StringNormalize, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4235 X_BINARY X_NOT_H_R ")",
4236 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4238 X_BINARY X_NOT_H_R ")",
4239 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4240 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4241 0, printableStringValidate, IA5StringNormalize, NULL},
4242 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4243 0, NULL, NULL, NULL},
4244 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4245 0, printablesStringValidate, IA5StringNormalize, NULL},
4246 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4247 0, utcTimeValidate, utcTimeNormalize, NULL},
4248 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4249 0, NULL, NULL, NULL},
4250 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4251 0, NULL, NULL, NULL},
4252 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4253 0, NULL, NULL, NULL},
4254 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4255 0, NULL, NULL, NULL},
4256 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4257 0, NULL, NULL, NULL},
4259 /* RFC 2307 NIS Syntaxes */
4260 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4261 0, nisNetgroupTripleValidate, NULL, NULL},
4262 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4263 0, bootParameterValidate, NULL, NULL},
4267 /* These OIDs are not published yet, but will be in the next
4268 * I-D for PKIX LDAPv3 schema as have been advanced by David
4269 * Chadwick in private mail.
4271 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4272 0, NULL, NULL, NULL},
4275 /* OpenLDAP Experimental Syntaxes */
4276 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4278 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4281 #ifdef SLAPD_AUTHPASSWD
4282 /* needs updating */
4283 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4284 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4287 /* OpenLDAP Void Syntax */
4288 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4289 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4290 {NULL, 0, NULL, NULL, NULL}
4294 * Other matching rules in X.520 that we do not use (yet):
4296 * 2.5.13.9 numericStringOrderingMatch
4297 * 2.5.13.15 integerOrderingMatch
4298 * 2.5.13.18 octetStringOrderingMatch
4299 * 2.5.13.19 octetStringSubstringsMatch
4300 * 2.5.13.25 uTCTimeMatch
4301 * 2.5.13.26 uTCTimeOrderingMatch
4302 * 2.5.13.31 directoryStringFirstComponentMatch
4303 * 2.5.13.32 wordMatch
4304 * 2.5.13.33 keywordMatch
4305 * 2.5.13.35 certificateMatch
4306 * 2.5.13.36 certificatePairExactMatch
4307 * 2.5.13.37 certificatePairMatch
4308 * 2.5.13.38 certificateListExactMatch
4309 * 2.5.13.39 certificateListMatch
4310 * 2.5.13.40 algorithmIdentifierMatch
4311 * 2.5.13.41 storedPrefixMatch
4312 * 2.5.13.42 attributeCertificateMatch
4313 * 2.5.13.43 readerAndKeyIDMatch
4314 * 2.5.13.44 attributeIntegrityMatch
4316 static struct mrule_defs_rec {
4318 slap_mask_t mrd_usage;
4319 slap_mr_convert_func * mrd_convert;
4320 slap_mr_normalize_func * mrd_normalize;
4321 slap_mr_match_func * mrd_match;
4322 slap_mr_indexer_func * mrd_indexer;
4323 slap_mr_filter_func * mrd_filter;
4325 char * mrd_associated;
4328 * EQUALITY matching rules must be listed after associated APPROX
4329 * matching rules. So, we list all APPROX matching rules first.
4331 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4332 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4333 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4335 directoryStringApproxMatch,
4336 directoryStringApproxIndexer,
4337 directoryStringApproxFilter,
4340 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4341 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4342 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4344 IA5StringApproxMatch,
4345 IA5StringApproxIndexer,
4346 IA5StringApproxFilter,
4350 * Other matching rules
4353 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4354 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4355 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4357 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4360 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4361 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4362 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4364 dnMatch, dnIndexer, dnFilter,
4367 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4368 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4369 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4371 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4372 directoryStringApproxMatchOID },
4374 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4375 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4378 caseIgnoreOrderingMatch, NULL, NULL,
4381 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4382 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4383 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4385 caseExactIgnoreSubstringsMatch,
4386 caseExactIgnoreSubstringsIndexer,
4387 caseExactIgnoreSubstringsFilter,
4390 {"( 2.5.13.5 NAME 'caseExactMatch' "
4391 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4392 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4394 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4395 directoryStringApproxMatchOID },
4397 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4398 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4401 caseExactOrderingMatch, NULL, NULL,
4404 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4405 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4406 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4408 caseExactIgnoreSubstringsMatch,
4409 caseExactIgnoreSubstringsIndexer,
4410 caseExactIgnoreSubstringsFilter,
4413 {"( 2.5.13.8 NAME 'numericStringMatch' "
4414 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4415 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4418 caseIgnoreIA5Indexer,
4419 caseIgnoreIA5Filter,
4422 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4423 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4424 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4426 caseIgnoreIA5SubstringsMatch,
4427 caseIgnoreIA5SubstringsIndexer,
4428 caseIgnoreIA5SubstringsFilter,
4431 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4432 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4433 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4435 caseIgnoreListMatch, NULL, NULL,
4438 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4439 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4440 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4442 caseIgnoreListSubstringsMatch, NULL, NULL,
4445 {"( 2.5.13.13 NAME 'booleanMatch' "
4446 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4447 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4449 booleanMatch, NULL, NULL,
4452 {"( 2.5.13.14 NAME 'integerMatch' "
4453 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4454 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4456 integerMatch, integerIndexer, integerFilter,
4459 {"( 2.5.13.16 NAME 'bitStringMatch' "
4460 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4461 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4463 bitStringMatch, bitStringIndexer, bitStringFilter,
4466 {"( 2.5.13.17 NAME 'octetStringMatch' "
4467 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4468 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4470 octetStringMatch, octetStringIndexer, octetStringFilter,
4473 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4474 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4475 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4477 telephoneNumberMatch,
4478 telephoneNumberIndexer,
4479 telephoneNumberFilter,
4482 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4483 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4484 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4486 telephoneNumberSubstringsMatch,
4487 telephoneNumberSubstringsIndexer,
4488 telephoneNumberSubstringsFilter,
4491 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4492 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4493 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4498 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4499 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4500 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4502 uniqueMemberMatch, NULL, NULL,
4505 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4506 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4507 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4509 protocolInformationMatch, NULL, NULL,
4512 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4513 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4514 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4516 generalizedTimeMatch, NULL, NULL,
4519 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4520 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4523 generalizedTimeOrderingMatch, NULL, NULL,
4526 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4527 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4528 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4530 integerFirstComponentMatch, NULL, NULL,
4533 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4534 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4535 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4537 objectIdentifierFirstComponentMatch, NULL, NULL,
4541 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4542 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4543 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4544 certificateExactConvert, NULL,
4545 certificateExactMatch,
4546 certificateExactIndexer, certificateExactFilter,
4550 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4551 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4552 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4554 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4555 IA5StringApproxMatchOID },
4557 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4558 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4559 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4561 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4562 IA5StringApproxMatchOID },
4564 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4565 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4568 caseIgnoreIA5SubstringsMatch,
4569 caseIgnoreIA5SubstringsIndexer,
4570 caseIgnoreIA5SubstringsFilter,
4573 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4574 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4577 caseExactIA5SubstringsMatch,
4578 caseExactIA5SubstringsIndexer,
4579 caseExactIA5SubstringsFilter,
4582 #ifdef SLAPD_AUTHPASSWD
4583 /* needs updating */
4584 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4585 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4588 authPasswordMatch, NULL, NULL,
4592 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4593 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4596 OpenLDAPaciMatch, NULL, NULL,
4599 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4600 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4603 integerBitAndMatch, NULL, NULL,
4606 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4607 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4610 integerBitOrMatch, NULL, NULL,
4613 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4617 slap_schema_init( void )
4622 /* we should only be called once (from main) */
4623 assert( schema_init_done == 0 );
4625 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4626 res = register_syntax( syntax_defs[i].sd_desc,
4627 syntax_defs[i].sd_flags,
4628 syntax_defs[i].sd_validate,
4629 syntax_defs[i].sd_normalize,
4630 syntax_defs[i].sd_pretty
4631 #ifdef SLAPD_BINARY_CONVERSION
4633 syntax_defs[i].sd_ber2str,
4634 syntax_defs[i].sd_str2ber
4639 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4640 syntax_defs[i].sd_desc );
4645 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4646 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4648 "slap_schema_init: Ingoring unusable matching rule %s\n",
4649 mrule_defs[i].mrd_desc );
4653 res = register_matching_rule(
4654 mrule_defs[i].mrd_desc,
4655 mrule_defs[i].mrd_usage,
4656 mrule_defs[i].mrd_convert,
4657 mrule_defs[i].mrd_normalize,
4658 mrule_defs[i].mrd_match,
4659 mrule_defs[i].mrd_indexer,
4660 mrule_defs[i].mrd_filter,
4661 mrule_defs[i].mrd_associated );
4665 "slap_schema_init: Error registering matching rule %s\n",
4666 mrule_defs[i].mrd_desc );
4671 res = slap_schema_load();
4672 schema_init_done = 1;
4677 schema_destroy( void )