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 /* We should replace MD5 with a faster hash */
25 #define HASH_BYTES LUTIL_HASH_BYTES
26 #define HASH_CONTEXT lutil_HASH_CTX
27 #define HASH_Init(c) lutil_HASHInit(c)
28 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
29 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
31 /* recycled validatation routines */
32 #define berValidate blobValidate
34 /* unimplemented pretters */
36 #define integerPretty NULL
38 /* recycled matching routines */
39 #define bitStringMatch octetStringMatch
40 #define numericStringMatch caseIgnoreIA5Match
41 #define objectIdentifierMatch caseIgnoreIA5Match
42 #define telephoneNumberMatch caseIgnoreIA5Match
43 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
44 #define generalizedTimeMatch caseIgnoreIA5Match
45 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
46 #define uniqueMemberMatch dnMatch
48 /* approx matching rules */
49 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
50 #define directoryStringApproxMatch approxMatch
51 #define directoryStringApproxIndexer approxIndexer
52 #define directoryStringApproxFilter approxFilter
53 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
54 #define IA5StringApproxMatch approxMatch
55 #define IA5StringApproxIndexer approxIndexer
56 #define IA5StringApproxFilter approxFilter
58 /* orderring matching rules */
59 #define caseIgnoreOrderingMatch caseIgnoreMatch
60 #define caseExactOrderingMatch caseExactMatch
62 /* unimplemented matching routines */
63 #define caseIgnoreListMatch NULL
64 #define caseIgnoreListSubstringsMatch NULL
65 #define protocolInformationMatch NULL
66 #define integerFirstComponentMatch NULL
68 #define OpenLDAPaciMatch NULL
69 #define authPasswordMatch NULL
71 /* recycled indexing/filtering routines */
72 #define dnIndexer caseExactIgnoreIndexer
73 #define dnFilter caseExactIgnoreFilter
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 int octetStringIndexer(
125 struct berval *prefix,
126 struct berval **values,
127 struct berval ***keysp )
131 struct berval **keys;
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 = strlen( syntax->ssyn_oid );
148 mlen = strlen( mr->smr_oid );
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 keys[i] = ber_bvdup( &digest );
174 /* Index generation function */
175 int octetStringFilter(
180 struct berval *prefix,
182 struct berval ***keysp )
185 struct berval **keys;
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 = strlen( syntax->ssyn_oid );
194 mlen = strlen( mr->smr_oid );
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 keys[0] = ber_bvdup( &digest );
227 if( in->bv_len == 0 ) return LDAP_SUCCESS;
229 dn = ch_strdup( in->bv_val );
232 return LDAP_INVALID_SYNTAX;
234 } else if ( strlen( in->bv_val ) != in->bv_len ) {
235 rc = LDAP_INVALID_SYNTAX;
237 } else if ( dn_validate( dn ) == NULL ) {
238 rc = LDAP_INVALID_SYNTAX;
252 struct berval **normalized )
256 if ( val->bv_len != 0 ) {
258 out = ber_bvstr( UTF8normalize( val->bv_val, UTF8_CASEFOLD ) );
260 dn = dn_validate( out->bv_val );
264 return LDAP_INVALID_SYNTAX;
268 out->bv_len = strlen( dn );
270 out = ber_bvdup( val );
283 struct berval *value,
284 void *assertedValue )
287 struct berval *asserted = (struct berval *) assertedValue;
289 match = value->bv_len - asserted->bv_len;
292 #ifdef USE_DN_NORMALIZE
293 match = strcmp( value->bv_val, asserted->bv_val );
295 match = strcasecmp( value->bv_val, asserted->bv_val );
300 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
301 "dnMatch: %d\n %s\n %s\n", match,
302 value->bv_val, asserted->bv_val ));
304 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
305 match, value->bv_val, asserted->bv_val );
321 if( in->bv_len == 0 ) return LDAP_SUCCESS;
323 dn = ber_bvdup( in );
325 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
326 /* assume presence of optional UID */
329 for(i=dn->bv_len-2; i>2; i--) {
330 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
334 if( dn->bv_val[i] != '\'' ) {
335 return LDAP_INVALID_SYNTAX;
337 if( dn->bv_val[i-1] != 'B' ) {
338 return LDAP_INVALID_SYNTAX;
340 if( dn->bv_val[i-2] != '#' ) {
341 return LDAP_INVALID_SYNTAX;
344 /* trim the UID to allow use of dn_validate */
345 dn->bv_val[i-2] = '\0';
348 rc = dn_validate( dn->bv_val ) == NULL
349 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
359 struct berval **normalized )
361 struct berval *out = ber_bvdup( val );
363 if( out->bv_len != 0 ) {
367 ber_len_t uidlen = 0;
369 if( out->bv_val[out->bv_len-1] == '\'' ) {
370 /* assume presence of optional UID */
371 uid = strrchr( out->bv_val, '#' );
375 return LDAP_INVALID_SYNTAX;
378 uidlen = out->bv_len - (out->bv_val - uid);
379 /* temporarily trim the UID */
383 #ifdef USE_DN_NORMALIZE
384 dn = dn_normalize( out->bv_val );
386 dn = dn_validate( out->bv_val );
391 return LDAP_INVALID_SYNTAX;
397 /* restore the separator */
400 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
404 out->bv_len = dnlen + uidlen;
416 /* any value allowed */
425 /* any value allowed */
436 /* very unforgiving validation, requires no normalization
437 * before simplistic matching
439 if( in->bv_len < 3 ) {
440 return LDAP_INVALID_SYNTAX;
443 if( in->bv_val[0] != 'B' ||
444 in->bv_val[1] != '\'' ||
445 in->bv_val[in->bv_len-1] != '\'' )
447 return LDAP_INVALID_SYNTAX;
450 for( i=in->bv_len-2; i>1; i-- ) {
451 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
452 return LDAP_INVALID_SYNTAX;
460 * Handling boolean syntax and matching is quite rigid.
461 * A more flexible approach would be to allow a variety
462 * of strings to be normalized and prettied into TRUE
470 /* very unforgiving validation, requires no normalization
471 * before simplistic matching
474 if( in->bv_len == 4 ) {
475 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
478 } else if( in->bv_len == 5 ) {
479 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
484 return LDAP_INVALID_SYNTAX;
493 struct berval *value,
494 void *assertedValue )
496 /* simplistic matching allowed by rigid validation */
497 struct berval *asserted = (struct berval *) assertedValue;
498 *matchp = value->bv_len != asserted->bv_len;
509 unsigned char *u = in->bv_val;
511 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
513 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
514 /* get the length indicated by the first byte */
515 len = LDAP_UTF8_CHARLEN( u );
517 /* should not be zero */
518 if( len == 0 ) return LDAP_INVALID_SYNTAX;
520 /* make sure len corresponds with the offset
521 to the next character */
522 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
525 if( count != 0 ) return LDAP_INVALID_SYNTAX;
534 struct berval **normalized )
536 struct berval *newval;
539 newval = ch_malloc( sizeof( struct berval ) );
543 /* Ignore initial whitespace */
544 while ( ldap_utf8_isspace( p ) ) {
550 return LDAP_INVALID_SYNTAX;
553 newval->bv_val = ch_strdup( p );
554 p = q = newval->bv_val;
560 if ( ldap_utf8_isspace( p ) ) {
561 len = LDAP_UTF8_COPY(q,p);
566 /* Ignore the extra whitespace */
567 while ( ldap_utf8_isspace( p ) ) {
571 len = LDAP_UTF8_COPY(q,p);
578 assert( *newval->bv_val );
579 assert( newval->bv_val < p );
582 /* cannot start with a space */
583 assert( !ldap_utf8_isspace(newval->bv_val) );
586 * If the string ended in space, backup the pointer one
587 * position. One is enough because the above loop collapsed
588 * all whitespace to a single space.
595 /* cannot end with a space */
596 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
601 newval->bv_len = q - newval->bv_val;
602 *normalized = newval;
607 /* Returns Unicode cannonically normalized copy of a substring assertion
608 * Skipping attribute description */
609 SubstringsAssertion *
610 UTF8SubstringsassertionNormalize(
611 SubstringsAssertion *sa,
614 SubstringsAssertion *nsa;
617 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
622 if( sa->sa_initial != NULL ) {
623 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, casefold ) );
624 if( nsa->sa_initial == NULL ) {
629 if( sa->sa_any != NULL ) {
630 for( i=0; sa->sa_any[i] != NULL; i++ ) {
633 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
634 for( i=0; sa->sa_any[i] != NULL; i++ ) {
635 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, casefold ) );
636 if( nsa->sa_any[i] == NULL ) {
640 nsa->sa_any[i] = NULL;
643 if( sa->sa_final != NULL ) {
644 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, casefold ) );
645 if( nsa->sa_final == NULL ) {
653 ch_free( nsa->sa_final );
654 ber_bvecfree( nsa->sa_any );
655 ch_free( nsa->sa_initial );
660 /* Strip characters with the 8th bit set */
673 while( *++q & 0x80 ) {
676 p = memmove(p, q, strlen(q) + 1);
684 #ifndef SLAPD_APPROX_OLDSINGLESTRING
686 #if defined(SLAPD_APPROX_INITIALS)
687 #define SLAPD_APPROX_DELIMITER "._ "
688 #define SLAPD_APPROX_WORDLEN 2
690 #define SLAPD_APPROX_DELIMITER " "
691 #define SLAPD_APPROX_WORDLEN 1
700 struct berval *value,
701 void *assertedValue )
703 char *val, *assertv, **values, **words, *c;
704 int i, count, len, nextchunk=0, nextavail=0;
707 /* Yes, this is necessary */
708 val = UTF8normalize( value->bv_val, UTF8_NOCASEFOLD );
713 strip8bitChars( val );
715 /* Yes, this is necessary */
716 assertv = UTF8normalize( ((struct berval *)assertedValue)->bv_val,
718 if( assertv == NULL ) {
723 strip8bitChars( assertv );
724 avlen = strlen( assertv );
726 /* Isolate how many words there are */
727 for( c=val,count=1; *c; c++ ) {
728 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
729 if ( c == NULL ) break;
734 /* Get a phonetic copy of each word */
735 words = (char **)ch_malloc( count * sizeof(char *) );
736 values = (char **)ch_malloc( count * sizeof(char *) );
737 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
739 values[i] = phonetic(c);
742 /* Work through the asserted value's words, to see if at least some
743 of the words are there, in the same order. */
745 while ( nextchunk < avlen ) {
746 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
751 #if defined(SLAPD_APPROX_INITIALS)
752 else if( len == 1 ) {
753 /* Single letter words need to at least match one word's initial */
754 for( i=nextavail; i<count; i++ )
755 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
762 /* Isolate the next word in the asserted value and phonetic it */
763 assertv[nextchunk+len] = '\0';
764 val = phonetic( assertv + nextchunk );
766 /* See if this phonetic chunk is in the remaining words of *value */
767 for( i=nextavail; i<count; i++ ){
768 if( !strcmp( val, values[i] ) ){
775 /* This chunk in the asserted value was NOT within the *value. */
781 /* Go on to the next word in the asserted value */
785 /* If some of the words were seen, call it a match */
786 if( nextavail > 0 ) {
795 for( i=0; i<count; i++ ) {
796 ch_free( values[i] );
811 struct berval *prefix,
812 struct berval **values,
813 struct berval ***keysp )
816 int i,j, len, wordcount, keycount=0;
817 struct berval **newkeys, **keys=NULL;
819 for( j=0; values[j] != NULL; j++ ) {
820 /* Yes, this is necessary */
821 val = UTF8normalize( values[j]->bv_val, UTF8_NOCASEFOLD );
822 strip8bitChars( val );
824 /* Isolate how many words there are. There will be a key for each */
825 for( wordcount=0,c=val; *c; c++) {
826 len = strcspn(c, SLAPD_APPROX_DELIMITER);
827 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
829 if (*c == '\0') break;
833 /* Allocate/increase storage to account for new keys */
834 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
835 * sizeof(struct berval *) );
836 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
837 if( keys ) ch_free( keys );
840 /* Get a phonetic copy of each word */
841 for( c=val,i=0; i<wordcount; c+=len+1 ) {
843 if( len < SLAPD_APPROX_WORDLEN ) continue;
844 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
845 keys[keycount]->bv_val = phonetic( c );
846 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
853 keys[keycount] = NULL;
865 struct berval *prefix,
867 struct berval ***keysp )
871 struct berval **keys;
873 /* Yes, this is necessary */
874 val = UTF8normalize( ((struct berval *)assertValue)->bv_val,
877 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
882 strip8bitChars( val );
884 /* Isolate how many words there are. There will be a key for each */
885 for( count=0,c=val; *c; c++) {
886 len = strcspn(c, SLAPD_APPROX_DELIMITER);
887 if( len >= SLAPD_APPROX_WORDLEN ) count++;
889 if (*c == '\0') break;
893 /* Allocate storage for new keys */
894 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
896 /* Get a phonetic copy of each word */
897 for( c=val,i=0; i<count; c+=len+1 ) {
899 if( len < SLAPD_APPROX_WORDLEN ) continue;
900 keys[i] = ber_bvstr( phonetic( c ) );
914 /* No other form of Approximate Matching is defined */
922 struct berval *value,
923 void *assertedValue )
925 char *vapprox, *avapprox;
928 /* Yes, this is necessary */
929 s = UTF8normalize( value->bv_val, UTF8_NOCASEFOLD );
935 /* Yes, this is necessary */
936 t = UTF8normalize( ((struct berval *)assertedValue)->bv_val,
944 vapprox = phonetic( strip8bitChars( s ) );
945 avapprox = phonetic( strip8bitChars( t ) );
950 *matchp = strcmp( vapprox, avapprox );
964 struct berval *prefix,
965 struct berval **values,
966 struct berval ***keysp )
969 struct berval **keys;
972 for( i=0; values[i] != NULL; i++ ) {
973 /* empty - just count them */
976 /* we should have at least one value at this point */
979 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
981 /* Copy each value and run it through phonetic() */
982 for( i=0; values[i] != NULL; i++ ) {
983 /* Yes, this is necessary */
984 s = UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD );
986 /* strip 8-bit chars and run through phonetic() */
987 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1003 struct berval *prefix,
1005 struct berval ***keysp )
1007 struct berval **keys;
1010 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1012 /* Yes, this is necessary */
1013 s = UTF8normalize( ((struct berval *)assertValue)->bv_val,
1018 /* strip 8-bit chars and run through phonetic() */
1019 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1025 return LDAP_SUCCESS;
1036 struct berval *value,
1037 void *assertedValue )
1039 *matchp = UTF8normcmp( value->bv_val,
1040 ((struct berval *) assertedValue)->bv_val,
1042 return LDAP_SUCCESS;
1046 caseExactIgnoreSubstringsMatch(
1051 struct berval *value,
1052 void *assertedValue )
1055 SubstringsAssertion *sub;
1059 char *nav, casefold;
1061 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1062 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1064 nav = UTF8normalize( value->bv_val, casefold );
1070 left.bv_len = strlen( nav );
1072 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1078 /* Add up asserted input length */
1079 if( sub->sa_initial ) {
1080 inlen += sub->sa_initial->bv_len;
1083 for(i=0; sub->sa_any[i] != NULL; i++) {
1084 inlen += sub->sa_any[i]->bv_len;
1087 if( sub->sa_final ) {
1088 inlen += sub->sa_final->bv_len;
1091 if( sub->sa_initial ) {
1092 if( inlen > left.bv_len ) {
1097 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1098 sub->sa_initial->bv_len );
1104 left.bv_val += sub->sa_initial->bv_len;
1105 left.bv_len -= sub->sa_initial->bv_len;
1106 inlen -= sub->sa_initial->bv_len;
1109 if( sub->sa_final ) {
1110 if( inlen > left.bv_len ) {
1115 match = strncmp( sub->sa_final->bv_val,
1116 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1117 sub->sa_final->bv_len );
1123 left.bv_len -= sub->sa_final->bv_len;
1124 inlen -= sub->sa_final->bv_len;
1128 for(i=0; sub->sa_any[i]; i++) {
1133 if( inlen > left.bv_len ) {
1134 /* not enough length */
1139 if( sub->sa_any[i]->bv_len == 0 ) {
1143 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1150 idx = p - left.bv_val;
1151 assert( idx < left.bv_len );
1153 if( idx >= left.bv_len ) {
1154 /* this shouldn't happen */
1161 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1162 /* not enough left */
1167 match = strncmp( left.bv_val,
1168 sub->sa_any[i]->bv_val,
1169 sub->sa_any[i]->bv_len );
1177 left.bv_val += sub->sa_any[i]->bv_len;
1178 left.bv_len -= sub->sa_any[i]->bv_len;
1179 inlen -= sub->sa_any[i]->bv_len;
1186 ch_free( sub->sa_final );
1187 ber_bvecfree( sub->sa_any );
1188 ch_free( sub->sa_initial );
1192 return LDAP_SUCCESS;
1195 /* Index generation function */
1196 int caseExactIgnoreIndexer(
1201 struct berval *prefix,
1202 struct berval **values,
1203 struct berval ***keysp )
1208 struct berval **keys;
1209 HASH_CONTEXT HASHcontext;
1210 unsigned char HASHdigest[HASH_BYTES];
1211 struct berval digest;
1212 digest.bv_val = HASHdigest;
1213 digest.bv_len = sizeof(HASHdigest);
1215 for( i=0; values[i] != NULL; i++ ) {
1216 /* empty - just count them */
1219 /* we should have at least one value at this point */
1222 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1224 slen = strlen( syntax->ssyn_oid );
1225 mlen = strlen( mr->smr_oid );
1227 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1228 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1230 for( i=0; values[i] != NULL; i++ ) {
1231 struct berval *value;
1232 value = ber_bvstr( UTF8normalize( values[i]->bv_val,
1235 HASH_Init( &HASHcontext );
1236 if( prefix != NULL && prefix->bv_len > 0 ) {
1237 HASH_Update( &HASHcontext,
1238 prefix->bv_val, prefix->bv_len );
1240 HASH_Update( &HASHcontext,
1241 syntax->ssyn_oid, slen );
1242 HASH_Update( &HASHcontext,
1243 mr->smr_oid, mlen );
1244 HASH_Update( &HASHcontext,
1245 value->bv_val, value->bv_len );
1246 HASH_Final( HASHdigest, &HASHcontext );
1248 ber_bvfree( value );
1250 keys[i] = ber_bvdup( &digest );
1255 return LDAP_SUCCESS;
1258 /* Index generation function */
1259 int caseExactIgnoreFilter(
1264 struct berval *prefix,
1266 struct berval ***keysp )
1270 struct berval **keys;
1271 HASH_CONTEXT HASHcontext;
1272 unsigned char HASHdigest[HASH_BYTES];
1273 struct berval *value;
1274 struct berval digest;
1275 digest.bv_val = HASHdigest;
1276 digest.bv_len = sizeof(HASHdigest);
1278 slen = strlen( syntax->ssyn_oid );
1279 mlen = strlen( mr->smr_oid );
1281 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1282 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1284 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val,
1286 /* This usually happens if filter contains bad UTF8 */
1287 if( value == NULL ) {
1288 keys = ch_malloc( sizeof( struct berval * ) );
1290 return LDAP_SUCCESS;
1293 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1295 HASH_Init( &HASHcontext );
1296 if( prefix != NULL && prefix->bv_len > 0 ) {
1297 HASH_Update( &HASHcontext,
1298 prefix->bv_val, prefix->bv_len );
1300 HASH_Update( &HASHcontext,
1301 syntax->ssyn_oid, slen );
1302 HASH_Update( &HASHcontext,
1303 mr->smr_oid, mlen );
1304 HASH_Update( &HASHcontext,
1305 value->bv_val, value->bv_len );
1306 HASH_Final( HASHdigest, &HASHcontext );
1308 keys[0] = ber_bvdup( &digest );
1311 ber_bvfree( value );
1314 return LDAP_SUCCESS;
1317 /* Substrings Index generation function */
1318 int caseExactIgnoreSubstringsIndexer(
1323 struct berval *prefix,
1324 struct berval **values,
1325 struct berval ***keysp )
1330 struct berval **keys;
1331 struct berval **nvalues;
1333 HASH_CONTEXT HASHcontext;
1334 unsigned char HASHdigest[HASH_BYTES];
1335 struct berval digest;
1336 digest.bv_val = HASHdigest;
1337 digest.bv_len = sizeof(HASHdigest);
1341 for( i=0; values[i] != NULL; i++ ) {
1342 /* empty - just count them */
1345 /* we should have at least one value at this point */
1348 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1349 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1351 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1352 for( i=0; values[i] != NULL; i++ ) {
1353 nvalues[i] = ber_bvstr( UTF8normalize( values[i]->bv_val,
1359 for( i=0; values[i] != NULL; i++ ) {
1360 /* count number of indices to generate */
1361 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1365 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1366 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1367 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1368 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1370 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1374 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1375 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1376 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1380 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1381 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1382 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1383 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1385 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1391 /* no keys to generate */
1393 return LDAP_SUCCESS;
1396 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1398 slen = strlen( syntax->ssyn_oid );
1399 mlen = strlen( mr->smr_oid );
1402 for( i=0; values[i] != NULL; i++ ) {
1404 struct berval *value;
1406 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1410 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1411 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1413 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1414 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1416 for( j=0; j<max; j++ ) {
1417 HASH_Init( &HASHcontext );
1418 if( prefix != NULL && prefix->bv_len > 0 ) {
1419 HASH_Update( &HASHcontext,
1420 prefix->bv_val, prefix->bv_len );
1423 HASH_Update( &HASHcontext,
1424 &pre, sizeof( pre ) );
1425 HASH_Update( &HASHcontext,
1426 syntax->ssyn_oid, slen );
1427 HASH_Update( &HASHcontext,
1428 mr->smr_oid, mlen );
1429 HASH_Update( &HASHcontext,
1431 SLAP_INDEX_SUBSTR_MAXLEN );
1432 HASH_Final( HASHdigest, &HASHcontext );
1434 keys[nkeys++] = ber_bvdup( &digest );
1438 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1439 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1441 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1444 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1445 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1446 HASH_Init( &HASHcontext );
1447 if( prefix != NULL && prefix->bv_len > 0 ) {
1448 HASH_Update( &HASHcontext,
1449 prefix->bv_val, prefix->bv_len );
1451 HASH_Update( &HASHcontext,
1452 &pre, sizeof( pre ) );
1453 HASH_Update( &HASHcontext,
1454 syntax->ssyn_oid, slen );
1455 HASH_Update( &HASHcontext,
1456 mr->smr_oid, mlen );
1457 HASH_Update( &HASHcontext,
1459 HASH_Final( HASHdigest, &HASHcontext );
1461 keys[nkeys++] = ber_bvdup( &digest );
1464 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1465 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1466 HASH_Init( &HASHcontext );
1467 if( prefix != NULL && prefix->bv_len > 0 ) {
1468 HASH_Update( &HASHcontext,
1469 prefix->bv_val, prefix->bv_len );
1471 HASH_Update( &HASHcontext,
1472 &pre, sizeof( pre ) );
1473 HASH_Update( &HASHcontext,
1474 syntax->ssyn_oid, slen );
1475 HASH_Update( &HASHcontext,
1476 mr->smr_oid, mlen );
1477 HASH_Update( &HASHcontext,
1478 &value->bv_val[value->bv_len-j], j );
1479 HASH_Final( HASHdigest, &HASHcontext );
1481 keys[nkeys++] = ber_bvdup( &digest );
1496 ber_bvecfree( nvalues );
1498 return LDAP_SUCCESS;
1501 int caseExactIgnoreSubstringsFilter(
1506 struct berval *prefix,
1508 struct berval ***keysp )
1510 SubstringsAssertion *sa;
1512 ber_len_t nkeys = 0;
1513 size_t slen, mlen, klen;
1514 struct berval **keys;
1515 HASH_CONTEXT HASHcontext;
1516 unsigned char HASHdigest[HASH_BYTES];
1517 struct berval *value;
1518 struct berval digest;
1520 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1521 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1523 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1526 return LDAP_SUCCESS;
1529 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1530 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1535 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1537 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1538 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1539 /* don't bother accounting for stepping */
1540 nkeys += sa->sa_any[i]->bv_len -
1541 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1546 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1547 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1554 return LDAP_SUCCESS;
1557 digest.bv_val = HASHdigest;
1558 digest.bv_len = sizeof(HASHdigest);
1560 slen = strlen( syntax->ssyn_oid );
1561 mlen = strlen( mr->smr_oid );
1563 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1566 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1567 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1569 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1570 value = sa->sa_initial;
1572 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1573 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1575 HASH_Init( &HASHcontext );
1576 if( prefix != NULL && prefix->bv_len > 0 ) {
1577 HASH_Update( &HASHcontext,
1578 prefix->bv_val, prefix->bv_len );
1580 HASH_Update( &HASHcontext,
1581 &pre, sizeof( pre ) );
1582 HASH_Update( &HASHcontext,
1583 syntax->ssyn_oid, slen );
1584 HASH_Update( &HASHcontext,
1585 mr->smr_oid, mlen );
1586 HASH_Update( &HASHcontext,
1587 value->bv_val, klen );
1588 HASH_Final( HASHdigest, &HASHcontext );
1590 keys[nkeys++] = ber_bvdup( &digest );
1593 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1595 pre = SLAP_INDEX_SUBSTR_PREFIX;
1596 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1598 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1599 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1603 value = sa->sa_any[i];
1606 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1607 j += SLAP_INDEX_SUBSTR_STEP )
1609 HASH_Init( &HASHcontext );
1610 if( prefix != NULL && prefix->bv_len > 0 ) {
1611 HASH_Update( &HASHcontext,
1612 prefix->bv_val, prefix->bv_len );
1614 HASH_Update( &HASHcontext,
1615 &pre, sizeof( pre ) );
1616 HASH_Update( &HASHcontext,
1617 syntax->ssyn_oid, slen );
1618 HASH_Update( &HASHcontext,
1619 mr->smr_oid, mlen );
1620 HASH_Update( &HASHcontext,
1621 &value->bv_val[j], klen );
1622 HASH_Final( HASHdigest, &HASHcontext );
1624 keys[nkeys++] = ber_bvdup( &digest );
1630 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1631 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1633 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1634 value = sa->sa_final;
1636 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1637 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1639 HASH_Init( &HASHcontext );
1640 if( prefix != NULL && prefix->bv_len > 0 ) {
1641 HASH_Update( &HASHcontext,
1642 prefix->bv_val, prefix->bv_len );
1644 HASH_Update( &HASHcontext,
1645 &pre, sizeof( pre ) );
1646 HASH_Update( &HASHcontext,
1647 syntax->ssyn_oid, slen );
1648 HASH_Update( &HASHcontext,
1649 mr->smr_oid, mlen );
1650 HASH_Update( &HASHcontext,
1651 &value->bv_val[value->bv_len-klen], klen );
1652 HASH_Final( HASHdigest, &HASHcontext );
1654 keys[nkeys++] = ber_bvdup( &digest );
1664 ch_free( sa->sa_final );
1665 ber_bvecfree( sa->sa_any );
1666 ch_free( sa->sa_initial );
1669 return LDAP_SUCCESS;
1678 struct berval *value,
1679 void *assertedValue )
1681 *matchp = UTF8normcmp( value->bv_val,
1682 ((struct berval *) assertedValue)->bv_val,
1684 return LDAP_SUCCESS;
1690 struct berval *val )
1694 if( val->bv_len == 0 ) {
1695 /* disallow empty strings */
1696 return LDAP_INVALID_SYNTAX;
1699 if( OID_LEADCHAR(val->bv_val[0]) ) {
1701 for(i=1; i < val->bv_len; i++) {
1702 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1703 if( dot++ ) return 1;
1704 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1707 return LDAP_INVALID_SYNTAX;
1711 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1713 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1714 for(i=1; i < val->bv_len; i++) {
1715 if( !DESC_CHAR(val->bv_val[i] ) ) {
1716 return LDAP_INVALID_SYNTAX;
1720 return LDAP_SUCCESS;
1723 return LDAP_INVALID_SYNTAX;
1732 struct berval *value,
1733 void *assertedValue )
1736 int vsign=0, avsign=0;
1737 struct berval *asserted;
1738 ber_len_t vlen, avlen;
1741 /* Start off pessimistic */
1744 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1746 vlen = value->bv_len;
1748 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1749 /* empty -- skip spaces */
1751 else if ( *v == '+' ) {
1754 else if ( *v == '-' ) {
1757 else if ( ASCII_DIGIT(*v) ) {
1758 if ( vsign == 0 ) vsign = 1;
1766 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1768 asserted = (struct berval *) assertedValue;
1769 av = asserted->bv_val;
1770 avlen = asserted->bv_len;
1772 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1773 /* empty -- skip spaces */
1775 else if ( *av == '+' ) {
1778 else if ( *av == '-' ) {
1781 else if ( ASCII_DIGIT(*av) ) {
1782 if ( avsign == 0 ) avsign = 1;
1790 /* The two ?sign vars are now one of :
1791 -2 negative non-zero number
1793 0 0 collapse these three to 0
1795 +2 positive non-zero number
1797 if ( abs( vsign ) == 1 ) vsign = 0;
1798 if ( abs( avsign ) == 1 ) avsign = 0;
1800 if( vsign != avsign ) return LDAP_SUCCESS;
1802 /* Check the significant digits */
1803 while( vlen && avlen ) {
1804 if( *v != *av ) break;
1811 /* If all digits compared equal, the numbers are equal */
1812 if(( vlen == 0 ) && ( avlen == 0 )) {
1815 return LDAP_SUCCESS;
1821 struct berval *val )
1825 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1827 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1828 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1829 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1830 return LDAP_INVALID_SYNTAX;
1833 for( i=1; i < val->bv_len; i++ ) {
1834 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1837 return LDAP_SUCCESS;
1844 struct berval **normalized )
1848 struct berval *newval;
1855 /* Ignore leading spaces */
1856 while ( len && ( *p == ' ' )) {
1863 negative = ( *p == '-' );
1864 if(( *p == '-' ) || ( *p == '+' )) {
1870 /* Ignore leading zeros */
1871 while ( len && ( *p == '0' )) {
1876 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
1878 /* If there are no non-zero digits left, the number is zero, otherwise
1879 allocate space for the number and copy it into the buffer */
1881 newval->bv_val = ch_strdup("0");
1885 newval->bv_len = len+negative;
1886 newval->bv_val = ch_malloc( newval->bv_len );
1888 newval->bv_val[0] = '-';
1890 memcpy( newval->bv_val + negative, p, len );
1893 *normalized = newval;
1894 return LDAP_SUCCESS;
1897 /* Index generation function */
1903 struct berval *prefix,
1904 struct berval **values,
1905 struct berval ***keysp )
1908 struct berval **keys;
1910 /* we should have at least one value at this point */
1911 assert( values != NULL && values[0] != NULL );
1913 for( i=0; values[i] != NULL; i++ ) {
1914 /* empty -- just count them */
1917 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1919 for( i=0; values[i] != NULL; i++ ) {
1920 integerNormalize( syntax, values[i], &keys[i] );
1925 return LDAP_SUCCESS;
1928 /* Index generation function */
1934 struct berval *prefix,
1936 struct berval ***keysp )
1938 struct berval **keys;
1940 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1941 integerNormalize( syntax, assertValue, &keys[0] );
1945 return LDAP_SUCCESS;
1950 countryStringValidate(
1952 struct berval *val )
1954 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1956 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1957 return LDAP_INVALID_SYNTAX;
1959 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1960 return LDAP_INVALID_SYNTAX;
1963 return LDAP_SUCCESS;
1967 printableStringValidate(
1969 struct berval *val )
1973 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1975 for(i=0; i < val->bv_len; i++) {
1976 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1977 return LDAP_INVALID_SYNTAX;
1981 return LDAP_SUCCESS;
1985 printablesStringValidate(
1987 struct berval *val )
1991 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1993 for(i=0; i < val->bv_len; i++) {
1994 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1995 return LDAP_INVALID_SYNTAX;
1999 return LDAP_SUCCESS;
2005 struct berval *val )
2009 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2011 for(i=0; i < val->bv_len; i++) {
2012 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2015 return LDAP_SUCCESS;
2022 struct berval **normalized )
2024 struct berval *newval;
2027 newval = ch_malloc( sizeof( struct berval ) );
2031 /* Ignore initial whitespace */
2032 while ( ASCII_SPACE( *p ) ) {
2038 return LDAP_INVALID_SYNTAX;
2041 newval->bv_val = ch_strdup( p );
2042 p = q = newval->bv_val;
2045 if ( ASCII_SPACE( *p ) ) {
2048 /* Ignore the extra whitespace */
2049 while ( ASCII_SPACE( *p ) ) {
2057 assert( *newval->bv_val );
2058 assert( newval->bv_val < p );
2061 /* cannot start with a space */
2062 assert( !ASCII_SPACE(*newval->bv_val) );
2065 * If the string ended in space, backup the pointer one
2066 * position. One is enough because the above loop collapsed
2067 * all whitespace to a single space.
2070 if ( ASCII_SPACE( q[-1] ) ) {
2074 /* cannot end with a space */
2075 assert( !ASCII_SPACE( q[-1] ) );
2077 /* null terminate */
2080 newval->bv_len = q - newval->bv_val;
2081 *normalized = newval;
2083 return LDAP_SUCCESS;
2092 struct berval *value,
2093 void *assertedValue )
2095 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2098 match = strncmp( value->bv_val,
2099 ((struct berval *) assertedValue)->bv_val,
2104 return LDAP_SUCCESS;
2108 caseExactIA5SubstringsMatch(
2113 struct berval *value,
2114 void *assertedValue )
2117 SubstringsAssertion *sub = assertedValue;
2118 struct berval left = *value;
2122 /* Add up asserted input length */
2123 if( sub->sa_initial ) {
2124 inlen += sub->sa_initial->bv_len;
2127 for(i=0; sub->sa_any[i] != NULL; i++) {
2128 inlen += sub->sa_any[i]->bv_len;
2131 if( sub->sa_final ) {
2132 inlen += sub->sa_final->bv_len;
2135 if( sub->sa_initial ) {
2136 if( inlen > left.bv_len ) {
2141 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2142 sub->sa_initial->bv_len );
2148 left.bv_val += sub->sa_initial->bv_len;
2149 left.bv_len -= sub->sa_initial->bv_len;
2150 inlen -= sub->sa_initial->bv_len;
2153 if( sub->sa_final ) {
2154 if( inlen > left.bv_len ) {
2159 match = strncmp( sub->sa_final->bv_val,
2160 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2161 sub->sa_final->bv_len );
2167 left.bv_len -= sub->sa_final->bv_len;
2168 inlen -= sub->sa_final->bv_len;
2172 for(i=0; sub->sa_any[i]; i++) {
2177 if( inlen > left.bv_len ) {
2178 /* not enough length */
2183 if( sub->sa_any[i]->bv_len == 0 ) {
2187 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2194 idx = p - left.bv_val;
2195 assert( idx < left.bv_len );
2197 if( idx >= left.bv_len ) {
2198 /* this shouldn't happen */
2205 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2206 /* not enough left */
2211 match = strncmp( left.bv_val,
2212 sub->sa_any[i]->bv_val,
2213 sub->sa_any[i]->bv_len );
2221 left.bv_val += sub->sa_any[i]->bv_len;
2222 left.bv_len -= sub->sa_any[i]->bv_len;
2223 inlen -= sub->sa_any[i]->bv_len;
2229 return LDAP_SUCCESS;
2232 /* Index generation function */
2233 int caseExactIA5Indexer(
2238 struct berval *prefix,
2239 struct berval **values,
2240 struct berval ***keysp )
2244 struct berval **keys;
2245 HASH_CONTEXT HASHcontext;
2246 unsigned char HASHdigest[HASH_BYTES];
2247 struct berval digest;
2248 digest.bv_val = HASHdigest;
2249 digest.bv_len = sizeof(HASHdigest);
2251 for( i=0; values[i] != NULL; i++ ) {
2252 /* empty - just count them */
2255 /* we should have at least one value at this point */
2258 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2260 slen = strlen( syntax->ssyn_oid );
2261 mlen = strlen( mr->smr_oid );
2263 for( i=0; values[i] != NULL; i++ ) {
2264 struct berval *value = values[i];
2266 HASH_Init( &HASHcontext );
2267 if( prefix != NULL && prefix->bv_len > 0 ) {
2268 HASH_Update( &HASHcontext,
2269 prefix->bv_val, prefix->bv_len );
2271 HASH_Update( &HASHcontext,
2272 syntax->ssyn_oid, slen );
2273 HASH_Update( &HASHcontext,
2274 mr->smr_oid, mlen );
2275 HASH_Update( &HASHcontext,
2276 value->bv_val, value->bv_len );
2277 HASH_Final( HASHdigest, &HASHcontext );
2279 keys[i] = ber_bvdup( &digest );
2284 return LDAP_SUCCESS;
2287 /* Index generation function */
2288 int caseExactIA5Filter(
2293 struct berval *prefix,
2295 struct berval ***keysp )
2298 struct berval **keys;
2299 HASH_CONTEXT HASHcontext;
2300 unsigned char HASHdigest[HASH_BYTES];
2301 struct berval *value;
2302 struct berval digest;
2303 digest.bv_val = HASHdigest;
2304 digest.bv_len = sizeof(HASHdigest);
2306 slen = strlen( syntax->ssyn_oid );
2307 mlen = strlen( mr->smr_oid );
2309 value = (struct berval *) assertValue;
2311 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2313 HASH_Init( &HASHcontext );
2314 if( prefix != NULL && prefix->bv_len > 0 ) {
2315 HASH_Update( &HASHcontext,
2316 prefix->bv_val, prefix->bv_len );
2318 HASH_Update( &HASHcontext,
2319 syntax->ssyn_oid, slen );
2320 HASH_Update( &HASHcontext,
2321 mr->smr_oid, mlen );
2322 HASH_Update( &HASHcontext,
2323 value->bv_val, value->bv_len );
2324 HASH_Final( HASHdigest, &HASHcontext );
2326 keys[0] = ber_bvdup( &digest );
2330 return LDAP_SUCCESS;
2333 /* Substrings Index generation function */
2334 int caseExactIA5SubstringsIndexer(
2339 struct berval *prefix,
2340 struct berval **values,
2341 struct berval ***keysp )
2345 struct berval **keys;
2346 HASH_CONTEXT HASHcontext;
2347 unsigned char HASHdigest[HASH_BYTES];
2348 struct berval digest;
2349 digest.bv_val = HASHdigest;
2350 digest.bv_len = sizeof(HASHdigest);
2352 /* we should have at least one value at this point */
2353 assert( values != NULL && values[0] != NULL );
2356 for( i=0; values[i] != NULL; i++ ) {
2357 /* count number of indices to generate */
2358 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2362 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2363 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2364 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2365 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2367 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2371 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2372 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2373 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2377 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2378 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2379 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2380 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2382 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2388 /* no keys to generate */
2390 return LDAP_SUCCESS;
2393 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2395 slen = strlen( syntax->ssyn_oid );
2396 mlen = strlen( mr->smr_oid );
2399 for( i=0; values[i] != NULL; i++ ) {
2401 struct berval *value;
2404 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2406 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2407 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2409 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2410 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2412 for( j=0; j<max; j++ ) {
2413 HASH_Init( &HASHcontext );
2414 if( prefix != NULL && prefix->bv_len > 0 ) {
2415 HASH_Update( &HASHcontext,
2416 prefix->bv_val, prefix->bv_len );
2419 HASH_Update( &HASHcontext,
2420 &pre, sizeof( pre ) );
2421 HASH_Update( &HASHcontext,
2422 syntax->ssyn_oid, slen );
2423 HASH_Update( &HASHcontext,
2424 mr->smr_oid, mlen );
2425 HASH_Update( &HASHcontext,
2427 SLAP_INDEX_SUBSTR_MAXLEN );
2428 HASH_Final( HASHdigest, &HASHcontext );
2430 keys[nkeys++] = ber_bvdup( &digest );
2434 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2435 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2437 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2440 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2441 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2442 HASH_Init( &HASHcontext );
2443 if( prefix != NULL && prefix->bv_len > 0 ) {
2444 HASH_Update( &HASHcontext,
2445 prefix->bv_val, prefix->bv_len );
2447 HASH_Update( &HASHcontext,
2448 &pre, sizeof( pre ) );
2449 HASH_Update( &HASHcontext,
2450 syntax->ssyn_oid, slen );
2451 HASH_Update( &HASHcontext,
2452 mr->smr_oid, mlen );
2453 HASH_Update( &HASHcontext,
2455 HASH_Final( HASHdigest, &HASHcontext );
2457 keys[nkeys++] = ber_bvdup( &digest );
2460 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2461 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2462 HASH_Init( &HASHcontext );
2463 if( prefix != NULL && prefix->bv_len > 0 ) {
2464 HASH_Update( &HASHcontext,
2465 prefix->bv_val, prefix->bv_len );
2467 HASH_Update( &HASHcontext,
2468 &pre, sizeof( pre ) );
2469 HASH_Update( &HASHcontext,
2470 syntax->ssyn_oid, slen );
2471 HASH_Update( &HASHcontext,
2472 mr->smr_oid, mlen );
2473 HASH_Update( &HASHcontext,
2474 &value->bv_val[value->bv_len-j], j );
2475 HASH_Final( HASHdigest, &HASHcontext );
2477 keys[nkeys++] = ber_bvdup( &digest );
2491 return LDAP_SUCCESS;
2494 int caseExactIA5SubstringsFilter(
2499 struct berval *prefix,
2501 struct berval ***keysp )
2503 SubstringsAssertion *sa = assertValue;
2505 ber_len_t nkeys = 0;
2506 size_t slen, mlen, klen;
2507 struct berval **keys;
2508 HASH_CONTEXT HASHcontext;
2509 unsigned char HASHdigest[HASH_BYTES];
2510 struct berval *value;
2511 struct berval digest;
2513 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2514 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2519 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2521 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2522 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2523 /* don't bother accounting for stepping */
2524 nkeys += sa->sa_any[i]->bv_len -
2525 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2530 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2531 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2538 return LDAP_SUCCESS;
2541 digest.bv_val = HASHdigest;
2542 digest.bv_len = sizeof(HASHdigest);
2544 slen = strlen( syntax->ssyn_oid );
2545 mlen = strlen( mr->smr_oid );
2547 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2550 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2551 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2553 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2554 value = sa->sa_initial;
2556 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2557 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2559 HASH_Init( &HASHcontext );
2560 if( prefix != NULL && prefix->bv_len > 0 ) {
2561 HASH_Update( &HASHcontext,
2562 prefix->bv_val, prefix->bv_len );
2564 HASH_Update( &HASHcontext,
2565 &pre, sizeof( pre ) );
2566 HASH_Update( &HASHcontext,
2567 syntax->ssyn_oid, slen );
2568 HASH_Update( &HASHcontext,
2569 mr->smr_oid, mlen );
2570 HASH_Update( &HASHcontext,
2571 value->bv_val, klen );
2572 HASH_Final( HASHdigest, &HASHcontext );
2574 keys[nkeys++] = ber_bvdup( &digest );
2577 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2579 pre = SLAP_INDEX_SUBSTR_PREFIX;
2580 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2582 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2583 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2587 value = sa->sa_any[i];
2590 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2591 j += SLAP_INDEX_SUBSTR_STEP )
2593 HASH_Init( &HASHcontext );
2594 if( prefix != NULL && prefix->bv_len > 0 ) {
2595 HASH_Update( &HASHcontext,
2596 prefix->bv_val, prefix->bv_len );
2598 HASH_Update( &HASHcontext,
2599 &pre, sizeof( pre ) );
2600 HASH_Update( &HASHcontext,
2601 syntax->ssyn_oid, slen );
2602 HASH_Update( &HASHcontext,
2603 mr->smr_oid, mlen );
2604 HASH_Update( &HASHcontext,
2605 &value->bv_val[j], klen );
2606 HASH_Final( HASHdigest, &HASHcontext );
2608 keys[nkeys++] = ber_bvdup( &digest );
2613 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2614 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2616 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2617 value = sa->sa_final;
2619 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2620 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2622 HASH_Init( &HASHcontext );
2623 if( prefix != NULL && prefix->bv_len > 0 ) {
2624 HASH_Update( &HASHcontext,
2625 prefix->bv_val, prefix->bv_len );
2627 HASH_Update( &HASHcontext,
2628 &pre, sizeof( pre ) );
2629 HASH_Update( &HASHcontext,
2630 syntax->ssyn_oid, slen );
2631 HASH_Update( &HASHcontext,
2632 mr->smr_oid, mlen );
2633 HASH_Update( &HASHcontext,
2634 &value->bv_val[value->bv_len-klen], klen );
2635 HASH_Final( HASHdigest, &HASHcontext );
2637 keys[nkeys++] = ber_bvdup( &digest );
2648 return LDAP_SUCCESS;
2657 struct berval *value,
2658 void *assertedValue )
2660 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2662 if( match == 0 && value->bv_len ) {
2663 match = strncasecmp( value->bv_val,
2664 ((struct berval *) assertedValue)->bv_val,
2669 return LDAP_SUCCESS;
2673 caseIgnoreIA5SubstringsMatch(
2678 struct berval *value,
2679 void *assertedValue )
2682 SubstringsAssertion *sub = assertedValue;
2683 struct berval left = *value;
2687 /* Add up asserted input length */
2688 if( sub->sa_initial ) {
2689 inlen += sub->sa_initial->bv_len;
2692 for(i=0; sub->sa_any[i] != NULL; i++) {
2693 inlen += sub->sa_any[i]->bv_len;
2696 if( sub->sa_final ) {
2697 inlen += sub->sa_final->bv_len;
2700 if( sub->sa_initial ) {
2701 if( inlen > left.bv_len ) {
2706 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2707 sub->sa_initial->bv_len );
2713 left.bv_val += sub->sa_initial->bv_len;
2714 left.bv_len -= sub->sa_initial->bv_len;
2715 inlen -= sub->sa_initial->bv_len;
2718 if( sub->sa_final ) {
2719 if( inlen > left.bv_len ) {
2724 match = strncasecmp( sub->sa_final->bv_val,
2725 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2726 sub->sa_final->bv_len );
2732 left.bv_len -= sub->sa_final->bv_len;
2733 inlen -= sub->sa_final->bv_len;
2737 for(i=0; sub->sa_any[i]; i++) {
2742 if( inlen > left.bv_len ) {
2743 /* not enough length */
2748 if( sub->sa_any[i]->bv_len == 0 ) {
2752 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2759 idx = p - left.bv_val;
2760 assert( idx < left.bv_len );
2762 if( idx >= left.bv_len ) {
2763 /* this shouldn't happen */
2770 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2771 /* not enough left */
2776 match = strncasecmp( left.bv_val,
2777 sub->sa_any[i]->bv_val,
2778 sub->sa_any[i]->bv_len );
2787 left.bv_val += sub->sa_any[i]->bv_len;
2788 left.bv_len -= sub->sa_any[i]->bv_len;
2789 inlen -= sub->sa_any[i]->bv_len;
2795 return LDAP_SUCCESS;
2798 /* Index generation function */
2799 int caseIgnoreIA5Indexer(
2804 struct berval *prefix,
2805 struct berval **values,
2806 struct berval ***keysp )
2810 struct berval **keys;
2811 HASH_CONTEXT HASHcontext;
2812 unsigned char HASHdigest[HASH_BYTES];
2813 struct berval digest;
2814 digest.bv_val = HASHdigest;
2815 digest.bv_len = sizeof(HASHdigest);
2817 /* we should have at least one value at this point */
2818 assert( values != NULL && values[0] != NULL );
2820 for( i=0; values[i] != NULL; i++ ) {
2821 /* just count them */
2824 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2826 slen = strlen( syntax->ssyn_oid );
2827 mlen = strlen( mr->smr_oid );
2829 for( i=0; values[i] != NULL; i++ ) {
2830 struct berval *value = ber_bvdup( values[i] );
2831 ldap_pvt_str2upper( value->bv_val );
2833 HASH_Init( &HASHcontext );
2834 if( prefix != NULL && prefix->bv_len > 0 ) {
2835 HASH_Update( &HASHcontext,
2836 prefix->bv_val, prefix->bv_len );
2838 HASH_Update( &HASHcontext,
2839 syntax->ssyn_oid, slen );
2840 HASH_Update( &HASHcontext,
2841 mr->smr_oid, mlen );
2842 HASH_Update( &HASHcontext,
2843 value->bv_val, value->bv_len );
2844 HASH_Final( HASHdigest, &HASHcontext );
2846 ber_bvfree( value );
2848 keys[i] = ber_bvdup( &digest );
2853 return LDAP_SUCCESS;
2856 /* Index generation function */
2857 int caseIgnoreIA5Filter(
2862 struct berval *prefix,
2864 struct berval ***keysp )
2867 struct berval **keys;
2868 HASH_CONTEXT HASHcontext;
2869 unsigned char HASHdigest[HASH_BYTES];
2870 struct berval *value;
2871 struct berval digest;
2872 digest.bv_val = HASHdigest;
2873 digest.bv_len = sizeof(HASHdigest);
2875 slen = strlen( syntax->ssyn_oid );
2876 mlen = strlen( mr->smr_oid );
2878 value = ber_bvdup( (struct berval *) assertValue );
2879 ldap_pvt_str2upper( value->bv_val );
2881 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2883 HASH_Init( &HASHcontext );
2884 if( prefix != NULL && prefix->bv_len > 0 ) {
2885 HASH_Update( &HASHcontext,
2886 prefix->bv_val, prefix->bv_len );
2888 HASH_Update( &HASHcontext,
2889 syntax->ssyn_oid, slen );
2890 HASH_Update( &HASHcontext,
2891 mr->smr_oid, mlen );
2892 HASH_Update( &HASHcontext,
2893 value->bv_val, value->bv_len );
2894 HASH_Final( HASHdigest, &HASHcontext );
2896 keys[0] = ber_bvdup( &digest );
2899 ber_bvfree( value );
2903 return LDAP_SUCCESS;
2906 /* Substrings Index generation function */
2907 int caseIgnoreIA5SubstringsIndexer(
2912 struct berval *prefix,
2913 struct berval **values,
2914 struct berval ***keysp )
2918 struct berval **keys;
2919 HASH_CONTEXT HASHcontext;
2920 unsigned char HASHdigest[HASH_BYTES];
2921 struct berval digest;
2922 digest.bv_val = HASHdigest;
2923 digest.bv_len = sizeof(HASHdigest);
2925 /* we should have at least one value at this point */
2926 assert( values != NULL && values[0] != NULL );
2929 for( i=0; values[i] != NULL; i++ ) {
2930 /* count number of indices to generate */
2931 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2935 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2936 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2937 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2938 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2940 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2944 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2945 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2946 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2950 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2951 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2952 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2953 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2955 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2961 /* no keys to generate */
2963 return LDAP_SUCCESS;
2966 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2968 slen = strlen( syntax->ssyn_oid );
2969 mlen = strlen( mr->smr_oid );
2972 for( i=0; values[i] != NULL; i++ ) {
2974 struct berval *value;
2976 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2978 value = ber_bvdup( values[i] );
2979 ldap_pvt_str2upper( value->bv_val );
2981 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2982 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2984 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2985 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2987 for( j=0; j<max; j++ ) {
2988 HASH_Init( &HASHcontext );
2989 if( prefix != NULL && prefix->bv_len > 0 ) {
2990 HASH_Update( &HASHcontext,
2991 prefix->bv_val, prefix->bv_len );
2994 HASH_Update( &HASHcontext,
2995 &pre, sizeof( pre ) );
2996 HASH_Update( &HASHcontext,
2997 syntax->ssyn_oid, slen );
2998 HASH_Update( &HASHcontext,
2999 mr->smr_oid, mlen );
3000 HASH_Update( &HASHcontext,
3002 SLAP_INDEX_SUBSTR_MAXLEN );
3003 HASH_Final( HASHdigest, &HASHcontext );
3005 keys[nkeys++] = ber_bvdup( &digest );
3009 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3010 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3012 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3015 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3016 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3017 HASH_Init( &HASHcontext );
3018 if( prefix != NULL && prefix->bv_len > 0 ) {
3019 HASH_Update( &HASHcontext,
3020 prefix->bv_val, prefix->bv_len );
3022 HASH_Update( &HASHcontext,
3023 &pre, sizeof( pre ) );
3024 HASH_Update( &HASHcontext,
3025 syntax->ssyn_oid, slen );
3026 HASH_Update( &HASHcontext,
3027 mr->smr_oid, mlen );
3028 HASH_Update( &HASHcontext,
3030 HASH_Final( HASHdigest, &HASHcontext );
3032 keys[nkeys++] = ber_bvdup( &digest );
3035 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3036 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3037 HASH_Init( &HASHcontext );
3038 if( prefix != NULL && prefix->bv_len > 0 ) {
3039 HASH_Update( &HASHcontext,
3040 prefix->bv_val, prefix->bv_len );
3042 HASH_Update( &HASHcontext,
3043 &pre, sizeof( pre ) );
3044 HASH_Update( &HASHcontext,
3045 syntax->ssyn_oid, slen );
3046 HASH_Update( &HASHcontext,
3047 mr->smr_oid, mlen );
3048 HASH_Update( &HASHcontext,
3049 &value->bv_val[value->bv_len-j], j );
3050 HASH_Final( HASHdigest, &HASHcontext );
3052 keys[nkeys++] = ber_bvdup( &digest );
3057 ber_bvfree( value );
3068 return LDAP_SUCCESS;
3071 int caseIgnoreIA5SubstringsFilter(
3076 struct berval *prefix,
3078 struct berval ***keysp )
3080 SubstringsAssertion *sa = assertValue;
3082 ber_len_t nkeys = 0;
3083 size_t slen, mlen, klen;
3084 struct berval **keys;
3085 HASH_CONTEXT HASHcontext;
3086 unsigned char HASHdigest[HASH_BYTES];
3087 struct berval *value;
3088 struct berval digest;
3090 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3091 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3096 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3098 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3099 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3100 /* don't bother accounting for stepping */
3101 nkeys += sa->sa_any[i]->bv_len -
3102 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3107 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3108 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3115 return LDAP_SUCCESS;
3118 digest.bv_val = HASHdigest;
3119 digest.bv_len = sizeof(HASHdigest);
3121 slen = strlen( syntax->ssyn_oid );
3122 mlen = strlen( mr->smr_oid );
3124 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3127 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3128 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3130 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3131 value = ber_bvdup( sa->sa_initial );
3132 ldap_pvt_str2upper( value->bv_val );
3134 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3135 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3137 HASH_Init( &HASHcontext );
3138 if( prefix != NULL && prefix->bv_len > 0 ) {
3139 HASH_Update( &HASHcontext,
3140 prefix->bv_val, prefix->bv_len );
3142 HASH_Update( &HASHcontext,
3143 &pre, sizeof( pre ) );
3144 HASH_Update( &HASHcontext,
3145 syntax->ssyn_oid, slen );
3146 HASH_Update( &HASHcontext,
3147 mr->smr_oid, mlen );
3148 HASH_Update( &HASHcontext,
3149 value->bv_val, klen );
3150 HASH_Final( HASHdigest, &HASHcontext );
3152 ber_bvfree( value );
3153 keys[nkeys++] = ber_bvdup( &digest );
3156 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3158 pre = SLAP_INDEX_SUBSTR_PREFIX;
3159 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3161 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3162 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3166 value = ber_bvdup( sa->sa_any[i] );
3167 ldap_pvt_str2upper( value->bv_val );
3170 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3171 j += SLAP_INDEX_SUBSTR_STEP )
3173 HASH_Init( &HASHcontext );
3174 if( prefix != NULL && prefix->bv_len > 0 ) {
3175 HASH_Update( &HASHcontext,
3176 prefix->bv_val, prefix->bv_len );
3178 HASH_Update( &HASHcontext,
3179 &pre, sizeof( pre ) );
3180 HASH_Update( &HASHcontext,
3181 syntax->ssyn_oid, slen );
3182 HASH_Update( &HASHcontext,
3183 mr->smr_oid, mlen );
3184 HASH_Update( &HASHcontext,
3185 &value->bv_val[j], klen );
3186 HASH_Final( HASHdigest, &HASHcontext );
3188 keys[nkeys++] = ber_bvdup( &digest );
3191 ber_bvfree( value );
3195 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3196 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3198 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3199 value = ber_bvdup( sa->sa_final );
3200 ldap_pvt_str2upper( value->bv_val );
3202 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3203 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3205 HASH_Init( &HASHcontext );
3206 if( prefix != NULL && prefix->bv_len > 0 ) {
3207 HASH_Update( &HASHcontext,
3208 prefix->bv_val, prefix->bv_len );
3210 HASH_Update( &HASHcontext,
3211 &pre, sizeof( pre ) );
3212 HASH_Update( &HASHcontext,
3213 syntax->ssyn_oid, slen );
3214 HASH_Update( &HASHcontext,
3215 mr->smr_oid, mlen );
3216 HASH_Update( &HASHcontext,
3217 &value->bv_val[value->bv_len-klen], klen );
3218 HASH_Final( HASHdigest, &HASHcontext );
3220 ber_bvfree( value );
3221 keys[nkeys++] = ber_bvdup( &digest );
3232 return LDAP_SUCCESS;
3236 numericStringValidate(
3242 for(i=0; i < in->bv_len; i++) {
3243 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3244 return LDAP_INVALID_SYNTAX;
3248 return LDAP_SUCCESS;
3252 numericStringNormalize(
3255 struct berval **normalized )
3257 /* removal all spaces */
3258 struct berval *newval;
3261 newval = ch_malloc( sizeof( struct berval ) );
3262 newval->bv_val = ch_malloc( val->bv_len + 1 );
3268 if ( ASCII_SPACE( *p ) ) {
3269 /* Ignore whitespace */
3276 /* we should have copied no more then is in val */
3277 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3279 /* null terminate */
3282 newval->bv_len = q - newval->bv_val;
3283 *normalized = newval;
3285 return LDAP_SUCCESS;
3289 objectIdentifierFirstComponentMatch(
3294 struct berval *value,
3295 void *assertedValue )
3297 int rc = LDAP_SUCCESS;
3299 struct berval *asserted = (struct berval *) assertedValue;
3303 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3304 return LDAP_INVALID_SYNTAX;
3307 /* trim leading white space */
3308 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3312 /* grab next word */
3313 oid.bv_val = &value->bv_val[i];
3314 oid.bv_len = value->bv_len - i;
3315 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3320 /* insert attributeTypes, objectclass check here */
3321 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3322 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3325 char *stored = ch_malloc( oid.bv_len + 1 );
3326 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3327 stored[oid.bv_len] = '\0';
3329 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3330 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3331 MatchingRule *stored_mr = mr_find( stored );
3333 if( asserted_mr == NULL ) {
3334 rc = SLAPD_COMPARE_UNDEFINED;
3336 match = asserted_mr != stored_mr;
3339 } else if ( !strcmp( syntax->ssyn_oid,
3340 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3342 AttributeType *asserted_at = at_find( asserted->bv_val );
3343 AttributeType *stored_at = at_find( stored );
3345 if( asserted_at == NULL ) {
3346 rc = SLAPD_COMPARE_UNDEFINED;
3348 match = asserted_at != stored_at;
3351 } else if ( !strcmp( syntax->ssyn_oid,
3352 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3354 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3355 ObjectClass *stored_oc = oc_find( stored );
3357 if( asserted_oc == NULL ) {
3358 rc = SLAPD_COMPARE_UNDEFINED;
3360 match = asserted_oc != stored_oc;
3368 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3369 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3370 match, value->bv_val, asserted->bv_val ));
3372 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3373 "%d\n\t\"%s\"\n\t\"%s\"\n",
3374 match, value->bv_val, asserted->bv_val );
3378 if( rc == LDAP_SUCCESS ) *matchp = match;
3388 struct berval *value,
3389 void *assertedValue )
3391 long lValue, lAssertedValue;
3393 /* safe to assume integers are NUL terminated? */
3394 lValue = strtoul(value->bv_val, NULL, 10);
3395 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3396 return LDAP_CONSTRAINT_VIOLATION;
3398 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3399 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3400 return LDAP_CONSTRAINT_VIOLATION;
3402 *matchp = (lValue & lAssertedValue);
3403 return LDAP_SUCCESS;
3412 struct berval *value,
3413 void *assertedValue )
3415 long lValue, lAssertedValue;
3417 /* safe to assume integers are NUL terminated? */
3418 lValue = strtoul(value->bv_val, NULL, 10);
3419 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3420 return LDAP_CONSTRAINT_VIOLATION;
3422 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3423 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3424 return LDAP_CONSTRAINT_VIOLATION;
3426 *matchp = (lValue | lAssertedValue);
3427 return LDAP_SUCCESS;
3431 #include <openssl/x509.h>
3432 #include <openssl/err.h>
3433 char digit[] = "0123456789";
3436 * Next function returns a string representation of a ASN1_INTEGER.
3437 * It works for unlimited lengths.
3440 static struct berval *
3441 asn1_integer2str(ASN1_INTEGER *a)
3446 /* We work backwards, make it fill from the end of buf */
3447 p = buf + sizeof(buf) - 1;
3450 if ( a == NULL || a->length == 0 ) {
3458 /* We want to preserve the original */
3459 copy = ch_malloc(n*sizeof(unsigned int));
3460 for (i = 0; i<n; i++) {
3461 copy[i] = a->data[i];
3465 * base indicates the index of the most significant
3466 * byte that might be nonzero. When it goes off the
3467 * end, we now there is nothing left to do.
3474 for (i = base; i<n; i++ ) {
3475 copy[i] += carry*256;
3476 carry = copy[i] % 10;
3481 * Way too large, we need to leave
3482 * room for sign if negative
3486 *--p = digit[carry];
3487 if (copy[base] == 0)
3493 if ( a->type == V_ASN1_NEG_INTEGER ) {
3497 return ber_bvstrdup(p);
3500 static struct berval *
3501 dn_openssl2ldap(X509_NAME *name)
3503 char issuer_dn[1024];
3506 bio = BIO_new(BIO_s_mem());
3508 fprintf(stderr, ERR_error_string(ERR_get_error(),NULL));
3509 /* ERR_print_errors(bio_err); */
3512 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3514 BIO_gets(bio, issuer_dn, 1024);
3517 return ber_bvstrdup(issuer_dn);
3521 serial_and_issuer_parse(
3522 struct berval *assertion,
3523 struct berval **serial,
3524 struct berval **issuer_dn
3532 begin = assertion->bv_val;
3533 end = assertion->bv_val+assertion->bv_len-1;
3534 for (p=begin; p<=end && *p != '$'; p++)
3537 return LDAP_INVALID_SYNTAX;
3539 /* p now points at the $ sign, now use begin and end to delimit the
3541 while (ASCII_SPACE(*begin++))
3544 while (ASCII_SPACE(*end--))
3547 q = ch_malloc( (end-begin+1)+1 );
3548 AC_MEMCPY( q, begin, end-begin+1 );
3549 q[end-begin+1] = '\0';
3550 *serial = ber_bvstr(q);
3552 /* now extract the issuer, remember p was at the dollar sign */
3554 end = assertion->bv_val+assertion->bv_len-1;
3555 while (ASCII_SPACE(*begin++))
3557 /* should we trim spaces at the end too? is it safe always? */
3559 q = ch_malloc( (end-begin+1)+1 );
3560 AC_MEMCPY( q, begin, end-begin+1 );
3561 q[end-begin+1] = '\0';
3562 *issuer_dn = ber_bvstr(q);
3564 return LDAP_SUCCESS;
3568 certificateExactMatch(
3573 struct berval *value,
3574 void *assertedValue )
3577 unsigned char *p = value->bv_val;
3578 struct berval *serial;
3579 struct berval *issuer_dn;
3580 struct berval *asserted_serial;
3581 struct berval *asserted_issuer_dn;
3584 xcert = d2i_X509(NULL, &p, value->bv_len);
3586 ERR_error_string(ERR_get_error(),NULL);
3589 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3590 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3594 serial_and_issuer_parse(assertedValue,
3596 &asserted_issuer_dn);
3601 slap_schema.si_syn_integer,
3602 slap_schema.si_mr_integerMatch,
3605 if ( ret == LDAP_SUCCESS ) {
3606 if ( *matchp == 0 ) {
3610 slap_schema.si_syn_distinguishedName,
3611 slap_schema.si_mr_distinguishedNameMatch,
3613 asserted_issuer_dn);
3618 ber_bvfree(issuer_dn);
3619 ber_bvfree(asserted_serial);
3620 ber_bvfree(asserted_issuer_dn);
3627 check_time_syntax (struct berval *val,
3631 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3632 static int mdays[2][12] = {
3633 /* non-leap years */
3634 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3636 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3639 int part, c, tzoffset, leapyear = 0 ;
3641 if( val->bv_len == 0 ) {
3642 return LDAP_INVALID_SYNTAX;
3645 p = (char *)val->bv_val;
3646 e = p + val->bv_len;
3648 /* Ignore initial whitespace */
3649 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3653 if (e - p < 13 - (2 * start)) {
3654 return LDAP_INVALID_SYNTAX;
3657 for (part = 0; part < 9; part++) {
3661 for (part = start; part < 7; part++) {
3663 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3670 return LDAP_INVALID_SYNTAX;
3672 if (c < 0 || c > 9) {
3673 return LDAP_INVALID_SYNTAX;
3679 return LDAP_INVALID_SYNTAX;
3681 if (c < 0 || c > 9) {
3682 return LDAP_INVALID_SYNTAX;
3687 if (part == 2 || part == 3) {
3690 if (parts[part] < 0) {
3691 return LDAP_INVALID_SYNTAX;
3693 if (parts[part] > ceiling[part]) {
3694 return LDAP_INVALID_SYNTAX;
3698 /* leapyear check for the Gregorian calendar (year>1581) */
3699 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3700 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3705 if (parts[3] > mdays[leapyear][parts[2]]) {
3706 return LDAP_INVALID_SYNTAX;
3711 tzoffset = 0; /* UTC */
3712 } else if (c != '+' && c != '-') {
3713 return LDAP_INVALID_SYNTAX;
3717 } else /* c == '+' */ {
3722 return LDAP_INVALID_SYNTAX;
3725 for (part = 7; part < 9; part++) {
3727 if (c < 0 || c > 9) {
3728 return LDAP_INVALID_SYNTAX;
3733 if (c < 0 || c > 9) {
3734 return LDAP_INVALID_SYNTAX;
3738 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3739 return LDAP_INVALID_SYNTAX;
3744 /* Ignore trailing whitespace */
3745 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3749 return LDAP_INVALID_SYNTAX;
3752 switch ( tzoffset ) {
3753 case -1: /* negativ offset to UTC, ie west of Greenwich */
3754 parts[4] += parts[7];
3755 parts[5] += parts[8];
3756 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3760 c = mdays[leapyear][parts[2]];
3762 if (parts[part] > c) {
3763 parts[part] -= c + 1;
3768 case 1: /* positive offset to UTC, ie east of Greenwich */
3769 parts[4] -= parts[7];
3770 parts[5] -= parts[8];
3771 for (part = 6; --part > 0; ) {
3775 /* first arg to % needs to be non negativ */
3776 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3778 if (parts[part] < 0) {
3779 parts[part] += c + 1;
3784 case 0: /* already UTC */
3788 return LDAP_SUCCESS;
3795 struct berval **normalized )
3800 rc = check_time_syntax(val, 1, parts);
3801 if (rc != LDAP_SUCCESS) {
3806 out = ch_malloc( sizeof(struct berval) );
3808 return LBER_ERROR_MEMORY;
3811 out->bv_val = ch_malloc( 14 );
3812 if ( out->bv_val == NULL ) {
3814 return LBER_ERROR_MEMORY;
3817 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3818 parts[1], parts[2] + 1, parts[3] + 1,
3819 parts[4], parts[5], parts[6] );
3823 return LDAP_SUCCESS;
3833 return check_time_syntax(in, 1, parts);
3837 generalizedTimeValidate(
3843 return check_time_syntax(in, 0, parts);
3847 generalizedTimeNormalize(
3850 struct berval **normalized )
3855 rc = check_time_syntax(val, 0, parts);
3856 if (rc != LDAP_SUCCESS) {
3861 out = ch_malloc( sizeof(struct berval) );
3863 return LBER_ERROR_MEMORY;
3866 out->bv_val = ch_malloc( 16 );
3867 if ( out->bv_val == NULL ) {
3869 return LBER_ERROR_MEMORY;
3872 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3873 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3874 parts[4], parts[5], parts[6] );
3878 return LDAP_SUCCESS;
3882 nisNetgroupTripleValidate(
3884 struct berval *val )
3889 if ( val->bv_len == 0 ) {
3890 return LDAP_INVALID_SYNTAX;
3893 p = (char *)val->bv_val;
3894 e = p + val->bv_len;
3896 if ( *p != '(' /*')'*/ ) {
3897 return LDAP_INVALID_SYNTAX;
3900 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3904 return LDAP_INVALID_SYNTAX;
3907 } else if ( !ATTR_CHAR( *p ) ) {
3908 return LDAP_INVALID_SYNTAX;
3912 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3913 return LDAP_INVALID_SYNTAX;
3919 return LDAP_INVALID_SYNTAX;
3922 return LDAP_SUCCESS;
3926 bootParameterValidate(
3928 struct berval *val )
3932 if ( val->bv_len == 0 ) {
3933 return LDAP_INVALID_SYNTAX;
3936 p = (char *)val->bv_val;
3937 e = p + val->bv_len;
3940 for (; ( p < e ) && ( *p != '=' ); p++ ) {
3941 if ( !ATTR_CHAR( *p ) ) {
3942 return LDAP_INVALID_SYNTAX;
3947 return LDAP_INVALID_SYNTAX;
3951 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
3952 if ( !ATTR_CHAR( *p ) ) {
3953 return LDAP_INVALID_SYNTAX;
3958 return LDAP_INVALID_SYNTAX;
3962 for ( p++; p < e; p++ ) {
3963 if ( !ATTR_CHAR( *p ) ) {
3964 return LDAP_INVALID_SYNTAX;
3968 return LDAP_SUCCESS;
3971 struct syntax_defs_rec {
3974 slap_syntax_validate_func *sd_validate;
3975 slap_syntax_transform_func *sd_normalize;
3976 slap_syntax_transform_func *sd_pretty;
3977 #ifdef SLAPD_BINARY_CONVERSION
3978 slap_syntax_transform_func *sd_ber2str;
3979 slap_syntax_transform_func *sd_str2ber;
3983 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
3984 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
3986 struct syntax_defs_rec syntax_defs[] = {
3987 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
3988 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
3989 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
3990 0, NULL, NULL, NULL},
3991 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
3992 0, NULL, NULL, NULL},
3993 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
3994 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3995 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
3996 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3997 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
3998 0, bitStringValidate, NULL, NULL },
3999 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4000 0, booleanValidate, NULL, NULL},
4001 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4002 X_BINARY X_NOT_H_R ")",
4003 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4004 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4005 X_BINARY X_NOT_H_R ")",
4006 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4007 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4008 X_BINARY X_NOT_H_R ")",
4009 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4010 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4011 0, countryStringValidate, IA5StringNormalize, NULL},
4012 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4013 0, dnValidate, dnNormalize, dnPretty},
4014 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4015 0, NULL, NULL, NULL},
4016 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4017 0, NULL, NULL, NULL},
4018 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4019 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4020 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4021 0, NULL, NULL, NULL},
4022 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4023 0, NULL, NULL, NULL},
4024 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4025 0, NULL, NULL, NULL},
4026 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4027 0, NULL, NULL, NULL},
4028 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4029 0, NULL, NULL, NULL},
4030 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4031 0, printablesStringValidate, IA5StringNormalize, NULL},
4032 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4033 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4034 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4035 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4036 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4037 0, NULL, NULL, NULL},
4038 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4039 0, IA5StringValidate, IA5StringNormalize, NULL},
4040 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4041 0, integerValidate, integerNormalize, integerPretty},
4042 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4043 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4044 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4045 0, NULL, NULL, NULL},
4046 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4047 0, NULL, NULL, NULL},
4048 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4049 0, NULL, NULL, NULL},
4050 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4051 0, NULL, NULL, NULL},
4052 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4053 0, NULL, NULL, NULL},
4054 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4055 0, nameUIDValidate, nameUIDNormalize, NULL},
4056 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4057 0, NULL, NULL, NULL},
4058 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4059 0, numericStringValidate, numericStringNormalize, NULL},
4060 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4061 0, NULL, NULL, NULL},
4062 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4063 0, oidValidate, NULL, NULL},
4064 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4065 0, IA5StringValidate, IA5StringNormalize, NULL},
4066 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4067 0, blobValidate, NULL, NULL},
4068 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4069 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4070 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4071 0, NULL, NULL, NULL},
4072 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4073 0, NULL, NULL, NULL},
4074 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4075 0, printableStringValidate, IA5StringNormalize, NULL},
4076 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4077 X_BINARY X_NOT_H_R ")",
4078 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4079 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4080 0, printableStringValidate, IA5StringNormalize, NULL},
4081 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4082 0, NULL, NULL, NULL},
4083 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4084 0, printableStringValidate, IA5StringNormalize, NULL},
4085 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4086 0, utcTimeValidate, utcTimeNormalize, NULL},
4087 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4088 0, NULL, NULL, NULL},
4089 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4090 0, NULL, NULL, NULL},
4091 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4092 0, NULL, NULL, NULL},
4093 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4094 0, NULL, NULL, NULL},
4095 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4096 0, NULL, NULL, NULL},
4098 /* RFC 2307 NIS Syntaxes */
4099 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4100 0, nisNetgroupTripleValidate, NULL, NULL},
4101 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4102 0, bootParameterValidate, NULL, NULL},
4106 /* These OIDs are not published yet, but have been assigned */
4107 {"( 1.3.6.1.4.1.1466.115.121.1.9999 DESC 'Serial Number and Issuer' )",
4108 0, NULL, NULL, NULL},
4111 /* OpenLDAP Experimental Syntaxes */
4112 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4113 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4115 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4116 0, NULL, NULL, NULL},
4118 /* OpenLDAP Void Syntax */
4119 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4120 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4121 {NULL, 0, NULL, NULL, NULL}
4124 struct mrule_defs_rec {
4126 slap_mask_t mrd_usage;
4127 slap_mr_convert_func * mrd_convert;
4128 slap_mr_normalize_func * mrd_normalize;
4129 slap_mr_match_func * mrd_match;
4130 slap_mr_indexer_func * mrd_indexer;
4131 slap_mr_filter_func * mrd_filter;
4133 char * mrd_associated;
4137 * Other matching rules in X.520 that we do not use (yet):
4139 * 2.5.13.9 numericStringOrderingMatch
4140 * 2.5.13.15 integerOrderingMatch
4141 * 2.5.13.18 octetStringOrderingMatch
4142 * 2.5.13.19 octetStringSubstringsMatch
4143 * 2.5.13.25 uTCTimeMatch
4144 * 2.5.13.26 uTCTimeOrderingMatch
4145 * 2.5.13.31 directoryStringFirstComponentMatch
4146 * 2.5.13.32 wordMatch
4147 * 2.5.13.33 keywordMatch
4148 * 2.5.13.35 certificateMatch
4149 * 2.5.13.36 certificatePairExactMatch
4150 * 2.5.13.37 certificatePairMatch
4151 * 2.5.13.38 certificateListExactMatch
4152 * 2.5.13.39 certificateListMatch
4153 * 2.5.13.40 algorithmIdentifierMatch
4154 * 2.5.13.41 storedPrefixMatch
4155 * 2.5.13.42 attributeCertificateMatch
4156 * 2.5.13.43 readerAndKeyIDMatch
4157 * 2.5.13.44 attributeIntegrityMatch
4160 struct mrule_defs_rec mrule_defs[] = {
4162 * EQUALITY matching rules must be listed after associated APPROX
4163 * matching rules. So, we list all APPROX matching rules first.
4165 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4166 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4167 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4169 directoryStringApproxMatch,
4170 directoryStringApproxIndexer,
4171 directoryStringApproxFilter,
4174 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4175 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4176 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4178 IA5StringApproxMatch,
4179 IA5StringApproxIndexer,
4180 IA5StringApproxFilter,
4184 * Other matching rules
4187 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4188 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4189 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4191 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4194 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4195 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4196 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4198 dnMatch, dnIndexer, dnFilter,
4201 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4202 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4203 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4205 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4206 directoryStringApproxMatchOID },
4208 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4209 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4212 caseIgnoreOrderingMatch, NULL, NULL,
4215 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4216 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4217 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4219 caseExactIgnoreSubstringsMatch,
4220 caseExactIgnoreSubstringsIndexer,
4221 caseExactIgnoreSubstringsFilter,
4224 {"( 2.5.13.5 NAME 'caseExactMatch' "
4225 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4226 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4228 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4229 directoryStringApproxMatchOID },
4231 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4232 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4235 caseExactOrderingMatch, NULL, NULL,
4238 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4239 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4240 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4242 caseExactIgnoreSubstringsMatch,
4243 caseExactIgnoreSubstringsIndexer,
4244 caseExactIgnoreSubstringsFilter,
4247 {"( 2.5.13.8 NAME 'numericStringMatch' "
4248 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4249 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4252 caseIgnoreIA5Indexer,
4253 caseIgnoreIA5Filter,
4256 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4257 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4258 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4260 caseIgnoreIA5SubstringsMatch,
4261 caseIgnoreIA5SubstringsIndexer,
4262 caseIgnoreIA5SubstringsFilter,
4265 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4266 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4267 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4269 caseIgnoreListMatch, NULL, NULL,
4272 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4273 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4274 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4276 caseIgnoreListSubstringsMatch, NULL, NULL,
4279 {"( 2.5.13.13 NAME 'booleanMatch' "
4280 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4281 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4283 booleanMatch, NULL, NULL,
4286 {"( 2.5.13.14 NAME 'integerMatch' "
4287 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4288 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4290 integerMatch, integerIndexer, integerFilter,
4293 {"( 2.5.13.16 NAME 'bitStringMatch' "
4294 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4295 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4297 bitStringMatch, NULL, NULL,
4300 {"( 2.5.13.17 NAME 'octetStringMatch' "
4301 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4302 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4304 octetStringMatch, octetStringIndexer, octetStringFilter,
4307 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4308 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4309 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4311 telephoneNumberMatch,
4312 telephoneNumberIndexer,
4313 telephoneNumberFilter,
4316 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4317 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4318 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4320 telephoneNumberSubstringsMatch,
4321 telephoneNumberSubstringsIndexer,
4322 telephoneNumberSubstringsFilter,
4325 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4326 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4327 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4332 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4333 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4334 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4336 uniqueMemberMatch, NULL, NULL,
4339 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4340 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4341 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4343 protocolInformationMatch, NULL, NULL,
4346 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4347 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4348 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4350 generalizedTimeMatch, NULL, NULL,
4353 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4354 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4357 generalizedTimeOrderingMatch, NULL, NULL,
4360 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4361 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4362 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4364 integerFirstComponentMatch, NULL, NULL,
4367 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4368 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4369 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4371 objectIdentifierFirstComponentMatch, NULL, NULL,
4375 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4376 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.9999 )",
4377 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4379 certificateExactMatch, NULL, NULL,
4383 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4384 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4385 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4387 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4388 IA5StringApproxMatchOID },
4390 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4391 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4392 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4394 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4395 IA5StringApproxMatchOID },
4397 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4398 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4401 caseIgnoreIA5SubstringsMatch,
4402 caseIgnoreIA5SubstringsIndexer,
4403 caseIgnoreIA5SubstringsFilter,
4406 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4407 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4410 caseExactIA5SubstringsMatch,
4411 caseExactIA5SubstringsIndexer,
4412 caseExactIA5SubstringsFilter,
4415 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4416 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4419 authPasswordMatch, NULL, NULL,
4422 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4423 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4426 OpenLDAPaciMatch, NULL, NULL,
4429 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4430 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4433 integerBitAndMatch, NULL, NULL,
4436 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4437 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4440 integerBitOrMatch, NULL, NULL,
4443 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4452 /* we should only be called once (from main) */
4453 assert( schema_init_done == 0 );
4455 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4456 res = register_syntax( syntax_defs[i].sd_desc,
4457 syntax_defs[i].sd_flags,
4458 syntax_defs[i].sd_validate,
4459 syntax_defs[i].sd_normalize,
4460 syntax_defs[i].sd_pretty
4461 #ifdef SLAPD_BINARY_CONVERSION
4463 syntax_defs[i].sd_ber2str,
4464 syntax_defs[i].sd_str2ber
4469 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4470 syntax_defs[i].sd_desc );
4475 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4476 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4478 "schema_init: Ingoring unusable matching rule %s\n",
4479 mrule_defs[i].mrd_desc );
4483 res = register_matching_rule(
4484 mrule_defs[i].mrd_desc,
4485 mrule_defs[i].mrd_usage,
4486 mrule_defs[i].mrd_convert,
4487 mrule_defs[i].mrd_normalize,
4488 mrule_defs[i].mrd_match,
4489 mrule_defs[i].mrd_indexer,
4490 mrule_defs[i].mrd_filter,
4491 mrule_defs[i].mrd_associated );
4495 "schema_init: Error registering matching rule %s\n",
4496 mrule_defs[i].mrd_desc );
4500 schema_init_done = 1;
4501 return LDAP_SUCCESS;