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 )
1553 ch_free( sa->sa_final );
1554 ber_bvecfree( sa->sa_any );
1555 ch_free( sa->sa_initial );
1558 return LDAP_SUCCESS;
1561 digest.bv_val = HASHdigest;
1562 digest.bv_len = sizeof(HASHdigest);
1564 slen = strlen( syntax->ssyn_oid );
1565 mlen = strlen( mr->smr_oid );
1567 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1570 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1571 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1573 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1574 value = sa->sa_initial;
1576 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1577 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1579 HASH_Init( &HASHcontext );
1580 if( prefix != NULL && prefix->bv_len > 0 ) {
1581 HASH_Update( &HASHcontext,
1582 prefix->bv_val, prefix->bv_len );
1584 HASH_Update( &HASHcontext,
1585 &pre, sizeof( pre ) );
1586 HASH_Update( &HASHcontext,
1587 syntax->ssyn_oid, slen );
1588 HASH_Update( &HASHcontext,
1589 mr->smr_oid, mlen );
1590 HASH_Update( &HASHcontext,
1591 value->bv_val, klen );
1592 HASH_Final( HASHdigest, &HASHcontext );
1594 keys[nkeys++] = ber_bvdup( &digest );
1597 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1599 pre = SLAP_INDEX_SUBSTR_PREFIX;
1600 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1602 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1603 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1607 value = sa->sa_any[i];
1610 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1611 j += SLAP_INDEX_SUBSTR_STEP )
1613 HASH_Init( &HASHcontext );
1614 if( prefix != NULL && prefix->bv_len > 0 ) {
1615 HASH_Update( &HASHcontext,
1616 prefix->bv_val, prefix->bv_len );
1618 HASH_Update( &HASHcontext,
1619 &pre, sizeof( pre ) );
1620 HASH_Update( &HASHcontext,
1621 syntax->ssyn_oid, slen );
1622 HASH_Update( &HASHcontext,
1623 mr->smr_oid, mlen );
1624 HASH_Update( &HASHcontext,
1625 &value->bv_val[j], klen );
1626 HASH_Final( HASHdigest, &HASHcontext );
1628 keys[nkeys++] = ber_bvdup( &digest );
1634 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1635 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1637 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1638 value = sa->sa_final;
1640 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1641 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1643 HASH_Init( &HASHcontext );
1644 if( prefix != NULL && prefix->bv_len > 0 ) {
1645 HASH_Update( &HASHcontext,
1646 prefix->bv_val, prefix->bv_len );
1648 HASH_Update( &HASHcontext,
1649 &pre, sizeof( pre ) );
1650 HASH_Update( &HASHcontext,
1651 syntax->ssyn_oid, slen );
1652 HASH_Update( &HASHcontext,
1653 mr->smr_oid, mlen );
1654 HASH_Update( &HASHcontext,
1655 &value->bv_val[value->bv_len-klen], klen );
1656 HASH_Final( HASHdigest, &HASHcontext );
1658 keys[nkeys++] = ber_bvdup( &digest );
1668 ch_free( sa->sa_final );
1669 ber_bvecfree( sa->sa_any );
1670 ch_free( sa->sa_initial );
1673 return LDAP_SUCCESS;
1682 struct berval *value,
1683 void *assertedValue )
1685 *matchp = UTF8normcmp( value->bv_val,
1686 ((struct berval *) assertedValue)->bv_val,
1688 return LDAP_SUCCESS;
1694 struct berval *val )
1698 if( val->bv_len == 0 ) {
1699 /* disallow empty strings */
1700 return LDAP_INVALID_SYNTAX;
1703 if( OID_LEADCHAR(val->bv_val[0]) ) {
1705 for(i=1; i < val->bv_len; i++) {
1706 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1707 if( dot++ ) return 1;
1708 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1711 return LDAP_INVALID_SYNTAX;
1715 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1717 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1718 for(i=1; i < val->bv_len; i++) {
1719 if( !DESC_CHAR(val->bv_val[i] ) ) {
1720 return LDAP_INVALID_SYNTAX;
1724 return LDAP_SUCCESS;
1727 return LDAP_INVALID_SYNTAX;
1736 struct berval *value,
1737 void *assertedValue )
1740 int vsign=0, avsign=0;
1741 struct berval *asserted;
1742 ber_len_t vlen, avlen;
1745 /* Start off pessimistic */
1748 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1750 vlen = value->bv_len;
1752 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1753 /* empty -- skip spaces */
1755 else if ( *v == '+' ) {
1758 else if ( *v == '-' ) {
1761 else if ( ASCII_DIGIT(*v) ) {
1762 if ( vsign == 0 ) vsign = 1;
1770 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1772 asserted = (struct berval *) assertedValue;
1773 av = asserted->bv_val;
1774 avlen = asserted->bv_len;
1776 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1777 /* empty -- skip spaces */
1779 else if ( *av == '+' ) {
1782 else if ( *av == '-' ) {
1785 else if ( ASCII_DIGIT(*av) ) {
1786 if ( avsign == 0 ) avsign = 1;
1794 /* The two ?sign vars are now one of :
1795 -2 negative non-zero number
1797 0 0 collapse these three to 0
1799 +2 positive non-zero number
1801 if ( abs( vsign ) == 1 ) vsign = 0;
1802 if ( abs( avsign ) == 1 ) avsign = 0;
1804 if( vsign != avsign ) return LDAP_SUCCESS;
1806 /* Check the significant digits */
1807 while( vlen && avlen ) {
1808 if( *v != *av ) break;
1815 /* If all digits compared equal, the numbers are equal */
1816 if(( vlen == 0 ) && ( avlen == 0 )) {
1819 return LDAP_SUCCESS;
1825 struct berval *val )
1829 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1831 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1832 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1833 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1834 return LDAP_INVALID_SYNTAX;
1837 for( i=1; i < val->bv_len; i++ ) {
1838 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1841 return LDAP_SUCCESS;
1848 struct berval **normalized )
1852 struct berval *newval;
1859 /* Ignore leading spaces */
1860 while ( len && ( *p == ' ' )) {
1867 negative = ( *p == '-' );
1868 if(( *p == '-' ) || ( *p == '+' )) {
1874 /* Ignore leading zeros */
1875 while ( len && ( *p == '0' )) {
1880 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
1882 /* If there are no non-zero digits left, the number is zero, otherwise
1883 allocate space for the number and copy it into the buffer */
1885 newval->bv_val = ch_strdup("0");
1889 newval->bv_len = len+negative;
1890 newval->bv_val = ch_malloc( newval->bv_len );
1892 newval->bv_val[0] = '-';
1894 memcpy( newval->bv_val + negative, p, len );
1897 *normalized = newval;
1898 return LDAP_SUCCESS;
1901 /* Index generation function */
1907 struct berval *prefix,
1908 struct berval **values,
1909 struct berval ***keysp )
1912 struct berval **keys;
1914 /* we should have at least one value at this point */
1915 assert( values != NULL && values[0] != NULL );
1917 for( i=0; values[i] != NULL; i++ ) {
1918 /* empty -- just count them */
1921 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1923 for( i=0; values[i] != NULL; i++ ) {
1924 integerNormalize( syntax, values[i], &keys[i] );
1929 return LDAP_SUCCESS;
1932 /* Index generation function */
1938 struct berval *prefix,
1940 struct berval ***keysp )
1942 struct berval **keys;
1944 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1945 integerNormalize( syntax, assertValue, &keys[0] );
1949 return LDAP_SUCCESS;
1954 countryStringValidate(
1956 struct berval *val )
1958 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1960 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1961 return LDAP_INVALID_SYNTAX;
1963 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1964 return LDAP_INVALID_SYNTAX;
1967 return LDAP_SUCCESS;
1971 printableStringValidate(
1973 struct berval *val )
1977 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1979 for(i=0; i < val->bv_len; i++) {
1980 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1981 return LDAP_INVALID_SYNTAX;
1985 return LDAP_SUCCESS;
1989 printablesStringValidate(
1991 struct berval *val )
1995 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1997 for(i=0; i < val->bv_len; i++) {
1998 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1999 return LDAP_INVALID_SYNTAX;
2003 return LDAP_SUCCESS;
2009 struct berval *val )
2013 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2015 for(i=0; i < val->bv_len; i++) {
2016 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2019 return LDAP_SUCCESS;
2026 struct berval **normalized )
2028 struct berval *newval;
2031 newval = ch_malloc( sizeof( struct berval ) );
2035 /* Ignore initial whitespace */
2036 while ( ASCII_SPACE( *p ) ) {
2042 return LDAP_INVALID_SYNTAX;
2045 newval->bv_val = ch_strdup( p );
2046 p = q = newval->bv_val;
2049 if ( ASCII_SPACE( *p ) ) {
2052 /* Ignore the extra whitespace */
2053 while ( ASCII_SPACE( *p ) ) {
2061 assert( *newval->bv_val );
2062 assert( newval->bv_val < p );
2065 /* cannot start with a space */
2066 assert( !ASCII_SPACE(*newval->bv_val) );
2069 * If the string ended in space, backup the pointer one
2070 * position. One is enough because the above loop collapsed
2071 * all whitespace to a single space.
2074 if ( ASCII_SPACE( q[-1] ) ) {
2078 /* cannot end with a space */
2079 assert( !ASCII_SPACE( q[-1] ) );
2081 /* null terminate */
2084 newval->bv_len = q - newval->bv_val;
2085 *normalized = newval;
2087 return LDAP_SUCCESS;
2096 struct berval *value,
2097 void *assertedValue )
2099 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2102 match = strncmp( value->bv_val,
2103 ((struct berval *) assertedValue)->bv_val,
2108 return LDAP_SUCCESS;
2112 caseExactIA5SubstringsMatch(
2117 struct berval *value,
2118 void *assertedValue )
2121 SubstringsAssertion *sub = assertedValue;
2122 struct berval left = *value;
2126 /* Add up asserted input length */
2127 if( sub->sa_initial ) {
2128 inlen += sub->sa_initial->bv_len;
2131 for(i=0; sub->sa_any[i] != NULL; i++) {
2132 inlen += sub->sa_any[i]->bv_len;
2135 if( sub->sa_final ) {
2136 inlen += sub->sa_final->bv_len;
2139 if( sub->sa_initial ) {
2140 if( inlen > left.bv_len ) {
2145 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2146 sub->sa_initial->bv_len );
2152 left.bv_val += sub->sa_initial->bv_len;
2153 left.bv_len -= sub->sa_initial->bv_len;
2154 inlen -= sub->sa_initial->bv_len;
2157 if( sub->sa_final ) {
2158 if( inlen > left.bv_len ) {
2163 match = strncmp( sub->sa_final->bv_val,
2164 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2165 sub->sa_final->bv_len );
2171 left.bv_len -= sub->sa_final->bv_len;
2172 inlen -= sub->sa_final->bv_len;
2176 for(i=0; sub->sa_any[i]; i++) {
2181 if( inlen > left.bv_len ) {
2182 /* not enough length */
2187 if( sub->sa_any[i]->bv_len == 0 ) {
2191 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2198 idx = p - left.bv_val;
2199 assert( idx < left.bv_len );
2201 if( idx >= left.bv_len ) {
2202 /* this shouldn't happen */
2209 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2210 /* not enough left */
2215 match = strncmp( left.bv_val,
2216 sub->sa_any[i]->bv_val,
2217 sub->sa_any[i]->bv_len );
2225 left.bv_val += sub->sa_any[i]->bv_len;
2226 left.bv_len -= sub->sa_any[i]->bv_len;
2227 inlen -= sub->sa_any[i]->bv_len;
2233 return LDAP_SUCCESS;
2236 /* Index generation function */
2237 int caseExactIA5Indexer(
2242 struct berval *prefix,
2243 struct berval **values,
2244 struct berval ***keysp )
2248 struct berval **keys;
2249 HASH_CONTEXT HASHcontext;
2250 unsigned char HASHdigest[HASH_BYTES];
2251 struct berval digest;
2252 digest.bv_val = HASHdigest;
2253 digest.bv_len = sizeof(HASHdigest);
2255 for( i=0; values[i] != NULL; i++ ) {
2256 /* empty - just count them */
2259 /* we should have at least one value at this point */
2262 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2264 slen = strlen( syntax->ssyn_oid );
2265 mlen = strlen( mr->smr_oid );
2267 for( i=0; values[i] != NULL; i++ ) {
2268 struct berval *value = values[i];
2270 HASH_Init( &HASHcontext );
2271 if( prefix != NULL && prefix->bv_len > 0 ) {
2272 HASH_Update( &HASHcontext,
2273 prefix->bv_val, prefix->bv_len );
2275 HASH_Update( &HASHcontext,
2276 syntax->ssyn_oid, slen );
2277 HASH_Update( &HASHcontext,
2278 mr->smr_oid, mlen );
2279 HASH_Update( &HASHcontext,
2280 value->bv_val, value->bv_len );
2281 HASH_Final( HASHdigest, &HASHcontext );
2283 keys[i] = ber_bvdup( &digest );
2288 return LDAP_SUCCESS;
2291 /* Index generation function */
2292 int caseExactIA5Filter(
2297 struct berval *prefix,
2299 struct berval ***keysp )
2302 struct berval **keys;
2303 HASH_CONTEXT HASHcontext;
2304 unsigned char HASHdigest[HASH_BYTES];
2305 struct berval *value;
2306 struct berval digest;
2307 digest.bv_val = HASHdigest;
2308 digest.bv_len = sizeof(HASHdigest);
2310 slen = strlen( syntax->ssyn_oid );
2311 mlen = strlen( mr->smr_oid );
2313 value = (struct berval *) assertValue;
2315 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2317 HASH_Init( &HASHcontext );
2318 if( prefix != NULL && prefix->bv_len > 0 ) {
2319 HASH_Update( &HASHcontext,
2320 prefix->bv_val, prefix->bv_len );
2322 HASH_Update( &HASHcontext,
2323 syntax->ssyn_oid, slen );
2324 HASH_Update( &HASHcontext,
2325 mr->smr_oid, mlen );
2326 HASH_Update( &HASHcontext,
2327 value->bv_val, value->bv_len );
2328 HASH_Final( HASHdigest, &HASHcontext );
2330 keys[0] = ber_bvdup( &digest );
2334 return LDAP_SUCCESS;
2337 /* Substrings Index generation function */
2338 int caseExactIA5SubstringsIndexer(
2343 struct berval *prefix,
2344 struct berval **values,
2345 struct berval ***keysp )
2349 struct berval **keys;
2350 HASH_CONTEXT HASHcontext;
2351 unsigned char HASHdigest[HASH_BYTES];
2352 struct berval digest;
2353 digest.bv_val = HASHdigest;
2354 digest.bv_len = sizeof(HASHdigest);
2356 /* we should have at least one value at this point */
2357 assert( values != NULL && values[0] != NULL );
2360 for( i=0; values[i] != NULL; i++ ) {
2361 /* count number of indices to generate */
2362 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2366 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2367 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2368 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2369 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2371 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2375 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2376 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2377 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2381 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2382 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2383 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2384 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2386 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2392 /* no keys to generate */
2394 return LDAP_SUCCESS;
2397 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2399 slen = strlen( syntax->ssyn_oid );
2400 mlen = strlen( mr->smr_oid );
2403 for( i=0; values[i] != NULL; i++ ) {
2405 struct berval *value;
2408 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2410 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2411 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2413 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2414 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2416 for( j=0; j<max; j++ ) {
2417 HASH_Init( &HASHcontext );
2418 if( prefix != NULL && prefix->bv_len > 0 ) {
2419 HASH_Update( &HASHcontext,
2420 prefix->bv_val, prefix->bv_len );
2423 HASH_Update( &HASHcontext,
2424 &pre, sizeof( pre ) );
2425 HASH_Update( &HASHcontext,
2426 syntax->ssyn_oid, slen );
2427 HASH_Update( &HASHcontext,
2428 mr->smr_oid, mlen );
2429 HASH_Update( &HASHcontext,
2431 SLAP_INDEX_SUBSTR_MAXLEN );
2432 HASH_Final( HASHdigest, &HASHcontext );
2434 keys[nkeys++] = ber_bvdup( &digest );
2438 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2439 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2441 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2444 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2445 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2446 HASH_Init( &HASHcontext );
2447 if( prefix != NULL && prefix->bv_len > 0 ) {
2448 HASH_Update( &HASHcontext,
2449 prefix->bv_val, prefix->bv_len );
2451 HASH_Update( &HASHcontext,
2452 &pre, sizeof( pre ) );
2453 HASH_Update( &HASHcontext,
2454 syntax->ssyn_oid, slen );
2455 HASH_Update( &HASHcontext,
2456 mr->smr_oid, mlen );
2457 HASH_Update( &HASHcontext,
2459 HASH_Final( HASHdigest, &HASHcontext );
2461 keys[nkeys++] = ber_bvdup( &digest );
2464 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2465 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
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-j], j );
2479 HASH_Final( HASHdigest, &HASHcontext );
2481 keys[nkeys++] = ber_bvdup( &digest );
2495 return LDAP_SUCCESS;
2498 int caseExactIA5SubstringsFilter(
2503 struct berval *prefix,
2505 struct berval ***keysp )
2507 SubstringsAssertion *sa = assertValue;
2509 ber_len_t nkeys = 0;
2510 size_t slen, mlen, klen;
2511 struct berval **keys;
2512 HASH_CONTEXT HASHcontext;
2513 unsigned char HASHdigest[HASH_BYTES];
2514 struct berval *value;
2515 struct berval digest;
2517 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2518 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2523 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2525 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2526 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2527 /* don't bother accounting for stepping */
2528 nkeys += sa->sa_any[i]->bv_len -
2529 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2534 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2535 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2542 return LDAP_SUCCESS;
2545 digest.bv_val = HASHdigest;
2546 digest.bv_len = sizeof(HASHdigest);
2548 slen = strlen( syntax->ssyn_oid );
2549 mlen = strlen( mr->smr_oid );
2551 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2554 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2555 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2557 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2558 value = sa->sa_initial;
2560 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2561 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2563 HASH_Init( &HASHcontext );
2564 if( prefix != NULL && prefix->bv_len > 0 ) {
2565 HASH_Update( &HASHcontext,
2566 prefix->bv_val, prefix->bv_len );
2568 HASH_Update( &HASHcontext,
2569 &pre, sizeof( pre ) );
2570 HASH_Update( &HASHcontext,
2571 syntax->ssyn_oid, slen );
2572 HASH_Update( &HASHcontext,
2573 mr->smr_oid, mlen );
2574 HASH_Update( &HASHcontext,
2575 value->bv_val, klen );
2576 HASH_Final( HASHdigest, &HASHcontext );
2578 keys[nkeys++] = ber_bvdup( &digest );
2581 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2583 pre = SLAP_INDEX_SUBSTR_PREFIX;
2584 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2586 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2587 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2591 value = sa->sa_any[i];
2594 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2595 j += SLAP_INDEX_SUBSTR_STEP )
2597 HASH_Init( &HASHcontext );
2598 if( prefix != NULL && prefix->bv_len > 0 ) {
2599 HASH_Update( &HASHcontext,
2600 prefix->bv_val, prefix->bv_len );
2602 HASH_Update( &HASHcontext,
2603 &pre, sizeof( pre ) );
2604 HASH_Update( &HASHcontext,
2605 syntax->ssyn_oid, slen );
2606 HASH_Update( &HASHcontext,
2607 mr->smr_oid, mlen );
2608 HASH_Update( &HASHcontext,
2609 &value->bv_val[j], klen );
2610 HASH_Final( HASHdigest, &HASHcontext );
2612 keys[nkeys++] = ber_bvdup( &digest );
2617 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2618 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2620 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2621 value = sa->sa_final;
2623 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2624 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2626 HASH_Init( &HASHcontext );
2627 if( prefix != NULL && prefix->bv_len > 0 ) {
2628 HASH_Update( &HASHcontext,
2629 prefix->bv_val, prefix->bv_len );
2631 HASH_Update( &HASHcontext,
2632 &pre, sizeof( pre ) );
2633 HASH_Update( &HASHcontext,
2634 syntax->ssyn_oid, slen );
2635 HASH_Update( &HASHcontext,
2636 mr->smr_oid, mlen );
2637 HASH_Update( &HASHcontext,
2638 &value->bv_val[value->bv_len-klen], klen );
2639 HASH_Final( HASHdigest, &HASHcontext );
2641 keys[nkeys++] = ber_bvdup( &digest );
2652 return LDAP_SUCCESS;
2661 struct berval *value,
2662 void *assertedValue )
2664 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2666 if( match == 0 && value->bv_len ) {
2667 match = strncasecmp( value->bv_val,
2668 ((struct berval *) assertedValue)->bv_val,
2673 return LDAP_SUCCESS;
2677 caseIgnoreIA5SubstringsMatch(
2682 struct berval *value,
2683 void *assertedValue )
2686 SubstringsAssertion *sub = assertedValue;
2687 struct berval left = *value;
2691 /* Add up asserted input length */
2692 if( sub->sa_initial ) {
2693 inlen += sub->sa_initial->bv_len;
2696 for(i=0; sub->sa_any[i] != NULL; i++) {
2697 inlen += sub->sa_any[i]->bv_len;
2700 if( sub->sa_final ) {
2701 inlen += sub->sa_final->bv_len;
2704 if( sub->sa_initial ) {
2705 if( inlen > left.bv_len ) {
2710 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2711 sub->sa_initial->bv_len );
2717 left.bv_val += sub->sa_initial->bv_len;
2718 left.bv_len -= sub->sa_initial->bv_len;
2719 inlen -= sub->sa_initial->bv_len;
2722 if( sub->sa_final ) {
2723 if( inlen > left.bv_len ) {
2728 match = strncasecmp( sub->sa_final->bv_val,
2729 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2730 sub->sa_final->bv_len );
2736 left.bv_len -= sub->sa_final->bv_len;
2737 inlen -= sub->sa_final->bv_len;
2741 for(i=0; sub->sa_any[i]; i++) {
2746 if( inlen > left.bv_len ) {
2747 /* not enough length */
2752 if( sub->sa_any[i]->bv_len == 0 ) {
2756 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2763 idx = p - left.bv_val;
2764 assert( idx < left.bv_len );
2766 if( idx >= left.bv_len ) {
2767 /* this shouldn't happen */
2774 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2775 /* not enough left */
2780 match = strncasecmp( left.bv_val,
2781 sub->sa_any[i]->bv_val,
2782 sub->sa_any[i]->bv_len );
2791 left.bv_val += sub->sa_any[i]->bv_len;
2792 left.bv_len -= sub->sa_any[i]->bv_len;
2793 inlen -= sub->sa_any[i]->bv_len;
2799 return LDAP_SUCCESS;
2802 /* Index generation function */
2803 int caseIgnoreIA5Indexer(
2808 struct berval *prefix,
2809 struct berval **values,
2810 struct berval ***keysp )
2814 struct berval **keys;
2815 HASH_CONTEXT HASHcontext;
2816 unsigned char HASHdigest[HASH_BYTES];
2817 struct berval digest;
2818 digest.bv_val = HASHdigest;
2819 digest.bv_len = sizeof(HASHdigest);
2821 /* we should have at least one value at this point */
2822 assert( values != NULL && values[0] != NULL );
2824 for( i=0; values[i] != NULL; i++ ) {
2825 /* just count them */
2828 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2830 slen = strlen( syntax->ssyn_oid );
2831 mlen = strlen( mr->smr_oid );
2833 for( i=0; values[i] != NULL; i++ ) {
2834 struct berval *value = ber_bvdup( values[i] );
2835 ldap_pvt_str2upper( value->bv_val );
2837 HASH_Init( &HASHcontext );
2838 if( prefix != NULL && prefix->bv_len > 0 ) {
2839 HASH_Update( &HASHcontext,
2840 prefix->bv_val, prefix->bv_len );
2842 HASH_Update( &HASHcontext,
2843 syntax->ssyn_oid, slen );
2844 HASH_Update( &HASHcontext,
2845 mr->smr_oid, mlen );
2846 HASH_Update( &HASHcontext,
2847 value->bv_val, value->bv_len );
2848 HASH_Final( HASHdigest, &HASHcontext );
2850 ber_bvfree( value );
2852 keys[i] = ber_bvdup( &digest );
2857 return LDAP_SUCCESS;
2860 /* Index generation function */
2861 int caseIgnoreIA5Filter(
2866 struct berval *prefix,
2868 struct berval ***keysp )
2871 struct berval **keys;
2872 HASH_CONTEXT HASHcontext;
2873 unsigned char HASHdigest[HASH_BYTES];
2874 struct berval *value;
2875 struct berval digest;
2876 digest.bv_val = HASHdigest;
2877 digest.bv_len = sizeof(HASHdigest);
2879 slen = strlen( syntax->ssyn_oid );
2880 mlen = strlen( mr->smr_oid );
2882 value = ber_bvdup( (struct berval *) assertValue );
2883 ldap_pvt_str2upper( value->bv_val );
2885 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2887 HASH_Init( &HASHcontext );
2888 if( prefix != NULL && prefix->bv_len > 0 ) {
2889 HASH_Update( &HASHcontext,
2890 prefix->bv_val, prefix->bv_len );
2892 HASH_Update( &HASHcontext,
2893 syntax->ssyn_oid, slen );
2894 HASH_Update( &HASHcontext,
2895 mr->smr_oid, mlen );
2896 HASH_Update( &HASHcontext,
2897 value->bv_val, value->bv_len );
2898 HASH_Final( HASHdigest, &HASHcontext );
2900 keys[0] = ber_bvdup( &digest );
2903 ber_bvfree( value );
2907 return LDAP_SUCCESS;
2910 /* Substrings Index generation function */
2911 int caseIgnoreIA5SubstringsIndexer(
2916 struct berval *prefix,
2917 struct berval **values,
2918 struct berval ***keysp )
2922 struct berval **keys;
2923 HASH_CONTEXT HASHcontext;
2924 unsigned char HASHdigest[HASH_BYTES];
2925 struct berval digest;
2926 digest.bv_val = HASHdigest;
2927 digest.bv_len = sizeof(HASHdigest);
2929 /* we should have at least one value at this point */
2930 assert( values != NULL && values[0] != NULL );
2933 for( i=0; values[i] != NULL; i++ ) {
2934 /* count number of indices to generate */
2935 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2939 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2940 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2941 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2942 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2944 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2948 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2949 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2950 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2954 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2955 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2956 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2957 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2959 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2965 /* no keys to generate */
2967 return LDAP_SUCCESS;
2970 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2972 slen = strlen( syntax->ssyn_oid );
2973 mlen = strlen( mr->smr_oid );
2976 for( i=0; values[i] != NULL; i++ ) {
2978 struct berval *value;
2980 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2982 value = ber_bvdup( values[i] );
2983 ldap_pvt_str2upper( value->bv_val );
2985 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2986 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2988 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2989 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2991 for( j=0; j<max; j++ ) {
2992 HASH_Init( &HASHcontext );
2993 if( prefix != NULL && prefix->bv_len > 0 ) {
2994 HASH_Update( &HASHcontext,
2995 prefix->bv_val, prefix->bv_len );
2998 HASH_Update( &HASHcontext,
2999 &pre, sizeof( pre ) );
3000 HASH_Update( &HASHcontext,
3001 syntax->ssyn_oid, slen );
3002 HASH_Update( &HASHcontext,
3003 mr->smr_oid, mlen );
3004 HASH_Update( &HASHcontext,
3006 SLAP_INDEX_SUBSTR_MAXLEN );
3007 HASH_Final( HASHdigest, &HASHcontext );
3009 keys[nkeys++] = ber_bvdup( &digest );
3013 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3014 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3016 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3019 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3020 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3021 HASH_Init( &HASHcontext );
3022 if( prefix != NULL && prefix->bv_len > 0 ) {
3023 HASH_Update( &HASHcontext,
3024 prefix->bv_val, prefix->bv_len );
3026 HASH_Update( &HASHcontext,
3027 &pre, sizeof( pre ) );
3028 HASH_Update( &HASHcontext,
3029 syntax->ssyn_oid, slen );
3030 HASH_Update( &HASHcontext,
3031 mr->smr_oid, mlen );
3032 HASH_Update( &HASHcontext,
3034 HASH_Final( HASHdigest, &HASHcontext );
3036 keys[nkeys++] = ber_bvdup( &digest );
3039 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3040 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3041 HASH_Init( &HASHcontext );
3042 if( prefix != NULL && prefix->bv_len > 0 ) {
3043 HASH_Update( &HASHcontext,
3044 prefix->bv_val, prefix->bv_len );
3046 HASH_Update( &HASHcontext,
3047 &pre, sizeof( pre ) );
3048 HASH_Update( &HASHcontext,
3049 syntax->ssyn_oid, slen );
3050 HASH_Update( &HASHcontext,
3051 mr->smr_oid, mlen );
3052 HASH_Update( &HASHcontext,
3053 &value->bv_val[value->bv_len-j], j );
3054 HASH_Final( HASHdigest, &HASHcontext );
3056 keys[nkeys++] = ber_bvdup( &digest );
3061 ber_bvfree( value );
3072 return LDAP_SUCCESS;
3075 int caseIgnoreIA5SubstringsFilter(
3080 struct berval *prefix,
3082 struct berval ***keysp )
3084 SubstringsAssertion *sa = assertValue;
3086 ber_len_t nkeys = 0;
3087 size_t slen, mlen, klen;
3088 struct berval **keys;
3089 HASH_CONTEXT HASHcontext;
3090 unsigned char HASHdigest[HASH_BYTES];
3091 struct berval *value;
3092 struct berval digest;
3094 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3095 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3100 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3102 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3103 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3104 /* don't bother accounting for stepping */
3105 nkeys += sa->sa_any[i]->bv_len -
3106 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3111 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3112 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3119 return LDAP_SUCCESS;
3122 digest.bv_val = HASHdigest;
3123 digest.bv_len = sizeof(HASHdigest);
3125 slen = strlen( syntax->ssyn_oid );
3126 mlen = strlen( mr->smr_oid );
3128 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3131 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3132 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3134 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3135 value = ber_bvdup( sa->sa_initial );
3136 ldap_pvt_str2upper( value->bv_val );
3138 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3139 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3141 HASH_Init( &HASHcontext );
3142 if( prefix != NULL && prefix->bv_len > 0 ) {
3143 HASH_Update( &HASHcontext,
3144 prefix->bv_val, prefix->bv_len );
3146 HASH_Update( &HASHcontext,
3147 &pre, sizeof( pre ) );
3148 HASH_Update( &HASHcontext,
3149 syntax->ssyn_oid, slen );
3150 HASH_Update( &HASHcontext,
3151 mr->smr_oid, mlen );
3152 HASH_Update( &HASHcontext,
3153 value->bv_val, klen );
3154 HASH_Final( HASHdigest, &HASHcontext );
3156 ber_bvfree( value );
3157 keys[nkeys++] = ber_bvdup( &digest );
3160 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3162 pre = SLAP_INDEX_SUBSTR_PREFIX;
3163 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3165 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3166 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3170 value = ber_bvdup( sa->sa_any[i] );
3171 ldap_pvt_str2upper( value->bv_val );
3174 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3175 j += SLAP_INDEX_SUBSTR_STEP )
3177 HASH_Init( &HASHcontext );
3178 if( prefix != NULL && prefix->bv_len > 0 ) {
3179 HASH_Update( &HASHcontext,
3180 prefix->bv_val, prefix->bv_len );
3182 HASH_Update( &HASHcontext,
3183 &pre, sizeof( pre ) );
3184 HASH_Update( &HASHcontext,
3185 syntax->ssyn_oid, slen );
3186 HASH_Update( &HASHcontext,
3187 mr->smr_oid, mlen );
3188 HASH_Update( &HASHcontext,
3189 &value->bv_val[j], klen );
3190 HASH_Final( HASHdigest, &HASHcontext );
3192 keys[nkeys++] = ber_bvdup( &digest );
3195 ber_bvfree( value );
3199 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3200 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3202 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3203 value = ber_bvdup( sa->sa_final );
3204 ldap_pvt_str2upper( value->bv_val );
3206 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3207 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3209 HASH_Init( &HASHcontext );
3210 if( prefix != NULL && prefix->bv_len > 0 ) {
3211 HASH_Update( &HASHcontext,
3212 prefix->bv_val, prefix->bv_len );
3214 HASH_Update( &HASHcontext,
3215 &pre, sizeof( pre ) );
3216 HASH_Update( &HASHcontext,
3217 syntax->ssyn_oid, slen );
3218 HASH_Update( &HASHcontext,
3219 mr->smr_oid, mlen );
3220 HASH_Update( &HASHcontext,
3221 &value->bv_val[value->bv_len-klen], klen );
3222 HASH_Final( HASHdigest, &HASHcontext );
3224 ber_bvfree( value );
3225 keys[nkeys++] = ber_bvdup( &digest );
3236 return LDAP_SUCCESS;
3240 numericStringValidate(
3246 for(i=0; i < in->bv_len; i++) {
3247 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3248 return LDAP_INVALID_SYNTAX;
3252 return LDAP_SUCCESS;
3256 numericStringNormalize(
3259 struct berval **normalized )
3261 /* removal all spaces */
3262 struct berval *newval;
3265 newval = ch_malloc( sizeof( struct berval ) );
3266 newval->bv_val = ch_malloc( val->bv_len + 1 );
3272 if ( ASCII_SPACE( *p ) ) {
3273 /* Ignore whitespace */
3280 /* we should have copied no more then is in val */
3281 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3283 /* null terminate */
3286 newval->bv_len = q - newval->bv_val;
3287 *normalized = newval;
3289 return LDAP_SUCCESS;
3293 objectIdentifierFirstComponentMatch(
3298 struct berval *value,
3299 void *assertedValue )
3301 int rc = LDAP_SUCCESS;
3303 struct berval *asserted = (struct berval *) assertedValue;
3307 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3308 return LDAP_INVALID_SYNTAX;
3311 /* trim leading white space */
3312 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3316 /* grab next word */
3317 oid.bv_val = &value->bv_val[i];
3318 oid.bv_len = value->bv_len - i;
3319 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3324 /* insert attributeTypes, objectclass check here */
3325 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3326 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3329 char *stored = ch_malloc( oid.bv_len + 1 );
3330 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3331 stored[oid.bv_len] = '\0';
3333 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3334 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3335 MatchingRule *stored_mr = mr_find( stored );
3337 if( asserted_mr == NULL ) {
3338 rc = SLAPD_COMPARE_UNDEFINED;
3340 match = asserted_mr != stored_mr;
3343 } else if ( !strcmp( syntax->ssyn_oid,
3344 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3346 AttributeType *asserted_at = at_find( asserted->bv_val );
3347 AttributeType *stored_at = at_find( stored );
3349 if( asserted_at == NULL ) {
3350 rc = SLAPD_COMPARE_UNDEFINED;
3352 match = asserted_at != stored_at;
3355 } else if ( !strcmp( syntax->ssyn_oid,
3356 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3358 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3359 ObjectClass *stored_oc = oc_find( stored );
3361 if( asserted_oc == NULL ) {
3362 rc = SLAPD_COMPARE_UNDEFINED;
3364 match = asserted_oc != stored_oc;
3372 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3373 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3374 match, value->bv_val, asserted->bv_val ));
3376 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3377 "%d\n\t\"%s\"\n\t\"%s\"\n",
3378 match, value->bv_val, asserted->bv_val );
3382 if( rc == LDAP_SUCCESS ) *matchp = match;
3392 struct berval *value,
3393 void *assertedValue )
3395 long lValue, lAssertedValue;
3397 /* safe to assume integers are NUL terminated? */
3398 lValue = strtoul(value->bv_val, NULL, 10);
3399 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3400 return LDAP_CONSTRAINT_VIOLATION;
3402 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3403 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3404 return LDAP_CONSTRAINT_VIOLATION;
3406 *matchp = (lValue & lAssertedValue);
3407 return LDAP_SUCCESS;
3416 struct berval *value,
3417 void *assertedValue )
3419 long lValue, lAssertedValue;
3421 /* safe to assume integers are NUL terminated? */
3422 lValue = strtoul(value->bv_val, NULL, 10);
3423 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3424 return LDAP_CONSTRAINT_VIOLATION;
3426 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3427 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3428 return LDAP_CONSTRAINT_VIOLATION;
3430 *matchp = (lValue | lAssertedValue);
3431 return LDAP_SUCCESS;
3435 #include <openssl/x509.h>
3436 #include <openssl/err.h>
3437 char digit[] = "0123456789";
3440 * Next function returns a string representation of a ASN1_INTEGER.
3441 * It works for unlimited lengths.
3444 static struct berval *
3445 asn1_integer2str(ASN1_INTEGER *a)
3450 /* We work backwards, make it fill from the end of buf */
3451 p = buf + sizeof(buf) - 1;
3454 if ( a == NULL || a->length == 0 ) {
3462 /* We want to preserve the original */
3463 copy = ch_malloc(n*sizeof(unsigned int));
3464 for (i = 0; i<n; i++) {
3465 copy[i] = a->data[i];
3469 * base indicates the index of the most significant
3470 * byte that might be nonzero. When it goes off the
3471 * end, we now there is nothing left to do.
3478 for (i = base; i<n; i++ ) {
3479 copy[i] += carry*256;
3480 carry = copy[i] % 10;
3485 * Way too large, we need to leave
3486 * room for sign if negative
3490 *--p = digit[carry];
3491 if (copy[base] == 0)
3497 if ( a->type == V_ASN1_NEG_INTEGER ) {
3501 return ber_bvstrdup(p);
3504 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3505 static struct berval *
3506 dn_openssl2ldap(X509_NAME *name)
3508 char issuer_dn[1024];
3511 bio = BIO_new(BIO_s_mem());
3514 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3515 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3516 ERR_error_string(ERR_get_error(),NULL)));
3518 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3519 "error creating BIO: %s\n",
3520 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3524 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3526 BIO_gets(bio, issuer_dn, 1024);
3529 return ber_bvstrdup(issuer_dn);
3533 * Given a certificate in DER format, extract the corresponding
3534 * assertion value for certificateExactMatch
3537 certificateExactConvert(
3539 struct berval ** out )
3542 unsigned char *p = in->bv_val;
3543 struct berval *serial;
3544 struct berval *issuer_dn;
3545 struct berval *bv_tmp;
3548 xcert = d2i_X509(NULL, &p, in->bv_len);
3551 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3552 "certificateExactConvert: error parsing cert: %s\n",
3553 ERR_error_string(ERR_get_error(),NULL)));
3555 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3556 "error parsing cert: %s\n",
3557 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3559 return LDAP_INVALID_SYNTAX;
3562 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3565 return LDAP_INVALID_SYNTAX;
3567 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3571 return LDAP_INVALID_SYNTAX;
3573 /* Actually, dn_openssl2ldap returns in a normalized format, but
3574 it is different from our normalized format */
3576 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3580 return LDAP_INVALID_SYNTAX;
3586 *out = ch_malloc(sizeof(struct berval));
3587 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3588 (*out)->bv_val = ch_malloc((*out)->bv_len);
3590 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3591 p += serial->bv_len;
3592 AC_MEMCPY(p, " $ ", 3);
3594 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3595 p += issuer_dn->bv_len;
3599 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3600 "certificateExactConvert: \n %s\n",
3603 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3605 (*out)->bv_val, NULL, NULL );
3609 ber_bvfree(issuer_dn);
3611 return LDAP_SUCCESS;
3615 serial_and_issuer_parse(
3616 struct berval *assertion,
3617 struct berval **serial,
3618 struct berval **issuer_dn
3626 begin = assertion->bv_val;
3627 end = assertion->bv_val+assertion->bv_len-1;
3628 for (p=begin; p<=end && *p != '$'; p++)
3631 return LDAP_INVALID_SYNTAX;
3633 /* p now points at the $ sign, now use begin and end to delimit the
3635 while (ASCII_SPACE(*begin))
3638 while (ASCII_SPACE(*end))
3641 q = ch_malloc( (end-begin+1)+1 );
3642 AC_MEMCPY( q, begin, end-begin+1 );
3643 q[end-begin+1] = '\0';
3644 *serial = ber_bvstr(q);
3646 /* now extract the issuer, remember p was at the dollar sign */
3648 end = assertion->bv_val+assertion->bv_len-1;
3649 while (ASCII_SPACE(*begin))
3651 /* should we trim spaces at the end too? is it safe always? */
3653 q = ch_malloc( (end-begin+1)+1 );
3654 AC_MEMCPY( q, begin, end-begin+1 );
3655 q[end-begin+1] = '\0';
3656 *issuer_dn = ber_bvstr(dn_normalize(q));
3658 return LDAP_SUCCESS;
3662 certificateExactMatch(
3667 struct berval *value,
3668 void *assertedValue )
3671 unsigned char *p = value->bv_val;
3672 struct berval *serial;
3673 struct berval *issuer_dn;
3674 struct berval *asserted_serial;
3675 struct berval *asserted_issuer_dn;
3678 xcert = d2i_X509(NULL, &p, value->bv_len);
3681 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3682 "certificateExactMatch: error parsing cert: %s\n",
3683 ERR_error_string(ERR_get_error(),NULL)));
3685 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3686 "error parsing cert: %s\n",
3687 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3689 return LDAP_INVALID_SYNTAX;
3692 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3693 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3697 serial_and_issuer_parse(assertedValue,
3699 &asserted_issuer_dn);
3704 slap_schema.si_syn_integer,
3705 slap_schema.si_mr_integerMatch,
3708 if ( ret == LDAP_SUCCESS ) {
3709 if ( *matchp == 0 ) {
3710 /* We need to normalize everything for dnMatch */
3714 slap_schema.si_syn_distinguishedName,
3715 slap_schema.si_mr_distinguishedNameMatch,
3717 asserted_issuer_dn);
3722 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3723 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3724 *matchp, serial->bv_val, issuer_dn->bv_val,
3725 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3727 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3728 "%d\n\t\"%s $ %s\"\n",
3729 *matchp, serial->bv_val, issuer_dn->bv_val );
3730 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3731 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3736 ber_bvfree(issuer_dn);
3737 ber_bvfree(asserted_serial);
3738 ber_bvfree(asserted_issuer_dn);
3744 * Index generation function
3745 * We just index the serials, in most scenarios the issuer DN is one of
3746 * a very small set of values.
3748 int certificateExactIndexer(
3753 struct berval *prefix,
3754 struct berval **values,
3755 struct berval ***keysp )
3758 struct berval **keys;
3761 struct berval * serial;
3763 /* we should have at least one value at this point */
3764 assert( values != NULL && values[0] != NULL );
3766 for( i=0; values[i] != NULL; i++ ) {
3767 /* empty -- just count them */
3770 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3772 for( i=0; values[i] != NULL; i++ ) {
3773 p = values[i]->bv_val;
3774 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
3777 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3778 "certificateExactIndexer: error parsing cert: %s\n",
3779 ERR_error_string(ERR_get_error(),NULL)));
3781 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3782 "error parsing cert: %s\n",
3783 ERR_error_string(ERR_get_error(),NULL),
3786 /* Do we leak keys on error? */
3787 return LDAP_INVALID_SYNTAX;
3790 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3792 integerNormalize( slap_schema.si_syn_integer,
3797 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3798 "certificateExactIndexer: returning: %s\n",
3801 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3810 return LDAP_SUCCESS;
3813 /* Index generation function */
3814 /* We think this is always called with a value in matching rule syntax */
3815 int certificateExactFilter(
3820 struct berval *prefix,
3822 struct berval ***keysp )
3824 struct berval **keys;
3825 struct berval *asserted_serial;
3826 struct berval *asserted_issuer_dn;
3828 serial_and_issuer_parse(assertValue,
3830 &asserted_issuer_dn);
3832 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3833 integerNormalize( syntax, asserted_serial, &keys[0] );
3837 ber_bvfree(asserted_serial);
3838 ber_bvfree(asserted_issuer_dn);
3839 return LDAP_SUCCESS;
3844 check_time_syntax (struct berval *val,
3848 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3849 static int mdays[2][12] = {
3850 /* non-leap years */
3851 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3853 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3856 int part, c, tzoffset, leapyear = 0 ;
3858 if( val->bv_len == 0 ) {
3859 return LDAP_INVALID_SYNTAX;
3862 p = (char *)val->bv_val;
3863 e = p + val->bv_len;
3865 /* Ignore initial whitespace */
3866 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3870 if (e - p < 13 - (2 * start)) {
3871 return LDAP_INVALID_SYNTAX;
3874 for (part = 0; part < 9; part++) {
3878 for (part = start; part < 7; part++) {
3880 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3887 return LDAP_INVALID_SYNTAX;
3889 if (c < 0 || c > 9) {
3890 return LDAP_INVALID_SYNTAX;
3896 return LDAP_INVALID_SYNTAX;
3898 if (c < 0 || c > 9) {
3899 return LDAP_INVALID_SYNTAX;
3904 if (part == 2 || part == 3) {
3907 if (parts[part] < 0) {
3908 return LDAP_INVALID_SYNTAX;
3910 if (parts[part] > ceiling[part]) {
3911 return LDAP_INVALID_SYNTAX;
3915 /* leapyear check for the Gregorian calendar (year>1581) */
3916 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3917 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3922 if (parts[3] > mdays[leapyear][parts[2]]) {
3923 return LDAP_INVALID_SYNTAX;
3928 tzoffset = 0; /* UTC */
3929 } else if (c != '+' && c != '-') {
3930 return LDAP_INVALID_SYNTAX;
3934 } else /* c == '+' */ {
3939 return LDAP_INVALID_SYNTAX;
3942 for (part = 7; part < 9; part++) {
3944 if (c < 0 || c > 9) {
3945 return LDAP_INVALID_SYNTAX;
3950 if (c < 0 || c > 9) {
3951 return LDAP_INVALID_SYNTAX;
3955 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3956 return LDAP_INVALID_SYNTAX;
3961 /* Ignore trailing whitespace */
3962 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3966 return LDAP_INVALID_SYNTAX;
3969 switch ( tzoffset ) {
3970 case -1: /* negativ offset to UTC, ie west of Greenwich */
3971 parts[4] += parts[7];
3972 parts[5] += parts[8];
3973 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3977 c = mdays[leapyear][parts[2]];
3979 if (parts[part] > c) {
3980 parts[part] -= c + 1;
3985 case 1: /* positive offset to UTC, ie east of Greenwich */
3986 parts[4] -= parts[7];
3987 parts[5] -= parts[8];
3988 for (part = 6; --part > 0; ) {
3992 /* first arg to % needs to be non negativ */
3993 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3995 if (parts[part] < 0) {
3996 parts[part] += c + 1;
4001 case 0: /* already UTC */
4005 return LDAP_SUCCESS;
4012 struct berval **normalized )
4017 rc = check_time_syntax(val, 1, parts);
4018 if (rc != LDAP_SUCCESS) {
4023 out = ch_malloc( sizeof(struct berval) );
4025 return LBER_ERROR_MEMORY;
4028 out->bv_val = ch_malloc( 14 );
4029 if ( out->bv_val == NULL ) {
4031 return LBER_ERROR_MEMORY;
4034 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
4035 parts[1], parts[2] + 1, parts[3] + 1,
4036 parts[4], parts[5], parts[6] );
4040 return LDAP_SUCCESS;
4050 return check_time_syntax(in, 1, parts);
4054 generalizedTimeValidate(
4060 return check_time_syntax(in, 0, parts);
4064 generalizedTimeNormalize(
4067 struct berval **normalized )
4072 rc = check_time_syntax(val, 0, parts);
4073 if (rc != LDAP_SUCCESS) {
4078 out = ch_malloc( sizeof(struct berval) );
4080 return LBER_ERROR_MEMORY;
4083 out->bv_val = ch_malloc( 16 );
4084 if ( out->bv_val == NULL ) {
4086 return LBER_ERROR_MEMORY;
4089 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4090 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4091 parts[4], parts[5], parts[6] );
4095 return LDAP_SUCCESS;
4099 nisNetgroupTripleValidate(
4101 struct berval *val )
4106 if ( val->bv_len == 0 ) {
4107 return LDAP_INVALID_SYNTAX;
4110 p = (char *)val->bv_val;
4111 e = p + val->bv_len;
4113 if ( *p != '(' /*')'*/ ) {
4114 return LDAP_INVALID_SYNTAX;
4117 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4121 return LDAP_INVALID_SYNTAX;
4124 } else if ( !ATTR_CHAR( *p ) ) {
4125 return LDAP_INVALID_SYNTAX;
4129 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4130 return LDAP_INVALID_SYNTAX;
4136 return LDAP_INVALID_SYNTAX;
4139 return LDAP_SUCCESS;
4143 bootParameterValidate(
4145 struct berval *val )
4149 if ( val->bv_len == 0 ) {
4150 return LDAP_INVALID_SYNTAX;
4153 p = (char *)val->bv_val;
4154 e = p + val->bv_len;
4157 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4158 if ( !ATTR_CHAR( *p ) ) {
4159 return LDAP_INVALID_SYNTAX;
4164 return LDAP_INVALID_SYNTAX;
4168 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4169 if ( !ATTR_CHAR( *p ) ) {
4170 return LDAP_INVALID_SYNTAX;
4175 return LDAP_INVALID_SYNTAX;
4179 for ( p++; p < e; p++ ) {
4180 if ( !ATTR_CHAR( *p ) ) {
4181 return LDAP_INVALID_SYNTAX;
4185 return LDAP_SUCCESS;
4188 struct syntax_defs_rec {
4191 slap_syntax_validate_func *sd_validate;
4192 slap_syntax_transform_func *sd_normalize;
4193 slap_syntax_transform_func *sd_pretty;
4194 #ifdef SLAPD_BINARY_CONVERSION
4195 slap_syntax_transform_func *sd_ber2str;
4196 slap_syntax_transform_func *sd_str2ber;
4200 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4201 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4203 struct syntax_defs_rec syntax_defs[] = {
4204 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4205 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4207 0, NULL, NULL, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4209 0, NULL, NULL, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4211 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4213 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4215 0, bitStringValidate, NULL, NULL },
4216 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4217 0, booleanValidate, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4219 X_BINARY X_NOT_H_R ")",
4220 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4222 X_BINARY X_NOT_H_R ")",
4223 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4225 X_BINARY X_NOT_H_R ")",
4226 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4227 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4228 0, countryStringValidate, IA5StringNormalize, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4230 0, dnValidate, dnNormalize, dnPretty},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4232 0, NULL, NULL, NULL},
4233 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4234 0, NULL, NULL, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4236 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4238 0, NULL, NULL, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4240 0, NULL, NULL, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4242 0, NULL, NULL, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4244 0, NULL, NULL, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4246 0, NULL, NULL, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4248 0, printablesStringValidate, IA5StringNormalize, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4250 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4251 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4252 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4253 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4254 0, NULL, NULL, NULL},
4255 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4256 0, IA5StringValidate, IA5StringNormalize, NULL},
4257 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4258 0, integerValidate, integerNormalize, NULL},
4259 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4260 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4261 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4262 0, NULL, NULL, NULL},
4263 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4264 0, NULL, NULL, NULL},
4265 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4266 0, NULL, NULL, NULL},
4267 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4268 0, NULL, NULL, NULL},
4269 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4270 0, NULL, NULL, NULL},
4271 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4272 0, nameUIDValidate, nameUIDNormalize, NULL},
4273 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4274 0, NULL, NULL, NULL},
4275 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4276 0, numericStringValidate, numericStringNormalize, NULL},
4277 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4278 0, NULL, NULL, NULL},
4279 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4280 0, oidValidate, NULL, NULL},
4281 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4282 0, IA5StringValidate, IA5StringNormalize, NULL},
4283 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4284 0, blobValidate, NULL, NULL},
4285 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4286 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4287 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4288 0, NULL, NULL, NULL},
4289 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4290 0, NULL, NULL, NULL},
4291 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4292 0, printableStringValidate, IA5StringNormalize, NULL},
4293 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4294 X_BINARY X_NOT_H_R ")",
4295 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4296 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4297 0, printableStringValidate, IA5StringNormalize, NULL},
4298 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4299 0, NULL, NULL, NULL},
4300 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4301 0, printablesStringValidate, IA5StringNormalize, NULL},
4302 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4303 0, utcTimeValidate, utcTimeNormalize, NULL},
4304 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4305 0, NULL, NULL, NULL},
4306 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4307 0, NULL, NULL, NULL},
4308 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4309 0, NULL, NULL, NULL},
4310 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4311 0, NULL, NULL, NULL},
4312 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4313 0, NULL, NULL, NULL},
4315 /* RFC 2307 NIS Syntaxes */
4316 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4317 0, nisNetgroupTripleValidate, NULL, NULL},
4318 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4319 0, bootParameterValidate, NULL, NULL},
4323 /* These OIDs are not published yet, but will be in the next
4324 * I-D for PKIX LDAPv3 schema as have been advanced by David
4325 * Chadwick in private mail.
4327 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4328 0, NULL, NULL, NULL},
4331 /* OpenLDAP Experimental Syntaxes */
4332 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4333 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4335 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4336 0, NULL, NULL, NULL},
4338 /* OpenLDAP Void Syntax */
4339 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4340 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4341 {NULL, 0, NULL, NULL, NULL}
4344 struct mrule_defs_rec {
4346 slap_mask_t mrd_usage;
4347 slap_mr_convert_func * mrd_convert;
4348 slap_mr_normalize_func * mrd_normalize;
4349 slap_mr_match_func * mrd_match;
4350 slap_mr_indexer_func * mrd_indexer;
4351 slap_mr_filter_func * mrd_filter;
4353 char * mrd_associated;
4357 * Other matching rules in X.520 that we do not use (yet):
4359 * 2.5.13.9 numericStringOrderingMatch
4360 * 2.5.13.15 integerOrderingMatch
4361 * 2.5.13.18 octetStringOrderingMatch
4362 * 2.5.13.19 octetStringSubstringsMatch
4363 * 2.5.13.25 uTCTimeMatch
4364 * 2.5.13.26 uTCTimeOrderingMatch
4365 * 2.5.13.31 directoryStringFirstComponentMatch
4366 * 2.5.13.32 wordMatch
4367 * 2.5.13.33 keywordMatch
4368 * 2.5.13.35 certificateMatch
4369 * 2.5.13.36 certificatePairExactMatch
4370 * 2.5.13.37 certificatePairMatch
4371 * 2.5.13.38 certificateListExactMatch
4372 * 2.5.13.39 certificateListMatch
4373 * 2.5.13.40 algorithmIdentifierMatch
4374 * 2.5.13.41 storedPrefixMatch
4375 * 2.5.13.42 attributeCertificateMatch
4376 * 2.5.13.43 readerAndKeyIDMatch
4377 * 2.5.13.44 attributeIntegrityMatch
4380 struct mrule_defs_rec mrule_defs[] = {
4382 * EQUALITY matching rules must be listed after associated APPROX
4383 * matching rules. So, we list all APPROX matching rules first.
4385 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4386 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4387 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4389 directoryStringApproxMatch,
4390 directoryStringApproxIndexer,
4391 directoryStringApproxFilter,
4394 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4395 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4396 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4398 IA5StringApproxMatch,
4399 IA5StringApproxIndexer,
4400 IA5StringApproxFilter,
4404 * Other matching rules
4407 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4408 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4409 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4411 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4414 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4415 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4416 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4418 dnMatch, dnIndexer, dnFilter,
4421 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4422 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4423 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4425 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4426 directoryStringApproxMatchOID },
4428 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4429 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4432 caseIgnoreOrderingMatch, NULL, NULL,
4435 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4436 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4437 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4439 caseExactIgnoreSubstringsMatch,
4440 caseExactIgnoreSubstringsIndexer,
4441 caseExactIgnoreSubstringsFilter,
4444 {"( 2.5.13.5 NAME 'caseExactMatch' "
4445 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4446 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4448 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4449 directoryStringApproxMatchOID },
4451 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4452 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4455 caseExactOrderingMatch, NULL, NULL,
4458 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4459 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4460 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4462 caseExactIgnoreSubstringsMatch,
4463 caseExactIgnoreSubstringsIndexer,
4464 caseExactIgnoreSubstringsFilter,
4467 {"( 2.5.13.8 NAME 'numericStringMatch' "
4468 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4469 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4472 caseIgnoreIA5Indexer,
4473 caseIgnoreIA5Filter,
4476 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4477 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4478 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4480 caseIgnoreIA5SubstringsMatch,
4481 caseIgnoreIA5SubstringsIndexer,
4482 caseIgnoreIA5SubstringsFilter,
4485 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4486 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4487 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4489 caseIgnoreListMatch, NULL, NULL,
4492 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4493 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4494 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4496 caseIgnoreListSubstringsMatch, NULL, NULL,
4499 {"( 2.5.13.13 NAME 'booleanMatch' "
4500 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4501 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4503 booleanMatch, NULL, NULL,
4506 {"( 2.5.13.14 NAME 'integerMatch' "
4507 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4508 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4510 integerMatch, integerIndexer, integerFilter,
4513 {"( 2.5.13.16 NAME 'bitStringMatch' "
4514 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4515 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4517 bitStringMatch, NULL, NULL,
4520 {"( 2.5.13.17 NAME 'octetStringMatch' "
4521 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4522 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4524 octetStringMatch, octetStringIndexer, octetStringFilter,
4527 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4528 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4529 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4531 telephoneNumberMatch,
4532 telephoneNumberIndexer,
4533 telephoneNumberFilter,
4536 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4537 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4538 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4540 telephoneNumberSubstringsMatch,
4541 telephoneNumberSubstringsIndexer,
4542 telephoneNumberSubstringsFilter,
4545 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4546 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4547 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4552 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4553 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4554 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4556 uniqueMemberMatch, NULL, NULL,
4559 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4560 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4561 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4563 protocolInformationMatch, NULL, NULL,
4566 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4567 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4568 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4570 generalizedTimeMatch, NULL, NULL,
4573 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4574 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4577 generalizedTimeOrderingMatch, NULL, NULL,
4580 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4581 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4582 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4584 integerFirstComponentMatch, NULL, NULL,
4587 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4588 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4589 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4591 objectIdentifierFirstComponentMatch, NULL, NULL,
4595 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4596 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4597 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4598 certificateExactConvert, NULL,
4599 certificateExactMatch,
4600 certificateExactIndexer, certificateExactFilter,
4604 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4605 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4606 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4608 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4609 IA5StringApproxMatchOID },
4611 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4612 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4613 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4615 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4616 IA5StringApproxMatchOID },
4618 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4619 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4622 caseIgnoreIA5SubstringsMatch,
4623 caseIgnoreIA5SubstringsIndexer,
4624 caseIgnoreIA5SubstringsFilter,
4627 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4628 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4631 caseExactIA5SubstringsMatch,
4632 caseExactIA5SubstringsIndexer,
4633 caseExactIA5SubstringsFilter,
4636 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4637 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4640 authPasswordMatch, NULL, NULL,
4643 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4644 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4647 OpenLDAPaciMatch, NULL, NULL,
4650 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4651 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4654 integerBitAndMatch, NULL, NULL,
4657 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4658 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4661 integerBitOrMatch, NULL, NULL,
4664 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4673 /* we should only be called once (from main) */
4674 assert( schema_init_done == 0 );
4676 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4677 res = register_syntax( syntax_defs[i].sd_desc,
4678 syntax_defs[i].sd_flags,
4679 syntax_defs[i].sd_validate,
4680 syntax_defs[i].sd_normalize,
4681 syntax_defs[i].sd_pretty
4682 #ifdef SLAPD_BINARY_CONVERSION
4684 syntax_defs[i].sd_ber2str,
4685 syntax_defs[i].sd_str2ber
4690 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4691 syntax_defs[i].sd_desc );
4696 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4697 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4699 "schema_init: Ingoring unusable matching rule %s\n",
4700 mrule_defs[i].mrd_desc );
4704 res = register_matching_rule(
4705 mrule_defs[i].mrd_desc,
4706 mrule_defs[i].mrd_usage,
4707 mrule_defs[i].mrd_convert,
4708 mrule_defs[i].mrd_normalize,
4709 mrule_defs[i].mrd_match,
4710 mrule_defs[i].mrd_indexer,
4711 mrule_defs[i].mrd_filter,
4712 mrule_defs[i].mrd_associated );
4716 "schema_init: Error registering matching rule %s\n",
4717 mrule_defs[i].mrd_desc );
4721 schema_init_done = 1;
4722 return LDAP_SUCCESS;