1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
15 #include <ac/string.h>
16 #include <ac/socket.h>
21 #include "ldap_utf8.h"
23 #include "lutil_hash.h"
24 #define HASH_BYTES LUTIL_HASH_BYTES
25 #define HASH_CONTEXT lutil_HASH_CTX
26 #define HASH_Init(c) lutil_HASHInit(c)
27 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
28 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
30 /* recycled validatation routines */
31 #define berValidate blobValidate
33 /* unimplemented pretters */
34 #define integerPretty NULL
36 /* recycled matching routines */
37 #define bitStringMatch octetStringMatch
38 #define numericStringMatch caseIgnoreIA5Match
39 #define objectIdentifierMatch caseIgnoreIA5Match
40 #define telephoneNumberMatch caseIgnoreIA5Match
41 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
42 #define generalizedTimeMatch caseIgnoreIA5Match
43 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
44 #define uniqueMemberMatch dnMatch
46 /* approx matching rules */
47 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
48 #define directoryStringApproxMatch approxMatch
49 #define directoryStringApproxIndexer approxIndexer
50 #define directoryStringApproxFilter approxFilter
51 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
52 #define IA5StringApproxMatch approxMatch
53 #define IA5StringApproxIndexer approxIndexer
54 #define IA5StringApproxFilter approxFilter
56 /* orderring matching rules */
57 #define caseIgnoreOrderingMatch caseIgnoreMatch
58 #define caseExactOrderingMatch caseExactMatch
60 /* unimplemented matching routines */
61 #define caseIgnoreListMatch NULL
62 #define caseIgnoreListSubstringsMatch NULL
63 #define protocolInformationMatch NULL
64 #define integerFirstComponentMatch NULL
66 #define OpenLDAPaciMatch NULL
67 #define authPasswordMatch NULL
69 /* recycled indexing/filtering routines */
70 #define dnIndexer caseExactIgnoreIndexer
71 #define dnFilter caseExactIgnoreFilter
72 #define bitStringFilter octetStringFilter
73 #define bitStringIndexer octetStringIndexer
75 #define telephoneNumberIndexer caseIgnoreIA5Indexer
76 #define telephoneNumberFilter caseIgnoreIA5Filter
77 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
78 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
80 /* must match OIDs below */
81 #define caseExactMatchOID "2.5.13.5"
82 #define caseExactSubstringsMatchOID "2.5.13.7"
84 static char *strcasechr( const char *str, int c )
86 char *lower = strchr( str, TOLOWER(c) );
87 char *upper = strchr( str, TOUPPER(c) );
89 if( lower && upper ) {
90 return lower < upper ? lower : upper;
104 struct berval *value,
105 void *assertedValue )
107 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
110 match = memcmp( value->bv_val,
111 ((struct berval *) assertedValue)->bv_val,
119 /* Index generation function */
120 static int octetStringIndexer(
125 struct berval *prefix,
126 struct berval **values,
127 struct berval **keysp )
132 HASH_CONTEXT HASHcontext;
133 unsigned char HASHdigest[HASH_BYTES];
134 struct berval digest;
135 digest.bv_val = HASHdigest;
136 digest.bv_len = sizeof(HASHdigest);
138 for( i=0; values[i] != NULL; i++ ) {
139 /* just count them */
142 /* we should have at least one value at this point */
145 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
147 slen = syntax->ssyn_oidlen;
148 mlen = mr->smr_oidlen;
150 for( i=0; values[i] != NULL; i++ ) {
151 HASH_Init( &HASHcontext );
152 if( prefix != NULL && prefix->bv_len > 0 ) {
153 HASH_Update( &HASHcontext,
154 prefix->bv_val, prefix->bv_len );
156 HASH_Update( &HASHcontext,
157 syntax->ssyn_oid, slen );
158 HASH_Update( &HASHcontext,
160 HASH_Update( &HASHcontext,
161 values[i]->bv_val, values[i]->bv_len );
162 HASH_Final( HASHdigest, &HASHcontext );
164 ber_dupbv( &keys[i], &digest );
167 keys[i].bv_val = NULL;
174 /* Index generation function */
175 static int octetStringFilter(
180 struct berval *prefix,
182 struct berval **keysp )
186 HASH_CONTEXT HASHcontext;
187 unsigned char HASHdigest[HASH_BYTES];
188 struct berval *value = (struct berval *) assertValue;
189 struct berval digest;
190 digest.bv_val = HASHdigest;
191 digest.bv_len = sizeof(HASHdigest);
193 slen = syntax->ssyn_oidlen;
194 mlen = mr->smr_oidlen;
196 keys = ch_malloc( sizeof( struct berval ) * 2 );
198 HASH_Init( &HASHcontext );
199 if( prefix != NULL && prefix->bv_len > 0 ) {
200 HASH_Update( &HASHcontext,
201 prefix->bv_val, prefix->bv_len );
203 HASH_Update( &HASHcontext,
204 syntax->ssyn_oid, slen );
205 HASH_Update( &HASHcontext,
207 HASH_Update( &HASHcontext,
208 value->bv_val, value->bv_len );
209 HASH_Final( HASHdigest, &HASHcontext );
211 ber_dupbv( keys, &digest );
212 keys[1].bv_val = NULL;
227 if( in->bv_len == 0 ) return LDAP_SUCCESS;
229 dn = ber_bvdup( in );
230 if( !dn ) return LDAP_OTHER;
232 if( dn->bv_val[dn->bv_len-1] == 'B'
233 && dn->bv_val[dn->bv_len-2] == '\'' )
235 /* assume presence of optional UID */
238 for(i=dn->bv_len-3; i>1; i--) {
239 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
243 if( dn->bv_val[i] != '\'' ||
244 dn->bv_val[i-1] != '#' ) {
246 return LDAP_INVALID_SYNTAX;
249 /* trim the UID to allow use of dnValidate */
250 dn->bv_val[i-1] = '\0';
254 rc = dnValidate( NULL, dn );
264 struct berval *normalized )
269 ber_dupbv( &out, val );
270 if( out.bv_len != 0 ) {
273 ber_len_t uidlen = 0;
275 if( out.bv_val[out.bv_len-1] == '\'' ) {
276 /* assume presence of optional UID */
277 uid = strrchr( out.bv_val, '#' );
281 return LDAP_INVALID_SYNTAX;
284 uidlen = out.bv_len - (uid - out.bv_val);
285 /* temporarily trim the UID */
287 out.bv_len -= uidlen;
290 #ifdef USE_DN_NORMALIZE
291 rc = dnNormalize2( NULL, &out, normalized );
293 rc = dnPretty2( NULL, &out, normalized );
296 if( rc != LDAP_SUCCESS ) {
298 return LDAP_INVALID_SYNTAX;
301 dnlen = normalized->bv_len;
305 b2.bv_val = ch_malloc(dnlen + uidlen + 1);
306 SAFEMEMCPY( b2.bv_val, normalized->bv_val, dnlen );
308 /* restore the separator */
311 SAFEMEMCPY( normalized->bv_val+dnlen, uid, uidlen );
312 b2.bv_len = dnlen + uidlen;
313 normalized->bv_val[dnlen+uidlen] = '\0';
314 free(normalized->bv_val);
328 /* any value allowed */
337 /* any value allowed */
348 /* very unforgiving validation, requires no normalization
349 * before simplistic matching
351 if( in->bv_len < 3 ) {
352 return LDAP_INVALID_SYNTAX;
356 * rfc 2252 section 6.3 Bit String
357 * bitstring = "'" *binary-digit "'"
358 * binary-digit = "0" / "1"
359 * example: '0101111101'B
362 if( in->bv_val[0] != '\'' ||
363 in->bv_val[in->bv_len-2] != '\'' ||
364 in->bv_val[in->bv_len-1] != 'B' )
366 return LDAP_INVALID_SYNTAX;
369 for( i=in->bv_len-3; i>0; i-- ) {
370 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
371 return LDAP_INVALID_SYNTAX;
382 struct berval *normalized )
385 * A normalized bitString is has no extaneous (leading) zero bits.
386 * That is, '00010'B is normalized to '10'B
387 * However, as a special case, '0'B requires no normalization.
391 /* start at the first bit */
394 /* Find the first non-zero bit */
395 while ( *p == '0' ) p++;
398 /* no non-zero bits */
399 ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
403 normalized->bv_val = ch_malloc( val->bv_len + 1 );
405 normalized->bv_val[0] = '\'';
406 normalized->bv_len = 1;
408 for( ; *p != '\0'; p++ ) {
409 normalized->bv_val[normalized->bv_len++] = *p;
412 normalized->bv_val[normalized->bv_len] = '\0';
419 * Handling boolean syntax and matching is quite rigid.
420 * A more flexible approach would be to allow a variety
421 * of strings to be normalized and prettied into TRUE
429 /* very unforgiving validation, requires no normalization
430 * before simplistic matching
433 if( in->bv_len == 4 ) {
434 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
437 } else if( in->bv_len == 5 ) {
438 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
443 return LDAP_INVALID_SYNTAX;
452 struct berval *value,
453 void *assertedValue )
455 /* simplistic matching allowed by rigid validation */
456 struct berval *asserted = (struct berval *) assertedValue;
457 *matchp = value->bv_len != asserted->bv_len;
468 unsigned char *u = in->bv_val;
470 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
472 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
473 /* get the length indicated by the first byte */
474 len = LDAP_UTF8_CHARLEN( u );
476 /* should not be zero */
477 if( len == 0 ) return LDAP_INVALID_SYNTAX;
479 /* make sure len corresponds with the offset
480 to the next character */
481 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
484 if( count != 0 ) return LDAP_INVALID_SYNTAX;
493 struct berval *normalized )
499 /* Ignore initial whitespace */
500 while ( ldap_utf8_isspace( p ) ) {
505 return LDAP_INVALID_SYNTAX;
508 ber_str2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
510 assert( normalized->bv_val );
512 p = q = normalized->bv_val;
518 if ( ldap_utf8_isspace( p ) ) {
519 len = LDAP_UTF8_COPY(q,p);
524 /* Ignore the extra whitespace */
525 while ( ldap_utf8_isspace( p ) ) {
529 len = LDAP_UTF8_COPY(q,p);
536 assert( normalized->bv_val < p );
539 /* cannot start with a space */
540 assert( !ldap_utf8_isspace(normalized->bv_val) );
543 * If the string ended in space, backup the pointer one
544 * position. One is enough because the above loop collapsed
545 * all whitespace to a single space.
552 /* cannot end with a space */
553 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
558 normalized->bv_len = q - normalized->bv_val;
563 /* Returns Unicode cannonically normalized copy of a substring assertion
564 * Skipping attribute description */
565 static SubstringsAssertion *
566 UTF8SubstringsassertionNormalize(
567 SubstringsAssertion *sa,
570 SubstringsAssertion *nsa;
573 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
578 if( sa->sa_initial.bv_val != NULL ) {
579 ber_str2bv( UTF8normalize( &sa->sa_initial, casefold ), 0,
580 0, &nsa->sa_initial );
581 if( nsa->sa_initial.bv_val == NULL ) {
586 if( sa->sa_any != NULL ) {
587 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
590 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
591 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
592 ber_str2bv( UTF8normalize( &sa->sa_any[i], casefold ),
593 0, 0, &nsa->sa_any[i] );
594 if( nsa->sa_any[i].bv_val == NULL ) {
598 nsa->sa_any[i].bv_val = NULL;
601 if( sa->sa_final.bv_val != NULL ) {
602 ber_str2bv( UTF8normalize( &sa->sa_final, casefold ), 0,
604 if( nsa->sa_final.bv_val == NULL ) {
612 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
613 if ( nsa->sa_any )bvarray_free( nsa->sa_any );
614 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
619 /* Strip characters with the 8th bit set */
632 while( *++q & 0x80 ) {
635 p = memmove(p, q, strlen(q) + 1);
643 #ifndef SLAPD_APPROX_OLDSINGLESTRING
645 #if defined(SLAPD_APPROX_INITIALS)
646 #define SLAPD_APPROX_DELIMITER "._ "
647 #define SLAPD_APPROX_WORDLEN 2
649 #define SLAPD_APPROX_DELIMITER " "
650 #define SLAPD_APPROX_WORDLEN 1
659 struct berval *value,
660 void *assertedValue )
662 char *val, *nval, *assertv, **values, **words, *c;
663 int i, count, len, nextchunk=0, nextavail=0;
666 /* Yes, this is necessary */
667 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
672 strip8bitChars( nval );
674 /* Yes, this is necessary */
675 assertv = UTF8normalize( ((struct berval *)assertedValue),
677 if( assertv == NULL ) {
682 strip8bitChars( assertv );
683 avlen = strlen( assertv );
685 /* Isolate how many words there are */
686 for( c=nval,count=1; *c; c++ ) {
687 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
688 if ( c == NULL ) break;
693 /* Get a phonetic copy of each word */
694 words = (char **)ch_malloc( count * sizeof(char *) );
695 values = (char **)ch_malloc( count * sizeof(char *) );
696 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
698 values[i] = phonetic(c);
701 /* Work through the asserted value's words, to see if at least some
702 of the words are there, in the same order. */
704 while ( (size_t) nextchunk < avlen ) {
705 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
710 #if defined(SLAPD_APPROX_INITIALS)
711 else if( len == 1 ) {
712 /* Single letter words need to at least match one word's initial */
713 for( i=nextavail; i<count; i++ )
714 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
721 /* Isolate the next word in the asserted value and phonetic it */
722 assertv[nextchunk+len] = '\0';
723 val = phonetic( assertv + nextchunk );
725 /* See if this phonetic chunk is in the remaining words of *value */
726 for( i=nextavail; i<count; i++ ){
727 if( !strcmp( val, values[i] ) ){
735 /* This chunk in the asserted value was NOT within the *value. */
741 /* Go on to the next word in the asserted value */
745 /* If some of the words were seen, call it a match */
746 if( nextavail > 0 ) {
755 for( i=0; i<count; i++ ) {
756 ch_free( values[i] );
771 struct berval *prefix,
772 struct berval **values,
773 struct berval **keysp )
776 int i,j, len, wordcount, keycount=0;
777 struct berval *newkeys, *keys=NULL;
779 for( j=0; values[j] != NULL; j++ ) {
780 /* Yes, this is necessary */
781 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
782 strip8bitChars( val );
784 /* Isolate how many words there are. There will be a key for each */
785 for( wordcount=0,c=val; *c; c++) {
786 len = strcspn(c, SLAPD_APPROX_DELIMITER);
787 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
789 if (*c == '\0') break;
793 /* Allocate/increase storage to account for new keys */
794 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
795 * sizeof(struct berval) );
796 memcpy( newkeys, keys, keycount * sizeof(struct berval) );
797 if( keys ) ch_free( keys );
800 /* Get a phonetic copy of each word */
801 for( c=val,i=0; i<wordcount; c+=len+1 ) {
803 if( len < SLAPD_APPROX_WORDLEN ) continue;
804 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
811 keys[keycount].bv_val = NULL;
823 struct berval *prefix,
825 struct berval **keysp )
831 /* Yes, this is necessary */
832 val = UTF8normalize( ((struct berval *)assertValue),
835 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
836 keys[0].bv_val = NULL;
840 strip8bitChars( val );
842 /* Isolate how many words there are. There will be a key for each */
843 for( count=0,c=val; *c; c++) {
844 len = strcspn(c, SLAPD_APPROX_DELIMITER);
845 if( len >= SLAPD_APPROX_WORDLEN ) count++;
847 if (*c == '\0') break;
851 /* Allocate storage for new keys */
852 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
854 /* Get a phonetic copy of each word */
855 for( c=val,i=0; i<count; c+=len+1 ) {
857 if( len < SLAPD_APPROX_WORDLEN ) continue;
858 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
864 keys[count].bv_val = NULL;
872 /* No other form of Approximate Matching is defined */
880 struct berval *value,
881 void *assertedValue )
883 char *vapprox, *avapprox;
886 /* Yes, this is necessary */
887 s = UTF8normalize( value, UTF8_NOCASEFOLD );
893 /* Yes, this is necessary */
894 t = UTF8normalize( ((struct berval *)assertedValue),
902 vapprox = phonetic( strip8bitChars( s ) );
903 avapprox = phonetic( strip8bitChars( t ) );
908 *matchp = strcmp( vapprox, avapprox );
922 struct berval *prefix,
923 struct berval **values,
924 struct berval **keysp )
930 for( i=0; values[i] != NULL; i++ ) {
931 /* empty - just count them */
934 /* we should have at least one value at this point */
937 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
939 /* Copy each value and run it through phonetic() */
940 for( i=0; values[i] != NULL; i++ ) {
941 /* Yes, this is necessary */
942 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
944 /* strip 8-bit chars and run through phonetic() */
945 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
948 keys[i].bv_val = NULL;
961 struct berval *prefix,
963 struct berval **keysp )
968 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
970 /* Yes, this is necessary */
971 s = UTF8normalize( ((struct berval *)assertValue),
976 /* strip 8-bit chars and run through phonetic() */
977 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
994 struct berval *value,
995 void *assertedValue )
997 *matchp = UTF8normcmp( value->bv_val,
998 ((struct berval *) assertedValue)->bv_val,
1000 return LDAP_SUCCESS;
1004 caseExactIgnoreSubstringsMatch(
1009 struct berval *value,
1010 void *assertedValue )
1013 SubstringsAssertion *sub = NULL;
1017 char *nav, casefold;
1019 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1020 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1022 nav = UTF8normalize( value, casefold );
1028 left.bv_len = strlen( nav );
1030 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1036 /* Add up asserted input length */
1037 if( sub->sa_initial.bv_val ) {
1038 inlen += sub->sa_initial.bv_len;
1041 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1042 inlen += sub->sa_any[i].bv_len;
1045 if( sub->sa_final.bv_val ) {
1046 inlen += sub->sa_final.bv_len;
1049 if( sub->sa_initial.bv_val ) {
1050 if( inlen > left.bv_len ) {
1055 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
1056 sub->sa_initial.bv_len );
1062 left.bv_val += sub->sa_initial.bv_len;
1063 left.bv_len -= sub->sa_initial.bv_len;
1064 inlen -= sub->sa_initial.bv_len;
1067 if( sub->sa_final.bv_val ) {
1068 if( inlen > left.bv_len ) {
1073 match = strncmp( sub->sa_final.bv_val,
1074 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1075 sub->sa_final.bv_len );
1081 left.bv_len -= sub->sa_final.bv_len;
1082 inlen -= sub->sa_final.bv_len;
1086 for(i=0; sub->sa_any[i].bv_val; i++) {
1091 if( inlen > left.bv_len ) {
1092 /* not enough length */
1097 if( sub->sa_any[i].bv_len == 0 ) {
1101 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
1108 idx = p - left.bv_val;
1109 assert( idx < left.bv_len );
1111 if( idx >= left.bv_len ) {
1112 /* this shouldn't happen */
1114 if ( sub->sa_final.bv_val )
1115 ch_free( sub->sa_final.bv_val );
1117 bvarray_free( sub->sa_any );
1118 if ( sub->sa_initial.bv_val )
1119 ch_free( sub->sa_initial.bv_val );
1127 if( sub->sa_any[i].bv_len > left.bv_len ) {
1128 /* not enough left */
1133 match = strncmp( left.bv_val,
1134 sub->sa_any[i].bv_val,
1135 sub->sa_any[i].bv_len );
1143 left.bv_val += sub->sa_any[i].bv_len;
1144 left.bv_len -= sub->sa_any[i].bv_len;
1145 inlen -= sub->sa_any[i].bv_len;
1152 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1153 if ( sub->sa_any ) bvarray_free( sub->sa_any );
1154 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1158 return LDAP_SUCCESS;
1161 /* Index generation function */
1162 static int caseExactIgnoreIndexer(
1167 struct berval *prefix,
1168 struct berval **values,
1169 struct berval **keysp )
1174 struct berval *keys;
1175 HASH_CONTEXT HASHcontext;
1176 unsigned char HASHdigest[HASH_BYTES];
1177 struct berval digest;
1178 digest.bv_val = HASHdigest;
1179 digest.bv_len = sizeof(HASHdigest);
1181 for( i=0; values[i] != NULL; i++ ) {
1182 /* empty - just count them */
1185 /* we should have at least one value at this point */
1188 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1190 slen = syntax->ssyn_oidlen;
1191 mlen = mr->smr_oidlen;
1193 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1194 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1196 for( i=0; values[i] != NULL; i++ ) {
1197 struct berval value;
1198 ber_str2bv( UTF8normalize( values[i], casefold ), 0, 0,
1201 HASH_Init( &HASHcontext );
1202 if( prefix != NULL && prefix->bv_len > 0 ) {
1203 HASH_Update( &HASHcontext,
1204 prefix->bv_val, prefix->bv_len );
1206 HASH_Update( &HASHcontext,
1207 syntax->ssyn_oid, slen );
1208 HASH_Update( &HASHcontext,
1209 mr->smr_oid, mlen );
1210 HASH_Update( &HASHcontext,
1211 value.bv_val, value.bv_len );
1212 HASH_Final( HASHdigest, &HASHcontext );
1214 free( value.bv_val );
1216 ber_dupbv( &keys[i], &digest );
1219 keys[i].bv_val = NULL;
1221 return LDAP_SUCCESS;
1224 /* Index generation function */
1225 static int caseExactIgnoreFilter(
1230 struct berval *prefix,
1232 struct berval **keysp )
1236 struct berval *keys;
1237 HASH_CONTEXT HASHcontext;
1238 unsigned char HASHdigest[HASH_BYTES];
1239 struct berval value;
1240 struct berval digest;
1241 digest.bv_val = HASHdigest;
1242 digest.bv_len = sizeof(HASHdigest);
1244 slen = syntax->ssyn_oidlen;
1245 mlen = mr->smr_oidlen;
1247 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1248 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1250 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1252 /* This usually happens if filter contains bad UTF8 */
1253 if( value.bv_val == NULL ) {
1254 keys = ch_malloc( sizeof( struct berval ) );
1255 keys[0].bv_val = NULL;
1256 return LDAP_SUCCESS;
1259 keys = ch_malloc( sizeof( struct berval ) * 2 );
1261 HASH_Init( &HASHcontext );
1262 if( prefix != NULL && prefix->bv_len > 0 ) {
1263 HASH_Update( &HASHcontext,
1264 prefix->bv_val, prefix->bv_len );
1266 HASH_Update( &HASHcontext,
1267 syntax->ssyn_oid, slen );
1268 HASH_Update( &HASHcontext,
1269 mr->smr_oid, mlen );
1270 HASH_Update( &HASHcontext,
1271 value.bv_val, value.bv_len );
1272 HASH_Final( HASHdigest, &HASHcontext );
1274 ber_dupbv( keys, &digest );
1275 keys[1].bv_val = NULL;
1277 free( value.bv_val );
1280 return LDAP_SUCCESS;
1283 /* Substrings Index generation function */
1284 static int caseExactIgnoreSubstringsIndexer(
1289 struct berval *prefix,
1290 struct berval **values,
1291 struct berval **keysp )
1296 struct berval *keys;
1297 struct berval **nvalues;
1299 HASH_CONTEXT HASHcontext;
1300 unsigned char HASHdigest[HASH_BYTES];
1301 struct berval digest;
1302 digest.bv_val = HASHdigest;
1303 digest.bv_len = sizeof(HASHdigest);
1307 for( i=0; values[i] != NULL; i++ ) {
1308 /* empty - just count them */
1311 /* we should have at least one value at this point */
1314 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1315 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1317 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1318 for( i=0; values[i] != NULL; i++ ) {
1319 nvalues[i] = ber_str2bv( UTF8normalize( values[i], casefold ),
1325 for( i=0; values[i] != NULL; i++ ) {
1326 /* count number of indices to generate */
1327 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1331 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1332 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1333 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1334 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1336 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1340 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1341 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1342 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1346 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1347 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1348 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1349 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1351 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1357 /* no keys to generate */
1359 ber_bvecfree( nvalues );
1360 return LDAP_SUCCESS;
1363 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1365 slen = syntax->ssyn_oidlen;
1366 mlen = mr->smr_oidlen;
1369 for( i=0; values[i] != NULL; i++ ) {
1372 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1374 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1375 ( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1377 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1378 max = values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1380 for( j=0; j<max; j++ ) {
1381 HASH_Init( &HASHcontext );
1382 if( prefix != NULL && prefix->bv_len > 0 ) {
1383 HASH_Update( &HASHcontext,
1384 prefix->bv_val, prefix->bv_len );
1387 HASH_Update( &HASHcontext,
1388 &pre, sizeof( pre ) );
1389 HASH_Update( &HASHcontext,
1390 syntax->ssyn_oid, slen );
1391 HASH_Update( &HASHcontext,
1392 mr->smr_oid, mlen );
1393 HASH_Update( &HASHcontext,
1394 &values[i]->bv_val[j],
1395 SLAP_INDEX_SUBSTR_MAXLEN );
1396 HASH_Final( HASHdigest, &HASHcontext );
1398 ber_dupbv( &keys[nkeys++], &digest );
1402 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i]->bv_len
1403 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i]->bv_len;
1405 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1408 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1409 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1410 HASH_Init( &HASHcontext );
1411 if( prefix != NULL && prefix->bv_len > 0 ) {
1412 HASH_Update( &HASHcontext,
1413 prefix->bv_val, prefix->bv_len );
1415 HASH_Update( &HASHcontext,
1416 &pre, sizeof( pre ) );
1417 HASH_Update( &HASHcontext,
1418 syntax->ssyn_oid, slen );
1419 HASH_Update( &HASHcontext,
1420 mr->smr_oid, mlen );
1421 HASH_Update( &HASHcontext,
1422 values[i]->bv_val, j );
1423 HASH_Final( HASHdigest, &HASHcontext );
1425 ber_dupbv( &keys[nkeys++], &digest );
1428 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1429 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1430 HASH_Init( &HASHcontext );
1431 if( prefix != NULL && prefix->bv_len > 0 ) {
1432 HASH_Update( &HASHcontext,
1433 prefix->bv_val, prefix->bv_len );
1435 HASH_Update( &HASHcontext,
1436 &pre, sizeof( pre ) );
1437 HASH_Update( &HASHcontext,
1438 syntax->ssyn_oid, slen );
1439 HASH_Update( &HASHcontext,
1440 mr->smr_oid, mlen );
1441 HASH_Update( &HASHcontext,
1442 &values[i]->bv_val[values[i]->bv_len-j], j );
1443 HASH_Final( HASHdigest, &HASHcontext );
1445 ber_dupbv( &keys[nkeys++], &digest );
1453 keys[nkeys].bv_val = NULL;
1460 ber_bvecfree( nvalues );
1462 return LDAP_SUCCESS;
1465 static int caseExactIgnoreSubstringsFilter(
1470 struct berval *prefix,
1472 struct berval **keysp )
1474 SubstringsAssertion *sa;
1476 ber_len_t nkeys = 0;
1477 size_t slen, mlen, klen;
1478 struct berval *keys;
1479 HASH_CONTEXT HASHcontext;
1480 unsigned char HASHdigest[HASH_BYTES];
1481 struct berval *value;
1482 struct berval digest;
1484 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1485 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1487 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1490 return LDAP_SUCCESS;
1493 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1494 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1499 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1501 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1502 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1503 /* don't bother accounting for stepping */
1504 nkeys += sa->sa_any[i].bv_len -
1505 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1510 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1511 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1517 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1518 if ( sa->sa_any ) bvarray_free( sa->sa_any );
1519 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1522 return LDAP_SUCCESS;
1525 digest.bv_val = HASHdigest;
1526 digest.bv_len = sizeof(HASHdigest);
1528 slen = syntax->ssyn_oidlen;
1529 mlen = mr->smr_oidlen;
1531 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1534 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1535 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1537 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1538 value = &sa->sa_initial;
1540 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1541 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1543 HASH_Init( &HASHcontext );
1544 if( prefix != NULL && prefix->bv_len > 0 ) {
1545 HASH_Update( &HASHcontext,
1546 prefix->bv_val, prefix->bv_len );
1548 HASH_Update( &HASHcontext,
1549 &pre, sizeof( pre ) );
1550 HASH_Update( &HASHcontext,
1551 syntax->ssyn_oid, slen );
1552 HASH_Update( &HASHcontext,
1553 mr->smr_oid, mlen );
1554 HASH_Update( &HASHcontext,
1555 value->bv_val, klen );
1556 HASH_Final( HASHdigest, &HASHcontext );
1558 ber_dupbv( &keys[nkeys++], &digest );
1561 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1563 pre = SLAP_INDEX_SUBSTR_PREFIX;
1564 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1566 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1567 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1571 value = &sa->sa_any[i];
1574 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1575 j += SLAP_INDEX_SUBSTR_STEP )
1577 HASH_Init( &HASHcontext );
1578 if( prefix != NULL && prefix->bv_len > 0 ) {
1579 HASH_Update( &HASHcontext,
1580 prefix->bv_val, prefix->bv_len );
1582 HASH_Update( &HASHcontext,
1583 &pre, sizeof( pre ) );
1584 HASH_Update( &HASHcontext,
1585 syntax->ssyn_oid, slen );
1586 HASH_Update( &HASHcontext,
1587 mr->smr_oid, mlen );
1588 HASH_Update( &HASHcontext,
1589 &value->bv_val[j], klen );
1590 HASH_Final( HASHdigest, &HASHcontext );
1592 ber_dupbv( &keys[nkeys++], &digest );
1598 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1599 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1601 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1602 value = &sa->sa_final;
1604 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1605 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1607 HASH_Init( &HASHcontext );
1608 if( prefix != NULL && prefix->bv_len > 0 ) {
1609 HASH_Update( &HASHcontext,
1610 prefix->bv_val, prefix->bv_len );
1612 HASH_Update( &HASHcontext,
1613 &pre, sizeof( pre ) );
1614 HASH_Update( &HASHcontext,
1615 syntax->ssyn_oid, slen );
1616 HASH_Update( &HASHcontext,
1617 mr->smr_oid, mlen );
1618 HASH_Update( &HASHcontext,
1619 &value->bv_val[value->bv_len-klen], klen );
1620 HASH_Final( HASHdigest, &HASHcontext );
1622 ber_dupbv( &keys[nkeys++], &digest );
1626 keys[nkeys].bv_val = NULL;
1632 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1633 if ( sa->sa_any ) bvarray_free( sa->sa_any );
1634 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1637 return LDAP_SUCCESS;
1646 struct berval *value,
1647 void *assertedValue )
1649 *matchp = UTF8normcmp( value->bv_val,
1650 ((struct berval *) assertedValue)->bv_val,
1652 return LDAP_SUCCESS;
1658 struct berval *val )
1662 if( val->bv_len == 0 ) {
1663 /* disallow empty strings */
1664 return LDAP_INVALID_SYNTAX;
1667 if( OID_LEADCHAR(val->bv_val[0]) ) {
1669 for(i=1; i < val->bv_len; i++) {
1670 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1671 if( dot++ ) return 1;
1672 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1675 return LDAP_INVALID_SYNTAX;
1679 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1681 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1682 for(i=1; i < val->bv_len; i++) {
1683 if( !DESC_CHAR(val->bv_val[i] ) ) {
1684 return LDAP_INVALID_SYNTAX;
1688 return LDAP_SUCCESS;
1691 return LDAP_INVALID_SYNTAX;
1700 struct berval *value,
1701 void *assertedValue )
1704 int vsign=0, avsign=0;
1705 struct berval *asserted;
1706 ber_len_t vlen, avlen;
1709 /* Start off pessimistic */
1712 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1714 vlen = value->bv_len;
1716 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1717 /* empty -- skip spaces */
1719 else if ( *v == '+' ) {
1722 else if ( *v == '-' ) {
1725 else if ( ASCII_DIGIT(*v) ) {
1726 if ( vsign == 0 ) vsign = 1;
1734 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1736 asserted = (struct berval *) assertedValue;
1737 av = asserted->bv_val;
1738 avlen = asserted->bv_len;
1740 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1741 /* empty -- skip spaces */
1743 else if ( *av == '+' ) {
1746 else if ( *av == '-' ) {
1749 else if ( ASCII_DIGIT(*av) ) {
1750 if ( avsign == 0 ) avsign = 1;
1758 /* The two ?sign vars are now one of :
1759 -2 negative non-zero number
1761 0 0 collapse these three to 0
1763 +2 positive non-zero number
1765 if ( abs( vsign ) == 1 ) vsign = 0;
1766 if ( abs( avsign ) == 1 ) avsign = 0;
1768 if( vsign != avsign ) return LDAP_SUCCESS;
1770 /* Check the significant digits */
1771 while( vlen && avlen ) {
1772 if( *v != *av ) break;
1779 /* If all digits compared equal, the numbers are equal */
1780 if(( vlen == 0 ) && ( avlen == 0 )) {
1783 return LDAP_SUCCESS;
1789 struct berval *val )
1793 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1795 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1796 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1797 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1798 return LDAP_INVALID_SYNTAX;
1801 for( i=1; i < val->bv_len; i++ ) {
1802 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1805 return LDAP_SUCCESS;
1812 struct berval *normalized )
1822 /* Ignore leading spaces */
1823 while ( len && ( *p == ' ' )) {
1830 negative = ( *p == '-' );
1831 if(( *p == '-' ) || ( *p == '+' )) {
1837 /* Ignore leading zeros */
1838 while ( len && ( *p == '0' )) {
1843 /* If there are no non-zero digits left, the number is zero, otherwise
1844 allocate space for the number and copy it into the buffer */
1846 normalized->bv_val = ch_strdup("0");
1847 normalized->bv_len = 1;
1850 normalized->bv_len = len+negative;
1851 normalized->bv_val = ch_malloc( normalized->bv_len );
1853 normalized->bv_val[0] = '-';
1855 memcpy( normalized->bv_val + negative, p, len );
1858 return LDAP_SUCCESS;
1861 /* Index generation function */
1862 static int integerIndexer(
1867 struct berval *prefix,
1868 struct berval **values,
1869 struct berval **keysp )
1872 struct berval *keys;
1874 /* we should have at least one value at this point */
1875 assert( values != NULL && values[0] != NULL );
1877 for( i=0; values[i] != NULL; i++ ) {
1878 /* empty -- just count them */
1881 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1883 for( i=0; values[i] != NULL; i++ ) {
1884 integerNormalize( syntax, values[i], &keys[i] );
1887 keys[i].bv_val = NULL;
1889 return LDAP_SUCCESS;
1892 /* Index generation function */
1893 static int integerFilter(
1898 struct berval *prefix,
1900 struct berval **keysp )
1902 struct berval *keys;
1904 keys = ch_malloc( sizeof( struct berval ) * 2 );
1905 integerNormalize( syntax, assertValue, &keys[0] );
1906 keys[1].bv_val = NULL;
1909 return LDAP_SUCCESS;
1914 countryStringValidate(
1916 struct berval *val )
1918 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1920 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1921 return LDAP_INVALID_SYNTAX;
1923 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1924 return LDAP_INVALID_SYNTAX;
1927 return LDAP_SUCCESS;
1931 printableStringValidate(
1933 struct berval *val )
1937 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1939 for(i=0; i < val->bv_len; i++) {
1940 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1941 return LDAP_INVALID_SYNTAX;
1945 return LDAP_SUCCESS;
1949 printablesStringValidate(
1951 struct berval *val )
1955 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1957 for(i=0; i < val->bv_len; i++) {
1958 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1959 return LDAP_INVALID_SYNTAX;
1963 return LDAP_SUCCESS;
1969 struct berval *val )
1973 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1975 for(i=0; i < val->bv_len; i++) {
1976 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1979 return LDAP_SUCCESS;
1986 struct berval *normalized )
1992 /* Ignore initial whitespace */
1993 while ( ASCII_SPACE( *p ) ) {
1998 return LDAP_INVALID_SYNTAX;
2001 normalized->bv_val = ch_strdup( p );
2002 p = q = normalized->bv_val;
2005 if ( ASCII_SPACE( *p ) ) {
2008 /* Ignore the extra whitespace */
2009 while ( ASCII_SPACE( *p ) ) {
2017 assert( normalized->bv_val < p );
2020 /* cannot start with a space */
2021 assert( !ASCII_SPACE(*normalized->bv_val) );
2024 * If the string ended in space, backup the pointer one
2025 * position. One is enough because the above loop collapsed
2026 * all whitespace to a single space.
2029 if ( ASCII_SPACE( q[-1] ) ) {
2033 /* cannot end with a space */
2034 assert( !ASCII_SPACE( q[-1] ) );
2036 /* null terminate */
2039 normalized->bv_len = q - normalized->bv_val;
2041 return LDAP_SUCCESS;
2050 struct berval *value,
2051 void *assertedValue )
2053 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2056 match = strncmp( value->bv_val,
2057 ((struct berval *) assertedValue)->bv_val,
2062 return LDAP_SUCCESS;
2066 caseExactIA5SubstringsMatch(
2071 struct berval *value,
2072 void *assertedValue )
2075 SubstringsAssertion *sub = assertedValue;
2076 struct berval left = *value;
2080 /* Add up asserted input length */
2081 if( sub->sa_initial.bv_val ) {
2082 inlen += sub->sa_initial.bv_len;
2085 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2086 inlen += sub->sa_any[i].bv_len;
2089 if( sub->sa_final.bv_val ) {
2090 inlen += sub->sa_final.bv_len;
2093 if( sub->sa_initial.bv_val ) {
2094 if( inlen > left.bv_len ) {
2099 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2100 sub->sa_initial.bv_len );
2106 left.bv_val += sub->sa_initial.bv_len;
2107 left.bv_len -= sub->sa_initial.bv_len;
2108 inlen -= sub->sa_initial.bv_len;
2111 if( sub->sa_final.bv_val ) {
2112 if( inlen > left.bv_len ) {
2117 match = strncmp( sub->sa_final.bv_val,
2118 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2119 sub->sa_final.bv_len );
2125 left.bv_len -= sub->sa_final.bv_len;
2126 inlen -= sub->sa_final.bv_len;
2130 for(i=0; sub->sa_any[i].bv_val; i++) {
2135 if( inlen > left.bv_len ) {
2136 /* not enough length */
2141 if( sub->sa_any[i].bv_len == 0 ) {
2145 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2152 idx = p - left.bv_val;
2153 assert( idx < left.bv_len );
2155 if( idx >= left.bv_len ) {
2156 /* this shouldn't happen */
2163 if( sub->sa_any[i].bv_len > left.bv_len ) {
2164 /* not enough left */
2169 match = strncmp( left.bv_val,
2170 sub->sa_any[i].bv_val,
2171 sub->sa_any[i].bv_len );
2179 left.bv_val += sub->sa_any[i].bv_len;
2180 left.bv_len -= sub->sa_any[i].bv_len;
2181 inlen -= sub->sa_any[i].bv_len;
2187 return LDAP_SUCCESS;
2190 /* Index generation function */
2191 static int caseExactIA5Indexer(
2196 struct berval *prefix,
2197 struct berval **values,
2198 struct berval **keysp )
2202 struct berval *keys;
2203 HASH_CONTEXT HASHcontext;
2204 unsigned char HASHdigest[HASH_BYTES];
2205 struct berval digest;
2206 digest.bv_val = HASHdigest;
2207 digest.bv_len = sizeof(HASHdigest);
2209 for( i=0; values[i] != NULL; i++ ) {
2210 /* empty - just count them */
2213 /* we should have at least one value at this point */
2216 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2218 slen = syntax->ssyn_oidlen;
2219 mlen = mr->smr_oidlen;
2221 for( i=0; values[i] != NULL; i++ ) {
2222 struct berval *value = values[i];
2224 HASH_Init( &HASHcontext );
2225 if( prefix != NULL && prefix->bv_len > 0 ) {
2226 HASH_Update( &HASHcontext,
2227 prefix->bv_val, prefix->bv_len );
2229 HASH_Update( &HASHcontext,
2230 syntax->ssyn_oid, slen );
2231 HASH_Update( &HASHcontext,
2232 mr->smr_oid, mlen );
2233 HASH_Update( &HASHcontext,
2234 value->bv_val, value->bv_len );
2235 HASH_Final( HASHdigest, &HASHcontext );
2237 ber_dupbv( &keys[i], &digest );
2240 keys[i].bv_val = NULL;
2242 return LDAP_SUCCESS;
2245 /* Index generation function */
2246 static int caseExactIA5Filter(
2251 struct berval *prefix,
2253 struct berval **keysp )
2256 struct berval *keys;
2257 HASH_CONTEXT HASHcontext;
2258 unsigned char HASHdigest[HASH_BYTES];
2259 struct berval *value;
2260 struct berval digest;
2261 digest.bv_val = HASHdigest;
2262 digest.bv_len = sizeof(HASHdigest);
2264 slen = syntax->ssyn_oidlen;
2265 mlen = mr->smr_oidlen;
2267 value = (struct berval *) assertValue;
2269 keys = ch_malloc( sizeof( struct berval ) * 2 );
2271 HASH_Init( &HASHcontext );
2272 if( prefix != NULL && prefix->bv_len > 0 ) {
2273 HASH_Update( &HASHcontext,
2274 prefix->bv_val, prefix->bv_len );
2276 HASH_Update( &HASHcontext,
2277 syntax->ssyn_oid, slen );
2278 HASH_Update( &HASHcontext,
2279 mr->smr_oid, mlen );
2280 HASH_Update( &HASHcontext,
2281 value->bv_val, value->bv_len );
2282 HASH_Final( HASHdigest, &HASHcontext );
2284 ber_dupbv( &keys[0], &digest );
2285 keys[1].bv_val = NULL;
2288 return LDAP_SUCCESS;
2291 /* Substrings Index generation function */
2292 static int caseExactIA5SubstringsIndexer(
2297 struct berval *prefix,
2298 struct berval **values,
2299 struct berval **keysp )
2303 struct berval *keys;
2304 HASH_CONTEXT HASHcontext;
2305 unsigned char HASHdigest[HASH_BYTES];
2306 struct berval digest;
2307 digest.bv_val = HASHdigest;
2308 digest.bv_len = sizeof(HASHdigest);
2310 /* we should have at least one value at this point */
2311 assert( values != NULL && values[0] != NULL );
2314 for( i=0; values[i] != NULL; i++ ) {
2315 /* count number of indices to generate */
2316 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2320 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2321 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2322 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2323 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2325 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2329 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2330 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2331 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2335 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2336 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2337 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2338 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2340 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2346 /* no keys to generate */
2348 return LDAP_SUCCESS;
2351 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2353 slen = syntax->ssyn_oidlen;
2354 mlen = mr->smr_oidlen;
2357 for( i=0; values[i] != NULL; i++ ) {
2359 struct berval *value;
2362 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2364 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2365 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2367 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2368 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2370 for( j=0; j<max; j++ ) {
2371 HASH_Init( &HASHcontext );
2372 if( prefix != NULL && prefix->bv_len > 0 ) {
2373 HASH_Update( &HASHcontext,
2374 prefix->bv_val, prefix->bv_len );
2377 HASH_Update( &HASHcontext,
2378 &pre, sizeof( pre ) );
2379 HASH_Update( &HASHcontext,
2380 syntax->ssyn_oid, slen );
2381 HASH_Update( &HASHcontext,
2382 mr->smr_oid, mlen );
2383 HASH_Update( &HASHcontext,
2385 SLAP_INDEX_SUBSTR_MAXLEN );
2386 HASH_Final( HASHdigest, &HASHcontext );
2388 ber_dupbv( &keys[nkeys++], &digest );
2392 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2393 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2395 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2398 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2399 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2400 HASH_Init( &HASHcontext );
2401 if( prefix != NULL && prefix->bv_len > 0 ) {
2402 HASH_Update( &HASHcontext,
2403 prefix->bv_val, prefix->bv_len );
2405 HASH_Update( &HASHcontext,
2406 &pre, sizeof( pre ) );
2407 HASH_Update( &HASHcontext,
2408 syntax->ssyn_oid, slen );
2409 HASH_Update( &HASHcontext,
2410 mr->smr_oid, mlen );
2411 HASH_Update( &HASHcontext,
2413 HASH_Final( HASHdigest, &HASHcontext );
2415 ber_dupbv( &keys[nkeys++], &digest );
2418 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2419 pre = SLAP_INDEX_SUBSTR_FINAL_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,
2432 &value->bv_val[value->bv_len-j], j );
2433 HASH_Final( HASHdigest, &HASHcontext );
2435 ber_dupbv( &keys[nkeys++], &digest );
2442 keys[nkeys].bv_val = NULL;
2449 return LDAP_SUCCESS;
2452 static int caseExactIA5SubstringsFilter(
2457 struct berval *prefix,
2459 struct berval **keysp )
2461 SubstringsAssertion *sa = assertValue;
2463 ber_len_t nkeys = 0;
2464 size_t slen, mlen, klen;
2465 struct berval *keys;
2466 HASH_CONTEXT HASHcontext;
2467 unsigned char HASHdigest[HASH_BYTES];
2468 struct berval *value;
2469 struct berval digest;
2471 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2472 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2477 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2479 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2480 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2481 /* don't bother accounting for stepping */
2482 nkeys += sa->sa_any[i].bv_len -
2483 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2488 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2489 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2496 return LDAP_SUCCESS;
2499 digest.bv_val = HASHdigest;
2500 digest.bv_len = sizeof(HASHdigest);
2502 slen = syntax->ssyn_oidlen;
2503 mlen = mr->smr_oidlen;
2505 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2508 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2509 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2511 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2512 value = &sa->sa_initial;
2514 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2515 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2517 HASH_Init( &HASHcontext );
2518 if( prefix != NULL && prefix->bv_len > 0 ) {
2519 HASH_Update( &HASHcontext,
2520 prefix->bv_val, prefix->bv_len );
2522 HASH_Update( &HASHcontext,
2523 &pre, sizeof( pre ) );
2524 HASH_Update( &HASHcontext,
2525 syntax->ssyn_oid, slen );
2526 HASH_Update( &HASHcontext,
2527 mr->smr_oid, mlen );
2528 HASH_Update( &HASHcontext,
2529 value->bv_val, klen );
2530 HASH_Final( HASHdigest, &HASHcontext );
2532 ber_dupbv( &keys[nkeys++], &digest );
2535 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2537 pre = SLAP_INDEX_SUBSTR_PREFIX;
2538 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2540 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2541 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2545 value = &sa->sa_any[i];
2548 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2549 j += SLAP_INDEX_SUBSTR_STEP )
2551 HASH_Init( &HASHcontext );
2552 if( prefix != NULL && prefix->bv_len > 0 ) {
2553 HASH_Update( &HASHcontext,
2554 prefix->bv_val, prefix->bv_len );
2556 HASH_Update( &HASHcontext,
2557 &pre, sizeof( pre ) );
2558 HASH_Update( &HASHcontext,
2559 syntax->ssyn_oid, slen );
2560 HASH_Update( &HASHcontext,
2561 mr->smr_oid, mlen );
2562 HASH_Update( &HASHcontext,
2563 &value->bv_val[j], klen );
2564 HASH_Final( HASHdigest, &HASHcontext );
2566 ber_dupbv( &keys[nkeys++], &digest );
2571 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2572 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2574 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2575 value = &sa->sa_final;
2577 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2578 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2580 HASH_Init( &HASHcontext );
2581 if( prefix != NULL && prefix->bv_len > 0 ) {
2582 HASH_Update( &HASHcontext,
2583 prefix->bv_val, prefix->bv_len );
2585 HASH_Update( &HASHcontext,
2586 &pre, sizeof( pre ) );
2587 HASH_Update( &HASHcontext,
2588 syntax->ssyn_oid, slen );
2589 HASH_Update( &HASHcontext,
2590 mr->smr_oid, mlen );
2591 HASH_Update( &HASHcontext,
2592 &value->bv_val[value->bv_len-klen], klen );
2593 HASH_Final( HASHdigest, &HASHcontext );
2595 ber_dupbv( &keys[nkeys++], &digest );
2599 keys[nkeys].bv_val = NULL;
2606 return LDAP_SUCCESS;
2615 struct berval *value,
2616 void *assertedValue )
2618 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2620 if( match == 0 && value->bv_len ) {
2621 match = strncasecmp( value->bv_val,
2622 ((struct berval *) assertedValue)->bv_val,
2627 return LDAP_SUCCESS;
2631 caseIgnoreIA5SubstringsMatch(
2636 struct berval *value,
2637 void *assertedValue )
2640 SubstringsAssertion *sub = assertedValue;
2641 struct berval left = *value;
2645 /* Add up asserted input length */
2646 if( sub->sa_initial.bv_val ) {
2647 inlen += sub->sa_initial.bv_len;
2650 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2651 inlen += sub->sa_any[i].bv_len;
2654 if( sub->sa_final.bv_val ) {
2655 inlen += sub->sa_final.bv_len;
2658 if( sub->sa_initial.bv_val ) {
2659 if( inlen > left.bv_len ) {
2664 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2665 sub->sa_initial.bv_len );
2671 left.bv_val += sub->sa_initial.bv_len;
2672 left.bv_len -= sub->sa_initial.bv_len;
2673 inlen -= sub->sa_initial.bv_len;
2676 if( sub->sa_final.bv_val ) {
2677 if( inlen > left.bv_len ) {
2682 match = strncasecmp( sub->sa_final.bv_val,
2683 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2684 sub->sa_final.bv_len );
2690 left.bv_len -= sub->sa_final.bv_len;
2691 inlen -= sub->sa_final.bv_len;
2695 for(i=0; sub->sa_any[i].bv_val; i++) {
2700 if( inlen > left.bv_len ) {
2701 /* not enough length */
2706 if( sub->sa_any[i].bv_len == 0 ) {
2710 p = strcasechr( left.bv_val, *sub->sa_any[i].bv_val );
2717 idx = p - left.bv_val;
2718 assert( idx < left.bv_len );
2720 if( idx >= left.bv_len ) {
2721 /* this shouldn't happen */
2728 if( sub->sa_any[i].bv_len > left.bv_len ) {
2729 /* not enough left */
2734 match = strncasecmp( left.bv_val,
2735 sub->sa_any[i].bv_val,
2736 sub->sa_any[i].bv_len );
2745 left.bv_val += sub->sa_any[i].bv_len;
2746 left.bv_len -= sub->sa_any[i].bv_len;
2747 inlen -= sub->sa_any[i].bv_len;
2753 return LDAP_SUCCESS;
2756 /* Index generation function */
2757 static int caseIgnoreIA5Indexer(
2762 struct berval *prefix,
2763 struct berval **values,
2764 struct berval **keysp )
2768 struct berval *keys;
2769 HASH_CONTEXT HASHcontext;
2770 unsigned char HASHdigest[HASH_BYTES];
2771 struct berval digest;
2772 digest.bv_val = HASHdigest;
2773 digest.bv_len = sizeof(HASHdigest);
2775 /* we should have at least one value at this point */
2776 assert( values != NULL && values[0] != NULL );
2778 for( i=0; values[i] != NULL; i++ ) {
2779 /* just count them */
2782 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2784 slen = syntax->ssyn_oidlen;
2785 mlen = mr->smr_oidlen;
2787 for( i=0; values[i] != NULL; i++ ) {
2788 struct berval value;
2789 ber_dupbv( &value, values[i] );
2790 ldap_pvt_str2upper( value.bv_val );
2792 HASH_Init( &HASHcontext );
2793 if( prefix != NULL && prefix->bv_len > 0 ) {
2794 HASH_Update( &HASHcontext,
2795 prefix->bv_val, prefix->bv_len );
2797 HASH_Update( &HASHcontext,
2798 syntax->ssyn_oid, slen );
2799 HASH_Update( &HASHcontext,
2800 mr->smr_oid, mlen );
2801 HASH_Update( &HASHcontext,
2802 value.bv_val, value.bv_len );
2803 HASH_Final( HASHdigest, &HASHcontext );
2805 free( value.bv_val );
2807 ber_dupbv( &keys[i], &digest );
2810 keys[i].bv_val = NULL;
2812 return LDAP_SUCCESS;
2815 /* Index generation function */
2816 static int caseIgnoreIA5Filter(
2821 struct berval *prefix,
2823 struct berval **keysp )
2826 struct berval *keys;
2827 HASH_CONTEXT HASHcontext;
2828 unsigned char HASHdigest[HASH_BYTES];
2829 struct berval value;
2830 struct berval digest;
2831 digest.bv_val = HASHdigest;
2832 digest.bv_len = sizeof(HASHdigest);
2834 slen = syntax->ssyn_oidlen;
2835 mlen = mr->smr_oidlen;
2837 ber_dupbv( &value, (struct berval *) assertValue );
2838 ldap_pvt_str2upper( value.bv_val );
2840 keys = ch_malloc( sizeof( struct berval ) * 2 );
2842 HASH_Init( &HASHcontext );
2843 if( prefix != NULL && prefix->bv_len > 0 ) {
2844 HASH_Update( &HASHcontext,
2845 prefix->bv_val, prefix->bv_len );
2847 HASH_Update( &HASHcontext,
2848 syntax->ssyn_oid, slen );
2849 HASH_Update( &HASHcontext,
2850 mr->smr_oid, mlen );
2851 HASH_Update( &HASHcontext,
2852 value.bv_val, value.bv_len );
2853 HASH_Final( HASHdigest, &HASHcontext );
2855 ber_dupbv( &keys[0], &digest );
2856 keys[1].bv_val = NULL;
2858 free( value.bv_val );
2862 return LDAP_SUCCESS;
2865 /* Substrings Index generation function */
2866 static int caseIgnoreIA5SubstringsIndexer(
2871 struct berval *prefix,
2872 struct berval **values,
2873 struct berval **keysp )
2877 struct berval *keys;
2878 HASH_CONTEXT HASHcontext;
2879 unsigned char HASHdigest[HASH_BYTES];
2880 struct berval digest;
2881 digest.bv_val = HASHdigest;
2882 digest.bv_len = sizeof(HASHdigest);
2884 /* we should have at least one value at this point */
2885 assert( values != NULL && values[0] != NULL );
2888 for( i=0; values[i] != NULL; i++ ) {
2889 /* count number of indices to generate */
2890 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2894 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2895 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2896 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2897 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2899 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2903 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2904 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2905 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2909 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2910 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2911 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2912 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2914 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2920 /* no keys to generate */
2922 return LDAP_SUCCESS;
2925 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2927 slen = syntax->ssyn_oidlen;
2928 mlen = mr->smr_oidlen;
2931 for( i=0; values[i] != NULL; i++ ) {
2933 struct berval value;
2935 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2937 ber_dupbv( &value, values[i] );
2938 ldap_pvt_str2upper( value.bv_val );
2940 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2941 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2943 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2944 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2946 for( j=0; j<max; j++ ) {
2947 HASH_Init( &HASHcontext );
2948 if( prefix != NULL && prefix->bv_len > 0 ) {
2949 HASH_Update( &HASHcontext,
2950 prefix->bv_val, prefix->bv_len );
2953 HASH_Update( &HASHcontext,
2954 &pre, sizeof( pre ) );
2955 HASH_Update( &HASHcontext,
2956 syntax->ssyn_oid, slen );
2957 HASH_Update( &HASHcontext,
2958 mr->smr_oid, mlen );
2959 HASH_Update( &HASHcontext,
2961 SLAP_INDEX_SUBSTR_MAXLEN );
2962 HASH_Final( HASHdigest, &HASHcontext );
2964 ber_dupbv( &keys[nkeys++], &digest );
2968 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2969 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2971 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2974 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2975 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2976 HASH_Init( &HASHcontext );
2977 if( prefix != NULL && prefix->bv_len > 0 ) {
2978 HASH_Update( &HASHcontext,
2979 prefix->bv_val, prefix->bv_len );
2981 HASH_Update( &HASHcontext,
2982 &pre, sizeof( pre ) );
2983 HASH_Update( &HASHcontext,
2984 syntax->ssyn_oid, slen );
2985 HASH_Update( &HASHcontext,
2986 mr->smr_oid, mlen );
2987 HASH_Update( &HASHcontext,
2989 HASH_Final( HASHdigest, &HASHcontext );
2991 ber_dupbv( &keys[nkeys++], &digest );
2994 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2995 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2996 HASH_Init( &HASHcontext );
2997 if( prefix != NULL && prefix->bv_len > 0 ) {
2998 HASH_Update( &HASHcontext,
2999 prefix->bv_val, prefix->bv_len );
3001 HASH_Update( &HASHcontext,
3002 &pre, sizeof( pre ) );
3003 HASH_Update( &HASHcontext,
3004 syntax->ssyn_oid, slen );
3005 HASH_Update( &HASHcontext,
3006 mr->smr_oid, mlen );
3007 HASH_Update( &HASHcontext,
3008 &value.bv_val[value.bv_len-j], j );
3009 HASH_Final( HASHdigest, &HASHcontext );
3011 ber_dupbv( &keys[nkeys++], &digest );
3016 free( value.bv_val );
3020 keys[nkeys].bv_val = NULL;
3027 return LDAP_SUCCESS;
3030 static int caseIgnoreIA5SubstringsFilter(
3035 struct berval *prefix,
3037 struct berval **keysp )
3039 SubstringsAssertion *sa = assertValue;
3041 ber_len_t nkeys = 0;
3042 size_t slen, mlen, klen;
3043 struct berval *keys;
3044 HASH_CONTEXT HASHcontext;
3045 unsigned char HASHdigest[HASH_BYTES];
3046 struct berval value;
3047 struct berval digest;
3049 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3050 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3055 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3057 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3058 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3059 /* don't bother accounting for stepping */
3060 nkeys += sa->sa_any[i].bv_len -
3061 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3066 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3067 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3074 return LDAP_SUCCESS;
3077 digest.bv_val = HASHdigest;
3078 digest.bv_len = sizeof(HASHdigest);
3080 slen = syntax->ssyn_oidlen;
3081 mlen = mr->smr_oidlen;
3083 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3086 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3087 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3089 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3090 ber_dupbv( &value, &sa->sa_initial );
3091 ldap_pvt_str2upper( value.bv_val );
3093 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3094 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3096 HASH_Init( &HASHcontext );
3097 if( prefix != NULL && prefix->bv_len > 0 ) {
3098 HASH_Update( &HASHcontext,
3099 prefix->bv_val, prefix->bv_len );
3101 HASH_Update( &HASHcontext,
3102 &pre, sizeof( pre ) );
3103 HASH_Update( &HASHcontext,
3104 syntax->ssyn_oid, slen );
3105 HASH_Update( &HASHcontext,
3106 mr->smr_oid, mlen );
3107 HASH_Update( &HASHcontext,
3108 value.bv_val, klen );
3109 HASH_Final( HASHdigest, &HASHcontext );
3111 free( value.bv_val );
3112 ber_dupbv( &keys[nkeys++], &digest );
3115 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3117 pre = SLAP_INDEX_SUBSTR_PREFIX;
3118 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3120 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3121 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3125 ber_dupbv( &value, &sa->sa_any[i] );
3126 ldap_pvt_str2upper( value.bv_val );
3129 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3130 j += SLAP_INDEX_SUBSTR_STEP )
3132 HASH_Init( &HASHcontext );
3133 if( prefix != NULL && prefix->bv_len > 0 ) {
3134 HASH_Update( &HASHcontext,
3135 prefix->bv_val, prefix->bv_len );
3137 HASH_Update( &HASHcontext,
3138 &pre, sizeof( pre ) );
3139 HASH_Update( &HASHcontext,
3140 syntax->ssyn_oid, slen );
3141 HASH_Update( &HASHcontext,
3142 mr->smr_oid, mlen );
3143 HASH_Update( &HASHcontext,
3144 &value.bv_val[j], klen );
3145 HASH_Final( HASHdigest, &HASHcontext );
3147 ber_dupbv( &keys[nkeys++], &digest );
3150 free( value.bv_val );
3154 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3155 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3157 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3158 ber_dupbv( &value, &sa->sa_final );
3159 ldap_pvt_str2upper( value.bv_val );
3161 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3162 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3164 HASH_Init( &HASHcontext );
3165 if( prefix != NULL && prefix->bv_len > 0 ) {
3166 HASH_Update( &HASHcontext,
3167 prefix->bv_val, prefix->bv_len );
3169 HASH_Update( &HASHcontext,
3170 &pre, sizeof( pre ) );
3171 HASH_Update( &HASHcontext,
3172 syntax->ssyn_oid, slen );
3173 HASH_Update( &HASHcontext,
3174 mr->smr_oid, mlen );
3175 HASH_Update( &HASHcontext,
3176 &value.bv_val[value.bv_len-klen], klen );
3177 HASH_Final( HASHdigest, &HASHcontext );
3179 free( value.bv_val );
3180 ber_dupbv( &keys[nkeys++], &digest );
3184 keys[nkeys].bv_val = NULL;
3191 return LDAP_SUCCESS;
3195 numericStringValidate(
3201 for(i=0; i < in->bv_len; i++) {
3202 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3203 return LDAP_INVALID_SYNTAX;
3207 return LDAP_SUCCESS;
3211 numericStringNormalize(
3214 struct berval *normalized )
3216 /* removal all spaces */
3219 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3222 q = normalized->bv_val;
3225 if ( ASCII_SPACE( *p ) ) {
3226 /* Ignore whitespace */
3233 /* we should have copied no more then is in val */
3234 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3236 /* null terminate */
3239 normalized->bv_len = q - normalized->bv_val;
3241 return LDAP_SUCCESS;
3245 objectIdentifierFirstComponentMatch(
3250 struct berval *value,
3251 void *assertedValue )
3253 int rc = LDAP_SUCCESS;
3255 struct berval *asserted = (struct berval *) assertedValue;
3259 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3260 return LDAP_INVALID_SYNTAX;
3263 /* trim leading white space */
3264 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3268 /* grab next word */
3269 oid.bv_val = &value->bv_val[i];
3270 oid.bv_len = value->bv_len - i;
3271 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3276 /* insert attributeTypes, objectclass check here */
3277 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3278 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3281 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3282 MatchingRule *asserted_mr = mr_bvfind( asserted );
3283 MatchingRule *stored_mr = mr_bvfind( &oid );
3285 if( asserted_mr == NULL ) {
3286 rc = SLAPD_COMPARE_UNDEFINED;
3288 match = asserted_mr != stored_mr;
3291 } else if ( !strcmp( syntax->ssyn_oid,
3292 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3294 AttributeType *asserted_at = at_bvfind( asserted );
3295 AttributeType *stored_at = at_bvfind( &oid );
3297 if( asserted_at == NULL ) {
3298 rc = SLAPD_COMPARE_UNDEFINED;
3300 match = asserted_at != stored_at;
3303 } else if ( !strcmp( syntax->ssyn_oid,
3304 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3306 ObjectClass *asserted_oc = oc_bvfind( asserted );
3307 ObjectClass *stored_oc = oc_bvfind( &oid );
3309 if( asserted_oc == NULL ) {
3310 rc = SLAPD_COMPARE_UNDEFINED;
3312 match = asserted_oc != stored_oc;
3318 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3319 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3320 match, value->bv_val, asserted->bv_val ));
3322 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3323 "%d\n\t\"%s\"\n\t\"%s\"\n",
3324 match, value->bv_val, asserted->bv_val );
3328 if( rc == LDAP_SUCCESS ) *matchp = match;
3338 struct berval *value,
3339 void *assertedValue )
3341 long lValue, lAssertedValue;
3343 /* safe to assume integers are NUL terminated? */
3344 lValue = strtoul(value->bv_val, NULL, 10);
3345 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3346 return LDAP_CONSTRAINT_VIOLATION;
3348 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3349 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3350 return LDAP_CONSTRAINT_VIOLATION;
3352 *matchp = (lValue & lAssertedValue);
3353 return LDAP_SUCCESS;
3362 struct berval *value,
3363 void *assertedValue )
3365 long lValue, lAssertedValue;
3367 /* safe to assume integers are NUL terminated? */
3368 lValue = strtoul(value->bv_val, NULL, 10);
3369 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3370 return LDAP_CONSTRAINT_VIOLATION;
3372 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3373 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3374 return LDAP_CONSTRAINT_VIOLATION;
3376 *matchp = (lValue | lAssertedValue);
3377 return LDAP_SUCCESS;
3381 #include <openssl/x509.h>
3382 #include <openssl/err.h>
3383 char digit[] = "0123456789";
3386 * Next function returns a string representation of a ASN1_INTEGER.
3387 * It works for unlimited lengths.
3390 static struct berval *
3391 asn1_integer2str(ASN1_INTEGER *a)
3396 /* We work backwards, make it fill from the end of buf */
3397 p = buf + sizeof(buf) - 1;
3400 if ( a == NULL || a->length == 0 ) {
3408 /* We want to preserve the original */
3409 copy = ch_malloc(n*sizeof(unsigned int));
3410 for (i = 0; i<n; i++) {
3411 copy[i] = a->data[i];
3415 * base indicates the index of the most significant
3416 * byte that might be nonzero. When it goes off the
3417 * end, we now there is nothing left to do.
3423 for (i = base; i<n; i++ ) {
3424 copy[i] += carry*256;
3425 carry = copy[i] % 10;
3430 * Way too large, we need to leave
3431 * room for sign if negative
3436 *--p = digit[carry];
3437 if (copy[base] == 0)
3443 if ( a->type == V_ASN1_NEG_INTEGER ) {
3447 return ber_bvstrdup(p);
3450 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3451 static struct berval *
3452 dn_openssl2ldap(X509_NAME *name)
3454 char issuer_dn[1024];
3457 bio = BIO_new(BIO_s_mem());
3460 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3461 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3462 ERR_error_string(ERR_get_error(),NULL)));
3464 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3465 "error creating BIO: %s\n",
3466 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3470 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3472 BIO_gets(bio, issuer_dn, 1024);
3475 return ber_bvstrdup(issuer_dn);
3479 * Given a certificate in DER format, extract the corresponding
3480 * assertion value for certificateExactMatch
3483 certificateExactConvert(
3485 struct berval * out )
3488 unsigned char *p = in->bv_val;
3489 struct berval *serial;
3490 struct berval *issuer_dn;
3491 struct berval *bv_tmp;
3493 xcert = d2i_X509(NULL, &p, in->bv_len);
3496 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3497 "certificateExactConvert: error parsing cert: %s\n",
3498 ERR_error_string(ERR_get_error(),NULL)));
3500 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3501 "error parsing cert: %s\n",
3502 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3504 return LDAP_INVALID_SYNTAX;
3507 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3510 return LDAP_INVALID_SYNTAX;
3512 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3516 return LDAP_INVALID_SYNTAX;
3518 /* Actually, dn_openssl2ldap returns in a normalized format, but
3519 it is different from our normalized format */
3521 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3525 return LDAP_INVALID_SYNTAX;
3531 out->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3532 out->bv_val = ch_malloc(out->bv_len);
3534 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3535 p += serial->bv_len;
3536 AC_MEMCPY(p, " $ ", 3);
3538 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3539 p += issuer_dn->bv_len;
3543 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3544 "certificateExactConvert: \n %s\n",
3547 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3549 out->bv_val, NULL, NULL );
3553 ber_bvfree(issuer_dn);
3555 return LDAP_SUCCESS;
3559 serial_and_issuer_parse(
3560 struct berval *assertion,
3561 struct berval **serial,
3562 struct berval **issuer_dn
3570 begin = assertion->bv_val;
3571 end = assertion->bv_val+assertion->bv_len-1;
3572 for (p=begin; p<=end && *p != '$'; p++)
3575 return LDAP_INVALID_SYNTAX;
3577 /* p now points at the $ sign, now use begin and end to delimit the
3579 while (ASCII_SPACE(*begin))
3582 while (ASCII_SPACE(*end))
3585 bv.bv_len = end-begin+1;
3587 *serial = ber_bvdup(&bv);
3589 /* now extract the issuer, remember p was at the dollar sign */
3591 end = assertion->bv_val+assertion->bv_len-1;
3592 while (ASCII_SPACE(*begin))
3594 /* should we trim spaces at the end too? is it safe always? */
3596 bv.bv_len = end-begin+1;
3598 dnNormalize( NULL, &bv, issuer_dn );
3600 return LDAP_SUCCESS;
3604 certificateExactMatch(
3609 struct berval *value,
3610 void *assertedValue )
3613 unsigned char *p = value->bv_val;
3614 struct berval *serial;
3615 struct berval *issuer_dn;
3616 struct berval *asserted_serial;
3617 struct berval *asserted_issuer_dn;
3620 xcert = d2i_X509(NULL, &p, value->bv_len);
3623 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3624 "certificateExactMatch: error parsing cert: %s\n",
3625 ERR_error_string(ERR_get_error(),NULL)));
3627 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3628 "error parsing cert: %s\n",
3629 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3631 return LDAP_INVALID_SYNTAX;
3634 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3635 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3639 serial_and_issuer_parse(assertedValue,
3641 &asserted_issuer_dn);
3646 slap_schema.si_syn_integer,
3647 slap_schema.si_mr_integerMatch,
3650 if ( ret == LDAP_SUCCESS ) {
3651 if ( *matchp == 0 ) {
3652 /* We need to normalize everything for dnMatch */
3656 slap_schema.si_syn_distinguishedName,
3657 slap_schema.si_mr_distinguishedNameMatch,
3659 asserted_issuer_dn);
3664 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3665 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3666 *matchp, serial->bv_val, issuer_dn->bv_val,
3667 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3669 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3670 "%d\n\t\"%s $ %s\"\n",
3671 *matchp, serial->bv_val, issuer_dn->bv_val );
3672 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3673 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3678 ber_bvfree(issuer_dn);
3679 ber_bvfree(asserted_serial);
3680 ber_bvfree(asserted_issuer_dn);
3686 * Index generation function
3687 * We just index the serials, in most scenarios the issuer DN is one of
3688 * a very small set of values.
3690 static int certificateExactIndexer(
3695 struct berval *prefix,
3696 struct berval **values,
3697 struct berval **keysp )
3700 struct berval *keys;
3703 struct berval * serial;
3705 /* we should have at least one value at this point */
3706 assert( values != NULL && values[0] != NULL );
3708 for( i=0; values[i] != NULL; i++ ) {
3709 /* empty -- just count them */
3712 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3714 for( i=0; values[i] != NULL; i++ ) {
3715 p = values[i]->bv_val;
3716 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
3719 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3720 "certificateExactIndexer: error parsing cert: %s\n",
3721 ERR_error_string(ERR_get_error(),NULL)));
3723 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3724 "error parsing cert: %s\n",
3725 ERR_error_string(ERR_get_error(),NULL),
3728 /* Do we leak keys on error? */
3729 return LDAP_INVALID_SYNTAX;
3732 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3734 integerNormalize( slap_schema.si_syn_integer,
3739 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3740 "certificateExactIndexer: returning: %s\n",
3743 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3750 keys[i].bv_val = NULL;
3752 return LDAP_SUCCESS;
3755 /* Index generation function */
3756 /* We think this is always called with a value in matching rule syntax */
3757 static int certificateExactFilter(
3762 struct berval *prefix,
3764 struct berval **keysp )
3766 struct berval *keys;
3767 struct berval *asserted_serial;
3768 struct berval *asserted_issuer_dn;
3770 serial_and_issuer_parse(assertValue,
3772 &asserted_issuer_dn);
3774 keys = ch_malloc( sizeof( struct berval ) * 2 );
3775 integerNormalize( syntax, asserted_serial, &keys[0] );
3776 keys[1].bv_val = NULL;
3779 ber_bvfree(asserted_serial);
3780 ber_bvfree(asserted_issuer_dn);
3781 return LDAP_SUCCESS;
3786 check_time_syntax (struct berval *val,
3790 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3791 static int mdays[2][12] = {
3792 /* non-leap years */
3793 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3795 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3798 int part, c, tzoffset, leapyear = 0 ;
3800 if( val->bv_len == 0 ) {
3801 return LDAP_INVALID_SYNTAX;
3804 p = (char *)val->bv_val;
3805 e = p + val->bv_len;
3807 /* Ignore initial whitespace */
3808 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3812 if (e - p < 13 - (2 * start)) {
3813 return LDAP_INVALID_SYNTAX;
3816 for (part = 0; part < 9; part++) {
3820 for (part = start; part < 7; part++) {
3822 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3829 return LDAP_INVALID_SYNTAX;
3831 if (c < 0 || c > 9) {
3832 return LDAP_INVALID_SYNTAX;
3838 return LDAP_INVALID_SYNTAX;
3840 if (c < 0 || c > 9) {
3841 return LDAP_INVALID_SYNTAX;
3846 if (part == 2 || part == 3) {
3849 if (parts[part] < 0) {
3850 return LDAP_INVALID_SYNTAX;
3852 if (parts[part] > ceiling[part]) {
3853 return LDAP_INVALID_SYNTAX;
3857 /* leapyear check for the Gregorian calendar (year>1581) */
3858 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3859 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3864 if (parts[3] > mdays[leapyear][parts[2]]) {
3865 return LDAP_INVALID_SYNTAX;
3870 tzoffset = 0; /* UTC */
3871 } else if (c != '+' && c != '-') {
3872 return LDAP_INVALID_SYNTAX;
3876 } else /* c == '+' */ {
3881 return LDAP_INVALID_SYNTAX;
3884 for (part = 7; part < 9; part++) {
3886 if (c < 0 || c > 9) {
3887 return LDAP_INVALID_SYNTAX;
3892 if (c < 0 || c > 9) {
3893 return LDAP_INVALID_SYNTAX;
3897 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3898 return LDAP_INVALID_SYNTAX;
3903 /* Ignore trailing whitespace */
3904 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3908 return LDAP_INVALID_SYNTAX;
3911 switch ( tzoffset ) {
3912 case -1: /* negativ offset to UTC, ie west of Greenwich */
3913 parts[4] += parts[7];
3914 parts[5] += parts[8];
3915 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3919 c = mdays[leapyear][parts[2]];
3921 if (parts[part] > c) {
3922 parts[part] -= c + 1;
3927 case 1: /* positive offset to UTC, ie east of Greenwich */
3928 parts[4] -= parts[7];
3929 parts[5] -= parts[8];
3930 for (part = 6; --part > 0; ) {
3934 /* first arg to % needs to be non negativ */
3935 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3937 if (parts[part] < 0) {
3938 parts[part] += c + 1;
3943 case 0: /* already UTC */
3947 return LDAP_SUCCESS;
3954 struct berval *normalized )
3958 rc = check_time_syntax(val, 1, parts);
3959 if (rc != LDAP_SUCCESS) {
3963 normalized->bv_val = ch_malloc( 14 );
3964 if ( normalized->bv_val == NULL ) {
3965 return LBER_ERROR_MEMORY;
3968 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3969 parts[1], parts[2] + 1, parts[3] + 1,
3970 parts[4], parts[5], parts[6] );
3971 normalized->bv_len = 13;
3973 return LDAP_SUCCESS;
3983 return check_time_syntax(in, 1, parts);
3987 generalizedTimeValidate(
3993 return check_time_syntax(in, 0, parts);
3997 generalizedTimeNormalize(
4000 struct berval *normalized )
4004 rc = check_time_syntax(val, 0, parts);
4005 if (rc != LDAP_SUCCESS) {
4009 normalized->bv_val = ch_malloc( 16 );
4010 if ( normalized->bv_val == NULL ) {
4011 return LBER_ERROR_MEMORY;
4014 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4015 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4016 parts[4], parts[5], parts[6] );
4017 normalized->bv_len = 15;
4019 return LDAP_SUCCESS;
4023 nisNetgroupTripleValidate(
4025 struct berval *val )
4030 if ( val->bv_len == 0 ) {
4031 return LDAP_INVALID_SYNTAX;
4034 p = (char *)val->bv_val;
4035 e = p + val->bv_len;
4037 if ( *p != '(' /*')'*/ ) {
4038 return LDAP_INVALID_SYNTAX;
4041 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4045 return LDAP_INVALID_SYNTAX;
4048 } else if ( !ATTR_CHAR( *p ) ) {
4049 return LDAP_INVALID_SYNTAX;
4053 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4054 return LDAP_INVALID_SYNTAX;
4060 return LDAP_INVALID_SYNTAX;
4063 return LDAP_SUCCESS;
4067 bootParameterValidate(
4069 struct berval *val )
4073 if ( val->bv_len == 0 ) {
4074 return LDAP_INVALID_SYNTAX;
4077 p = (char *)val->bv_val;
4078 e = p + val->bv_len;
4081 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4082 if ( !ATTR_CHAR( *p ) ) {
4083 return LDAP_INVALID_SYNTAX;
4088 return LDAP_INVALID_SYNTAX;
4092 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4093 if ( !ATTR_CHAR( *p ) ) {
4094 return LDAP_INVALID_SYNTAX;
4099 return LDAP_INVALID_SYNTAX;
4103 for ( p++; p < e; p++ ) {
4104 if ( !ATTR_CHAR( *p ) ) {
4105 return LDAP_INVALID_SYNTAX;
4109 return LDAP_SUCCESS;
4112 static struct syntax_defs_rec {
4114 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4115 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4117 slap_syntax_validate_func *sd_validate;
4118 slap_syntax_transform_func *sd_normalize;
4119 slap_syntax_transform_func *sd_pretty;
4120 #ifdef SLAPD_BINARY_CONVERSION
4121 slap_syntax_transform_func *sd_ber2str;
4122 slap_syntax_transform_func *sd_str2ber;
4125 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4126 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4127 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4128 0, NULL, NULL, NULL},
4129 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4130 0, NULL, NULL, NULL},
4131 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4132 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4133 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4134 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4135 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4136 0, bitStringValidate, bitStringNormalize, NULL },
4137 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4138 0, booleanValidate, NULL, NULL},
4139 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4140 X_BINARY X_NOT_H_R ")",
4141 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4142 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4143 X_BINARY X_NOT_H_R ")",
4144 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4146 X_BINARY X_NOT_H_R ")",
4147 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4148 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4149 0, countryStringValidate, IA5StringNormalize, NULL},
4150 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4151 0, dnValidate, dnNormalize2, dnPretty2},
4152 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4153 0, NULL, NULL, NULL},
4154 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4155 0, NULL, NULL, NULL},
4156 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4157 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4158 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4159 0, NULL, NULL, NULL},
4160 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4161 0, NULL, NULL, NULL},
4162 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4163 0, NULL, NULL, NULL},
4164 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4165 0, NULL, NULL, NULL},
4166 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4167 0, NULL, NULL, NULL},
4168 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4169 0, printablesStringValidate, IA5StringNormalize, NULL},
4170 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4171 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4173 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4175 0, NULL, NULL, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4177 0, IA5StringValidate, IA5StringNormalize, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4179 0, integerValidate, integerNormalize, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4181 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4183 0, NULL, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4185 0, NULL, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4187 0, NULL, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4189 0, NULL, NULL, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4191 0, NULL, NULL, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4193 0, nameUIDValidate, nameUIDNormalize, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4195 0, NULL, NULL, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4197 0, numericStringValidate, numericStringNormalize, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4199 0, NULL, NULL, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4201 0, oidValidate, NULL, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4203 0, IA5StringValidate, IA5StringNormalize, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4205 0, blobValidate, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4207 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4209 0, NULL, NULL, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4211 0, NULL, NULL, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4213 0, printableStringValidate, IA5StringNormalize, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4215 X_BINARY X_NOT_H_R ")",
4216 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4218 0, printableStringValidate, IA5StringNormalize, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4220 0, NULL, NULL, NULL},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4222 0, printablesStringValidate, IA5StringNormalize, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4224 0, utcTimeValidate, utcTimeNormalize, NULL},
4225 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4226 0, NULL, NULL, NULL},
4227 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4228 0, NULL, NULL, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4230 0, NULL, NULL, NULL},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4232 0, NULL, NULL, NULL},
4233 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4234 0, NULL, NULL, NULL},
4236 /* RFC 2307 NIS Syntaxes */
4237 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4238 0, nisNetgroupTripleValidate, NULL, NULL},
4239 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4240 0, bootParameterValidate, NULL, NULL},
4244 /* These OIDs are not published yet, but will be in the next
4245 * I-D for PKIX LDAPv3 schema as have been advanced by David
4246 * Chadwick in private mail.
4248 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4249 0, NULL, NULL, NULL},
4252 /* OpenLDAP Experimental Syntaxes */
4253 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4255 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4258 /* needs updating */
4259 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4260 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4262 /* OpenLDAP Void Syntax */
4263 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4264 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4265 {NULL, 0, NULL, NULL, NULL}
4269 * Other matching rules in X.520 that we do not use (yet):
4271 * 2.5.13.9 numericStringOrderingMatch
4272 * 2.5.13.15 integerOrderingMatch
4273 * 2.5.13.18 octetStringOrderingMatch
4274 * 2.5.13.19 octetStringSubstringsMatch
4275 * 2.5.13.25 uTCTimeMatch
4276 * 2.5.13.26 uTCTimeOrderingMatch
4277 * 2.5.13.31 directoryStringFirstComponentMatch
4278 * 2.5.13.32 wordMatch
4279 * 2.5.13.33 keywordMatch
4280 * 2.5.13.35 certificateMatch
4281 * 2.5.13.36 certificatePairExactMatch
4282 * 2.5.13.37 certificatePairMatch
4283 * 2.5.13.38 certificateListExactMatch
4284 * 2.5.13.39 certificateListMatch
4285 * 2.5.13.40 algorithmIdentifierMatch
4286 * 2.5.13.41 storedPrefixMatch
4287 * 2.5.13.42 attributeCertificateMatch
4288 * 2.5.13.43 readerAndKeyIDMatch
4289 * 2.5.13.44 attributeIntegrityMatch
4291 static struct mrule_defs_rec {
4293 slap_mask_t mrd_usage;
4294 slap_mr_convert_func * mrd_convert;
4295 slap_mr_normalize_func * mrd_normalize;
4296 slap_mr_match_func * mrd_match;
4297 slap_mr_indexer_func * mrd_indexer;
4298 slap_mr_filter_func * mrd_filter;
4300 char * mrd_associated;
4303 * EQUALITY matching rules must be listed after associated APPROX
4304 * matching rules. So, we list all APPROX matching rules first.
4306 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4307 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4308 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4310 directoryStringApproxMatch,
4311 directoryStringApproxIndexer,
4312 directoryStringApproxFilter,
4315 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4316 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4317 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4319 IA5StringApproxMatch,
4320 IA5StringApproxIndexer,
4321 IA5StringApproxFilter,
4325 * Other matching rules
4328 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4329 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4330 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4332 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4335 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4336 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4337 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4339 dnMatch, dnIndexer, dnFilter,
4342 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4343 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4344 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4346 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4347 directoryStringApproxMatchOID },
4349 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4350 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4353 caseIgnoreOrderingMatch, NULL, NULL,
4356 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4357 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4358 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4360 caseExactIgnoreSubstringsMatch,
4361 caseExactIgnoreSubstringsIndexer,
4362 caseExactIgnoreSubstringsFilter,
4365 {"( 2.5.13.5 NAME 'caseExactMatch' "
4366 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4367 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4369 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4370 directoryStringApproxMatchOID },
4372 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4373 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4376 caseExactOrderingMatch, NULL, NULL,
4379 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4380 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4381 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4383 caseExactIgnoreSubstringsMatch,
4384 caseExactIgnoreSubstringsIndexer,
4385 caseExactIgnoreSubstringsFilter,
4388 {"( 2.5.13.8 NAME 'numericStringMatch' "
4389 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4390 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4393 caseIgnoreIA5Indexer,
4394 caseIgnoreIA5Filter,
4397 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4398 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4399 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4401 caseIgnoreIA5SubstringsMatch,
4402 caseIgnoreIA5SubstringsIndexer,
4403 caseIgnoreIA5SubstringsFilter,
4406 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4407 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4408 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4410 caseIgnoreListMatch, NULL, NULL,
4413 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4414 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4415 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4417 caseIgnoreListSubstringsMatch, NULL, NULL,
4420 {"( 2.5.13.13 NAME 'booleanMatch' "
4421 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4422 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4424 booleanMatch, NULL, NULL,
4427 {"( 2.5.13.14 NAME 'integerMatch' "
4428 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4429 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4431 integerMatch, integerIndexer, integerFilter,
4434 {"( 2.5.13.16 NAME 'bitStringMatch' "
4435 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4436 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4438 bitStringMatch, bitStringIndexer, bitStringFilter,
4441 {"( 2.5.13.17 NAME 'octetStringMatch' "
4442 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4443 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4445 octetStringMatch, octetStringIndexer, octetStringFilter,
4448 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4449 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4450 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4452 telephoneNumberMatch,
4453 telephoneNumberIndexer,
4454 telephoneNumberFilter,
4457 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4458 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4459 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4461 telephoneNumberSubstringsMatch,
4462 telephoneNumberSubstringsIndexer,
4463 telephoneNumberSubstringsFilter,
4466 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4467 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4468 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4473 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4474 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4475 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4477 uniqueMemberMatch, NULL, NULL,
4480 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4481 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4482 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4484 protocolInformationMatch, NULL, NULL,
4487 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4488 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4489 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4491 generalizedTimeMatch, NULL, NULL,
4494 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4495 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4498 generalizedTimeOrderingMatch, NULL, NULL,
4501 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4502 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4503 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4505 integerFirstComponentMatch, NULL, NULL,
4508 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4509 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4510 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4512 objectIdentifierFirstComponentMatch, NULL, NULL,
4516 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4517 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4518 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4519 certificateExactConvert, NULL,
4520 certificateExactMatch,
4521 certificateExactIndexer, certificateExactFilter,
4525 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4526 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4527 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4529 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4530 IA5StringApproxMatchOID },
4532 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4533 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4534 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4536 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4537 IA5StringApproxMatchOID },
4539 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4540 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4543 caseIgnoreIA5SubstringsMatch,
4544 caseIgnoreIA5SubstringsIndexer,
4545 caseIgnoreIA5SubstringsFilter,
4548 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4549 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4552 caseExactIA5SubstringsMatch,
4553 caseExactIA5SubstringsIndexer,
4554 caseExactIA5SubstringsFilter,
4557 /* needs updating */
4558 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4559 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4562 authPasswordMatch, NULL, NULL,
4565 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4566 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4569 OpenLDAPaciMatch, NULL, NULL,
4572 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4573 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4576 integerBitAndMatch, NULL, NULL,
4579 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4580 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4583 integerBitOrMatch, NULL, NULL,
4586 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4595 /* we should only be called once (from main) */
4596 assert( schema_init_done == 0 );
4598 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4599 res = register_syntax( syntax_defs[i].sd_desc,
4600 syntax_defs[i].sd_flags,
4601 syntax_defs[i].sd_validate,
4602 syntax_defs[i].sd_normalize,
4603 syntax_defs[i].sd_pretty
4604 #ifdef SLAPD_BINARY_CONVERSION
4606 syntax_defs[i].sd_ber2str,
4607 syntax_defs[i].sd_str2ber
4612 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4613 syntax_defs[i].sd_desc );
4618 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4619 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4621 "schema_init: Ingoring unusable matching rule %s\n",
4622 mrule_defs[i].mrd_desc );
4626 res = register_matching_rule(
4627 mrule_defs[i].mrd_desc,
4628 mrule_defs[i].mrd_usage,
4629 mrule_defs[i].mrd_convert,
4630 mrule_defs[i].mrd_normalize,
4631 mrule_defs[i].mrd_match,
4632 mrule_defs[i].mrd_indexer,
4633 mrule_defs[i].mrd_filter,
4634 mrule_defs[i].mrd_associated );
4638 "schema_init: Error registering matching rule %s\n",
4639 mrule_defs[i].mrd_desc );
4643 schema_init_done = 1;
4644 return LDAP_SUCCESS;
4648 schema_destroy( void )