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 check_time_syntax (struct berval *val,
3435 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3436 static int mdays[2][12] = {
3437 /* non-leap years */
3438 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3440 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3443 int part, c, tzoffset, leapyear = 0 ;
3445 if( val->bv_len == 0 ) {
3446 return LDAP_INVALID_SYNTAX;
3449 p = (char *)val->bv_val;
3450 e = p + val->bv_len;
3452 /* Ignore initial whitespace */
3453 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3457 if (e - p < 13 - (2 * start)) {
3458 return LDAP_INVALID_SYNTAX;
3461 for (part = 0; part < 9; part++) {
3465 for (part = start; part < 7; part++) {
3467 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3474 return LDAP_INVALID_SYNTAX;
3476 if (c < 0 || c > 9) {
3477 return LDAP_INVALID_SYNTAX;
3483 return LDAP_INVALID_SYNTAX;
3485 if (c < 0 || c > 9) {
3486 return LDAP_INVALID_SYNTAX;
3491 if (part == 2 || part == 3) {
3494 if (parts[part] < 0) {
3495 return LDAP_INVALID_SYNTAX;
3497 if (parts[part] > ceiling[part]) {
3498 return LDAP_INVALID_SYNTAX;
3502 /* leapyear check for the Gregorian calendar (year>1581) */
3503 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3504 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3509 if (parts[3] > mdays[leapyear][parts[2]]) {
3510 return LDAP_INVALID_SYNTAX;
3515 tzoffset = 0; /* UTC */
3516 } else if (c != '+' && c != '-') {
3517 return LDAP_INVALID_SYNTAX;
3521 } else /* c == '+' */ {
3526 return LDAP_INVALID_SYNTAX;
3529 for (part = 7; part < 9; part++) {
3531 if (c < 0 || c > 9) {
3532 return LDAP_INVALID_SYNTAX;
3537 if (c < 0 || c > 9) {
3538 return LDAP_INVALID_SYNTAX;
3542 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3543 return LDAP_INVALID_SYNTAX;
3548 /* Ignore trailing whitespace */
3549 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3553 return LDAP_INVALID_SYNTAX;
3556 switch ( tzoffset ) {
3557 case -1: /* negativ offset to UTC, ie west of Greenwich */
3558 parts[4] += parts[7];
3559 parts[5] += parts[8];
3560 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3564 c = mdays[leapyear][parts[2]];
3566 if (parts[part] > c) {
3567 parts[part] -= c + 1;
3572 case 1: /* positive offset to UTC, ie east of Greenwich */
3573 parts[4] -= parts[7];
3574 parts[5] -= parts[8];
3575 for (part = 6; --part > 0; ) {
3579 /* first arg to % needs to be non negativ */
3580 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3582 if (parts[part] < 0) {
3583 parts[part] += c + 1;
3588 case 0: /* already UTC */
3592 return LDAP_SUCCESS;
3599 struct berval **normalized )
3604 rc = check_time_syntax(val, 1, parts);
3605 if (rc != LDAP_SUCCESS) {
3610 out = ch_malloc( sizeof(struct berval) );
3612 return LBER_ERROR_MEMORY;
3615 out->bv_val = ch_malloc( 14 );
3616 if ( out->bv_val == NULL ) {
3618 return LBER_ERROR_MEMORY;
3621 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3622 parts[1], parts[2] + 1, parts[3] + 1,
3623 parts[4], parts[5], parts[6] );
3627 return LDAP_SUCCESS;
3637 return check_time_syntax(in, 1, parts);
3641 generalizedTimeValidate(
3647 return check_time_syntax(in, 0, parts);
3651 generalizedTimeNormalize(
3654 struct berval **normalized )
3659 rc = check_time_syntax(val, 0, parts);
3660 if (rc != LDAP_SUCCESS) {
3665 out = ch_malloc( sizeof(struct berval) );
3667 return LBER_ERROR_MEMORY;
3670 out->bv_val = ch_malloc( 16 );
3671 if ( out->bv_val == NULL ) {
3673 return LBER_ERROR_MEMORY;
3676 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3677 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3678 parts[4], parts[5], parts[6] );
3682 return LDAP_SUCCESS;
3686 nisNetgroupTripleValidate(
3688 struct berval *val )
3693 if ( val->bv_len == 0 ) {
3694 return LDAP_INVALID_SYNTAX;
3697 p = (char *)val->bv_val;
3698 e = p + val->bv_len;
3700 if ( *p != '(' /*')'*/ ) {
3701 return LDAP_INVALID_SYNTAX;
3704 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3708 return LDAP_INVALID_SYNTAX;
3711 } else if ( !ATTR_CHAR( *p ) ) {
3712 return LDAP_INVALID_SYNTAX;
3716 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3717 return LDAP_INVALID_SYNTAX;
3723 return LDAP_INVALID_SYNTAX;
3726 return LDAP_SUCCESS;
3730 bootParameterValidate(
3732 struct berval *val )
3736 if ( val->bv_len == 0 ) {
3737 return LDAP_INVALID_SYNTAX;
3740 p = (char *)val->bv_val;
3741 e = p + val->bv_len;
3744 for (; ( p < e ) && ( *p != '=' ); p++ ) {
3745 if ( !ATTR_CHAR( *p ) ) {
3746 return LDAP_INVALID_SYNTAX;
3751 return LDAP_INVALID_SYNTAX;
3755 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
3756 if ( !ATTR_CHAR( *p ) ) {
3757 return LDAP_INVALID_SYNTAX;
3762 return LDAP_INVALID_SYNTAX;
3766 for ( p++; p < e; p++ ) {
3767 if ( !ATTR_CHAR( *p ) ) {
3768 return LDAP_INVALID_SYNTAX;
3772 return LDAP_SUCCESS;
3775 struct syntax_defs_rec {
3778 slap_syntax_validate_func *sd_validate;
3779 slap_syntax_transform_func *sd_normalize;
3780 slap_syntax_transform_func *sd_pretty;
3781 #ifdef SLAPD_BINARY_CONVERSION
3782 slap_syntax_transform_func *sd_ber2str;
3783 slap_syntax_transform_func *sd_str2ber;
3787 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
3788 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
3790 struct syntax_defs_rec syntax_defs[] = {
3791 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
3792 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
3793 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
3794 0, NULL, NULL, NULL},
3795 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
3796 0, NULL, NULL, NULL},
3797 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
3798 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3799 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
3800 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3801 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
3802 0, bitStringValidate, NULL, NULL },
3803 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
3804 0, booleanValidate, NULL, NULL},
3805 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
3806 X_BINARY X_NOT_H_R ")",
3807 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3808 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
3809 X_BINARY X_NOT_H_R ")",
3810 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3811 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
3812 X_BINARY X_NOT_H_R ")",
3813 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3814 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
3815 0, countryStringValidate, IA5StringNormalize, NULL},
3816 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
3817 0, dnValidate, dnNormalize, dnPretty},
3818 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
3819 0, NULL, NULL, NULL},
3820 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
3821 0, NULL, NULL, NULL},
3822 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
3823 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3824 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
3825 0, NULL, NULL, NULL},
3826 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
3827 0, NULL, NULL, NULL},
3828 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
3829 0, NULL, NULL, NULL},
3830 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
3831 0, NULL, NULL, NULL},
3832 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
3833 0, NULL, NULL, NULL},
3834 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
3835 0, printablesStringValidate, IA5StringNormalize, NULL},
3836 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
3837 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
3838 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
3839 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
3840 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
3841 0, NULL, NULL, NULL},
3842 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
3843 0, IA5StringValidate, IA5StringNormalize, NULL},
3844 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
3845 0, integerValidate, integerNormalize, integerPretty},
3846 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
3847 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3848 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
3849 0, NULL, NULL, NULL},
3850 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
3851 0, NULL, NULL, NULL},
3852 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
3853 0, NULL, NULL, NULL},
3854 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
3855 0, NULL, NULL, NULL},
3856 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
3857 0, NULL, NULL, NULL},
3858 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
3859 0, nameUIDValidate, nameUIDNormalize, NULL},
3860 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
3861 0, NULL, NULL, NULL},
3862 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
3863 0, numericStringValidate, numericStringNormalize, NULL},
3864 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
3865 0, NULL, NULL, NULL},
3866 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
3867 0, oidValidate, NULL, NULL},
3868 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
3869 0, IA5StringValidate, IA5StringNormalize, NULL},
3870 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
3871 0, blobValidate, NULL, NULL},
3872 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
3873 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3874 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
3875 0, NULL, NULL, NULL},
3876 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
3877 0, NULL, NULL, NULL},
3878 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
3879 0, printableStringValidate, IA5StringNormalize, NULL},
3880 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
3881 X_BINARY X_NOT_H_R ")",
3882 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3883 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
3884 0, printableStringValidate, IA5StringNormalize, NULL},
3885 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
3886 0, NULL, NULL, NULL},
3887 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
3888 0, printableStringValidate, IA5StringNormalize, NULL},
3889 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
3890 0, utcTimeValidate, utcTimeNormalize, NULL},
3891 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
3892 0, NULL, NULL, NULL},
3893 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
3894 0, NULL, NULL, NULL},
3895 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
3896 0, NULL, NULL, NULL},
3897 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
3898 0, NULL, NULL, NULL},
3899 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
3900 0, NULL, NULL, NULL},
3902 /* RFC 2307 NIS Syntaxes */
3903 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
3904 0, nisNetgroupTripleValidate, NULL, NULL},
3905 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
3906 0, bootParameterValidate, NULL, NULL},
3908 /* OpenLDAP Experimental Syntaxes */
3909 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
3910 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
3912 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
3913 0, NULL, NULL, NULL},
3915 /* OpenLDAP Void Syntax */
3916 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
3917 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
3918 {NULL, 0, NULL, NULL, NULL}
3921 struct mrule_defs_rec {
3923 slap_mask_t mrd_usage;
3924 slap_mr_convert_func * mrd_convert;
3925 slap_mr_normalize_func * mrd_normalize;
3926 slap_mr_match_func * mrd_match;
3927 slap_mr_indexer_func * mrd_indexer;
3928 slap_mr_filter_func * mrd_filter;
3930 char * mrd_associated;
3934 * Other matching rules in X.520 that we do not use (yet):
3936 * 2.5.13.9 numericStringOrderingMatch
3937 * 2.5.13.15 integerOrderingMatch
3938 * 2.5.13.18 octetStringOrderingMatch
3939 * 2.5.13.19 octetStringSubstringsMatch
3940 * 2.5.13.25 uTCTimeMatch
3941 * 2.5.13.26 uTCTimeOrderingMatch
3942 * 2.5.13.31 directoryStringFirstComponentMatch
3943 * 2.5.13.32 wordMatch
3944 * 2.5.13.33 keywordMatch
3945 * 2.5.13.34 certificateExactMatch
3946 * 2.5.13.35 certificateMatch
3947 * 2.5.13.36 certificatePairExactMatch
3948 * 2.5.13.37 certificatePairMatch
3949 * 2.5.13.38 certificateListExactMatch
3950 * 2.5.13.39 certificateListMatch
3951 * 2.5.13.40 algorithmIdentifierMatch
3952 * 2.5.13.41 storedPrefixMatch
3953 * 2.5.13.42 attributeCertificateMatch
3954 * 2.5.13.43 readerAndKeyIDMatch
3955 * 2.5.13.44 attributeIntegrityMatch
3958 struct mrule_defs_rec mrule_defs[] = {
3960 * EQUALITY matching rules must be listed after associated APPROX
3961 * matching rules. So, we list all APPROX matching rules first.
3963 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
3964 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3965 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3967 directoryStringApproxMatch,
3968 directoryStringApproxIndexer,
3969 directoryStringApproxFilter,
3972 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
3973 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3974 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3976 IA5StringApproxMatch,
3977 IA5StringApproxIndexer,
3978 IA5StringApproxFilter,
3982 * Other matching rules
3985 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
3986 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3987 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3989 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
3992 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
3993 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
3994 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3996 dnMatch, dnIndexer, dnFilter,
3999 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4000 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4001 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4003 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4004 directoryStringApproxMatchOID },
4006 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4007 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4010 caseIgnoreOrderingMatch, NULL, NULL,
4013 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4014 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4015 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4017 caseExactIgnoreSubstringsMatch,
4018 caseExactIgnoreSubstringsIndexer,
4019 caseExactIgnoreSubstringsFilter,
4022 {"( 2.5.13.5 NAME 'caseExactMatch' "
4023 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4024 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4026 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4027 directoryStringApproxMatchOID },
4029 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4030 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4033 caseExactOrderingMatch, NULL, NULL,
4036 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4037 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4038 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4040 caseExactIgnoreSubstringsMatch,
4041 caseExactIgnoreSubstringsIndexer,
4042 caseExactIgnoreSubstringsFilter,
4045 {"( 2.5.13.8 NAME 'numericStringMatch' "
4046 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4047 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4050 caseIgnoreIA5Indexer,
4051 caseIgnoreIA5Filter,
4054 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4055 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4056 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4058 caseIgnoreIA5SubstringsMatch,
4059 caseIgnoreIA5SubstringsIndexer,
4060 caseIgnoreIA5SubstringsFilter,
4063 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4064 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4065 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4067 caseIgnoreListMatch, NULL, NULL,
4070 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4071 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4072 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4074 caseIgnoreListSubstringsMatch, NULL, NULL,
4077 {"( 2.5.13.13 NAME 'booleanMatch' "
4078 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4079 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4081 booleanMatch, NULL, NULL,
4084 {"( 2.5.13.14 NAME 'integerMatch' "
4085 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4086 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4088 integerMatch, integerIndexer, integerFilter,
4091 {"( 2.5.13.16 NAME 'bitStringMatch' "
4092 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4093 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4095 bitStringMatch, NULL, NULL,
4098 {"( 2.5.13.17 NAME 'octetStringMatch' "
4099 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4100 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4102 octetStringMatch, octetStringIndexer, octetStringFilter,
4105 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4106 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4107 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4109 telephoneNumberMatch,
4110 telephoneNumberIndexer,
4111 telephoneNumberFilter,
4114 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4115 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4116 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4118 telephoneNumberSubstringsMatch,
4119 telephoneNumberSubstringsIndexer,
4120 telephoneNumberSubstringsFilter,
4123 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4124 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4125 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4130 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4131 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4132 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4134 uniqueMemberMatch, NULL, NULL,
4137 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4138 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4139 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4141 protocolInformationMatch, NULL, NULL,
4144 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4145 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4146 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4148 generalizedTimeMatch, NULL, NULL,
4151 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4152 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4155 generalizedTimeOrderingMatch, NULL, NULL,
4158 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4159 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4160 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4162 integerFirstComponentMatch, NULL, NULL,
4165 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4166 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4167 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4169 objectIdentifierFirstComponentMatch, NULL, NULL,
4172 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4173 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4174 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4176 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4177 IA5StringApproxMatchOID },
4179 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4180 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4181 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4183 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4184 IA5StringApproxMatchOID },
4186 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4187 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4190 caseIgnoreIA5SubstringsMatch,
4191 caseIgnoreIA5SubstringsIndexer,
4192 caseIgnoreIA5SubstringsFilter,
4195 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4196 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4199 caseExactIA5SubstringsMatch,
4200 caseExactIA5SubstringsIndexer,
4201 caseExactIA5SubstringsFilter,
4204 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4205 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4208 authPasswordMatch, NULL, NULL,
4211 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4212 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4215 OpenLDAPaciMatch, NULL, NULL,
4218 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4219 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4222 integerBitAndMatch, NULL, NULL,
4225 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4226 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4229 integerBitOrMatch, NULL, NULL,
4232 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4241 /* we should only be called once (from main) */
4242 assert( schema_init_done == 0 );
4244 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4245 res = register_syntax( syntax_defs[i].sd_desc,
4246 syntax_defs[i].sd_flags,
4247 syntax_defs[i].sd_validate,
4248 syntax_defs[i].sd_normalize,
4249 syntax_defs[i].sd_pretty
4250 #ifdef SLAPD_BINARY_CONVERSION
4252 syntax_defs[i].sd_ber2str,
4253 syntax_defs[i].sd_str2ber
4258 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4259 syntax_defs[i].sd_desc );
4264 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4265 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4267 "schema_init: Ingoring unusable matching rule %s\n",
4268 mrule_defs[i].mrd_desc );
4272 res = register_matching_rule(
4273 mrule_defs[i].mrd_desc,
4274 mrule_defs[i].mrd_usage,
4275 mrule_defs[i].mrd_convert,
4276 mrule_defs[i].mrd_normalize,
4277 mrule_defs[i].mrd_match,
4278 mrule_defs[i].mrd_indexer,
4279 mrule_defs[i].mrd_filter,
4280 mrule_defs[i].mrd_associated );
4284 "schema_init: Error registering matching rule %s\n",
4285 mrule_defs[i].mrd_desc );
4289 schema_init_done = 1;
4290 return LDAP_SUCCESS;