1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
15 #include <ac/string.h>
16 #include <ac/socket.h>
21 #include "ldap_utf8.h"
23 #include "lutil_hash.h"
24 #define HASH_BYTES LUTIL_HASH_BYTES
25 #define HASH_CONTEXT lutil_HASH_CTX
26 #define HASH_Init(c) lutil_HASHInit(c)
27 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
28 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
30 /* recycled validatation routines */
31 #define berValidate blobValidate
33 /* unimplemented pretters */
34 #define integerPretty NULL
36 /* recycled matching routines */
37 #define bitStringMatch octetStringMatch
38 #define numericStringMatch caseIgnoreIA5Match
39 #define objectIdentifierMatch caseIgnoreIA5Match
40 #define telephoneNumberMatch caseIgnoreIA5Match
41 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
42 #define generalizedTimeMatch caseIgnoreIA5Match
43 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
44 #define uniqueMemberMatch dnMatch
46 /* approx matching rules */
47 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
48 #define directoryStringApproxMatch approxMatch
49 #define directoryStringApproxIndexer approxIndexer
50 #define directoryStringApproxFilter approxFilter
51 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
52 #define IA5StringApproxMatch approxMatch
53 #define IA5StringApproxIndexer approxIndexer
54 #define IA5StringApproxFilter approxFilter
56 /* orderring matching rules */
57 #define caseIgnoreOrderingMatch caseIgnoreMatch
58 #define caseExactOrderingMatch caseExactMatch
60 /* unimplemented matching routines */
61 #define caseIgnoreListMatch NULL
62 #define caseIgnoreListSubstringsMatch NULL
63 #define protocolInformationMatch NULL
64 #define integerFirstComponentMatch NULL
66 #define OpenLDAPaciMatch NULL
67 #define authPasswordMatch NULL
69 /* recycled indexing/filtering routines */
70 #define dnIndexer caseExactIgnoreIndexer
71 #define dnFilter caseExactIgnoreFilter
72 #define bitStringFilter octetStringFilter
73 #define bitStringIndexer octetStringIndexer
75 #define telephoneNumberIndexer caseIgnoreIA5Indexer
76 #define telephoneNumberFilter caseIgnoreIA5Filter
77 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
78 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
80 /* must match OIDs below */
81 #define caseExactMatchOID "2.5.13.5"
82 #define caseExactSubstringsMatchOID "2.5.13.7"
84 static char *strcasechr( const char *str, int c )
86 char *lower = strchr( str, TOLOWER(c) );
87 char *upper = strchr( str, TOUPPER(c) );
89 if( lower && upper ) {
90 return lower < upper ? lower : upper;
104 struct berval *value,
105 void *assertedValue )
107 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
110 match = memcmp( value->bv_val,
111 ((struct berval *) assertedValue)->bv_val,
119 /* Index generation function */
120 static int octetStringIndexer(
125 struct berval *prefix,
126 struct berval **values,
127 struct berval **keysp )
132 HASH_CONTEXT HASHcontext;
133 unsigned char HASHdigest[HASH_BYTES];
134 struct berval digest;
135 digest.bv_val = HASHdigest;
136 digest.bv_len = sizeof(HASHdigest);
138 for( i=0; values[i] != NULL; i++ ) {
139 /* just count them */
142 /* we should have at least one value at this point */
145 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
147 slen = syntax->ssyn_oidlen;
148 mlen = mr->smr_oidlen;
150 for( i=0; values[i] != NULL; i++ ) {
151 HASH_Init( &HASHcontext );
152 if( prefix != NULL && prefix->bv_len > 0 ) {
153 HASH_Update( &HASHcontext,
154 prefix->bv_val, prefix->bv_len );
156 HASH_Update( &HASHcontext,
157 syntax->ssyn_oid, slen );
158 HASH_Update( &HASHcontext,
160 HASH_Update( &HASHcontext,
161 values[i]->bv_val, values[i]->bv_len );
162 HASH_Final( HASHdigest, &HASHcontext );
164 ber_dupbv( &keys[i], &digest );
167 keys[i].bv_val = NULL;
174 /* Index generation function */
175 static int octetStringFilter(
180 struct berval *prefix,
182 struct berval **keysp )
186 HASH_CONTEXT HASHcontext;
187 unsigned char HASHdigest[HASH_BYTES];
188 struct berval *value = (struct berval *) assertValue;
189 struct berval digest;
190 digest.bv_val = HASHdigest;
191 digest.bv_len = sizeof(HASHdigest);
193 slen = syntax->ssyn_oidlen;
194 mlen = mr->smr_oidlen;
196 keys = ch_malloc( sizeof( struct berval ) * 2 );
198 HASH_Init( &HASHcontext );
199 if( prefix != NULL && prefix->bv_len > 0 ) {
200 HASH_Update( &HASHcontext,
201 prefix->bv_val, prefix->bv_len );
203 HASH_Update( &HASHcontext,
204 syntax->ssyn_oid, slen );
205 HASH_Update( &HASHcontext,
207 HASH_Update( &HASHcontext,
208 value->bv_val, value->bv_len );
209 HASH_Final( HASHdigest, &HASHcontext );
211 ber_dupbv( keys, &digest );
212 keys[1].bv_val = NULL;
227 if( in->bv_len == 0 ) return LDAP_SUCCESS;
229 dn = ber_bvdup( in );
230 if( !dn ) return LDAP_OTHER;
232 if( dn->bv_val[dn->bv_len-1] == 'B'
233 && dn->bv_val[dn->bv_len-2] == '\'' )
235 /* assume presence of optional UID */
238 for(i=dn->bv_len-3; i>1; i--) {
239 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
243 if( dn->bv_val[i] != '\'' ||
244 dn->bv_val[i-1] != '#' ) {
246 return LDAP_INVALID_SYNTAX;
249 /* trim the UID to allow use of dnValidate */
250 dn->bv_val[i-1] = '\0';
254 rc = dnValidate( NULL, dn );
264 struct berval *normalized )
269 ber_dupbv( &out, val );
270 if( out.bv_len != 0 ) {
273 ber_len_t uidlen = 0;
275 if( out.bv_val[out.bv_len-1] == '\'' ) {
276 /* assume presence of optional UID */
277 uid = strrchr( out.bv_val, '#' );
281 return LDAP_INVALID_SYNTAX;
284 uidlen = out.bv_len - (uid - out.bv_val);
285 /* temporarily trim the UID */
287 out.bv_len -= uidlen;
290 #ifdef USE_DN_NORMALIZE
291 rc = dnNormalize2( NULL, &out, normalized );
293 rc = dnPretty2( NULL, &out, normalized );
296 if( rc != LDAP_SUCCESS ) {
298 return LDAP_INVALID_SYNTAX;
301 dnlen = normalized->bv_len;
305 b2.bv_val = ch_malloc(dnlen + uidlen + 1);
306 SAFEMEMCPY( b2.bv_val, normalized->bv_val, dnlen );
308 /* restore the separator */
311 SAFEMEMCPY( normalized->bv_val+dnlen, uid, uidlen );
312 b2.bv_len = dnlen + uidlen;
313 normalized->bv_val[dnlen+uidlen] = '\0';
314 free(normalized->bv_val);
328 /* any value allowed */
337 /* any value allowed */
348 /* very unforgiving validation, requires no normalization
349 * before simplistic matching
351 if( in->bv_len < 3 ) {
352 return LDAP_INVALID_SYNTAX;
356 * rfc 2252 section 6.3 Bit String
357 * bitstring = "'" *binary-digit "'"
358 * binary-digit = "0" / "1"
359 * example: '0101111101'B
362 if( in->bv_val[0] != '\'' ||
363 in->bv_val[in->bv_len-2] != '\'' ||
364 in->bv_val[in->bv_len-1] != 'B' )
366 return LDAP_INVALID_SYNTAX;
369 for( i=in->bv_len-3; i>0; i-- ) {
370 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
371 return LDAP_INVALID_SYNTAX;
382 struct berval *normalized )
385 * A normalized bitString is has no extaneous (leading) zero bits.
386 * That is, '00010'B is normalized to '10'B
387 * However, as a special case, '0'B requires no normalization.
391 /* start at the first bit */
394 /* Find the first non-zero bit */
395 while ( *p == '0' ) p++;
398 /* no non-zero bits */
399 ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
403 normalized->bv_val = ch_malloc( val->bv_len + 1 );
405 normalized->bv_val[0] = '\'';
406 normalized->bv_len = 1;
408 for( ; *p != '\0'; p++ ) {
409 normalized->bv_val[normalized->bv_len++] = *p;
412 normalized->bv_val[normalized->bv_len] = '\0';
419 * Handling boolean syntax and matching is quite rigid.
420 * A more flexible approach would be to allow a variety
421 * of strings to be normalized and prettied into TRUE
429 /* very unforgiving validation, requires no normalization
430 * before simplistic matching
433 if( in->bv_len == 4 ) {
434 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
437 } else if( in->bv_len == 5 ) {
438 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
443 return LDAP_INVALID_SYNTAX;
452 struct berval *value,
453 void *assertedValue )
455 /* simplistic matching allowed by rigid validation */
456 struct berval *asserted = (struct berval *) assertedValue;
457 *matchp = value->bv_len != asserted->bv_len;
468 unsigned char *u = in->bv_val;
470 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
472 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
473 /* get the length indicated by the first byte */
474 len = LDAP_UTF8_CHARLEN( u );
476 /* should not be zero */
477 if( len == 0 ) return LDAP_INVALID_SYNTAX;
479 /* make sure len corresponds with the offset
480 to the next character */
481 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
484 if( count != 0 ) return LDAP_INVALID_SYNTAX;
493 struct berval *normalized )
500 /* Ignore initial whitespace */
501 /* All space is ASCII. All ASCII is 1 byte */
502 while ( ASCII_SPACE( *p ) ) {
507 return LDAP_INVALID_SYNTAX;
510 ber_str2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
512 assert( normalized->bv_val );
514 p = q = normalized->bv_val;
519 if ( ASCII_SPACE( *p ) ) {
524 /* Ignore the extra whitespace */
525 while ( ASCII_SPACE( *p ) ) {
529 len = LDAP_UTF8_COPY(q,p);
535 assert( normalized->bv_val < p );
536 assert( q+len <= p );
538 /* cannot start with a space */
539 assert( !ASCII_SPACE(normalized->bv_val[0]) );
542 * If the string ended in space, backup the pointer one
543 * position. One is enough because the above loop collapsed
544 * all whitespace to a single space.
551 /* cannot end with a space */
552 assert( !ASCII_SPACE( *q ) );
559 normalized->bv_len = q - normalized->bv_val;
564 /* Returns Unicode canonically normalized copy of a substring assertion
565 * Skipping attribute description */
566 static SubstringsAssertion *
567 UTF8SubstringsassertionNormalize(
568 SubstringsAssertion *sa,
571 SubstringsAssertion *nsa;
574 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
579 if( sa->sa_initial.bv_val != NULL ) {
580 ber_str2bv( UTF8normalize( &sa->sa_initial, casefold ), 0,
581 0, &nsa->sa_initial );
582 if( nsa->sa_initial.bv_val == NULL ) {
587 if( sa->sa_any != NULL ) {
588 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
591 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
592 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
593 ber_str2bv( UTF8normalize( &sa->sa_any[i], casefold ),
594 0, 0, &nsa->sa_any[i] );
595 if( nsa->sa_any[i].bv_val == NULL ) {
599 nsa->sa_any[i].bv_val = NULL;
602 if( sa->sa_final.bv_val != NULL ) {
603 ber_str2bv( UTF8normalize( &sa->sa_final, casefold ), 0,
605 if( nsa->sa_final.bv_val == NULL ) {
613 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
614 if ( nsa->sa_any )bvarray_free( nsa->sa_any );
615 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
620 /* Strip characters with the 8th bit set */
633 while( *++q & 0x80 ) {
636 p = memmove(p, q, strlen(q) + 1);
644 #ifndef SLAPD_APPROX_OLDSINGLESTRING
646 #if defined(SLAPD_APPROX_INITIALS)
647 #define SLAPD_APPROX_DELIMITER "._ "
648 #define SLAPD_APPROX_WORDLEN 2
650 #define SLAPD_APPROX_DELIMITER " "
651 #define SLAPD_APPROX_WORDLEN 1
660 struct berval *value,
661 void *assertedValue )
663 char *val, *nval, *assertv, **values, **words, *c;
664 int i, count, len, nextchunk=0, nextavail=0;
667 /* Yes, this is necessary */
668 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
673 strip8bitChars( nval );
675 /* Yes, this is necessary */
676 assertv = UTF8normalize( ((struct berval *)assertedValue),
678 if( assertv == NULL ) {
683 strip8bitChars( assertv );
684 avlen = strlen( assertv );
686 /* Isolate how many words there are */
687 for( c=nval,count=1; *c; c++ ) {
688 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
689 if ( c == NULL ) break;
694 /* Get a phonetic copy of each word */
695 words = (char **)ch_malloc( count * sizeof(char *) );
696 values = (char **)ch_malloc( count * sizeof(char *) );
697 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
699 values[i] = phonetic(c);
702 /* Work through the asserted value's words, to see if at least some
703 of the words are there, in the same order. */
705 while ( (size_t) nextchunk < avlen ) {
706 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
711 #if defined(SLAPD_APPROX_INITIALS)
712 else if( len == 1 ) {
713 /* Single letter words need to at least match one word's initial */
714 for( i=nextavail; i<count; i++ )
715 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
722 /* Isolate the next word in the asserted value and phonetic it */
723 assertv[nextchunk+len] = '\0';
724 val = phonetic( assertv + nextchunk );
726 /* See if this phonetic chunk is in the remaining words of *value */
727 for( i=nextavail; i<count; i++ ){
728 if( !strcmp( val, values[i] ) ){
736 /* This chunk in the asserted value was NOT within the *value. */
742 /* Go on to the next word in the asserted value */
746 /* If some of the words were seen, call it a match */
747 if( nextavail > 0 ) {
756 for( i=0; i<count; i++ ) {
757 ch_free( values[i] );
772 struct berval *prefix,
773 struct berval **values,
774 struct berval **keysp )
777 int i,j, len, wordcount, keycount=0;
778 struct berval *newkeys, *keys=NULL;
780 for( j=0; values[j] != NULL; j++ ) {
781 /* Yes, this is necessary */
782 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
783 strip8bitChars( val );
785 /* Isolate how many words there are. There will be a key for each */
786 for( wordcount=0,c=val; *c; c++) {
787 len = strcspn(c, SLAPD_APPROX_DELIMITER);
788 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
790 if (*c == '\0') break;
794 /* Allocate/increase storage to account for new keys */
795 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
796 * sizeof(struct berval) );
797 memcpy( newkeys, keys, keycount * sizeof(struct berval) );
798 if( keys ) ch_free( keys );
801 /* Get a phonetic copy of each word */
802 for( c=val,i=0; i<wordcount; c+=len+1 ) {
804 if( len < SLAPD_APPROX_WORDLEN ) continue;
805 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
812 keys[keycount].bv_val = NULL;
824 struct berval *prefix,
826 struct berval **keysp )
832 /* Yes, this is necessary */
833 val = UTF8normalize( ((struct berval *)assertValue),
836 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
837 keys[0].bv_val = NULL;
841 strip8bitChars( val );
843 /* Isolate how many words there are. There will be a key for each */
844 for( count=0,c=val; *c; c++) {
845 len = strcspn(c, SLAPD_APPROX_DELIMITER);
846 if( len >= SLAPD_APPROX_WORDLEN ) count++;
848 if (*c == '\0') break;
852 /* Allocate storage for new keys */
853 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
855 /* Get a phonetic copy of each word */
856 for( c=val,i=0; i<count; c+=len+1 ) {
858 if( len < SLAPD_APPROX_WORDLEN ) continue;
859 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
865 keys[count].bv_val = NULL;
873 /* No other form of Approximate Matching is defined */
881 struct berval *value,
882 void *assertedValue )
884 char *vapprox, *avapprox;
887 /* Yes, this is necessary */
888 s = UTF8normalize( value, UTF8_NOCASEFOLD );
894 /* Yes, this is necessary */
895 t = UTF8normalize( ((struct berval *)assertedValue),
903 vapprox = phonetic( strip8bitChars( s ) );
904 avapprox = phonetic( strip8bitChars( t ) );
909 *matchp = strcmp( vapprox, avapprox );
923 struct berval *prefix,
924 struct berval **values,
925 struct berval **keysp )
931 for( i=0; values[i] != NULL; i++ ) {
932 /* empty - just count them */
935 /* we should have at least one value at this point */
938 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
940 /* Copy each value and run it through phonetic() */
941 for( i=0; values[i] != NULL; i++ ) {
942 /* Yes, this is necessary */
943 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
945 /* strip 8-bit chars and run through phonetic() */
946 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
949 keys[i].bv_val = NULL;
962 struct berval *prefix,
964 struct berval **keysp )
969 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
971 /* Yes, this is necessary */
972 s = UTF8normalize( ((struct berval *)assertValue),
977 /* strip 8-bit chars and run through phonetic() */
978 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
995 struct berval *value,
996 void *assertedValue )
998 *matchp = UTF8normcmp( value->bv_val,
999 ((struct berval *) assertedValue)->bv_val,
1001 return LDAP_SUCCESS;
1005 caseExactIgnoreSubstringsMatch(
1010 struct berval *value,
1011 void *assertedValue )
1014 SubstringsAssertion *sub = NULL;
1018 char *nav, casefold;
1020 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1021 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1023 nav = UTF8normalize( value, casefold );
1029 left.bv_len = strlen( nav );
1031 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1037 /* Add up asserted input length */
1038 if( sub->sa_initial.bv_val ) {
1039 inlen += sub->sa_initial.bv_len;
1042 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1043 inlen += sub->sa_any[i].bv_len;
1046 if( sub->sa_final.bv_val ) {
1047 inlen += sub->sa_final.bv_len;
1050 if( sub->sa_initial.bv_val ) {
1051 if( inlen > left.bv_len ) {
1056 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
1057 sub->sa_initial.bv_len );
1063 left.bv_val += sub->sa_initial.bv_len;
1064 left.bv_len -= sub->sa_initial.bv_len;
1065 inlen -= sub->sa_initial.bv_len;
1068 if( sub->sa_final.bv_val ) {
1069 if( inlen > left.bv_len ) {
1074 match = strncmp( sub->sa_final.bv_val,
1075 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1076 sub->sa_final.bv_len );
1082 left.bv_len -= sub->sa_final.bv_len;
1083 inlen -= sub->sa_final.bv_len;
1087 for(i=0; sub->sa_any[i].bv_val; i++) {
1092 if( inlen > left.bv_len ) {
1093 /* not enough length */
1098 if( sub->sa_any[i].bv_len == 0 ) {
1102 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
1109 idx = p - left.bv_val;
1110 assert( idx < left.bv_len );
1112 if( idx >= left.bv_len ) {
1113 /* this shouldn't happen */
1115 if ( sub->sa_final.bv_val )
1116 ch_free( sub->sa_final.bv_val );
1118 bvarray_free( sub->sa_any );
1119 if ( sub->sa_initial.bv_val )
1120 ch_free( sub->sa_initial.bv_val );
1128 if( sub->sa_any[i].bv_len > left.bv_len ) {
1129 /* not enough left */
1134 match = strncmp( left.bv_val,
1135 sub->sa_any[i].bv_val,
1136 sub->sa_any[i].bv_len );
1144 left.bv_val += sub->sa_any[i].bv_len;
1145 left.bv_len -= sub->sa_any[i].bv_len;
1146 inlen -= sub->sa_any[i].bv_len;
1153 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1154 if ( sub->sa_any ) bvarray_free( sub->sa_any );
1155 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1159 return LDAP_SUCCESS;
1162 /* Index generation function */
1163 static int caseExactIgnoreIndexer(
1168 struct berval *prefix,
1169 struct berval **values,
1170 struct berval **keysp )
1175 struct berval *keys;
1176 HASH_CONTEXT HASHcontext;
1177 unsigned char HASHdigest[HASH_BYTES];
1178 struct berval digest;
1179 digest.bv_val = HASHdigest;
1180 digest.bv_len = sizeof(HASHdigest);
1182 for( i=0; values[i] != NULL; i++ ) {
1183 /* empty - just count them */
1186 /* we should have at least one value at this point */
1189 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1191 slen = syntax->ssyn_oidlen;
1192 mlen = mr->smr_oidlen;
1194 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1195 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1197 for( i=0; values[i] != NULL; i++ ) {
1198 struct berval value;
1199 ber_str2bv( UTF8normalize( values[i], casefold ), 0, 0,
1202 HASH_Init( &HASHcontext );
1203 if( prefix != NULL && prefix->bv_len > 0 ) {
1204 HASH_Update( &HASHcontext,
1205 prefix->bv_val, prefix->bv_len );
1207 HASH_Update( &HASHcontext,
1208 syntax->ssyn_oid, slen );
1209 HASH_Update( &HASHcontext,
1210 mr->smr_oid, mlen );
1211 HASH_Update( &HASHcontext,
1212 value.bv_val, value.bv_len );
1213 HASH_Final( HASHdigest, &HASHcontext );
1215 free( value.bv_val );
1217 ber_dupbv( &keys[i], &digest );
1220 keys[i].bv_val = NULL;
1222 return LDAP_SUCCESS;
1225 /* Index generation function */
1226 static int caseExactIgnoreFilter(
1231 struct berval *prefix,
1233 struct berval **keysp )
1237 struct berval *keys;
1238 HASH_CONTEXT HASHcontext;
1239 unsigned char HASHdigest[HASH_BYTES];
1240 struct berval value;
1241 struct berval digest;
1242 digest.bv_val = HASHdigest;
1243 digest.bv_len = sizeof(HASHdigest);
1245 slen = syntax->ssyn_oidlen;
1246 mlen = mr->smr_oidlen;
1248 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1249 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1251 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1253 /* This usually happens if filter contains bad UTF8 */
1254 if( value.bv_val == NULL ) {
1255 keys = ch_malloc( sizeof( struct berval ) );
1256 keys[0].bv_val = NULL;
1257 return LDAP_SUCCESS;
1260 keys = ch_malloc( sizeof( struct berval ) * 2 );
1262 HASH_Init( &HASHcontext );
1263 if( prefix != NULL && prefix->bv_len > 0 ) {
1264 HASH_Update( &HASHcontext,
1265 prefix->bv_val, prefix->bv_len );
1267 HASH_Update( &HASHcontext,
1268 syntax->ssyn_oid, slen );
1269 HASH_Update( &HASHcontext,
1270 mr->smr_oid, mlen );
1271 HASH_Update( &HASHcontext,
1272 value.bv_val, value.bv_len );
1273 HASH_Final( HASHdigest, &HASHcontext );
1275 ber_dupbv( keys, &digest );
1276 keys[1].bv_val = NULL;
1278 free( value.bv_val );
1281 return LDAP_SUCCESS;
1284 /* Substrings Index generation function */
1285 static int caseExactIgnoreSubstringsIndexer(
1290 struct berval *prefix,
1291 struct berval **values,
1292 struct berval **keysp )
1297 struct berval *keys;
1298 struct berval **nvalues;
1300 HASH_CONTEXT HASHcontext;
1301 unsigned char HASHdigest[HASH_BYTES];
1302 struct berval digest;
1303 digest.bv_val = HASHdigest;
1304 digest.bv_len = sizeof(HASHdigest);
1308 for( i=0; values[i] != NULL; i++ ) {
1309 /* empty - just count them */
1312 /* we should have at least one value at this point */
1315 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1316 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1318 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1319 for( i=0; values[i] != NULL; i++ ) {
1320 nvalues[i] = ber_str2bv( UTF8normalize( values[i], casefold ),
1326 for( i=0; values[i] != NULL; i++ ) {
1327 /* count number of indices to generate */
1328 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1332 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1333 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1334 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1335 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1337 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1341 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1342 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1343 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1347 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1348 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1349 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1350 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1352 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1358 /* no keys to generate */
1360 ber_bvecfree( nvalues );
1361 return LDAP_SUCCESS;
1364 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1366 slen = syntax->ssyn_oidlen;
1367 mlen = mr->smr_oidlen;
1370 for( i=0; values[i] != NULL; i++ ) {
1373 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1375 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1376 ( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1378 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1379 max = values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1381 for( j=0; j<max; j++ ) {
1382 HASH_Init( &HASHcontext );
1383 if( prefix != NULL && prefix->bv_len > 0 ) {
1384 HASH_Update( &HASHcontext,
1385 prefix->bv_val, prefix->bv_len );
1388 HASH_Update( &HASHcontext,
1389 &pre, sizeof( pre ) );
1390 HASH_Update( &HASHcontext,
1391 syntax->ssyn_oid, slen );
1392 HASH_Update( &HASHcontext,
1393 mr->smr_oid, mlen );
1394 HASH_Update( &HASHcontext,
1395 &values[i]->bv_val[j],
1396 SLAP_INDEX_SUBSTR_MAXLEN );
1397 HASH_Final( HASHdigest, &HASHcontext );
1399 ber_dupbv( &keys[nkeys++], &digest );
1403 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i]->bv_len
1404 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i]->bv_len;
1406 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1409 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1410 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1411 HASH_Init( &HASHcontext );
1412 if( prefix != NULL && prefix->bv_len > 0 ) {
1413 HASH_Update( &HASHcontext,
1414 prefix->bv_val, prefix->bv_len );
1416 HASH_Update( &HASHcontext,
1417 &pre, sizeof( pre ) );
1418 HASH_Update( &HASHcontext,
1419 syntax->ssyn_oid, slen );
1420 HASH_Update( &HASHcontext,
1421 mr->smr_oid, mlen );
1422 HASH_Update( &HASHcontext,
1423 values[i]->bv_val, j );
1424 HASH_Final( HASHdigest, &HASHcontext );
1426 ber_dupbv( &keys[nkeys++], &digest );
1429 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1430 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1431 HASH_Init( &HASHcontext );
1432 if( prefix != NULL && prefix->bv_len > 0 ) {
1433 HASH_Update( &HASHcontext,
1434 prefix->bv_val, prefix->bv_len );
1436 HASH_Update( &HASHcontext,
1437 &pre, sizeof( pre ) );
1438 HASH_Update( &HASHcontext,
1439 syntax->ssyn_oid, slen );
1440 HASH_Update( &HASHcontext,
1441 mr->smr_oid, mlen );
1442 HASH_Update( &HASHcontext,
1443 &values[i]->bv_val[values[i]->bv_len-j], j );
1444 HASH_Final( HASHdigest, &HASHcontext );
1446 ber_dupbv( &keys[nkeys++], &digest );
1454 keys[nkeys].bv_val = NULL;
1461 ber_bvecfree( nvalues );
1463 return LDAP_SUCCESS;
1466 static int caseExactIgnoreSubstringsFilter(
1471 struct berval *prefix,
1473 struct berval **keysp )
1475 SubstringsAssertion *sa;
1477 ber_len_t nkeys = 0;
1478 size_t slen, mlen, klen;
1479 struct berval *keys;
1480 HASH_CONTEXT HASHcontext;
1481 unsigned char HASHdigest[HASH_BYTES];
1482 struct berval *value;
1483 struct berval digest;
1485 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1486 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1488 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1491 return LDAP_SUCCESS;
1494 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1495 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1500 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1502 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1503 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1504 /* don't bother accounting for stepping */
1505 nkeys += sa->sa_any[i].bv_len -
1506 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1511 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1512 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1518 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1519 if ( sa->sa_any ) bvarray_free( sa->sa_any );
1520 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1523 return LDAP_SUCCESS;
1526 digest.bv_val = HASHdigest;
1527 digest.bv_len = sizeof(HASHdigest);
1529 slen = syntax->ssyn_oidlen;
1530 mlen = mr->smr_oidlen;
1532 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1535 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1536 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1538 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1539 value = &sa->sa_initial;
1541 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1542 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1544 HASH_Init( &HASHcontext );
1545 if( prefix != NULL && prefix->bv_len > 0 ) {
1546 HASH_Update( &HASHcontext,
1547 prefix->bv_val, prefix->bv_len );
1549 HASH_Update( &HASHcontext,
1550 &pre, sizeof( pre ) );
1551 HASH_Update( &HASHcontext,
1552 syntax->ssyn_oid, slen );
1553 HASH_Update( &HASHcontext,
1554 mr->smr_oid, mlen );
1555 HASH_Update( &HASHcontext,
1556 value->bv_val, klen );
1557 HASH_Final( HASHdigest, &HASHcontext );
1559 ber_dupbv( &keys[nkeys++], &digest );
1562 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1564 pre = SLAP_INDEX_SUBSTR_PREFIX;
1565 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1567 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1568 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1572 value = &sa->sa_any[i];
1575 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1576 j += SLAP_INDEX_SUBSTR_STEP )
1578 HASH_Init( &HASHcontext );
1579 if( prefix != NULL && prefix->bv_len > 0 ) {
1580 HASH_Update( &HASHcontext,
1581 prefix->bv_val, prefix->bv_len );
1583 HASH_Update( &HASHcontext,
1584 &pre, sizeof( pre ) );
1585 HASH_Update( &HASHcontext,
1586 syntax->ssyn_oid, slen );
1587 HASH_Update( &HASHcontext,
1588 mr->smr_oid, mlen );
1589 HASH_Update( &HASHcontext,
1590 &value->bv_val[j], klen );
1591 HASH_Final( HASHdigest, &HASHcontext );
1593 ber_dupbv( &keys[nkeys++], &digest );
1599 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1600 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1602 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1603 value = &sa->sa_final;
1605 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1606 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1608 HASH_Init( &HASHcontext );
1609 if( prefix != NULL && prefix->bv_len > 0 ) {
1610 HASH_Update( &HASHcontext,
1611 prefix->bv_val, prefix->bv_len );
1613 HASH_Update( &HASHcontext,
1614 &pre, sizeof( pre ) );
1615 HASH_Update( &HASHcontext,
1616 syntax->ssyn_oid, slen );
1617 HASH_Update( &HASHcontext,
1618 mr->smr_oid, mlen );
1619 HASH_Update( &HASHcontext,
1620 &value->bv_val[value->bv_len-klen], klen );
1621 HASH_Final( HASHdigest, &HASHcontext );
1623 ber_dupbv( &keys[nkeys++], &digest );
1627 keys[nkeys].bv_val = NULL;
1633 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1634 if ( sa->sa_any ) bvarray_free( sa->sa_any );
1635 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1638 return LDAP_SUCCESS;
1647 struct berval *value,
1648 void *assertedValue )
1650 *matchp = UTF8normcmp( value->bv_val,
1651 ((struct berval *) assertedValue)->bv_val,
1653 return LDAP_SUCCESS;
1659 struct berval *val )
1663 if( val->bv_len == 0 ) {
1664 /* disallow empty strings */
1665 return LDAP_INVALID_SYNTAX;
1668 if( OID_LEADCHAR(val->bv_val[0]) ) {
1670 for(i=1; i < val->bv_len; i++) {
1671 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1672 if( dot++ ) return 1;
1673 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1676 return LDAP_INVALID_SYNTAX;
1680 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1682 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1683 for(i=1; i < val->bv_len; i++) {
1684 if( !DESC_CHAR(val->bv_val[i] ) ) {
1685 return LDAP_INVALID_SYNTAX;
1689 return LDAP_SUCCESS;
1692 return LDAP_INVALID_SYNTAX;
1701 struct berval *value,
1702 void *assertedValue )
1705 int vsign=0, avsign=0;
1706 struct berval *asserted;
1707 ber_len_t vlen, avlen;
1710 /* Start off pessimistic */
1713 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1715 vlen = value->bv_len;
1717 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1718 /* empty -- skip spaces */
1720 else if ( *v == '+' ) {
1723 else if ( *v == '-' ) {
1726 else if ( ASCII_DIGIT(*v) ) {
1727 if ( vsign == 0 ) vsign = 1;
1735 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1737 asserted = (struct berval *) assertedValue;
1738 av = asserted->bv_val;
1739 avlen = asserted->bv_len;
1741 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1742 /* empty -- skip spaces */
1744 else if ( *av == '+' ) {
1747 else if ( *av == '-' ) {
1750 else if ( ASCII_DIGIT(*av) ) {
1751 if ( avsign == 0 ) avsign = 1;
1759 /* The two ?sign vars are now one of :
1760 -2 negative non-zero number
1762 0 0 collapse these three to 0
1764 +2 positive non-zero number
1766 if ( abs( vsign ) == 1 ) vsign = 0;
1767 if ( abs( avsign ) == 1 ) avsign = 0;
1769 if( vsign != avsign ) return LDAP_SUCCESS;
1771 /* Check the significant digits */
1772 while( vlen && avlen ) {
1773 if( *v != *av ) break;
1780 /* If all digits compared equal, the numbers are equal */
1781 if(( vlen == 0 ) && ( avlen == 0 )) {
1784 return LDAP_SUCCESS;
1790 struct berval *val )
1794 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1796 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1797 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1798 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1799 return LDAP_INVALID_SYNTAX;
1802 for( i=1; i < val->bv_len; i++ ) {
1803 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1806 return LDAP_SUCCESS;
1813 struct berval *normalized )
1823 /* Ignore leading spaces */
1824 while ( len && ( *p == ' ' )) {
1831 negative = ( *p == '-' );
1832 if(( *p == '-' ) || ( *p == '+' )) {
1838 /* Ignore leading zeros */
1839 while ( len && ( *p == '0' )) {
1844 /* If there are no non-zero digits left, the number is zero, otherwise
1845 allocate space for the number and copy it into the buffer */
1847 normalized->bv_val = ch_strdup("0");
1848 normalized->bv_len = 1;
1851 normalized->bv_len = len+negative;
1852 normalized->bv_val = ch_malloc( normalized->bv_len );
1854 normalized->bv_val[0] = '-';
1856 memcpy( normalized->bv_val + negative, p, len );
1859 return LDAP_SUCCESS;
1862 /* Index generation function */
1863 static int integerIndexer(
1868 struct berval *prefix,
1869 struct berval **values,
1870 struct berval **keysp )
1873 struct berval *keys;
1875 /* we should have at least one value at this point */
1876 assert( values != NULL && values[0] != NULL );
1878 for( i=0; values[i] != NULL; i++ ) {
1879 /* empty -- just count them */
1882 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1884 for( i=0; values[i] != NULL; i++ ) {
1885 integerNormalize( syntax, values[i], &keys[i] );
1888 keys[i].bv_val = NULL;
1890 return LDAP_SUCCESS;
1893 /* Index generation function */
1894 static int integerFilter(
1899 struct berval *prefix,
1901 struct berval **keysp )
1903 struct berval *keys;
1905 keys = ch_malloc( sizeof( struct berval ) * 2 );
1906 integerNormalize( syntax, assertValue, &keys[0] );
1907 keys[1].bv_val = NULL;
1910 return LDAP_SUCCESS;
1915 countryStringValidate(
1917 struct berval *val )
1919 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1921 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1922 return LDAP_INVALID_SYNTAX;
1924 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1925 return LDAP_INVALID_SYNTAX;
1928 return LDAP_SUCCESS;
1932 printableStringValidate(
1934 struct berval *val )
1938 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1940 for(i=0; i < val->bv_len; i++) {
1941 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1942 return LDAP_INVALID_SYNTAX;
1946 return LDAP_SUCCESS;
1950 printablesStringValidate(
1952 struct berval *val )
1956 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1958 for(i=0; i < val->bv_len; i++) {
1959 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1960 return LDAP_INVALID_SYNTAX;
1964 return LDAP_SUCCESS;
1970 struct berval *val )
1974 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1976 for(i=0; i < val->bv_len; i++) {
1977 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1980 return LDAP_SUCCESS;
1987 struct berval *normalized )
1993 /* Ignore initial whitespace */
1994 while ( ASCII_SPACE( *p ) ) {
1999 return LDAP_INVALID_SYNTAX;
2002 normalized->bv_val = ch_strdup( p );
2003 p = q = normalized->bv_val;
2006 if ( ASCII_SPACE( *p ) ) {
2009 /* Ignore the extra whitespace */
2010 while ( ASCII_SPACE( *p ) ) {
2018 assert( normalized->bv_val < p );
2021 /* cannot start with a space */
2022 assert( !ASCII_SPACE(*normalized->bv_val) );
2025 * If the string ended in space, backup the pointer one
2026 * position. One is enough because the above loop collapsed
2027 * all whitespace to a single space.
2030 if ( ASCII_SPACE( q[-1] ) ) {
2034 /* cannot end with a space */
2035 assert( !ASCII_SPACE( q[-1] ) );
2037 /* null terminate */
2040 normalized->bv_len = q - normalized->bv_val;
2042 return LDAP_SUCCESS;
2051 struct berval *value,
2052 void *assertedValue )
2054 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2057 match = strncmp( value->bv_val,
2058 ((struct berval *) assertedValue)->bv_val,
2063 return LDAP_SUCCESS;
2067 caseExactIA5SubstringsMatch(
2072 struct berval *value,
2073 void *assertedValue )
2076 SubstringsAssertion *sub = assertedValue;
2077 struct berval left = *value;
2081 /* Add up asserted input length */
2082 if( sub->sa_initial.bv_val ) {
2083 inlen += sub->sa_initial.bv_len;
2086 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2087 inlen += sub->sa_any[i].bv_len;
2090 if( sub->sa_final.bv_val ) {
2091 inlen += sub->sa_final.bv_len;
2094 if( sub->sa_initial.bv_val ) {
2095 if( inlen > left.bv_len ) {
2100 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2101 sub->sa_initial.bv_len );
2107 left.bv_val += sub->sa_initial.bv_len;
2108 left.bv_len -= sub->sa_initial.bv_len;
2109 inlen -= sub->sa_initial.bv_len;
2112 if( sub->sa_final.bv_val ) {
2113 if( inlen > left.bv_len ) {
2118 match = strncmp( sub->sa_final.bv_val,
2119 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2120 sub->sa_final.bv_len );
2126 left.bv_len -= sub->sa_final.bv_len;
2127 inlen -= sub->sa_final.bv_len;
2131 for(i=0; sub->sa_any[i].bv_val; i++) {
2136 if( inlen > left.bv_len ) {
2137 /* not enough length */
2142 if( sub->sa_any[i].bv_len == 0 ) {
2146 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2153 idx = p - left.bv_val;
2154 assert( idx < left.bv_len );
2156 if( idx >= left.bv_len ) {
2157 /* this shouldn't happen */
2164 if( sub->sa_any[i].bv_len > left.bv_len ) {
2165 /* not enough left */
2170 match = strncmp( left.bv_val,
2171 sub->sa_any[i].bv_val,
2172 sub->sa_any[i].bv_len );
2180 left.bv_val += sub->sa_any[i].bv_len;
2181 left.bv_len -= sub->sa_any[i].bv_len;
2182 inlen -= sub->sa_any[i].bv_len;
2188 return LDAP_SUCCESS;
2191 /* Index generation function */
2192 static int caseExactIA5Indexer(
2197 struct berval *prefix,
2198 struct berval **values,
2199 struct berval **keysp )
2203 struct berval *keys;
2204 HASH_CONTEXT HASHcontext;
2205 unsigned char HASHdigest[HASH_BYTES];
2206 struct berval digest;
2207 digest.bv_val = HASHdigest;
2208 digest.bv_len = sizeof(HASHdigest);
2210 for( i=0; values[i] != NULL; i++ ) {
2211 /* empty - just count them */
2214 /* we should have at least one value at this point */
2217 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2219 slen = syntax->ssyn_oidlen;
2220 mlen = mr->smr_oidlen;
2222 for( i=0; values[i] != NULL; i++ ) {
2223 struct berval *value = values[i];
2225 HASH_Init( &HASHcontext );
2226 if( prefix != NULL && prefix->bv_len > 0 ) {
2227 HASH_Update( &HASHcontext,
2228 prefix->bv_val, prefix->bv_len );
2230 HASH_Update( &HASHcontext,
2231 syntax->ssyn_oid, slen );
2232 HASH_Update( &HASHcontext,
2233 mr->smr_oid, mlen );
2234 HASH_Update( &HASHcontext,
2235 value->bv_val, value->bv_len );
2236 HASH_Final( HASHdigest, &HASHcontext );
2238 ber_dupbv( &keys[i], &digest );
2241 keys[i].bv_val = NULL;
2243 return LDAP_SUCCESS;
2246 /* Index generation function */
2247 static int caseExactIA5Filter(
2252 struct berval *prefix,
2254 struct berval **keysp )
2257 struct berval *keys;
2258 HASH_CONTEXT HASHcontext;
2259 unsigned char HASHdigest[HASH_BYTES];
2260 struct berval *value;
2261 struct berval digest;
2262 digest.bv_val = HASHdigest;
2263 digest.bv_len = sizeof(HASHdigest);
2265 slen = syntax->ssyn_oidlen;
2266 mlen = mr->smr_oidlen;
2268 value = (struct berval *) assertValue;
2270 keys = ch_malloc( sizeof( struct berval ) * 2 );
2272 HASH_Init( &HASHcontext );
2273 if( prefix != NULL && prefix->bv_len > 0 ) {
2274 HASH_Update( &HASHcontext,
2275 prefix->bv_val, prefix->bv_len );
2277 HASH_Update( &HASHcontext,
2278 syntax->ssyn_oid, slen );
2279 HASH_Update( &HASHcontext,
2280 mr->smr_oid, mlen );
2281 HASH_Update( &HASHcontext,
2282 value->bv_val, value->bv_len );
2283 HASH_Final( HASHdigest, &HASHcontext );
2285 ber_dupbv( &keys[0], &digest );
2286 keys[1].bv_val = NULL;
2289 return LDAP_SUCCESS;
2292 /* Substrings Index generation function */
2293 static int caseExactIA5SubstringsIndexer(
2298 struct berval *prefix,
2299 struct berval **values,
2300 struct berval **keysp )
2304 struct berval *keys;
2305 HASH_CONTEXT HASHcontext;
2306 unsigned char HASHdigest[HASH_BYTES];
2307 struct berval digest;
2308 digest.bv_val = HASHdigest;
2309 digest.bv_len = sizeof(HASHdigest);
2311 /* we should have at least one value at this point */
2312 assert( values != NULL && values[0] != NULL );
2315 for( i=0; values[i] != NULL; i++ ) {
2316 /* count number of indices to generate */
2317 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2321 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2322 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2323 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2324 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2326 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2330 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2331 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2332 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2336 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2337 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2338 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2339 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2341 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2347 /* no keys to generate */
2349 return LDAP_SUCCESS;
2352 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2354 slen = syntax->ssyn_oidlen;
2355 mlen = mr->smr_oidlen;
2358 for( i=0; values[i] != NULL; i++ ) {
2360 struct berval *value;
2363 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2365 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2366 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2368 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2369 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2371 for( j=0; j<max; j++ ) {
2372 HASH_Init( &HASHcontext );
2373 if( prefix != NULL && prefix->bv_len > 0 ) {
2374 HASH_Update( &HASHcontext,
2375 prefix->bv_val, prefix->bv_len );
2378 HASH_Update( &HASHcontext,
2379 &pre, sizeof( pre ) );
2380 HASH_Update( &HASHcontext,
2381 syntax->ssyn_oid, slen );
2382 HASH_Update( &HASHcontext,
2383 mr->smr_oid, mlen );
2384 HASH_Update( &HASHcontext,
2386 SLAP_INDEX_SUBSTR_MAXLEN );
2387 HASH_Final( HASHdigest, &HASHcontext );
2389 ber_dupbv( &keys[nkeys++], &digest );
2393 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2394 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2396 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2399 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2400 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2401 HASH_Init( &HASHcontext );
2402 if( prefix != NULL && prefix->bv_len > 0 ) {
2403 HASH_Update( &HASHcontext,
2404 prefix->bv_val, prefix->bv_len );
2406 HASH_Update( &HASHcontext,
2407 &pre, sizeof( pre ) );
2408 HASH_Update( &HASHcontext,
2409 syntax->ssyn_oid, slen );
2410 HASH_Update( &HASHcontext,
2411 mr->smr_oid, mlen );
2412 HASH_Update( &HASHcontext,
2414 HASH_Final( HASHdigest, &HASHcontext );
2416 ber_dupbv( &keys[nkeys++], &digest );
2419 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2420 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2421 HASH_Init( &HASHcontext );
2422 if( prefix != NULL && prefix->bv_len > 0 ) {
2423 HASH_Update( &HASHcontext,
2424 prefix->bv_val, prefix->bv_len );
2426 HASH_Update( &HASHcontext,
2427 &pre, sizeof( pre ) );
2428 HASH_Update( &HASHcontext,
2429 syntax->ssyn_oid, slen );
2430 HASH_Update( &HASHcontext,
2431 mr->smr_oid, mlen );
2432 HASH_Update( &HASHcontext,
2433 &value->bv_val[value->bv_len-j], j );
2434 HASH_Final( HASHdigest, &HASHcontext );
2436 ber_dupbv( &keys[nkeys++], &digest );
2443 keys[nkeys].bv_val = NULL;
2450 return LDAP_SUCCESS;
2453 static int caseExactIA5SubstringsFilter(
2458 struct berval *prefix,
2460 struct berval **keysp )
2462 SubstringsAssertion *sa = assertValue;
2464 ber_len_t nkeys = 0;
2465 size_t slen, mlen, klen;
2466 struct berval *keys;
2467 HASH_CONTEXT HASHcontext;
2468 unsigned char HASHdigest[HASH_BYTES];
2469 struct berval *value;
2470 struct berval digest;
2472 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2473 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2478 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2480 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2481 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2482 /* don't bother accounting for stepping */
2483 nkeys += sa->sa_any[i].bv_len -
2484 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2489 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2490 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2497 return LDAP_SUCCESS;
2500 digest.bv_val = HASHdigest;
2501 digest.bv_len = sizeof(HASHdigest);
2503 slen = syntax->ssyn_oidlen;
2504 mlen = mr->smr_oidlen;
2506 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2509 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2510 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2512 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2513 value = &sa->sa_initial;
2515 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2516 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2518 HASH_Init( &HASHcontext );
2519 if( prefix != NULL && prefix->bv_len > 0 ) {
2520 HASH_Update( &HASHcontext,
2521 prefix->bv_val, prefix->bv_len );
2523 HASH_Update( &HASHcontext,
2524 &pre, sizeof( pre ) );
2525 HASH_Update( &HASHcontext,
2526 syntax->ssyn_oid, slen );
2527 HASH_Update( &HASHcontext,
2528 mr->smr_oid, mlen );
2529 HASH_Update( &HASHcontext,
2530 value->bv_val, klen );
2531 HASH_Final( HASHdigest, &HASHcontext );
2533 ber_dupbv( &keys[nkeys++], &digest );
2536 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2538 pre = SLAP_INDEX_SUBSTR_PREFIX;
2539 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2541 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2542 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2546 value = &sa->sa_any[i];
2549 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2550 j += SLAP_INDEX_SUBSTR_STEP )
2552 HASH_Init( &HASHcontext );
2553 if( prefix != NULL && prefix->bv_len > 0 ) {
2554 HASH_Update( &HASHcontext,
2555 prefix->bv_val, prefix->bv_len );
2557 HASH_Update( &HASHcontext,
2558 &pre, sizeof( pre ) );
2559 HASH_Update( &HASHcontext,
2560 syntax->ssyn_oid, slen );
2561 HASH_Update( &HASHcontext,
2562 mr->smr_oid, mlen );
2563 HASH_Update( &HASHcontext,
2564 &value->bv_val[j], klen );
2565 HASH_Final( HASHdigest, &HASHcontext );
2567 ber_dupbv( &keys[nkeys++], &digest );
2572 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2573 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2575 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2576 value = &sa->sa_final;
2578 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2579 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2581 HASH_Init( &HASHcontext );
2582 if( prefix != NULL && prefix->bv_len > 0 ) {
2583 HASH_Update( &HASHcontext,
2584 prefix->bv_val, prefix->bv_len );
2586 HASH_Update( &HASHcontext,
2587 &pre, sizeof( pre ) );
2588 HASH_Update( &HASHcontext,
2589 syntax->ssyn_oid, slen );
2590 HASH_Update( &HASHcontext,
2591 mr->smr_oid, mlen );
2592 HASH_Update( &HASHcontext,
2593 &value->bv_val[value->bv_len-klen], klen );
2594 HASH_Final( HASHdigest, &HASHcontext );
2596 ber_dupbv( &keys[nkeys++], &digest );
2600 keys[nkeys].bv_val = NULL;
2607 return LDAP_SUCCESS;
2616 struct berval *value,
2617 void *assertedValue )
2619 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2621 if( match == 0 && value->bv_len ) {
2622 match = strncasecmp( value->bv_val,
2623 ((struct berval *) assertedValue)->bv_val,
2628 return LDAP_SUCCESS;
2632 caseIgnoreIA5SubstringsMatch(
2637 struct berval *value,
2638 void *assertedValue )
2641 SubstringsAssertion *sub = assertedValue;
2642 struct berval left = *value;
2646 /* Add up asserted input length */
2647 if( sub->sa_initial.bv_val ) {
2648 inlen += sub->sa_initial.bv_len;
2651 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2652 inlen += sub->sa_any[i].bv_len;
2655 if( sub->sa_final.bv_val ) {
2656 inlen += sub->sa_final.bv_len;
2659 if( sub->sa_initial.bv_val ) {
2660 if( inlen > left.bv_len ) {
2665 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2666 sub->sa_initial.bv_len );
2672 left.bv_val += sub->sa_initial.bv_len;
2673 left.bv_len -= sub->sa_initial.bv_len;
2674 inlen -= sub->sa_initial.bv_len;
2677 if( sub->sa_final.bv_val ) {
2678 if( inlen > left.bv_len ) {
2683 match = strncasecmp( sub->sa_final.bv_val,
2684 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2685 sub->sa_final.bv_len );
2691 left.bv_len -= sub->sa_final.bv_len;
2692 inlen -= sub->sa_final.bv_len;
2696 for(i=0; sub->sa_any[i].bv_val; i++) {
2701 if( inlen > left.bv_len ) {
2702 /* not enough length */
2707 if( sub->sa_any[i].bv_len == 0 ) {
2711 p = strcasechr( left.bv_val, *sub->sa_any[i].bv_val );
2718 idx = p - left.bv_val;
2719 assert( idx < left.bv_len );
2721 if( idx >= left.bv_len ) {
2722 /* this shouldn't happen */
2729 if( sub->sa_any[i].bv_len > left.bv_len ) {
2730 /* not enough left */
2735 match = strncasecmp( left.bv_val,
2736 sub->sa_any[i].bv_val,
2737 sub->sa_any[i].bv_len );
2746 left.bv_val += sub->sa_any[i].bv_len;
2747 left.bv_len -= sub->sa_any[i].bv_len;
2748 inlen -= sub->sa_any[i].bv_len;
2754 return LDAP_SUCCESS;
2757 /* Index generation function */
2758 static int caseIgnoreIA5Indexer(
2763 struct berval *prefix,
2764 struct berval **values,
2765 struct berval **keysp )
2769 struct berval *keys;
2770 HASH_CONTEXT HASHcontext;
2771 unsigned char HASHdigest[HASH_BYTES];
2772 struct berval digest;
2773 digest.bv_val = HASHdigest;
2774 digest.bv_len = sizeof(HASHdigest);
2776 /* we should have at least one value at this point */
2777 assert( values != NULL && values[0] != NULL );
2779 for( i=0; values[i] != NULL; i++ ) {
2780 /* just count them */
2783 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2785 slen = syntax->ssyn_oidlen;
2786 mlen = mr->smr_oidlen;
2788 for( i=0; values[i] != NULL; i++ ) {
2789 struct berval value;
2790 ber_dupbv( &value, values[i] );
2791 ldap_pvt_str2upper( value.bv_val );
2793 HASH_Init( &HASHcontext );
2794 if( prefix != NULL && prefix->bv_len > 0 ) {
2795 HASH_Update( &HASHcontext,
2796 prefix->bv_val, prefix->bv_len );
2798 HASH_Update( &HASHcontext,
2799 syntax->ssyn_oid, slen );
2800 HASH_Update( &HASHcontext,
2801 mr->smr_oid, mlen );
2802 HASH_Update( &HASHcontext,
2803 value.bv_val, value.bv_len );
2804 HASH_Final( HASHdigest, &HASHcontext );
2806 free( value.bv_val );
2808 ber_dupbv( &keys[i], &digest );
2811 keys[i].bv_val = NULL;
2813 return LDAP_SUCCESS;
2816 /* Index generation function */
2817 static int caseIgnoreIA5Filter(
2822 struct berval *prefix,
2824 struct berval **keysp )
2827 struct berval *keys;
2828 HASH_CONTEXT HASHcontext;
2829 unsigned char HASHdigest[HASH_BYTES];
2830 struct berval value;
2831 struct berval digest;
2832 digest.bv_val = HASHdigest;
2833 digest.bv_len = sizeof(HASHdigest);
2835 slen = syntax->ssyn_oidlen;
2836 mlen = mr->smr_oidlen;
2838 ber_dupbv( &value, (struct berval *) assertValue );
2839 ldap_pvt_str2upper( value.bv_val );
2841 keys = ch_malloc( sizeof( struct berval ) * 2 );
2843 HASH_Init( &HASHcontext );
2844 if( prefix != NULL && prefix->bv_len > 0 ) {
2845 HASH_Update( &HASHcontext,
2846 prefix->bv_val, prefix->bv_len );
2848 HASH_Update( &HASHcontext,
2849 syntax->ssyn_oid, slen );
2850 HASH_Update( &HASHcontext,
2851 mr->smr_oid, mlen );
2852 HASH_Update( &HASHcontext,
2853 value.bv_val, value.bv_len );
2854 HASH_Final( HASHdigest, &HASHcontext );
2856 ber_dupbv( &keys[0], &digest );
2857 keys[1].bv_val = NULL;
2859 free( value.bv_val );
2863 return LDAP_SUCCESS;
2866 /* Substrings Index generation function */
2867 static int caseIgnoreIA5SubstringsIndexer(
2872 struct berval *prefix,
2873 struct berval **values,
2874 struct berval **keysp )
2878 struct berval *keys;
2879 HASH_CONTEXT HASHcontext;
2880 unsigned char HASHdigest[HASH_BYTES];
2881 struct berval digest;
2882 digest.bv_val = HASHdigest;
2883 digest.bv_len = sizeof(HASHdigest);
2885 /* we should have at least one value at this point */
2886 assert( values != NULL && values[0] != NULL );
2889 for( i=0; values[i] != NULL; i++ ) {
2890 /* count number of indices to generate */
2891 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2895 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2896 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2897 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2898 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2900 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2904 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2905 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2906 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2910 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2911 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2912 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2913 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2915 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2921 /* no keys to generate */
2923 return LDAP_SUCCESS;
2926 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2928 slen = syntax->ssyn_oidlen;
2929 mlen = mr->smr_oidlen;
2932 for( i=0; values[i] != NULL; i++ ) {
2934 struct berval value;
2936 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2938 ber_dupbv( &value, values[i] );
2939 ldap_pvt_str2upper( value.bv_val );
2941 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2942 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2944 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2945 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2947 for( j=0; j<max; j++ ) {
2948 HASH_Init( &HASHcontext );
2949 if( prefix != NULL && prefix->bv_len > 0 ) {
2950 HASH_Update( &HASHcontext,
2951 prefix->bv_val, prefix->bv_len );
2954 HASH_Update( &HASHcontext,
2955 &pre, sizeof( pre ) );
2956 HASH_Update( &HASHcontext,
2957 syntax->ssyn_oid, slen );
2958 HASH_Update( &HASHcontext,
2959 mr->smr_oid, mlen );
2960 HASH_Update( &HASHcontext,
2962 SLAP_INDEX_SUBSTR_MAXLEN );
2963 HASH_Final( HASHdigest, &HASHcontext );
2965 ber_dupbv( &keys[nkeys++], &digest );
2969 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2970 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2972 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2975 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2976 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2977 HASH_Init( &HASHcontext );
2978 if( prefix != NULL && prefix->bv_len > 0 ) {
2979 HASH_Update( &HASHcontext,
2980 prefix->bv_val, prefix->bv_len );
2982 HASH_Update( &HASHcontext,
2983 &pre, sizeof( pre ) );
2984 HASH_Update( &HASHcontext,
2985 syntax->ssyn_oid, slen );
2986 HASH_Update( &HASHcontext,
2987 mr->smr_oid, mlen );
2988 HASH_Update( &HASHcontext,
2990 HASH_Final( HASHdigest, &HASHcontext );
2992 ber_dupbv( &keys[nkeys++], &digest );
2995 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2996 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2997 HASH_Init( &HASHcontext );
2998 if( prefix != NULL && prefix->bv_len > 0 ) {
2999 HASH_Update( &HASHcontext,
3000 prefix->bv_val, prefix->bv_len );
3002 HASH_Update( &HASHcontext,
3003 &pre, sizeof( pre ) );
3004 HASH_Update( &HASHcontext,
3005 syntax->ssyn_oid, slen );
3006 HASH_Update( &HASHcontext,
3007 mr->smr_oid, mlen );
3008 HASH_Update( &HASHcontext,
3009 &value.bv_val[value.bv_len-j], j );
3010 HASH_Final( HASHdigest, &HASHcontext );
3012 ber_dupbv( &keys[nkeys++], &digest );
3017 free( value.bv_val );
3021 keys[nkeys].bv_val = NULL;
3028 return LDAP_SUCCESS;
3031 static int caseIgnoreIA5SubstringsFilter(
3036 struct berval *prefix,
3038 struct berval **keysp )
3040 SubstringsAssertion *sa = assertValue;
3042 ber_len_t nkeys = 0;
3043 size_t slen, mlen, klen;
3044 struct berval *keys;
3045 HASH_CONTEXT HASHcontext;
3046 unsigned char HASHdigest[HASH_BYTES];
3047 struct berval value;
3048 struct berval digest;
3050 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3051 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3056 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3058 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3059 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3060 /* don't bother accounting for stepping */
3061 nkeys += sa->sa_any[i].bv_len -
3062 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3067 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3068 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3075 return LDAP_SUCCESS;
3078 digest.bv_val = HASHdigest;
3079 digest.bv_len = sizeof(HASHdigest);
3081 slen = syntax->ssyn_oidlen;
3082 mlen = mr->smr_oidlen;
3084 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3087 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3088 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3090 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3091 ber_dupbv( &value, &sa->sa_initial );
3092 ldap_pvt_str2upper( value.bv_val );
3094 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3095 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3097 HASH_Init( &HASHcontext );
3098 if( prefix != NULL && prefix->bv_len > 0 ) {
3099 HASH_Update( &HASHcontext,
3100 prefix->bv_val, prefix->bv_len );
3102 HASH_Update( &HASHcontext,
3103 &pre, sizeof( pre ) );
3104 HASH_Update( &HASHcontext,
3105 syntax->ssyn_oid, slen );
3106 HASH_Update( &HASHcontext,
3107 mr->smr_oid, mlen );
3108 HASH_Update( &HASHcontext,
3109 value.bv_val, klen );
3110 HASH_Final( HASHdigest, &HASHcontext );
3112 free( value.bv_val );
3113 ber_dupbv( &keys[nkeys++], &digest );
3116 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3118 pre = SLAP_INDEX_SUBSTR_PREFIX;
3119 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3121 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3122 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3126 ber_dupbv( &value, &sa->sa_any[i] );
3127 ldap_pvt_str2upper( value.bv_val );
3130 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3131 j += SLAP_INDEX_SUBSTR_STEP )
3133 HASH_Init( &HASHcontext );
3134 if( prefix != NULL && prefix->bv_len > 0 ) {
3135 HASH_Update( &HASHcontext,
3136 prefix->bv_val, prefix->bv_len );
3138 HASH_Update( &HASHcontext,
3139 &pre, sizeof( pre ) );
3140 HASH_Update( &HASHcontext,
3141 syntax->ssyn_oid, slen );
3142 HASH_Update( &HASHcontext,
3143 mr->smr_oid, mlen );
3144 HASH_Update( &HASHcontext,
3145 &value.bv_val[j], klen );
3146 HASH_Final( HASHdigest, &HASHcontext );
3148 ber_dupbv( &keys[nkeys++], &digest );
3151 free( value.bv_val );
3155 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3156 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3158 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3159 ber_dupbv( &value, &sa->sa_final );
3160 ldap_pvt_str2upper( value.bv_val );
3162 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3163 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3165 HASH_Init( &HASHcontext );
3166 if( prefix != NULL && prefix->bv_len > 0 ) {
3167 HASH_Update( &HASHcontext,
3168 prefix->bv_val, prefix->bv_len );
3170 HASH_Update( &HASHcontext,
3171 &pre, sizeof( pre ) );
3172 HASH_Update( &HASHcontext,
3173 syntax->ssyn_oid, slen );
3174 HASH_Update( &HASHcontext,
3175 mr->smr_oid, mlen );
3176 HASH_Update( &HASHcontext,
3177 &value.bv_val[value.bv_len-klen], klen );
3178 HASH_Final( HASHdigest, &HASHcontext );
3180 free( value.bv_val );
3181 ber_dupbv( &keys[nkeys++], &digest );
3185 keys[nkeys].bv_val = NULL;
3192 return LDAP_SUCCESS;
3196 numericStringValidate(
3202 for(i=0; i < in->bv_len; i++) {
3203 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3204 return LDAP_INVALID_SYNTAX;
3208 return LDAP_SUCCESS;
3212 numericStringNormalize(
3215 struct berval *normalized )
3217 /* removal all spaces */
3220 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3223 q = normalized->bv_val;
3226 if ( ASCII_SPACE( *p ) ) {
3227 /* Ignore whitespace */
3234 /* we should have copied no more then is in val */
3235 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3237 /* null terminate */
3240 normalized->bv_len = q - normalized->bv_val;
3242 return LDAP_SUCCESS;
3246 objectIdentifierFirstComponentMatch(
3251 struct berval *value,
3252 void *assertedValue )
3254 int rc = LDAP_SUCCESS;
3256 struct berval *asserted = (struct berval *) assertedValue;
3260 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3261 return LDAP_INVALID_SYNTAX;
3264 /* trim leading white space */
3265 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3269 /* grab next word */
3270 oid.bv_val = &value->bv_val[i];
3271 oid.bv_len = value->bv_len - i;
3272 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3277 /* insert attributeTypes, objectclass check here */
3278 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3279 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3282 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3283 MatchingRule *asserted_mr = mr_bvfind( asserted );
3284 MatchingRule *stored_mr = mr_bvfind( &oid );
3286 if( asserted_mr == NULL ) {
3287 rc = SLAPD_COMPARE_UNDEFINED;
3289 match = asserted_mr != stored_mr;
3292 } else if ( !strcmp( syntax->ssyn_oid,
3293 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3295 AttributeType *asserted_at = at_bvfind( asserted );
3296 AttributeType *stored_at = at_bvfind( &oid );
3298 if( asserted_at == NULL ) {
3299 rc = SLAPD_COMPARE_UNDEFINED;
3301 match = asserted_at != stored_at;
3304 } else if ( !strcmp( syntax->ssyn_oid,
3305 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3307 ObjectClass *asserted_oc = oc_bvfind( asserted );
3308 ObjectClass *stored_oc = oc_bvfind( &oid );
3310 if( asserted_oc == NULL ) {
3311 rc = SLAPD_COMPARE_UNDEFINED;
3313 match = asserted_oc != stored_oc;
3319 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3320 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3321 match, value->bv_val, asserted->bv_val ));
3323 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3324 "%d\n\t\"%s\"\n\t\"%s\"\n",
3325 match, value->bv_val, asserted->bv_val );
3329 if( rc == LDAP_SUCCESS ) *matchp = match;
3339 struct berval *value,
3340 void *assertedValue )
3342 long lValue, lAssertedValue;
3344 /* safe to assume integers are NUL terminated? */
3345 lValue = strtoul(value->bv_val, NULL, 10);
3346 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3347 return LDAP_CONSTRAINT_VIOLATION;
3349 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3350 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3351 return LDAP_CONSTRAINT_VIOLATION;
3353 *matchp = (lValue & lAssertedValue);
3354 return LDAP_SUCCESS;
3363 struct berval *value,
3364 void *assertedValue )
3366 long lValue, lAssertedValue;
3368 /* safe to assume integers are NUL terminated? */
3369 lValue = strtoul(value->bv_val, NULL, 10);
3370 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3371 return LDAP_CONSTRAINT_VIOLATION;
3373 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3374 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3375 return LDAP_CONSTRAINT_VIOLATION;
3377 *matchp = (lValue | lAssertedValue);
3378 return LDAP_SUCCESS;
3382 #include <openssl/x509.h>
3383 #include <openssl/err.h>
3384 char digit[] = "0123456789";
3387 * Next function returns a string representation of a ASN1_INTEGER.
3388 * It works for unlimited lengths.
3391 static struct berval *
3392 asn1_integer2str(ASN1_INTEGER *a)
3397 /* We work backwards, make it fill from the end of buf */
3398 p = buf + sizeof(buf) - 1;
3401 if ( a == NULL || a->length == 0 ) {
3409 /* We want to preserve the original */
3410 copy = ch_malloc(n*sizeof(unsigned int));
3411 for (i = 0; i<n; i++) {
3412 copy[i] = a->data[i];
3416 * base indicates the index of the most significant
3417 * byte that might be nonzero. When it goes off the
3418 * end, we now there is nothing left to do.
3424 for (i = base; i<n; i++ ) {
3425 copy[i] += carry*256;
3426 carry = copy[i] % 10;
3431 * Way too large, we need to leave
3432 * room for sign if negative
3437 *--p = digit[carry];
3438 if (copy[base] == 0)
3444 if ( a->type == V_ASN1_NEG_INTEGER ) {
3448 return ber_bvstrdup(p);
3451 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3452 static struct berval *
3453 dn_openssl2ldap(X509_NAME *name)
3455 char issuer_dn[1024];
3458 bio = BIO_new(BIO_s_mem());
3461 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3462 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3463 ERR_error_string(ERR_get_error(),NULL)));
3465 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3466 "error creating BIO: %s\n",
3467 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3471 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3473 BIO_gets(bio, issuer_dn, 1024);
3476 return ber_bvstrdup(issuer_dn);
3480 * Given a certificate in DER format, extract the corresponding
3481 * assertion value for certificateExactMatch
3484 certificateExactConvert(
3486 struct berval * out )
3489 unsigned char *p = in->bv_val;
3490 struct berval *serial;
3491 struct berval *issuer_dn;
3492 struct berval *bv_tmp;
3494 xcert = d2i_X509(NULL, &p, in->bv_len);
3497 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3498 "certificateExactConvert: error parsing cert: %s\n",
3499 ERR_error_string(ERR_get_error(),NULL)));
3501 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3502 "error parsing cert: %s\n",
3503 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3505 return LDAP_INVALID_SYNTAX;
3508 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3511 return LDAP_INVALID_SYNTAX;
3513 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3517 return LDAP_INVALID_SYNTAX;
3519 /* Actually, dn_openssl2ldap returns in a normalized format, but
3520 it is different from our normalized format */
3522 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3526 return LDAP_INVALID_SYNTAX;
3532 out->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3533 out->bv_val = ch_malloc(out->bv_len);
3535 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3536 p += serial->bv_len;
3537 AC_MEMCPY(p, " $ ", 3);
3539 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3540 p += issuer_dn->bv_len;
3544 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3545 "certificateExactConvert: \n %s\n",
3548 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3550 out->bv_val, NULL, NULL );
3554 ber_bvfree(issuer_dn);
3556 return LDAP_SUCCESS;
3560 serial_and_issuer_parse(
3561 struct berval *assertion,
3562 struct berval **serial,
3563 struct berval **issuer_dn
3571 begin = assertion->bv_val;
3572 end = assertion->bv_val+assertion->bv_len-1;
3573 for (p=begin; p<=end && *p != '$'; p++)
3576 return LDAP_INVALID_SYNTAX;
3578 /* p now points at the $ sign, now use begin and end to delimit the
3580 while (ASCII_SPACE(*begin))
3583 while (ASCII_SPACE(*end))
3586 bv.bv_len = end-begin+1;
3588 *serial = ber_bvdup(&bv);
3590 /* now extract the issuer, remember p was at the dollar sign */
3592 end = assertion->bv_val+assertion->bv_len-1;
3593 while (ASCII_SPACE(*begin))
3595 /* should we trim spaces at the end too? is it safe always? */
3597 bv.bv_len = end-begin+1;
3599 dnNormalize( NULL, &bv, issuer_dn );
3601 return LDAP_SUCCESS;
3605 certificateExactMatch(
3610 struct berval *value,
3611 void *assertedValue )
3614 unsigned char *p = value->bv_val;
3615 struct berval *serial;
3616 struct berval *issuer_dn;
3617 struct berval *asserted_serial;
3618 struct berval *asserted_issuer_dn;
3621 xcert = d2i_X509(NULL, &p, value->bv_len);
3624 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3625 "certificateExactMatch: error parsing cert: %s\n",
3626 ERR_error_string(ERR_get_error(),NULL)));
3628 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3629 "error parsing cert: %s\n",
3630 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3632 return LDAP_INVALID_SYNTAX;
3635 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3636 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3640 serial_and_issuer_parse(assertedValue,
3642 &asserted_issuer_dn);
3647 slap_schema.si_syn_integer,
3648 slap_schema.si_mr_integerMatch,
3651 if ( ret == LDAP_SUCCESS ) {
3652 if ( *matchp == 0 ) {
3653 /* We need to normalize everything for dnMatch */
3657 slap_schema.si_syn_distinguishedName,
3658 slap_schema.si_mr_distinguishedNameMatch,
3660 asserted_issuer_dn);
3665 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3666 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3667 *matchp, serial->bv_val, issuer_dn->bv_val,
3668 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3670 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3671 "%d\n\t\"%s $ %s\"\n",
3672 *matchp, serial->bv_val, issuer_dn->bv_val );
3673 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3674 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3679 ber_bvfree(issuer_dn);
3680 ber_bvfree(asserted_serial);
3681 ber_bvfree(asserted_issuer_dn);
3687 * Index generation function
3688 * We just index the serials, in most scenarios the issuer DN is one of
3689 * a very small set of values.
3691 static int certificateExactIndexer(
3696 struct berval *prefix,
3697 struct berval **values,
3698 struct berval **keysp )
3701 struct berval *keys;
3704 struct berval * serial;
3706 /* we should have at least one value at this point */
3707 assert( values != NULL && values[0] != NULL );
3709 for( i=0; values[i] != NULL; i++ ) {
3710 /* empty -- just count them */
3713 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3715 for( i=0; values[i] != NULL; i++ ) {
3716 p = values[i]->bv_val;
3717 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
3720 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3721 "certificateExactIndexer: error parsing cert: %s\n",
3722 ERR_error_string(ERR_get_error(),NULL)));
3724 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3725 "error parsing cert: %s\n",
3726 ERR_error_string(ERR_get_error(),NULL),
3729 /* Do we leak keys on error? */
3730 return LDAP_INVALID_SYNTAX;
3733 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3735 integerNormalize( slap_schema.si_syn_integer,
3740 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3741 "certificateExactIndexer: returning: %s\n",
3744 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3751 keys[i].bv_val = NULL;
3753 return LDAP_SUCCESS;
3756 /* Index generation function */
3757 /* We think this is always called with a value in matching rule syntax */
3758 static int certificateExactFilter(
3763 struct berval *prefix,
3765 struct berval **keysp )
3767 struct berval *keys;
3768 struct berval *asserted_serial;
3769 struct berval *asserted_issuer_dn;
3771 serial_and_issuer_parse(assertValue,
3773 &asserted_issuer_dn);
3775 keys = ch_malloc( sizeof( struct berval ) * 2 );
3776 integerNormalize( syntax, asserted_serial, &keys[0] );
3777 keys[1].bv_val = NULL;
3780 ber_bvfree(asserted_serial);
3781 ber_bvfree(asserted_issuer_dn);
3782 return LDAP_SUCCESS;
3787 check_time_syntax (struct berval *val,
3791 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3792 static int mdays[2][12] = {
3793 /* non-leap years */
3794 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3796 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3799 int part, c, tzoffset, leapyear = 0 ;
3801 if( val->bv_len == 0 ) {
3802 return LDAP_INVALID_SYNTAX;
3805 p = (char *)val->bv_val;
3806 e = p + val->bv_len;
3808 /* Ignore initial whitespace */
3809 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3813 if (e - p < 13 - (2 * start)) {
3814 return LDAP_INVALID_SYNTAX;
3817 for (part = 0; part < 9; part++) {
3821 for (part = start; part < 7; part++) {
3823 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3830 return LDAP_INVALID_SYNTAX;
3832 if (c < 0 || c > 9) {
3833 return LDAP_INVALID_SYNTAX;
3839 return LDAP_INVALID_SYNTAX;
3841 if (c < 0 || c > 9) {
3842 return LDAP_INVALID_SYNTAX;
3847 if (part == 2 || part == 3) {
3850 if (parts[part] < 0) {
3851 return LDAP_INVALID_SYNTAX;
3853 if (parts[part] > ceiling[part]) {
3854 return LDAP_INVALID_SYNTAX;
3858 /* leapyear check for the Gregorian calendar (year>1581) */
3859 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3860 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3865 if (parts[3] > mdays[leapyear][parts[2]]) {
3866 return LDAP_INVALID_SYNTAX;
3871 tzoffset = 0; /* UTC */
3872 } else if (c != '+' && c != '-') {
3873 return LDAP_INVALID_SYNTAX;
3877 } else /* c == '+' */ {
3882 return LDAP_INVALID_SYNTAX;
3885 for (part = 7; part < 9; part++) {
3887 if (c < 0 || c > 9) {
3888 return LDAP_INVALID_SYNTAX;
3893 if (c < 0 || c > 9) {
3894 return LDAP_INVALID_SYNTAX;
3898 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3899 return LDAP_INVALID_SYNTAX;
3904 /* Ignore trailing whitespace */
3905 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3909 return LDAP_INVALID_SYNTAX;
3912 switch ( tzoffset ) {
3913 case -1: /* negativ offset to UTC, ie west of Greenwich */
3914 parts[4] += parts[7];
3915 parts[5] += parts[8];
3916 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3920 c = mdays[leapyear][parts[2]];
3922 if (parts[part] > c) {
3923 parts[part] -= c + 1;
3928 case 1: /* positive offset to UTC, ie east of Greenwich */
3929 parts[4] -= parts[7];
3930 parts[5] -= parts[8];
3931 for (part = 6; --part > 0; ) {
3935 /* first arg to % needs to be non negativ */
3936 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3938 if (parts[part] < 0) {
3939 parts[part] += c + 1;
3944 case 0: /* already UTC */
3948 return LDAP_SUCCESS;
3955 struct berval *normalized )
3959 rc = check_time_syntax(val, 1, parts);
3960 if (rc != LDAP_SUCCESS) {
3964 normalized->bv_val = ch_malloc( 14 );
3965 if ( normalized->bv_val == NULL ) {
3966 return LBER_ERROR_MEMORY;
3969 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3970 parts[1], parts[2] + 1, parts[3] + 1,
3971 parts[4], parts[5], parts[6] );
3972 normalized->bv_len = 13;
3974 return LDAP_SUCCESS;
3984 return check_time_syntax(in, 1, parts);
3988 generalizedTimeValidate(
3994 return check_time_syntax(in, 0, parts);
3998 generalizedTimeNormalize(
4001 struct berval *normalized )
4005 rc = check_time_syntax(val, 0, parts);
4006 if (rc != LDAP_SUCCESS) {
4010 normalized->bv_val = ch_malloc( 16 );
4011 if ( normalized->bv_val == NULL ) {
4012 return LBER_ERROR_MEMORY;
4015 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4016 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4017 parts[4], parts[5], parts[6] );
4018 normalized->bv_len = 15;
4020 return LDAP_SUCCESS;
4024 nisNetgroupTripleValidate(
4026 struct berval *val )
4031 if ( val->bv_len == 0 ) {
4032 return LDAP_INVALID_SYNTAX;
4035 p = (char *)val->bv_val;
4036 e = p + val->bv_len;
4038 if ( *p != '(' /*')'*/ ) {
4039 return LDAP_INVALID_SYNTAX;
4042 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4046 return LDAP_INVALID_SYNTAX;
4049 } else if ( !ATTR_CHAR( *p ) ) {
4050 return LDAP_INVALID_SYNTAX;
4054 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4055 return LDAP_INVALID_SYNTAX;
4061 return LDAP_INVALID_SYNTAX;
4064 return LDAP_SUCCESS;
4068 bootParameterValidate(
4070 struct berval *val )
4074 if ( val->bv_len == 0 ) {
4075 return LDAP_INVALID_SYNTAX;
4078 p = (char *)val->bv_val;
4079 e = p + val->bv_len;
4082 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4083 if ( !ATTR_CHAR( *p ) ) {
4084 return LDAP_INVALID_SYNTAX;
4089 return LDAP_INVALID_SYNTAX;
4093 for ( p++; ( 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++ ) {
4105 if ( !ATTR_CHAR( *p ) ) {
4106 return LDAP_INVALID_SYNTAX;
4110 return LDAP_SUCCESS;
4113 static struct syntax_defs_rec {
4115 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4116 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4118 slap_syntax_validate_func *sd_validate;
4119 slap_syntax_transform_func *sd_normalize;
4120 slap_syntax_transform_func *sd_pretty;
4121 #ifdef SLAPD_BINARY_CONVERSION
4122 slap_syntax_transform_func *sd_ber2str;
4123 slap_syntax_transform_func *sd_str2ber;
4126 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4127 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4128 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4129 0, NULL, NULL, NULL},
4130 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4131 0, NULL, NULL, NULL},
4132 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4133 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4134 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4135 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4136 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4137 0, bitStringValidate, bitStringNormalize, NULL },
4138 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4139 0, booleanValidate, NULL, NULL},
4140 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4141 X_BINARY X_NOT_H_R ")",
4142 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4144 X_BINARY X_NOT_H_R ")",
4145 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4146 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4147 X_BINARY X_NOT_H_R ")",
4148 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4149 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4150 0, countryStringValidate, IA5StringNormalize, NULL},
4151 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4152 0, dnValidate, dnNormalize2, dnPretty2},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4154 0, NULL, NULL, NULL},
4155 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4156 0, NULL, NULL, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4158 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4160 0, NULL, NULL, NULL},
4161 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4162 0, NULL, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4164 0, NULL, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4166 0, NULL, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4168 0, NULL, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4170 0, printablesStringValidate, IA5StringNormalize, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4172 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4174 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4176 0, NULL, NULL, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4178 0, IA5StringValidate, IA5StringNormalize, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4180 0, integerValidate, integerNormalize, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4182 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4184 0, NULL, NULL, NULL},
4185 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4186 0, NULL, NULL, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4188 0, NULL, NULL, NULL},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4190 0, NULL, NULL, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4192 0, NULL, NULL, NULL},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4194 0, nameUIDValidate, nameUIDNormalize, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4196 0, NULL, NULL, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4198 0, numericStringValidate, numericStringNormalize, NULL},
4199 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4200 0, NULL, NULL, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4202 0, oidValidate, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4204 0, IA5StringValidate, IA5StringNormalize, NULL},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4206 0, blobValidate, NULL, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4208 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4210 0, NULL, NULL, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4212 0, NULL, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4214 0, printableStringValidate, IA5StringNormalize, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4216 X_BINARY X_NOT_H_R ")",
4217 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4219 0, printableStringValidate, IA5StringNormalize, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4221 0, NULL, NULL, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4223 0, printablesStringValidate, IA5StringNormalize, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4225 0, utcTimeValidate, utcTimeNormalize, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4227 0, NULL, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4229 0, NULL, NULL, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4231 0, NULL, NULL, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4233 0, NULL, NULL, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4235 0, NULL, NULL, NULL},
4237 /* RFC 2307 NIS Syntaxes */
4238 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4239 0, nisNetgroupTripleValidate, NULL, NULL},
4240 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4241 0, bootParameterValidate, NULL, NULL},
4245 /* These OIDs are not published yet, but will be in the next
4246 * I-D for PKIX LDAPv3 schema as have been advanced by David
4247 * Chadwick in private mail.
4249 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4250 0, NULL, NULL, NULL},
4253 /* OpenLDAP Experimental Syntaxes */
4254 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4256 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4259 /* needs updating */
4260 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4261 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4263 /* OpenLDAP Void Syntax */
4264 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4265 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4266 {NULL, 0, NULL, NULL, NULL}
4270 * Other matching rules in X.520 that we do not use (yet):
4272 * 2.5.13.9 numericStringOrderingMatch
4273 * 2.5.13.15 integerOrderingMatch
4274 * 2.5.13.18 octetStringOrderingMatch
4275 * 2.5.13.19 octetStringSubstringsMatch
4276 * 2.5.13.25 uTCTimeMatch
4277 * 2.5.13.26 uTCTimeOrderingMatch
4278 * 2.5.13.31 directoryStringFirstComponentMatch
4279 * 2.5.13.32 wordMatch
4280 * 2.5.13.33 keywordMatch
4281 * 2.5.13.35 certificateMatch
4282 * 2.5.13.36 certificatePairExactMatch
4283 * 2.5.13.37 certificatePairMatch
4284 * 2.5.13.38 certificateListExactMatch
4285 * 2.5.13.39 certificateListMatch
4286 * 2.5.13.40 algorithmIdentifierMatch
4287 * 2.5.13.41 storedPrefixMatch
4288 * 2.5.13.42 attributeCertificateMatch
4289 * 2.5.13.43 readerAndKeyIDMatch
4290 * 2.5.13.44 attributeIntegrityMatch
4292 static struct mrule_defs_rec {
4294 slap_mask_t mrd_usage;
4295 slap_mr_convert_func * mrd_convert;
4296 slap_mr_normalize_func * mrd_normalize;
4297 slap_mr_match_func * mrd_match;
4298 slap_mr_indexer_func * mrd_indexer;
4299 slap_mr_filter_func * mrd_filter;
4301 char * mrd_associated;
4304 * EQUALITY matching rules must be listed after associated APPROX
4305 * matching rules. So, we list all APPROX matching rules first.
4307 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4308 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4309 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4311 directoryStringApproxMatch,
4312 directoryStringApproxIndexer,
4313 directoryStringApproxFilter,
4316 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4317 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4318 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4320 IA5StringApproxMatch,
4321 IA5StringApproxIndexer,
4322 IA5StringApproxFilter,
4326 * Other matching rules
4329 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4330 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4331 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4333 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4336 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4337 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4338 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4340 dnMatch, dnIndexer, dnFilter,
4343 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4344 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4345 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4347 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4348 directoryStringApproxMatchOID },
4350 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4351 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4354 caseIgnoreOrderingMatch, NULL, NULL,
4357 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4358 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4359 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4361 caseExactIgnoreSubstringsMatch,
4362 caseExactIgnoreSubstringsIndexer,
4363 caseExactIgnoreSubstringsFilter,
4366 {"( 2.5.13.5 NAME 'caseExactMatch' "
4367 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4368 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4370 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4371 directoryStringApproxMatchOID },
4373 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4374 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4377 caseExactOrderingMatch, NULL, NULL,
4380 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4381 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4382 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4384 caseExactIgnoreSubstringsMatch,
4385 caseExactIgnoreSubstringsIndexer,
4386 caseExactIgnoreSubstringsFilter,
4389 {"( 2.5.13.8 NAME 'numericStringMatch' "
4390 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4391 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4394 caseIgnoreIA5Indexer,
4395 caseIgnoreIA5Filter,
4398 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4399 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4400 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4402 caseIgnoreIA5SubstringsMatch,
4403 caseIgnoreIA5SubstringsIndexer,
4404 caseIgnoreIA5SubstringsFilter,
4407 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4408 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4409 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4411 caseIgnoreListMatch, NULL, NULL,
4414 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4415 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4416 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4418 caseIgnoreListSubstringsMatch, NULL, NULL,
4421 {"( 2.5.13.13 NAME 'booleanMatch' "
4422 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4423 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4425 booleanMatch, NULL, NULL,
4428 {"( 2.5.13.14 NAME 'integerMatch' "
4429 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4430 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4432 integerMatch, integerIndexer, integerFilter,
4435 {"( 2.5.13.16 NAME 'bitStringMatch' "
4436 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4437 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4439 bitStringMatch, bitStringIndexer, bitStringFilter,
4442 {"( 2.5.13.17 NAME 'octetStringMatch' "
4443 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4444 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4446 octetStringMatch, octetStringIndexer, octetStringFilter,
4449 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4450 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4451 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4453 telephoneNumberMatch,
4454 telephoneNumberIndexer,
4455 telephoneNumberFilter,
4458 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4459 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4460 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4462 telephoneNumberSubstringsMatch,
4463 telephoneNumberSubstringsIndexer,
4464 telephoneNumberSubstringsFilter,
4467 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4468 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4469 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4474 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4475 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4476 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4478 uniqueMemberMatch, NULL, NULL,
4481 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4482 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4483 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4485 protocolInformationMatch, NULL, NULL,
4488 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4489 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4490 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4492 generalizedTimeMatch, NULL, NULL,
4495 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4496 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4499 generalizedTimeOrderingMatch, NULL, NULL,
4502 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4503 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4504 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4506 integerFirstComponentMatch, NULL, NULL,
4509 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4510 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4511 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4513 objectIdentifierFirstComponentMatch, NULL, NULL,
4517 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4518 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4519 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4520 certificateExactConvert, NULL,
4521 certificateExactMatch,
4522 certificateExactIndexer, certificateExactFilter,
4526 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4527 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4528 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4530 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4531 IA5StringApproxMatchOID },
4533 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4534 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4535 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4537 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4538 IA5StringApproxMatchOID },
4540 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4541 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4544 caseIgnoreIA5SubstringsMatch,
4545 caseIgnoreIA5SubstringsIndexer,
4546 caseIgnoreIA5SubstringsFilter,
4549 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4550 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4553 caseExactIA5SubstringsMatch,
4554 caseExactIA5SubstringsIndexer,
4555 caseExactIA5SubstringsFilter,
4558 /* needs updating */
4559 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4560 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4563 authPasswordMatch, NULL, NULL,
4566 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4567 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4570 OpenLDAPaciMatch, NULL, NULL,
4573 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4574 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4577 integerBitAndMatch, NULL, NULL,
4580 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4581 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4584 integerBitOrMatch, NULL, NULL,
4587 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4596 /* we should only be called once (from main) */
4597 assert( schema_init_done == 0 );
4599 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4600 res = register_syntax( syntax_defs[i].sd_desc,
4601 syntax_defs[i].sd_flags,
4602 syntax_defs[i].sd_validate,
4603 syntax_defs[i].sd_normalize,
4604 syntax_defs[i].sd_pretty
4605 #ifdef SLAPD_BINARY_CONVERSION
4607 syntax_defs[i].sd_ber2str,
4608 syntax_defs[i].sd_str2ber
4613 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4614 syntax_defs[i].sd_desc );
4619 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4620 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4622 "schema_init: Ingoring unusable matching rule %s\n",
4623 mrule_defs[i].mrd_desc );
4627 res = register_matching_rule(
4628 mrule_defs[i].mrd_desc,
4629 mrule_defs[i].mrd_usage,
4630 mrule_defs[i].mrd_convert,
4631 mrule_defs[i].mrd_normalize,
4632 mrule_defs[i].mrd_match,
4633 mrule_defs[i].mrd_indexer,
4634 mrule_defs[i].mrd_filter,
4635 mrule_defs[i].mrd_associated );
4639 "schema_init: Error registering matching rule %s\n",
4640 mrule_defs[i].mrd_desc );
4644 schema_init_done = 1;
4645 return LDAP_SUCCESS;
4649 schema_destroy( void )