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,
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 )
2360 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2362 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2363 return LDAP_INVALID_SYNTAX;
2365 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2366 return LDAP_INVALID_SYNTAX;
2369 return LDAP_SUCCESS;
2373 printableStringValidate(
2375 struct berval *val )
2379 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2381 for(i=0; i < val->bv_len; i++) {
2382 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2383 return LDAP_INVALID_SYNTAX;
2387 return LDAP_SUCCESS;
2391 printablesStringValidate(
2393 struct berval *val )
2397 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2399 for(i=0; i < val->bv_len; i++) {
2400 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2401 return LDAP_INVALID_SYNTAX;
2405 return LDAP_SUCCESS;
2411 struct berval *val )
2415 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2417 for(i=0; i < val->bv_len; i++) {
2418 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2421 return LDAP_SUCCESS;
2428 struct berval **normalized )
2430 struct berval *newval;
2433 newval = ch_malloc( sizeof( struct berval ) );
2437 /* Ignore initial whitespace */
2438 while ( ASCII_SPACE( *p ) ) {
2444 return LDAP_INVALID_SYNTAX;
2447 newval->bv_val = ch_strdup( p );
2448 p = q = newval->bv_val;
2451 if ( ASCII_SPACE( *p ) ) {
2454 /* Ignore the extra whitespace */
2455 while ( ASCII_SPACE( *p ) ) {
2463 assert( *newval->bv_val );
2464 assert( newval->bv_val < p );
2467 /* cannot start with a space */
2468 assert( !ASCII_SPACE(*newval->bv_val) );
2471 * If the string ended in space, backup the pointer one
2472 * position. One is enough because the above loop collapsed
2473 * all whitespace to a single space.
2476 if ( ASCII_SPACE( q[-1] ) ) {
2480 /* cannot end with a space */
2481 assert( !ASCII_SPACE( q[-1] ) );
2483 /* null terminate */
2486 newval->bv_len = q - newval->bv_val;
2487 *normalized = newval;
2489 return LDAP_SUCCESS;
2498 struct berval *value,
2499 void *assertedValue )
2501 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2504 match = strncmp( value->bv_val,
2505 ((struct berval *) assertedValue)->bv_val,
2510 return LDAP_SUCCESS;
2514 caseExactIA5SubstringsMatch(
2519 struct berval *value,
2520 void *assertedValue )
2523 SubstringsAssertion *sub = assertedValue;
2524 struct berval left = *value;
2528 /* Add up asserted input length */
2529 if( sub->sa_initial ) {
2530 inlen += sub->sa_initial->bv_len;
2533 for(i=0; sub->sa_any[i] != NULL; i++) {
2534 inlen += sub->sa_any[i]->bv_len;
2537 if( sub->sa_final ) {
2538 inlen += sub->sa_final->bv_len;
2541 if( sub->sa_initial ) {
2542 if( inlen > left.bv_len ) {
2547 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2548 sub->sa_initial->bv_len );
2554 left.bv_val += sub->sa_initial->bv_len;
2555 left.bv_len -= sub->sa_initial->bv_len;
2556 inlen -= sub->sa_initial->bv_len;
2559 if( sub->sa_final ) {
2560 if( inlen > left.bv_len ) {
2565 match = strncmp( sub->sa_final->bv_val,
2566 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2567 sub->sa_final->bv_len );
2573 left.bv_len -= sub->sa_final->bv_len;
2574 inlen -= sub->sa_final->bv_len;
2578 for(i=0; sub->sa_any[i]; i++) {
2583 if( inlen > left.bv_len ) {
2584 /* not enough length */
2589 if( sub->sa_any[i]->bv_len == 0 ) {
2593 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2600 idx = p - left.bv_val;
2601 assert( idx < left.bv_len );
2603 if( idx >= left.bv_len ) {
2604 /* this shouldn't happen */
2611 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2612 /* not enough left */
2617 match = strncmp( left.bv_val,
2618 sub->sa_any[i]->bv_val,
2619 sub->sa_any[i]->bv_len );
2627 left.bv_val += sub->sa_any[i]->bv_len;
2628 left.bv_len -= sub->sa_any[i]->bv_len;
2629 inlen -= sub->sa_any[i]->bv_len;
2635 return LDAP_SUCCESS;
2638 /* Index generation function */
2639 int caseExactIA5Indexer(
2644 struct berval *prefix,
2645 struct berval **values,
2646 struct berval ***keysp )
2650 struct berval **keys;
2651 HASH_CONTEXT HASHcontext;
2652 unsigned char HASHdigest[HASH_BYTES];
2653 struct berval digest;
2654 digest.bv_val = HASHdigest;
2655 digest.bv_len = sizeof(HASHdigest);
2657 /* we should have at least one value at this point */
2658 assert( values != NULL && values[0] != NULL );
2660 for( i=0; values[i] != NULL; i++ ) {
2661 /* just count them */
2664 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2666 slen = strlen( syntax->ssyn_oid );
2667 mlen = strlen( mr->smr_oid );
2669 for( i=0; values[i] != NULL; i++ ) {
2670 struct berval *value = values[i];
2672 HASH_Init( &HASHcontext );
2673 if( prefix != NULL && prefix->bv_len > 0 ) {
2674 HASH_Update( &HASHcontext,
2675 prefix->bv_val, prefix->bv_len );
2677 HASH_Update( &HASHcontext,
2678 syntax->ssyn_oid, slen );
2679 HASH_Update( &HASHcontext,
2680 mr->smr_oid, mlen );
2681 HASH_Update( &HASHcontext,
2682 value->bv_val, value->bv_len );
2683 HASH_Final( HASHdigest, &HASHcontext );
2685 keys[i] = ber_bvdup( &digest );
2690 return LDAP_SUCCESS;
2693 /* Index generation function */
2694 int caseExactIA5Filter(
2699 struct berval *prefix,
2701 struct berval ***keysp )
2704 struct berval **keys;
2705 HASH_CONTEXT HASHcontext;
2706 unsigned char HASHdigest[HASH_BYTES];
2707 struct berval *value;
2708 struct berval digest;
2709 digest.bv_val = HASHdigest;
2710 digest.bv_len = sizeof(HASHdigest);
2712 slen = strlen( syntax->ssyn_oid );
2713 mlen = strlen( mr->smr_oid );
2715 value = (struct berval *) assertValue;
2717 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2719 HASH_Init( &HASHcontext );
2720 if( prefix != NULL && prefix->bv_len > 0 ) {
2721 HASH_Update( &HASHcontext,
2722 prefix->bv_val, prefix->bv_len );
2724 HASH_Update( &HASHcontext,
2725 syntax->ssyn_oid, slen );
2726 HASH_Update( &HASHcontext,
2727 mr->smr_oid, mlen );
2728 HASH_Update( &HASHcontext,
2729 value->bv_val, value->bv_len );
2730 HASH_Final( HASHdigest, &HASHcontext );
2732 keys[0] = ber_bvdup( &digest );
2736 return LDAP_SUCCESS;
2739 /* Substrings Index generation function */
2740 int caseExactIA5SubstringsIndexer(
2745 struct berval *prefix,
2746 struct berval **values,
2747 struct berval ***keysp )
2751 struct berval **keys;
2752 HASH_CONTEXT HASHcontext;
2753 unsigned char HASHdigest[HASH_BYTES];
2754 struct berval digest;
2755 digest.bv_val = HASHdigest;
2756 digest.bv_len = sizeof(HASHdigest);
2758 /* we should have at least one value at this point */
2759 assert( values != NULL && values[0] != NULL );
2762 for( i=0; values[i] != NULL; i++ ) {
2763 /* count number of indices to generate */
2764 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2768 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2769 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2770 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2771 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2773 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2777 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2778 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2779 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2783 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2784 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2785 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2786 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2788 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2794 /* no keys to generate */
2796 return LDAP_SUCCESS;
2799 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2801 slen = strlen( syntax->ssyn_oid );
2802 mlen = strlen( mr->smr_oid );
2805 for( i=0; values[i] != NULL; i++ ) {
2807 struct berval *value;
2810 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2812 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2813 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2815 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2816 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2818 for( j=0; j<max; j++ ) {
2819 HASH_Init( &HASHcontext );
2820 if( prefix != NULL && prefix->bv_len > 0 ) {
2821 HASH_Update( &HASHcontext,
2822 prefix->bv_val, prefix->bv_len );
2825 HASH_Update( &HASHcontext,
2826 &pre, sizeof( pre ) );
2827 HASH_Update( &HASHcontext,
2828 syntax->ssyn_oid, slen );
2829 HASH_Update( &HASHcontext,
2830 mr->smr_oid, mlen );
2831 HASH_Update( &HASHcontext,
2833 SLAP_INDEX_SUBSTR_MAXLEN );
2834 HASH_Final( HASHdigest, &HASHcontext );
2836 keys[nkeys++] = ber_bvdup( &digest );
2840 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2841 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2843 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2846 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2847 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2848 HASH_Init( &HASHcontext );
2849 if( prefix != NULL && prefix->bv_len > 0 ) {
2850 HASH_Update( &HASHcontext,
2851 prefix->bv_val, prefix->bv_len );
2853 HASH_Update( &HASHcontext,
2854 &pre, sizeof( pre ) );
2855 HASH_Update( &HASHcontext,
2856 syntax->ssyn_oid, slen );
2857 HASH_Update( &HASHcontext,
2858 mr->smr_oid, mlen );
2859 HASH_Update( &HASHcontext,
2861 HASH_Final( HASHdigest, &HASHcontext );
2863 keys[nkeys++] = ber_bvdup( &digest );
2866 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2867 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2868 HASH_Init( &HASHcontext );
2869 if( prefix != NULL && prefix->bv_len > 0 ) {
2870 HASH_Update( &HASHcontext,
2871 prefix->bv_val, prefix->bv_len );
2873 HASH_Update( &HASHcontext,
2874 &pre, sizeof( pre ) );
2875 HASH_Update( &HASHcontext,
2876 syntax->ssyn_oid, slen );
2877 HASH_Update( &HASHcontext,
2878 mr->smr_oid, mlen );
2879 HASH_Update( &HASHcontext,
2880 &value->bv_val[value->bv_len-j], j );
2881 HASH_Final( HASHdigest, &HASHcontext );
2883 keys[nkeys++] = ber_bvdup( &digest );
2897 return LDAP_SUCCESS;
2900 int caseExactIA5SubstringsFilter(
2905 struct berval *prefix,
2907 struct berval ***keysp )
2909 SubstringsAssertion *sa = assertValue;
2911 ber_len_t nkeys = 0;
2912 size_t slen, mlen, klen;
2913 struct berval **keys;
2914 HASH_CONTEXT HASHcontext;
2915 unsigned char HASHdigest[HASH_BYTES];
2916 struct berval *value;
2917 struct berval digest;
2919 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2920 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2925 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2927 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2928 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2929 /* don't bother accounting for stepping */
2930 nkeys += sa->sa_any[i]->bv_len -
2931 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2936 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2937 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2944 return LDAP_SUCCESS;
2947 digest.bv_val = HASHdigest;
2948 digest.bv_len = sizeof(HASHdigest);
2950 slen = strlen( syntax->ssyn_oid );
2951 mlen = strlen( mr->smr_oid );
2953 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2956 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2957 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2959 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2960 value = sa->sa_initial;
2962 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2963 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2965 HASH_Init( &HASHcontext );
2966 if( prefix != NULL && prefix->bv_len > 0 ) {
2967 HASH_Update( &HASHcontext,
2968 prefix->bv_val, prefix->bv_len );
2970 HASH_Update( &HASHcontext,
2971 &pre, sizeof( pre ) );
2972 HASH_Update( &HASHcontext,
2973 syntax->ssyn_oid, slen );
2974 HASH_Update( &HASHcontext,
2975 mr->smr_oid, mlen );
2976 HASH_Update( &HASHcontext,
2977 value->bv_val, klen );
2978 HASH_Final( HASHdigest, &HASHcontext );
2980 keys[nkeys++] = ber_bvdup( &digest );
2983 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2985 pre = SLAP_INDEX_SUBSTR_PREFIX;
2986 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2988 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2989 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2993 value = sa->sa_any[i];
2996 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2997 j += SLAP_INDEX_SUBSTR_STEP )
2999 HASH_Init( &HASHcontext );
3000 if( prefix != NULL && prefix->bv_len > 0 ) {
3001 HASH_Update( &HASHcontext,
3002 prefix->bv_val, prefix->bv_len );
3004 HASH_Update( &HASHcontext,
3005 &pre, sizeof( pre ) );
3006 HASH_Update( &HASHcontext,
3007 syntax->ssyn_oid, slen );
3008 HASH_Update( &HASHcontext,
3009 mr->smr_oid, mlen );
3010 HASH_Update( &HASHcontext,
3011 &value->bv_val[j], klen );
3012 HASH_Final( HASHdigest, &HASHcontext );
3014 keys[nkeys++] = ber_bvdup( &digest );
3019 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3020 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3022 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3023 value = sa->sa_final;
3025 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3026 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3028 HASH_Init( &HASHcontext );
3029 if( prefix != NULL && prefix->bv_len > 0 ) {
3030 HASH_Update( &HASHcontext,
3031 prefix->bv_val, prefix->bv_len );
3033 HASH_Update( &HASHcontext,
3034 &pre, sizeof( pre ) );
3035 HASH_Update( &HASHcontext,
3036 syntax->ssyn_oid, slen );
3037 HASH_Update( &HASHcontext,
3038 mr->smr_oid, mlen );
3039 HASH_Update( &HASHcontext,
3040 &value->bv_val[value->bv_len-klen], klen );
3041 HASH_Final( HASHdigest, &HASHcontext );
3043 keys[nkeys++] = ber_bvdup( &digest );
3054 return LDAP_SUCCESS;
3063 struct berval *value,
3064 void *assertedValue )
3066 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3068 if( match == 0 && value->bv_len ) {
3069 match = strncasecmp( value->bv_val,
3070 ((struct berval *) assertedValue)->bv_val,
3075 return LDAP_SUCCESS;
3079 caseIgnoreIA5SubstringsMatch(
3084 struct berval *value,
3085 void *assertedValue )
3088 SubstringsAssertion *sub = assertedValue;
3089 struct berval left = *value;
3093 /* Add up asserted input length */
3094 if( sub->sa_initial ) {
3095 inlen += sub->sa_initial->bv_len;
3098 for(i=0; sub->sa_any[i] != NULL; i++) {
3099 inlen += sub->sa_any[i]->bv_len;
3102 if( sub->sa_final ) {
3103 inlen += sub->sa_final->bv_len;
3106 if( sub->sa_initial ) {
3107 if( inlen > left.bv_len ) {
3112 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3113 sub->sa_initial->bv_len );
3119 left.bv_val += sub->sa_initial->bv_len;
3120 left.bv_len -= sub->sa_initial->bv_len;
3121 inlen -= sub->sa_initial->bv_len;
3124 if( sub->sa_final ) {
3125 if( inlen > left.bv_len ) {
3130 match = strncasecmp( sub->sa_final->bv_val,
3131 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3132 sub->sa_final->bv_len );
3138 left.bv_len -= sub->sa_final->bv_len;
3139 inlen -= sub->sa_final->bv_len;
3143 for(i=0; sub->sa_any[i]; i++) {
3148 if( inlen > left.bv_len ) {
3149 /* not enough length */
3154 if( sub->sa_any[i]->bv_len == 0 ) {
3158 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3165 idx = p - left.bv_val;
3166 assert( idx < left.bv_len );
3168 if( idx >= left.bv_len ) {
3169 /* this shouldn't happen */
3176 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3177 /* not enough left */
3182 match = strncasecmp( left.bv_val,
3183 sub->sa_any[i]->bv_val,
3184 sub->sa_any[i]->bv_len );
3193 left.bv_val += sub->sa_any[i]->bv_len;
3194 left.bv_len -= sub->sa_any[i]->bv_len;
3195 inlen -= sub->sa_any[i]->bv_len;
3201 return LDAP_SUCCESS;
3204 /* Index generation function */
3205 int caseIgnoreIA5Indexer(
3210 struct berval *prefix,
3211 struct berval **values,
3212 struct berval ***keysp )
3216 struct berval **keys;
3217 HASH_CONTEXT HASHcontext;
3218 unsigned char HASHdigest[HASH_BYTES];
3219 struct berval digest;
3220 digest.bv_val = HASHdigest;
3221 digest.bv_len = sizeof(HASHdigest);
3223 /* we should have at least one value at this point */
3224 assert( values != NULL && values[0] != NULL );
3226 for( i=0; values[i] != NULL; i++ ) {
3227 /* just count them */
3230 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3232 slen = strlen( syntax->ssyn_oid );
3233 mlen = strlen( mr->smr_oid );
3235 for( i=0; values[i] != NULL; i++ ) {
3236 struct berval *value = ber_bvdup( values[i] );
3237 ldap_pvt_str2upper( value->bv_val );
3239 HASH_Init( &HASHcontext );
3240 if( prefix != NULL && prefix->bv_len > 0 ) {
3241 HASH_Update( &HASHcontext,
3242 prefix->bv_val, prefix->bv_len );
3244 HASH_Update( &HASHcontext,
3245 syntax->ssyn_oid, slen );
3246 HASH_Update( &HASHcontext,
3247 mr->smr_oid, mlen );
3248 HASH_Update( &HASHcontext,
3249 value->bv_val, value->bv_len );
3250 HASH_Final( HASHdigest, &HASHcontext );
3252 ber_bvfree( value );
3254 keys[i] = ber_bvdup( &digest );
3259 return LDAP_SUCCESS;
3262 /* Index generation function */
3263 int caseIgnoreIA5Filter(
3268 struct berval *prefix,
3270 struct berval ***keysp )
3273 struct berval **keys;
3274 HASH_CONTEXT HASHcontext;
3275 unsigned char HASHdigest[HASH_BYTES];
3276 struct berval *value;
3277 struct berval digest;
3278 digest.bv_val = HASHdigest;
3279 digest.bv_len = sizeof(HASHdigest);
3281 slen = strlen( syntax->ssyn_oid );
3282 mlen = strlen( mr->smr_oid );
3284 value = ber_bvdup( (struct berval *) assertValue );
3285 ldap_pvt_str2upper( value->bv_val );
3287 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3289 HASH_Init( &HASHcontext );
3290 if( prefix != NULL && prefix->bv_len > 0 ) {
3291 HASH_Update( &HASHcontext,
3292 prefix->bv_val, prefix->bv_len );
3294 HASH_Update( &HASHcontext,
3295 syntax->ssyn_oid, slen );
3296 HASH_Update( &HASHcontext,
3297 mr->smr_oid, mlen );
3298 HASH_Update( &HASHcontext,
3299 value->bv_val, value->bv_len );
3300 HASH_Final( HASHdigest, &HASHcontext );
3302 keys[0] = ber_bvdup( &digest );
3305 ber_bvfree( value );
3309 return LDAP_SUCCESS;
3312 /* Substrings Index generation function */
3313 int caseIgnoreIA5SubstringsIndexer(
3318 struct berval *prefix,
3319 struct berval **values,
3320 struct berval ***keysp )
3324 struct berval **keys;
3325 HASH_CONTEXT HASHcontext;
3326 unsigned char HASHdigest[HASH_BYTES];
3327 struct berval digest;
3328 digest.bv_val = HASHdigest;
3329 digest.bv_len = sizeof(HASHdigest);
3331 /* we should have at least one value at this point */
3332 assert( values != NULL && values[0] != NULL );
3335 for( i=0; values[i] != NULL; i++ ) {
3336 /* count number of indices to generate */
3337 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3341 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3342 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3343 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3344 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3346 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3350 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3351 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3352 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3356 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3357 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3358 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3359 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3361 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3367 /* no keys to generate */
3369 return LDAP_SUCCESS;
3372 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3374 slen = strlen( syntax->ssyn_oid );
3375 mlen = strlen( mr->smr_oid );
3378 for( i=0; values[i] != NULL; i++ ) {
3380 struct berval *value;
3382 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3384 value = ber_bvdup( values[i] );
3385 ldap_pvt_str2upper( value->bv_val );
3387 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3388 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3390 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3391 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3393 for( j=0; j<max; j++ ) {
3394 HASH_Init( &HASHcontext );
3395 if( prefix != NULL && prefix->bv_len > 0 ) {
3396 HASH_Update( &HASHcontext,
3397 prefix->bv_val, prefix->bv_len );
3400 HASH_Update( &HASHcontext,
3401 &pre, sizeof( pre ) );
3402 HASH_Update( &HASHcontext,
3403 syntax->ssyn_oid, slen );
3404 HASH_Update( &HASHcontext,
3405 mr->smr_oid, mlen );
3406 HASH_Update( &HASHcontext,
3408 SLAP_INDEX_SUBSTR_MAXLEN );
3409 HASH_Final( HASHdigest, &HASHcontext );
3411 keys[nkeys++] = ber_bvdup( &digest );
3415 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3416 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3418 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3421 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3422 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3423 HASH_Init( &HASHcontext );
3424 if( prefix != NULL && prefix->bv_len > 0 ) {
3425 HASH_Update( &HASHcontext,
3426 prefix->bv_val, prefix->bv_len );
3428 HASH_Update( &HASHcontext,
3429 &pre, sizeof( pre ) );
3430 HASH_Update( &HASHcontext,
3431 syntax->ssyn_oid, slen );
3432 HASH_Update( &HASHcontext,
3433 mr->smr_oid, mlen );
3434 HASH_Update( &HASHcontext,
3436 HASH_Final( HASHdigest, &HASHcontext );
3438 keys[nkeys++] = ber_bvdup( &digest );
3441 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3442 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3443 HASH_Init( &HASHcontext );
3444 if( prefix != NULL && prefix->bv_len > 0 ) {
3445 HASH_Update( &HASHcontext,
3446 prefix->bv_val, prefix->bv_len );
3448 HASH_Update( &HASHcontext,
3449 &pre, sizeof( pre ) );
3450 HASH_Update( &HASHcontext,
3451 syntax->ssyn_oid, slen );
3452 HASH_Update( &HASHcontext,
3453 mr->smr_oid, mlen );
3454 HASH_Update( &HASHcontext,
3455 &value->bv_val[value->bv_len-j], j );
3456 HASH_Final( HASHdigest, &HASHcontext );
3458 keys[nkeys++] = ber_bvdup( &digest );
3463 ber_bvfree( value );
3474 return LDAP_SUCCESS;
3477 int caseIgnoreIA5SubstringsFilter(
3482 struct berval *prefix,
3484 struct berval ***keysp )
3486 SubstringsAssertion *sa = assertValue;
3488 ber_len_t nkeys = 0;
3489 size_t slen, mlen, klen;
3490 struct berval **keys;
3491 HASH_CONTEXT HASHcontext;
3492 unsigned char HASHdigest[HASH_BYTES];
3493 struct berval *value;
3494 struct berval digest;
3496 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3497 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3502 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3504 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3505 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3506 /* don't bother accounting for stepping */
3507 nkeys += sa->sa_any[i]->bv_len -
3508 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3513 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3514 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3521 return LDAP_SUCCESS;
3524 digest.bv_val = HASHdigest;
3525 digest.bv_len = sizeof(HASHdigest);
3527 slen = strlen( syntax->ssyn_oid );
3528 mlen = strlen( mr->smr_oid );
3530 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3533 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3534 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3536 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3537 value = ber_bvdup( sa->sa_initial );
3538 ldap_pvt_str2upper( value->bv_val );
3540 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3541 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3543 HASH_Init( &HASHcontext );
3544 if( prefix != NULL && prefix->bv_len > 0 ) {
3545 HASH_Update( &HASHcontext,
3546 prefix->bv_val, prefix->bv_len );
3548 HASH_Update( &HASHcontext,
3549 &pre, sizeof( pre ) );
3550 HASH_Update( &HASHcontext,
3551 syntax->ssyn_oid, slen );
3552 HASH_Update( &HASHcontext,
3553 mr->smr_oid, mlen );
3554 HASH_Update( &HASHcontext,
3555 value->bv_val, klen );
3556 HASH_Final( HASHdigest, &HASHcontext );
3558 ber_bvfree( value );
3559 keys[nkeys++] = ber_bvdup( &digest );
3562 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3564 pre = SLAP_INDEX_SUBSTR_PREFIX;
3565 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3567 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3568 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3572 value = ber_bvdup( sa->sa_any[i] );
3573 ldap_pvt_str2upper( value->bv_val );
3576 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3577 j += SLAP_INDEX_SUBSTR_STEP )
3579 HASH_Init( &HASHcontext );
3580 if( prefix != NULL && prefix->bv_len > 0 ) {
3581 HASH_Update( &HASHcontext,
3582 prefix->bv_val, prefix->bv_len );
3584 HASH_Update( &HASHcontext,
3585 &pre, sizeof( pre ) );
3586 HASH_Update( &HASHcontext,
3587 syntax->ssyn_oid, slen );
3588 HASH_Update( &HASHcontext,
3589 mr->smr_oid, mlen );
3590 HASH_Update( &HASHcontext,
3591 &value->bv_val[j], klen );
3592 HASH_Final( HASHdigest, &HASHcontext );
3594 keys[nkeys++] = ber_bvdup( &digest );
3597 ber_bvfree( value );
3601 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3602 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3604 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3605 value = ber_bvdup( sa->sa_final );
3606 ldap_pvt_str2upper( value->bv_val );
3608 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3609 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3611 HASH_Init( &HASHcontext );
3612 if( prefix != NULL && prefix->bv_len > 0 ) {
3613 HASH_Update( &HASHcontext,
3614 prefix->bv_val, prefix->bv_len );
3616 HASH_Update( &HASHcontext,
3617 &pre, sizeof( pre ) );
3618 HASH_Update( &HASHcontext,
3619 syntax->ssyn_oid, slen );
3620 HASH_Update( &HASHcontext,
3621 mr->smr_oid, mlen );
3622 HASH_Update( &HASHcontext,
3623 &value->bv_val[value->bv_len-klen], klen );
3624 HASH_Final( HASHdigest, &HASHcontext );
3626 ber_bvfree( value );
3627 keys[nkeys++] = ber_bvdup( &digest );
3638 return LDAP_SUCCESS;
3642 numericStringValidate(
3648 for(i=0; i < in->bv_len; i++) {
3649 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3650 return LDAP_INVALID_SYNTAX;
3654 return LDAP_SUCCESS;
3658 numericStringNormalize(
3661 struct berval **normalized )
3663 /* removal all spaces */
3664 struct berval *newval;
3667 newval = ch_malloc( sizeof( struct berval ) );
3668 newval->bv_val = ch_malloc( val->bv_len + 1 );
3674 if ( ASCII_SPACE( *p ) ) {
3675 /* Ignore whitespace */
3682 assert( newval->bv_val =< p );
3685 /* null terminate */
3688 newval->bv_len = q - newval->bv_val;
3689 *normalized = newval;
3691 return LDAP_SUCCESS;
3695 objectIdentifierFirstComponentMatch(
3700 struct berval *value,
3701 void *assertedValue )
3703 int rc = LDAP_SUCCESS;
3705 struct berval *asserted = (struct berval *) assertedValue;
3709 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3710 return LDAP_INVALID_SYNTAX;
3713 /* trim leading white space */
3714 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3718 /* grab next word */
3719 oid.bv_val = &value->bv_val[i];
3720 oid.bv_len = value->bv_len - i;
3721 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3726 /* insert attributeTypes, objectclass check here */
3727 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3728 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3731 char *stored = ch_malloc( oid.bv_len + 1 );
3732 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3733 stored[oid.bv_len] = '\0';
3735 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3736 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3737 MatchingRule *stored_mr = mr_find( stored );
3739 if( asserted_mr == NULL ) {
3740 rc = SLAPD_COMPARE_UNDEFINED;
3742 match = asserted_mr != stored_mr;
3745 } else if ( !strcmp( syntax->ssyn_oid,
3746 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3748 AttributeType *asserted_at = at_find( asserted->bv_val );
3749 AttributeType *stored_at = at_find( stored );
3751 if( asserted_at == NULL ) {
3752 rc = SLAPD_COMPARE_UNDEFINED;
3754 match = asserted_at != stored_at;
3757 } else if ( !strcmp( syntax->ssyn_oid,
3758 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3760 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3761 ObjectClass *stored_oc = oc_find( stored );
3763 if( asserted_oc == NULL ) {
3764 rc = SLAPD_COMPARE_UNDEFINED;
3766 match = asserted_oc != stored_oc;
3774 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3775 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3776 match, value->bv_val, asserted->bv_val ));
3778 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3779 "%d\n\t\"%s\"\n\t\"%s\"\n",
3780 match, value->bv_val, asserted->bv_val );
3784 if( rc == LDAP_SUCCESS ) *matchp = match;
3789 check_time_syntax (struct berval *val,
3793 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3794 static int mdays[2][12] = {
3795 /* non-leap years */
3796 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3798 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3801 int part, c, tzoffset, leapyear = 0 ;
3803 if( val->bv_len == 0 ) {
3804 return LDAP_INVALID_SYNTAX;
3807 p = (char *)val->bv_val;
3808 e = p + val->bv_len;
3810 /* Ignore initial whitespace */
3811 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3815 if (e - p < 13 - (2 * start)) {
3816 return LDAP_INVALID_SYNTAX;
3819 for (part = 0; part < 9; part++) {
3823 for (part = start; part < 7; part++) {
3825 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3832 return LDAP_INVALID_SYNTAX;
3834 if (c < 0 || c > 9) {
3835 return LDAP_INVALID_SYNTAX;
3841 return LDAP_INVALID_SYNTAX;
3843 if (c < 0 || c > 9) {
3844 return LDAP_INVALID_SYNTAX;
3849 if (part == 2 || part == 3) {
3852 if (parts[part] < 0) {
3853 return LDAP_INVALID_SYNTAX;
3855 if (parts[part] > ceiling[part]) {
3856 return LDAP_INVALID_SYNTAX;
3860 /* leapyear check for the Gregorian calendar (year>1581) */
3861 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3862 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3867 if (parts[3] > mdays[leapyear][parts[2]]) {
3868 return LDAP_INVALID_SYNTAX;
3873 tzoffset = 0; /* UTC */
3874 } else if (c != '+' && c != '-') {
3875 return LDAP_INVALID_SYNTAX;
3879 } else /* c == '+' */ {
3884 return LDAP_INVALID_SYNTAX;
3887 for (part = 7; part < 9; part++) {
3889 if (c < 0 || c > 9) {
3890 return LDAP_INVALID_SYNTAX;
3895 if (c < 0 || c > 9) {
3896 return LDAP_INVALID_SYNTAX;
3900 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3901 return LDAP_INVALID_SYNTAX;
3906 /* Ignore trailing whitespace */
3907 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3911 return LDAP_INVALID_SYNTAX;
3914 switch ( tzoffset ) {
3915 case -1: /* negativ offset to UTC, ie west of Greenwich */
3916 parts[4] += parts[7];
3917 parts[5] += parts[8];
3918 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3922 c = mdays[leapyear][parts[2]];
3924 if (parts[part] > c) {
3925 parts[part] -= c + 1;
3930 case 1: /* positive offset to UTC, ie east of Greenwich */
3931 parts[4] -= parts[7];
3932 parts[5] -= parts[8];
3933 for (part = 6; --part > 0; ) {
3937 /* first arg to % needs to be non negativ */
3938 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3940 if (parts[part] < 0) {
3941 parts[part] += c + 1;
3946 case 0: /* already UTC */
3950 return LDAP_SUCCESS;
3957 struct berval **normalized )
3962 rc = check_time_syntax(val, 1, parts);
3963 if (rc != LDAP_SUCCESS) {
3968 out = ch_malloc( sizeof(struct berval) );
3970 return LBER_ERROR_MEMORY;
3973 out->bv_val = ch_malloc( 14 );
3974 if ( out->bv_val == NULL ) {
3976 return LBER_ERROR_MEMORY;
3979 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3980 parts[1], parts[2] + 1, parts[3] + 1,
3981 parts[4], parts[5], parts[6] );
3985 return LDAP_SUCCESS;
3995 return check_time_syntax(in, 1, parts);
3999 generalizedTimeValidate(
4005 return check_time_syntax(in, 0, parts);
4009 generalizedTimeNormalize(
4012 struct berval **normalized )
4017 rc = check_time_syntax(val, 0, parts);
4018 if (rc != LDAP_SUCCESS) {
4023 out = ch_malloc( sizeof(struct berval) );
4025 return LBER_ERROR_MEMORY;
4028 out->bv_val = ch_malloc( 16 );
4029 if ( out->bv_val == NULL ) {
4031 return LBER_ERROR_MEMORY;
4034 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4035 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4036 parts[4], parts[5], parts[6] );
4040 return LDAP_SUCCESS;
4044 nisNetgroupTripleValidate(
4046 struct berval *val )
4051 if ( val->bv_len == 0 ) {
4052 return LDAP_INVALID_SYNTAX;
4055 p = (char *)val->bv_val;
4056 e = p + val->bv_len;
4059 /* syntax does not allow leading white space */
4060 /* Ignore initial whitespace */
4061 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4066 if ( *p != '(' /*')'*/ ) {
4067 return LDAP_INVALID_SYNTAX;
4070 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4074 return LDAP_INVALID_SYNTAX;
4077 } else if ( !ATTR_CHAR( *p ) ) {
4078 return LDAP_INVALID_SYNTAX;
4082 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4083 return LDAP_INVALID_SYNTAX;
4089 /* syntax does not allow trailing white space */
4090 /* Ignore trailing whitespace */
4091 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4097 return LDAP_INVALID_SYNTAX;
4100 return LDAP_SUCCESS;
4104 bootParameterValidate(
4106 struct berval *val )
4110 if ( val->bv_len == 0 ) {
4111 return LDAP_INVALID_SYNTAX;
4114 p = (char *)val->bv_val;
4115 e = p + val->bv_len;
4118 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4119 if ( !ATTR_CHAR( *p ) ) {
4120 return LDAP_INVALID_SYNTAX;
4125 return LDAP_INVALID_SYNTAX;
4129 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4130 if ( !ATTR_CHAR( *p ) ) {
4131 return LDAP_INVALID_SYNTAX;
4136 return LDAP_INVALID_SYNTAX;
4140 for ( p++; p < e; p++ ) {
4141 if ( !ATTR_CHAR( *p ) ) {
4142 return LDAP_INVALID_SYNTAX;
4146 return LDAP_SUCCESS;
4149 struct syntax_defs_rec {
4152 slap_syntax_validate_func *sd_validate;
4153 slap_syntax_transform_func *sd_normalize;
4154 slap_syntax_transform_func *sd_pretty;
4155 #ifdef SLAPD_BINARY_CONVERSION
4156 slap_syntax_transform_func *sd_ber2str;
4157 slap_syntax_transform_func *sd_str2ber;
4161 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4162 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4164 struct syntax_defs_rec syntax_defs[] = {
4165 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4166 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4168 0, NULL, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4170 0, NULL, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4172 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4174 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4176 0, bitStringValidate, NULL, NULL },
4177 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4178 0, booleanValidate, NULL, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4180 X_BINARY X_NOT_H_R ")",
4181 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4183 X_BINARY X_NOT_H_R ")",
4184 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4185 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4186 X_BINARY X_NOT_H_R ")",
4187 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4189 0, countryStringValidate, IA5StringNormalize, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4191 0, dnValidate, dnNormalize, dnPretty},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4193 0, NULL, NULL, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4195 0, NULL, NULL, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4197 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4199 0, NULL, NULL, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4201 0, NULL, NULL, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4203 0, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4205 0, NULL, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4207 0, NULL, NULL, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4209 0, printablesStringValidate, IA5StringNormalize, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4211 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4213 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4215 0, NULL, NULL, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4217 0, IA5StringValidate, IA5StringNormalize, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4219 0, integerValidate, integerNormalize, integerPretty},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4221 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4223 0, NULL, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4225 0, NULL, NULL, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4227 0, NULL, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4229 0, NULL, NULL, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4231 0, NULL, NULL, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4233 0, nameUIDValidate, nameUIDNormalize, NULL},
4234 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4235 0, NULL, NULL, NULL},
4236 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4237 0, numericStringValidate, numericStringNormalize, NULL},
4238 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4239 0, NULL, NULL, NULL},
4240 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4241 0, oidValidate, NULL, NULL},
4242 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4243 0, IA5StringValidate, IA5StringNormalize, NULL},
4244 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4245 0, blobValidate, NULL, NULL},
4246 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4247 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4248 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4249 0, NULL, NULL, NULL},
4250 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4251 0, NULL, NULL, NULL},
4252 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4253 0, printableStringValidate, IA5StringNormalize, NULL},
4254 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4255 X_BINARY X_NOT_H_R ")",
4256 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4257 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4258 0, printableStringValidate, IA5StringNormalize, NULL},
4259 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4260 0, NULL, NULL, NULL},
4261 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4262 0, printableStringValidate, IA5StringNormalize, NULL},
4263 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4264 0, utcTimeValidate, utcTimeNormalize, NULL},
4265 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4266 0, NULL, NULL, NULL},
4267 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4268 0, NULL, NULL, NULL},
4269 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4270 0, NULL, NULL, NULL},
4271 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4272 0, NULL, NULL, NULL},
4273 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4274 0, NULL, NULL, NULL},
4276 /* RFC 2307 NIS Syntaxes */
4277 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4278 0, nisNetgroupTripleValidate, NULL, NULL},
4279 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4280 0, bootParameterValidate, NULL, NULL},
4282 /* OpenLDAP Experimental Syntaxes */
4283 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4284 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4286 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4287 0, NULL, NULL, NULL},
4289 /* OpenLDAP Void Syntax */
4290 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4291 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4292 {NULL, 0, NULL, NULL, NULL}
4295 struct mrule_defs_rec {
4297 slap_mask_t mrd_usage;
4298 slap_mr_convert_func * mrd_convert;
4299 slap_mr_normalize_func * mrd_normalize;
4300 slap_mr_match_func * mrd_match;
4301 slap_mr_indexer_func * mrd_indexer;
4302 slap_mr_filter_func * mrd_filter;
4304 char * mrd_associated;
4308 * Other matching rules in X.520 that we do not use (yet):
4310 * 2.5.13.9 numericStringOrderingMatch
4311 * 2.5.13.15 integerOrderingMatch
4312 * 2.5.13.18 octetStringOrderingMatch
4313 * 2.5.13.19 octetStringSubstringsMatch
4314 * 2.5.13.25 uTCTimeMatch
4315 * 2.5.13.26 uTCTimeOrderingMatch
4316 * 2.5.13.31 directoryStringFirstComponentMatch
4317 * 2.5.13.32 wordMatch
4318 * 2.5.13.33 keywordMatch
4319 * 2.5.13.34 certificateExactMatch
4320 * 2.5.13.35 certificateMatch
4321 * 2.5.13.36 certificatePairExactMatch
4322 * 2.5.13.37 certificatePairMatch
4323 * 2.5.13.38 certificateListExactMatch
4324 * 2.5.13.39 certificateListMatch
4325 * 2.5.13.40 algorithmIdentifierMatch
4326 * 2.5.13.41 storedPrefixMatch
4327 * 2.5.13.42 attributeCertificateMatch
4328 * 2.5.13.43 readerAndKeyIDMatch
4329 * 2.5.13.44 attributeIntegrityMatch
4332 struct mrule_defs_rec mrule_defs[] = {
4334 * EQUALITY matching rules must be listed after associated APPROX
4335 * matching rules. So, we list all APPROX matching rules first.
4337 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4338 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4339 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4341 directoryStringApproxMatch,
4342 directoryStringApproxIndexer,
4343 directoryStringApproxFilter,
4346 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4347 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4348 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4350 IA5StringApproxMatch,
4351 IA5StringApproxIndexer,
4352 IA5StringApproxFilter,
4356 * Other matching rules
4359 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4360 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4361 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4363 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4366 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4367 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4368 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4370 dnMatch, dnIndexer, dnFilter,
4373 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4374 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4375 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4377 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4378 directoryStringApproxMatchOID },
4380 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4381 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4384 caseIgnoreOrderingMatch, NULL, NULL,
4387 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4388 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4389 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4391 caseIgnoreSubstringsMatch,
4392 caseIgnoreSubstringsIndexer,
4393 caseIgnoreSubstringsFilter,
4396 {"( 2.5.13.5 NAME 'caseExactMatch' "
4397 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4398 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4400 caseExactMatch, caseExactIndexer, caseExactFilter,
4401 directoryStringApproxMatchOID },
4403 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4404 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4407 caseExactOrderingMatch, NULL, NULL,
4410 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4411 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4412 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4414 caseExactSubstringsMatch,
4415 caseExactSubstringsIndexer,
4416 caseExactSubstringsFilter,
4419 {"( 2.5.13.8 NAME 'numericStringMatch' "
4420 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4421 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4424 caseIgnoreIA5Indexer,
4425 caseIgnoreIA5Filter,
4428 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4429 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4430 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4432 caseIgnoreIA5SubstringsMatch,
4433 caseIgnoreIA5SubstringsIndexer,
4434 caseIgnoreIA5SubstringsFilter,
4437 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4438 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4439 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4441 caseIgnoreListMatch, NULL, NULL,
4444 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4445 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4446 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4448 caseIgnoreListSubstringsMatch, NULL, NULL,
4451 {"( 2.5.13.13 NAME 'booleanMatch' "
4452 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4453 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4455 booleanMatch, NULL, NULL,
4458 {"( 2.5.13.14 NAME 'integerMatch' "
4459 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4460 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4462 integerMatch, integerIndexer, integerFilter,
4465 {"( 2.5.13.16 NAME 'bitStringMatch' "
4466 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4467 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4469 bitStringMatch, NULL, NULL,
4472 {"( 2.5.13.17 NAME 'octetStringMatch' "
4473 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4474 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4476 octetStringMatch, octetStringIndexer, octetStringFilter,
4479 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4480 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4481 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4483 telephoneNumberMatch,
4484 telephoneNumberIndexer,
4485 telephoneNumberFilter,
4488 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4489 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4490 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4492 telephoneNumberSubstringsMatch,
4493 telephoneNumberSubstringsIndexer,
4494 telephoneNumberSubstringsFilter,
4497 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4498 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4499 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4504 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4505 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4506 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4508 uniqueMemberMatch, NULL, NULL,
4511 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4512 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4513 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4515 protocolInformationMatch, NULL, NULL,
4518 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4519 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4520 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4522 generalizedTimeMatch, NULL, NULL,
4525 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4526 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4529 generalizedTimeOrderingMatch, NULL, NULL,
4532 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4533 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4534 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4536 integerFirstComponentMatch, NULL, NULL,
4539 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4540 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4541 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4543 objectIdentifierFirstComponentMatch, NULL, NULL,
4546 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4547 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4548 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4550 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4551 IA5StringApproxMatchOID },
4553 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4554 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4555 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4557 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4558 IA5StringApproxMatchOID },
4560 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4561 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4564 caseIgnoreIA5SubstringsMatch,
4565 caseIgnoreIA5SubstringsIndexer,
4566 caseIgnoreIA5SubstringsFilter,
4569 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4570 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4573 caseExactIA5SubstringsMatch,
4574 caseExactIA5SubstringsIndexer,
4575 caseExactIA5SubstringsFilter,
4578 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4579 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4582 authPasswordMatch, NULL, NULL,
4585 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4586 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4589 OpenLDAPaciMatch, NULL, NULL,
4592 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4601 /* we should only be called once (from main) */
4602 assert( schema_init_done == 0 );
4604 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4605 res = register_syntax( syntax_defs[i].sd_desc,
4606 syntax_defs[i].sd_flags,
4607 syntax_defs[i].sd_validate,
4608 syntax_defs[i].sd_normalize,
4609 syntax_defs[i].sd_pretty
4610 #ifdef SLAPD_BINARY_CONVERSION
4612 syntax_defs[i].sd_ber2str,
4613 syntax_defs[i].sd_str2ber
4618 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4619 syntax_defs[i].sd_desc );
4624 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4625 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4627 "schema_init: Ingoring unusable matching rule %s\n",
4628 mrule_defs[i].mrd_desc );
4632 res = register_matching_rule(
4633 mrule_defs[i].mrd_desc,
4634 mrule_defs[i].mrd_usage,
4635 mrule_defs[i].mrd_convert,
4636 mrule_defs[i].mrd_normalize,
4637 mrule_defs[i].mrd_match,
4638 mrule_defs[i].mrd_indexer,
4639 mrule_defs[i].mrd_filter,
4640 mrule_defs[i].mrd_associated );
4644 "schema_init: Error registering matching rule %s\n",
4645 mrule_defs[i].mrd_desc );
4649 schema_init_done = 1;
4650 return LDAP_SUCCESS;