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 ) {
545 /* case insensitive UTF8 strncmp with offset for second string */
548 struct berval *right,
556 ldap_unicode_t ru, lu;
557 ldap_unicode_t ruu, luu;
559 rslen = len < right->bv_len ? len : right->bv_len;
560 lslen = len + offset < left->bv_len ? len : left->bv_len;
562 for( r = 0, l = offset;
563 r < rslen && l < lslen;
567 * XXYYZ: we convert to ucs4 even though -llunicode
568 * expects ucs2 in an unsigned long
570 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
571 if( ru == LDAP_UCS4_INVALID ) {
575 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
576 if( lu == LDAP_UCS4_INVALID ) {
580 ruu = uctoupper( ru );
581 luu = uctoupper( lu );
585 } else if( luu > ruu ) {
589 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
590 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
606 static char *UTF8casechr( const char *str, const char *c )
608 char *p, *lower, *upper;
609 ldap_ucs4_t tch, ch = ldap_utf8_to_ucs4(c);
611 tch = uctolower ( ch );
612 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
613 if( ldap_utf8_to_ucs4( p ) == tch ) {
617 lower = *p != '\0' ? p : NULL;
619 tch = uctoupper ( ch );
620 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
621 if( ldap_utf8_to_ucs4( p ) == tch ) {
625 upper = *p != '\0' ? p : NULL;
627 if( lower && upper ) {
628 return lower < upper ? lower : upper;
629 } else if ( lower ) {
644 unsigned char *u = in->bv_val;
646 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
648 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
649 /* get the length indicated by the first byte */
650 len = LDAP_UTF8_CHARLEN( u );
652 /* should not be zero */
653 if( len == 0 ) return LDAP_INVALID_SYNTAX;
655 /* make sure len corresponds with the offset
656 to the next character */
657 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
660 if( count != 0 ) return LDAP_INVALID_SYNTAX;
669 struct berval **normalized )
671 struct berval *newval;
674 newval = ch_malloc( sizeof( struct berval ) );
678 /* Ignore initial whitespace */
679 while ( ldap_utf8_isspace( p ) ) {
685 return LDAP_INVALID_SYNTAX;
688 newval->bv_val = ch_strdup( p );
689 p = q = newval->bv_val;
695 if ( ldap_utf8_isspace( p ) ) {
696 len = LDAP_UTF8_COPY(q,p);
701 /* Ignore the extra whitespace */
702 while ( ldap_utf8_isspace( p ) ) {
706 len = LDAP_UTF8_COPY(q,p);
713 assert( *newval->bv_val );
714 assert( newval->bv_val < p );
717 /* cannot start with a space */
718 assert( !ldap_utf8_isspace(newval->bv_val) );
721 * If the string ended in space, backup the pointer one
722 * position. One is enough because the above loop collapsed
723 * all whitespace to a single space.
730 /* cannot end with a space */
731 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
736 newval->bv_len = q - newval->bv_val;
737 *normalized = newval;
742 #if defined(SLAPD_APPROX_MULTISTRING)
744 #if defined(SLAPD_APPROX_INITIALS)
745 #define SLAPD_APPROX_DELIMITER "._ "
746 #define SLAPD_APPROX_WORDLEN 2
748 #define SLAPD_APPROX_DELIMITER " "
749 #define SLAPD_APPROX_WORDLEN 1
758 struct berval *value,
759 void *assertedValue )
761 char *val, *assertv, **values, **words, *c;
762 int i, count, len, nextchunk=0, nextavail=0;
765 /* Isolate how many words there are */
766 val = ch_strdup( value->bv_val );
767 for( c=val,count=1; *c; c++ ) {
768 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
769 if ( c == NULL ) break;
774 /* Get a phonetic copy of each word */
775 words = (char **)ch_malloc( count * sizeof(char *) );
776 values = (char **)ch_malloc( count * sizeof(char *) );
777 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
779 values[i] = phonetic(c);
783 /* Work through the asserted value's words, to see if at least some
784 of the words are there, in the same order. */
785 assertv = ch_strdup( ((struct berval *)assertedValue)->bv_val );
787 while ( nextchunk < ((struct berval *)assertedValue)->bv_len ) {
788 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
789 #if defined(SLAPD_APPROX_INITIALS)
791 /* Single letter words need to at least match one word's initial */
792 for( i=nextavail; i<count; i++ )
793 if( !strncasecmp( assertv+nextchunk, words[i], 1 ))
800 /* Isolate the next word in the asserted value and phonetic it */
801 assertv[nextchunk+len] = '\0';
802 val = phonetic( assertv + nextchunk );
804 /* See if this phonetic chunk is in the remaining words of *value */
805 for( i=nextavail; i<count; i++ ){
806 if( !strcmp( val, values[i] ) ){
813 /* This chunk in the asserted value was NOT within the *value. */
819 /* Go on to the next word in the asserted value */
823 /* If some of the words were seen, call it a match */
824 if( nextavail > 0 ) {
833 for( i=0; i<count; i++ ) {
834 ch_free( values[i] );
850 struct berval *prefix,
851 struct berval **values,
852 struct berval ***keysp )
855 int i,j, len, wordcount, keycount=0;
856 struct berval **newkeys, **keys=NULL;
859 for( j=0; values[j] != NULL; j++ ) {
861 /* Isolate how many words there are. There will be a key for each */
862 val = ch_strdup( values[j]->bv_val );
863 for( wordcount=0,c=val; *c; c++) {
864 len = strcspn(c, SLAPD_APPROX_DELIMITER);
865 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
867 if (*c == '\0') break;
871 /* Allocate/increase storage to account for new keys */
872 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
873 * sizeof(struct berval *) );
874 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
875 if( keys ) ch_free( keys );
878 /* Get a phonetic copy of each word */
879 for( c=val,i=0; i<wordcount; c+=len+1 ) {
881 if( len < SLAPD_APPROX_WORDLEN ) continue;
882 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
883 keys[keycount]->bv_val = phonetic( c );
884 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
891 keys[keycount] = NULL;
904 struct berval *prefix,
906 struct berval ***keysp )
910 struct berval **keys;
913 /* Isolate how many words there are. There will be a key for each */
914 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
915 for( count=0,c=val; *c; c++) {
916 len = strcspn(c, SLAPD_APPROX_DELIMITER);
917 if( len >= SLAPD_APPROX_WORDLEN ) count++;
919 if (*c == '\0') break;
923 /* Allocate storage for new keys */
924 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
926 /* Get a phonetic copy of each word */
927 for( c=val,i=0; i<count; c+=len+1 ) {
929 if( len < SLAPD_APPROX_WORDLEN ) continue;
930 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
931 keys[i]->bv_val = phonetic( c );
932 keys[i]->bv_len = strlen( keys[i]->bv_val );
946 /* No other form of Approximate Matching is defined */
954 struct berval *value,
955 void *assertedValue )
957 char *vapprox, *avapprox;
959 vapprox = phonetic( value->bv_val );
960 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
962 *matchp = strcmp( vapprox, avapprox );
976 struct berval *prefix,
977 struct berval **values,
978 struct berval ***keysp )
981 struct berval **keys;
984 for( i=0; values[i] != NULL; i++ ) {
985 /* just count them */
989 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
991 /* Copy each value and run it through phonetic() */
992 for( i=0; values[i] != NULL; i++ ) {
993 keys[i] = ch_malloc( sizeof( struct berval * ) );
994 keys[i]->bv_val = phonetic( values[i]->bv_val );
995 keys[i]->bv_len = strlen( keys[i]->bv_val );
1000 return LDAP_SUCCESS;
1010 struct berval *prefix,
1012 struct berval ***keysp )
1014 struct berval **keys;
1017 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1019 /* Copy the value and run it through phonetic() */
1020 keys[0] = ch_malloc( sizeof( struct berval * ) );
1021 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
1022 keys[0]->bv_len = strlen( keys[0]->bv_val );
1026 return LDAP_SUCCESS;
1037 struct berval *value,
1038 void *assertedValue )
1040 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1043 match = strncmp( value->bv_val,
1044 ((struct berval *) assertedValue)->bv_val,
1049 return LDAP_SUCCESS;
1053 caseExactSubstringsMatch(
1058 struct berval *value,
1059 void *assertedValue )
1062 SubstringsAssertion *sub = assertedValue;
1063 struct berval left = *value;
1067 /* Add up asserted input length */
1068 if( sub->sa_initial ) {
1069 inlen += sub->sa_initial->bv_len;
1072 for(i=0; sub->sa_any[i] != NULL; i++) {
1073 inlen += sub->sa_any[i]->bv_len;
1076 if( sub->sa_final ) {
1077 inlen += sub->sa_final->bv_len;
1080 if( sub->sa_initial ) {
1081 if( inlen > left.bv_len ) {
1086 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1087 sub->sa_initial->bv_len );
1093 left.bv_val += sub->sa_initial->bv_len;
1094 left.bv_len -= sub->sa_initial->bv_len;
1095 inlen -= sub->sa_initial->bv_len;
1098 if( sub->sa_final ) {
1099 if( inlen > left.bv_len ) {
1104 match = strncmp( sub->sa_final->bv_val,
1105 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1106 sub->sa_final->bv_len );
1112 left.bv_len -= sub->sa_final->bv_len;
1113 inlen -= sub->sa_final->bv_len;
1117 for(i=0; sub->sa_any[i]; i++) {
1122 if( inlen > left.bv_len ) {
1123 /* not enough length */
1128 if( sub->sa_any[i]->bv_len == 0 ) {
1132 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1139 idx = p - left.bv_val;
1140 assert( idx < left.bv_len );
1142 if( idx >= left.bv_len ) {
1143 /* this shouldn't happen */
1150 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1151 /* not enough left */
1156 match = strncmp( left.bv_val,
1157 sub->sa_any[i]->bv_val,
1158 sub->sa_any[i]->bv_len );
1166 left.bv_val += sub->sa_any[i]->bv_len;
1167 left.bv_len -= sub->sa_any[i]->bv_len;
1168 inlen -= sub->sa_any[i]->bv_len;
1174 return LDAP_SUCCESS;
1177 /* Index generation function */
1178 int caseExactIndexer(
1183 struct berval *prefix,
1184 struct berval **values,
1185 struct berval ***keysp )
1189 struct berval **keys;
1190 HASH_CONTEXT HASHcontext;
1191 unsigned char HASHdigest[HASH_BYTES];
1192 struct berval digest;
1193 digest.bv_val = HASHdigest;
1194 digest.bv_len = sizeof(HASHdigest);
1196 /* we should have at least one value at this point */
1197 assert( values != NULL && values[0] != NULL );
1199 for( i=0; values[i] != NULL; i++ ) {
1200 /* just count them */
1203 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1205 slen = strlen( syntax->ssyn_oid );
1206 mlen = strlen( mr->smr_oid );
1208 for( i=0; values[i] != NULL; i++ ) {
1209 struct berval *value = values[i];
1211 HASH_Init( &HASHcontext );
1212 if( prefix != NULL && prefix->bv_len > 0 ) {
1213 HASH_Update( &HASHcontext,
1214 prefix->bv_val, prefix->bv_len );
1216 HASH_Update( &HASHcontext,
1217 syntax->ssyn_oid, slen );
1218 HASH_Update( &HASHcontext,
1219 mr->smr_oid, mlen );
1220 HASH_Update( &HASHcontext,
1221 value->bv_val, value->bv_len );
1222 HASH_Final( HASHdigest, &HASHcontext );
1224 keys[i] = ber_bvdup( &digest );
1229 return LDAP_SUCCESS;
1232 /* Index generation function */
1233 int caseExactFilter(
1238 struct berval *prefix,
1240 struct berval ***keysp )
1243 struct berval **keys;
1244 HASH_CONTEXT HASHcontext;
1245 unsigned char HASHdigest[HASH_BYTES];
1246 struct berval *value;
1247 struct berval digest;
1248 digest.bv_val = HASHdigest;
1249 digest.bv_len = sizeof(HASHdigest);
1251 slen = strlen( syntax->ssyn_oid );
1252 mlen = strlen( mr->smr_oid );
1254 value = (struct berval *) assertValue;
1256 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1258 HASH_Init( &HASHcontext );
1259 if( prefix != NULL && prefix->bv_len > 0 ) {
1260 HASH_Update( &HASHcontext,
1261 prefix->bv_val, prefix->bv_len );
1263 HASH_Update( &HASHcontext,
1264 syntax->ssyn_oid, slen );
1265 HASH_Update( &HASHcontext,
1266 mr->smr_oid, mlen );
1267 HASH_Update( &HASHcontext,
1268 value->bv_val, value->bv_len );
1269 HASH_Final( HASHdigest, &HASHcontext );
1271 keys[0] = ber_bvdup( &digest );
1275 return LDAP_SUCCESS;
1278 /* Substrings Index generation function */
1279 int caseExactSubstringsIndexer(
1284 struct berval *prefix,
1285 struct berval **values,
1286 struct berval ***keysp )
1290 struct berval **keys;
1291 HASH_CONTEXT HASHcontext;
1292 unsigned char HASHdigest[HASH_BYTES];
1293 struct berval digest;
1294 digest.bv_val = HASHdigest;
1295 digest.bv_len = sizeof(HASHdigest);
1297 /* we should have at least one value at this point */
1298 assert( values != NULL && values[0] != NULL );
1301 for( i=0; values[i] != NULL; i++ ) {
1302 /* count number of indices to generate */
1303 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1307 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1308 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1309 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1310 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1312 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1316 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1317 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1318 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1322 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1323 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1324 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1325 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1327 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1333 /* no keys to generate */
1335 return LDAP_SUCCESS;
1338 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1340 slen = strlen( syntax->ssyn_oid );
1341 mlen = strlen( mr->smr_oid );
1344 for( i=0; values[i] != NULL; i++ ) {
1346 struct berval *value;
1349 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1351 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1352 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1354 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1355 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1357 for( j=0; j<max; j++ ) {
1358 HASH_Init( &HASHcontext );
1359 if( prefix != NULL && prefix->bv_len > 0 ) {
1360 HASH_Update( &HASHcontext,
1361 prefix->bv_val, prefix->bv_len );
1364 HASH_Update( &HASHcontext,
1365 &pre, sizeof( pre ) );
1366 HASH_Update( &HASHcontext,
1367 syntax->ssyn_oid, slen );
1368 HASH_Update( &HASHcontext,
1369 mr->smr_oid, mlen );
1370 HASH_Update( &HASHcontext,
1372 SLAP_INDEX_SUBSTR_MAXLEN );
1373 HASH_Final( HASHdigest, &HASHcontext );
1375 keys[nkeys++] = ber_bvdup( &digest );
1379 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1380 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1382 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1385 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1386 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1387 HASH_Init( &HASHcontext );
1388 if( prefix != NULL && prefix->bv_len > 0 ) {
1389 HASH_Update( &HASHcontext,
1390 prefix->bv_val, prefix->bv_len );
1392 HASH_Update( &HASHcontext,
1393 &pre, sizeof( pre ) );
1394 HASH_Update( &HASHcontext,
1395 syntax->ssyn_oid, slen );
1396 HASH_Update( &HASHcontext,
1397 mr->smr_oid, mlen );
1398 HASH_Update( &HASHcontext,
1400 HASH_Final( HASHdigest, &HASHcontext );
1402 keys[nkeys++] = ber_bvdup( &digest );
1405 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1406 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1407 HASH_Init( &HASHcontext );
1408 if( prefix != NULL && prefix->bv_len > 0 ) {
1409 HASH_Update( &HASHcontext,
1410 prefix->bv_val, prefix->bv_len );
1412 HASH_Update( &HASHcontext,
1413 &pre, sizeof( pre ) );
1414 HASH_Update( &HASHcontext,
1415 syntax->ssyn_oid, slen );
1416 HASH_Update( &HASHcontext,
1417 mr->smr_oid, mlen );
1418 HASH_Update( &HASHcontext,
1419 &value->bv_val[value->bv_len-j], j );
1420 HASH_Final( HASHdigest, &HASHcontext );
1422 keys[nkeys++] = ber_bvdup( &digest );
1436 return LDAP_SUCCESS;
1439 int caseExactSubstringsFilter(
1444 struct berval *prefix,
1446 struct berval ***keysp )
1448 SubstringsAssertion *sa = assertValue;
1450 ber_len_t nkeys = 0;
1451 size_t slen, mlen, klen;
1452 struct berval **keys;
1453 HASH_CONTEXT HASHcontext;
1454 unsigned char HASHdigest[HASH_BYTES];
1455 struct berval *value;
1456 struct berval digest;
1458 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1459 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1464 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1466 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1467 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1468 /* don't bother accounting for stepping */
1469 nkeys += sa->sa_any[i]->bv_len -
1470 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1475 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1476 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1483 return LDAP_SUCCESS;
1486 digest.bv_val = HASHdigest;
1487 digest.bv_len = sizeof(HASHdigest);
1489 slen = strlen( syntax->ssyn_oid );
1490 mlen = strlen( mr->smr_oid );
1492 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1495 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1496 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1498 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1499 value = sa->sa_initial;
1501 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1502 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1504 HASH_Init( &HASHcontext );
1505 if( prefix != NULL && prefix->bv_len > 0 ) {
1506 HASH_Update( &HASHcontext,
1507 prefix->bv_val, prefix->bv_len );
1509 HASH_Update( &HASHcontext,
1510 &pre, sizeof( pre ) );
1511 HASH_Update( &HASHcontext,
1512 syntax->ssyn_oid, slen );
1513 HASH_Update( &HASHcontext,
1514 mr->smr_oid, mlen );
1515 HASH_Update( &HASHcontext,
1516 value->bv_val, klen );
1517 HASH_Final( HASHdigest, &HASHcontext );
1519 keys[nkeys++] = ber_bvdup( &digest );
1522 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1524 pre = SLAP_INDEX_SUBSTR_PREFIX;
1525 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1527 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1528 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1532 value = sa->sa_any[i];
1535 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1536 j += SLAP_INDEX_SUBSTR_STEP )
1538 HASH_Init( &HASHcontext );
1539 if( prefix != NULL && prefix->bv_len > 0 ) {
1540 HASH_Update( &HASHcontext,
1541 prefix->bv_val, prefix->bv_len );
1543 HASH_Update( &HASHcontext,
1544 &pre, sizeof( pre ) );
1545 HASH_Update( &HASHcontext,
1546 syntax->ssyn_oid, slen );
1547 HASH_Update( &HASHcontext,
1548 mr->smr_oid, mlen );
1549 HASH_Update( &HASHcontext,
1550 &value->bv_val[j], klen );
1551 HASH_Final( HASHdigest, &HASHcontext );
1553 keys[nkeys++] = ber_bvdup( &digest );
1558 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1559 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1561 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1562 value = sa->sa_final;
1564 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1565 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1567 HASH_Init( &HASHcontext );
1568 if( prefix != NULL && prefix->bv_len > 0 ) {
1569 HASH_Update( &HASHcontext,
1570 prefix->bv_val, prefix->bv_len );
1572 HASH_Update( &HASHcontext,
1573 &pre, sizeof( pre ) );
1574 HASH_Update( &HASHcontext,
1575 syntax->ssyn_oid, slen );
1576 HASH_Update( &HASHcontext,
1577 mr->smr_oid, mlen );
1578 HASH_Update( &HASHcontext,
1579 &value->bv_val[value->bv_len-klen], klen );
1580 HASH_Final( HASHdigest, &HASHcontext );
1582 keys[nkeys++] = ber_bvdup( &digest );
1593 return LDAP_SUCCESS;
1602 struct berval *value,
1603 void *assertedValue )
1606 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1608 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1611 match = strncasecmp( value->bv_val,
1612 ((struct berval *) assertedValue)->bv_val,
1618 return LDAP_SUCCESS;
1622 caseIgnoreSubstringsMatch(
1627 struct berval *value,
1628 void *assertedValue )
1631 SubstringsAssertion *sub = assertedValue;
1632 struct berval left = *value;
1636 /* Add up asserted input length */
1637 if( sub->sa_initial ) {
1638 inlen += sub->sa_initial->bv_len;
1641 for(i=0; sub->sa_any[i] != NULL; i++) {
1642 inlen += sub->sa_any[i]->bv_len;
1645 if( sub->sa_final ) {
1646 inlen += sub->sa_final->bv_len;
1649 if( sub->sa_initial ) {
1650 if( inlen > left.bv_len ) {
1656 match = UTF8oncasecmp( sub->sa_initial, &left,
1657 sub->sa_initial->bv_len, 0 );
1659 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1660 sub->sa_initial->bv_len );
1667 left.bv_val += sub->sa_initial->bv_len;
1668 left.bv_len -= sub->sa_initial->bv_len;
1669 inlen -= sub->sa_initial->bv_len;
1672 if( sub->sa_final ) {
1673 if( inlen > left.bv_len ) {
1679 match = UTF8oncasecmp( sub->sa_final, &left,
1680 sub->sa_final->bv_len,
1681 left.bv_len - sub->sa_final->bv_len );
1683 match = strncasecmp( sub->sa_final->bv_val,
1684 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1685 sub->sa_final->bv_len );
1692 left.bv_len -= sub->sa_final->bv_len;
1693 inlen -= sub->sa_final->bv_len;
1697 for(i=0; sub->sa_any[i]; i++) {
1702 if( inlen > left.bv_len ) {
1703 /* not enough length */
1708 if( sub->sa_any[i]->bv_len == 0 ) {
1713 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1715 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1723 idx = p - left.bv_val;
1724 assert( idx < left.bv_len );
1726 if( idx >= left.bv_len ) {
1727 /* this shouldn't happen */
1734 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1735 /* not enough left */
1741 match = UTF8oncasecmp( &left, sub->sa_any[i],
1742 sub->sa_any[i]->bv_len, 0 );
1745 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1751 match = strncasecmp( left.bv_val,
1752 sub->sa_any[i]->bv_val,
1753 sub->sa_any[i]->bv_len );
1763 left.bv_val += sub->sa_any[i]->bv_len;
1764 left.bv_len -= sub->sa_any[i]->bv_len;
1765 inlen -= sub->sa_any[i]->bv_len;
1771 return LDAP_SUCCESS;
1774 /* Index generation function */
1775 int caseIgnoreIndexer(
1780 struct berval *prefix,
1781 struct berval **values,
1782 struct berval ***keysp )
1786 struct berval **keys;
1787 HASH_CONTEXT HASHcontext;
1788 unsigned char HASHdigest[HASH_BYTES];
1789 struct berval digest;
1790 digest.bv_val = HASHdigest;
1791 digest.bv_len = sizeof(HASHdigest);
1793 /* we should have at least one value at this point */
1794 assert( values != NULL && values[0] != NULL );
1796 for( i=0; values[i] != NULL; i++ ) {
1797 /* just count them */
1800 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1802 slen = strlen( syntax->ssyn_oid );
1803 mlen = strlen( mr->smr_oid );
1805 for( i=0; values[i] != NULL; i++ ) {
1806 struct berval *value = ber_bvdup( values[i] );
1807 ldap_pvt_str2upper( value->bv_val );
1809 HASH_Init( &HASHcontext );
1810 if( prefix != NULL && prefix->bv_len > 0 ) {
1811 HASH_Update( &HASHcontext,
1812 prefix->bv_val, prefix->bv_len );
1814 HASH_Update( &HASHcontext,
1815 syntax->ssyn_oid, slen );
1816 HASH_Update( &HASHcontext,
1817 mr->smr_oid, mlen );
1818 HASH_Update( &HASHcontext,
1819 value->bv_val, value->bv_len );
1820 HASH_Final( HASHdigest, &HASHcontext );
1822 ber_bvfree( value );
1824 keys[i] = ber_bvdup( &digest );
1829 return LDAP_SUCCESS;
1832 /* Index generation function */
1833 int caseIgnoreFilter(
1838 struct berval *prefix,
1840 struct berval ***keysp )
1843 struct berval **keys;
1844 HASH_CONTEXT HASHcontext;
1845 unsigned char HASHdigest[HASH_BYTES];
1846 struct berval *value;
1847 struct berval digest;
1848 digest.bv_val = HASHdigest;
1849 digest.bv_len = sizeof(HASHdigest);
1851 slen = strlen( syntax->ssyn_oid );
1852 mlen = strlen( mr->smr_oid );
1854 value = ber_bvdup( (struct berval *) assertValue );
1855 ldap_pvt_str2upper( value->bv_val );
1857 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1859 HASH_Init( &HASHcontext );
1860 if( prefix != NULL && prefix->bv_len > 0 ) {
1861 HASH_Update( &HASHcontext,
1862 prefix->bv_val, prefix->bv_len );
1864 HASH_Update( &HASHcontext,
1865 syntax->ssyn_oid, slen );
1866 HASH_Update( &HASHcontext,
1867 mr->smr_oid, mlen );
1868 HASH_Update( &HASHcontext,
1869 value->bv_val, value->bv_len );
1870 HASH_Final( HASHdigest, &HASHcontext );
1872 keys[0] = ber_bvdup( &digest );
1875 ber_bvfree( value );
1879 return LDAP_SUCCESS;
1882 /* Substrings Index generation function */
1883 int caseIgnoreSubstringsIndexer(
1888 struct berval *prefix,
1889 struct berval **values,
1890 struct berval ***keysp )
1894 struct berval **keys;
1895 HASH_CONTEXT HASHcontext;
1896 unsigned char HASHdigest[HASH_BYTES];
1897 struct berval digest;
1898 digest.bv_val = HASHdigest;
1899 digest.bv_len = sizeof(HASHdigest);
1901 /* we should have at least one value at this point */
1902 assert( values != NULL && values[0] != NULL );
1905 for( i=0; values[i] != NULL; i++ ) {
1906 /* count number of indices to generate */
1907 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1911 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1912 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1913 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1914 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1916 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1920 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1921 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1922 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1926 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1927 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1928 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1929 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1931 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1937 /* no keys to generate */
1939 return LDAP_SUCCESS;
1942 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1944 slen = strlen( syntax->ssyn_oid );
1945 mlen = strlen( mr->smr_oid );
1948 for( i=0; values[i] != NULL; i++ ) {
1950 struct berval *value;
1952 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1954 value = ber_bvdup( values[i] );
1955 ldap_pvt_str2upper( value->bv_val );
1957 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1958 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1960 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1961 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1963 for( j=0; j<max; j++ ) {
1964 HASH_Init( &HASHcontext );
1965 if( prefix != NULL && prefix->bv_len > 0 ) {
1966 HASH_Update( &HASHcontext,
1967 prefix->bv_val, prefix->bv_len );
1970 HASH_Update( &HASHcontext,
1971 &pre, sizeof( pre ) );
1972 HASH_Update( &HASHcontext,
1973 syntax->ssyn_oid, slen );
1974 HASH_Update( &HASHcontext,
1975 mr->smr_oid, mlen );
1976 HASH_Update( &HASHcontext,
1978 SLAP_INDEX_SUBSTR_MAXLEN );
1979 HASH_Final( HASHdigest, &HASHcontext );
1981 keys[nkeys++] = ber_bvdup( &digest );
1985 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1986 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1988 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1991 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1992 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1993 HASH_Init( &HASHcontext );
1994 if( prefix != NULL && prefix->bv_len > 0 ) {
1995 HASH_Update( &HASHcontext,
1996 prefix->bv_val, prefix->bv_len );
1998 HASH_Update( &HASHcontext,
1999 &pre, sizeof( pre ) );
2000 HASH_Update( &HASHcontext,
2001 syntax->ssyn_oid, slen );
2002 HASH_Update( &HASHcontext,
2003 mr->smr_oid, mlen );
2004 HASH_Update( &HASHcontext,
2006 HASH_Final( HASHdigest, &HASHcontext );
2008 keys[nkeys++] = ber_bvdup( &digest );
2011 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2012 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2013 HASH_Init( &HASHcontext );
2014 if( prefix != NULL && prefix->bv_len > 0 ) {
2015 HASH_Update( &HASHcontext,
2016 prefix->bv_val, prefix->bv_len );
2018 HASH_Update( &HASHcontext,
2019 &pre, sizeof( pre ) );
2020 HASH_Update( &HASHcontext,
2021 syntax->ssyn_oid, slen );
2022 HASH_Update( &HASHcontext,
2023 mr->smr_oid, mlen );
2024 HASH_Update( &HASHcontext,
2025 &value->bv_val[value->bv_len-j], j );
2026 HASH_Final( HASHdigest, &HASHcontext );
2028 keys[nkeys++] = ber_bvdup( &digest );
2033 ber_bvfree( value );
2044 return LDAP_SUCCESS;
2047 int caseIgnoreSubstringsFilter(
2052 struct berval *prefix,
2054 struct berval ***keysp )
2056 SubstringsAssertion *sa = assertValue;
2058 ber_len_t nkeys = 0;
2059 size_t slen, mlen, klen;
2060 struct berval **keys;
2061 HASH_CONTEXT HASHcontext;
2062 unsigned char HASHdigest[HASH_BYTES];
2063 struct berval *value;
2064 struct berval digest;
2066 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2067 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2072 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2074 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2075 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2076 /* don't bother accounting for stepping */
2077 nkeys += sa->sa_any[i]->bv_len -
2078 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2083 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2084 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2091 return LDAP_SUCCESS;
2094 digest.bv_val = HASHdigest;
2095 digest.bv_len = sizeof(HASHdigest);
2097 slen = strlen( syntax->ssyn_oid );
2098 mlen = strlen( mr->smr_oid );
2100 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2103 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2104 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2106 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2107 value = ber_bvdup( sa->sa_initial );
2108 ldap_pvt_str2upper( value->bv_val );
2110 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2111 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2113 HASH_Init( &HASHcontext );
2114 if( prefix != NULL && prefix->bv_len > 0 ) {
2115 HASH_Update( &HASHcontext,
2116 prefix->bv_val, prefix->bv_len );
2118 HASH_Update( &HASHcontext,
2119 &pre, sizeof( pre ) );
2120 HASH_Update( &HASHcontext,
2121 syntax->ssyn_oid, slen );
2122 HASH_Update( &HASHcontext,
2123 mr->smr_oid, mlen );
2124 HASH_Update( &HASHcontext,
2125 value->bv_val, klen );
2126 HASH_Final( HASHdigest, &HASHcontext );
2128 ber_bvfree( value );
2129 keys[nkeys++] = ber_bvdup( &digest );
2132 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2134 pre = SLAP_INDEX_SUBSTR_PREFIX;
2135 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2137 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2138 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2142 value = ber_bvdup( sa->sa_any[i] );
2143 ldap_pvt_str2upper( value->bv_val );
2146 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2147 j += SLAP_INDEX_SUBSTR_STEP )
2149 HASH_Init( &HASHcontext );
2150 if( prefix != NULL && prefix->bv_len > 0 ) {
2151 HASH_Update( &HASHcontext,
2152 prefix->bv_val, prefix->bv_len );
2154 HASH_Update( &HASHcontext,
2155 &pre, sizeof( pre ) );
2156 HASH_Update( &HASHcontext,
2157 syntax->ssyn_oid, slen );
2158 HASH_Update( &HASHcontext,
2159 mr->smr_oid, mlen );
2160 HASH_Update( &HASHcontext,
2161 &value->bv_val[j], klen );
2162 HASH_Final( HASHdigest, &HASHcontext );
2164 keys[nkeys++] = ber_bvdup( &digest );
2167 ber_bvfree( value );
2171 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2172 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2174 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2175 value = ber_bvdup( sa->sa_final );
2176 ldap_pvt_str2upper( value->bv_val );
2178 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2179 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2181 HASH_Init( &HASHcontext );
2182 if( prefix != NULL && prefix->bv_len > 0 ) {
2183 HASH_Update( &HASHcontext,
2184 prefix->bv_val, prefix->bv_len );
2186 HASH_Update( &HASHcontext,
2187 &pre, sizeof( pre ) );
2188 HASH_Update( &HASHcontext,
2189 syntax->ssyn_oid, slen );
2190 HASH_Update( &HASHcontext,
2191 mr->smr_oid, mlen );
2192 HASH_Update( &HASHcontext,
2193 &value->bv_val[value->bv_len-klen], klen );
2194 HASH_Final( HASHdigest, &HASHcontext );
2196 ber_bvfree( value );
2197 keys[nkeys++] = ber_bvdup( &digest );
2208 return LDAP_SUCCESS;
2214 struct berval *val )
2218 if( val->bv_len == 0 ) return 0;
2220 if( OID_LEADCHAR(val->bv_val[0]) ) {
2222 for(i=1; i < val->bv_len; i++) {
2223 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2224 if( dot++ ) return 1;
2225 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2228 return LDAP_INVALID_SYNTAX;
2232 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2234 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2235 for(i=1; i < val->bv_len; i++) {
2236 if( !DESC_CHAR(val->bv_val[i] ) ) {
2237 return LDAP_INVALID_SYNTAX;
2241 return LDAP_SUCCESS;
2244 return LDAP_INVALID_SYNTAX;
2250 struct berval *val )
2254 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2256 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2257 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2258 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2259 return LDAP_INVALID_SYNTAX;
2262 for(i=1; i < val->bv_len; i++) {
2263 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2266 return LDAP_SUCCESS;
2273 struct berval **normalized )
2276 struct berval *newval;
2282 negative = ( *p == '-' );
2283 if( *p == '-' || *p == '+' ) p++;
2285 /* Ignore leading zeros */
2286 while ( *p == '0' ) p++;
2288 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2291 newval->bv_val = ch_strdup("0");
2296 newval->bv_val = ch_malloc( val->bv_len + 1 );
2300 newval->bv_val[newval->bv_len++] = '-';
2303 for( ; *p != '\0'; p++ ) {
2304 newval->bv_val[newval->bv_len++] = *p;
2308 *normalized = newval;
2309 return LDAP_SUCCESS;
2313 printableStringValidate(
2315 struct berval *val )
2319 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2321 for(i=0; i < val->bv_len; i++) {
2322 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2325 return LDAP_SUCCESS;
2331 struct berval *val )
2335 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2337 for(i=0; i < val->bv_len; i++) {
2338 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2341 return LDAP_SUCCESS;
2348 struct berval **normalized )
2350 struct berval *newval;
2353 newval = ch_malloc( sizeof( struct berval ) );
2357 /* Ignore initial whitespace */
2358 while ( ASCII_SPACE( *p ) ) {
2364 return LDAP_INVALID_SYNTAX;
2367 newval->bv_val = ch_strdup( p );
2368 p = q = newval->bv_val;
2371 if ( ASCII_SPACE( *p ) ) {
2374 /* Ignore the extra whitespace */
2375 while ( ASCII_SPACE( *p ) ) {
2383 assert( *newval->bv_val );
2384 assert( newval->bv_val < p );
2387 /* cannot start with a space */
2388 assert( !ASCII_SPACE(*newval->bv_val) );
2391 * If the string ended in space, backup the pointer one
2392 * position. One is enough because the above loop collapsed
2393 * all whitespace to a single space.
2396 if ( ASCII_SPACE( q[-1] ) ) {
2400 /* cannot end with a space */
2401 assert( !ASCII_SPACE( q[-1] ) );
2403 /* null terminate */
2406 newval->bv_len = q - newval->bv_val;
2407 *normalized = newval;
2409 return LDAP_SUCCESS;
2418 struct berval *value,
2419 void *assertedValue )
2421 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2424 match = strncmp( value->bv_val,
2425 ((struct berval *) assertedValue)->bv_val,
2430 return LDAP_SUCCESS;
2434 caseExactIA5SubstringsMatch(
2439 struct berval *value,
2440 void *assertedValue )
2443 SubstringsAssertion *sub = assertedValue;
2444 struct berval left = *value;
2448 /* Add up asserted input length */
2449 if( sub->sa_initial ) {
2450 inlen += sub->sa_initial->bv_len;
2453 for(i=0; sub->sa_any[i] != NULL; i++) {
2454 inlen += sub->sa_any[i]->bv_len;
2457 if( sub->sa_final ) {
2458 inlen += sub->sa_final->bv_len;
2461 if( sub->sa_initial ) {
2462 if( inlen > left.bv_len ) {
2467 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2468 sub->sa_initial->bv_len );
2474 left.bv_val += sub->sa_initial->bv_len;
2475 left.bv_len -= sub->sa_initial->bv_len;
2476 inlen -= sub->sa_initial->bv_len;
2479 if( sub->sa_final ) {
2480 if( inlen > left.bv_len ) {
2485 match = strncmp( sub->sa_final->bv_val,
2486 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2487 sub->sa_final->bv_len );
2493 left.bv_len -= sub->sa_final->bv_len;
2494 inlen -= sub->sa_final->bv_len;
2498 for(i=0; sub->sa_any[i]; i++) {
2503 if( inlen > left.bv_len ) {
2504 /* not enough length */
2509 if( sub->sa_any[i]->bv_len == 0 ) {
2513 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2520 idx = p - left.bv_val;
2521 assert( idx < left.bv_len );
2523 if( idx >= left.bv_len ) {
2524 /* this shouldn't happen */
2531 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2532 /* not enough left */
2537 match = strncmp( left.bv_val,
2538 sub->sa_any[i]->bv_val,
2539 sub->sa_any[i]->bv_len );
2547 left.bv_val += sub->sa_any[i]->bv_len;
2548 left.bv_len -= sub->sa_any[i]->bv_len;
2549 inlen -= sub->sa_any[i]->bv_len;
2555 return LDAP_SUCCESS;
2558 /* Index generation function */
2559 int caseExactIA5Indexer(
2564 struct berval *prefix,
2565 struct berval **values,
2566 struct berval ***keysp )
2570 struct berval **keys;
2571 HASH_CONTEXT HASHcontext;
2572 unsigned char HASHdigest[HASH_BYTES];
2573 struct berval digest;
2574 digest.bv_val = HASHdigest;
2575 digest.bv_len = sizeof(HASHdigest);
2577 /* we should have at least one value at this point */
2578 assert( values != NULL && values[0] != NULL );
2580 for( i=0; values[i] != NULL; i++ ) {
2581 /* just count them */
2584 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2586 slen = strlen( syntax->ssyn_oid );
2587 mlen = strlen( mr->smr_oid );
2589 for( i=0; values[i] != NULL; i++ ) {
2590 struct berval *value = values[i];
2592 HASH_Init( &HASHcontext );
2593 if( prefix != NULL && prefix->bv_len > 0 ) {
2594 HASH_Update( &HASHcontext,
2595 prefix->bv_val, prefix->bv_len );
2597 HASH_Update( &HASHcontext,
2598 syntax->ssyn_oid, slen );
2599 HASH_Update( &HASHcontext,
2600 mr->smr_oid, mlen );
2601 HASH_Update( &HASHcontext,
2602 value->bv_val, value->bv_len );
2603 HASH_Final( HASHdigest, &HASHcontext );
2605 keys[i] = ber_bvdup( &digest );
2610 return LDAP_SUCCESS;
2613 /* Index generation function */
2614 int caseExactIA5Filter(
2619 struct berval *prefix,
2621 struct berval ***keysp )
2624 struct berval **keys;
2625 HASH_CONTEXT HASHcontext;
2626 unsigned char HASHdigest[HASH_BYTES];
2627 struct berval *value;
2628 struct berval digest;
2629 digest.bv_val = HASHdigest;
2630 digest.bv_len = sizeof(HASHdigest);
2632 slen = strlen( syntax->ssyn_oid );
2633 mlen = strlen( mr->smr_oid );
2635 value = (struct berval *) assertValue;
2637 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2639 HASH_Init( &HASHcontext );
2640 if( prefix != NULL && prefix->bv_len > 0 ) {
2641 HASH_Update( &HASHcontext,
2642 prefix->bv_val, prefix->bv_len );
2644 HASH_Update( &HASHcontext,
2645 syntax->ssyn_oid, slen );
2646 HASH_Update( &HASHcontext,
2647 mr->smr_oid, mlen );
2648 HASH_Update( &HASHcontext,
2649 value->bv_val, value->bv_len );
2650 HASH_Final( HASHdigest, &HASHcontext );
2652 keys[0] = ber_bvdup( &digest );
2656 return LDAP_SUCCESS;
2659 /* Substrings Index generation function */
2660 int caseExactIA5SubstringsIndexer(
2665 struct berval *prefix,
2666 struct berval **values,
2667 struct berval ***keysp )
2671 struct berval **keys;
2672 HASH_CONTEXT HASHcontext;
2673 unsigned char HASHdigest[HASH_BYTES];
2674 struct berval digest;
2675 digest.bv_val = HASHdigest;
2676 digest.bv_len = sizeof(HASHdigest);
2678 /* we should have at least one value at this point */
2679 assert( values != NULL && values[0] != NULL );
2682 for( i=0; values[i] != NULL; i++ ) {
2683 /* count number of indices to generate */
2684 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2688 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2689 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2690 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2691 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2693 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2697 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2698 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2699 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2703 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2704 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2705 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2706 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2708 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2714 /* no keys to generate */
2716 return LDAP_SUCCESS;
2719 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2721 slen = strlen( syntax->ssyn_oid );
2722 mlen = strlen( mr->smr_oid );
2725 for( i=0; values[i] != NULL; i++ ) {
2727 struct berval *value;
2730 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2732 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2733 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2735 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2736 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2738 for( j=0; j<max; j++ ) {
2739 HASH_Init( &HASHcontext );
2740 if( prefix != NULL && prefix->bv_len > 0 ) {
2741 HASH_Update( &HASHcontext,
2742 prefix->bv_val, prefix->bv_len );
2745 HASH_Update( &HASHcontext,
2746 &pre, sizeof( pre ) );
2747 HASH_Update( &HASHcontext,
2748 syntax->ssyn_oid, slen );
2749 HASH_Update( &HASHcontext,
2750 mr->smr_oid, mlen );
2751 HASH_Update( &HASHcontext,
2753 SLAP_INDEX_SUBSTR_MAXLEN );
2754 HASH_Final( HASHdigest, &HASHcontext );
2756 keys[nkeys++] = ber_bvdup( &digest );
2760 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2761 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2763 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2766 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2767 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2768 HASH_Init( &HASHcontext );
2769 if( prefix != NULL && prefix->bv_len > 0 ) {
2770 HASH_Update( &HASHcontext,
2771 prefix->bv_val, prefix->bv_len );
2773 HASH_Update( &HASHcontext,
2774 &pre, sizeof( pre ) );
2775 HASH_Update( &HASHcontext,
2776 syntax->ssyn_oid, slen );
2777 HASH_Update( &HASHcontext,
2778 mr->smr_oid, mlen );
2779 HASH_Update( &HASHcontext,
2781 HASH_Final( HASHdigest, &HASHcontext );
2783 keys[nkeys++] = ber_bvdup( &digest );
2786 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2787 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2788 HASH_Init( &HASHcontext );
2789 if( prefix != NULL && prefix->bv_len > 0 ) {
2790 HASH_Update( &HASHcontext,
2791 prefix->bv_val, prefix->bv_len );
2793 HASH_Update( &HASHcontext,
2794 &pre, sizeof( pre ) );
2795 HASH_Update( &HASHcontext,
2796 syntax->ssyn_oid, slen );
2797 HASH_Update( &HASHcontext,
2798 mr->smr_oid, mlen );
2799 HASH_Update( &HASHcontext,
2800 &value->bv_val[value->bv_len-j], j );
2801 HASH_Final( HASHdigest, &HASHcontext );
2803 keys[nkeys++] = ber_bvdup( &digest );
2817 return LDAP_SUCCESS;
2820 int caseExactIA5SubstringsFilter(
2825 struct berval *prefix,
2827 struct berval ***keysp )
2829 SubstringsAssertion *sa = assertValue;
2831 ber_len_t nkeys = 0;
2832 size_t slen, mlen, klen;
2833 struct berval **keys;
2834 HASH_CONTEXT HASHcontext;
2835 unsigned char HASHdigest[HASH_BYTES];
2836 struct berval *value;
2837 struct berval digest;
2839 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2840 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2845 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2847 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2848 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2849 /* don't bother accounting for stepping */
2850 nkeys += sa->sa_any[i]->bv_len -
2851 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2856 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2857 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2864 return LDAP_SUCCESS;
2867 digest.bv_val = HASHdigest;
2868 digest.bv_len = sizeof(HASHdigest);
2870 slen = strlen( syntax->ssyn_oid );
2871 mlen = strlen( mr->smr_oid );
2873 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2876 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2877 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2879 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2880 value = sa->sa_initial;
2882 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2883 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2885 HASH_Init( &HASHcontext );
2886 if( prefix != NULL && prefix->bv_len > 0 ) {
2887 HASH_Update( &HASHcontext,
2888 prefix->bv_val, prefix->bv_len );
2890 HASH_Update( &HASHcontext,
2891 &pre, sizeof( pre ) );
2892 HASH_Update( &HASHcontext,
2893 syntax->ssyn_oid, slen );
2894 HASH_Update( &HASHcontext,
2895 mr->smr_oid, mlen );
2896 HASH_Update( &HASHcontext,
2897 value->bv_val, klen );
2898 HASH_Final( HASHdigest, &HASHcontext );
2900 keys[nkeys++] = ber_bvdup( &digest );
2903 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2905 pre = SLAP_INDEX_SUBSTR_PREFIX;
2906 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2908 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2909 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2913 value = sa->sa_any[i];
2916 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2917 j += SLAP_INDEX_SUBSTR_STEP )
2919 HASH_Init( &HASHcontext );
2920 if( prefix != NULL && prefix->bv_len > 0 ) {
2921 HASH_Update( &HASHcontext,
2922 prefix->bv_val, prefix->bv_len );
2924 HASH_Update( &HASHcontext,
2925 &pre, sizeof( pre ) );
2926 HASH_Update( &HASHcontext,
2927 syntax->ssyn_oid, slen );
2928 HASH_Update( &HASHcontext,
2929 mr->smr_oid, mlen );
2930 HASH_Update( &HASHcontext,
2931 &value->bv_val[j], klen );
2932 HASH_Final( HASHdigest, &HASHcontext );
2934 keys[nkeys++] = ber_bvdup( &digest );
2939 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2940 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2942 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2943 value = sa->sa_final;
2945 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2946 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2948 HASH_Init( &HASHcontext );
2949 if( prefix != NULL && prefix->bv_len > 0 ) {
2950 HASH_Update( &HASHcontext,
2951 prefix->bv_val, prefix->bv_len );
2953 HASH_Update( &HASHcontext,
2954 &pre, sizeof( pre ) );
2955 HASH_Update( &HASHcontext,
2956 syntax->ssyn_oid, slen );
2957 HASH_Update( &HASHcontext,
2958 mr->smr_oid, mlen );
2959 HASH_Update( &HASHcontext,
2960 &value->bv_val[value->bv_len-klen], klen );
2961 HASH_Final( HASHdigest, &HASHcontext );
2963 keys[nkeys++] = ber_bvdup( &digest );
2974 return LDAP_SUCCESS;
2983 struct berval *value,
2984 void *assertedValue )
2986 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2989 match = strncasecmp( value->bv_val,
2990 ((struct berval *) assertedValue)->bv_val,
2995 return LDAP_SUCCESS;
2999 caseIgnoreIA5SubstringsMatch(
3004 struct berval *value,
3005 void *assertedValue )
3008 SubstringsAssertion *sub = assertedValue;
3009 struct berval left = *value;
3013 /* Add up asserted input length */
3014 if( sub->sa_initial ) {
3015 inlen += sub->sa_initial->bv_len;
3018 for(i=0; sub->sa_any[i] != NULL; i++) {
3019 inlen += sub->sa_any[i]->bv_len;
3022 if( sub->sa_final ) {
3023 inlen += sub->sa_final->bv_len;
3026 if( sub->sa_initial ) {
3027 if( inlen > left.bv_len ) {
3032 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3033 sub->sa_initial->bv_len );
3039 left.bv_val += sub->sa_initial->bv_len;
3040 left.bv_len -= sub->sa_initial->bv_len;
3041 inlen -= sub->sa_initial->bv_len;
3044 if( sub->sa_final ) {
3045 if( inlen > left.bv_len ) {
3050 match = strncasecmp( sub->sa_final->bv_val,
3051 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3052 sub->sa_final->bv_len );
3058 left.bv_len -= sub->sa_final->bv_len;
3059 inlen -= sub->sa_final->bv_len;
3063 for(i=0; sub->sa_any[i]; i++) {
3068 if( inlen > left.bv_len ) {
3069 /* not enough length */
3074 if( sub->sa_any[i]->bv_len == 0 ) {
3078 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3085 idx = p - left.bv_val;
3086 assert( idx < left.bv_len );
3088 if( idx >= left.bv_len ) {
3089 /* this shouldn't happen */
3096 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3097 /* not enough left */
3102 match = strncasecmp( left.bv_val,
3103 sub->sa_any[i]->bv_val,
3104 sub->sa_any[i]->bv_len );
3113 left.bv_val += sub->sa_any[i]->bv_len;
3114 left.bv_len -= sub->sa_any[i]->bv_len;
3115 inlen -= sub->sa_any[i]->bv_len;
3121 return LDAP_SUCCESS;
3124 /* Index generation function */
3125 int caseIgnoreIA5Indexer(
3130 struct berval *prefix,
3131 struct berval **values,
3132 struct berval ***keysp )
3136 struct berval **keys;
3137 HASH_CONTEXT HASHcontext;
3138 unsigned char HASHdigest[HASH_BYTES];
3139 struct berval digest;
3140 digest.bv_val = HASHdigest;
3141 digest.bv_len = sizeof(HASHdigest);
3143 /* we should have at least one value at this point */
3144 assert( values != NULL && values[0] != NULL );
3146 for( i=0; values[i] != NULL; i++ ) {
3147 /* just count them */
3150 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3152 slen = strlen( syntax->ssyn_oid );
3153 mlen = strlen( mr->smr_oid );
3155 for( i=0; values[i] != NULL; i++ ) {
3156 struct berval *value = ber_bvdup( values[i] );
3157 ldap_pvt_str2upper( value->bv_val );
3159 HASH_Init( &HASHcontext );
3160 if( prefix != NULL && prefix->bv_len > 0 ) {
3161 HASH_Update( &HASHcontext,
3162 prefix->bv_val, prefix->bv_len );
3164 HASH_Update( &HASHcontext,
3165 syntax->ssyn_oid, slen );
3166 HASH_Update( &HASHcontext,
3167 mr->smr_oid, mlen );
3168 HASH_Update( &HASHcontext,
3169 value->bv_val, value->bv_len );
3170 HASH_Final( HASHdigest, &HASHcontext );
3172 ber_bvfree( value );
3174 keys[i] = ber_bvdup( &digest );
3179 return LDAP_SUCCESS;
3182 /* Index generation function */
3183 int caseIgnoreIA5Filter(
3188 struct berval *prefix,
3190 struct berval ***keysp )
3193 struct berval **keys;
3194 HASH_CONTEXT HASHcontext;
3195 unsigned char HASHdigest[HASH_BYTES];
3196 struct berval *value;
3197 struct berval digest;
3198 digest.bv_val = HASHdigest;
3199 digest.bv_len = sizeof(HASHdigest);
3201 slen = strlen( syntax->ssyn_oid );
3202 mlen = strlen( mr->smr_oid );
3204 value = ber_bvdup( (struct berval *) assertValue );
3205 ldap_pvt_str2upper( value->bv_val );
3207 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3209 HASH_Init( &HASHcontext );
3210 if( prefix != NULL && prefix->bv_len > 0 ) {
3211 HASH_Update( &HASHcontext,
3212 prefix->bv_val, prefix->bv_len );
3214 HASH_Update( &HASHcontext,
3215 syntax->ssyn_oid, slen );
3216 HASH_Update( &HASHcontext,
3217 mr->smr_oid, mlen );
3218 HASH_Update( &HASHcontext,
3219 value->bv_val, value->bv_len );
3220 HASH_Final( HASHdigest, &HASHcontext );
3222 keys[0] = ber_bvdup( &digest );
3225 ber_bvfree( value );
3229 return LDAP_SUCCESS;
3232 /* Substrings Index generation function */
3233 int caseIgnoreIA5SubstringsIndexer(
3238 struct berval *prefix,
3239 struct berval **values,
3240 struct berval ***keysp )
3244 struct berval **keys;
3245 HASH_CONTEXT HASHcontext;
3246 unsigned char HASHdigest[HASH_BYTES];
3247 struct berval digest;
3248 digest.bv_val = HASHdigest;
3249 digest.bv_len = sizeof(HASHdigest);
3251 /* we should have at least one value at this point */
3252 assert( values != NULL && values[0] != NULL );
3255 for( i=0; values[i] != NULL; i++ ) {
3256 /* count number of indices to generate */
3257 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3261 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3262 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3263 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3264 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3266 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3270 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3271 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3272 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3276 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3277 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3278 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3279 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3281 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3287 /* no keys to generate */
3289 return LDAP_SUCCESS;
3292 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3294 slen = strlen( syntax->ssyn_oid );
3295 mlen = strlen( mr->smr_oid );
3298 for( i=0; values[i] != NULL; i++ ) {
3300 struct berval *value;
3302 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3304 value = ber_bvdup( values[i] );
3305 ldap_pvt_str2upper( value->bv_val );
3307 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3308 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3310 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3311 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3313 for( j=0; j<max; j++ ) {
3314 HASH_Init( &HASHcontext );
3315 if( prefix != NULL && prefix->bv_len > 0 ) {
3316 HASH_Update( &HASHcontext,
3317 prefix->bv_val, prefix->bv_len );
3320 HASH_Update( &HASHcontext,
3321 &pre, sizeof( pre ) );
3322 HASH_Update( &HASHcontext,
3323 syntax->ssyn_oid, slen );
3324 HASH_Update( &HASHcontext,
3325 mr->smr_oid, mlen );
3326 HASH_Update( &HASHcontext,
3328 SLAP_INDEX_SUBSTR_MAXLEN );
3329 HASH_Final( HASHdigest, &HASHcontext );
3331 keys[nkeys++] = ber_bvdup( &digest );
3335 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3336 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3338 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3341 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3342 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3343 HASH_Init( &HASHcontext );
3344 if( prefix != NULL && prefix->bv_len > 0 ) {
3345 HASH_Update( &HASHcontext,
3346 prefix->bv_val, prefix->bv_len );
3348 HASH_Update( &HASHcontext,
3349 &pre, sizeof( pre ) );
3350 HASH_Update( &HASHcontext,
3351 syntax->ssyn_oid, slen );
3352 HASH_Update( &HASHcontext,
3353 mr->smr_oid, mlen );
3354 HASH_Update( &HASHcontext,
3356 HASH_Final( HASHdigest, &HASHcontext );
3358 keys[nkeys++] = ber_bvdup( &digest );
3361 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3362 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3363 HASH_Init( &HASHcontext );
3364 if( prefix != NULL && prefix->bv_len > 0 ) {
3365 HASH_Update( &HASHcontext,
3366 prefix->bv_val, prefix->bv_len );
3368 HASH_Update( &HASHcontext,
3369 &pre, sizeof( pre ) );
3370 HASH_Update( &HASHcontext,
3371 syntax->ssyn_oid, slen );
3372 HASH_Update( &HASHcontext,
3373 mr->smr_oid, mlen );
3374 HASH_Update( &HASHcontext,
3375 &value->bv_val[value->bv_len-j], j );
3376 HASH_Final( HASHdigest, &HASHcontext );
3378 keys[nkeys++] = ber_bvdup( &digest );
3383 ber_bvfree( value );
3394 return LDAP_SUCCESS;
3397 int caseIgnoreIA5SubstringsFilter(
3402 struct berval *prefix,
3404 struct berval ***keysp )
3406 SubstringsAssertion *sa = assertValue;
3408 ber_len_t nkeys = 0;
3409 size_t slen, mlen, klen;
3410 struct berval **keys;
3411 HASH_CONTEXT HASHcontext;
3412 unsigned char HASHdigest[HASH_BYTES];
3413 struct berval *value;
3414 struct berval digest;
3416 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3417 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3422 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3424 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3425 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3426 /* don't bother accounting for stepping */
3427 nkeys += sa->sa_any[i]->bv_len -
3428 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3433 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3434 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3441 return LDAP_SUCCESS;
3444 digest.bv_val = HASHdigest;
3445 digest.bv_len = sizeof(HASHdigest);
3447 slen = strlen( syntax->ssyn_oid );
3448 mlen = strlen( mr->smr_oid );
3450 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3453 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3454 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3456 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3457 value = ber_bvdup( sa->sa_initial );
3458 ldap_pvt_str2upper( value->bv_val );
3460 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3461 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3463 HASH_Init( &HASHcontext );
3464 if( prefix != NULL && prefix->bv_len > 0 ) {
3465 HASH_Update( &HASHcontext,
3466 prefix->bv_val, prefix->bv_len );
3468 HASH_Update( &HASHcontext,
3469 &pre, sizeof( pre ) );
3470 HASH_Update( &HASHcontext,
3471 syntax->ssyn_oid, slen );
3472 HASH_Update( &HASHcontext,
3473 mr->smr_oid, mlen );
3474 HASH_Update( &HASHcontext,
3475 value->bv_val, klen );
3476 HASH_Final( HASHdigest, &HASHcontext );
3478 ber_bvfree( value );
3479 keys[nkeys++] = ber_bvdup( &digest );
3482 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3484 pre = SLAP_INDEX_SUBSTR_PREFIX;
3485 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3487 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3488 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3492 value = ber_bvdup( sa->sa_any[i] );
3493 ldap_pvt_str2upper( value->bv_val );
3496 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3497 j += SLAP_INDEX_SUBSTR_STEP )
3499 HASH_Init( &HASHcontext );
3500 if( prefix != NULL && prefix->bv_len > 0 ) {
3501 HASH_Update( &HASHcontext,
3502 prefix->bv_val, prefix->bv_len );
3504 HASH_Update( &HASHcontext,
3505 &pre, sizeof( pre ) );
3506 HASH_Update( &HASHcontext,
3507 syntax->ssyn_oid, slen );
3508 HASH_Update( &HASHcontext,
3509 mr->smr_oid, mlen );
3510 HASH_Update( &HASHcontext,
3511 &value->bv_val[j], klen );
3512 HASH_Final( HASHdigest, &HASHcontext );
3514 keys[nkeys++] = ber_bvdup( &digest );
3517 ber_bvfree( value );
3521 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3522 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3524 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3525 value = ber_bvdup( sa->sa_final );
3526 ldap_pvt_str2upper( value->bv_val );
3528 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3529 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3531 HASH_Init( &HASHcontext );
3532 if( prefix != NULL && prefix->bv_len > 0 ) {
3533 HASH_Update( &HASHcontext,
3534 prefix->bv_val, prefix->bv_len );
3536 HASH_Update( &HASHcontext,
3537 &pre, sizeof( pre ) );
3538 HASH_Update( &HASHcontext,
3539 syntax->ssyn_oid, slen );
3540 HASH_Update( &HASHcontext,
3541 mr->smr_oid, mlen );
3542 HASH_Update( &HASHcontext,
3543 &value->bv_val[value->bv_len-klen], klen );
3544 HASH_Final( HASHdigest, &HASHcontext );
3546 ber_bvfree( value );
3547 keys[nkeys++] = ber_bvdup( &digest );
3558 return LDAP_SUCCESS;
3562 numericStringNormalize(
3565 struct berval **normalized )
3567 /* similiar to IA5StringNormalize except removes all spaces */
3568 struct berval *newval;
3571 newval = ch_malloc( sizeof( struct berval ) );
3575 /* Ignore initial whitespace */
3576 while ( ASCII_SPACE( *p ) ) {
3582 return LDAP_INVALID_SYNTAX;
3585 newval->bv_val = ch_strdup( p );
3586 p = q = newval->bv_val;
3589 if ( ASCII_SPACE( *p ) ) {
3590 /* Ignore whitespace */
3597 assert( *newval->bv_val );
3598 assert( newval->bv_val < p );
3601 /* cannot start with a space */
3602 assert( !ASCII_SPACE(*newval->bv_val) );
3604 /* cannot end with a space */
3605 assert( !ASCII_SPACE( q[-1] ) );
3607 /* null terminate */
3610 newval->bv_len = q - newval->bv_val;
3611 *normalized = newval;
3613 return LDAP_SUCCESS;
3617 objectIdentifierFirstComponentMatch(
3622 struct berval *value,
3623 void *assertedValue )
3625 int rc = LDAP_SUCCESS;
3627 struct berval *asserted = (struct berval *) assertedValue;
3631 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3632 return LDAP_INVALID_SYNTAX;
3635 /* trim leading white space */
3636 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3640 /* grab next word */
3641 oid.bv_val = &value->bv_val[i];
3642 oid.bv_len = value->bv_len - i;
3643 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3648 /* insert attributeTypes, objectclass check here */
3649 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3650 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3653 char *stored = ch_malloc( oid.bv_len + 1 );
3654 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3655 stored[oid.bv_len] = '\0';
3657 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3658 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3659 MatchingRule *stored_mr = mr_find( stored );
3661 if( asserted_mr == NULL ) {
3662 rc = SLAPD_COMPARE_UNDEFINED;
3664 match = asserted_mr != stored_mr;
3667 } else if ( !strcmp( syntax->ssyn_oid,
3668 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3670 AttributeType *asserted_at = at_find( asserted->bv_val );
3671 AttributeType *stored_at = at_find( stored );
3673 if( asserted_at == NULL ) {
3674 rc = SLAPD_COMPARE_UNDEFINED;
3676 match = asserted_at != stored_at;
3679 } else if ( !strcmp( syntax->ssyn_oid,
3680 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3682 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3683 ObjectClass *stored_oc = oc_find( stored );
3685 if( asserted_oc == NULL ) {
3686 rc = SLAPD_COMPARE_UNDEFINED;
3688 match = asserted_oc != stored_oc;
3695 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3696 "%d\n\t\"%s\"\n\t\"%s\"\n",
3697 match, value->bv_val, asserted->bv_val );
3699 if( rc == LDAP_SUCCESS ) *matchp = match;
3704 check_time_syntax (struct berval *val,
3708 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3709 static int mdays[2][12] = {
3710 /* non-leap years */
3711 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3713 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3716 int part, c, tzoffset, leapyear = 0 ;
3718 if( val->bv_len == 0 ) {
3719 return LDAP_INVALID_SYNTAX;
3722 p = (char *)val->bv_val;
3723 e = p + val->bv_len;
3725 /* Ignore initial whitespace */
3726 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3730 if (e - p < 13 - (2 * start)) {
3731 return LDAP_INVALID_SYNTAX;
3734 for (part = 0; part < 9; part++) {
3738 for (part = start; part < 7; part++) {
3740 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3747 return LDAP_INVALID_SYNTAX;
3749 if (c < 0 || c > 9) {
3750 return LDAP_INVALID_SYNTAX;
3756 return LDAP_INVALID_SYNTAX;
3758 if (c < 0 || c > 9) {
3759 return LDAP_INVALID_SYNTAX;
3764 if (part == 2 || part == 3) {
3767 if (parts[part] < 0) {
3768 return LDAP_INVALID_SYNTAX;
3770 if (parts[part] > ceiling[part]) {
3771 return LDAP_INVALID_SYNTAX;
3775 /* leapyear check for the Gregorian calendar (year>1581) */
3776 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3777 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3782 if (parts[3] > mdays[leapyear][parts[2]]) {
3783 return LDAP_INVALID_SYNTAX;
3788 tzoffset = 0; /* UTC */
3789 } else if (c != '+' && c != '-') {
3790 return LDAP_INVALID_SYNTAX;
3794 } else /* c == '+' */ {
3799 return LDAP_INVALID_SYNTAX;
3802 for (part = 7; part < 9; part++) {
3804 if (c < 0 || c > 9) {
3805 return LDAP_INVALID_SYNTAX;
3810 if (c < 0 || c > 9) {
3811 return LDAP_INVALID_SYNTAX;
3815 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3816 return LDAP_INVALID_SYNTAX;
3821 /* Ignore trailing whitespace */
3822 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3826 return LDAP_INVALID_SYNTAX;
3829 switch ( tzoffset ) {
3830 case -1: /* negativ offset to UTC, ie west of Greenwich */
3831 parts[4] += parts[7];
3832 parts[5] += parts[8];
3833 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3837 c = mdays[leapyear][parts[2]];
3839 if (parts[part] > c) {
3840 parts[part] -= c + 1;
3845 case 1: /* positive offset to UTC, ie east of Greenwich */
3846 parts[4] -= parts[7];
3847 parts[5] -= parts[8];
3848 for (part = 6; --part > 0; ) {
3852 /* first arg to % needs to be non negativ */
3853 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3855 if (parts[part] < 0) {
3856 parts[part] += c + 1;
3861 case 0: /* already UTC */
3865 return LDAP_SUCCESS;
3872 struct berval **normalized )
3877 rc = check_time_syntax(val, 1, parts);
3878 if (rc != LDAP_SUCCESS) {
3883 out = ch_malloc( sizeof(struct berval) );
3885 return LBER_ERROR_MEMORY;
3888 out->bv_val = ch_malloc( 14 );
3889 if ( out->bv_val == NULL ) {
3891 return LBER_ERROR_MEMORY;
3894 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3895 parts[1], parts[2] + 1, parts[3] + 1,
3896 parts[4], parts[5], parts[6] );
3900 return LDAP_SUCCESS;
3910 return check_time_syntax(in, 1, parts);
3914 generalizedTimeValidate(
3920 return check_time_syntax(in, 0, parts);
3924 generalizedTimeNormalize(
3927 struct berval **normalized )
3932 rc = check_time_syntax(val, 0, parts);
3933 if (rc != LDAP_SUCCESS) {
3938 out = ch_malloc( sizeof(struct berval) );
3940 return LBER_ERROR_MEMORY;
3943 out->bv_val = ch_malloc( 16 );
3944 if ( out->bv_val == NULL ) {
3946 return LBER_ERROR_MEMORY;
3949 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3950 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3951 parts[4], parts[5], parts[6] );
3955 return LDAP_SUCCESS;
3959 nisNetgroupTripleValidate(
3961 struct berval *val )
3966 if ( val->bv_len == 0 ) {
3967 return LDAP_INVALID_SYNTAX;
3970 p = (char *)val->bv_val;
3971 e = p + val->bv_len;
3974 /* syntax does not allow leading white space */
3975 /* Ignore initial whitespace */
3976 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3981 if ( *p != '(' /*')'*/ ) {
3982 return LDAP_INVALID_SYNTAX;
3985 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3989 return LDAP_INVALID_SYNTAX;
3992 } else if ( !ATTR_CHAR( *p ) ) {
3993 return LDAP_INVALID_SYNTAX;
3997 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3998 return LDAP_INVALID_SYNTAX;
4004 /* syntax does not allow trailing white space */
4005 /* Ignore trailing whitespace */
4006 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4012 return LDAP_INVALID_SYNTAX;
4015 return LDAP_SUCCESS;
4019 bootParameterValidate(
4021 struct berval *val )
4025 if ( val->bv_len == 0 ) {
4026 return LDAP_INVALID_SYNTAX;
4029 p = (char *)val->bv_val;
4030 e = p + val->bv_len;
4033 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4034 if ( !ATTR_CHAR( *p ) ) {
4035 return LDAP_INVALID_SYNTAX;
4040 return LDAP_INVALID_SYNTAX;
4044 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4045 if ( !ATTR_CHAR( *p ) ) {
4046 return LDAP_INVALID_SYNTAX;
4051 return LDAP_INVALID_SYNTAX;
4055 for ( p++; p < e; p++ ) {
4056 if ( !ATTR_CHAR( *p ) ) {
4057 return LDAP_INVALID_SYNTAX;
4061 return LDAP_SUCCESS;
4064 struct syntax_defs_rec {
4067 slap_syntax_validate_func *sd_validate;
4068 slap_syntax_transform_func *sd_normalize;
4069 slap_syntax_transform_func *sd_pretty;
4070 #ifdef SLAPD_BINARY_CONVERSION
4071 slap_syntax_transform_func *sd_ber2str;
4072 slap_syntax_transform_func *sd_str2ber;
4076 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4077 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4079 struct syntax_defs_rec syntax_defs[] = {
4080 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4081 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4082 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4083 0, NULL, NULL, NULL},
4084 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4085 0, NULL, NULL, NULL},
4086 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4087 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4088 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4089 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4090 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4091 0, bitStringValidate, NULL, NULL },
4092 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4093 0, booleanValidate, NULL, NULL},
4094 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4095 X_BINARY X_NOT_H_R ")",
4096 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4097 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4098 X_BINARY X_NOT_H_R ")",
4099 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4100 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
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.11 DESC 'Country String' )",
4104 0, NULL, NULL, NULL},
4105 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4106 0, dnValidate, dnNormalize, dnPretty},
4107 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4108 0, NULL, NULL, NULL},
4109 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4110 0, NULL, NULL, NULL},
4111 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4112 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4113 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4114 0, NULL, NULL, NULL},
4115 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4116 0, NULL, NULL, NULL},
4117 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4118 0, NULL, NULL, NULL},
4119 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4120 0, NULL, NULL, NULL},
4121 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4122 0, NULL, NULL, NULL},
4123 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4124 0, IA5StringValidate, faxNumberNormalize, NULL},
4125 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4126 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4127 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4128 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4129 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4130 0, NULL, NULL, NULL},
4131 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4132 0, IA5StringValidate, IA5StringNormalize, NULL},
4133 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4134 0, integerValidate, integerNormalize, integerPretty},
4135 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4136 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4137 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4138 0, NULL, NULL, NULL},
4139 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4140 0, NULL, NULL, NULL},
4141 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4142 0, NULL, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4144 0, NULL, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4146 0, NULL, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4148 0, nameUIDValidate, nameUIDNormalize, NULL},
4149 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4150 0, NULL, NULL, NULL},
4151 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4152 0, IA5StringValidate, numericStringNormalize, NULL},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4154 0, NULL, NULL, NULL},
4155 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4156 0, oidValidate, NULL, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4158 0, NULL, NULL, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4160 0, blobValidate, NULL, NULL},
4161 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4162 0, blobValidate, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4164 0, NULL, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4166 0, NULL, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4168 0, printableStringValidate, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4170 X_BINARY X_NOT_H_R ")",
4171 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4173 0, IA5StringValidate, phoneNumberNormalize, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4175 0, NULL, NULL, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4177 0, IA5StringValidate, telexNumberNormalize, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4179 0, utcTimeValidate, utcTimeNormalize, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4181 0, NULL, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4183 0, NULL, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4185 0, NULL, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4187 0, NULL, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4189 0, NULL, NULL, NULL},
4191 /* RFC 2307 NIS Syntaxes */
4192 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4193 0, nisNetgroupTripleValidate, NULL, NULL},
4194 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4195 0, bootParameterValidate, NULL, NULL},
4197 /* OpenLDAP Experimental Syntaxes */
4198 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4199 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4201 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4202 0, NULL, NULL, NULL},
4204 /* OpenLDAP Void Syntax */
4205 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4206 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4207 {NULL, 0, NULL, NULL, NULL}
4210 struct mrule_defs_rec {
4212 slap_mask_t mrd_usage;
4213 slap_mr_convert_func * mrd_convert;
4214 slap_mr_normalize_func * mrd_normalize;
4215 slap_mr_match_func * mrd_match;
4216 slap_mr_indexer_func * mrd_indexer;
4217 slap_mr_filter_func * mrd_filter;
4219 char * mrd_associated;
4223 * Other matching rules in X.520 that we do not use (yet):
4225 * 2.5.13.9 numericStringOrderingMatch
4226 * 2.5.13.15 integerOrderingMatch
4227 * 2.5.13.18 octetStringOrderingMatch
4228 * 2.5.13.19 octetStringSubstringsMatch
4229 * 2.5.13.25 uTCTimeMatch
4230 * 2.5.13.26 uTCTimeOrderingMatch
4231 * 2.5.13.31 directoryStringFirstComponentMatch
4232 * 2.5.13.32 wordMatch
4233 * 2.5.13.33 keywordMatch
4234 * 2.5.13.34 certificateExactMatch
4235 * 2.5.13.35 certificateMatch
4236 * 2.5.13.36 certificatePairExactMatch
4237 * 2.5.13.37 certificatePairMatch
4238 * 2.5.13.38 certificateListExactMatch
4239 * 2.5.13.39 certificateListMatch
4240 * 2.5.13.40 algorithmIdentifierMatch
4241 * 2.5.13.41 storedPrefixMatch
4242 * 2.5.13.42 attributeCertificateMatch
4243 * 2.5.13.43 readerAndKeyIDMatch
4244 * 2.5.13.44 attributeIntegrityMatch
4247 struct mrule_defs_rec mrule_defs[] = {
4249 * EQUALITY matching rules must be listed after associated APPROX
4250 * matching rules. So, we list all APPROX matching rules first.
4252 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4253 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4254 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4256 directoryStringApproxMatch, directoryStringApproxIndexer,
4257 directoryStringApproxFilter,
4260 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4261 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4262 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4264 IA5StringApproxMatch, IA5StringApproxIndexer,
4265 IA5StringApproxFilter,
4269 * Other matching rules
4272 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4273 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4274 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4276 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4279 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4280 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4281 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4283 dnMatch, dnIndexer, dnFilter,
4286 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4287 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4288 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4290 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4291 directoryStringApproxMatchOID },
4293 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4294 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4297 caseIgnoreOrderingMatch, NULL, NULL,
4300 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4301 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4302 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4304 caseIgnoreSubstringsMatch,
4305 caseIgnoreSubstringsIndexer,
4306 caseIgnoreSubstringsFilter,
4309 {"( 2.5.13.5 NAME 'caseExactMatch' "
4310 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4311 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4313 caseExactMatch, caseExactIndexer, caseExactFilter,
4314 directoryStringApproxMatchOID },
4316 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4317 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4320 caseExactOrderingMatch, NULL, NULL,
4323 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4324 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4325 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4327 caseExactSubstringsMatch,
4328 caseExactSubstringsIndexer,
4329 caseExactSubstringsFilter,
4332 {"( 2.5.13.8 NAME 'numericStringMatch' "
4333 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4334 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4337 caseIgnoreIA5Indexer,
4338 caseIgnoreIA5Filter,
4341 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4342 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4343 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4345 caseIgnoreIA5SubstringsMatch,
4346 caseIgnoreIA5SubstringsIndexer,
4347 caseIgnoreIA5SubstringsFilter,
4350 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4351 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4352 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4354 caseIgnoreListMatch, NULL, NULL,
4357 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4358 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4359 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4361 caseIgnoreListSubstringsMatch, NULL, NULL,
4364 {"( 2.5.13.13 NAME 'booleanMatch' "
4365 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4366 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4368 booleanMatch, NULL, NULL,
4371 {"( 2.5.13.14 NAME 'integerMatch' "
4372 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4373 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4375 integerMatch, integerIndexer, integerFilter,
4378 {"( 2.5.13.16 NAME 'bitStringMatch' "
4379 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4380 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4382 bitStringMatch, NULL, NULL,
4385 {"( 2.5.13.17 NAME 'octetStringMatch' "
4386 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4387 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4389 octetStringMatch, octetStringIndexer, octetStringFilter,
4392 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4393 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4394 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4396 telephoneNumberMatch, NULL, NULL,
4399 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4400 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4401 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4403 telephoneNumberSubstringsMatch, NULL, NULL,
4406 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4407 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4408 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4410 presentationAddressMatch, NULL, NULL,
4413 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4414 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4415 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4417 uniqueMemberMatch, NULL, NULL,
4420 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4421 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4422 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4424 protocolInformationMatch, NULL, NULL,
4427 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4428 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4429 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4431 generalizedTimeMatch, NULL, NULL,
4434 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4435 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4438 generalizedTimeOrderingMatch, NULL, NULL,
4441 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4442 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4443 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4445 integerFirstComponentMatch, NULL, NULL,
4448 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4449 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4450 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4452 objectIdentifierFirstComponentMatch, NULL, NULL,
4455 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4456 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4457 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4459 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4460 IA5StringApproxMatchOID },
4462 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4463 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4464 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4466 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4467 IA5StringApproxMatchOID },
4469 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4470 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4473 caseIgnoreIA5SubstringsMatch,
4474 caseIgnoreIA5SubstringsIndexer,
4475 caseIgnoreIA5SubstringsFilter,
4478 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4479 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4482 caseExactIA5SubstringsMatch,
4483 caseExactIA5SubstringsIndexer,
4484 caseExactIA5SubstringsFilter,
4487 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4488 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4491 authPasswordMatch, NULL, NULL,
4494 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4495 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4498 OpenLDAPaciMatch, NULL, NULL,
4501 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4510 /* we should only be called once (from main) */
4511 assert( schema_init_done == 0 );
4513 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4514 res = register_syntax( syntax_defs[i].sd_desc,
4515 syntax_defs[i].sd_flags,
4516 syntax_defs[i].sd_validate,
4517 syntax_defs[i].sd_normalize,
4518 syntax_defs[i].sd_pretty
4519 #ifdef SLAPD_BINARY_CONVERSION
4521 syntax_defs[i].sd_ber2str,
4522 syntax_defs[i].sd_str2ber
4527 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4528 syntax_defs[i].sd_desc );
4533 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4534 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4536 "schema_init: Ingoring unusable matching rule %s\n",
4537 mrule_defs[i].mrd_desc );
4541 res = register_matching_rule(
4542 mrule_defs[i].mrd_desc,
4543 mrule_defs[i].mrd_usage,
4544 mrule_defs[i].mrd_convert,
4545 mrule_defs[i].mrd_normalize,
4546 mrule_defs[i].mrd_match,
4547 mrule_defs[i].mrd_indexer,
4548 mrule_defs[i].mrd_filter,
4549 mrule_defs[i].mrd_associated );
4553 "schema_init: Error registering matching rule %s\n",
4554 mrule_defs[i].mrd_desc );
4558 schema_init_done = 1;
4559 return LDAP_SUCCESS;