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 UTF8bvnormalize( &sa->sa_initial, &nsa->sa_initial, casefold );
613 if( nsa->sa_initial.bv_val == NULL ) {
618 if( sa->sa_any != NULL ) {
619 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
622 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
623 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
624 UTF8bvnormalize( &sa->sa_any[i], &nsa->sa_any[i],
626 if( nsa->sa_any[i].bv_val == NULL ) {
630 nsa->sa_any[i].bv_val = NULL;
633 if( sa->sa_final.bv_val != NULL ) {
634 UTF8bvnormalize( &sa->sa_final, &nsa->sa_final, casefold );
635 if( nsa->sa_final.bv_val == NULL ) {
643 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
644 if ( nsa->sa_any )ber_bvarray_free( nsa->sa_any );
645 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
650 /* Strip characters with the 8th bit set */
663 while( *++q & 0x80 ) {
666 p = AC_MEMCPY(p, q, strlen(q) + 1);
674 #ifndef SLAPD_APPROX_OLDSINGLESTRING
676 #if defined(SLAPD_APPROX_INITIALS)
677 #define SLAPD_APPROX_DELIMITER "._ "
678 #define SLAPD_APPROX_WORDLEN 2
680 #define SLAPD_APPROX_DELIMITER " "
681 #define SLAPD_APPROX_WORDLEN 1
690 struct berval *value,
691 void *assertedValue )
693 char *val, *nval, *assertv, **values, **words, *c;
694 int i, count, len, nextchunk=0, nextavail=0;
697 /* Yes, this is necessary */
698 nval = UTF8normalize( value, LDAP_UTF8_NOCASEFOLD );
703 strip8bitChars( nval );
705 /* Yes, this is necessary */
706 assertv = UTF8normalize( ((struct berval *)assertedValue),
707 LDAP_UTF8_NOCASEFOLD );
708 if( assertv == NULL ) {
713 strip8bitChars( assertv );
714 avlen = strlen( assertv );
716 /* Isolate how many words there are */
717 for( c=nval,count=1; *c; c++ ) {
718 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
719 if ( c == NULL ) break;
724 /* Get a phonetic copy of each word */
725 words = (char **)ch_malloc( count * sizeof(char *) );
726 values = (char **)ch_malloc( count * sizeof(char *) );
727 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
729 values[i] = phonetic(c);
732 /* Work through the asserted value's words, to see if at least some
733 of the words are there, in the same order. */
735 while ( (size_t) nextchunk < avlen ) {
736 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
741 #if defined(SLAPD_APPROX_INITIALS)
742 else if( len == 1 ) {
743 /* Single letter words need to at least match one word's initial */
744 for( i=nextavail; i<count; i++ )
745 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
752 /* Isolate the next word in the asserted value and phonetic it */
753 assertv[nextchunk+len] = '\0';
754 val = phonetic( assertv + nextchunk );
756 /* See if this phonetic chunk is in the remaining words of *value */
757 for( i=nextavail; i<count; i++ ){
758 if( !strcmp( val, values[i] ) ){
766 /* This chunk in the asserted value was NOT within the *value. */
772 /* Go on to the next word in the asserted value */
776 /* If some of the words were seen, call it a match */
777 if( nextavail > 0 ) {
786 for( i=0; i<count; i++ ) {
787 ch_free( values[i] );
802 struct berval *prefix,
807 int i,j, len, wordcount, keycount=0;
808 struct berval *newkeys;
811 for( j=0; values[j].bv_val != NULL; j++ ) {
812 /* Yes, this is necessary */
813 val = UTF8normalize( &values[j], LDAP_UTF8_NOCASEFOLD );
814 strip8bitChars( val );
816 /* Isolate how many words there are. There will be a key for each */
817 for( wordcount=0,c=val; *c; c++) {
818 len = strcspn(c, SLAPD_APPROX_DELIMITER);
819 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
821 if (*c == '\0') break;
825 /* Allocate/increase storage to account for new keys */
826 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
827 * sizeof(struct berval) );
828 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
829 if( keys ) ch_free( keys );
832 /* Get a phonetic copy of each word */
833 for( c=val,i=0; i<wordcount; c+=len+1 ) {
835 if( len < SLAPD_APPROX_WORDLEN ) continue;
836 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
843 keys[keycount].bv_val = NULL;
855 struct berval *prefix,
863 /* Yes, this is necessary */
864 val = UTF8normalize( ((struct berval *)assertValue),
865 LDAP_UTF8_NOCASEFOLD );
867 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
868 keys[0].bv_val = NULL;
872 strip8bitChars( val );
874 /* Isolate how many words there are. There will be a key for each */
875 for( count=0,c=val; *c; c++) {
876 len = strcspn(c, SLAPD_APPROX_DELIMITER);
877 if( len >= SLAPD_APPROX_WORDLEN ) count++;
879 if (*c == '\0') break;
883 /* Allocate storage for new keys */
884 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
886 /* Get a phonetic copy of each word */
887 for( c=val,i=0; i<count; c+=len+1 ) {
889 if( len < SLAPD_APPROX_WORDLEN ) continue;
890 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
896 keys[count].bv_val = NULL;
904 /* No other form of Approximate Matching is defined */
912 struct berval *value,
913 void *assertedValue )
915 char *vapprox, *avapprox;
918 /* Yes, this is necessary */
919 s = UTF8normalize( value, UTF8_NOCASEFOLD );
925 /* Yes, this is necessary */
926 t = UTF8normalize( ((struct berval *)assertedValue),
934 vapprox = phonetic( strip8bitChars( s ) );
935 avapprox = phonetic( strip8bitChars( t ) );
940 *matchp = strcmp( vapprox, avapprox );
954 struct berval *prefix,
962 for( i=0; values[i].bv_val != NULL; i++ ) {
963 /* empty - just count them */
966 /* we should have at least one value at this point */
969 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
971 /* Copy each value and run it through phonetic() */
972 for( i=0; values[i].bv_val != NULL; i++ ) {
973 /* Yes, this is necessary */
974 s = UTF8normalize( &values[i], UTF8_NOCASEFOLD );
976 /* strip 8-bit chars and run through phonetic() */
977 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
980 keys[i].bv_val = NULL;
993 struct berval *prefix,
1000 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
1002 /* Yes, this is necessary */
1003 s = UTF8normalize( ((struct berval *)assertValue),
1008 /* strip 8-bit chars and run through phonetic() */
1009 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1015 return LDAP_SUCCESS;
1026 struct berval *value,
1027 void *assertedValue )
1029 *matchp = UTF8normcmp( value->bv_val,
1030 ((struct berval *) assertedValue)->bv_val,
1031 LDAP_UTF8_NOCASEFOLD );
1032 return LDAP_SUCCESS;
1036 caseExactIgnoreSubstringsMatch(
1041 struct berval *value,
1042 void *assertedValue )
1045 SubstringsAssertion *sub = NULL;
1046 struct berval left = { 0, NULL };
1052 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1053 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1055 if ( UTF8bvnormalize( value, &left, casefold ) == NULL ) {
1061 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1067 /* Add up asserted input length */
1068 if( sub->sa_initial.bv_val ) {
1069 inlen += sub->sa_initial.bv_len;
1072 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1073 inlen += sub->sa_any[i].bv_len;
1076 if( sub->sa_final.bv_val ) {
1077 inlen += sub->sa_final.bv_len;
1080 if( sub->sa_initial.bv_val ) {
1081 if( inlen > left.bv_len ) {
1086 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
1087 sub->sa_initial.bv_len );
1093 left.bv_val += sub->sa_initial.bv_len;
1094 left.bv_len -= sub->sa_initial.bv_len;
1095 inlen -= sub->sa_initial.bv_len;
1098 if( sub->sa_final.bv_val ) {
1099 if( inlen > left.bv_len ) {
1104 match = strncmp( sub->sa_final.bv_val,
1105 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1106 sub->sa_final.bv_len );
1112 left.bv_len -= sub->sa_final.bv_len;
1113 inlen -= sub->sa_final.bv_len;
1117 for(i=0; sub->sa_any[i].bv_val; i++) {
1122 if( inlen > left.bv_len ) {
1123 /* not enough length */
1128 if( sub->sa_any[i].bv_len == 0 ) {
1132 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
1139 idx = p - left.bv_val;
1141 if( idx >= left.bv_len ) {
1142 /* this shouldn't happen */
1144 if ( sub->sa_final.bv_val )
1145 ch_free( sub->sa_final.bv_val );
1147 ber_bvarray_free( sub->sa_any );
1148 if ( sub->sa_initial.bv_val )
1149 ch_free( sub->sa_initial.bv_val );
1157 if( sub->sa_any[i].bv_len > left.bv_len ) {
1158 /* not enough left */
1163 match = strncmp( left.bv_val,
1164 sub->sa_any[i].bv_val,
1165 sub->sa_any[i].bv_len );
1173 left.bv_val += sub->sa_any[i].bv_len;
1174 left.bv_len -= sub->sa_any[i].bv_len;
1175 inlen -= sub->sa_any[i].bv_len;
1182 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1183 if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
1184 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1188 return LDAP_SUCCESS;
1191 /* Index generation function */
1192 static int caseExactIgnoreIndexer(
1197 struct berval *prefix,
1205 HASH_CONTEXT HASHcontext;
1206 unsigned char HASHdigest[HASH_BYTES];
1207 struct berval digest;
1208 digest.bv_val = HASHdigest;
1209 digest.bv_len = sizeof(HASHdigest);
1211 for( i=0; values[i].bv_val != NULL; i++ ) {
1212 /* empty - just count them */
1215 /* we should have at least one value at this point */
1218 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1220 slen = syntax->ssyn_oidlen;
1221 mlen = mr->smr_oidlen;
1223 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1224 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1226 for( i=0; values[i].bv_val != NULL; i++ ) {
1227 struct berval value;
1228 ber_str2bv( UTF8normalize( &values[i], casefold ), 0, 0,
1231 HASH_Init( &HASHcontext );
1232 if( prefix != NULL && prefix->bv_len > 0 ) {
1233 HASH_Update( &HASHcontext,
1234 prefix->bv_val, prefix->bv_len );
1236 HASH_Update( &HASHcontext,
1237 syntax->ssyn_oid, slen );
1238 HASH_Update( &HASHcontext,
1239 mr->smr_oid, mlen );
1240 HASH_Update( &HASHcontext,
1241 value.bv_val, value.bv_len );
1242 HASH_Final( HASHdigest, &HASHcontext );
1244 free( value.bv_val );
1246 ber_dupbv( &keys[i], &digest );
1249 keys[i].bv_val = NULL;
1251 return LDAP_SUCCESS;
1254 /* Index generation function */
1255 static int caseExactIgnoreFilter(
1260 struct berval *prefix,
1267 HASH_CONTEXT HASHcontext;
1268 unsigned char HASHdigest[HASH_BYTES];
1269 struct berval value;
1270 struct berval digest;
1271 digest.bv_val = HASHdigest;
1272 digest.bv_len = sizeof(HASHdigest);
1274 slen = syntax->ssyn_oidlen;
1275 mlen = mr->smr_oidlen;
1277 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1278 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1280 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1282 /* This usually happens if filter contains bad UTF8 */
1283 if( value.bv_val == NULL ) {
1284 keys = ch_malloc( sizeof( struct berval ) );
1285 keys[0].bv_val = NULL;
1286 return LDAP_SUCCESS;
1289 keys = ch_malloc( sizeof( struct berval ) * 2 );
1291 HASH_Init( &HASHcontext );
1292 if( prefix != NULL && prefix->bv_len > 0 ) {
1293 HASH_Update( &HASHcontext,
1294 prefix->bv_val, prefix->bv_len );
1296 HASH_Update( &HASHcontext,
1297 syntax->ssyn_oid, slen );
1298 HASH_Update( &HASHcontext,
1299 mr->smr_oid, mlen );
1300 HASH_Update( &HASHcontext,
1301 value.bv_val, value.bv_len );
1302 HASH_Final( HASHdigest, &HASHcontext );
1304 ber_dupbv( keys, &digest );
1305 keys[1].bv_val = NULL;
1307 free( value.bv_val );
1310 return LDAP_SUCCESS;
1313 /* Substrings Index generation function */
1314 static int caseExactIgnoreSubstringsIndexer(
1319 struct berval *prefix,
1329 HASH_CONTEXT HASHcontext;
1330 unsigned char HASHdigest[HASH_BYTES];
1331 struct berval digest;
1332 digest.bv_val = HASHdigest;
1333 digest.bv_len = sizeof(HASHdigest);
1337 for( i=0; values[i].bv_val != NULL; i++ ) {
1338 /* empty - just count them */
1341 /* we should have at least one value at this point */
1344 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1345 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1347 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1348 for( i=0; values[i].bv_val != NULL; i++ ) {
1349 ber_str2bv( UTF8normalize( &values[i], casefold ),
1350 0, 0, &nvalues[i] );
1352 nvalues[i].bv_val = NULL;
1355 for( i=0; values[i].bv_val != NULL; i++ ) {
1356 /* count number of indices to generate */
1357 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1361 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1362 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1363 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1364 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1366 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1370 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1371 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1372 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1376 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1377 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1378 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1379 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1381 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1387 /* no keys to generate */
1389 ber_bvarray_free( nvalues );
1390 return LDAP_SUCCESS;
1393 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1395 slen = syntax->ssyn_oidlen;
1396 mlen = mr->smr_oidlen;
1399 for( i=0; values[i].bv_val != NULL; i++ ) {
1402 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1404 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1405 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1407 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1408 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1410 for( j=0; j<max; j++ ) {
1411 HASH_Init( &HASHcontext );
1412 if( prefix != NULL && prefix->bv_len > 0 ) {
1413 HASH_Update( &HASHcontext,
1414 prefix->bv_val, prefix->bv_len );
1417 HASH_Update( &HASHcontext,
1418 &pre, sizeof( pre ) );
1419 HASH_Update( &HASHcontext,
1420 syntax->ssyn_oid, slen );
1421 HASH_Update( &HASHcontext,
1422 mr->smr_oid, mlen );
1423 HASH_Update( &HASHcontext,
1424 &values[i].bv_val[j],
1425 SLAP_INDEX_SUBSTR_MAXLEN );
1426 HASH_Final( HASHdigest, &HASHcontext );
1428 ber_dupbv( &keys[nkeys++], &digest );
1432 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1433 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1435 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1438 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1439 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1440 HASH_Init( &HASHcontext );
1441 if( prefix != NULL && prefix->bv_len > 0 ) {
1442 HASH_Update( &HASHcontext,
1443 prefix->bv_val, prefix->bv_len );
1445 HASH_Update( &HASHcontext,
1446 &pre, sizeof( pre ) );
1447 HASH_Update( &HASHcontext,
1448 syntax->ssyn_oid, slen );
1449 HASH_Update( &HASHcontext,
1450 mr->smr_oid, mlen );
1451 HASH_Update( &HASHcontext,
1452 values[i].bv_val, j );
1453 HASH_Final( HASHdigest, &HASHcontext );
1455 ber_dupbv( &keys[nkeys++], &digest );
1458 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1459 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1460 HASH_Init( &HASHcontext );
1461 if( prefix != NULL && prefix->bv_len > 0 ) {
1462 HASH_Update( &HASHcontext,
1463 prefix->bv_val, prefix->bv_len );
1465 HASH_Update( &HASHcontext,
1466 &pre, sizeof( pre ) );
1467 HASH_Update( &HASHcontext,
1468 syntax->ssyn_oid, slen );
1469 HASH_Update( &HASHcontext,
1470 mr->smr_oid, mlen );
1471 HASH_Update( &HASHcontext,
1472 &values[i].bv_val[values[i].bv_len-j], j );
1473 HASH_Final( HASHdigest, &HASHcontext );
1475 ber_dupbv( &keys[nkeys++], &digest );
1483 keys[nkeys].bv_val = NULL;
1490 ber_bvarray_free( nvalues );
1492 return LDAP_SUCCESS;
1495 static int caseExactIgnoreSubstringsFilter(
1500 struct berval *prefix,
1504 SubstringsAssertion *sa;
1507 ber_len_t nkeys = 0;
1508 size_t slen, mlen, klen;
1510 HASH_CONTEXT HASHcontext;
1511 unsigned char HASHdigest[HASH_BYTES];
1512 struct berval *value;
1513 struct berval digest;
1515 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1516 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1518 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1521 return LDAP_SUCCESS;
1524 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1525 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1530 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1532 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1533 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1534 /* don't bother accounting for stepping */
1535 nkeys += sa->sa_any[i].bv_len -
1536 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1541 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1542 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1548 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1549 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1550 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1553 return LDAP_SUCCESS;
1556 digest.bv_val = HASHdigest;
1557 digest.bv_len = sizeof(HASHdigest);
1559 slen = syntax->ssyn_oidlen;
1560 mlen = mr->smr_oidlen;
1562 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1565 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1566 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1568 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1569 value = &sa->sa_initial;
1571 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1572 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1574 HASH_Init( &HASHcontext );
1575 if( prefix != NULL && prefix->bv_len > 0 ) {
1576 HASH_Update( &HASHcontext,
1577 prefix->bv_val, prefix->bv_len );
1579 HASH_Update( &HASHcontext,
1580 &pre, sizeof( pre ) );
1581 HASH_Update( &HASHcontext,
1582 syntax->ssyn_oid, slen );
1583 HASH_Update( &HASHcontext,
1584 mr->smr_oid, mlen );
1585 HASH_Update( &HASHcontext,
1586 value->bv_val, klen );
1587 HASH_Final( HASHdigest, &HASHcontext );
1589 ber_dupbv( &keys[nkeys++], &digest );
1592 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1594 pre = SLAP_INDEX_SUBSTR_PREFIX;
1595 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1597 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1598 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1602 value = &sa->sa_any[i];
1605 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1606 j += SLAP_INDEX_SUBSTR_STEP )
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[j], klen );
1621 HASH_Final( HASHdigest, &HASHcontext );
1623 ber_dupbv( &keys[nkeys++], &digest );
1629 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1630 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1632 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1633 value = &sa->sa_final;
1635 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1636 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1638 HASH_Init( &HASHcontext );
1639 if( prefix != NULL && prefix->bv_len > 0 ) {
1640 HASH_Update( &HASHcontext,
1641 prefix->bv_val, prefix->bv_len );
1643 HASH_Update( &HASHcontext,
1644 &pre, sizeof( pre ) );
1645 HASH_Update( &HASHcontext,
1646 syntax->ssyn_oid, slen );
1647 HASH_Update( &HASHcontext,
1648 mr->smr_oid, mlen );
1649 HASH_Update( &HASHcontext,
1650 &value->bv_val[value->bv_len-klen], klen );
1651 HASH_Final( HASHdigest, &HASHcontext );
1653 ber_dupbv( &keys[nkeys++], &digest );
1657 keys[nkeys].bv_val = NULL;
1663 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1664 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1665 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1668 return LDAP_SUCCESS;
1677 struct berval *value,
1678 void *assertedValue )
1680 *matchp = UTF8normcmp( value->bv_val,
1681 ((struct berval *) assertedValue)->bv_val,
1682 LDAP_UTF8_CASEFOLD );
1683 return LDAP_SUCCESS;
1689 struct berval *val )
1693 if( val->bv_len == 0 ) {
1694 /* disallow empty strings */
1695 return LDAP_INVALID_SYNTAX;
1698 if( OID_LEADCHAR(val->bv_val[0]) ) {
1700 for(i=1; i < val->bv_len; i++) {
1701 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1702 if( dot++ ) return 1;
1703 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1706 return LDAP_INVALID_SYNTAX;
1710 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1712 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1713 for(i=1; i < val->bv_len; i++) {
1714 if( !DESC_CHAR(val->bv_val[i] ) ) {
1715 return LDAP_INVALID_SYNTAX;
1719 return LDAP_SUCCESS;
1722 return LDAP_INVALID_SYNTAX;
1731 struct berval *value,
1732 void *assertedValue )
1735 int vsign=0, avsign=0;
1736 struct berval *asserted;
1737 ber_len_t vlen, avlen;
1740 /* Start off pessimistic */
1743 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1745 vlen = value->bv_len;
1747 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1748 /* empty -- skip spaces */
1750 else if ( *v == '+' ) {
1753 else if ( *v == '-' ) {
1756 else if ( ASCII_DIGIT(*v) ) {
1757 if ( vsign == 0 ) vsign = 1;
1765 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1767 asserted = (struct berval *) assertedValue;
1768 av = asserted->bv_val;
1769 avlen = asserted->bv_len;
1771 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1772 /* empty -- skip spaces */
1774 else if ( *av == '+' ) {
1777 else if ( *av == '-' ) {
1780 else if ( ASCII_DIGIT(*av) ) {
1781 if ( avsign == 0 ) avsign = 1;
1789 /* The two ?sign vars are now one of :
1790 -2 negative non-zero number
1792 0 0 collapse these three to 0
1794 +2 positive non-zero number
1796 if ( abs( vsign ) == 1 ) vsign = 0;
1797 if ( abs( avsign ) == 1 ) avsign = 0;
1799 if( vsign != avsign ) return LDAP_SUCCESS;
1801 /* Check the significant digits */
1802 while( vlen && avlen ) {
1803 if( *v != *av ) break;
1810 /* If all digits compared equal, the numbers are equal */
1811 if(( vlen == 0 ) && ( avlen == 0 )) {
1814 return LDAP_SUCCESS;
1820 struct berval *val )
1824 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1826 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1827 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1828 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1829 return LDAP_INVALID_SYNTAX;
1832 for( i=1; i < val->bv_len; i++ ) {
1833 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1836 return LDAP_SUCCESS;
1843 struct berval *normalized )
1853 /* Ignore leading spaces */
1854 while ( len && ( *p == ' ' )) {
1861 negative = ( *p == '-' );
1862 if(( *p == '-' ) || ( *p == '+' )) {
1868 /* Ignore leading zeros */
1869 while ( len && ( *p == '0' )) {
1874 /* If there are no non-zero digits left, the number is zero, otherwise
1875 allocate space for the number and copy it into the buffer */
1877 normalized->bv_val = ch_strdup("0");
1878 normalized->bv_len = 1;
1881 normalized->bv_len = len+negative;
1882 normalized->bv_val = ch_malloc( normalized->bv_len );
1884 normalized->bv_val[0] = '-';
1886 AC_MEMCPY( normalized->bv_val + negative, p, len );
1889 return LDAP_SUCCESS;
1892 /* Index generation function */
1893 static int integerIndexer(
1898 struct berval *prefix,
1905 /* we should have at least one value at this point */
1906 assert( values != NULL && values[0].bv_val != NULL );
1908 for( i=0; values[i].bv_val != NULL; i++ ) {
1909 /* empty -- just count them */
1912 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1914 for( i=0; values[i].bv_val != NULL; i++ ) {
1915 integerNormalize( syntax, &values[i], &keys[i] );
1918 keys[i].bv_val = NULL;
1920 return LDAP_SUCCESS;
1923 /* Index generation function */
1924 static int integerFilter(
1929 struct berval *prefix,
1935 keys = ch_malloc( sizeof( struct berval ) * 2 );
1936 integerNormalize( syntax, assertValue, &keys[0] );
1937 keys[1].bv_val = NULL;
1940 return LDAP_SUCCESS;
1945 countryStringValidate(
1947 struct berval *val )
1949 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1951 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1952 return LDAP_INVALID_SYNTAX;
1954 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1955 return LDAP_INVALID_SYNTAX;
1958 return LDAP_SUCCESS;
1962 printableStringValidate(
1964 struct berval *val )
1968 for(i=0; i < val->bv_len; i++) {
1969 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1970 return LDAP_INVALID_SYNTAX;
1974 return LDAP_SUCCESS;
1978 printablesStringValidate(
1980 struct berval *val )
1984 for(i=0; i < val->bv_len; i++) {
1985 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1986 return LDAP_INVALID_SYNTAX;
1990 return LDAP_SUCCESS;
1996 struct berval *val )
2000 for(i=0; i < val->bv_len; i++) {
2001 if( !LDAP_ASCII(val->bv_val[i]) ) {
2002 return LDAP_INVALID_SYNTAX;
2006 return LDAP_SUCCESS;
2013 struct berval *normalized )
2019 /* Ignore initial whitespace */
2020 while ( ASCII_SPACE( *p ) ) {
2024 normalized->bv_val = ch_strdup( p );
2025 p = q = normalized->bv_val;
2028 if ( ASCII_SPACE( *p ) ) {
2031 /* Ignore the extra whitespace */
2032 while ( ASCII_SPACE( *p ) ) {
2040 assert( normalized->bv_val <= p );
2044 * If the string ended in space, backup the pointer one
2045 * position. One is enough because the above loop collapsed
2046 * all whitespace to a single space.
2049 if ( ASCII_SPACE( q[-1] ) ) {
2053 /* null terminate */
2056 normalized->bv_len = q - normalized->bv_val;
2058 return LDAP_SUCCESS;
2067 struct berval *value,
2068 void *assertedValue )
2070 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2073 match = strncmp( value->bv_val,
2074 ((struct berval *) assertedValue)->bv_val,
2079 return LDAP_SUCCESS;
2083 caseExactIA5SubstringsMatch(
2088 struct berval *value,
2089 void *assertedValue )
2092 SubstringsAssertion *sub = assertedValue;
2093 struct berval left = *value;
2097 /* Add up asserted input length */
2098 if( sub->sa_initial.bv_val ) {
2099 inlen += sub->sa_initial.bv_len;
2102 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2103 inlen += sub->sa_any[i].bv_len;
2106 if( sub->sa_final.bv_val ) {
2107 inlen += sub->sa_final.bv_len;
2110 if( sub->sa_initial.bv_val ) {
2111 if( inlen > left.bv_len ) {
2116 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2117 sub->sa_initial.bv_len );
2123 left.bv_val += sub->sa_initial.bv_len;
2124 left.bv_len -= sub->sa_initial.bv_len;
2125 inlen -= sub->sa_initial.bv_len;
2128 if( sub->sa_final.bv_val ) {
2129 if( inlen > left.bv_len ) {
2134 match = strncmp( sub->sa_final.bv_val,
2135 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2136 sub->sa_final.bv_len );
2142 left.bv_len -= sub->sa_final.bv_len;
2143 inlen -= sub->sa_final.bv_len;
2147 for(i=0; sub->sa_any[i].bv_val; i++) {
2152 if( inlen > left.bv_len ) {
2153 /* not enough length */
2158 if( sub->sa_any[i].bv_len == 0 ) {
2162 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2169 idx = p - left.bv_val;
2171 if( idx >= left.bv_len ) {
2172 /* this shouldn't happen */
2179 if( sub->sa_any[i].bv_len > left.bv_len ) {
2180 /* not enough left */
2185 match = strncmp( left.bv_val,
2186 sub->sa_any[i].bv_val,
2187 sub->sa_any[i].bv_len );
2195 left.bv_val += sub->sa_any[i].bv_len;
2196 left.bv_len -= sub->sa_any[i].bv_len;
2197 inlen -= sub->sa_any[i].bv_len;
2203 return LDAP_SUCCESS;
2206 /* Index generation function */
2207 static int caseExactIA5Indexer(
2212 struct berval *prefix,
2219 HASH_CONTEXT HASHcontext;
2220 unsigned char HASHdigest[HASH_BYTES];
2221 struct berval digest;
2222 digest.bv_val = HASHdigest;
2223 digest.bv_len = sizeof(HASHdigest);
2225 for( i=0; values[i].bv_val != NULL; i++ ) {
2226 /* empty - just count them */
2229 /* we should have at least one value at this point */
2232 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2234 slen = syntax->ssyn_oidlen;
2235 mlen = mr->smr_oidlen;
2237 for( i=0; values[i].bv_val != NULL; i++ ) {
2238 struct berval *value = &values[i];
2240 HASH_Init( &HASHcontext );
2241 if( prefix != NULL && prefix->bv_len > 0 ) {
2242 HASH_Update( &HASHcontext,
2243 prefix->bv_val, prefix->bv_len );
2245 HASH_Update( &HASHcontext,
2246 syntax->ssyn_oid, slen );
2247 HASH_Update( &HASHcontext,
2248 mr->smr_oid, mlen );
2249 HASH_Update( &HASHcontext,
2250 value->bv_val, value->bv_len );
2251 HASH_Final( HASHdigest, &HASHcontext );
2253 ber_dupbv( &keys[i], &digest );
2256 keys[i].bv_val = NULL;
2258 return LDAP_SUCCESS;
2261 /* Index generation function */
2262 static int caseExactIA5Filter(
2267 struct berval *prefix,
2273 HASH_CONTEXT HASHcontext;
2274 unsigned char HASHdigest[HASH_BYTES];
2275 struct berval *value;
2276 struct berval digest;
2277 digest.bv_val = HASHdigest;
2278 digest.bv_len = sizeof(HASHdigest);
2280 slen = syntax->ssyn_oidlen;
2281 mlen = mr->smr_oidlen;
2283 value = (struct berval *) assertValue;
2285 keys = ch_malloc( sizeof( struct berval ) * 2 );
2287 HASH_Init( &HASHcontext );
2288 if( prefix != NULL && prefix->bv_len > 0 ) {
2289 HASH_Update( &HASHcontext,
2290 prefix->bv_val, prefix->bv_len );
2292 HASH_Update( &HASHcontext,
2293 syntax->ssyn_oid, slen );
2294 HASH_Update( &HASHcontext,
2295 mr->smr_oid, mlen );
2296 HASH_Update( &HASHcontext,
2297 value->bv_val, value->bv_len );
2298 HASH_Final( HASHdigest, &HASHcontext );
2300 ber_dupbv( &keys[0], &digest );
2301 keys[1].bv_val = NULL;
2304 return LDAP_SUCCESS;
2307 /* Substrings Index generation function */
2308 static int caseExactIA5SubstringsIndexer(
2313 struct berval *prefix,
2320 HASH_CONTEXT HASHcontext;
2321 unsigned char HASHdigest[HASH_BYTES];
2322 struct berval digest;
2323 digest.bv_val = HASHdigest;
2324 digest.bv_len = sizeof(HASHdigest);
2326 /* we should have at least one value at this point */
2327 assert( values != NULL && values[0].bv_val != NULL );
2330 for( i=0; values[i].bv_val != NULL; i++ ) {
2331 /* count number of indices to generate */
2332 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2336 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
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 );
2345 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2346 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2347 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2351 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2352 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2353 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2354 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2356 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2362 /* no keys to generate */
2364 return LDAP_SUCCESS;
2367 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2369 slen = syntax->ssyn_oidlen;
2370 mlen = mr->smr_oidlen;
2373 for( i=0; values[i].bv_val != NULL; i++ ) {
2375 struct berval *value;
2378 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2380 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2381 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2383 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2384 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2386 for( j=0; j<max; j++ ) {
2387 HASH_Init( &HASHcontext );
2388 if( prefix != NULL && prefix->bv_len > 0 ) {
2389 HASH_Update( &HASHcontext,
2390 prefix->bv_val, prefix->bv_len );
2393 HASH_Update( &HASHcontext,
2394 &pre, sizeof( pre ) );
2395 HASH_Update( &HASHcontext,
2396 syntax->ssyn_oid, slen );
2397 HASH_Update( &HASHcontext,
2398 mr->smr_oid, mlen );
2399 HASH_Update( &HASHcontext,
2401 SLAP_INDEX_SUBSTR_MAXLEN );
2402 HASH_Final( HASHdigest, &HASHcontext );
2404 ber_dupbv( &keys[nkeys++], &digest );
2408 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2409 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2411 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2414 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2415 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2416 HASH_Init( &HASHcontext );
2417 if( prefix != NULL && prefix->bv_len > 0 ) {
2418 HASH_Update( &HASHcontext,
2419 prefix->bv_val, prefix->bv_len );
2421 HASH_Update( &HASHcontext,
2422 &pre, sizeof( pre ) );
2423 HASH_Update( &HASHcontext,
2424 syntax->ssyn_oid, slen );
2425 HASH_Update( &HASHcontext,
2426 mr->smr_oid, mlen );
2427 HASH_Update( &HASHcontext,
2429 HASH_Final( HASHdigest, &HASHcontext );
2431 ber_dupbv( &keys[nkeys++], &digest );
2434 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2435 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2436 HASH_Init( &HASHcontext );
2437 if( prefix != NULL && prefix->bv_len > 0 ) {
2438 HASH_Update( &HASHcontext,
2439 prefix->bv_val, prefix->bv_len );
2441 HASH_Update( &HASHcontext,
2442 &pre, sizeof( pre ) );
2443 HASH_Update( &HASHcontext,
2444 syntax->ssyn_oid, slen );
2445 HASH_Update( &HASHcontext,
2446 mr->smr_oid, mlen );
2447 HASH_Update( &HASHcontext,
2448 &value->bv_val[value->bv_len-j], j );
2449 HASH_Final( HASHdigest, &HASHcontext );
2451 ber_dupbv( &keys[nkeys++], &digest );
2458 keys[nkeys].bv_val = NULL;
2465 return LDAP_SUCCESS;
2468 static int caseExactIA5SubstringsFilter(
2473 struct berval *prefix,
2477 SubstringsAssertion *sa = assertValue;
2479 ber_len_t nkeys = 0;
2480 size_t slen, mlen, klen;
2482 HASH_CONTEXT HASHcontext;
2483 unsigned char HASHdigest[HASH_BYTES];
2484 struct berval *value;
2485 struct berval digest;
2487 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2488 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2493 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2495 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2496 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2497 /* don't bother accounting for stepping */
2498 nkeys += sa->sa_any[i].bv_len -
2499 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2504 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2505 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2512 return LDAP_SUCCESS;
2515 digest.bv_val = HASHdigest;
2516 digest.bv_len = sizeof(HASHdigest);
2518 slen = syntax->ssyn_oidlen;
2519 mlen = mr->smr_oidlen;
2521 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2524 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2525 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2527 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2528 value = &sa->sa_initial;
2530 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2531 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2533 HASH_Init( &HASHcontext );
2534 if( prefix != NULL && prefix->bv_len > 0 ) {
2535 HASH_Update( &HASHcontext,
2536 prefix->bv_val, prefix->bv_len );
2538 HASH_Update( &HASHcontext,
2539 &pre, sizeof( pre ) );
2540 HASH_Update( &HASHcontext,
2541 syntax->ssyn_oid, slen );
2542 HASH_Update( &HASHcontext,
2543 mr->smr_oid, mlen );
2544 HASH_Update( &HASHcontext,
2545 value->bv_val, klen );
2546 HASH_Final( HASHdigest, &HASHcontext );
2548 ber_dupbv( &keys[nkeys++], &digest );
2551 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2553 pre = SLAP_INDEX_SUBSTR_PREFIX;
2554 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2556 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2557 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2561 value = &sa->sa_any[i];
2564 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2565 j += SLAP_INDEX_SUBSTR_STEP )
2567 HASH_Init( &HASHcontext );
2568 if( prefix != NULL && prefix->bv_len > 0 ) {
2569 HASH_Update( &HASHcontext,
2570 prefix->bv_val, prefix->bv_len );
2572 HASH_Update( &HASHcontext,
2573 &pre, sizeof( pre ) );
2574 HASH_Update( &HASHcontext,
2575 syntax->ssyn_oid, slen );
2576 HASH_Update( &HASHcontext,
2577 mr->smr_oid, mlen );
2578 HASH_Update( &HASHcontext,
2579 &value->bv_val[j], klen );
2580 HASH_Final( HASHdigest, &HASHcontext );
2582 ber_dupbv( &keys[nkeys++], &digest );
2587 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2588 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2590 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2591 value = &sa->sa_final;
2593 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2594 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2596 HASH_Init( &HASHcontext );
2597 if( prefix != NULL && prefix->bv_len > 0 ) {
2598 HASH_Update( &HASHcontext,
2599 prefix->bv_val, prefix->bv_len );
2601 HASH_Update( &HASHcontext,
2602 &pre, sizeof( pre ) );
2603 HASH_Update( &HASHcontext,
2604 syntax->ssyn_oid, slen );
2605 HASH_Update( &HASHcontext,
2606 mr->smr_oid, mlen );
2607 HASH_Update( &HASHcontext,
2608 &value->bv_val[value->bv_len-klen], klen );
2609 HASH_Final( HASHdigest, &HASHcontext );
2611 ber_dupbv( &keys[nkeys++], &digest );
2615 keys[nkeys].bv_val = NULL;
2622 return LDAP_SUCCESS;
2631 struct berval *value,
2632 void *assertedValue )
2634 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2636 if( match == 0 && value->bv_len ) {
2637 match = strncasecmp( value->bv_val,
2638 ((struct berval *) assertedValue)->bv_val,
2643 return LDAP_SUCCESS;
2647 caseIgnoreIA5SubstringsMatch(
2652 struct berval *value,
2653 void *assertedValue )
2656 SubstringsAssertion *sub = assertedValue;
2657 struct berval left = *value;
2661 /* Add up asserted input length */
2662 if( sub->sa_initial.bv_val ) {
2663 inlen += sub->sa_initial.bv_len;
2666 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2667 inlen += sub->sa_any[i].bv_len;
2670 if( sub->sa_final.bv_val ) {
2671 inlen += sub->sa_final.bv_len;
2674 if( sub->sa_initial.bv_val ) {
2675 if( inlen > left.bv_len ) {
2680 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2681 sub->sa_initial.bv_len );
2687 left.bv_val += sub->sa_initial.bv_len;
2688 left.bv_len -= sub->sa_initial.bv_len;
2689 inlen -= sub->sa_initial.bv_len;
2692 if( sub->sa_final.bv_val ) {
2693 if( inlen > left.bv_len ) {
2698 match = strncasecmp( sub->sa_final.bv_val,
2699 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2700 sub->sa_final.bv_len );
2706 left.bv_len -= sub->sa_final.bv_len;
2707 inlen -= sub->sa_final.bv_len;
2711 for(i=0; sub->sa_any[i].bv_val; i++) {
2716 if( inlen > left.bv_len ) {
2717 /* not enough length */
2722 if( sub->sa_any[i].bv_len == 0 ) {
2726 p = bvcasechr( &left, *sub->sa_any[i].bv_val, &idx );
2733 assert( idx < left.bv_len );
2734 if( idx >= left.bv_len ) {
2735 /* this shouldn't happen */
2742 if( sub->sa_any[i].bv_len > left.bv_len ) {
2743 /* not enough left */
2748 match = strncasecmp( left.bv_val,
2749 sub->sa_any[i].bv_val,
2750 sub->sa_any[i].bv_len );
2759 left.bv_val += sub->sa_any[i].bv_len;
2760 left.bv_len -= sub->sa_any[i].bv_len;
2761 inlen -= sub->sa_any[i].bv_len;
2767 return LDAP_SUCCESS;
2770 /* Index generation function */
2771 static int caseIgnoreIA5Indexer(
2776 struct berval *prefix,
2783 HASH_CONTEXT HASHcontext;
2784 unsigned char HASHdigest[HASH_BYTES];
2785 struct berval digest;
2786 digest.bv_val = HASHdigest;
2787 digest.bv_len = sizeof(HASHdigest);
2789 /* we should have at least one value at this point */
2790 assert( values != NULL && values[0].bv_val != NULL );
2792 for( i=0; values[i].bv_val != NULL; i++ ) {
2793 /* just count them */
2796 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2798 slen = syntax->ssyn_oidlen;
2799 mlen = mr->smr_oidlen;
2801 for( i=0; values[i].bv_val != NULL; i++ ) {
2802 struct berval value;
2803 ber_dupbv( &value, &values[i] );
2804 ldap_pvt_str2upper( value.bv_val );
2806 HASH_Init( &HASHcontext );
2807 if( prefix != NULL && prefix->bv_len > 0 ) {
2808 HASH_Update( &HASHcontext,
2809 prefix->bv_val, prefix->bv_len );
2811 HASH_Update( &HASHcontext,
2812 syntax->ssyn_oid, slen );
2813 HASH_Update( &HASHcontext,
2814 mr->smr_oid, mlen );
2815 HASH_Update( &HASHcontext,
2816 value.bv_val, value.bv_len );
2817 HASH_Final( HASHdigest, &HASHcontext );
2819 free( value.bv_val );
2821 ber_dupbv( &keys[i], &digest );
2824 keys[i].bv_val = NULL;
2826 return LDAP_SUCCESS;
2829 /* Index generation function */
2830 static int caseIgnoreIA5Filter(
2835 struct berval *prefix,
2841 HASH_CONTEXT HASHcontext;
2842 unsigned char HASHdigest[HASH_BYTES];
2843 struct berval value;
2844 struct berval digest;
2845 digest.bv_val = HASHdigest;
2846 digest.bv_len = sizeof(HASHdigest);
2848 slen = syntax->ssyn_oidlen;
2849 mlen = mr->smr_oidlen;
2851 ber_dupbv( &value, (struct berval *) assertValue );
2852 ldap_pvt_str2upper( value.bv_val );
2854 keys = ch_malloc( sizeof( struct berval ) * 2 );
2856 HASH_Init( &HASHcontext );
2857 if( prefix != NULL && prefix->bv_len > 0 ) {
2858 HASH_Update( &HASHcontext,
2859 prefix->bv_val, prefix->bv_len );
2861 HASH_Update( &HASHcontext,
2862 syntax->ssyn_oid, slen );
2863 HASH_Update( &HASHcontext,
2864 mr->smr_oid, mlen );
2865 HASH_Update( &HASHcontext,
2866 value.bv_val, value.bv_len );
2867 HASH_Final( HASHdigest, &HASHcontext );
2869 ber_dupbv( &keys[0], &digest );
2870 keys[1].bv_val = NULL;
2872 free( value.bv_val );
2876 return LDAP_SUCCESS;
2879 /* Substrings Index generation function */
2880 static int caseIgnoreIA5SubstringsIndexer(
2885 struct berval *prefix,
2892 HASH_CONTEXT HASHcontext;
2893 unsigned char HASHdigest[HASH_BYTES];
2894 struct berval digest;
2895 digest.bv_val = HASHdigest;
2896 digest.bv_len = sizeof(HASHdigest);
2898 /* we should have at least one value at this point */
2899 assert( values != NULL && values[0].bv_val != NULL );
2902 for( i=0; values[i].bv_val != NULL; i++ ) {
2903 /* count number of indices to generate */
2904 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2908 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2909 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2910 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2911 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2913 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2917 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2918 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2919 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2923 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2924 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2925 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2926 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2928 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2934 /* no keys to generate */
2936 return LDAP_SUCCESS;
2939 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2941 slen = syntax->ssyn_oidlen;
2942 mlen = mr->smr_oidlen;
2945 for( i=0; values[i].bv_val != NULL; i++ ) {
2947 struct berval value;
2949 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2951 ber_dupbv( &value, &values[i] );
2952 ldap_pvt_str2upper( value.bv_val );
2954 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2955 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2957 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2958 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2960 for( j=0; j<max; j++ ) {
2961 HASH_Init( &HASHcontext );
2962 if( prefix != NULL && prefix->bv_len > 0 ) {
2963 HASH_Update( &HASHcontext,
2964 prefix->bv_val, prefix->bv_len );
2967 HASH_Update( &HASHcontext,
2968 &pre, sizeof( pre ) );
2969 HASH_Update( &HASHcontext,
2970 syntax->ssyn_oid, slen );
2971 HASH_Update( &HASHcontext,
2972 mr->smr_oid, mlen );
2973 HASH_Update( &HASHcontext,
2975 SLAP_INDEX_SUBSTR_MAXLEN );
2976 HASH_Final( HASHdigest, &HASHcontext );
2978 ber_dupbv( &keys[nkeys++], &digest );
2982 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2983 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2985 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2988 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2989 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2990 HASH_Init( &HASHcontext );
2991 if( prefix != NULL && prefix->bv_len > 0 ) {
2992 HASH_Update( &HASHcontext,
2993 prefix->bv_val, prefix->bv_len );
2995 HASH_Update( &HASHcontext,
2996 &pre, sizeof( pre ) );
2997 HASH_Update( &HASHcontext,
2998 syntax->ssyn_oid, slen );
2999 HASH_Update( &HASHcontext,
3000 mr->smr_oid, mlen );
3001 HASH_Update( &HASHcontext,
3003 HASH_Final( HASHdigest, &HASHcontext );
3005 ber_dupbv( &keys[nkeys++], &digest );
3008 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3009 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3010 HASH_Init( &HASHcontext );
3011 if( prefix != NULL && prefix->bv_len > 0 ) {
3012 HASH_Update( &HASHcontext,
3013 prefix->bv_val, prefix->bv_len );
3015 HASH_Update( &HASHcontext,
3016 &pre, sizeof( pre ) );
3017 HASH_Update( &HASHcontext,
3018 syntax->ssyn_oid, slen );
3019 HASH_Update( &HASHcontext,
3020 mr->smr_oid, mlen );
3021 HASH_Update( &HASHcontext,
3022 &value.bv_val[value.bv_len-j], j );
3023 HASH_Final( HASHdigest, &HASHcontext );
3025 ber_dupbv( &keys[nkeys++], &digest );
3030 free( value.bv_val );
3034 keys[nkeys].bv_val = NULL;
3041 return LDAP_SUCCESS;
3044 static int caseIgnoreIA5SubstringsFilter(
3049 struct berval *prefix,
3053 SubstringsAssertion *sa = assertValue;
3055 ber_len_t nkeys = 0;
3056 size_t slen, mlen, klen;
3058 HASH_CONTEXT HASHcontext;
3059 unsigned char HASHdigest[HASH_BYTES];
3060 struct berval value;
3061 struct berval digest;
3063 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3064 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3069 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3071 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3072 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3073 /* don't bother accounting for stepping */
3074 nkeys += sa->sa_any[i].bv_len -
3075 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3080 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3081 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3088 return LDAP_SUCCESS;
3091 digest.bv_val = HASHdigest;
3092 digest.bv_len = sizeof(HASHdigest);
3094 slen = syntax->ssyn_oidlen;
3095 mlen = mr->smr_oidlen;
3097 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3100 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3101 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3103 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3104 ber_dupbv( &value, &sa->sa_initial );
3105 ldap_pvt_str2upper( value.bv_val );
3107 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3108 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3110 HASH_Init( &HASHcontext );
3111 if( prefix != NULL && prefix->bv_len > 0 ) {
3112 HASH_Update( &HASHcontext,
3113 prefix->bv_val, prefix->bv_len );
3115 HASH_Update( &HASHcontext,
3116 &pre, sizeof( pre ) );
3117 HASH_Update( &HASHcontext,
3118 syntax->ssyn_oid, slen );
3119 HASH_Update( &HASHcontext,
3120 mr->smr_oid, mlen );
3121 HASH_Update( &HASHcontext,
3122 value.bv_val, klen );
3123 HASH_Final( HASHdigest, &HASHcontext );
3125 free( value.bv_val );
3126 ber_dupbv( &keys[nkeys++], &digest );
3129 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3131 pre = SLAP_INDEX_SUBSTR_PREFIX;
3132 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3134 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3135 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3139 ber_dupbv( &value, &sa->sa_any[i] );
3140 ldap_pvt_str2upper( value.bv_val );
3143 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3144 j += SLAP_INDEX_SUBSTR_STEP )
3146 HASH_Init( &HASHcontext );
3147 if( prefix != NULL && prefix->bv_len > 0 ) {
3148 HASH_Update( &HASHcontext,
3149 prefix->bv_val, prefix->bv_len );
3151 HASH_Update( &HASHcontext,
3152 &pre, sizeof( pre ) );
3153 HASH_Update( &HASHcontext,
3154 syntax->ssyn_oid, slen );
3155 HASH_Update( &HASHcontext,
3156 mr->smr_oid, mlen );
3157 HASH_Update( &HASHcontext,
3158 &value.bv_val[j], klen );
3159 HASH_Final( HASHdigest, &HASHcontext );
3161 ber_dupbv( &keys[nkeys++], &digest );
3164 free( value.bv_val );
3168 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3169 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3171 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3172 ber_dupbv( &value, &sa->sa_final );
3173 ldap_pvt_str2upper( value.bv_val );
3175 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3176 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3178 HASH_Init( &HASHcontext );
3179 if( prefix != NULL && prefix->bv_len > 0 ) {
3180 HASH_Update( &HASHcontext,
3181 prefix->bv_val, prefix->bv_len );
3183 HASH_Update( &HASHcontext,
3184 &pre, sizeof( pre ) );
3185 HASH_Update( &HASHcontext,
3186 syntax->ssyn_oid, slen );
3187 HASH_Update( &HASHcontext,
3188 mr->smr_oid, mlen );
3189 HASH_Update( &HASHcontext,
3190 &value.bv_val[value.bv_len-klen], klen );
3191 HASH_Final( HASHdigest, &HASHcontext );
3193 free( value.bv_val );
3194 ber_dupbv( &keys[nkeys++], &digest );
3198 keys[nkeys].bv_val = NULL;
3205 return LDAP_SUCCESS;
3209 numericStringValidate(
3215 for(i=0; i < in->bv_len; i++) {
3216 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3217 return LDAP_INVALID_SYNTAX;
3221 return LDAP_SUCCESS;
3225 numericStringNormalize(
3228 struct berval *normalized )
3230 /* removal all spaces */
3233 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3236 q = normalized->bv_val;
3239 if ( ASCII_SPACE( *p ) ) {
3240 /* Ignore whitespace */
3247 /* we should have copied no more then is in val */
3248 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3250 /* null terminate */
3253 normalized->bv_len = q - normalized->bv_val;
3255 return LDAP_SUCCESS;
3259 objectIdentifierFirstComponentMatch(
3264 struct berval *value,
3265 void *assertedValue )
3267 int rc = LDAP_SUCCESS;
3269 struct berval *asserted = (struct berval *) assertedValue;
3273 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3274 return LDAP_INVALID_SYNTAX;
3277 /* trim leading white space */
3278 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3282 /* grab next word */
3283 oid.bv_val = &value->bv_val[i];
3284 oid.bv_len = value->bv_len - i;
3285 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3290 /* insert attributeTypes, objectclass check here */
3291 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3292 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3295 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3296 MatchingRule *asserted_mr = mr_bvfind( asserted );
3297 MatchingRule *stored_mr = mr_bvfind( &oid );
3299 if( asserted_mr == NULL ) {
3300 rc = SLAPD_COMPARE_UNDEFINED;
3302 match = asserted_mr != stored_mr;
3305 } else if ( !strcmp( syntax->ssyn_oid,
3306 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3308 AttributeType *asserted_at = at_bvfind( asserted );
3309 AttributeType *stored_at = at_bvfind( &oid );
3311 if( asserted_at == NULL ) {
3312 rc = SLAPD_COMPARE_UNDEFINED;
3314 match = asserted_at != stored_at;
3317 } else if ( !strcmp( syntax->ssyn_oid,
3318 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3320 ObjectClass *asserted_oc = oc_bvfind( asserted );
3321 ObjectClass *stored_oc = oc_bvfind( &oid );
3323 if( asserted_oc == NULL ) {
3324 rc = SLAPD_COMPARE_UNDEFINED;
3326 match = asserted_oc != stored_oc;
3332 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3333 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3334 match, value->bv_val, asserted->bv_val ));
3336 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3337 "%d\n\t\"%s\"\n\t\"%s\"\n",
3338 match, value->bv_val, asserted->bv_val );
3342 if( rc == LDAP_SUCCESS ) *matchp = match;
3352 struct berval *value,
3353 void *assertedValue )
3355 long lValue, lAssertedValue;
3357 /* safe to assume integers are NUL terminated? */
3358 lValue = strtoul(value->bv_val, NULL, 10);
3359 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3360 return LDAP_CONSTRAINT_VIOLATION;
3362 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3363 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3364 return LDAP_CONSTRAINT_VIOLATION;
3366 *matchp = (lValue & lAssertedValue);
3367 return LDAP_SUCCESS;
3376 struct berval *value,
3377 void *assertedValue )
3379 long lValue, lAssertedValue;
3381 /* safe to assume integers are NUL terminated? */
3382 lValue = strtoul(value->bv_val, NULL, 10);
3383 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3384 return LDAP_CONSTRAINT_VIOLATION;
3386 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3387 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3388 return LDAP_CONSTRAINT_VIOLATION;
3390 *matchp = (lValue | lAssertedValue);
3391 return LDAP_SUCCESS;
3395 #include <openssl/x509.h>
3396 #include <openssl/err.h>
3397 char digit[] = "0123456789";
3400 * Next function returns a string representation of a ASN1_INTEGER.
3401 * It works for unlimited lengths.
3404 static struct berval *
3405 asn1_integer2str(ASN1_INTEGER *a)
3410 /* We work backwards, make it fill from the end of buf */
3411 p = buf + sizeof(buf) - 1;
3414 if ( a == NULL || a->length == 0 ) {
3422 /* We want to preserve the original */
3423 copy = ch_malloc(n*sizeof(unsigned int));
3424 for (i = 0; i<n; i++) {
3425 copy[i] = a->data[i];
3429 * base indicates the index of the most significant
3430 * byte that might be nonzero. When it goes off the
3431 * end, we now there is nothing left to do.
3437 for (i = base; i<n; i++ ) {
3438 copy[i] += carry*256;
3439 carry = copy[i] % 10;
3444 * Way too large, we need to leave
3445 * room for sign if negative
3450 *--p = digit[carry];
3451 if (copy[base] == 0)
3457 if ( a->type == V_ASN1_NEG_INTEGER ) {
3461 return ber_bvstrdup(p);
3464 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3465 static struct berval *
3466 dn_openssl2ldap(X509_NAME *name)
3468 char issuer_dn[1024];
3471 bio = BIO_new(BIO_s_mem());
3474 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3475 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3476 ERR_error_string(ERR_get_error(),NULL)));
3478 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3479 "error creating BIO: %s\n",
3480 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3484 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3486 BIO_gets(bio, issuer_dn, 1024);
3489 return ber_bvstrdup(issuer_dn);
3493 * Given a certificate in DER format, extract the corresponding
3494 * assertion value for certificateExactMatch
3497 certificateExactConvert(
3499 struct berval * out )
3502 unsigned char *p = in->bv_val;
3503 struct berval *serial;
3504 struct berval *issuer_dn;
3505 struct berval *bv_tmp;
3507 xcert = d2i_X509(NULL, &p, in->bv_len);
3510 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3511 "certificateExactConvert: error parsing cert: %s\n",
3512 ERR_error_string(ERR_get_error(),NULL)));
3514 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3515 "error parsing cert: %s\n",
3516 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3518 return LDAP_INVALID_SYNTAX;
3521 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3524 return LDAP_INVALID_SYNTAX;
3526 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3530 return LDAP_INVALID_SYNTAX;
3532 /* Actually, dn_openssl2ldap returns in a normalized format, but
3533 it is different from our normalized format */
3535 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3539 return LDAP_INVALID_SYNTAX;
3545 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3546 out->bv_val = ch_malloc(out->bv_len);
3548 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3549 p += serial->bv_len;
3550 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3552 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3553 p += issuer_dn->bv_len;
3557 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3558 "certificateExactConvert: \n %s\n",
3561 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3563 out->bv_val, NULL, NULL );
3567 ber_bvfree(issuer_dn);
3569 return LDAP_SUCCESS;
3573 serial_and_issuer_parse(
3574 struct berval *assertion,
3575 struct berval **serial,
3576 struct berval **issuer_dn
3584 begin = assertion->bv_val;
3585 end = assertion->bv_val+assertion->bv_len-1;
3586 for (p=begin; p<=end && *p != '$'; p++)
3589 return LDAP_INVALID_SYNTAX;
3591 /* p now points at the $ sign, now use begin and end to delimit the
3593 while (ASCII_SPACE(*begin))
3596 while (ASCII_SPACE(*end))
3599 bv.bv_len = end-begin+1;
3601 *serial = ber_dupbv(NULL, &bv);
3603 /* now extract the issuer, remember p was at the dollar sign */
3605 end = assertion->bv_val+assertion->bv_len-1;
3606 while (ASCII_SPACE(*begin))
3608 /* should we trim spaces at the end too? is it safe always? */
3610 bv.bv_len = end-begin+1;
3612 dnNormalize( NULL, &bv, issuer_dn );
3614 return LDAP_SUCCESS;
3618 certificateExactMatch(
3623 struct berval *value,
3624 void *assertedValue )
3627 unsigned char *p = value->bv_val;
3628 struct berval *serial;
3629 struct berval *issuer_dn;
3630 struct berval *asserted_serial;
3631 struct berval *asserted_issuer_dn;
3634 xcert = d2i_X509(NULL, &p, value->bv_len);
3637 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3638 "certificateExactMatch: error parsing cert: %s\n",
3639 ERR_error_string(ERR_get_error(),NULL)));
3641 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3642 "error parsing cert: %s\n",
3643 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3645 return LDAP_INVALID_SYNTAX;
3648 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3649 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3653 serial_and_issuer_parse(assertedValue,
3655 &asserted_issuer_dn);
3660 slap_schema.si_syn_integer,
3661 slap_schema.si_mr_integerMatch,
3664 if ( ret == LDAP_SUCCESS ) {
3665 if ( *matchp == 0 ) {
3666 /* We need to normalize everything for dnMatch */
3670 slap_schema.si_syn_distinguishedName,
3671 slap_schema.si_mr_distinguishedNameMatch,
3673 asserted_issuer_dn);
3678 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3679 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3680 *matchp, serial->bv_val, issuer_dn->bv_val,
3681 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3683 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3684 "%d\n\t\"%s $ %s\"\n",
3685 *matchp, serial->bv_val, issuer_dn->bv_val );
3686 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3687 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3692 ber_bvfree(issuer_dn);
3693 ber_bvfree(asserted_serial);
3694 ber_bvfree(asserted_issuer_dn);
3700 * Index generation function
3701 * We just index the serials, in most scenarios the issuer DN is one of
3702 * a very small set of values.
3704 static int certificateExactIndexer(
3709 struct berval *prefix,
3717 struct berval * serial;
3719 /* we should have at least one value at this point */
3720 assert( values != NULL && values[0].bv_val != NULL );
3722 for( i=0; values[i].bv_val != NULL; i++ ) {
3723 /* empty -- just count them */
3726 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3728 for( i=0; values[i].bv_val != NULL; i++ ) {
3729 p = values[i].bv_val;
3730 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3733 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3734 "certificateExactIndexer: error parsing cert: %s\n",
3735 ERR_error_string(ERR_get_error(),NULL)));
3737 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3738 "error parsing cert: %s\n",
3739 ERR_error_string(ERR_get_error(),NULL),
3742 /* Do we leak keys on error? */
3743 return LDAP_INVALID_SYNTAX;
3746 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3748 integerNormalize( slap_schema.si_syn_integer,
3753 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3754 "certificateExactIndexer: returning: %s\n",
3757 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3764 keys[i].bv_val = NULL;
3766 return LDAP_SUCCESS;
3769 /* Index generation function */
3770 /* We think this is always called with a value in matching rule syntax */
3771 static int certificateExactFilter(
3776 struct berval *prefix,
3781 struct berval *asserted_serial;
3782 struct berval *asserted_issuer_dn;
3784 serial_and_issuer_parse(assertValue,
3786 &asserted_issuer_dn);
3788 keys = ch_malloc( sizeof( struct berval ) * 2 );
3789 integerNormalize( syntax, asserted_serial, &keys[0] );
3790 keys[1].bv_val = NULL;
3793 ber_bvfree(asserted_serial);
3794 ber_bvfree(asserted_issuer_dn);
3795 return LDAP_SUCCESS;
3800 check_time_syntax (struct berval *val,
3804 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3805 static int mdays[2][12] = {
3806 /* non-leap years */
3807 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3809 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3812 int part, c, tzoffset, leapyear = 0 ;
3814 if( val->bv_len == 0 ) {
3815 return LDAP_INVALID_SYNTAX;
3818 p = (char *)val->bv_val;
3819 e = p + val->bv_len;
3821 /* Ignore initial whitespace */
3822 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3826 if (e - p < 13 - (2 * start)) {
3827 return LDAP_INVALID_SYNTAX;
3830 for (part = 0; part < 9; part++) {
3834 for (part = start; part < 7; part++) {
3836 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3843 return LDAP_INVALID_SYNTAX;
3845 if (c < 0 || c > 9) {
3846 return LDAP_INVALID_SYNTAX;
3852 return LDAP_INVALID_SYNTAX;
3854 if (c < 0 || c > 9) {
3855 return LDAP_INVALID_SYNTAX;
3860 if (part == 2 || part == 3) {
3863 if (parts[part] < 0) {
3864 return LDAP_INVALID_SYNTAX;
3866 if (parts[part] > ceiling[part]) {
3867 return LDAP_INVALID_SYNTAX;
3871 /* leapyear check for the Gregorian calendar (year>1581) */
3872 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3873 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3878 if (parts[3] > mdays[leapyear][parts[2]]) {
3879 return LDAP_INVALID_SYNTAX;
3884 tzoffset = 0; /* UTC */
3885 } else if (c != '+' && c != '-') {
3886 return LDAP_INVALID_SYNTAX;
3890 } else /* c == '+' */ {
3895 return LDAP_INVALID_SYNTAX;
3898 for (part = 7; part < 9; part++) {
3900 if (c < 0 || c > 9) {
3901 return LDAP_INVALID_SYNTAX;
3906 if (c < 0 || c > 9) {
3907 return LDAP_INVALID_SYNTAX;
3911 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3912 return LDAP_INVALID_SYNTAX;
3917 /* Ignore trailing whitespace */
3918 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3922 return LDAP_INVALID_SYNTAX;
3925 switch ( tzoffset ) {
3926 case -1: /* negativ offset to UTC, ie west of Greenwich */
3927 parts[4] += parts[7];
3928 parts[5] += parts[8];
3929 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3933 c = mdays[leapyear][parts[2]];
3935 if (parts[part] > c) {
3936 parts[part] -= c + 1;
3941 case 1: /* positive offset to UTC, ie east of Greenwich */
3942 parts[4] -= parts[7];
3943 parts[5] -= parts[8];
3944 for (part = 6; --part > 0; ) {
3948 /* first arg to % needs to be non negativ */
3949 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3951 if (parts[part] < 0) {
3952 parts[part] += c + 1;
3957 case 0: /* already UTC */
3961 return LDAP_SUCCESS;
3968 struct berval *normalized )
3972 rc = check_time_syntax(val, 1, parts);
3973 if (rc != LDAP_SUCCESS) {
3977 normalized->bv_val = ch_malloc( 14 );
3978 if ( normalized->bv_val == NULL ) {
3979 return LBER_ERROR_MEMORY;
3982 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3983 parts[1], parts[2] + 1, parts[3] + 1,
3984 parts[4], parts[5], parts[6] );
3985 normalized->bv_len = 13;
3987 return LDAP_SUCCESS;
3997 return check_time_syntax(in, 1, parts);
4001 generalizedTimeValidate(
4007 return check_time_syntax(in, 0, parts);
4011 generalizedTimeNormalize(
4014 struct berval *normalized )
4018 rc = check_time_syntax(val, 0, parts);
4019 if (rc != LDAP_SUCCESS) {
4023 normalized->bv_val = ch_malloc( 16 );
4024 if ( normalized->bv_val == NULL ) {
4025 return LBER_ERROR_MEMORY;
4028 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4029 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4030 parts[4], parts[5], parts[6] );
4031 normalized->bv_len = 15;
4033 return LDAP_SUCCESS;
4037 nisNetgroupTripleValidate(
4039 struct berval *val )
4044 if ( val->bv_len == 0 ) {
4045 return LDAP_INVALID_SYNTAX;
4048 p = (char *)val->bv_val;
4049 e = p + val->bv_len;
4051 if ( *p != '(' /*')'*/ ) {
4052 return LDAP_INVALID_SYNTAX;
4055 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4059 return LDAP_INVALID_SYNTAX;
4062 } else if ( !ATTR_CHAR( *p ) ) {
4063 return LDAP_INVALID_SYNTAX;
4067 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4068 return LDAP_INVALID_SYNTAX;
4074 return LDAP_INVALID_SYNTAX;
4077 return LDAP_SUCCESS;
4081 bootParameterValidate(
4083 struct berval *val )
4087 if ( val->bv_len == 0 ) {
4088 return LDAP_INVALID_SYNTAX;
4091 p = (char *)val->bv_val;
4092 e = p + val->bv_len;
4095 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4096 if ( !ATTR_CHAR( *p ) ) {
4097 return LDAP_INVALID_SYNTAX;
4102 return LDAP_INVALID_SYNTAX;
4106 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4107 if ( !ATTR_CHAR( *p ) ) {
4108 return LDAP_INVALID_SYNTAX;
4113 return LDAP_INVALID_SYNTAX;
4117 for ( p++; p < e; p++ ) {
4118 if ( !ATTR_CHAR( *p ) ) {
4119 return LDAP_INVALID_SYNTAX;
4123 return LDAP_SUCCESS;
4126 static struct syntax_defs_rec {
4128 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4129 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4131 slap_syntax_validate_func *sd_validate;
4132 slap_syntax_transform_func *sd_normalize;
4133 slap_syntax_transform_func *sd_pretty;
4134 #ifdef SLAPD_BINARY_CONVERSION
4135 slap_syntax_transform_func *sd_ber2str;
4136 slap_syntax_transform_func *sd_str2ber;
4139 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4140 X_BINARY X_NOT_H_R ")",
4141 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4142 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4143 0, NULL, NULL, NULL},
4144 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4145 0, NULL, NULL, NULL},
4146 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4148 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4149 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4151 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4152 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4153 0, bitStringValidate, bitStringNormalize, NULL },
4154 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4155 0, booleanValidate, NULL, NULL},
4156 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4157 X_BINARY X_NOT_H_R ")",
4158 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4160 X_BINARY X_NOT_H_R ")",
4161 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4162 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4163 X_BINARY X_NOT_H_R ")",
4164 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4166 0, countryStringValidate, IA5StringNormalize, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4168 0, dnValidate, dnNormalize2, dnPretty2},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4170 0, NULL, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4172 0, NULL, NULL, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4174 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4176 0, NULL, NULL, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4178 0, NULL, NULL, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4180 0, NULL, NULL, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4182 0, NULL, NULL, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4184 0, NULL, NULL, NULL},
4185 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4186 0, printablesStringValidate, IA5StringNormalize, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4188 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4190 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4192 0, NULL, NULL, NULL},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4194 0, IA5StringValidate, IA5StringNormalize, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4196 0, integerValidate, integerNormalize, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4198 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4199 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4200 0, NULL, NULL, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4202 0, NULL, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4204 0, NULL, NULL, NULL},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4206 0, NULL, NULL, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4208 0, NULL, NULL, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4210 0, nameUIDValidate, nameUIDNormalize, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4212 0, NULL, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4214 0, numericStringValidate, numericStringNormalize, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4216 0, NULL, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4218 0, oidValidate, NULL, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4220 0, IA5StringValidate, IA5StringNormalize, NULL},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4222 0, blobValidate, NULL, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4224 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4225 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4226 0, NULL, NULL, NULL},
4227 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4228 0, NULL, NULL, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4230 0, printableStringValidate, IA5StringNormalize, NULL},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4232 X_BINARY X_NOT_H_R ")",
4233 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4235 X_BINARY X_NOT_H_R ")",
4236 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4238 0, printableStringValidate, IA5StringNormalize, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4240 0, NULL, NULL, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4242 0, printablesStringValidate, IA5StringNormalize, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4244 0, utcTimeValidate, utcTimeNormalize, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4246 0, NULL, NULL, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4248 0, NULL, NULL, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4250 0, NULL, NULL, NULL},
4251 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4252 0, NULL, NULL, NULL},
4253 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4254 0, NULL, NULL, NULL},
4256 /* RFC 2307 NIS Syntaxes */
4257 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4258 0, nisNetgroupTripleValidate, NULL, NULL},
4259 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4260 0, bootParameterValidate, NULL, NULL},
4264 /* These OIDs are not published yet, but will be in the next
4265 * I-D for PKIX LDAPv3 schema as have been advanced by David
4266 * Chadwick in private mail.
4268 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4269 0, NULL, NULL, NULL},
4272 /* OpenLDAP Experimental Syntaxes */
4273 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4275 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4278 #ifdef SLAPD_AUTHPASSWD
4279 /* needs updating */
4280 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4281 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4284 /* OpenLDAP Void Syntax */
4285 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4286 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4287 {NULL, 0, NULL, NULL, NULL}
4291 * Other matching rules in X.520 that we do not use (yet):
4293 * 2.5.13.9 numericStringOrderingMatch
4294 * 2.5.13.15 integerOrderingMatch
4295 * 2.5.13.18 octetStringOrderingMatch
4296 * 2.5.13.19 octetStringSubstringsMatch
4297 * 2.5.13.25 uTCTimeMatch
4298 * 2.5.13.26 uTCTimeOrderingMatch
4299 * 2.5.13.31 directoryStringFirstComponentMatch
4300 * 2.5.13.32 wordMatch
4301 * 2.5.13.33 keywordMatch
4302 * 2.5.13.35 certificateMatch
4303 * 2.5.13.36 certificatePairExactMatch
4304 * 2.5.13.37 certificatePairMatch
4305 * 2.5.13.38 certificateListExactMatch
4306 * 2.5.13.39 certificateListMatch
4307 * 2.5.13.40 algorithmIdentifierMatch
4308 * 2.5.13.41 storedPrefixMatch
4309 * 2.5.13.42 attributeCertificateMatch
4310 * 2.5.13.43 readerAndKeyIDMatch
4311 * 2.5.13.44 attributeIntegrityMatch
4313 static struct mrule_defs_rec {
4315 slap_mask_t mrd_usage;
4316 slap_mr_convert_func * mrd_convert;
4317 slap_mr_normalize_func * mrd_normalize;
4318 slap_mr_match_func * mrd_match;
4319 slap_mr_indexer_func * mrd_indexer;
4320 slap_mr_filter_func * mrd_filter;
4322 char * mrd_associated;
4325 * EQUALITY matching rules must be listed after associated APPROX
4326 * matching rules. So, we list all APPROX matching rules first.
4328 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4329 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4330 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4332 directoryStringApproxMatch,
4333 directoryStringApproxIndexer,
4334 directoryStringApproxFilter,
4337 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4338 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4339 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4341 IA5StringApproxMatch,
4342 IA5StringApproxIndexer,
4343 IA5StringApproxFilter,
4347 * Other matching rules
4350 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4351 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4352 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4354 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4357 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4358 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4359 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4361 dnMatch, dnIndexer, dnFilter,
4364 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4365 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4366 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4368 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4369 directoryStringApproxMatchOID },
4371 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4372 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4375 caseIgnoreOrderingMatch, NULL, NULL,
4378 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4379 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4380 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4382 caseExactIgnoreSubstringsMatch,
4383 caseExactIgnoreSubstringsIndexer,
4384 caseExactIgnoreSubstringsFilter,
4387 {"( 2.5.13.5 NAME 'caseExactMatch' "
4388 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4389 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4391 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4392 directoryStringApproxMatchOID },
4394 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4395 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4398 caseExactOrderingMatch, NULL, NULL,
4401 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4402 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4403 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4405 caseExactIgnoreSubstringsMatch,
4406 caseExactIgnoreSubstringsIndexer,
4407 caseExactIgnoreSubstringsFilter,
4410 {"( 2.5.13.8 NAME 'numericStringMatch' "
4411 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4412 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4415 caseIgnoreIA5Indexer,
4416 caseIgnoreIA5Filter,
4419 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4420 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4421 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4423 caseIgnoreIA5SubstringsMatch,
4424 caseIgnoreIA5SubstringsIndexer,
4425 caseIgnoreIA5SubstringsFilter,
4428 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4429 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4430 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4432 caseIgnoreListMatch, NULL, NULL,
4435 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4436 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4437 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4439 caseIgnoreListSubstringsMatch, NULL, NULL,
4442 {"( 2.5.13.13 NAME 'booleanMatch' "
4443 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4444 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4446 booleanMatch, NULL, NULL,
4449 {"( 2.5.13.14 NAME 'integerMatch' "
4450 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4451 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4453 integerMatch, integerIndexer, integerFilter,
4456 {"( 2.5.13.16 NAME 'bitStringMatch' "
4457 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4458 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4460 bitStringMatch, bitStringIndexer, bitStringFilter,
4463 {"( 2.5.13.17 NAME 'octetStringMatch' "
4464 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4465 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4467 octetStringMatch, octetStringIndexer, octetStringFilter,
4470 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4471 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4472 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4474 telephoneNumberMatch,
4475 telephoneNumberIndexer,
4476 telephoneNumberFilter,
4479 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4480 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4481 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4483 telephoneNumberSubstringsMatch,
4484 telephoneNumberSubstringsIndexer,
4485 telephoneNumberSubstringsFilter,
4488 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4489 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4490 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4495 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4496 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4497 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4499 uniqueMemberMatch, NULL, NULL,
4502 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4503 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4504 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4506 protocolInformationMatch, NULL, NULL,
4509 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4510 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4511 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4513 generalizedTimeMatch, NULL, NULL,
4516 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4517 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4520 generalizedTimeOrderingMatch, NULL, NULL,
4523 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4524 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4525 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4527 integerFirstComponentMatch, NULL, NULL,
4530 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4531 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4532 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4534 objectIdentifierFirstComponentMatch, NULL, NULL,
4538 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4539 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4540 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4541 certificateExactConvert, NULL,
4542 certificateExactMatch,
4543 certificateExactIndexer, certificateExactFilter,
4547 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4548 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4549 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4551 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4552 IA5StringApproxMatchOID },
4554 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4555 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4556 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4558 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4559 IA5StringApproxMatchOID },
4561 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4562 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4565 caseIgnoreIA5SubstringsMatch,
4566 caseIgnoreIA5SubstringsIndexer,
4567 caseIgnoreIA5SubstringsFilter,
4570 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4571 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4574 caseExactIA5SubstringsMatch,
4575 caseExactIA5SubstringsIndexer,
4576 caseExactIA5SubstringsFilter,
4579 #ifdef SLAPD_AUTHPASSWD
4580 /* needs updating */
4581 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4582 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4585 authPasswordMatch, NULL, NULL,
4589 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4590 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4593 OpenLDAPaciMatch, NULL, NULL,
4596 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4597 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4600 integerBitAndMatch, NULL, NULL,
4603 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4604 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4607 integerBitOrMatch, NULL, NULL,
4610 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4614 slap_schema_init( void )
4619 /* we should only be called once (from main) */
4620 assert( schema_init_done == 0 );
4622 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4623 res = register_syntax( syntax_defs[i].sd_desc,
4624 syntax_defs[i].sd_flags,
4625 syntax_defs[i].sd_validate,
4626 syntax_defs[i].sd_normalize,
4627 syntax_defs[i].sd_pretty
4628 #ifdef SLAPD_BINARY_CONVERSION
4630 syntax_defs[i].sd_ber2str,
4631 syntax_defs[i].sd_str2ber
4636 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4637 syntax_defs[i].sd_desc );
4642 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4643 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4645 "slap_schema_init: Ingoring unusable matching rule %s\n",
4646 mrule_defs[i].mrd_desc );
4650 res = register_matching_rule(
4651 mrule_defs[i].mrd_desc,
4652 mrule_defs[i].mrd_usage,
4653 mrule_defs[i].mrd_convert,
4654 mrule_defs[i].mrd_normalize,
4655 mrule_defs[i].mrd_match,
4656 mrule_defs[i].mrd_indexer,
4657 mrule_defs[i].mrd_filter,
4658 mrule_defs[i].mrd_associated );
4662 "slap_schema_init: Error registering matching rule %s\n",
4663 mrule_defs[i].mrd_desc );
4668 res = slap_schema_load();
4669 schema_init_done = 1;
4674 schema_destroy( void )