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>
20 #include "lutil_md5.h"
21 /* We should replace MD5 with a faster hash */
22 #define HASH_BYTES LUTIL_MD5_BYTES
23 #define HASH_CONTEXT lutil_MD5_CTX
24 #define HASH_Init(c) lutil_MD5Init(c)
25 #define HASH_Update(c,buf,len) lutil_MD5Update(c,buf,len)
26 #define HASH_Final(d,c) lutil_MD5Final(d,c)
28 #include "lutil_hash.h"
29 /* We should replace MD5 with a faster hash */
30 #define HASH_BYTES LUTIL_HASH_BYTES
31 #define HASH_CONTEXT lutil_HASH_CTX
32 #define HASH_Init(c) lutil_HASHInit(c)
33 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
34 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
37 /* recycled validatation routines */
38 #define berValidate blobValidate
40 /* recycled normalization routines */
41 #define faxNumberNormalize numericStringNormalize
42 #define phoneNumberNormalize numericStringNormalize
43 #define telexNumberNormalize numericStringNormalize
45 /* unimplemented pretters */
47 #define integerPretty NULL
49 /* recycled matching routines */
50 #define bitStringMatch octetStringMatch
51 #define integerMatch caseIgnoreIA5Match
52 #define numericStringMatch caseIgnoreMatch
53 #define objectIdentifierMatch numericStringMatch
54 #define telephoneNumberMatch numericStringMatch
55 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
56 #define generalizedTimeMatch numericStringMatch
57 #define generalizedTimeOrderingMatch numericStringMatch
58 #define uniqueMemberMatch dnMatch
60 /* approx matching rules */
61 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
62 #define directoryStringApproxMatch approxMatch
63 #define directoryStringApproxIndexer approxIndexer
64 #define directoryStringApproxFilter approxFilter
65 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
66 #define IA5StringApproxMatch approxMatch
67 #define IA5StringApproxIndexer approxIndexer
68 #define IA5StringApproxFilter approxFilter
70 /* orderring matching rules */
71 #define caseIgnoreOrderingMatch caseIgnoreMatch
72 #define caseExactOrderingMatch caseExactMatch
74 /* unimplemented matching routines */
75 #define caseIgnoreListMatch NULL
76 #define caseIgnoreListSubstringsMatch NULL
77 #define presentationAddressMatch NULL
78 #define protocolInformationMatch NULL
79 #define integerFirstComponentMatch NULL
81 #define OpenLDAPaciMatch NULL
82 #define authPasswordMatch NULL
84 /* recycled indexing/filtering routines */
85 #define dnIndexer caseIgnoreIndexer
86 #define dnFilter caseIgnoreFilter
87 #define integerIndexer caseIgnoreIA5Indexer
88 #define integerFilter caseIgnoreIA5Filter
90 static char *strcasechr( const char *str, int c )
92 char *lower = strchr( str, TOLOWER(c) );
93 char *upper = strchr( str, TOUPPER(c) );
95 if( lower && upper ) {
96 return lower < upper ? lower : upper;
110 struct berval *value,
111 void *assertedValue )
113 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
116 match = memcmp( value->bv_val,
117 ((struct berval *) assertedValue)->bv_val,
125 /* Index generation function */
126 int octetStringIndexer(
131 struct berval *prefix,
132 struct berval **values,
133 struct berval ***keysp )
137 struct berval **keys;
138 HASH_CONTEXT HASHcontext;
139 unsigned char HASHdigest[HASH_BYTES];
140 struct berval digest;
141 digest.bv_val = HASHdigest;
142 digest.bv_len = sizeof(HASHdigest);
144 /* we should have at least one value at this point */
145 assert( values != NULL && values[0] != NULL );
147 for( i=0; values[i] != NULL; i++ ) {
148 /* just count them */
151 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
153 slen = strlen( syntax->ssyn_oid );
154 mlen = strlen( mr->smr_oid );
156 for( i=0; values[i] != NULL; i++ ) {
157 HASH_Init( &HASHcontext );
158 if( prefix != NULL && prefix->bv_len > 0 ) {
159 HASH_Update( &HASHcontext,
160 prefix->bv_val, prefix->bv_len );
162 HASH_Update( &HASHcontext,
163 syntax->ssyn_oid, slen );
164 HASH_Update( &HASHcontext,
166 HASH_Update( &HASHcontext,
167 values[i]->bv_val, values[i]->bv_len );
168 HASH_Final( HASHdigest, &HASHcontext );
170 keys[i] = ber_bvdup( &digest );
180 /* Index generation function */
181 int octetStringFilter(
186 struct berval *prefix,
188 struct berval ***keysp )
191 struct berval **keys;
192 HASH_CONTEXT HASHcontext;
193 unsigned char HASHdigest[HASH_BYTES];
194 struct berval *value = (struct berval *) assertValue;
195 struct berval digest;
196 digest.bv_val = HASHdigest;
197 digest.bv_len = sizeof(HASHdigest);
199 slen = strlen( syntax->ssyn_oid );
200 mlen = strlen( mr->smr_oid );
202 keys = ch_malloc( sizeof( struct berval * ) * 2 );
204 HASH_Init( &HASHcontext );
205 if( prefix != NULL && prefix->bv_len > 0 ) {
206 HASH_Update( &HASHcontext,
207 prefix->bv_val, prefix->bv_len );
209 HASH_Update( &HASHcontext,
210 syntax->ssyn_oid, slen );
211 HASH_Update( &HASHcontext,
213 HASH_Update( &HASHcontext,
214 value->bv_val, value->bv_len );
215 HASH_Final( HASHdigest, &HASHcontext );
217 keys[0] = ber_bvdup( &digest );
233 if( in->bv_len == 0 ) return LDAP_SUCCESS;
235 dn = ch_strdup( in->bv_val );
237 rc = dn_validate( dn ) == NULL
238 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
248 struct berval **normalized )
250 struct berval *out = ber_bvdup( val );
252 if( out->bv_len != 0 ) {
254 #ifdef USE_DN_NORMALIZE
255 dn = dn_normalize( out->bv_val );
257 dn = dn_validate( out->bv_val );
262 return LDAP_INVALID_SYNTAX;
266 out->bv_len = strlen( dn );
279 struct berval *value,
280 void *assertedValue )
283 struct berval *asserted = (struct berval *) assertedValue;
285 match = value->bv_len - asserted->bv_len;
288 #ifdef USE_DN_NORMALIZE
289 match = strcmp( value->bv_val, asserted->bv_val );
291 match = strcasecmp( value->bv_val, asserted->bv_val );
295 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
296 match, value->bv_val, asserted->bv_val );
310 if( in->bv_len == 0 ) return LDAP_SUCCESS;
312 dn = ber_bvdup( in );
314 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
315 /* assume presence of optional UID */
318 for(i=dn->bv_len-2; i>2; i--) {
319 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
323 if( dn->bv_val[i] != '\'' ) {
324 return LDAP_INVALID_SYNTAX;
326 if( dn->bv_val[i-1] != 'B' ) {
327 return LDAP_INVALID_SYNTAX;
329 if( dn->bv_val[i-2] != '#' ) {
330 return LDAP_INVALID_SYNTAX;
333 /* trim the UID to allow use of dn_validate */
334 dn->bv_val[i-2] = '\0';
337 rc = dn_validate( dn->bv_val ) == NULL
338 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
348 struct berval **normalized )
350 struct berval *out = ber_bvdup( val );
352 if( out->bv_len != 0 ) {
356 ber_len_t uidlen = 0;
358 if( out->bv_val[out->bv_len-1] == '\'' ) {
359 /* assume presence of optional UID */
360 uid = strrchr( out->bv_val, '#' );
364 return LDAP_INVALID_SYNTAX;
367 uidlen = out->bv_len - (out->bv_val - uid);
368 /* temporarily trim the UID */
372 #ifdef USE_DN_NORMALIZE
373 dn = dn_normalize( out->bv_val );
375 dn = dn_validate( out->bv_val );
380 return LDAP_INVALID_SYNTAX;
386 /* restore the separator */
389 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
393 out->bv_len = dnlen + uidlen;
405 /* any value allowed */
414 /* any value allowed */
425 /* very unforgiving validation, requires no normalization
426 * before simplistic matching
428 if( in->bv_len < 3 ) {
429 return LDAP_INVALID_SYNTAX;
431 if( in->bv_val[0] != 'B' ||
432 in->bv_val[1] != '\'' ||
433 in->bv_val[in->bv_len-1] != '\'' )
435 return LDAP_INVALID_SYNTAX;
438 for( i=in->bv_len-2; i>1; i-- ) {
439 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
440 return LDAP_INVALID_SYNTAX;
448 * Handling boolean syntax and matching is quite rigid.
449 * A more flexible approach would be to allow a variety
450 * of strings to be normalized and prettied into TRUE
458 /* very unforgiving validation, requires no normalization
459 * before simplistic matching
462 if( in->bv_len == 4 ) {
463 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
466 } else if( in->bv_len == 5 ) {
467 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
472 return LDAP_INVALID_SYNTAX;
481 struct berval *value,
482 void *assertedValue )
484 /* simplistic matching allowed by rigid validation */
485 struct berval *asserted = (struct berval *) assertedValue;
486 *matchp = value->bv_len != asserted->bv_len;
493 struct berval *right,
494 struct berval *left )
498 ldap_unicode_t ru, lu;
499 ldap_unicode_t ruu, luu;
502 r < right->bv_len && l < left->bv_len;
506 * XXYYZ: we convert to ucs4 even though -llunicode
507 * expects ucs2 in an unsigned long
509 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
510 if( ru == LDAP_UCS4_INVALID ) {
514 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
515 if( lu == LDAP_UCS4_INVALID ) {
519 ruu = uctoupper( ru );
520 luu = uctoupper( lu );
524 } else if( luu > ruu ) {
528 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
529 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
532 if( r < right->bv_len ) {
537 if( l < left->bv_len ) {
553 unsigned char *u = in->bv_val;
555 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
557 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
558 /* get the length indicated by the first byte */
559 len = LDAP_UTF8_CHARLEN( u );
561 /* should not be zero */
562 if( len == 0 ) return LDAP_INVALID_SYNTAX;
564 /* make sure len corresponds with the offset
565 to the next character */
566 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
569 if( count != 0 ) return LDAP_INVALID_SYNTAX;
578 struct berval **normalized )
580 struct berval *newval;
583 newval = ch_malloc( sizeof( struct berval ) );
587 /* Ignore initial whitespace */
588 while ( ldap_utf8_isspace( p ) ) {
594 return LDAP_INVALID_SYNTAX;
597 newval->bv_val = ch_strdup( p );
598 p = q = newval->bv_val;
604 if ( ldap_utf8_isspace( p ) ) {
605 len = LDAP_UTF8_COPY(q,p);
610 /* Ignore the extra whitespace */
611 while ( ldap_utf8_isspace( p ) ) {
615 len = LDAP_UTF8_COPY(q,p);
622 assert( *newval->bv_val );
623 assert( newval->bv_val < p );
626 /* cannot start with a space */
627 assert( !ldap_utf8_isspace(newval->bv_val) );
630 * If the string ended in space, backup the pointer one
631 * position. One is enough because the above loop collapsed
632 * all whitespace to a single space.
639 /* cannot end with a space */
640 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
645 newval->bv_len = q - newval->bv_val;
646 *normalized = newval;
651 #if defined(SLAPD_APPROX_MULTISTRING)
653 #if defined(SLAPD_APPROX_INITIALS)
654 #define SLAPD_APPROX_DELIMITER "._ "
655 #define SLAPD_APPROX_WORDLEN 2
657 #define SLAPD_APPROX_DELIMITER " "
658 #define SLAPD_APPROX_WORDLEN 1
667 struct berval *value,
668 void *assertedValue )
670 char *val, *assertv, **values, **words, *c;
671 int i, count, len, nextchunk=0, nextavail=0;
674 /* Isolate how many words there are */
675 val = ch_strdup( value->bv_val );
676 for( c=val,count=1; *c; c++ ) {
677 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
678 if ( c == NULL ) break;
683 /* Get a phonetic copy of each word */
684 words = (char **)ch_malloc( count * sizeof(char *) );
685 values = (char **)ch_malloc( count * sizeof(char *) );
686 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
688 values[i] = phonetic(c);
692 /* Work through the asserted value's words, to see if at least some
693 of the words are there, in the same order. */
694 assertv = ch_strdup( ((struct berval *)assertedValue)->bv_val );
696 while ( nextchunk < ((struct berval *)assertedValue)->bv_len ) {
697 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
698 #if defined(SLAPD_APPROX_INITIALS)
700 /* Single letter words need to at least match one word's initial */
701 for( i=nextavail; i<count; i++ )
702 if( !strncasecmp( assertv+nextchunk, words[i], 1 ))
709 /* Isolate the next word in the asserted value and phonetic it */
710 assertv[nextchunk+len] = '\0';
711 val = phonetic( assertv + nextchunk );
713 /* See if this phonetic chunk is in the remaining words of *value */
714 for( i=nextavail; i<count; i++ ){
715 if( !strcmp( val, values[i] ) ){
722 /* This chunk in the asserted value was NOT within the *value. */
728 /* Go on to the next word in the asserted value */
732 /* If some of the words were seen, call it a match */
733 if( nextavail > 0 ) {
742 for( i=0; i<count; i++ ) {
743 ch_free( values[i] );
759 struct berval *prefix,
760 struct berval **values,
761 struct berval ***keysp )
764 int i,j, len, wordcount, keycount=0;
765 struct berval **newkeys, **keys=NULL;
768 for( j=0; values[j] != NULL; j++ ) {
770 /* Isolate how many words there are. There will be a key for each */
771 val = ch_strdup( values[j]->bv_val );
772 for( wordcount=0,c=val; *c; c++) {
773 len = strcspn(c, SLAPD_APPROX_DELIMITER);
774 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
776 if (*c == '\0') break;
780 /* Allocate/increase storage to account for new keys */
781 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
782 * sizeof(struct berval *) );
783 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
784 if( keys ) ch_free( keys );
787 /* Get a phonetic copy of each word */
788 for( c=val,i=0; i<wordcount; c+=len+1 ) {
790 if( len < SLAPD_APPROX_WORDLEN ) continue;
791 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
792 keys[keycount]->bv_val = phonetic( c );
793 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
800 keys[keycount] = NULL;
813 struct berval *prefix,
815 struct berval ***keysp )
819 struct berval **keys;
822 /* Isolate how many words there are. There will be a key for each */
823 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
824 for( count=0,c=val; *c; c++) {
825 len = strcspn(c, SLAPD_APPROX_DELIMITER);
826 if( len >= SLAPD_APPROX_WORDLEN ) count++;
828 if (*c == '\0') break;
832 /* Allocate storage for new keys */
833 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
835 /* Get a phonetic copy of each word */
836 for( c=val,i=0; i<count; c+=len+1 ) {
838 if( len < SLAPD_APPROX_WORDLEN ) continue;
839 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
840 keys[i]->bv_val = phonetic( c );
841 keys[i]->bv_len = strlen( keys[i]->bv_val );
855 /* No other form of Approximate Matching is defined */
863 struct berval *value,
864 void *assertedValue )
866 char *vapprox, *avapprox;
868 vapprox = phonetic( value->bv_val );
869 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
871 *matchp = strcmp( vapprox, avapprox );
885 struct berval *prefix,
886 struct berval **values,
887 struct berval ***keysp )
890 struct berval **keys;
893 for( i=0; values[i] != NULL; i++ ) {
894 /* just count them */
898 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
900 /* Copy each value and run it through phonetic() */
901 for( i=0; values[i] != NULL; i++ ) {
902 keys[i] = ch_malloc( sizeof( struct berval * ) );
903 keys[i]->bv_val = phonetic( values[i]->bv_val );
904 keys[i]->bv_len = strlen( keys[i]->bv_val );
919 struct berval *prefix,
921 struct berval ***keysp )
923 struct berval **keys;
926 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
928 /* Copy the value and run it through phonetic() */
929 keys[0] = ch_malloc( sizeof( struct berval * ) );
930 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
931 keys[0]->bv_len = strlen( keys[0]->bv_val );
946 struct berval *value,
947 void *assertedValue )
949 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
952 match = strncmp( value->bv_val,
953 ((struct berval *) assertedValue)->bv_val,
962 caseExactSubstringsMatch(
967 struct berval *value,
968 void *assertedValue )
971 SubstringsAssertion *sub = assertedValue;
972 struct berval left = *value;
976 /* Add up asserted input length */
977 if( sub->sa_initial ) {
978 inlen += sub->sa_initial->bv_len;
981 for(i=0; sub->sa_any[i] != NULL; i++) {
982 inlen += sub->sa_any[i]->bv_len;
985 if( sub->sa_final ) {
986 inlen += sub->sa_final->bv_len;
989 if( sub->sa_initial ) {
990 if( inlen > left.bv_len ) {
995 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
996 sub->sa_initial->bv_len );
1002 left.bv_val += sub->sa_initial->bv_len;
1003 left.bv_len -= sub->sa_initial->bv_len;
1004 inlen -= sub->sa_initial->bv_len;
1007 if( sub->sa_final ) {
1008 if( inlen > left.bv_len ) {
1013 match = strncmp( sub->sa_final->bv_val,
1014 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1015 sub->sa_final->bv_len );
1021 left.bv_len -= sub->sa_final->bv_len;
1022 inlen -= sub->sa_final->bv_len;
1026 for(i=0; sub->sa_any[i]; i++) {
1031 if( inlen > left.bv_len ) {
1032 /* not enough length */
1037 if( sub->sa_any[i]->bv_len == 0 ) {
1041 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1048 idx = p - left.bv_val;
1049 assert( idx < left.bv_len );
1051 if( idx >= left.bv_len ) {
1052 /* this shouldn't happen */
1059 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1060 /* not enough left */
1065 match = strncmp( left.bv_val,
1066 sub->sa_any[i]->bv_val,
1067 sub->sa_any[i]->bv_len );
1075 left.bv_val += sub->sa_any[i]->bv_len;
1076 left.bv_len -= sub->sa_any[i]->bv_len;
1077 inlen -= sub->sa_any[i]->bv_len;
1083 return LDAP_SUCCESS;
1086 /* Index generation function */
1087 int caseExactIndexer(
1092 struct berval *prefix,
1093 struct berval **values,
1094 struct berval ***keysp )
1098 struct berval **keys;
1099 HASH_CONTEXT HASHcontext;
1100 unsigned char HASHdigest[HASH_BYTES];
1101 struct berval digest;
1102 digest.bv_val = HASHdigest;
1103 digest.bv_len = sizeof(HASHdigest);
1105 /* we should have at least one value at this point */
1106 assert( values != NULL && values[0] != NULL );
1108 for( i=0; values[i] != NULL; i++ ) {
1109 /* just count them */
1112 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1114 slen = strlen( syntax->ssyn_oid );
1115 mlen = strlen( mr->smr_oid );
1117 for( i=0; values[i] != NULL; i++ ) {
1118 struct berval *value = values[i];
1120 HASH_Init( &HASHcontext );
1121 if( prefix != NULL && prefix->bv_len > 0 ) {
1122 HASH_Update( &HASHcontext,
1123 prefix->bv_val, prefix->bv_len );
1125 HASH_Update( &HASHcontext,
1126 syntax->ssyn_oid, slen );
1127 HASH_Update( &HASHcontext,
1128 mr->smr_oid, mlen );
1129 HASH_Update( &HASHcontext,
1130 value->bv_val, value->bv_len );
1131 HASH_Final( HASHdigest, &HASHcontext );
1133 keys[i] = ber_bvdup( &digest );
1138 return LDAP_SUCCESS;
1141 /* Index generation function */
1142 int caseExactFilter(
1147 struct berval *prefix,
1149 struct berval ***keysp )
1152 struct berval **keys;
1153 HASH_CONTEXT HASHcontext;
1154 unsigned char HASHdigest[HASH_BYTES];
1155 struct berval *value;
1156 struct berval digest;
1157 digest.bv_val = HASHdigest;
1158 digest.bv_len = sizeof(HASHdigest);
1160 slen = strlen( syntax->ssyn_oid );
1161 mlen = strlen( mr->smr_oid );
1163 value = (struct berval *) assertValue;
1165 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1167 HASH_Init( &HASHcontext );
1168 if( prefix != NULL && prefix->bv_len > 0 ) {
1169 HASH_Update( &HASHcontext,
1170 prefix->bv_val, prefix->bv_len );
1172 HASH_Update( &HASHcontext,
1173 syntax->ssyn_oid, slen );
1174 HASH_Update( &HASHcontext,
1175 mr->smr_oid, mlen );
1176 HASH_Update( &HASHcontext,
1177 value->bv_val, value->bv_len );
1178 HASH_Final( HASHdigest, &HASHcontext );
1180 keys[0] = ber_bvdup( &digest );
1184 return LDAP_SUCCESS;
1187 /* Substrings Index generation function */
1188 int caseExactSubstringsIndexer(
1193 struct berval *prefix,
1194 struct berval **values,
1195 struct berval ***keysp )
1199 struct berval **keys;
1200 HASH_CONTEXT HASHcontext;
1201 unsigned char HASHdigest[HASH_BYTES];
1202 struct berval digest;
1203 digest.bv_val = HASHdigest;
1204 digest.bv_len = sizeof(HASHdigest);
1206 /* we should have at least one value at this point */
1207 assert( values != NULL && values[0] != NULL );
1210 for( i=0; values[i] != NULL; i++ ) {
1211 /* count number of indices to generate */
1212 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1216 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1217 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1218 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1219 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1221 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1225 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1226 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1227 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1231 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1232 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1233 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1234 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1236 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1242 /* no keys to generate */
1244 return LDAP_SUCCESS;
1247 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1249 slen = strlen( syntax->ssyn_oid );
1250 mlen = strlen( mr->smr_oid );
1253 for( i=0; values[i] != NULL; i++ ) {
1255 struct berval *value;
1258 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1260 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1261 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1263 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1264 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1266 for( j=0; j<max; j++ ) {
1267 HASH_Init( &HASHcontext );
1268 if( prefix != NULL && prefix->bv_len > 0 ) {
1269 HASH_Update( &HASHcontext,
1270 prefix->bv_val, prefix->bv_len );
1273 HASH_Update( &HASHcontext,
1274 &pre, sizeof( pre ) );
1275 HASH_Update( &HASHcontext,
1276 syntax->ssyn_oid, slen );
1277 HASH_Update( &HASHcontext,
1278 mr->smr_oid, mlen );
1279 HASH_Update( &HASHcontext,
1281 SLAP_INDEX_SUBSTR_MAXLEN );
1282 HASH_Final( HASHdigest, &HASHcontext );
1284 keys[nkeys++] = ber_bvdup( &digest );
1288 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1289 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1291 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1294 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1295 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1296 HASH_Init( &HASHcontext );
1297 if( prefix != NULL && prefix->bv_len > 0 ) {
1298 HASH_Update( &HASHcontext,
1299 prefix->bv_val, prefix->bv_len );
1301 HASH_Update( &HASHcontext,
1302 &pre, sizeof( pre ) );
1303 HASH_Update( &HASHcontext,
1304 syntax->ssyn_oid, slen );
1305 HASH_Update( &HASHcontext,
1306 mr->smr_oid, mlen );
1307 HASH_Update( &HASHcontext,
1309 HASH_Final( HASHdigest, &HASHcontext );
1311 keys[nkeys++] = ber_bvdup( &digest );
1314 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1315 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1316 HASH_Init( &HASHcontext );
1317 if( prefix != NULL && prefix->bv_len > 0 ) {
1318 HASH_Update( &HASHcontext,
1319 prefix->bv_val, prefix->bv_len );
1321 HASH_Update( &HASHcontext,
1322 &pre, sizeof( pre ) );
1323 HASH_Update( &HASHcontext,
1324 syntax->ssyn_oid, slen );
1325 HASH_Update( &HASHcontext,
1326 mr->smr_oid, mlen );
1327 HASH_Update( &HASHcontext,
1328 &value->bv_val[value->bv_len-j], j );
1329 HASH_Final( HASHdigest, &HASHcontext );
1331 keys[nkeys++] = ber_bvdup( &digest );
1345 return LDAP_SUCCESS;
1348 int caseExactSubstringsFilter(
1353 struct berval *prefix,
1355 struct berval ***keysp )
1357 SubstringsAssertion *sa = assertValue;
1359 ber_len_t nkeys = 0;
1360 size_t slen, mlen, klen;
1361 struct berval **keys;
1362 HASH_CONTEXT HASHcontext;
1363 unsigned char HASHdigest[HASH_BYTES];
1364 struct berval *value;
1365 struct berval digest;
1367 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1368 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1373 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1375 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1376 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1377 /* don't bother accounting for stepping */
1378 nkeys += sa->sa_any[i]->bv_len -
1379 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1384 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1385 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1392 return LDAP_SUCCESS;
1395 digest.bv_val = HASHdigest;
1396 digest.bv_len = sizeof(HASHdigest);
1398 slen = strlen( syntax->ssyn_oid );
1399 mlen = strlen( mr->smr_oid );
1401 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1404 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1405 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1407 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1408 value = sa->sa_initial;
1410 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1411 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
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, klen );
1426 HASH_Final( HASHdigest, &HASHcontext );
1428 keys[nkeys++] = ber_bvdup( &digest );
1431 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1433 pre = SLAP_INDEX_SUBSTR_PREFIX;
1434 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1436 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1437 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1441 value = sa->sa_any[i];
1444 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1445 j += SLAP_INDEX_SUBSTR_STEP )
1447 HASH_Init( &HASHcontext );
1448 if( prefix != NULL && prefix->bv_len > 0 ) {
1449 HASH_Update( &HASHcontext,
1450 prefix->bv_val, prefix->bv_len );
1452 HASH_Update( &HASHcontext,
1453 &pre, sizeof( pre ) );
1454 HASH_Update( &HASHcontext,
1455 syntax->ssyn_oid, slen );
1456 HASH_Update( &HASHcontext,
1457 mr->smr_oid, mlen );
1458 HASH_Update( &HASHcontext,
1459 &value->bv_val[j], klen );
1460 HASH_Final( HASHdigest, &HASHcontext );
1462 keys[nkeys++] = ber_bvdup( &digest );
1467 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1468 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1470 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1471 value = sa->sa_final;
1473 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1474 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1476 HASH_Init( &HASHcontext );
1477 if( prefix != NULL && prefix->bv_len > 0 ) {
1478 HASH_Update( &HASHcontext,
1479 prefix->bv_val, prefix->bv_len );
1481 HASH_Update( &HASHcontext,
1482 &pre, sizeof( pre ) );
1483 HASH_Update( &HASHcontext,
1484 syntax->ssyn_oid, slen );
1485 HASH_Update( &HASHcontext,
1486 mr->smr_oid, mlen );
1487 HASH_Update( &HASHcontext,
1488 &value->bv_val[value->bv_len-klen], klen );
1489 HASH_Final( HASHdigest, &HASHcontext );
1491 keys[nkeys++] = ber_bvdup( &digest );
1502 return LDAP_SUCCESS;
1511 struct berval *value,
1512 void *assertedValue )
1515 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1517 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1520 match = strncasecmp( value->bv_val,
1521 ((struct berval *) assertedValue)->bv_val,
1527 return LDAP_SUCCESS;
1531 caseIgnoreSubstringsMatch(
1536 struct berval *value,
1537 void *assertedValue )
1540 SubstringsAssertion *sub = assertedValue;
1541 struct berval left = *value;
1545 /* Add up asserted input length */
1546 if( sub->sa_initial ) {
1547 inlen += sub->sa_initial->bv_len;
1550 for(i=0; sub->sa_any[i] != NULL; i++) {
1551 inlen += sub->sa_any[i]->bv_len;
1554 if( sub->sa_final ) {
1555 inlen += sub->sa_final->bv_len;
1558 if( sub->sa_initial ) {
1559 if( inlen > left.bv_len ) {
1564 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1565 sub->sa_initial->bv_len );
1571 left.bv_val += sub->sa_initial->bv_len;
1572 left.bv_len -= sub->sa_initial->bv_len;
1573 inlen -= sub->sa_initial->bv_len;
1576 if( sub->sa_final ) {
1577 if( inlen > left.bv_len ) {
1582 match = strncasecmp( sub->sa_final->bv_val,
1583 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1584 sub->sa_final->bv_len );
1590 left.bv_len -= sub->sa_final->bv_len;
1591 inlen -= sub->sa_final->bv_len;
1595 for(i=0; sub->sa_any[i]; i++) {
1600 if( inlen > left.bv_len ) {
1601 /* not enough length */
1606 if( sub->sa_any[i]->bv_len == 0 ) {
1610 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1617 idx = p - left.bv_val;
1618 assert( idx < left.bv_len );
1620 if( idx >= left.bv_len ) {
1621 /* this shouldn't happen */
1628 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1629 /* not enough left */
1634 match = strncasecmp( left.bv_val,
1635 sub->sa_any[i]->bv_val,
1636 sub->sa_any[i]->bv_len );
1645 left.bv_val += sub->sa_any[i]->bv_len;
1646 left.bv_len -= sub->sa_any[i]->bv_len;
1647 inlen -= sub->sa_any[i]->bv_len;
1653 return LDAP_SUCCESS;
1656 /* Index generation function */
1657 int caseIgnoreIndexer(
1662 struct berval *prefix,
1663 struct berval **values,
1664 struct berval ***keysp )
1668 struct berval **keys;
1669 HASH_CONTEXT HASHcontext;
1670 unsigned char HASHdigest[HASH_BYTES];
1671 struct berval digest;
1672 digest.bv_val = HASHdigest;
1673 digest.bv_len = sizeof(HASHdigest);
1675 /* we should have at least one value at this point */
1676 assert( values != NULL && values[0] != NULL );
1678 for( i=0; values[i] != NULL; i++ ) {
1679 /* just count them */
1682 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1684 slen = strlen( syntax->ssyn_oid );
1685 mlen = strlen( mr->smr_oid );
1687 for( i=0; values[i] != NULL; i++ ) {
1688 struct berval *value = ber_bvdup( values[i] );
1689 ldap_pvt_str2upper( value->bv_val );
1691 HASH_Init( &HASHcontext );
1692 if( prefix != NULL && prefix->bv_len > 0 ) {
1693 HASH_Update( &HASHcontext,
1694 prefix->bv_val, prefix->bv_len );
1696 HASH_Update( &HASHcontext,
1697 syntax->ssyn_oid, slen );
1698 HASH_Update( &HASHcontext,
1699 mr->smr_oid, mlen );
1700 HASH_Update( &HASHcontext,
1701 value->bv_val, value->bv_len );
1702 HASH_Final( HASHdigest, &HASHcontext );
1704 ber_bvfree( value );
1706 keys[i] = ber_bvdup( &digest );
1711 return LDAP_SUCCESS;
1714 /* Index generation function */
1715 int caseIgnoreFilter(
1720 struct berval *prefix,
1722 struct berval ***keysp )
1725 struct berval **keys;
1726 HASH_CONTEXT HASHcontext;
1727 unsigned char HASHdigest[HASH_BYTES];
1728 struct berval *value;
1729 struct berval digest;
1730 digest.bv_val = HASHdigest;
1731 digest.bv_len = sizeof(HASHdigest);
1733 slen = strlen( syntax->ssyn_oid );
1734 mlen = strlen( mr->smr_oid );
1736 value = ber_bvdup( (struct berval *) assertValue );
1737 ldap_pvt_str2upper( value->bv_val );
1739 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1741 HASH_Init( &HASHcontext );
1742 if( prefix != NULL && prefix->bv_len > 0 ) {
1743 HASH_Update( &HASHcontext,
1744 prefix->bv_val, prefix->bv_len );
1746 HASH_Update( &HASHcontext,
1747 syntax->ssyn_oid, slen );
1748 HASH_Update( &HASHcontext,
1749 mr->smr_oid, mlen );
1750 HASH_Update( &HASHcontext,
1751 value->bv_val, value->bv_len );
1752 HASH_Final( HASHdigest, &HASHcontext );
1754 keys[0] = ber_bvdup( &digest );
1757 ber_bvfree( value );
1761 return LDAP_SUCCESS;
1764 /* Substrings Index generation function */
1765 int caseIgnoreSubstringsIndexer(
1770 struct berval *prefix,
1771 struct berval **values,
1772 struct berval ***keysp )
1776 struct berval **keys;
1777 HASH_CONTEXT HASHcontext;
1778 unsigned char HASHdigest[HASH_BYTES];
1779 struct berval digest;
1780 digest.bv_val = HASHdigest;
1781 digest.bv_len = sizeof(HASHdigest);
1783 /* we should have at least one value at this point */
1784 assert( values != NULL && values[0] != NULL );
1787 for( i=0; values[i] != NULL; i++ ) {
1788 /* count number of indices to generate */
1789 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1793 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1794 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1795 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1796 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1798 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1802 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1803 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1804 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1808 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1809 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1810 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1811 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1813 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1819 /* no keys to generate */
1821 return LDAP_SUCCESS;
1824 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1826 slen = strlen( syntax->ssyn_oid );
1827 mlen = strlen( mr->smr_oid );
1830 for( i=0; values[i] != NULL; i++ ) {
1832 struct berval *value;
1834 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1836 value = ber_bvdup( values[i] );
1837 ldap_pvt_str2upper( value->bv_val );
1839 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1840 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1842 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1843 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1845 for( j=0; j<max; j++ ) {
1846 HASH_Init( &HASHcontext );
1847 if( prefix != NULL && prefix->bv_len > 0 ) {
1848 HASH_Update( &HASHcontext,
1849 prefix->bv_val, prefix->bv_len );
1852 HASH_Update( &HASHcontext,
1853 &pre, sizeof( pre ) );
1854 HASH_Update( &HASHcontext,
1855 syntax->ssyn_oid, slen );
1856 HASH_Update( &HASHcontext,
1857 mr->smr_oid, mlen );
1858 HASH_Update( &HASHcontext,
1860 SLAP_INDEX_SUBSTR_MAXLEN );
1861 HASH_Final( HASHdigest, &HASHcontext );
1863 keys[nkeys++] = ber_bvdup( &digest );
1867 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1868 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1870 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1873 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1874 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1875 HASH_Init( &HASHcontext );
1876 if( prefix != NULL && prefix->bv_len > 0 ) {
1877 HASH_Update( &HASHcontext,
1878 prefix->bv_val, prefix->bv_len );
1880 HASH_Update( &HASHcontext,
1881 &pre, sizeof( pre ) );
1882 HASH_Update( &HASHcontext,
1883 syntax->ssyn_oid, slen );
1884 HASH_Update( &HASHcontext,
1885 mr->smr_oid, mlen );
1886 HASH_Update( &HASHcontext,
1888 HASH_Final( HASHdigest, &HASHcontext );
1890 keys[nkeys++] = ber_bvdup( &digest );
1893 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1894 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1895 HASH_Init( &HASHcontext );
1896 if( prefix != NULL && prefix->bv_len > 0 ) {
1897 HASH_Update( &HASHcontext,
1898 prefix->bv_val, prefix->bv_len );
1900 HASH_Update( &HASHcontext,
1901 &pre, sizeof( pre ) );
1902 HASH_Update( &HASHcontext,
1903 syntax->ssyn_oid, slen );
1904 HASH_Update( &HASHcontext,
1905 mr->smr_oid, mlen );
1906 HASH_Update( &HASHcontext,
1907 &value->bv_val[value->bv_len-j], j );
1908 HASH_Final( HASHdigest, &HASHcontext );
1910 keys[nkeys++] = ber_bvdup( &digest );
1915 ber_bvfree( value );
1926 return LDAP_SUCCESS;
1929 int caseIgnoreSubstringsFilter(
1934 struct berval *prefix,
1936 struct berval ***keysp )
1938 SubstringsAssertion *sa = assertValue;
1940 ber_len_t nkeys = 0;
1941 size_t slen, mlen, klen;
1942 struct berval **keys;
1943 HASH_CONTEXT HASHcontext;
1944 unsigned char HASHdigest[HASH_BYTES];
1945 struct berval *value;
1946 struct berval digest;
1948 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1949 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1954 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1956 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1957 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1958 /* don't bother accounting for stepping */
1959 nkeys += sa->sa_any[i]->bv_len -
1960 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1965 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1966 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1973 return LDAP_SUCCESS;
1976 digest.bv_val = HASHdigest;
1977 digest.bv_len = sizeof(HASHdigest);
1979 slen = strlen( syntax->ssyn_oid );
1980 mlen = strlen( mr->smr_oid );
1982 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1985 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1986 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1988 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1989 value = ber_bvdup( sa->sa_initial );
1990 ldap_pvt_str2upper( value->bv_val );
1992 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1993 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
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,
2007 value->bv_val, klen );
2008 HASH_Final( HASHdigest, &HASHcontext );
2010 ber_bvfree( value );
2011 keys[nkeys++] = ber_bvdup( &digest );
2014 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2016 pre = SLAP_INDEX_SUBSTR_PREFIX;
2017 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2019 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2020 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2024 value = ber_bvdup( sa->sa_any[i] );
2025 ldap_pvt_str2upper( value->bv_val );
2028 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2029 j += SLAP_INDEX_SUBSTR_STEP )
2031 HASH_Init( &HASHcontext );
2032 if( prefix != NULL && prefix->bv_len > 0 ) {
2033 HASH_Update( &HASHcontext,
2034 prefix->bv_val, prefix->bv_len );
2036 HASH_Update( &HASHcontext,
2037 &pre, sizeof( pre ) );
2038 HASH_Update( &HASHcontext,
2039 syntax->ssyn_oid, slen );
2040 HASH_Update( &HASHcontext,
2041 mr->smr_oid, mlen );
2042 HASH_Update( &HASHcontext,
2043 &value->bv_val[j], klen );
2044 HASH_Final( HASHdigest, &HASHcontext );
2046 keys[nkeys++] = ber_bvdup( &digest );
2049 ber_bvfree( value );
2053 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2054 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2056 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2057 value = ber_bvdup( sa->sa_final );
2058 ldap_pvt_str2upper( value->bv_val );
2060 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2061 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2063 HASH_Init( &HASHcontext );
2064 if( prefix != NULL && prefix->bv_len > 0 ) {
2065 HASH_Update( &HASHcontext,
2066 prefix->bv_val, prefix->bv_len );
2068 HASH_Update( &HASHcontext,
2069 &pre, sizeof( pre ) );
2070 HASH_Update( &HASHcontext,
2071 syntax->ssyn_oid, slen );
2072 HASH_Update( &HASHcontext,
2073 mr->smr_oid, mlen );
2074 HASH_Update( &HASHcontext,
2075 &value->bv_val[value->bv_len-klen], klen );
2076 HASH_Final( HASHdigest, &HASHcontext );
2078 ber_bvfree( value );
2079 keys[nkeys++] = ber_bvdup( &digest );
2090 return LDAP_SUCCESS;
2096 struct berval *val )
2100 if( val->bv_len == 0 ) return 0;
2102 if( OID_LEADCHAR(val->bv_val[0]) ) {
2104 for(i=1; i < val->bv_len; i++) {
2105 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2106 if( dot++ ) return 1;
2107 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2110 return LDAP_INVALID_SYNTAX;
2114 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2116 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2117 for(i=1; i < val->bv_len; i++) {
2118 if( !DESC_CHAR(val->bv_val[i] ) ) {
2119 return LDAP_INVALID_SYNTAX;
2123 return LDAP_SUCCESS;
2126 return LDAP_INVALID_SYNTAX;
2132 struct berval *val )
2136 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2138 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2139 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2140 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2141 return LDAP_INVALID_SYNTAX;
2144 for(i=1; i < val->bv_len; i++) {
2145 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2148 return LDAP_SUCCESS;
2155 struct berval **normalized )
2158 struct berval *newval;
2164 negative = ( *p == '-' );
2165 if( *p == '-' || *p == '+' ) p++;
2167 /* Ignore leading zeros */
2168 while ( *p == '0' ) p++;
2170 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2173 newval->bv_val = ch_strdup("0");
2178 newval->bv_val = ch_malloc( val->bv_len + 1 );
2182 newval->bv_val[newval->bv_len++] = '-';
2185 for( ; *p != '\0'; p++ ) {
2186 newval->bv_val[newval->bv_len++] = *p;
2190 *normalized = newval;
2191 return LDAP_SUCCESS;
2195 printableStringValidate(
2197 struct berval *val )
2201 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2203 for(i=0; i < val->bv_len; i++) {
2204 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2207 return LDAP_SUCCESS;
2213 struct berval *val )
2217 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2219 for(i=0; i < val->bv_len; i++) {
2220 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2223 return LDAP_SUCCESS;
2230 struct berval **normalized )
2232 struct berval *newval;
2235 newval = ch_malloc( sizeof( struct berval ) );
2239 /* Ignore initial whitespace */
2240 while ( ASCII_SPACE( *p ) ) {
2246 return LDAP_INVALID_SYNTAX;
2249 newval->bv_val = ch_strdup( p );
2250 p = q = newval->bv_val;
2253 if ( ASCII_SPACE( *p ) ) {
2256 /* Ignore the extra whitespace */
2257 while ( ASCII_SPACE( *p ) ) {
2265 assert( *newval->bv_val );
2266 assert( newval->bv_val < p );
2269 /* cannot start with a space */
2270 assert( !ASCII_SPACE(*newval->bv_val) );
2273 * If the string ended in space, backup the pointer one
2274 * position. One is enough because the above loop collapsed
2275 * all whitespace to a single space.
2278 if ( ASCII_SPACE( q[-1] ) ) {
2282 /* cannot end with a space */
2283 assert( !ASCII_SPACE( q[-1] ) );
2285 /* null terminate */
2288 newval->bv_len = q - newval->bv_val;
2289 *normalized = newval;
2291 return LDAP_SUCCESS;
2300 struct berval *value,
2301 void *assertedValue )
2303 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2306 match = strncmp( value->bv_val,
2307 ((struct berval *) assertedValue)->bv_val,
2312 return LDAP_SUCCESS;
2316 caseExactIA5SubstringsMatch(
2321 struct berval *value,
2322 void *assertedValue )
2325 SubstringsAssertion *sub = assertedValue;
2326 struct berval left = *value;
2330 /* Add up asserted input length */
2331 if( sub->sa_initial ) {
2332 inlen += sub->sa_initial->bv_len;
2335 for(i=0; sub->sa_any[i] != NULL; i++) {
2336 inlen += sub->sa_any[i]->bv_len;
2339 if( sub->sa_final ) {
2340 inlen += sub->sa_final->bv_len;
2343 if( sub->sa_initial ) {
2344 if( inlen > left.bv_len ) {
2349 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2350 sub->sa_initial->bv_len );
2356 left.bv_val += sub->sa_initial->bv_len;
2357 left.bv_len -= sub->sa_initial->bv_len;
2358 inlen -= sub->sa_initial->bv_len;
2361 if( sub->sa_final ) {
2362 if( inlen > left.bv_len ) {
2367 match = strncmp( sub->sa_final->bv_val,
2368 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2369 sub->sa_final->bv_len );
2375 left.bv_len -= sub->sa_final->bv_len;
2376 inlen -= sub->sa_final->bv_len;
2380 for(i=0; sub->sa_any[i]; i++) {
2385 if( inlen > left.bv_len ) {
2386 /* not enough length */
2391 if( sub->sa_any[i]->bv_len == 0 ) {
2395 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2402 idx = p - left.bv_val;
2403 assert( idx < left.bv_len );
2405 if( idx >= left.bv_len ) {
2406 /* this shouldn't happen */
2413 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2414 /* not enough left */
2419 match = strncmp( left.bv_val,
2420 sub->sa_any[i]->bv_val,
2421 sub->sa_any[i]->bv_len );
2429 left.bv_val += sub->sa_any[i]->bv_len;
2430 left.bv_len -= sub->sa_any[i]->bv_len;
2431 inlen -= sub->sa_any[i]->bv_len;
2437 return LDAP_SUCCESS;
2440 /* Index generation function */
2441 int caseExactIA5Indexer(
2446 struct berval *prefix,
2447 struct berval **values,
2448 struct berval ***keysp )
2452 struct berval **keys;
2453 HASH_CONTEXT HASHcontext;
2454 unsigned char HASHdigest[HASH_BYTES];
2455 struct berval digest;
2456 digest.bv_val = HASHdigest;
2457 digest.bv_len = sizeof(HASHdigest);
2459 /* we should have at least one value at this point */
2460 assert( values != NULL && values[0] != NULL );
2462 for( i=0; values[i] != NULL; i++ ) {
2463 /* just count them */
2466 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2468 slen = strlen( syntax->ssyn_oid );
2469 mlen = strlen( mr->smr_oid );
2471 for( i=0; values[i] != NULL; i++ ) {
2472 struct berval *value = values[i];
2474 HASH_Init( &HASHcontext );
2475 if( prefix != NULL && prefix->bv_len > 0 ) {
2476 HASH_Update( &HASHcontext,
2477 prefix->bv_val, prefix->bv_len );
2479 HASH_Update( &HASHcontext,
2480 syntax->ssyn_oid, slen );
2481 HASH_Update( &HASHcontext,
2482 mr->smr_oid, mlen );
2483 HASH_Update( &HASHcontext,
2484 value->bv_val, value->bv_len );
2485 HASH_Final( HASHdigest, &HASHcontext );
2487 keys[i] = ber_bvdup( &digest );
2492 return LDAP_SUCCESS;
2495 /* Index generation function */
2496 int caseExactIA5Filter(
2501 struct berval *prefix,
2503 struct berval ***keysp )
2506 struct berval **keys;
2507 HASH_CONTEXT HASHcontext;
2508 unsigned char HASHdigest[HASH_BYTES];
2509 struct berval *value;
2510 struct berval digest;
2511 digest.bv_val = HASHdigest;
2512 digest.bv_len = sizeof(HASHdigest);
2514 slen = strlen( syntax->ssyn_oid );
2515 mlen = strlen( mr->smr_oid );
2517 value = (struct berval *) assertValue;
2519 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2521 HASH_Init( &HASHcontext );
2522 if( prefix != NULL && prefix->bv_len > 0 ) {
2523 HASH_Update( &HASHcontext,
2524 prefix->bv_val, prefix->bv_len );
2526 HASH_Update( &HASHcontext,
2527 syntax->ssyn_oid, slen );
2528 HASH_Update( &HASHcontext,
2529 mr->smr_oid, mlen );
2530 HASH_Update( &HASHcontext,
2531 value->bv_val, value->bv_len );
2532 HASH_Final( HASHdigest, &HASHcontext );
2534 keys[0] = ber_bvdup( &digest );
2538 return LDAP_SUCCESS;
2541 /* Substrings Index generation function */
2542 int caseExactIA5SubstringsIndexer(
2547 struct berval *prefix,
2548 struct berval **values,
2549 struct berval ***keysp )
2553 struct berval **keys;
2554 HASH_CONTEXT HASHcontext;
2555 unsigned char HASHdigest[HASH_BYTES];
2556 struct berval digest;
2557 digest.bv_val = HASHdigest;
2558 digest.bv_len = sizeof(HASHdigest);
2560 /* we should have at least one value at this point */
2561 assert( values != NULL && values[0] != NULL );
2564 for( i=0; values[i] != NULL; i++ ) {
2565 /* count number of indices to generate */
2566 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2570 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2571 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2572 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2573 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2575 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2579 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2580 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2581 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2585 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2586 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2587 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2588 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2590 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2596 /* no keys to generate */
2598 return LDAP_SUCCESS;
2601 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2603 slen = strlen( syntax->ssyn_oid );
2604 mlen = strlen( mr->smr_oid );
2607 for( i=0; values[i] != NULL; i++ ) {
2609 struct berval *value;
2612 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2614 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2615 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2617 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2618 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2620 for( j=0; j<max; j++ ) {
2621 HASH_Init( &HASHcontext );
2622 if( prefix != NULL && prefix->bv_len > 0 ) {
2623 HASH_Update( &HASHcontext,
2624 prefix->bv_val, prefix->bv_len );
2627 HASH_Update( &HASHcontext,
2628 &pre, sizeof( pre ) );
2629 HASH_Update( &HASHcontext,
2630 syntax->ssyn_oid, slen );
2631 HASH_Update( &HASHcontext,
2632 mr->smr_oid, mlen );
2633 HASH_Update( &HASHcontext,
2635 SLAP_INDEX_SUBSTR_MAXLEN );
2636 HASH_Final( HASHdigest, &HASHcontext );
2638 keys[nkeys++] = ber_bvdup( &digest );
2642 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2643 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2645 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2648 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2649 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2650 HASH_Init( &HASHcontext );
2651 if( prefix != NULL && prefix->bv_len > 0 ) {
2652 HASH_Update( &HASHcontext,
2653 prefix->bv_val, prefix->bv_len );
2655 HASH_Update( &HASHcontext,
2656 &pre, sizeof( pre ) );
2657 HASH_Update( &HASHcontext,
2658 syntax->ssyn_oid, slen );
2659 HASH_Update( &HASHcontext,
2660 mr->smr_oid, mlen );
2661 HASH_Update( &HASHcontext,
2663 HASH_Final( HASHdigest, &HASHcontext );
2665 keys[nkeys++] = ber_bvdup( &digest );
2668 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2669 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2670 HASH_Init( &HASHcontext );
2671 if( prefix != NULL && prefix->bv_len > 0 ) {
2672 HASH_Update( &HASHcontext,
2673 prefix->bv_val, prefix->bv_len );
2675 HASH_Update( &HASHcontext,
2676 &pre, sizeof( pre ) );
2677 HASH_Update( &HASHcontext,
2678 syntax->ssyn_oid, slen );
2679 HASH_Update( &HASHcontext,
2680 mr->smr_oid, mlen );
2681 HASH_Update( &HASHcontext,
2682 &value->bv_val[value->bv_len-j], j );
2683 HASH_Final( HASHdigest, &HASHcontext );
2685 keys[nkeys++] = ber_bvdup( &digest );
2699 return LDAP_SUCCESS;
2702 int caseExactIA5SubstringsFilter(
2707 struct berval *prefix,
2709 struct berval ***keysp )
2711 SubstringsAssertion *sa = assertValue;
2713 ber_len_t nkeys = 0;
2714 size_t slen, mlen, klen;
2715 struct berval **keys;
2716 HASH_CONTEXT HASHcontext;
2717 unsigned char HASHdigest[HASH_BYTES];
2718 struct berval *value;
2719 struct berval digest;
2721 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2722 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2727 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2729 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2730 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2731 /* don't bother accounting for stepping */
2732 nkeys += sa->sa_any[i]->bv_len -
2733 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2738 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2739 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2746 return LDAP_SUCCESS;
2749 digest.bv_val = HASHdigest;
2750 digest.bv_len = sizeof(HASHdigest);
2752 slen = strlen( syntax->ssyn_oid );
2753 mlen = strlen( mr->smr_oid );
2755 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2758 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2759 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2761 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2762 value = sa->sa_initial;
2764 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2765 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2767 HASH_Init( &HASHcontext );
2768 if( prefix != NULL && prefix->bv_len > 0 ) {
2769 HASH_Update( &HASHcontext,
2770 prefix->bv_val, prefix->bv_len );
2772 HASH_Update( &HASHcontext,
2773 &pre, sizeof( pre ) );
2774 HASH_Update( &HASHcontext,
2775 syntax->ssyn_oid, slen );
2776 HASH_Update( &HASHcontext,
2777 mr->smr_oid, mlen );
2778 HASH_Update( &HASHcontext,
2779 value->bv_val, klen );
2780 HASH_Final( HASHdigest, &HASHcontext );
2782 keys[nkeys++] = ber_bvdup( &digest );
2785 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2787 pre = SLAP_INDEX_SUBSTR_PREFIX;
2788 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2790 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2791 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2795 value = sa->sa_any[i];
2798 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2799 j += SLAP_INDEX_SUBSTR_STEP )
2801 HASH_Init( &HASHcontext );
2802 if( prefix != NULL && prefix->bv_len > 0 ) {
2803 HASH_Update( &HASHcontext,
2804 prefix->bv_val, prefix->bv_len );
2806 HASH_Update( &HASHcontext,
2807 &pre, sizeof( pre ) );
2808 HASH_Update( &HASHcontext,
2809 syntax->ssyn_oid, slen );
2810 HASH_Update( &HASHcontext,
2811 mr->smr_oid, mlen );
2812 HASH_Update( &HASHcontext,
2813 &value->bv_val[j], klen );
2814 HASH_Final( HASHdigest, &HASHcontext );
2816 keys[nkeys++] = ber_bvdup( &digest );
2821 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2822 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2824 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2825 value = sa->sa_final;
2827 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2828 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2830 HASH_Init( &HASHcontext );
2831 if( prefix != NULL && prefix->bv_len > 0 ) {
2832 HASH_Update( &HASHcontext,
2833 prefix->bv_val, prefix->bv_len );
2835 HASH_Update( &HASHcontext,
2836 &pre, sizeof( pre ) );
2837 HASH_Update( &HASHcontext,
2838 syntax->ssyn_oid, slen );
2839 HASH_Update( &HASHcontext,
2840 mr->smr_oid, mlen );
2841 HASH_Update( &HASHcontext,
2842 &value->bv_val[value->bv_len-klen], klen );
2843 HASH_Final( HASHdigest, &HASHcontext );
2845 keys[nkeys++] = ber_bvdup( &digest );
2856 return LDAP_SUCCESS;
2865 struct berval *value,
2866 void *assertedValue )
2868 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2871 match = strncasecmp( value->bv_val,
2872 ((struct berval *) assertedValue)->bv_val,
2877 return LDAP_SUCCESS;
2881 caseIgnoreIA5SubstringsMatch(
2886 struct berval *value,
2887 void *assertedValue )
2890 SubstringsAssertion *sub = assertedValue;
2891 struct berval left = *value;
2895 /* Add up asserted input length */
2896 if( sub->sa_initial ) {
2897 inlen += sub->sa_initial->bv_len;
2900 for(i=0; sub->sa_any[i] != NULL; i++) {
2901 inlen += sub->sa_any[i]->bv_len;
2904 if( sub->sa_final ) {
2905 inlen += sub->sa_final->bv_len;
2908 if( sub->sa_initial ) {
2909 if( inlen > left.bv_len ) {
2914 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2915 sub->sa_initial->bv_len );
2921 left.bv_val += sub->sa_initial->bv_len;
2922 left.bv_len -= sub->sa_initial->bv_len;
2923 inlen -= sub->sa_initial->bv_len;
2926 if( sub->sa_final ) {
2927 if( inlen > left.bv_len ) {
2932 match = strncasecmp( sub->sa_final->bv_val,
2933 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2934 sub->sa_final->bv_len );
2940 left.bv_len -= sub->sa_final->bv_len;
2941 inlen -= sub->sa_final->bv_len;
2945 for(i=0; sub->sa_any[i]; i++) {
2950 if( inlen > left.bv_len ) {
2951 /* not enough length */
2956 if( sub->sa_any[i]->bv_len == 0 ) {
2960 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2967 idx = p - left.bv_val;
2968 assert( idx < left.bv_len );
2970 if( idx >= left.bv_len ) {
2971 /* this shouldn't happen */
2978 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2979 /* not enough left */
2984 match = strncasecmp( left.bv_val,
2985 sub->sa_any[i]->bv_val,
2986 sub->sa_any[i]->bv_len );
2995 left.bv_val += sub->sa_any[i]->bv_len;
2996 left.bv_len -= sub->sa_any[i]->bv_len;
2997 inlen -= sub->sa_any[i]->bv_len;
3003 return LDAP_SUCCESS;
3006 /* Index generation function */
3007 int caseIgnoreIA5Indexer(
3012 struct berval *prefix,
3013 struct berval **values,
3014 struct berval ***keysp )
3018 struct berval **keys;
3019 HASH_CONTEXT HASHcontext;
3020 unsigned char HASHdigest[HASH_BYTES];
3021 struct berval digest;
3022 digest.bv_val = HASHdigest;
3023 digest.bv_len = sizeof(HASHdigest);
3025 /* we should have at least one value at this point */
3026 assert( values != NULL && values[0] != NULL );
3028 for( i=0; values[i] != NULL; i++ ) {
3029 /* just count them */
3032 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3034 slen = strlen( syntax->ssyn_oid );
3035 mlen = strlen( mr->smr_oid );
3037 for( i=0; values[i] != NULL; i++ ) {
3038 struct berval *value = ber_bvdup( values[i] );
3039 ldap_pvt_str2upper( value->bv_val );
3041 HASH_Init( &HASHcontext );
3042 if( prefix != NULL && prefix->bv_len > 0 ) {
3043 HASH_Update( &HASHcontext,
3044 prefix->bv_val, prefix->bv_len );
3046 HASH_Update( &HASHcontext,
3047 syntax->ssyn_oid, slen );
3048 HASH_Update( &HASHcontext,
3049 mr->smr_oid, mlen );
3050 HASH_Update( &HASHcontext,
3051 value->bv_val, value->bv_len );
3052 HASH_Final( HASHdigest, &HASHcontext );
3054 ber_bvfree( value );
3056 keys[i] = ber_bvdup( &digest );
3061 return LDAP_SUCCESS;
3064 /* Index generation function */
3065 int caseIgnoreIA5Filter(
3070 struct berval *prefix,
3072 struct berval ***keysp )
3075 struct berval **keys;
3076 HASH_CONTEXT HASHcontext;
3077 unsigned char HASHdigest[HASH_BYTES];
3078 struct berval *value;
3079 struct berval digest;
3080 digest.bv_val = HASHdigest;
3081 digest.bv_len = sizeof(HASHdigest);
3083 slen = strlen( syntax->ssyn_oid );
3084 mlen = strlen( mr->smr_oid );
3086 value = ber_bvdup( (struct berval *) assertValue );
3087 ldap_pvt_str2upper( value->bv_val );
3089 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3091 HASH_Init( &HASHcontext );
3092 if( prefix != NULL && prefix->bv_len > 0 ) {
3093 HASH_Update( &HASHcontext,
3094 prefix->bv_val, prefix->bv_len );
3096 HASH_Update( &HASHcontext,
3097 syntax->ssyn_oid, slen );
3098 HASH_Update( &HASHcontext,
3099 mr->smr_oid, mlen );
3100 HASH_Update( &HASHcontext,
3101 value->bv_val, value->bv_len );
3102 HASH_Final( HASHdigest, &HASHcontext );
3104 keys[0] = ber_bvdup( &digest );
3107 ber_bvfree( value );
3111 return LDAP_SUCCESS;
3114 /* Substrings Index generation function */
3115 int caseIgnoreIA5SubstringsIndexer(
3120 struct berval *prefix,
3121 struct berval **values,
3122 struct berval ***keysp )
3126 struct berval **keys;
3127 HASH_CONTEXT HASHcontext;
3128 unsigned char HASHdigest[HASH_BYTES];
3129 struct berval digest;
3130 digest.bv_val = HASHdigest;
3131 digest.bv_len = sizeof(HASHdigest);
3133 /* we should have at least one value at this point */
3134 assert( values != NULL && values[0] != NULL );
3137 for( i=0; values[i] != NULL; i++ ) {
3138 /* count number of indices to generate */
3139 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3143 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3144 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3145 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3146 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3148 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3152 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3153 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3154 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3158 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3159 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3160 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3161 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3163 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3169 /* no keys to generate */
3171 return LDAP_SUCCESS;
3174 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3176 slen = strlen( syntax->ssyn_oid );
3177 mlen = strlen( mr->smr_oid );
3180 for( i=0; values[i] != NULL; i++ ) {
3182 struct berval *value;
3184 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3186 value = ber_bvdup( values[i] );
3187 ldap_pvt_str2upper( value->bv_val );
3189 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3190 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3192 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3193 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3195 for( j=0; j<max; j++ ) {
3196 HASH_Init( &HASHcontext );
3197 if( prefix != NULL && prefix->bv_len > 0 ) {
3198 HASH_Update( &HASHcontext,
3199 prefix->bv_val, prefix->bv_len );
3202 HASH_Update( &HASHcontext,
3203 &pre, sizeof( pre ) );
3204 HASH_Update( &HASHcontext,
3205 syntax->ssyn_oid, slen );
3206 HASH_Update( &HASHcontext,
3207 mr->smr_oid, mlen );
3208 HASH_Update( &HASHcontext,
3210 SLAP_INDEX_SUBSTR_MAXLEN );
3211 HASH_Final( HASHdigest, &HASHcontext );
3213 keys[nkeys++] = ber_bvdup( &digest );
3217 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3218 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3220 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3223 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3224 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3225 HASH_Init( &HASHcontext );
3226 if( prefix != NULL && prefix->bv_len > 0 ) {
3227 HASH_Update( &HASHcontext,
3228 prefix->bv_val, prefix->bv_len );
3230 HASH_Update( &HASHcontext,
3231 &pre, sizeof( pre ) );
3232 HASH_Update( &HASHcontext,
3233 syntax->ssyn_oid, slen );
3234 HASH_Update( &HASHcontext,
3235 mr->smr_oid, mlen );
3236 HASH_Update( &HASHcontext,
3238 HASH_Final( HASHdigest, &HASHcontext );
3240 keys[nkeys++] = ber_bvdup( &digest );
3243 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3244 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3245 HASH_Init( &HASHcontext );
3246 if( prefix != NULL && prefix->bv_len > 0 ) {
3247 HASH_Update( &HASHcontext,
3248 prefix->bv_val, prefix->bv_len );
3250 HASH_Update( &HASHcontext,
3251 &pre, sizeof( pre ) );
3252 HASH_Update( &HASHcontext,
3253 syntax->ssyn_oid, slen );
3254 HASH_Update( &HASHcontext,
3255 mr->smr_oid, mlen );
3256 HASH_Update( &HASHcontext,
3257 &value->bv_val[value->bv_len-j], j );
3258 HASH_Final( HASHdigest, &HASHcontext );
3260 keys[nkeys++] = ber_bvdup( &digest );
3265 ber_bvfree( value );
3276 return LDAP_SUCCESS;
3279 int caseIgnoreIA5SubstringsFilter(
3284 struct berval *prefix,
3286 struct berval ***keysp )
3288 SubstringsAssertion *sa = assertValue;
3290 ber_len_t nkeys = 0;
3291 size_t slen, mlen, klen;
3292 struct berval **keys;
3293 HASH_CONTEXT HASHcontext;
3294 unsigned char HASHdigest[HASH_BYTES];
3295 struct berval *value;
3296 struct berval digest;
3298 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3299 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3304 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3306 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3307 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3308 /* don't bother accounting for stepping */
3309 nkeys += sa->sa_any[i]->bv_len -
3310 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3315 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3316 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3323 return LDAP_SUCCESS;
3326 digest.bv_val = HASHdigest;
3327 digest.bv_len = sizeof(HASHdigest);
3329 slen = strlen( syntax->ssyn_oid );
3330 mlen = strlen( mr->smr_oid );
3332 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3335 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3336 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3338 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3339 value = ber_bvdup( sa->sa_initial );
3340 ldap_pvt_str2upper( value->bv_val );
3342 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3343 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
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,
3357 value->bv_val, klen );
3358 HASH_Final( HASHdigest, &HASHcontext );
3360 ber_bvfree( value );
3361 keys[nkeys++] = ber_bvdup( &digest );
3364 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3366 pre = SLAP_INDEX_SUBSTR_PREFIX;
3367 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3369 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3370 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3374 value = ber_bvdup( sa->sa_any[i] );
3375 ldap_pvt_str2upper( value->bv_val );
3378 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3379 j += SLAP_INDEX_SUBSTR_STEP )
3381 HASH_Init( &HASHcontext );
3382 if( prefix != NULL && prefix->bv_len > 0 ) {
3383 HASH_Update( &HASHcontext,
3384 prefix->bv_val, prefix->bv_len );
3386 HASH_Update( &HASHcontext,
3387 &pre, sizeof( pre ) );
3388 HASH_Update( &HASHcontext,
3389 syntax->ssyn_oid, slen );
3390 HASH_Update( &HASHcontext,
3391 mr->smr_oid, mlen );
3392 HASH_Update( &HASHcontext,
3393 &value->bv_val[j], klen );
3394 HASH_Final( HASHdigest, &HASHcontext );
3396 keys[nkeys++] = ber_bvdup( &digest );
3399 ber_bvfree( value );
3403 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3404 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3406 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3407 value = ber_bvdup( sa->sa_final );
3408 ldap_pvt_str2upper( value->bv_val );
3410 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3411 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3413 HASH_Init( &HASHcontext );
3414 if( prefix != NULL && prefix->bv_len > 0 ) {
3415 HASH_Update( &HASHcontext,
3416 prefix->bv_val, prefix->bv_len );
3418 HASH_Update( &HASHcontext,
3419 &pre, sizeof( pre ) );
3420 HASH_Update( &HASHcontext,
3421 syntax->ssyn_oid, slen );
3422 HASH_Update( &HASHcontext,
3423 mr->smr_oid, mlen );
3424 HASH_Update( &HASHcontext,
3425 &value->bv_val[value->bv_len-klen], klen );
3426 HASH_Final( HASHdigest, &HASHcontext );
3428 ber_bvfree( value );
3429 keys[nkeys++] = ber_bvdup( &digest );
3440 return LDAP_SUCCESS;
3444 numericStringNormalize(
3447 struct berval **normalized )
3449 /* similiar to IA5StringNormalize except removes all spaces */
3450 struct berval *newval;
3453 newval = ch_malloc( sizeof( struct berval ) );
3457 /* Ignore initial whitespace */
3458 while ( ASCII_SPACE( *p ) ) {
3464 return LDAP_INVALID_SYNTAX;
3467 newval->bv_val = ch_strdup( p );
3468 p = q = newval->bv_val;
3471 if ( ASCII_SPACE( *p ) ) {
3472 /* Ignore whitespace */
3479 assert( *newval->bv_val );
3480 assert( newval->bv_val < p );
3483 /* cannot start with a space */
3484 assert( !ASCII_SPACE(*newval->bv_val) );
3486 /* cannot end with a space */
3487 assert( !ASCII_SPACE( q[-1] ) );
3489 /* null terminate */
3492 newval->bv_len = q - newval->bv_val;
3493 *normalized = newval;
3495 return LDAP_SUCCESS;
3499 objectIdentifierFirstComponentMatch(
3504 struct berval *value,
3505 void *assertedValue )
3507 int rc = LDAP_SUCCESS;
3509 struct berval *asserted = (struct berval *) assertedValue;
3513 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3514 return LDAP_INVALID_SYNTAX;
3517 /* trim leading white space */
3518 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3522 /* grab next word */
3523 oid.bv_val = &value->bv_val[i];
3524 oid.bv_len = value->bv_len - i;
3525 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3530 /* insert attributeTypes, objectclass check here */
3531 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3532 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3535 char *stored = ch_malloc( oid.bv_len + 1 );
3536 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3537 stored[oid.bv_len] = '\0';
3539 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3540 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3541 MatchingRule *stored_mr = mr_find( stored );
3543 if( asserted_mr == NULL ) {
3544 rc = SLAPD_COMPARE_UNDEFINED;
3546 match = asserted_mr != stored_mr;
3549 } else if ( !strcmp( syntax->ssyn_oid,
3550 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3552 AttributeType *asserted_at = at_find( asserted->bv_val );
3553 AttributeType *stored_at = at_find( stored );
3555 if( asserted_at == NULL ) {
3556 rc = SLAPD_COMPARE_UNDEFINED;
3558 match = asserted_at != stored_at;
3561 } else if ( !strcmp( syntax->ssyn_oid,
3562 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3564 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3565 ObjectClass *stored_oc = oc_find( stored );
3567 if( asserted_oc == NULL ) {
3568 rc = SLAPD_COMPARE_UNDEFINED;
3570 match = asserted_oc != stored_oc;
3577 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3578 "%d\n\t\"%s\"\n\t\"%s\"\n",
3579 match, value->bv_val, asserted->bv_val );
3581 if( rc == LDAP_SUCCESS ) *matchp = match;
3586 check_time_syntax (struct berval *val,
3590 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3591 static int mdays[2][12] = {
3592 /* non-leap years */
3593 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3595 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3598 int part, c, tzoffset, leapyear = 0 ;
3600 if( val->bv_len == 0 ) {
3601 return LDAP_INVALID_SYNTAX;
3604 p = (char *)val->bv_val;
3605 e = p + val->bv_len;
3607 /* Ignore initial whitespace */
3608 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3612 if (e - p < 13 - (2 * start)) {
3613 return LDAP_INVALID_SYNTAX;
3616 for (part = 0; part < 9; part++) {
3620 for (part = start; part < 7; part++) {
3622 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3629 return LDAP_INVALID_SYNTAX;
3631 if (c < 0 || c > 9) {
3632 return LDAP_INVALID_SYNTAX;
3638 return LDAP_INVALID_SYNTAX;
3640 if (c < 0 || c > 9) {
3641 return LDAP_INVALID_SYNTAX;
3646 if (part == 2 || part == 3) {
3649 if (parts[part] < 0) {
3650 return LDAP_INVALID_SYNTAX;
3652 if (parts[part] > ceiling[part]) {
3653 return LDAP_INVALID_SYNTAX;
3657 /* leapyear check for the Gregorian calendar (year>1581) */
3658 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3659 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3664 if (parts[3] > mdays[leapyear][parts[2]]) {
3665 return LDAP_INVALID_SYNTAX;
3670 tzoffset = 0; /* UTC */
3671 } else if (c != '+' && c != '-') {
3672 return LDAP_INVALID_SYNTAX;
3676 } else /* c == '+' */ {
3681 return LDAP_INVALID_SYNTAX;
3684 for (part = 7; part < 9; part++) {
3686 if (c < 0 || c > 9) {
3687 return LDAP_INVALID_SYNTAX;
3692 if (c < 0 || c > 9) {
3693 return LDAP_INVALID_SYNTAX;
3697 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3698 return LDAP_INVALID_SYNTAX;
3703 /* Ignore trailing whitespace */
3704 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3708 return LDAP_INVALID_SYNTAX;
3711 switch ( tzoffset ) {
3712 case -1: /* negativ offset to UTC, ie west of Greenwich */
3713 parts[4] += parts[7];
3714 parts[5] += parts[8];
3715 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3719 c = mdays[leapyear][parts[2]];
3721 if (parts[part] > c) {
3722 parts[part] -= c + 1;
3727 case 1: /* positive offset to UTC, ie east of Greenwich */
3728 parts[4] -= parts[7];
3729 parts[5] -= parts[8];
3730 for (part = 6; --part > 0; ) {
3734 /* first arg to % needs to be non negativ */
3735 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3737 if (parts[part] < 0) {
3738 parts[part] += c + 1;
3743 case 0: /* already UTC */
3747 return LDAP_SUCCESS;
3754 struct berval **normalized )
3759 rc = check_time_syntax(val, 1, parts);
3760 if (rc != LDAP_SUCCESS) {
3765 out = ch_malloc( sizeof(struct berval) );
3767 return LBER_ERROR_MEMORY;
3770 out->bv_val = ch_malloc( 14 );
3771 if ( out->bv_val == NULL ) {
3773 return LBER_ERROR_MEMORY;
3776 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3777 parts[1], parts[2] + 1, parts[3] + 1,
3778 parts[4], parts[5], parts[6] );
3782 return LDAP_SUCCESS;
3792 return check_time_syntax(in, 1, parts);
3796 generalizedTimeValidate(
3802 return check_time_syntax(in, 0, parts);
3806 generalizedTimeNormalize(
3809 struct berval **normalized )
3814 rc = check_time_syntax(val, 0, parts);
3815 if (rc != LDAP_SUCCESS) {
3820 out = ch_malloc( sizeof(struct berval) );
3822 return LBER_ERROR_MEMORY;
3825 out->bv_val = ch_malloc( 16 );
3826 if ( out->bv_val == NULL ) {
3828 return LBER_ERROR_MEMORY;
3831 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3832 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3833 parts[4], parts[5], parts[6] );
3837 return LDAP_SUCCESS;
3841 nisNetgroupTripleValidate(
3843 struct berval *val )
3848 if ( val->bv_len == 0 ) {
3849 return LDAP_INVALID_SYNTAX;
3852 p = (char *)val->bv_val;
3853 e = p + val->bv_len;
3856 /* syntax does not allow leading white space */
3857 /* Ignore initial whitespace */
3858 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3863 if ( *p != '(' /*')'*/ ) {
3864 return LDAP_INVALID_SYNTAX;
3867 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3871 return LDAP_INVALID_SYNTAX;
3874 } else if ( !ATTR_CHAR( *p ) ) {
3875 return LDAP_INVALID_SYNTAX;
3879 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3880 return LDAP_INVALID_SYNTAX;
3886 /* syntax does not allow trailing white space */
3887 /* Ignore trailing whitespace */
3888 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3894 return LDAP_INVALID_SYNTAX;
3897 return LDAP_SUCCESS;
3901 bootParameterValidate(
3903 struct berval *val )
3907 if ( val->bv_len == 0 ) {
3908 return LDAP_INVALID_SYNTAX;
3911 p = (char *)val->bv_val;
3912 e = p + val->bv_len;
3915 for (; ( p < e ) && ( *p != '=' ); p++ ) {
3916 if ( !ATTR_CHAR( *p ) ) {
3917 return LDAP_INVALID_SYNTAX;
3922 return LDAP_INVALID_SYNTAX;
3926 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
3927 if ( !ATTR_CHAR( *p ) ) {
3928 return LDAP_INVALID_SYNTAX;
3933 return LDAP_INVALID_SYNTAX;
3937 for ( p++; p < e; p++ ) {
3938 if ( !ATTR_CHAR( *p ) ) {
3939 return LDAP_INVALID_SYNTAX;
3943 return LDAP_SUCCESS;
3946 struct syntax_defs_rec {
3949 slap_syntax_validate_func *sd_validate;
3950 slap_syntax_transform_func *sd_normalize;
3951 slap_syntax_transform_func *sd_pretty;
3952 #ifdef SLAPD_BINARY_CONVERSION
3953 slap_syntax_transform_func *sd_ber2str;
3954 slap_syntax_transform_func *sd_str2ber;
3958 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
3959 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
3961 struct syntax_defs_rec syntax_defs[] = {
3962 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
3963 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
3964 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
3965 0, NULL, NULL, NULL},
3966 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
3967 0, NULL, NULL, NULL},
3968 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
3969 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3970 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
3971 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3972 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
3973 0, bitStringValidate, NULL, NULL },
3974 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
3975 0, booleanValidate, NULL, NULL},
3976 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
3977 X_BINARY X_NOT_H_R ")",
3978 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3979 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
3980 X_BINARY X_NOT_H_R ")",
3981 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3982 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
3983 X_BINARY X_NOT_H_R ")",
3984 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3985 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
3986 0, NULL, NULL, NULL},
3987 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
3988 0, dnValidate, dnNormalize, dnPretty},
3989 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
3990 0, NULL, NULL, NULL},
3991 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
3992 0, NULL, NULL, NULL},
3993 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
3994 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3995 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
3996 0, NULL, NULL, NULL},
3997 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
3998 0, NULL, NULL, NULL},
3999 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4000 0, NULL, NULL, NULL},
4001 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4002 0, NULL, NULL, NULL},
4003 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4004 0, NULL, NULL, NULL},
4005 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4006 0, IA5StringValidate, faxNumberNormalize, NULL},
4007 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4008 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4009 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4010 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4011 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4012 0, NULL, NULL, NULL},
4013 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4014 0, IA5StringValidate, IA5StringNormalize, NULL},
4015 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4016 0, integerValidate, integerNormalize, integerPretty},
4017 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4018 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4019 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4020 0, NULL, NULL, NULL},
4021 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4022 0, NULL, NULL, NULL},
4023 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4024 0, NULL, NULL, NULL},
4025 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4026 0, NULL, NULL, NULL},
4027 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4028 0, NULL, NULL, NULL},
4029 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4030 0, nameUIDValidate, nameUIDNormalize, NULL},
4031 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4032 0, NULL, NULL, NULL},
4033 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4034 0, IA5StringValidate, numericStringNormalize, NULL},
4035 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4036 0, NULL, NULL, NULL},
4037 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4038 0, oidValidate, NULL, NULL},
4039 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4040 0, NULL, NULL, NULL},
4041 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4042 0, blobValidate, NULL, NULL},
4043 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4044 0, blobValidate, NULL, NULL},
4045 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4046 0, NULL, NULL, NULL},
4047 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4048 0, NULL, NULL, NULL},
4049 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4050 0, printableStringValidate, NULL, NULL},
4051 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4052 X_BINARY X_NOT_H_R ")",
4053 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4054 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4055 0, IA5StringValidate, phoneNumberNormalize, NULL},
4056 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4057 0, NULL, NULL, NULL},
4058 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4059 0, IA5StringValidate, telexNumberNormalize, NULL},
4060 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4061 0, utcTimeValidate, utcTimeNormalize, NULL},
4062 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4063 0, NULL, NULL, NULL},
4064 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4065 0, NULL, NULL, NULL},
4066 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4067 0, NULL, NULL, NULL},
4068 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4069 0, NULL, NULL, NULL},
4070 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4071 0, NULL, NULL, NULL},
4073 /* RFC 2307 NIS Syntaxes */
4074 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4075 0, nisNetgroupTripleValidate, NULL, NULL},
4076 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4077 0, bootParameterValidate, NULL, NULL},
4079 /* OpenLDAP Experimental Syntaxes */
4080 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4081 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4083 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4084 0, NULL, NULL, NULL},
4086 /* OpenLDAP Void Syntax */
4087 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4088 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4089 {NULL, 0, NULL, NULL, NULL}
4092 struct mrule_defs_rec {
4094 slap_mask_t mrd_usage;
4095 slap_mr_convert_func * mrd_convert;
4096 slap_mr_normalize_func * mrd_normalize;
4097 slap_mr_match_func * mrd_match;
4098 slap_mr_indexer_func * mrd_indexer;
4099 slap_mr_filter_func * mrd_filter;
4101 char * mrd_associated;
4105 * Other matching rules in X.520 that we do not use (yet):
4107 * 2.5.13.9 numericStringOrderingMatch
4108 * 2.5.13.15 integerOrderingMatch
4109 * 2.5.13.18 octetStringOrderingMatch
4110 * 2.5.13.19 octetStringSubstringsMatch
4111 * 2.5.13.25 uTCTimeMatch
4112 * 2.5.13.26 uTCTimeOrderingMatch
4113 * 2.5.13.31 directoryStringFirstComponentMatch
4114 * 2.5.13.32 wordMatch
4115 * 2.5.13.33 keywordMatch
4116 * 2.5.13.34 certificateExactMatch
4117 * 2.5.13.35 certificateMatch
4118 * 2.5.13.36 certificatePairExactMatch
4119 * 2.5.13.37 certificatePairMatch
4120 * 2.5.13.38 certificateListExactMatch
4121 * 2.5.13.39 certificateListMatch
4122 * 2.5.13.40 algorithmIdentifierMatch
4123 * 2.5.13.41 storedPrefixMatch
4124 * 2.5.13.42 attributeCertificateMatch
4125 * 2.5.13.43 readerAndKeyIDMatch
4126 * 2.5.13.44 attributeIntegrityMatch
4129 struct mrule_defs_rec mrule_defs[] = {
4131 * EQUALITY matching rules must be listed after associated APPROX
4132 * matching rules. So, we list all APPROX matching rules first.
4134 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4135 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4136 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4138 directoryStringApproxMatch, directoryStringApproxIndexer,
4139 directoryStringApproxFilter,
4142 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4143 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4144 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4146 IA5StringApproxMatch, IA5StringApproxIndexer,
4147 IA5StringApproxFilter,
4151 * Other matching rules
4154 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4155 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4156 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4158 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4161 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4162 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4163 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4165 dnMatch, dnIndexer, dnFilter,
4168 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4169 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4170 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4172 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4173 directoryStringApproxMatchOID },
4175 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4176 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4179 caseIgnoreOrderingMatch, NULL, NULL,
4182 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4183 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4184 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4186 caseIgnoreSubstringsMatch,
4187 caseIgnoreSubstringsIndexer,
4188 caseIgnoreSubstringsFilter,
4191 {"( 2.5.13.5 NAME 'caseExactMatch' "
4192 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4193 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4195 caseExactMatch, caseExactIndexer, caseExactFilter,
4196 directoryStringApproxMatchOID },
4198 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4199 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4202 caseExactOrderingMatch, NULL, NULL,
4205 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4206 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4207 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4209 caseExactSubstringsMatch,
4210 caseExactSubstringsIndexer,
4211 caseExactSubstringsFilter,
4214 {"( 2.5.13.8 NAME 'numericStringMatch' "
4215 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4216 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4219 caseIgnoreIA5Indexer,
4220 caseIgnoreIA5Filter,
4223 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4224 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4225 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4227 caseIgnoreIA5SubstringsMatch,
4228 caseIgnoreIA5SubstringsIndexer,
4229 caseIgnoreIA5SubstringsFilter,
4232 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4233 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4234 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4236 caseIgnoreListMatch, NULL, NULL,
4239 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4240 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4241 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4243 caseIgnoreListSubstringsMatch, NULL, NULL,
4246 {"( 2.5.13.13 NAME 'booleanMatch' "
4247 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4248 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4250 booleanMatch, NULL, NULL,
4253 {"( 2.5.13.14 NAME 'integerMatch' "
4254 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4255 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4257 integerMatch, integerIndexer, integerFilter,
4260 {"( 2.5.13.16 NAME 'bitStringMatch' "
4261 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4262 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4264 bitStringMatch, NULL, NULL,
4267 {"( 2.5.13.17 NAME 'octetStringMatch' "
4268 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4269 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4271 octetStringMatch, octetStringIndexer, octetStringFilter,
4274 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4275 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4276 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4278 telephoneNumberMatch, NULL, NULL,
4281 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4282 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4283 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4285 telephoneNumberSubstringsMatch, NULL, NULL,
4288 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4289 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4290 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4292 presentationAddressMatch, NULL, NULL,
4295 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4296 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4297 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4299 uniqueMemberMatch, NULL, NULL,
4302 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4303 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4304 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4306 protocolInformationMatch, NULL, NULL,
4309 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4310 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4311 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4313 generalizedTimeMatch, NULL, NULL,
4316 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4317 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4320 generalizedTimeOrderingMatch, NULL, NULL,
4323 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4324 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4325 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4327 integerFirstComponentMatch, NULL, NULL,
4330 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4331 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4332 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4334 objectIdentifierFirstComponentMatch, NULL, NULL,
4337 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4338 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4339 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4341 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4342 IA5StringApproxMatchOID },
4344 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4345 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4346 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4348 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4349 IA5StringApproxMatchOID },
4351 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4352 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4355 caseIgnoreIA5SubstringsMatch,
4356 caseIgnoreIA5SubstringsIndexer,
4357 caseIgnoreIA5SubstringsFilter,
4360 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4361 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4364 caseExactIA5SubstringsMatch,
4365 caseExactIA5SubstringsIndexer,
4366 caseExactIA5SubstringsFilter,
4369 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4370 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4373 authPasswordMatch, NULL, NULL,
4376 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4377 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4380 OpenLDAPaciMatch, NULL, NULL,
4383 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4392 /* we should only be called once (from main) */
4393 assert( schema_init_done == 0 );
4395 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4396 res = register_syntax( syntax_defs[i].sd_desc,
4397 syntax_defs[i].sd_flags,
4398 syntax_defs[i].sd_validate,
4399 syntax_defs[i].sd_normalize,
4400 syntax_defs[i].sd_pretty
4401 #ifdef SLAPD_BINARY_CONVERSION
4403 syntax_defs[i].sd_ber2str,
4404 syntax_defs[i].sd_str2ber
4409 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4410 syntax_defs[i].sd_desc );
4415 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4416 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4418 "schema_init: Ingoring unusable matching rule %s\n",
4419 mrule_defs[i].mrd_desc );
4423 res = register_matching_rule(
4424 mrule_defs[i].mrd_desc,
4425 mrule_defs[i].mrd_usage,
4426 mrule_defs[i].mrd_convert,
4427 mrule_defs[i].mrd_normalize,
4428 mrule_defs[i].mrd_match,
4429 mrule_defs[i].mrd_indexer,
4430 mrule_defs[i].mrd_filter,
4431 mrule_defs[i].mrd_associated );
4435 "schema_init: Error registering matching rule %s\n",
4436 mrule_defs[i].mrd_desc );
4440 schema_init_done = 1;
4441 return LDAP_SUCCESS;