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