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);
795 #if defined(SLAPD_APPROX_INITIALS)
796 else if( len == 1 ) {
797 /* Single letter words need to at least match one word's initial */
798 for( i=nextavail; i<count; i++ )
799 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
806 /* Isolate the next word in the asserted value and phonetic it */
807 assertv[nextchunk+len] = '\0';
808 val = phonetic( assertv + nextchunk );
810 /* See if this phonetic chunk is in the remaining words of *value */
811 for( i=nextavail; i<count; i++ ){
812 if( !strcmp( val, values[i] ) ){
819 /* This chunk in the asserted value was NOT within the *value. */
825 /* Go on to the next word in the asserted value */
829 /* If some of the words were seen, call it a match */
830 if( nextavail > 0 ) {
839 for( i=0; i<count; i++ ) {
840 ch_free( values[i] );
856 struct berval *prefix,
857 struct berval **values,
858 struct berval ***keysp )
861 int i,j, len, wordcount, keycount=0;
862 struct berval **newkeys, **keys=NULL;
865 for( j=0; values[j] != NULL; j++ ) {
867 /* Isolate how many words there are. There will be a key for each */
868 val = ch_strdup( values[j]->bv_val );
869 for( wordcount=0,c=val; *c; c++) {
870 len = strcspn(c, SLAPD_APPROX_DELIMITER);
871 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
873 if (*c == '\0') break;
877 /* Allocate/increase storage to account for new keys */
878 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
879 * sizeof(struct berval *) );
880 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
881 if( keys ) ch_free( keys );
884 /* Get a phonetic copy of each word */
885 for( c=val,i=0; i<wordcount; c+=len+1 ) {
887 if( len < SLAPD_APPROX_WORDLEN ) continue;
888 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
889 keys[keycount]->bv_val = phonetic( c );
890 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
897 keys[keycount] = NULL;
910 struct berval *prefix,
912 struct berval ***keysp )
916 struct berval **keys;
919 /* Isolate how many words there are. There will be a key for each */
920 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
921 for( count=0,c=val; *c; c++) {
922 len = strcspn(c, SLAPD_APPROX_DELIMITER);
923 if( len >= SLAPD_APPROX_WORDLEN ) count++;
925 if (*c == '\0') break;
929 /* Allocate storage for new keys */
930 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
932 /* Get a phonetic copy of each word */
933 for( c=val,i=0; i<count; c+=len+1 ) {
935 if( len < SLAPD_APPROX_WORDLEN ) continue;
936 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
937 keys[i]->bv_val = phonetic( c );
938 keys[i]->bv_len = strlen( keys[i]->bv_val );
952 /* No other form of Approximate Matching is defined */
960 struct berval *value,
961 void *assertedValue )
963 char *vapprox, *avapprox;
965 vapprox = phonetic( value->bv_val );
966 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
968 *matchp = strcmp( vapprox, avapprox );
982 struct berval *prefix,
983 struct berval **values,
984 struct berval ***keysp )
987 struct berval **keys;
990 for( i=0; values[i] != NULL; i++ ) {
991 /* just count them */
995 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
997 /* Copy each value and run it through phonetic() */
998 for( i=0; values[i] != NULL; i++ ) {
999 keys[i] = ch_malloc( sizeof( struct berval * ) );
1000 keys[i]->bv_val = phonetic( values[i]->bv_val );
1001 keys[i]->bv_len = strlen( keys[i]->bv_val );
1006 return LDAP_SUCCESS;
1016 struct berval *prefix,
1018 struct berval ***keysp )
1020 struct berval **keys;
1023 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1025 /* Copy the value and run it through phonetic() */
1026 keys[0] = ch_malloc( sizeof( struct berval * ) );
1027 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
1028 keys[0]->bv_len = strlen( keys[0]->bv_val );
1032 return LDAP_SUCCESS;
1043 struct berval *value,
1044 void *assertedValue )
1046 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1049 match = strncmp( value->bv_val,
1050 ((struct berval *) assertedValue)->bv_val,
1055 return LDAP_SUCCESS;
1059 caseExactSubstringsMatch(
1064 struct berval *value,
1065 void *assertedValue )
1068 SubstringsAssertion *sub = assertedValue;
1069 struct berval left = *value;
1073 /* Add up asserted input length */
1074 if( sub->sa_initial ) {
1075 inlen += sub->sa_initial->bv_len;
1078 for(i=0; sub->sa_any[i] != NULL; i++) {
1079 inlen += sub->sa_any[i]->bv_len;
1082 if( sub->sa_final ) {
1083 inlen += sub->sa_final->bv_len;
1086 if( sub->sa_initial ) {
1087 if( inlen > left.bv_len ) {
1092 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1093 sub->sa_initial->bv_len );
1099 left.bv_val += sub->sa_initial->bv_len;
1100 left.bv_len -= sub->sa_initial->bv_len;
1101 inlen -= sub->sa_initial->bv_len;
1104 if( sub->sa_final ) {
1105 if( inlen > left.bv_len ) {
1110 match = strncmp( sub->sa_final->bv_val,
1111 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1112 sub->sa_final->bv_len );
1118 left.bv_len -= sub->sa_final->bv_len;
1119 inlen -= sub->sa_final->bv_len;
1123 for(i=0; sub->sa_any[i]; i++) {
1128 if( inlen > left.bv_len ) {
1129 /* not enough length */
1134 if( sub->sa_any[i]->bv_len == 0 ) {
1138 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1145 idx = p - left.bv_val;
1146 assert( idx < left.bv_len );
1148 if( idx >= left.bv_len ) {
1149 /* this shouldn't happen */
1156 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1157 /* not enough left */
1162 match = strncmp( left.bv_val,
1163 sub->sa_any[i]->bv_val,
1164 sub->sa_any[i]->bv_len );
1172 left.bv_val += sub->sa_any[i]->bv_len;
1173 left.bv_len -= sub->sa_any[i]->bv_len;
1174 inlen -= sub->sa_any[i]->bv_len;
1180 return LDAP_SUCCESS;
1183 /* Index generation function */
1184 int caseExactIndexer(
1189 struct berval *prefix,
1190 struct berval **values,
1191 struct berval ***keysp )
1195 struct berval **keys;
1196 HASH_CONTEXT HASHcontext;
1197 unsigned char HASHdigest[HASH_BYTES];
1198 struct berval digest;
1199 digest.bv_val = HASHdigest;
1200 digest.bv_len = sizeof(HASHdigest);
1202 /* we should have at least one value at this point */
1203 assert( values != NULL && values[0] != NULL );
1205 for( i=0; values[i] != NULL; i++ ) {
1206 /* just count them */
1209 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1211 slen = strlen( syntax->ssyn_oid );
1212 mlen = strlen( mr->smr_oid );
1214 for( i=0; values[i] != NULL; i++ ) {
1215 struct berval *value = values[i];
1217 HASH_Init( &HASHcontext );
1218 if( prefix != NULL && prefix->bv_len > 0 ) {
1219 HASH_Update( &HASHcontext,
1220 prefix->bv_val, prefix->bv_len );
1222 HASH_Update( &HASHcontext,
1223 syntax->ssyn_oid, slen );
1224 HASH_Update( &HASHcontext,
1225 mr->smr_oid, mlen );
1226 HASH_Update( &HASHcontext,
1227 value->bv_val, value->bv_len );
1228 HASH_Final( HASHdigest, &HASHcontext );
1230 keys[i] = ber_bvdup( &digest );
1235 return LDAP_SUCCESS;
1238 /* Index generation function */
1239 int caseExactFilter(
1244 struct berval *prefix,
1246 struct berval ***keysp )
1249 struct berval **keys;
1250 HASH_CONTEXT HASHcontext;
1251 unsigned char HASHdigest[HASH_BYTES];
1252 struct berval *value;
1253 struct berval digest;
1254 digest.bv_val = HASHdigest;
1255 digest.bv_len = sizeof(HASHdigest);
1257 slen = strlen( syntax->ssyn_oid );
1258 mlen = strlen( mr->smr_oid );
1260 value = (struct berval *) assertValue;
1262 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1264 HASH_Init( &HASHcontext );
1265 if( prefix != NULL && prefix->bv_len > 0 ) {
1266 HASH_Update( &HASHcontext,
1267 prefix->bv_val, prefix->bv_len );
1269 HASH_Update( &HASHcontext,
1270 syntax->ssyn_oid, slen );
1271 HASH_Update( &HASHcontext,
1272 mr->smr_oid, mlen );
1273 HASH_Update( &HASHcontext,
1274 value->bv_val, value->bv_len );
1275 HASH_Final( HASHdigest, &HASHcontext );
1277 keys[0] = ber_bvdup( &digest );
1281 return LDAP_SUCCESS;
1284 /* Substrings Index generation function */
1285 int caseExactSubstringsIndexer(
1290 struct berval *prefix,
1291 struct berval **values,
1292 struct berval ***keysp )
1296 struct berval **keys;
1297 HASH_CONTEXT HASHcontext;
1298 unsigned char HASHdigest[HASH_BYTES];
1299 struct berval digest;
1300 digest.bv_val = HASHdigest;
1301 digest.bv_len = sizeof(HASHdigest);
1303 /* we should have at least one value at this point */
1304 assert( values != NULL && values[0] != NULL );
1307 for( i=0; values[i] != NULL; i++ ) {
1308 /* count number of indices to generate */
1309 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1313 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1314 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1315 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1316 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1318 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1322 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1323 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1324 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1328 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1329 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1330 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1331 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1333 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1339 /* no keys to generate */
1341 return LDAP_SUCCESS;
1344 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1346 slen = strlen( syntax->ssyn_oid );
1347 mlen = strlen( mr->smr_oid );
1350 for( i=0; values[i] != NULL; i++ ) {
1352 struct berval *value;
1355 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1357 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1358 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1360 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1361 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1363 for( j=0; j<max; j++ ) {
1364 HASH_Init( &HASHcontext );
1365 if( prefix != NULL && prefix->bv_len > 0 ) {
1366 HASH_Update( &HASHcontext,
1367 prefix->bv_val, prefix->bv_len );
1370 HASH_Update( &HASHcontext,
1371 &pre, sizeof( pre ) );
1372 HASH_Update( &HASHcontext,
1373 syntax->ssyn_oid, slen );
1374 HASH_Update( &HASHcontext,
1375 mr->smr_oid, mlen );
1376 HASH_Update( &HASHcontext,
1378 SLAP_INDEX_SUBSTR_MAXLEN );
1379 HASH_Final( HASHdigest, &HASHcontext );
1381 keys[nkeys++] = ber_bvdup( &digest );
1385 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1386 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1388 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1391 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1392 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1393 HASH_Init( &HASHcontext );
1394 if( prefix != NULL && prefix->bv_len > 0 ) {
1395 HASH_Update( &HASHcontext,
1396 prefix->bv_val, prefix->bv_len );
1398 HASH_Update( &HASHcontext,
1399 &pre, sizeof( pre ) );
1400 HASH_Update( &HASHcontext,
1401 syntax->ssyn_oid, slen );
1402 HASH_Update( &HASHcontext,
1403 mr->smr_oid, mlen );
1404 HASH_Update( &HASHcontext,
1406 HASH_Final( HASHdigest, &HASHcontext );
1408 keys[nkeys++] = ber_bvdup( &digest );
1411 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1412 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1413 HASH_Init( &HASHcontext );
1414 if( prefix != NULL && prefix->bv_len > 0 ) {
1415 HASH_Update( &HASHcontext,
1416 prefix->bv_val, prefix->bv_len );
1418 HASH_Update( &HASHcontext,
1419 &pre, sizeof( pre ) );
1420 HASH_Update( &HASHcontext,
1421 syntax->ssyn_oid, slen );
1422 HASH_Update( &HASHcontext,
1423 mr->smr_oid, mlen );
1424 HASH_Update( &HASHcontext,
1425 &value->bv_val[value->bv_len-j], j );
1426 HASH_Final( HASHdigest, &HASHcontext );
1428 keys[nkeys++] = ber_bvdup( &digest );
1442 return LDAP_SUCCESS;
1445 int caseExactSubstringsFilter(
1450 struct berval *prefix,
1452 struct berval ***keysp )
1454 SubstringsAssertion *sa = assertValue;
1456 ber_len_t nkeys = 0;
1457 size_t slen, mlen, klen;
1458 struct berval **keys;
1459 HASH_CONTEXT HASHcontext;
1460 unsigned char HASHdigest[HASH_BYTES];
1461 struct berval *value;
1462 struct berval digest;
1464 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1465 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1470 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1472 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1473 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1474 /* don't bother accounting for stepping */
1475 nkeys += sa->sa_any[i]->bv_len -
1476 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1481 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1482 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1489 return LDAP_SUCCESS;
1492 digest.bv_val = HASHdigest;
1493 digest.bv_len = sizeof(HASHdigest);
1495 slen = strlen( syntax->ssyn_oid );
1496 mlen = strlen( mr->smr_oid );
1498 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1501 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1502 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1504 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1505 value = sa->sa_initial;
1507 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1508 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1510 HASH_Init( &HASHcontext );
1511 if( prefix != NULL && prefix->bv_len > 0 ) {
1512 HASH_Update( &HASHcontext,
1513 prefix->bv_val, prefix->bv_len );
1515 HASH_Update( &HASHcontext,
1516 &pre, sizeof( pre ) );
1517 HASH_Update( &HASHcontext,
1518 syntax->ssyn_oid, slen );
1519 HASH_Update( &HASHcontext,
1520 mr->smr_oid, mlen );
1521 HASH_Update( &HASHcontext,
1522 value->bv_val, klen );
1523 HASH_Final( HASHdigest, &HASHcontext );
1525 keys[nkeys++] = ber_bvdup( &digest );
1528 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1530 pre = SLAP_INDEX_SUBSTR_PREFIX;
1531 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1533 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1534 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1538 value = sa->sa_any[i];
1541 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1542 j += SLAP_INDEX_SUBSTR_STEP )
1544 HASH_Init( &HASHcontext );
1545 if( prefix != NULL && prefix->bv_len > 0 ) {
1546 HASH_Update( &HASHcontext,
1547 prefix->bv_val, prefix->bv_len );
1549 HASH_Update( &HASHcontext,
1550 &pre, sizeof( pre ) );
1551 HASH_Update( &HASHcontext,
1552 syntax->ssyn_oid, slen );
1553 HASH_Update( &HASHcontext,
1554 mr->smr_oid, mlen );
1555 HASH_Update( &HASHcontext,
1556 &value->bv_val[j], klen );
1557 HASH_Final( HASHdigest, &HASHcontext );
1559 keys[nkeys++] = ber_bvdup( &digest );
1564 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1565 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1567 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1568 value = sa->sa_final;
1570 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1571 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1573 HASH_Init( &HASHcontext );
1574 if( prefix != NULL && prefix->bv_len > 0 ) {
1575 HASH_Update( &HASHcontext,
1576 prefix->bv_val, prefix->bv_len );
1578 HASH_Update( &HASHcontext,
1579 &pre, sizeof( pre ) );
1580 HASH_Update( &HASHcontext,
1581 syntax->ssyn_oid, slen );
1582 HASH_Update( &HASHcontext,
1583 mr->smr_oid, mlen );
1584 HASH_Update( &HASHcontext,
1585 &value->bv_val[value->bv_len-klen], klen );
1586 HASH_Final( HASHdigest, &HASHcontext );
1588 keys[nkeys++] = ber_bvdup( &digest );
1599 return LDAP_SUCCESS;
1608 struct berval *value,
1609 void *assertedValue )
1612 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1614 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1617 match = strncasecmp( value->bv_val,
1618 ((struct berval *) assertedValue)->bv_val,
1624 return LDAP_SUCCESS;
1628 caseIgnoreSubstringsMatch(
1633 struct berval *value,
1634 void *assertedValue )
1637 SubstringsAssertion *sub = assertedValue;
1638 struct berval left = *value;
1642 /* Add up asserted input length */
1643 if( sub->sa_initial ) {
1644 inlen += sub->sa_initial->bv_len;
1647 for(i=0; sub->sa_any[i] != NULL; i++) {
1648 inlen += sub->sa_any[i]->bv_len;
1651 if( sub->sa_final ) {
1652 inlen += sub->sa_final->bv_len;
1655 if( sub->sa_initial ) {
1656 if( inlen > left.bv_len ) {
1662 match = UTF8oncasecmp( sub->sa_initial, &left,
1663 sub->sa_initial->bv_len, 0 );
1665 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1666 sub->sa_initial->bv_len );
1673 left.bv_val += sub->sa_initial->bv_len;
1674 left.bv_len -= sub->sa_initial->bv_len;
1675 inlen -= sub->sa_initial->bv_len;
1678 if( sub->sa_final ) {
1679 if( inlen > left.bv_len ) {
1685 match = UTF8oncasecmp( sub->sa_final, &left,
1686 sub->sa_final->bv_len,
1687 left.bv_len - sub->sa_final->bv_len );
1689 match = strncasecmp( sub->sa_final->bv_val,
1690 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1691 sub->sa_final->bv_len );
1698 left.bv_len -= sub->sa_final->bv_len;
1699 inlen -= sub->sa_final->bv_len;
1703 for(i=0; sub->sa_any[i]; i++) {
1708 if( inlen > left.bv_len ) {
1709 /* not enough length */
1714 if( sub->sa_any[i]->bv_len == 0 ) {
1719 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1721 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1729 idx = p - left.bv_val;
1730 assert( idx < left.bv_len );
1732 if( idx >= left.bv_len ) {
1733 /* this shouldn't happen */
1740 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1741 /* not enough left */
1747 match = UTF8oncasecmp( &left, sub->sa_any[i],
1748 sub->sa_any[i]->bv_len, 0 );
1751 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1757 match = strncasecmp( left.bv_val,
1758 sub->sa_any[i]->bv_val,
1759 sub->sa_any[i]->bv_len );
1769 left.bv_val += sub->sa_any[i]->bv_len;
1770 left.bv_len -= sub->sa_any[i]->bv_len;
1771 inlen -= sub->sa_any[i]->bv_len;
1777 return LDAP_SUCCESS;
1780 /* Index generation function */
1781 int caseIgnoreIndexer(
1786 struct berval *prefix,
1787 struct berval **values,
1788 struct berval ***keysp )
1792 struct berval **keys;
1793 HASH_CONTEXT HASHcontext;
1794 unsigned char HASHdigest[HASH_BYTES];
1795 struct berval digest;
1796 digest.bv_val = HASHdigest;
1797 digest.bv_len = sizeof(HASHdigest);
1799 /* we should have at least one value at this point */
1800 assert( values != NULL && values[0] != NULL );
1802 for( i=0; values[i] != NULL; i++ ) {
1803 /* just count them */
1806 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1808 slen = strlen( syntax->ssyn_oid );
1809 mlen = strlen( mr->smr_oid );
1811 for( i=0; values[i] != NULL; i++ ) {
1812 struct berval *value = ber_bvdup( values[i] );
1813 ldap_pvt_str2upper( value->bv_val );
1815 HASH_Init( &HASHcontext );
1816 if( prefix != NULL && prefix->bv_len > 0 ) {
1817 HASH_Update( &HASHcontext,
1818 prefix->bv_val, prefix->bv_len );
1820 HASH_Update( &HASHcontext,
1821 syntax->ssyn_oid, slen );
1822 HASH_Update( &HASHcontext,
1823 mr->smr_oid, mlen );
1824 HASH_Update( &HASHcontext,
1825 value->bv_val, value->bv_len );
1826 HASH_Final( HASHdigest, &HASHcontext );
1828 ber_bvfree( value );
1830 keys[i] = ber_bvdup( &digest );
1835 return LDAP_SUCCESS;
1838 /* Index generation function */
1839 int caseIgnoreFilter(
1844 struct berval *prefix,
1846 struct berval ***keysp )
1849 struct berval **keys;
1850 HASH_CONTEXT HASHcontext;
1851 unsigned char HASHdigest[HASH_BYTES];
1852 struct berval *value;
1853 struct berval digest;
1854 digest.bv_val = HASHdigest;
1855 digest.bv_len = sizeof(HASHdigest);
1857 slen = strlen( syntax->ssyn_oid );
1858 mlen = strlen( mr->smr_oid );
1860 value = ber_bvdup( (struct berval *) assertValue );
1861 ldap_pvt_str2upper( value->bv_val );
1863 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1865 HASH_Init( &HASHcontext );
1866 if( prefix != NULL && prefix->bv_len > 0 ) {
1867 HASH_Update( &HASHcontext,
1868 prefix->bv_val, prefix->bv_len );
1870 HASH_Update( &HASHcontext,
1871 syntax->ssyn_oid, slen );
1872 HASH_Update( &HASHcontext,
1873 mr->smr_oid, mlen );
1874 HASH_Update( &HASHcontext,
1875 value->bv_val, value->bv_len );
1876 HASH_Final( HASHdigest, &HASHcontext );
1878 keys[0] = ber_bvdup( &digest );
1881 ber_bvfree( value );
1885 return LDAP_SUCCESS;
1888 /* Substrings Index generation function */
1889 int caseIgnoreSubstringsIndexer(
1894 struct berval *prefix,
1895 struct berval **values,
1896 struct berval ***keysp )
1900 struct berval **keys;
1901 HASH_CONTEXT HASHcontext;
1902 unsigned char HASHdigest[HASH_BYTES];
1903 struct berval digest;
1904 digest.bv_val = HASHdigest;
1905 digest.bv_len = sizeof(HASHdigest);
1907 /* we should have at least one value at this point */
1908 assert( values != NULL && values[0] != NULL );
1911 for( i=0; values[i] != NULL; i++ ) {
1912 /* count number of indices to generate */
1913 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1917 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1918 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1919 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1920 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1922 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1926 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1927 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1928 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1932 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1933 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1934 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1935 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1937 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1943 /* no keys to generate */
1945 return LDAP_SUCCESS;
1948 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1950 slen = strlen( syntax->ssyn_oid );
1951 mlen = strlen( mr->smr_oid );
1954 for( i=0; values[i] != NULL; i++ ) {
1956 struct berval *value;
1958 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1960 value = ber_bvdup( values[i] );
1961 ldap_pvt_str2upper( value->bv_val );
1963 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1964 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1966 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1967 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1969 for( j=0; j<max; j++ ) {
1970 HASH_Init( &HASHcontext );
1971 if( prefix != NULL && prefix->bv_len > 0 ) {
1972 HASH_Update( &HASHcontext,
1973 prefix->bv_val, prefix->bv_len );
1976 HASH_Update( &HASHcontext,
1977 &pre, sizeof( pre ) );
1978 HASH_Update( &HASHcontext,
1979 syntax->ssyn_oid, slen );
1980 HASH_Update( &HASHcontext,
1981 mr->smr_oid, mlen );
1982 HASH_Update( &HASHcontext,
1984 SLAP_INDEX_SUBSTR_MAXLEN );
1985 HASH_Final( HASHdigest, &HASHcontext );
1987 keys[nkeys++] = ber_bvdup( &digest );
1991 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1992 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1994 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1997 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1998 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1999 HASH_Init( &HASHcontext );
2000 if( prefix != NULL && prefix->bv_len > 0 ) {
2001 HASH_Update( &HASHcontext,
2002 prefix->bv_val, prefix->bv_len );
2004 HASH_Update( &HASHcontext,
2005 &pre, sizeof( pre ) );
2006 HASH_Update( &HASHcontext,
2007 syntax->ssyn_oid, slen );
2008 HASH_Update( &HASHcontext,
2009 mr->smr_oid, mlen );
2010 HASH_Update( &HASHcontext,
2012 HASH_Final( HASHdigest, &HASHcontext );
2014 keys[nkeys++] = ber_bvdup( &digest );
2017 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2018 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2019 HASH_Init( &HASHcontext );
2020 if( prefix != NULL && prefix->bv_len > 0 ) {
2021 HASH_Update( &HASHcontext,
2022 prefix->bv_val, prefix->bv_len );
2024 HASH_Update( &HASHcontext,
2025 &pre, sizeof( pre ) );
2026 HASH_Update( &HASHcontext,
2027 syntax->ssyn_oid, slen );
2028 HASH_Update( &HASHcontext,
2029 mr->smr_oid, mlen );
2030 HASH_Update( &HASHcontext,
2031 &value->bv_val[value->bv_len-j], j );
2032 HASH_Final( HASHdigest, &HASHcontext );
2034 keys[nkeys++] = ber_bvdup( &digest );
2039 ber_bvfree( value );
2050 return LDAP_SUCCESS;
2053 int caseIgnoreSubstringsFilter(
2058 struct berval *prefix,
2060 struct berval ***keysp )
2062 SubstringsAssertion *sa = assertValue;
2064 ber_len_t nkeys = 0;
2065 size_t slen, mlen, klen;
2066 struct berval **keys;
2067 HASH_CONTEXT HASHcontext;
2068 unsigned char HASHdigest[HASH_BYTES];
2069 struct berval *value;
2070 struct berval digest;
2072 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2073 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2078 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2080 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2081 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2082 /* don't bother accounting for stepping */
2083 nkeys += sa->sa_any[i]->bv_len -
2084 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2089 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2090 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2097 return LDAP_SUCCESS;
2100 digest.bv_val = HASHdigest;
2101 digest.bv_len = sizeof(HASHdigest);
2103 slen = strlen( syntax->ssyn_oid );
2104 mlen = strlen( mr->smr_oid );
2106 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2109 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2110 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2112 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2113 value = ber_bvdup( sa->sa_initial );
2114 ldap_pvt_str2upper( value->bv_val );
2116 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2117 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2119 HASH_Init( &HASHcontext );
2120 if( prefix != NULL && prefix->bv_len > 0 ) {
2121 HASH_Update( &HASHcontext,
2122 prefix->bv_val, prefix->bv_len );
2124 HASH_Update( &HASHcontext,
2125 &pre, sizeof( pre ) );
2126 HASH_Update( &HASHcontext,
2127 syntax->ssyn_oid, slen );
2128 HASH_Update( &HASHcontext,
2129 mr->smr_oid, mlen );
2130 HASH_Update( &HASHcontext,
2131 value->bv_val, klen );
2132 HASH_Final( HASHdigest, &HASHcontext );
2134 ber_bvfree( value );
2135 keys[nkeys++] = ber_bvdup( &digest );
2138 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2140 pre = SLAP_INDEX_SUBSTR_PREFIX;
2141 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2143 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2144 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2148 value = ber_bvdup( sa->sa_any[i] );
2149 ldap_pvt_str2upper( value->bv_val );
2152 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2153 j += SLAP_INDEX_SUBSTR_STEP )
2155 HASH_Init( &HASHcontext );
2156 if( prefix != NULL && prefix->bv_len > 0 ) {
2157 HASH_Update( &HASHcontext,
2158 prefix->bv_val, prefix->bv_len );
2160 HASH_Update( &HASHcontext,
2161 &pre, sizeof( pre ) );
2162 HASH_Update( &HASHcontext,
2163 syntax->ssyn_oid, slen );
2164 HASH_Update( &HASHcontext,
2165 mr->smr_oid, mlen );
2166 HASH_Update( &HASHcontext,
2167 &value->bv_val[j], klen );
2168 HASH_Final( HASHdigest, &HASHcontext );
2170 keys[nkeys++] = ber_bvdup( &digest );
2173 ber_bvfree( value );
2177 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2178 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2180 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2181 value = ber_bvdup( sa->sa_final );
2182 ldap_pvt_str2upper( value->bv_val );
2184 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2185 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2187 HASH_Init( &HASHcontext );
2188 if( prefix != NULL && prefix->bv_len > 0 ) {
2189 HASH_Update( &HASHcontext,
2190 prefix->bv_val, prefix->bv_len );
2192 HASH_Update( &HASHcontext,
2193 &pre, sizeof( pre ) );
2194 HASH_Update( &HASHcontext,
2195 syntax->ssyn_oid, slen );
2196 HASH_Update( &HASHcontext,
2197 mr->smr_oid, mlen );
2198 HASH_Update( &HASHcontext,
2199 &value->bv_val[value->bv_len-klen], klen );
2200 HASH_Final( HASHdigest, &HASHcontext );
2202 ber_bvfree( value );
2203 keys[nkeys++] = ber_bvdup( &digest );
2214 return LDAP_SUCCESS;
2220 struct berval *val )
2224 if( val->bv_len == 0 ) return 0;
2226 if( OID_LEADCHAR(val->bv_val[0]) ) {
2228 for(i=1; i < val->bv_len; i++) {
2229 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2230 if( dot++ ) return 1;
2231 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2234 return LDAP_INVALID_SYNTAX;
2238 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2240 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2241 for(i=1; i < val->bv_len; i++) {
2242 if( !DESC_CHAR(val->bv_val[i] ) ) {
2243 return LDAP_INVALID_SYNTAX;
2247 return LDAP_SUCCESS;
2250 return LDAP_INVALID_SYNTAX;
2256 struct berval *val )
2260 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2262 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2263 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2264 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2265 return LDAP_INVALID_SYNTAX;
2268 for(i=1; i < val->bv_len; i++) {
2269 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2272 return LDAP_SUCCESS;
2279 struct berval **normalized )
2282 struct berval *newval;
2288 negative = ( *p == '-' );
2289 if( *p == '-' || *p == '+' ) p++;
2291 /* Ignore leading zeros */
2292 while ( *p == '0' ) p++;
2294 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2297 newval->bv_val = ch_strdup("0");
2302 newval->bv_val = ch_malloc( val->bv_len + 1 );
2306 newval->bv_val[newval->bv_len++] = '-';
2309 for( ; *p != '\0'; p++ ) {
2310 newval->bv_val[newval->bv_len++] = *p;
2314 *normalized = newval;
2315 return LDAP_SUCCESS;
2319 printableStringValidate(
2321 struct berval *val )
2325 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2327 for(i=0; i < val->bv_len; i++) {
2328 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2331 return LDAP_SUCCESS;
2337 struct berval *val )
2341 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2343 for(i=0; i < val->bv_len; i++) {
2344 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2347 return LDAP_SUCCESS;
2354 struct berval **normalized )
2356 struct berval *newval;
2359 newval = ch_malloc( sizeof( struct berval ) );
2363 /* Ignore initial whitespace */
2364 while ( ASCII_SPACE( *p ) ) {
2370 return LDAP_INVALID_SYNTAX;
2373 newval->bv_val = ch_strdup( p );
2374 p = q = newval->bv_val;
2377 if ( ASCII_SPACE( *p ) ) {
2380 /* Ignore the extra whitespace */
2381 while ( ASCII_SPACE( *p ) ) {
2389 assert( *newval->bv_val );
2390 assert( newval->bv_val < p );
2393 /* cannot start with a space */
2394 assert( !ASCII_SPACE(*newval->bv_val) );
2397 * If the string ended in space, backup the pointer one
2398 * position. One is enough because the above loop collapsed
2399 * all whitespace to a single space.
2402 if ( ASCII_SPACE( q[-1] ) ) {
2406 /* cannot end with a space */
2407 assert( !ASCII_SPACE( q[-1] ) );
2409 /* null terminate */
2412 newval->bv_len = q - newval->bv_val;
2413 *normalized = newval;
2415 return LDAP_SUCCESS;
2424 struct berval *value,
2425 void *assertedValue )
2427 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2430 match = strncmp( value->bv_val,
2431 ((struct berval *) assertedValue)->bv_val,
2436 return LDAP_SUCCESS;
2440 caseExactIA5SubstringsMatch(
2445 struct berval *value,
2446 void *assertedValue )
2449 SubstringsAssertion *sub = assertedValue;
2450 struct berval left = *value;
2454 /* Add up asserted input length */
2455 if( sub->sa_initial ) {
2456 inlen += sub->sa_initial->bv_len;
2459 for(i=0; sub->sa_any[i] != NULL; i++) {
2460 inlen += sub->sa_any[i]->bv_len;
2463 if( sub->sa_final ) {
2464 inlen += sub->sa_final->bv_len;
2467 if( sub->sa_initial ) {
2468 if( inlen > left.bv_len ) {
2473 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2474 sub->sa_initial->bv_len );
2480 left.bv_val += sub->sa_initial->bv_len;
2481 left.bv_len -= sub->sa_initial->bv_len;
2482 inlen -= sub->sa_initial->bv_len;
2485 if( sub->sa_final ) {
2486 if( inlen > left.bv_len ) {
2491 match = strncmp( sub->sa_final->bv_val,
2492 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2493 sub->sa_final->bv_len );
2499 left.bv_len -= sub->sa_final->bv_len;
2500 inlen -= sub->sa_final->bv_len;
2504 for(i=0; sub->sa_any[i]; i++) {
2509 if( inlen > left.bv_len ) {
2510 /* not enough length */
2515 if( sub->sa_any[i]->bv_len == 0 ) {
2519 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2526 idx = p - left.bv_val;
2527 assert( idx < left.bv_len );
2529 if( idx >= left.bv_len ) {
2530 /* this shouldn't happen */
2537 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2538 /* not enough left */
2543 match = strncmp( left.bv_val,
2544 sub->sa_any[i]->bv_val,
2545 sub->sa_any[i]->bv_len );
2553 left.bv_val += sub->sa_any[i]->bv_len;
2554 left.bv_len -= sub->sa_any[i]->bv_len;
2555 inlen -= sub->sa_any[i]->bv_len;
2561 return LDAP_SUCCESS;
2564 /* Index generation function */
2565 int caseExactIA5Indexer(
2570 struct berval *prefix,
2571 struct berval **values,
2572 struct berval ***keysp )
2576 struct berval **keys;
2577 HASH_CONTEXT HASHcontext;
2578 unsigned char HASHdigest[HASH_BYTES];
2579 struct berval digest;
2580 digest.bv_val = HASHdigest;
2581 digest.bv_len = sizeof(HASHdigest);
2583 /* we should have at least one value at this point */
2584 assert( values != NULL && values[0] != NULL );
2586 for( i=0; values[i] != NULL; i++ ) {
2587 /* just count them */
2590 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2592 slen = strlen( syntax->ssyn_oid );
2593 mlen = strlen( mr->smr_oid );
2595 for( i=0; values[i] != NULL; i++ ) {
2596 struct berval *value = values[i];
2598 HASH_Init( &HASHcontext );
2599 if( prefix != NULL && prefix->bv_len > 0 ) {
2600 HASH_Update( &HASHcontext,
2601 prefix->bv_val, prefix->bv_len );
2603 HASH_Update( &HASHcontext,
2604 syntax->ssyn_oid, slen );
2605 HASH_Update( &HASHcontext,
2606 mr->smr_oid, mlen );
2607 HASH_Update( &HASHcontext,
2608 value->bv_val, value->bv_len );
2609 HASH_Final( HASHdigest, &HASHcontext );
2611 keys[i] = ber_bvdup( &digest );
2616 return LDAP_SUCCESS;
2619 /* Index generation function */
2620 int caseExactIA5Filter(
2625 struct berval *prefix,
2627 struct berval ***keysp )
2630 struct berval **keys;
2631 HASH_CONTEXT HASHcontext;
2632 unsigned char HASHdigest[HASH_BYTES];
2633 struct berval *value;
2634 struct berval digest;
2635 digest.bv_val = HASHdigest;
2636 digest.bv_len = sizeof(HASHdigest);
2638 slen = strlen( syntax->ssyn_oid );
2639 mlen = strlen( mr->smr_oid );
2641 value = (struct berval *) assertValue;
2643 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2645 HASH_Init( &HASHcontext );
2646 if( prefix != NULL && prefix->bv_len > 0 ) {
2647 HASH_Update( &HASHcontext,
2648 prefix->bv_val, prefix->bv_len );
2650 HASH_Update( &HASHcontext,
2651 syntax->ssyn_oid, slen );
2652 HASH_Update( &HASHcontext,
2653 mr->smr_oid, mlen );
2654 HASH_Update( &HASHcontext,
2655 value->bv_val, value->bv_len );
2656 HASH_Final( HASHdigest, &HASHcontext );
2658 keys[0] = ber_bvdup( &digest );
2662 return LDAP_SUCCESS;
2665 /* Substrings Index generation function */
2666 int caseExactIA5SubstringsIndexer(
2671 struct berval *prefix,
2672 struct berval **values,
2673 struct berval ***keysp )
2677 struct berval **keys;
2678 HASH_CONTEXT HASHcontext;
2679 unsigned char HASHdigest[HASH_BYTES];
2680 struct berval digest;
2681 digest.bv_val = HASHdigest;
2682 digest.bv_len = sizeof(HASHdigest);
2684 /* we should have at least one value at this point */
2685 assert( values != NULL && values[0] != NULL );
2688 for( i=0; values[i] != NULL; i++ ) {
2689 /* count number of indices to generate */
2690 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2694 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2695 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2696 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2697 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2699 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2703 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2704 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2705 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2709 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2710 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2711 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2712 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2714 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2720 /* no keys to generate */
2722 return LDAP_SUCCESS;
2725 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2727 slen = strlen( syntax->ssyn_oid );
2728 mlen = strlen( mr->smr_oid );
2731 for( i=0; values[i] != NULL; i++ ) {
2733 struct berval *value;
2736 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2738 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2739 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2741 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2742 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2744 for( j=0; j<max; j++ ) {
2745 HASH_Init( &HASHcontext );
2746 if( prefix != NULL && prefix->bv_len > 0 ) {
2747 HASH_Update( &HASHcontext,
2748 prefix->bv_val, prefix->bv_len );
2751 HASH_Update( &HASHcontext,
2752 &pre, sizeof( pre ) );
2753 HASH_Update( &HASHcontext,
2754 syntax->ssyn_oid, slen );
2755 HASH_Update( &HASHcontext,
2756 mr->smr_oid, mlen );
2757 HASH_Update( &HASHcontext,
2759 SLAP_INDEX_SUBSTR_MAXLEN );
2760 HASH_Final( HASHdigest, &HASHcontext );
2762 keys[nkeys++] = ber_bvdup( &digest );
2766 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2767 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2769 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2772 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2773 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2774 HASH_Init( &HASHcontext );
2775 if( prefix != NULL && prefix->bv_len > 0 ) {
2776 HASH_Update( &HASHcontext,
2777 prefix->bv_val, prefix->bv_len );
2779 HASH_Update( &HASHcontext,
2780 &pre, sizeof( pre ) );
2781 HASH_Update( &HASHcontext,
2782 syntax->ssyn_oid, slen );
2783 HASH_Update( &HASHcontext,
2784 mr->smr_oid, mlen );
2785 HASH_Update( &HASHcontext,
2787 HASH_Final( HASHdigest, &HASHcontext );
2789 keys[nkeys++] = ber_bvdup( &digest );
2792 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2793 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2794 HASH_Init( &HASHcontext );
2795 if( prefix != NULL && prefix->bv_len > 0 ) {
2796 HASH_Update( &HASHcontext,
2797 prefix->bv_val, prefix->bv_len );
2799 HASH_Update( &HASHcontext,
2800 &pre, sizeof( pre ) );
2801 HASH_Update( &HASHcontext,
2802 syntax->ssyn_oid, slen );
2803 HASH_Update( &HASHcontext,
2804 mr->smr_oid, mlen );
2805 HASH_Update( &HASHcontext,
2806 &value->bv_val[value->bv_len-j], j );
2807 HASH_Final( HASHdigest, &HASHcontext );
2809 keys[nkeys++] = ber_bvdup( &digest );
2823 return LDAP_SUCCESS;
2826 int caseExactIA5SubstringsFilter(
2831 struct berval *prefix,
2833 struct berval ***keysp )
2835 SubstringsAssertion *sa = assertValue;
2837 ber_len_t nkeys = 0;
2838 size_t slen, mlen, klen;
2839 struct berval **keys;
2840 HASH_CONTEXT HASHcontext;
2841 unsigned char HASHdigest[HASH_BYTES];
2842 struct berval *value;
2843 struct berval digest;
2845 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2846 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2851 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2853 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2854 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2855 /* don't bother accounting for stepping */
2856 nkeys += sa->sa_any[i]->bv_len -
2857 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2862 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2863 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2870 return LDAP_SUCCESS;
2873 digest.bv_val = HASHdigest;
2874 digest.bv_len = sizeof(HASHdigest);
2876 slen = strlen( syntax->ssyn_oid );
2877 mlen = strlen( mr->smr_oid );
2879 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2882 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2883 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2885 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2886 value = sa->sa_initial;
2888 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2889 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2891 HASH_Init( &HASHcontext );
2892 if( prefix != NULL && prefix->bv_len > 0 ) {
2893 HASH_Update( &HASHcontext,
2894 prefix->bv_val, prefix->bv_len );
2896 HASH_Update( &HASHcontext,
2897 &pre, sizeof( pre ) );
2898 HASH_Update( &HASHcontext,
2899 syntax->ssyn_oid, slen );
2900 HASH_Update( &HASHcontext,
2901 mr->smr_oid, mlen );
2902 HASH_Update( &HASHcontext,
2903 value->bv_val, klen );
2904 HASH_Final( HASHdigest, &HASHcontext );
2906 keys[nkeys++] = ber_bvdup( &digest );
2909 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2911 pre = SLAP_INDEX_SUBSTR_PREFIX;
2912 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2914 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2915 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2919 value = sa->sa_any[i];
2922 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2923 j += SLAP_INDEX_SUBSTR_STEP )
2925 HASH_Init( &HASHcontext );
2926 if( prefix != NULL && prefix->bv_len > 0 ) {
2927 HASH_Update( &HASHcontext,
2928 prefix->bv_val, prefix->bv_len );
2930 HASH_Update( &HASHcontext,
2931 &pre, sizeof( pre ) );
2932 HASH_Update( &HASHcontext,
2933 syntax->ssyn_oid, slen );
2934 HASH_Update( &HASHcontext,
2935 mr->smr_oid, mlen );
2936 HASH_Update( &HASHcontext,
2937 &value->bv_val[j], klen );
2938 HASH_Final( HASHdigest, &HASHcontext );
2940 keys[nkeys++] = ber_bvdup( &digest );
2945 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2946 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2948 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2949 value = sa->sa_final;
2951 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2952 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2954 HASH_Init( &HASHcontext );
2955 if( prefix != NULL && prefix->bv_len > 0 ) {
2956 HASH_Update( &HASHcontext,
2957 prefix->bv_val, prefix->bv_len );
2959 HASH_Update( &HASHcontext,
2960 &pre, sizeof( pre ) );
2961 HASH_Update( &HASHcontext,
2962 syntax->ssyn_oid, slen );
2963 HASH_Update( &HASHcontext,
2964 mr->smr_oid, mlen );
2965 HASH_Update( &HASHcontext,
2966 &value->bv_val[value->bv_len-klen], klen );
2967 HASH_Final( HASHdigest, &HASHcontext );
2969 keys[nkeys++] = ber_bvdup( &digest );
2980 return LDAP_SUCCESS;
2989 struct berval *value,
2990 void *assertedValue )
2992 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2995 match = strncasecmp( value->bv_val,
2996 ((struct berval *) assertedValue)->bv_val,
3001 return LDAP_SUCCESS;
3005 caseIgnoreIA5SubstringsMatch(
3010 struct berval *value,
3011 void *assertedValue )
3014 SubstringsAssertion *sub = assertedValue;
3015 struct berval left = *value;
3019 /* Add up asserted input length */
3020 if( sub->sa_initial ) {
3021 inlen += sub->sa_initial->bv_len;
3024 for(i=0; sub->sa_any[i] != NULL; i++) {
3025 inlen += sub->sa_any[i]->bv_len;
3028 if( sub->sa_final ) {
3029 inlen += sub->sa_final->bv_len;
3032 if( sub->sa_initial ) {
3033 if( inlen > left.bv_len ) {
3038 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3039 sub->sa_initial->bv_len );
3045 left.bv_val += sub->sa_initial->bv_len;
3046 left.bv_len -= sub->sa_initial->bv_len;
3047 inlen -= sub->sa_initial->bv_len;
3050 if( sub->sa_final ) {
3051 if( inlen > left.bv_len ) {
3056 match = strncasecmp( sub->sa_final->bv_val,
3057 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3058 sub->sa_final->bv_len );
3064 left.bv_len -= sub->sa_final->bv_len;
3065 inlen -= sub->sa_final->bv_len;
3069 for(i=0; sub->sa_any[i]; i++) {
3074 if( inlen > left.bv_len ) {
3075 /* not enough length */
3080 if( sub->sa_any[i]->bv_len == 0 ) {
3084 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3091 idx = p - left.bv_val;
3092 assert( idx < left.bv_len );
3094 if( idx >= left.bv_len ) {
3095 /* this shouldn't happen */
3102 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3103 /* not enough left */
3108 match = strncasecmp( left.bv_val,
3109 sub->sa_any[i]->bv_val,
3110 sub->sa_any[i]->bv_len );
3119 left.bv_val += sub->sa_any[i]->bv_len;
3120 left.bv_len -= sub->sa_any[i]->bv_len;
3121 inlen -= sub->sa_any[i]->bv_len;
3127 return LDAP_SUCCESS;
3130 /* Index generation function */
3131 int caseIgnoreIA5Indexer(
3136 struct berval *prefix,
3137 struct berval **values,
3138 struct berval ***keysp )
3142 struct berval **keys;
3143 HASH_CONTEXT HASHcontext;
3144 unsigned char HASHdigest[HASH_BYTES];
3145 struct berval digest;
3146 digest.bv_val = HASHdigest;
3147 digest.bv_len = sizeof(HASHdigest);
3149 /* we should have at least one value at this point */
3150 assert( values != NULL && values[0] != NULL );
3152 for( i=0; values[i] != NULL; i++ ) {
3153 /* just count them */
3156 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3158 slen = strlen( syntax->ssyn_oid );
3159 mlen = strlen( mr->smr_oid );
3161 for( i=0; values[i] != NULL; i++ ) {
3162 struct berval *value = ber_bvdup( values[i] );
3163 ldap_pvt_str2upper( value->bv_val );
3165 HASH_Init( &HASHcontext );
3166 if( prefix != NULL && prefix->bv_len > 0 ) {
3167 HASH_Update( &HASHcontext,
3168 prefix->bv_val, prefix->bv_len );
3170 HASH_Update( &HASHcontext,
3171 syntax->ssyn_oid, slen );
3172 HASH_Update( &HASHcontext,
3173 mr->smr_oid, mlen );
3174 HASH_Update( &HASHcontext,
3175 value->bv_val, value->bv_len );
3176 HASH_Final( HASHdigest, &HASHcontext );
3178 ber_bvfree( value );
3180 keys[i] = ber_bvdup( &digest );
3185 return LDAP_SUCCESS;
3188 /* Index generation function */
3189 int caseIgnoreIA5Filter(
3194 struct berval *prefix,
3196 struct berval ***keysp )
3199 struct berval **keys;
3200 HASH_CONTEXT HASHcontext;
3201 unsigned char HASHdigest[HASH_BYTES];
3202 struct berval *value;
3203 struct berval digest;
3204 digest.bv_val = HASHdigest;
3205 digest.bv_len = sizeof(HASHdigest);
3207 slen = strlen( syntax->ssyn_oid );
3208 mlen = strlen( mr->smr_oid );
3210 value = ber_bvdup( (struct berval *) assertValue );
3211 ldap_pvt_str2upper( value->bv_val );
3213 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3215 HASH_Init( &HASHcontext );
3216 if( prefix != NULL && prefix->bv_len > 0 ) {
3217 HASH_Update( &HASHcontext,
3218 prefix->bv_val, prefix->bv_len );
3220 HASH_Update( &HASHcontext,
3221 syntax->ssyn_oid, slen );
3222 HASH_Update( &HASHcontext,
3223 mr->smr_oid, mlen );
3224 HASH_Update( &HASHcontext,
3225 value->bv_val, value->bv_len );
3226 HASH_Final( HASHdigest, &HASHcontext );
3228 keys[0] = ber_bvdup( &digest );
3231 ber_bvfree( value );
3235 return LDAP_SUCCESS;
3238 /* Substrings Index generation function */
3239 int caseIgnoreIA5SubstringsIndexer(
3244 struct berval *prefix,
3245 struct berval **values,
3246 struct berval ***keysp )
3250 struct berval **keys;
3251 HASH_CONTEXT HASHcontext;
3252 unsigned char HASHdigest[HASH_BYTES];
3253 struct berval digest;
3254 digest.bv_val = HASHdigest;
3255 digest.bv_len = sizeof(HASHdigest);
3257 /* we should have at least one value at this point */
3258 assert( values != NULL && values[0] != NULL );
3261 for( i=0; values[i] != NULL; i++ ) {
3262 /* count number of indices to generate */
3263 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3267 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3268 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3269 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3270 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3272 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3276 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3277 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3278 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3282 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3283 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3284 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3285 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3287 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3293 /* no keys to generate */
3295 return LDAP_SUCCESS;
3298 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3300 slen = strlen( syntax->ssyn_oid );
3301 mlen = strlen( mr->smr_oid );
3304 for( i=0; values[i] != NULL; i++ ) {
3306 struct berval *value;
3308 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3310 value = ber_bvdup( values[i] );
3311 ldap_pvt_str2upper( value->bv_val );
3313 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3314 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3316 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3317 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3319 for( j=0; j<max; j++ ) {
3320 HASH_Init( &HASHcontext );
3321 if( prefix != NULL && prefix->bv_len > 0 ) {
3322 HASH_Update( &HASHcontext,
3323 prefix->bv_val, prefix->bv_len );
3326 HASH_Update( &HASHcontext,
3327 &pre, sizeof( pre ) );
3328 HASH_Update( &HASHcontext,
3329 syntax->ssyn_oid, slen );
3330 HASH_Update( &HASHcontext,
3331 mr->smr_oid, mlen );
3332 HASH_Update( &HASHcontext,
3334 SLAP_INDEX_SUBSTR_MAXLEN );
3335 HASH_Final( HASHdigest, &HASHcontext );
3337 keys[nkeys++] = ber_bvdup( &digest );
3341 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3342 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3344 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3347 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3348 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3349 HASH_Init( &HASHcontext );
3350 if( prefix != NULL && prefix->bv_len > 0 ) {
3351 HASH_Update( &HASHcontext,
3352 prefix->bv_val, prefix->bv_len );
3354 HASH_Update( &HASHcontext,
3355 &pre, sizeof( pre ) );
3356 HASH_Update( &HASHcontext,
3357 syntax->ssyn_oid, slen );
3358 HASH_Update( &HASHcontext,
3359 mr->smr_oid, mlen );
3360 HASH_Update( &HASHcontext,
3362 HASH_Final( HASHdigest, &HASHcontext );
3364 keys[nkeys++] = ber_bvdup( &digest );
3367 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3368 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3369 HASH_Init( &HASHcontext );
3370 if( prefix != NULL && prefix->bv_len > 0 ) {
3371 HASH_Update( &HASHcontext,
3372 prefix->bv_val, prefix->bv_len );
3374 HASH_Update( &HASHcontext,
3375 &pre, sizeof( pre ) );
3376 HASH_Update( &HASHcontext,
3377 syntax->ssyn_oid, slen );
3378 HASH_Update( &HASHcontext,
3379 mr->smr_oid, mlen );
3380 HASH_Update( &HASHcontext,
3381 &value->bv_val[value->bv_len-j], j );
3382 HASH_Final( HASHdigest, &HASHcontext );
3384 keys[nkeys++] = ber_bvdup( &digest );
3389 ber_bvfree( value );
3400 return LDAP_SUCCESS;
3403 int caseIgnoreIA5SubstringsFilter(
3408 struct berval *prefix,
3410 struct berval ***keysp )
3412 SubstringsAssertion *sa = assertValue;
3414 ber_len_t nkeys = 0;
3415 size_t slen, mlen, klen;
3416 struct berval **keys;
3417 HASH_CONTEXT HASHcontext;
3418 unsigned char HASHdigest[HASH_BYTES];
3419 struct berval *value;
3420 struct berval digest;
3422 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3423 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3428 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3430 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3431 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3432 /* don't bother accounting for stepping */
3433 nkeys += sa->sa_any[i]->bv_len -
3434 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3439 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3440 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3447 return LDAP_SUCCESS;
3450 digest.bv_val = HASHdigest;
3451 digest.bv_len = sizeof(HASHdigest);
3453 slen = strlen( syntax->ssyn_oid );
3454 mlen = strlen( mr->smr_oid );
3456 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3459 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3460 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3462 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3463 value = ber_bvdup( sa->sa_initial );
3464 ldap_pvt_str2upper( value->bv_val );
3466 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3467 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3469 HASH_Init( &HASHcontext );
3470 if( prefix != NULL && prefix->bv_len > 0 ) {
3471 HASH_Update( &HASHcontext,
3472 prefix->bv_val, prefix->bv_len );
3474 HASH_Update( &HASHcontext,
3475 &pre, sizeof( pre ) );
3476 HASH_Update( &HASHcontext,
3477 syntax->ssyn_oid, slen );
3478 HASH_Update( &HASHcontext,
3479 mr->smr_oid, mlen );
3480 HASH_Update( &HASHcontext,
3481 value->bv_val, klen );
3482 HASH_Final( HASHdigest, &HASHcontext );
3484 ber_bvfree( value );
3485 keys[nkeys++] = ber_bvdup( &digest );
3488 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3490 pre = SLAP_INDEX_SUBSTR_PREFIX;
3491 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3493 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3494 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3498 value = ber_bvdup( sa->sa_any[i] );
3499 ldap_pvt_str2upper( value->bv_val );
3502 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3503 j += SLAP_INDEX_SUBSTR_STEP )
3505 HASH_Init( &HASHcontext );
3506 if( prefix != NULL && prefix->bv_len > 0 ) {
3507 HASH_Update( &HASHcontext,
3508 prefix->bv_val, prefix->bv_len );
3510 HASH_Update( &HASHcontext,
3511 &pre, sizeof( pre ) );
3512 HASH_Update( &HASHcontext,
3513 syntax->ssyn_oid, slen );
3514 HASH_Update( &HASHcontext,
3515 mr->smr_oid, mlen );
3516 HASH_Update( &HASHcontext,
3517 &value->bv_val[j], klen );
3518 HASH_Final( HASHdigest, &HASHcontext );
3520 keys[nkeys++] = ber_bvdup( &digest );
3523 ber_bvfree( value );
3527 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3528 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3530 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3531 value = ber_bvdup( sa->sa_final );
3532 ldap_pvt_str2upper( value->bv_val );
3534 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3535 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3537 HASH_Init( &HASHcontext );
3538 if( prefix != NULL && prefix->bv_len > 0 ) {
3539 HASH_Update( &HASHcontext,
3540 prefix->bv_val, prefix->bv_len );
3542 HASH_Update( &HASHcontext,
3543 &pre, sizeof( pre ) );
3544 HASH_Update( &HASHcontext,
3545 syntax->ssyn_oid, slen );
3546 HASH_Update( &HASHcontext,
3547 mr->smr_oid, mlen );
3548 HASH_Update( &HASHcontext,
3549 &value->bv_val[value->bv_len-klen], klen );
3550 HASH_Final( HASHdigest, &HASHcontext );
3552 ber_bvfree( value );
3553 keys[nkeys++] = ber_bvdup( &digest );
3564 return LDAP_SUCCESS;
3568 numericStringNormalize(
3571 struct berval **normalized )
3573 /* similiar to IA5StringNormalize except removes all spaces */
3574 struct berval *newval;
3577 newval = ch_malloc( sizeof( struct berval ) );
3581 /* Ignore initial whitespace */
3582 while ( ASCII_SPACE( *p ) ) {
3588 return LDAP_INVALID_SYNTAX;
3591 newval->bv_val = ch_strdup( p );
3592 p = q = newval->bv_val;
3595 if ( ASCII_SPACE( *p ) ) {
3596 /* Ignore whitespace */
3603 assert( *newval->bv_val );
3604 assert( newval->bv_val < p );
3607 /* cannot start with a space */
3608 assert( !ASCII_SPACE(*newval->bv_val) );
3610 /* cannot end with a space */
3611 assert( !ASCII_SPACE( q[-1] ) );
3613 /* null terminate */
3616 newval->bv_len = q - newval->bv_val;
3617 *normalized = newval;
3619 return LDAP_SUCCESS;
3623 objectIdentifierFirstComponentMatch(
3628 struct berval *value,
3629 void *assertedValue )
3631 int rc = LDAP_SUCCESS;
3633 struct berval *asserted = (struct berval *) assertedValue;
3637 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3638 return LDAP_INVALID_SYNTAX;
3641 /* trim leading white space */
3642 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3646 /* grab next word */
3647 oid.bv_val = &value->bv_val[i];
3648 oid.bv_len = value->bv_len - i;
3649 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3654 /* insert attributeTypes, objectclass check here */
3655 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3656 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3659 char *stored = ch_malloc( oid.bv_len + 1 );
3660 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3661 stored[oid.bv_len] = '\0';
3663 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3664 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3665 MatchingRule *stored_mr = mr_find( stored );
3667 if( asserted_mr == NULL ) {
3668 rc = SLAPD_COMPARE_UNDEFINED;
3670 match = asserted_mr != stored_mr;
3673 } else if ( !strcmp( syntax->ssyn_oid,
3674 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3676 AttributeType *asserted_at = at_find( asserted->bv_val );
3677 AttributeType *stored_at = at_find( stored );
3679 if( asserted_at == NULL ) {
3680 rc = SLAPD_COMPARE_UNDEFINED;
3682 match = asserted_at != stored_at;
3685 } else if ( !strcmp( syntax->ssyn_oid,
3686 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3688 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3689 ObjectClass *stored_oc = oc_find( stored );
3691 if( asserted_oc == NULL ) {
3692 rc = SLAPD_COMPARE_UNDEFINED;
3694 match = asserted_oc != stored_oc;
3701 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3702 "%d\n\t\"%s\"\n\t\"%s\"\n",
3703 match, value->bv_val, asserted->bv_val );
3705 if( rc == LDAP_SUCCESS ) *matchp = match;
3710 check_time_syntax (struct berval *val,
3714 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3715 static int mdays[2][12] = {
3716 /* non-leap years */
3717 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3719 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3722 int part, c, tzoffset, leapyear = 0 ;
3724 if( val->bv_len == 0 ) {
3725 return LDAP_INVALID_SYNTAX;
3728 p = (char *)val->bv_val;
3729 e = p + val->bv_len;
3731 /* Ignore initial whitespace */
3732 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3736 if (e - p < 13 - (2 * start)) {
3737 return LDAP_INVALID_SYNTAX;
3740 for (part = 0; part < 9; part++) {
3744 for (part = start; part < 7; part++) {
3746 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3753 return LDAP_INVALID_SYNTAX;
3755 if (c < 0 || c > 9) {
3756 return LDAP_INVALID_SYNTAX;
3762 return LDAP_INVALID_SYNTAX;
3764 if (c < 0 || c > 9) {
3765 return LDAP_INVALID_SYNTAX;
3770 if (part == 2 || part == 3) {
3773 if (parts[part] < 0) {
3774 return LDAP_INVALID_SYNTAX;
3776 if (parts[part] > ceiling[part]) {
3777 return LDAP_INVALID_SYNTAX;
3781 /* leapyear check for the Gregorian calendar (year>1581) */
3782 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3783 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3788 if (parts[3] > mdays[leapyear][parts[2]]) {
3789 return LDAP_INVALID_SYNTAX;
3794 tzoffset = 0; /* UTC */
3795 } else if (c != '+' && c != '-') {
3796 return LDAP_INVALID_SYNTAX;
3800 } else /* c == '+' */ {
3805 return LDAP_INVALID_SYNTAX;
3808 for (part = 7; part < 9; part++) {
3810 if (c < 0 || c > 9) {
3811 return LDAP_INVALID_SYNTAX;
3816 if (c < 0 || c > 9) {
3817 return LDAP_INVALID_SYNTAX;
3821 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3822 return LDAP_INVALID_SYNTAX;
3827 /* Ignore trailing whitespace */
3828 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3832 return LDAP_INVALID_SYNTAX;
3835 switch ( tzoffset ) {
3836 case -1: /* negativ offset to UTC, ie west of Greenwich */
3837 parts[4] += parts[7];
3838 parts[5] += parts[8];
3839 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3843 c = mdays[leapyear][parts[2]];
3845 if (parts[part] > c) {
3846 parts[part] -= c + 1;
3851 case 1: /* positive offset to UTC, ie east of Greenwich */
3852 parts[4] -= parts[7];
3853 parts[5] -= parts[8];
3854 for (part = 6; --part > 0; ) {
3858 /* first arg to % needs to be non negativ */
3859 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3861 if (parts[part] < 0) {
3862 parts[part] += c + 1;
3867 case 0: /* already UTC */
3871 return LDAP_SUCCESS;
3878 struct berval **normalized )
3883 rc = check_time_syntax(val, 1, parts);
3884 if (rc != LDAP_SUCCESS) {
3889 out = ch_malloc( sizeof(struct berval) );
3891 return LBER_ERROR_MEMORY;
3894 out->bv_val = ch_malloc( 14 );
3895 if ( out->bv_val == NULL ) {
3897 return LBER_ERROR_MEMORY;
3900 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3901 parts[1], parts[2] + 1, parts[3] + 1,
3902 parts[4], parts[5], parts[6] );
3906 return LDAP_SUCCESS;
3916 return check_time_syntax(in, 1, parts);
3920 generalizedTimeValidate(
3926 return check_time_syntax(in, 0, parts);
3930 generalizedTimeNormalize(
3933 struct berval **normalized )
3938 rc = check_time_syntax(val, 0, parts);
3939 if (rc != LDAP_SUCCESS) {
3944 out = ch_malloc( sizeof(struct berval) );
3946 return LBER_ERROR_MEMORY;
3949 out->bv_val = ch_malloc( 16 );
3950 if ( out->bv_val == NULL ) {
3952 return LBER_ERROR_MEMORY;
3955 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3956 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3957 parts[4], parts[5], parts[6] );
3961 return LDAP_SUCCESS;
3965 nisNetgroupTripleValidate(
3967 struct berval *val )
3972 if ( val->bv_len == 0 ) {
3973 return LDAP_INVALID_SYNTAX;
3976 p = (char *)val->bv_val;
3977 e = p + val->bv_len;
3980 /* syntax does not allow leading white space */
3981 /* Ignore initial whitespace */
3982 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3987 if ( *p != '(' /*')'*/ ) {
3988 return LDAP_INVALID_SYNTAX;
3991 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3995 return LDAP_INVALID_SYNTAX;
3998 } else if ( !ATTR_CHAR( *p ) ) {
3999 return LDAP_INVALID_SYNTAX;
4003 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4004 return LDAP_INVALID_SYNTAX;
4010 /* syntax does not allow trailing white space */
4011 /* Ignore trailing whitespace */
4012 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4018 return LDAP_INVALID_SYNTAX;
4021 return LDAP_SUCCESS;
4025 bootParameterValidate(
4027 struct berval *val )
4031 if ( val->bv_len == 0 ) {
4032 return LDAP_INVALID_SYNTAX;
4035 p = (char *)val->bv_val;
4036 e = p + val->bv_len;
4039 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4040 if ( !ATTR_CHAR( *p ) ) {
4041 return LDAP_INVALID_SYNTAX;
4046 return LDAP_INVALID_SYNTAX;
4050 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4051 if ( !ATTR_CHAR( *p ) ) {
4052 return LDAP_INVALID_SYNTAX;
4057 return LDAP_INVALID_SYNTAX;
4061 for ( p++; p < e; p++ ) {
4062 if ( !ATTR_CHAR( *p ) ) {
4063 return LDAP_INVALID_SYNTAX;
4067 return LDAP_SUCCESS;
4070 struct syntax_defs_rec {
4073 slap_syntax_validate_func *sd_validate;
4074 slap_syntax_transform_func *sd_normalize;
4075 slap_syntax_transform_func *sd_pretty;
4076 #ifdef SLAPD_BINARY_CONVERSION
4077 slap_syntax_transform_func *sd_ber2str;
4078 slap_syntax_transform_func *sd_str2ber;
4082 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4083 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4085 struct syntax_defs_rec syntax_defs[] = {
4086 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4087 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4088 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4089 0, NULL, NULL, NULL},
4090 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4091 0, NULL, NULL, NULL},
4092 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4093 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4094 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4095 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4096 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4097 0, bitStringValidate, NULL, NULL },
4098 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4099 0, booleanValidate, NULL, NULL},
4100 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4101 X_BINARY X_NOT_H_R ")",
4102 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4103 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4104 X_BINARY X_NOT_H_R ")",
4105 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4106 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4107 X_BINARY X_NOT_H_R ")",
4108 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4109 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4110 0, NULL, NULL, NULL},
4111 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4112 0, dnValidate, dnNormalize, dnPretty},
4113 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4114 0, NULL, NULL, NULL},
4115 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4116 0, NULL, NULL, NULL},
4117 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4118 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4119 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4120 0, NULL, NULL, NULL},
4121 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4122 0, NULL, NULL, NULL},
4123 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4124 0, NULL, NULL, NULL},
4125 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4126 0, NULL, NULL, NULL},
4127 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4128 0, NULL, NULL, NULL},
4129 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4130 0, IA5StringValidate, faxNumberNormalize, NULL},
4131 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4132 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4133 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4134 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4135 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4136 0, NULL, NULL, NULL},
4137 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4138 0, IA5StringValidate, IA5StringNormalize, NULL},
4139 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4140 0, integerValidate, integerNormalize, integerPretty},
4141 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4142 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4144 0, NULL, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4146 0, NULL, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4148 0, NULL, NULL, NULL},
4149 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4150 0, NULL, NULL, NULL},
4151 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4152 0, NULL, NULL, NULL},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4154 0, nameUIDValidate, nameUIDNormalize, NULL},
4155 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4156 0, NULL, NULL, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4158 0, IA5StringValidate, numericStringNormalize, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4160 0, NULL, NULL, NULL},
4161 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4162 0, oidValidate, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4164 0, NULL, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4166 0, blobValidate, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4168 0, blobValidate, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4170 0, NULL, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4172 0, NULL, NULL, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4174 0, printableStringValidate, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4176 X_BINARY X_NOT_H_R ")",
4177 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4179 0, IA5StringValidate, phoneNumberNormalize, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4181 0, NULL, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4183 0, IA5StringValidate, telexNumberNormalize, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4185 0, utcTimeValidate, utcTimeNormalize, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4187 0, NULL, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4189 0, NULL, NULL, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4191 0, NULL, NULL, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4193 0, NULL, NULL, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4195 0, NULL, NULL, NULL},
4197 /* RFC 2307 NIS Syntaxes */
4198 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4199 0, nisNetgroupTripleValidate, NULL, NULL},
4200 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4201 0, bootParameterValidate, NULL, NULL},
4203 /* OpenLDAP Experimental Syntaxes */
4204 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4205 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4207 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4208 0, NULL, NULL, NULL},
4210 /* OpenLDAP Void Syntax */
4211 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4212 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4213 {NULL, 0, NULL, NULL, NULL}
4216 struct mrule_defs_rec {
4218 slap_mask_t mrd_usage;
4219 slap_mr_convert_func * mrd_convert;
4220 slap_mr_normalize_func * mrd_normalize;
4221 slap_mr_match_func * mrd_match;
4222 slap_mr_indexer_func * mrd_indexer;
4223 slap_mr_filter_func * mrd_filter;
4225 char * mrd_associated;
4229 * Other matching rules in X.520 that we do not use (yet):
4231 * 2.5.13.9 numericStringOrderingMatch
4232 * 2.5.13.15 integerOrderingMatch
4233 * 2.5.13.18 octetStringOrderingMatch
4234 * 2.5.13.19 octetStringSubstringsMatch
4235 * 2.5.13.25 uTCTimeMatch
4236 * 2.5.13.26 uTCTimeOrderingMatch
4237 * 2.5.13.31 directoryStringFirstComponentMatch
4238 * 2.5.13.32 wordMatch
4239 * 2.5.13.33 keywordMatch
4240 * 2.5.13.34 certificateExactMatch
4241 * 2.5.13.35 certificateMatch
4242 * 2.5.13.36 certificatePairExactMatch
4243 * 2.5.13.37 certificatePairMatch
4244 * 2.5.13.38 certificateListExactMatch
4245 * 2.5.13.39 certificateListMatch
4246 * 2.5.13.40 algorithmIdentifierMatch
4247 * 2.5.13.41 storedPrefixMatch
4248 * 2.5.13.42 attributeCertificateMatch
4249 * 2.5.13.43 readerAndKeyIDMatch
4250 * 2.5.13.44 attributeIntegrityMatch
4253 struct mrule_defs_rec mrule_defs[] = {
4255 * EQUALITY matching rules must be listed after associated APPROX
4256 * matching rules. So, we list all APPROX matching rules first.
4258 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4259 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4260 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4262 directoryStringApproxMatch, directoryStringApproxIndexer,
4263 directoryStringApproxFilter,
4266 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4267 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4268 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4270 IA5StringApproxMatch, IA5StringApproxIndexer,
4271 IA5StringApproxFilter,
4275 * Other matching rules
4278 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4279 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4280 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4282 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4285 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4286 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4287 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4289 dnMatch, dnIndexer, dnFilter,
4292 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4293 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4294 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4296 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4297 directoryStringApproxMatchOID },
4299 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4300 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4303 caseIgnoreOrderingMatch, NULL, NULL,
4306 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4307 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4308 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4310 caseIgnoreSubstringsMatch,
4311 caseIgnoreSubstringsIndexer,
4312 caseIgnoreSubstringsFilter,
4315 {"( 2.5.13.5 NAME 'caseExactMatch' "
4316 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4317 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4319 caseExactMatch, caseExactIndexer, caseExactFilter,
4320 directoryStringApproxMatchOID },
4322 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4323 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4326 caseExactOrderingMatch, NULL, NULL,
4329 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4330 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4331 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4333 caseExactSubstringsMatch,
4334 caseExactSubstringsIndexer,
4335 caseExactSubstringsFilter,
4338 {"( 2.5.13.8 NAME 'numericStringMatch' "
4339 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4340 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4343 caseIgnoreIA5Indexer,
4344 caseIgnoreIA5Filter,
4347 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4348 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4349 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4351 caseIgnoreIA5SubstringsMatch,
4352 caseIgnoreIA5SubstringsIndexer,
4353 caseIgnoreIA5SubstringsFilter,
4356 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4357 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4358 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4360 caseIgnoreListMatch, NULL, NULL,
4363 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4364 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4365 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4367 caseIgnoreListSubstringsMatch, NULL, NULL,
4370 {"( 2.5.13.13 NAME 'booleanMatch' "
4371 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4372 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4374 booleanMatch, NULL, NULL,
4377 {"( 2.5.13.14 NAME 'integerMatch' "
4378 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4379 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4381 integerMatch, integerIndexer, integerFilter,
4384 {"( 2.5.13.16 NAME 'bitStringMatch' "
4385 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4386 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4388 bitStringMatch, NULL, NULL,
4391 {"( 2.5.13.17 NAME 'octetStringMatch' "
4392 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4393 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4395 octetStringMatch, octetStringIndexer, octetStringFilter,
4398 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4399 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4400 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4402 telephoneNumberMatch, NULL, NULL,
4405 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4406 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4407 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4409 telephoneNumberSubstringsMatch, NULL, NULL,
4412 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4413 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4414 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4416 presentationAddressMatch, NULL, NULL,
4419 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4420 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4421 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4423 uniqueMemberMatch, NULL, NULL,
4426 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4427 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4428 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4430 protocolInformationMatch, NULL, NULL,
4433 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4434 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4435 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4437 generalizedTimeMatch, NULL, NULL,
4440 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4441 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4444 generalizedTimeOrderingMatch, NULL, NULL,
4447 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4448 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4449 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4451 integerFirstComponentMatch, NULL, NULL,
4454 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4455 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4456 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4458 objectIdentifierFirstComponentMatch, NULL, NULL,
4461 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4462 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4463 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4465 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4466 IA5StringApproxMatchOID },
4468 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4469 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4470 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4472 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4473 IA5StringApproxMatchOID },
4475 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4476 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4479 caseIgnoreIA5SubstringsMatch,
4480 caseIgnoreIA5SubstringsIndexer,
4481 caseIgnoreIA5SubstringsFilter,
4484 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4485 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4488 caseExactIA5SubstringsMatch,
4489 caseExactIA5SubstringsIndexer,
4490 caseExactIA5SubstringsFilter,
4493 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4494 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4497 authPasswordMatch, NULL, NULL,
4500 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4501 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4504 OpenLDAPaciMatch, NULL, NULL,
4507 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4516 /* we should only be called once (from main) */
4517 assert( schema_init_done == 0 );
4519 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4520 res = register_syntax( syntax_defs[i].sd_desc,
4521 syntax_defs[i].sd_flags,
4522 syntax_defs[i].sd_validate,
4523 syntax_defs[i].sd_normalize,
4524 syntax_defs[i].sd_pretty
4525 #ifdef SLAPD_BINARY_CONVERSION
4527 syntax_defs[i].sd_ber2str,
4528 syntax_defs[i].sd_str2ber
4533 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4534 syntax_defs[i].sd_desc );
4539 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4540 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4542 "schema_init: Ingoring unusable matching rule %s\n",
4543 mrule_defs[i].mrd_desc );
4547 res = register_matching_rule(
4548 mrule_defs[i].mrd_desc,
4549 mrule_defs[i].mrd_usage,
4550 mrule_defs[i].mrd_convert,
4551 mrule_defs[i].mrd_normalize,
4552 mrule_defs[i].mrd_match,
4553 mrule_defs[i].mrd_indexer,
4554 mrule_defs[i].mrd_filter,
4555 mrule_defs[i].mrd_associated );
4559 "schema_init: Error registering matching rule %s\n",
4560 mrule_defs[i].mrd_desc );
4564 schema_init_done = 1;
4565 return LDAP_SUCCESS;