1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
22 #include "lutil_md5.h"
23 /* We should replace MD5 with a faster hash */
24 #define HASH_BYTES LUTIL_MD5_BYTES
25 #define HASH_CONTEXT lutil_MD5_CTX
26 #define HASH_Init(c) lutil_MD5Init(c)
27 #define HASH_Update(c,buf,len) lutil_MD5Update(c,buf,len)
28 #define HASH_Final(d,c) lutil_MD5Final(d,c)
30 #include "lutil_hash.h"
31 /* We should replace MD5 with a faster hash */
32 #define HASH_BYTES LUTIL_HASH_BYTES
33 #define HASH_CONTEXT lutil_HASH_CTX
34 #define HASH_Init(c) lutil_HASHInit(c)
35 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
36 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
39 /* recycled validatation routines */
40 #define berValidate blobValidate
42 /* unimplemented pretters */
44 #define integerPretty NULL
46 /* recycled matching routines */
47 #define bitStringMatch octetStringMatch
48 #define integerMatch caseIgnoreIA5Match
49 #define numericStringMatch caseIgnoreIA5Match
50 #define objectIdentifierMatch caseIgnoreIA5Match
51 #define telephoneNumberMatch caseIgnoreIA5Match
52 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
53 #define generalizedTimeMatch caseIgnoreIA5Match
54 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
55 #define uniqueMemberMatch dnMatch
57 /* approx matching rules */
58 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
59 #define directoryStringApproxMatch approxMatch
60 #define directoryStringApproxIndexer approxIndexer
61 #define directoryStringApproxFilter approxFilter
62 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
63 #define IA5StringApproxMatch approxMatch
64 #define IA5StringApproxIndexer approxIndexer
65 #define IA5StringApproxFilter approxFilter
67 /* orderring matching rules */
68 #define caseIgnoreOrderingMatch caseIgnoreMatch
69 #define caseExactOrderingMatch caseExactMatch
71 /* unimplemented matching routines */
72 #define caseIgnoreListMatch NULL
73 #define caseIgnoreListSubstringsMatch NULL
74 #define protocolInformationMatch NULL
75 #define integerFirstComponentMatch NULL
77 #define OpenLDAPaciMatch NULL
78 #define authPasswordMatch NULL
80 /* recycled indexing/filtering routines */
81 #define dnIndexer caseIgnoreIndexer
82 #define dnFilter caseIgnoreFilter
83 #define integerIndexer caseIgnoreIA5Indexer
84 #define integerFilter caseIgnoreIA5Filter
86 #define telephoneNumberIndexer caseIgnoreIA5Indexer
87 #define telephoneNumberFilter caseIgnoreIA5Filter
88 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
89 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
91 static char *strcasechr( const char *str, int c )
93 char *lower = strchr( str, TOLOWER(c) );
94 char *upper = strchr( str, TOUPPER(c) );
96 if( lower && upper ) {
97 return lower < upper ? lower : upper;
111 struct berval *value,
112 void *assertedValue )
114 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
117 match = memcmp( value->bv_val,
118 ((struct berval *) assertedValue)->bv_val,
126 /* Index generation function */
127 int octetStringIndexer(
132 struct berval *prefix,
133 struct berval **values,
134 struct berval ***keysp )
138 struct berval **keys;
139 HASH_CONTEXT HASHcontext;
140 unsigned char HASHdigest[HASH_BYTES];
141 struct berval digest;
142 digest.bv_val = HASHdigest;
143 digest.bv_len = sizeof(HASHdigest);
145 /* we should have at least one value at this point */
146 assert( values != NULL && values[0] != NULL );
148 for( i=0; values[i] != NULL; i++ ) {
149 /* just count them */
152 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
154 slen = strlen( syntax->ssyn_oid );
155 mlen = strlen( mr->smr_oid );
157 for( i=0; values[i] != NULL; i++ ) {
158 HASH_Init( &HASHcontext );
159 if( prefix != NULL && prefix->bv_len > 0 ) {
160 HASH_Update( &HASHcontext,
161 prefix->bv_val, prefix->bv_len );
163 HASH_Update( &HASHcontext,
164 syntax->ssyn_oid, slen );
165 HASH_Update( &HASHcontext,
167 HASH_Update( &HASHcontext,
168 values[i]->bv_val, values[i]->bv_len );
169 HASH_Final( HASHdigest, &HASHcontext );
171 keys[i] = ber_bvdup( &digest );
181 /* Index generation function */
182 int octetStringFilter(
187 struct berval *prefix,
189 struct berval ***keysp )
192 struct berval **keys;
193 HASH_CONTEXT HASHcontext;
194 unsigned char HASHdigest[HASH_BYTES];
195 struct berval *value = (struct berval *) assertValue;
196 struct berval digest;
197 digest.bv_val = HASHdigest;
198 digest.bv_len = sizeof(HASHdigest);
200 slen = strlen( syntax->ssyn_oid );
201 mlen = strlen( mr->smr_oid );
203 keys = ch_malloc( sizeof( struct berval * ) * 2 );
205 HASH_Init( &HASHcontext );
206 if( prefix != NULL && prefix->bv_len > 0 ) {
207 HASH_Update( &HASHcontext,
208 prefix->bv_val, prefix->bv_len );
210 HASH_Update( &HASHcontext,
211 syntax->ssyn_oid, slen );
212 HASH_Update( &HASHcontext,
214 HASH_Update( &HASHcontext,
215 value->bv_val, value->bv_len );
216 HASH_Final( HASHdigest, &HASHcontext );
218 keys[0] = ber_bvdup( &digest );
234 if( in->bv_len == 0 ) return LDAP_SUCCESS;
236 dn = ch_strdup( in->bv_val );
238 rc = dn_validate( dn ) == NULL
239 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
249 struct berval **normalized )
253 if ( val->bv_len != 0 ) {
255 #ifdef USE_DN_NORMALIZE
256 out = ber_bvstr( UTF8normalize( val->bv_val, UTF8_CASEFOLD ) );
258 out = ber_bvdup( val );
259 ldap_pvt_str2upper( out->bv_val );
261 dn = dn_validate( out->bv_val );
265 return LDAP_INVALID_SYNTAX;
269 out->bv_len = strlen( dn );
271 out = ber_bvdup( val );
284 struct berval *value,
285 void *assertedValue )
288 struct berval *asserted = (struct berval *) assertedValue;
290 match = value->bv_len - asserted->bv_len;
293 #ifdef USE_DN_NORMALIZE
294 match = strcmp( value->bv_val, asserted->bv_val );
296 match = strcasecmp( value->bv_val, asserted->bv_val );
301 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
302 "dnMatch: %d\n %s\n %s\n", match,
303 value->bv_val, asserted->bv_val ));
305 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
306 match, value->bv_val, asserted->bv_val );
322 if( in->bv_len == 0 ) return LDAP_SUCCESS;
324 dn = ber_bvdup( in );
326 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
327 /* assume presence of optional UID */
330 for(i=dn->bv_len-2; i>2; i--) {
331 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
335 if( dn->bv_val[i] != '\'' ) {
336 return LDAP_INVALID_SYNTAX;
338 if( dn->bv_val[i-1] != 'B' ) {
339 return LDAP_INVALID_SYNTAX;
341 if( dn->bv_val[i-2] != '#' ) {
342 return LDAP_INVALID_SYNTAX;
345 /* trim the UID to allow use of dn_validate */
346 dn->bv_val[i-2] = '\0';
349 rc = dn_validate( dn->bv_val ) == NULL
350 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
360 struct berval **normalized )
362 struct berval *out = ber_bvdup( val );
364 if( out->bv_len != 0 ) {
368 ber_len_t uidlen = 0;
370 if( out->bv_val[out->bv_len-1] == '\'' ) {
371 /* assume presence of optional UID */
372 uid = strrchr( out->bv_val, '#' );
376 return LDAP_INVALID_SYNTAX;
379 uidlen = out->bv_len - (out->bv_val - uid);
380 /* temporarily trim the UID */
384 #ifdef USE_DN_NORMALIZE
385 dn = dn_normalize( out->bv_val );
387 dn = dn_validate( out->bv_val );
392 return LDAP_INVALID_SYNTAX;
398 /* restore the separator */
401 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
405 out->bv_len = dnlen + uidlen;
417 /* any value allowed */
426 /* any value allowed */
437 /* very unforgiving validation, requires no normalization
438 * before simplistic matching
440 if( in->bv_len < 3 ) {
441 return LDAP_INVALID_SYNTAX;
444 if( in->bv_val[0] != 'B' ||
445 in->bv_val[1] != '\'' ||
446 in->bv_val[in->bv_len-1] != '\'' )
448 return LDAP_INVALID_SYNTAX;
451 for( i=in->bv_len-2; i>1; i-- ) {
452 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
453 return LDAP_INVALID_SYNTAX;
461 * Handling boolean syntax and matching is quite rigid.
462 * A more flexible approach would be to allow a variety
463 * of strings to be normalized and prettied into TRUE
471 /* very unforgiving validation, requires no normalization
472 * before simplistic matching
475 if( in->bv_len == 4 ) {
476 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
479 } else if( in->bv_len == 5 ) {
480 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
485 return LDAP_INVALID_SYNTAX;
494 struct berval *value,
495 void *assertedValue )
497 /* simplistic matching allowed by rigid validation */
498 struct berval *asserted = (struct berval *) assertedValue;
499 *matchp = value->bv_len != asserted->bv_len;
504 /* case insensitive UTF8 strncmp with offset for second string */
507 struct berval *right,
513 ber_len_t rlen, llen;
514 ber_len_t rslen, lslen;
515 ldap_unicode_t ru, lu;
516 ldap_unicode_t ruu, luu;
518 rslen = len < right->bv_len ? len : right->bv_len;
519 lslen = len + offset < left->bv_len ? len : left->bv_len;
521 for( r = 0, l = offset;
522 r < rslen && l < lslen;
526 * XXYYZ: we convert to ucs4 even though -llunicode
527 * expects ucs2 in an unsigned long
529 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
530 if( ru == LDAP_UCS4_INVALID ) {
534 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
535 if( lu == LDAP_UCS4_INVALID ) {
539 ruu = uctoupper( ru );
540 luu = uctoupper( lu );
544 } else if( luu > ruu ) {
548 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
549 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
565 static char *UTF8casechr( const char *str, const char *c )
567 char *p, *lower, *upper;
568 ldap_ucs4_t tch, ch = ldap_utf8_to_ucs4(c);
570 tch = uctolower ( ch );
571 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
572 if( ldap_utf8_to_ucs4( p ) == tch ) {
576 lower = *p != '\0' ? p : NULL;
578 tch = uctoupper ( ch );
579 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
580 if( ldap_utf8_to_ucs4( p ) == tch ) {
584 upper = *p != '\0' ? p : NULL;
586 if( lower && upper ) {
587 return lower < upper ? lower : upper;
588 } else if ( lower ) {
603 unsigned char *u = in->bv_val;
605 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
607 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
608 /* get the length indicated by the first byte */
609 len = LDAP_UTF8_CHARLEN( u );
611 /* should not be zero */
612 if( len == 0 ) return LDAP_INVALID_SYNTAX;
614 /* make sure len corresponds with the offset
615 to the next character */
616 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
619 if( count != 0 ) return LDAP_INVALID_SYNTAX;
628 struct berval **normalized )
630 struct berval *newval;
633 newval = ch_malloc( sizeof( struct berval ) );
637 /* Ignore initial whitespace */
638 while ( ldap_utf8_isspace( p ) ) {
644 return LDAP_INVALID_SYNTAX;
647 newval->bv_val = ch_strdup( p );
648 p = q = newval->bv_val;
654 if ( ldap_utf8_isspace( p ) ) {
655 len = LDAP_UTF8_COPY(q,p);
660 /* Ignore the extra whitespace */
661 while ( ldap_utf8_isspace( p ) ) {
665 len = LDAP_UTF8_COPY(q,p);
672 assert( *newval->bv_val );
673 assert( newval->bv_val < p );
676 /* cannot start with a space */
677 assert( !ldap_utf8_isspace(newval->bv_val) );
680 * If the string ended in space, backup the pointer one
681 * position. One is enough because the above loop collapsed
682 * all whitespace to a single space.
689 /* cannot end with a space */
690 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
695 newval->bv_len = q - newval->bv_val;
696 *normalized = newval;
701 #if defined(SLAPD_APPROX_MULTISTRING)
703 #if defined(SLAPD_APPROX_INITIALS)
704 #define SLAPD_APPROX_DELIMITER "._ "
705 #define SLAPD_APPROX_WORDLEN 2
707 #define SLAPD_APPROX_DELIMITER " "
708 #define SLAPD_APPROX_WORDLEN 1
717 struct berval *value,
718 void *assertedValue )
720 char *val, *assertv, **values, **words, *c;
721 int i, count, len, nextchunk=0, nextavail=0;
724 /* Isolate how many words there are */
725 val = ch_strdup( value->bv_val );
726 for( c=val,count=1; *c; c++ ) {
727 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
728 if ( c == NULL ) break;
733 /* Get a phonetic copy of each word */
734 words = (char **)ch_malloc( count * sizeof(char *) );
735 values = (char **)ch_malloc( count * sizeof(char *) );
736 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
738 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. */
744 assertv = ch_strdup( ((struct berval *)assertedValue)->bv_val );
746 while ( nextchunk < ((struct berval *)assertedValue)->bv_len ) {
747 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
752 #if defined(SLAPD_APPROX_INITIALS)
753 else if( len == 1 ) {
754 /* Single letter words need to at least match one word's initial */
755 for( i=nextavail; i<count; i++ )
756 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
763 /* Isolate the next word in the asserted value and phonetic it */
764 assertv[nextchunk+len] = '\0';
765 val = phonetic( assertv + nextchunk );
767 /* See if this phonetic chunk is in the remaining words of *value */
768 for( i=nextavail; i<count; i++ ){
769 if( !strcmp( val, values[i] ) ){
776 /* This chunk in the asserted value was NOT within the *value. */
782 /* Go on to the next word in the asserted value */
786 /* If some of the words were seen, call it a match */
787 if( nextavail > 0 ) {
796 for( i=0; i<count; i++ ) {
797 ch_free( values[i] );
813 struct berval *prefix,
814 struct berval **values,
815 struct berval ***keysp )
818 int i,j, len, wordcount, keycount=0;
819 struct berval **newkeys, **keys=NULL;
822 for( j=0; values[j] != NULL; j++ ) {
824 /* Isolate how many words there are. There will be a key for each */
825 val = ch_strdup( values[j]->bv_val );
826 for( wordcount=0,c=val; *c; c++) {
827 len = strcspn(c, SLAPD_APPROX_DELIMITER);
828 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
830 if (*c == '\0') break;
834 /* Allocate/increase storage to account for new keys */
835 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
836 * sizeof(struct berval *) );
837 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
838 if( keys ) ch_free( keys );
841 /* Get a phonetic copy of each word */
842 for( c=val,i=0; i<wordcount; c+=len+1 ) {
844 if( len < SLAPD_APPROX_WORDLEN ) continue;
845 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
846 keys[keycount]->bv_val = phonetic( c );
847 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
854 keys[keycount] = NULL;
867 struct berval *prefix,
869 struct berval ***keysp )
873 struct berval **keys;
876 /* Isolate how many words there are. There will be a key for each */
877 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
878 for( count=0,c=val; *c; c++) {
879 len = strcspn(c, SLAPD_APPROX_DELIMITER);
880 if( len >= SLAPD_APPROX_WORDLEN ) count++;
882 if (*c == '\0') break;
886 /* Allocate storage for new keys */
887 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
889 /* Get a phonetic copy of each word */
890 for( c=val,i=0; i<count; c+=len+1 ) {
892 if( len < SLAPD_APPROX_WORDLEN ) continue;
893 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
894 keys[i]->bv_val = phonetic( c );
895 keys[i]->bv_len = strlen( keys[i]->bv_val );
909 /* No other form of Approximate Matching is defined */
917 struct berval *value,
918 void *assertedValue )
920 char *vapprox, *avapprox;
922 vapprox = phonetic( value->bv_val );
923 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
925 *matchp = strcmp( vapprox, avapprox );
939 struct berval *prefix,
940 struct berval **values,
941 struct berval ***keysp )
944 struct berval **keys;
947 for( i=0; values[i] != NULL; i++ ) {
948 /* just count them */
952 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
954 /* Copy each value and run it through phonetic() */
955 for( i=0; values[i] != NULL; i++ ) {
956 keys[i] = ch_malloc( sizeof( struct berval * ) );
957 keys[i]->bv_val = phonetic( values[i]->bv_val );
958 keys[i]->bv_len = strlen( keys[i]->bv_val );
973 struct berval *prefix,
975 struct berval ***keysp )
977 struct berval **keys;
980 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
982 /* Copy the value and run it through phonetic() */
983 keys[0] = ch_malloc( sizeof( struct berval * ) );
984 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
985 keys[0]->bv_len = strlen( keys[0]->bv_val );
1000 struct berval *value,
1001 void *assertedValue )
1003 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1006 match = strncmp( value->bv_val,
1007 ((struct berval *) assertedValue)->bv_val,
1012 return LDAP_SUCCESS;
1016 caseExactSubstringsMatch(
1021 struct berval *value,
1022 void *assertedValue )
1025 SubstringsAssertion *sub = assertedValue;
1026 struct berval left = *value;
1030 /* Add up asserted input length */
1031 if( sub->sa_initial ) {
1032 inlen += sub->sa_initial->bv_len;
1035 for(i=0; sub->sa_any[i] != NULL; i++) {
1036 inlen += sub->sa_any[i]->bv_len;
1039 if( sub->sa_final ) {
1040 inlen += sub->sa_final->bv_len;
1043 if( sub->sa_initial ) {
1044 if( inlen > left.bv_len ) {
1049 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1050 sub->sa_initial->bv_len );
1056 left.bv_val += sub->sa_initial->bv_len;
1057 left.bv_len -= sub->sa_initial->bv_len;
1058 inlen -= sub->sa_initial->bv_len;
1061 if( sub->sa_final ) {
1062 if( inlen > left.bv_len ) {
1067 match = strncmp( sub->sa_final->bv_val,
1068 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1069 sub->sa_final->bv_len );
1075 left.bv_len -= sub->sa_final->bv_len;
1076 inlen -= sub->sa_final->bv_len;
1080 for(i=0; sub->sa_any[i]; i++) {
1085 if( inlen > left.bv_len ) {
1086 /* not enough length */
1091 if( sub->sa_any[i]->bv_len == 0 ) {
1095 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1102 idx = p - left.bv_val;
1103 assert( idx < left.bv_len );
1105 if( idx >= left.bv_len ) {
1106 /* this shouldn't happen */
1113 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1114 /* not enough left */
1119 match = strncmp( left.bv_val,
1120 sub->sa_any[i]->bv_val,
1121 sub->sa_any[i]->bv_len );
1129 left.bv_val += sub->sa_any[i]->bv_len;
1130 left.bv_len -= sub->sa_any[i]->bv_len;
1131 inlen -= sub->sa_any[i]->bv_len;
1137 return LDAP_SUCCESS;
1140 /* Index generation function */
1141 int caseExactIndexer(
1146 struct berval *prefix,
1147 struct berval **values,
1148 struct berval ***keysp )
1152 struct berval **keys;
1153 HASH_CONTEXT HASHcontext;
1154 unsigned char HASHdigest[HASH_BYTES];
1155 struct berval digest;
1156 digest.bv_val = HASHdigest;
1157 digest.bv_len = sizeof(HASHdigest);
1159 /* we should have at least one value at this point */
1160 assert( values != NULL && values[0] != NULL );
1162 for( i=0; values[i] != NULL; i++ ) {
1163 /* just count them */
1166 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1168 slen = strlen( syntax->ssyn_oid );
1169 mlen = strlen( mr->smr_oid );
1171 for( i=0; values[i] != NULL; i++ ) {
1172 struct berval *value;
1174 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
1179 HASH_Init( &HASHcontext );
1180 if( prefix != NULL && prefix->bv_len > 0 ) {
1181 HASH_Update( &HASHcontext,
1182 prefix->bv_val, prefix->bv_len );
1184 HASH_Update( &HASHcontext,
1185 syntax->ssyn_oid, slen );
1186 HASH_Update( &HASHcontext,
1187 mr->smr_oid, mlen );
1188 HASH_Update( &HASHcontext,
1189 value->bv_val, value->bv_len );
1190 HASH_Final( HASHdigest, &HASHcontext );
1193 ber_bvfree( value );
1196 keys[i] = ber_bvdup( &digest );
1201 return LDAP_SUCCESS;
1204 /* Index generation function */
1205 int caseExactFilter(
1210 struct berval *prefix,
1212 struct berval ***keysp )
1215 struct berval **keys;
1216 HASH_CONTEXT HASHcontext;
1217 unsigned char HASHdigest[HASH_BYTES];
1218 struct berval *value;
1219 struct berval digest;
1220 digest.bv_val = HASHdigest;
1221 digest.bv_len = sizeof(HASHdigest);
1223 slen = strlen( syntax->ssyn_oid );
1224 mlen = strlen( mr->smr_oid );
1227 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val, UTF8_NOCASEFOLD ) );
1229 value = (struct berval *) assertValue;
1232 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1234 HASH_Init( &HASHcontext );
1235 if( prefix != NULL && prefix->bv_len > 0 ) {
1236 HASH_Update( &HASHcontext,
1237 prefix->bv_val, prefix->bv_len );
1239 HASH_Update( &HASHcontext,
1240 syntax->ssyn_oid, slen );
1241 HASH_Update( &HASHcontext,
1242 mr->smr_oid, mlen );
1243 HASH_Update( &HASHcontext,
1244 value->bv_val, value->bv_len );
1245 HASH_Final( HASHdigest, &HASHcontext );
1247 keys[0] = ber_bvdup( &digest );
1251 ber_bvfree( value );
1255 return LDAP_SUCCESS;
1258 /* Substrings Index generation function */
1259 int caseExactSubstringsIndexer(
1264 struct berval *prefix,
1265 struct berval **values,
1266 struct berval ***keysp )
1270 struct berval **keys;
1271 HASH_CONTEXT HASHcontext;
1272 unsigned char HASHdigest[HASH_BYTES];
1273 struct berval digest;
1274 digest.bv_val = HASHdigest;
1275 digest.bv_len = sizeof(HASHdigest);
1277 /* we should have at least one value at this point */
1278 assert( values != NULL && values[0] != NULL );
1281 for( i=0; values[i] != NULL; i++ ) {
1282 /* count number of indices to generate */
1283 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1287 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1288 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1289 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1290 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1292 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1296 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1297 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1298 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1302 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1303 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1304 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1305 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1307 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1313 /* no keys to generate */
1315 return LDAP_SUCCESS;
1318 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1320 slen = strlen( syntax->ssyn_oid );
1321 mlen = strlen( mr->smr_oid );
1324 for( i=0; values[i] != NULL; i++ ) {
1326 struct berval *value;
1328 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1331 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
1336 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1337 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1339 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1340 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1342 for( j=0; j<max; j++ ) {
1343 HASH_Init( &HASHcontext );
1344 if( prefix != NULL && prefix->bv_len > 0 ) {
1345 HASH_Update( &HASHcontext,
1346 prefix->bv_val, prefix->bv_len );
1349 HASH_Update( &HASHcontext,
1350 &pre, sizeof( pre ) );
1351 HASH_Update( &HASHcontext,
1352 syntax->ssyn_oid, slen );
1353 HASH_Update( &HASHcontext,
1354 mr->smr_oid, mlen );
1355 HASH_Update( &HASHcontext,
1357 SLAP_INDEX_SUBSTR_MAXLEN );
1358 HASH_Final( HASHdigest, &HASHcontext );
1360 keys[nkeys++] = ber_bvdup( &digest );
1364 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1365 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1367 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1370 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1371 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1372 HASH_Init( &HASHcontext );
1373 if( prefix != NULL && prefix->bv_len > 0 ) {
1374 HASH_Update( &HASHcontext,
1375 prefix->bv_val, prefix->bv_len );
1377 HASH_Update( &HASHcontext,
1378 &pre, sizeof( pre ) );
1379 HASH_Update( &HASHcontext,
1380 syntax->ssyn_oid, slen );
1381 HASH_Update( &HASHcontext,
1382 mr->smr_oid, mlen );
1383 HASH_Update( &HASHcontext,
1385 HASH_Final( HASHdigest, &HASHcontext );
1387 keys[nkeys++] = ber_bvdup( &digest );
1390 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1391 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1392 HASH_Init( &HASHcontext );
1393 if( prefix != NULL && prefix->bv_len > 0 ) {
1394 HASH_Update( &HASHcontext,
1395 prefix->bv_val, prefix->bv_len );
1397 HASH_Update( &HASHcontext,
1398 &pre, sizeof( pre ) );
1399 HASH_Update( &HASHcontext,
1400 syntax->ssyn_oid, slen );
1401 HASH_Update( &HASHcontext,
1402 mr->smr_oid, mlen );
1403 HASH_Update( &HASHcontext,
1404 &value->bv_val[value->bv_len-j], j );
1405 HASH_Final( HASHdigest, &HASHcontext );
1407 keys[nkeys++] = ber_bvdup( &digest );
1413 ber_bvfree( value );
1426 return LDAP_SUCCESS;
1429 int caseExactSubstringsFilter(
1434 struct berval *prefix,
1436 struct berval ***keysp )
1438 SubstringsAssertion *sa = assertValue;
1440 ber_len_t nkeys = 0;
1441 size_t slen, mlen, klen;
1442 struct berval **keys;
1443 HASH_CONTEXT HASHcontext;
1444 unsigned char HASHdigest[HASH_BYTES];
1445 struct berval *value;
1446 struct berval digest;
1448 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1449 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1454 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1456 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1457 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1458 /* don't bother accounting for stepping */
1459 nkeys += sa->sa_any[i]->bv_len -
1460 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1465 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1466 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1473 return LDAP_SUCCESS;
1476 digest.bv_val = HASHdigest;
1477 digest.bv_len = sizeof(HASHdigest);
1479 slen = strlen( syntax->ssyn_oid );
1480 mlen = strlen( mr->smr_oid );
1482 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1485 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1486 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1488 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1490 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_NOCASEFOLD ) );
1492 value = sa->sa_initial;
1495 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1496 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1498 HASH_Init( &HASHcontext );
1499 if( prefix != NULL && prefix->bv_len > 0 ) {
1500 HASH_Update( &HASHcontext,
1501 prefix->bv_val, prefix->bv_len );
1503 HASH_Update( &HASHcontext,
1504 &pre, sizeof( pre ) );
1505 HASH_Update( &HASHcontext,
1506 syntax->ssyn_oid, slen );
1507 HASH_Update( &HASHcontext,
1508 mr->smr_oid, mlen );
1509 HASH_Update( &HASHcontext,
1510 value->bv_val, klen );
1511 HASH_Final( HASHdigest, &HASHcontext );
1514 ber_bvfree( value );
1516 keys[nkeys++] = ber_bvdup( &digest );
1519 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1521 pre = SLAP_INDEX_SUBSTR_PREFIX;
1522 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1524 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1525 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1530 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_NOCASEFOLD ) );
1532 value = sa->sa_any[i];
1536 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1537 j += SLAP_INDEX_SUBSTR_STEP )
1539 HASH_Init( &HASHcontext );
1540 if( prefix != NULL && prefix->bv_len > 0 ) {
1541 HASH_Update( &HASHcontext,
1542 prefix->bv_val, prefix->bv_len );
1544 HASH_Update( &HASHcontext,
1545 &pre, sizeof( pre ) );
1546 HASH_Update( &HASHcontext,
1547 syntax->ssyn_oid, slen );
1548 HASH_Update( &HASHcontext,
1549 mr->smr_oid, mlen );
1550 HASH_Update( &HASHcontext,
1551 &value->bv_val[j], klen );
1552 HASH_Final( HASHdigest, &HASHcontext );
1554 keys[nkeys++] = ber_bvdup( &digest );
1558 ber_bvfree( value );
1563 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1564 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1566 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1568 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_NOCASEFOLD ) );
1570 value = sa->sa_final;
1573 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1574 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1576 HASH_Init( &HASHcontext );
1577 if( prefix != NULL && prefix->bv_len > 0 ) {
1578 HASH_Update( &HASHcontext,
1579 prefix->bv_val, prefix->bv_len );
1581 HASH_Update( &HASHcontext,
1582 &pre, sizeof( pre ) );
1583 HASH_Update( &HASHcontext,
1584 syntax->ssyn_oid, slen );
1585 HASH_Update( &HASHcontext,
1586 mr->smr_oid, mlen );
1587 HASH_Update( &HASHcontext,
1588 &value->bv_val[value->bv_len-klen], klen );
1589 HASH_Final( HASHdigest, &HASHcontext );
1592 ber_bvfree( value );
1594 keys[nkeys++] = ber_bvdup( &digest );
1605 return LDAP_SUCCESS;
1614 struct berval *value,
1615 void *assertedValue )
1618 *matchp = UTF8normcmp( value->bv_val,
1619 ((struct berval *) assertedValue)->bv_val,
1622 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1625 match = strncasecmp( value->bv_val,
1626 ((struct berval *) assertedValue)->bv_val,
1632 return LDAP_SUCCESS;
1636 caseIgnoreSubstringsMatch(
1641 struct berval *value,
1642 void *assertedValue )
1645 SubstringsAssertion *sub = assertedValue;
1646 struct berval left = *value;
1650 /* Add up asserted input length */
1651 if( sub->sa_initial ) {
1652 inlen += sub->sa_initial->bv_len;
1655 for(i=0; sub->sa_any[i] != NULL; i++) {
1656 inlen += sub->sa_any[i]->bv_len;
1659 if( sub->sa_final ) {
1660 inlen += sub->sa_final->bv_len;
1663 if( sub->sa_initial ) {
1664 if( inlen > left.bv_len ) {
1670 match = UTF8oncasecmp( sub->sa_initial, &left,
1671 sub->sa_initial->bv_len, 0 );
1673 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1674 sub->sa_initial->bv_len );
1681 left.bv_val += sub->sa_initial->bv_len;
1682 left.bv_len -= sub->sa_initial->bv_len;
1683 inlen -= sub->sa_initial->bv_len;
1686 if( sub->sa_final ) {
1687 if( inlen > left.bv_len ) {
1693 match = UTF8oncasecmp( sub->sa_final, &left,
1694 sub->sa_final->bv_len,
1695 left.bv_len - sub->sa_final->bv_len );
1697 match = strncasecmp( sub->sa_final->bv_val,
1698 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1699 sub->sa_final->bv_len );
1706 left.bv_len -= sub->sa_final->bv_len;
1707 inlen -= sub->sa_final->bv_len;
1711 for(i=0; sub->sa_any[i]; i++) {
1716 if( inlen > left.bv_len ) {
1717 /* not enough length */
1722 if( sub->sa_any[i]->bv_len == 0 ) {
1727 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1729 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1737 idx = p - left.bv_val;
1738 assert( idx < left.bv_len );
1740 if( idx >= left.bv_len ) {
1741 /* this shouldn't happen */
1748 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1749 /* not enough left */
1755 match = UTF8oncasecmp( &left, sub->sa_any[i],
1756 sub->sa_any[i]->bv_len, 0 );
1759 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1765 match = strncasecmp( left.bv_val,
1766 sub->sa_any[i]->bv_val,
1767 sub->sa_any[i]->bv_len );
1777 left.bv_val += sub->sa_any[i]->bv_len;
1778 left.bv_len -= sub->sa_any[i]->bv_len;
1779 inlen -= sub->sa_any[i]->bv_len;
1785 return LDAP_SUCCESS;
1788 /* Index generation function */
1789 int caseIgnoreIndexer(
1794 struct berval *prefix,
1795 struct berval **values,
1796 struct berval ***keysp )
1800 struct berval **keys;
1801 HASH_CONTEXT HASHcontext;
1802 unsigned char HASHdigest[HASH_BYTES];
1803 struct berval digest;
1804 digest.bv_val = HASHdigest;
1805 digest.bv_len = sizeof(HASHdigest);
1807 /* we should have at least one value at this point */
1808 assert( values != NULL && values[0] != NULL );
1810 for( i=0; values[i] != NULL; i++ ) {
1811 /* just count them */
1814 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1816 slen = strlen( syntax->ssyn_oid );
1817 mlen = strlen( mr->smr_oid );
1819 for( i=0; values[i] != NULL; i++ ) {
1820 struct berval *value;
1822 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1824 value = ber_bvdup( values[i] );
1825 ldap_pvt_str2upper( value->bv_val );
1827 HASH_Init( &HASHcontext );
1828 if( prefix != NULL && prefix->bv_len > 0 ) {
1829 HASH_Update( &HASHcontext,
1830 prefix->bv_val, prefix->bv_len );
1832 HASH_Update( &HASHcontext,
1833 syntax->ssyn_oid, slen );
1834 HASH_Update( &HASHcontext,
1835 mr->smr_oid, mlen );
1836 HASH_Update( &HASHcontext,
1837 value->bv_val, value->bv_len );
1838 HASH_Final( HASHdigest, &HASHcontext );
1840 ber_bvfree( value );
1842 keys[i] = ber_bvdup( &digest );
1847 return LDAP_SUCCESS;
1850 /* Index generation function */
1851 int caseIgnoreFilter(
1856 struct berval *prefix,
1858 struct berval ***keysp )
1861 struct berval **keys;
1862 HASH_CONTEXT HASHcontext;
1863 unsigned char HASHdigest[HASH_BYTES];
1864 struct berval *value;
1865 struct berval digest;
1866 digest.bv_val = HASHdigest;
1867 digest.bv_len = sizeof(HASHdigest);
1869 slen = strlen( syntax->ssyn_oid );
1870 mlen = strlen( mr->smr_oid );
1873 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val, UTF8_CASEFOLD ) );
1875 value = ber_bvdup( (struct berval *) assertValue );
1876 ldap_pvt_str2upper( value->bv_val );
1879 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1881 HASH_Init( &HASHcontext );
1882 if( prefix != NULL && prefix->bv_len > 0 ) {
1883 HASH_Update( &HASHcontext,
1884 prefix->bv_val, prefix->bv_len );
1886 HASH_Update( &HASHcontext,
1887 syntax->ssyn_oid, slen );
1888 HASH_Update( &HASHcontext,
1889 mr->smr_oid, mlen );
1890 HASH_Update( &HASHcontext,
1891 value->bv_val, value->bv_len );
1892 HASH_Final( HASHdigest, &HASHcontext );
1894 keys[0] = ber_bvdup( &digest );
1897 ber_bvfree( value );
1901 return LDAP_SUCCESS;
1904 /* Substrings Index generation function */
1905 int caseIgnoreSubstringsIndexer(
1910 struct berval *prefix,
1911 struct berval **values,
1912 struct berval ***keysp )
1916 struct berval **keys;
1917 HASH_CONTEXT HASHcontext;
1918 unsigned char HASHdigest[HASH_BYTES];
1919 struct berval digest;
1920 digest.bv_val = HASHdigest;
1921 digest.bv_len = sizeof(HASHdigest);
1923 /* we should have at least one value at this point */
1924 assert( values != NULL && values[0] != NULL );
1927 for( i=0; values[i] != NULL; i++ ) {
1928 /* count number of indices to generate */
1929 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1933 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1934 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1935 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1936 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1938 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1942 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1943 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1944 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1948 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1949 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1950 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1951 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1953 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1959 /* no keys to generate */
1961 return LDAP_SUCCESS;
1964 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1966 slen = strlen( syntax->ssyn_oid );
1967 mlen = strlen( mr->smr_oid );
1970 for( i=0; values[i] != NULL; i++ ) {
1972 struct berval *value;
1974 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1977 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1979 value = ber_bvdup( values[i] );
1980 ldap_pvt_str2upper( value->bv_val );
1983 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1984 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1986 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1987 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1989 for( j=0; j<max; j++ ) {
1990 HASH_Init( &HASHcontext );
1991 if( prefix != NULL && prefix->bv_len > 0 ) {
1992 HASH_Update( &HASHcontext,
1993 prefix->bv_val, prefix->bv_len );
1996 HASH_Update( &HASHcontext,
1997 &pre, sizeof( pre ) );
1998 HASH_Update( &HASHcontext,
1999 syntax->ssyn_oid, slen );
2000 HASH_Update( &HASHcontext,
2001 mr->smr_oid, mlen );
2002 HASH_Update( &HASHcontext,
2004 SLAP_INDEX_SUBSTR_MAXLEN );
2005 HASH_Final( HASHdigest, &HASHcontext );
2007 keys[nkeys++] = ber_bvdup( &digest );
2011 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2012 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2014 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2017 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2018 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2019 HASH_Init( &HASHcontext );
2020 if( prefix != NULL && prefix->bv_len > 0 ) {
2021 HASH_Update( &HASHcontext,
2022 prefix->bv_val, prefix->bv_len );
2024 HASH_Update( &HASHcontext,
2025 &pre, sizeof( pre ) );
2026 HASH_Update( &HASHcontext,
2027 syntax->ssyn_oid, slen );
2028 HASH_Update( &HASHcontext,
2029 mr->smr_oid, mlen );
2030 HASH_Update( &HASHcontext,
2032 HASH_Final( HASHdigest, &HASHcontext );
2034 keys[nkeys++] = ber_bvdup( &digest );
2037 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2038 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2039 HASH_Init( &HASHcontext );
2040 if( prefix != NULL && prefix->bv_len > 0 ) {
2041 HASH_Update( &HASHcontext,
2042 prefix->bv_val, prefix->bv_len );
2044 HASH_Update( &HASHcontext,
2045 &pre, sizeof( pre ) );
2046 HASH_Update( &HASHcontext,
2047 syntax->ssyn_oid, slen );
2048 HASH_Update( &HASHcontext,
2049 mr->smr_oid, mlen );
2050 HASH_Update( &HASHcontext,
2051 &value->bv_val[value->bv_len-j], j );
2052 HASH_Final( HASHdigest, &HASHcontext );
2054 keys[nkeys++] = ber_bvdup( &digest );
2059 ber_bvfree( value );
2070 return LDAP_SUCCESS;
2073 int caseIgnoreSubstringsFilter(
2078 struct berval *prefix,
2080 struct berval ***keysp )
2082 SubstringsAssertion *sa = assertValue;
2084 ber_len_t nkeys = 0;
2085 size_t slen, mlen, klen;
2086 struct berval **keys;
2087 HASH_CONTEXT HASHcontext;
2088 unsigned char HASHdigest[HASH_BYTES];
2089 struct berval *value;
2090 struct berval digest;
2092 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2093 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2098 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2100 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2101 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2102 /* don't bother accounting for stepping */
2103 nkeys += sa->sa_any[i]->bv_len -
2104 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2109 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2110 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2117 return LDAP_SUCCESS;
2120 digest.bv_val = HASHdigest;
2121 digest.bv_len = sizeof(HASHdigest);
2123 slen = strlen( syntax->ssyn_oid );
2124 mlen = strlen( mr->smr_oid );
2126 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2129 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2130 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2132 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2134 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_CASEFOLD ) );
2136 value = ber_bvdup( sa->sa_initial );
2137 ldap_pvt_str2upper( value->bv_val );
2140 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2141 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2143 HASH_Init( &HASHcontext );
2144 if( prefix != NULL && prefix->bv_len > 0 ) {
2145 HASH_Update( &HASHcontext,
2146 prefix->bv_val, prefix->bv_len );
2148 HASH_Update( &HASHcontext,
2149 &pre, sizeof( pre ) );
2150 HASH_Update( &HASHcontext,
2151 syntax->ssyn_oid, slen );
2152 HASH_Update( &HASHcontext,
2153 mr->smr_oid, mlen );
2154 HASH_Update( &HASHcontext,
2155 value->bv_val, klen );
2156 HASH_Final( HASHdigest, &HASHcontext );
2158 ber_bvfree( value );
2159 keys[nkeys++] = ber_bvdup( &digest );
2162 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2164 pre = SLAP_INDEX_SUBSTR_PREFIX;
2165 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2167 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2168 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2173 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_CASEFOLD ) );
2175 value = ber_bvdup( sa->sa_any[i] );
2176 ldap_pvt_str2upper( value->bv_val );
2180 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2181 j += SLAP_INDEX_SUBSTR_STEP )
2183 HASH_Init( &HASHcontext );
2184 if( prefix != NULL && prefix->bv_len > 0 ) {
2185 HASH_Update( &HASHcontext,
2186 prefix->bv_val, prefix->bv_len );
2188 HASH_Update( &HASHcontext,
2189 &pre, sizeof( pre ) );
2190 HASH_Update( &HASHcontext,
2191 syntax->ssyn_oid, slen );
2192 HASH_Update( &HASHcontext,
2193 mr->smr_oid, mlen );
2194 HASH_Update( &HASHcontext,
2195 &value->bv_val[j], klen );
2196 HASH_Final( HASHdigest, &HASHcontext );
2198 keys[nkeys++] = ber_bvdup( &digest );
2201 ber_bvfree( value );
2205 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2206 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2208 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2210 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_CASEFOLD ) );
2212 value = ber_bvdup( sa->sa_final );
2213 ldap_pvt_str2upper( value->bv_val );
2216 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2217 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2219 HASH_Init( &HASHcontext );
2220 if( prefix != NULL && prefix->bv_len > 0 ) {
2221 HASH_Update( &HASHcontext,
2222 prefix->bv_val, prefix->bv_len );
2224 HASH_Update( &HASHcontext,
2225 &pre, sizeof( pre ) );
2226 HASH_Update( &HASHcontext,
2227 syntax->ssyn_oid, slen );
2228 HASH_Update( &HASHcontext,
2229 mr->smr_oid, mlen );
2230 HASH_Update( &HASHcontext,
2231 &value->bv_val[value->bv_len-klen], klen );
2232 HASH_Final( HASHdigest, &HASHcontext );
2234 ber_bvfree( value );
2235 keys[nkeys++] = ber_bvdup( &digest );
2246 return LDAP_SUCCESS;
2252 struct berval *val )
2256 if( val->bv_len == 0 ) {
2257 /* disallow empty strings */
2258 return LDAP_INVALID_SYNTAX;
2261 if( OID_LEADCHAR(val->bv_val[0]) ) {
2263 for(i=1; i < val->bv_len; i++) {
2264 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2265 if( dot++ ) return 1;
2266 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2269 return LDAP_INVALID_SYNTAX;
2273 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2275 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2276 for(i=1; i < val->bv_len; i++) {
2277 if( !DESC_CHAR(val->bv_val[i] ) ) {
2278 return LDAP_INVALID_SYNTAX;
2282 return LDAP_SUCCESS;
2285 return LDAP_INVALID_SYNTAX;
2291 struct berval *val )
2295 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2297 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2298 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2299 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2300 return LDAP_INVALID_SYNTAX;
2303 for(i=1; i < val->bv_len; i++) {
2304 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2307 return LDAP_SUCCESS;
2314 struct berval **normalized )
2317 struct berval *newval;
2323 negative = ( *p == '-' );
2324 if( *p == '-' || *p == '+' ) p++;
2326 /* Ignore leading zeros */
2327 while ( *p == '0' ) p++;
2329 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2332 newval->bv_val = ch_strdup("0");
2337 newval->bv_val = ch_malloc( val->bv_len + 1 );
2341 newval->bv_val[newval->bv_len++] = '-';
2344 for( ; *p != '\0'; p++ ) {
2345 newval->bv_val[newval->bv_len++] = *p;
2349 *normalized = newval;
2350 return LDAP_SUCCESS;
2354 countryStringValidate(
2356 struct berval *val )
2358 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2360 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2361 return LDAP_INVALID_SYNTAX;
2363 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2364 return LDAP_INVALID_SYNTAX;
2367 return LDAP_SUCCESS;
2371 printableStringValidate(
2373 struct berval *val )
2377 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2379 for(i=0; i < val->bv_len; i++) {
2380 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2381 return LDAP_INVALID_SYNTAX;
2385 return LDAP_SUCCESS;
2389 printablesStringValidate(
2391 struct berval *val )
2395 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2397 for(i=0; i < val->bv_len; i++) {
2398 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2399 return LDAP_INVALID_SYNTAX;
2403 return LDAP_SUCCESS;
2409 struct berval *val )
2413 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2415 for(i=0; i < val->bv_len; i++) {
2416 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2419 return LDAP_SUCCESS;
2426 struct berval **normalized )
2428 struct berval *newval;
2431 newval = ch_malloc( sizeof( struct berval ) );
2435 /* Ignore initial whitespace */
2436 while ( ASCII_SPACE( *p ) ) {
2442 return LDAP_INVALID_SYNTAX;
2445 newval->bv_val = ch_strdup( p );
2446 p = q = newval->bv_val;
2449 if ( ASCII_SPACE( *p ) ) {
2452 /* Ignore the extra whitespace */
2453 while ( ASCII_SPACE( *p ) ) {
2461 assert( *newval->bv_val );
2462 assert( newval->bv_val < p );
2465 /* cannot start with a space */
2466 assert( !ASCII_SPACE(*newval->bv_val) );
2469 * If the string ended in space, backup the pointer one
2470 * position. One is enough because the above loop collapsed
2471 * all whitespace to a single space.
2474 if ( ASCII_SPACE( q[-1] ) ) {
2478 /* cannot end with a space */
2479 assert( !ASCII_SPACE( q[-1] ) );
2481 /* null terminate */
2484 newval->bv_len = q - newval->bv_val;
2485 *normalized = newval;
2487 return LDAP_SUCCESS;
2496 struct berval *value,
2497 void *assertedValue )
2499 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2502 match = strncmp( value->bv_val,
2503 ((struct berval *) assertedValue)->bv_val,
2508 return LDAP_SUCCESS;
2512 caseExactIA5SubstringsMatch(
2517 struct berval *value,
2518 void *assertedValue )
2521 SubstringsAssertion *sub = assertedValue;
2522 struct berval left = *value;
2526 /* Add up asserted input length */
2527 if( sub->sa_initial ) {
2528 inlen += sub->sa_initial->bv_len;
2531 for(i=0; sub->sa_any[i] != NULL; i++) {
2532 inlen += sub->sa_any[i]->bv_len;
2535 if( sub->sa_final ) {
2536 inlen += sub->sa_final->bv_len;
2539 if( sub->sa_initial ) {
2540 if( inlen > left.bv_len ) {
2545 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2546 sub->sa_initial->bv_len );
2552 left.bv_val += sub->sa_initial->bv_len;
2553 left.bv_len -= sub->sa_initial->bv_len;
2554 inlen -= sub->sa_initial->bv_len;
2557 if( sub->sa_final ) {
2558 if( inlen > left.bv_len ) {
2563 match = strncmp( sub->sa_final->bv_val,
2564 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2565 sub->sa_final->bv_len );
2571 left.bv_len -= sub->sa_final->bv_len;
2572 inlen -= sub->sa_final->bv_len;
2576 for(i=0; sub->sa_any[i]; i++) {
2581 if( inlen > left.bv_len ) {
2582 /* not enough length */
2587 if( sub->sa_any[i]->bv_len == 0 ) {
2591 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2598 idx = p - left.bv_val;
2599 assert( idx < left.bv_len );
2601 if( idx >= left.bv_len ) {
2602 /* this shouldn't happen */
2609 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2610 /* not enough left */
2615 match = strncmp( left.bv_val,
2616 sub->sa_any[i]->bv_val,
2617 sub->sa_any[i]->bv_len );
2625 left.bv_val += sub->sa_any[i]->bv_len;
2626 left.bv_len -= sub->sa_any[i]->bv_len;
2627 inlen -= sub->sa_any[i]->bv_len;
2633 return LDAP_SUCCESS;
2636 /* Index generation function */
2637 int caseExactIA5Indexer(
2642 struct berval *prefix,
2643 struct berval **values,
2644 struct berval ***keysp )
2648 struct berval **keys;
2649 HASH_CONTEXT HASHcontext;
2650 unsigned char HASHdigest[HASH_BYTES];
2651 struct berval digest;
2652 digest.bv_val = HASHdigest;
2653 digest.bv_len = sizeof(HASHdigest);
2655 /* we should have at least one value at this point */
2656 assert( values != NULL && values[0] != NULL );
2658 for( i=0; values[i] != NULL; i++ ) {
2659 /* just count them */
2662 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2664 slen = strlen( syntax->ssyn_oid );
2665 mlen = strlen( mr->smr_oid );
2667 for( i=0; values[i] != NULL; i++ ) {
2668 struct berval *value = values[i];
2670 HASH_Init( &HASHcontext );
2671 if( prefix != NULL && prefix->bv_len > 0 ) {
2672 HASH_Update( &HASHcontext,
2673 prefix->bv_val, prefix->bv_len );
2675 HASH_Update( &HASHcontext,
2676 syntax->ssyn_oid, slen );
2677 HASH_Update( &HASHcontext,
2678 mr->smr_oid, mlen );
2679 HASH_Update( &HASHcontext,
2680 value->bv_val, value->bv_len );
2681 HASH_Final( HASHdigest, &HASHcontext );
2683 keys[i] = ber_bvdup( &digest );
2688 return LDAP_SUCCESS;
2691 /* Index generation function */
2692 int caseExactIA5Filter(
2697 struct berval *prefix,
2699 struct berval ***keysp )
2702 struct berval **keys;
2703 HASH_CONTEXT HASHcontext;
2704 unsigned char HASHdigest[HASH_BYTES];
2705 struct berval *value;
2706 struct berval digest;
2707 digest.bv_val = HASHdigest;
2708 digest.bv_len = sizeof(HASHdigest);
2710 slen = strlen( syntax->ssyn_oid );
2711 mlen = strlen( mr->smr_oid );
2713 value = (struct berval *) assertValue;
2715 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2717 HASH_Init( &HASHcontext );
2718 if( prefix != NULL && prefix->bv_len > 0 ) {
2719 HASH_Update( &HASHcontext,
2720 prefix->bv_val, prefix->bv_len );
2722 HASH_Update( &HASHcontext,
2723 syntax->ssyn_oid, slen );
2724 HASH_Update( &HASHcontext,
2725 mr->smr_oid, mlen );
2726 HASH_Update( &HASHcontext,
2727 value->bv_val, value->bv_len );
2728 HASH_Final( HASHdigest, &HASHcontext );
2730 keys[0] = ber_bvdup( &digest );
2734 return LDAP_SUCCESS;
2737 /* Substrings Index generation function */
2738 int caseExactIA5SubstringsIndexer(
2743 struct berval *prefix,
2744 struct berval **values,
2745 struct berval ***keysp )
2749 struct berval **keys;
2750 HASH_CONTEXT HASHcontext;
2751 unsigned char HASHdigest[HASH_BYTES];
2752 struct berval digest;
2753 digest.bv_val = HASHdigest;
2754 digest.bv_len = sizeof(HASHdigest);
2756 /* we should have at least one value at this point */
2757 assert( values != NULL && values[0] != NULL );
2760 for( i=0; values[i] != NULL; i++ ) {
2761 /* count number of indices to generate */
2762 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2766 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2767 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2768 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2769 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2771 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2775 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2776 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2777 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2781 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2782 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2783 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2784 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2786 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2792 /* no keys to generate */
2794 return LDAP_SUCCESS;
2797 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2799 slen = strlen( syntax->ssyn_oid );
2800 mlen = strlen( mr->smr_oid );
2803 for( i=0; values[i] != NULL; i++ ) {
2805 struct berval *value;
2808 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2810 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2811 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2813 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2814 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2816 for( j=0; j<max; j++ ) {
2817 HASH_Init( &HASHcontext );
2818 if( prefix != NULL && prefix->bv_len > 0 ) {
2819 HASH_Update( &HASHcontext,
2820 prefix->bv_val, prefix->bv_len );
2823 HASH_Update( &HASHcontext,
2824 &pre, sizeof( pre ) );
2825 HASH_Update( &HASHcontext,
2826 syntax->ssyn_oid, slen );
2827 HASH_Update( &HASHcontext,
2828 mr->smr_oid, mlen );
2829 HASH_Update( &HASHcontext,
2831 SLAP_INDEX_SUBSTR_MAXLEN );
2832 HASH_Final( HASHdigest, &HASHcontext );
2834 keys[nkeys++] = ber_bvdup( &digest );
2838 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2839 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2841 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2844 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2845 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2846 HASH_Init( &HASHcontext );
2847 if( prefix != NULL && prefix->bv_len > 0 ) {
2848 HASH_Update( &HASHcontext,
2849 prefix->bv_val, prefix->bv_len );
2851 HASH_Update( &HASHcontext,
2852 &pre, sizeof( pre ) );
2853 HASH_Update( &HASHcontext,
2854 syntax->ssyn_oid, slen );
2855 HASH_Update( &HASHcontext,
2856 mr->smr_oid, mlen );
2857 HASH_Update( &HASHcontext,
2859 HASH_Final( HASHdigest, &HASHcontext );
2861 keys[nkeys++] = ber_bvdup( &digest );
2864 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2865 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2866 HASH_Init( &HASHcontext );
2867 if( prefix != NULL && prefix->bv_len > 0 ) {
2868 HASH_Update( &HASHcontext,
2869 prefix->bv_val, prefix->bv_len );
2871 HASH_Update( &HASHcontext,
2872 &pre, sizeof( pre ) );
2873 HASH_Update( &HASHcontext,
2874 syntax->ssyn_oid, slen );
2875 HASH_Update( &HASHcontext,
2876 mr->smr_oid, mlen );
2877 HASH_Update( &HASHcontext,
2878 &value->bv_val[value->bv_len-j], j );
2879 HASH_Final( HASHdigest, &HASHcontext );
2881 keys[nkeys++] = ber_bvdup( &digest );
2895 return LDAP_SUCCESS;
2898 int caseExactIA5SubstringsFilter(
2903 struct berval *prefix,
2905 struct berval ***keysp )
2907 SubstringsAssertion *sa = assertValue;
2909 ber_len_t nkeys = 0;
2910 size_t slen, mlen, klen;
2911 struct berval **keys;
2912 HASH_CONTEXT HASHcontext;
2913 unsigned char HASHdigest[HASH_BYTES];
2914 struct berval *value;
2915 struct berval digest;
2917 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2918 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2923 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2925 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2926 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2927 /* don't bother accounting for stepping */
2928 nkeys += sa->sa_any[i]->bv_len -
2929 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2934 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2935 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2942 return LDAP_SUCCESS;
2945 digest.bv_val = HASHdigest;
2946 digest.bv_len = sizeof(HASHdigest);
2948 slen = strlen( syntax->ssyn_oid );
2949 mlen = strlen( mr->smr_oid );
2951 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2954 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2955 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2957 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2958 value = sa->sa_initial;
2960 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2961 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2963 HASH_Init( &HASHcontext );
2964 if( prefix != NULL && prefix->bv_len > 0 ) {
2965 HASH_Update( &HASHcontext,
2966 prefix->bv_val, prefix->bv_len );
2968 HASH_Update( &HASHcontext,
2969 &pre, sizeof( pre ) );
2970 HASH_Update( &HASHcontext,
2971 syntax->ssyn_oid, slen );
2972 HASH_Update( &HASHcontext,
2973 mr->smr_oid, mlen );
2974 HASH_Update( &HASHcontext,
2975 value->bv_val, klen );
2976 HASH_Final( HASHdigest, &HASHcontext );
2978 keys[nkeys++] = ber_bvdup( &digest );
2981 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2983 pre = SLAP_INDEX_SUBSTR_PREFIX;
2984 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2986 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2987 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2991 value = sa->sa_any[i];
2994 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2995 j += SLAP_INDEX_SUBSTR_STEP )
2997 HASH_Init( &HASHcontext );
2998 if( prefix != NULL && prefix->bv_len > 0 ) {
2999 HASH_Update( &HASHcontext,
3000 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,
3009 &value->bv_val[j], klen );
3010 HASH_Final( HASHdigest, &HASHcontext );
3012 keys[nkeys++] = ber_bvdup( &digest );
3017 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3018 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3020 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3021 value = sa->sa_final;
3023 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3024 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3026 HASH_Init( &HASHcontext );
3027 if( prefix != NULL && prefix->bv_len > 0 ) {
3028 HASH_Update( &HASHcontext,
3029 prefix->bv_val, prefix->bv_len );
3031 HASH_Update( &HASHcontext,
3032 &pre, sizeof( pre ) );
3033 HASH_Update( &HASHcontext,
3034 syntax->ssyn_oid, slen );
3035 HASH_Update( &HASHcontext,
3036 mr->smr_oid, mlen );
3037 HASH_Update( &HASHcontext,
3038 &value->bv_val[value->bv_len-klen], klen );
3039 HASH_Final( HASHdigest, &HASHcontext );
3041 keys[nkeys++] = ber_bvdup( &digest );
3052 return LDAP_SUCCESS;
3061 struct berval *value,
3062 void *assertedValue )
3064 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3066 if( match == 0 && value->bv_len ) {
3067 match = strncasecmp( value->bv_val,
3068 ((struct berval *) assertedValue)->bv_val,
3073 return LDAP_SUCCESS;
3077 caseIgnoreIA5SubstringsMatch(
3082 struct berval *value,
3083 void *assertedValue )
3086 SubstringsAssertion *sub = assertedValue;
3087 struct berval left = *value;
3091 /* Add up asserted input length */
3092 if( sub->sa_initial ) {
3093 inlen += sub->sa_initial->bv_len;
3096 for(i=0; sub->sa_any[i] != NULL; i++) {
3097 inlen += sub->sa_any[i]->bv_len;
3100 if( sub->sa_final ) {
3101 inlen += sub->sa_final->bv_len;
3104 if( sub->sa_initial ) {
3105 if( inlen > left.bv_len ) {
3110 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3111 sub->sa_initial->bv_len );
3117 left.bv_val += sub->sa_initial->bv_len;
3118 left.bv_len -= sub->sa_initial->bv_len;
3119 inlen -= sub->sa_initial->bv_len;
3122 if( sub->sa_final ) {
3123 if( inlen > left.bv_len ) {
3128 match = strncasecmp( sub->sa_final->bv_val,
3129 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3130 sub->sa_final->bv_len );
3136 left.bv_len -= sub->sa_final->bv_len;
3137 inlen -= sub->sa_final->bv_len;
3141 for(i=0; sub->sa_any[i]; i++) {
3146 if( inlen > left.bv_len ) {
3147 /* not enough length */
3152 if( sub->sa_any[i]->bv_len == 0 ) {
3156 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3163 idx = p - left.bv_val;
3164 assert( idx < left.bv_len );
3166 if( idx >= left.bv_len ) {
3167 /* this shouldn't happen */
3174 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3175 /* not enough left */
3180 match = strncasecmp( left.bv_val,
3181 sub->sa_any[i]->bv_val,
3182 sub->sa_any[i]->bv_len );
3191 left.bv_val += sub->sa_any[i]->bv_len;
3192 left.bv_len -= sub->sa_any[i]->bv_len;
3193 inlen -= sub->sa_any[i]->bv_len;
3199 return LDAP_SUCCESS;
3202 /* Index generation function */
3203 int caseIgnoreIA5Indexer(
3208 struct berval *prefix,
3209 struct berval **values,
3210 struct berval ***keysp )
3214 struct berval **keys;
3215 HASH_CONTEXT HASHcontext;
3216 unsigned char HASHdigest[HASH_BYTES];
3217 struct berval digest;
3218 digest.bv_val = HASHdigest;
3219 digest.bv_len = sizeof(HASHdigest);
3221 /* we should have at least one value at this point */
3222 assert( values != NULL && values[0] != NULL );
3224 for( i=0; values[i] != NULL; i++ ) {
3225 /* just count them */
3228 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3230 slen = strlen( syntax->ssyn_oid );
3231 mlen = strlen( mr->smr_oid );
3233 for( i=0; values[i] != NULL; i++ ) {
3234 struct berval *value = ber_bvdup( values[i] );
3235 ldap_pvt_str2upper( value->bv_val );
3237 HASH_Init( &HASHcontext );
3238 if( prefix != NULL && prefix->bv_len > 0 ) {
3239 HASH_Update( &HASHcontext,
3240 prefix->bv_val, prefix->bv_len );
3242 HASH_Update( &HASHcontext,
3243 syntax->ssyn_oid, slen );
3244 HASH_Update( &HASHcontext,
3245 mr->smr_oid, mlen );
3246 HASH_Update( &HASHcontext,
3247 value->bv_val, value->bv_len );
3248 HASH_Final( HASHdigest, &HASHcontext );
3250 ber_bvfree( value );
3252 keys[i] = ber_bvdup( &digest );
3257 return LDAP_SUCCESS;
3260 /* Index generation function */
3261 int caseIgnoreIA5Filter(
3266 struct berval *prefix,
3268 struct berval ***keysp )
3271 struct berval **keys;
3272 HASH_CONTEXT HASHcontext;
3273 unsigned char HASHdigest[HASH_BYTES];
3274 struct berval *value;
3275 struct berval digest;
3276 digest.bv_val = HASHdigest;
3277 digest.bv_len = sizeof(HASHdigest);
3279 slen = strlen( syntax->ssyn_oid );
3280 mlen = strlen( mr->smr_oid );
3282 value = ber_bvdup( (struct berval *) assertValue );
3283 ldap_pvt_str2upper( value->bv_val );
3285 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3287 HASH_Init( &HASHcontext );
3288 if( prefix != NULL && prefix->bv_len > 0 ) {
3289 HASH_Update( &HASHcontext,
3290 prefix->bv_val, prefix->bv_len );
3292 HASH_Update( &HASHcontext,
3293 syntax->ssyn_oid, slen );
3294 HASH_Update( &HASHcontext,
3295 mr->smr_oid, mlen );
3296 HASH_Update( &HASHcontext,
3297 value->bv_val, value->bv_len );
3298 HASH_Final( HASHdigest, &HASHcontext );
3300 keys[0] = ber_bvdup( &digest );
3303 ber_bvfree( value );
3307 return LDAP_SUCCESS;
3310 /* Substrings Index generation function */
3311 int caseIgnoreIA5SubstringsIndexer(
3316 struct berval *prefix,
3317 struct berval **values,
3318 struct berval ***keysp )
3322 struct berval **keys;
3323 HASH_CONTEXT HASHcontext;
3324 unsigned char HASHdigest[HASH_BYTES];
3325 struct berval digest;
3326 digest.bv_val = HASHdigest;
3327 digest.bv_len = sizeof(HASHdigest);
3329 /* we should have at least one value at this point */
3330 assert( values != NULL && values[0] != NULL );
3333 for( i=0; values[i] != NULL; i++ ) {
3334 /* count number of indices to generate */
3335 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3339 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3340 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3341 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3342 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3344 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3348 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3349 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3350 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3354 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3355 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3356 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3357 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3359 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3365 /* no keys to generate */
3367 return LDAP_SUCCESS;
3370 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3372 slen = strlen( syntax->ssyn_oid );
3373 mlen = strlen( mr->smr_oid );
3376 for( i=0; values[i] != NULL; i++ ) {
3378 struct berval *value;
3380 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3382 value = ber_bvdup( values[i] );
3383 ldap_pvt_str2upper( value->bv_val );
3385 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3386 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3388 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3389 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3391 for( j=0; j<max; j++ ) {
3392 HASH_Init( &HASHcontext );
3393 if( prefix != NULL && prefix->bv_len > 0 ) {
3394 HASH_Update( &HASHcontext,
3395 prefix->bv_val, prefix->bv_len );
3398 HASH_Update( &HASHcontext,
3399 &pre, sizeof( pre ) );
3400 HASH_Update( &HASHcontext,
3401 syntax->ssyn_oid, slen );
3402 HASH_Update( &HASHcontext,
3403 mr->smr_oid, mlen );
3404 HASH_Update( &HASHcontext,
3406 SLAP_INDEX_SUBSTR_MAXLEN );
3407 HASH_Final( HASHdigest, &HASHcontext );
3409 keys[nkeys++] = ber_bvdup( &digest );
3413 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3414 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3416 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3419 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3420 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3421 HASH_Init( &HASHcontext );
3422 if( prefix != NULL && prefix->bv_len > 0 ) {
3423 HASH_Update( &HASHcontext,
3424 prefix->bv_val, prefix->bv_len );
3426 HASH_Update( &HASHcontext,
3427 &pre, sizeof( pre ) );
3428 HASH_Update( &HASHcontext,
3429 syntax->ssyn_oid, slen );
3430 HASH_Update( &HASHcontext,
3431 mr->smr_oid, mlen );
3432 HASH_Update( &HASHcontext,
3434 HASH_Final( HASHdigest, &HASHcontext );
3436 keys[nkeys++] = ber_bvdup( &digest );
3439 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3440 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3441 HASH_Init( &HASHcontext );
3442 if( prefix != NULL && prefix->bv_len > 0 ) {
3443 HASH_Update( &HASHcontext,
3444 prefix->bv_val, prefix->bv_len );
3446 HASH_Update( &HASHcontext,
3447 &pre, sizeof( pre ) );
3448 HASH_Update( &HASHcontext,
3449 syntax->ssyn_oid, slen );
3450 HASH_Update( &HASHcontext,
3451 mr->smr_oid, mlen );
3452 HASH_Update( &HASHcontext,
3453 &value->bv_val[value->bv_len-j], j );
3454 HASH_Final( HASHdigest, &HASHcontext );
3456 keys[nkeys++] = ber_bvdup( &digest );
3461 ber_bvfree( value );
3472 return LDAP_SUCCESS;
3475 int caseIgnoreIA5SubstringsFilter(
3480 struct berval *prefix,
3482 struct berval ***keysp )
3484 SubstringsAssertion *sa = assertValue;
3486 ber_len_t nkeys = 0;
3487 size_t slen, mlen, klen;
3488 struct berval **keys;
3489 HASH_CONTEXT HASHcontext;
3490 unsigned char HASHdigest[HASH_BYTES];
3491 struct berval *value;
3492 struct berval digest;
3494 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3495 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3500 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3502 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3503 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3504 /* don't bother accounting for stepping */
3505 nkeys += sa->sa_any[i]->bv_len -
3506 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3511 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3512 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3519 return LDAP_SUCCESS;
3522 digest.bv_val = HASHdigest;
3523 digest.bv_len = sizeof(HASHdigest);
3525 slen = strlen( syntax->ssyn_oid );
3526 mlen = strlen( mr->smr_oid );
3528 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3531 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3532 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3534 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3535 value = ber_bvdup( sa->sa_initial );
3536 ldap_pvt_str2upper( value->bv_val );
3538 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3539 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3541 HASH_Init( &HASHcontext );
3542 if( prefix != NULL && prefix->bv_len > 0 ) {
3543 HASH_Update( &HASHcontext,
3544 prefix->bv_val, prefix->bv_len );
3546 HASH_Update( &HASHcontext,
3547 &pre, sizeof( pre ) );
3548 HASH_Update( &HASHcontext,
3549 syntax->ssyn_oid, slen );
3550 HASH_Update( &HASHcontext,
3551 mr->smr_oid, mlen );
3552 HASH_Update( &HASHcontext,
3553 value->bv_val, klen );
3554 HASH_Final( HASHdigest, &HASHcontext );
3556 ber_bvfree( value );
3557 keys[nkeys++] = ber_bvdup( &digest );
3560 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3562 pre = SLAP_INDEX_SUBSTR_PREFIX;
3563 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3565 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3566 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3570 value = ber_bvdup( sa->sa_any[i] );
3571 ldap_pvt_str2upper( value->bv_val );
3574 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3575 j += SLAP_INDEX_SUBSTR_STEP )
3577 HASH_Init( &HASHcontext );
3578 if( prefix != NULL && prefix->bv_len > 0 ) {
3579 HASH_Update( &HASHcontext,
3580 prefix->bv_val, prefix->bv_len );
3582 HASH_Update( &HASHcontext,
3583 &pre, sizeof( pre ) );
3584 HASH_Update( &HASHcontext,
3585 syntax->ssyn_oid, slen );
3586 HASH_Update( &HASHcontext,
3587 mr->smr_oid, mlen );
3588 HASH_Update( &HASHcontext,
3589 &value->bv_val[j], klen );
3590 HASH_Final( HASHdigest, &HASHcontext );
3592 keys[nkeys++] = ber_bvdup( &digest );
3595 ber_bvfree( value );
3599 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3600 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3602 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3603 value = ber_bvdup( sa->sa_final );
3604 ldap_pvt_str2upper( value->bv_val );
3606 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3607 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3609 HASH_Init( &HASHcontext );
3610 if( prefix != NULL && prefix->bv_len > 0 ) {
3611 HASH_Update( &HASHcontext,
3612 prefix->bv_val, prefix->bv_len );
3614 HASH_Update( &HASHcontext,
3615 &pre, sizeof( pre ) );
3616 HASH_Update( &HASHcontext,
3617 syntax->ssyn_oid, slen );
3618 HASH_Update( &HASHcontext,
3619 mr->smr_oid, mlen );
3620 HASH_Update( &HASHcontext,
3621 &value->bv_val[value->bv_len-klen], klen );
3622 HASH_Final( HASHdigest, &HASHcontext );
3624 ber_bvfree( value );
3625 keys[nkeys++] = ber_bvdup( &digest );
3636 return LDAP_SUCCESS;
3640 numericStringValidate(
3646 for(i=0; i < in->bv_len; i++) {
3647 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3648 return LDAP_INVALID_SYNTAX;
3652 return LDAP_SUCCESS;
3656 numericStringNormalize(
3659 struct berval **normalized )
3661 /* removal all spaces */
3662 struct berval *newval;
3665 newval = ch_malloc( sizeof( struct berval ) );
3666 newval->bv_val = ch_malloc( val->bv_len + 1 );
3672 if ( ASCII_SPACE( *p ) ) {
3673 /* Ignore whitespace */
3680 assert( newval->bv_val <= p );
3683 /* null terminate */
3686 newval->bv_len = q - newval->bv_val;
3687 *normalized = newval;
3689 return LDAP_SUCCESS;
3693 objectIdentifierFirstComponentMatch(
3698 struct berval *value,
3699 void *assertedValue )
3701 int rc = LDAP_SUCCESS;
3703 struct berval *asserted = (struct berval *) assertedValue;
3707 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3708 return LDAP_INVALID_SYNTAX;
3711 /* trim leading white space */
3712 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3716 /* grab next word */
3717 oid.bv_val = &value->bv_val[i];
3718 oid.bv_len = value->bv_len - i;
3719 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3724 /* insert attributeTypes, objectclass check here */
3725 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3726 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3729 char *stored = ch_malloc( oid.bv_len + 1 );
3730 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3731 stored[oid.bv_len] = '\0';
3733 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3734 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3735 MatchingRule *stored_mr = mr_find( stored );
3737 if( asserted_mr == NULL ) {
3738 rc = SLAPD_COMPARE_UNDEFINED;
3740 match = asserted_mr != stored_mr;
3743 } else if ( !strcmp( syntax->ssyn_oid,
3744 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3746 AttributeType *asserted_at = at_find( asserted->bv_val );
3747 AttributeType *stored_at = at_find( stored );
3749 if( asserted_at == NULL ) {
3750 rc = SLAPD_COMPARE_UNDEFINED;
3752 match = asserted_at != stored_at;
3755 } else if ( !strcmp( syntax->ssyn_oid,
3756 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3758 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3759 ObjectClass *stored_oc = oc_find( stored );
3761 if( asserted_oc == NULL ) {
3762 rc = SLAPD_COMPARE_UNDEFINED;
3764 match = asserted_oc != stored_oc;
3772 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3773 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3774 match, value->bv_val, asserted->bv_val ));
3776 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3777 "%d\n\t\"%s\"\n\t\"%s\"\n",
3778 match, value->bv_val, asserted->bv_val );
3782 if( rc == LDAP_SUCCESS ) *matchp = match;
3787 check_time_syntax (struct berval *val,
3791 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3792 static int mdays[2][12] = {
3793 /* non-leap years */
3794 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3796 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3799 int part, c, tzoffset, leapyear = 0 ;
3801 if( val->bv_len == 0 ) {
3802 return LDAP_INVALID_SYNTAX;
3805 p = (char *)val->bv_val;
3806 e = p + val->bv_len;
3808 /* Ignore initial whitespace */
3809 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3813 if (e - p < 13 - (2 * start)) {
3814 return LDAP_INVALID_SYNTAX;
3817 for (part = 0; part < 9; part++) {
3821 for (part = start; part < 7; part++) {
3823 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3830 return LDAP_INVALID_SYNTAX;
3832 if (c < 0 || c > 9) {
3833 return LDAP_INVALID_SYNTAX;
3839 return LDAP_INVALID_SYNTAX;
3841 if (c < 0 || c > 9) {
3842 return LDAP_INVALID_SYNTAX;
3847 if (part == 2 || part == 3) {
3850 if (parts[part] < 0) {
3851 return LDAP_INVALID_SYNTAX;
3853 if (parts[part] > ceiling[part]) {
3854 return LDAP_INVALID_SYNTAX;
3858 /* leapyear check for the Gregorian calendar (year>1581) */
3859 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3860 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3865 if (parts[3] > mdays[leapyear][parts[2]]) {
3866 return LDAP_INVALID_SYNTAX;
3871 tzoffset = 0; /* UTC */
3872 } else if (c != '+' && c != '-') {
3873 return LDAP_INVALID_SYNTAX;
3877 } else /* c == '+' */ {
3882 return LDAP_INVALID_SYNTAX;
3885 for (part = 7; part < 9; part++) {
3887 if (c < 0 || c > 9) {
3888 return LDAP_INVALID_SYNTAX;
3893 if (c < 0 || c > 9) {
3894 return LDAP_INVALID_SYNTAX;
3898 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3899 return LDAP_INVALID_SYNTAX;
3904 /* Ignore trailing whitespace */
3905 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3909 return LDAP_INVALID_SYNTAX;
3912 switch ( tzoffset ) {
3913 case -1: /* negativ offset to UTC, ie west of Greenwich */
3914 parts[4] += parts[7];
3915 parts[5] += parts[8];
3916 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3920 c = mdays[leapyear][parts[2]];
3922 if (parts[part] > c) {
3923 parts[part] -= c + 1;
3928 case 1: /* positive offset to UTC, ie east of Greenwich */
3929 parts[4] -= parts[7];
3930 parts[5] -= parts[8];
3931 for (part = 6; --part > 0; ) {
3935 /* first arg to % needs to be non negativ */
3936 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3938 if (parts[part] < 0) {
3939 parts[part] += c + 1;
3944 case 0: /* already UTC */
3948 return LDAP_SUCCESS;
3955 struct berval **normalized )
3960 rc = check_time_syntax(val, 1, parts);
3961 if (rc != LDAP_SUCCESS) {
3966 out = ch_malloc( sizeof(struct berval) );
3968 return LBER_ERROR_MEMORY;
3971 out->bv_val = ch_malloc( 14 );
3972 if ( out->bv_val == NULL ) {
3974 return LBER_ERROR_MEMORY;
3977 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3978 parts[1], parts[2] + 1, parts[3] + 1,
3979 parts[4], parts[5], parts[6] );
3983 return LDAP_SUCCESS;
3993 return check_time_syntax(in, 1, parts);
3997 generalizedTimeValidate(
4003 return check_time_syntax(in, 0, parts);
4007 generalizedTimeNormalize(
4010 struct berval **normalized )
4015 rc = check_time_syntax(val, 0, parts);
4016 if (rc != LDAP_SUCCESS) {
4021 out = ch_malloc( sizeof(struct berval) );
4023 return LBER_ERROR_MEMORY;
4026 out->bv_val = ch_malloc( 16 );
4027 if ( out->bv_val == NULL ) {
4029 return LBER_ERROR_MEMORY;
4032 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4033 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4034 parts[4], parts[5], parts[6] );
4038 return LDAP_SUCCESS;
4042 nisNetgroupTripleValidate(
4044 struct berval *val )
4049 if ( val->bv_len == 0 ) {
4050 return LDAP_INVALID_SYNTAX;
4053 p = (char *)val->bv_val;
4054 e = p + val->bv_len;
4057 /* syntax does not allow leading white space */
4058 /* Ignore initial whitespace */
4059 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4064 if ( *p != '(' /*')'*/ ) {
4065 return LDAP_INVALID_SYNTAX;
4068 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4072 return LDAP_INVALID_SYNTAX;
4075 } else if ( !ATTR_CHAR( *p ) ) {
4076 return LDAP_INVALID_SYNTAX;
4080 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4081 return LDAP_INVALID_SYNTAX;
4087 /* syntax does not allow trailing white space */
4088 /* Ignore trailing whitespace */
4089 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4095 return LDAP_INVALID_SYNTAX;
4098 return LDAP_SUCCESS;
4102 bootParameterValidate(
4104 struct berval *val )
4108 if ( val->bv_len == 0 ) {
4109 return LDAP_INVALID_SYNTAX;
4112 p = (char *)val->bv_val;
4113 e = p + val->bv_len;
4116 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4117 if ( !ATTR_CHAR( *p ) ) {
4118 return LDAP_INVALID_SYNTAX;
4123 return LDAP_INVALID_SYNTAX;
4127 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4128 if ( !ATTR_CHAR( *p ) ) {
4129 return LDAP_INVALID_SYNTAX;
4134 return LDAP_INVALID_SYNTAX;
4138 for ( p++; p < e; p++ ) {
4139 if ( !ATTR_CHAR( *p ) ) {
4140 return LDAP_INVALID_SYNTAX;
4144 return LDAP_SUCCESS;
4147 struct syntax_defs_rec {
4150 slap_syntax_validate_func *sd_validate;
4151 slap_syntax_transform_func *sd_normalize;
4152 slap_syntax_transform_func *sd_pretty;
4153 #ifdef SLAPD_BINARY_CONVERSION
4154 slap_syntax_transform_func *sd_ber2str;
4155 slap_syntax_transform_func *sd_str2ber;
4159 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4160 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4162 struct syntax_defs_rec syntax_defs[] = {
4163 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4164 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4166 0, NULL, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4168 0, NULL, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4170 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4172 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4174 0, bitStringValidate, NULL, NULL },
4175 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4176 0, booleanValidate, NULL, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4178 X_BINARY X_NOT_H_R ")",
4179 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4181 X_BINARY X_NOT_H_R ")",
4182 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4184 X_BINARY X_NOT_H_R ")",
4185 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4187 0, countryStringValidate, IA5StringNormalize, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4189 0, dnValidate, dnNormalize, dnPretty},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4191 0, NULL, NULL, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4193 0, NULL, NULL, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4195 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4197 0, NULL, NULL, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4199 0, NULL, NULL, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4201 0, NULL, NULL, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4203 0, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4205 0, NULL, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4207 0, printablesStringValidate, IA5StringNormalize, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4209 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4211 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4213 0, NULL, NULL, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4215 0, IA5StringValidate, IA5StringNormalize, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4217 0, integerValidate, integerNormalize, integerPretty},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4219 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4221 0, NULL, NULL, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4223 0, NULL, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4225 0, NULL, NULL, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4227 0, NULL, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4229 0, NULL, NULL, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4231 0, nameUIDValidate, nameUIDNormalize, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4233 0, NULL, NULL, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4235 0, numericStringValidate, numericStringNormalize, NULL},
4236 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4237 0, NULL, NULL, NULL},
4238 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4239 0, oidValidate, NULL, NULL},
4240 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4241 0, IA5StringValidate, IA5StringNormalize, NULL},
4242 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4243 0, blobValidate, NULL, NULL},
4244 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4245 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4246 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4247 0, NULL, NULL, NULL},
4248 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4249 0, NULL, NULL, NULL},
4250 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4251 0, printableStringValidate, IA5StringNormalize, NULL},
4252 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4253 X_BINARY X_NOT_H_R ")",
4254 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4255 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4256 0, printableStringValidate, IA5StringNormalize, NULL},
4257 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4258 0, NULL, NULL, NULL},
4259 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4260 0, printableStringValidate, IA5StringNormalize, NULL},
4261 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4262 0, utcTimeValidate, utcTimeNormalize, NULL},
4263 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4264 0, NULL, NULL, NULL},
4265 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4266 0, NULL, NULL, NULL},
4267 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4268 0, NULL, NULL, NULL},
4269 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4270 0, NULL, NULL, NULL},
4271 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4272 0, NULL, NULL, NULL},
4274 /* RFC 2307 NIS Syntaxes */
4275 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4276 0, nisNetgroupTripleValidate, NULL, NULL},
4277 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4278 0, bootParameterValidate, NULL, NULL},
4280 /* OpenLDAP Experimental Syntaxes */
4281 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4282 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4284 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4285 0, NULL, NULL, NULL},
4287 /* OpenLDAP Void Syntax */
4288 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4289 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4290 {NULL, 0, NULL, NULL, NULL}
4293 struct mrule_defs_rec {
4295 slap_mask_t mrd_usage;
4296 slap_mr_convert_func * mrd_convert;
4297 slap_mr_normalize_func * mrd_normalize;
4298 slap_mr_match_func * mrd_match;
4299 slap_mr_indexer_func * mrd_indexer;
4300 slap_mr_filter_func * mrd_filter;
4302 char * mrd_associated;
4306 * Other matching rules in X.520 that we do not use (yet):
4308 * 2.5.13.9 numericStringOrderingMatch
4309 * 2.5.13.15 integerOrderingMatch
4310 * 2.5.13.18 octetStringOrderingMatch
4311 * 2.5.13.19 octetStringSubstringsMatch
4312 * 2.5.13.25 uTCTimeMatch
4313 * 2.5.13.26 uTCTimeOrderingMatch
4314 * 2.5.13.31 directoryStringFirstComponentMatch
4315 * 2.5.13.32 wordMatch
4316 * 2.5.13.33 keywordMatch
4317 * 2.5.13.34 certificateExactMatch
4318 * 2.5.13.35 certificateMatch
4319 * 2.5.13.36 certificatePairExactMatch
4320 * 2.5.13.37 certificatePairMatch
4321 * 2.5.13.38 certificateListExactMatch
4322 * 2.5.13.39 certificateListMatch
4323 * 2.5.13.40 algorithmIdentifierMatch
4324 * 2.5.13.41 storedPrefixMatch
4325 * 2.5.13.42 attributeCertificateMatch
4326 * 2.5.13.43 readerAndKeyIDMatch
4327 * 2.5.13.44 attributeIntegrityMatch
4330 struct mrule_defs_rec mrule_defs[] = {
4332 * EQUALITY matching rules must be listed after associated APPROX
4333 * matching rules. So, we list all APPROX matching rules first.
4335 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4336 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4337 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4339 directoryStringApproxMatch,
4340 directoryStringApproxIndexer,
4341 directoryStringApproxFilter,
4344 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4345 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4346 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4348 IA5StringApproxMatch,
4349 IA5StringApproxIndexer,
4350 IA5StringApproxFilter,
4354 * Other matching rules
4357 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4358 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4359 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4361 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4364 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4365 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4366 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4368 dnMatch, dnIndexer, dnFilter,
4371 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4372 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4373 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4375 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4376 directoryStringApproxMatchOID },
4378 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4379 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4382 caseIgnoreOrderingMatch, NULL, NULL,
4385 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4386 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4387 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4389 caseIgnoreSubstringsMatch,
4390 caseIgnoreSubstringsIndexer,
4391 caseIgnoreSubstringsFilter,
4394 {"( 2.5.13.5 NAME 'caseExactMatch' "
4395 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4396 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4398 caseExactMatch, caseExactIndexer, caseExactFilter,
4399 directoryStringApproxMatchOID },
4401 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4402 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4405 caseExactOrderingMatch, NULL, NULL,
4408 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4409 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4410 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4412 caseExactSubstringsMatch,
4413 caseExactSubstringsIndexer,
4414 caseExactSubstringsFilter,
4417 {"( 2.5.13.8 NAME 'numericStringMatch' "
4418 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4419 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4422 caseIgnoreIA5Indexer,
4423 caseIgnoreIA5Filter,
4426 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4427 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4428 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4430 caseIgnoreIA5SubstringsMatch,
4431 caseIgnoreIA5SubstringsIndexer,
4432 caseIgnoreIA5SubstringsFilter,
4435 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4436 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4437 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4439 caseIgnoreListMatch, NULL, NULL,
4442 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4443 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4444 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4446 caseIgnoreListSubstringsMatch, NULL, NULL,
4449 {"( 2.5.13.13 NAME 'booleanMatch' "
4450 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4451 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4453 booleanMatch, NULL, NULL,
4456 {"( 2.5.13.14 NAME 'integerMatch' "
4457 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4458 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4460 integerMatch, integerIndexer, integerFilter,
4463 {"( 2.5.13.16 NAME 'bitStringMatch' "
4464 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4465 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4467 bitStringMatch, NULL, NULL,
4470 {"( 2.5.13.17 NAME 'octetStringMatch' "
4471 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4472 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4474 octetStringMatch, octetStringIndexer, octetStringFilter,
4477 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4478 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4479 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4481 telephoneNumberMatch,
4482 telephoneNumberIndexer,
4483 telephoneNumberFilter,
4486 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4487 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4488 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4490 telephoneNumberSubstringsMatch,
4491 telephoneNumberSubstringsIndexer,
4492 telephoneNumberSubstringsFilter,
4495 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4496 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4497 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4502 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4503 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4504 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4506 uniqueMemberMatch, NULL, NULL,
4509 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4510 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4511 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4513 protocolInformationMatch, NULL, NULL,
4516 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4517 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4518 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4520 generalizedTimeMatch, NULL, NULL,
4523 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4524 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4527 generalizedTimeOrderingMatch, NULL, NULL,
4530 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4531 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4532 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4534 integerFirstComponentMatch, NULL, NULL,
4537 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4538 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4539 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4541 objectIdentifierFirstComponentMatch, NULL, NULL,
4544 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4545 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4546 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4548 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4549 IA5StringApproxMatchOID },
4551 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4552 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4553 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4555 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4556 IA5StringApproxMatchOID },
4558 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4559 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4562 caseIgnoreIA5SubstringsMatch,
4563 caseIgnoreIA5SubstringsIndexer,
4564 caseIgnoreIA5SubstringsFilter,
4567 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4568 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4571 caseExactIA5SubstringsMatch,
4572 caseExactIA5SubstringsIndexer,
4573 caseExactIA5SubstringsFilter,
4576 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4577 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4580 authPasswordMatch, NULL, NULL,
4583 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4584 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4587 OpenLDAPaciMatch, NULL, NULL,
4590 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4599 /* we should only be called once (from main) */
4600 assert( schema_init_done == 0 );
4602 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4603 res = register_syntax( syntax_defs[i].sd_desc,
4604 syntax_defs[i].sd_flags,
4605 syntax_defs[i].sd_validate,
4606 syntax_defs[i].sd_normalize,
4607 syntax_defs[i].sd_pretty
4608 #ifdef SLAPD_BINARY_CONVERSION
4610 syntax_defs[i].sd_ber2str,
4611 syntax_defs[i].sd_str2ber
4616 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4617 syntax_defs[i].sd_desc );
4622 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4623 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4625 "schema_init: Ingoring unusable matching rule %s\n",
4626 mrule_defs[i].mrd_desc );
4630 res = register_matching_rule(
4631 mrule_defs[i].mrd_desc,
4632 mrule_defs[i].mrd_usage,
4633 mrule_defs[i].mrd_convert,
4634 mrule_defs[i].mrd_normalize,
4635 mrule_defs[i].mrd_match,
4636 mrule_defs[i].mrd_indexer,
4637 mrule_defs[i].mrd_filter,
4638 mrule_defs[i].mrd_associated );
4642 "schema_init: Error registering matching rule %s\n",
4643 mrule_defs[i].mrd_desc );
4647 schema_init_done = 1;
4648 return LDAP_SUCCESS;