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>
22 #include "ldap_utf8.h"
24 #include "lutil_hash.h"
25 #define HASH_BYTES LUTIL_HASH_BYTES
26 #define HASH_CONTEXT lutil_HASH_CTX
27 #define HASH_Init(c) lutil_HASHInit(c)
28 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
29 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
31 /* recycled validatation routines */
32 #define berValidate blobValidate
34 /* unimplemented pretters */
35 #define integerPretty NULL
37 /* recycled matching routines */
38 #define bitStringMatch octetStringMatch
39 #define numericStringMatch caseIgnoreIA5Match
40 #define objectIdentifierMatch caseIgnoreIA5Match
41 #define telephoneNumberMatch caseIgnoreIA5Match
42 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
43 #define generalizedTimeMatch caseIgnoreIA5Match
44 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
45 #define uniqueMemberMatch dnMatch
47 /* approx matching rules */
48 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
49 #define directoryStringApproxMatch approxMatch
50 #define directoryStringApproxIndexer approxIndexer
51 #define directoryStringApproxFilter approxFilter
52 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
53 #define IA5StringApproxMatch approxMatch
54 #define IA5StringApproxIndexer approxIndexer
55 #define IA5StringApproxFilter approxFilter
57 /* orderring matching rules */
58 #define caseIgnoreOrderingMatch caseIgnoreMatch
59 #define caseExactOrderingMatch caseExactMatch
61 /* unimplemented matching routines */
62 #define caseIgnoreListMatch NULL
63 #define caseIgnoreListSubstringsMatch NULL
64 #define protocolInformationMatch NULL
65 #define integerFirstComponentMatch NULL
67 #ifdef SLAPD_ACI_ENABLED
68 #define OpenLDAPaciMatch NULL
70 #ifdef SLAPD_AUTHPASSWD
71 #define authPasswordMatch NULL
74 /* recycled indexing/filtering routines */
75 #define dnIndexer caseExactIgnoreIndexer
76 #define dnFilter caseExactIgnoreFilter
77 #define bitStringFilter octetStringFilter
78 #define bitStringIndexer octetStringIndexer
80 #define telephoneNumberIndexer caseIgnoreIA5Indexer
81 #define telephoneNumberFilter caseIgnoreIA5Filter
82 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
83 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
85 /* must match OIDs below */
86 #define caseExactMatchOID "2.5.13.5"
87 #define caseExactSubstringsMatchOID "2.5.13.7"
89 static char *bvcasechr( struct berval *bv, int c, ber_len_t *len )
92 int lower = TOLOWER( c );
93 int upper = TOUPPER( c );
95 if( c == 0 ) return NULL;
97 for( i=0; i < bv->bv_len; i++ ) {
98 if( upper == bv->bv_val[i] || lower == bv->bv_val[i] ) {
100 return &bv->bv_val[i];
113 struct berval *value,
114 void *assertedValue )
116 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
119 match = memcmp( value->bv_val,
120 ((struct berval *) assertedValue)->bv_val,
128 /* Index generation function */
129 static int octetStringIndexer(
134 struct berval *prefix,
141 HASH_CONTEXT HASHcontext;
142 unsigned char HASHdigest[HASH_BYTES];
143 struct berval digest;
144 digest.bv_val = HASHdigest;
145 digest.bv_len = sizeof(HASHdigest);
147 for( i=0; values[i].bv_val != NULL; i++ ) {
148 /* just count them */
151 /* we should have at least one value at this point */
154 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
156 slen = syntax->ssyn_oidlen;
157 mlen = mr->smr_oidlen;
159 for( i=0; values[i].bv_val != NULL; i++ ) {
160 HASH_Init( &HASHcontext );
161 if( prefix != NULL && prefix->bv_len > 0 ) {
162 HASH_Update( &HASHcontext,
163 prefix->bv_val, prefix->bv_len );
165 HASH_Update( &HASHcontext,
166 syntax->ssyn_oid, slen );
167 HASH_Update( &HASHcontext,
169 HASH_Update( &HASHcontext,
170 values[i].bv_val, values[i].bv_len );
171 HASH_Final( HASHdigest, &HASHcontext );
173 ber_dupbv( &keys[i], &digest );
176 keys[i].bv_val = NULL;
183 /* Index generation function */
184 static int octetStringFilter(
189 struct berval *prefix,
195 HASH_CONTEXT HASHcontext;
196 unsigned char HASHdigest[HASH_BYTES];
197 struct berval *value = (struct berval *) assertValue;
198 struct berval digest;
199 digest.bv_val = HASHdigest;
200 digest.bv_len = sizeof(HASHdigest);
202 slen = syntax->ssyn_oidlen;
203 mlen = mr->smr_oidlen;
205 keys = ch_malloc( sizeof( struct berval ) * 2 );
207 HASH_Init( &HASHcontext );
208 if( prefix != NULL && prefix->bv_len > 0 ) {
209 HASH_Update( &HASHcontext,
210 prefix->bv_val, prefix->bv_len );
212 HASH_Update( &HASHcontext,
213 syntax->ssyn_oid, slen );
214 HASH_Update( &HASHcontext,
216 HASH_Update( &HASHcontext,
217 value->bv_val, value->bv_len );
218 HASH_Final( HASHdigest, &HASHcontext );
220 ber_dupbv( keys, &digest );
221 keys[1].bv_val = NULL;
236 if( in->bv_len == 0 ) return LDAP_SUCCESS;
238 ber_dupbv( &dn, in );
239 if( !dn.bv_val ) return LDAP_OTHER;
241 if( dn.bv_val[dn.bv_len-1] == 'B'
242 && dn.bv_val[dn.bv_len-2] == '\'' )
244 /* assume presence of optional UID */
247 for(i=dn.bv_len-3; i>1; i--) {
248 if( dn.bv_val[i] != '0' && dn.bv_val[i] != '1' ) {
252 if( dn.bv_val[i] != '\'' ||
253 dn.bv_val[i-1] != '#' ) {
254 ber_memfree( dn.bv_val );
255 return LDAP_INVALID_SYNTAX;
258 /* trim the UID to allow use of dnValidate */
259 dn.bv_val[i-1] = '\0';
263 rc = dnValidate( NULL, &dn );
273 struct berval *normalized )
278 ber_dupbv( &out, val );
279 if( out.bv_len != 0 ) {
282 ber_len_t uidlen = 0;
284 if( out.bv_val[out.bv_len-1] == '\'' ) {
285 /* assume presence of optional UID */
286 uid = strrchr( out.bv_val, '#' );
290 return LDAP_INVALID_SYNTAX;
293 uidlen = out.bv_len - (uid - out.bv_val);
294 /* temporarily trim the UID */
296 out.bv_len -= uidlen;
299 #ifdef USE_DN_NORMALIZE
300 rc = dnNormalize2( NULL, &out, normalized );
302 rc = dnPretty2( NULL, &out, normalized );
305 if( rc != LDAP_SUCCESS ) {
307 return LDAP_INVALID_SYNTAX;
310 dnlen = normalized->bv_len;
314 b2.bv_val = ch_malloc(dnlen + uidlen + 1);
315 AC_MEMCPY( b2.bv_val, normalized->bv_val, dnlen );
317 /* restore the separator */
320 AC_MEMCPY( normalized->bv_val+dnlen, uid, uidlen );
321 b2.bv_len = dnlen + uidlen;
322 normalized->bv_val[dnlen+uidlen] = '\0';
323 free(normalized->bv_val);
337 /* any value allowed */
346 /* any value allowed */
357 /* very unforgiving validation, requires no normalization
358 * before simplistic matching
360 if( in->bv_len < 3 ) {
361 return LDAP_INVALID_SYNTAX;
365 * rfc 2252 section 6.3 Bit String
366 * bitstring = "'" *binary-digit "'"
367 * binary-digit = "0" / "1"
368 * example: '0101111101'B
371 if( in->bv_val[0] != '\'' ||
372 in->bv_val[in->bv_len-2] != '\'' ||
373 in->bv_val[in->bv_len-1] != 'B' )
375 return LDAP_INVALID_SYNTAX;
378 for( i=in->bv_len-3; i>0; i-- ) {
379 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
380 return LDAP_INVALID_SYNTAX;
391 struct berval *normalized )
394 * A normalized bitString is has no extaneous (leading) zero bits.
395 * That is, '00010'B is normalized to '10'B
396 * However, as a special case, '0'B requires no normalization.
400 /* start at the first bit */
403 /* Find the first non-zero bit */
404 while ( *p == '0' ) p++;
407 /* no non-zero bits */
408 ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
412 normalized->bv_val = ch_malloc( val->bv_len + 1 );
414 normalized->bv_val[0] = '\'';
415 normalized->bv_len = 1;
417 for( ; *p != '\0'; p++ ) {
418 normalized->bv_val[normalized->bv_len++] = *p;
421 normalized->bv_val[normalized->bv_len] = '\0';
428 * Handling boolean syntax and matching is quite rigid.
429 * A more flexible approach would be to allow a variety
430 * of strings to be normalized and prettied into TRUE
438 /* very unforgiving validation, requires no normalization
439 * before simplistic matching
442 if( in->bv_len == 4 ) {
443 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
446 } else if( in->bv_len == 5 ) {
447 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
452 return LDAP_INVALID_SYNTAX;
461 struct berval *value,
462 void *assertedValue )
464 /* simplistic matching allowed by rigid validation */
465 struct berval *asserted = (struct berval *) assertedValue;
466 *matchp = value->bv_len != asserted->bv_len;
477 unsigned char *u = in->bv_val;
479 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
481 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
482 /* get the length indicated by the first byte */
483 len = LDAP_UTF8_CHARLEN2( u, len );
485 /* very basic checks */
488 if( (u[5] & 0xC0) != 0x80 ) {
489 return LDAP_INVALID_SYNTAX;
492 if( (u[4] & 0xC0) != 0x80 ) {
493 return LDAP_INVALID_SYNTAX;
496 if( (u[3] & 0xC0) != 0x80 ) {
497 return LDAP_INVALID_SYNTAX;
500 if( (u[2] & 0xC0 )!= 0x80 ) {
501 return LDAP_INVALID_SYNTAX;
504 if( (u[1] & 0xC0) != 0x80 ) {
505 return LDAP_INVALID_SYNTAX;
508 /* CHARLEN already validated it */
511 return LDAP_INVALID_SYNTAX;
514 /* make sure len corresponds with the offset
515 to the next character */
516 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
519 if( count != 0 ) return LDAP_INVALID_SYNTAX;
528 struct berval *normalized )
535 /* Ignore initial whitespace */
536 /* All space is ASCII. All ASCII is 1 byte */
537 for ( ; p < val->bv_val + val->bv_len && ASCII_SPACE( p[ 0 ] ); p++ );
539 ber_mem2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
540 e = normalized->bv_val + val->bv_len - (p - val->bv_val);
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 UTF8bvnormalize( &sa->sa_initial, &nsa->sa_initial, casefold );
612 if( nsa->sa_initial.bv_val == NULL ) {
617 if( sa->sa_any != NULL ) {
618 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
621 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
622 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
623 UTF8bvnormalize( &sa->sa_any[i], &nsa->sa_any[i],
625 if( nsa->sa_any[i].bv_val == NULL ) {
629 nsa->sa_any[i].bv_val = NULL;
632 if( sa->sa_final.bv_val != NULL ) {
633 UTF8bvnormalize( &sa->sa_final, &nsa->sa_final, casefold );
634 if( nsa->sa_final.bv_val == NULL ) {
642 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
643 if ( nsa->sa_any )ber_bvarray_free( nsa->sa_any );
644 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
649 /* Strip characters with the 8th bit set */
662 while( *++q & 0x80 ) {
665 p = AC_MEMCPY(p, q, strlen(q) + 1);
673 #ifndef SLAPD_APPROX_OLDSINGLESTRING
675 #if defined(SLAPD_APPROX_INITIALS)
676 #define SLAPD_APPROX_DELIMITER "._ "
677 #define SLAPD_APPROX_WORDLEN 2
679 #define SLAPD_APPROX_DELIMITER " "
680 #define SLAPD_APPROX_WORDLEN 1
689 struct berval *value,
690 void *assertedValue )
692 char *val, *nval, *assertv, **values, **words, *c;
693 int i, count, len, nextchunk=0, nextavail=0;
696 /* Yes, this is necessary */
697 nval = UTF8normalize( value, LDAP_UTF8_NOCASEFOLD );
702 strip8bitChars( nval );
704 /* Yes, this is necessary */
705 assertv = UTF8normalize( ((struct berval *)assertedValue),
706 LDAP_UTF8_NOCASEFOLD );
707 if( assertv == NULL ) {
712 strip8bitChars( assertv );
713 avlen = strlen( assertv );
715 /* Isolate how many words there are */
716 for( c=nval,count=1; *c; c++ ) {
717 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
718 if ( c == NULL ) break;
723 /* Get a phonetic copy of each word */
724 words = (char **)ch_malloc( count * sizeof(char *) );
725 values = (char **)ch_malloc( count * sizeof(char *) );
726 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
728 values[i] = phonetic(c);
731 /* Work through the asserted value's words, to see if at least some
732 of the words are there, in the same order. */
734 while ( (size_t) nextchunk < avlen ) {
735 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
740 #if defined(SLAPD_APPROX_INITIALS)
741 else if( len == 1 ) {
742 /* Single letter words need to at least match one word's initial */
743 for( i=nextavail; i<count; i++ )
744 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
751 /* Isolate the next word in the asserted value and phonetic it */
752 assertv[nextchunk+len] = '\0';
753 val = phonetic( assertv + nextchunk );
755 /* See if this phonetic chunk is in the remaining words of *value */
756 for( i=nextavail; i<count; i++ ){
757 if( !strcmp( val, values[i] ) ){
765 /* This chunk in the asserted value was NOT within the *value. */
771 /* Go on to the next word in the asserted value */
775 /* If some of the words were seen, call it a match */
776 if( nextavail > 0 ) {
785 for( i=0; i<count; i++ ) {
786 ch_free( values[i] );
801 struct berval *prefix,
806 int i,j, len, wordcount, keycount=0;
807 struct berval *newkeys;
810 for( j=0; values[j].bv_val != NULL; j++ ) {
811 /* Yes, this is necessary */
812 val = UTF8normalize( &values[j], LDAP_UTF8_NOCASEFOLD );
813 strip8bitChars( val );
815 /* Isolate how many words there are. There will be a key for each */
816 for( wordcount=0,c=val; *c; c++) {
817 len = strcspn(c, SLAPD_APPROX_DELIMITER);
818 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
820 if (*c == '\0') break;
824 /* Allocate/increase storage to account for new keys */
825 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
826 * sizeof(struct berval) );
827 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
828 if( keys ) ch_free( keys );
831 /* Get a phonetic copy of each word */
832 for( c=val,i=0; i<wordcount; c+=len+1 ) {
834 if( len < SLAPD_APPROX_WORDLEN ) continue;
835 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
842 keys[keycount].bv_val = NULL;
854 struct berval *prefix,
862 /* Yes, this is necessary */
863 val = UTF8normalize( ((struct berval *)assertValue),
864 LDAP_UTF8_NOCASEFOLD );
866 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
867 keys[0].bv_val = NULL;
871 strip8bitChars( val );
873 /* Isolate how many words there are. There will be a key for each */
874 for( count=0,c=val; *c; c++) {
875 len = strcspn(c, SLAPD_APPROX_DELIMITER);
876 if( len >= SLAPD_APPROX_WORDLEN ) count++;
878 if (*c == '\0') break;
882 /* Allocate storage for new keys */
883 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
885 /* Get a phonetic copy of each word */
886 for( c=val,i=0; i<count; c+=len+1 ) {
888 if( len < SLAPD_APPROX_WORDLEN ) continue;
889 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
895 keys[count].bv_val = NULL;
903 /* No other form of Approximate Matching is defined */
911 struct berval *value,
912 void *assertedValue )
914 char *vapprox, *avapprox;
917 /* Yes, this is necessary */
918 s = UTF8normalize( value, UTF8_NOCASEFOLD );
924 /* Yes, this is necessary */
925 t = UTF8normalize( ((struct berval *)assertedValue),
933 vapprox = phonetic( strip8bitChars( s ) );
934 avapprox = phonetic( strip8bitChars( t ) );
939 *matchp = strcmp( vapprox, avapprox );
953 struct berval *prefix,
961 for( i=0; values[i].bv_val != NULL; i++ ) {
962 /* empty - just count them */
965 /* we should have at least one value at this point */
968 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
970 /* Copy each value and run it through phonetic() */
971 for( i=0; values[i].bv_val != NULL; i++ ) {
972 /* Yes, this is necessary */
973 s = UTF8normalize( &values[i], UTF8_NOCASEFOLD );
975 /* strip 8-bit chars and run through phonetic() */
976 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
979 keys[i].bv_val = NULL;
992 struct berval *prefix,
999 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
1001 /* Yes, this is necessary */
1002 s = UTF8normalize( ((struct berval *)assertValue),
1007 /* strip 8-bit chars and run through phonetic() */
1008 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1014 return LDAP_SUCCESS;
1025 struct berval *value,
1026 void *assertedValue )
1028 *matchp = UTF8normcmp( value->bv_val,
1029 ((struct berval *) assertedValue)->bv_val,
1030 LDAP_UTF8_NOCASEFOLD );
1031 return LDAP_SUCCESS;
1035 caseExactIgnoreSubstringsMatch(
1040 struct berval *value,
1041 void *assertedValue )
1044 SubstringsAssertion *sub = NULL;
1045 struct berval left = { 0, NULL };
1051 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1052 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1054 if ( UTF8bvnormalize( value, &left, casefold ) == NULL ) {
1060 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1066 /* Add up asserted input length */
1067 if( sub->sa_initial.bv_val ) {
1068 inlen += sub->sa_initial.bv_len;
1071 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1072 inlen += sub->sa_any[i].bv_len;
1075 if( sub->sa_final.bv_val ) {
1076 inlen += sub->sa_final.bv_len;
1079 if( sub->sa_initial.bv_val ) {
1080 if( inlen > left.bv_len ) {
1085 match = memcmp( sub->sa_initial.bv_val, left.bv_val,
1086 sub->sa_initial.bv_len );
1092 left.bv_val += sub->sa_initial.bv_len;
1093 left.bv_len -= sub->sa_initial.bv_len;
1094 inlen -= sub->sa_initial.bv_len;
1097 if( sub->sa_final.bv_val ) {
1098 if( inlen > left.bv_len ) {
1103 match = memcmp( sub->sa_final.bv_val,
1104 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1105 sub->sa_final.bv_len );
1111 left.bv_len -= sub->sa_final.bv_len;
1112 inlen -= sub->sa_final.bv_len;
1116 for(i=0; sub->sa_any[i].bv_val; i++) {
1121 if( inlen > left.bv_len ) {
1122 /* not enough length */
1127 if( sub->sa_any[i].bv_len == 0 ) {
1131 p = ber_bvchr( &left, *sub->sa_any[i].bv_val );
1137 idx = p - left.bv_val;
1139 if( idx >= left.bv_len ) {
1140 /* this shouldn't happen */
1142 if ( sub->sa_final.bv_val )
1143 ch_free( sub->sa_final.bv_val );
1145 ber_bvarray_free( sub->sa_any );
1146 if ( sub->sa_initial.bv_val )
1147 ch_free( sub->sa_initial.bv_val );
1155 if( sub->sa_any[i].bv_len > left.bv_len ) {
1156 /* not enough left */
1161 match = memcmp( left.bv_val,
1162 sub->sa_any[i].bv_val,
1163 sub->sa_any[i].bv_len );
1171 left.bv_val += sub->sa_any[i].bv_len;
1172 left.bv_len -= sub->sa_any[i].bv_len;
1173 inlen -= sub->sa_any[i].bv_len;
1180 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1181 if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
1182 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1186 return LDAP_SUCCESS;
1189 /* Index generation function */
1190 static int caseExactIgnoreIndexer(
1195 struct berval *prefix,
1203 HASH_CONTEXT HASHcontext;
1204 unsigned char HASHdigest[HASH_BYTES];
1205 struct berval digest;
1206 digest.bv_val = HASHdigest;
1207 digest.bv_len = sizeof(HASHdigest);
1209 for( i=0; values[i].bv_val != NULL; i++ ) {
1210 /* empty - just count them */
1213 /* we should have at least one value at this point */
1216 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1218 slen = syntax->ssyn_oidlen;
1219 mlen = mr->smr_oidlen;
1221 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1222 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1224 for( i=0; values[i].bv_val != NULL; i++ ) {
1225 struct berval value;
1226 ber_str2bv( UTF8normalize( &values[i], casefold ), 0, 0,
1229 HASH_Init( &HASHcontext );
1230 if( prefix != NULL && prefix->bv_len > 0 ) {
1231 HASH_Update( &HASHcontext,
1232 prefix->bv_val, prefix->bv_len );
1234 HASH_Update( &HASHcontext,
1235 syntax->ssyn_oid, slen );
1236 HASH_Update( &HASHcontext,
1237 mr->smr_oid, mlen );
1238 HASH_Update( &HASHcontext,
1239 value.bv_val, value.bv_len );
1240 HASH_Final( HASHdigest, &HASHcontext );
1242 free( value.bv_val );
1244 ber_dupbv( &keys[i], &digest );
1247 keys[i].bv_val = NULL;
1249 return LDAP_SUCCESS;
1252 /* Index generation function */
1253 static int caseExactIgnoreFilter(
1258 struct berval *prefix,
1265 HASH_CONTEXT HASHcontext;
1266 unsigned char HASHdigest[HASH_BYTES];
1267 struct berval value;
1268 struct berval digest;
1269 digest.bv_val = HASHdigest;
1270 digest.bv_len = sizeof(HASHdigest);
1272 slen = syntax->ssyn_oidlen;
1273 mlen = mr->smr_oidlen;
1275 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1276 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1278 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1280 /* This usually happens if filter contains bad UTF8 */
1281 if( value.bv_val == NULL ) {
1282 keys = ch_malloc( sizeof( struct berval ) );
1283 keys[0].bv_val = NULL;
1284 return LDAP_SUCCESS;
1287 keys = ch_malloc( sizeof( struct berval ) * 2 );
1289 HASH_Init( &HASHcontext );
1290 if( prefix != NULL && prefix->bv_len > 0 ) {
1291 HASH_Update( &HASHcontext,
1292 prefix->bv_val, prefix->bv_len );
1294 HASH_Update( &HASHcontext,
1295 syntax->ssyn_oid, slen );
1296 HASH_Update( &HASHcontext,
1297 mr->smr_oid, mlen );
1298 HASH_Update( &HASHcontext,
1299 value.bv_val, value.bv_len );
1300 HASH_Final( HASHdigest, &HASHcontext );
1302 ber_dupbv( keys, &digest );
1303 keys[1].bv_val = NULL;
1305 free( value.bv_val );
1308 return LDAP_SUCCESS;
1311 /* Substrings Index generation function */
1312 static int caseExactIgnoreSubstringsIndexer(
1317 struct berval *prefix,
1327 HASH_CONTEXT HASHcontext;
1328 unsigned char HASHdigest[HASH_BYTES];
1329 struct berval digest;
1330 digest.bv_val = HASHdigest;
1331 digest.bv_len = sizeof(HASHdigest);
1335 for( i=0; values[i].bv_val != NULL; i++ ) {
1336 /* empty - just count them */
1339 /* we should have at least one value at this point */
1342 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1343 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1345 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1346 for( i=0; values[i].bv_val != NULL; i++ ) {
1347 ber_str2bv( UTF8normalize( &values[i], casefold ),
1348 0, 0, &nvalues[i] );
1350 nvalues[i].bv_val = NULL;
1353 for( i=0; values[i].bv_val != NULL; i++ ) {
1354 /* count number of indices to generate */
1355 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1359 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1360 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1361 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1362 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1364 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1368 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1369 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1370 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1374 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1375 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1376 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1377 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1379 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1385 /* no keys to generate */
1387 ber_bvarray_free( nvalues );
1388 return LDAP_SUCCESS;
1391 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1393 slen = syntax->ssyn_oidlen;
1394 mlen = mr->smr_oidlen;
1397 for( i=0; values[i].bv_val != NULL; i++ ) {
1400 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1402 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1403 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1405 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1406 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1408 for( j=0; j<max; j++ ) {
1409 HASH_Init( &HASHcontext );
1410 if( prefix != NULL && prefix->bv_len > 0 ) {
1411 HASH_Update( &HASHcontext,
1412 prefix->bv_val, prefix->bv_len );
1415 HASH_Update( &HASHcontext,
1416 &pre, sizeof( pre ) );
1417 HASH_Update( &HASHcontext,
1418 syntax->ssyn_oid, slen );
1419 HASH_Update( &HASHcontext,
1420 mr->smr_oid, mlen );
1421 HASH_Update( &HASHcontext,
1422 &values[i].bv_val[j],
1423 SLAP_INDEX_SUBSTR_MAXLEN );
1424 HASH_Final( HASHdigest, &HASHcontext );
1426 ber_dupbv( &keys[nkeys++], &digest );
1430 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1431 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1433 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1436 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1437 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1438 HASH_Init( &HASHcontext );
1439 if( prefix != NULL && prefix->bv_len > 0 ) {
1440 HASH_Update( &HASHcontext,
1441 prefix->bv_val, prefix->bv_len );
1443 HASH_Update( &HASHcontext,
1444 &pre, sizeof( pre ) );
1445 HASH_Update( &HASHcontext,
1446 syntax->ssyn_oid, slen );
1447 HASH_Update( &HASHcontext,
1448 mr->smr_oid, mlen );
1449 HASH_Update( &HASHcontext,
1450 values[i].bv_val, j );
1451 HASH_Final( HASHdigest, &HASHcontext );
1453 ber_dupbv( &keys[nkeys++], &digest );
1456 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1457 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1458 HASH_Init( &HASHcontext );
1459 if( prefix != NULL && prefix->bv_len > 0 ) {
1460 HASH_Update( &HASHcontext,
1461 prefix->bv_val, prefix->bv_len );
1463 HASH_Update( &HASHcontext,
1464 &pre, sizeof( pre ) );
1465 HASH_Update( &HASHcontext,
1466 syntax->ssyn_oid, slen );
1467 HASH_Update( &HASHcontext,
1468 mr->smr_oid, mlen );
1469 HASH_Update( &HASHcontext,
1470 &values[i].bv_val[values[i].bv_len-j], j );
1471 HASH_Final( HASHdigest, &HASHcontext );
1473 ber_dupbv( &keys[nkeys++], &digest );
1481 keys[nkeys].bv_val = NULL;
1488 ber_bvarray_free( nvalues );
1490 return LDAP_SUCCESS;
1493 static int caseExactIgnoreSubstringsFilter(
1498 struct berval *prefix,
1502 SubstringsAssertion *sa;
1505 ber_len_t nkeys = 0;
1506 size_t slen, mlen, klen;
1508 HASH_CONTEXT HASHcontext;
1509 unsigned char HASHdigest[HASH_BYTES];
1510 struct berval *value;
1511 struct berval digest;
1513 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1514 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1516 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1519 return LDAP_SUCCESS;
1522 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1523 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1528 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1530 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1531 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1532 /* don't bother accounting for stepping */
1533 nkeys += sa->sa_any[i].bv_len -
1534 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1539 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1540 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1546 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1547 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1548 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1551 return LDAP_SUCCESS;
1554 digest.bv_val = HASHdigest;
1555 digest.bv_len = sizeof(HASHdigest);
1557 slen = syntax->ssyn_oidlen;
1558 mlen = mr->smr_oidlen;
1560 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1563 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1564 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1566 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1567 value = &sa->sa_initial;
1569 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1570 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1572 HASH_Init( &HASHcontext );
1573 if( prefix != NULL && prefix->bv_len > 0 ) {
1574 HASH_Update( &HASHcontext,
1575 prefix->bv_val, prefix->bv_len );
1577 HASH_Update( &HASHcontext,
1578 &pre, sizeof( pre ) );
1579 HASH_Update( &HASHcontext,
1580 syntax->ssyn_oid, slen );
1581 HASH_Update( &HASHcontext,
1582 mr->smr_oid, mlen );
1583 HASH_Update( &HASHcontext,
1584 value->bv_val, klen );
1585 HASH_Final( HASHdigest, &HASHcontext );
1587 ber_dupbv( &keys[nkeys++], &digest );
1590 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1592 pre = SLAP_INDEX_SUBSTR_PREFIX;
1593 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1595 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1596 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1600 value = &sa->sa_any[i];
1603 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1604 j += SLAP_INDEX_SUBSTR_STEP )
1606 HASH_Init( &HASHcontext );
1607 if( prefix != NULL && prefix->bv_len > 0 ) {
1608 HASH_Update( &HASHcontext,
1609 prefix->bv_val, prefix->bv_len );
1611 HASH_Update( &HASHcontext,
1612 &pre, sizeof( pre ) );
1613 HASH_Update( &HASHcontext,
1614 syntax->ssyn_oid, slen );
1615 HASH_Update( &HASHcontext,
1616 mr->smr_oid, mlen );
1617 HASH_Update( &HASHcontext,
1618 &value->bv_val[j], klen );
1619 HASH_Final( HASHdigest, &HASHcontext );
1621 ber_dupbv( &keys[nkeys++], &digest );
1627 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1628 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1630 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1631 value = &sa->sa_final;
1633 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1634 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1636 HASH_Init( &HASHcontext );
1637 if( prefix != NULL && prefix->bv_len > 0 ) {
1638 HASH_Update( &HASHcontext,
1639 prefix->bv_val, prefix->bv_len );
1641 HASH_Update( &HASHcontext,
1642 &pre, sizeof( pre ) );
1643 HASH_Update( &HASHcontext,
1644 syntax->ssyn_oid, slen );
1645 HASH_Update( &HASHcontext,
1646 mr->smr_oid, mlen );
1647 HASH_Update( &HASHcontext,
1648 &value->bv_val[value->bv_len-klen], klen );
1649 HASH_Final( HASHdigest, &HASHcontext );
1651 ber_dupbv( &keys[nkeys++], &digest );
1655 keys[nkeys].bv_val = NULL;
1661 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1662 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1663 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1666 return LDAP_SUCCESS;
1675 struct berval *value,
1676 void *assertedValue )
1678 *matchp = UTF8normcmp( value->bv_val,
1679 ((struct berval *) assertedValue)->bv_val,
1680 LDAP_UTF8_CASEFOLD );
1681 return LDAP_SUCCESS;
1687 struct berval *val )
1691 if( val->bv_len == 0 ) {
1692 /* disallow empty strings */
1693 return LDAP_INVALID_SYNTAX;
1696 if( OID_LEADCHAR(val->bv_val[0]) ) {
1698 for(i=1; i < val->bv_len; i++) {
1699 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1700 if( dot++ ) return 1;
1701 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1704 return LDAP_INVALID_SYNTAX;
1708 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1710 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1711 for(i=1; i < val->bv_len; i++) {
1712 if( !DESC_CHAR(val->bv_val[i] ) ) {
1713 return LDAP_INVALID_SYNTAX;
1717 return LDAP_SUCCESS;
1720 return LDAP_INVALID_SYNTAX;
1729 struct berval *value,
1730 void *assertedValue )
1733 int vsign=0, avsign=0;
1734 struct berval *asserted;
1735 ber_len_t vlen, avlen;
1738 /* Start off pessimistic */
1741 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1743 vlen = value->bv_len;
1745 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1746 /* empty -- skip spaces */
1748 else if ( *v == '+' ) {
1751 else if ( *v == '-' ) {
1754 else if ( ASCII_DIGIT(*v) ) {
1755 if ( vsign == 0 ) vsign = 1;
1763 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1765 asserted = (struct berval *) assertedValue;
1766 av = asserted->bv_val;
1767 avlen = asserted->bv_len;
1769 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1770 /* empty -- skip spaces */
1772 else if ( *av == '+' ) {
1775 else if ( *av == '-' ) {
1778 else if ( ASCII_DIGIT(*av) ) {
1779 if ( avsign == 0 ) avsign = 1;
1787 /* The two ?sign vars are now one of :
1788 -2 negative non-zero number
1790 0 0 collapse these three to 0
1792 +2 positive non-zero number
1794 if ( abs( vsign ) == 1 ) vsign = 0;
1795 if ( abs( avsign ) == 1 ) avsign = 0;
1797 if( vsign != avsign ) return LDAP_SUCCESS;
1799 /* Check the significant digits */
1800 while( vlen && avlen ) {
1801 if( *v != *av ) break;
1808 /* If all digits compared equal, the numbers are equal */
1809 if(( vlen == 0 ) && ( avlen == 0 )) {
1812 return LDAP_SUCCESS;
1818 struct berval *val )
1822 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1824 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1825 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1826 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1827 return LDAP_INVALID_SYNTAX;
1830 for( i=1; i < val->bv_len; i++ ) {
1831 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1834 return LDAP_SUCCESS;
1841 struct berval *normalized )
1851 /* Ignore leading spaces */
1852 while ( len && ( *p == ' ' )) {
1859 negative = ( *p == '-' );
1860 if(( *p == '-' ) || ( *p == '+' )) {
1866 /* Ignore leading zeros */
1867 while ( len && ( *p == '0' )) {
1872 /* If there are no non-zero digits left, the number is zero, otherwise
1873 allocate space for the number and copy it into the buffer */
1875 normalized->bv_val = ch_strdup("0");
1876 normalized->bv_len = 1;
1879 normalized->bv_len = len+negative;
1880 normalized->bv_val = ch_malloc( normalized->bv_len );
1882 normalized->bv_val[0] = '-';
1884 AC_MEMCPY( normalized->bv_val + negative, p, len );
1887 return LDAP_SUCCESS;
1890 /* Index generation function */
1891 static int integerIndexer(
1896 struct berval *prefix,
1903 /* we should have at least one value at this point */
1904 assert( values != NULL && values[0].bv_val != NULL );
1906 for( i=0; values[i].bv_val != NULL; i++ ) {
1907 /* empty -- just count them */
1910 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1912 for( i=0; values[i].bv_val != NULL; i++ ) {
1913 integerNormalize( syntax, &values[i], &keys[i] );
1916 keys[i].bv_val = NULL;
1918 return LDAP_SUCCESS;
1921 /* Index generation function */
1922 static int integerFilter(
1927 struct berval *prefix,
1933 keys = ch_malloc( sizeof( struct berval ) * 2 );
1934 integerNormalize( syntax, assertValue, &keys[0] );
1935 keys[1].bv_val = NULL;
1938 return LDAP_SUCCESS;
1943 countryStringValidate(
1945 struct berval *val )
1947 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1949 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1950 return LDAP_INVALID_SYNTAX;
1952 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1953 return LDAP_INVALID_SYNTAX;
1956 return LDAP_SUCCESS;
1960 printableStringValidate(
1962 struct berval *val )
1966 for(i=0; i < val->bv_len; i++) {
1967 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1968 return LDAP_INVALID_SYNTAX;
1972 return LDAP_SUCCESS;
1976 printablesStringValidate(
1978 struct berval *val )
1982 for(i=0; i < val->bv_len; i++) {
1983 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1984 return LDAP_INVALID_SYNTAX;
1988 return LDAP_SUCCESS;
1994 struct berval *val )
1998 for(i=0; i < val->bv_len; i++) {
1999 if( !LDAP_ASCII(val->bv_val[i]) ) {
2000 return LDAP_INVALID_SYNTAX;
2004 return LDAP_SUCCESS;
2011 struct berval *normalized )
2017 /* Ignore initial whitespace */
2018 while ( ASCII_SPACE( *p ) ) {
2022 normalized->bv_val = ch_strdup( p );
2023 p = q = normalized->bv_val;
2026 if ( ASCII_SPACE( *p ) ) {
2029 /* Ignore the extra whitespace */
2030 while ( ASCII_SPACE( *p ) ) {
2038 assert( normalized->bv_val <= p );
2042 * If the string ended in space, backup the pointer one
2043 * position. One is enough because the above loop collapsed
2044 * all whitespace to a single space.
2047 if ( ASCII_SPACE( q[-1] ) ) {
2051 /* null terminate */
2054 normalized->bv_len = q - normalized->bv_val;
2056 return LDAP_SUCCESS;
2065 struct berval *value,
2066 void *assertedValue )
2068 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2071 match = strncmp( value->bv_val,
2072 ((struct berval *) assertedValue)->bv_val,
2077 return LDAP_SUCCESS;
2081 caseExactIA5SubstringsMatch(
2086 struct berval *value,
2087 void *assertedValue )
2090 SubstringsAssertion *sub = assertedValue;
2091 struct berval left = *value;
2095 /* Add up asserted input length */
2096 if( sub->sa_initial.bv_val ) {
2097 inlen += sub->sa_initial.bv_len;
2100 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2101 inlen += sub->sa_any[i].bv_len;
2104 if( sub->sa_final.bv_val ) {
2105 inlen += sub->sa_final.bv_len;
2108 if( sub->sa_initial.bv_val ) {
2109 if( inlen > left.bv_len ) {
2114 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2115 sub->sa_initial.bv_len );
2121 left.bv_val += sub->sa_initial.bv_len;
2122 left.bv_len -= sub->sa_initial.bv_len;
2123 inlen -= sub->sa_initial.bv_len;
2126 if( sub->sa_final.bv_val ) {
2127 if( inlen > left.bv_len ) {
2132 match = strncmp( sub->sa_final.bv_val,
2133 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2134 sub->sa_final.bv_len );
2140 left.bv_len -= sub->sa_final.bv_len;
2141 inlen -= sub->sa_final.bv_len;
2145 for(i=0; sub->sa_any[i].bv_val; i++) {
2150 if( inlen > left.bv_len ) {
2151 /* not enough length */
2156 if( sub->sa_any[i].bv_len == 0 ) {
2160 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2167 idx = p - left.bv_val;
2169 if( idx >= left.bv_len ) {
2170 /* this shouldn't happen */
2177 if( sub->sa_any[i].bv_len > left.bv_len ) {
2178 /* not enough left */
2183 match = strncmp( left.bv_val,
2184 sub->sa_any[i].bv_val,
2185 sub->sa_any[i].bv_len );
2193 left.bv_val += sub->sa_any[i].bv_len;
2194 left.bv_len -= sub->sa_any[i].bv_len;
2195 inlen -= sub->sa_any[i].bv_len;
2201 return LDAP_SUCCESS;
2204 /* Index generation function */
2205 static int caseExactIA5Indexer(
2210 struct berval *prefix,
2217 HASH_CONTEXT HASHcontext;
2218 unsigned char HASHdigest[HASH_BYTES];
2219 struct berval digest;
2220 digest.bv_val = HASHdigest;
2221 digest.bv_len = sizeof(HASHdigest);
2223 for( i=0; values[i].bv_val != NULL; i++ ) {
2224 /* empty - just count them */
2227 /* we should have at least one value at this point */
2230 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2232 slen = syntax->ssyn_oidlen;
2233 mlen = mr->smr_oidlen;
2235 for( i=0; values[i].bv_val != NULL; i++ ) {
2236 struct berval *value = &values[i];
2238 HASH_Init( &HASHcontext );
2239 if( prefix != NULL && prefix->bv_len > 0 ) {
2240 HASH_Update( &HASHcontext,
2241 prefix->bv_val, prefix->bv_len );
2243 HASH_Update( &HASHcontext,
2244 syntax->ssyn_oid, slen );
2245 HASH_Update( &HASHcontext,
2246 mr->smr_oid, mlen );
2247 HASH_Update( &HASHcontext,
2248 value->bv_val, value->bv_len );
2249 HASH_Final( HASHdigest, &HASHcontext );
2251 ber_dupbv( &keys[i], &digest );
2254 keys[i].bv_val = NULL;
2256 return LDAP_SUCCESS;
2259 /* Index generation function */
2260 static int caseExactIA5Filter(
2265 struct berval *prefix,
2271 HASH_CONTEXT HASHcontext;
2272 unsigned char HASHdigest[HASH_BYTES];
2273 struct berval *value;
2274 struct berval digest;
2275 digest.bv_val = HASHdigest;
2276 digest.bv_len = sizeof(HASHdigest);
2278 slen = syntax->ssyn_oidlen;
2279 mlen = mr->smr_oidlen;
2281 value = (struct berval *) assertValue;
2283 keys = ch_malloc( sizeof( struct berval ) * 2 );
2285 HASH_Init( &HASHcontext );
2286 if( prefix != NULL && prefix->bv_len > 0 ) {
2287 HASH_Update( &HASHcontext,
2288 prefix->bv_val, prefix->bv_len );
2290 HASH_Update( &HASHcontext,
2291 syntax->ssyn_oid, slen );
2292 HASH_Update( &HASHcontext,
2293 mr->smr_oid, mlen );
2294 HASH_Update( &HASHcontext,
2295 value->bv_val, value->bv_len );
2296 HASH_Final( HASHdigest, &HASHcontext );
2298 ber_dupbv( &keys[0], &digest );
2299 keys[1].bv_val = NULL;
2302 return LDAP_SUCCESS;
2305 /* Substrings Index generation function */
2306 static int caseExactIA5SubstringsIndexer(
2311 struct berval *prefix,
2318 HASH_CONTEXT HASHcontext;
2319 unsigned char HASHdigest[HASH_BYTES];
2320 struct berval digest;
2321 digest.bv_val = HASHdigest;
2322 digest.bv_len = sizeof(HASHdigest);
2324 /* we should have at least one value at this point */
2325 assert( values != NULL && values[0].bv_val != NULL );
2328 for( i=0; values[i].bv_val != NULL; i++ ) {
2329 /* count number of indices to generate */
2330 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2334 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2335 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2336 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2337 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2339 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2343 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2344 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2345 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2349 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2350 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2351 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2352 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2354 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2360 /* no keys to generate */
2362 return LDAP_SUCCESS;
2365 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2367 slen = syntax->ssyn_oidlen;
2368 mlen = mr->smr_oidlen;
2371 for( i=0; values[i].bv_val != NULL; i++ ) {
2373 struct berval *value;
2376 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2378 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2379 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2381 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2382 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2384 for( j=0; j<max; j++ ) {
2385 HASH_Init( &HASHcontext );
2386 if( prefix != NULL && prefix->bv_len > 0 ) {
2387 HASH_Update( &HASHcontext,
2388 prefix->bv_val, prefix->bv_len );
2391 HASH_Update( &HASHcontext,
2392 &pre, sizeof( pre ) );
2393 HASH_Update( &HASHcontext,
2394 syntax->ssyn_oid, slen );
2395 HASH_Update( &HASHcontext,
2396 mr->smr_oid, mlen );
2397 HASH_Update( &HASHcontext,
2399 SLAP_INDEX_SUBSTR_MAXLEN );
2400 HASH_Final( HASHdigest, &HASHcontext );
2402 ber_dupbv( &keys[nkeys++], &digest );
2406 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2407 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2409 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2412 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2413 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2414 HASH_Init( &HASHcontext );
2415 if( prefix != NULL && prefix->bv_len > 0 ) {
2416 HASH_Update( &HASHcontext,
2417 prefix->bv_val, prefix->bv_len );
2419 HASH_Update( &HASHcontext,
2420 &pre, sizeof( pre ) );
2421 HASH_Update( &HASHcontext,
2422 syntax->ssyn_oid, slen );
2423 HASH_Update( &HASHcontext,
2424 mr->smr_oid, mlen );
2425 HASH_Update( &HASHcontext,
2427 HASH_Final( HASHdigest, &HASHcontext );
2429 ber_dupbv( &keys[nkeys++], &digest );
2432 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2433 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2434 HASH_Init( &HASHcontext );
2435 if( prefix != NULL && prefix->bv_len > 0 ) {
2436 HASH_Update( &HASHcontext,
2437 prefix->bv_val, prefix->bv_len );
2439 HASH_Update( &HASHcontext,
2440 &pre, sizeof( pre ) );
2441 HASH_Update( &HASHcontext,
2442 syntax->ssyn_oid, slen );
2443 HASH_Update( &HASHcontext,
2444 mr->smr_oid, mlen );
2445 HASH_Update( &HASHcontext,
2446 &value->bv_val[value->bv_len-j], j );
2447 HASH_Final( HASHdigest, &HASHcontext );
2449 ber_dupbv( &keys[nkeys++], &digest );
2456 keys[nkeys].bv_val = NULL;
2463 return LDAP_SUCCESS;
2466 static int caseExactIA5SubstringsFilter(
2471 struct berval *prefix,
2475 SubstringsAssertion *sa = assertValue;
2477 ber_len_t nkeys = 0;
2478 size_t slen, mlen, klen;
2480 HASH_CONTEXT HASHcontext;
2481 unsigned char HASHdigest[HASH_BYTES];
2482 struct berval *value;
2483 struct berval digest;
2485 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2486 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2491 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2493 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2494 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2495 /* don't bother accounting for stepping */
2496 nkeys += sa->sa_any[i].bv_len -
2497 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2502 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2503 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2510 return LDAP_SUCCESS;
2513 digest.bv_val = HASHdigest;
2514 digest.bv_len = sizeof(HASHdigest);
2516 slen = syntax->ssyn_oidlen;
2517 mlen = mr->smr_oidlen;
2519 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2522 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2523 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2525 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2526 value = &sa->sa_initial;
2528 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2529 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2531 HASH_Init( &HASHcontext );
2532 if( prefix != NULL && prefix->bv_len > 0 ) {
2533 HASH_Update( &HASHcontext,
2534 prefix->bv_val, prefix->bv_len );
2536 HASH_Update( &HASHcontext,
2537 &pre, sizeof( pre ) );
2538 HASH_Update( &HASHcontext,
2539 syntax->ssyn_oid, slen );
2540 HASH_Update( &HASHcontext,
2541 mr->smr_oid, mlen );
2542 HASH_Update( &HASHcontext,
2543 value->bv_val, klen );
2544 HASH_Final( HASHdigest, &HASHcontext );
2546 ber_dupbv( &keys[nkeys++], &digest );
2549 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2551 pre = SLAP_INDEX_SUBSTR_PREFIX;
2552 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2554 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2555 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2559 value = &sa->sa_any[i];
2562 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2563 j += SLAP_INDEX_SUBSTR_STEP )
2565 HASH_Init( &HASHcontext );
2566 if( prefix != NULL && prefix->bv_len > 0 ) {
2567 HASH_Update( &HASHcontext,
2568 prefix->bv_val, prefix->bv_len );
2570 HASH_Update( &HASHcontext,
2571 &pre, sizeof( pre ) );
2572 HASH_Update( &HASHcontext,
2573 syntax->ssyn_oid, slen );
2574 HASH_Update( &HASHcontext,
2575 mr->smr_oid, mlen );
2576 HASH_Update( &HASHcontext,
2577 &value->bv_val[j], klen );
2578 HASH_Final( HASHdigest, &HASHcontext );
2580 ber_dupbv( &keys[nkeys++], &digest );
2585 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2586 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2588 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2589 value = &sa->sa_final;
2591 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2592 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2594 HASH_Init( &HASHcontext );
2595 if( prefix != NULL && prefix->bv_len > 0 ) {
2596 HASH_Update( &HASHcontext,
2597 prefix->bv_val, prefix->bv_len );
2599 HASH_Update( &HASHcontext,
2600 &pre, sizeof( pre ) );
2601 HASH_Update( &HASHcontext,
2602 syntax->ssyn_oid, slen );
2603 HASH_Update( &HASHcontext,
2604 mr->smr_oid, mlen );
2605 HASH_Update( &HASHcontext,
2606 &value->bv_val[value->bv_len-klen], klen );
2607 HASH_Final( HASHdigest, &HASHcontext );
2609 ber_dupbv( &keys[nkeys++], &digest );
2613 keys[nkeys].bv_val = NULL;
2620 return LDAP_SUCCESS;
2629 struct berval *value,
2630 void *assertedValue )
2632 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2634 if( match == 0 && value->bv_len ) {
2635 match = strncasecmp( value->bv_val,
2636 ((struct berval *) assertedValue)->bv_val,
2641 return LDAP_SUCCESS;
2645 caseIgnoreIA5SubstringsMatch(
2650 struct berval *value,
2651 void *assertedValue )
2654 SubstringsAssertion *sub = assertedValue;
2655 struct berval left = *value;
2659 /* Add up asserted input length */
2660 if( sub->sa_initial.bv_val ) {
2661 inlen += sub->sa_initial.bv_len;
2664 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2665 inlen += sub->sa_any[i].bv_len;
2668 if( sub->sa_final.bv_val ) {
2669 inlen += sub->sa_final.bv_len;
2672 if( sub->sa_initial.bv_val ) {
2673 if( inlen > left.bv_len ) {
2678 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2679 sub->sa_initial.bv_len );
2685 left.bv_val += sub->sa_initial.bv_len;
2686 left.bv_len -= sub->sa_initial.bv_len;
2687 inlen -= sub->sa_initial.bv_len;
2690 if( sub->sa_final.bv_val ) {
2691 if( inlen > left.bv_len ) {
2696 match = strncasecmp( sub->sa_final.bv_val,
2697 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2698 sub->sa_final.bv_len );
2704 left.bv_len -= sub->sa_final.bv_len;
2705 inlen -= sub->sa_final.bv_len;
2709 for(i=0; sub->sa_any[i].bv_val; i++) {
2714 if( inlen > left.bv_len ) {
2715 /* not enough length */
2720 if( sub->sa_any[i].bv_len == 0 ) {
2724 p = bvcasechr( &left, *sub->sa_any[i].bv_val, &idx );
2731 assert( idx < left.bv_len );
2732 if( idx >= left.bv_len ) {
2733 /* this shouldn't happen */
2740 if( sub->sa_any[i].bv_len > left.bv_len ) {
2741 /* not enough left */
2746 match = strncasecmp( left.bv_val,
2747 sub->sa_any[i].bv_val,
2748 sub->sa_any[i].bv_len );
2757 left.bv_val += sub->sa_any[i].bv_len;
2758 left.bv_len -= sub->sa_any[i].bv_len;
2759 inlen -= sub->sa_any[i].bv_len;
2765 return LDAP_SUCCESS;
2768 /* Index generation function */
2769 static int caseIgnoreIA5Indexer(
2774 struct berval *prefix,
2781 HASH_CONTEXT HASHcontext;
2782 unsigned char HASHdigest[HASH_BYTES];
2783 struct berval digest;
2784 digest.bv_val = HASHdigest;
2785 digest.bv_len = sizeof(HASHdigest);
2787 /* we should have at least one value at this point */
2788 assert( values != NULL && values[0].bv_val != NULL );
2790 for( i=0; values[i].bv_val != NULL; i++ ) {
2791 /* just count them */
2794 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2796 slen = syntax->ssyn_oidlen;
2797 mlen = mr->smr_oidlen;
2799 for( i=0; values[i].bv_val != NULL; i++ ) {
2800 struct berval value;
2801 ber_dupbv( &value, &values[i] );
2802 ldap_pvt_str2upper( value.bv_val );
2804 HASH_Init( &HASHcontext );
2805 if( prefix != NULL && prefix->bv_len > 0 ) {
2806 HASH_Update( &HASHcontext,
2807 prefix->bv_val, prefix->bv_len );
2809 HASH_Update( &HASHcontext,
2810 syntax->ssyn_oid, slen );
2811 HASH_Update( &HASHcontext,
2812 mr->smr_oid, mlen );
2813 HASH_Update( &HASHcontext,
2814 value.bv_val, value.bv_len );
2815 HASH_Final( HASHdigest, &HASHcontext );
2817 free( value.bv_val );
2819 ber_dupbv( &keys[i], &digest );
2822 keys[i].bv_val = NULL;
2824 return LDAP_SUCCESS;
2827 /* Index generation function */
2828 static int caseIgnoreIA5Filter(
2833 struct berval *prefix,
2839 HASH_CONTEXT HASHcontext;
2840 unsigned char HASHdigest[HASH_BYTES];
2841 struct berval value;
2842 struct berval digest;
2843 digest.bv_val = HASHdigest;
2844 digest.bv_len = sizeof(HASHdigest);
2846 slen = syntax->ssyn_oidlen;
2847 mlen = mr->smr_oidlen;
2849 ber_dupbv( &value, (struct berval *) assertValue );
2850 ldap_pvt_str2upper( value.bv_val );
2852 keys = ch_malloc( sizeof( struct berval ) * 2 );
2854 HASH_Init( &HASHcontext );
2855 if( prefix != NULL && prefix->bv_len > 0 ) {
2856 HASH_Update( &HASHcontext,
2857 prefix->bv_val, prefix->bv_len );
2859 HASH_Update( &HASHcontext,
2860 syntax->ssyn_oid, slen );
2861 HASH_Update( &HASHcontext,
2862 mr->smr_oid, mlen );
2863 HASH_Update( &HASHcontext,
2864 value.bv_val, value.bv_len );
2865 HASH_Final( HASHdigest, &HASHcontext );
2867 ber_dupbv( &keys[0], &digest );
2868 keys[1].bv_val = NULL;
2870 free( value.bv_val );
2874 return LDAP_SUCCESS;
2877 /* Substrings Index generation function */
2878 static int caseIgnoreIA5SubstringsIndexer(
2883 struct berval *prefix,
2890 HASH_CONTEXT HASHcontext;
2891 unsigned char HASHdigest[HASH_BYTES];
2892 struct berval digest;
2893 digest.bv_val = HASHdigest;
2894 digest.bv_len = sizeof(HASHdigest);
2896 /* we should have at least one value at this point */
2897 assert( values != NULL && values[0].bv_val != NULL );
2900 for( i=0; values[i].bv_val != NULL; i++ ) {
2901 /* count number of indices to generate */
2902 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2906 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2907 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2908 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2909 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2911 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2915 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2916 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2917 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2921 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2922 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2923 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2924 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2926 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2932 /* no keys to generate */
2934 return LDAP_SUCCESS;
2937 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2939 slen = syntax->ssyn_oidlen;
2940 mlen = mr->smr_oidlen;
2943 for( i=0; values[i].bv_val != NULL; i++ ) {
2945 struct berval value;
2947 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2949 ber_dupbv( &value, &values[i] );
2950 ldap_pvt_str2upper( value.bv_val );
2952 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2953 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2955 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2956 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2958 for( j=0; j<max; j++ ) {
2959 HASH_Init( &HASHcontext );
2960 if( prefix != NULL && prefix->bv_len > 0 ) {
2961 HASH_Update( &HASHcontext,
2962 prefix->bv_val, prefix->bv_len );
2965 HASH_Update( &HASHcontext,
2966 &pre, sizeof( pre ) );
2967 HASH_Update( &HASHcontext,
2968 syntax->ssyn_oid, slen );
2969 HASH_Update( &HASHcontext,
2970 mr->smr_oid, mlen );
2971 HASH_Update( &HASHcontext,
2973 SLAP_INDEX_SUBSTR_MAXLEN );
2974 HASH_Final( HASHdigest, &HASHcontext );
2976 ber_dupbv( &keys[nkeys++], &digest );
2980 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2981 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2983 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2986 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2987 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2988 HASH_Init( &HASHcontext );
2989 if( prefix != NULL && prefix->bv_len > 0 ) {
2990 HASH_Update( &HASHcontext,
2991 prefix->bv_val, prefix->bv_len );
2993 HASH_Update( &HASHcontext,
2994 &pre, sizeof( pre ) );
2995 HASH_Update( &HASHcontext,
2996 syntax->ssyn_oid, slen );
2997 HASH_Update( &HASHcontext,
2998 mr->smr_oid, mlen );
2999 HASH_Update( &HASHcontext,
3001 HASH_Final( HASHdigest, &HASHcontext );
3003 ber_dupbv( &keys[nkeys++], &digest );
3006 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3007 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3008 HASH_Init( &HASHcontext );
3009 if( prefix != NULL && prefix->bv_len > 0 ) {
3010 HASH_Update( &HASHcontext,
3011 prefix->bv_val, prefix->bv_len );
3013 HASH_Update( &HASHcontext,
3014 &pre, sizeof( pre ) );
3015 HASH_Update( &HASHcontext,
3016 syntax->ssyn_oid, slen );
3017 HASH_Update( &HASHcontext,
3018 mr->smr_oid, mlen );
3019 HASH_Update( &HASHcontext,
3020 &value.bv_val[value.bv_len-j], j );
3021 HASH_Final( HASHdigest, &HASHcontext );
3023 ber_dupbv( &keys[nkeys++], &digest );
3028 free( value.bv_val );
3032 keys[nkeys].bv_val = NULL;
3039 return LDAP_SUCCESS;
3042 static int caseIgnoreIA5SubstringsFilter(
3047 struct berval *prefix,
3051 SubstringsAssertion *sa = assertValue;
3053 ber_len_t nkeys = 0;
3054 size_t slen, mlen, klen;
3056 HASH_CONTEXT HASHcontext;
3057 unsigned char HASHdigest[HASH_BYTES];
3058 struct berval value;
3059 struct berval digest;
3061 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3062 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3067 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3069 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3070 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3071 /* don't bother accounting for stepping */
3072 nkeys += sa->sa_any[i].bv_len -
3073 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3078 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3079 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3086 return LDAP_SUCCESS;
3089 digest.bv_val = HASHdigest;
3090 digest.bv_len = sizeof(HASHdigest);
3092 slen = syntax->ssyn_oidlen;
3093 mlen = mr->smr_oidlen;
3095 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3098 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3099 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3101 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3102 ber_dupbv( &value, &sa->sa_initial );
3103 ldap_pvt_str2upper( value.bv_val );
3105 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3106 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3108 HASH_Init( &HASHcontext );
3109 if( prefix != NULL && prefix->bv_len > 0 ) {
3110 HASH_Update( &HASHcontext,
3111 prefix->bv_val, prefix->bv_len );
3113 HASH_Update( &HASHcontext,
3114 &pre, sizeof( pre ) );
3115 HASH_Update( &HASHcontext,
3116 syntax->ssyn_oid, slen );
3117 HASH_Update( &HASHcontext,
3118 mr->smr_oid, mlen );
3119 HASH_Update( &HASHcontext,
3120 value.bv_val, klen );
3121 HASH_Final( HASHdigest, &HASHcontext );
3123 free( value.bv_val );
3124 ber_dupbv( &keys[nkeys++], &digest );
3127 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3129 pre = SLAP_INDEX_SUBSTR_PREFIX;
3130 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3132 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3133 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3137 ber_dupbv( &value, &sa->sa_any[i] );
3138 ldap_pvt_str2upper( value.bv_val );
3141 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3142 j += SLAP_INDEX_SUBSTR_STEP )
3144 HASH_Init( &HASHcontext );
3145 if( prefix != NULL && prefix->bv_len > 0 ) {
3146 HASH_Update( &HASHcontext,
3147 prefix->bv_val, prefix->bv_len );
3149 HASH_Update( &HASHcontext,
3150 &pre, sizeof( pre ) );
3151 HASH_Update( &HASHcontext,
3152 syntax->ssyn_oid, slen );
3153 HASH_Update( &HASHcontext,
3154 mr->smr_oid, mlen );
3155 HASH_Update( &HASHcontext,
3156 &value.bv_val[j], klen );
3157 HASH_Final( HASHdigest, &HASHcontext );
3159 ber_dupbv( &keys[nkeys++], &digest );
3162 free( value.bv_val );
3166 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3167 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3169 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3170 ber_dupbv( &value, &sa->sa_final );
3171 ldap_pvt_str2upper( value.bv_val );
3173 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3174 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3176 HASH_Init( &HASHcontext );
3177 if( prefix != NULL && prefix->bv_len > 0 ) {
3178 HASH_Update( &HASHcontext,
3179 prefix->bv_val, prefix->bv_len );
3181 HASH_Update( &HASHcontext,
3182 &pre, sizeof( pre ) );
3183 HASH_Update( &HASHcontext,
3184 syntax->ssyn_oid, slen );
3185 HASH_Update( &HASHcontext,
3186 mr->smr_oid, mlen );
3187 HASH_Update( &HASHcontext,
3188 &value.bv_val[value.bv_len-klen], klen );
3189 HASH_Final( HASHdigest, &HASHcontext );
3191 free( value.bv_val );
3192 ber_dupbv( &keys[nkeys++], &digest );
3196 keys[nkeys].bv_val = NULL;
3203 return LDAP_SUCCESS;
3207 numericStringValidate(
3213 for(i=0; i < in->bv_len; i++) {
3214 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3215 return LDAP_INVALID_SYNTAX;
3219 return LDAP_SUCCESS;
3223 numericStringNormalize(
3226 struct berval *normalized )
3228 /* removal all spaces */
3231 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3234 q = normalized->bv_val;
3237 if ( ASCII_SPACE( *p ) ) {
3238 /* Ignore whitespace */
3245 /* we should have copied no more then is in val */
3246 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3248 /* null terminate */
3251 normalized->bv_len = q - normalized->bv_val;
3253 return LDAP_SUCCESS;
3257 objectIdentifierFirstComponentMatch(
3262 struct berval *value,
3263 void *assertedValue )
3265 int rc = LDAP_SUCCESS;
3267 struct berval *asserted = (struct berval *) assertedValue;
3271 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3272 return LDAP_INVALID_SYNTAX;
3275 /* trim leading white space */
3276 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3280 /* grab next word */
3281 oid.bv_val = &value->bv_val[i];
3282 oid.bv_len = value->bv_len - i;
3283 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3288 /* insert attributeTypes, objectclass check here */
3289 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3290 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3293 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3294 MatchingRule *asserted_mr = mr_bvfind( asserted );
3295 MatchingRule *stored_mr = mr_bvfind( &oid );
3297 if( asserted_mr == NULL ) {
3298 rc = SLAPD_COMPARE_UNDEFINED;
3300 match = asserted_mr != stored_mr;
3303 } else if ( !strcmp( syntax->ssyn_oid,
3304 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3306 AttributeType *asserted_at = at_bvfind( asserted );
3307 AttributeType *stored_at = at_bvfind( &oid );
3309 if( asserted_at == NULL ) {
3310 rc = SLAPD_COMPARE_UNDEFINED;
3312 match = asserted_at != stored_at;
3315 } else if ( !strcmp( syntax->ssyn_oid,
3316 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3318 ObjectClass *asserted_oc = oc_bvfind( asserted );
3319 ObjectClass *stored_oc = oc_bvfind( &oid );
3321 if( asserted_oc == NULL ) {
3322 rc = SLAPD_COMPARE_UNDEFINED;
3324 match = asserted_oc != stored_oc;
3330 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3331 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3332 match, value->bv_val, asserted->bv_val ));
3334 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3335 "%d\n\t\"%s\"\n\t\"%s\"\n",
3336 match, value->bv_val, asserted->bv_val );
3340 if( rc == LDAP_SUCCESS ) *matchp = match;
3350 struct berval *value,
3351 void *assertedValue )
3353 long lValue, lAssertedValue;
3355 /* safe to assume integers are NUL terminated? */
3356 lValue = strtoul(value->bv_val, NULL, 10);
3357 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3358 return LDAP_CONSTRAINT_VIOLATION;
3360 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3361 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3362 return LDAP_CONSTRAINT_VIOLATION;
3364 *matchp = (lValue & lAssertedValue);
3365 return LDAP_SUCCESS;
3374 struct berval *value,
3375 void *assertedValue )
3377 long lValue, lAssertedValue;
3379 /* safe to assume integers are NUL terminated? */
3380 lValue = strtoul(value->bv_val, NULL, 10);
3381 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3382 return LDAP_CONSTRAINT_VIOLATION;
3384 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3385 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3386 return LDAP_CONSTRAINT_VIOLATION;
3388 *matchp = (lValue | lAssertedValue);
3389 return LDAP_SUCCESS;
3393 #include <openssl/x509.h>
3394 #include <openssl/err.h>
3395 char digit[] = "0123456789";
3398 * Next function returns a string representation of a ASN1_INTEGER.
3399 * It works for unlimited lengths.
3402 static struct berval *
3403 asn1_integer2str(ASN1_INTEGER *a)
3408 /* We work backwards, make it fill from the end of buf */
3409 p = buf + sizeof(buf) - 1;
3412 if ( a == NULL || a->length == 0 ) {
3420 /* We want to preserve the original */
3421 copy = ch_malloc(n*sizeof(unsigned int));
3422 for (i = 0; i<n; i++) {
3423 copy[i] = a->data[i];
3427 * base indicates the index of the most significant
3428 * byte that might be nonzero. When it goes off the
3429 * end, we now there is nothing left to do.
3435 for (i = base; i<n; i++ ) {
3436 copy[i] += carry*256;
3437 carry = copy[i] % 10;
3442 * Way too large, we need to leave
3443 * room for sign if negative
3448 *--p = digit[carry];
3449 if (copy[base] == 0)
3455 if ( a->type == V_ASN1_NEG_INTEGER ) {
3459 return ber_bvstrdup(p);
3462 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3463 static struct berval *
3464 dn_openssl2ldap(X509_NAME *name)
3466 char issuer_dn[1024];
3469 bio = BIO_new(BIO_s_mem());
3472 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3473 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3474 ERR_error_string(ERR_get_error(),NULL)));
3476 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3477 "error creating BIO: %s\n",
3478 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3482 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3484 BIO_gets(bio, issuer_dn, 1024);
3487 return ber_bvstrdup(issuer_dn);
3491 * Given a certificate in DER format, extract the corresponding
3492 * assertion value for certificateExactMatch
3495 certificateExactConvert(
3497 struct berval * out )
3500 unsigned char *p = in->bv_val;
3501 struct berval *serial;
3502 struct berval *issuer_dn;
3503 struct berval *bv_tmp;
3505 xcert = d2i_X509(NULL, &p, in->bv_len);
3508 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3509 "certificateExactConvert: error parsing cert: %s\n",
3510 ERR_error_string(ERR_get_error(),NULL)));
3512 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3513 "error parsing cert: %s\n",
3514 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3516 return LDAP_INVALID_SYNTAX;
3519 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3522 return LDAP_INVALID_SYNTAX;
3524 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3528 return LDAP_INVALID_SYNTAX;
3530 /* Actually, dn_openssl2ldap returns in a normalized format, but
3531 it is different from our normalized format */
3533 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3537 return LDAP_INVALID_SYNTAX;
3543 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3544 out->bv_val = ch_malloc(out->bv_len);
3546 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3547 p += serial->bv_len;
3548 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3550 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3551 p += issuer_dn->bv_len;
3555 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3556 "certificateExactConvert: \n %s\n",
3559 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3561 out->bv_val, NULL, NULL );
3565 ber_bvfree(issuer_dn);
3567 return LDAP_SUCCESS;
3571 serial_and_issuer_parse(
3572 struct berval *assertion,
3573 struct berval **serial,
3574 struct berval **issuer_dn
3582 begin = assertion->bv_val;
3583 end = assertion->bv_val+assertion->bv_len-1;
3584 for (p=begin; p<=end && *p != '$'; p++)
3587 return LDAP_INVALID_SYNTAX;
3589 /* p now points at the $ sign, now use begin and end to delimit the
3591 while (ASCII_SPACE(*begin))
3594 while (ASCII_SPACE(*end))
3597 bv.bv_len = end-begin+1;
3599 *serial = ber_dupbv(NULL, &bv);
3601 /* now extract the issuer, remember p was at the dollar sign */
3603 end = assertion->bv_val+assertion->bv_len-1;
3604 while (ASCII_SPACE(*begin))
3606 /* should we trim spaces at the end too? is it safe always? */
3608 bv.bv_len = end-begin+1;
3610 dnNormalize( NULL, &bv, issuer_dn );
3612 return LDAP_SUCCESS;
3616 certificateExactMatch(
3621 struct berval *value,
3622 void *assertedValue )
3625 unsigned char *p = value->bv_val;
3626 struct berval *serial;
3627 struct berval *issuer_dn;
3628 struct berval *asserted_serial;
3629 struct berval *asserted_issuer_dn;
3632 xcert = d2i_X509(NULL, &p, value->bv_len);
3635 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3636 "certificateExactMatch: error parsing cert: %s\n",
3637 ERR_error_string(ERR_get_error(),NULL)));
3639 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3640 "error parsing cert: %s\n",
3641 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3643 return LDAP_INVALID_SYNTAX;
3646 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3647 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3651 serial_and_issuer_parse(assertedValue,
3653 &asserted_issuer_dn);
3658 slap_schema.si_syn_integer,
3659 slap_schema.si_mr_integerMatch,
3662 if ( ret == LDAP_SUCCESS ) {
3663 if ( *matchp == 0 ) {
3664 /* We need to normalize everything for dnMatch */
3668 slap_schema.si_syn_distinguishedName,
3669 slap_schema.si_mr_distinguishedNameMatch,
3671 asserted_issuer_dn);
3676 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3677 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3678 *matchp, serial->bv_val, issuer_dn->bv_val,
3679 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3681 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3682 "%d\n\t\"%s $ %s\"\n",
3683 *matchp, serial->bv_val, issuer_dn->bv_val );
3684 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3685 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3690 ber_bvfree(issuer_dn);
3691 ber_bvfree(asserted_serial);
3692 ber_bvfree(asserted_issuer_dn);
3698 * Index generation function
3699 * We just index the serials, in most scenarios the issuer DN is one of
3700 * a very small set of values.
3702 static int certificateExactIndexer(
3707 struct berval *prefix,
3715 struct berval * serial;
3717 /* we should have at least one value at this point */
3718 assert( values != NULL && values[0].bv_val != NULL );
3720 for( i=0; values[i].bv_val != NULL; i++ ) {
3721 /* empty -- just count them */
3724 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3726 for( i=0; values[i].bv_val != NULL; i++ ) {
3727 p = values[i].bv_val;
3728 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3731 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3732 "certificateExactIndexer: error parsing cert: %s\n",
3733 ERR_error_string(ERR_get_error(),NULL)));
3735 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3736 "error parsing cert: %s\n",
3737 ERR_error_string(ERR_get_error(),NULL),
3740 /* Do we leak keys on error? */
3741 return LDAP_INVALID_SYNTAX;
3744 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3746 integerNormalize( slap_schema.si_syn_integer,
3751 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3752 "certificateExactIndexer: returning: %s\n",
3755 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3762 keys[i].bv_val = NULL;
3764 return LDAP_SUCCESS;
3767 /* Index generation function */
3768 /* We think this is always called with a value in matching rule syntax */
3769 static int certificateExactFilter(
3774 struct berval *prefix,
3779 struct berval *asserted_serial;
3780 struct berval *asserted_issuer_dn;
3782 serial_and_issuer_parse(assertValue,
3784 &asserted_issuer_dn);
3786 keys = ch_malloc( sizeof( struct berval ) * 2 );
3787 integerNormalize( syntax, asserted_serial, &keys[0] );
3788 keys[1].bv_val = NULL;
3791 ber_bvfree(asserted_serial);
3792 ber_bvfree(asserted_issuer_dn);
3793 return LDAP_SUCCESS;
3798 check_time_syntax (struct berval *val,
3802 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3803 static int mdays[2][12] = {
3804 /* non-leap years */
3805 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3807 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3810 int part, c, tzoffset, leapyear = 0 ;
3812 if( val->bv_len == 0 ) {
3813 return LDAP_INVALID_SYNTAX;
3816 p = (char *)val->bv_val;
3817 e = p + val->bv_len;
3819 /* Ignore initial whitespace */
3820 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3824 if (e - p < 13 - (2 * start)) {
3825 return LDAP_INVALID_SYNTAX;
3828 for (part = 0; part < 9; part++) {
3832 for (part = start; part < 7; part++) {
3834 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3841 return LDAP_INVALID_SYNTAX;
3843 if (c < 0 || c > 9) {
3844 return LDAP_INVALID_SYNTAX;
3850 return LDAP_INVALID_SYNTAX;
3852 if (c < 0 || c > 9) {
3853 return LDAP_INVALID_SYNTAX;
3858 if (part == 2 || part == 3) {
3861 if (parts[part] < 0) {
3862 return LDAP_INVALID_SYNTAX;
3864 if (parts[part] > ceiling[part]) {
3865 return LDAP_INVALID_SYNTAX;
3869 /* leapyear check for the Gregorian calendar (year>1581) */
3870 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3871 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3876 if (parts[3] > mdays[leapyear][parts[2]]) {
3877 return LDAP_INVALID_SYNTAX;
3882 tzoffset = 0; /* UTC */
3883 } else if (c != '+' && c != '-') {
3884 return LDAP_INVALID_SYNTAX;
3888 } else /* c == '+' */ {
3893 return LDAP_INVALID_SYNTAX;
3896 for (part = 7; part < 9; part++) {
3898 if (c < 0 || c > 9) {
3899 return LDAP_INVALID_SYNTAX;
3904 if (c < 0 || c > 9) {
3905 return LDAP_INVALID_SYNTAX;
3909 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3910 return LDAP_INVALID_SYNTAX;
3915 /* Ignore trailing whitespace */
3916 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3920 return LDAP_INVALID_SYNTAX;
3923 switch ( tzoffset ) {
3924 case -1: /* negativ offset to UTC, ie west of Greenwich */
3925 parts[4] += parts[7];
3926 parts[5] += parts[8];
3927 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3931 c = mdays[leapyear][parts[2]];
3933 if (parts[part] > c) {
3934 parts[part] -= c + 1;
3939 case 1: /* positive offset to UTC, ie east of Greenwich */
3940 parts[4] -= parts[7];
3941 parts[5] -= parts[8];
3942 for (part = 6; --part > 0; ) {
3946 /* first arg to % needs to be non negativ */
3947 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3949 if (parts[part] < 0) {
3950 parts[part] += c + 1;
3955 case 0: /* already UTC */
3959 return LDAP_SUCCESS;
3966 struct berval *normalized )
3970 rc = check_time_syntax(val, 1, parts);
3971 if (rc != LDAP_SUCCESS) {
3975 normalized->bv_val = ch_malloc( 14 );
3976 if ( normalized->bv_val == NULL ) {
3977 return LBER_ERROR_MEMORY;
3980 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3981 parts[1], parts[2] + 1, parts[3] + 1,
3982 parts[4], parts[5], parts[6] );
3983 normalized->bv_len = 13;
3985 return LDAP_SUCCESS;
3995 return check_time_syntax(in, 1, parts);
3999 generalizedTimeValidate(
4005 return check_time_syntax(in, 0, parts);
4009 generalizedTimeNormalize(
4012 struct berval *normalized )
4016 rc = check_time_syntax(val, 0, parts);
4017 if (rc != LDAP_SUCCESS) {
4021 normalized->bv_val = ch_malloc( 16 );
4022 if ( normalized->bv_val == NULL ) {
4023 return LBER_ERROR_MEMORY;
4026 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4027 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4028 parts[4], parts[5], parts[6] );
4029 normalized->bv_len = 15;
4031 return LDAP_SUCCESS;
4035 nisNetgroupTripleValidate(
4037 struct berval *val )
4042 if ( val->bv_len == 0 ) {
4043 return LDAP_INVALID_SYNTAX;
4046 p = (char *)val->bv_val;
4047 e = p + val->bv_len;
4049 if ( *p != '(' /*')'*/ ) {
4050 return LDAP_INVALID_SYNTAX;
4053 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4057 return LDAP_INVALID_SYNTAX;
4060 } else if ( !ATTR_CHAR( *p ) ) {
4061 return LDAP_INVALID_SYNTAX;
4065 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4066 return LDAP_INVALID_SYNTAX;
4072 return LDAP_INVALID_SYNTAX;
4075 return LDAP_SUCCESS;
4079 bootParameterValidate(
4081 struct berval *val )
4085 if ( val->bv_len == 0 ) {
4086 return LDAP_INVALID_SYNTAX;
4089 p = (char *)val->bv_val;
4090 e = p + val->bv_len;
4093 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4094 if ( !ATTR_CHAR( *p ) ) {
4095 return LDAP_INVALID_SYNTAX;
4100 return LDAP_INVALID_SYNTAX;
4104 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4105 if ( !ATTR_CHAR( *p ) ) {
4106 return LDAP_INVALID_SYNTAX;
4111 return LDAP_INVALID_SYNTAX;
4115 for ( p++; p < e; p++ ) {
4116 if ( !ATTR_CHAR( *p ) ) {
4117 return LDAP_INVALID_SYNTAX;
4121 return LDAP_SUCCESS;
4124 static struct syntax_defs_rec {
4126 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4127 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4129 slap_syntax_validate_func *sd_validate;
4130 slap_syntax_transform_func *sd_normalize;
4131 slap_syntax_transform_func *sd_pretty;
4132 #ifdef SLAPD_BINARY_CONVERSION
4133 slap_syntax_transform_func *sd_ber2str;
4134 slap_syntax_transform_func *sd_str2ber;
4137 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4138 X_BINARY X_NOT_H_R ")",
4139 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4140 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4141 0, NULL, NULL, NULL},
4142 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4143 0, NULL, NULL, NULL},
4144 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4146 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4149 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4150 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4151 0, bitStringValidate, bitStringNormalize, NULL },
4152 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4153 0, booleanValidate, NULL, NULL},
4154 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4155 X_BINARY X_NOT_H_R ")",
4156 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4158 X_BINARY X_NOT_H_R ")",
4159 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4160 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4161 X_BINARY X_NOT_H_R ")",
4162 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4164 0, countryStringValidate, IA5StringNormalize, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4166 0, dnValidate, dnNormalize2, dnPretty2},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4168 0, NULL, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4170 0, NULL, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4172 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4174 0, NULL, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4176 0, NULL, NULL, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4178 0, NULL, NULL, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4180 0, NULL, NULL, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4182 0, NULL, NULL, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4184 0, printablesStringValidate, IA5StringNormalize, NULL},
4185 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4186 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4188 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4190 0, NULL, NULL, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4192 0, IA5StringValidate, IA5StringNormalize, NULL},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4194 0, integerValidate, integerNormalize, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4196 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4198 0, NULL, NULL, NULL},
4199 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4200 0, NULL, NULL, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4202 0, NULL, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4204 0, NULL, NULL, NULL},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4206 0, NULL, NULL, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4208 0, nameUIDValidate, nameUIDNormalize, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4210 0, NULL, NULL, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4212 0, numericStringValidate, numericStringNormalize, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4214 0, NULL, NULL, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4216 0, oidValidate, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4218 0, IA5StringValidate, IA5StringNormalize, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4220 0, blobValidate, NULL, NULL},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4222 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4224 0, NULL, NULL, NULL},
4225 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4226 0, NULL, NULL, NULL},
4227 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4228 0, printableStringValidate, IA5StringNormalize, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4230 X_BINARY X_NOT_H_R ")",
4231 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4233 X_BINARY X_NOT_H_R ")",
4234 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4236 0, printableStringValidate, IA5StringNormalize, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4238 0, NULL, NULL, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4240 0, printablesStringValidate, IA5StringNormalize, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4242 0, utcTimeValidate, utcTimeNormalize, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4244 0, NULL, NULL, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4246 0, NULL, NULL, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4248 0, NULL, NULL, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4250 0, NULL, NULL, NULL},
4251 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4252 0, NULL, NULL, NULL},
4254 /* RFC 2307 NIS Syntaxes */
4255 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4256 0, nisNetgroupTripleValidate, NULL, NULL},
4257 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4258 0, bootParameterValidate, NULL, NULL},
4262 /* These OIDs are not published yet, but will be in the next
4263 * I-D for PKIX LDAPv3 schema as have been advanced by David
4264 * Chadwick in private mail.
4266 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4267 0, NULL, NULL, NULL},
4270 /* OpenLDAP Experimental Syntaxes */
4271 #ifdef SLAPD_ACI_ENABLED
4272 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4274 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4278 #ifdef SLAPD_AUTHPASSWD
4279 /* needs updating */
4280 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4281 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4284 /* OpenLDAP Void Syntax */
4285 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4286 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4287 {NULL, 0, NULL, NULL, NULL}
4291 * Other matching rules in X.520 that we do not use (yet):
4293 * 2.5.13.9 numericStringOrderingMatch
4294 * 2.5.13.15 integerOrderingMatch
4295 * 2.5.13.18 octetStringOrderingMatch
4296 * 2.5.13.19 octetStringSubstringsMatch
4297 * 2.5.13.25 uTCTimeMatch
4298 * 2.5.13.26 uTCTimeOrderingMatch
4299 * 2.5.13.31 directoryStringFirstComponentMatch
4300 * 2.5.13.32 wordMatch
4301 * 2.5.13.33 keywordMatch
4302 * 2.5.13.35 certificateMatch
4303 * 2.5.13.36 certificatePairExactMatch
4304 * 2.5.13.37 certificatePairMatch
4305 * 2.5.13.38 certificateListExactMatch
4306 * 2.5.13.39 certificateListMatch
4307 * 2.5.13.40 algorithmIdentifierMatch
4308 * 2.5.13.41 storedPrefixMatch
4309 * 2.5.13.42 attributeCertificateMatch
4310 * 2.5.13.43 readerAndKeyIDMatch
4311 * 2.5.13.44 attributeIntegrityMatch
4313 static struct mrule_defs_rec {
4315 slap_mask_t mrd_usage;
4316 slap_mr_convert_func * mrd_convert;
4317 slap_mr_normalize_func * mrd_normalize;
4318 slap_mr_match_func * mrd_match;
4319 slap_mr_indexer_func * mrd_indexer;
4320 slap_mr_filter_func * mrd_filter;
4322 char * mrd_associated;
4325 * EQUALITY matching rules must be listed after associated APPROX
4326 * matching rules. So, we list all APPROX matching rules first.
4328 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4329 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4330 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4332 directoryStringApproxMatch,
4333 directoryStringApproxIndexer,
4334 directoryStringApproxFilter,
4337 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4338 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4339 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4341 IA5StringApproxMatch,
4342 IA5StringApproxIndexer,
4343 IA5StringApproxFilter,
4347 * Other matching rules
4350 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4351 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4352 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4354 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4357 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4358 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4359 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4361 dnMatch, dnIndexer, dnFilter,
4364 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4365 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4366 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4368 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4369 directoryStringApproxMatchOID },
4371 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4372 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4375 caseIgnoreOrderingMatch, NULL, NULL,
4378 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4379 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4380 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4382 caseExactIgnoreSubstringsMatch,
4383 caseExactIgnoreSubstringsIndexer,
4384 caseExactIgnoreSubstringsFilter,
4387 {"( 2.5.13.5 NAME 'caseExactMatch' "
4388 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4389 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4391 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4392 directoryStringApproxMatchOID },
4394 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4395 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4398 caseExactOrderingMatch, NULL, NULL,
4401 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4402 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4403 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4405 caseExactIgnoreSubstringsMatch,
4406 caseExactIgnoreSubstringsIndexer,
4407 caseExactIgnoreSubstringsFilter,
4410 {"( 2.5.13.8 NAME 'numericStringMatch' "
4411 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4412 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4415 caseIgnoreIA5Indexer,
4416 caseIgnoreIA5Filter,
4419 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4420 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4421 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4423 caseIgnoreIA5SubstringsMatch,
4424 caseIgnoreIA5SubstringsIndexer,
4425 caseIgnoreIA5SubstringsFilter,
4428 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4429 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4430 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4432 caseIgnoreListMatch, NULL, NULL,
4435 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4436 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4437 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4439 caseIgnoreListSubstringsMatch, NULL, NULL,
4442 {"( 2.5.13.13 NAME 'booleanMatch' "
4443 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4444 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4446 booleanMatch, NULL, NULL,
4449 {"( 2.5.13.14 NAME 'integerMatch' "
4450 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4451 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4453 integerMatch, integerIndexer, integerFilter,
4456 {"( 2.5.13.16 NAME 'bitStringMatch' "
4457 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4458 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4460 bitStringMatch, bitStringIndexer, bitStringFilter,
4463 {"( 2.5.13.17 NAME 'octetStringMatch' "
4464 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4465 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4467 octetStringMatch, octetStringIndexer, octetStringFilter,
4470 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4471 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4472 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4474 telephoneNumberMatch,
4475 telephoneNumberIndexer,
4476 telephoneNumberFilter,
4479 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4480 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4481 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4483 telephoneNumberSubstringsMatch,
4484 telephoneNumberSubstringsIndexer,
4485 telephoneNumberSubstringsFilter,
4488 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4489 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4490 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4495 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4496 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4497 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4499 uniqueMemberMatch, NULL, NULL,
4502 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4503 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4504 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4506 protocolInformationMatch, NULL, NULL,
4509 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4510 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4511 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4513 generalizedTimeMatch, NULL, NULL,
4516 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4517 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4520 generalizedTimeOrderingMatch, NULL, NULL,
4523 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4524 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4525 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4527 integerFirstComponentMatch, NULL, NULL,
4530 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4531 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4532 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4534 objectIdentifierFirstComponentMatch, NULL, NULL,
4538 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4539 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4540 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4541 certificateExactConvert, NULL,
4542 certificateExactMatch,
4543 certificateExactIndexer, certificateExactFilter,
4547 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4548 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4549 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4551 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4552 IA5StringApproxMatchOID },
4554 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4555 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4556 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4558 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4559 IA5StringApproxMatchOID },
4561 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4562 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4565 caseIgnoreIA5SubstringsMatch,
4566 caseIgnoreIA5SubstringsIndexer,
4567 caseIgnoreIA5SubstringsFilter,
4570 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4571 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4574 caseExactIA5SubstringsMatch,
4575 caseExactIA5SubstringsIndexer,
4576 caseExactIA5SubstringsFilter,
4579 #ifdef SLAPD_AUTHPASSWD
4580 /* needs updating */
4581 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4582 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4585 authPasswordMatch, NULL, NULL,
4589 #ifdef SLAPD_ACI_ENABLED
4590 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4591 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4594 OpenLDAPaciMatch, NULL, NULL,
4598 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4599 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4602 integerBitAndMatch, NULL, NULL,
4605 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4606 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4609 integerBitOrMatch, NULL, NULL,
4612 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4616 slap_schema_init( void )
4621 /* we should only be called once (from main) */
4622 assert( schema_init_done == 0 );
4624 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4625 res = register_syntax( syntax_defs[i].sd_desc,
4626 syntax_defs[i].sd_flags,
4627 syntax_defs[i].sd_validate,
4628 syntax_defs[i].sd_normalize,
4629 syntax_defs[i].sd_pretty
4630 #ifdef SLAPD_BINARY_CONVERSION
4632 syntax_defs[i].sd_ber2str,
4633 syntax_defs[i].sd_str2ber
4638 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4639 syntax_defs[i].sd_desc );
4644 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4645 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4647 "slap_schema_init: Ingoring unusable matching rule %s\n",
4648 mrule_defs[i].mrd_desc );
4652 res = register_matching_rule(
4653 mrule_defs[i].mrd_desc,
4654 mrule_defs[i].mrd_usage,
4655 mrule_defs[i].mrd_convert,
4656 mrule_defs[i].mrd_normalize,
4657 mrule_defs[i].mrd_match,
4658 mrule_defs[i].mrd_indexer,
4659 mrule_defs[i].mrd_filter,
4660 mrule_defs[i].mrd_associated );
4664 "slap_schema_init: Error registering matching rule %s\n",
4665 mrule_defs[i].mrd_desc );
4670 res = slap_schema_load();
4671 schema_init_done = 1;
4676 schema_destroy( void )