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 for ( ; p < val->bv_val + val->bv_len && ASCII_SPACE( p[ 0 ] ); p++ );
534 ber_mem2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
535 e = normalized->bv_val + val->bv_len - (p - val->bv_val);
537 assert( normalized->bv_val );
539 p = q = normalized->bv_val;
544 if ( ASCII_SPACE( *p ) ) {
549 /* Ignore the extra whitespace */
550 while ( ASCII_SPACE( *p ) ) {
554 len = LDAP_UTF8_COPY(q,p);
560 assert( normalized->bv_val < p );
561 assert( q+len <= p );
563 /* cannot start with a space */
564 assert( !ASCII_SPACE(normalized->bv_val[0]) );
567 * If the string ended in space, backup the pointer one
568 * position. One is enough because the above loop collapsed
569 * all whitespace to a single space.
577 /* cannot end with a space */
578 assert( !ASCII_SPACE( *q ) );
585 normalized->bv_len = q - normalized->bv_val;
590 /* Returns Unicode canonically normalized copy of a substring assertion
591 * Skipping attribute description */
592 static SubstringsAssertion *
593 UTF8SubstringsassertionNormalize(
594 SubstringsAssertion *sa,
597 SubstringsAssertion *nsa;
600 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
605 if( sa->sa_initial.bv_val != NULL ) {
606 UTF8bvnormalize( &sa->sa_initial, &nsa->sa_initial, casefold );
607 if( nsa->sa_initial.bv_val == NULL ) {
612 if( sa->sa_any != NULL ) {
613 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
616 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
617 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
618 UTF8bvnormalize( &sa->sa_any[i], &nsa->sa_any[i],
620 if( nsa->sa_any[i].bv_val == NULL ) {
624 nsa->sa_any[i].bv_val = NULL;
627 if( sa->sa_final.bv_val != NULL ) {
628 UTF8bvnormalize( &sa->sa_final, &nsa->sa_final, casefold );
629 if( nsa->sa_final.bv_val == NULL ) {
637 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
638 if ( nsa->sa_any )ber_bvarray_free( nsa->sa_any );
639 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
644 /* Strip characters with the 8th bit set */
657 while( *++q & 0x80 ) {
660 p = AC_MEMCPY(p, q, strlen(q) + 1);
668 #ifndef SLAPD_APPROX_OLDSINGLESTRING
670 #if defined(SLAPD_APPROX_INITIALS)
671 #define SLAPD_APPROX_DELIMITER "._ "
672 #define SLAPD_APPROX_WORDLEN 2
674 #define SLAPD_APPROX_DELIMITER " "
675 #define SLAPD_APPROX_WORDLEN 1
684 struct berval *value,
685 void *assertedValue )
687 char *val, *nval, *assertv, **values, **words, *c;
688 int i, count, len, nextchunk=0, nextavail=0;
691 /* Yes, this is necessary */
692 nval = UTF8normalize( value, LDAP_UTF8_NOCASEFOLD );
697 strip8bitChars( nval );
699 /* Yes, this is necessary */
700 assertv = UTF8normalize( ((struct berval *)assertedValue),
701 LDAP_UTF8_NOCASEFOLD );
702 if( assertv == NULL ) {
707 strip8bitChars( assertv );
708 avlen = strlen( assertv );
710 /* Isolate how many words there are */
711 for( c=nval,count=1; *c; c++ ) {
712 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
713 if ( c == NULL ) break;
718 /* Get a phonetic copy of each word */
719 words = (char **)ch_malloc( count * sizeof(char *) );
720 values = (char **)ch_malloc( count * sizeof(char *) );
721 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
723 values[i] = phonetic(c);
726 /* Work through the asserted value's words, to see if at least some
727 of the words are there, in the same order. */
729 while ( (size_t) nextchunk < avlen ) {
730 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
735 #if defined(SLAPD_APPROX_INITIALS)
736 else if( len == 1 ) {
737 /* Single letter words need to at least match one word's initial */
738 for( i=nextavail; i<count; i++ )
739 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
746 /* Isolate the next word in the asserted value and phonetic it */
747 assertv[nextchunk+len] = '\0';
748 val = phonetic( assertv + nextchunk );
750 /* See if this phonetic chunk is in the remaining words of *value */
751 for( i=nextavail; i<count; i++ ){
752 if( !strcmp( val, values[i] ) ){
760 /* This chunk in the asserted value was NOT within the *value. */
766 /* Go on to the next word in the asserted value */
770 /* If some of the words were seen, call it a match */
771 if( nextavail > 0 ) {
780 for( i=0; i<count; i++ ) {
781 ch_free( values[i] );
796 struct berval *prefix,
801 int i,j, len, wordcount, keycount=0;
802 struct berval *newkeys;
805 for( j=0; values[j].bv_val != NULL; j++ ) {
806 /* Yes, this is necessary */
807 val = UTF8normalize( &values[j], LDAP_UTF8_NOCASEFOLD );
808 strip8bitChars( val );
810 /* Isolate how many words there are. There will be a key for each */
811 for( wordcount=0,c=val; *c; c++) {
812 len = strcspn(c, SLAPD_APPROX_DELIMITER);
813 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
815 if (*c == '\0') break;
819 /* Allocate/increase storage to account for new keys */
820 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
821 * sizeof(struct berval) );
822 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
823 if( keys ) ch_free( keys );
826 /* Get a phonetic copy of each word */
827 for( c=val,i=0; i<wordcount; c+=len+1 ) {
829 if( len < SLAPD_APPROX_WORDLEN ) continue;
830 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
837 keys[keycount].bv_val = NULL;
849 struct berval *prefix,
857 /* Yes, this is necessary */
858 val = UTF8normalize( ((struct berval *)assertValue),
859 LDAP_UTF8_NOCASEFOLD );
861 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
862 keys[0].bv_val = NULL;
866 strip8bitChars( val );
868 /* Isolate how many words there are. There will be a key for each */
869 for( count=0,c=val; *c; c++) {
870 len = strcspn(c, SLAPD_APPROX_DELIMITER);
871 if( len >= SLAPD_APPROX_WORDLEN ) count++;
873 if (*c == '\0') break;
877 /* Allocate storage for new keys */
878 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
880 /* Get a phonetic copy of each word */
881 for( c=val,i=0; i<count; c+=len+1 ) {
883 if( len < SLAPD_APPROX_WORDLEN ) continue;
884 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
890 keys[count].bv_val = NULL;
898 /* No other form of Approximate Matching is defined */
906 struct berval *value,
907 void *assertedValue )
909 char *vapprox, *avapprox;
912 /* Yes, this is necessary */
913 s = UTF8normalize( value, UTF8_NOCASEFOLD );
919 /* Yes, this is necessary */
920 t = UTF8normalize( ((struct berval *)assertedValue),
928 vapprox = phonetic( strip8bitChars( s ) );
929 avapprox = phonetic( strip8bitChars( t ) );
934 *matchp = strcmp( vapprox, avapprox );
948 struct berval *prefix,
956 for( i=0; values[i].bv_val != NULL; i++ ) {
957 /* empty - just count them */
960 /* we should have at least one value at this point */
963 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
965 /* Copy each value and run it through phonetic() */
966 for( i=0; values[i].bv_val != NULL; i++ ) {
967 /* Yes, this is necessary */
968 s = UTF8normalize( &values[i], UTF8_NOCASEFOLD );
970 /* strip 8-bit chars and run through phonetic() */
971 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
974 keys[i].bv_val = NULL;
987 struct berval *prefix,
994 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
996 /* Yes, this is necessary */
997 s = UTF8normalize( ((struct berval *)assertValue),
1002 /* strip 8-bit chars and run through phonetic() */
1003 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1009 return LDAP_SUCCESS;
1020 struct berval *value,
1021 void *assertedValue )
1023 *matchp = UTF8normcmp( value->bv_val,
1024 ((struct berval *) assertedValue)->bv_val,
1025 LDAP_UTF8_NOCASEFOLD );
1026 return LDAP_SUCCESS;
1030 caseExactIgnoreSubstringsMatch(
1035 struct berval *value,
1036 void *assertedValue )
1039 SubstringsAssertion *sub = NULL;
1040 struct berval left = { 0, NULL };
1046 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1047 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1049 if ( UTF8bvnormalize( value, &left, casefold ) == NULL ) {
1055 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1061 /* Add up asserted input length */
1062 if( sub->sa_initial.bv_val ) {
1063 inlen += sub->sa_initial.bv_len;
1066 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1067 inlen += sub->sa_any[i].bv_len;
1070 if( sub->sa_final.bv_val ) {
1071 inlen += sub->sa_final.bv_len;
1074 if( sub->sa_initial.bv_val ) {
1075 if( inlen > left.bv_len ) {
1080 match = memcmp( sub->sa_initial.bv_val, left.bv_val,
1081 sub->sa_initial.bv_len );
1087 left.bv_val += sub->sa_initial.bv_len;
1088 left.bv_len -= sub->sa_initial.bv_len;
1089 inlen -= sub->sa_initial.bv_len;
1092 if( sub->sa_final.bv_val ) {
1093 if( inlen > left.bv_len ) {
1098 match = memcmp( sub->sa_final.bv_val,
1099 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1100 sub->sa_final.bv_len );
1106 left.bv_len -= sub->sa_final.bv_len;
1107 inlen -= sub->sa_final.bv_len;
1111 for(i=0; sub->sa_any[i].bv_val; i++) {
1116 if( inlen > left.bv_len ) {
1117 /* not enough length */
1122 if( sub->sa_any[i].bv_len == 0 ) {
1126 p = ber_bvchr( &left, *sub->sa_any[i].bv_val );
1133 idx = p - left.bv_val;
1135 if( idx >= left.bv_len ) {
1136 /* this shouldn't happen */
1138 if ( sub->sa_final.bv_val )
1139 ch_free( sub->sa_final.bv_val );
1141 ber_bvarray_free( sub->sa_any );
1142 if ( sub->sa_initial.bv_val )
1143 ch_free( sub->sa_initial.bv_val );
1151 if( sub->sa_any[i].bv_len > left.bv_len ) {
1152 /* not enough left */
1157 match = memcmp( left.bv_val,
1158 sub->sa_any[i].bv_val,
1159 sub->sa_any[i].bv_len );
1167 left.bv_val += sub->sa_any[i].bv_len;
1168 left.bv_len -= sub->sa_any[i].bv_len;
1169 inlen -= sub->sa_any[i].bv_len;
1176 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1177 if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
1178 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1182 return LDAP_SUCCESS;
1185 /* Index generation function */
1186 static int caseExactIgnoreIndexer(
1191 struct berval *prefix,
1199 HASH_CONTEXT HASHcontext;
1200 unsigned char HASHdigest[HASH_BYTES];
1201 struct berval digest;
1202 digest.bv_val = HASHdigest;
1203 digest.bv_len = sizeof(HASHdigest);
1205 for( i=0; values[i].bv_val != NULL; i++ ) {
1206 /* empty - just count them */
1209 /* we should have at least one value at this point */
1212 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1214 slen = syntax->ssyn_oidlen;
1215 mlen = mr->smr_oidlen;
1217 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1218 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1220 for( i=0; values[i].bv_val != NULL; i++ ) {
1221 struct berval value;
1222 ber_str2bv( UTF8normalize( &values[i], casefold ), 0, 0,
1225 HASH_Init( &HASHcontext );
1226 if( prefix != NULL && prefix->bv_len > 0 ) {
1227 HASH_Update( &HASHcontext,
1228 prefix->bv_val, prefix->bv_len );
1230 HASH_Update( &HASHcontext,
1231 syntax->ssyn_oid, slen );
1232 HASH_Update( &HASHcontext,
1233 mr->smr_oid, mlen );
1234 HASH_Update( &HASHcontext,
1235 value.bv_val, value.bv_len );
1236 HASH_Final( HASHdigest, &HASHcontext );
1238 free( value.bv_val );
1240 ber_dupbv( &keys[i], &digest );
1243 keys[i].bv_val = NULL;
1245 return LDAP_SUCCESS;
1248 /* Index generation function */
1249 static int caseExactIgnoreFilter(
1254 struct berval *prefix,
1261 HASH_CONTEXT HASHcontext;
1262 unsigned char HASHdigest[HASH_BYTES];
1263 struct berval value;
1264 struct berval digest;
1265 digest.bv_val = HASHdigest;
1266 digest.bv_len = sizeof(HASHdigest);
1268 slen = syntax->ssyn_oidlen;
1269 mlen = mr->smr_oidlen;
1271 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1272 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1274 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1276 /* This usually happens if filter contains bad UTF8 */
1277 if( value.bv_val == NULL ) {
1278 keys = ch_malloc( sizeof( struct berval ) );
1279 keys[0].bv_val = NULL;
1280 return LDAP_SUCCESS;
1283 keys = ch_malloc( sizeof( struct berval ) * 2 );
1285 HASH_Init( &HASHcontext );
1286 if( prefix != NULL && prefix->bv_len > 0 ) {
1287 HASH_Update( &HASHcontext,
1288 prefix->bv_val, prefix->bv_len );
1290 HASH_Update( &HASHcontext,
1291 syntax->ssyn_oid, slen );
1292 HASH_Update( &HASHcontext,
1293 mr->smr_oid, mlen );
1294 HASH_Update( &HASHcontext,
1295 value.bv_val, value.bv_len );
1296 HASH_Final( HASHdigest, &HASHcontext );
1298 ber_dupbv( keys, &digest );
1299 keys[1].bv_val = NULL;
1301 free( value.bv_val );
1304 return LDAP_SUCCESS;
1307 /* Substrings Index generation function */
1308 static int caseExactIgnoreSubstringsIndexer(
1313 struct berval *prefix,
1323 HASH_CONTEXT HASHcontext;
1324 unsigned char HASHdigest[HASH_BYTES];
1325 struct berval digest;
1326 digest.bv_val = HASHdigest;
1327 digest.bv_len = sizeof(HASHdigest);
1331 for( i=0; values[i].bv_val != NULL; i++ ) {
1332 /* empty - just count them */
1335 /* we should have at least one value at this point */
1338 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1339 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1341 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1342 for( i=0; values[i].bv_val != NULL; i++ ) {
1343 ber_str2bv( UTF8normalize( &values[i], casefold ),
1344 0, 0, &nvalues[i] );
1346 nvalues[i].bv_val = NULL;
1349 for( i=0; values[i].bv_val != NULL; i++ ) {
1350 /* count number of indices to generate */
1351 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1355 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1356 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1357 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1358 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1360 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1364 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1365 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1366 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1370 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1371 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1372 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1373 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1375 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1381 /* no keys to generate */
1383 ber_bvarray_free( nvalues );
1384 return LDAP_SUCCESS;
1387 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1389 slen = syntax->ssyn_oidlen;
1390 mlen = mr->smr_oidlen;
1393 for( i=0; values[i].bv_val != NULL; i++ ) {
1396 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1398 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1399 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1401 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1402 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1404 for( j=0; j<max; j++ ) {
1405 HASH_Init( &HASHcontext );
1406 if( prefix != NULL && prefix->bv_len > 0 ) {
1407 HASH_Update( &HASHcontext,
1408 prefix->bv_val, prefix->bv_len );
1411 HASH_Update( &HASHcontext,
1412 &pre, sizeof( pre ) );
1413 HASH_Update( &HASHcontext,
1414 syntax->ssyn_oid, slen );
1415 HASH_Update( &HASHcontext,
1416 mr->smr_oid, mlen );
1417 HASH_Update( &HASHcontext,
1418 &values[i].bv_val[j],
1419 SLAP_INDEX_SUBSTR_MAXLEN );
1420 HASH_Final( HASHdigest, &HASHcontext );
1422 ber_dupbv( &keys[nkeys++], &digest );
1426 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1427 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1429 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1432 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1433 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1434 HASH_Init( &HASHcontext );
1435 if( prefix != NULL && prefix->bv_len > 0 ) {
1436 HASH_Update( &HASHcontext,
1437 prefix->bv_val, prefix->bv_len );
1439 HASH_Update( &HASHcontext,
1440 &pre, sizeof( pre ) );
1441 HASH_Update( &HASHcontext,
1442 syntax->ssyn_oid, slen );
1443 HASH_Update( &HASHcontext,
1444 mr->smr_oid, mlen );
1445 HASH_Update( &HASHcontext,
1446 values[i].bv_val, j );
1447 HASH_Final( HASHdigest, &HASHcontext );
1449 ber_dupbv( &keys[nkeys++], &digest );
1452 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1453 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1454 HASH_Init( &HASHcontext );
1455 if( prefix != NULL && prefix->bv_len > 0 ) {
1456 HASH_Update( &HASHcontext,
1457 prefix->bv_val, prefix->bv_len );
1459 HASH_Update( &HASHcontext,
1460 &pre, sizeof( pre ) );
1461 HASH_Update( &HASHcontext,
1462 syntax->ssyn_oid, slen );
1463 HASH_Update( &HASHcontext,
1464 mr->smr_oid, mlen );
1465 HASH_Update( &HASHcontext,
1466 &values[i].bv_val[values[i].bv_len-j], j );
1467 HASH_Final( HASHdigest, &HASHcontext );
1469 ber_dupbv( &keys[nkeys++], &digest );
1477 keys[nkeys].bv_val = NULL;
1484 ber_bvarray_free( nvalues );
1486 return LDAP_SUCCESS;
1489 static int caseExactIgnoreSubstringsFilter(
1494 struct berval *prefix,
1498 SubstringsAssertion *sa;
1501 ber_len_t nkeys = 0;
1502 size_t slen, mlen, klen;
1504 HASH_CONTEXT HASHcontext;
1505 unsigned char HASHdigest[HASH_BYTES];
1506 struct berval *value;
1507 struct berval digest;
1509 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1510 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1512 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1515 return LDAP_SUCCESS;
1518 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1519 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1524 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1526 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1527 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1528 /* don't bother accounting for stepping */
1529 nkeys += sa->sa_any[i].bv_len -
1530 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1535 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1536 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1542 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1543 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1544 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1547 return LDAP_SUCCESS;
1550 digest.bv_val = HASHdigest;
1551 digest.bv_len = sizeof(HASHdigest);
1553 slen = syntax->ssyn_oidlen;
1554 mlen = mr->smr_oidlen;
1556 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1559 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1560 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1562 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1563 value = &sa->sa_initial;
1565 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1566 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1568 HASH_Init( &HASHcontext );
1569 if( prefix != NULL && prefix->bv_len > 0 ) {
1570 HASH_Update( &HASHcontext,
1571 prefix->bv_val, prefix->bv_len );
1573 HASH_Update( &HASHcontext,
1574 &pre, sizeof( pre ) );
1575 HASH_Update( &HASHcontext,
1576 syntax->ssyn_oid, slen );
1577 HASH_Update( &HASHcontext,
1578 mr->smr_oid, mlen );
1579 HASH_Update( &HASHcontext,
1580 value->bv_val, klen );
1581 HASH_Final( HASHdigest, &HASHcontext );
1583 ber_dupbv( &keys[nkeys++], &digest );
1586 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1588 pre = SLAP_INDEX_SUBSTR_PREFIX;
1589 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1591 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1592 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1596 value = &sa->sa_any[i];
1599 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1600 j += SLAP_INDEX_SUBSTR_STEP )
1602 HASH_Init( &HASHcontext );
1603 if( prefix != NULL && prefix->bv_len > 0 ) {
1604 HASH_Update( &HASHcontext,
1605 prefix->bv_val, prefix->bv_len );
1607 HASH_Update( &HASHcontext,
1608 &pre, sizeof( pre ) );
1609 HASH_Update( &HASHcontext,
1610 syntax->ssyn_oid, slen );
1611 HASH_Update( &HASHcontext,
1612 mr->smr_oid, mlen );
1613 HASH_Update( &HASHcontext,
1614 &value->bv_val[j], klen );
1615 HASH_Final( HASHdigest, &HASHcontext );
1617 ber_dupbv( &keys[nkeys++], &digest );
1623 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1624 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1626 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1627 value = &sa->sa_final;
1629 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1630 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1632 HASH_Init( &HASHcontext );
1633 if( prefix != NULL && prefix->bv_len > 0 ) {
1634 HASH_Update( &HASHcontext,
1635 prefix->bv_val, prefix->bv_len );
1637 HASH_Update( &HASHcontext,
1638 &pre, sizeof( pre ) );
1639 HASH_Update( &HASHcontext,
1640 syntax->ssyn_oid, slen );
1641 HASH_Update( &HASHcontext,
1642 mr->smr_oid, mlen );
1643 HASH_Update( &HASHcontext,
1644 &value->bv_val[value->bv_len-klen], klen );
1645 HASH_Final( HASHdigest, &HASHcontext );
1647 ber_dupbv( &keys[nkeys++], &digest );
1651 keys[nkeys].bv_val = NULL;
1657 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1658 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1659 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1662 return LDAP_SUCCESS;
1671 struct berval *value,
1672 void *assertedValue )
1674 *matchp = UTF8normcmp( value->bv_val,
1675 ((struct berval *) assertedValue)->bv_val,
1676 LDAP_UTF8_CASEFOLD );
1677 return LDAP_SUCCESS;
1683 struct berval *val )
1687 if( val->bv_len == 0 ) {
1688 /* disallow empty strings */
1689 return LDAP_INVALID_SYNTAX;
1692 if( OID_LEADCHAR(val->bv_val[0]) ) {
1694 for(i=1; i < val->bv_len; i++) {
1695 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1696 if( dot++ ) return 1;
1697 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1700 return LDAP_INVALID_SYNTAX;
1704 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1706 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1707 for(i=1; i < val->bv_len; i++) {
1708 if( !DESC_CHAR(val->bv_val[i] ) ) {
1709 return LDAP_INVALID_SYNTAX;
1713 return LDAP_SUCCESS;
1716 return LDAP_INVALID_SYNTAX;
1725 struct berval *value,
1726 void *assertedValue )
1729 int vsign=0, avsign=0;
1730 struct berval *asserted;
1731 ber_len_t vlen, avlen;
1734 /* Start off pessimistic */
1737 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1739 vlen = value->bv_len;
1741 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1742 /* empty -- skip spaces */
1744 else if ( *v == '+' ) {
1747 else if ( *v == '-' ) {
1750 else if ( ASCII_DIGIT(*v) ) {
1751 if ( vsign == 0 ) vsign = 1;
1759 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1761 asserted = (struct berval *) assertedValue;
1762 av = asserted->bv_val;
1763 avlen = asserted->bv_len;
1765 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1766 /* empty -- skip spaces */
1768 else if ( *av == '+' ) {
1771 else if ( *av == '-' ) {
1774 else if ( ASCII_DIGIT(*av) ) {
1775 if ( avsign == 0 ) avsign = 1;
1783 /* The two ?sign vars are now one of :
1784 -2 negative non-zero number
1786 0 0 collapse these three to 0
1788 +2 positive non-zero number
1790 if ( abs( vsign ) == 1 ) vsign = 0;
1791 if ( abs( avsign ) == 1 ) avsign = 0;
1793 if( vsign != avsign ) return LDAP_SUCCESS;
1795 /* Check the significant digits */
1796 while( vlen && avlen ) {
1797 if( *v != *av ) break;
1804 /* If all digits compared equal, the numbers are equal */
1805 if(( vlen == 0 ) && ( avlen == 0 )) {
1808 return LDAP_SUCCESS;
1814 struct berval *val )
1818 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1820 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1821 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1822 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1823 return LDAP_INVALID_SYNTAX;
1826 for( i=1; i < val->bv_len; i++ ) {
1827 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1830 return LDAP_SUCCESS;
1837 struct berval *normalized )
1847 /* Ignore leading spaces */
1848 while ( len && ( *p == ' ' )) {
1855 negative = ( *p == '-' );
1856 if(( *p == '-' ) || ( *p == '+' )) {
1862 /* Ignore leading zeros */
1863 while ( len && ( *p == '0' )) {
1868 /* If there are no non-zero digits left, the number is zero, otherwise
1869 allocate space for the number and copy it into the buffer */
1871 normalized->bv_val = ch_strdup("0");
1872 normalized->bv_len = 1;
1875 normalized->bv_len = len+negative;
1876 normalized->bv_val = ch_malloc( normalized->bv_len );
1878 normalized->bv_val[0] = '-';
1880 AC_MEMCPY( normalized->bv_val + negative, p, len );
1883 return LDAP_SUCCESS;
1886 /* Index generation function */
1887 static int integerIndexer(
1892 struct berval *prefix,
1899 /* we should have at least one value at this point */
1900 assert( values != NULL && values[0].bv_val != NULL );
1902 for( i=0; values[i].bv_val != NULL; i++ ) {
1903 /* empty -- just count them */
1906 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1908 for( i=0; values[i].bv_val != NULL; i++ ) {
1909 integerNormalize( syntax, &values[i], &keys[i] );
1912 keys[i].bv_val = NULL;
1914 return LDAP_SUCCESS;
1917 /* Index generation function */
1918 static int integerFilter(
1923 struct berval *prefix,
1929 keys = ch_malloc( sizeof( struct berval ) * 2 );
1930 integerNormalize( syntax, assertValue, &keys[0] );
1931 keys[1].bv_val = NULL;
1934 return LDAP_SUCCESS;
1939 countryStringValidate(
1941 struct berval *val )
1943 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1945 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1946 return LDAP_INVALID_SYNTAX;
1948 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1949 return LDAP_INVALID_SYNTAX;
1952 return LDAP_SUCCESS;
1956 printableStringValidate(
1958 struct berval *val )
1962 for(i=0; i < val->bv_len; i++) {
1963 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1964 return LDAP_INVALID_SYNTAX;
1968 return LDAP_SUCCESS;
1972 printablesStringValidate(
1974 struct berval *val )
1978 for(i=0; i < val->bv_len; i++) {
1979 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1980 return LDAP_INVALID_SYNTAX;
1984 return LDAP_SUCCESS;
1990 struct berval *val )
1994 for(i=0; i < val->bv_len; i++) {
1995 if( !LDAP_ASCII(val->bv_val[i]) ) {
1996 return LDAP_INVALID_SYNTAX;
2000 return LDAP_SUCCESS;
2007 struct berval *normalized )
2013 /* Ignore initial whitespace */
2014 while ( ASCII_SPACE( *p ) ) {
2018 normalized->bv_val = ch_strdup( p );
2019 p = q = normalized->bv_val;
2022 if ( ASCII_SPACE( *p ) ) {
2025 /* Ignore the extra whitespace */
2026 while ( ASCII_SPACE( *p ) ) {
2034 assert( normalized->bv_val <= p );
2038 * If the string ended in space, backup the pointer one
2039 * position. One is enough because the above loop collapsed
2040 * all whitespace to a single space.
2043 if ( ASCII_SPACE( q[-1] ) ) {
2047 /* null terminate */
2050 normalized->bv_len = q - normalized->bv_val;
2052 return LDAP_SUCCESS;
2061 struct berval *value,
2062 void *assertedValue )
2064 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2067 match = strncmp( value->bv_val,
2068 ((struct berval *) assertedValue)->bv_val,
2073 return LDAP_SUCCESS;
2077 caseExactIA5SubstringsMatch(
2082 struct berval *value,
2083 void *assertedValue )
2086 SubstringsAssertion *sub = assertedValue;
2087 struct berval left = *value;
2091 /* Add up asserted input length */
2092 if( sub->sa_initial.bv_val ) {
2093 inlen += sub->sa_initial.bv_len;
2096 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2097 inlen += sub->sa_any[i].bv_len;
2100 if( sub->sa_final.bv_val ) {
2101 inlen += sub->sa_final.bv_len;
2104 if( sub->sa_initial.bv_val ) {
2105 if( inlen > left.bv_len ) {
2110 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2111 sub->sa_initial.bv_len );
2117 left.bv_val += sub->sa_initial.bv_len;
2118 left.bv_len -= sub->sa_initial.bv_len;
2119 inlen -= sub->sa_initial.bv_len;
2122 if( sub->sa_final.bv_val ) {
2123 if( inlen > left.bv_len ) {
2128 match = strncmp( sub->sa_final.bv_val,
2129 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2130 sub->sa_final.bv_len );
2136 left.bv_len -= sub->sa_final.bv_len;
2137 inlen -= sub->sa_final.bv_len;
2141 for(i=0; sub->sa_any[i].bv_val; i++) {
2146 if( inlen > left.bv_len ) {
2147 /* not enough length */
2152 if( sub->sa_any[i].bv_len == 0 ) {
2156 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2163 idx = p - left.bv_val;
2165 if( idx >= left.bv_len ) {
2166 /* this shouldn't happen */
2173 if( sub->sa_any[i].bv_len > left.bv_len ) {
2174 /* not enough left */
2179 match = strncmp( left.bv_val,
2180 sub->sa_any[i].bv_val,
2181 sub->sa_any[i].bv_len );
2189 left.bv_val += sub->sa_any[i].bv_len;
2190 left.bv_len -= sub->sa_any[i].bv_len;
2191 inlen -= sub->sa_any[i].bv_len;
2197 return LDAP_SUCCESS;
2200 /* Index generation function */
2201 static int caseExactIA5Indexer(
2206 struct berval *prefix,
2213 HASH_CONTEXT HASHcontext;
2214 unsigned char HASHdigest[HASH_BYTES];
2215 struct berval digest;
2216 digest.bv_val = HASHdigest;
2217 digest.bv_len = sizeof(HASHdigest);
2219 for( i=0; values[i].bv_val != NULL; i++ ) {
2220 /* empty - just count them */
2223 /* we should have at least one value at this point */
2226 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2228 slen = syntax->ssyn_oidlen;
2229 mlen = mr->smr_oidlen;
2231 for( i=0; values[i].bv_val != NULL; i++ ) {
2232 struct berval *value = &values[i];
2234 HASH_Init( &HASHcontext );
2235 if( prefix != NULL && prefix->bv_len > 0 ) {
2236 HASH_Update( &HASHcontext,
2237 prefix->bv_val, prefix->bv_len );
2239 HASH_Update( &HASHcontext,
2240 syntax->ssyn_oid, slen );
2241 HASH_Update( &HASHcontext,
2242 mr->smr_oid, mlen );
2243 HASH_Update( &HASHcontext,
2244 value->bv_val, value->bv_len );
2245 HASH_Final( HASHdigest, &HASHcontext );
2247 ber_dupbv( &keys[i], &digest );
2250 keys[i].bv_val = NULL;
2252 return LDAP_SUCCESS;
2255 /* Index generation function */
2256 static int caseExactIA5Filter(
2261 struct berval *prefix,
2267 HASH_CONTEXT HASHcontext;
2268 unsigned char HASHdigest[HASH_BYTES];
2269 struct berval *value;
2270 struct berval digest;
2271 digest.bv_val = HASHdigest;
2272 digest.bv_len = sizeof(HASHdigest);
2274 slen = syntax->ssyn_oidlen;
2275 mlen = mr->smr_oidlen;
2277 value = (struct berval *) assertValue;
2279 keys = ch_malloc( sizeof( struct berval ) * 2 );
2281 HASH_Init( &HASHcontext );
2282 if( prefix != NULL && prefix->bv_len > 0 ) {
2283 HASH_Update( &HASHcontext,
2284 prefix->bv_val, prefix->bv_len );
2286 HASH_Update( &HASHcontext,
2287 syntax->ssyn_oid, slen );
2288 HASH_Update( &HASHcontext,
2289 mr->smr_oid, mlen );
2290 HASH_Update( &HASHcontext,
2291 value->bv_val, value->bv_len );
2292 HASH_Final( HASHdigest, &HASHcontext );
2294 ber_dupbv( &keys[0], &digest );
2295 keys[1].bv_val = NULL;
2298 return LDAP_SUCCESS;
2301 /* Substrings Index generation function */
2302 static int caseExactIA5SubstringsIndexer(
2307 struct berval *prefix,
2314 HASH_CONTEXT HASHcontext;
2315 unsigned char HASHdigest[HASH_BYTES];
2316 struct berval digest;
2317 digest.bv_val = HASHdigest;
2318 digest.bv_len = sizeof(HASHdigest);
2320 /* we should have at least one value at this point */
2321 assert( values != NULL && values[0].bv_val != NULL );
2324 for( i=0; values[i].bv_val != NULL; i++ ) {
2325 /* count number of indices to generate */
2326 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2330 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2331 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2332 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2333 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2335 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2339 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2340 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2341 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2345 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2346 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2347 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2348 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2350 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2356 /* no keys to generate */
2358 return LDAP_SUCCESS;
2361 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2363 slen = syntax->ssyn_oidlen;
2364 mlen = mr->smr_oidlen;
2367 for( i=0; values[i].bv_val != NULL; i++ ) {
2369 struct berval *value;
2372 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2374 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2375 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2377 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2378 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2380 for( j=0; j<max; j++ ) {
2381 HASH_Init( &HASHcontext );
2382 if( prefix != NULL && prefix->bv_len > 0 ) {
2383 HASH_Update( &HASHcontext,
2384 prefix->bv_val, prefix->bv_len );
2387 HASH_Update( &HASHcontext,
2388 &pre, sizeof( pre ) );
2389 HASH_Update( &HASHcontext,
2390 syntax->ssyn_oid, slen );
2391 HASH_Update( &HASHcontext,
2392 mr->smr_oid, mlen );
2393 HASH_Update( &HASHcontext,
2395 SLAP_INDEX_SUBSTR_MAXLEN );
2396 HASH_Final( HASHdigest, &HASHcontext );
2398 ber_dupbv( &keys[nkeys++], &digest );
2402 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2403 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2405 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2408 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2409 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2410 HASH_Init( &HASHcontext );
2411 if( prefix != NULL && prefix->bv_len > 0 ) {
2412 HASH_Update( &HASHcontext,
2413 prefix->bv_val, prefix->bv_len );
2415 HASH_Update( &HASHcontext,
2416 &pre, sizeof( pre ) );
2417 HASH_Update( &HASHcontext,
2418 syntax->ssyn_oid, slen );
2419 HASH_Update( &HASHcontext,
2420 mr->smr_oid, mlen );
2421 HASH_Update( &HASHcontext,
2423 HASH_Final( HASHdigest, &HASHcontext );
2425 ber_dupbv( &keys[nkeys++], &digest );
2428 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2429 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2430 HASH_Init( &HASHcontext );
2431 if( prefix != NULL && prefix->bv_len > 0 ) {
2432 HASH_Update( &HASHcontext,
2433 prefix->bv_val, prefix->bv_len );
2435 HASH_Update( &HASHcontext,
2436 &pre, sizeof( pre ) );
2437 HASH_Update( &HASHcontext,
2438 syntax->ssyn_oid, slen );
2439 HASH_Update( &HASHcontext,
2440 mr->smr_oid, mlen );
2441 HASH_Update( &HASHcontext,
2442 &value->bv_val[value->bv_len-j], j );
2443 HASH_Final( HASHdigest, &HASHcontext );
2445 ber_dupbv( &keys[nkeys++], &digest );
2452 keys[nkeys].bv_val = NULL;
2459 return LDAP_SUCCESS;
2462 static int caseExactIA5SubstringsFilter(
2467 struct berval *prefix,
2471 SubstringsAssertion *sa = assertValue;
2473 ber_len_t nkeys = 0;
2474 size_t slen, mlen, klen;
2476 HASH_CONTEXT HASHcontext;
2477 unsigned char HASHdigest[HASH_BYTES];
2478 struct berval *value;
2479 struct berval digest;
2481 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2482 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2487 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2489 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2490 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2491 /* don't bother accounting for stepping */
2492 nkeys += sa->sa_any[i].bv_len -
2493 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2498 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2499 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2506 return LDAP_SUCCESS;
2509 digest.bv_val = HASHdigest;
2510 digest.bv_len = sizeof(HASHdigest);
2512 slen = syntax->ssyn_oidlen;
2513 mlen = mr->smr_oidlen;
2515 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2518 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2519 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2521 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2522 value = &sa->sa_initial;
2524 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2525 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2527 HASH_Init( &HASHcontext );
2528 if( prefix != NULL && prefix->bv_len > 0 ) {
2529 HASH_Update( &HASHcontext,
2530 prefix->bv_val, prefix->bv_len );
2532 HASH_Update( &HASHcontext,
2533 &pre, sizeof( pre ) );
2534 HASH_Update( &HASHcontext,
2535 syntax->ssyn_oid, slen );
2536 HASH_Update( &HASHcontext,
2537 mr->smr_oid, mlen );
2538 HASH_Update( &HASHcontext,
2539 value->bv_val, klen );
2540 HASH_Final( HASHdigest, &HASHcontext );
2542 ber_dupbv( &keys[nkeys++], &digest );
2545 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2547 pre = SLAP_INDEX_SUBSTR_PREFIX;
2548 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2550 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2551 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2555 value = &sa->sa_any[i];
2558 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2559 j += SLAP_INDEX_SUBSTR_STEP )
2561 HASH_Init( &HASHcontext );
2562 if( prefix != NULL && prefix->bv_len > 0 ) {
2563 HASH_Update( &HASHcontext,
2564 prefix->bv_val, prefix->bv_len );
2566 HASH_Update( &HASHcontext,
2567 &pre, sizeof( pre ) );
2568 HASH_Update( &HASHcontext,
2569 syntax->ssyn_oid, slen );
2570 HASH_Update( &HASHcontext,
2571 mr->smr_oid, mlen );
2572 HASH_Update( &HASHcontext,
2573 &value->bv_val[j], klen );
2574 HASH_Final( HASHdigest, &HASHcontext );
2576 ber_dupbv( &keys[nkeys++], &digest );
2581 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2582 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2584 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2585 value = &sa->sa_final;
2587 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2588 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2590 HASH_Init( &HASHcontext );
2591 if( prefix != NULL && prefix->bv_len > 0 ) {
2592 HASH_Update( &HASHcontext,
2593 prefix->bv_val, prefix->bv_len );
2595 HASH_Update( &HASHcontext,
2596 &pre, sizeof( pre ) );
2597 HASH_Update( &HASHcontext,
2598 syntax->ssyn_oid, slen );
2599 HASH_Update( &HASHcontext,
2600 mr->smr_oid, mlen );
2601 HASH_Update( &HASHcontext,
2602 &value->bv_val[value->bv_len-klen], klen );
2603 HASH_Final( HASHdigest, &HASHcontext );
2605 ber_dupbv( &keys[nkeys++], &digest );
2609 keys[nkeys].bv_val = NULL;
2616 return LDAP_SUCCESS;
2625 struct berval *value,
2626 void *assertedValue )
2628 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2630 if( match == 0 && value->bv_len ) {
2631 match = strncasecmp( value->bv_val,
2632 ((struct berval *) assertedValue)->bv_val,
2637 return LDAP_SUCCESS;
2641 caseIgnoreIA5SubstringsMatch(
2646 struct berval *value,
2647 void *assertedValue )
2650 SubstringsAssertion *sub = assertedValue;
2651 struct berval left = *value;
2655 /* Add up asserted input length */
2656 if( sub->sa_initial.bv_val ) {
2657 inlen += sub->sa_initial.bv_len;
2660 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2661 inlen += sub->sa_any[i].bv_len;
2664 if( sub->sa_final.bv_val ) {
2665 inlen += sub->sa_final.bv_len;
2668 if( sub->sa_initial.bv_val ) {
2669 if( inlen > left.bv_len ) {
2674 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2675 sub->sa_initial.bv_len );
2681 left.bv_val += sub->sa_initial.bv_len;
2682 left.bv_len -= sub->sa_initial.bv_len;
2683 inlen -= sub->sa_initial.bv_len;
2686 if( sub->sa_final.bv_val ) {
2687 if( inlen > left.bv_len ) {
2692 match = strncasecmp( sub->sa_final.bv_val,
2693 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2694 sub->sa_final.bv_len );
2700 left.bv_len -= sub->sa_final.bv_len;
2701 inlen -= sub->sa_final.bv_len;
2705 for(i=0; sub->sa_any[i].bv_val; i++) {
2710 if( inlen > left.bv_len ) {
2711 /* not enough length */
2716 if( sub->sa_any[i].bv_len == 0 ) {
2720 p = bvcasechr( &left, *sub->sa_any[i].bv_val, &idx );
2727 assert( idx < left.bv_len );
2728 if( idx >= left.bv_len ) {
2729 /* this shouldn't happen */
2736 if( sub->sa_any[i].bv_len > left.bv_len ) {
2737 /* not enough left */
2742 match = strncasecmp( left.bv_val,
2743 sub->sa_any[i].bv_val,
2744 sub->sa_any[i].bv_len );
2753 left.bv_val += sub->sa_any[i].bv_len;
2754 left.bv_len -= sub->sa_any[i].bv_len;
2755 inlen -= sub->sa_any[i].bv_len;
2761 return LDAP_SUCCESS;
2764 /* Index generation function */
2765 static int caseIgnoreIA5Indexer(
2770 struct berval *prefix,
2777 HASH_CONTEXT HASHcontext;
2778 unsigned char HASHdigest[HASH_BYTES];
2779 struct berval digest;
2780 digest.bv_val = HASHdigest;
2781 digest.bv_len = sizeof(HASHdigest);
2783 /* we should have at least one value at this point */
2784 assert( values != NULL && values[0].bv_val != NULL );
2786 for( i=0; values[i].bv_val != NULL; i++ ) {
2787 /* just count them */
2790 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2792 slen = syntax->ssyn_oidlen;
2793 mlen = mr->smr_oidlen;
2795 for( i=0; values[i].bv_val != NULL; i++ ) {
2796 struct berval value;
2797 ber_dupbv( &value, &values[i] );
2798 ldap_pvt_str2upper( value.bv_val );
2800 HASH_Init( &HASHcontext );
2801 if( prefix != NULL && prefix->bv_len > 0 ) {
2802 HASH_Update( &HASHcontext,
2803 prefix->bv_val, prefix->bv_len );
2805 HASH_Update( &HASHcontext,
2806 syntax->ssyn_oid, slen );
2807 HASH_Update( &HASHcontext,
2808 mr->smr_oid, mlen );
2809 HASH_Update( &HASHcontext,
2810 value.bv_val, value.bv_len );
2811 HASH_Final( HASHdigest, &HASHcontext );
2813 free( value.bv_val );
2815 ber_dupbv( &keys[i], &digest );
2818 keys[i].bv_val = NULL;
2820 return LDAP_SUCCESS;
2823 /* Index generation function */
2824 static int caseIgnoreIA5Filter(
2829 struct berval *prefix,
2835 HASH_CONTEXT HASHcontext;
2836 unsigned char HASHdigest[HASH_BYTES];
2837 struct berval value;
2838 struct berval digest;
2839 digest.bv_val = HASHdigest;
2840 digest.bv_len = sizeof(HASHdigest);
2842 slen = syntax->ssyn_oidlen;
2843 mlen = mr->smr_oidlen;
2845 ber_dupbv( &value, (struct berval *) assertValue );
2846 ldap_pvt_str2upper( value.bv_val );
2848 keys = ch_malloc( sizeof( struct berval ) * 2 );
2850 HASH_Init( &HASHcontext );
2851 if( prefix != NULL && prefix->bv_len > 0 ) {
2852 HASH_Update( &HASHcontext,
2853 prefix->bv_val, prefix->bv_len );
2855 HASH_Update( &HASHcontext,
2856 syntax->ssyn_oid, slen );
2857 HASH_Update( &HASHcontext,
2858 mr->smr_oid, mlen );
2859 HASH_Update( &HASHcontext,
2860 value.bv_val, value.bv_len );
2861 HASH_Final( HASHdigest, &HASHcontext );
2863 ber_dupbv( &keys[0], &digest );
2864 keys[1].bv_val = NULL;
2866 free( value.bv_val );
2870 return LDAP_SUCCESS;
2873 /* Substrings Index generation function */
2874 static int caseIgnoreIA5SubstringsIndexer(
2879 struct berval *prefix,
2886 HASH_CONTEXT HASHcontext;
2887 unsigned char HASHdigest[HASH_BYTES];
2888 struct berval digest;
2889 digest.bv_val = HASHdigest;
2890 digest.bv_len = sizeof(HASHdigest);
2892 /* we should have at least one value at this point */
2893 assert( values != NULL && values[0].bv_val != NULL );
2896 for( i=0; values[i].bv_val != NULL; i++ ) {
2897 /* count number of indices to generate */
2898 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2902 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2903 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2904 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2905 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2907 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2911 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2912 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2913 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2917 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2918 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2919 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2920 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2922 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2928 /* no keys to generate */
2930 return LDAP_SUCCESS;
2933 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2935 slen = syntax->ssyn_oidlen;
2936 mlen = mr->smr_oidlen;
2939 for( i=0; values[i].bv_val != NULL; i++ ) {
2941 struct berval value;
2943 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2945 ber_dupbv( &value, &values[i] );
2946 ldap_pvt_str2upper( value.bv_val );
2948 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2949 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2951 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2952 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2954 for( j=0; j<max; j++ ) {
2955 HASH_Init( &HASHcontext );
2956 if( prefix != NULL && prefix->bv_len > 0 ) {
2957 HASH_Update( &HASHcontext,
2958 prefix->bv_val, prefix->bv_len );
2961 HASH_Update( &HASHcontext,
2962 &pre, sizeof( pre ) );
2963 HASH_Update( &HASHcontext,
2964 syntax->ssyn_oid, slen );
2965 HASH_Update( &HASHcontext,
2966 mr->smr_oid, mlen );
2967 HASH_Update( &HASHcontext,
2969 SLAP_INDEX_SUBSTR_MAXLEN );
2970 HASH_Final( HASHdigest, &HASHcontext );
2972 ber_dupbv( &keys[nkeys++], &digest );
2976 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2977 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2979 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2982 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2983 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2984 HASH_Init( &HASHcontext );
2985 if( prefix != NULL && prefix->bv_len > 0 ) {
2986 HASH_Update( &HASHcontext,
2987 prefix->bv_val, prefix->bv_len );
2989 HASH_Update( &HASHcontext,
2990 &pre, sizeof( pre ) );
2991 HASH_Update( &HASHcontext,
2992 syntax->ssyn_oid, slen );
2993 HASH_Update( &HASHcontext,
2994 mr->smr_oid, mlen );
2995 HASH_Update( &HASHcontext,
2997 HASH_Final( HASHdigest, &HASHcontext );
2999 ber_dupbv( &keys[nkeys++], &digest );
3002 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3003 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3004 HASH_Init( &HASHcontext );
3005 if( prefix != NULL && prefix->bv_len > 0 ) {
3006 HASH_Update( &HASHcontext,
3007 prefix->bv_val, prefix->bv_len );
3009 HASH_Update( &HASHcontext,
3010 &pre, sizeof( pre ) );
3011 HASH_Update( &HASHcontext,
3012 syntax->ssyn_oid, slen );
3013 HASH_Update( &HASHcontext,
3014 mr->smr_oid, mlen );
3015 HASH_Update( &HASHcontext,
3016 &value.bv_val[value.bv_len-j], j );
3017 HASH_Final( HASHdigest, &HASHcontext );
3019 ber_dupbv( &keys[nkeys++], &digest );
3024 free( value.bv_val );
3028 keys[nkeys].bv_val = NULL;
3035 return LDAP_SUCCESS;
3038 static int caseIgnoreIA5SubstringsFilter(
3043 struct berval *prefix,
3047 SubstringsAssertion *sa = assertValue;
3049 ber_len_t nkeys = 0;
3050 size_t slen, mlen, klen;
3052 HASH_CONTEXT HASHcontext;
3053 unsigned char HASHdigest[HASH_BYTES];
3054 struct berval value;
3055 struct berval digest;
3057 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3058 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3063 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3065 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3066 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3067 /* don't bother accounting for stepping */
3068 nkeys += sa->sa_any[i].bv_len -
3069 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3074 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3075 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3082 return LDAP_SUCCESS;
3085 digest.bv_val = HASHdigest;
3086 digest.bv_len = sizeof(HASHdigest);
3088 slen = syntax->ssyn_oidlen;
3089 mlen = mr->smr_oidlen;
3091 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3094 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3095 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3097 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3098 ber_dupbv( &value, &sa->sa_initial );
3099 ldap_pvt_str2upper( value.bv_val );
3101 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3102 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3104 HASH_Init( &HASHcontext );
3105 if( prefix != NULL && prefix->bv_len > 0 ) {
3106 HASH_Update( &HASHcontext,
3107 prefix->bv_val, prefix->bv_len );
3109 HASH_Update( &HASHcontext,
3110 &pre, sizeof( pre ) );
3111 HASH_Update( &HASHcontext,
3112 syntax->ssyn_oid, slen );
3113 HASH_Update( &HASHcontext,
3114 mr->smr_oid, mlen );
3115 HASH_Update( &HASHcontext,
3116 value.bv_val, klen );
3117 HASH_Final( HASHdigest, &HASHcontext );
3119 free( value.bv_val );
3120 ber_dupbv( &keys[nkeys++], &digest );
3123 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3125 pre = SLAP_INDEX_SUBSTR_PREFIX;
3126 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3128 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3129 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3133 ber_dupbv( &value, &sa->sa_any[i] );
3134 ldap_pvt_str2upper( value.bv_val );
3137 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3138 j += SLAP_INDEX_SUBSTR_STEP )
3140 HASH_Init( &HASHcontext );
3141 if( prefix != NULL && prefix->bv_len > 0 ) {
3142 HASH_Update( &HASHcontext,
3143 prefix->bv_val, prefix->bv_len );
3145 HASH_Update( &HASHcontext,
3146 &pre, sizeof( pre ) );
3147 HASH_Update( &HASHcontext,
3148 syntax->ssyn_oid, slen );
3149 HASH_Update( &HASHcontext,
3150 mr->smr_oid, mlen );
3151 HASH_Update( &HASHcontext,
3152 &value.bv_val[j], klen );
3153 HASH_Final( HASHdigest, &HASHcontext );
3155 ber_dupbv( &keys[nkeys++], &digest );
3158 free( value.bv_val );
3162 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3163 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3165 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3166 ber_dupbv( &value, &sa->sa_final );
3167 ldap_pvt_str2upper( value.bv_val );
3169 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3170 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3172 HASH_Init( &HASHcontext );
3173 if( prefix != NULL && prefix->bv_len > 0 ) {
3174 HASH_Update( &HASHcontext,
3175 prefix->bv_val, prefix->bv_len );
3177 HASH_Update( &HASHcontext,
3178 &pre, sizeof( pre ) );
3179 HASH_Update( &HASHcontext,
3180 syntax->ssyn_oid, slen );
3181 HASH_Update( &HASHcontext,
3182 mr->smr_oid, mlen );
3183 HASH_Update( &HASHcontext,
3184 &value.bv_val[value.bv_len-klen], klen );
3185 HASH_Final( HASHdigest, &HASHcontext );
3187 free( value.bv_val );
3188 ber_dupbv( &keys[nkeys++], &digest );
3192 keys[nkeys].bv_val = NULL;
3199 return LDAP_SUCCESS;
3203 numericStringValidate(
3209 for(i=0; i < in->bv_len; i++) {
3210 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3211 return LDAP_INVALID_SYNTAX;
3215 return LDAP_SUCCESS;
3219 numericStringNormalize(
3222 struct berval *normalized )
3224 /* removal all spaces */
3227 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3230 q = normalized->bv_val;
3233 if ( ASCII_SPACE( *p ) ) {
3234 /* Ignore whitespace */
3241 /* we should have copied no more then is in val */
3242 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3244 /* null terminate */
3247 normalized->bv_len = q - normalized->bv_val;
3249 return LDAP_SUCCESS;
3253 objectIdentifierFirstComponentMatch(
3258 struct berval *value,
3259 void *assertedValue )
3261 int rc = LDAP_SUCCESS;
3263 struct berval *asserted = (struct berval *) assertedValue;
3267 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3268 return LDAP_INVALID_SYNTAX;
3271 /* trim leading white space */
3272 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3276 /* grab next word */
3277 oid.bv_val = &value->bv_val[i];
3278 oid.bv_len = value->bv_len - i;
3279 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3284 /* insert attributeTypes, objectclass check here */
3285 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3286 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3289 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3290 MatchingRule *asserted_mr = mr_bvfind( asserted );
3291 MatchingRule *stored_mr = mr_bvfind( &oid );
3293 if( asserted_mr == NULL ) {
3294 rc = SLAPD_COMPARE_UNDEFINED;
3296 match = asserted_mr != stored_mr;
3299 } else if ( !strcmp( syntax->ssyn_oid,
3300 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3302 AttributeType *asserted_at = at_bvfind( asserted );
3303 AttributeType *stored_at = at_bvfind( &oid );
3305 if( asserted_at == NULL ) {
3306 rc = SLAPD_COMPARE_UNDEFINED;
3308 match = asserted_at != stored_at;
3311 } else if ( !strcmp( syntax->ssyn_oid,
3312 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3314 ObjectClass *asserted_oc = oc_bvfind( asserted );
3315 ObjectClass *stored_oc = oc_bvfind( &oid );
3317 if( asserted_oc == NULL ) {
3318 rc = SLAPD_COMPARE_UNDEFINED;
3320 match = asserted_oc != stored_oc;
3326 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3327 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3328 match, value->bv_val, asserted->bv_val ));
3330 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3331 "%d\n\t\"%s\"\n\t\"%s\"\n",
3332 match, value->bv_val, asserted->bv_val );
3336 if( rc == LDAP_SUCCESS ) *matchp = match;
3346 struct berval *value,
3347 void *assertedValue )
3349 long lValue, lAssertedValue;
3351 /* safe to assume integers are NUL terminated? */
3352 lValue = strtoul(value->bv_val, NULL, 10);
3353 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3354 return LDAP_CONSTRAINT_VIOLATION;
3356 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3357 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3358 return LDAP_CONSTRAINT_VIOLATION;
3360 *matchp = (lValue & lAssertedValue);
3361 return LDAP_SUCCESS;
3370 struct berval *value,
3371 void *assertedValue )
3373 long lValue, lAssertedValue;
3375 /* safe to assume integers are NUL terminated? */
3376 lValue = strtoul(value->bv_val, NULL, 10);
3377 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3378 return LDAP_CONSTRAINT_VIOLATION;
3380 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3381 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3382 return LDAP_CONSTRAINT_VIOLATION;
3384 *matchp = (lValue | lAssertedValue);
3385 return LDAP_SUCCESS;
3389 #include <openssl/x509.h>
3390 #include <openssl/err.h>
3391 char digit[] = "0123456789";
3394 * Next function returns a string representation of a ASN1_INTEGER.
3395 * It works for unlimited lengths.
3398 static struct berval *
3399 asn1_integer2str(ASN1_INTEGER *a)
3404 /* We work backwards, make it fill from the end of buf */
3405 p = buf + sizeof(buf) - 1;
3408 if ( a == NULL || a->length == 0 ) {
3416 /* We want to preserve the original */
3417 copy = ch_malloc(n*sizeof(unsigned int));
3418 for (i = 0; i<n; i++) {
3419 copy[i] = a->data[i];
3423 * base indicates the index of the most significant
3424 * byte that might be nonzero. When it goes off the
3425 * end, we now there is nothing left to do.
3431 for (i = base; i<n; i++ ) {
3432 copy[i] += carry*256;
3433 carry = copy[i] % 10;
3438 * Way too large, we need to leave
3439 * room for sign if negative
3444 *--p = digit[carry];
3445 if (copy[base] == 0)
3451 if ( a->type == V_ASN1_NEG_INTEGER ) {
3455 return ber_bvstrdup(p);
3458 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3459 static struct berval *
3460 dn_openssl2ldap(X509_NAME *name)
3462 char issuer_dn[1024];
3465 bio = BIO_new(BIO_s_mem());
3468 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3469 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3470 ERR_error_string(ERR_get_error(),NULL)));
3472 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3473 "error creating BIO: %s\n",
3474 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3478 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3480 BIO_gets(bio, issuer_dn, 1024);
3483 return ber_bvstrdup(issuer_dn);
3487 * Given a certificate in DER format, extract the corresponding
3488 * assertion value for certificateExactMatch
3491 certificateExactConvert(
3493 struct berval * out )
3496 unsigned char *p = in->bv_val;
3497 struct berval *serial;
3498 struct berval *issuer_dn;
3499 struct berval *bv_tmp;
3501 xcert = d2i_X509(NULL, &p, in->bv_len);
3504 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3505 "certificateExactConvert: error parsing cert: %s\n",
3506 ERR_error_string(ERR_get_error(),NULL)));
3508 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3509 "error parsing cert: %s\n",
3510 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3512 return LDAP_INVALID_SYNTAX;
3515 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3518 return LDAP_INVALID_SYNTAX;
3520 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3524 return LDAP_INVALID_SYNTAX;
3526 /* Actually, dn_openssl2ldap returns in a normalized format, but
3527 it is different from our normalized format */
3529 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3533 return LDAP_INVALID_SYNTAX;
3539 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3540 out->bv_val = ch_malloc(out->bv_len);
3542 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3543 p += serial->bv_len;
3544 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3546 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3547 p += issuer_dn->bv_len;
3551 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3552 "certificateExactConvert: \n %s\n",
3555 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3557 out->bv_val, NULL, NULL );
3561 ber_bvfree(issuer_dn);
3563 return LDAP_SUCCESS;
3567 serial_and_issuer_parse(
3568 struct berval *assertion,
3569 struct berval **serial,
3570 struct berval **issuer_dn
3578 begin = assertion->bv_val;
3579 end = assertion->bv_val+assertion->bv_len-1;
3580 for (p=begin; p<=end && *p != '$'; p++)
3583 return LDAP_INVALID_SYNTAX;
3585 /* p now points at the $ sign, now use begin and end to delimit the
3587 while (ASCII_SPACE(*begin))
3590 while (ASCII_SPACE(*end))
3593 bv.bv_len = end-begin+1;
3595 *serial = ber_dupbv(NULL, &bv);
3597 /* now extract the issuer, remember p was at the dollar sign */
3599 end = assertion->bv_val+assertion->bv_len-1;
3600 while (ASCII_SPACE(*begin))
3602 /* should we trim spaces at the end too? is it safe always? */
3604 bv.bv_len = end-begin+1;
3606 dnNormalize( NULL, &bv, issuer_dn );
3608 return LDAP_SUCCESS;
3612 certificateExactMatch(
3617 struct berval *value,
3618 void *assertedValue )
3621 unsigned char *p = value->bv_val;
3622 struct berval *serial;
3623 struct berval *issuer_dn;
3624 struct berval *asserted_serial;
3625 struct berval *asserted_issuer_dn;
3628 xcert = d2i_X509(NULL, &p, value->bv_len);
3631 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3632 "certificateExactMatch: error parsing cert: %s\n",
3633 ERR_error_string(ERR_get_error(),NULL)));
3635 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3636 "error parsing cert: %s\n",
3637 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3639 return LDAP_INVALID_SYNTAX;
3642 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3643 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3647 serial_and_issuer_parse(assertedValue,
3649 &asserted_issuer_dn);
3654 slap_schema.si_syn_integer,
3655 slap_schema.si_mr_integerMatch,
3658 if ( ret == LDAP_SUCCESS ) {
3659 if ( *matchp == 0 ) {
3660 /* We need to normalize everything for dnMatch */
3664 slap_schema.si_syn_distinguishedName,
3665 slap_schema.si_mr_distinguishedNameMatch,
3667 asserted_issuer_dn);
3672 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3673 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3674 *matchp, serial->bv_val, issuer_dn->bv_val,
3675 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3677 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3678 "%d\n\t\"%s $ %s\"\n",
3679 *matchp, serial->bv_val, issuer_dn->bv_val );
3680 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3681 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3686 ber_bvfree(issuer_dn);
3687 ber_bvfree(asserted_serial);
3688 ber_bvfree(asserted_issuer_dn);
3694 * Index generation function
3695 * We just index the serials, in most scenarios the issuer DN is one of
3696 * a very small set of values.
3698 static int certificateExactIndexer(
3703 struct berval *prefix,
3711 struct berval * serial;
3713 /* we should have at least one value at this point */
3714 assert( values != NULL && values[0].bv_val != NULL );
3716 for( i=0; values[i].bv_val != NULL; i++ ) {
3717 /* empty -- just count them */
3720 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3722 for( i=0; values[i].bv_val != NULL; i++ ) {
3723 p = values[i].bv_val;
3724 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3727 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3728 "certificateExactIndexer: error parsing cert: %s\n",
3729 ERR_error_string(ERR_get_error(),NULL)));
3731 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3732 "error parsing cert: %s\n",
3733 ERR_error_string(ERR_get_error(),NULL),
3736 /* Do we leak keys on error? */
3737 return LDAP_INVALID_SYNTAX;
3740 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3742 integerNormalize( slap_schema.si_syn_integer,
3747 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3748 "certificateExactIndexer: returning: %s\n",
3751 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3758 keys[i].bv_val = NULL;
3760 return LDAP_SUCCESS;
3763 /* Index generation function */
3764 /* We think this is always called with a value in matching rule syntax */
3765 static int certificateExactFilter(
3770 struct berval *prefix,
3775 struct berval *asserted_serial;
3776 struct berval *asserted_issuer_dn;
3778 serial_and_issuer_parse(assertValue,
3780 &asserted_issuer_dn);
3782 keys = ch_malloc( sizeof( struct berval ) * 2 );
3783 integerNormalize( syntax, asserted_serial, &keys[0] );
3784 keys[1].bv_val = NULL;
3787 ber_bvfree(asserted_serial);
3788 ber_bvfree(asserted_issuer_dn);
3789 return LDAP_SUCCESS;
3794 check_time_syntax (struct berval *val,
3798 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3799 static int mdays[2][12] = {
3800 /* non-leap years */
3801 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3803 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3806 int part, c, tzoffset, leapyear = 0 ;
3808 if( val->bv_len == 0 ) {
3809 return LDAP_INVALID_SYNTAX;
3812 p = (char *)val->bv_val;
3813 e = p + val->bv_len;
3815 /* Ignore initial whitespace */
3816 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3820 if (e - p < 13 - (2 * start)) {
3821 return LDAP_INVALID_SYNTAX;
3824 for (part = 0; part < 9; part++) {
3828 for (part = start; part < 7; part++) {
3830 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3837 return LDAP_INVALID_SYNTAX;
3839 if (c < 0 || c > 9) {
3840 return LDAP_INVALID_SYNTAX;
3846 return LDAP_INVALID_SYNTAX;
3848 if (c < 0 || c > 9) {
3849 return LDAP_INVALID_SYNTAX;
3854 if (part == 2 || part == 3) {
3857 if (parts[part] < 0) {
3858 return LDAP_INVALID_SYNTAX;
3860 if (parts[part] > ceiling[part]) {
3861 return LDAP_INVALID_SYNTAX;
3865 /* leapyear check for the Gregorian calendar (year>1581) */
3866 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3867 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3872 if (parts[3] > mdays[leapyear][parts[2]]) {
3873 return LDAP_INVALID_SYNTAX;
3878 tzoffset = 0; /* UTC */
3879 } else if (c != '+' && c != '-') {
3880 return LDAP_INVALID_SYNTAX;
3884 } else /* c == '+' */ {
3889 return LDAP_INVALID_SYNTAX;
3892 for (part = 7; part < 9; part++) {
3894 if (c < 0 || c > 9) {
3895 return LDAP_INVALID_SYNTAX;
3900 if (c < 0 || c > 9) {
3901 return LDAP_INVALID_SYNTAX;
3905 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3906 return LDAP_INVALID_SYNTAX;
3911 /* Ignore trailing whitespace */
3912 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3916 return LDAP_INVALID_SYNTAX;
3919 switch ( tzoffset ) {
3920 case -1: /* negativ offset to UTC, ie west of Greenwich */
3921 parts[4] += parts[7];
3922 parts[5] += parts[8];
3923 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3927 c = mdays[leapyear][parts[2]];
3929 if (parts[part] > c) {
3930 parts[part] -= c + 1;
3935 case 1: /* positive offset to UTC, ie east of Greenwich */
3936 parts[4] -= parts[7];
3937 parts[5] -= parts[8];
3938 for (part = 6; --part > 0; ) {
3942 /* first arg to % needs to be non negativ */
3943 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3945 if (parts[part] < 0) {
3946 parts[part] += c + 1;
3951 case 0: /* already UTC */
3955 return LDAP_SUCCESS;
3962 struct berval *normalized )
3966 rc = check_time_syntax(val, 1, parts);
3967 if (rc != LDAP_SUCCESS) {
3971 normalized->bv_val = ch_malloc( 14 );
3972 if ( normalized->bv_val == NULL ) {
3973 return LBER_ERROR_MEMORY;
3976 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3977 parts[1], parts[2] + 1, parts[3] + 1,
3978 parts[4], parts[5], parts[6] );
3979 normalized->bv_len = 13;
3981 return LDAP_SUCCESS;
3991 return check_time_syntax(in, 1, parts);
3995 generalizedTimeValidate(
4001 return check_time_syntax(in, 0, parts);
4005 generalizedTimeNormalize(
4008 struct berval *normalized )
4012 rc = check_time_syntax(val, 0, parts);
4013 if (rc != LDAP_SUCCESS) {
4017 normalized->bv_val = ch_malloc( 16 );
4018 if ( normalized->bv_val == NULL ) {
4019 return LBER_ERROR_MEMORY;
4022 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4023 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4024 parts[4], parts[5], parts[6] );
4025 normalized->bv_len = 15;
4027 return LDAP_SUCCESS;
4031 nisNetgroupTripleValidate(
4033 struct berval *val )
4038 if ( val->bv_len == 0 ) {
4039 return LDAP_INVALID_SYNTAX;
4042 p = (char *)val->bv_val;
4043 e = p + val->bv_len;
4045 if ( *p != '(' /*')'*/ ) {
4046 return LDAP_INVALID_SYNTAX;
4049 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4053 return LDAP_INVALID_SYNTAX;
4056 } else if ( !ATTR_CHAR( *p ) ) {
4057 return LDAP_INVALID_SYNTAX;
4061 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4062 return LDAP_INVALID_SYNTAX;
4068 return LDAP_INVALID_SYNTAX;
4071 return LDAP_SUCCESS;
4075 bootParameterValidate(
4077 struct berval *val )
4081 if ( val->bv_len == 0 ) {
4082 return LDAP_INVALID_SYNTAX;
4085 p = (char *)val->bv_val;
4086 e = p + val->bv_len;
4089 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4090 if ( !ATTR_CHAR( *p ) ) {
4091 return LDAP_INVALID_SYNTAX;
4096 return LDAP_INVALID_SYNTAX;
4100 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4101 if ( !ATTR_CHAR( *p ) ) {
4102 return LDAP_INVALID_SYNTAX;
4107 return LDAP_INVALID_SYNTAX;
4111 for ( p++; p < e; p++ ) {
4112 if ( !ATTR_CHAR( *p ) ) {
4113 return LDAP_INVALID_SYNTAX;
4117 return LDAP_SUCCESS;
4120 static struct syntax_defs_rec {
4122 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4123 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4125 slap_syntax_validate_func *sd_validate;
4126 slap_syntax_transform_func *sd_normalize;
4127 slap_syntax_transform_func *sd_pretty;
4128 #ifdef SLAPD_BINARY_CONVERSION
4129 slap_syntax_transform_func *sd_ber2str;
4130 slap_syntax_transform_func *sd_str2ber;
4133 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4134 X_BINARY X_NOT_H_R ")",
4135 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4136 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4137 0, NULL, NULL, NULL},
4138 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4139 0, NULL, NULL, NULL},
4140 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4142 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4145 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4146 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4147 0, bitStringValidate, bitStringNormalize, NULL },
4148 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4149 0, booleanValidate, NULL, NULL},
4150 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4151 X_BINARY X_NOT_H_R ")",
4152 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4154 X_BINARY X_NOT_H_R ")",
4155 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4156 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4157 X_BINARY X_NOT_H_R ")",
4158 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4160 0, countryStringValidate, IA5StringNormalize, NULL},
4161 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4162 0, dnValidate, dnNormalize2, dnPretty2},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4164 0, NULL, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4166 0, NULL, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4168 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4170 0, NULL, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4172 0, NULL, NULL, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4174 0, NULL, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4176 0, NULL, NULL, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4178 0, NULL, NULL, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4180 0, printablesStringValidate, IA5StringNormalize, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4182 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4184 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4185 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4186 0, NULL, NULL, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4188 0, IA5StringValidate, IA5StringNormalize, NULL},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4190 0, integerValidate, integerNormalize, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4192 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4194 0, NULL, NULL, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4196 0, NULL, NULL, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4198 0, NULL, NULL, NULL},
4199 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4200 0, NULL, NULL, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4202 0, NULL, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4204 0, nameUIDValidate, nameUIDNormalize, NULL},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4206 0, NULL, NULL, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4208 0, numericStringValidate, numericStringNormalize, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4210 0, NULL, NULL, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4212 0, oidValidate, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4214 0, IA5StringValidate, IA5StringNormalize, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4216 0, blobValidate, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4218 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4220 0, NULL, NULL, NULL},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4222 0, NULL, NULL, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4224 0, printableStringValidate, IA5StringNormalize, NULL},
4225 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4226 X_BINARY X_NOT_H_R ")",
4227 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4229 X_BINARY X_NOT_H_R ")",
4230 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4232 0, printableStringValidate, IA5StringNormalize, NULL},
4233 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4234 0, NULL, NULL, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4236 0, printablesStringValidate, IA5StringNormalize, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4238 0, utcTimeValidate, utcTimeNormalize, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4240 0, NULL, NULL, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4242 0, NULL, NULL, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4244 0, NULL, NULL, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4246 0, NULL, NULL, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4248 0, NULL, NULL, NULL},
4250 /* RFC 2307 NIS Syntaxes */
4251 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4252 0, nisNetgroupTripleValidate, NULL, NULL},
4253 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4254 0, bootParameterValidate, NULL, NULL},
4258 /* These OIDs are not published yet, but will be in the next
4259 * I-D for PKIX LDAPv3 schema as have been advanced by David
4260 * Chadwick in private mail.
4262 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4263 0, NULL, NULL, NULL},
4266 /* OpenLDAP Experimental Syntaxes */
4267 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4269 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4272 #ifdef SLAPD_AUTHPASSWD
4273 /* needs updating */
4274 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4275 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4278 /* OpenLDAP Void Syntax */
4279 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4280 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4281 {NULL, 0, NULL, NULL, NULL}
4285 * Other matching rules in X.520 that we do not use (yet):
4287 * 2.5.13.9 numericStringOrderingMatch
4288 * 2.5.13.15 integerOrderingMatch
4289 * 2.5.13.18 octetStringOrderingMatch
4290 * 2.5.13.19 octetStringSubstringsMatch
4291 * 2.5.13.25 uTCTimeMatch
4292 * 2.5.13.26 uTCTimeOrderingMatch
4293 * 2.5.13.31 directoryStringFirstComponentMatch
4294 * 2.5.13.32 wordMatch
4295 * 2.5.13.33 keywordMatch
4296 * 2.5.13.35 certificateMatch
4297 * 2.5.13.36 certificatePairExactMatch
4298 * 2.5.13.37 certificatePairMatch
4299 * 2.5.13.38 certificateListExactMatch
4300 * 2.5.13.39 certificateListMatch
4301 * 2.5.13.40 algorithmIdentifierMatch
4302 * 2.5.13.41 storedPrefixMatch
4303 * 2.5.13.42 attributeCertificateMatch
4304 * 2.5.13.43 readerAndKeyIDMatch
4305 * 2.5.13.44 attributeIntegrityMatch
4307 static struct mrule_defs_rec {
4309 slap_mask_t mrd_usage;
4310 slap_mr_convert_func * mrd_convert;
4311 slap_mr_normalize_func * mrd_normalize;
4312 slap_mr_match_func * mrd_match;
4313 slap_mr_indexer_func * mrd_indexer;
4314 slap_mr_filter_func * mrd_filter;
4316 char * mrd_associated;
4319 * EQUALITY matching rules must be listed after associated APPROX
4320 * matching rules. So, we list all APPROX matching rules first.
4322 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4323 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4324 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4326 directoryStringApproxMatch,
4327 directoryStringApproxIndexer,
4328 directoryStringApproxFilter,
4331 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4332 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4333 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4335 IA5StringApproxMatch,
4336 IA5StringApproxIndexer,
4337 IA5StringApproxFilter,
4341 * Other matching rules
4344 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4345 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4346 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4348 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4351 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4352 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4353 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4355 dnMatch, dnIndexer, dnFilter,
4358 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4359 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4360 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4362 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4363 directoryStringApproxMatchOID },
4365 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4366 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4369 caseIgnoreOrderingMatch, NULL, NULL,
4372 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4373 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4374 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4376 caseExactIgnoreSubstringsMatch,
4377 caseExactIgnoreSubstringsIndexer,
4378 caseExactIgnoreSubstringsFilter,
4381 {"( 2.5.13.5 NAME 'caseExactMatch' "
4382 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4383 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4385 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4386 directoryStringApproxMatchOID },
4388 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4389 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4392 caseExactOrderingMatch, NULL, NULL,
4395 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4396 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4397 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4399 caseExactIgnoreSubstringsMatch,
4400 caseExactIgnoreSubstringsIndexer,
4401 caseExactIgnoreSubstringsFilter,
4404 {"( 2.5.13.8 NAME 'numericStringMatch' "
4405 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4406 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4409 caseIgnoreIA5Indexer,
4410 caseIgnoreIA5Filter,
4413 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4414 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4415 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4417 caseIgnoreIA5SubstringsMatch,
4418 caseIgnoreIA5SubstringsIndexer,
4419 caseIgnoreIA5SubstringsFilter,
4422 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4423 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4424 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4426 caseIgnoreListMatch, NULL, NULL,
4429 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4430 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4431 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4433 caseIgnoreListSubstringsMatch, NULL, NULL,
4436 {"( 2.5.13.13 NAME 'booleanMatch' "
4437 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4438 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4440 booleanMatch, NULL, NULL,
4443 {"( 2.5.13.14 NAME 'integerMatch' "
4444 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4445 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4447 integerMatch, integerIndexer, integerFilter,
4450 {"( 2.5.13.16 NAME 'bitStringMatch' "
4451 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4452 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4454 bitStringMatch, bitStringIndexer, bitStringFilter,
4457 {"( 2.5.13.17 NAME 'octetStringMatch' "
4458 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4459 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4461 octetStringMatch, octetStringIndexer, octetStringFilter,
4464 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4465 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4466 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4468 telephoneNumberMatch,
4469 telephoneNumberIndexer,
4470 telephoneNumberFilter,
4473 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4474 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4475 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4477 telephoneNumberSubstringsMatch,
4478 telephoneNumberSubstringsIndexer,
4479 telephoneNumberSubstringsFilter,
4482 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4483 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4484 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4489 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4490 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4491 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4493 uniqueMemberMatch, NULL, NULL,
4496 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4497 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4498 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4500 protocolInformationMatch, NULL, NULL,
4503 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4504 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4505 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4507 generalizedTimeMatch, NULL, NULL,
4510 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4511 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4514 generalizedTimeOrderingMatch, NULL, NULL,
4517 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4518 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4519 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4521 integerFirstComponentMatch, NULL, NULL,
4524 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4525 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4526 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4528 objectIdentifierFirstComponentMatch, NULL, NULL,
4532 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4533 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4534 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4535 certificateExactConvert, NULL,
4536 certificateExactMatch,
4537 certificateExactIndexer, certificateExactFilter,
4541 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4542 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4543 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4545 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4546 IA5StringApproxMatchOID },
4548 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4549 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4550 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4552 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4553 IA5StringApproxMatchOID },
4555 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4556 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4559 caseIgnoreIA5SubstringsMatch,
4560 caseIgnoreIA5SubstringsIndexer,
4561 caseIgnoreIA5SubstringsFilter,
4564 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4565 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4568 caseExactIA5SubstringsMatch,
4569 caseExactIA5SubstringsIndexer,
4570 caseExactIA5SubstringsFilter,
4573 #ifdef SLAPD_AUTHPASSWD
4574 /* needs updating */
4575 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4576 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4579 authPasswordMatch, NULL, NULL,
4583 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4584 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4587 OpenLDAPaciMatch, NULL, NULL,
4590 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4591 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4594 integerBitAndMatch, NULL, NULL,
4597 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4598 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4601 integerBitOrMatch, NULL, NULL,
4604 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4608 slap_schema_init( void )
4613 /* we should only be called once (from main) */
4614 assert( schema_init_done == 0 );
4616 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4617 res = register_syntax( syntax_defs[i].sd_desc,
4618 syntax_defs[i].sd_flags,
4619 syntax_defs[i].sd_validate,
4620 syntax_defs[i].sd_normalize,
4621 syntax_defs[i].sd_pretty
4622 #ifdef SLAPD_BINARY_CONVERSION
4624 syntax_defs[i].sd_ber2str,
4625 syntax_defs[i].sd_str2ber
4630 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4631 syntax_defs[i].sd_desc );
4636 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4637 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4639 "slap_schema_init: Ingoring unusable matching rule %s\n",
4640 mrule_defs[i].mrd_desc );
4644 res = register_matching_rule(
4645 mrule_defs[i].mrd_desc,
4646 mrule_defs[i].mrd_usage,
4647 mrule_defs[i].mrd_convert,
4648 mrule_defs[i].mrd_normalize,
4649 mrule_defs[i].mrd_match,
4650 mrule_defs[i].mrd_indexer,
4651 mrule_defs[i].mrd_filter,
4652 mrule_defs[i].mrd_associated );
4656 "slap_schema_init: Error registering matching rule %s\n",
4657 mrule_defs[i].mrd_desc );
4662 res = slap_schema_load();
4663 schema_init_done = 1;
4668 schema_destroy( void )