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 presentationAddressMatch NULL
75 #define protocolInformationMatch NULL
76 #define integerFirstComponentMatch NULL
78 #define OpenLDAPaciMatch NULL
79 #define authPasswordMatch NULL
81 /* recycled indexing/filtering routines */
82 #define dnIndexer caseIgnoreIndexer
83 #define dnFilter caseIgnoreFilter
84 #define integerIndexer caseIgnoreIA5Indexer
85 #define integerFilter caseIgnoreIA5Filter
87 static char *strcasechr( const char *str, int c )
89 char *lower = strchr( str, TOLOWER(c) );
90 char *upper = strchr( str, TOUPPER(c) );
92 if( lower && upper ) {
93 return lower < upper ? lower : upper;
107 struct berval *value,
108 void *assertedValue )
110 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
113 match = memcmp( value->bv_val,
114 ((struct berval *) assertedValue)->bv_val,
122 /* Index generation function */
123 int octetStringIndexer(
128 struct berval *prefix,
129 struct berval **values,
130 struct berval ***keysp )
134 struct berval **keys;
135 HASH_CONTEXT HASHcontext;
136 unsigned char HASHdigest[HASH_BYTES];
137 struct berval digest;
138 digest.bv_val = HASHdigest;
139 digest.bv_len = sizeof(HASHdigest);
141 /* we should have at least one value at this point */
142 assert( values != NULL && values[0] != NULL );
144 for( i=0; values[i] != NULL; i++ ) {
145 /* just count them */
148 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
150 slen = strlen( syntax->ssyn_oid );
151 mlen = strlen( mr->smr_oid );
153 for( i=0; values[i] != NULL; i++ ) {
154 HASH_Init( &HASHcontext );
155 if( prefix != NULL && prefix->bv_len > 0 ) {
156 HASH_Update( &HASHcontext,
157 prefix->bv_val, prefix->bv_len );
159 HASH_Update( &HASHcontext,
160 syntax->ssyn_oid, slen );
161 HASH_Update( &HASHcontext,
163 HASH_Update( &HASHcontext,
164 values[i]->bv_val, values[i]->bv_len );
165 HASH_Final( HASHdigest, &HASHcontext );
167 keys[i] = ber_bvdup( &digest );
177 /* Index generation function */
178 int octetStringFilter(
183 struct berval *prefix,
185 struct berval ***keysp )
188 struct berval **keys;
189 HASH_CONTEXT HASHcontext;
190 unsigned char HASHdigest[HASH_BYTES];
191 struct berval *value = (struct berval *) assertValue;
192 struct berval digest;
193 digest.bv_val = HASHdigest;
194 digest.bv_len = sizeof(HASHdigest);
196 slen = strlen( syntax->ssyn_oid );
197 mlen = strlen( mr->smr_oid );
199 keys = ch_malloc( sizeof( struct berval * ) * 2 );
201 HASH_Init( &HASHcontext );
202 if( prefix != NULL && prefix->bv_len > 0 ) {
203 HASH_Update( &HASHcontext,
204 prefix->bv_val, prefix->bv_len );
206 HASH_Update( &HASHcontext,
207 syntax->ssyn_oid, slen );
208 HASH_Update( &HASHcontext,
210 HASH_Update( &HASHcontext,
211 value->bv_val, value->bv_len );
212 HASH_Final( HASHdigest, &HASHcontext );
214 keys[0] = ber_bvdup( &digest );
230 if( in->bv_len == 0 ) return LDAP_SUCCESS;
232 dn = ch_strdup( in->bv_val );
234 rc = dn_validate( dn ) == NULL
235 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
245 struct berval **normalized )
249 if ( val->bv_len != 0 ) {
251 #ifdef USE_DN_NORMALIZE
252 out = ber_bvstr( UTF8normalize( val->bv_val, UTF8_CASEFOLD ) );
254 out = ber_bvdup( val );
255 ldap_pvt_str2upper( out->bv_val );
257 dn = dn_validate( out->bv_val );
261 return LDAP_INVALID_SYNTAX;
265 out->bv_len = strlen( dn );
267 out = ber_bvdup( val );
280 struct berval *value,
281 void *assertedValue )
284 struct berval *asserted = (struct berval *) assertedValue;
286 match = value->bv_len - asserted->bv_len;
289 #ifdef USE_DN_NORMALIZE
290 match = strcmp( value->bv_val, asserted->bv_val );
292 match = strcasecmp( value->bv_val, asserted->bv_val );
297 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
298 "dnMatch: %d\n %s\n %s\n", match,
299 value->bv_val, asserted->bv_val ));
301 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
302 match, value->bv_val, asserted->bv_val );
318 if( in->bv_len == 0 ) return LDAP_SUCCESS;
320 dn = ber_bvdup( in );
322 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
323 /* assume presence of optional UID */
326 for(i=dn->bv_len-2; i>2; i--) {
327 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
331 if( dn->bv_val[i] != '\'' ) {
332 return LDAP_INVALID_SYNTAX;
334 if( dn->bv_val[i-1] != 'B' ) {
335 return LDAP_INVALID_SYNTAX;
337 if( dn->bv_val[i-2] != '#' ) {
338 return LDAP_INVALID_SYNTAX;
341 /* trim the UID to allow use of dn_validate */
342 dn->bv_val[i-2] = '\0';
345 rc = dn_validate( dn->bv_val ) == NULL
346 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
356 struct berval **normalized )
358 struct berval *out = ber_bvdup( val );
360 if( out->bv_len != 0 ) {
364 ber_len_t uidlen = 0;
366 if( out->bv_val[out->bv_len-1] == '\'' ) {
367 /* assume presence of optional UID */
368 uid = strrchr( out->bv_val, '#' );
372 return LDAP_INVALID_SYNTAX;
375 uidlen = out->bv_len - (out->bv_val - uid);
376 /* temporarily trim the UID */
380 #ifdef USE_DN_NORMALIZE
381 dn = dn_normalize( out->bv_val );
383 dn = dn_validate( out->bv_val );
388 return LDAP_INVALID_SYNTAX;
394 /* restore the separator */
397 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
401 out->bv_len = dnlen + uidlen;
413 /* any value allowed */
422 /* any value allowed */
433 /* very unforgiving validation, requires no normalization
434 * before simplistic matching
436 if( in->bv_len < 3 ) {
437 return LDAP_INVALID_SYNTAX;
439 if( in->bv_val[0] != 'B' ||
440 in->bv_val[1] != '\'' ||
441 in->bv_val[in->bv_len-1] != '\'' )
443 return LDAP_INVALID_SYNTAX;
446 for( i=in->bv_len-2; i>1; i-- ) {
447 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
448 return LDAP_INVALID_SYNTAX;
456 * Handling boolean syntax and matching is quite rigid.
457 * A more flexible approach would be to allow a variety
458 * of strings to be normalized and prettied into TRUE
466 /* very unforgiving validation, requires no normalization
467 * before simplistic matching
470 if( in->bv_len == 4 ) {
471 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
474 } else if( in->bv_len == 5 ) {
475 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
480 return LDAP_INVALID_SYNTAX;
489 struct berval *value,
490 void *assertedValue )
492 /* simplistic matching allowed by rigid validation */
493 struct berval *asserted = (struct berval *) assertedValue;
494 *matchp = value->bv_len != asserted->bv_len;
499 /* case insensitive UTF8 strncmp with offset for second string */
502 struct berval *right,
510 ldap_unicode_t ru, lu;
511 ldap_unicode_t ruu, luu;
513 rslen = len < right->bv_len ? len : right->bv_len;
514 lslen = len + offset < left->bv_len ? len : left->bv_len;
516 for( r = 0, l = offset;
517 r < rslen && l < lslen;
521 * XXYYZ: we convert to ucs4 even though -llunicode
522 * expects ucs2 in an unsigned long
524 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
525 if( ru == LDAP_UCS4_INVALID ) {
529 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
530 if( lu == LDAP_UCS4_INVALID ) {
534 ruu = uctoupper( ru );
535 luu = uctoupper( lu );
539 } else if( luu > ruu ) {
543 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
544 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
560 static char *UTF8casechr( const char *str, const char *c )
562 char *p, *lower, *upper;
563 ldap_ucs4_t tch, ch = ldap_utf8_to_ucs4(c);
565 tch = uctolower ( ch );
566 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
567 if( ldap_utf8_to_ucs4( p ) == tch ) {
571 lower = *p != '\0' ? p : NULL;
573 tch = uctoupper ( ch );
574 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
575 if( ldap_utf8_to_ucs4( p ) == tch ) {
579 upper = *p != '\0' ? p : NULL;
581 if( lower && upper ) {
582 return lower < upper ? lower : upper;
583 } else if ( lower ) {
598 unsigned char *u = in->bv_val;
600 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
602 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
603 /* get the length indicated by the first byte */
604 len = LDAP_UTF8_CHARLEN( u );
606 /* should not be zero */
607 if( len == 0 ) return LDAP_INVALID_SYNTAX;
609 /* make sure len corresponds with the offset
610 to the next character */
611 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
614 if( count != 0 ) return LDAP_INVALID_SYNTAX;
623 struct berval **normalized )
625 struct berval *newval;
628 newval = ch_malloc( sizeof( struct berval ) );
632 /* Ignore initial whitespace */
633 while ( ldap_utf8_isspace( p ) ) {
639 return LDAP_INVALID_SYNTAX;
642 newval->bv_val = ch_strdup( p );
643 p = q = newval->bv_val;
649 if ( ldap_utf8_isspace( p ) ) {
650 len = LDAP_UTF8_COPY(q,p);
655 /* Ignore the extra whitespace */
656 while ( ldap_utf8_isspace( p ) ) {
660 len = LDAP_UTF8_COPY(q,p);
667 assert( *newval->bv_val );
668 assert( newval->bv_val < p );
671 /* cannot start with a space */
672 assert( !ldap_utf8_isspace(newval->bv_val) );
675 * If the string ended in space, backup the pointer one
676 * position. One is enough because the above loop collapsed
677 * all whitespace to a single space.
684 /* cannot end with a space */
685 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
690 newval->bv_len = q - newval->bv_val;
691 *normalized = newval;
696 #if defined(SLAPD_APPROX_MULTISTRING)
698 #if defined(SLAPD_APPROX_INITIALS)
699 #define SLAPD_APPROX_DELIMITER "._ "
700 #define SLAPD_APPROX_WORDLEN 2
702 #define SLAPD_APPROX_DELIMITER " "
703 #define SLAPD_APPROX_WORDLEN 1
712 struct berval *value,
713 void *assertedValue )
715 char *val, *assertv, **values, **words, *c;
716 int i, count, len, nextchunk=0, nextavail=0;
719 /* Isolate how many words there are */
720 val = ch_strdup( value->bv_val );
721 for( c=val,count=1; *c; c++ ) {
722 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
723 if ( c == NULL ) break;
728 /* Get a phonetic copy of each word */
729 words = (char **)ch_malloc( count * sizeof(char *) );
730 values = (char **)ch_malloc( count * sizeof(char *) );
731 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
733 values[i] = phonetic(c);
737 /* Work through the asserted value's words, to see if at least some
738 of the words are there, in the same order. */
739 assertv = ch_strdup( ((struct berval *)assertedValue)->bv_val );
741 while ( nextchunk < ((struct berval *)assertedValue)->bv_len ) {
742 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
747 #if defined(SLAPD_APPROX_INITIALS)
748 else if( len == 1 ) {
749 /* Single letter words need to at least match one word's initial */
750 for( i=nextavail; i<count; i++ )
751 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
758 /* Isolate the next word in the asserted value and phonetic it */
759 assertv[nextchunk+len] = '\0';
760 val = phonetic( assertv + nextchunk );
762 /* See if this phonetic chunk is in the remaining words of *value */
763 for( i=nextavail; i<count; i++ ){
764 if( !strcmp( val, values[i] ) ){
771 /* This chunk in the asserted value was NOT within the *value. */
777 /* Go on to the next word in the asserted value */
781 /* If some of the words were seen, call it a match */
782 if( nextavail > 0 ) {
791 for( i=0; i<count; i++ ) {
792 ch_free( values[i] );
808 struct berval *prefix,
809 struct berval **values,
810 struct berval ***keysp )
813 int i,j, len, wordcount, keycount=0;
814 struct berval **newkeys, **keys=NULL;
817 for( j=0; values[j] != NULL; j++ ) {
819 /* Isolate how many words there are. There will be a key for each */
820 val = ch_strdup( values[j]->bv_val );
821 for( wordcount=0,c=val; *c; c++) {
822 len = strcspn(c, SLAPD_APPROX_DELIMITER);
823 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
825 if (*c == '\0') break;
829 /* Allocate/increase storage to account for new keys */
830 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
831 * sizeof(struct berval *) );
832 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
833 if( keys ) ch_free( keys );
836 /* Get a phonetic copy of each word */
837 for( c=val,i=0; i<wordcount; c+=len+1 ) {
839 if( len < SLAPD_APPROX_WORDLEN ) continue;
840 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
841 keys[keycount]->bv_val = phonetic( c );
842 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
849 keys[keycount] = NULL;
862 struct berval *prefix,
864 struct berval ***keysp )
868 struct berval **keys;
871 /* Isolate how many words there are. There will be a key for each */
872 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
873 for( count=0,c=val; *c; c++) {
874 len = strcspn(c, SLAPD_APPROX_DELIMITER);
875 if( len >= SLAPD_APPROX_WORDLEN ) count++;
877 if (*c == '\0') break;
881 /* Allocate storage for new keys */
882 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
884 /* Get a phonetic copy of each word */
885 for( c=val,i=0; i<count; c+=len+1 ) {
887 if( len < SLAPD_APPROX_WORDLEN ) continue;
888 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
889 keys[i]->bv_val = phonetic( c );
890 keys[i]->bv_len = strlen( keys[i]->bv_val );
904 /* No other form of Approximate Matching is defined */
912 struct berval *value,
913 void *assertedValue )
915 char *vapprox, *avapprox;
917 vapprox = phonetic( value->bv_val );
918 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
920 *matchp = strcmp( vapprox, avapprox );
934 struct berval *prefix,
935 struct berval **values,
936 struct berval ***keysp )
939 struct berval **keys;
942 for( i=0; values[i] != NULL; i++ ) {
943 /* just count them */
947 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
949 /* Copy each value and run it through phonetic() */
950 for( i=0; values[i] != NULL; i++ ) {
951 keys[i] = ch_malloc( sizeof( struct berval * ) );
952 keys[i]->bv_val = phonetic( values[i]->bv_val );
953 keys[i]->bv_len = strlen( keys[i]->bv_val );
968 struct berval *prefix,
970 struct berval ***keysp )
972 struct berval **keys;
975 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
977 /* Copy the value and run it through phonetic() */
978 keys[0] = ch_malloc( sizeof( struct berval * ) );
979 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
980 keys[0]->bv_len = strlen( keys[0]->bv_val );
995 struct berval *value,
996 void *assertedValue )
998 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1001 match = strncmp( value->bv_val,
1002 ((struct berval *) assertedValue)->bv_val,
1007 return LDAP_SUCCESS;
1011 caseExactSubstringsMatch(
1016 struct berval *value,
1017 void *assertedValue )
1020 SubstringsAssertion *sub = assertedValue;
1021 struct berval left = *value;
1025 /* Add up asserted input length */
1026 if( sub->sa_initial ) {
1027 inlen += sub->sa_initial->bv_len;
1030 for(i=0; sub->sa_any[i] != NULL; i++) {
1031 inlen += sub->sa_any[i]->bv_len;
1034 if( sub->sa_final ) {
1035 inlen += sub->sa_final->bv_len;
1038 if( sub->sa_initial ) {
1039 if( inlen > left.bv_len ) {
1044 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1045 sub->sa_initial->bv_len );
1051 left.bv_val += sub->sa_initial->bv_len;
1052 left.bv_len -= sub->sa_initial->bv_len;
1053 inlen -= sub->sa_initial->bv_len;
1056 if( sub->sa_final ) {
1057 if( inlen > left.bv_len ) {
1062 match = strncmp( sub->sa_final->bv_val,
1063 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1064 sub->sa_final->bv_len );
1070 left.bv_len -= sub->sa_final->bv_len;
1071 inlen -= sub->sa_final->bv_len;
1075 for(i=0; sub->sa_any[i]; i++) {
1080 if( inlen > left.bv_len ) {
1081 /* not enough length */
1086 if( sub->sa_any[i]->bv_len == 0 ) {
1090 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1097 idx = p - left.bv_val;
1098 assert( idx < left.bv_len );
1100 if( idx >= left.bv_len ) {
1101 /* this shouldn't happen */
1108 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1109 /* not enough left */
1114 match = strncmp( left.bv_val,
1115 sub->sa_any[i]->bv_val,
1116 sub->sa_any[i]->bv_len );
1124 left.bv_val += sub->sa_any[i]->bv_len;
1125 left.bv_len -= sub->sa_any[i]->bv_len;
1126 inlen -= sub->sa_any[i]->bv_len;
1132 return LDAP_SUCCESS;
1135 /* Index generation function */
1136 int caseExactIndexer(
1141 struct berval *prefix,
1142 struct berval **values,
1143 struct berval ***keysp )
1147 struct berval **keys;
1148 HASH_CONTEXT HASHcontext;
1149 unsigned char HASHdigest[HASH_BYTES];
1150 struct berval digest;
1151 digest.bv_val = HASHdigest;
1152 digest.bv_len = sizeof(HASHdigest);
1154 /* we should have at least one value at this point */
1155 assert( values != NULL && values[0] != NULL );
1157 for( i=0; values[i] != NULL; i++ ) {
1158 /* just count them */
1161 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1163 slen = strlen( syntax->ssyn_oid );
1164 mlen = strlen( mr->smr_oid );
1166 for( i=0; values[i] != NULL; i++ ) {
1167 struct berval *value;
1169 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
1174 HASH_Init( &HASHcontext );
1175 if( prefix != NULL && prefix->bv_len > 0 ) {
1176 HASH_Update( &HASHcontext,
1177 prefix->bv_val, prefix->bv_len );
1179 HASH_Update( &HASHcontext,
1180 syntax->ssyn_oid, slen );
1181 HASH_Update( &HASHcontext,
1182 mr->smr_oid, mlen );
1183 HASH_Update( &HASHcontext,
1184 value->bv_val, value->bv_len );
1185 HASH_Final( HASHdigest, &HASHcontext );
1188 ber_bvfree( value );
1191 keys[i] = ber_bvdup( &digest );
1196 return LDAP_SUCCESS;
1199 /* Index generation function */
1200 int caseExactFilter(
1205 struct berval *prefix,
1207 struct berval ***keysp )
1210 struct berval **keys;
1211 HASH_CONTEXT HASHcontext;
1212 unsigned char HASHdigest[HASH_BYTES];
1213 struct berval *value;
1214 struct berval digest;
1215 digest.bv_val = HASHdigest;
1216 digest.bv_len = sizeof(HASHdigest);
1218 slen = strlen( syntax->ssyn_oid );
1219 mlen = strlen( mr->smr_oid );
1222 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val, UTF8_NOCASEFOLD ) );
1224 value = (struct berval *) assertValue;
1227 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1229 HASH_Init( &HASHcontext );
1230 if( prefix != NULL && prefix->bv_len > 0 ) {
1231 HASH_Update( &HASHcontext,
1232 prefix->bv_val, prefix->bv_len );
1234 HASH_Update( &HASHcontext,
1235 syntax->ssyn_oid, slen );
1236 HASH_Update( &HASHcontext,
1237 mr->smr_oid, mlen );
1238 HASH_Update( &HASHcontext,
1239 value->bv_val, value->bv_len );
1240 HASH_Final( HASHdigest, &HASHcontext );
1242 keys[0] = ber_bvdup( &digest );
1246 ber_bvfree( value );
1250 return LDAP_SUCCESS;
1253 /* Substrings Index generation function */
1254 int caseExactSubstringsIndexer(
1259 struct berval *prefix,
1260 struct berval **values,
1261 struct berval ***keysp )
1265 struct berval **keys;
1266 HASH_CONTEXT HASHcontext;
1267 unsigned char HASHdigest[HASH_BYTES];
1268 struct berval digest;
1269 digest.bv_val = HASHdigest;
1270 digest.bv_len = sizeof(HASHdigest);
1272 /* we should have at least one value at this point */
1273 assert( values != NULL && values[0] != NULL );
1276 for( i=0; values[i] != NULL; i++ ) {
1277 /* count number of indices to generate */
1278 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1282 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1283 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1284 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1285 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1287 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1291 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1292 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1293 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1297 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1298 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1299 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1300 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1302 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1308 /* no keys to generate */
1310 return LDAP_SUCCESS;
1313 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1315 slen = strlen( syntax->ssyn_oid );
1316 mlen = strlen( mr->smr_oid );
1319 for( i=0; values[i] != NULL; i++ ) {
1321 struct berval *value;
1323 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1326 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_NOCASEFOLD ) );
1331 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1332 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1334 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1335 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1337 for( j=0; j<max; j++ ) {
1338 HASH_Init( &HASHcontext );
1339 if( prefix != NULL && prefix->bv_len > 0 ) {
1340 HASH_Update( &HASHcontext,
1341 prefix->bv_val, prefix->bv_len );
1344 HASH_Update( &HASHcontext,
1345 &pre, sizeof( pre ) );
1346 HASH_Update( &HASHcontext,
1347 syntax->ssyn_oid, slen );
1348 HASH_Update( &HASHcontext,
1349 mr->smr_oid, mlen );
1350 HASH_Update( &HASHcontext,
1352 SLAP_INDEX_SUBSTR_MAXLEN );
1353 HASH_Final( HASHdigest, &HASHcontext );
1355 keys[nkeys++] = ber_bvdup( &digest );
1359 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1360 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1362 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1365 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1366 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1367 HASH_Init( &HASHcontext );
1368 if( prefix != NULL && prefix->bv_len > 0 ) {
1369 HASH_Update( &HASHcontext,
1370 prefix->bv_val, prefix->bv_len );
1372 HASH_Update( &HASHcontext,
1373 &pre, sizeof( pre ) );
1374 HASH_Update( &HASHcontext,
1375 syntax->ssyn_oid, slen );
1376 HASH_Update( &HASHcontext,
1377 mr->smr_oid, mlen );
1378 HASH_Update( &HASHcontext,
1380 HASH_Final( HASHdigest, &HASHcontext );
1382 keys[nkeys++] = ber_bvdup( &digest );
1385 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1386 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1387 HASH_Init( &HASHcontext );
1388 if( prefix != NULL && prefix->bv_len > 0 ) {
1389 HASH_Update( &HASHcontext,
1390 prefix->bv_val, prefix->bv_len );
1392 HASH_Update( &HASHcontext,
1393 &pre, sizeof( pre ) );
1394 HASH_Update( &HASHcontext,
1395 syntax->ssyn_oid, slen );
1396 HASH_Update( &HASHcontext,
1397 mr->smr_oid, mlen );
1398 HASH_Update( &HASHcontext,
1399 &value->bv_val[value->bv_len-j], j );
1400 HASH_Final( HASHdigest, &HASHcontext );
1402 keys[nkeys++] = ber_bvdup( &digest );
1408 ber_bvfree( value );
1421 return LDAP_SUCCESS;
1424 int caseExactSubstringsFilter(
1429 struct berval *prefix,
1431 struct berval ***keysp )
1433 SubstringsAssertion *sa = assertValue;
1435 ber_len_t nkeys = 0;
1436 size_t slen, mlen, klen;
1437 struct berval **keys;
1438 HASH_CONTEXT HASHcontext;
1439 unsigned char HASHdigest[HASH_BYTES];
1440 struct berval *value;
1441 struct berval digest;
1443 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1444 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1449 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1451 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1452 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1453 /* don't bother accounting for stepping */
1454 nkeys += sa->sa_any[i]->bv_len -
1455 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1460 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1461 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1468 return LDAP_SUCCESS;
1471 digest.bv_val = HASHdigest;
1472 digest.bv_len = sizeof(HASHdigest);
1474 slen = strlen( syntax->ssyn_oid );
1475 mlen = strlen( mr->smr_oid );
1477 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1480 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1481 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1483 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1485 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_NOCASEFOLD ) );
1487 value = sa->sa_initial;
1490 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1491 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1493 HASH_Init( &HASHcontext );
1494 if( prefix != NULL && prefix->bv_len > 0 ) {
1495 HASH_Update( &HASHcontext,
1496 prefix->bv_val, prefix->bv_len );
1498 HASH_Update( &HASHcontext,
1499 &pre, sizeof( pre ) );
1500 HASH_Update( &HASHcontext,
1501 syntax->ssyn_oid, slen );
1502 HASH_Update( &HASHcontext,
1503 mr->smr_oid, mlen );
1504 HASH_Update( &HASHcontext,
1505 value->bv_val, klen );
1506 HASH_Final( HASHdigest, &HASHcontext );
1509 ber_bvfree( value );
1511 keys[nkeys++] = ber_bvdup( &digest );
1514 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1516 pre = SLAP_INDEX_SUBSTR_PREFIX;
1517 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1519 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1520 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1525 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_NOCASEFOLD ) );
1527 value = sa->sa_any[i];
1531 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1532 j += SLAP_INDEX_SUBSTR_STEP )
1534 HASH_Init( &HASHcontext );
1535 if( prefix != NULL && prefix->bv_len > 0 ) {
1536 HASH_Update( &HASHcontext,
1537 prefix->bv_val, prefix->bv_len );
1539 HASH_Update( &HASHcontext,
1540 &pre, sizeof( pre ) );
1541 HASH_Update( &HASHcontext,
1542 syntax->ssyn_oid, slen );
1543 HASH_Update( &HASHcontext,
1544 mr->smr_oid, mlen );
1545 HASH_Update( &HASHcontext,
1546 &value->bv_val[j], klen );
1547 HASH_Final( HASHdigest, &HASHcontext );
1549 keys[nkeys++] = ber_bvdup( &digest );
1553 ber_bvfree( value );
1558 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1559 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1561 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1563 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_NOCASEFOLD ) );
1565 value = sa->sa_final;
1568 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1569 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1571 HASH_Init( &HASHcontext );
1572 if( prefix != NULL && prefix->bv_len > 0 ) {
1573 HASH_Update( &HASHcontext,
1574 prefix->bv_val, prefix->bv_len );
1576 HASH_Update( &HASHcontext,
1577 &pre, sizeof( pre ) );
1578 HASH_Update( &HASHcontext,
1579 syntax->ssyn_oid, slen );
1580 HASH_Update( &HASHcontext,
1581 mr->smr_oid, mlen );
1582 HASH_Update( &HASHcontext,
1583 &value->bv_val[value->bv_len-klen], klen );
1584 HASH_Final( HASHdigest, &HASHcontext );
1587 ber_bvfree( value );
1589 keys[nkeys++] = ber_bvdup( &digest );
1600 return LDAP_SUCCESS;
1609 struct berval *value,
1610 void *assertedValue )
1613 *matchp = UTF8normcmp( value->bv_val,
1614 ((struct berval *) assertedValue)->bv_val,
1617 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1620 match = strncasecmp( value->bv_val,
1621 ((struct berval *) assertedValue)->bv_val,
1627 return LDAP_SUCCESS;
1631 caseIgnoreSubstringsMatch(
1636 struct berval *value,
1637 void *assertedValue )
1640 SubstringsAssertion *sub = assertedValue;
1641 struct berval left = *value;
1645 /* Add up asserted input length */
1646 if( sub->sa_initial ) {
1647 inlen += sub->sa_initial->bv_len;
1650 for(i=0; sub->sa_any[i] != NULL; i++) {
1651 inlen += sub->sa_any[i]->bv_len;
1654 if( sub->sa_final ) {
1655 inlen += sub->sa_final->bv_len;
1658 if( sub->sa_initial ) {
1659 if( inlen > left.bv_len ) {
1665 match = UTF8oncasecmp( sub->sa_initial, &left,
1666 sub->sa_initial->bv_len, 0 );
1668 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1669 sub->sa_initial->bv_len );
1676 left.bv_val += sub->sa_initial->bv_len;
1677 left.bv_len -= sub->sa_initial->bv_len;
1678 inlen -= sub->sa_initial->bv_len;
1681 if( sub->sa_final ) {
1682 if( inlen > left.bv_len ) {
1688 match = UTF8oncasecmp( sub->sa_final, &left,
1689 sub->sa_final->bv_len,
1690 left.bv_len - sub->sa_final->bv_len );
1692 match = strncasecmp( sub->sa_final->bv_val,
1693 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1694 sub->sa_final->bv_len );
1701 left.bv_len -= sub->sa_final->bv_len;
1702 inlen -= sub->sa_final->bv_len;
1706 for(i=0; sub->sa_any[i]; i++) {
1711 if( inlen > left.bv_len ) {
1712 /* not enough length */
1717 if( sub->sa_any[i]->bv_len == 0 ) {
1722 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1724 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1732 idx = p - left.bv_val;
1733 assert( idx < left.bv_len );
1735 if( idx >= left.bv_len ) {
1736 /* this shouldn't happen */
1743 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1744 /* not enough left */
1750 match = UTF8oncasecmp( &left, sub->sa_any[i],
1751 sub->sa_any[i]->bv_len, 0 );
1754 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1760 match = strncasecmp( left.bv_val,
1761 sub->sa_any[i]->bv_val,
1762 sub->sa_any[i]->bv_len );
1772 left.bv_val += sub->sa_any[i]->bv_len;
1773 left.bv_len -= sub->sa_any[i]->bv_len;
1774 inlen -= sub->sa_any[i]->bv_len;
1780 return LDAP_SUCCESS;
1783 /* Index generation function */
1784 int caseIgnoreIndexer(
1789 struct berval *prefix,
1790 struct berval **values,
1791 struct berval ***keysp )
1795 struct berval **keys;
1796 HASH_CONTEXT HASHcontext;
1797 unsigned char HASHdigest[HASH_BYTES];
1798 struct berval digest;
1799 digest.bv_val = HASHdigest;
1800 digest.bv_len = sizeof(HASHdigest);
1802 /* we should have at least one value at this point */
1803 assert( values != NULL && values[0] != NULL );
1805 for( i=0; values[i] != NULL; i++ ) {
1806 /* just count them */
1809 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1811 slen = strlen( syntax->ssyn_oid );
1812 mlen = strlen( mr->smr_oid );
1814 for( i=0; values[i] != NULL; i++ ) {
1815 struct berval *value;
1817 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1819 value = ber_bvdup( values[i] );
1820 ldap_pvt_str2upper( value->bv_val );
1822 HASH_Init( &HASHcontext );
1823 if( prefix != NULL && prefix->bv_len > 0 ) {
1824 HASH_Update( &HASHcontext,
1825 prefix->bv_val, prefix->bv_len );
1827 HASH_Update( &HASHcontext,
1828 syntax->ssyn_oid, slen );
1829 HASH_Update( &HASHcontext,
1830 mr->smr_oid, mlen );
1831 HASH_Update( &HASHcontext,
1832 value->bv_val, value->bv_len );
1833 HASH_Final( HASHdigest, &HASHcontext );
1835 ber_bvfree( value );
1837 keys[i] = ber_bvdup( &digest );
1842 return LDAP_SUCCESS;
1845 /* Index generation function */
1846 int caseIgnoreFilter(
1851 struct berval *prefix,
1853 struct berval ***keysp )
1856 struct berval **keys;
1857 HASH_CONTEXT HASHcontext;
1858 unsigned char HASHdigest[HASH_BYTES];
1859 struct berval *value;
1860 struct berval digest;
1861 digest.bv_val = HASHdigest;
1862 digest.bv_len = sizeof(HASHdigest);
1864 slen = strlen( syntax->ssyn_oid );
1865 mlen = strlen( mr->smr_oid );
1868 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue)->bv_val, UTF8_CASEFOLD ) );
1870 value = ber_bvdup( (struct berval *) assertValue );
1871 ldap_pvt_str2upper( value->bv_val );
1874 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1876 HASH_Init( &HASHcontext );
1877 if( prefix != NULL && prefix->bv_len > 0 ) {
1878 HASH_Update( &HASHcontext,
1879 prefix->bv_val, prefix->bv_len );
1881 HASH_Update( &HASHcontext,
1882 syntax->ssyn_oid, slen );
1883 HASH_Update( &HASHcontext,
1884 mr->smr_oid, mlen );
1885 HASH_Update( &HASHcontext,
1886 value->bv_val, value->bv_len );
1887 HASH_Final( HASHdigest, &HASHcontext );
1889 keys[0] = ber_bvdup( &digest );
1892 ber_bvfree( value );
1896 return LDAP_SUCCESS;
1899 /* Substrings Index generation function */
1900 int caseIgnoreSubstringsIndexer(
1905 struct berval *prefix,
1906 struct berval **values,
1907 struct berval ***keysp )
1911 struct berval **keys;
1912 HASH_CONTEXT HASHcontext;
1913 unsigned char HASHdigest[HASH_BYTES];
1914 struct berval digest;
1915 digest.bv_val = HASHdigest;
1916 digest.bv_len = sizeof(HASHdigest);
1918 /* we should have at least one value at this point */
1919 assert( values != NULL && values[0] != NULL );
1922 for( i=0; values[i] != NULL; i++ ) {
1923 /* count number of indices to generate */
1924 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1928 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1929 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1930 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1931 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1933 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1937 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1938 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1939 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1943 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1944 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1945 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1946 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1948 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1954 /* no keys to generate */
1956 return LDAP_SUCCESS;
1959 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1961 slen = strlen( syntax->ssyn_oid );
1962 mlen = strlen( mr->smr_oid );
1965 for( i=0; values[i] != NULL; i++ ) {
1967 struct berval *value;
1969 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1972 value = ber_bvstr( UTF8normalize( values[i]->bv_val, UTF8_CASEFOLD ) );
1974 value = ber_bvdup( values[i] );
1975 ldap_pvt_str2upper( value->bv_val );
1978 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1979 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1981 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1982 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1984 for( j=0; j<max; j++ ) {
1985 HASH_Init( &HASHcontext );
1986 if( prefix != NULL && prefix->bv_len > 0 ) {
1987 HASH_Update( &HASHcontext,
1988 prefix->bv_val, prefix->bv_len );
1991 HASH_Update( &HASHcontext,
1992 &pre, sizeof( pre ) );
1993 HASH_Update( &HASHcontext,
1994 syntax->ssyn_oid, slen );
1995 HASH_Update( &HASHcontext,
1996 mr->smr_oid, mlen );
1997 HASH_Update( &HASHcontext,
1999 SLAP_INDEX_SUBSTR_MAXLEN );
2000 HASH_Final( HASHdigest, &HASHcontext );
2002 keys[nkeys++] = ber_bvdup( &digest );
2006 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2007 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2009 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2012 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2013 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2014 HASH_Init( &HASHcontext );
2015 if( prefix != NULL && prefix->bv_len > 0 ) {
2016 HASH_Update( &HASHcontext,
2017 prefix->bv_val, prefix->bv_len );
2019 HASH_Update( &HASHcontext,
2020 &pre, sizeof( pre ) );
2021 HASH_Update( &HASHcontext,
2022 syntax->ssyn_oid, slen );
2023 HASH_Update( &HASHcontext,
2024 mr->smr_oid, mlen );
2025 HASH_Update( &HASHcontext,
2027 HASH_Final( HASHdigest, &HASHcontext );
2029 keys[nkeys++] = ber_bvdup( &digest );
2032 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2033 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2034 HASH_Init( &HASHcontext );
2035 if( prefix != NULL && prefix->bv_len > 0 ) {
2036 HASH_Update( &HASHcontext,
2037 prefix->bv_val, prefix->bv_len );
2039 HASH_Update( &HASHcontext,
2040 &pre, sizeof( pre ) );
2041 HASH_Update( &HASHcontext,
2042 syntax->ssyn_oid, slen );
2043 HASH_Update( &HASHcontext,
2044 mr->smr_oid, mlen );
2045 HASH_Update( &HASHcontext,
2046 &value->bv_val[value->bv_len-j], j );
2047 HASH_Final( HASHdigest, &HASHcontext );
2049 keys[nkeys++] = ber_bvdup( &digest );
2054 ber_bvfree( value );
2065 return LDAP_SUCCESS;
2068 int caseIgnoreSubstringsFilter(
2073 struct berval *prefix,
2075 struct berval ***keysp )
2077 SubstringsAssertion *sa = assertValue;
2079 ber_len_t nkeys = 0;
2080 size_t slen, mlen, klen;
2081 struct berval **keys;
2082 HASH_CONTEXT HASHcontext;
2083 unsigned char HASHdigest[HASH_BYTES];
2084 struct berval *value;
2085 struct berval digest;
2087 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2088 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2093 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2095 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2096 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2097 /* don't bother accounting for stepping */
2098 nkeys += sa->sa_any[i]->bv_len -
2099 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2104 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2105 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2112 return LDAP_SUCCESS;
2115 digest.bv_val = HASHdigest;
2116 digest.bv_len = sizeof(HASHdigest);
2118 slen = strlen( syntax->ssyn_oid );
2119 mlen = strlen( mr->smr_oid );
2121 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2124 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2125 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2127 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2129 value = ber_bvstr( UTF8normalize( sa->sa_initial->bv_val, UTF8_CASEFOLD ) );
2131 value = ber_bvdup( sa->sa_initial );
2132 ldap_pvt_str2upper( value->bv_val );
2135 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2136 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2138 HASH_Init( &HASHcontext );
2139 if( prefix != NULL && prefix->bv_len > 0 ) {
2140 HASH_Update( &HASHcontext,
2141 prefix->bv_val, prefix->bv_len );
2143 HASH_Update( &HASHcontext,
2144 &pre, sizeof( pre ) );
2145 HASH_Update( &HASHcontext,
2146 syntax->ssyn_oid, slen );
2147 HASH_Update( &HASHcontext,
2148 mr->smr_oid, mlen );
2149 HASH_Update( &HASHcontext,
2150 value->bv_val, klen );
2151 HASH_Final( HASHdigest, &HASHcontext );
2153 ber_bvfree( value );
2154 keys[nkeys++] = ber_bvdup( &digest );
2157 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2159 pre = SLAP_INDEX_SUBSTR_PREFIX;
2160 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2162 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2163 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2168 value = ber_bvstr( UTF8normalize( sa->sa_any[i]->bv_val, UTF8_CASEFOLD ) );
2170 value = ber_bvdup( sa->sa_any[i] );
2171 ldap_pvt_str2upper( value->bv_val );
2175 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2176 j += SLAP_INDEX_SUBSTR_STEP )
2178 HASH_Init( &HASHcontext );
2179 if( prefix != NULL && prefix->bv_len > 0 ) {
2180 HASH_Update( &HASHcontext,
2181 prefix->bv_val, prefix->bv_len );
2183 HASH_Update( &HASHcontext,
2184 &pre, sizeof( pre ) );
2185 HASH_Update( &HASHcontext,
2186 syntax->ssyn_oid, slen );
2187 HASH_Update( &HASHcontext,
2188 mr->smr_oid, mlen );
2189 HASH_Update( &HASHcontext,
2190 &value->bv_val[j], klen );
2191 HASH_Final( HASHdigest, &HASHcontext );
2193 keys[nkeys++] = ber_bvdup( &digest );
2196 ber_bvfree( value );
2200 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2201 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2203 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2205 value = ber_bvstr( UTF8normalize( sa->sa_final->bv_val, UTF8_CASEFOLD ) );
2207 value = ber_bvdup( sa->sa_final );
2208 ldap_pvt_str2upper( value->bv_val );
2211 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2212 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2214 HASH_Init( &HASHcontext );
2215 if( prefix != NULL && prefix->bv_len > 0 ) {
2216 HASH_Update( &HASHcontext,
2217 prefix->bv_val, prefix->bv_len );
2219 HASH_Update( &HASHcontext,
2220 &pre, sizeof( pre ) );
2221 HASH_Update( &HASHcontext,
2222 syntax->ssyn_oid, slen );
2223 HASH_Update( &HASHcontext,
2224 mr->smr_oid, mlen );
2225 HASH_Update( &HASHcontext,
2226 &value->bv_val[value->bv_len-klen], klen );
2227 HASH_Final( HASHdigest, &HASHcontext );
2229 ber_bvfree( value );
2230 keys[nkeys++] = ber_bvdup( &digest );
2241 return LDAP_SUCCESS;
2247 struct berval *val )
2251 if( val->bv_len == 0 ) {
2252 /* disallow empty strings */
2253 return LDAP_INVALID_SYNTAX;
2256 if( OID_LEADCHAR(val->bv_val[0]) ) {
2258 for(i=1; i < val->bv_len; i++) {
2259 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2260 if( dot++ ) return 1;
2261 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2264 return LDAP_INVALID_SYNTAX;
2268 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2270 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2271 for(i=1; i < val->bv_len; i++) {
2272 if( !DESC_CHAR(val->bv_val[i] ) ) {
2273 return LDAP_INVALID_SYNTAX;
2277 return LDAP_SUCCESS;
2280 return LDAP_INVALID_SYNTAX;
2286 struct berval *val )
2290 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2292 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2293 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2294 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2295 return LDAP_INVALID_SYNTAX;
2298 for(i=1; i < val->bv_len; i++) {
2299 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2302 return LDAP_SUCCESS;
2309 struct berval **normalized )
2312 struct berval *newval;
2318 negative = ( *p == '-' );
2319 if( *p == '-' || *p == '+' ) p++;
2321 /* Ignore leading zeros */
2322 while ( *p == '0' ) p++;
2324 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2327 newval->bv_val = ch_strdup("0");
2332 newval->bv_val = ch_malloc( val->bv_len + 1 );
2336 newval->bv_val[newval->bv_len++] = '-';
2339 for( ; *p != '\0'; p++ ) {
2340 newval->bv_val[newval->bv_len++] = *p;
2344 *normalized = newval;
2345 return LDAP_SUCCESS;
2349 countryStringValidate(
2351 struct berval *val )
2355 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2357 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2358 return LDAP_INVALID_SYNTAX;
2360 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2361 return LDAP_INVALID_SYNTAX;
2364 return LDAP_SUCCESS;
2368 printableStringValidate(
2370 struct berval *val )
2374 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2376 for(i=0; i < val->bv_len; i++) {
2377 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2378 return LDAP_INVALID_SYNTAX;
2382 return LDAP_SUCCESS;
2386 printablesStringValidate(
2388 struct berval *val )
2392 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2394 for(i=0; i < val->bv_len; i++) {
2395 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2396 return LDAP_INVALID_SYNTAX;
2400 return LDAP_SUCCESS;
2406 struct berval *val )
2410 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2412 for(i=0; i < val->bv_len; i++) {
2413 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2416 return LDAP_SUCCESS;
2423 struct berval **normalized )
2425 struct berval *newval;
2428 newval = ch_malloc( sizeof( struct berval ) );
2432 /* Ignore initial whitespace */
2433 while ( ASCII_SPACE( *p ) ) {
2439 return LDAP_INVALID_SYNTAX;
2442 newval->bv_val = ch_strdup( p );
2443 p = q = newval->bv_val;
2446 if ( ASCII_SPACE( *p ) ) {
2449 /* Ignore the extra whitespace */
2450 while ( ASCII_SPACE( *p ) ) {
2458 assert( *newval->bv_val );
2459 assert( newval->bv_val < p );
2462 /* cannot start with a space */
2463 assert( !ASCII_SPACE(*newval->bv_val) );
2466 * If the string ended in space, backup the pointer one
2467 * position. One is enough because the above loop collapsed
2468 * all whitespace to a single space.
2471 if ( ASCII_SPACE( q[-1] ) ) {
2475 /* cannot end with a space */
2476 assert( !ASCII_SPACE( q[-1] ) );
2478 /* null terminate */
2481 newval->bv_len = q - newval->bv_val;
2482 *normalized = newval;
2484 return LDAP_SUCCESS;
2493 struct berval *value,
2494 void *assertedValue )
2496 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2499 match = strncmp( value->bv_val,
2500 ((struct berval *) assertedValue)->bv_val,
2505 return LDAP_SUCCESS;
2509 caseExactIA5SubstringsMatch(
2514 struct berval *value,
2515 void *assertedValue )
2518 SubstringsAssertion *sub = assertedValue;
2519 struct berval left = *value;
2523 /* Add up asserted input length */
2524 if( sub->sa_initial ) {
2525 inlen += sub->sa_initial->bv_len;
2528 for(i=0; sub->sa_any[i] != NULL; i++) {
2529 inlen += sub->sa_any[i]->bv_len;
2532 if( sub->sa_final ) {
2533 inlen += sub->sa_final->bv_len;
2536 if( sub->sa_initial ) {
2537 if( inlen > left.bv_len ) {
2542 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2543 sub->sa_initial->bv_len );
2549 left.bv_val += sub->sa_initial->bv_len;
2550 left.bv_len -= sub->sa_initial->bv_len;
2551 inlen -= sub->sa_initial->bv_len;
2554 if( sub->sa_final ) {
2555 if( inlen > left.bv_len ) {
2560 match = strncmp( sub->sa_final->bv_val,
2561 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2562 sub->sa_final->bv_len );
2568 left.bv_len -= sub->sa_final->bv_len;
2569 inlen -= sub->sa_final->bv_len;
2573 for(i=0; sub->sa_any[i]; i++) {
2578 if( inlen > left.bv_len ) {
2579 /* not enough length */
2584 if( sub->sa_any[i]->bv_len == 0 ) {
2588 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2595 idx = p - left.bv_val;
2596 assert( idx < left.bv_len );
2598 if( idx >= left.bv_len ) {
2599 /* this shouldn't happen */
2606 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2607 /* not enough left */
2612 match = strncmp( left.bv_val,
2613 sub->sa_any[i]->bv_val,
2614 sub->sa_any[i]->bv_len );
2622 left.bv_val += sub->sa_any[i]->bv_len;
2623 left.bv_len -= sub->sa_any[i]->bv_len;
2624 inlen -= sub->sa_any[i]->bv_len;
2630 return LDAP_SUCCESS;
2633 /* Index generation function */
2634 int caseExactIA5Indexer(
2639 struct berval *prefix,
2640 struct berval **values,
2641 struct berval ***keysp )
2645 struct berval **keys;
2646 HASH_CONTEXT HASHcontext;
2647 unsigned char HASHdigest[HASH_BYTES];
2648 struct berval digest;
2649 digest.bv_val = HASHdigest;
2650 digest.bv_len = sizeof(HASHdigest);
2652 /* we should have at least one value at this point */
2653 assert( values != NULL && values[0] != NULL );
2655 for( i=0; values[i] != NULL; i++ ) {
2656 /* just count them */
2659 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2661 slen = strlen( syntax->ssyn_oid );
2662 mlen = strlen( mr->smr_oid );
2664 for( i=0; values[i] != NULL; i++ ) {
2665 struct berval *value = values[i];
2667 HASH_Init( &HASHcontext );
2668 if( prefix != NULL && prefix->bv_len > 0 ) {
2669 HASH_Update( &HASHcontext,
2670 prefix->bv_val, prefix->bv_len );
2672 HASH_Update( &HASHcontext,
2673 syntax->ssyn_oid, slen );
2674 HASH_Update( &HASHcontext,
2675 mr->smr_oid, mlen );
2676 HASH_Update( &HASHcontext,
2677 value->bv_val, value->bv_len );
2678 HASH_Final( HASHdigest, &HASHcontext );
2680 keys[i] = ber_bvdup( &digest );
2685 return LDAP_SUCCESS;
2688 /* Index generation function */
2689 int caseExactIA5Filter(
2694 struct berval *prefix,
2696 struct berval ***keysp )
2699 struct berval **keys;
2700 HASH_CONTEXT HASHcontext;
2701 unsigned char HASHdigest[HASH_BYTES];
2702 struct berval *value;
2703 struct berval digest;
2704 digest.bv_val = HASHdigest;
2705 digest.bv_len = sizeof(HASHdigest);
2707 slen = strlen( syntax->ssyn_oid );
2708 mlen = strlen( mr->smr_oid );
2710 value = (struct berval *) assertValue;
2712 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2714 HASH_Init( &HASHcontext );
2715 if( prefix != NULL && prefix->bv_len > 0 ) {
2716 HASH_Update( &HASHcontext,
2717 prefix->bv_val, prefix->bv_len );
2719 HASH_Update( &HASHcontext,
2720 syntax->ssyn_oid, slen );
2721 HASH_Update( &HASHcontext,
2722 mr->smr_oid, mlen );
2723 HASH_Update( &HASHcontext,
2724 value->bv_val, value->bv_len );
2725 HASH_Final( HASHdigest, &HASHcontext );
2727 keys[0] = ber_bvdup( &digest );
2731 return LDAP_SUCCESS;
2734 /* Substrings Index generation function */
2735 int caseExactIA5SubstringsIndexer(
2740 struct berval *prefix,
2741 struct berval **values,
2742 struct berval ***keysp )
2746 struct berval **keys;
2747 HASH_CONTEXT HASHcontext;
2748 unsigned char HASHdigest[HASH_BYTES];
2749 struct berval digest;
2750 digest.bv_val = HASHdigest;
2751 digest.bv_len = sizeof(HASHdigest);
2753 /* we should have at least one value at this point */
2754 assert( values != NULL && values[0] != NULL );
2757 for( i=0; values[i] != NULL; i++ ) {
2758 /* count number of indices to generate */
2759 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2763 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2764 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2765 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2766 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2768 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2772 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2773 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2774 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2778 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2779 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2780 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2781 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2783 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2789 /* no keys to generate */
2791 return LDAP_SUCCESS;
2794 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2796 slen = strlen( syntax->ssyn_oid );
2797 mlen = strlen( mr->smr_oid );
2800 for( i=0; values[i] != NULL; i++ ) {
2802 struct berval *value;
2805 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2807 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2808 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2810 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2811 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2813 for( j=0; j<max; j++ ) {
2814 HASH_Init( &HASHcontext );
2815 if( prefix != NULL && prefix->bv_len > 0 ) {
2816 HASH_Update( &HASHcontext,
2817 prefix->bv_val, prefix->bv_len );
2820 HASH_Update( &HASHcontext,
2821 &pre, sizeof( pre ) );
2822 HASH_Update( &HASHcontext,
2823 syntax->ssyn_oid, slen );
2824 HASH_Update( &HASHcontext,
2825 mr->smr_oid, mlen );
2826 HASH_Update( &HASHcontext,
2828 SLAP_INDEX_SUBSTR_MAXLEN );
2829 HASH_Final( HASHdigest, &HASHcontext );
2831 keys[nkeys++] = ber_bvdup( &digest );
2835 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2836 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2838 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2841 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2842 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2843 HASH_Init( &HASHcontext );
2844 if( prefix != NULL && prefix->bv_len > 0 ) {
2845 HASH_Update( &HASHcontext,
2846 prefix->bv_val, prefix->bv_len );
2848 HASH_Update( &HASHcontext,
2849 &pre, sizeof( pre ) );
2850 HASH_Update( &HASHcontext,
2851 syntax->ssyn_oid, slen );
2852 HASH_Update( &HASHcontext,
2853 mr->smr_oid, mlen );
2854 HASH_Update( &HASHcontext,
2856 HASH_Final( HASHdigest, &HASHcontext );
2858 keys[nkeys++] = ber_bvdup( &digest );
2861 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2862 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2863 HASH_Init( &HASHcontext );
2864 if( prefix != NULL && prefix->bv_len > 0 ) {
2865 HASH_Update( &HASHcontext,
2866 prefix->bv_val, prefix->bv_len );
2868 HASH_Update( &HASHcontext,
2869 &pre, sizeof( pre ) );
2870 HASH_Update( &HASHcontext,
2871 syntax->ssyn_oid, slen );
2872 HASH_Update( &HASHcontext,
2873 mr->smr_oid, mlen );
2874 HASH_Update( &HASHcontext,
2875 &value->bv_val[value->bv_len-j], j );
2876 HASH_Final( HASHdigest, &HASHcontext );
2878 keys[nkeys++] = ber_bvdup( &digest );
2892 return LDAP_SUCCESS;
2895 int caseExactIA5SubstringsFilter(
2900 struct berval *prefix,
2902 struct berval ***keysp )
2904 SubstringsAssertion *sa = assertValue;
2906 ber_len_t nkeys = 0;
2907 size_t slen, mlen, klen;
2908 struct berval **keys;
2909 HASH_CONTEXT HASHcontext;
2910 unsigned char HASHdigest[HASH_BYTES];
2911 struct berval *value;
2912 struct berval digest;
2914 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2915 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2920 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2922 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2923 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2924 /* don't bother accounting for stepping */
2925 nkeys += sa->sa_any[i]->bv_len -
2926 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2931 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2932 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2939 return LDAP_SUCCESS;
2942 digest.bv_val = HASHdigest;
2943 digest.bv_len = sizeof(HASHdigest);
2945 slen = strlen( syntax->ssyn_oid );
2946 mlen = strlen( mr->smr_oid );
2948 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2951 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2952 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2954 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2955 value = sa->sa_initial;
2957 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2958 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2960 HASH_Init( &HASHcontext );
2961 if( prefix != NULL && prefix->bv_len > 0 ) {
2962 HASH_Update( &HASHcontext,
2963 prefix->bv_val, prefix->bv_len );
2965 HASH_Update( &HASHcontext,
2966 &pre, sizeof( pre ) );
2967 HASH_Update( &HASHcontext,
2968 syntax->ssyn_oid, slen );
2969 HASH_Update( &HASHcontext,
2970 mr->smr_oid, mlen );
2971 HASH_Update( &HASHcontext,
2972 value->bv_val, klen );
2973 HASH_Final( HASHdigest, &HASHcontext );
2975 keys[nkeys++] = ber_bvdup( &digest );
2978 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2980 pre = SLAP_INDEX_SUBSTR_PREFIX;
2981 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2983 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2984 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2988 value = sa->sa_any[i];
2991 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2992 j += SLAP_INDEX_SUBSTR_STEP )
2994 HASH_Init( &HASHcontext );
2995 if( prefix != NULL && prefix->bv_len > 0 ) {
2996 HASH_Update( &HASHcontext,
2997 prefix->bv_val, prefix->bv_len );
2999 HASH_Update( &HASHcontext,
3000 &pre, sizeof( pre ) );
3001 HASH_Update( &HASHcontext,
3002 syntax->ssyn_oid, slen );
3003 HASH_Update( &HASHcontext,
3004 mr->smr_oid, mlen );
3005 HASH_Update( &HASHcontext,
3006 &value->bv_val[j], klen );
3007 HASH_Final( HASHdigest, &HASHcontext );
3009 keys[nkeys++] = ber_bvdup( &digest );
3014 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3015 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3017 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3018 value = sa->sa_final;
3020 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3021 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3023 HASH_Init( &HASHcontext );
3024 if( prefix != NULL && prefix->bv_len > 0 ) {
3025 HASH_Update( &HASHcontext,
3026 prefix->bv_val, prefix->bv_len );
3028 HASH_Update( &HASHcontext,
3029 &pre, sizeof( pre ) );
3030 HASH_Update( &HASHcontext,
3031 syntax->ssyn_oid, slen );
3032 HASH_Update( &HASHcontext,
3033 mr->smr_oid, mlen );
3034 HASH_Update( &HASHcontext,
3035 &value->bv_val[value->bv_len-klen], klen );
3036 HASH_Final( HASHdigest, &HASHcontext );
3038 keys[nkeys++] = ber_bvdup( &digest );
3049 return LDAP_SUCCESS;
3058 struct berval *value,
3059 void *assertedValue )
3061 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3063 if( match == 0 && value->bv_len ) {
3064 match = strncasecmp( value->bv_val,
3065 ((struct berval *) assertedValue)->bv_val,
3070 return LDAP_SUCCESS;
3074 caseIgnoreIA5SubstringsMatch(
3079 struct berval *value,
3080 void *assertedValue )
3083 SubstringsAssertion *sub = assertedValue;
3084 struct berval left = *value;
3088 /* Add up asserted input length */
3089 if( sub->sa_initial ) {
3090 inlen += sub->sa_initial->bv_len;
3093 for(i=0; sub->sa_any[i] != NULL; i++) {
3094 inlen += sub->sa_any[i]->bv_len;
3097 if( sub->sa_final ) {
3098 inlen += sub->sa_final->bv_len;
3101 if( sub->sa_initial ) {
3102 if( inlen > left.bv_len ) {
3107 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3108 sub->sa_initial->bv_len );
3114 left.bv_val += sub->sa_initial->bv_len;
3115 left.bv_len -= sub->sa_initial->bv_len;
3116 inlen -= sub->sa_initial->bv_len;
3119 if( sub->sa_final ) {
3120 if( inlen > left.bv_len ) {
3125 match = strncasecmp( sub->sa_final->bv_val,
3126 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3127 sub->sa_final->bv_len );
3133 left.bv_len -= sub->sa_final->bv_len;
3134 inlen -= sub->sa_final->bv_len;
3138 for(i=0; sub->sa_any[i]; i++) {
3143 if( inlen > left.bv_len ) {
3144 /* not enough length */
3149 if( sub->sa_any[i]->bv_len == 0 ) {
3153 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3160 idx = p - left.bv_val;
3161 assert( idx < left.bv_len );
3163 if( idx >= left.bv_len ) {
3164 /* this shouldn't happen */
3171 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3172 /* not enough left */
3177 match = strncasecmp( left.bv_val,
3178 sub->sa_any[i]->bv_val,
3179 sub->sa_any[i]->bv_len );
3188 left.bv_val += sub->sa_any[i]->bv_len;
3189 left.bv_len -= sub->sa_any[i]->bv_len;
3190 inlen -= sub->sa_any[i]->bv_len;
3196 return LDAP_SUCCESS;
3199 /* Index generation function */
3200 int caseIgnoreIA5Indexer(
3205 struct berval *prefix,
3206 struct berval **values,
3207 struct berval ***keysp )
3211 struct berval **keys;
3212 HASH_CONTEXT HASHcontext;
3213 unsigned char HASHdigest[HASH_BYTES];
3214 struct berval digest;
3215 digest.bv_val = HASHdigest;
3216 digest.bv_len = sizeof(HASHdigest);
3218 /* we should have at least one value at this point */
3219 assert( values != NULL && values[0] != NULL );
3221 for( i=0; values[i] != NULL; i++ ) {
3222 /* just count them */
3225 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3227 slen = strlen( syntax->ssyn_oid );
3228 mlen = strlen( mr->smr_oid );
3230 for( i=0; values[i] != NULL; i++ ) {
3231 struct berval *value = ber_bvdup( values[i] );
3232 ldap_pvt_str2upper( value->bv_val );
3234 HASH_Init( &HASHcontext );
3235 if( prefix != NULL && prefix->bv_len > 0 ) {
3236 HASH_Update( &HASHcontext,
3237 prefix->bv_val, prefix->bv_len );
3239 HASH_Update( &HASHcontext,
3240 syntax->ssyn_oid, slen );
3241 HASH_Update( &HASHcontext,
3242 mr->smr_oid, mlen );
3243 HASH_Update( &HASHcontext,
3244 value->bv_val, value->bv_len );
3245 HASH_Final( HASHdigest, &HASHcontext );
3247 ber_bvfree( value );
3249 keys[i] = ber_bvdup( &digest );
3254 return LDAP_SUCCESS;
3257 /* Index generation function */
3258 int caseIgnoreIA5Filter(
3263 struct berval *prefix,
3265 struct berval ***keysp )
3268 struct berval **keys;
3269 HASH_CONTEXT HASHcontext;
3270 unsigned char HASHdigest[HASH_BYTES];
3271 struct berval *value;
3272 struct berval digest;
3273 digest.bv_val = HASHdigest;
3274 digest.bv_len = sizeof(HASHdigest);
3276 slen = strlen( syntax->ssyn_oid );
3277 mlen = strlen( mr->smr_oid );
3279 value = ber_bvdup( (struct berval *) assertValue );
3280 ldap_pvt_str2upper( value->bv_val );
3282 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3284 HASH_Init( &HASHcontext );
3285 if( prefix != NULL && prefix->bv_len > 0 ) {
3286 HASH_Update( &HASHcontext,
3287 prefix->bv_val, prefix->bv_len );
3289 HASH_Update( &HASHcontext,
3290 syntax->ssyn_oid, slen );
3291 HASH_Update( &HASHcontext,
3292 mr->smr_oid, mlen );
3293 HASH_Update( &HASHcontext,
3294 value->bv_val, value->bv_len );
3295 HASH_Final( HASHdigest, &HASHcontext );
3297 keys[0] = ber_bvdup( &digest );
3300 ber_bvfree( value );
3304 return LDAP_SUCCESS;
3307 /* Substrings Index generation function */
3308 int caseIgnoreIA5SubstringsIndexer(
3313 struct berval *prefix,
3314 struct berval **values,
3315 struct berval ***keysp )
3319 struct berval **keys;
3320 HASH_CONTEXT HASHcontext;
3321 unsigned char HASHdigest[HASH_BYTES];
3322 struct berval digest;
3323 digest.bv_val = HASHdigest;
3324 digest.bv_len = sizeof(HASHdigest);
3326 /* we should have at least one value at this point */
3327 assert( values != NULL && values[0] != NULL );
3330 for( i=0; values[i] != NULL; i++ ) {
3331 /* count number of indices to generate */
3332 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3336 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3337 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3338 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3339 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3341 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3345 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3346 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3347 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3351 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3352 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3353 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3354 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3356 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3362 /* no keys to generate */
3364 return LDAP_SUCCESS;
3367 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3369 slen = strlen( syntax->ssyn_oid );
3370 mlen = strlen( mr->smr_oid );
3373 for( i=0; values[i] != NULL; i++ ) {
3375 struct berval *value;
3377 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3379 value = ber_bvdup( values[i] );
3380 ldap_pvt_str2upper( value->bv_val );
3382 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3383 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3385 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3386 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3388 for( j=0; j<max; j++ ) {
3389 HASH_Init( &HASHcontext );
3390 if( prefix != NULL && prefix->bv_len > 0 ) {
3391 HASH_Update( &HASHcontext,
3392 prefix->bv_val, prefix->bv_len );
3395 HASH_Update( &HASHcontext,
3396 &pre, sizeof( pre ) );
3397 HASH_Update( &HASHcontext,
3398 syntax->ssyn_oid, slen );
3399 HASH_Update( &HASHcontext,
3400 mr->smr_oid, mlen );
3401 HASH_Update( &HASHcontext,
3403 SLAP_INDEX_SUBSTR_MAXLEN );
3404 HASH_Final( HASHdigest, &HASHcontext );
3406 keys[nkeys++] = ber_bvdup( &digest );
3410 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3411 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3413 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3416 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3417 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3418 HASH_Init( &HASHcontext );
3419 if( prefix != NULL && prefix->bv_len > 0 ) {
3420 HASH_Update( &HASHcontext,
3421 prefix->bv_val, prefix->bv_len );
3423 HASH_Update( &HASHcontext,
3424 &pre, sizeof( pre ) );
3425 HASH_Update( &HASHcontext,
3426 syntax->ssyn_oid, slen );
3427 HASH_Update( &HASHcontext,
3428 mr->smr_oid, mlen );
3429 HASH_Update( &HASHcontext,
3431 HASH_Final( HASHdigest, &HASHcontext );
3433 keys[nkeys++] = ber_bvdup( &digest );
3436 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3437 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3438 HASH_Init( &HASHcontext );
3439 if( prefix != NULL && prefix->bv_len > 0 ) {
3440 HASH_Update( &HASHcontext,
3441 prefix->bv_val, prefix->bv_len );
3443 HASH_Update( &HASHcontext,
3444 &pre, sizeof( pre ) );
3445 HASH_Update( &HASHcontext,
3446 syntax->ssyn_oid, slen );
3447 HASH_Update( &HASHcontext,
3448 mr->smr_oid, mlen );
3449 HASH_Update( &HASHcontext,
3450 &value->bv_val[value->bv_len-j], j );
3451 HASH_Final( HASHdigest, &HASHcontext );
3453 keys[nkeys++] = ber_bvdup( &digest );
3458 ber_bvfree( value );
3469 return LDAP_SUCCESS;
3472 int caseIgnoreIA5SubstringsFilter(
3477 struct berval *prefix,
3479 struct berval ***keysp )
3481 SubstringsAssertion *sa = assertValue;
3483 ber_len_t nkeys = 0;
3484 size_t slen, mlen, klen;
3485 struct berval **keys;
3486 HASH_CONTEXT HASHcontext;
3487 unsigned char HASHdigest[HASH_BYTES];
3488 struct berval *value;
3489 struct berval digest;
3491 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3492 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3497 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3499 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3500 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3501 /* don't bother accounting for stepping */
3502 nkeys += sa->sa_any[i]->bv_len -
3503 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3508 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3509 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3516 return LDAP_SUCCESS;
3519 digest.bv_val = HASHdigest;
3520 digest.bv_len = sizeof(HASHdigest);
3522 slen = strlen( syntax->ssyn_oid );
3523 mlen = strlen( mr->smr_oid );
3525 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3528 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3529 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3531 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3532 value = ber_bvdup( sa->sa_initial );
3533 ldap_pvt_str2upper( value->bv_val );
3535 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3536 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3538 HASH_Init( &HASHcontext );
3539 if( prefix != NULL && prefix->bv_len > 0 ) {
3540 HASH_Update( &HASHcontext,
3541 prefix->bv_val, prefix->bv_len );
3543 HASH_Update( &HASHcontext,
3544 &pre, sizeof( pre ) );
3545 HASH_Update( &HASHcontext,
3546 syntax->ssyn_oid, slen );
3547 HASH_Update( &HASHcontext,
3548 mr->smr_oid, mlen );
3549 HASH_Update( &HASHcontext,
3550 value->bv_val, klen );
3551 HASH_Final( HASHdigest, &HASHcontext );
3553 ber_bvfree( value );
3554 keys[nkeys++] = ber_bvdup( &digest );
3557 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3559 pre = SLAP_INDEX_SUBSTR_PREFIX;
3560 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3562 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3563 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3567 value = ber_bvdup( sa->sa_any[i] );
3568 ldap_pvt_str2upper( value->bv_val );
3571 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3572 j += SLAP_INDEX_SUBSTR_STEP )
3574 HASH_Init( &HASHcontext );
3575 if( prefix != NULL && prefix->bv_len > 0 ) {
3576 HASH_Update( &HASHcontext,
3577 prefix->bv_val, prefix->bv_len );
3579 HASH_Update( &HASHcontext,
3580 &pre, sizeof( pre ) );
3581 HASH_Update( &HASHcontext,
3582 syntax->ssyn_oid, slen );
3583 HASH_Update( &HASHcontext,
3584 mr->smr_oid, mlen );
3585 HASH_Update( &HASHcontext,
3586 &value->bv_val[j], klen );
3587 HASH_Final( HASHdigest, &HASHcontext );
3589 keys[nkeys++] = ber_bvdup( &digest );
3592 ber_bvfree( value );
3596 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3597 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3599 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3600 value = ber_bvdup( sa->sa_final );
3601 ldap_pvt_str2upper( value->bv_val );
3603 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3604 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3606 HASH_Init( &HASHcontext );
3607 if( prefix != NULL && prefix->bv_len > 0 ) {
3608 HASH_Update( &HASHcontext,
3609 prefix->bv_val, prefix->bv_len );
3611 HASH_Update( &HASHcontext,
3612 &pre, sizeof( pre ) );
3613 HASH_Update( &HASHcontext,
3614 syntax->ssyn_oid, slen );
3615 HASH_Update( &HASHcontext,
3616 mr->smr_oid, mlen );
3617 HASH_Update( &HASHcontext,
3618 &value->bv_val[value->bv_len-klen], klen );
3619 HASH_Final( HASHdigest, &HASHcontext );
3621 ber_bvfree( value );
3622 keys[nkeys++] = ber_bvdup( &digest );
3633 return LDAP_SUCCESS;
3637 numericStringValidate(
3643 /* disallow empty numeric strings */
3645 for(i=0; i < in->bv_len; i++) {
3646 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3647 return LDAP_INVALID_SYNTAX;
3651 return LDAP_SUCCESS;
3655 numericStringNormalize(
3658 struct berval **normalized )
3660 /* removal all spaces */
3661 struct berval *newval;
3664 newval = ch_malloc( sizeof( struct berval ) );
3665 newval->bv_val = ch_malloc( val->bv_len + 1 );
3671 if ( ASCII_SPACE( *p ) ) {
3672 /* Ignore whitespace */
3679 assert( newval->bv_val < p );
3682 /* null terminate */
3685 newval->bv_len = q - newval->bv_val;
3686 *normalized = newval;
3688 return LDAP_SUCCESS;
3692 objectIdentifierFirstComponentMatch(
3697 struct berval *value,
3698 void *assertedValue )
3700 int rc = LDAP_SUCCESS;
3702 struct berval *asserted = (struct berval *) assertedValue;
3706 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3707 return LDAP_INVALID_SYNTAX;
3710 /* trim leading white space */
3711 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3715 /* grab next word */
3716 oid.bv_val = &value->bv_val[i];
3717 oid.bv_len = value->bv_len - i;
3718 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3723 /* insert attributeTypes, objectclass check here */
3724 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3725 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3728 char *stored = ch_malloc( oid.bv_len + 1 );
3729 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3730 stored[oid.bv_len] = '\0';
3732 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3733 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3734 MatchingRule *stored_mr = mr_find( stored );
3736 if( asserted_mr == NULL ) {
3737 rc = SLAPD_COMPARE_UNDEFINED;
3739 match = asserted_mr != stored_mr;
3742 } else if ( !strcmp( syntax->ssyn_oid,
3743 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3745 AttributeType *asserted_at = at_find( asserted->bv_val );
3746 AttributeType *stored_at = at_find( stored );
3748 if( asserted_at == NULL ) {
3749 rc = SLAPD_COMPARE_UNDEFINED;
3751 match = asserted_at != stored_at;
3754 } else if ( !strcmp( syntax->ssyn_oid,
3755 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3757 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3758 ObjectClass *stored_oc = oc_find( stored );
3760 if( asserted_oc == NULL ) {
3761 rc = SLAPD_COMPARE_UNDEFINED;
3763 match = asserted_oc != stored_oc;
3771 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3772 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3773 match, value->bv_val, asserted->bv_val ));
3775 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3776 "%d\n\t\"%s\"\n\t\"%s\"\n",
3777 match, value->bv_val, asserted->bv_val );
3781 if( rc == LDAP_SUCCESS ) *matchp = match;
3786 check_time_syntax (struct berval *val,
3790 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3791 static int mdays[2][12] = {
3792 /* non-leap years */
3793 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3795 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3798 int part, c, tzoffset, leapyear = 0 ;
3800 if( val->bv_len == 0 ) {
3801 return LDAP_INVALID_SYNTAX;
3804 p = (char *)val->bv_val;
3805 e = p + val->bv_len;
3807 /* Ignore initial whitespace */
3808 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3812 if (e - p < 13 - (2 * start)) {
3813 return LDAP_INVALID_SYNTAX;
3816 for (part = 0; part < 9; part++) {
3820 for (part = start; part < 7; part++) {
3822 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3829 return LDAP_INVALID_SYNTAX;
3831 if (c < 0 || c > 9) {
3832 return LDAP_INVALID_SYNTAX;
3838 return LDAP_INVALID_SYNTAX;
3840 if (c < 0 || c > 9) {
3841 return LDAP_INVALID_SYNTAX;
3846 if (part == 2 || part == 3) {
3849 if (parts[part] < 0) {
3850 return LDAP_INVALID_SYNTAX;
3852 if (parts[part] > ceiling[part]) {
3853 return LDAP_INVALID_SYNTAX;
3857 /* leapyear check for the Gregorian calendar (year>1581) */
3858 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3859 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3864 if (parts[3] > mdays[leapyear][parts[2]]) {
3865 return LDAP_INVALID_SYNTAX;
3870 tzoffset = 0; /* UTC */
3871 } else if (c != '+' && c != '-') {
3872 return LDAP_INVALID_SYNTAX;
3876 } else /* c == '+' */ {
3881 return LDAP_INVALID_SYNTAX;
3884 for (part = 7; part < 9; part++) {
3886 if (c < 0 || c > 9) {
3887 return LDAP_INVALID_SYNTAX;
3892 if (c < 0 || c > 9) {
3893 return LDAP_INVALID_SYNTAX;
3897 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3898 return LDAP_INVALID_SYNTAX;
3903 /* Ignore trailing whitespace */
3904 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3908 return LDAP_INVALID_SYNTAX;
3911 switch ( tzoffset ) {
3912 case -1: /* negativ offset to UTC, ie west of Greenwich */
3913 parts[4] += parts[7];
3914 parts[5] += parts[8];
3915 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3919 c = mdays[leapyear][parts[2]];
3921 if (parts[part] > c) {
3922 parts[part] -= c + 1;
3927 case 1: /* positive offset to UTC, ie east of Greenwich */
3928 parts[4] -= parts[7];
3929 parts[5] -= parts[8];
3930 for (part = 6; --part > 0; ) {
3934 /* first arg to % needs to be non negativ */
3935 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3937 if (parts[part] < 0) {
3938 parts[part] += c + 1;
3943 case 0: /* already UTC */
3947 return LDAP_SUCCESS;
3954 struct berval **normalized )
3959 rc = check_time_syntax(val, 1, parts);
3960 if (rc != LDAP_SUCCESS) {
3965 out = ch_malloc( sizeof(struct berval) );
3967 return LBER_ERROR_MEMORY;
3970 out->bv_val = ch_malloc( 14 );
3971 if ( out->bv_val == NULL ) {
3973 return LBER_ERROR_MEMORY;
3976 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3977 parts[1], parts[2] + 1, parts[3] + 1,
3978 parts[4], parts[5], parts[6] );
3982 return LDAP_SUCCESS;
3992 return check_time_syntax(in, 1, parts);
3996 generalizedTimeValidate(
4002 return check_time_syntax(in, 0, parts);
4006 generalizedTimeNormalize(
4009 struct berval **normalized )
4014 rc = check_time_syntax(val, 0, parts);
4015 if (rc != LDAP_SUCCESS) {
4020 out = ch_malloc( sizeof(struct berval) );
4022 return LBER_ERROR_MEMORY;
4025 out->bv_val = ch_malloc( 16 );
4026 if ( out->bv_val == NULL ) {
4028 return LBER_ERROR_MEMORY;
4031 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4032 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4033 parts[4], parts[5], parts[6] );
4037 return LDAP_SUCCESS;
4041 nisNetgroupTripleValidate(
4043 struct berval *val )
4048 if ( val->bv_len == 0 ) {
4049 return LDAP_INVALID_SYNTAX;
4052 p = (char *)val->bv_val;
4053 e = p + val->bv_len;
4056 /* syntax does not allow leading white space */
4057 /* Ignore initial whitespace */
4058 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4063 if ( *p != '(' /*')'*/ ) {
4064 return LDAP_INVALID_SYNTAX;
4067 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4071 return LDAP_INVALID_SYNTAX;
4074 } else if ( !ATTR_CHAR( *p ) ) {
4075 return LDAP_INVALID_SYNTAX;
4079 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4080 return LDAP_INVALID_SYNTAX;
4086 /* syntax does not allow trailing white space */
4087 /* Ignore trailing whitespace */
4088 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4094 return LDAP_INVALID_SYNTAX;
4097 return LDAP_SUCCESS;
4101 bootParameterValidate(
4103 struct berval *val )
4107 if ( val->bv_len == 0 ) {
4108 return LDAP_INVALID_SYNTAX;
4111 p = (char *)val->bv_val;
4112 e = p + val->bv_len;
4115 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4116 if ( !ATTR_CHAR( *p ) ) {
4117 return LDAP_INVALID_SYNTAX;
4122 return LDAP_INVALID_SYNTAX;
4126 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4127 if ( !ATTR_CHAR( *p ) ) {
4128 return LDAP_INVALID_SYNTAX;
4133 return LDAP_INVALID_SYNTAX;
4137 for ( p++; p < e; p++ ) {
4138 if ( !ATTR_CHAR( *p ) ) {
4139 return LDAP_INVALID_SYNTAX;
4143 return LDAP_SUCCESS;
4146 struct syntax_defs_rec {
4149 slap_syntax_validate_func *sd_validate;
4150 slap_syntax_transform_func *sd_normalize;
4151 slap_syntax_transform_func *sd_pretty;
4152 #ifdef SLAPD_BINARY_CONVERSION
4153 slap_syntax_transform_func *sd_ber2str;
4154 slap_syntax_transform_func *sd_str2ber;
4158 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4159 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4161 struct syntax_defs_rec syntax_defs[] = {
4162 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4163 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4164 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4165 0, NULL, NULL, NULL},
4166 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4167 0, NULL, NULL, NULL},
4168 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4169 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4170 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4171 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4173 0, bitStringValidate, NULL, NULL },
4174 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4175 0, booleanValidate, NULL, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4177 X_BINARY X_NOT_H_R ")",
4178 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
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.10 DESC 'Certificate Pair' "
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.11 DESC 'Country String' )",
4186 0, countryStringValidate, IA5StringNormalize, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4188 0, dnValidate, dnNormalize, dnPretty},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4190 0, NULL, NULL, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4192 0, NULL, NULL, NULL},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4194 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4196 0, NULL, NULL, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4198 0, NULL, NULL, NULL},
4199 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4200 0, NULL, NULL, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4202 0, NULL, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4204 0, NULL, NULL, NULL},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4206 0, printablesStringValidate, IA5StringNormalize, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4208 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4210 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4212 0, NULL, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4214 0, IA5StringValidate, IA5StringNormalize, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4216 0, integerValidate, integerNormalize, integerPretty},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4218 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4220 0, NULL, NULL, NULL},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4222 0, NULL, NULL, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4224 0, NULL, NULL, NULL},
4225 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4226 0, NULL, NULL, NULL},
4227 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4228 0, NULL, NULL, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4230 0, nameUIDValidate, nameUIDNormalize, NULL},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4232 0, NULL, NULL, NULL},
4233 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4234 0, numericStringValidate, numericStringNormalize, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4236 0, NULL, NULL, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4238 0, oidValidate, NULL, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4240 0, IA5StringValidate, IA5StringNormalize, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4242 0, blobValidate, NULL, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4244 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4246 0, NULL, NULL, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4248 0, NULL, NULL, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4250 0, printableStringValidate, IA5StringNormalize, NULL},
4251 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4252 X_BINARY X_NOT_H_R ")",
4253 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4254 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4255 0, printableStringValidate, IA5StringNormalize, NULL},
4256 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4257 0, NULL, NULL, NULL},
4258 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4259 0, printableStringValidate, IA5StringNormalize, NULL},
4260 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4261 0, utcTimeValidate, utcTimeNormalize, NULL},
4262 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4263 0, NULL, NULL, NULL},
4264 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4265 0, NULL, NULL, NULL},
4266 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4267 0, NULL, NULL, NULL},
4268 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4269 0, NULL, NULL, NULL},
4270 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4271 0, NULL, NULL, NULL},
4273 /* RFC 2307 NIS Syntaxes */
4274 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4275 0, nisNetgroupTripleValidate, NULL, NULL},
4276 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4277 0, bootParameterValidate, NULL, NULL},
4279 /* OpenLDAP Experimental Syntaxes */
4280 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4281 0, UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4283 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4284 0, NULL, NULL, NULL},
4286 /* OpenLDAP Void Syntax */
4287 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4288 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4289 {NULL, 0, NULL, NULL, NULL}
4292 struct mrule_defs_rec {
4294 slap_mask_t mrd_usage;
4295 slap_mr_convert_func * mrd_convert;
4296 slap_mr_normalize_func * mrd_normalize;
4297 slap_mr_match_func * mrd_match;
4298 slap_mr_indexer_func * mrd_indexer;
4299 slap_mr_filter_func * mrd_filter;
4301 char * mrd_associated;
4305 * Other matching rules in X.520 that we do not use (yet):
4307 * 2.5.13.9 numericStringOrderingMatch
4308 * 2.5.13.15 integerOrderingMatch
4309 * 2.5.13.18 octetStringOrderingMatch
4310 * 2.5.13.19 octetStringSubstringsMatch
4311 * 2.5.13.25 uTCTimeMatch
4312 * 2.5.13.26 uTCTimeOrderingMatch
4313 * 2.5.13.31 directoryStringFirstComponentMatch
4314 * 2.5.13.32 wordMatch
4315 * 2.5.13.33 keywordMatch
4316 * 2.5.13.34 certificateExactMatch
4317 * 2.5.13.35 certificateMatch
4318 * 2.5.13.36 certificatePairExactMatch
4319 * 2.5.13.37 certificatePairMatch
4320 * 2.5.13.38 certificateListExactMatch
4321 * 2.5.13.39 certificateListMatch
4322 * 2.5.13.40 algorithmIdentifierMatch
4323 * 2.5.13.41 storedPrefixMatch
4324 * 2.5.13.42 attributeCertificateMatch
4325 * 2.5.13.43 readerAndKeyIDMatch
4326 * 2.5.13.44 attributeIntegrityMatch
4329 struct mrule_defs_rec mrule_defs[] = {
4331 * EQUALITY matching rules must be listed after associated APPROX
4332 * matching rules. So, we list all APPROX matching rules first.
4334 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4335 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4336 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4338 directoryStringApproxMatch,
4339 directoryStringApproxIndexer,
4340 directoryStringApproxFilter,
4343 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4344 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4345 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4347 IA5StringApproxMatch,
4348 IA5StringApproxIndexer,
4349 IA5StringApproxFilter,
4353 * Other matching rules
4356 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4357 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4358 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4360 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4363 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4364 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4365 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4367 dnMatch, dnIndexer, dnFilter,
4370 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4371 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4372 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4374 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4375 directoryStringApproxMatchOID },
4377 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4378 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4381 caseIgnoreOrderingMatch, NULL, NULL,
4384 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4385 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4386 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4388 caseIgnoreSubstringsMatch,
4389 caseIgnoreSubstringsIndexer,
4390 caseIgnoreSubstringsFilter,
4393 {"( 2.5.13.5 NAME 'caseExactMatch' "
4394 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4395 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4397 caseExactMatch, caseExactIndexer, caseExactFilter,
4398 directoryStringApproxMatchOID },
4400 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4401 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4404 caseExactOrderingMatch, NULL, NULL,
4407 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4408 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4409 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4411 caseExactSubstringsMatch,
4412 caseExactSubstringsIndexer,
4413 caseExactSubstringsFilter,
4416 {"( 2.5.13.8 NAME 'numericStringMatch' "
4417 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4418 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4421 caseIgnoreIA5Indexer,
4422 caseIgnoreIA5Filter,
4425 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4426 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4427 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4429 caseIgnoreIA5SubstringsMatch,
4430 caseIgnoreIA5SubstringsIndexer,
4431 caseIgnoreIA5SubstringsFilter,
4434 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4435 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4436 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4438 caseIgnoreListMatch, NULL, NULL,
4441 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4442 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4443 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4445 caseIgnoreListSubstringsMatch, NULL, NULL,
4448 {"( 2.5.13.13 NAME 'booleanMatch' "
4449 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4450 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4452 booleanMatch, NULL, NULL,
4455 {"( 2.5.13.14 NAME 'integerMatch' "
4456 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4457 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4459 integerMatch, integerIndexer, integerFilter,
4462 {"( 2.5.13.16 NAME 'bitStringMatch' "
4463 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4464 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4466 bitStringMatch, NULL, NULL,
4469 {"( 2.5.13.17 NAME 'octetStringMatch' "
4470 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4471 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4473 octetStringMatch, octetStringIndexer, octetStringFilter,
4476 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4477 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4478 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4480 telephoneNumberMatch, NULL, NULL,
4483 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4484 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4485 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4487 telephoneNumberSubstringsMatch, NULL, NULL,
4490 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4491 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4492 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4494 presentationAddressMatch, NULL, NULL,
4497 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4498 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4499 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4501 uniqueMemberMatch, NULL, NULL,
4504 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4505 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4506 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4508 protocolInformationMatch, NULL, NULL,
4511 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4512 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4513 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4515 generalizedTimeMatch, NULL, NULL,
4518 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4519 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4522 generalizedTimeOrderingMatch, NULL, NULL,
4525 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4526 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4527 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4529 integerFirstComponentMatch, NULL, NULL,
4532 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4533 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4534 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4536 objectIdentifierFirstComponentMatch, NULL, NULL,
4539 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4540 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4541 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4543 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4544 IA5StringApproxMatchOID },
4546 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4547 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4548 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4550 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4551 IA5StringApproxMatchOID },
4553 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4554 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4557 caseIgnoreIA5SubstringsMatch,
4558 caseIgnoreIA5SubstringsIndexer,
4559 caseIgnoreIA5SubstringsFilter,
4562 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4563 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4566 caseExactIA5SubstringsMatch,
4567 caseExactIA5SubstringsIndexer,
4568 caseExactIA5SubstringsFilter,
4571 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4572 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4575 authPasswordMatch, NULL, NULL,
4578 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4579 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4582 OpenLDAPaciMatch, NULL, NULL,
4585 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4594 /* we should only be called once (from main) */
4595 assert( schema_init_done == 0 );
4597 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4598 res = register_syntax( syntax_defs[i].sd_desc,
4599 syntax_defs[i].sd_flags,
4600 syntax_defs[i].sd_validate,
4601 syntax_defs[i].sd_normalize,
4602 syntax_defs[i].sd_pretty
4603 #ifdef SLAPD_BINARY_CONVERSION
4605 syntax_defs[i].sd_ber2str,
4606 syntax_defs[i].sd_str2ber
4611 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4612 syntax_defs[i].sd_desc );
4617 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4618 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4620 "schema_init: Ingoring unusable matching rule %s\n",
4621 mrule_defs[i].mrd_desc );
4625 res = register_matching_rule(
4626 mrule_defs[i].mrd_desc,
4627 mrule_defs[i].mrd_usage,
4628 mrule_defs[i].mrd_convert,
4629 mrule_defs[i].mrd_normalize,
4630 mrule_defs[i].mrd_match,
4631 mrule_defs[i].mrd_indexer,
4632 mrule_defs[i].mrd_filter,
4633 mrule_defs[i].mrd_associated );
4637 "schema_init: Error registering matching rule %s\n",
4638 mrule_defs[i].mrd_desc );
4642 schema_init_done = 1;
4643 return LDAP_SUCCESS;