1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
15 #include <ac/string.h>
16 #include <ac/socket.h>
21 #include "ldap_utf8.h"
23 #include "lutil_hash.h"
24 #define HASH_BYTES LUTIL_HASH_BYTES
25 #define HASH_CONTEXT lutil_HASH_CTX
26 #define HASH_Init(c) lutil_HASHInit(c)
27 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
28 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
30 /* recycled validatation routines */
31 #define berValidate blobValidate
33 /* unimplemented pretters */
34 #define integerPretty NULL
36 /* recycled matching routines */
37 #define bitStringMatch octetStringMatch
38 #define numericStringMatch caseIgnoreIA5Match
39 #define objectIdentifierMatch caseIgnoreIA5Match
40 #define telephoneNumberMatch caseIgnoreIA5Match
41 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
42 #define generalizedTimeMatch caseIgnoreIA5Match
43 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
44 #define uniqueMemberMatch dnMatch
46 /* approx matching rules */
47 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
48 #define directoryStringApproxMatch approxMatch
49 #define directoryStringApproxIndexer approxIndexer
50 #define directoryStringApproxFilter approxFilter
51 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
52 #define IA5StringApproxMatch approxMatch
53 #define IA5StringApproxIndexer approxIndexer
54 #define IA5StringApproxFilter approxFilter
56 /* orderring matching rules */
57 #define caseIgnoreOrderingMatch caseIgnoreMatch
58 #define caseExactOrderingMatch caseExactMatch
60 /* unimplemented matching routines */
61 #define caseIgnoreListMatch NULL
62 #define caseIgnoreListSubstringsMatch NULL
63 #define protocolInformationMatch NULL
64 #define integerFirstComponentMatch NULL
66 #define OpenLDAPaciMatch NULL
67 #define authPasswordMatch NULL
69 /* recycled indexing/filtering routines */
70 #define dnIndexer caseExactIgnoreIndexer
71 #define dnFilter caseExactIgnoreFilter
72 #define bitStringFilter octetStringFilter
73 #define bitStringIndexer octetStringIndexer
75 #define telephoneNumberIndexer caseIgnoreIA5Indexer
76 #define telephoneNumberFilter caseIgnoreIA5Filter
77 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
78 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
80 /* must match OIDs below */
81 #define caseExactMatchOID "2.5.13.5"
82 #define caseExactSubstringsMatchOID "2.5.13.7"
84 static char *bvcasechr( struct berval *bv, int c, ber_len_t *len )
87 int lower = TOLOWER( c );
88 int upper = TOUPPER( c );
90 if( c == 0 ) return NULL;
92 for( i=0; i < bv->bv_len; i++ ) {
93 if( upper == bv->bv_val[i] || lower == bv->bv_val[i] ) {
95 return &bv->bv_val[i];
108 struct berval *value,
109 void *assertedValue )
111 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
114 match = memcmp( value->bv_val,
115 ((struct berval *) assertedValue)->bv_val,
123 /* Index generation function */
124 static int octetStringIndexer(
129 struct berval *prefix,
136 HASH_CONTEXT HASHcontext;
137 unsigned char HASHdigest[HASH_BYTES];
138 struct berval digest;
139 digest.bv_val = HASHdigest;
140 digest.bv_len = sizeof(HASHdigest);
142 for( i=0; values[i].bv_val != NULL; i++ ) {
143 /* just count them */
146 /* we should have at least one value at this point */
149 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
151 slen = syntax->ssyn_oidlen;
152 mlen = mr->smr_oidlen;
154 for( i=0; values[i].bv_val != NULL; i++ ) {
155 HASH_Init( &HASHcontext );
156 if( prefix != NULL && prefix->bv_len > 0 ) {
157 HASH_Update( &HASHcontext,
158 prefix->bv_val, prefix->bv_len );
160 HASH_Update( &HASHcontext,
161 syntax->ssyn_oid, slen );
162 HASH_Update( &HASHcontext,
164 HASH_Update( &HASHcontext,
165 values[i].bv_val, values[i].bv_len );
166 HASH_Final( HASHdigest, &HASHcontext );
168 ber_dupbv( &keys[i], &digest );
171 keys[i].bv_val = NULL;
178 /* Index generation function */
179 static int octetStringFilter(
184 struct berval *prefix,
190 HASH_CONTEXT HASHcontext;
191 unsigned char HASHdigest[HASH_BYTES];
192 struct berval *value = (struct berval *) assertValue;
193 struct berval digest;
194 digest.bv_val = HASHdigest;
195 digest.bv_len = sizeof(HASHdigest);
197 slen = syntax->ssyn_oidlen;
198 mlen = mr->smr_oidlen;
200 keys = ch_malloc( sizeof( struct berval ) * 2 );
202 HASH_Init( &HASHcontext );
203 if( prefix != NULL && prefix->bv_len > 0 ) {
204 HASH_Update( &HASHcontext,
205 prefix->bv_val, prefix->bv_len );
207 HASH_Update( &HASHcontext,
208 syntax->ssyn_oid, slen );
209 HASH_Update( &HASHcontext,
211 HASH_Update( &HASHcontext,
212 value->bv_val, value->bv_len );
213 HASH_Final( HASHdigest, &HASHcontext );
215 ber_dupbv( keys, &digest );
216 keys[1].bv_val = NULL;
231 if( in->bv_len == 0 ) return LDAP_SUCCESS;
233 ber_dupbv( &dn, in );
234 if( !dn.bv_val ) return LDAP_OTHER;
236 if( dn.bv_val[dn.bv_len-1] == 'B'
237 && dn.bv_val[dn.bv_len-2] == '\'' )
239 /* assume presence of optional UID */
242 for(i=dn.bv_len-3; i>1; i--) {
243 if( dn.bv_val[i] != '0' && dn.bv_val[i] != '1' ) {
247 if( dn.bv_val[i] != '\'' ||
248 dn.bv_val[i-1] != '#' ) {
249 ber_memfree( dn.bv_val );
250 return LDAP_INVALID_SYNTAX;
253 /* trim the UID to allow use of dnValidate */
254 dn.bv_val[i-1] = '\0';
258 rc = dnValidate( NULL, &dn );
268 struct berval *normalized )
273 ber_dupbv( &out, val );
274 if( out.bv_len != 0 ) {
277 ber_len_t uidlen = 0;
279 if( out.bv_val[out.bv_len-1] == '\'' ) {
280 /* assume presence of optional UID */
281 uid = strrchr( out.bv_val, '#' );
285 return LDAP_INVALID_SYNTAX;
288 uidlen = out.bv_len - (uid - out.bv_val);
289 /* temporarily trim the UID */
291 out.bv_len -= uidlen;
294 #ifdef USE_DN_NORMALIZE
295 rc = dnNormalize2( NULL, &out, normalized );
297 rc = dnPretty2( NULL, &out, normalized );
300 if( rc != LDAP_SUCCESS ) {
302 return LDAP_INVALID_SYNTAX;
305 dnlen = normalized->bv_len;
309 b2.bv_val = ch_malloc(dnlen + uidlen + 1);
310 AC_MEMCPY( b2.bv_val, normalized->bv_val, dnlen );
312 /* restore the separator */
315 AC_MEMCPY( normalized->bv_val+dnlen, uid, uidlen );
316 b2.bv_len = dnlen + uidlen;
317 normalized->bv_val[dnlen+uidlen] = '\0';
318 free(normalized->bv_val);
332 /* any value allowed */
341 /* any value allowed */
352 /* very unforgiving validation, requires no normalization
353 * before simplistic matching
355 if( in->bv_len < 3 ) {
356 return LDAP_INVALID_SYNTAX;
360 * rfc 2252 section 6.3 Bit String
361 * bitstring = "'" *binary-digit "'"
362 * binary-digit = "0" / "1"
363 * example: '0101111101'B
366 if( in->bv_val[0] != '\'' ||
367 in->bv_val[in->bv_len-2] != '\'' ||
368 in->bv_val[in->bv_len-1] != 'B' )
370 return LDAP_INVALID_SYNTAX;
373 for( i=in->bv_len-3; i>0; i-- ) {
374 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
375 return LDAP_INVALID_SYNTAX;
386 struct berval *normalized )
389 * A normalized bitString is has no extaneous (leading) zero bits.
390 * That is, '00010'B is normalized to '10'B
391 * However, as a special case, '0'B requires no normalization.
395 /* start at the first bit */
398 /* Find the first non-zero bit */
399 while ( *p == '0' ) p++;
402 /* no non-zero bits */
403 ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
407 normalized->bv_val = ch_malloc( val->bv_len + 1 );
409 normalized->bv_val[0] = '\'';
410 normalized->bv_len = 1;
412 for( ; *p != '\0'; p++ ) {
413 normalized->bv_val[normalized->bv_len++] = *p;
416 normalized->bv_val[normalized->bv_len] = '\0';
423 * Handling boolean syntax and matching is quite rigid.
424 * A more flexible approach would be to allow a variety
425 * of strings to be normalized and prettied into TRUE
433 /* very unforgiving validation, requires no normalization
434 * before simplistic matching
437 if( in->bv_len == 4 ) {
438 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
441 } else if( in->bv_len == 5 ) {
442 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
447 return LDAP_INVALID_SYNTAX;
456 struct berval *value,
457 void *assertedValue )
459 /* simplistic matching allowed by rigid validation */
460 struct berval *asserted = (struct berval *) assertedValue;
461 *matchp = value->bv_len != asserted->bv_len;
472 unsigned char *u = in->bv_val;
474 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
476 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
477 /* get the length indicated by the first byte */
478 len = LDAP_UTF8_CHARLEN2( u, len );
480 /* very basic checks */
483 if( (u[5] & 0xC0) != 0x80 ) {
484 return LDAP_INVALID_SYNTAX;
487 if( (u[4] & 0xC0) != 0x80 ) {
488 return LDAP_INVALID_SYNTAX;
491 if( (u[3] & 0xC0) != 0x80 ) {
492 return LDAP_INVALID_SYNTAX;
495 if( (u[2] & 0xC0 )!= 0x80 ) {
496 return LDAP_INVALID_SYNTAX;
499 if( (u[1] & 0xC0) != 0x80 ) {
500 return LDAP_INVALID_SYNTAX;
503 /* CHARLEN already validated it */
506 return LDAP_INVALID_SYNTAX;
509 /* make sure len corresponds with the offset
510 to the next character */
511 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
514 if( count != 0 ) return LDAP_INVALID_SYNTAX;
523 struct berval *normalized )
530 /* Ignore initial whitespace */
531 /* All space is ASCII. All ASCII is 1 byte */
532 while ( ASCII_SPACE( *p ) ) {
537 return LDAP_INVALID_SYNTAX;
540 ber_mem2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
541 e = normalized->bv_val + val->bv_len - (p - val->bv_val);
543 assert( normalized->bv_val );
545 p = q = normalized->bv_val;
550 if ( ASCII_SPACE( *p ) ) {
555 /* Ignore the extra whitespace */
556 while ( ASCII_SPACE( *p ) ) {
560 len = LDAP_UTF8_COPY(q,p);
566 assert( normalized->bv_val < p );
567 assert( q+len <= p );
569 /* cannot start with a space */
570 assert( !ASCII_SPACE(normalized->bv_val[0]) );
573 * If the string ended in space, backup the pointer one
574 * position. One is enough because the above loop collapsed
575 * all whitespace to a single space.
583 /* cannot end with a space */
584 assert( !ASCII_SPACE( *q ) );
591 normalized->bv_len = q - normalized->bv_val;
596 /* Returns Unicode canonically normalized copy of a substring assertion
597 * Skipping attribute description */
598 static SubstringsAssertion *
599 UTF8SubstringsassertionNormalize(
600 SubstringsAssertion *sa,
603 SubstringsAssertion *nsa;
606 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
611 if( sa->sa_initial.bv_val != NULL ) {
612 ber_str2bv( UTF8normalize( &sa->sa_initial, casefold ), 0,
613 0, &nsa->sa_initial );
614 if( nsa->sa_initial.bv_val == NULL ) {
619 if( sa->sa_any != NULL ) {
620 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
623 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
624 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
625 ber_str2bv( UTF8normalize( &sa->sa_any[i], casefold ),
626 0, 0, &nsa->sa_any[i] );
627 if( nsa->sa_any[i].bv_val == NULL ) {
631 nsa->sa_any[i].bv_val = NULL;
634 if( sa->sa_final.bv_val != NULL ) {
635 ber_str2bv( UTF8normalize( &sa->sa_final, casefold ), 0,
637 if( nsa->sa_final.bv_val == NULL ) {
645 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
646 if ( nsa->sa_any )ber_bvarray_free( nsa->sa_any );
647 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
652 /* Strip characters with the 8th bit set */
665 while( *++q & 0x80 ) {
668 p = AC_MEMCPY(p, q, strlen(q) + 1);
676 #ifndef SLAPD_APPROX_OLDSINGLESTRING
678 #if defined(SLAPD_APPROX_INITIALS)
679 #define SLAPD_APPROX_DELIMITER "._ "
680 #define SLAPD_APPROX_WORDLEN 2
682 #define SLAPD_APPROX_DELIMITER " "
683 #define SLAPD_APPROX_WORDLEN 1
692 struct berval *value,
693 void *assertedValue )
695 char *val, *nval, *assertv, **values, **words, *c;
696 int i, count, len, nextchunk=0, nextavail=0;
699 /* Yes, this is necessary */
700 nval = UTF8normalize( value, LDAP_UTF8_NOCASEFOLD );
705 strip8bitChars( nval );
707 /* Yes, this is necessary */
708 assertv = UTF8normalize( ((struct berval *)assertedValue),
709 LDAP_UTF8_NOCASEFOLD );
710 if( assertv == NULL ) {
715 strip8bitChars( assertv );
716 avlen = strlen( assertv );
718 /* Isolate how many words there are */
719 for( c=nval,count=1; *c; c++ ) {
720 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
721 if ( c == NULL ) break;
726 /* Get a phonetic copy of each word */
727 words = (char **)ch_malloc( count * sizeof(char *) );
728 values = (char **)ch_malloc( count * sizeof(char *) );
729 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
731 values[i] = phonetic(c);
734 /* Work through the asserted value's words, to see if at least some
735 of the words are there, in the same order. */
737 while ( (size_t) nextchunk < avlen ) {
738 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
743 #if defined(SLAPD_APPROX_INITIALS)
744 else if( len == 1 ) {
745 /* Single letter words need to at least match one word's initial */
746 for( i=nextavail; i<count; i++ )
747 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
754 /* Isolate the next word in the asserted value and phonetic it */
755 assertv[nextchunk+len] = '\0';
756 val = phonetic( assertv + nextchunk );
758 /* See if this phonetic chunk is in the remaining words of *value */
759 for( i=nextavail; i<count; i++ ){
760 if( !strcmp( val, values[i] ) ){
768 /* This chunk in the asserted value was NOT within the *value. */
774 /* Go on to the next word in the asserted value */
778 /* If some of the words were seen, call it a match */
779 if( nextavail > 0 ) {
788 for( i=0; i<count; i++ ) {
789 ch_free( values[i] );
804 struct berval *prefix,
809 int i,j, len, wordcount, keycount=0;
810 struct berval *newkeys;
813 for( j=0; values[j].bv_val != NULL; j++ ) {
814 /* Yes, this is necessary */
815 val = UTF8normalize( &values[j], LDAP_UTF8_NOCASEFOLD );
816 strip8bitChars( val );
818 /* Isolate how many words there are. There will be a key for each */
819 for( wordcount=0,c=val; *c; c++) {
820 len = strcspn(c, SLAPD_APPROX_DELIMITER);
821 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
823 if (*c == '\0') break;
827 /* Allocate/increase storage to account for new keys */
828 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
829 * sizeof(struct berval) );
830 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
831 if( keys ) ch_free( keys );
834 /* Get a phonetic copy of each word */
835 for( c=val,i=0; i<wordcount; c+=len+1 ) {
837 if( len < SLAPD_APPROX_WORDLEN ) continue;
838 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
845 keys[keycount].bv_val = NULL;
857 struct berval *prefix,
865 /* Yes, this is necessary */
866 val = UTF8normalize( ((struct berval *)assertValue),
867 LDAP_UTF8_NOCASEFOLD );
869 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
870 keys[0].bv_val = NULL;
874 strip8bitChars( val );
876 /* Isolate how many words there are. There will be a key for each */
877 for( count=0,c=val; *c; c++) {
878 len = strcspn(c, SLAPD_APPROX_DELIMITER);
879 if( len >= SLAPD_APPROX_WORDLEN ) count++;
881 if (*c == '\0') break;
885 /* Allocate storage for new keys */
886 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
888 /* Get a phonetic copy of each word */
889 for( c=val,i=0; i<count; c+=len+1 ) {
891 if( len < SLAPD_APPROX_WORDLEN ) continue;
892 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
898 keys[count].bv_val = NULL;
906 /* No other form of Approximate Matching is defined */
914 struct berval *value,
915 void *assertedValue )
917 char *vapprox, *avapprox;
920 /* Yes, this is necessary */
921 s = UTF8normalize( value, UTF8_NOCASEFOLD );
927 /* Yes, this is necessary */
928 t = UTF8normalize( ((struct berval *)assertedValue),
936 vapprox = phonetic( strip8bitChars( s ) );
937 avapprox = phonetic( strip8bitChars( t ) );
942 *matchp = strcmp( vapprox, avapprox );
956 struct berval *prefix,
964 for( i=0; values[i].bv_val != NULL; i++ ) {
965 /* empty - just count them */
968 /* we should have at least one value at this point */
971 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
973 /* Copy each value and run it through phonetic() */
974 for( i=0; values[i].bv_val != NULL; i++ ) {
975 /* Yes, this is necessary */
976 s = UTF8normalize( &values[i], UTF8_NOCASEFOLD );
978 /* strip 8-bit chars and run through phonetic() */
979 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
982 keys[i].bv_val = NULL;
995 struct berval *prefix,
1002 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
1004 /* Yes, this is necessary */
1005 s = UTF8normalize( ((struct berval *)assertValue),
1010 /* strip 8-bit chars and run through phonetic() */
1011 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1017 return LDAP_SUCCESS;
1028 struct berval *value,
1029 void *assertedValue )
1031 *matchp = UTF8normcmp( value->bv_val,
1032 ((struct berval *) assertedValue)->bv_val,
1033 LDAP_UTF8_NOCASEFOLD );
1034 return LDAP_SUCCESS;
1038 caseExactIgnoreSubstringsMatch(
1043 struct berval *value,
1044 void *assertedValue )
1047 SubstringsAssertion *sub = NULL;
1054 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1055 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1057 nav = UTF8normalize( value, casefold );
1063 left.bv_len = strlen( nav );
1065 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1071 /* Add up asserted input length */
1072 if( sub->sa_initial.bv_val ) {
1073 inlen += sub->sa_initial.bv_len;
1076 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1077 inlen += sub->sa_any[i].bv_len;
1080 if( sub->sa_final.bv_val ) {
1081 inlen += sub->sa_final.bv_len;
1084 if( sub->sa_initial.bv_val ) {
1085 if( inlen > left.bv_len ) {
1090 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
1091 sub->sa_initial.bv_len );
1097 left.bv_val += sub->sa_initial.bv_len;
1098 left.bv_len -= sub->sa_initial.bv_len;
1099 inlen -= sub->sa_initial.bv_len;
1102 if( sub->sa_final.bv_val ) {
1103 if( inlen > left.bv_len ) {
1108 match = strncmp( sub->sa_final.bv_val,
1109 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1110 sub->sa_final.bv_len );
1116 left.bv_len -= sub->sa_final.bv_len;
1117 inlen -= sub->sa_final.bv_len;
1121 for(i=0; sub->sa_any[i].bv_val; i++) {
1126 if( inlen > left.bv_len ) {
1127 /* not enough length */
1132 if( sub->sa_any[i].bv_len == 0 ) {
1136 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
1143 idx = p - left.bv_val;
1145 if( idx >= left.bv_len ) {
1146 /* this shouldn't happen */
1148 if ( sub->sa_final.bv_val )
1149 ch_free( sub->sa_final.bv_val );
1151 ber_bvarray_free( sub->sa_any );
1152 if ( sub->sa_initial.bv_val )
1153 ch_free( sub->sa_initial.bv_val );
1161 if( sub->sa_any[i].bv_len > left.bv_len ) {
1162 /* not enough left */
1167 match = strncmp( left.bv_val,
1168 sub->sa_any[i].bv_val,
1169 sub->sa_any[i].bv_len );
1177 left.bv_val += sub->sa_any[i].bv_len;
1178 left.bv_len -= sub->sa_any[i].bv_len;
1179 inlen -= sub->sa_any[i].bv_len;
1186 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1187 if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
1188 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1192 return LDAP_SUCCESS;
1195 /* Index generation function */
1196 static int caseExactIgnoreIndexer(
1201 struct berval *prefix,
1209 HASH_CONTEXT HASHcontext;
1210 unsigned char HASHdigest[HASH_BYTES];
1211 struct berval digest;
1212 digest.bv_val = HASHdigest;
1213 digest.bv_len = sizeof(HASHdigest);
1215 for( i=0; values[i].bv_val != NULL; i++ ) {
1216 /* empty - just count them */
1219 /* we should have at least one value at this point */
1222 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1224 slen = syntax->ssyn_oidlen;
1225 mlen = mr->smr_oidlen;
1227 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1228 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1230 for( i=0; values[i].bv_val != NULL; i++ ) {
1231 struct berval value;
1232 ber_str2bv( UTF8normalize( &values[i], casefold ), 0, 0,
1235 HASH_Init( &HASHcontext );
1236 if( prefix != NULL && prefix->bv_len > 0 ) {
1237 HASH_Update( &HASHcontext,
1238 prefix->bv_val, prefix->bv_len );
1240 HASH_Update( &HASHcontext,
1241 syntax->ssyn_oid, slen );
1242 HASH_Update( &HASHcontext,
1243 mr->smr_oid, mlen );
1244 HASH_Update( &HASHcontext,
1245 value.bv_val, value.bv_len );
1246 HASH_Final( HASHdigest, &HASHcontext );
1248 free( value.bv_val );
1250 ber_dupbv( &keys[i], &digest );
1253 keys[i].bv_val = NULL;
1255 return LDAP_SUCCESS;
1258 /* Index generation function */
1259 static int caseExactIgnoreFilter(
1264 struct berval *prefix,
1271 HASH_CONTEXT HASHcontext;
1272 unsigned char HASHdigest[HASH_BYTES];
1273 struct berval value;
1274 struct berval digest;
1275 digest.bv_val = HASHdigest;
1276 digest.bv_len = sizeof(HASHdigest);
1278 slen = syntax->ssyn_oidlen;
1279 mlen = mr->smr_oidlen;
1281 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1282 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1284 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1286 /* This usually happens if filter contains bad UTF8 */
1287 if( value.bv_val == NULL ) {
1288 keys = ch_malloc( sizeof( struct berval ) );
1289 keys[0].bv_val = NULL;
1290 return LDAP_SUCCESS;
1293 keys = ch_malloc( sizeof( struct berval ) * 2 );
1295 HASH_Init( &HASHcontext );
1296 if( prefix != NULL && prefix->bv_len > 0 ) {
1297 HASH_Update( &HASHcontext,
1298 prefix->bv_val, prefix->bv_len );
1300 HASH_Update( &HASHcontext,
1301 syntax->ssyn_oid, slen );
1302 HASH_Update( &HASHcontext,
1303 mr->smr_oid, mlen );
1304 HASH_Update( &HASHcontext,
1305 value.bv_val, value.bv_len );
1306 HASH_Final( HASHdigest, &HASHcontext );
1308 ber_dupbv( keys, &digest );
1309 keys[1].bv_val = NULL;
1311 free( value.bv_val );
1314 return LDAP_SUCCESS;
1317 /* Substrings Index generation function */
1318 static int caseExactIgnoreSubstringsIndexer(
1323 struct berval *prefix,
1333 HASH_CONTEXT HASHcontext;
1334 unsigned char HASHdigest[HASH_BYTES];
1335 struct berval digest;
1336 digest.bv_val = HASHdigest;
1337 digest.bv_len = sizeof(HASHdigest);
1341 for( i=0; values[i].bv_val != NULL; i++ ) {
1342 /* empty - just count them */
1345 /* we should have at least one value at this point */
1348 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1349 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1351 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1352 for( i=0; values[i].bv_val != NULL; i++ ) {
1353 ber_str2bv( UTF8normalize( &values[i], casefold ),
1354 0, 0, &nvalues[i] );
1356 nvalues[i].bv_val = NULL;
1359 for( i=0; values[i].bv_val != NULL; i++ ) {
1360 /* count number of indices to generate */
1361 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1365 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1366 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1367 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1368 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1370 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1374 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1375 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1376 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1380 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1381 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1382 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1383 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1385 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1391 /* no keys to generate */
1393 ber_bvarray_free( nvalues );
1394 return LDAP_SUCCESS;
1397 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1399 slen = syntax->ssyn_oidlen;
1400 mlen = mr->smr_oidlen;
1403 for( i=0; values[i].bv_val != NULL; i++ ) {
1406 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1408 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1409 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1411 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1412 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1414 for( j=0; j<max; j++ ) {
1415 HASH_Init( &HASHcontext );
1416 if( prefix != NULL && prefix->bv_len > 0 ) {
1417 HASH_Update( &HASHcontext,
1418 prefix->bv_val, prefix->bv_len );
1421 HASH_Update( &HASHcontext,
1422 &pre, sizeof( pre ) );
1423 HASH_Update( &HASHcontext,
1424 syntax->ssyn_oid, slen );
1425 HASH_Update( &HASHcontext,
1426 mr->smr_oid, mlen );
1427 HASH_Update( &HASHcontext,
1428 &values[i].bv_val[j],
1429 SLAP_INDEX_SUBSTR_MAXLEN );
1430 HASH_Final( HASHdigest, &HASHcontext );
1432 ber_dupbv( &keys[nkeys++], &digest );
1436 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1437 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1439 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1442 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1443 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1444 HASH_Init( &HASHcontext );
1445 if( prefix != NULL && prefix->bv_len > 0 ) {
1446 HASH_Update( &HASHcontext,
1447 prefix->bv_val, prefix->bv_len );
1449 HASH_Update( &HASHcontext,
1450 &pre, sizeof( pre ) );
1451 HASH_Update( &HASHcontext,
1452 syntax->ssyn_oid, slen );
1453 HASH_Update( &HASHcontext,
1454 mr->smr_oid, mlen );
1455 HASH_Update( &HASHcontext,
1456 values[i].bv_val, j );
1457 HASH_Final( HASHdigest, &HASHcontext );
1459 ber_dupbv( &keys[nkeys++], &digest );
1462 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1463 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1464 HASH_Init( &HASHcontext );
1465 if( prefix != NULL && prefix->bv_len > 0 ) {
1466 HASH_Update( &HASHcontext,
1467 prefix->bv_val, prefix->bv_len );
1469 HASH_Update( &HASHcontext,
1470 &pre, sizeof( pre ) );
1471 HASH_Update( &HASHcontext,
1472 syntax->ssyn_oid, slen );
1473 HASH_Update( &HASHcontext,
1474 mr->smr_oid, mlen );
1475 HASH_Update( &HASHcontext,
1476 &values[i].bv_val[values[i].bv_len-j], j );
1477 HASH_Final( HASHdigest, &HASHcontext );
1479 ber_dupbv( &keys[nkeys++], &digest );
1487 keys[nkeys].bv_val = NULL;
1494 ber_bvarray_free( nvalues );
1496 return LDAP_SUCCESS;
1499 static int caseExactIgnoreSubstringsFilter(
1504 struct berval *prefix,
1508 SubstringsAssertion *sa;
1511 ber_len_t nkeys = 0;
1512 size_t slen, mlen, klen;
1514 HASH_CONTEXT HASHcontext;
1515 unsigned char HASHdigest[HASH_BYTES];
1516 struct berval *value;
1517 struct berval digest;
1519 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1520 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1522 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1525 return LDAP_SUCCESS;
1528 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1529 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1534 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1536 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1537 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1538 /* don't bother accounting for stepping */
1539 nkeys += sa->sa_any[i].bv_len -
1540 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1545 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1546 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1552 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1553 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1554 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1557 return LDAP_SUCCESS;
1560 digest.bv_val = HASHdigest;
1561 digest.bv_len = sizeof(HASHdigest);
1563 slen = syntax->ssyn_oidlen;
1564 mlen = mr->smr_oidlen;
1566 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1569 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1570 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1572 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1573 value = &sa->sa_initial;
1575 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1576 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
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, klen );
1591 HASH_Final( HASHdigest, &HASHcontext );
1593 ber_dupbv( &keys[nkeys++], &digest );
1596 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1598 pre = SLAP_INDEX_SUBSTR_PREFIX;
1599 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1601 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1602 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1606 value = &sa->sa_any[i];
1609 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1610 j += SLAP_INDEX_SUBSTR_STEP )
1612 HASH_Init( &HASHcontext );
1613 if( prefix != NULL && prefix->bv_len > 0 ) {
1614 HASH_Update( &HASHcontext,
1615 prefix->bv_val, prefix->bv_len );
1617 HASH_Update( &HASHcontext,
1618 &pre, sizeof( pre ) );
1619 HASH_Update( &HASHcontext,
1620 syntax->ssyn_oid, slen );
1621 HASH_Update( &HASHcontext,
1622 mr->smr_oid, mlen );
1623 HASH_Update( &HASHcontext,
1624 &value->bv_val[j], klen );
1625 HASH_Final( HASHdigest, &HASHcontext );
1627 ber_dupbv( &keys[nkeys++], &digest );
1633 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1634 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1636 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1637 value = &sa->sa_final;
1639 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1640 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1642 HASH_Init( &HASHcontext );
1643 if( prefix != NULL && prefix->bv_len > 0 ) {
1644 HASH_Update( &HASHcontext,
1645 prefix->bv_val, prefix->bv_len );
1647 HASH_Update( &HASHcontext,
1648 &pre, sizeof( pre ) );
1649 HASH_Update( &HASHcontext,
1650 syntax->ssyn_oid, slen );
1651 HASH_Update( &HASHcontext,
1652 mr->smr_oid, mlen );
1653 HASH_Update( &HASHcontext,
1654 &value->bv_val[value->bv_len-klen], klen );
1655 HASH_Final( HASHdigest, &HASHcontext );
1657 ber_dupbv( &keys[nkeys++], &digest );
1661 keys[nkeys].bv_val = NULL;
1667 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1668 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1669 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1672 return LDAP_SUCCESS;
1681 struct berval *value,
1682 void *assertedValue )
1684 *matchp = UTF8normcmp( value->bv_val,
1685 ((struct berval *) assertedValue)->bv_val,
1686 LDAP_UTF8_CASEFOLD );
1687 return LDAP_SUCCESS;
1693 struct berval *val )
1697 if( val->bv_len == 0 ) {
1698 /* disallow empty strings */
1699 return LDAP_INVALID_SYNTAX;
1702 if( OID_LEADCHAR(val->bv_val[0]) ) {
1704 for(i=1; i < val->bv_len; i++) {
1705 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1706 if( dot++ ) return 1;
1707 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1710 return LDAP_INVALID_SYNTAX;
1714 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1716 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1717 for(i=1; i < val->bv_len; i++) {
1718 if( !DESC_CHAR(val->bv_val[i] ) ) {
1719 return LDAP_INVALID_SYNTAX;
1723 return LDAP_SUCCESS;
1726 return LDAP_INVALID_SYNTAX;
1735 struct berval *value,
1736 void *assertedValue )
1739 int vsign=0, avsign=0;
1740 struct berval *asserted;
1741 ber_len_t vlen, avlen;
1744 /* Start off pessimistic */
1747 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1749 vlen = value->bv_len;
1751 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1752 /* empty -- skip spaces */
1754 else if ( *v == '+' ) {
1757 else if ( *v == '-' ) {
1760 else if ( ASCII_DIGIT(*v) ) {
1761 if ( vsign == 0 ) vsign = 1;
1769 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1771 asserted = (struct berval *) assertedValue;
1772 av = asserted->bv_val;
1773 avlen = asserted->bv_len;
1775 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1776 /* empty -- skip spaces */
1778 else if ( *av == '+' ) {
1781 else if ( *av == '-' ) {
1784 else if ( ASCII_DIGIT(*av) ) {
1785 if ( avsign == 0 ) avsign = 1;
1793 /* The two ?sign vars are now one of :
1794 -2 negative non-zero number
1796 0 0 collapse these three to 0
1798 +2 positive non-zero number
1800 if ( abs( vsign ) == 1 ) vsign = 0;
1801 if ( abs( avsign ) == 1 ) avsign = 0;
1803 if( vsign != avsign ) return LDAP_SUCCESS;
1805 /* Check the significant digits */
1806 while( vlen && avlen ) {
1807 if( *v != *av ) break;
1814 /* If all digits compared equal, the numbers are equal */
1815 if(( vlen == 0 ) && ( avlen == 0 )) {
1818 return LDAP_SUCCESS;
1824 struct berval *val )
1828 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1830 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1831 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1832 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1833 return LDAP_INVALID_SYNTAX;
1836 for( i=1; i < val->bv_len; i++ ) {
1837 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1840 return LDAP_SUCCESS;
1847 struct berval *normalized )
1857 /* Ignore leading spaces */
1858 while ( len && ( *p == ' ' )) {
1865 negative = ( *p == '-' );
1866 if(( *p == '-' ) || ( *p == '+' )) {
1872 /* Ignore leading zeros */
1873 while ( len && ( *p == '0' )) {
1878 /* If there are no non-zero digits left, the number is zero, otherwise
1879 allocate space for the number and copy it into the buffer */
1881 normalized->bv_val = ch_strdup("0");
1882 normalized->bv_len = 1;
1885 normalized->bv_len = len+negative;
1886 normalized->bv_val = ch_malloc( normalized->bv_len );
1888 normalized->bv_val[0] = '-';
1890 AC_MEMCPY( normalized->bv_val + negative, p, len );
1893 return LDAP_SUCCESS;
1896 /* Index generation function */
1897 static int integerIndexer(
1902 struct berval *prefix,
1909 /* we should have at least one value at this point */
1910 assert( values != NULL && values[0].bv_val != NULL );
1912 for( i=0; values[i].bv_val != NULL; i++ ) {
1913 /* empty -- just count them */
1916 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1918 for( i=0; values[i].bv_val != NULL; i++ ) {
1919 integerNormalize( syntax, &values[i], &keys[i] );
1922 keys[i].bv_val = NULL;
1924 return LDAP_SUCCESS;
1927 /* Index generation function */
1928 static int integerFilter(
1933 struct berval *prefix,
1939 keys = ch_malloc( sizeof( struct berval ) * 2 );
1940 integerNormalize( syntax, assertValue, &keys[0] );
1941 keys[1].bv_val = NULL;
1944 return LDAP_SUCCESS;
1949 countryStringValidate(
1951 struct berval *val )
1953 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1955 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1956 return LDAP_INVALID_SYNTAX;
1958 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1959 return LDAP_INVALID_SYNTAX;
1962 return LDAP_SUCCESS;
1966 printableStringValidate(
1968 struct berval *val )
1972 for(i=0; i < val->bv_len; i++) {
1973 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1974 return LDAP_INVALID_SYNTAX;
1978 return LDAP_SUCCESS;
1982 printablesStringValidate(
1984 struct berval *val )
1988 for(i=0; i < val->bv_len; i++) {
1989 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1990 return LDAP_INVALID_SYNTAX;
1994 return LDAP_SUCCESS;
2000 struct berval *val )
2004 for(i=0; i < val->bv_len; i++) {
2005 if( !LDAP_ASCII(val->bv_val[i]) ) {
2006 return LDAP_INVALID_SYNTAX;
2010 return LDAP_SUCCESS;
2017 struct berval *normalized )
2023 /* Ignore initial whitespace */
2024 while ( ASCII_SPACE( *p ) ) {
2028 normalized->bv_val = ch_strdup( p );
2029 p = q = normalized->bv_val;
2032 if ( ASCII_SPACE( *p ) ) {
2035 /* Ignore the extra whitespace */
2036 while ( ASCII_SPACE( *p ) ) {
2044 assert( normalized->bv_val <= p );
2048 * If the string ended in space, backup the pointer one
2049 * position. One is enough because the above loop collapsed
2050 * all whitespace to a single space.
2053 if ( ASCII_SPACE( q[-1] ) ) {
2057 /* null terminate */
2060 normalized->bv_len = q - normalized->bv_val;
2062 return LDAP_SUCCESS;
2071 struct berval *value,
2072 void *assertedValue )
2074 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2077 match = strncmp( value->bv_val,
2078 ((struct berval *) assertedValue)->bv_val,
2083 return LDAP_SUCCESS;
2087 caseExactIA5SubstringsMatch(
2092 struct berval *value,
2093 void *assertedValue )
2096 SubstringsAssertion *sub = assertedValue;
2097 struct berval left = *value;
2101 /* Add up asserted input length */
2102 if( sub->sa_initial.bv_val ) {
2103 inlen += sub->sa_initial.bv_len;
2106 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2107 inlen += sub->sa_any[i].bv_len;
2110 if( sub->sa_final.bv_val ) {
2111 inlen += sub->sa_final.bv_len;
2114 if( sub->sa_initial.bv_val ) {
2115 if( inlen > left.bv_len ) {
2120 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2121 sub->sa_initial.bv_len );
2127 left.bv_val += sub->sa_initial.bv_len;
2128 left.bv_len -= sub->sa_initial.bv_len;
2129 inlen -= sub->sa_initial.bv_len;
2132 if( sub->sa_final.bv_val ) {
2133 if( inlen > left.bv_len ) {
2138 match = strncmp( sub->sa_final.bv_val,
2139 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2140 sub->sa_final.bv_len );
2146 left.bv_len -= sub->sa_final.bv_len;
2147 inlen -= sub->sa_final.bv_len;
2151 for(i=0; sub->sa_any[i].bv_val; i++) {
2156 if( inlen > left.bv_len ) {
2157 /* not enough length */
2162 if( sub->sa_any[i].bv_len == 0 ) {
2166 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2173 idx = p - left.bv_val;
2175 if( idx >= left.bv_len ) {
2176 /* this shouldn't happen */
2183 if( sub->sa_any[i].bv_len > left.bv_len ) {
2184 /* not enough left */
2189 match = strncmp( left.bv_val,
2190 sub->sa_any[i].bv_val,
2191 sub->sa_any[i].bv_len );
2199 left.bv_val += sub->sa_any[i].bv_len;
2200 left.bv_len -= sub->sa_any[i].bv_len;
2201 inlen -= sub->sa_any[i].bv_len;
2207 return LDAP_SUCCESS;
2210 /* Index generation function */
2211 static int caseExactIA5Indexer(
2216 struct berval *prefix,
2223 HASH_CONTEXT HASHcontext;
2224 unsigned char HASHdigest[HASH_BYTES];
2225 struct berval digest;
2226 digest.bv_val = HASHdigest;
2227 digest.bv_len = sizeof(HASHdigest);
2229 for( i=0; values[i].bv_val != NULL; i++ ) {
2230 /* empty - just count them */
2233 /* we should have at least one value at this point */
2236 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2238 slen = syntax->ssyn_oidlen;
2239 mlen = mr->smr_oidlen;
2241 for( i=0; values[i].bv_val != NULL; i++ ) {
2242 struct berval *value = &values[i];
2244 HASH_Init( &HASHcontext );
2245 if( prefix != NULL && prefix->bv_len > 0 ) {
2246 HASH_Update( &HASHcontext,
2247 prefix->bv_val, prefix->bv_len );
2249 HASH_Update( &HASHcontext,
2250 syntax->ssyn_oid, slen );
2251 HASH_Update( &HASHcontext,
2252 mr->smr_oid, mlen );
2253 HASH_Update( &HASHcontext,
2254 value->bv_val, value->bv_len );
2255 HASH_Final( HASHdigest, &HASHcontext );
2257 ber_dupbv( &keys[i], &digest );
2260 keys[i].bv_val = NULL;
2262 return LDAP_SUCCESS;
2265 /* Index generation function */
2266 static int caseExactIA5Filter(
2271 struct berval *prefix,
2277 HASH_CONTEXT HASHcontext;
2278 unsigned char HASHdigest[HASH_BYTES];
2279 struct berval *value;
2280 struct berval digest;
2281 digest.bv_val = HASHdigest;
2282 digest.bv_len = sizeof(HASHdigest);
2284 slen = syntax->ssyn_oidlen;
2285 mlen = mr->smr_oidlen;
2287 value = (struct berval *) assertValue;
2289 keys = ch_malloc( sizeof( struct berval ) * 2 );
2291 HASH_Init( &HASHcontext );
2292 if( prefix != NULL && prefix->bv_len > 0 ) {
2293 HASH_Update( &HASHcontext,
2294 prefix->bv_val, prefix->bv_len );
2296 HASH_Update( &HASHcontext,
2297 syntax->ssyn_oid, slen );
2298 HASH_Update( &HASHcontext,
2299 mr->smr_oid, mlen );
2300 HASH_Update( &HASHcontext,
2301 value->bv_val, value->bv_len );
2302 HASH_Final( HASHdigest, &HASHcontext );
2304 ber_dupbv( &keys[0], &digest );
2305 keys[1].bv_val = NULL;
2308 return LDAP_SUCCESS;
2311 /* Substrings Index generation function */
2312 static int caseExactIA5SubstringsIndexer(
2317 struct berval *prefix,
2324 HASH_CONTEXT HASHcontext;
2325 unsigned char HASHdigest[HASH_BYTES];
2326 struct berval digest;
2327 digest.bv_val = HASHdigest;
2328 digest.bv_len = sizeof(HASHdigest);
2330 /* we should have at least one value at this point */
2331 assert( values != NULL && values[0].bv_val != NULL );
2334 for( i=0; values[i].bv_val != NULL; i++ ) {
2335 /* count number of indices to generate */
2336 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2340 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2341 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2342 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2343 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2345 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2349 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2350 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2351 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2355 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2356 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2357 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2358 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2360 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2366 /* no keys to generate */
2368 return LDAP_SUCCESS;
2371 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2373 slen = syntax->ssyn_oidlen;
2374 mlen = mr->smr_oidlen;
2377 for( i=0; values[i].bv_val != NULL; i++ ) {
2379 struct berval *value;
2382 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2384 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2385 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2387 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2388 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2390 for( j=0; j<max; j++ ) {
2391 HASH_Init( &HASHcontext );
2392 if( prefix != NULL && prefix->bv_len > 0 ) {
2393 HASH_Update( &HASHcontext,
2394 prefix->bv_val, prefix->bv_len );
2397 HASH_Update( &HASHcontext,
2398 &pre, sizeof( pre ) );
2399 HASH_Update( &HASHcontext,
2400 syntax->ssyn_oid, slen );
2401 HASH_Update( &HASHcontext,
2402 mr->smr_oid, mlen );
2403 HASH_Update( &HASHcontext,
2405 SLAP_INDEX_SUBSTR_MAXLEN );
2406 HASH_Final( HASHdigest, &HASHcontext );
2408 ber_dupbv( &keys[nkeys++], &digest );
2412 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2413 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2415 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2418 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2419 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2420 HASH_Init( &HASHcontext );
2421 if( prefix != NULL && prefix->bv_len > 0 ) {
2422 HASH_Update( &HASHcontext,
2423 prefix->bv_val, prefix->bv_len );
2425 HASH_Update( &HASHcontext,
2426 &pre, sizeof( pre ) );
2427 HASH_Update( &HASHcontext,
2428 syntax->ssyn_oid, slen );
2429 HASH_Update( &HASHcontext,
2430 mr->smr_oid, mlen );
2431 HASH_Update( &HASHcontext,
2433 HASH_Final( HASHdigest, &HASHcontext );
2435 ber_dupbv( &keys[nkeys++], &digest );
2438 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2439 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2440 HASH_Init( &HASHcontext );
2441 if( prefix != NULL && prefix->bv_len > 0 ) {
2442 HASH_Update( &HASHcontext,
2443 prefix->bv_val, prefix->bv_len );
2445 HASH_Update( &HASHcontext,
2446 &pre, sizeof( pre ) );
2447 HASH_Update( &HASHcontext,
2448 syntax->ssyn_oid, slen );
2449 HASH_Update( &HASHcontext,
2450 mr->smr_oid, mlen );
2451 HASH_Update( &HASHcontext,
2452 &value->bv_val[value->bv_len-j], j );
2453 HASH_Final( HASHdigest, &HASHcontext );
2455 ber_dupbv( &keys[nkeys++], &digest );
2462 keys[nkeys].bv_val = NULL;
2469 return LDAP_SUCCESS;
2472 static int caseExactIA5SubstringsFilter(
2477 struct berval *prefix,
2481 SubstringsAssertion *sa = assertValue;
2483 ber_len_t nkeys = 0;
2484 size_t slen, mlen, klen;
2486 HASH_CONTEXT HASHcontext;
2487 unsigned char HASHdigest[HASH_BYTES];
2488 struct berval *value;
2489 struct berval digest;
2491 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2492 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2497 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2499 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2500 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2501 /* don't bother accounting for stepping */
2502 nkeys += sa->sa_any[i].bv_len -
2503 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2508 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2509 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2516 return LDAP_SUCCESS;
2519 digest.bv_val = HASHdigest;
2520 digest.bv_len = sizeof(HASHdigest);
2522 slen = syntax->ssyn_oidlen;
2523 mlen = mr->smr_oidlen;
2525 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2528 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2529 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2531 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2532 value = &sa->sa_initial;
2534 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2535 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2537 HASH_Init( &HASHcontext );
2538 if( prefix != NULL && prefix->bv_len > 0 ) {
2539 HASH_Update( &HASHcontext,
2540 prefix->bv_val, prefix->bv_len );
2542 HASH_Update( &HASHcontext,
2543 &pre, sizeof( pre ) );
2544 HASH_Update( &HASHcontext,
2545 syntax->ssyn_oid, slen );
2546 HASH_Update( &HASHcontext,
2547 mr->smr_oid, mlen );
2548 HASH_Update( &HASHcontext,
2549 value->bv_val, klen );
2550 HASH_Final( HASHdigest, &HASHcontext );
2552 ber_dupbv( &keys[nkeys++], &digest );
2555 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2557 pre = SLAP_INDEX_SUBSTR_PREFIX;
2558 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2560 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2561 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2565 value = &sa->sa_any[i];
2568 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2569 j += SLAP_INDEX_SUBSTR_STEP )
2571 HASH_Init( &HASHcontext );
2572 if( prefix != NULL && prefix->bv_len > 0 ) {
2573 HASH_Update( &HASHcontext,
2574 prefix->bv_val, prefix->bv_len );
2576 HASH_Update( &HASHcontext,
2577 &pre, sizeof( pre ) );
2578 HASH_Update( &HASHcontext,
2579 syntax->ssyn_oid, slen );
2580 HASH_Update( &HASHcontext,
2581 mr->smr_oid, mlen );
2582 HASH_Update( &HASHcontext,
2583 &value->bv_val[j], klen );
2584 HASH_Final( HASHdigest, &HASHcontext );
2586 ber_dupbv( &keys[nkeys++], &digest );
2591 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2592 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2594 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2595 value = &sa->sa_final;
2597 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2598 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2600 HASH_Init( &HASHcontext );
2601 if( prefix != NULL && prefix->bv_len > 0 ) {
2602 HASH_Update( &HASHcontext,
2603 prefix->bv_val, prefix->bv_len );
2605 HASH_Update( &HASHcontext,
2606 &pre, sizeof( pre ) );
2607 HASH_Update( &HASHcontext,
2608 syntax->ssyn_oid, slen );
2609 HASH_Update( &HASHcontext,
2610 mr->smr_oid, mlen );
2611 HASH_Update( &HASHcontext,
2612 &value->bv_val[value->bv_len-klen], klen );
2613 HASH_Final( HASHdigest, &HASHcontext );
2615 ber_dupbv( &keys[nkeys++], &digest );
2619 keys[nkeys].bv_val = NULL;
2626 return LDAP_SUCCESS;
2635 struct berval *value,
2636 void *assertedValue )
2638 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2640 if( match == 0 && value->bv_len ) {
2641 match = strncasecmp( value->bv_val,
2642 ((struct berval *) assertedValue)->bv_val,
2647 return LDAP_SUCCESS;
2651 caseIgnoreIA5SubstringsMatch(
2656 struct berval *value,
2657 void *assertedValue )
2660 SubstringsAssertion *sub = assertedValue;
2661 struct berval left = *value;
2665 /* Add up asserted input length */
2666 if( sub->sa_initial.bv_val ) {
2667 inlen += sub->sa_initial.bv_len;
2670 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2671 inlen += sub->sa_any[i].bv_len;
2674 if( sub->sa_final.bv_val ) {
2675 inlen += sub->sa_final.bv_len;
2678 if( sub->sa_initial.bv_val ) {
2679 if( inlen > left.bv_len ) {
2684 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2685 sub->sa_initial.bv_len );
2691 left.bv_val += sub->sa_initial.bv_len;
2692 left.bv_len -= sub->sa_initial.bv_len;
2693 inlen -= sub->sa_initial.bv_len;
2696 if( sub->sa_final.bv_val ) {
2697 if( inlen > left.bv_len ) {
2702 match = strncasecmp( sub->sa_final.bv_val,
2703 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2704 sub->sa_final.bv_len );
2710 left.bv_len -= sub->sa_final.bv_len;
2711 inlen -= sub->sa_final.bv_len;
2715 for(i=0; sub->sa_any[i].bv_val; i++) {
2720 if( inlen > left.bv_len ) {
2721 /* not enough length */
2726 if( sub->sa_any[i].bv_len == 0 ) {
2730 p = bvcasechr( &left, *sub->sa_any[i].bv_val, &idx );
2737 assert( idx < left.bv_len );
2738 if( idx >= left.bv_len ) {
2739 /* this shouldn't happen */
2746 if( sub->sa_any[i].bv_len > left.bv_len ) {
2747 /* not enough left */
2752 match = strncasecmp( left.bv_val,
2753 sub->sa_any[i].bv_val,
2754 sub->sa_any[i].bv_len );
2763 left.bv_val += sub->sa_any[i].bv_len;
2764 left.bv_len -= sub->sa_any[i].bv_len;
2765 inlen -= sub->sa_any[i].bv_len;
2771 return LDAP_SUCCESS;
2774 /* Index generation function */
2775 static int caseIgnoreIA5Indexer(
2780 struct berval *prefix,
2787 HASH_CONTEXT HASHcontext;
2788 unsigned char HASHdigest[HASH_BYTES];
2789 struct berval digest;
2790 digest.bv_val = HASHdigest;
2791 digest.bv_len = sizeof(HASHdigest);
2793 /* we should have at least one value at this point */
2794 assert( values != NULL && values[0].bv_val != NULL );
2796 for( i=0; values[i].bv_val != NULL; i++ ) {
2797 /* just count them */
2800 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2802 slen = syntax->ssyn_oidlen;
2803 mlen = mr->smr_oidlen;
2805 for( i=0; values[i].bv_val != NULL; i++ ) {
2806 struct berval value;
2807 ber_dupbv( &value, &values[i] );
2808 ldap_pvt_str2upper( value.bv_val );
2810 HASH_Init( &HASHcontext );
2811 if( prefix != NULL && prefix->bv_len > 0 ) {
2812 HASH_Update( &HASHcontext,
2813 prefix->bv_val, prefix->bv_len );
2815 HASH_Update( &HASHcontext,
2816 syntax->ssyn_oid, slen );
2817 HASH_Update( &HASHcontext,
2818 mr->smr_oid, mlen );
2819 HASH_Update( &HASHcontext,
2820 value.bv_val, value.bv_len );
2821 HASH_Final( HASHdigest, &HASHcontext );
2823 free( value.bv_val );
2825 ber_dupbv( &keys[i], &digest );
2828 keys[i].bv_val = NULL;
2830 return LDAP_SUCCESS;
2833 /* Index generation function */
2834 static int caseIgnoreIA5Filter(
2839 struct berval *prefix,
2845 HASH_CONTEXT HASHcontext;
2846 unsigned char HASHdigest[HASH_BYTES];
2847 struct berval value;
2848 struct berval digest;
2849 digest.bv_val = HASHdigest;
2850 digest.bv_len = sizeof(HASHdigest);
2852 slen = syntax->ssyn_oidlen;
2853 mlen = mr->smr_oidlen;
2855 ber_dupbv( &value, (struct berval *) assertValue );
2856 ldap_pvt_str2upper( value.bv_val );
2858 keys = ch_malloc( sizeof( struct berval ) * 2 );
2860 HASH_Init( &HASHcontext );
2861 if( prefix != NULL && prefix->bv_len > 0 ) {
2862 HASH_Update( &HASHcontext,
2863 prefix->bv_val, prefix->bv_len );
2865 HASH_Update( &HASHcontext,
2866 syntax->ssyn_oid, slen );
2867 HASH_Update( &HASHcontext,
2868 mr->smr_oid, mlen );
2869 HASH_Update( &HASHcontext,
2870 value.bv_val, value.bv_len );
2871 HASH_Final( HASHdigest, &HASHcontext );
2873 ber_dupbv( &keys[0], &digest );
2874 keys[1].bv_val = NULL;
2876 free( value.bv_val );
2880 return LDAP_SUCCESS;
2883 /* Substrings Index generation function */
2884 static int caseIgnoreIA5SubstringsIndexer(
2889 struct berval *prefix,
2896 HASH_CONTEXT HASHcontext;
2897 unsigned char HASHdigest[HASH_BYTES];
2898 struct berval digest;
2899 digest.bv_val = HASHdigest;
2900 digest.bv_len = sizeof(HASHdigest);
2902 /* we should have at least one value at this point */
2903 assert( values != NULL && values[0].bv_val != NULL );
2906 for( i=0; values[i].bv_val != NULL; i++ ) {
2907 /* count number of indices to generate */
2908 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2912 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2913 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2914 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2915 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2917 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2921 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2922 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2923 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2927 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2928 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2929 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2930 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2932 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2938 /* no keys to generate */
2940 return LDAP_SUCCESS;
2943 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2945 slen = syntax->ssyn_oidlen;
2946 mlen = mr->smr_oidlen;
2949 for( i=0; values[i].bv_val != NULL; i++ ) {
2951 struct berval value;
2953 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2955 ber_dupbv( &value, &values[i] );
2956 ldap_pvt_str2upper( value.bv_val );
2958 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2959 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2961 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2962 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2964 for( j=0; j<max; j++ ) {
2965 HASH_Init( &HASHcontext );
2966 if( prefix != NULL && prefix->bv_len > 0 ) {
2967 HASH_Update( &HASHcontext,
2968 prefix->bv_val, prefix->bv_len );
2971 HASH_Update( &HASHcontext,
2972 &pre, sizeof( pre ) );
2973 HASH_Update( &HASHcontext,
2974 syntax->ssyn_oid, slen );
2975 HASH_Update( &HASHcontext,
2976 mr->smr_oid, mlen );
2977 HASH_Update( &HASHcontext,
2979 SLAP_INDEX_SUBSTR_MAXLEN );
2980 HASH_Final( HASHdigest, &HASHcontext );
2982 ber_dupbv( &keys[nkeys++], &digest );
2986 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2987 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2989 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2992 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2993 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2994 HASH_Init( &HASHcontext );
2995 if( prefix != NULL && prefix->bv_len > 0 ) {
2996 HASH_Update( &HASHcontext,
2997 prefix->bv_val, prefix->bv_len );
2999 HASH_Update( &HASHcontext,
3000 &pre, sizeof( pre ) );
3001 HASH_Update( &HASHcontext,
3002 syntax->ssyn_oid, slen );
3003 HASH_Update( &HASHcontext,
3004 mr->smr_oid, mlen );
3005 HASH_Update( &HASHcontext,
3007 HASH_Final( HASHdigest, &HASHcontext );
3009 ber_dupbv( &keys[nkeys++], &digest );
3012 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3013 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3014 HASH_Init( &HASHcontext );
3015 if( prefix != NULL && prefix->bv_len > 0 ) {
3016 HASH_Update( &HASHcontext,
3017 prefix->bv_val, prefix->bv_len );
3019 HASH_Update( &HASHcontext,
3020 &pre, sizeof( pre ) );
3021 HASH_Update( &HASHcontext,
3022 syntax->ssyn_oid, slen );
3023 HASH_Update( &HASHcontext,
3024 mr->smr_oid, mlen );
3025 HASH_Update( &HASHcontext,
3026 &value.bv_val[value.bv_len-j], j );
3027 HASH_Final( HASHdigest, &HASHcontext );
3029 ber_dupbv( &keys[nkeys++], &digest );
3034 free( value.bv_val );
3038 keys[nkeys].bv_val = NULL;
3045 return LDAP_SUCCESS;
3048 static int caseIgnoreIA5SubstringsFilter(
3053 struct berval *prefix,
3057 SubstringsAssertion *sa = assertValue;
3059 ber_len_t nkeys = 0;
3060 size_t slen, mlen, klen;
3062 HASH_CONTEXT HASHcontext;
3063 unsigned char HASHdigest[HASH_BYTES];
3064 struct berval value;
3065 struct berval digest;
3067 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3068 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3073 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3075 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3076 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3077 /* don't bother accounting for stepping */
3078 nkeys += sa->sa_any[i].bv_len -
3079 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3084 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3085 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3092 return LDAP_SUCCESS;
3095 digest.bv_val = HASHdigest;
3096 digest.bv_len = sizeof(HASHdigest);
3098 slen = syntax->ssyn_oidlen;
3099 mlen = mr->smr_oidlen;
3101 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3104 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3105 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3107 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3108 ber_dupbv( &value, &sa->sa_initial );
3109 ldap_pvt_str2upper( value.bv_val );
3111 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3112 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3114 HASH_Init( &HASHcontext );
3115 if( prefix != NULL && prefix->bv_len > 0 ) {
3116 HASH_Update( &HASHcontext,
3117 prefix->bv_val, prefix->bv_len );
3119 HASH_Update( &HASHcontext,
3120 &pre, sizeof( pre ) );
3121 HASH_Update( &HASHcontext,
3122 syntax->ssyn_oid, slen );
3123 HASH_Update( &HASHcontext,
3124 mr->smr_oid, mlen );
3125 HASH_Update( &HASHcontext,
3126 value.bv_val, klen );
3127 HASH_Final( HASHdigest, &HASHcontext );
3129 free( value.bv_val );
3130 ber_dupbv( &keys[nkeys++], &digest );
3133 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3135 pre = SLAP_INDEX_SUBSTR_PREFIX;
3136 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3138 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3139 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3143 ber_dupbv( &value, &sa->sa_any[i] );
3144 ldap_pvt_str2upper( value.bv_val );
3147 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3148 j += SLAP_INDEX_SUBSTR_STEP )
3150 HASH_Init( &HASHcontext );
3151 if( prefix != NULL && prefix->bv_len > 0 ) {
3152 HASH_Update( &HASHcontext,
3153 prefix->bv_val, prefix->bv_len );
3155 HASH_Update( &HASHcontext,
3156 &pre, sizeof( pre ) );
3157 HASH_Update( &HASHcontext,
3158 syntax->ssyn_oid, slen );
3159 HASH_Update( &HASHcontext,
3160 mr->smr_oid, mlen );
3161 HASH_Update( &HASHcontext,
3162 &value.bv_val[j], klen );
3163 HASH_Final( HASHdigest, &HASHcontext );
3165 ber_dupbv( &keys[nkeys++], &digest );
3168 free( value.bv_val );
3172 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3173 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3175 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3176 ber_dupbv( &value, &sa->sa_final );
3177 ldap_pvt_str2upper( value.bv_val );
3179 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3180 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3182 HASH_Init( &HASHcontext );
3183 if( prefix != NULL && prefix->bv_len > 0 ) {
3184 HASH_Update( &HASHcontext,
3185 prefix->bv_val, prefix->bv_len );
3187 HASH_Update( &HASHcontext,
3188 &pre, sizeof( pre ) );
3189 HASH_Update( &HASHcontext,
3190 syntax->ssyn_oid, slen );
3191 HASH_Update( &HASHcontext,
3192 mr->smr_oid, mlen );
3193 HASH_Update( &HASHcontext,
3194 &value.bv_val[value.bv_len-klen], klen );
3195 HASH_Final( HASHdigest, &HASHcontext );
3197 free( value.bv_val );
3198 ber_dupbv( &keys[nkeys++], &digest );
3202 keys[nkeys].bv_val = NULL;
3209 return LDAP_SUCCESS;
3213 numericStringValidate(
3219 for(i=0; i < in->bv_len; i++) {
3220 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3221 return LDAP_INVALID_SYNTAX;
3225 return LDAP_SUCCESS;
3229 numericStringNormalize(
3232 struct berval *normalized )
3234 /* removal all spaces */
3237 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3240 q = normalized->bv_val;
3243 if ( ASCII_SPACE( *p ) ) {
3244 /* Ignore whitespace */
3251 /* we should have copied no more then is in val */
3252 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3254 /* null terminate */
3257 normalized->bv_len = q - normalized->bv_val;
3259 return LDAP_SUCCESS;
3263 objectIdentifierFirstComponentMatch(
3268 struct berval *value,
3269 void *assertedValue )
3271 int rc = LDAP_SUCCESS;
3273 struct berval *asserted = (struct berval *) assertedValue;
3277 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3278 return LDAP_INVALID_SYNTAX;
3281 /* trim leading white space */
3282 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3286 /* grab next word */
3287 oid.bv_val = &value->bv_val[i];
3288 oid.bv_len = value->bv_len - i;
3289 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3294 /* insert attributeTypes, objectclass check here */
3295 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3296 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3299 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3300 MatchingRule *asserted_mr = mr_bvfind( asserted );
3301 MatchingRule *stored_mr = mr_bvfind( &oid );
3303 if( asserted_mr == NULL ) {
3304 rc = SLAPD_COMPARE_UNDEFINED;
3306 match = asserted_mr != stored_mr;
3309 } else if ( !strcmp( syntax->ssyn_oid,
3310 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3312 AttributeType *asserted_at = at_bvfind( asserted );
3313 AttributeType *stored_at = at_bvfind( &oid );
3315 if( asserted_at == NULL ) {
3316 rc = SLAPD_COMPARE_UNDEFINED;
3318 match = asserted_at != stored_at;
3321 } else if ( !strcmp( syntax->ssyn_oid,
3322 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3324 ObjectClass *asserted_oc = oc_bvfind( asserted );
3325 ObjectClass *stored_oc = oc_bvfind( &oid );
3327 if( asserted_oc == NULL ) {
3328 rc = SLAPD_COMPARE_UNDEFINED;
3330 match = asserted_oc != stored_oc;
3336 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3337 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3338 match, value->bv_val, asserted->bv_val ));
3340 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3341 "%d\n\t\"%s\"\n\t\"%s\"\n",
3342 match, value->bv_val, asserted->bv_val );
3346 if( rc == LDAP_SUCCESS ) *matchp = match;
3356 struct berval *value,
3357 void *assertedValue )
3359 long lValue, lAssertedValue;
3361 /* safe to assume integers are NUL terminated? */
3362 lValue = strtoul(value->bv_val, NULL, 10);
3363 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3364 return LDAP_CONSTRAINT_VIOLATION;
3366 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3367 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3368 return LDAP_CONSTRAINT_VIOLATION;
3370 *matchp = (lValue & lAssertedValue);
3371 return LDAP_SUCCESS;
3380 struct berval *value,
3381 void *assertedValue )
3383 long lValue, lAssertedValue;
3385 /* safe to assume integers are NUL terminated? */
3386 lValue = strtoul(value->bv_val, NULL, 10);
3387 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3388 return LDAP_CONSTRAINT_VIOLATION;
3390 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3391 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3392 return LDAP_CONSTRAINT_VIOLATION;
3394 *matchp = (lValue | lAssertedValue);
3395 return LDAP_SUCCESS;
3399 #include <openssl/x509.h>
3400 #include <openssl/err.h>
3401 char digit[] = "0123456789";
3404 * Next function returns a string representation of a ASN1_INTEGER.
3405 * It works for unlimited lengths.
3408 static struct berval *
3409 asn1_integer2str(ASN1_INTEGER *a)
3414 /* We work backwards, make it fill from the end of buf */
3415 p = buf + sizeof(buf) - 1;
3418 if ( a == NULL || a->length == 0 ) {
3426 /* We want to preserve the original */
3427 copy = ch_malloc(n*sizeof(unsigned int));
3428 for (i = 0; i<n; i++) {
3429 copy[i] = a->data[i];
3433 * base indicates the index of the most significant
3434 * byte that might be nonzero. When it goes off the
3435 * end, we now there is nothing left to do.
3441 for (i = base; i<n; i++ ) {
3442 copy[i] += carry*256;
3443 carry = copy[i] % 10;
3448 * Way too large, we need to leave
3449 * room for sign if negative
3454 *--p = digit[carry];
3455 if (copy[base] == 0)
3461 if ( a->type == V_ASN1_NEG_INTEGER ) {
3465 return ber_bvstrdup(p);
3468 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3469 static struct berval *
3470 dn_openssl2ldap(X509_NAME *name)
3472 char issuer_dn[1024];
3475 bio = BIO_new(BIO_s_mem());
3478 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3479 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3480 ERR_error_string(ERR_get_error(),NULL)));
3482 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3483 "error creating BIO: %s\n",
3484 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3488 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3490 BIO_gets(bio, issuer_dn, 1024);
3493 return ber_bvstrdup(issuer_dn);
3497 * Given a certificate in DER format, extract the corresponding
3498 * assertion value for certificateExactMatch
3501 certificateExactConvert(
3503 struct berval * out )
3506 unsigned char *p = in->bv_val;
3507 struct berval *serial;
3508 struct berval *issuer_dn;
3509 struct berval *bv_tmp;
3511 xcert = d2i_X509(NULL, &p, in->bv_len);
3514 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3515 "certificateExactConvert: error parsing cert: %s\n",
3516 ERR_error_string(ERR_get_error(),NULL)));
3518 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3519 "error parsing cert: %s\n",
3520 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3522 return LDAP_INVALID_SYNTAX;
3525 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3528 return LDAP_INVALID_SYNTAX;
3530 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3534 return LDAP_INVALID_SYNTAX;
3536 /* Actually, dn_openssl2ldap returns in a normalized format, but
3537 it is different from our normalized format */
3539 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3543 return LDAP_INVALID_SYNTAX;
3549 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3550 out->bv_val = ch_malloc(out->bv_len);
3552 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3553 p += serial->bv_len;
3554 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3556 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3557 p += issuer_dn->bv_len;
3561 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3562 "certificateExactConvert: \n %s\n",
3565 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3567 out->bv_val, NULL, NULL );
3571 ber_bvfree(issuer_dn);
3573 return LDAP_SUCCESS;
3577 serial_and_issuer_parse(
3578 struct berval *assertion,
3579 struct berval **serial,
3580 struct berval **issuer_dn
3588 begin = assertion->bv_val;
3589 end = assertion->bv_val+assertion->bv_len-1;
3590 for (p=begin; p<=end && *p != '$'; p++)
3593 return LDAP_INVALID_SYNTAX;
3595 /* p now points at the $ sign, now use begin and end to delimit the
3597 while (ASCII_SPACE(*begin))
3600 while (ASCII_SPACE(*end))
3603 bv.bv_len = end-begin+1;
3605 *serial = ber_dupbv(NULL, &bv);
3607 /* now extract the issuer, remember p was at the dollar sign */
3609 end = assertion->bv_val+assertion->bv_len-1;
3610 while (ASCII_SPACE(*begin))
3612 /* should we trim spaces at the end too? is it safe always? */
3614 bv.bv_len = end-begin+1;
3616 dnNormalize( NULL, &bv, issuer_dn );
3618 return LDAP_SUCCESS;
3622 certificateExactMatch(
3627 struct berval *value,
3628 void *assertedValue )
3631 unsigned char *p = value->bv_val;
3632 struct berval *serial;
3633 struct berval *issuer_dn;
3634 struct berval *asserted_serial;
3635 struct berval *asserted_issuer_dn;
3638 xcert = d2i_X509(NULL, &p, value->bv_len);
3641 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3642 "certificateExactMatch: error parsing cert: %s\n",
3643 ERR_error_string(ERR_get_error(),NULL)));
3645 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3646 "error parsing cert: %s\n",
3647 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3649 return LDAP_INVALID_SYNTAX;
3652 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3653 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3657 serial_and_issuer_parse(assertedValue,
3659 &asserted_issuer_dn);
3664 slap_schema.si_syn_integer,
3665 slap_schema.si_mr_integerMatch,
3668 if ( ret == LDAP_SUCCESS ) {
3669 if ( *matchp == 0 ) {
3670 /* We need to normalize everything for dnMatch */
3674 slap_schema.si_syn_distinguishedName,
3675 slap_schema.si_mr_distinguishedNameMatch,
3677 asserted_issuer_dn);
3682 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3683 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3684 *matchp, serial->bv_val, issuer_dn->bv_val,
3685 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3687 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3688 "%d\n\t\"%s $ %s\"\n",
3689 *matchp, serial->bv_val, issuer_dn->bv_val );
3690 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3691 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3696 ber_bvfree(issuer_dn);
3697 ber_bvfree(asserted_serial);
3698 ber_bvfree(asserted_issuer_dn);
3704 * Index generation function
3705 * We just index the serials, in most scenarios the issuer DN is one of
3706 * a very small set of values.
3708 static int certificateExactIndexer(
3713 struct berval *prefix,
3721 struct berval * serial;
3723 /* we should have at least one value at this point */
3724 assert( values != NULL && values[0].bv_val != NULL );
3726 for( i=0; values[i].bv_val != NULL; i++ ) {
3727 /* empty -- just count them */
3730 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3732 for( i=0; values[i].bv_val != NULL; i++ ) {
3733 p = values[i].bv_val;
3734 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3737 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3738 "certificateExactIndexer: error parsing cert: %s\n",
3739 ERR_error_string(ERR_get_error(),NULL)));
3741 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3742 "error parsing cert: %s\n",
3743 ERR_error_string(ERR_get_error(),NULL),
3746 /* Do we leak keys on error? */
3747 return LDAP_INVALID_SYNTAX;
3750 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3752 integerNormalize( slap_schema.si_syn_integer,
3757 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3758 "certificateExactIndexer: returning: %s\n",
3761 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3768 keys[i].bv_val = NULL;
3770 return LDAP_SUCCESS;
3773 /* Index generation function */
3774 /* We think this is always called with a value in matching rule syntax */
3775 static int certificateExactFilter(
3780 struct berval *prefix,
3785 struct berval *asserted_serial;
3786 struct berval *asserted_issuer_dn;
3788 serial_and_issuer_parse(assertValue,
3790 &asserted_issuer_dn);
3792 keys = ch_malloc( sizeof( struct berval ) * 2 );
3793 integerNormalize( syntax, asserted_serial, &keys[0] );
3794 keys[1].bv_val = NULL;
3797 ber_bvfree(asserted_serial);
3798 ber_bvfree(asserted_issuer_dn);
3799 return LDAP_SUCCESS;
3804 check_time_syntax (struct berval *val,
3808 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3809 static int mdays[2][12] = {
3810 /* non-leap years */
3811 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3813 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3816 int part, c, tzoffset, leapyear = 0 ;
3818 if( val->bv_len == 0 ) {
3819 return LDAP_INVALID_SYNTAX;
3822 p = (char *)val->bv_val;
3823 e = p + val->bv_len;
3825 /* Ignore initial whitespace */
3826 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3830 if (e - p < 13 - (2 * start)) {
3831 return LDAP_INVALID_SYNTAX;
3834 for (part = 0; part < 9; part++) {
3838 for (part = start; part < 7; part++) {
3840 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3847 return LDAP_INVALID_SYNTAX;
3849 if (c < 0 || c > 9) {
3850 return LDAP_INVALID_SYNTAX;
3856 return LDAP_INVALID_SYNTAX;
3858 if (c < 0 || c > 9) {
3859 return LDAP_INVALID_SYNTAX;
3864 if (part == 2 || part == 3) {
3867 if (parts[part] < 0) {
3868 return LDAP_INVALID_SYNTAX;
3870 if (parts[part] > ceiling[part]) {
3871 return LDAP_INVALID_SYNTAX;
3875 /* leapyear check for the Gregorian calendar (year>1581) */
3876 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3877 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3882 if (parts[3] > mdays[leapyear][parts[2]]) {
3883 return LDAP_INVALID_SYNTAX;
3888 tzoffset = 0; /* UTC */
3889 } else if (c != '+' && c != '-') {
3890 return LDAP_INVALID_SYNTAX;
3894 } else /* c == '+' */ {
3899 return LDAP_INVALID_SYNTAX;
3902 for (part = 7; part < 9; part++) {
3904 if (c < 0 || c > 9) {
3905 return LDAP_INVALID_SYNTAX;
3910 if (c < 0 || c > 9) {
3911 return LDAP_INVALID_SYNTAX;
3915 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3916 return LDAP_INVALID_SYNTAX;
3921 /* Ignore trailing whitespace */
3922 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3926 return LDAP_INVALID_SYNTAX;
3929 switch ( tzoffset ) {
3930 case -1: /* negativ offset to UTC, ie west of Greenwich */
3931 parts[4] += parts[7];
3932 parts[5] += parts[8];
3933 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3937 c = mdays[leapyear][parts[2]];
3939 if (parts[part] > c) {
3940 parts[part] -= c + 1;
3945 case 1: /* positive offset to UTC, ie east of Greenwich */
3946 parts[4] -= parts[7];
3947 parts[5] -= parts[8];
3948 for (part = 6; --part > 0; ) {
3952 /* first arg to % needs to be non negativ */
3953 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3955 if (parts[part] < 0) {
3956 parts[part] += c + 1;
3961 case 0: /* already UTC */
3965 return LDAP_SUCCESS;
3972 struct berval *normalized )
3976 rc = check_time_syntax(val, 1, parts);
3977 if (rc != LDAP_SUCCESS) {
3981 normalized->bv_val = ch_malloc( 14 );
3982 if ( normalized->bv_val == NULL ) {
3983 return LBER_ERROR_MEMORY;
3986 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3987 parts[1], parts[2] + 1, parts[3] + 1,
3988 parts[4], parts[5], parts[6] );
3989 normalized->bv_len = 13;
3991 return LDAP_SUCCESS;
4001 return check_time_syntax(in, 1, parts);
4005 generalizedTimeValidate(
4011 return check_time_syntax(in, 0, parts);
4015 generalizedTimeNormalize(
4018 struct berval *normalized )
4022 rc = check_time_syntax(val, 0, parts);
4023 if (rc != LDAP_SUCCESS) {
4027 normalized->bv_val = ch_malloc( 16 );
4028 if ( normalized->bv_val == NULL ) {
4029 return LBER_ERROR_MEMORY;
4032 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4033 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4034 parts[4], parts[5], parts[6] );
4035 normalized->bv_len = 15;
4037 return LDAP_SUCCESS;
4041 nisNetgroupTripleValidate(
4043 struct berval *val )
4048 if ( val->bv_len == 0 ) {
4049 return LDAP_INVALID_SYNTAX;
4052 p = (char *)val->bv_val;
4053 e = p + val->bv_len;
4055 if ( *p != '(' /*')'*/ ) {
4056 return LDAP_INVALID_SYNTAX;
4059 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4063 return LDAP_INVALID_SYNTAX;
4066 } else if ( !ATTR_CHAR( *p ) ) {
4067 return LDAP_INVALID_SYNTAX;
4071 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4072 return LDAP_INVALID_SYNTAX;
4078 return LDAP_INVALID_SYNTAX;
4081 return LDAP_SUCCESS;
4085 bootParameterValidate(
4087 struct berval *val )
4091 if ( val->bv_len == 0 ) {
4092 return LDAP_INVALID_SYNTAX;
4095 p = (char *)val->bv_val;
4096 e = p + val->bv_len;
4099 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4100 if ( !ATTR_CHAR( *p ) ) {
4101 return LDAP_INVALID_SYNTAX;
4106 return LDAP_INVALID_SYNTAX;
4110 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4111 if ( !ATTR_CHAR( *p ) ) {
4112 return LDAP_INVALID_SYNTAX;
4117 return LDAP_INVALID_SYNTAX;
4121 for ( p++; p < e; p++ ) {
4122 if ( !ATTR_CHAR( *p ) ) {
4123 return LDAP_INVALID_SYNTAX;
4127 return LDAP_SUCCESS;
4130 static struct syntax_defs_rec {
4132 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4133 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4135 slap_syntax_validate_func *sd_validate;
4136 slap_syntax_transform_func *sd_normalize;
4137 slap_syntax_transform_func *sd_pretty;
4138 #ifdef SLAPD_BINARY_CONVERSION
4139 slap_syntax_transform_func *sd_ber2str;
4140 slap_syntax_transform_func *sd_str2ber;
4143 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4144 X_BINARY X_NOT_H_R ")",
4145 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4146 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4147 0, NULL, NULL, NULL},
4148 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4149 0, NULL, NULL, NULL},
4150 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4152 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4155 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4156 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4157 0, bitStringValidate, bitStringNormalize, NULL },
4158 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4159 0, booleanValidate, NULL, NULL},
4160 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4161 X_BINARY X_NOT_H_R ")",
4162 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4164 X_BINARY X_NOT_H_R ")",
4165 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4166 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4167 X_BINARY X_NOT_H_R ")",
4168 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4170 0, countryStringValidate, IA5StringNormalize, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4172 0, dnValidate, dnNormalize2, dnPretty2},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4174 0, NULL, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4176 0, NULL, NULL, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4178 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4180 0, NULL, NULL, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4182 0, NULL, NULL, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4184 0, NULL, NULL, NULL},
4185 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4186 0, NULL, NULL, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4188 0, NULL, NULL, NULL},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4190 0, printablesStringValidate, IA5StringNormalize, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4192 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4194 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4196 0, NULL, NULL, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4198 0, IA5StringValidate, IA5StringNormalize, NULL},
4199 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4200 0, integerValidate, integerNormalize, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4202 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4204 0, NULL, NULL, NULL},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4206 0, NULL, NULL, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4208 0, NULL, NULL, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4210 0, NULL, NULL, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4212 0, NULL, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4214 0, nameUIDValidate, nameUIDNormalize, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4216 0, NULL, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4218 0, numericStringValidate, numericStringNormalize, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4220 0, NULL, NULL, NULL},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4222 0, oidValidate, NULL, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4224 0, IA5StringValidate, IA5StringNormalize, NULL},
4225 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4226 0, blobValidate, NULL, NULL},
4227 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4228 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4230 0, NULL, NULL, NULL},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4232 0, NULL, NULL, NULL},
4233 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4234 0, printableStringValidate, IA5StringNormalize, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4236 X_BINARY X_NOT_H_R ")",
4237 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4238 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4239 X_BINARY X_NOT_H_R ")",
4240 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4242 0, printableStringValidate, IA5StringNormalize, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4244 0, NULL, NULL, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4246 0, printablesStringValidate, IA5StringNormalize, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4248 0, utcTimeValidate, utcTimeNormalize, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4250 0, NULL, NULL, NULL},
4251 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4252 0, NULL, NULL, NULL},
4253 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4254 0, NULL, NULL, NULL},
4255 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4256 0, NULL, NULL, NULL},
4257 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4258 0, NULL, NULL, NULL},
4260 /* RFC 2307 NIS Syntaxes */
4261 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4262 0, nisNetgroupTripleValidate, NULL, NULL},
4263 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4264 0, bootParameterValidate, NULL, NULL},
4268 /* These OIDs are not published yet, but will be in the next
4269 * I-D for PKIX LDAPv3 schema as have been advanced by David
4270 * Chadwick in private mail.
4272 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4273 0, NULL, NULL, NULL},
4276 /* OpenLDAP Experimental Syntaxes */
4277 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4279 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4282 #ifdef SLAPD_AUTHPASSWD
4283 /* needs updating */
4284 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4285 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4288 /* OpenLDAP Void Syntax */
4289 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4290 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4291 {NULL, 0, NULL, NULL, NULL}
4295 * Other matching rules in X.520 that we do not use (yet):
4297 * 2.5.13.9 numericStringOrderingMatch
4298 * 2.5.13.15 integerOrderingMatch
4299 * 2.5.13.18 octetStringOrderingMatch
4300 * 2.5.13.19 octetStringSubstringsMatch
4301 * 2.5.13.25 uTCTimeMatch
4302 * 2.5.13.26 uTCTimeOrderingMatch
4303 * 2.5.13.31 directoryStringFirstComponentMatch
4304 * 2.5.13.32 wordMatch
4305 * 2.5.13.33 keywordMatch
4306 * 2.5.13.35 certificateMatch
4307 * 2.5.13.36 certificatePairExactMatch
4308 * 2.5.13.37 certificatePairMatch
4309 * 2.5.13.38 certificateListExactMatch
4310 * 2.5.13.39 certificateListMatch
4311 * 2.5.13.40 algorithmIdentifierMatch
4312 * 2.5.13.41 storedPrefixMatch
4313 * 2.5.13.42 attributeCertificateMatch
4314 * 2.5.13.43 readerAndKeyIDMatch
4315 * 2.5.13.44 attributeIntegrityMatch
4317 static struct mrule_defs_rec {
4319 slap_mask_t mrd_usage;
4320 slap_mr_convert_func * mrd_convert;
4321 slap_mr_normalize_func * mrd_normalize;
4322 slap_mr_match_func * mrd_match;
4323 slap_mr_indexer_func * mrd_indexer;
4324 slap_mr_filter_func * mrd_filter;
4326 char * mrd_associated;
4329 * EQUALITY matching rules must be listed after associated APPROX
4330 * matching rules. So, we list all APPROX matching rules first.
4332 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4333 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4334 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4336 directoryStringApproxMatch,
4337 directoryStringApproxIndexer,
4338 directoryStringApproxFilter,
4341 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4342 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4343 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4345 IA5StringApproxMatch,
4346 IA5StringApproxIndexer,
4347 IA5StringApproxFilter,
4351 * Other matching rules
4354 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4355 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4356 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4358 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4361 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4362 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4363 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4365 dnMatch, dnIndexer, dnFilter,
4368 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4369 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4370 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4372 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4373 directoryStringApproxMatchOID },
4375 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4376 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4379 caseIgnoreOrderingMatch, NULL, NULL,
4382 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4383 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4384 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4386 caseExactIgnoreSubstringsMatch,
4387 caseExactIgnoreSubstringsIndexer,
4388 caseExactIgnoreSubstringsFilter,
4391 {"( 2.5.13.5 NAME 'caseExactMatch' "
4392 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4393 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4395 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4396 directoryStringApproxMatchOID },
4398 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4399 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4402 caseExactOrderingMatch, NULL, NULL,
4405 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4406 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4407 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4409 caseExactIgnoreSubstringsMatch,
4410 caseExactIgnoreSubstringsIndexer,
4411 caseExactIgnoreSubstringsFilter,
4414 {"( 2.5.13.8 NAME 'numericStringMatch' "
4415 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4416 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4419 caseIgnoreIA5Indexer,
4420 caseIgnoreIA5Filter,
4423 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4424 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4425 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4427 caseIgnoreIA5SubstringsMatch,
4428 caseIgnoreIA5SubstringsIndexer,
4429 caseIgnoreIA5SubstringsFilter,
4432 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4433 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4434 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4436 caseIgnoreListMatch, NULL, NULL,
4439 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4440 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4441 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4443 caseIgnoreListSubstringsMatch, NULL, NULL,
4446 {"( 2.5.13.13 NAME 'booleanMatch' "
4447 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4448 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4450 booleanMatch, NULL, NULL,
4453 {"( 2.5.13.14 NAME 'integerMatch' "
4454 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4455 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4457 integerMatch, integerIndexer, integerFilter,
4460 {"( 2.5.13.16 NAME 'bitStringMatch' "
4461 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4462 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4464 bitStringMatch, bitStringIndexer, bitStringFilter,
4467 {"( 2.5.13.17 NAME 'octetStringMatch' "
4468 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4469 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4471 octetStringMatch, octetStringIndexer, octetStringFilter,
4474 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4475 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4476 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4478 telephoneNumberMatch,
4479 telephoneNumberIndexer,
4480 telephoneNumberFilter,
4483 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4484 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4485 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4487 telephoneNumberSubstringsMatch,
4488 telephoneNumberSubstringsIndexer,
4489 telephoneNumberSubstringsFilter,
4492 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4493 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4494 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4499 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4500 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4501 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4503 uniqueMemberMatch, NULL, NULL,
4506 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4507 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4508 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4510 protocolInformationMatch, NULL, NULL,
4513 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4514 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4515 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4517 generalizedTimeMatch, NULL, NULL,
4520 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4521 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4524 generalizedTimeOrderingMatch, NULL, NULL,
4527 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4528 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4529 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4531 integerFirstComponentMatch, NULL, NULL,
4534 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4535 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4536 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4538 objectIdentifierFirstComponentMatch, NULL, NULL,
4542 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4543 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4544 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4545 certificateExactConvert, NULL,
4546 certificateExactMatch,
4547 certificateExactIndexer, certificateExactFilter,
4551 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4552 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4553 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4555 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4556 IA5StringApproxMatchOID },
4558 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4559 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4560 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4562 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4563 IA5StringApproxMatchOID },
4565 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4566 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4569 caseIgnoreIA5SubstringsMatch,
4570 caseIgnoreIA5SubstringsIndexer,
4571 caseIgnoreIA5SubstringsFilter,
4574 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4575 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4578 caseExactIA5SubstringsMatch,
4579 caseExactIA5SubstringsIndexer,
4580 caseExactIA5SubstringsFilter,
4583 #ifdef SLAPD_AUTHPASSWD
4584 /* needs updating */
4585 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4586 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4589 authPasswordMatch, NULL, NULL,
4593 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4594 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4597 OpenLDAPaciMatch, NULL, NULL,
4600 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4601 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4604 integerBitAndMatch, NULL, NULL,
4607 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4608 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4611 integerBitOrMatch, NULL, NULL,
4614 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4618 slap_schema_init( void )
4623 /* we should only be called once (from main) */
4624 assert( schema_init_done == 0 );
4626 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4627 res = register_syntax( syntax_defs[i].sd_desc,
4628 syntax_defs[i].sd_flags,
4629 syntax_defs[i].sd_validate,
4630 syntax_defs[i].sd_normalize,
4631 syntax_defs[i].sd_pretty
4632 #ifdef SLAPD_BINARY_CONVERSION
4634 syntax_defs[i].sd_ber2str,
4635 syntax_defs[i].sd_str2ber
4640 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4641 syntax_defs[i].sd_desc );
4646 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4647 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4649 "slap_schema_init: Ingoring unusable matching rule %s\n",
4650 mrule_defs[i].mrd_desc );
4654 res = register_matching_rule(
4655 mrule_defs[i].mrd_desc,
4656 mrule_defs[i].mrd_usage,
4657 mrule_defs[i].mrd_convert,
4658 mrule_defs[i].mrd_normalize,
4659 mrule_defs[i].mrd_match,
4660 mrule_defs[i].mrd_indexer,
4661 mrule_defs[i].mrd_filter,
4662 mrule_defs[i].mrd_associated );
4666 "slap_schema_init: Error registering matching rule %s\n",
4667 mrule_defs[i].mrd_desc );
4672 res = slap_schema_load();
4673 schema_init_done = 1;
4678 schema_destroy( void )