1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
14 #include <ac/string.h>
15 #include <ac/socket.h>
20 #include "ldap_utf8.h"
22 #include "lutil_hash.h"
23 /* We should replace MD5 with a faster hash */
24 #define HASH_BYTES LUTIL_HASH_BYTES
25 #define HASH_CONTEXT lutil_HASH_CTX
26 #define HASH_Init(c) lutil_HASHInit(c)
27 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
28 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
30 /* recycled validatation routines */
31 #define berValidate blobValidate
33 /* unimplemented pretters */
35 #define integerPretty NULL
37 /* recycled matching routines */
38 #define bitStringMatch octetStringMatch
39 #define integerMatch caseIgnoreIA5Match
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
74 #define integerIndexer caseIgnoreIA5Indexer
75 #define integerFilter caseIgnoreIA5Filter
77 #define telephoneNumberIndexer caseIgnoreIA5Indexer
78 #define telephoneNumberFilter caseIgnoreIA5Filter
79 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
80 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
82 /* must match OIDs below */
83 #define caseExactMatchOID "2.5.13.5"
84 #define caseExactSubstringsMatchOID "2.5.13.7"
86 static char *strcasechr( const char *str, int c )
88 char *lower = strchr( str, TOLOWER(c) );
89 char *upper = strchr( str, TOUPPER(c) );
91 if( lower && upper ) {
92 return lower < upper ? lower : upper;
106 struct berval *value,
107 void *assertedValue )
109 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
112 match = memcmp( value->bv_val,
113 ((struct berval *) assertedValue)->bv_val,
121 /* Index generation function */
122 int octetStringIndexer(
127 struct berval *prefix,
128 struct berval **values,
129 struct berval ***keysp )
133 struct berval **keys;
134 HASH_CONTEXT HASHcontext;
135 unsigned char HASHdigest[HASH_BYTES];
136 struct berval digest;
137 digest.bv_val = HASHdigest;
138 digest.bv_len = sizeof(HASHdigest);
140 for( i=0; values[i] != NULL; i++ ) {
141 /* just count them */
144 /* we should have at least one value at this point */
147 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
149 slen = strlen( syntax->ssyn_oid );
150 mlen = strlen( mr->smr_oid );
152 for( i=0; values[i] != NULL; i++ ) {
153 HASH_Init( &HASHcontext );
154 if( prefix != NULL && prefix->bv_len > 0 ) {
155 HASH_Update( &HASHcontext,
156 prefix->bv_val, prefix->bv_len );
158 HASH_Update( &HASHcontext,
159 syntax->ssyn_oid, slen );
160 HASH_Update( &HASHcontext,
162 HASH_Update( &HASHcontext,
163 values[i]->bv_val, values[i]->bv_len );
164 HASH_Final( HASHdigest, &HASHcontext );
166 keys[i] = ber_bvdup( &digest );
176 /* Index generation function */
177 int octetStringFilter(
182 struct berval *prefix,
184 struct berval ***keysp )
187 struct berval **keys;
188 HASH_CONTEXT HASHcontext;
189 unsigned char HASHdigest[HASH_BYTES];
190 struct berval *value = (struct berval *) assertValue;
191 struct berval digest;
192 digest.bv_val = HASHdigest;
193 digest.bv_len = sizeof(HASHdigest);
195 slen = strlen( syntax->ssyn_oid );
196 mlen = strlen( mr->smr_oid );
198 keys = ch_malloc( sizeof( struct berval * ) * 2 );
200 HASH_Init( &HASHcontext );
201 if( prefix != NULL && prefix->bv_len > 0 ) {
202 HASH_Update( &HASHcontext,
203 prefix->bv_val, prefix->bv_len );
205 HASH_Update( &HASHcontext,
206 syntax->ssyn_oid, slen );
207 HASH_Update( &HASHcontext,
209 HASH_Update( &HASHcontext,
210 value->bv_val, value->bv_len );
211 HASH_Final( HASHdigest, &HASHcontext );
213 keys[0] = ber_bvdup( &digest );
229 if( in->bv_len == 0 ) return LDAP_SUCCESS;
231 dn = ch_strdup( in->bv_val );
234 return LDAP_INVALID_SYNTAX;
236 } else if ( strlen( in->bv_val ) != in->bv_len ) {
237 rc = LDAP_INVALID_SYNTAX;
239 } else if ( dn_validate( dn ) == NULL ) {
240 rc = LDAP_INVALID_SYNTAX;
254 struct berval **normalized )
258 if ( val->bv_len != 0 ) {
260 out = ber_bvstr( UTF8normalize( val->bv_val, UTF8_CASEFOLD ) );
262 dn = dn_validate( out->bv_val );
266 return LDAP_INVALID_SYNTAX;
270 out->bv_len = strlen( dn );
272 out = ber_bvdup( val );
285 struct berval *value,
286 void *assertedValue )
289 struct berval *asserted = (struct berval *) assertedValue;
291 match = value->bv_len - asserted->bv_len;
294 #ifdef USE_DN_NORMALIZE
295 match = strcmp( value->bv_val, asserted->bv_val );
297 match = strcasecmp( value->bv_val, asserted->bv_val );
302 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
303 "dnMatch: %d\n %s\n %s\n", match,
304 value->bv_val, asserted->bv_val ));
306 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
307 match, value->bv_val, asserted->bv_val );
323 if( in->bv_len == 0 ) return LDAP_SUCCESS;
325 dn = ber_bvdup( in );
327 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
328 /* assume presence of optional UID */
331 for(i=dn->bv_len-2; i>2; i--) {
332 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
336 if( dn->bv_val[i] != '\'' ) {
337 return LDAP_INVALID_SYNTAX;
339 if( dn->bv_val[i-1] != 'B' ) {
340 return LDAP_INVALID_SYNTAX;
342 if( dn->bv_val[i-2] != '#' ) {
343 return LDAP_INVALID_SYNTAX;
346 /* trim the UID to allow use of dn_validate */
347 dn->bv_val[i-2] = '\0';
350 rc = dn_validate( dn->bv_val ) == NULL
351 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
361 struct berval **normalized )
363 struct berval *out = ber_bvdup( val );
365 if( out->bv_len != 0 ) {
369 ber_len_t uidlen = 0;
371 if( out->bv_val[out->bv_len-1] == '\'' ) {
372 /* assume presence of optional UID */
373 uid = strrchr( out->bv_val, '#' );
377 return LDAP_INVALID_SYNTAX;
380 uidlen = out->bv_len - (out->bv_val - uid);
381 /* temporarily trim the UID */
385 #ifdef USE_DN_NORMALIZE
386 dn = dn_normalize( out->bv_val );
388 dn = dn_validate( out->bv_val );
393 return LDAP_INVALID_SYNTAX;
399 /* restore the separator */
402 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
406 out->bv_len = dnlen + uidlen;
418 /* any value allowed */
427 /* any value allowed */
438 /* very unforgiving validation, requires no normalization
439 * before simplistic matching
441 if( in->bv_len < 3 ) {
442 return LDAP_INVALID_SYNTAX;
445 if( in->bv_val[0] != 'B' ||
446 in->bv_val[1] != '\'' ||
447 in->bv_val[in->bv_len-1] != '\'' )
449 return LDAP_INVALID_SYNTAX;
452 for( i=in->bv_len-2; i>1; i-- ) {
453 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
454 return LDAP_INVALID_SYNTAX;
462 * Handling boolean syntax and matching is quite rigid.
463 * A more flexible approach would be to allow a variety
464 * of strings to be normalized and prettied into TRUE
472 /* very unforgiving validation, requires no normalization
473 * before simplistic matching
476 if( in->bv_len == 4 ) {
477 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
480 } else if( in->bv_len == 5 ) {
481 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
486 return LDAP_INVALID_SYNTAX;
495 struct berval *value,
496 void *assertedValue )
498 /* simplistic matching allowed by rigid validation */
499 struct berval *asserted = (struct berval *) assertedValue;
500 *matchp = value->bv_len != asserted->bv_len;
511 unsigned char *u = in->bv_val;
513 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
515 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
516 /* get the length indicated by the first byte */
517 len = LDAP_UTF8_CHARLEN( u );
519 /* should not be zero */
520 if( len == 0 ) return LDAP_INVALID_SYNTAX;
522 /* make sure len corresponds with the offset
523 to the next character */
524 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
527 if( count != 0 ) return LDAP_INVALID_SYNTAX;
536 struct berval **normalized )
538 struct berval *newval;
541 newval = ch_malloc( sizeof( struct berval ) );
545 /* Ignore initial whitespace */
546 while ( ldap_utf8_isspace( p ) ) {
552 return LDAP_INVALID_SYNTAX;
555 newval->bv_val = ch_strdup( p );
556 p = q = newval->bv_val;
562 if ( ldap_utf8_isspace( p ) ) {
563 len = LDAP_UTF8_COPY(q,p);
568 /* Ignore the extra whitespace */
569 while ( ldap_utf8_isspace( p ) ) {
573 len = LDAP_UTF8_COPY(q,p);
580 assert( *newval->bv_val );
581 assert( newval->bv_val < p );
584 /* cannot start with a space */
585 assert( !ldap_utf8_isspace(newval->bv_val) );
588 * If the string ended in space, backup the pointer one
589 * position. One is enough because the above loop collapsed
590 * all whitespace to a single space.
597 /* cannot end with a space */
598 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
603 newval->bv_len = q - newval->bv_val;
604 *normalized = newval;
609 /* Returns Unicode cannonically normalized copy of a substring assertion
610 * Skipping attribute description */
611 SubstringsAssertion *
612 UTF8SubstringsassertionNormalize(
613 SubstringsAssertion *sa,
616 SubstringsAssertion *nsa;
619 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
624 if( sa->sa_initial != NULL ) {
625 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, casefold ) );
626 if( nsa->sa_initial == NULL ) {
631 if( sa->sa_any != NULL ) {
632 for( i=0; sa->sa_any[i] != NULL; i++ ) {
635 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
636 for( i=0; sa->sa_any[i] != NULL; i++ ) {
637 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, casefold ) );
638 if( nsa->sa_any[i] == NULL ) {
642 nsa->sa_any[i] = NULL;
645 if( sa->sa_final != NULL ) {
646 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, casefold ) );
647 if( nsa->sa_final == NULL ) {
655 ch_free( nsa->sa_final );
656 ber_bvecfree( nsa->sa_any );
657 ch_free( nsa->sa_initial );
662 /* Strip characters with the 8th bit set */
675 while( *++q & 0x80 ) {
678 p = memmove(p, q, strlen(q) + 1);
686 #ifndef SLAPD_APPROX_OLDSINGLESTRING
688 #if defined(SLAPD_APPROX_INITIALS)
689 #define SLAPD_APPROX_DELIMITER "._ "
690 #define SLAPD_APPROX_WORDLEN 2
692 #define SLAPD_APPROX_DELIMITER " "
693 #define SLAPD_APPROX_WORDLEN 1
702 struct berval *value,
703 void *assertedValue )
705 char *val, *assertv, **values, **words, *c;
706 int i, count, len, nextchunk=0, nextavail=0;
709 /* Yes, this is necessary */
710 val = UTF8normalize( value->bv_val, UTF8_NOCASEFOLD );
715 strip8bitChars( val );
717 /* Yes, this is necessary */
718 assertv = UTF8normalize( ((struct berval *)assertedValue)->bv_val,
720 if( assertv == NULL ) {
725 strip8bitChars( assertv );
726 avlen = strlen( assertv );
728 /* Isolate how many words there are */
729 for( c=val,count=1; *c; c++ ) {
730 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
731 if ( c == NULL ) break;
736 /* Get a phonetic copy of each word */
737 words = (char **)ch_malloc( count * sizeof(char *) );
738 values = (char **)ch_malloc( count * sizeof(char *) );
739 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
741 values[i] = phonetic(c);
744 /* Work through the asserted value's words, to see if at least some
745 of the words are there, in the same order. */
747 while ( nextchunk < avlen ) {
748 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
753 #if defined(SLAPD_APPROX_INITIALS)
754 else if( len == 1 ) {
755 /* Single letter words need to at least match one word's initial */
756 for( i=nextavail; i<count; i++ )
757 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
764 /* Isolate the next word in the asserted value and phonetic it */
765 assertv[nextchunk+len] = '\0';
766 val = phonetic( assertv + nextchunk );
768 /* See if this phonetic chunk is in the remaining words of *value */
769 for( i=nextavail; i<count; i++ ){
770 if( !strcmp( val, values[i] ) ){
777 /* This chunk in the asserted value was NOT within the *value. */
783 /* Go on to the next word in the asserted value */
787 /* If some of the words were seen, call it a match */
788 if( nextavail > 0 ) {
797 for( i=0; i<count; i++ ) {
798 ch_free( values[i] );
813 struct berval *prefix,
814 struct berval **values,
815 struct berval ***keysp )
818 int i,j, len, wordcount, keycount=0;
819 struct berval **newkeys, **keys=NULL;
821 for( j=0; values[j] != NULL; j++ ) {
822 /* Yes, this is necessary */
823 val = UTF8normalize( values[j]->bv_val, UTF8_NOCASEFOLD );
824 strip8bitChars( val );
826 /* Isolate how many words there are. There will be a key for each */
827 for( wordcount=0,c=val; *c; c++) {
828 len = strcspn(c, SLAPD_APPROX_DELIMITER);
829 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
831 if (*c == '\0') break;
835 /* Allocate/increase storage to account for new keys */
836 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
837 * sizeof(struct berval *) );
838 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
839 if( keys ) ch_free( keys );
842 /* Get a phonetic copy of each word */
843 for( c=val,i=0; i<wordcount; c+=len+1 ) {
845 if( len < SLAPD_APPROX_WORDLEN ) continue;
846 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
847 keys[keycount]->bv_val = phonetic( c );
848 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
855 keys[keycount] = NULL;
867 struct berval *prefix,
869 struct berval ***keysp )
873 struct berval **keys;
875 /* Yes, this is necessary */
876 val = UTF8normalize( ((struct berval *)assertValue)->bv_val,
879 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
884 strip8bitChars( val );
886 /* Isolate how many words there are. There will be a key for each */
887 for( count=0,c=val; *c; c++) {
888 len = strcspn(c, SLAPD_APPROX_DELIMITER);
889 if( len >= SLAPD_APPROX_WORDLEN ) count++;
891 if (*c == '\0') break;
895 /* Allocate storage for new keys */
896 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
898 /* Get a phonetic copy of each word */
899 for( c=val,i=0; i<count; c+=len+1 ) {
901 if( len < SLAPD_APPROX_WORDLEN ) continue;
902 keys[i] = ber_bvstr( phonetic( c ) );
916 /* No other form of Approximate Matching is defined */
924 struct berval *value,
925 void *assertedValue )
927 char *vapprox, *avapprox;
930 /* Yes, this is necessary */
931 s = UTF8normalize( value->bv_val, UTF8_NOCASEFOLD );
937 /* Yes, this is necessary */
938 t = UTF8normalize( ((struct berval *)assertedValue)->bv_val,
946 vapprox = phonetic( strip8bitChars( s ) );
947 avapprox = phonetic( strip8bitChars( t ) );
952 *matchp = strcmp( vapprox, avapprox );
966 struct berval *prefix,
967 struct berval **values,
968 struct berval ***keysp )
971 struct berval **keys;
974 for( i=0; values[i] != NULL; i++ ) {
975 /* empty - just count them */
978 /* we should have at least one value at this point */
981 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
983 /* Copy each value and run it through phonetic() */
984 for( i=0; values[i] != NULL; i++ ) {
985 /* Yes, this is necessary */
986 s = UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD );
988 /* strip 8-bit chars and run through phonetic() */
989 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1005 struct berval *prefix,
1007 struct berval ***keysp )
1009 struct berval **keys;
1012 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1014 /* Yes, this is necessary */
1015 s = UTF8normalize( ((struct berval *)assertValue)->bv_val,
1020 /* strip 8-bit chars and run through phonetic() */
1021 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1027 return LDAP_SUCCESS;
1038 struct berval *value,
1039 void *assertedValue )
1041 *matchp = UTF8normcmp( value->bv_val,
1042 ((struct berval *) assertedValue)->bv_val,
1044 return LDAP_SUCCESS;
1048 caseExactIgnoreSubstringsMatch(
1053 struct berval *value,
1054 void *assertedValue )
1057 SubstringsAssertion *sub;
1061 char *nav, casefold;
1063 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1064 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1066 nav = UTF8normalize( value->bv_val, casefold );
1072 left.bv_len = strlen( nav );
1074 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1080 /* Add up asserted input length */
1081 if( sub->sa_initial ) {
1082 inlen += sub->sa_initial->bv_len;
1085 for(i=0; sub->sa_any[i] != NULL; i++) {
1086 inlen += sub->sa_any[i]->bv_len;
1089 if( sub->sa_final ) {
1090 inlen += sub->sa_final->bv_len;
1093 if( sub->sa_initial ) {
1094 if( inlen > left.bv_len ) {
1099 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1100 sub->sa_initial->bv_len );
1106 left.bv_val += sub->sa_initial->bv_len;
1107 left.bv_len -= sub->sa_initial->bv_len;
1108 inlen -= sub->sa_initial->bv_len;
1111 if( sub->sa_final ) {
1112 if( inlen > left.bv_len ) {
1117 match = strncmp( sub->sa_final->bv_val,
1118 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1119 sub->sa_final->bv_len );
1125 left.bv_len -= sub->sa_final->bv_len;
1126 inlen -= sub->sa_final->bv_len;
1130 for(i=0; sub->sa_any[i]; i++) {
1135 if( inlen > left.bv_len ) {
1136 /* not enough length */
1141 if( sub->sa_any[i]->bv_len == 0 ) {
1145 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1152 idx = p - left.bv_val;
1153 assert( idx < left.bv_len );
1155 if( idx >= left.bv_len ) {
1156 /* this shouldn't happen */
1163 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1164 /* not enough left */
1169 match = strncmp( left.bv_val,
1170 sub->sa_any[i]->bv_val,
1171 sub->sa_any[i]->bv_len );
1179 left.bv_val += sub->sa_any[i]->bv_len;
1180 left.bv_len -= sub->sa_any[i]->bv_len;
1181 inlen -= sub->sa_any[i]->bv_len;
1188 ch_free( sub->sa_final );
1189 ber_bvecfree( sub->sa_any );
1190 ch_free( sub->sa_initial );
1194 return LDAP_SUCCESS;
1197 /* Index generation function */
1198 int caseExactIgnoreIndexer(
1203 struct berval *prefix,
1204 struct berval **values,
1205 struct berval ***keysp )
1210 struct berval **keys;
1211 HASH_CONTEXT HASHcontext;
1212 unsigned char HASHdigest[HASH_BYTES];
1213 struct berval digest;
1214 digest.bv_val = HASHdigest;
1215 digest.bv_len = sizeof(HASHdigest);
1217 for( i=0; values[i] != NULL; i++ ) {
1218 /* empty - just count them */
1221 /* we should have at least one value at this point */
1224 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1226 slen = strlen( syntax->ssyn_oid );
1227 mlen = strlen( mr->smr_oid );
1229 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1230 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1232 for( i=0; values[i] != NULL; i++ ) {
1233 struct berval *value;
1234 value = ber_bvstr( UTF8normalize( values[i]->bv_val,
1237 HASH_Init( &HASHcontext );
1238 if( prefix != NULL && prefix->bv_len > 0 ) {
1239 HASH_Update( &HASHcontext,
1240 prefix->bv_val, prefix->bv_len );
1242 HASH_Update( &HASHcontext,
1243 syntax->ssyn_oid, slen );
1244 HASH_Update( &HASHcontext,
1245 mr->smr_oid, mlen );
1246 HASH_Update( &HASHcontext,
1247 value->bv_val, value->bv_len );
1248 HASH_Final( HASHdigest, &HASHcontext );
1250 ber_bvfree( value );
1252 keys[i] = ber_bvdup( &digest );
1257 return LDAP_SUCCESS;
1260 /* Index generation function */
1261 int caseExactIgnoreFilter(
1266 struct berval *prefix,
1268 struct berval ***keysp )
1272 struct berval **keys;
1273 HASH_CONTEXT HASHcontext;
1274 unsigned char HASHdigest[HASH_BYTES];
1275 struct berval *value;
1276 struct berval digest;
1277 digest.bv_val = HASHdigest;
1278 digest.bv_len = sizeof(HASHdigest);
1280 slen = strlen( syntax->ssyn_oid );
1281 mlen = strlen( mr->smr_oid );
1283 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1284 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1286 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val,
1288 /* This usually happens if filter contains bad UTF8 */
1289 if( value == NULL ) {
1290 keys = ch_malloc( sizeof( struct berval * ) );
1292 return LDAP_SUCCESS;
1295 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1297 HASH_Init( &HASHcontext );
1298 if( prefix != NULL && prefix->bv_len > 0 ) {
1299 HASH_Update( &HASHcontext,
1300 prefix->bv_val, prefix->bv_len );
1302 HASH_Update( &HASHcontext,
1303 syntax->ssyn_oid, slen );
1304 HASH_Update( &HASHcontext,
1305 mr->smr_oid, mlen );
1306 HASH_Update( &HASHcontext,
1307 value->bv_val, value->bv_len );
1308 HASH_Final( HASHdigest, &HASHcontext );
1310 keys[0] = ber_bvdup( &digest );
1313 ber_bvfree( value );
1316 return LDAP_SUCCESS;
1319 /* Substrings Index generation function */
1320 int caseExactIgnoreSubstringsIndexer(
1325 struct berval *prefix,
1326 struct berval **values,
1327 struct berval ***keysp )
1332 struct berval **keys;
1333 struct berval **nvalues;
1335 HASH_CONTEXT HASHcontext;
1336 unsigned char HASHdigest[HASH_BYTES];
1337 struct berval digest;
1338 digest.bv_val = HASHdigest;
1339 digest.bv_len = sizeof(HASHdigest);
1343 for( i=0; values[i] != NULL; i++ ) {
1344 /* empty - just count them */
1347 /* we should have at least one value at this point */
1350 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1351 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1353 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1354 for( i=0; values[i] != NULL; i++ ) {
1355 nvalues[i] = ber_bvstr( UTF8normalize( values[i]->bv_val,
1361 for( i=0; values[i] != NULL; i++ ) {
1362 /* count number of indices to generate */
1363 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1367 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1368 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1369 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1370 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1372 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1376 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1377 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1378 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1382 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1383 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1384 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1385 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1387 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1393 /* no keys to generate */
1395 return LDAP_SUCCESS;
1398 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1400 slen = strlen( syntax->ssyn_oid );
1401 mlen = strlen( mr->smr_oid );
1404 for( i=0; values[i] != NULL; i++ ) {
1406 struct berval *value;
1408 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1412 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1413 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1415 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1416 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1418 for( j=0; j<max; j++ ) {
1419 HASH_Init( &HASHcontext );
1420 if( prefix != NULL && prefix->bv_len > 0 ) {
1421 HASH_Update( &HASHcontext,
1422 prefix->bv_val, prefix->bv_len );
1425 HASH_Update( &HASHcontext,
1426 &pre, sizeof( pre ) );
1427 HASH_Update( &HASHcontext,
1428 syntax->ssyn_oid, slen );
1429 HASH_Update( &HASHcontext,
1430 mr->smr_oid, mlen );
1431 HASH_Update( &HASHcontext,
1433 SLAP_INDEX_SUBSTR_MAXLEN );
1434 HASH_Final( HASHdigest, &HASHcontext );
1436 keys[nkeys++] = ber_bvdup( &digest );
1440 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1441 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1443 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1446 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1447 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1448 HASH_Init( &HASHcontext );
1449 if( prefix != NULL && prefix->bv_len > 0 ) {
1450 HASH_Update( &HASHcontext,
1451 prefix->bv_val, prefix->bv_len );
1453 HASH_Update( &HASHcontext,
1454 &pre, sizeof( pre ) );
1455 HASH_Update( &HASHcontext,
1456 syntax->ssyn_oid, slen );
1457 HASH_Update( &HASHcontext,
1458 mr->smr_oid, mlen );
1459 HASH_Update( &HASHcontext,
1461 HASH_Final( HASHdigest, &HASHcontext );
1463 keys[nkeys++] = ber_bvdup( &digest );
1466 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1467 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1468 HASH_Init( &HASHcontext );
1469 if( prefix != NULL && prefix->bv_len > 0 ) {
1470 HASH_Update( &HASHcontext,
1471 prefix->bv_val, prefix->bv_len );
1473 HASH_Update( &HASHcontext,
1474 &pre, sizeof( pre ) );
1475 HASH_Update( &HASHcontext,
1476 syntax->ssyn_oid, slen );
1477 HASH_Update( &HASHcontext,
1478 mr->smr_oid, mlen );
1479 HASH_Update( &HASHcontext,
1480 &value->bv_val[value->bv_len-j], j );
1481 HASH_Final( HASHdigest, &HASHcontext );
1483 keys[nkeys++] = ber_bvdup( &digest );
1498 ber_bvecfree( nvalues );
1500 return LDAP_SUCCESS;
1503 int caseExactIgnoreSubstringsFilter(
1508 struct berval *prefix,
1510 struct berval ***keysp )
1512 SubstringsAssertion *sa;
1514 ber_len_t nkeys = 0;
1515 size_t slen, mlen, klen;
1516 struct berval **keys;
1517 HASH_CONTEXT HASHcontext;
1518 unsigned char HASHdigest[HASH_BYTES];
1519 struct berval *value;
1520 struct berval digest;
1522 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1523 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1525 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1528 return LDAP_SUCCESS;
1531 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1532 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1537 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1539 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1540 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1541 /* don't bother accounting for stepping */
1542 nkeys += sa->sa_any[i]->bv_len -
1543 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1548 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1549 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1556 return LDAP_SUCCESS;
1559 digest.bv_val = HASHdigest;
1560 digest.bv_len = sizeof(HASHdigest);
1562 slen = strlen( syntax->ssyn_oid );
1563 mlen = strlen( mr->smr_oid );
1565 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1568 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1569 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1571 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1572 value = sa->sa_initial;
1574 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1575 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1577 HASH_Init( &HASHcontext );
1578 if( prefix != NULL && prefix->bv_len > 0 ) {
1579 HASH_Update( &HASHcontext,
1580 prefix->bv_val, prefix->bv_len );
1582 HASH_Update( &HASHcontext,
1583 &pre, sizeof( pre ) );
1584 HASH_Update( &HASHcontext,
1585 syntax->ssyn_oid, slen );
1586 HASH_Update( &HASHcontext,
1587 mr->smr_oid, mlen );
1588 HASH_Update( &HASHcontext,
1589 value->bv_val, klen );
1590 HASH_Final( HASHdigest, &HASHcontext );
1592 keys[nkeys++] = ber_bvdup( &digest );
1595 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1597 pre = SLAP_INDEX_SUBSTR_PREFIX;
1598 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1600 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1601 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1605 value = sa->sa_any[i];
1608 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1609 j += SLAP_INDEX_SUBSTR_STEP )
1611 HASH_Init( &HASHcontext );
1612 if( prefix != NULL && prefix->bv_len > 0 ) {
1613 HASH_Update( &HASHcontext,
1614 prefix->bv_val, prefix->bv_len );
1616 HASH_Update( &HASHcontext,
1617 &pre, sizeof( pre ) );
1618 HASH_Update( &HASHcontext,
1619 syntax->ssyn_oid, slen );
1620 HASH_Update( &HASHcontext,
1621 mr->smr_oid, mlen );
1622 HASH_Update( &HASHcontext,
1623 &value->bv_val[j], klen );
1624 HASH_Final( HASHdigest, &HASHcontext );
1626 keys[nkeys++] = ber_bvdup( &digest );
1632 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1633 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1635 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1636 value = sa->sa_final;
1638 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1639 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1641 HASH_Init( &HASHcontext );
1642 if( prefix != NULL && prefix->bv_len > 0 ) {
1643 HASH_Update( &HASHcontext,
1644 prefix->bv_val, prefix->bv_len );
1646 HASH_Update( &HASHcontext,
1647 &pre, sizeof( pre ) );
1648 HASH_Update( &HASHcontext,
1649 syntax->ssyn_oid, slen );
1650 HASH_Update( &HASHcontext,
1651 mr->smr_oid, mlen );
1652 HASH_Update( &HASHcontext,
1653 &value->bv_val[value->bv_len-klen], klen );
1654 HASH_Final( HASHdigest, &HASHcontext );
1656 keys[nkeys++] = ber_bvdup( &digest );
1666 ch_free( sa->sa_final );
1667 ber_bvecfree( sa->sa_any );
1668 ch_free( sa->sa_initial );
1671 return LDAP_SUCCESS;
1680 struct berval *value,
1681 void *assertedValue )
1683 *matchp = UTF8normcmp( value->bv_val,
1684 ((struct berval *) assertedValue)->bv_val,
1686 return LDAP_SUCCESS;
1692 struct berval *val )
1696 if( val->bv_len == 0 ) {
1697 /* disallow empty strings */
1698 return LDAP_INVALID_SYNTAX;
1701 if( OID_LEADCHAR(val->bv_val[0]) ) {
1703 for(i=1; i < val->bv_len; i++) {
1704 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1705 if( dot++ ) return 1;
1706 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1709 return LDAP_INVALID_SYNTAX;
1713 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1715 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1716 for(i=1; i < val->bv_len; i++) {
1717 if( !DESC_CHAR(val->bv_val[i] ) ) {
1718 return LDAP_INVALID_SYNTAX;
1722 return LDAP_SUCCESS;
1725 return LDAP_INVALID_SYNTAX;
1731 struct berval *val )
1735 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1737 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
1738 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1739 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1740 return LDAP_INVALID_SYNTAX;
1743 for(i=1; i < val->bv_len; i++) {
1744 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1747 return LDAP_SUCCESS;
1754 struct berval **normalized )
1757 struct berval *newval;
1763 negative = ( *p == '-' );
1764 if( *p == '-' || *p == '+' ) p++;
1766 /* Ignore leading zeros */
1767 while ( *p == '0' ) p++;
1769 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
1772 newval->bv_val = ch_strdup("0");
1777 newval->bv_val = ch_malloc( val->bv_len + 1 );
1781 newval->bv_val[newval->bv_len++] = '-';
1784 for( ; *p != '\0'; p++ ) {
1785 newval->bv_val[newval->bv_len++] = *p;
1789 *normalized = newval;
1790 return LDAP_SUCCESS;
1794 countryStringValidate(
1796 struct berval *val )
1798 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1800 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1801 return LDAP_INVALID_SYNTAX;
1803 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1804 return LDAP_INVALID_SYNTAX;
1807 return LDAP_SUCCESS;
1811 printableStringValidate(
1813 struct berval *val )
1817 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1819 for(i=0; i < val->bv_len; i++) {
1820 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1821 return LDAP_INVALID_SYNTAX;
1825 return LDAP_SUCCESS;
1829 printablesStringValidate(
1831 struct berval *val )
1835 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1837 for(i=0; i < val->bv_len; i++) {
1838 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1839 return LDAP_INVALID_SYNTAX;
1843 return LDAP_SUCCESS;
1849 struct berval *val )
1853 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1855 for(i=0; i < val->bv_len; i++) {
1856 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1859 return LDAP_SUCCESS;
1866 struct berval **normalized )
1868 struct berval *newval;
1871 newval = ch_malloc( sizeof( struct berval ) );
1875 /* Ignore initial whitespace */
1876 while ( ASCII_SPACE( *p ) ) {
1882 return LDAP_INVALID_SYNTAX;
1885 newval->bv_val = ch_strdup( p );
1886 p = q = newval->bv_val;
1889 if ( ASCII_SPACE( *p ) ) {
1892 /* Ignore the extra whitespace */
1893 while ( ASCII_SPACE( *p ) ) {
1901 assert( *newval->bv_val );
1902 assert( newval->bv_val < p );
1905 /* cannot start with a space */
1906 assert( !ASCII_SPACE(*newval->bv_val) );
1909 * If the string ended in space, backup the pointer one
1910 * position. One is enough because the above loop collapsed
1911 * all whitespace to a single space.
1914 if ( ASCII_SPACE( q[-1] ) ) {
1918 /* cannot end with a space */
1919 assert( !ASCII_SPACE( q[-1] ) );
1921 /* null terminate */
1924 newval->bv_len = q - newval->bv_val;
1925 *normalized = newval;
1927 return LDAP_SUCCESS;
1936 struct berval *value,
1937 void *assertedValue )
1939 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1942 match = strncmp( value->bv_val,
1943 ((struct berval *) assertedValue)->bv_val,
1948 return LDAP_SUCCESS;
1952 caseExactIA5SubstringsMatch(
1957 struct berval *value,
1958 void *assertedValue )
1961 SubstringsAssertion *sub = assertedValue;
1962 struct berval left = *value;
1966 /* Add up asserted input length */
1967 if( sub->sa_initial ) {
1968 inlen += sub->sa_initial->bv_len;
1971 for(i=0; sub->sa_any[i] != NULL; i++) {
1972 inlen += sub->sa_any[i]->bv_len;
1975 if( sub->sa_final ) {
1976 inlen += sub->sa_final->bv_len;
1979 if( sub->sa_initial ) {
1980 if( inlen > left.bv_len ) {
1985 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1986 sub->sa_initial->bv_len );
1992 left.bv_val += sub->sa_initial->bv_len;
1993 left.bv_len -= sub->sa_initial->bv_len;
1994 inlen -= sub->sa_initial->bv_len;
1997 if( sub->sa_final ) {
1998 if( inlen > left.bv_len ) {
2003 match = strncmp( sub->sa_final->bv_val,
2004 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2005 sub->sa_final->bv_len );
2011 left.bv_len -= sub->sa_final->bv_len;
2012 inlen -= sub->sa_final->bv_len;
2016 for(i=0; sub->sa_any[i]; i++) {
2021 if( inlen > left.bv_len ) {
2022 /* not enough length */
2027 if( sub->sa_any[i]->bv_len == 0 ) {
2031 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2038 idx = p - left.bv_val;
2039 assert( idx < left.bv_len );
2041 if( idx >= left.bv_len ) {
2042 /* this shouldn't happen */
2049 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2050 /* not enough left */
2055 match = strncmp( left.bv_val,
2056 sub->sa_any[i]->bv_val,
2057 sub->sa_any[i]->bv_len );
2065 left.bv_val += sub->sa_any[i]->bv_len;
2066 left.bv_len -= sub->sa_any[i]->bv_len;
2067 inlen -= sub->sa_any[i]->bv_len;
2073 return LDAP_SUCCESS;
2076 /* Index generation function */
2077 int caseExactIA5Indexer(
2082 struct berval *prefix,
2083 struct berval **values,
2084 struct berval ***keysp )
2088 struct berval **keys;
2089 HASH_CONTEXT HASHcontext;
2090 unsigned char HASHdigest[HASH_BYTES];
2091 struct berval digest;
2092 digest.bv_val = HASHdigest;
2093 digest.bv_len = sizeof(HASHdigest);
2095 for( i=0; values[i] != NULL; i++ ) {
2096 /* empty - just count them */
2099 /* we should have at least one value at this point */
2102 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2104 slen = strlen( syntax->ssyn_oid );
2105 mlen = strlen( mr->smr_oid );
2107 for( i=0; values[i] != NULL; i++ ) {
2108 struct berval *value = values[i];
2110 HASH_Init( &HASHcontext );
2111 if( prefix != NULL && prefix->bv_len > 0 ) {
2112 HASH_Update( &HASHcontext,
2113 prefix->bv_val, prefix->bv_len );
2115 HASH_Update( &HASHcontext,
2116 syntax->ssyn_oid, slen );
2117 HASH_Update( &HASHcontext,
2118 mr->smr_oid, mlen );
2119 HASH_Update( &HASHcontext,
2120 value->bv_val, value->bv_len );
2121 HASH_Final( HASHdigest, &HASHcontext );
2123 keys[i] = ber_bvdup( &digest );
2128 return LDAP_SUCCESS;
2131 /* Index generation function */
2132 int caseExactIA5Filter(
2137 struct berval *prefix,
2139 struct berval ***keysp )
2142 struct berval **keys;
2143 HASH_CONTEXT HASHcontext;
2144 unsigned char HASHdigest[HASH_BYTES];
2145 struct berval *value;
2146 struct berval digest;
2147 digest.bv_val = HASHdigest;
2148 digest.bv_len = sizeof(HASHdigest);
2150 slen = strlen( syntax->ssyn_oid );
2151 mlen = strlen( mr->smr_oid );
2153 value = (struct berval *) assertValue;
2155 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2157 HASH_Init( &HASHcontext );
2158 if( prefix != NULL && prefix->bv_len > 0 ) {
2159 HASH_Update( &HASHcontext,
2160 prefix->bv_val, prefix->bv_len );
2162 HASH_Update( &HASHcontext,
2163 syntax->ssyn_oid, slen );
2164 HASH_Update( &HASHcontext,
2165 mr->smr_oid, mlen );
2166 HASH_Update( &HASHcontext,
2167 value->bv_val, value->bv_len );
2168 HASH_Final( HASHdigest, &HASHcontext );
2170 keys[0] = ber_bvdup( &digest );
2174 return LDAP_SUCCESS;
2177 /* Substrings Index generation function */
2178 int caseExactIA5SubstringsIndexer(
2183 struct berval *prefix,
2184 struct berval **values,
2185 struct berval ***keysp )
2189 struct berval **keys;
2190 HASH_CONTEXT HASHcontext;
2191 unsigned char HASHdigest[HASH_BYTES];
2192 struct berval digest;
2193 digest.bv_val = HASHdigest;
2194 digest.bv_len = sizeof(HASHdigest);
2196 /* we should have at least one value at this point */
2197 assert( values != NULL && values[0] != NULL );
2200 for( i=0; values[i] != NULL; i++ ) {
2201 /* count number of indices to generate */
2202 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2206 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2207 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2208 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2209 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2211 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2215 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2216 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2217 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2221 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2222 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2223 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2224 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2226 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2232 /* no keys to generate */
2234 return LDAP_SUCCESS;
2237 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2239 slen = strlen( syntax->ssyn_oid );
2240 mlen = strlen( mr->smr_oid );
2243 for( i=0; values[i] != NULL; i++ ) {
2245 struct berval *value;
2248 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2250 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2251 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2253 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2254 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2256 for( j=0; j<max; j++ ) {
2257 HASH_Init( &HASHcontext );
2258 if( prefix != NULL && prefix->bv_len > 0 ) {
2259 HASH_Update( &HASHcontext,
2260 prefix->bv_val, prefix->bv_len );
2263 HASH_Update( &HASHcontext,
2264 &pre, sizeof( pre ) );
2265 HASH_Update( &HASHcontext,
2266 syntax->ssyn_oid, slen );
2267 HASH_Update( &HASHcontext,
2268 mr->smr_oid, mlen );
2269 HASH_Update( &HASHcontext,
2271 SLAP_INDEX_SUBSTR_MAXLEN );
2272 HASH_Final( HASHdigest, &HASHcontext );
2274 keys[nkeys++] = ber_bvdup( &digest );
2278 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2279 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2281 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2284 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2285 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2286 HASH_Init( &HASHcontext );
2287 if( prefix != NULL && prefix->bv_len > 0 ) {
2288 HASH_Update( &HASHcontext,
2289 prefix->bv_val, prefix->bv_len );
2291 HASH_Update( &HASHcontext,
2292 &pre, sizeof( pre ) );
2293 HASH_Update( &HASHcontext,
2294 syntax->ssyn_oid, slen );
2295 HASH_Update( &HASHcontext,
2296 mr->smr_oid, mlen );
2297 HASH_Update( &HASHcontext,
2299 HASH_Final( HASHdigest, &HASHcontext );
2301 keys[nkeys++] = ber_bvdup( &digest );
2304 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2305 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2306 HASH_Init( &HASHcontext );
2307 if( prefix != NULL && prefix->bv_len > 0 ) {
2308 HASH_Update( &HASHcontext,
2309 prefix->bv_val, prefix->bv_len );
2311 HASH_Update( &HASHcontext,
2312 &pre, sizeof( pre ) );
2313 HASH_Update( &HASHcontext,
2314 syntax->ssyn_oid, slen );
2315 HASH_Update( &HASHcontext,
2316 mr->smr_oid, mlen );
2317 HASH_Update( &HASHcontext,
2318 &value->bv_val[value->bv_len-j], j );
2319 HASH_Final( HASHdigest, &HASHcontext );
2321 keys[nkeys++] = ber_bvdup( &digest );
2335 return LDAP_SUCCESS;
2338 int caseExactIA5SubstringsFilter(
2343 struct berval *prefix,
2345 struct berval ***keysp )
2347 SubstringsAssertion *sa = assertValue;
2349 ber_len_t nkeys = 0;
2350 size_t slen, mlen, klen;
2351 struct berval **keys;
2352 HASH_CONTEXT HASHcontext;
2353 unsigned char HASHdigest[HASH_BYTES];
2354 struct berval *value;
2355 struct berval digest;
2357 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2358 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2363 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2365 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2366 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2367 /* don't bother accounting for stepping */
2368 nkeys += sa->sa_any[i]->bv_len -
2369 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2374 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2375 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2382 return LDAP_SUCCESS;
2385 digest.bv_val = HASHdigest;
2386 digest.bv_len = sizeof(HASHdigest);
2388 slen = strlen( syntax->ssyn_oid );
2389 mlen = strlen( mr->smr_oid );
2391 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2394 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2395 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2397 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2398 value = sa->sa_initial;
2400 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2401 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2403 HASH_Init( &HASHcontext );
2404 if( prefix != NULL && prefix->bv_len > 0 ) {
2405 HASH_Update( &HASHcontext,
2406 prefix->bv_val, prefix->bv_len );
2408 HASH_Update( &HASHcontext,
2409 &pre, sizeof( pre ) );
2410 HASH_Update( &HASHcontext,
2411 syntax->ssyn_oid, slen );
2412 HASH_Update( &HASHcontext,
2413 mr->smr_oid, mlen );
2414 HASH_Update( &HASHcontext,
2415 value->bv_val, klen );
2416 HASH_Final( HASHdigest, &HASHcontext );
2418 keys[nkeys++] = ber_bvdup( &digest );
2421 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2423 pre = SLAP_INDEX_SUBSTR_PREFIX;
2424 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2426 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2427 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2431 value = sa->sa_any[i];
2434 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2435 j += SLAP_INDEX_SUBSTR_STEP )
2437 HASH_Init( &HASHcontext );
2438 if( prefix != NULL && prefix->bv_len > 0 ) {
2439 HASH_Update( &HASHcontext,
2440 prefix->bv_val, prefix->bv_len );
2442 HASH_Update( &HASHcontext,
2443 &pre, sizeof( pre ) );
2444 HASH_Update( &HASHcontext,
2445 syntax->ssyn_oid, slen );
2446 HASH_Update( &HASHcontext,
2447 mr->smr_oid, mlen );
2448 HASH_Update( &HASHcontext,
2449 &value->bv_val[j], klen );
2450 HASH_Final( HASHdigest, &HASHcontext );
2452 keys[nkeys++] = ber_bvdup( &digest );
2457 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2458 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2460 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2461 value = sa->sa_final;
2463 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2464 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2466 HASH_Init( &HASHcontext );
2467 if( prefix != NULL && prefix->bv_len > 0 ) {
2468 HASH_Update( &HASHcontext,
2469 prefix->bv_val, prefix->bv_len );
2471 HASH_Update( &HASHcontext,
2472 &pre, sizeof( pre ) );
2473 HASH_Update( &HASHcontext,
2474 syntax->ssyn_oid, slen );
2475 HASH_Update( &HASHcontext,
2476 mr->smr_oid, mlen );
2477 HASH_Update( &HASHcontext,
2478 &value->bv_val[value->bv_len-klen], klen );
2479 HASH_Final( HASHdigest, &HASHcontext );
2481 keys[nkeys++] = ber_bvdup( &digest );
2492 return LDAP_SUCCESS;
2501 struct berval *value,
2502 void *assertedValue )
2504 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2506 if( match == 0 && value->bv_len ) {
2507 match = strncasecmp( value->bv_val,
2508 ((struct berval *) assertedValue)->bv_val,
2513 return LDAP_SUCCESS;
2517 caseIgnoreIA5SubstringsMatch(
2522 struct berval *value,
2523 void *assertedValue )
2526 SubstringsAssertion *sub = assertedValue;
2527 struct berval left = *value;
2531 /* Add up asserted input length */
2532 if( sub->sa_initial ) {
2533 inlen += sub->sa_initial->bv_len;
2536 for(i=0; sub->sa_any[i] != NULL; i++) {
2537 inlen += sub->sa_any[i]->bv_len;
2540 if( sub->sa_final ) {
2541 inlen += sub->sa_final->bv_len;
2544 if( sub->sa_initial ) {
2545 if( inlen > left.bv_len ) {
2550 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2551 sub->sa_initial->bv_len );
2557 left.bv_val += sub->sa_initial->bv_len;
2558 left.bv_len -= sub->sa_initial->bv_len;
2559 inlen -= sub->sa_initial->bv_len;
2562 if( sub->sa_final ) {
2563 if( inlen > left.bv_len ) {
2568 match = strncasecmp( sub->sa_final->bv_val,
2569 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2570 sub->sa_final->bv_len );
2576 left.bv_len -= sub->sa_final->bv_len;
2577 inlen -= sub->sa_final->bv_len;
2581 for(i=0; sub->sa_any[i]; i++) {
2586 if( inlen > left.bv_len ) {
2587 /* not enough length */
2592 if( sub->sa_any[i]->bv_len == 0 ) {
2596 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2603 idx = p - left.bv_val;
2604 assert( idx < left.bv_len );
2606 if( idx >= left.bv_len ) {
2607 /* this shouldn't happen */
2614 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2615 /* not enough left */
2620 match = strncasecmp( left.bv_val,
2621 sub->sa_any[i]->bv_val,
2622 sub->sa_any[i]->bv_len );
2631 left.bv_val += sub->sa_any[i]->bv_len;
2632 left.bv_len -= sub->sa_any[i]->bv_len;
2633 inlen -= sub->sa_any[i]->bv_len;
2639 return LDAP_SUCCESS;
2642 /* Index generation function */
2643 int caseIgnoreIA5Indexer(
2648 struct berval *prefix,
2649 struct berval **values,
2650 struct berval ***keysp )
2654 struct berval **keys;
2655 HASH_CONTEXT HASHcontext;
2656 unsigned char HASHdigest[HASH_BYTES];
2657 struct berval digest;
2658 digest.bv_val = HASHdigest;
2659 digest.bv_len = sizeof(HASHdigest);
2661 /* we should have at least one value at this point */
2662 assert( values != NULL && values[0] != NULL );
2664 for( i=0; values[i] != NULL; i++ ) {
2665 /* just count them */
2668 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2670 slen = strlen( syntax->ssyn_oid );
2671 mlen = strlen( mr->smr_oid );
2673 for( i=0; values[i] != NULL; i++ ) {
2674 struct berval *value = ber_bvdup( values[i] );
2675 ldap_pvt_str2upper( value->bv_val );
2677 HASH_Init( &HASHcontext );
2678 if( prefix != NULL && prefix->bv_len > 0 ) {
2679 HASH_Update( &HASHcontext,
2680 prefix->bv_val, prefix->bv_len );
2682 HASH_Update( &HASHcontext,
2683 syntax->ssyn_oid, slen );
2684 HASH_Update( &HASHcontext,
2685 mr->smr_oid, mlen );
2686 HASH_Update( &HASHcontext,
2687 value->bv_val, value->bv_len );
2688 HASH_Final( HASHdigest, &HASHcontext );
2690 ber_bvfree( value );
2692 keys[i] = ber_bvdup( &digest );
2697 return LDAP_SUCCESS;
2700 /* Index generation function */
2701 int caseIgnoreIA5Filter(
2706 struct berval *prefix,
2708 struct berval ***keysp )
2711 struct berval **keys;
2712 HASH_CONTEXT HASHcontext;
2713 unsigned char HASHdigest[HASH_BYTES];
2714 struct berval *value;
2715 struct berval digest;
2716 digest.bv_val = HASHdigest;
2717 digest.bv_len = sizeof(HASHdigest);
2719 slen = strlen( syntax->ssyn_oid );
2720 mlen = strlen( mr->smr_oid );
2722 value = ber_bvdup( (struct berval *) assertValue );
2723 ldap_pvt_str2upper( value->bv_val );
2725 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2727 HASH_Init( &HASHcontext );
2728 if( prefix != NULL && prefix->bv_len > 0 ) {
2729 HASH_Update( &HASHcontext,
2730 prefix->bv_val, prefix->bv_len );
2732 HASH_Update( &HASHcontext,
2733 syntax->ssyn_oid, slen );
2734 HASH_Update( &HASHcontext,
2735 mr->smr_oid, mlen );
2736 HASH_Update( &HASHcontext,
2737 value->bv_val, value->bv_len );
2738 HASH_Final( HASHdigest, &HASHcontext );
2740 keys[0] = ber_bvdup( &digest );
2743 ber_bvfree( value );
2747 return LDAP_SUCCESS;
2750 /* Substrings Index generation function */
2751 int caseIgnoreIA5SubstringsIndexer(
2756 struct berval *prefix,
2757 struct berval **values,
2758 struct berval ***keysp )
2762 struct berval **keys;
2763 HASH_CONTEXT HASHcontext;
2764 unsigned char HASHdigest[HASH_BYTES];
2765 struct berval digest;
2766 digest.bv_val = HASHdigest;
2767 digest.bv_len = sizeof(HASHdigest);
2769 /* we should have at least one value at this point */
2770 assert( values != NULL && values[0] != NULL );
2773 for( i=0; values[i] != NULL; i++ ) {
2774 /* count number of indices to generate */
2775 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2779 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2780 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2781 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2782 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2784 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2788 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2789 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2790 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2794 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2795 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2796 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2797 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2799 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2805 /* no keys to generate */
2807 return LDAP_SUCCESS;
2810 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2812 slen = strlen( syntax->ssyn_oid );
2813 mlen = strlen( mr->smr_oid );
2816 for( i=0; values[i] != NULL; i++ ) {
2818 struct berval *value;
2820 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2822 value = ber_bvdup( values[i] );
2823 ldap_pvt_str2upper( value->bv_val );
2825 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2826 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2828 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2829 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2831 for( j=0; j<max; j++ ) {
2832 HASH_Init( &HASHcontext );
2833 if( prefix != NULL && prefix->bv_len > 0 ) {
2834 HASH_Update( &HASHcontext,
2835 prefix->bv_val, prefix->bv_len );
2838 HASH_Update( &HASHcontext,
2839 &pre, sizeof( pre ) );
2840 HASH_Update( &HASHcontext,
2841 syntax->ssyn_oid, slen );
2842 HASH_Update( &HASHcontext,
2843 mr->smr_oid, mlen );
2844 HASH_Update( &HASHcontext,
2846 SLAP_INDEX_SUBSTR_MAXLEN );
2847 HASH_Final( HASHdigest, &HASHcontext );
2849 keys[nkeys++] = ber_bvdup( &digest );
2853 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2854 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2856 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2859 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2860 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2861 HASH_Init( &HASHcontext );
2862 if( prefix != NULL && prefix->bv_len > 0 ) {
2863 HASH_Update( &HASHcontext,
2864 prefix->bv_val, prefix->bv_len );
2866 HASH_Update( &HASHcontext,
2867 &pre, sizeof( pre ) );
2868 HASH_Update( &HASHcontext,
2869 syntax->ssyn_oid, slen );
2870 HASH_Update( &HASHcontext,
2871 mr->smr_oid, mlen );
2872 HASH_Update( &HASHcontext,
2874 HASH_Final( HASHdigest, &HASHcontext );
2876 keys[nkeys++] = ber_bvdup( &digest );
2879 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2880 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2881 HASH_Init( &HASHcontext );
2882 if( prefix != NULL && prefix->bv_len > 0 ) {
2883 HASH_Update( &HASHcontext,
2884 prefix->bv_val, prefix->bv_len );
2886 HASH_Update( &HASHcontext,
2887 &pre, sizeof( pre ) );
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-j], j );
2894 HASH_Final( HASHdigest, &HASHcontext );
2896 keys[nkeys++] = ber_bvdup( &digest );
2901 ber_bvfree( value );
2912 return LDAP_SUCCESS;
2915 int caseIgnoreIA5SubstringsFilter(
2920 struct berval *prefix,
2922 struct berval ***keysp )
2924 SubstringsAssertion *sa = assertValue;
2926 ber_len_t nkeys = 0;
2927 size_t slen, mlen, klen;
2928 struct berval **keys;
2929 HASH_CONTEXT HASHcontext;
2930 unsigned char HASHdigest[HASH_BYTES];
2931 struct berval *value;
2932 struct berval digest;
2934 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2935 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2940 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2942 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2943 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2944 /* don't bother accounting for stepping */
2945 nkeys += sa->sa_any[i]->bv_len -
2946 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2951 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2952 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2959 return LDAP_SUCCESS;
2962 digest.bv_val = HASHdigest;
2963 digest.bv_len = sizeof(HASHdigest);
2965 slen = strlen( syntax->ssyn_oid );
2966 mlen = strlen( mr->smr_oid );
2968 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2971 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2972 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2974 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2975 value = ber_bvdup( sa->sa_initial );
2976 ldap_pvt_str2upper( value->bv_val );
2978 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2979 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2981 HASH_Init( &HASHcontext );
2982 if( prefix != NULL && prefix->bv_len > 0 ) {
2983 HASH_Update( &HASHcontext,
2984 prefix->bv_val, prefix->bv_len );
2986 HASH_Update( &HASHcontext,
2987 &pre, sizeof( pre ) );
2988 HASH_Update( &HASHcontext,
2989 syntax->ssyn_oid, slen );
2990 HASH_Update( &HASHcontext,
2991 mr->smr_oid, mlen );
2992 HASH_Update( &HASHcontext,
2993 value->bv_val, klen );
2994 HASH_Final( HASHdigest, &HASHcontext );
2996 ber_bvfree( value );
2997 keys[nkeys++] = ber_bvdup( &digest );
3000 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3002 pre = SLAP_INDEX_SUBSTR_PREFIX;
3003 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3005 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3006 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3010 value = ber_bvdup( sa->sa_any[i] );
3011 ldap_pvt_str2upper( value->bv_val );
3014 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3015 j += SLAP_INDEX_SUBSTR_STEP )
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,
3029 &value->bv_val[j], klen );
3030 HASH_Final( HASHdigest, &HASHcontext );
3032 keys[nkeys++] = ber_bvdup( &digest );
3035 ber_bvfree( value );
3039 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3040 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3042 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3043 value = ber_bvdup( sa->sa_final );
3044 ldap_pvt_str2upper( value->bv_val );
3046 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3047 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3049 HASH_Init( &HASHcontext );
3050 if( prefix != NULL && prefix->bv_len > 0 ) {
3051 HASH_Update( &HASHcontext,
3052 prefix->bv_val, prefix->bv_len );
3054 HASH_Update( &HASHcontext,
3055 &pre, sizeof( pre ) );
3056 HASH_Update( &HASHcontext,
3057 syntax->ssyn_oid, slen );
3058 HASH_Update( &HASHcontext,
3059 mr->smr_oid, mlen );
3060 HASH_Update( &HASHcontext,
3061 &value->bv_val[value->bv_len-klen], klen );
3062 HASH_Final( HASHdigest, &HASHcontext );
3064 ber_bvfree( value );
3065 keys[nkeys++] = ber_bvdup( &digest );
3076 return LDAP_SUCCESS;
3080 numericStringValidate(
3086 for(i=0; i < in->bv_len; i++) {
3087 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3088 return LDAP_INVALID_SYNTAX;
3092 return LDAP_SUCCESS;
3096 numericStringNormalize(
3099 struct berval **normalized )
3101 /* removal all spaces */
3102 struct berval *newval;
3105 newval = ch_malloc( sizeof( struct berval ) );
3106 newval->bv_val = ch_malloc( val->bv_len + 1 );
3112 if ( ASCII_SPACE( *p ) ) {
3113 /* Ignore whitespace */
3120 /* we should have copied no more then is in val */
3121 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3123 /* null terminate */
3126 newval->bv_len = q - newval->bv_val;
3127 *normalized = newval;
3129 return LDAP_SUCCESS;
3133 objectIdentifierFirstComponentMatch(
3138 struct berval *value,
3139 void *assertedValue )
3141 int rc = LDAP_SUCCESS;
3143 struct berval *asserted = (struct berval *) assertedValue;
3147 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3148 return LDAP_INVALID_SYNTAX;
3151 /* trim leading white space */
3152 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3156 /* grab next word */
3157 oid.bv_val = &value->bv_val[i];
3158 oid.bv_len = value->bv_len - i;
3159 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3164 /* insert attributeTypes, objectclass check here */
3165 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3166 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3169 char *stored = ch_malloc( oid.bv_len + 1 );
3170 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3171 stored[oid.bv_len] = '\0';
3173 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3174 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3175 MatchingRule *stored_mr = mr_find( stored );
3177 if( asserted_mr == NULL ) {
3178 rc = SLAPD_COMPARE_UNDEFINED;
3180 match = asserted_mr != stored_mr;
3183 } else if ( !strcmp( syntax->ssyn_oid,
3184 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3186 AttributeType *asserted_at = at_find( asserted->bv_val );
3187 AttributeType *stored_at = at_find( stored );
3189 if( asserted_at == NULL ) {
3190 rc = SLAPD_COMPARE_UNDEFINED;
3192 match = asserted_at != stored_at;
3195 } else if ( !strcmp( syntax->ssyn_oid,
3196 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3198 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3199 ObjectClass *stored_oc = oc_find( stored );
3201 if( asserted_oc == NULL ) {
3202 rc = SLAPD_COMPARE_UNDEFINED;
3204 match = asserted_oc != stored_oc;
3212 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3213 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3214 match, value->bv_val, asserted->bv_val ));
3216 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3217 "%d\n\t\"%s\"\n\t\"%s\"\n",
3218 match, value->bv_val, asserted->bv_val );
3222 if( rc == LDAP_SUCCESS ) *matchp = match;
3232 struct berval *value,
3233 void *assertedValue )
3235 long lValue, lAssertedValue;
3237 /* safe to assume integers are NUL terminated? */
3238 lValue = strtoul(value->bv_val, NULL, 10);
3239 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3240 return LDAP_CONSTRAINT_VIOLATION;
3242 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3243 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3244 return LDAP_CONSTRAINT_VIOLATION;
3246 *matchp = (lValue & lAssertedValue);
3247 return LDAP_SUCCESS;
3256 struct berval *value,
3257 void *assertedValue )
3259 long lValue, lAssertedValue;
3261 /* safe to assume integers are NUL terminated? */
3262 lValue = strtoul(value->bv_val, NULL, 10);
3263 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3264 return LDAP_CONSTRAINT_VIOLATION;
3266 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3267 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3268 return LDAP_CONSTRAINT_VIOLATION;
3270 *matchp = (lValue | lAssertedValue);
3271 return LDAP_SUCCESS;
3275 check_time_syntax (struct berval *val,
3279 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3280 static int mdays[2][12] = {
3281 /* non-leap years */
3282 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3284 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3287 int part, c, tzoffset, leapyear = 0 ;
3289 if( val->bv_len == 0 ) {
3290 return LDAP_INVALID_SYNTAX;
3293 p = (char *)val->bv_val;
3294 e = p + val->bv_len;
3296 /* Ignore initial whitespace */
3297 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3301 if (e - p < 13 - (2 * start)) {
3302 return LDAP_INVALID_SYNTAX;
3305 for (part = 0; part < 9; part++) {
3309 for (part = start; part < 7; part++) {
3311 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3318 return LDAP_INVALID_SYNTAX;
3320 if (c < 0 || c > 9) {
3321 return LDAP_INVALID_SYNTAX;
3327 return LDAP_INVALID_SYNTAX;
3329 if (c < 0 || c > 9) {
3330 return LDAP_INVALID_SYNTAX;
3335 if (part == 2 || part == 3) {
3338 if (parts[part] < 0) {
3339 return LDAP_INVALID_SYNTAX;
3341 if (parts[part] > ceiling[part]) {
3342 return LDAP_INVALID_SYNTAX;
3346 /* leapyear check for the Gregorian calendar (year>1581) */
3347 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3348 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3353 if (parts[3] > mdays[leapyear][parts[2]]) {
3354 return LDAP_INVALID_SYNTAX;
3359 tzoffset = 0; /* UTC */
3360 } else if (c != '+' && c != '-') {
3361 return LDAP_INVALID_SYNTAX;
3365 } else /* c == '+' */ {
3370 return LDAP_INVALID_SYNTAX;
3373 for (part = 7; part < 9; part++) {
3375 if (c < 0 || c > 9) {
3376 return LDAP_INVALID_SYNTAX;
3381 if (c < 0 || c > 9) {
3382 return LDAP_INVALID_SYNTAX;
3386 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3387 return LDAP_INVALID_SYNTAX;
3392 /* Ignore trailing whitespace */
3393 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3397 return LDAP_INVALID_SYNTAX;
3400 switch ( tzoffset ) {
3401 case -1: /* negativ offset to UTC, ie west of Greenwich */
3402 parts[4] += parts[7];
3403 parts[5] += parts[8];
3404 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3408 c = mdays[leapyear][parts[2]];
3410 if (parts[part] > c) {
3411 parts[part] -= c + 1;
3416 case 1: /* positive offset to UTC, ie east of Greenwich */
3417 parts[4] -= parts[7];
3418 parts[5] -= parts[8];
3419 for (part = 6; --part > 0; ) {
3423 /* first arg to % needs to be non negativ */
3424 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3426 if (parts[part] < 0) {
3427 parts[part] += c + 1;
3432 case 0: /* already UTC */
3436 return LDAP_SUCCESS;
3443 struct berval **normalized )
3448 rc = check_time_syntax(val, 1, parts);
3449 if (rc != LDAP_SUCCESS) {
3454 out = ch_malloc( sizeof(struct berval) );
3456 return LBER_ERROR_MEMORY;
3459 out->bv_val = ch_malloc( 14 );
3460 if ( out->bv_val == NULL ) {
3462 return LBER_ERROR_MEMORY;
3465 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3466 parts[1], parts[2] + 1, parts[3] + 1,
3467 parts[4], parts[5], parts[6] );
3471 return LDAP_SUCCESS;
3481 return check_time_syntax(in, 1, parts);
3485 generalizedTimeValidate(
3491 return check_time_syntax(in, 0, parts);
3495 generalizedTimeNormalize(
3498 struct berval **normalized )
3503 rc = check_time_syntax(val, 0, parts);
3504 if (rc != LDAP_SUCCESS) {
3509 out = ch_malloc( sizeof(struct berval) );
3511 return LBER_ERROR_MEMORY;
3514 out->bv_val = ch_malloc( 16 );
3515 if ( out->bv_val == NULL ) {
3517 return LBER_ERROR_MEMORY;
3520 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3521 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3522 parts[4], parts[5], parts[6] );
3526 return LDAP_SUCCESS;
3530 nisNetgroupTripleValidate(
3532 struct berval *val )
3537 if ( val->bv_len == 0 ) {
3538 return LDAP_INVALID_SYNTAX;
3541 p = (char *)val->bv_val;
3542 e = p + val->bv_len;
3544 if ( *p != '(' /*')'*/ ) {
3545 return LDAP_INVALID_SYNTAX;
3548 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3552 return LDAP_INVALID_SYNTAX;
3555 } else if ( !ATTR_CHAR( *p ) ) {
3556 return LDAP_INVALID_SYNTAX;
3560 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3561 return LDAP_INVALID_SYNTAX;
3567 return LDAP_INVALID_SYNTAX;
3570 return LDAP_SUCCESS;
3574 bootParameterValidate(
3576 struct berval *val )
3580 if ( val->bv_len == 0 ) {
3581 return LDAP_INVALID_SYNTAX;
3584 p = (char *)val->bv_val;
3585 e = p + val->bv_len;
3588 for (; ( p < e ) && ( *p != '=' ); p++ ) {
3589 if ( !ATTR_CHAR( *p ) ) {
3590 return LDAP_INVALID_SYNTAX;
3595 return LDAP_INVALID_SYNTAX;
3599 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
3600 if ( !ATTR_CHAR( *p ) ) {
3601 return LDAP_INVALID_SYNTAX;
3606 return LDAP_INVALID_SYNTAX;
3610 for ( p++; p < e; p++ ) {
3611 if ( !ATTR_CHAR( *p ) ) {
3612 return LDAP_INVALID_SYNTAX;
3616 return LDAP_SUCCESS;
3619 struct syntax_defs_rec {
3622 slap_syntax_validate_func *sd_validate;
3623 slap_syntax_transform_func *sd_normalize;
3624 slap_syntax_transform_func *sd_pretty;
3625 #ifdef SLAPD_BINARY_CONVERSION
3626 slap_syntax_transform_func *sd_ber2str;
3627 slap_syntax_transform_func *sd_str2ber;
3631 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
3632 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
3634 struct syntax_defs_rec syntax_defs[] = {
3635 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
3636 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
3637 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
3638 0, NULL, NULL, NULL},
3639 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
3640 0, NULL, NULL, NULL},
3641 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
3642 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3643 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
3644 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3645 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
3646 0, bitStringValidate, NULL, NULL },
3647 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
3648 0, booleanValidate, NULL, NULL},
3649 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
3650 X_BINARY X_NOT_H_R ")",
3651 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3652 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
3653 X_BINARY X_NOT_H_R ")",
3654 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3655 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
3656 X_BINARY X_NOT_H_R ")",
3657 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3658 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
3659 0, countryStringValidate, IA5StringNormalize, NULL},
3660 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
3661 0, dnValidate, dnNormalize, dnPretty},
3662 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
3663 0, NULL, NULL, NULL},
3664 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
3665 0, NULL, NULL, NULL},
3666 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
3667 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3668 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
3669 0, NULL, NULL, NULL},
3670 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
3671 0, NULL, NULL, NULL},
3672 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
3673 0, NULL, NULL, NULL},
3674 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
3675 0, NULL, NULL, NULL},
3676 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
3677 0, NULL, NULL, NULL},
3678 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
3679 0, printablesStringValidate, IA5StringNormalize, NULL},
3680 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
3681 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
3682 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
3683 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
3684 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
3685 0, NULL, NULL, NULL},
3686 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
3687 0, IA5StringValidate, IA5StringNormalize, NULL},
3688 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
3689 0, integerValidate, integerNormalize, integerPretty},
3690 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
3691 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3692 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
3693 0, NULL, NULL, NULL},
3694 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
3695 0, NULL, NULL, NULL},
3696 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
3697 0, NULL, NULL, NULL},
3698 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
3699 0, NULL, NULL, NULL},
3700 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
3701 0, NULL, NULL, NULL},
3702 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
3703 0, nameUIDValidate, nameUIDNormalize, NULL},
3704 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
3705 0, NULL, NULL, NULL},
3706 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
3707 0, numericStringValidate, numericStringNormalize, NULL},
3708 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
3709 0, NULL, NULL, NULL},
3710 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
3711 0, oidValidate, NULL, NULL},
3712 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
3713 0, IA5StringValidate, IA5StringNormalize, NULL},
3714 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
3715 0, blobValidate, NULL, NULL},
3716 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
3717 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3718 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
3719 0, NULL, NULL, NULL},
3720 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
3721 0, NULL, NULL, NULL},
3722 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
3723 0, printableStringValidate, IA5StringNormalize, NULL},
3724 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
3725 X_BINARY X_NOT_H_R ")",
3726 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3727 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
3728 0, printableStringValidate, IA5StringNormalize, NULL},
3729 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
3730 0, NULL, NULL, NULL},
3731 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
3732 0, printableStringValidate, IA5StringNormalize, NULL},
3733 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
3734 0, utcTimeValidate, utcTimeNormalize, NULL},
3735 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
3736 0, NULL, NULL, NULL},
3737 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
3738 0, NULL, NULL, NULL},
3739 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
3740 0, NULL, NULL, NULL},
3741 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
3742 0, NULL, NULL, NULL},
3743 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
3744 0, NULL, NULL, NULL},
3746 /* RFC 2307 NIS Syntaxes */
3747 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
3748 0, nisNetgroupTripleValidate, NULL, NULL},
3749 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
3750 0, bootParameterValidate, NULL, NULL},
3752 /* OpenLDAP Experimental Syntaxes */
3753 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
3754 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
3756 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
3757 0, NULL, NULL, NULL},
3759 /* OpenLDAP Void Syntax */
3760 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
3761 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
3762 {NULL, 0, NULL, NULL, NULL}
3765 struct mrule_defs_rec {
3767 slap_mask_t mrd_usage;
3768 slap_mr_convert_func * mrd_convert;
3769 slap_mr_normalize_func * mrd_normalize;
3770 slap_mr_match_func * mrd_match;
3771 slap_mr_indexer_func * mrd_indexer;
3772 slap_mr_filter_func * mrd_filter;
3774 char * mrd_associated;
3778 * Other matching rules in X.520 that we do not use (yet):
3780 * 2.5.13.9 numericStringOrderingMatch
3781 * 2.5.13.15 integerOrderingMatch
3782 * 2.5.13.18 octetStringOrderingMatch
3783 * 2.5.13.19 octetStringSubstringsMatch
3784 * 2.5.13.25 uTCTimeMatch
3785 * 2.5.13.26 uTCTimeOrderingMatch
3786 * 2.5.13.31 directoryStringFirstComponentMatch
3787 * 2.5.13.32 wordMatch
3788 * 2.5.13.33 keywordMatch
3789 * 2.5.13.34 certificateExactMatch
3790 * 2.5.13.35 certificateMatch
3791 * 2.5.13.36 certificatePairExactMatch
3792 * 2.5.13.37 certificatePairMatch
3793 * 2.5.13.38 certificateListExactMatch
3794 * 2.5.13.39 certificateListMatch
3795 * 2.5.13.40 algorithmIdentifierMatch
3796 * 2.5.13.41 storedPrefixMatch
3797 * 2.5.13.42 attributeCertificateMatch
3798 * 2.5.13.43 readerAndKeyIDMatch
3799 * 2.5.13.44 attributeIntegrityMatch
3802 struct mrule_defs_rec mrule_defs[] = {
3804 * EQUALITY matching rules must be listed after associated APPROX
3805 * matching rules. So, we list all APPROX matching rules first.
3807 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
3808 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3809 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3811 directoryStringApproxMatch,
3812 directoryStringApproxIndexer,
3813 directoryStringApproxFilter,
3816 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
3817 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3818 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3820 IA5StringApproxMatch,
3821 IA5StringApproxIndexer,
3822 IA5StringApproxFilter,
3826 * Other matching rules
3829 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
3830 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3831 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3833 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
3836 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
3837 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
3838 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3840 dnMatch, dnIndexer, dnFilter,
3843 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
3844 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3845 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3847 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
3848 directoryStringApproxMatchOID },
3850 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
3851 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3854 caseIgnoreOrderingMatch, NULL, NULL,
3857 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
3858 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3859 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3861 caseExactIgnoreSubstringsMatch,
3862 caseExactIgnoreSubstringsIndexer,
3863 caseExactIgnoreSubstringsFilter,
3866 {"( 2.5.13.5 NAME 'caseExactMatch' "
3867 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3868 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3870 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
3871 directoryStringApproxMatchOID },
3873 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
3874 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3877 caseExactOrderingMatch, NULL, NULL,
3880 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
3881 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3882 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3884 caseExactIgnoreSubstringsMatch,
3885 caseExactIgnoreSubstringsIndexer,
3886 caseExactIgnoreSubstringsFilter,
3889 {"( 2.5.13.8 NAME 'numericStringMatch' "
3890 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
3891 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3894 caseIgnoreIA5Indexer,
3895 caseIgnoreIA5Filter,
3898 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
3899 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3900 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3902 caseIgnoreIA5SubstringsMatch,
3903 caseIgnoreIA5SubstringsIndexer,
3904 caseIgnoreIA5SubstringsFilter,
3907 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
3908 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
3909 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3911 caseIgnoreListMatch, NULL, NULL,
3914 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
3915 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3916 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3918 caseIgnoreListSubstringsMatch, NULL, NULL,
3921 {"( 2.5.13.13 NAME 'booleanMatch' "
3922 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
3923 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3925 booleanMatch, NULL, NULL,
3928 {"( 2.5.13.14 NAME 'integerMatch' "
3929 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
3930 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3932 integerMatch, integerIndexer, integerFilter,
3935 {"( 2.5.13.16 NAME 'bitStringMatch' "
3936 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
3937 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3939 bitStringMatch, NULL, NULL,
3942 {"( 2.5.13.17 NAME 'octetStringMatch' "
3943 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
3944 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3946 octetStringMatch, octetStringIndexer, octetStringFilter,
3949 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
3950 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
3951 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3953 telephoneNumberMatch,
3954 telephoneNumberIndexer,
3955 telephoneNumberFilter,
3958 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
3959 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3960 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3962 telephoneNumberSubstringsMatch,
3963 telephoneNumberSubstringsIndexer,
3964 telephoneNumberSubstringsFilter,
3967 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
3968 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
3969 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3974 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
3975 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
3976 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3978 uniqueMemberMatch, NULL, NULL,
3981 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
3982 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
3983 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3985 protocolInformationMatch, NULL, NULL,
3988 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
3989 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
3990 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3992 generalizedTimeMatch, NULL, NULL,
3995 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
3996 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
3999 generalizedTimeOrderingMatch, NULL, NULL,
4002 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4003 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4004 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4006 integerFirstComponentMatch, NULL, NULL,
4009 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4010 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4011 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4013 objectIdentifierFirstComponentMatch, NULL, NULL,
4016 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4017 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4018 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4020 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4021 IA5StringApproxMatchOID },
4023 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4024 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4025 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4027 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4028 IA5StringApproxMatchOID },
4030 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4031 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4034 caseIgnoreIA5SubstringsMatch,
4035 caseIgnoreIA5SubstringsIndexer,
4036 caseIgnoreIA5SubstringsFilter,
4039 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4040 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4043 caseExactIA5SubstringsMatch,
4044 caseExactIA5SubstringsIndexer,
4045 caseExactIA5SubstringsFilter,
4048 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4049 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4052 authPasswordMatch, NULL, NULL,
4055 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4056 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4059 OpenLDAPaciMatch, NULL, NULL,
4062 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4063 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4066 integerBitAndMatch, NULL, NULL,
4069 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4070 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4073 integerBitOrMatch, NULL, NULL,
4076 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4085 /* we should only be called once (from main) */
4086 assert( schema_init_done == 0 );
4088 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4089 res = register_syntax( syntax_defs[i].sd_desc,
4090 syntax_defs[i].sd_flags,
4091 syntax_defs[i].sd_validate,
4092 syntax_defs[i].sd_normalize,
4093 syntax_defs[i].sd_pretty
4094 #ifdef SLAPD_BINARY_CONVERSION
4096 syntax_defs[i].sd_ber2str,
4097 syntax_defs[i].sd_str2ber
4102 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4103 syntax_defs[i].sd_desc );
4108 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4109 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4111 "schema_init: Ingoring unusable matching rule %s\n",
4112 mrule_defs[i].mrd_desc );
4116 res = register_matching_rule(
4117 mrule_defs[i].mrd_desc,
4118 mrule_defs[i].mrd_usage,
4119 mrule_defs[i].mrd_convert,
4120 mrule_defs[i].mrd_normalize,
4121 mrule_defs[i].mrd_match,
4122 mrule_defs[i].mrd_indexer,
4123 mrule_defs[i].mrd_filter,
4124 mrule_defs[i].mrd_associated );
4128 "schema_init: Error registering matching rule %s\n",
4129 mrule_defs[i].mrd_desc );
4133 schema_init_done = 1;
4134 return LDAP_SUCCESS;