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, 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 dn->bv_val[i-1] != 'B' ||
336 dn->bv_val[i-2] != '#' ) {
338 return LDAP_INVALID_SYNTAX;
341 /* trim the UID to allow use of dn_validate */
342 dn->bv_val[i-2] = '\0';
345 rc = dn_validate( dn->bv_val ) == NULL
346 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
356 struct berval **normalized )
358 struct berval *out = ber_bvdup( val );
360 if( out->bv_len != 0 ) {
364 ber_len_t uidlen = 0;
366 if( out->bv_val[out->bv_len-1] == '\'' ) {
367 /* assume presence of optional UID */
368 uid = strrchr( out->bv_val, '#' );
372 return LDAP_INVALID_SYNTAX;
375 uidlen = out->bv_len - (out->bv_val - uid);
376 /* temporarily trim the UID */
380 #ifdef USE_DN_NORMALIZE
381 dn = dn_normalize( out->bv_val );
383 dn = dn_validate( out->bv_val );
388 return LDAP_INVALID_SYNTAX;
394 /* restore the separator */
397 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
401 out->bv_len = dnlen + uidlen;
413 /* any value allowed */
422 /* any value allowed */
433 /* very unforgiving validation, requires no normalization
434 * before simplistic matching
436 if( in->bv_len < 3 ) {
437 return LDAP_INVALID_SYNTAX;
440 if( in->bv_val[0] != 'B' ||
441 in->bv_val[1] != '\'' ||
442 in->bv_val[in->bv_len-1] != '\'' )
444 return LDAP_INVALID_SYNTAX;
447 for( i=in->bv_len-2; i>1; i-- ) {
448 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
449 return LDAP_INVALID_SYNTAX;
457 * Handling boolean syntax and matching is quite rigid.
458 * A more flexible approach would be to allow a variety
459 * of strings to be normalized and prettied into TRUE
467 /* very unforgiving validation, requires no normalization
468 * before simplistic matching
471 if( in->bv_len == 4 ) {
472 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
475 } else if( in->bv_len == 5 ) {
476 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
481 return LDAP_INVALID_SYNTAX;
490 struct berval *value,
491 void *assertedValue )
493 /* simplistic matching allowed by rigid validation */
494 struct berval *asserted = (struct berval *) assertedValue;
495 *matchp = value->bv_len != asserted->bv_len;
506 unsigned char *u = in->bv_val;
508 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
510 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
511 /* get the length indicated by the first byte */
512 len = LDAP_UTF8_CHARLEN( u );
514 /* should not be zero */
515 if( len == 0 ) return LDAP_INVALID_SYNTAX;
517 /* make sure len corresponds with the offset
518 to the next character */
519 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
522 if( count != 0 ) return LDAP_INVALID_SYNTAX;
531 struct berval **normalized )
533 struct berval *newval;
536 newval = ch_malloc( sizeof( struct berval ) );
540 /* Ignore initial whitespace */
541 while ( ldap_utf8_isspace( p ) ) {
547 return LDAP_INVALID_SYNTAX;
550 newval->bv_val = ch_strdup( p );
551 p = q = newval->bv_val;
557 if ( ldap_utf8_isspace( p ) ) {
558 len = LDAP_UTF8_COPY(q,p);
563 /* Ignore the extra whitespace */
564 while ( ldap_utf8_isspace( p ) ) {
568 len = LDAP_UTF8_COPY(q,p);
575 assert( *newval->bv_val );
576 assert( newval->bv_val < p );
579 /* cannot start with a space */
580 assert( !ldap_utf8_isspace(newval->bv_val) );
583 * If the string ended in space, backup the pointer one
584 * position. One is enough because the above loop collapsed
585 * all whitespace to a single space.
592 /* cannot end with a space */
593 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
598 newval->bv_len = q - newval->bv_val;
599 *normalized = newval;
604 /* Returns Unicode cannonically normalized copy of a substring assertion
605 * Skipping attribute description */
606 SubstringsAssertion *
607 UTF8SubstringsassertionNormalize(
608 SubstringsAssertion *sa,
611 SubstringsAssertion *nsa;
614 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
619 if( sa->sa_initial != NULL ) {
620 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
621 if( nsa->sa_initial == NULL ) {
626 if( sa->sa_any != NULL ) {
627 for( i=0; sa->sa_any[i] != NULL; i++ ) {
630 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
631 for( i=0; sa->sa_any[i] != NULL; i++ ) {
632 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
633 if( nsa->sa_any[i] == NULL ) {
637 nsa->sa_any[i] = NULL;
640 if( sa->sa_final != NULL ) {
641 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
642 if( nsa->sa_final == NULL ) {
650 ber_bvfree( nsa->sa_final );
651 ber_bvecfree( nsa->sa_any );
652 ber_bvfree( nsa->sa_initial );
657 /* Strip characters with the 8th bit set */
670 while( *++q & 0x80 ) {
673 p = memmove(p, q, strlen(q) + 1);
681 #ifndef SLAPD_APPROX_OLDSINGLESTRING
683 #if defined(SLAPD_APPROX_INITIALS)
684 #define SLAPD_APPROX_DELIMITER "._ "
685 #define SLAPD_APPROX_WORDLEN 2
687 #define SLAPD_APPROX_DELIMITER " "
688 #define SLAPD_APPROX_WORDLEN 1
697 struct berval *value,
698 void *assertedValue )
700 char *val, *nval, *assertv, **values, **words, *c;
701 int i, count, len, nextchunk=0, nextavail=0;
704 /* Yes, this is necessary */
705 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
710 strip8bitChars( nval );
712 /* Yes, this is necessary */
713 assertv = UTF8normalize( ((struct berval *)assertedValue),
715 if( assertv == NULL ) {
720 strip8bitChars( assertv );
721 avlen = strlen( assertv );
723 /* Isolate how many words there are */
724 for( c=nval,count=1; *c; c++ ) {
725 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
726 if ( c == NULL ) break;
731 /* Get a phonetic copy of each word */
732 words = (char **)ch_malloc( count * sizeof(char *) );
733 values = (char **)ch_malloc( count * sizeof(char *) );
734 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
736 values[i] = phonetic(c);
739 /* Work through the asserted value's words, to see if at least some
740 of the words are there, in the same order. */
742 while ( nextchunk < avlen ) {
743 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
748 #if defined(SLAPD_APPROX_INITIALS)
749 else if( len == 1 ) {
750 /* Single letter words need to at least match one word's initial */
751 for( i=nextavail; i<count; i++ )
752 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
759 /* Isolate the next word in the asserted value and phonetic it */
760 assertv[nextchunk+len] = '\0';
761 val = phonetic( assertv + nextchunk );
763 /* See if this phonetic chunk is in the remaining words of *value */
764 for( i=nextavail; i<count; i++ ){
765 if( !strcmp( val, values[i] ) ){
773 /* This chunk in the asserted value was NOT within the *value. */
779 /* Go on to the next word in the asserted value */
783 /* If some of the words were seen, call it a match */
784 if( nextavail > 0 ) {
793 for( i=0; i<count; i++ ) {
794 ch_free( values[i] );
809 struct berval *prefix,
810 struct berval **values,
811 struct berval ***keysp )
814 int i,j, len, wordcount, keycount=0;
815 struct berval **newkeys, **keys=NULL;
817 for( j=0; values[j] != NULL; j++ ) {
818 /* Yes, this is necessary */
819 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
820 strip8bitChars( val );
822 /* Isolate how many words there are. There will be a key for each */
823 for( wordcount=0,c=val; *c; c++) {
824 len = strcspn(c, SLAPD_APPROX_DELIMITER);
825 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
827 if (*c == '\0') break;
831 /* Allocate/increase storage to account for new keys */
832 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
833 * sizeof(struct berval *) );
834 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
835 if( keys ) ch_free( keys );
838 /* Get a phonetic copy of each word */
839 for( c=val,i=0; i<wordcount; c+=len+1 ) {
841 if( len < SLAPD_APPROX_WORDLEN ) continue;
842 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
843 keys[keycount]->bv_val = phonetic( c );
844 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
851 keys[keycount] = NULL;
863 struct berval *prefix,
865 struct berval ***keysp )
869 struct berval **keys;
871 /* Yes, this is necessary */
872 val = UTF8normalize( ((struct berval *)assertValue),
875 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
880 strip8bitChars( val );
882 /* Isolate how many words there are. There will be a key for each */
883 for( count=0,c=val; *c; c++) {
884 len = strcspn(c, SLAPD_APPROX_DELIMITER);
885 if( len >= SLAPD_APPROX_WORDLEN ) count++;
887 if (*c == '\0') break;
891 /* Allocate storage for new keys */
892 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
894 /* Get a phonetic copy of each word */
895 for( c=val,i=0; i<count; c+=len+1 ) {
897 if( len < SLAPD_APPROX_WORDLEN ) continue;
898 keys[i] = ber_bvstr( phonetic( c ) );
912 /* No other form of Approximate Matching is defined */
920 struct berval *value,
921 void *assertedValue )
923 char *vapprox, *avapprox;
926 /* Yes, this is necessary */
927 s = UTF8normalize( value, UTF8_NOCASEFOLD );
933 /* Yes, this is necessary */
934 t = UTF8normalize( ((struct berval *)assertedValue),
942 vapprox = phonetic( strip8bitChars( s ) );
943 avapprox = phonetic( strip8bitChars( t ) );
948 *matchp = strcmp( vapprox, avapprox );
962 struct berval *prefix,
963 struct berval **values,
964 struct berval ***keysp )
967 struct berval **keys;
970 for( i=0; values[i] != NULL; i++ ) {
971 /* empty - just count them */
974 /* we should have at least one value at this point */
977 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
979 /* Copy each value and run it through phonetic() */
980 for( i=0; values[i] != NULL; i++ ) {
981 /* Yes, this is necessary */
982 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
984 /* strip 8-bit chars and run through phonetic() */
985 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1001 struct berval *prefix,
1003 struct berval ***keysp )
1005 struct berval **keys;
1008 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1010 /* Yes, this is necessary */
1011 s = UTF8normalize( ((struct berval *)assertValue),
1016 /* strip 8-bit chars and run through phonetic() */
1017 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1023 return LDAP_SUCCESS;
1034 struct berval *value,
1035 void *assertedValue )
1037 *matchp = UTF8normcmp( value->bv_val,
1038 ((struct berval *) assertedValue)->bv_val,
1040 return LDAP_SUCCESS;
1044 caseExactIgnoreSubstringsMatch(
1049 struct berval *value,
1050 void *assertedValue )
1053 SubstringsAssertion *sub;
1057 char *nav, casefold;
1059 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1060 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1062 nav = UTF8normalize( value, casefold );
1068 left.bv_len = strlen( nav );
1070 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1076 /* Add up asserted input length */
1077 if( sub->sa_initial ) {
1078 inlen += sub->sa_initial->bv_len;
1081 for(i=0; sub->sa_any[i] != NULL; i++) {
1082 inlen += sub->sa_any[i]->bv_len;
1085 if( sub->sa_final ) {
1086 inlen += sub->sa_final->bv_len;
1089 if( sub->sa_initial ) {
1090 if( inlen > left.bv_len ) {
1095 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1096 sub->sa_initial->bv_len );
1102 left.bv_val += sub->sa_initial->bv_len;
1103 left.bv_len -= sub->sa_initial->bv_len;
1104 inlen -= sub->sa_initial->bv_len;
1107 if( sub->sa_final ) {
1108 if( inlen > left.bv_len ) {
1113 match = strncmp( sub->sa_final->bv_val,
1114 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1115 sub->sa_final->bv_len );
1121 left.bv_len -= sub->sa_final->bv_len;
1122 inlen -= sub->sa_final->bv_len;
1126 for(i=0; sub->sa_any[i]; i++) {
1131 if( inlen > left.bv_len ) {
1132 /* not enough length */
1137 if( sub->sa_any[i]->bv_len == 0 ) {
1141 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1148 idx = p - left.bv_val;
1149 assert( idx < left.bv_len );
1151 if( idx >= left.bv_len ) {
1152 /* this shouldn't happen */
1154 ch_free( sub->sa_final );
1155 ber_bvecfree( sub->sa_any );
1156 ch_free( sub->sa_initial );
1164 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1165 /* not enough left */
1170 match = strncmp( left.bv_val,
1171 sub->sa_any[i]->bv_val,
1172 sub->sa_any[i]->bv_len );
1180 left.bv_val += sub->sa_any[i]->bv_len;
1181 left.bv_len -= sub->sa_any[i]->bv_len;
1182 inlen -= sub->sa_any[i]->bv_len;
1189 ber_bvfree( sub->sa_final );
1190 ber_bvecfree( sub->sa_any );
1191 ber_bvfree( sub->sa_initial );
1195 return LDAP_SUCCESS;
1198 /* Index generation function */
1199 int caseExactIgnoreIndexer(
1204 struct berval *prefix,
1205 struct berval **values,
1206 struct berval ***keysp )
1211 struct berval **keys;
1212 HASH_CONTEXT HASHcontext;
1213 unsigned char HASHdigest[HASH_BYTES];
1214 struct berval digest;
1215 digest.bv_val = HASHdigest;
1216 digest.bv_len = sizeof(HASHdigest);
1218 for( i=0; values[i] != NULL; i++ ) {
1219 /* empty - just count them */
1222 /* we should have at least one value at this point */
1225 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1227 slen = strlen( syntax->ssyn_oid );
1228 mlen = strlen( mr->smr_oid );
1230 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1231 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1233 for( i=0; values[i] != NULL; i++ ) {
1234 struct berval *value;
1235 value = ber_bvstr( UTF8normalize( values[i],
1238 HASH_Init( &HASHcontext );
1239 if( prefix != NULL && prefix->bv_len > 0 ) {
1240 HASH_Update( &HASHcontext,
1241 prefix->bv_val, prefix->bv_len );
1243 HASH_Update( &HASHcontext,
1244 syntax->ssyn_oid, slen );
1245 HASH_Update( &HASHcontext,
1246 mr->smr_oid, mlen );
1247 HASH_Update( &HASHcontext,
1248 value->bv_val, value->bv_len );
1249 HASH_Final( HASHdigest, &HASHcontext );
1251 ber_bvfree( value );
1253 keys[i] = ber_bvdup( &digest );
1258 return LDAP_SUCCESS;
1261 /* Index generation function */
1262 int caseExactIgnoreFilter(
1267 struct berval *prefix,
1269 struct berval ***keysp )
1273 struct berval **keys;
1274 HASH_CONTEXT HASHcontext;
1275 unsigned char HASHdigest[HASH_BYTES];
1276 struct berval *value;
1277 struct berval digest;
1278 digest.bv_val = HASHdigest;
1279 digest.bv_len = sizeof(HASHdigest);
1281 slen = strlen( syntax->ssyn_oid );
1282 mlen = strlen( mr->smr_oid );
1284 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1285 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1287 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
1289 /* This usually happens if filter contains bad UTF8 */
1290 if( value == NULL ) {
1291 keys = ch_malloc( sizeof( struct berval * ) );
1293 return LDAP_SUCCESS;
1296 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1298 HASH_Init( &HASHcontext );
1299 if( prefix != NULL && prefix->bv_len > 0 ) {
1300 HASH_Update( &HASHcontext,
1301 prefix->bv_val, prefix->bv_len );
1303 HASH_Update( &HASHcontext,
1304 syntax->ssyn_oid, slen );
1305 HASH_Update( &HASHcontext,
1306 mr->smr_oid, mlen );
1307 HASH_Update( &HASHcontext,
1308 value->bv_val, value->bv_len );
1309 HASH_Final( HASHdigest, &HASHcontext );
1311 keys[0] = ber_bvdup( &digest );
1314 ber_bvfree( value );
1317 return LDAP_SUCCESS;
1320 /* Substrings Index generation function */
1321 int caseExactIgnoreSubstringsIndexer(
1326 struct berval *prefix,
1327 struct berval **values,
1328 struct berval ***keysp )
1333 struct berval **keys;
1334 struct berval **nvalues;
1336 HASH_CONTEXT HASHcontext;
1337 unsigned char HASHdigest[HASH_BYTES];
1338 struct berval digest;
1339 digest.bv_val = HASHdigest;
1340 digest.bv_len = sizeof(HASHdigest);
1344 for( i=0; values[i] != NULL; i++ ) {
1345 /* empty - just count them */
1348 /* we should have at least one value at this point */
1351 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1352 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1354 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1355 for( i=0; values[i] != NULL; i++ ) {
1356 nvalues[i] = ber_bvstr( UTF8normalize( values[i],
1362 for( i=0; values[i] != NULL; i++ ) {
1363 /* count number of indices to generate */
1364 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1368 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1369 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1370 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1371 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1373 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1377 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1378 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1379 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1383 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1384 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1385 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1386 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1388 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1394 /* no keys to generate */
1396 ber_bvecfree( nvalues );
1397 return LDAP_SUCCESS;
1400 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1402 slen = strlen( syntax->ssyn_oid );
1403 mlen = strlen( mr->smr_oid );
1406 for( i=0; values[i] != NULL; i++ ) {
1408 struct berval *value;
1410 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1414 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1415 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1417 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1418 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1420 for( j=0; j<max; j++ ) {
1421 HASH_Init( &HASHcontext );
1422 if( prefix != NULL && prefix->bv_len > 0 ) {
1423 HASH_Update( &HASHcontext,
1424 prefix->bv_val, prefix->bv_len );
1427 HASH_Update( &HASHcontext,
1428 &pre, sizeof( pre ) );
1429 HASH_Update( &HASHcontext,
1430 syntax->ssyn_oid, slen );
1431 HASH_Update( &HASHcontext,
1432 mr->smr_oid, mlen );
1433 HASH_Update( &HASHcontext,
1435 SLAP_INDEX_SUBSTR_MAXLEN );
1436 HASH_Final( HASHdigest, &HASHcontext );
1438 keys[nkeys++] = ber_bvdup( &digest );
1442 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1443 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1445 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1448 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1449 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1450 HASH_Init( &HASHcontext );
1451 if( prefix != NULL && prefix->bv_len > 0 ) {
1452 HASH_Update( &HASHcontext,
1453 prefix->bv_val, prefix->bv_len );
1455 HASH_Update( &HASHcontext,
1456 &pre, sizeof( pre ) );
1457 HASH_Update( &HASHcontext,
1458 syntax->ssyn_oid, slen );
1459 HASH_Update( &HASHcontext,
1460 mr->smr_oid, mlen );
1461 HASH_Update( &HASHcontext,
1463 HASH_Final( HASHdigest, &HASHcontext );
1465 keys[nkeys++] = ber_bvdup( &digest );
1468 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1469 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1470 HASH_Init( &HASHcontext );
1471 if( prefix != NULL && prefix->bv_len > 0 ) {
1472 HASH_Update( &HASHcontext,
1473 prefix->bv_val, prefix->bv_len );
1475 HASH_Update( &HASHcontext,
1476 &pre, sizeof( pre ) );
1477 HASH_Update( &HASHcontext,
1478 syntax->ssyn_oid, slen );
1479 HASH_Update( &HASHcontext,
1480 mr->smr_oid, mlen );
1481 HASH_Update( &HASHcontext,
1482 &value->bv_val[value->bv_len-j], j );
1483 HASH_Final( HASHdigest, &HASHcontext );
1485 keys[nkeys++] = ber_bvdup( &digest );
1500 ber_bvecfree( nvalues );
1502 return LDAP_SUCCESS;
1505 int caseExactIgnoreSubstringsFilter(
1510 struct berval *prefix,
1512 struct berval ***keysp )
1514 SubstringsAssertion *sa;
1516 ber_len_t nkeys = 0;
1517 size_t slen, mlen, klen;
1518 struct berval **keys;
1519 HASH_CONTEXT HASHcontext;
1520 unsigned char HASHdigest[HASH_BYTES];
1521 struct berval *value;
1522 struct berval digest;
1524 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1525 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1527 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1530 return LDAP_SUCCESS;
1533 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1534 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1539 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1541 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1542 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1543 /* don't bother accounting for stepping */
1544 nkeys += sa->sa_any[i]->bv_len -
1545 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1550 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1551 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1557 ber_bvfree( sa->sa_final );
1558 ber_bvecfree( sa->sa_any );
1559 ber_bvfree( sa->sa_initial );
1562 return LDAP_SUCCESS;
1565 digest.bv_val = HASHdigest;
1566 digest.bv_len = sizeof(HASHdigest);
1568 slen = strlen( syntax->ssyn_oid );
1569 mlen = strlen( mr->smr_oid );
1571 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1574 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1575 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1577 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1578 value = sa->sa_initial;
1580 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1581 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1583 HASH_Init( &HASHcontext );
1584 if( prefix != NULL && prefix->bv_len > 0 ) {
1585 HASH_Update( &HASHcontext,
1586 prefix->bv_val, prefix->bv_len );
1588 HASH_Update( &HASHcontext,
1589 &pre, sizeof( pre ) );
1590 HASH_Update( &HASHcontext,
1591 syntax->ssyn_oid, slen );
1592 HASH_Update( &HASHcontext,
1593 mr->smr_oid, mlen );
1594 HASH_Update( &HASHcontext,
1595 value->bv_val, klen );
1596 HASH_Final( HASHdigest, &HASHcontext );
1598 keys[nkeys++] = ber_bvdup( &digest );
1601 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1603 pre = SLAP_INDEX_SUBSTR_PREFIX;
1604 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1606 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1607 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1611 value = sa->sa_any[i];
1614 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1615 j += SLAP_INDEX_SUBSTR_STEP )
1617 HASH_Init( &HASHcontext );
1618 if( prefix != NULL && prefix->bv_len > 0 ) {
1619 HASH_Update( &HASHcontext,
1620 prefix->bv_val, prefix->bv_len );
1622 HASH_Update( &HASHcontext,
1623 &pre, sizeof( pre ) );
1624 HASH_Update( &HASHcontext,
1625 syntax->ssyn_oid, slen );
1626 HASH_Update( &HASHcontext,
1627 mr->smr_oid, mlen );
1628 HASH_Update( &HASHcontext,
1629 &value->bv_val[j], klen );
1630 HASH_Final( HASHdigest, &HASHcontext );
1632 keys[nkeys++] = ber_bvdup( &digest );
1638 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1639 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1641 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1642 value = sa->sa_final;
1644 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1645 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1647 HASH_Init( &HASHcontext );
1648 if( prefix != NULL && prefix->bv_len > 0 ) {
1649 HASH_Update( &HASHcontext,
1650 prefix->bv_val, prefix->bv_len );
1652 HASH_Update( &HASHcontext,
1653 &pre, sizeof( pre ) );
1654 HASH_Update( &HASHcontext,
1655 syntax->ssyn_oid, slen );
1656 HASH_Update( &HASHcontext,
1657 mr->smr_oid, mlen );
1658 HASH_Update( &HASHcontext,
1659 &value->bv_val[value->bv_len-klen], klen );
1660 HASH_Final( HASHdigest, &HASHcontext );
1662 keys[nkeys++] = ber_bvdup( &digest );
1672 ber_bvfree( sa->sa_final );
1673 ber_bvecfree( sa->sa_any );
1674 ber_bvfree( sa->sa_initial );
1677 return LDAP_SUCCESS;
1686 struct berval *value,
1687 void *assertedValue )
1689 *matchp = UTF8normcmp( value->bv_val,
1690 ((struct berval *) assertedValue)->bv_val,
1692 return LDAP_SUCCESS;
1698 struct berval *val )
1702 if( val->bv_len == 0 ) {
1703 /* disallow empty strings */
1704 return LDAP_INVALID_SYNTAX;
1707 if( OID_LEADCHAR(val->bv_val[0]) ) {
1709 for(i=1; i < val->bv_len; i++) {
1710 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1711 if( dot++ ) return 1;
1712 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1715 return LDAP_INVALID_SYNTAX;
1719 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1721 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1722 for(i=1; i < val->bv_len; i++) {
1723 if( !DESC_CHAR(val->bv_val[i] ) ) {
1724 return LDAP_INVALID_SYNTAX;
1728 return LDAP_SUCCESS;
1731 return LDAP_INVALID_SYNTAX;
1740 struct berval *value,
1741 void *assertedValue )
1744 int vsign=0, avsign=0;
1745 struct berval *asserted;
1746 ber_len_t vlen, avlen;
1749 /* Start off pessimistic */
1752 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1754 vlen = value->bv_len;
1756 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1757 /* empty -- skip spaces */
1759 else if ( *v == '+' ) {
1762 else if ( *v == '-' ) {
1765 else if ( ASCII_DIGIT(*v) ) {
1766 if ( vsign == 0 ) vsign = 1;
1774 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1776 asserted = (struct berval *) assertedValue;
1777 av = asserted->bv_val;
1778 avlen = asserted->bv_len;
1780 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1781 /* empty -- skip spaces */
1783 else if ( *av == '+' ) {
1786 else if ( *av == '-' ) {
1789 else if ( ASCII_DIGIT(*av) ) {
1790 if ( avsign == 0 ) avsign = 1;
1798 /* The two ?sign vars are now one of :
1799 -2 negative non-zero number
1801 0 0 collapse these three to 0
1803 +2 positive non-zero number
1805 if ( abs( vsign ) == 1 ) vsign = 0;
1806 if ( abs( avsign ) == 1 ) avsign = 0;
1808 if( vsign != avsign ) return LDAP_SUCCESS;
1810 /* Check the significant digits */
1811 while( vlen && avlen ) {
1812 if( *v != *av ) break;
1819 /* If all digits compared equal, the numbers are equal */
1820 if(( vlen == 0 ) && ( avlen == 0 )) {
1823 return LDAP_SUCCESS;
1829 struct berval *val )
1833 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1835 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1836 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1837 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1838 return LDAP_INVALID_SYNTAX;
1841 for( i=1; i < val->bv_len; i++ ) {
1842 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1845 return LDAP_SUCCESS;
1852 struct berval **normalized )
1856 struct berval *newval;
1863 /* Ignore leading spaces */
1864 while ( len && ( *p == ' ' )) {
1871 negative = ( *p == '-' );
1872 if(( *p == '-' ) || ( *p == '+' )) {
1878 /* Ignore leading zeros */
1879 while ( len && ( *p == '0' )) {
1884 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
1886 /* If there are no non-zero digits left, the number is zero, otherwise
1887 allocate space for the number and copy it into the buffer */
1889 newval->bv_val = ch_strdup("0");
1893 newval->bv_len = len+negative;
1894 newval->bv_val = ch_malloc( newval->bv_len );
1896 newval->bv_val[0] = '-';
1898 memcpy( newval->bv_val + negative, p, len );
1901 *normalized = newval;
1902 return LDAP_SUCCESS;
1905 /* Index generation function */
1911 struct berval *prefix,
1912 struct berval **values,
1913 struct berval ***keysp )
1916 struct berval **keys;
1918 /* we should have at least one value at this point */
1919 assert( values != NULL && values[0] != NULL );
1921 for( i=0; values[i] != NULL; i++ ) {
1922 /* empty -- just count them */
1925 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1927 for( i=0; values[i] != NULL; i++ ) {
1928 integerNormalize( syntax, values[i], &keys[i] );
1933 return LDAP_SUCCESS;
1936 /* Index generation function */
1942 struct berval *prefix,
1944 struct berval ***keysp )
1946 struct berval **keys;
1948 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1949 integerNormalize( syntax, assertValue, &keys[0] );
1953 return LDAP_SUCCESS;
1958 countryStringValidate(
1960 struct berval *val )
1962 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1964 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1965 return LDAP_INVALID_SYNTAX;
1967 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1968 return LDAP_INVALID_SYNTAX;
1971 return LDAP_SUCCESS;
1975 printableStringValidate(
1977 struct berval *val )
1981 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1983 for(i=0; i < val->bv_len; i++) {
1984 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1985 return LDAP_INVALID_SYNTAX;
1989 return LDAP_SUCCESS;
1993 printablesStringValidate(
1995 struct berval *val )
1999 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2001 for(i=0; i < val->bv_len; i++) {
2002 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2003 return LDAP_INVALID_SYNTAX;
2007 return LDAP_SUCCESS;
2013 struct berval *val )
2017 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2019 for(i=0; i < val->bv_len; i++) {
2020 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2023 return LDAP_SUCCESS;
2030 struct berval **normalized )
2032 struct berval *newval;
2035 newval = ch_malloc( sizeof( struct berval ) );
2039 /* Ignore initial whitespace */
2040 while ( ASCII_SPACE( *p ) ) {
2046 return LDAP_INVALID_SYNTAX;
2049 newval->bv_val = ch_strdup( p );
2050 p = q = newval->bv_val;
2053 if ( ASCII_SPACE( *p ) ) {
2056 /* Ignore the extra whitespace */
2057 while ( ASCII_SPACE( *p ) ) {
2065 assert( *newval->bv_val );
2066 assert( newval->bv_val < p );
2069 /* cannot start with a space */
2070 assert( !ASCII_SPACE(*newval->bv_val) );
2073 * If the string ended in space, backup the pointer one
2074 * position. One is enough because the above loop collapsed
2075 * all whitespace to a single space.
2078 if ( ASCII_SPACE( q[-1] ) ) {
2082 /* cannot end with a space */
2083 assert( !ASCII_SPACE( q[-1] ) );
2085 /* null terminate */
2088 newval->bv_len = q - newval->bv_val;
2089 *normalized = newval;
2091 return LDAP_SUCCESS;
2100 struct berval *value,
2101 void *assertedValue )
2103 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2106 match = strncmp( value->bv_val,
2107 ((struct berval *) assertedValue)->bv_val,
2112 return LDAP_SUCCESS;
2116 caseExactIA5SubstringsMatch(
2121 struct berval *value,
2122 void *assertedValue )
2125 SubstringsAssertion *sub = assertedValue;
2126 struct berval left = *value;
2130 /* Add up asserted input length */
2131 if( sub->sa_initial ) {
2132 inlen += sub->sa_initial->bv_len;
2135 for(i=0; sub->sa_any[i] != NULL; i++) {
2136 inlen += sub->sa_any[i]->bv_len;
2139 if( sub->sa_final ) {
2140 inlen += sub->sa_final->bv_len;
2143 if( sub->sa_initial ) {
2144 if( inlen > left.bv_len ) {
2149 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2150 sub->sa_initial->bv_len );
2156 left.bv_val += sub->sa_initial->bv_len;
2157 left.bv_len -= sub->sa_initial->bv_len;
2158 inlen -= sub->sa_initial->bv_len;
2161 if( sub->sa_final ) {
2162 if( inlen > left.bv_len ) {
2167 match = strncmp( sub->sa_final->bv_val,
2168 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2169 sub->sa_final->bv_len );
2175 left.bv_len -= sub->sa_final->bv_len;
2176 inlen -= sub->sa_final->bv_len;
2180 for(i=0; sub->sa_any[i]; i++) {
2185 if( inlen > left.bv_len ) {
2186 /* not enough length */
2191 if( sub->sa_any[i]->bv_len == 0 ) {
2195 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2202 idx = p - left.bv_val;
2203 assert( idx < left.bv_len );
2205 if( idx >= left.bv_len ) {
2206 /* this shouldn't happen */
2213 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2214 /* not enough left */
2219 match = strncmp( left.bv_val,
2220 sub->sa_any[i]->bv_val,
2221 sub->sa_any[i]->bv_len );
2229 left.bv_val += sub->sa_any[i]->bv_len;
2230 left.bv_len -= sub->sa_any[i]->bv_len;
2231 inlen -= sub->sa_any[i]->bv_len;
2237 return LDAP_SUCCESS;
2240 /* Index generation function */
2241 int caseExactIA5Indexer(
2246 struct berval *prefix,
2247 struct berval **values,
2248 struct berval ***keysp )
2252 struct berval **keys;
2253 HASH_CONTEXT HASHcontext;
2254 unsigned char HASHdigest[HASH_BYTES];
2255 struct berval digest;
2256 digest.bv_val = HASHdigest;
2257 digest.bv_len = sizeof(HASHdigest);
2259 for( i=0; values[i] != NULL; i++ ) {
2260 /* empty - just count them */
2263 /* we should have at least one value at this point */
2266 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2268 slen = strlen( syntax->ssyn_oid );
2269 mlen = strlen( mr->smr_oid );
2271 for( i=0; values[i] != NULL; i++ ) {
2272 struct berval *value = values[i];
2274 HASH_Init( &HASHcontext );
2275 if( prefix != NULL && prefix->bv_len > 0 ) {
2276 HASH_Update( &HASHcontext,
2277 prefix->bv_val, prefix->bv_len );
2279 HASH_Update( &HASHcontext,
2280 syntax->ssyn_oid, slen );
2281 HASH_Update( &HASHcontext,
2282 mr->smr_oid, mlen );
2283 HASH_Update( &HASHcontext,
2284 value->bv_val, value->bv_len );
2285 HASH_Final( HASHdigest, &HASHcontext );
2287 keys[i] = ber_bvdup( &digest );
2292 return LDAP_SUCCESS;
2295 /* Index generation function */
2296 int caseExactIA5Filter(
2301 struct berval *prefix,
2303 struct berval ***keysp )
2306 struct berval **keys;
2307 HASH_CONTEXT HASHcontext;
2308 unsigned char HASHdigest[HASH_BYTES];
2309 struct berval *value;
2310 struct berval digest;
2311 digest.bv_val = HASHdigest;
2312 digest.bv_len = sizeof(HASHdigest);
2314 slen = strlen( syntax->ssyn_oid );
2315 mlen = strlen( mr->smr_oid );
2317 value = (struct berval *) assertValue;
2319 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2321 HASH_Init( &HASHcontext );
2322 if( prefix != NULL && prefix->bv_len > 0 ) {
2323 HASH_Update( &HASHcontext,
2324 prefix->bv_val, prefix->bv_len );
2326 HASH_Update( &HASHcontext,
2327 syntax->ssyn_oid, slen );
2328 HASH_Update( &HASHcontext,
2329 mr->smr_oid, mlen );
2330 HASH_Update( &HASHcontext,
2331 value->bv_val, value->bv_len );
2332 HASH_Final( HASHdigest, &HASHcontext );
2334 keys[0] = ber_bvdup( &digest );
2338 return LDAP_SUCCESS;
2341 /* Substrings Index generation function */
2342 int caseExactIA5SubstringsIndexer(
2347 struct berval *prefix,
2348 struct berval **values,
2349 struct berval ***keysp )
2353 struct berval **keys;
2354 HASH_CONTEXT HASHcontext;
2355 unsigned char HASHdigest[HASH_BYTES];
2356 struct berval digest;
2357 digest.bv_val = HASHdigest;
2358 digest.bv_len = sizeof(HASHdigest);
2360 /* we should have at least one value at this point */
2361 assert( values != NULL && values[0] != NULL );
2364 for( i=0; values[i] != NULL; i++ ) {
2365 /* count number of indices to generate */
2366 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2370 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2371 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2372 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2373 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2375 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2379 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2380 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2381 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2385 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2386 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2387 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2388 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2390 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2396 /* no keys to generate */
2398 return LDAP_SUCCESS;
2401 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2403 slen = strlen( syntax->ssyn_oid );
2404 mlen = strlen( mr->smr_oid );
2407 for( i=0; values[i] != NULL; i++ ) {
2409 struct berval *value;
2412 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2414 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2415 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2417 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2418 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2420 for( j=0; j<max; j++ ) {
2421 HASH_Init( &HASHcontext );
2422 if( prefix != NULL && prefix->bv_len > 0 ) {
2423 HASH_Update( &HASHcontext,
2424 prefix->bv_val, prefix->bv_len );
2427 HASH_Update( &HASHcontext,
2428 &pre, sizeof( pre ) );
2429 HASH_Update( &HASHcontext,
2430 syntax->ssyn_oid, slen );
2431 HASH_Update( &HASHcontext,
2432 mr->smr_oid, mlen );
2433 HASH_Update( &HASHcontext,
2435 SLAP_INDEX_SUBSTR_MAXLEN );
2436 HASH_Final( HASHdigest, &HASHcontext );
2438 keys[nkeys++] = ber_bvdup( &digest );
2442 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2443 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2445 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2448 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2449 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2450 HASH_Init( &HASHcontext );
2451 if( prefix != NULL && prefix->bv_len > 0 ) {
2452 HASH_Update( &HASHcontext,
2453 prefix->bv_val, prefix->bv_len );
2455 HASH_Update( &HASHcontext,
2456 &pre, sizeof( pre ) );
2457 HASH_Update( &HASHcontext,
2458 syntax->ssyn_oid, slen );
2459 HASH_Update( &HASHcontext,
2460 mr->smr_oid, mlen );
2461 HASH_Update( &HASHcontext,
2463 HASH_Final( HASHdigest, &HASHcontext );
2465 keys[nkeys++] = ber_bvdup( &digest );
2468 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2469 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2470 HASH_Init( &HASHcontext );
2471 if( prefix != NULL && prefix->bv_len > 0 ) {
2472 HASH_Update( &HASHcontext,
2473 prefix->bv_val, prefix->bv_len );
2475 HASH_Update( &HASHcontext,
2476 &pre, sizeof( pre ) );
2477 HASH_Update( &HASHcontext,
2478 syntax->ssyn_oid, slen );
2479 HASH_Update( &HASHcontext,
2480 mr->smr_oid, mlen );
2481 HASH_Update( &HASHcontext,
2482 &value->bv_val[value->bv_len-j], j );
2483 HASH_Final( HASHdigest, &HASHcontext );
2485 keys[nkeys++] = ber_bvdup( &digest );
2499 return LDAP_SUCCESS;
2502 int caseExactIA5SubstringsFilter(
2507 struct berval *prefix,
2509 struct berval ***keysp )
2511 SubstringsAssertion *sa = assertValue;
2513 ber_len_t nkeys = 0;
2514 size_t slen, mlen, klen;
2515 struct berval **keys;
2516 HASH_CONTEXT HASHcontext;
2517 unsigned char HASHdigest[HASH_BYTES];
2518 struct berval *value;
2519 struct berval digest;
2521 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2522 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2527 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2529 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2530 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2531 /* don't bother accounting for stepping */
2532 nkeys += sa->sa_any[i]->bv_len -
2533 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2538 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2539 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2546 return LDAP_SUCCESS;
2549 digest.bv_val = HASHdigest;
2550 digest.bv_len = sizeof(HASHdigest);
2552 slen = strlen( syntax->ssyn_oid );
2553 mlen = strlen( mr->smr_oid );
2555 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2558 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2559 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2561 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2562 value = sa->sa_initial;
2564 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2565 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2567 HASH_Init( &HASHcontext );
2568 if( prefix != NULL && prefix->bv_len > 0 ) {
2569 HASH_Update( &HASHcontext,
2570 prefix->bv_val, prefix->bv_len );
2572 HASH_Update( &HASHcontext,
2573 &pre, sizeof( pre ) );
2574 HASH_Update( &HASHcontext,
2575 syntax->ssyn_oid, slen );
2576 HASH_Update( &HASHcontext,
2577 mr->smr_oid, mlen );
2578 HASH_Update( &HASHcontext,
2579 value->bv_val, klen );
2580 HASH_Final( HASHdigest, &HASHcontext );
2582 keys[nkeys++] = ber_bvdup( &digest );
2585 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2587 pre = SLAP_INDEX_SUBSTR_PREFIX;
2588 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2590 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2591 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2595 value = sa->sa_any[i];
2598 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2599 j += SLAP_INDEX_SUBSTR_STEP )
2601 HASH_Init( &HASHcontext );
2602 if( prefix != NULL && prefix->bv_len > 0 ) {
2603 HASH_Update( &HASHcontext,
2604 prefix->bv_val, prefix->bv_len );
2606 HASH_Update( &HASHcontext,
2607 &pre, sizeof( pre ) );
2608 HASH_Update( &HASHcontext,
2609 syntax->ssyn_oid, slen );
2610 HASH_Update( &HASHcontext,
2611 mr->smr_oid, mlen );
2612 HASH_Update( &HASHcontext,
2613 &value->bv_val[j], klen );
2614 HASH_Final( HASHdigest, &HASHcontext );
2616 keys[nkeys++] = ber_bvdup( &digest );
2621 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2622 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2624 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2625 value = sa->sa_final;
2627 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2628 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2630 HASH_Init( &HASHcontext );
2631 if( prefix != NULL && prefix->bv_len > 0 ) {
2632 HASH_Update( &HASHcontext,
2633 prefix->bv_val, prefix->bv_len );
2635 HASH_Update( &HASHcontext,
2636 &pre, sizeof( pre ) );
2637 HASH_Update( &HASHcontext,
2638 syntax->ssyn_oid, slen );
2639 HASH_Update( &HASHcontext,
2640 mr->smr_oid, mlen );
2641 HASH_Update( &HASHcontext,
2642 &value->bv_val[value->bv_len-klen], klen );
2643 HASH_Final( HASHdigest, &HASHcontext );
2645 keys[nkeys++] = ber_bvdup( &digest );
2656 return LDAP_SUCCESS;
2665 struct berval *value,
2666 void *assertedValue )
2668 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2670 if( match == 0 && value->bv_len ) {
2671 match = strncasecmp( value->bv_val,
2672 ((struct berval *) assertedValue)->bv_val,
2677 return LDAP_SUCCESS;
2681 caseIgnoreIA5SubstringsMatch(
2686 struct berval *value,
2687 void *assertedValue )
2690 SubstringsAssertion *sub = assertedValue;
2691 struct berval left = *value;
2695 /* Add up asserted input length */
2696 if( sub->sa_initial ) {
2697 inlen += sub->sa_initial->bv_len;
2700 for(i=0; sub->sa_any[i] != NULL; i++) {
2701 inlen += sub->sa_any[i]->bv_len;
2704 if( sub->sa_final ) {
2705 inlen += sub->sa_final->bv_len;
2708 if( sub->sa_initial ) {
2709 if( inlen > left.bv_len ) {
2714 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2715 sub->sa_initial->bv_len );
2721 left.bv_val += sub->sa_initial->bv_len;
2722 left.bv_len -= sub->sa_initial->bv_len;
2723 inlen -= sub->sa_initial->bv_len;
2726 if( sub->sa_final ) {
2727 if( inlen > left.bv_len ) {
2732 match = strncasecmp( sub->sa_final->bv_val,
2733 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2734 sub->sa_final->bv_len );
2740 left.bv_len -= sub->sa_final->bv_len;
2741 inlen -= sub->sa_final->bv_len;
2745 for(i=0; sub->sa_any[i]; i++) {
2750 if( inlen > left.bv_len ) {
2751 /* not enough length */
2756 if( sub->sa_any[i]->bv_len == 0 ) {
2760 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2767 idx = p - left.bv_val;
2768 assert( idx < left.bv_len );
2770 if( idx >= left.bv_len ) {
2771 /* this shouldn't happen */
2778 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2779 /* not enough left */
2784 match = strncasecmp( left.bv_val,
2785 sub->sa_any[i]->bv_val,
2786 sub->sa_any[i]->bv_len );
2795 left.bv_val += sub->sa_any[i]->bv_len;
2796 left.bv_len -= sub->sa_any[i]->bv_len;
2797 inlen -= sub->sa_any[i]->bv_len;
2803 return LDAP_SUCCESS;
2806 /* Index generation function */
2807 int caseIgnoreIA5Indexer(
2812 struct berval *prefix,
2813 struct berval **values,
2814 struct berval ***keysp )
2818 struct berval **keys;
2819 HASH_CONTEXT HASHcontext;
2820 unsigned char HASHdigest[HASH_BYTES];
2821 struct berval digest;
2822 digest.bv_val = HASHdigest;
2823 digest.bv_len = sizeof(HASHdigest);
2825 /* we should have at least one value at this point */
2826 assert( values != NULL && values[0] != NULL );
2828 for( i=0; values[i] != NULL; i++ ) {
2829 /* just count them */
2832 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2834 slen = strlen( syntax->ssyn_oid );
2835 mlen = strlen( mr->smr_oid );
2837 for( i=0; values[i] != NULL; i++ ) {
2838 struct berval *value = ber_bvdup( values[i] );
2839 ldap_pvt_str2upper( value->bv_val );
2841 HASH_Init( &HASHcontext );
2842 if( prefix != NULL && prefix->bv_len > 0 ) {
2843 HASH_Update( &HASHcontext,
2844 prefix->bv_val, prefix->bv_len );
2846 HASH_Update( &HASHcontext,
2847 syntax->ssyn_oid, slen );
2848 HASH_Update( &HASHcontext,
2849 mr->smr_oid, mlen );
2850 HASH_Update( &HASHcontext,
2851 value->bv_val, value->bv_len );
2852 HASH_Final( HASHdigest, &HASHcontext );
2854 ber_bvfree( value );
2856 keys[i] = ber_bvdup( &digest );
2861 return LDAP_SUCCESS;
2864 /* Index generation function */
2865 int caseIgnoreIA5Filter(
2870 struct berval *prefix,
2872 struct berval ***keysp )
2875 struct berval **keys;
2876 HASH_CONTEXT HASHcontext;
2877 unsigned char HASHdigest[HASH_BYTES];
2878 struct berval *value;
2879 struct berval digest;
2880 digest.bv_val = HASHdigest;
2881 digest.bv_len = sizeof(HASHdigest);
2883 slen = strlen( syntax->ssyn_oid );
2884 mlen = strlen( mr->smr_oid );
2886 value = ber_bvdup( (struct berval *) assertValue );
2887 ldap_pvt_str2upper( value->bv_val );
2889 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2891 HASH_Init( &HASHcontext );
2892 if( prefix != NULL && prefix->bv_len > 0 ) {
2893 HASH_Update( &HASHcontext,
2894 prefix->bv_val, prefix->bv_len );
2896 HASH_Update( &HASHcontext,
2897 syntax->ssyn_oid, slen );
2898 HASH_Update( &HASHcontext,
2899 mr->smr_oid, mlen );
2900 HASH_Update( &HASHcontext,
2901 value->bv_val, value->bv_len );
2902 HASH_Final( HASHdigest, &HASHcontext );
2904 keys[0] = ber_bvdup( &digest );
2907 ber_bvfree( value );
2911 return LDAP_SUCCESS;
2914 /* Substrings Index generation function */
2915 int caseIgnoreIA5SubstringsIndexer(
2920 struct berval *prefix,
2921 struct berval **values,
2922 struct berval ***keysp )
2926 struct berval **keys;
2927 HASH_CONTEXT HASHcontext;
2928 unsigned char HASHdigest[HASH_BYTES];
2929 struct berval digest;
2930 digest.bv_val = HASHdigest;
2931 digest.bv_len = sizeof(HASHdigest);
2933 /* we should have at least one value at this point */
2934 assert( values != NULL && values[0] != NULL );
2937 for( i=0; values[i] != NULL; i++ ) {
2938 /* count number of indices to generate */
2939 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2943 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2944 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2945 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2946 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2948 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2952 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2953 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2954 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2958 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2959 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2960 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2961 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2963 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2969 /* no keys to generate */
2971 return LDAP_SUCCESS;
2974 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2976 slen = strlen( syntax->ssyn_oid );
2977 mlen = strlen( mr->smr_oid );
2980 for( i=0; values[i] != NULL; i++ ) {
2982 struct berval *value;
2984 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2986 value = ber_bvdup( values[i] );
2987 ldap_pvt_str2upper( value->bv_val );
2989 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2990 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2992 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2993 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2995 for( j=0; j<max; j++ ) {
2996 HASH_Init( &HASHcontext );
2997 if( prefix != NULL && prefix->bv_len > 0 ) {
2998 HASH_Update( &HASHcontext,
2999 prefix->bv_val, prefix->bv_len );
3002 HASH_Update( &HASHcontext,
3003 &pre, sizeof( pre ) );
3004 HASH_Update( &HASHcontext,
3005 syntax->ssyn_oid, slen );
3006 HASH_Update( &HASHcontext,
3007 mr->smr_oid, mlen );
3008 HASH_Update( &HASHcontext,
3010 SLAP_INDEX_SUBSTR_MAXLEN );
3011 HASH_Final( HASHdigest, &HASHcontext );
3013 keys[nkeys++] = ber_bvdup( &digest );
3017 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3018 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3020 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3023 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3024 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3025 HASH_Init( &HASHcontext );
3026 if( prefix != NULL && prefix->bv_len > 0 ) {
3027 HASH_Update( &HASHcontext,
3028 prefix->bv_val, prefix->bv_len );
3030 HASH_Update( &HASHcontext,
3031 &pre, sizeof( pre ) );
3032 HASH_Update( &HASHcontext,
3033 syntax->ssyn_oid, slen );
3034 HASH_Update( &HASHcontext,
3035 mr->smr_oid, mlen );
3036 HASH_Update( &HASHcontext,
3038 HASH_Final( HASHdigest, &HASHcontext );
3040 keys[nkeys++] = ber_bvdup( &digest );
3043 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3044 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3045 HASH_Init( &HASHcontext );
3046 if( prefix != NULL && prefix->bv_len > 0 ) {
3047 HASH_Update( &HASHcontext,
3048 prefix->bv_val, prefix->bv_len );
3050 HASH_Update( &HASHcontext,
3051 &pre, sizeof( pre ) );
3052 HASH_Update( &HASHcontext,
3053 syntax->ssyn_oid, slen );
3054 HASH_Update( &HASHcontext,
3055 mr->smr_oid, mlen );
3056 HASH_Update( &HASHcontext,
3057 &value->bv_val[value->bv_len-j], j );
3058 HASH_Final( HASHdigest, &HASHcontext );
3060 keys[nkeys++] = ber_bvdup( &digest );
3065 ber_bvfree( value );
3076 return LDAP_SUCCESS;
3079 int caseIgnoreIA5SubstringsFilter(
3084 struct berval *prefix,
3086 struct berval ***keysp )
3088 SubstringsAssertion *sa = assertValue;
3090 ber_len_t nkeys = 0;
3091 size_t slen, mlen, klen;
3092 struct berval **keys;
3093 HASH_CONTEXT HASHcontext;
3094 unsigned char HASHdigest[HASH_BYTES];
3095 struct berval *value;
3096 struct berval digest;
3098 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3099 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3104 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3106 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3107 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3108 /* don't bother accounting for stepping */
3109 nkeys += sa->sa_any[i]->bv_len -
3110 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3115 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3116 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3123 return LDAP_SUCCESS;
3126 digest.bv_val = HASHdigest;
3127 digest.bv_len = sizeof(HASHdigest);
3129 slen = strlen( syntax->ssyn_oid );
3130 mlen = strlen( mr->smr_oid );
3132 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3135 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3136 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3138 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3139 value = ber_bvdup( sa->sa_initial );
3140 ldap_pvt_str2upper( value->bv_val );
3142 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3143 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3145 HASH_Init( &HASHcontext );
3146 if( prefix != NULL && prefix->bv_len > 0 ) {
3147 HASH_Update( &HASHcontext,
3148 prefix->bv_val, prefix->bv_len );
3150 HASH_Update( &HASHcontext,
3151 &pre, sizeof( pre ) );
3152 HASH_Update( &HASHcontext,
3153 syntax->ssyn_oid, slen );
3154 HASH_Update( &HASHcontext,
3155 mr->smr_oid, mlen );
3156 HASH_Update( &HASHcontext,
3157 value->bv_val, klen );
3158 HASH_Final( HASHdigest, &HASHcontext );
3160 ber_bvfree( value );
3161 keys[nkeys++] = ber_bvdup( &digest );
3164 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3166 pre = SLAP_INDEX_SUBSTR_PREFIX;
3167 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3169 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3170 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3174 value = ber_bvdup( sa->sa_any[i] );
3175 ldap_pvt_str2upper( value->bv_val );
3178 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3179 j += SLAP_INDEX_SUBSTR_STEP )
3181 HASH_Init( &HASHcontext );
3182 if( prefix != NULL && prefix->bv_len > 0 ) {
3183 HASH_Update( &HASHcontext,
3184 prefix->bv_val, prefix->bv_len );
3186 HASH_Update( &HASHcontext,
3187 &pre, sizeof( pre ) );
3188 HASH_Update( &HASHcontext,
3189 syntax->ssyn_oid, slen );
3190 HASH_Update( &HASHcontext,
3191 mr->smr_oid, mlen );
3192 HASH_Update( &HASHcontext,
3193 &value->bv_val[j], klen );
3194 HASH_Final( HASHdigest, &HASHcontext );
3196 keys[nkeys++] = ber_bvdup( &digest );
3199 ber_bvfree( value );
3203 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3204 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3206 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3207 value = ber_bvdup( sa->sa_final );
3208 ldap_pvt_str2upper( value->bv_val );
3210 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3211 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3213 HASH_Init( &HASHcontext );
3214 if( prefix != NULL && prefix->bv_len > 0 ) {
3215 HASH_Update( &HASHcontext,
3216 prefix->bv_val, prefix->bv_len );
3218 HASH_Update( &HASHcontext,
3219 &pre, sizeof( pre ) );
3220 HASH_Update( &HASHcontext,
3221 syntax->ssyn_oid, slen );
3222 HASH_Update( &HASHcontext,
3223 mr->smr_oid, mlen );
3224 HASH_Update( &HASHcontext,
3225 &value->bv_val[value->bv_len-klen], klen );
3226 HASH_Final( HASHdigest, &HASHcontext );
3228 ber_bvfree( value );
3229 keys[nkeys++] = ber_bvdup( &digest );
3240 return LDAP_SUCCESS;
3244 numericStringValidate(
3250 for(i=0; i < in->bv_len; i++) {
3251 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3252 return LDAP_INVALID_SYNTAX;
3256 return LDAP_SUCCESS;
3260 numericStringNormalize(
3263 struct berval **normalized )
3265 /* removal all spaces */
3266 struct berval *newval;
3269 newval = ch_malloc( sizeof( struct berval ) );
3270 newval->bv_val = ch_malloc( val->bv_len + 1 );
3276 if ( ASCII_SPACE( *p ) ) {
3277 /* Ignore whitespace */
3284 /* we should have copied no more then is in val */
3285 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3287 /* null terminate */
3290 newval->bv_len = q - newval->bv_val;
3291 *normalized = newval;
3293 return LDAP_SUCCESS;
3297 objectIdentifierFirstComponentMatch(
3302 struct berval *value,
3303 void *assertedValue )
3305 int rc = LDAP_SUCCESS;
3307 struct berval *asserted = (struct berval *) assertedValue;
3311 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3312 return LDAP_INVALID_SYNTAX;
3315 /* trim leading white space */
3316 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3320 /* grab next word */
3321 oid.bv_val = &value->bv_val[i];
3322 oid.bv_len = value->bv_len - i;
3323 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3328 /* insert attributeTypes, objectclass check here */
3329 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3330 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3333 char *stored = ch_malloc( oid.bv_len + 1 );
3334 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3335 stored[oid.bv_len] = '\0';
3337 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3338 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3339 MatchingRule *stored_mr = mr_find( stored );
3341 if( asserted_mr == NULL ) {
3342 rc = SLAPD_COMPARE_UNDEFINED;
3344 match = asserted_mr != stored_mr;
3347 } else if ( !strcmp( syntax->ssyn_oid,
3348 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3350 AttributeType *asserted_at = at_find( asserted->bv_val );
3351 AttributeType *stored_at = at_find( stored );
3353 if( asserted_at == NULL ) {
3354 rc = SLAPD_COMPARE_UNDEFINED;
3356 match = asserted_at != stored_at;
3359 } else if ( !strcmp( syntax->ssyn_oid,
3360 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3362 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3363 ObjectClass *stored_oc = oc_find( stored );
3365 if( asserted_oc == NULL ) {
3366 rc = SLAPD_COMPARE_UNDEFINED;
3368 match = asserted_oc != stored_oc;
3376 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3377 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3378 match, value->bv_val, asserted->bv_val ));
3380 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3381 "%d\n\t\"%s\"\n\t\"%s\"\n",
3382 match, value->bv_val, asserted->bv_val );
3386 if( rc == LDAP_SUCCESS ) *matchp = match;
3396 struct berval *value,
3397 void *assertedValue )
3399 long lValue, lAssertedValue;
3401 /* safe to assume integers are NUL terminated? */
3402 lValue = strtoul(value->bv_val, NULL, 10);
3403 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3404 return LDAP_CONSTRAINT_VIOLATION;
3406 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3407 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3408 return LDAP_CONSTRAINT_VIOLATION;
3410 *matchp = (lValue & lAssertedValue);
3411 return LDAP_SUCCESS;
3420 struct berval *value,
3421 void *assertedValue )
3423 long lValue, lAssertedValue;
3425 /* safe to assume integers are NUL terminated? */
3426 lValue = strtoul(value->bv_val, NULL, 10);
3427 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3428 return LDAP_CONSTRAINT_VIOLATION;
3430 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3431 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3432 return LDAP_CONSTRAINT_VIOLATION;
3434 *matchp = (lValue | lAssertedValue);
3435 return LDAP_SUCCESS;
3439 #include <openssl/x509.h>
3440 #include <openssl/err.h>
3441 char digit[] = "0123456789";
3444 * Next function returns a string representation of a ASN1_INTEGER.
3445 * It works for unlimited lengths.
3448 static struct berval *
3449 asn1_integer2str(ASN1_INTEGER *a)
3454 /* We work backwards, make it fill from the end of buf */
3455 p = buf + sizeof(buf) - 1;
3458 if ( a == NULL || a->length == 0 ) {
3466 /* We want to preserve the original */
3467 copy = ch_malloc(n*sizeof(unsigned int));
3468 for (i = 0; i<n; i++) {
3469 copy[i] = a->data[i];
3473 * base indicates the index of the most significant
3474 * byte that might be nonzero. When it goes off the
3475 * end, we now there is nothing left to do.
3482 for (i = base; i<n; i++ ) {
3483 copy[i] += carry*256;
3484 carry = copy[i] % 10;
3489 * Way too large, we need to leave
3490 * room for sign if negative
3495 *--p = digit[carry];
3496 if (copy[base] == 0)
3502 if ( a->type == V_ASN1_NEG_INTEGER ) {
3506 return ber_bvstrdup(p);
3509 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3510 static struct berval *
3511 dn_openssl2ldap(X509_NAME *name)
3513 char issuer_dn[1024];
3516 bio = BIO_new(BIO_s_mem());
3519 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3520 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3521 ERR_error_string(ERR_get_error(),NULL)));
3523 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3524 "error creating BIO: %s\n",
3525 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3529 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3531 BIO_gets(bio, issuer_dn, 1024);
3534 return ber_bvstrdup(issuer_dn);
3538 * Given a certificate in DER format, extract the corresponding
3539 * assertion value for certificateExactMatch
3542 certificateExactConvert(
3544 struct berval ** out )
3547 unsigned char *p = in->bv_val;
3548 struct berval *serial;
3549 struct berval *issuer_dn;
3550 struct berval *bv_tmp;
3553 xcert = d2i_X509(NULL, &p, in->bv_len);
3556 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3557 "certificateExactConvert: error parsing cert: %s\n",
3558 ERR_error_string(ERR_get_error(),NULL)));
3560 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3561 "error parsing cert: %s\n",
3562 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3564 return LDAP_INVALID_SYNTAX;
3567 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3570 return LDAP_INVALID_SYNTAX;
3572 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3576 return LDAP_INVALID_SYNTAX;
3578 /* Actually, dn_openssl2ldap returns in a normalized format, but
3579 it is different from our normalized format */
3581 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3585 return LDAP_INVALID_SYNTAX;
3591 *out = ch_malloc(sizeof(struct berval));
3592 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3593 (*out)->bv_val = ch_malloc((*out)->bv_len);
3595 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3596 p += serial->bv_len;
3597 AC_MEMCPY(p, " $ ", 3);
3599 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3600 p += issuer_dn->bv_len;
3604 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3605 "certificateExactConvert: \n %s\n",
3608 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3610 (*out)->bv_val, NULL, NULL );
3614 ber_bvfree(issuer_dn);
3616 return LDAP_SUCCESS;
3620 serial_and_issuer_parse(
3621 struct berval *assertion,
3622 struct berval **serial,
3623 struct berval **issuer_dn
3631 begin = assertion->bv_val;
3632 end = assertion->bv_val+assertion->bv_len-1;
3633 for (p=begin; p<=end && *p != '$'; p++)
3636 return LDAP_INVALID_SYNTAX;
3638 /* p now points at the $ sign, now use begin and end to delimit the
3640 while (ASCII_SPACE(*begin))
3643 while (ASCII_SPACE(*end))
3646 q = ch_malloc( (end-begin+1)+1 );
3647 AC_MEMCPY( q, begin, end-begin+1 );
3648 q[end-begin+1] = '\0';
3649 *serial = ber_bvstr(q);
3651 /* now extract the issuer, remember p was at the dollar sign */
3653 end = assertion->bv_val+assertion->bv_len-1;
3654 while (ASCII_SPACE(*begin))
3656 /* should we trim spaces at the end too? is it safe always? */
3658 q = ch_malloc( (end-begin+1)+1 );
3659 AC_MEMCPY( q, begin, end-begin+1 );
3660 q[end-begin+1] = '\0';
3661 *issuer_dn = ber_bvstr(dn_normalize(q));
3663 return LDAP_SUCCESS;
3667 certificateExactMatch(
3672 struct berval *value,
3673 void *assertedValue )
3676 unsigned char *p = value->bv_val;
3677 struct berval *serial;
3678 struct berval *issuer_dn;
3679 struct berval *asserted_serial;
3680 struct berval *asserted_issuer_dn;
3683 xcert = d2i_X509(NULL, &p, value->bv_len);
3686 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3687 "certificateExactMatch: error parsing cert: %s\n",
3688 ERR_error_string(ERR_get_error(),NULL)));
3690 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3691 "error parsing cert: %s\n",
3692 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3694 return LDAP_INVALID_SYNTAX;
3697 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3698 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3702 serial_and_issuer_parse(assertedValue,
3704 &asserted_issuer_dn);
3709 slap_schema.si_syn_integer,
3710 slap_schema.si_mr_integerMatch,
3713 if ( ret == LDAP_SUCCESS ) {
3714 if ( *matchp == 0 ) {
3715 /* We need to normalize everything for dnMatch */
3719 slap_schema.si_syn_distinguishedName,
3720 slap_schema.si_mr_distinguishedNameMatch,
3722 asserted_issuer_dn);
3727 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3728 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3729 *matchp, serial->bv_val, issuer_dn->bv_val,
3730 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3732 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3733 "%d\n\t\"%s $ %s\"\n",
3734 *matchp, serial->bv_val, issuer_dn->bv_val );
3735 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3736 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3741 ber_bvfree(issuer_dn);
3742 ber_bvfree(asserted_serial);
3743 ber_bvfree(asserted_issuer_dn);
3749 * Index generation function
3750 * We just index the serials, in most scenarios the issuer DN is one of
3751 * a very small set of values.
3753 int certificateExactIndexer(
3758 struct berval *prefix,
3759 struct berval **values,
3760 struct berval ***keysp )
3763 struct berval **keys;
3766 struct berval * serial;
3768 /* we should have at least one value at this point */
3769 assert( values != NULL && values[0] != NULL );
3771 for( i=0; values[i] != NULL; i++ ) {
3772 /* empty -- just count them */
3775 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3777 for( i=0; values[i] != NULL; i++ ) {
3778 p = values[i]->bv_val;
3779 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
3782 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3783 "certificateExactIndexer: error parsing cert: %s\n",
3784 ERR_error_string(ERR_get_error(),NULL)));
3786 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3787 "error parsing cert: %s\n",
3788 ERR_error_string(ERR_get_error(),NULL),
3791 /* Do we leak keys on error? */
3792 return LDAP_INVALID_SYNTAX;
3795 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3797 integerNormalize( slap_schema.si_syn_integer,
3802 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3803 "certificateExactIndexer: returning: %s\n",
3806 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3815 return LDAP_SUCCESS;
3818 /* Index generation function */
3819 /* We think this is always called with a value in matching rule syntax */
3820 int certificateExactFilter(
3825 struct berval *prefix,
3827 struct berval ***keysp )
3829 struct berval **keys;
3830 struct berval *asserted_serial;
3831 struct berval *asserted_issuer_dn;
3833 serial_and_issuer_parse(assertValue,
3835 &asserted_issuer_dn);
3837 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3838 integerNormalize( syntax, asserted_serial, &keys[0] );
3842 ber_bvfree(asserted_serial);
3843 ber_bvfree(asserted_issuer_dn);
3844 return LDAP_SUCCESS;
3849 check_time_syntax (struct berval *val,
3853 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3854 static int mdays[2][12] = {
3855 /* non-leap years */
3856 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3858 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3861 int part, c, tzoffset, leapyear = 0 ;
3863 if( val->bv_len == 0 ) {
3864 return LDAP_INVALID_SYNTAX;
3867 p = (char *)val->bv_val;
3868 e = p + val->bv_len;
3870 /* Ignore initial whitespace */
3871 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3875 if (e - p < 13 - (2 * start)) {
3876 return LDAP_INVALID_SYNTAX;
3879 for (part = 0; part < 9; part++) {
3883 for (part = start; part < 7; part++) {
3885 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3892 return LDAP_INVALID_SYNTAX;
3894 if (c < 0 || c > 9) {
3895 return LDAP_INVALID_SYNTAX;
3901 return LDAP_INVALID_SYNTAX;
3903 if (c < 0 || c > 9) {
3904 return LDAP_INVALID_SYNTAX;
3909 if (part == 2 || part == 3) {
3912 if (parts[part] < 0) {
3913 return LDAP_INVALID_SYNTAX;
3915 if (parts[part] > ceiling[part]) {
3916 return LDAP_INVALID_SYNTAX;
3920 /* leapyear check for the Gregorian calendar (year>1581) */
3921 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3922 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3927 if (parts[3] > mdays[leapyear][parts[2]]) {
3928 return LDAP_INVALID_SYNTAX;
3933 tzoffset = 0; /* UTC */
3934 } else if (c != '+' && c != '-') {
3935 return LDAP_INVALID_SYNTAX;
3939 } else /* c == '+' */ {
3944 return LDAP_INVALID_SYNTAX;
3947 for (part = 7; part < 9; part++) {
3949 if (c < 0 || c > 9) {
3950 return LDAP_INVALID_SYNTAX;
3955 if (c < 0 || c > 9) {
3956 return LDAP_INVALID_SYNTAX;
3960 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3961 return LDAP_INVALID_SYNTAX;
3966 /* Ignore trailing whitespace */
3967 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3971 return LDAP_INVALID_SYNTAX;
3974 switch ( tzoffset ) {
3975 case -1: /* negativ offset to UTC, ie west of Greenwich */
3976 parts[4] += parts[7];
3977 parts[5] += parts[8];
3978 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3982 c = mdays[leapyear][parts[2]];
3984 if (parts[part] > c) {
3985 parts[part] -= c + 1;
3990 case 1: /* positive offset to UTC, ie east of Greenwich */
3991 parts[4] -= parts[7];
3992 parts[5] -= parts[8];
3993 for (part = 6; --part > 0; ) {
3997 /* first arg to % needs to be non negativ */
3998 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
4000 if (parts[part] < 0) {
4001 parts[part] += c + 1;
4006 case 0: /* already UTC */
4010 return LDAP_SUCCESS;
4017 struct berval **normalized )
4022 rc = check_time_syntax(val, 1, parts);
4023 if (rc != LDAP_SUCCESS) {
4028 out = ch_malloc( sizeof(struct berval) );
4030 return LBER_ERROR_MEMORY;
4033 out->bv_val = ch_malloc( 14 );
4034 if ( out->bv_val == NULL ) {
4036 return LBER_ERROR_MEMORY;
4039 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
4040 parts[1], parts[2] + 1, parts[3] + 1,
4041 parts[4], parts[5], parts[6] );
4045 return LDAP_SUCCESS;
4055 return check_time_syntax(in, 1, parts);
4059 generalizedTimeValidate(
4065 return check_time_syntax(in, 0, parts);
4069 generalizedTimeNormalize(
4072 struct berval **normalized )
4077 rc = check_time_syntax(val, 0, parts);
4078 if (rc != LDAP_SUCCESS) {
4083 out = ch_malloc( sizeof(struct berval) );
4085 return LBER_ERROR_MEMORY;
4088 out->bv_val = ch_malloc( 16 );
4089 if ( out->bv_val == NULL ) {
4091 return LBER_ERROR_MEMORY;
4094 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4095 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4096 parts[4], parts[5], parts[6] );
4100 return LDAP_SUCCESS;
4104 nisNetgroupTripleValidate(
4106 struct berval *val )
4111 if ( val->bv_len == 0 ) {
4112 return LDAP_INVALID_SYNTAX;
4115 p = (char *)val->bv_val;
4116 e = p + val->bv_len;
4118 if ( *p != '(' /*')'*/ ) {
4119 return LDAP_INVALID_SYNTAX;
4122 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4126 return LDAP_INVALID_SYNTAX;
4129 } else if ( !ATTR_CHAR( *p ) ) {
4130 return LDAP_INVALID_SYNTAX;
4134 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4135 return LDAP_INVALID_SYNTAX;
4141 return LDAP_INVALID_SYNTAX;
4144 return LDAP_SUCCESS;
4148 bootParameterValidate(
4150 struct berval *val )
4154 if ( val->bv_len == 0 ) {
4155 return LDAP_INVALID_SYNTAX;
4158 p = (char *)val->bv_val;
4159 e = p + val->bv_len;
4162 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4163 if ( !ATTR_CHAR( *p ) ) {
4164 return LDAP_INVALID_SYNTAX;
4169 return LDAP_INVALID_SYNTAX;
4173 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4174 if ( !ATTR_CHAR( *p ) ) {
4175 return LDAP_INVALID_SYNTAX;
4180 return LDAP_INVALID_SYNTAX;
4184 for ( p++; p < e; p++ ) {
4185 if ( !ATTR_CHAR( *p ) ) {
4186 return LDAP_INVALID_SYNTAX;
4190 return LDAP_SUCCESS;
4193 struct syntax_defs_rec {
4196 slap_syntax_validate_func *sd_validate;
4197 slap_syntax_transform_func *sd_normalize;
4198 slap_syntax_transform_func *sd_pretty;
4199 #ifdef SLAPD_BINARY_CONVERSION
4200 slap_syntax_transform_func *sd_ber2str;
4201 slap_syntax_transform_func *sd_str2ber;
4205 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4206 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4208 struct syntax_defs_rec syntax_defs[] = {
4209 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4210 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4212 0, NULL, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4214 0, NULL, NULL, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4216 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4218 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4220 0, bitStringValidate, NULL, NULL },
4221 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4222 0, booleanValidate, NULL, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4224 X_BINARY X_NOT_H_R ")",
4225 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4227 X_BINARY X_NOT_H_R ")",
4228 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4230 X_BINARY X_NOT_H_R ")",
4231 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4233 0, countryStringValidate, IA5StringNormalize, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4235 0, dnValidate, dnNormalize, dnPretty},
4236 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4237 0, NULL, NULL, NULL},
4238 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4239 0, NULL, NULL, NULL},
4240 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4241 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4242 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4243 0, NULL, NULL, NULL},
4244 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4245 0, NULL, NULL, NULL},
4246 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4247 0, NULL, NULL, NULL},
4248 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4249 0, NULL, NULL, NULL},
4250 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4251 0, NULL, NULL, NULL},
4252 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4253 0, printablesStringValidate, IA5StringNormalize, NULL},
4254 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4255 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4256 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4257 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4258 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4259 0, NULL, NULL, NULL},
4260 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4261 0, IA5StringValidate, IA5StringNormalize, NULL},
4262 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4263 0, integerValidate, integerNormalize, NULL},
4264 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4265 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4266 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4267 0, NULL, NULL, NULL},
4268 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4269 0, NULL, NULL, NULL},
4270 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4271 0, NULL, NULL, NULL},
4272 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4273 0, NULL, NULL, NULL},
4274 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4275 0, NULL, NULL, NULL},
4276 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4277 0, nameUIDValidate, nameUIDNormalize, NULL},
4278 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4279 0, NULL, NULL, NULL},
4280 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4281 0, numericStringValidate, numericStringNormalize, NULL},
4282 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4283 0, NULL, NULL, NULL},
4284 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4285 0, oidValidate, NULL, NULL},
4286 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4287 0, IA5StringValidate, IA5StringNormalize, NULL},
4288 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4289 0, blobValidate, NULL, NULL},
4290 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4291 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4292 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4293 0, NULL, NULL, NULL},
4294 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4295 0, NULL, NULL, NULL},
4296 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4297 0, printableStringValidate, IA5StringNormalize, NULL},
4298 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4299 X_BINARY X_NOT_H_R ")",
4300 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4301 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4302 0, printableStringValidate, IA5StringNormalize, NULL},
4303 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4304 0, NULL, NULL, NULL},
4305 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4306 0, printablesStringValidate, IA5StringNormalize, NULL},
4307 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4308 0, utcTimeValidate, utcTimeNormalize, NULL},
4309 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4310 0, NULL, NULL, NULL},
4311 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4312 0, NULL, NULL, NULL},
4313 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4314 0, NULL, NULL, NULL},
4315 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4316 0, NULL, NULL, NULL},
4317 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4318 0, NULL, NULL, NULL},
4320 /* RFC 2307 NIS Syntaxes */
4321 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4322 0, nisNetgroupTripleValidate, NULL, NULL},
4323 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4324 0, bootParameterValidate, NULL, NULL},
4328 /* These OIDs are not published yet, but will be in the next
4329 * I-D for PKIX LDAPv3 schema as have been advanced by David
4330 * Chadwick in private mail.
4332 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4333 0, NULL, NULL, NULL},
4336 /* OpenLDAP Experimental Syntaxes */
4337 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4338 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4340 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4341 0, NULL, NULL, NULL},
4343 /* OpenLDAP Void Syntax */
4344 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4345 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4346 {NULL, 0, NULL, NULL, NULL}
4349 struct mrule_defs_rec {
4351 slap_mask_t mrd_usage;
4352 slap_mr_convert_func * mrd_convert;
4353 slap_mr_normalize_func * mrd_normalize;
4354 slap_mr_match_func * mrd_match;
4355 slap_mr_indexer_func * mrd_indexer;
4356 slap_mr_filter_func * mrd_filter;
4358 char * mrd_associated;
4362 * Other matching rules in X.520 that we do not use (yet):
4364 * 2.5.13.9 numericStringOrderingMatch
4365 * 2.5.13.15 integerOrderingMatch
4366 * 2.5.13.18 octetStringOrderingMatch
4367 * 2.5.13.19 octetStringSubstringsMatch
4368 * 2.5.13.25 uTCTimeMatch
4369 * 2.5.13.26 uTCTimeOrderingMatch
4370 * 2.5.13.31 directoryStringFirstComponentMatch
4371 * 2.5.13.32 wordMatch
4372 * 2.5.13.33 keywordMatch
4373 * 2.5.13.35 certificateMatch
4374 * 2.5.13.36 certificatePairExactMatch
4375 * 2.5.13.37 certificatePairMatch
4376 * 2.5.13.38 certificateListExactMatch
4377 * 2.5.13.39 certificateListMatch
4378 * 2.5.13.40 algorithmIdentifierMatch
4379 * 2.5.13.41 storedPrefixMatch
4380 * 2.5.13.42 attributeCertificateMatch
4381 * 2.5.13.43 readerAndKeyIDMatch
4382 * 2.5.13.44 attributeIntegrityMatch
4385 struct mrule_defs_rec mrule_defs[] = {
4387 * EQUALITY matching rules must be listed after associated APPROX
4388 * matching rules. So, we list all APPROX matching rules first.
4390 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4391 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4392 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4394 directoryStringApproxMatch,
4395 directoryStringApproxIndexer,
4396 directoryStringApproxFilter,
4399 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4400 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4401 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4403 IA5StringApproxMatch,
4404 IA5StringApproxIndexer,
4405 IA5StringApproxFilter,
4409 * Other matching rules
4412 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4413 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4414 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4416 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4419 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4420 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4421 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4423 dnMatch, dnIndexer, dnFilter,
4426 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4427 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4428 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4430 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4431 directoryStringApproxMatchOID },
4433 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4434 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4437 caseIgnoreOrderingMatch, NULL, NULL,
4440 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4441 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4442 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4444 caseExactIgnoreSubstringsMatch,
4445 caseExactIgnoreSubstringsIndexer,
4446 caseExactIgnoreSubstringsFilter,
4449 {"( 2.5.13.5 NAME 'caseExactMatch' "
4450 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4451 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4453 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4454 directoryStringApproxMatchOID },
4456 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4457 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4460 caseExactOrderingMatch, NULL, NULL,
4463 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4464 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4465 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4467 caseExactIgnoreSubstringsMatch,
4468 caseExactIgnoreSubstringsIndexer,
4469 caseExactIgnoreSubstringsFilter,
4472 {"( 2.5.13.8 NAME 'numericStringMatch' "
4473 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4474 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4477 caseIgnoreIA5Indexer,
4478 caseIgnoreIA5Filter,
4481 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4482 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4483 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4485 caseIgnoreIA5SubstringsMatch,
4486 caseIgnoreIA5SubstringsIndexer,
4487 caseIgnoreIA5SubstringsFilter,
4490 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4491 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4492 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4494 caseIgnoreListMatch, NULL, NULL,
4497 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4498 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4499 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4501 caseIgnoreListSubstringsMatch, NULL, NULL,
4504 {"( 2.5.13.13 NAME 'booleanMatch' "
4505 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4506 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4508 booleanMatch, NULL, NULL,
4511 {"( 2.5.13.14 NAME 'integerMatch' "
4512 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4513 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4515 integerMatch, integerIndexer, integerFilter,
4518 {"( 2.5.13.16 NAME 'bitStringMatch' "
4519 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4520 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4522 bitStringMatch, NULL, NULL,
4525 {"( 2.5.13.17 NAME 'octetStringMatch' "
4526 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4527 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4529 octetStringMatch, octetStringIndexer, octetStringFilter,
4532 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4533 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4534 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4536 telephoneNumberMatch,
4537 telephoneNumberIndexer,
4538 telephoneNumberFilter,
4541 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4542 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4543 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4545 telephoneNumberSubstringsMatch,
4546 telephoneNumberSubstringsIndexer,
4547 telephoneNumberSubstringsFilter,
4550 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4551 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4552 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4557 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4558 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4559 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4561 uniqueMemberMatch, NULL, NULL,
4564 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4565 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4566 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4568 protocolInformationMatch, NULL, NULL,
4571 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4572 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4573 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4575 generalizedTimeMatch, NULL, NULL,
4578 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4579 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4582 generalizedTimeOrderingMatch, NULL, NULL,
4585 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4586 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4587 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4589 integerFirstComponentMatch, NULL, NULL,
4592 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4593 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4594 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4596 objectIdentifierFirstComponentMatch, NULL, NULL,
4600 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4601 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4602 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4603 certificateExactConvert, NULL,
4604 certificateExactMatch,
4605 certificateExactIndexer, certificateExactFilter,
4609 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4610 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4611 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4613 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4614 IA5StringApproxMatchOID },
4616 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4617 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4618 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4620 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4621 IA5StringApproxMatchOID },
4623 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4624 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4627 caseIgnoreIA5SubstringsMatch,
4628 caseIgnoreIA5SubstringsIndexer,
4629 caseIgnoreIA5SubstringsFilter,
4632 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4633 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4636 caseExactIA5SubstringsMatch,
4637 caseExactIA5SubstringsIndexer,
4638 caseExactIA5SubstringsFilter,
4641 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4642 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4645 authPasswordMatch, NULL, NULL,
4648 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4649 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4652 OpenLDAPaciMatch, NULL, NULL,
4655 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4656 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4659 integerBitAndMatch, NULL, NULL,
4662 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4663 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4666 integerBitOrMatch, NULL, NULL,
4669 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4678 /* we should only be called once (from main) */
4679 assert( schema_init_done == 0 );
4681 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4682 res = register_syntax( syntax_defs[i].sd_desc,
4683 syntax_defs[i].sd_flags,
4684 syntax_defs[i].sd_validate,
4685 syntax_defs[i].sd_normalize,
4686 syntax_defs[i].sd_pretty
4687 #ifdef SLAPD_BINARY_CONVERSION
4689 syntax_defs[i].sd_ber2str,
4690 syntax_defs[i].sd_str2ber
4695 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4696 syntax_defs[i].sd_desc );
4701 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4702 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4704 "schema_init: Ingoring unusable matching rule %s\n",
4705 mrule_defs[i].mrd_desc );
4709 res = register_matching_rule(
4710 mrule_defs[i].mrd_desc,
4711 mrule_defs[i].mrd_usage,
4712 mrule_defs[i].mrd_convert,
4713 mrule_defs[i].mrd_normalize,
4714 mrule_defs[i].mrd_match,
4715 mrule_defs[i].mrd_indexer,
4716 mrule_defs[i].mrd_filter,
4717 mrule_defs[i].mrd_associated );
4721 "schema_init: Error registering matching rule %s\n",
4722 mrule_defs[i].mrd_desc );
4726 schema_init_done = 1;
4727 return LDAP_SUCCESS;
4731 schema_destroy( void )