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 /* recycled normalization routines */
43 #define faxNumberNormalize numericStringNormalize
44 #define phoneNumberNormalize numericStringNormalize
45 #define telexNumberNormalize numericStringNormalize
47 /* unimplemented pretters */
49 #define integerPretty NULL
51 /* recycled matching routines */
52 #define bitStringMatch octetStringMatch
53 #define integerMatch caseIgnoreIA5Match
54 #define numericStringMatch caseIgnoreMatch
55 #define objectIdentifierMatch numericStringMatch
56 #define telephoneNumberMatch numericStringMatch
57 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
58 #define generalizedTimeMatch numericStringMatch
59 #define generalizedTimeOrderingMatch numericStringMatch
60 #define uniqueMemberMatch dnMatch
62 /* approx matching rules */
63 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
64 #define directoryStringApproxMatch approxMatch
65 #define directoryStringApproxIndexer approxIndexer
66 #define directoryStringApproxFilter approxFilter
67 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
68 #define IA5StringApproxMatch approxMatch
69 #define IA5StringApproxIndexer approxIndexer
70 #define IA5StringApproxFilter approxFilter
72 /* orderring matching rules */
73 #define caseIgnoreOrderingMatch caseIgnoreMatch
74 #define caseExactOrderingMatch caseExactMatch
76 /* unimplemented matching routines */
77 #define caseIgnoreListMatch NULL
78 #define caseIgnoreListSubstringsMatch NULL
79 #define presentationAddressMatch NULL
80 #define protocolInformationMatch NULL
81 #define integerFirstComponentMatch NULL
83 #define OpenLDAPaciMatch NULL
84 #define authPasswordMatch NULL
86 /* recycled indexing/filtering routines */
87 #define dnIndexer caseIgnoreIndexer
88 #define dnFilter caseIgnoreFilter
89 #define integerIndexer caseIgnoreIA5Indexer
90 #define integerFilter caseIgnoreIA5Filter
92 static char *strcasechr( const char *str, int c )
94 char *lower = strchr( str, TOLOWER(c) );
95 char *upper = strchr( str, TOUPPER(c) );
97 if( lower && upper ) {
98 return lower < upper ? lower : upper;
112 struct berval *value,
113 void *assertedValue )
115 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
118 match = memcmp( value->bv_val,
119 ((struct berval *) assertedValue)->bv_val,
127 /* Index generation function */
128 int octetStringIndexer(
133 struct berval *prefix,
134 struct berval **values,
135 struct berval ***keysp )
139 struct berval **keys;
140 HASH_CONTEXT HASHcontext;
141 unsigned char HASHdigest[HASH_BYTES];
142 struct berval digest;
143 digest.bv_val = HASHdigest;
144 digest.bv_len = sizeof(HASHdigest);
146 /* we should have at least one value at this point */
147 assert( values != NULL && values[0] != NULL );
149 for( i=0; values[i] != NULL; i++ ) {
150 /* just count them */
153 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
155 slen = strlen( syntax->ssyn_oid );
156 mlen = strlen( mr->smr_oid );
158 for( i=0; values[i] != NULL; i++ ) {
159 HASH_Init( &HASHcontext );
160 if( prefix != NULL && prefix->bv_len > 0 ) {
161 HASH_Update( &HASHcontext,
162 prefix->bv_val, prefix->bv_len );
164 HASH_Update( &HASHcontext,
165 syntax->ssyn_oid, slen );
166 HASH_Update( &HASHcontext,
168 HASH_Update( &HASHcontext,
169 values[i]->bv_val, values[i]->bv_len );
170 HASH_Final( HASHdigest, &HASHcontext );
172 keys[i] = ber_bvdup( &digest );
182 /* Index generation function */
183 int octetStringFilter(
188 struct berval *prefix,
190 struct berval ***keysp )
193 struct berval **keys;
194 HASH_CONTEXT HASHcontext;
195 unsigned char HASHdigest[HASH_BYTES];
196 struct berval *value = (struct berval *) assertValue;
197 struct berval digest;
198 digest.bv_val = HASHdigest;
199 digest.bv_len = sizeof(HASHdigest);
201 slen = strlen( syntax->ssyn_oid );
202 mlen = strlen( mr->smr_oid );
204 keys = ch_malloc( sizeof( struct berval * ) * 2 );
206 HASH_Init( &HASHcontext );
207 if( prefix != NULL && prefix->bv_len > 0 ) {
208 HASH_Update( &HASHcontext,
209 prefix->bv_val, prefix->bv_len );
211 HASH_Update( &HASHcontext,
212 syntax->ssyn_oid, slen );
213 HASH_Update( &HASHcontext,
215 HASH_Update( &HASHcontext,
216 value->bv_val, value->bv_len );
217 HASH_Final( HASHdigest, &HASHcontext );
219 keys[0] = ber_bvdup( &digest );
235 if( in->bv_len == 0 ) return LDAP_SUCCESS;
237 dn = ch_strdup( in->bv_val );
239 rc = dn_validate( dn ) == NULL
240 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
250 struct berval **normalized )
252 struct berval *out = ber_bvdup( val );
254 if( out->bv_len != 0 ) {
256 #ifdef USE_DN_NORMALIZE
257 dn = dn_normalize( out->bv_val );
259 dn = dn_validate( out->bv_val );
264 return LDAP_INVALID_SYNTAX;
268 out->bv_len = strlen( dn );
281 struct berval *value,
282 void *assertedValue )
285 struct berval *asserted = (struct berval *) assertedValue;
287 match = value->bv_len - asserted->bv_len;
290 #ifdef USE_DN_NORMALIZE
291 match = strcmp( value->bv_val, asserted->bv_val );
293 match = strcasecmp( value->bv_val, asserted->bv_val );
297 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
298 match, value->bv_val, asserted->bv_val );
312 if( in->bv_len == 0 ) return LDAP_SUCCESS;
314 dn = ber_bvdup( in );
316 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
317 /* assume presence of optional UID */
320 for(i=dn->bv_len-2; i>2; i--) {
321 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
325 if( dn->bv_val[i] != '\'' ) {
326 return LDAP_INVALID_SYNTAX;
328 if( dn->bv_val[i-1] != 'B' ) {
329 return LDAP_INVALID_SYNTAX;
331 if( dn->bv_val[i-2] != '#' ) {
332 return LDAP_INVALID_SYNTAX;
335 /* trim the UID to allow use of dn_validate */
336 dn->bv_val[i-2] = '\0';
339 rc = dn_validate( dn->bv_val ) == NULL
340 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
350 struct berval **normalized )
352 struct berval *out = ber_bvdup( val );
354 if( out->bv_len != 0 ) {
358 ber_len_t uidlen = 0;
360 if( out->bv_val[out->bv_len-1] == '\'' ) {
361 /* assume presence of optional UID */
362 uid = strrchr( out->bv_val, '#' );
366 return LDAP_INVALID_SYNTAX;
369 uidlen = out->bv_len - (out->bv_val - uid);
370 /* temporarily trim the UID */
374 #ifdef USE_DN_NORMALIZE
375 dn = dn_normalize( out->bv_val );
377 dn = dn_validate( out->bv_val );
382 return LDAP_INVALID_SYNTAX;
388 /* restore the separator */
391 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
395 out->bv_len = dnlen + uidlen;
407 /* any value allowed */
416 /* any value allowed */
427 /* very unforgiving validation, requires no normalization
428 * before simplistic matching
430 if( in->bv_len < 3 ) {
431 return LDAP_INVALID_SYNTAX;
433 if( in->bv_val[0] != 'B' ||
434 in->bv_val[1] != '\'' ||
435 in->bv_val[in->bv_len-1] != '\'' )
437 return LDAP_INVALID_SYNTAX;
440 for( i=in->bv_len-2; i>1; i-- ) {
441 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
442 return LDAP_INVALID_SYNTAX;
450 * Handling boolean syntax and matching is quite rigid.
451 * A more flexible approach would be to allow a variety
452 * of strings to be normalized and prettied into TRUE
460 /* very unforgiving validation, requires no normalization
461 * before simplistic matching
464 if( in->bv_len == 4 ) {
465 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
468 } else if( in->bv_len == 5 ) {
469 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
474 return LDAP_INVALID_SYNTAX;
483 struct berval *value,
484 void *assertedValue )
486 /* simplistic matching allowed by rigid validation */
487 struct berval *asserted = (struct berval *) assertedValue;
488 *matchp = value->bv_len != asserted->bv_len;
495 struct berval *right,
496 struct berval *left )
500 ldap_unicode_t ru, lu;
501 ldap_unicode_t ruu, luu;
504 r < right->bv_len && l < left->bv_len;
508 * XXYYZ: we convert to ucs4 even though -llunicode
509 * expects ucs2 in an unsigned long
511 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
512 if( ru == LDAP_UCS4_INVALID ) {
516 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
517 if( lu == LDAP_UCS4_INVALID ) {
521 ruu = uctoupper( ru );
522 luu = uctoupper( lu );
526 } else if( luu > ruu ) {
530 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
531 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
534 if( r < right->bv_len ) {
539 if( l < left->bv_len ) {
547 /* case insensitive UTF8 strncmp with offset for second string */
550 struct berval *right,
558 ldap_unicode_t ru, lu;
559 ldap_unicode_t ruu, luu;
561 rslen = len < right->bv_len ? len : right->bv_len;
562 lslen = len + offset < left->bv_len ? len : left->bv_len;
564 for( r = 0, l = offset;
565 r < rslen && l < lslen;
569 * XXYYZ: we convert to ucs4 even though -llunicode
570 * expects ucs2 in an unsigned long
572 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
573 if( ru == LDAP_UCS4_INVALID ) {
577 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
578 if( lu == LDAP_UCS4_INVALID ) {
582 ruu = uctoupper( ru );
583 luu = uctoupper( lu );
587 } else if( luu > ruu ) {
591 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
592 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
608 static char *UTF8casechr( const char *str, const char *c )
610 char *p, *lower, *upper;
611 ldap_ucs4_t tch, ch = ldap_utf8_to_ucs4(c);
613 tch = uctolower ( ch );
614 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
615 if( ldap_utf8_to_ucs4( p ) == tch ) {
619 lower = *p != '\0' ? p : NULL;
621 tch = uctoupper ( ch );
622 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
623 if( ldap_utf8_to_ucs4( p ) == tch ) {
627 upper = *p != '\0' ? p : NULL;
629 if( lower && upper ) {
630 return lower < upper ? lower : upper;
631 } else if ( lower ) {
646 unsigned char *u = in->bv_val;
648 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
650 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
651 /* get the length indicated by the first byte */
652 len = LDAP_UTF8_CHARLEN( u );
654 /* should not be zero */
655 if( len == 0 ) return LDAP_INVALID_SYNTAX;
657 /* make sure len corresponds with the offset
658 to the next character */
659 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
662 if( count != 0 ) return LDAP_INVALID_SYNTAX;
671 struct berval **normalized )
673 struct berval *newval;
676 newval = ch_malloc( sizeof( struct berval ) );
680 /* Ignore initial whitespace */
681 while ( ldap_utf8_isspace( p ) ) {
687 return LDAP_INVALID_SYNTAX;
690 newval->bv_val = ch_strdup( p );
691 p = q = newval->bv_val;
697 if ( ldap_utf8_isspace( p ) ) {
698 len = LDAP_UTF8_COPY(q,p);
703 /* Ignore the extra whitespace */
704 while ( ldap_utf8_isspace( p ) ) {
708 len = LDAP_UTF8_COPY(q,p);
715 assert( *newval->bv_val );
716 assert( newval->bv_val < p );
719 /* cannot start with a space */
720 assert( !ldap_utf8_isspace(newval->bv_val) );
723 * If the string ended in space, backup the pointer one
724 * position. One is enough because the above loop collapsed
725 * all whitespace to a single space.
732 /* cannot end with a space */
733 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
738 newval->bv_len = q - newval->bv_val;
739 *normalized = newval;
744 #if defined(SLAPD_APPROX_MULTISTRING)
746 #if defined(SLAPD_APPROX_INITIALS)
747 #define SLAPD_APPROX_DELIMITER "._ "
748 #define SLAPD_APPROX_WORDLEN 2
750 #define SLAPD_APPROX_DELIMITER " "
751 #define SLAPD_APPROX_WORDLEN 1
760 struct berval *value,
761 void *assertedValue )
763 char *val, *assertv, **values, **words, *c;
764 int i, count, len, nextchunk=0, nextavail=0;
767 /* Isolate how many words there are */
768 val = ch_strdup( value->bv_val );
769 for( c=val,count=1; *c; c++ ) {
770 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
771 if ( c == NULL ) break;
776 /* Get a phonetic copy of each word */
777 words = (char **)ch_malloc( count * sizeof(char *) );
778 values = (char **)ch_malloc( count * sizeof(char *) );
779 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
781 values[i] = phonetic(c);
785 /* Work through the asserted value's words, to see if at least some
786 of the words are there, in the same order. */
787 assertv = ch_strdup( ((struct berval *)assertedValue)->bv_val );
789 while ( nextchunk < ((struct berval *)assertedValue)->bv_len ) {
790 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
791 #if defined(SLAPD_APPROX_INITIALS)
793 /* Single letter words need to at least match one word's initial */
794 for( i=nextavail; i<count; i++ )
795 if( !strncasecmp( assertv+nextchunk, words[i], 1 ))
802 /* Isolate the next word in the asserted value and phonetic it */
803 assertv[nextchunk+len] = '\0';
804 val = phonetic( assertv + nextchunk );
806 /* See if this phonetic chunk is in the remaining words of *value */
807 for( i=nextavail; i<count; i++ ){
808 if( !strcmp( val, values[i] ) ){
815 /* This chunk in the asserted value was NOT within the *value. */
821 /* Go on to the next word in the asserted value */
825 /* If some of the words were seen, call it a match */
826 if( nextavail > 0 ) {
835 for( i=0; i<count; i++ ) {
836 ch_free( values[i] );
852 struct berval *prefix,
853 struct berval **values,
854 struct berval ***keysp )
857 int i,j, len, wordcount, keycount=0;
858 struct berval **newkeys, **keys=NULL;
861 for( j=0; values[j] != NULL; j++ ) {
863 /* Isolate how many words there are. There will be a key for each */
864 val = ch_strdup( values[j]->bv_val );
865 for( wordcount=0,c=val; *c; c++) {
866 len = strcspn(c, SLAPD_APPROX_DELIMITER);
867 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
869 if (*c == '\0') break;
873 /* Allocate/increase storage to account for new keys */
874 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
875 * sizeof(struct berval *) );
876 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
877 if( keys ) ch_free( keys );
880 /* Get a phonetic copy of each word */
881 for( c=val,i=0; i<wordcount; c+=len+1 ) {
883 if( len < SLAPD_APPROX_WORDLEN ) continue;
884 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
885 keys[keycount]->bv_val = phonetic( c );
886 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
893 keys[keycount] = NULL;
906 struct berval *prefix,
908 struct berval ***keysp )
912 struct berval **keys;
915 /* Isolate how many words there are. There will be a key for each */
916 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
917 for( count=0,c=val; *c; c++) {
918 len = strcspn(c, SLAPD_APPROX_DELIMITER);
919 if( len >= SLAPD_APPROX_WORDLEN ) count++;
921 if (*c == '\0') break;
925 /* Allocate storage for new keys */
926 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
928 /* Get a phonetic copy of each word */
929 for( c=val,i=0; i<count; c+=len+1 ) {
931 if( len < SLAPD_APPROX_WORDLEN ) continue;
932 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
933 keys[i]->bv_val = phonetic( c );
934 keys[i]->bv_len = strlen( keys[i]->bv_val );
948 /* No other form of Approximate Matching is defined */
956 struct berval *value,
957 void *assertedValue )
959 char *vapprox, *avapprox;
961 vapprox = phonetic( value->bv_val );
962 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
964 *matchp = strcmp( vapprox, avapprox );
978 struct berval *prefix,
979 struct berval **values,
980 struct berval ***keysp )
983 struct berval **keys;
986 for( i=0; values[i] != NULL; i++ ) {
987 /* just count them */
991 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
993 /* Copy each value and run it through phonetic() */
994 for( i=0; values[i] != NULL; i++ ) {
995 keys[i] = ch_malloc( sizeof( struct berval * ) );
996 keys[i]->bv_val = phonetic( values[i]->bv_val );
997 keys[i]->bv_len = strlen( keys[i]->bv_val );
1002 return LDAP_SUCCESS;
1012 struct berval *prefix,
1014 struct berval ***keysp )
1016 struct berval **keys;
1019 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1021 /* Copy the value and run it through phonetic() */
1022 keys[0] = ch_malloc( sizeof( struct berval * ) );
1023 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
1024 keys[0]->bv_len = strlen( keys[0]->bv_val );
1028 return LDAP_SUCCESS;
1039 struct berval *value,
1040 void *assertedValue )
1042 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1045 match = strncmp( value->bv_val,
1046 ((struct berval *) assertedValue)->bv_val,
1051 return LDAP_SUCCESS;
1055 caseExactSubstringsMatch(
1060 struct berval *value,
1061 void *assertedValue )
1064 SubstringsAssertion *sub = assertedValue;
1065 struct berval left = *value;
1069 /* Add up asserted input length */
1070 if( sub->sa_initial ) {
1071 inlen += sub->sa_initial->bv_len;
1074 for(i=0; sub->sa_any[i] != NULL; i++) {
1075 inlen += sub->sa_any[i]->bv_len;
1078 if( sub->sa_final ) {
1079 inlen += sub->sa_final->bv_len;
1082 if( sub->sa_initial ) {
1083 if( inlen > left.bv_len ) {
1088 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1089 sub->sa_initial->bv_len );
1095 left.bv_val += sub->sa_initial->bv_len;
1096 left.bv_len -= sub->sa_initial->bv_len;
1097 inlen -= sub->sa_initial->bv_len;
1100 if( sub->sa_final ) {
1101 if( inlen > left.bv_len ) {
1106 match = strncmp( sub->sa_final->bv_val,
1107 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1108 sub->sa_final->bv_len );
1114 left.bv_len -= sub->sa_final->bv_len;
1115 inlen -= sub->sa_final->bv_len;
1119 for(i=0; sub->sa_any[i]; i++) {
1124 if( inlen > left.bv_len ) {
1125 /* not enough length */
1130 if( sub->sa_any[i]->bv_len == 0 ) {
1134 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1141 idx = p - left.bv_val;
1142 assert( idx < left.bv_len );
1144 if( idx >= left.bv_len ) {
1145 /* this shouldn't happen */
1152 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1153 /* not enough left */
1158 match = strncmp( left.bv_val,
1159 sub->sa_any[i]->bv_val,
1160 sub->sa_any[i]->bv_len );
1168 left.bv_val += sub->sa_any[i]->bv_len;
1169 left.bv_len -= sub->sa_any[i]->bv_len;
1170 inlen -= sub->sa_any[i]->bv_len;
1176 return LDAP_SUCCESS;
1179 /* Index generation function */
1180 int caseExactIndexer(
1185 struct berval *prefix,
1186 struct berval **values,
1187 struct berval ***keysp )
1191 struct berval **keys;
1192 HASH_CONTEXT HASHcontext;
1193 unsigned char HASHdigest[HASH_BYTES];
1194 struct berval digest;
1195 digest.bv_val = HASHdigest;
1196 digest.bv_len = sizeof(HASHdigest);
1198 /* we should have at least one value at this point */
1199 assert( values != NULL && values[0] != NULL );
1201 for( i=0; values[i] != NULL; i++ ) {
1202 /* just count them */
1205 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1207 slen = strlen( syntax->ssyn_oid );
1208 mlen = strlen( mr->smr_oid );
1210 for( i=0; values[i] != NULL; i++ ) {
1211 struct berval *value = values[i];
1213 HASH_Init( &HASHcontext );
1214 if( prefix != NULL && prefix->bv_len > 0 ) {
1215 HASH_Update( &HASHcontext,
1216 prefix->bv_val, prefix->bv_len );
1218 HASH_Update( &HASHcontext,
1219 syntax->ssyn_oid, slen );
1220 HASH_Update( &HASHcontext,
1221 mr->smr_oid, mlen );
1222 HASH_Update( &HASHcontext,
1223 value->bv_val, value->bv_len );
1224 HASH_Final( HASHdigest, &HASHcontext );
1226 keys[i] = ber_bvdup( &digest );
1231 return LDAP_SUCCESS;
1234 /* Index generation function */
1235 int caseExactFilter(
1240 struct berval *prefix,
1242 struct berval ***keysp )
1245 struct berval **keys;
1246 HASH_CONTEXT HASHcontext;
1247 unsigned char HASHdigest[HASH_BYTES];
1248 struct berval *value;
1249 struct berval digest;
1250 digest.bv_val = HASHdigest;
1251 digest.bv_len = sizeof(HASHdigest);
1253 slen = strlen( syntax->ssyn_oid );
1254 mlen = strlen( mr->smr_oid );
1256 value = (struct berval *) assertValue;
1258 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1260 HASH_Init( &HASHcontext );
1261 if( prefix != NULL && prefix->bv_len > 0 ) {
1262 HASH_Update( &HASHcontext,
1263 prefix->bv_val, prefix->bv_len );
1265 HASH_Update( &HASHcontext,
1266 syntax->ssyn_oid, slen );
1267 HASH_Update( &HASHcontext,
1268 mr->smr_oid, mlen );
1269 HASH_Update( &HASHcontext,
1270 value->bv_val, value->bv_len );
1271 HASH_Final( HASHdigest, &HASHcontext );
1273 keys[0] = ber_bvdup( &digest );
1277 return LDAP_SUCCESS;
1280 /* Substrings Index generation function */
1281 int caseExactSubstringsIndexer(
1286 struct berval *prefix,
1287 struct berval **values,
1288 struct berval ***keysp )
1292 struct berval **keys;
1293 HASH_CONTEXT HASHcontext;
1294 unsigned char HASHdigest[HASH_BYTES];
1295 struct berval digest;
1296 digest.bv_val = HASHdigest;
1297 digest.bv_len = sizeof(HASHdigest);
1299 /* we should have at least one value at this point */
1300 assert( values != NULL && values[0] != NULL );
1303 for( i=0; values[i] != NULL; i++ ) {
1304 /* count number of indices to generate */
1305 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1309 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1310 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1311 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1312 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1314 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1318 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1319 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1320 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1324 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1325 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1326 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1327 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1329 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1335 /* no keys to generate */
1337 return LDAP_SUCCESS;
1340 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1342 slen = strlen( syntax->ssyn_oid );
1343 mlen = strlen( mr->smr_oid );
1346 for( i=0; values[i] != NULL; i++ ) {
1348 struct berval *value;
1351 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1353 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1354 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1356 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1357 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1359 for( j=0; j<max; j++ ) {
1360 HASH_Init( &HASHcontext );
1361 if( prefix != NULL && prefix->bv_len > 0 ) {
1362 HASH_Update( &HASHcontext,
1363 prefix->bv_val, prefix->bv_len );
1366 HASH_Update( &HASHcontext,
1367 &pre, sizeof( pre ) );
1368 HASH_Update( &HASHcontext,
1369 syntax->ssyn_oid, slen );
1370 HASH_Update( &HASHcontext,
1371 mr->smr_oid, mlen );
1372 HASH_Update( &HASHcontext,
1374 SLAP_INDEX_SUBSTR_MAXLEN );
1375 HASH_Final( HASHdigest, &HASHcontext );
1377 keys[nkeys++] = ber_bvdup( &digest );
1381 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1382 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1384 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1387 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1388 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1389 HASH_Init( &HASHcontext );
1390 if( prefix != NULL && prefix->bv_len > 0 ) {
1391 HASH_Update( &HASHcontext,
1392 prefix->bv_val, prefix->bv_len );
1394 HASH_Update( &HASHcontext,
1395 &pre, sizeof( pre ) );
1396 HASH_Update( &HASHcontext,
1397 syntax->ssyn_oid, slen );
1398 HASH_Update( &HASHcontext,
1399 mr->smr_oid, mlen );
1400 HASH_Update( &HASHcontext,
1402 HASH_Final( HASHdigest, &HASHcontext );
1404 keys[nkeys++] = ber_bvdup( &digest );
1407 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1408 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1409 HASH_Init( &HASHcontext );
1410 if( prefix != NULL && prefix->bv_len > 0 ) {
1411 HASH_Update( &HASHcontext,
1412 prefix->bv_val, prefix->bv_len );
1414 HASH_Update( &HASHcontext,
1415 &pre, sizeof( pre ) );
1416 HASH_Update( &HASHcontext,
1417 syntax->ssyn_oid, slen );
1418 HASH_Update( &HASHcontext,
1419 mr->smr_oid, mlen );
1420 HASH_Update( &HASHcontext,
1421 &value->bv_val[value->bv_len-j], j );
1422 HASH_Final( HASHdigest, &HASHcontext );
1424 keys[nkeys++] = ber_bvdup( &digest );
1438 return LDAP_SUCCESS;
1441 int caseExactSubstringsFilter(
1446 struct berval *prefix,
1448 struct berval ***keysp )
1450 SubstringsAssertion *sa = assertValue;
1452 ber_len_t nkeys = 0;
1453 size_t slen, mlen, klen;
1454 struct berval **keys;
1455 HASH_CONTEXT HASHcontext;
1456 unsigned char HASHdigest[HASH_BYTES];
1457 struct berval *value;
1458 struct berval digest;
1460 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1461 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1466 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1468 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1469 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1470 /* don't bother accounting for stepping */
1471 nkeys += sa->sa_any[i]->bv_len -
1472 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1477 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1478 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1485 return LDAP_SUCCESS;
1488 digest.bv_val = HASHdigest;
1489 digest.bv_len = sizeof(HASHdigest);
1491 slen = strlen( syntax->ssyn_oid );
1492 mlen = strlen( mr->smr_oid );
1494 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1497 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1498 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1500 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1501 value = sa->sa_initial;
1503 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1504 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1506 HASH_Init( &HASHcontext );
1507 if( prefix != NULL && prefix->bv_len > 0 ) {
1508 HASH_Update( &HASHcontext,
1509 prefix->bv_val, prefix->bv_len );
1511 HASH_Update( &HASHcontext,
1512 &pre, sizeof( pre ) );
1513 HASH_Update( &HASHcontext,
1514 syntax->ssyn_oid, slen );
1515 HASH_Update( &HASHcontext,
1516 mr->smr_oid, mlen );
1517 HASH_Update( &HASHcontext,
1518 value->bv_val, klen );
1519 HASH_Final( HASHdigest, &HASHcontext );
1521 keys[nkeys++] = ber_bvdup( &digest );
1524 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1526 pre = SLAP_INDEX_SUBSTR_PREFIX;
1527 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1529 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1530 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1534 value = sa->sa_any[i];
1537 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1538 j += SLAP_INDEX_SUBSTR_STEP )
1540 HASH_Init( &HASHcontext );
1541 if( prefix != NULL && prefix->bv_len > 0 ) {
1542 HASH_Update( &HASHcontext,
1543 prefix->bv_val, prefix->bv_len );
1545 HASH_Update( &HASHcontext,
1546 &pre, sizeof( pre ) );
1547 HASH_Update( &HASHcontext,
1548 syntax->ssyn_oid, slen );
1549 HASH_Update( &HASHcontext,
1550 mr->smr_oid, mlen );
1551 HASH_Update( &HASHcontext,
1552 &value->bv_val[j], klen );
1553 HASH_Final( HASHdigest, &HASHcontext );
1555 keys[nkeys++] = ber_bvdup( &digest );
1560 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1561 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1563 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1564 value = sa->sa_final;
1566 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1567 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1569 HASH_Init( &HASHcontext );
1570 if( prefix != NULL && prefix->bv_len > 0 ) {
1571 HASH_Update( &HASHcontext,
1572 prefix->bv_val, prefix->bv_len );
1574 HASH_Update( &HASHcontext,
1575 &pre, sizeof( pre ) );
1576 HASH_Update( &HASHcontext,
1577 syntax->ssyn_oid, slen );
1578 HASH_Update( &HASHcontext,
1579 mr->smr_oid, mlen );
1580 HASH_Update( &HASHcontext,
1581 &value->bv_val[value->bv_len-klen], klen );
1582 HASH_Final( HASHdigest, &HASHcontext );
1584 keys[nkeys++] = ber_bvdup( &digest );
1595 return LDAP_SUCCESS;
1604 struct berval *value,
1605 void *assertedValue )
1608 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1610 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1613 match = strncasecmp( value->bv_val,
1614 ((struct berval *) assertedValue)->bv_val,
1620 return LDAP_SUCCESS;
1624 caseIgnoreSubstringsMatch(
1629 struct berval *value,
1630 void *assertedValue )
1633 SubstringsAssertion *sub = assertedValue;
1634 struct berval left = *value;
1638 /* Add up asserted input length */
1639 if( sub->sa_initial ) {
1640 inlen += sub->sa_initial->bv_len;
1643 for(i=0; sub->sa_any[i] != NULL; i++) {
1644 inlen += sub->sa_any[i]->bv_len;
1647 if( sub->sa_final ) {
1648 inlen += sub->sa_final->bv_len;
1651 if( sub->sa_initial ) {
1652 if( inlen > left.bv_len ) {
1658 match = UTF8oncasecmp( sub->sa_initial, &left,
1659 sub->sa_initial->bv_len, 0 );
1661 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1662 sub->sa_initial->bv_len );
1669 left.bv_val += sub->sa_initial->bv_len;
1670 left.bv_len -= sub->sa_initial->bv_len;
1671 inlen -= sub->sa_initial->bv_len;
1674 if( sub->sa_final ) {
1675 if( inlen > left.bv_len ) {
1681 match = UTF8oncasecmp( sub->sa_final, &left,
1682 sub->sa_final->bv_len,
1683 left.bv_len - sub->sa_final->bv_len );
1685 match = strncasecmp( sub->sa_final->bv_val,
1686 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1687 sub->sa_final->bv_len );
1694 left.bv_len -= sub->sa_final->bv_len;
1695 inlen -= sub->sa_final->bv_len;
1699 for(i=0; sub->sa_any[i]; i++) {
1704 if( inlen > left.bv_len ) {
1705 /* not enough length */
1710 if( sub->sa_any[i]->bv_len == 0 ) {
1715 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1717 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1725 idx = p - left.bv_val;
1726 assert( idx < left.bv_len );
1728 if( idx >= left.bv_len ) {
1729 /* this shouldn't happen */
1736 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1737 /* not enough left */
1743 match = UTF8oncasecmp( &left, sub->sa_any[i],
1744 sub->sa_any[i]->bv_len, 0 );
1747 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1753 match = strncasecmp( left.bv_val,
1754 sub->sa_any[i]->bv_val,
1755 sub->sa_any[i]->bv_len );
1765 left.bv_val += sub->sa_any[i]->bv_len;
1766 left.bv_len -= sub->sa_any[i]->bv_len;
1767 inlen -= sub->sa_any[i]->bv_len;
1773 return LDAP_SUCCESS;
1776 /* Index generation function */
1777 int caseIgnoreIndexer(
1782 struct berval *prefix,
1783 struct berval **values,
1784 struct berval ***keysp )
1788 struct berval **keys;
1789 HASH_CONTEXT HASHcontext;
1790 unsigned char HASHdigest[HASH_BYTES];
1791 struct berval digest;
1792 digest.bv_val = HASHdigest;
1793 digest.bv_len = sizeof(HASHdigest);
1795 /* we should have at least one value at this point */
1796 assert( values != NULL && values[0] != NULL );
1798 for( i=0; values[i] != NULL; i++ ) {
1799 /* just count them */
1802 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1804 slen = strlen( syntax->ssyn_oid );
1805 mlen = strlen( mr->smr_oid );
1807 for( i=0; values[i] != NULL; i++ ) {
1808 struct berval *value = ber_bvdup( values[i] );
1809 ldap_pvt_str2upper( value->bv_val );
1811 HASH_Init( &HASHcontext );
1812 if( prefix != NULL && prefix->bv_len > 0 ) {
1813 HASH_Update( &HASHcontext,
1814 prefix->bv_val, prefix->bv_len );
1816 HASH_Update( &HASHcontext,
1817 syntax->ssyn_oid, slen );
1818 HASH_Update( &HASHcontext,
1819 mr->smr_oid, mlen );
1820 HASH_Update( &HASHcontext,
1821 value->bv_val, value->bv_len );
1822 HASH_Final( HASHdigest, &HASHcontext );
1824 ber_bvfree( value );
1826 keys[i] = ber_bvdup( &digest );
1831 return LDAP_SUCCESS;
1834 /* Index generation function */
1835 int caseIgnoreFilter(
1840 struct berval *prefix,
1842 struct berval ***keysp )
1845 struct berval **keys;
1846 HASH_CONTEXT HASHcontext;
1847 unsigned char HASHdigest[HASH_BYTES];
1848 struct berval *value;
1849 struct berval digest;
1850 digest.bv_val = HASHdigest;
1851 digest.bv_len = sizeof(HASHdigest);
1853 slen = strlen( syntax->ssyn_oid );
1854 mlen = strlen( mr->smr_oid );
1856 value = ber_bvdup( (struct berval *) assertValue );
1857 ldap_pvt_str2upper( value->bv_val );
1859 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1861 HASH_Init( &HASHcontext );
1862 if( prefix != NULL && prefix->bv_len > 0 ) {
1863 HASH_Update( &HASHcontext,
1864 prefix->bv_val, prefix->bv_len );
1866 HASH_Update( &HASHcontext,
1867 syntax->ssyn_oid, slen );
1868 HASH_Update( &HASHcontext,
1869 mr->smr_oid, mlen );
1870 HASH_Update( &HASHcontext,
1871 value->bv_val, value->bv_len );
1872 HASH_Final( HASHdigest, &HASHcontext );
1874 keys[0] = ber_bvdup( &digest );
1877 ber_bvfree( value );
1881 return LDAP_SUCCESS;
1884 /* Substrings Index generation function */
1885 int caseIgnoreSubstringsIndexer(
1890 struct berval *prefix,
1891 struct berval **values,
1892 struct berval ***keysp )
1896 struct berval **keys;
1897 HASH_CONTEXT HASHcontext;
1898 unsigned char HASHdigest[HASH_BYTES];
1899 struct berval digest;
1900 digest.bv_val = HASHdigest;
1901 digest.bv_len = sizeof(HASHdigest);
1903 /* we should have at least one value at this point */
1904 assert( values != NULL && values[0] != NULL );
1907 for( i=0; values[i] != NULL; i++ ) {
1908 /* count number of indices to generate */
1909 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1913 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1914 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1915 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1916 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1918 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1922 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1923 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1924 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1928 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
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 );
1939 /* no keys to generate */
1941 return LDAP_SUCCESS;
1944 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1946 slen = strlen( syntax->ssyn_oid );
1947 mlen = strlen( mr->smr_oid );
1950 for( i=0; values[i] != NULL; i++ ) {
1952 struct berval *value;
1954 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1956 value = ber_bvdup( values[i] );
1957 ldap_pvt_str2upper( value->bv_val );
1959 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1960 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1962 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1963 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1965 for( j=0; j<max; j++ ) {
1966 HASH_Init( &HASHcontext );
1967 if( prefix != NULL && prefix->bv_len > 0 ) {
1968 HASH_Update( &HASHcontext,
1969 prefix->bv_val, prefix->bv_len );
1972 HASH_Update( &HASHcontext,
1973 &pre, sizeof( pre ) );
1974 HASH_Update( &HASHcontext,
1975 syntax->ssyn_oid, slen );
1976 HASH_Update( &HASHcontext,
1977 mr->smr_oid, mlen );
1978 HASH_Update( &HASHcontext,
1980 SLAP_INDEX_SUBSTR_MAXLEN );
1981 HASH_Final( HASHdigest, &HASHcontext );
1983 keys[nkeys++] = ber_bvdup( &digest );
1987 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1988 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1990 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1993 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1994 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1995 HASH_Init( &HASHcontext );
1996 if( prefix != NULL && prefix->bv_len > 0 ) {
1997 HASH_Update( &HASHcontext,
1998 prefix->bv_val, prefix->bv_len );
2000 HASH_Update( &HASHcontext,
2001 &pre, sizeof( pre ) );
2002 HASH_Update( &HASHcontext,
2003 syntax->ssyn_oid, slen );
2004 HASH_Update( &HASHcontext,
2005 mr->smr_oid, mlen );
2006 HASH_Update( &HASHcontext,
2008 HASH_Final( HASHdigest, &HASHcontext );
2010 keys[nkeys++] = ber_bvdup( &digest );
2013 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2014 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2015 HASH_Init( &HASHcontext );
2016 if( prefix != NULL && prefix->bv_len > 0 ) {
2017 HASH_Update( &HASHcontext,
2018 prefix->bv_val, prefix->bv_len );
2020 HASH_Update( &HASHcontext,
2021 &pre, sizeof( pre ) );
2022 HASH_Update( &HASHcontext,
2023 syntax->ssyn_oid, slen );
2024 HASH_Update( &HASHcontext,
2025 mr->smr_oid, mlen );
2026 HASH_Update( &HASHcontext,
2027 &value->bv_val[value->bv_len-j], j );
2028 HASH_Final( HASHdigest, &HASHcontext );
2030 keys[nkeys++] = ber_bvdup( &digest );
2035 ber_bvfree( value );
2046 return LDAP_SUCCESS;
2049 int caseIgnoreSubstringsFilter(
2054 struct berval *prefix,
2056 struct berval ***keysp )
2058 SubstringsAssertion *sa = assertValue;
2060 ber_len_t nkeys = 0;
2061 size_t slen, mlen, klen;
2062 struct berval **keys;
2063 HASH_CONTEXT HASHcontext;
2064 unsigned char HASHdigest[HASH_BYTES];
2065 struct berval *value;
2066 struct berval digest;
2068 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2069 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2074 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2076 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2077 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2078 /* don't bother accounting for stepping */
2079 nkeys += sa->sa_any[i]->bv_len -
2080 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2085 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2086 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2093 return LDAP_SUCCESS;
2096 digest.bv_val = HASHdigest;
2097 digest.bv_len = sizeof(HASHdigest);
2099 slen = strlen( syntax->ssyn_oid );
2100 mlen = strlen( mr->smr_oid );
2102 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2105 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2106 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2108 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2109 value = ber_bvdup( sa->sa_initial );
2110 ldap_pvt_str2upper( value->bv_val );
2112 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2113 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2115 HASH_Init( &HASHcontext );
2116 if( prefix != NULL && prefix->bv_len > 0 ) {
2117 HASH_Update( &HASHcontext,
2118 prefix->bv_val, prefix->bv_len );
2120 HASH_Update( &HASHcontext,
2121 &pre, sizeof( pre ) );
2122 HASH_Update( &HASHcontext,
2123 syntax->ssyn_oid, slen );
2124 HASH_Update( &HASHcontext,
2125 mr->smr_oid, mlen );
2126 HASH_Update( &HASHcontext,
2127 value->bv_val, klen );
2128 HASH_Final( HASHdigest, &HASHcontext );
2130 ber_bvfree( value );
2131 keys[nkeys++] = ber_bvdup( &digest );
2134 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2136 pre = SLAP_INDEX_SUBSTR_PREFIX;
2137 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2139 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2140 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2144 value = ber_bvdup( sa->sa_any[i] );
2145 ldap_pvt_str2upper( value->bv_val );
2148 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2149 j += SLAP_INDEX_SUBSTR_STEP )
2151 HASH_Init( &HASHcontext );
2152 if( prefix != NULL && prefix->bv_len > 0 ) {
2153 HASH_Update( &HASHcontext,
2154 prefix->bv_val, prefix->bv_len );
2156 HASH_Update( &HASHcontext,
2157 &pre, sizeof( pre ) );
2158 HASH_Update( &HASHcontext,
2159 syntax->ssyn_oid, slen );
2160 HASH_Update( &HASHcontext,
2161 mr->smr_oid, mlen );
2162 HASH_Update( &HASHcontext,
2163 &value->bv_val[j], klen );
2164 HASH_Final( HASHdigest, &HASHcontext );
2166 keys[nkeys++] = ber_bvdup( &digest );
2169 ber_bvfree( value );
2173 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2174 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2176 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2177 value = ber_bvdup( sa->sa_final );
2178 ldap_pvt_str2upper( value->bv_val );
2180 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2181 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
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[value->bv_len-klen], klen );
2196 HASH_Final( HASHdigest, &HASHcontext );
2198 ber_bvfree( value );
2199 keys[nkeys++] = ber_bvdup( &digest );
2210 return LDAP_SUCCESS;
2216 struct berval *val )
2220 if( val->bv_len == 0 ) return 0;
2222 if( OID_LEADCHAR(val->bv_val[0]) ) {
2224 for(i=1; i < val->bv_len; i++) {
2225 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2226 if( dot++ ) return 1;
2227 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2230 return LDAP_INVALID_SYNTAX;
2234 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2236 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2237 for(i=1; i < val->bv_len; i++) {
2238 if( !DESC_CHAR(val->bv_val[i] ) ) {
2239 return LDAP_INVALID_SYNTAX;
2243 return LDAP_SUCCESS;
2246 return LDAP_INVALID_SYNTAX;
2252 struct berval *val )
2256 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2258 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2259 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2260 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2261 return LDAP_INVALID_SYNTAX;
2264 for(i=1; i < val->bv_len; i++) {
2265 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2268 return LDAP_SUCCESS;
2275 struct berval **normalized )
2278 struct berval *newval;
2284 negative = ( *p == '-' );
2285 if( *p == '-' || *p == '+' ) p++;
2287 /* Ignore leading zeros */
2288 while ( *p == '0' ) p++;
2290 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2293 newval->bv_val = ch_strdup("0");
2298 newval->bv_val = ch_malloc( val->bv_len + 1 );
2302 newval->bv_val[newval->bv_len++] = '-';
2305 for( ; *p != '\0'; p++ ) {
2306 newval->bv_val[newval->bv_len++] = *p;
2310 *normalized = newval;
2311 return LDAP_SUCCESS;
2315 printableStringValidate(
2317 struct berval *val )
2321 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2323 for(i=0; i < val->bv_len; i++) {
2324 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2327 return LDAP_SUCCESS;
2333 struct berval *val )
2337 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2339 for(i=0; i < val->bv_len; i++) {
2340 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2343 return LDAP_SUCCESS;
2350 struct berval **normalized )
2352 struct berval *newval;
2355 newval = ch_malloc( sizeof( struct berval ) );
2359 /* Ignore initial whitespace */
2360 while ( ASCII_SPACE( *p ) ) {
2366 return LDAP_INVALID_SYNTAX;
2369 newval->bv_val = ch_strdup( p );
2370 p = q = newval->bv_val;
2373 if ( ASCII_SPACE( *p ) ) {
2376 /* Ignore the extra whitespace */
2377 while ( ASCII_SPACE( *p ) ) {
2385 assert( *newval->bv_val );
2386 assert( newval->bv_val < p );
2389 /* cannot start with a space */
2390 assert( !ASCII_SPACE(*newval->bv_val) );
2393 * If the string ended in space, backup the pointer one
2394 * position. One is enough because the above loop collapsed
2395 * all whitespace to a single space.
2398 if ( ASCII_SPACE( q[-1] ) ) {
2402 /* cannot end with a space */
2403 assert( !ASCII_SPACE( q[-1] ) );
2405 /* null terminate */
2408 newval->bv_len = q - newval->bv_val;
2409 *normalized = newval;
2411 return LDAP_SUCCESS;
2420 struct berval *value,
2421 void *assertedValue )
2423 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2426 match = strncmp( value->bv_val,
2427 ((struct berval *) assertedValue)->bv_val,
2432 return LDAP_SUCCESS;
2436 caseExactIA5SubstringsMatch(
2441 struct berval *value,
2442 void *assertedValue )
2445 SubstringsAssertion *sub = assertedValue;
2446 struct berval left = *value;
2450 /* Add up asserted input length */
2451 if( sub->sa_initial ) {
2452 inlen += sub->sa_initial->bv_len;
2455 for(i=0; sub->sa_any[i] != NULL; i++) {
2456 inlen += sub->sa_any[i]->bv_len;
2459 if( sub->sa_final ) {
2460 inlen += sub->sa_final->bv_len;
2463 if( sub->sa_initial ) {
2464 if( inlen > left.bv_len ) {
2469 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2470 sub->sa_initial->bv_len );
2476 left.bv_val += sub->sa_initial->bv_len;
2477 left.bv_len -= sub->sa_initial->bv_len;
2478 inlen -= sub->sa_initial->bv_len;
2481 if( sub->sa_final ) {
2482 if( inlen > left.bv_len ) {
2487 match = strncmp( sub->sa_final->bv_val,
2488 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2489 sub->sa_final->bv_len );
2495 left.bv_len -= sub->sa_final->bv_len;
2496 inlen -= sub->sa_final->bv_len;
2500 for(i=0; sub->sa_any[i]; i++) {
2505 if( inlen > left.bv_len ) {
2506 /* not enough length */
2511 if( sub->sa_any[i]->bv_len == 0 ) {
2515 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2522 idx = p - left.bv_val;
2523 assert( idx < left.bv_len );
2525 if( idx >= left.bv_len ) {
2526 /* this shouldn't happen */
2533 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2534 /* not enough left */
2539 match = strncmp( left.bv_val,
2540 sub->sa_any[i]->bv_val,
2541 sub->sa_any[i]->bv_len );
2549 left.bv_val += sub->sa_any[i]->bv_len;
2550 left.bv_len -= sub->sa_any[i]->bv_len;
2551 inlen -= sub->sa_any[i]->bv_len;
2557 return LDAP_SUCCESS;
2560 /* Index generation function */
2561 int caseExactIA5Indexer(
2566 struct berval *prefix,
2567 struct berval **values,
2568 struct berval ***keysp )
2572 struct berval **keys;
2573 HASH_CONTEXT HASHcontext;
2574 unsigned char HASHdigest[HASH_BYTES];
2575 struct berval digest;
2576 digest.bv_val = HASHdigest;
2577 digest.bv_len = sizeof(HASHdigest);
2579 /* we should have at least one value at this point */
2580 assert( values != NULL && values[0] != NULL );
2582 for( i=0; values[i] != NULL; i++ ) {
2583 /* just count them */
2586 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2588 slen = strlen( syntax->ssyn_oid );
2589 mlen = strlen( mr->smr_oid );
2591 for( i=0; values[i] != NULL; i++ ) {
2592 struct berval *value = values[i];
2594 HASH_Init( &HASHcontext );
2595 if( prefix != NULL && prefix->bv_len > 0 ) {
2596 HASH_Update( &HASHcontext,
2597 prefix->bv_val, prefix->bv_len );
2599 HASH_Update( &HASHcontext,
2600 syntax->ssyn_oid, slen );
2601 HASH_Update( &HASHcontext,
2602 mr->smr_oid, mlen );
2603 HASH_Update( &HASHcontext,
2604 value->bv_val, value->bv_len );
2605 HASH_Final( HASHdigest, &HASHcontext );
2607 keys[i] = ber_bvdup( &digest );
2612 return LDAP_SUCCESS;
2615 /* Index generation function */
2616 int caseExactIA5Filter(
2621 struct berval *prefix,
2623 struct berval ***keysp )
2626 struct berval **keys;
2627 HASH_CONTEXT HASHcontext;
2628 unsigned char HASHdigest[HASH_BYTES];
2629 struct berval *value;
2630 struct berval digest;
2631 digest.bv_val = HASHdigest;
2632 digest.bv_len = sizeof(HASHdigest);
2634 slen = strlen( syntax->ssyn_oid );
2635 mlen = strlen( mr->smr_oid );
2637 value = (struct berval *) assertValue;
2639 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2641 HASH_Init( &HASHcontext );
2642 if( prefix != NULL && prefix->bv_len > 0 ) {
2643 HASH_Update( &HASHcontext,
2644 prefix->bv_val, prefix->bv_len );
2646 HASH_Update( &HASHcontext,
2647 syntax->ssyn_oid, slen );
2648 HASH_Update( &HASHcontext,
2649 mr->smr_oid, mlen );
2650 HASH_Update( &HASHcontext,
2651 value->bv_val, value->bv_len );
2652 HASH_Final( HASHdigest, &HASHcontext );
2654 keys[0] = ber_bvdup( &digest );
2658 return LDAP_SUCCESS;
2661 /* Substrings Index generation function */
2662 int caseExactIA5SubstringsIndexer(
2667 struct berval *prefix,
2668 struct berval **values,
2669 struct berval ***keysp )
2673 struct berval **keys;
2674 HASH_CONTEXT HASHcontext;
2675 unsigned char HASHdigest[HASH_BYTES];
2676 struct berval digest;
2677 digest.bv_val = HASHdigest;
2678 digest.bv_len = sizeof(HASHdigest);
2680 /* we should have at least one value at this point */
2681 assert( values != NULL && values[0] != NULL );
2684 for( i=0; values[i] != NULL; i++ ) {
2685 /* count number of indices to generate */
2686 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2690 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2691 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2692 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2693 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2695 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2699 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2700 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2701 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2705 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2706 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2707 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2708 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2710 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2716 /* no keys to generate */
2718 return LDAP_SUCCESS;
2721 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2723 slen = strlen( syntax->ssyn_oid );
2724 mlen = strlen( mr->smr_oid );
2727 for( i=0; values[i] != NULL; i++ ) {
2729 struct berval *value;
2732 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2734 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2735 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2737 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2738 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2740 for( j=0; j<max; j++ ) {
2741 HASH_Init( &HASHcontext );
2742 if( prefix != NULL && prefix->bv_len > 0 ) {
2743 HASH_Update( &HASHcontext,
2744 prefix->bv_val, prefix->bv_len );
2747 HASH_Update( &HASHcontext,
2748 &pre, sizeof( pre ) );
2749 HASH_Update( &HASHcontext,
2750 syntax->ssyn_oid, slen );
2751 HASH_Update( &HASHcontext,
2752 mr->smr_oid, mlen );
2753 HASH_Update( &HASHcontext,
2755 SLAP_INDEX_SUBSTR_MAXLEN );
2756 HASH_Final( HASHdigest, &HASHcontext );
2758 keys[nkeys++] = ber_bvdup( &digest );
2762 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2763 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2765 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2768 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2769 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2770 HASH_Init( &HASHcontext );
2771 if( prefix != NULL && prefix->bv_len > 0 ) {
2772 HASH_Update( &HASHcontext,
2773 prefix->bv_val, prefix->bv_len );
2775 HASH_Update( &HASHcontext,
2776 &pre, sizeof( pre ) );
2777 HASH_Update( &HASHcontext,
2778 syntax->ssyn_oid, slen );
2779 HASH_Update( &HASHcontext,
2780 mr->smr_oid, mlen );
2781 HASH_Update( &HASHcontext,
2783 HASH_Final( HASHdigest, &HASHcontext );
2785 keys[nkeys++] = ber_bvdup( &digest );
2788 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2789 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2790 HASH_Init( &HASHcontext );
2791 if( prefix != NULL && prefix->bv_len > 0 ) {
2792 HASH_Update( &HASHcontext,
2793 prefix->bv_val, prefix->bv_len );
2795 HASH_Update( &HASHcontext,
2796 &pre, sizeof( pre ) );
2797 HASH_Update( &HASHcontext,
2798 syntax->ssyn_oid, slen );
2799 HASH_Update( &HASHcontext,
2800 mr->smr_oid, mlen );
2801 HASH_Update( &HASHcontext,
2802 &value->bv_val[value->bv_len-j], j );
2803 HASH_Final( HASHdigest, &HASHcontext );
2805 keys[nkeys++] = ber_bvdup( &digest );
2819 return LDAP_SUCCESS;
2822 int caseExactIA5SubstringsFilter(
2827 struct berval *prefix,
2829 struct berval ***keysp )
2831 SubstringsAssertion *sa = assertValue;
2833 ber_len_t nkeys = 0;
2834 size_t slen, mlen, klen;
2835 struct berval **keys;
2836 HASH_CONTEXT HASHcontext;
2837 unsigned char HASHdigest[HASH_BYTES];
2838 struct berval *value;
2839 struct berval digest;
2841 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2842 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2847 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2849 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2850 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2851 /* don't bother accounting for stepping */
2852 nkeys += sa->sa_any[i]->bv_len -
2853 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2858 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2859 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2866 return LDAP_SUCCESS;
2869 digest.bv_val = HASHdigest;
2870 digest.bv_len = sizeof(HASHdigest);
2872 slen = strlen( syntax->ssyn_oid );
2873 mlen = strlen( mr->smr_oid );
2875 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2878 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2879 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2881 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2882 value = sa->sa_initial;
2884 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2885 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2887 HASH_Init( &HASHcontext );
2888 if( prefix != NULL && prefix->bv_len > 0 ) {
2889 HASH_Update( &HASHcontext,
2890 prefix->bv_val, prefix->bv_len );
2892 HASH_Update( &HASHcontext,
2893 &pre, sizeof( pre ) );
2894 HASH_Update( &HASHcontext,
2895 syntax->ssyn_oid, slen );
2896 HASH_Update( &HASHcontext,
2897 mr->smr_oid, mlen );
2898 HASH_Update( &HASHcontext,
2899 value->bv_val, klen );
2900 HASH_Final( HASHdigest, &HASHcontext );
2902 keys[nkeys++] = ber_bvdup( &digest );
2905 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2907 pre = SLAP_INDEX_SUBSTR_PREFIX;
2908 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2910 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2911 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2915 value = sa->sa_any[i];
2918 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2919 j += SLAP_INDEX_SUBSTR_STEP )
2921 HASH_Init( &HASHcontext );
2922 if( prefix != NULL && prefix->bv_len > 0 ) {
2923 HASH_Update( &HASHcontext,
2924 prefix->bv_val, prefix->bv_len );
2926 HASH_Update( &HASHcontext,
2927 &pre, sizeof( pre ) );
2928 HASH_Update( &HASHcontext,
2929 syntax->ssyn_oid, slen );
2930 HASH_Update( &HASHcontext,
2931 mr->smr_oid, mlen );
2932 HASH_Update( &HASHcontext,
2933 &value->bv_val[j], klen );
2934 HASH_Final( HASHdigest, &HASHcontext );
2936 keys[nkeys++] = ber_bvdup( &digest );
2941 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2942 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2944 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2945 value = sa->sa_final;
2947 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2948 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2950 HASH_Init( &HASHcontext );
2951 if( prefix != NULL && prefix->bv_len > 0 ) {
2952 HASH_Update( &HASHcontext,
2953 prefix->bv_val, prefix->bv_len );
2955 HASH_Update( &HASHcontext,
2956 &pre, sizeof( pre ) );
2957 HASH_Update( &HASHcontext,
2958 syntax->ssyn_oid, slen );
2959 HASH_Update( &HASHcontext,
2960 mr->smr_oid, mlen );
2961 HASH_Update( &HASHcontext,
2962 &value->bv_val[value->bv_len-klen], klen );
2963 HASH_Final( HASHdigest, &HASHcontext );
2965 keys[nkeys++] = ber_bvdup( &digest );
2976 return LDAP_SUCCESS;
2985 struct berval *value,
2986 void *assertedValue )
2988 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2991 match = strncasecmp( value->bv_val,
2992 ((struct berval *) assertedValue)->bv_val,
2997 return LDAP_SUCCESS;
3001 caseIgnoreIA5SubstringsMatch(
3006 struct berval *value,
3007 void *assertedValue )
3010 SubstringsAssertion *sub = assertedValue;
3011 struct berval left = *value;
3015 /* Add up asserted input length */
3016 if( sub->sa_initial ) {
3017 inlen += sub->sa_initial->bv_len;
3020 for(i=0; sub->sa_any[i] != NULL; i++) {
3021 inlen += sub->sa_any[i]->bv_len;
3024 if( sub->sa_final ) {
3025 inlen += sub->sa_final->bv_len;
3028 if( sub->sa_initial ) {
3029 if( inlen > left.bv_len ) {
3034 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3035 sub->sa_initial->bv_len );
3041 left.bv_val += sub->sa_initial->bv_len;
3042 left.bv_len -= sub->sa_initial->bv_len;
3043 inlen -= sub->sa_initial->bv_len;
3046 if( sub->sa_final ) {
3047 if( inlen > left.bv_len ) {
3052 match = strncasecmp( sub->sa_final->bv_val,
3053 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3054 sub->sa_final->bv_len );
3060 left.bv_len -= sub->sa_final->bv_len;
3061 inlen -= sub->sa_final->bv_len;
3065 for(i=0; sub->sa_any[i]; i++) {
3070 if( inlen > left.bv_len ) {
3071 /* not enough length */
3076 if( sub->sa_any[i]->bv_len == 0 ) {
3080 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3087 idx = p - left.bv_val;
3088 assert( idx < left.bv_len );
3090 if( idx >= left.bv_len ) {
3091 /* this shouldn't happen */
3098 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3099 /* not enough left */
3104 match = strncasecmp( left.bv_val,
3105 sub->sa_any[i]->bv_val,
3106 sub->sa_any[i]->bv_len );
3115 left.bv_val += sub->sa_any[i]->bv_len;
3116 left.bv_len -= sub->sa_any[i]->bv_len;
3117 inlen -= sub->sa_any[i]->bv_len;
3123 return LDAP_SUCCESS;
3126 /* Index generation function */
3127 int caseIgnoreIA5Indexer(
3132 struct berval *prefix,
3133 struct berval **values,
3134 struct berval ***keysp )
3138 struct berval **keys;
3139 HASH_CONTEXT HASHcontext;
3140 unsigned char HASHdigest[HASH_BYTES];
3141 struct berval digest;
3142 digest.bv_val = HASHdigest;
3143 digest.bv_len = sizeof(HASHdigest);
3145 /* we should have at least one value at this point */
3146 assert( values != NULL && values[0] != NULL );
3148 for( i=0; values[i] != NULL; i++ ) {
3149 /* just count them */
3152 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3154 slen = strlen( syntax->ssyn_oid );
3155 mlen = strlen( mr->smr_oid );
3157 for( i=0; values[i] != NULL; i++ ) {
3158 struct berval *value = ber_bvdup( values[i] );
3159 ldap_pvt_str2upper( value->bv_val );
3161 HASH_Init( &HASHcontext );
3162 if( prefix != NULL && prefix->bv_len > 0 ) {
3163 HASH_Update( &HASHcontext,
3164 prefix->bv_val, prefix->bv_len );
3166 HASH_Update( &HASHcontext,
3167 syntax->ssyn_oid, slen );
3168 HASH_Update( &HASHcontext,
3169 mr->smr_oid, mlen );
3170 HASH_Update( &HASHcontext,
3171 value->bv_val, value->bv_len );
3172 HASH_Final( HASHdigest, &HASHcontext );
3174 ber_bvfree( value );
3176 keys[i] = ber_bvdup( &digest );
3181 return LDAP_SUCCESS;
3184 /* Index generation function */
3185 int caseIgnoreIA5Filter(
3190 struct berval *prefix,
3192 struct berval ***keysp )
3195 struct berval **keys;
3196 HASH_CONTEXT HASHcontext;
3197 unsigned char HASHdigest[HASH_BYTES];
3198 struct berval *value;
3199 struct berval digest;
3200 digest.bv_val = HASHdigest;
3201 digest.bv_len = sizeof(HASHdigest);
3203 slen = strlen( syntax->ssyn_oid );
3204 mlen = strlen( mr->smr_oid );
3206 value = ber_bvdup( (struct berval *) assertValue );
3207 ldap_pvt_str2upper( value->bv_val );
3209 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3211 HASH_Init( &HASHcontext );
3212 if( prefix != NULL && prefix->bv_len > 0 ) {
3213 HASH_Update( &HASHcontext,
3214 prefix->bv_val, prefix->bv_len );
3216 HASH_Update( &HASHcontext,
3217 syntax->ssyn_oid, slen );
3218 HASH_Update( &HASHcontext,
3219 mr->smr_oid, mlen );
3220 HASH_Update( &HASHcontext,
3221 value->bv_val, value->bv_len );
3222 HASH_Final( HASHdigest, &HASHcontext );
3224 keys[0] = ber_bvdup( &digest );
3227 ber_bvfree( value );
3231 return LDAP_SUCCESS;
3234 /* Substrings Index generation function */
3235 int caseIgnoreIA5SubstringsIndexer(
3240 struct berval *prefix,
3241 struct berval **values,
3242 struct berval ***keysp )
3246 struct berval **keys;
3247 HASH_CONTEXT HASHcontext;
3248 unsigned char HASHdigest[HASH_BYTES];
3249 struct berval digest;
3250 digest.bv_val = HASHdigest;
3251 digest.bv_len = sizeof(HASHdigest);
3253 /* we should have at least one value at this point */
3254 assert( values != NULL && values[0] != NULL );
3257 for( i=0; values[i] != NULL; i++ ) {
3258 /* count number of indices to generate */
3259 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3263 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3264 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3265 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3266 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3268 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3272 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3273 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3274 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3278 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3279 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3280 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3281 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3283 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3289 /* no keys to generate */
3291 return LDAP_SUCCESS;
3294 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3296 slen = strlen( syntax->ssyn_oid );
3297 mlen = strlen( mr->smr_oid );
3300 for( i=0; values[i] != NULL; i++ ) {
3302 struct berval *value;
3304 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3306 value = ber_bvdup( values[i] );
3307 ldap_pvt_str2upper( value->bv_val );
3309 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3310 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3312 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3313 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3315 for( j=0; j<max; j++ ) {
3316 HASH_Init( &HASHcontext );
3317 if( prefix != NULL && prefix->bv_len > 0 ) {
3318 HASH_Update( &HASHcontext,
3319 prefix->bv_val, prefix->bv_len );
3322 HASH_Update( &HASHcontext,
3323 &pre, sizeof( pre ) );
3324 HASH_Update( &HASHcontext,
3325 syntax->ssyn_oid, slen );
3326 HASH_Update( &HASHcontext,
3327 mr->smr_oid, mlen );
3328 HASH_Update( &HASHcontext,
3330 SLAP_INDEX_SUBSTR_MAXLEN );
3331 HASH_Final( HASHdigest, &HASHcontext );
3333 keys[nkeys++] = ber_bvdup( &digest );
3337 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3338 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3340 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3343 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3344 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3345 HASH_Init( &HASHcontext );
3346 if( prefix != NULL && prefix->bv_len > 0 ) {
3347 HASH_Update( &HASHcontext,
3348 prefix->bv_val, prefix->bv_len );
3350 HASH_Update( &HASHcontext,
3351 &pre, sizeof( pre ) );
3352 HASH_Update( &HASHcontext,
3353 syntax->ssyn_oid, slen );
3354 HASH_Update( &HASHcontext,
3355 mr->smr_oid, mlen );
3356 HASH_Update( &HASHcontext,
3358 HASH_Final( HASHdigest, &HASHcontext );
3360 keys[nkeys++] = ber_bvdup( &digest );
3363 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3364 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3365 HASH_Init( &HASHcontext );
3366 if( prefix != NULL && prefix->bv_len > 0 ) {
3367 HASH_Update( &HASHcontext,
3368 prefix->bv_val, prefix->bv_len );
3370 HASH_Update( &HASHcontext,
3371 &pre, sizeof( pre ) );
3372 HASH_Update( &HASHcontext,
3373 syntax->ssyn_oid, slen );
3374 HASH_Update( &HASHcontext,
3375 mr->smr_oid, mlen );
3376 HASH_Update( &HASHcontext,
3377 &value->bv_val[value->bv_len-j], j );
3378 HASH_Final( HASHdigest, &HASHcontext );
3380 keys[nkeys++] = ber_bvdup( &digest );
3385 ber_bvfree( value );
3396 return LDAP_SUCCESS;
3399 int caseIgnoreIA5SubstringsFilter(
3404 struct berval *prefix,
3406 struct berval ***keysp )
3408 SubstringsAssertion *sa = assertValue;
3410 ber_len_t nkeys = 0;
3411 size_t slen, mlen, klen;
3412 struct berval **keys;
3413 HASH_CONTEXT HASHcontext;
3414 unsigned char HASHdigest[HASH_BYTES];
3415 struct berval *value;
3416 struct berval digest;
3418 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3419 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3424 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3426 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3427 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3428 /* don't bother accounting for stepping */
3429 nkeys += sa->sa_any[i]->bv_len -
3430 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3435 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3436 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3443 return LDAP_SUCCESS;
3446 digest.bv_val = HASHdigest;
3447 digest.bv_len = sizeof(HASHdigest);
3449 slen = strlen( syntax->ssyn_oid );
3450 mlen = strlen( mr->smr_oid );
3452 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3455 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3456 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3458 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3459 value = ber_bvdup( sa->sa_initial );
3460 ldap_pvt_str2upper( value->bv_val );
3462 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3463 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3465 HASH_Init( &HASHcontext );
3466 if( prefix != NULL && prefix->bv_len > 0 ) {
3467 HASH_Update( &HASHcontext,
3468 prefix->bv_val, prefix->bv_len );
3470 HASH_Update( &HASHcontext,
3471 &pre, sizeof( pre ) );
3472 HASH_Update( &HASHcontext,
3473 syntax->ssyn_oid, slen );
3474 HASH_Update( &HASHcontext,
3475 mr->smr_oid, mlen );
3476 HASH_Update( &HASHcontext,
3477 value->bv_val, klen );
3478 HASH_Final( HASHdigest, &HASHcontext );
3480 ber_bvfree( value );
3481 keys[nkeys++] = ber_bvdup( &digest );
3484 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3486 pre = SLAP_INDEX_SUBSTR_PREFIX;
3487 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3489 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3490 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3494 value = ber_bvdup( sa->sa_any[i] );
3495 ldap_pvt_str2upper( value->bv_val );
3498 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3499 j += SLAP_INDEX_SUBSTR_STEP )
3501 HASH_Init( &HASHcontext );
3502 if( prefix != NULL && prefix->bv_len > 0 ) {
3503 HASH_Update( &HASHcontext,
3504 prefix->bv_val, prefix->bv_len );
3506 HASH_Update( &HASHcontext,
3507 &pre, sizeof( pre ) );
3508 HASH_Update( &HASHcontext,
3509 syntax->ssyn_oid, slen );
3510 HASH_Update( &HASHcontext,
3511 mr->smr_oid, mlen );
3512 HASH_Update( &HASHcontext,
3513 &value->bv_val[j], klen );
3514 HASH_Final( HASHdigest, &HASHcontext );
3516 keys[nkeys++] = ber_bvdup( &digest );
3519 ber_bvfree( value );
3523 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3524 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3526 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3527 value = ber_bvdup( sa->sa_final );
3528 ldap_pvt_str2upper( value->bv_val );
3530 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3531 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3533 HASH_Init( &HASHcontext );
3534 if( prefix != NULL && prefix->bv_len > 0 ) {
3535 HASH_Update( &HASHcontext,
3536 prefix->bv_val, prefix->bv_len );
3538 HASH_Update( &HASHcontext,
3539 &pre, sizeof( pre ) );
3540 HASH_Update( &HASHcontext,
3541 syntax->ssyn_oid, slen );
3542 HASH_Update( &HASHcontext,
3543 mr->smr_oid, mlen );
3544 HASH_Update( &HASHcontext,
3545 &value->bv_val[value->bv_len-klen], klen );
3546 HASH_Final( HASHdigest, &HASHcontext );
3548 ber_bvfree( value );
3549 keys[nkeys++] = ber_bvdup( &digest );
3560 return LDAP_SUCCESS;
3564 numericStringNormalize(
3567 struct berval **normalized )
3569 /* similiar to IA5StringNormalize except removes all spaces */
3570 struct berval *newval;
3573 newval = ch_malloc( sizeof( struct berval ) );
3577 /* Ignore initial whitespace */
3578 while ( ASCII_SPACE( *p ) ) {
3584 return LDAP_INVALID_SYNTAX;
3587 newval->bv_val = ch_strdup( p );
3588 p = q = newval->bv_val;
3591 if ( ASCII_SPACE( *p ) ) {
3592 /* Ignore whitespace */
3599 assert( *newval->bv_val );
3600 assert( newval->bv_val < p );
3603 /* cannot start with a space */
3604 assert( !ASCII_SPACE(*newval->bv_val) );
3606 /* cannot end with a space */
3607 assert( !ASCII_SPACE( q[-1] ) );
3609 /* null terminate */
3612 newval->bv_len = q - newval->bv_val;
3613 *normalized = newval;
3615 return LDAP_SUCCESS;
3619 objectIdentifierFirstComponentMatch(
3624 struct berval *value,
3625 void *assertedValue )
3627 int rc = LDAP_SUCCESS;
3629 struct berval *asserted = (struct berval *) assertedValue;
3633 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3634 return LDAP_INVALID_SYNTAX;
3637 /* trim leading white space */
3638 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3642 /* grab next word */
3643 oid.bv_val = &value->bv_val[i];
3644 oid.bv_len = value->bv_len - i;
3645 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3650 /* insert attributeTypes, objectclass check here */
3651 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3652 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3655 char *stored = ch_malloc( oid.bv_len + 1 );
3656 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3657 stored[oid.bv_len] = '\0';
3659 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3660 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3661 MatchingRule *stored_mr = mr_find( stored );
3663 if( asserted_mr == NULL ) {
3664 rc = SLAPD_COMPARE_UNDEFINED;
3666 match = asserted_mr != stored_mr;
3669 } else if ( !strcmp( syntax->ssyn_oid,
3670 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3672 AttributeType *asserted_at = at_find( asserted->bv_val );
3673 AttributeType *stored_at = at_find( stored );
3675 if( asserted_at == NULL ) {
3676 rc = SLAPD_COMPARE_UNDEFINED;
3678 match = asserted_at != stored_at;
3681 } else if ( !strcmp( syntax->ssyn_oid,
3682 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3684 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3685 ObjectClass *stored_oc = oc_find( stored );
3687 if( asserted_oc == NULL ) {
3688 rc = SLAPD_COMPARE_UNDEFINED;
3690 match = asserted_oc != stored_oc;
3697 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3698 "%d\n\t\"%s\"\n\t\"%s\"\n",
3699 match, value->bv_val, asserted->bv_val );
3701 if( rc == LDAP_SUCCESS ) *matchp = match;
3706 check_time_syntax (struct berval *val,
3710 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3711 static int mdays[2][12] = {
3712 /* non-leap years */
3713 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3715 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3718 int part, c, tzoffset, leapyear = 0 ;
3720 if( val->bv_len == 0 ) {
3721 return LDAP_INVALID_SYNTAX;
3724 p = (char *)val->bv_val;
3725 e = p + val->bv_len;
3727 /* Ignore initial whitespace */
3728 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3732 if (e - p < 13 - (2 * start)) {
3733 return LDAP_INVALID_SYNTAX;
3736 for (part = 0; part < 9; part++) {
3740 for (part = start; part < 7; part++) {
3742 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3749 return LDAP_INVALID_SYNTAX;
3751 if (c < 0 || c > 9) {
3752 return LDAP_INVALID_SYNTAX;
3758 return LDAP_INVALID_SYNTAX;
3760 if (c < 0 || c > 9) {
3761 return LDAP_INVALID_SYNTAX;
3766 if (part == 2 || part == 3) {
3769 if (parts[part] < 0) {
3770 return LDAP_INVALID_SYNTAX;
3772 if (parts[part] > ceiling[part]) {
3773 return LDAP_INVALID_SYNTAX;
3777 /* leapyear check for the Gregorian calendar (year>1581) */
3778 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3779 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3784 if (parts[3] > mdays[leapyear][parts[2]]) {
3785 return LDAP_INVALID_SYNTAX;
3790 tzoffset = 0; /* UTC */
3791 } else if (c != '+' && c != '-') {
3792 return LDAP_INVALID_SYNTAX;
3796 } else /* c == '+' */ {
3801 return LDAP_INVALID_SYNTAX;
3804 for (part = 7; part < 9; part++) {
3806 if (c < 0 || c > 9) {
3807 return LDAP_INVALID_SYNTAX;
3812 if (c < 0 || c > 9) {
3813 return LDAP_INVALID_SYNTAX;
3817 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3818 return LDAP_INVALID_SYNTAX;
3823 /* Ignore trailing whitespace */
3824 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3828 return LDAP_INVALID_SYNTAX;
3831 switch ( tzoffset ) {
3832 case -1: /* negativ offset to UTC, ie west of Greenwich */
3833 parts[4] += parts[7];
3834 parts[5] += parts[8];
3835 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3839 c = mdays[leapyear][parts[2]];
3841 if (parts[part] > c) {
3842 parts[part] -= c + 1;
3847 case 1: /* positive offset to UTC, ie east of Greenwich */
3848 parts[4] -= parts[7];
3849 parts[5] -= parts[8];
3850 for (part = 6; --part > 0; ) {
3854 /* first arg to % needs to be non negativ */
3855 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3857 if (parts[part] < 0) {
3858 parts[part] += c + 1;
3863 case 0: /* already UTC */
3867 return LDAP_SUCCESS;
3874 struct berval **normalized )
3879 rc = check_time_syntax(val, 1, parts);
3880 if (rc != LDAP_SUCCESS) {
3885 out = ch_malloc( sizeof(struct berval) );
3887 return LBER_ERROR_MEMORY;
3890 out->bv_val = ch_malloc( 14 );
3891 if ( out->bv_val == NULL ) {
3893 return LBER_ERROR_MEMORY;
3896 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3897 parts[1], parts[2] + 1, parts[3] + 1,
3898 parts[4], parts[5], parts[6] );
3902 return LDAP_SUCCESS;
3912 return check_time_syntax(in, 1, parts);
3916 generalizedTimeValidate(
3922 return check_time_syntax(in, 0, parts);
3926 generalizedTimeNormalize(
3929 struct berval **normalized )
3934 rc = check_time_syntax(val, 0, parts);
3935 if (rc != LDAP_SUCCESS) {
3940 out = ch_malloc( sizeof(struct berval) );
3942 return LBER_ERROR_MEMORY;
3945 out->bv_val = ch_malloc( 16 );
3946 if ( out->bv_val == NULL ) {
3948 return LBER_ERROR_MEMORY;
3951 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3952 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3953 parts[4], parts[5], parts[6] );
3957 return LDAP_SUCCESS;
3961 nisNetgroupTripleValidate(
3963 struct berval *val )
3968 if ( val->bv_len == 0 ) {
3969 return LDAP_INVALID_SYNTAX;
3972 p = (char *)val->bv_val;
3973 e = p + val->bv_len;
3976 /* syntax does not allow leading white space */
3977 /* Ignore initial whitespace */
3978 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3983 if ( *p != '(' /*')'*/ ) {
3984 return LDAP_INVALID_SYNTAX;
3987 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3991 return LDAP_INVALID_SYNTAX;
3994 } else if ( !ATTR_CHAR( *p ) ) {
3995 return LDAP_INVALID_SYNTAX;
3999 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4000 return LDAP_INVALID_SYNTAX;
4006 /* syntax does not allow trailing white space */
4007 /* Ignore trailing whitespace */
4008 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4014 return LDAP_INVALID_SYNTAX;
4017 return LDAP_SUCCESS;
4021 bootParameterValidate(
4023 struct berval *val )
4027 if ( val->bv_len == 0 ) {
4028 return LDAP_INVALID_SYNTAX;
4031 p = (char *)val->bv_val;
4032 e = p + val->bv_len;
4035 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4036 if ( !ATTR_CHAR( *p ) ) {
4037 return LDAP_INVALID_SYNTAX;
4042 return LDAP_INVALID_SYNTAX;
4046 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4047 if ( !ATTR_CHAR( *p ) ) {
4048 return LDAP_INVALID_SYNTAX;
4053 return LDAP_INVALID_SYNTAX;
4057 for ( p++; p < e; p++ ) {
4058 if ( !ATTR_CHAR( *p ) ) {
4059 return LDAP_INVALID_SYNTAX;
4063 return LDAP_SUCCESS;
4066 struct syntax_defs_rec {
4069 slap_syntax_validate_func *sd_validate;
4070 slap_syntax_transform_func *sd_normalize;
4071 slap_syntax_transform_func *sd_pretty;
4072 #ifdef SLAPD_BINARY_CONVERSION
4073 slap_syntax_transform_func *sd_ber2str;
4074 slap_syntax_transform_func *sd_str2ber;
4078 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4079 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4081 struct syntax_defs_rec syntax_defs[] = {
4082 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4083 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4084 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4085 0, NULL, NULL, NULL},
4086 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4087 0, NULL, NULL, NULL},
4088 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4089 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4090 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4091 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4092 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4093 0, bitStringValidate, NULL, NULL },
4094 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4095 0, booleanValidate, NULL, NULL},
4096 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4097 X_BINARY X_NOT_H_R ")",
4098 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4099 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4100 X_BINARY X_NOT_H_R ")",
4101 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4102 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4103 X_BINARY X_NOT_H_R ")",
4104 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4105 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4106 0, NULL, NULL, NULL},
4107 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4108 0, dnValidate, dnNormalize, dnPretty},
4109 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4110 0, NULL, NULL, NULL},
4111 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4112 0, NULL, NULL, NULL},
4113 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4114 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4115 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4116 0, NULL, NULL, NULL},
4117 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4118 0, NULL, NULL, NULL},
4119 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4120 0, NULL, NULL, NULL},
4121 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4122 0, NULL, NULL, NULL},
4123 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4124 0, NULL, NULL, NULL},
4125 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4126 0, IA5StringValidate, faxNumberNormalize, NULL},
4127 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4128 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4129 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4130 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4131 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4132 0, NULL, NULL, NULL},
4133 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4134 0, IA5StringValidate, IA5StringNormalize, NULL},
4135 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4136 0, integerValidate, integerNormalize, integerPretty},
4137 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4138 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4139 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4140 0, NULL, NULL, NULL},
4141 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4142 0, NULL, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4144 0, NULL, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4146 0, NULL, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4148 0, NULL, NULL, NULL},
4149 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4150 0, nameUIDValidate, nameUIDNormalize, NULL},
4151 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4152 0, NULL, NULL, NULL},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4154 0, IA5StringValidate, numericStringNormalize, NULL},
4155 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4156 0, NULL, NULL, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4158 0, oidValidate, NULL, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4160 0, NULL, NULL, NULL},
4161 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4162 0, blobValidate, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4164 0, blobValidate, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4166 0, NULL, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4168 0, NULL, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4170 0, printableStringValidate, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4172 X_BINARY X_NOT_H_R ")",
4173 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4175 0, IA5StringValidate, phoneNumberNormalize, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4177 0, NULL, NULL, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4179 0, IA5StringValidate, telexNumberNormalize, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4181 0, utcTimeValidate, utcTimeNormalize, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4183 0, NULL, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4185 0, NULL, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4187 0, NULL, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4189 0, NULL, NULL, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4191 0, NULL, NULL, NULL},
4193 /* RFC 2307 NIS Syntaxes */
4194 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4195 0, nisNetgroupTripleValidate, NULL, NULL},
4196 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4197 0, bootParameterValidate, NULL, NULL},
4199 /* OpenLDAP Experimental Syntaxes */
4200 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4201 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4203 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4204 0, NULL, NULL, NULL},
4206 /* OpenLDAP Void Syntax */
4207 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4208 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4209 {NULL, 0, NULL, NULL, NULL}
4212 struct mrule_defs_rec {
4214 slap_mask_t mrd_usage;
4215 slap_mr_convert_func * mrd_convert;
4216 slap_mr_normalize_func * mrd_normalize;
4217 slap_mr_match_func * mrd_match;
4218 slap_mr_indexer_func * mrd_indexer;
4219 slap_mr_filter_func * mrd_filter;
4221 char * mrd_associated;
4225 * Other matching rules in X.520 that we do not use (yet):
4227 * 2.5.13.9 numericStringOrderingMatch
4228 * 2.5.13.15 integerOrderingMatch
4229 * 2.5.13.18 octetStringOrderingMatch
4230 * 2.5.13.19 octetStringSubstringsMatch
4231 * 2.5.13.25 uTCTimeMatch
4232 * 2.5.13.26 uTCTimeOrderingMatch
4233 * 2.5.13.31 directoryStringFirstComponentMatch
4234 * 2.5.13.32 wordMatch
4235 * 2.5.13.33 keywordMatch
4236 * 2.5.13.34 certificateExactMatch
4237 * 2.5.13.35 certificateMatch
4238 * 2.5.13.36 certificatePairExactMatch
4239 * 2.5.13.37 certificatePairMatch
4240 * 2.5.13.38 certificateListExactMatch
4241 * 2.5.13.39 certificateListMatch
4242 * 2.5.13.40 algorithmIdentifierMatch
4243 * 2.5.13.41 storedPrefixMatch
4244 * 2.5.13.42 attributeCertificateMatch
4245 * 2.5.13.43 readerAndKeyIDMatch
4246 * 2.5.13.44 attributeIntegrityMatch
4249 struct mrule_defs_rec mrule_defs[] = {
4251 * EQUALITY matching rules must be listed after associated APPROX
4252 * matching rules. So, we list all APPROX matching rules first.
4254 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4255 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4256 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4258 directoryStringApproxMatch, directoryStringApproxIndexer,
4259 directoryStringApproxFilter,
4262 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4263 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4264 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4266 IA5StringApproxMatch, IA5StringApproxIndexer,
4267 IA5StringApproxFilter,
4271 * Other matching rules
4274 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4275 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4276 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4278 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4281 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4282 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4283 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4285 dnMatch, dnIndexer, dnFilter,
4288 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4289 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4290 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4292 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4293 directoryStringApproxMatchOID },
4295 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4296 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4299 caseIgnoreOrderingMatch, NULL, NULL,
4302 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4303 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4304 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4306 caseIgnoreSubstringsMatch,
4307 caseIgnoreSubstringsIndexer,
4308 caseIgnoreSubstringsFilter,
4311 {"( 2.5.13.5 NAME 'caseExactMatch' "
4312 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4313 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4315 caseExactMatch, caseExactIndexer, caseExactFilter,
4316 directoryStringApproxMatchOID },
4318 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4319 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4322 caseExactOrderingMatch, NULL, NULL,
4325 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4326 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4327 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4329 caseExactSubstringsMatch,
4330 caseExactSubstringsIndexer,
4331 caseExactSubstringsFilter,
4334 {"( 2.5.13.8 NAME 'numericStringMatch' "
4335 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4336 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4339 caseIgnoreIA5Indexer,
4340 caseIgnoreIA5Filter,
4343 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4344 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4345 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4347 caseIgnoreIA5SubstringsMatch,
4348 caseIgnoreIA5SubstringsIndexer,
4349 caseIgnoreIA5SubstringsFilter,
4352 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4353 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4354 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4356 caseIgnoreListMatch, NULL, NULL,
4359 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4360 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4361 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4363 caseIgnoreListSubstringsMatch, NULL, NULL,
4366 {"( 2.5.13.13 NAME 'booleanMatch' "
4367 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4368 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4370 booleanMatch, NULL, NULL,
4373 {"( 2.5.13.14 NAME 'integerMatch' "
4374 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4375 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4377 integerMatch, integerIndexer, integerFilter,
4380 {"( 2.5.13.16 NAME 'bitStringMatch' "
4381 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4382 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4384 bitStringMatch, NULL, NULL,
4387 {"( 2.5.13.17 NAME 'octetStringMatch' "
4388 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4389 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4391 octetStringMatch, octetStringIndexer, octetStringFilter,
4394 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4395 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4396 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4398 telephoneNumberMatch, NULL, NULL,
4401 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4402 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4403 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4405 telephoneNumberSubstringsMatch, NULL, NULL,
4408 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4409 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4410 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4412 presentationAddressMatch, NULL, NULL,
4415 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4416 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4417 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4419 uniqueMemberMatch, NULL, NULL,
4422 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4423 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4424 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4426 protocolInformationMatch, NULL, NULL,
4429 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4430 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4431 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4433 generalizedTimeMatch, NULL, NULL,
4436 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4437 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4440 generalizedTimeOrderingMatch, NULL, NULL,
4443 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4444 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4445 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4447 integerFirstComponentMatch, NULL, NULL,
4450 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4451 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4452 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4454 objectIdentifierFirstComponentMatch, NULL, NULL,
4457 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4458 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4459 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4461 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4462 IA5StringApproxMatchOID },
4464 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4465 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4466 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4468 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4469 IA5StringApproxMatchOID },
4471 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4472 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4475 caseIgnoreIA5SubstringsMatch,
4476 caseIgnoreIA5SubstringsIndexer,
4477 caseIgnoreIA5SubstringsFilter,
4480 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4481 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4484 caseExactIA5SubstringsMatch,
4485 caseExactIA5SubstringsIndexer,
4486 caseExactIA5SubstringsFilter,
4489 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4490 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4493 authPasswordMatch, NULL, NULL,
4496 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4497 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4500 OpenLDAPaciMatch, NULL, NULL,
4503 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4512 /* we should only be called once (from main) */
4513 assert( schema_init_done == 0 );
4515 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4516 res = register_syntax( syntax_defs[i].sd_desc,
4517 syntax_defs[i].sd_flags,
4518 syntax_defs[i].sd_validate,
4519 syntax_defs[i].sd_normalize,
4520 syntax_defs[i].sd_pretty
4521 #ifdef SLAPD_BINARY_CONVERSION
4523 syntax_defs[i].sd_ber2str,
4524 syntax_defs[i].sd_str2ber
4529 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4530 syntax_defs[i].sd_desc );
4535 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4536 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4538 "schema_init: Ingoring unusable matching rule %s\n",
4539 mrule_defs[i].mrd_desc );
4543 res = register_matching_rule(
4544 mrule_defs[i].mrd_desc,
4545 mrule_defs[i].mrd_usage,
4546 mrule_defs[i].mrd_convert,
4547 mrule_defs[i].mrd_normalize,
4548 mrule_defs[i].mrd_match,
4549 mrule_defs[i].mrd_indexer,
4550 mrule_defs[i].mrd_filter,
4551 mrule_defs[i].mrd_associated );
4555 "schema_init: Error registering matching rule %s\n",
4556 mrule_defs[i].mrd_desc );
4560 schema_init_done = 1;
4561 return LDAP_SUCCESS;