1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
22 #include "lutil_md5.h"
23 /* We should replace MD5 with a faster hash */
24 #define HASH_BYTES LUTIL_MD5_BYTES
25 #define HASH_CONTEXT lutil_MD5_CTX
26 #define HASH_Init(c) lutil_MD5Init(c)
27 #define HASH_Update(c,buf,len) lutil_MD5Update(c,buf,len)
28 #define HASH_Final(d,c) lutil_MD5Final(d,c)
30 #include "lutil_hash.h"
31 /* We should replace MD5 with a faster hash */
32 #define HASH_BYTES LUTIL_HASH_BYTES
33 #define HASH_CONTEXT lutil_HASH_CTX
34 #define HASH_Init(c) lutil_HASHInit(c)
35 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
36 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
39 /* recycled validatation routines */
40 #define berValidate blobValidate
42 /* unimplemented pretters */
44 #define integerPretty NULL
46 /* recycled matching routines */
47 #define bitStringMatch octetStringMatch
48 #define integerMatch caseIgnoreIA5Match
49 #define numericStringMatch caseIgnoreMatch
50 #define objectIdentifierMatch numericStringMatch
51 #define telephoneNumberMatch numericStringMatch
52 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
53 #define generalizedTimeMatch numericStringMatch
54 #define generalizedTimeOrderingMatch numericStringMatch
55 #define uniqueMemberMatch dnMatch
57 /* approx matching rules */
58 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
59 #define directoryStringApproxMatch approxMatch
60 #define directoryStringApproxIndexer approxIndexer
61 #define directoryStringApproxFilter approxFilter
62 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
63 #define IA5StringApproxMatch approxMatch
64 #define IA5StringApproxIndexer approxIndexer
65 #define IA5StringApproxFilter approxFilter
67 /* orderring matching rules */
68 #define caseIgnoreOrderingMatch caseIgnoreMatch
69 #define caseExactOrderingMatch caseExactMatch
71 /* unimplemented matching routines */
72 #define caseIgnoreListMatch NULL
73 #define caseIgnoreListSubstringsMatch NULL
74 #define presentationAddressMatch NULL
75 #define protocolInformationMatch NULL
76 #define integerFirstComponentMatch NULL
78 #define OpenLDAPaciMatch NULL
79 #define authPasswordMatch NULL
81 /* recycled indexing/filtering routines */
82 #define dnIndexer caseIgnoreIndexer
83 #define dnFilter caseIgnoreFilter
84 #define integerIndexer caseIgnoreIA5Indexer
85 #define integerFilter caseIgnoreIA5Filter
87 static char *strcasechr( const char *str, int c )
89 char *lower = strchr( str, TOLOWER(c) );
90 char *upper = strchr( str, TOUPPER(c) );
92 if( lower && upper ) {
93 return lower < upper ? lower : upper;
107 struct berval *value,
108 void *assertedValue )
110 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
113 match = memcmp( value->bv_val,
114 ((struct berval *) assertedValue)->bv_val,
122 /* Index generation function */
123 int octetStringIndexer(
128 struct berval *prefix,
129 struct berval **values,
130 struct berval ***keysp )
134 struct berval **keys;
135 HASH_CONTEXT HASHcontext;
136 unsigned char HASHdigest[HASH_BYTES];
137 struct berval digest;
138 digest.bv_val = HASHdigest;
139 digest.bv_len = sizeof(HASHdigest);
141 /* we should have at least one value at this point */
142 assert( values != NULL && values[0] != NULL );
144 for( i=0; values[i] != NULL; i++ ) {
145 /* just count them */
148 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
150 slen = strlen( syntax->ssyn_oid );
151 mlen = strlen( mr->smr_oid );
153 for( i=0; values[i] != NULL; i++ ) {
154 HASH_Init( &HASHcontext );
155 if( prefix != NULL && prefix->bv_len > 0 ) {
156 HASH_Update( &HASHcontext,
157 prefix->bv_val, prefix->bv_len );
159 HASH_Update( &HASHcontext,
160 syntax->ssyn_oid, slen );
161 HASH_Update( &HASHcontext,
163 HASH_Update( &HASHcontext,
164 values[i]->bv_val, values[i]->bv_len );
165 HASH_Final( HASHdigest, &HASHcontext );
167 keys[i] = ber_bvdup( &digest );
177 /* Index generation function */
178 int octetStringFilter(
183 struct berval *prefix,
185 struct berval ***keysp )
188 struct berval **keys;
189 HASH_CONTEXT HASHcontext;
190 unsigned char HASHdigest[HASH_BYTES];
191 struct berval *value = (struct berval *) assertValue;
192 struct berval digest;
193 digest.bv_val = HASHdigest;
194 digest.bv_len = sizeof(HASHdigest);
196 slen = strlen( syntax->ssyn_oid );
197 mlen = strlen( mr->smr_oid );
199 keys = ch_malloc( sizeof( struct berval * ) * 2 );
201 HASH_Init( &HASHcontext );
202 if( prefix != NULL && prefix->bv_len > 0 ) {
203 HASH_Update( &HASHcontext,
204 prefix->bv_val, prefix->bv_len );
206 HASH_Update( &HASHcontext,
207 syntax->ssyn_oid, slen );
208 HASH_Update( &HASHcontext,
210 HASH_Update( &HASHcontext,
211 value->bv_val, value->bv_len );
212 HASH_Final( HASHdigest, &HASHcontext );
214 keys[0] = ber_bvdup( &digest );
230 if( in->bv_len == 0 ) return LDAP_SUCCESS;
232 dn = ch_strdup( in->bv_val );
234 rc = dn_validate( dn ) == NULL
235 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
245 struct berval **normalized )
247 struct berval *out = ber_bvdup( val );
249 if( out->bv_len != 0 ) {
251 #ifdef USE_DN_NORMALIZE
252 dn = dn_normalize( out->bv_val );
254 dn = dn_validate( out->bv_val );
259 return LDAP_INVALID_SYNTAX;
263 out->bv_len = strlen( dn );
276 struct berval *value,
277 void *assertedValue )
280 struct berval *asserted = (struct berval *) assertedValue;
282 match = value->bv_len - asserted->bv_len;
285 #ifdef USE_DN_NORMALIZE
286 match = strcmp( value->bv_val, asserted->bv_val );
288 match = strcasecmp( value->bv_val, asserted->bv_val );
293 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
294 "dnMatch: %d\n %s\n %s\n", match,
295 value->bv_val, asserted->bv_val ));
297 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
298 match, value->bv_val, asserted->bv_val );
314 if( in->bv_len == 0 ) return LDAP_SUCCESS;
316 dn = ber_bvdup( in );
318 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
319 /* assume presence of optional UID */
322 for(i=dn->bv_len-2; i>2; i--) {
323 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
327 if( dn->bv_val[i] != '\'' ) {
328 return LDAP_INVALID_SYNTAX;
330 if( dn->bv_val[i-1] != 'B' ) {
331 return LDAP_INVALID_SYNTAX;
333 if( dn->bv_val[i-2] != '#' ) {
334 return LDAP_INVALID_SYNTAX;
337 /* trim the UID to allow use of dn_validate */
338 dn->bv_val[i-2] = '\0';
341 rc = dn_validate( dn->bv_val ) == NULL
342 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
352 struct berval **normalized )
354 struct berval *out = ber_bvdup( val );
356 if( out->bv_len != 0 ) {
360 ber_len_t uidlen = 0;
362 if( out->bv_val[out->bv_len-1] == '\'' ) {
363 /* assume presence of optional UID */
364 uid = strrchr( out->bv_val, '#' );
368 return LDAP_INVALID_SYNTAX;
371 uidlen = out->bv_len - (out->bv_val - uid);
372 /* temporarily trim the UID */
376 #ifdef USE_DN_NORMALIZE
377 dn = dn_normalize( out->bv_val );
379 dn = dn_validate( out->bv_val );
384 return LDAP_INVALID_SYNTAX;
390 /* restore the separator */
393 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
397 out->bv_len = dnlen + uidlen;
409 /* any value allowed */
418 /* any value allowed */
429 /* very unforgiving validation, requires no normalization
430 * before simplistic matching
432 if( in->bv_len < 3 ) {
433 return LDAP_INVALID_SYNTAX;
435 if( in->bv_val[0] != 'B' ||
436 in->bv_val[1] != '\'' ||
437 in->bv_val[in->bv_len-1] != '\'' )
439 return LDAP_INVALID_SYNTAX;
442 for( i=in->bv_len-2; i>1; i-- ) {
443 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
444 return LDAP_INVALID_SYNTAX;
452 * Handling boolean syntax and matching is quite rigid.
453 * A more flexible approach would be to allow a variety
454 * of strings to be normalized and prettied into TRUE
462 /* very unforgiving validation, requires no normalization
463 * before simplistic matching
466 if( in->bv_len == 4 ) {
467 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
470 } else if( in->bv_len == 5 ) {
471 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
476 return LDAP_INVALID_SYNTAX;
485 struct berval *value,
486 void *assertedValue )
488 /* simplistic matching allowed by rigid validation */
489 struct berval *asserted = (struct berval *) assertedValue;
490 *matchp = value->bv_len != asserted->bv_len;
497 struct berval *right,
498 struct berval *left )
502 ldap_unicode_t ru, lu;
503 ldap_unicode_t ruu, luu;
506 r < right->bv_len && l < left->bv_len;
510 * XXYYZ: we convert to ucs4 even though -llunicode
511 * expects ucs2 in an unsigned long
513 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
514 if( ru == LDAP_UCS4_INVALID ) {
518 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
519 if( lu == LDAP_UCS4_INVALID ) {
523 ruu = uctoupper( ru );
524 luu = uctoupper( lu );
528 } else if( luu > ruu ) {
532 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
533 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
536 if( r < right->bv_len ) {
541 if( l < left->bv_len ) {
549 /* case insensitive UTF8 strncmp with offset for second string */
552 struct berval *right,
560 ldap_unicode_t ru, lu;
561 ldap_unicode_t ruu, luu;
563 rslen = len < right->bv_len ? len : right->bv_len;
564 lslen = len + offset < left->bv_len ? len : left->bv_len;
566 for( r = 0, l = offset;
567 r < rslen && l < lslen;
571 * XXYYZ: we convert to ucs4 even though -llunicode
572 * expects ucs2 in an unsigned long
574 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
575 if( ru == LDAP_UCS4_INVALID ) {
579 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
580 if( lu == LDAP_UCS4_INVALID ) {
584 ruu = uctoupper( ru );
585 luu = uctoupper( lu );
589 } else if( luu > ruu ) {
593 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
594 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
610 static char *UTF8casechr( const char *str, const char *c )
612 char *p, *lower, *upper;
613 ldap_ucs4_t tch, ch = ldap_utf8_to_ucs4(c);
615 tch = uctolower ( ch );
616 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
617 if( ldap_utf8_to_ucs4( p ) == tch ) {
621 lower = *p != '\0' ? p : NULL;
623 tch = uctoupper ( ch );
624 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
625 if( ldap_utf8_to_ucs4( p ) == tch ) {
629 upper = *p != '\0' ? p : NULL;
631 if( lower && upper ) {
632 return lower < upper ? lower : upper;
633 } else if ( lower ) {
648 unsigned char *u = in->bv_val;
650 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
652 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
653 /* get the length indicated by the first byte */
654 len = LDAP_UTF8_CHARLEN( u );
656 /* should not be zero */
657 if( len == 0 ) return LDAP_INVALID_SYNTAX;
659 /* make sure len corresponds with the offset
660 to the next character */
661 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
664 if( count != 0 ) return LDAP_INVALID_SYNTAX;
673 struct berval **normalized )
675 struct berval *newval;
678 newval = ch_malloc( sizeof( struct berval ) );
682 /* Ignore initial whitespace */
683 while ( ldap_utf8_isspace( p ) ) {
689 return LDAP_INVALID_SYNTAX;
692 newval->bv_val = ch_strdup( p );
693 p = q = newval->bv_val;
699 if ( ldap_utf8_isspace( p ) ) {
700 len = LDAP_UTF8_COPY(q,p);
705 /* Ignore the extra whitespace */
706 while ( ldap_utf8_isspace( p ) ) {
710 len = LDAP_UTF8_COPY(q,p);
717 assert( *newval->bv_val );
718 assert( newval->bv_val < p );
721 /* cannot start with a space */
722 assert( !ldap_utf8_isspace(newval->bv_val) );
725 * If the string ended in space, backup the pointer one
726 * position. One is enough because the above loop collapsed
727 * all whitespace to a single space.
734 /* cannot end with a space */
735 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
740 newval->bv_len = q - newval->bv_val;
741 *normalized = newval;
746 #if defined(SLAPD_APPROX_MULTISTRING)
748 #if defined(SLAPD_APPROX_INITIALS)
749 #define SLAPD_APPROX_DELIMITER "._ "
750 #define SLAPD_APPROX_WORDLEN 2
752 #define SLAPD_APPROX_DELIMITER " "
753 #define SLAPD_APPROX_WORDLEN 1
762 struct berval *value,
763 void *assertedValue )
765 char *val, *assertv, **values, **words, *c;
766 int i, count, len, nextchunk=0, nextavail=0;
769 /* Isolate how many words there are */
770 val = ch_strdup( value->bv_val );
771 for( c=val,count=1; *c; c++ ) {
772 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
773 if ( c == NULL ) break;
778 /* Get a phonetic copy of each word */
779 words = (char **)ch_malloc( count * sizeof(char *) );
780 values = (char **)ch_malloc( count * sizeof(char *) );
781 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
783 values[i] = phonetic(c);
787 /* Work through the asserted value's words, to see if at least some
788 of the words are there, in the same order. */
789 assertv = ch_strdup( ((struct berval *)assertedValue)->bv_val );
791 while ( nextchunk < ((struct berval *)assertedValue)->bv_len ) {
792 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
797 #if defined(SLAPD_APPROX_INITIALS)
798 else if( len == 1 ) {
799 /* Single letter words need to at least match one word's initial */
800 for( i=nextavail; i<count; i++ )
801 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
808 /* Isolate the next word in the asserted value and phonetic it */
809 assertv[nextchunk+len] = '\0';
810 val = phonetic( assertv + nextchunk );
812 /* See if this phonetic chunk is in the remaining words of *value */
813 for( i=nextavail; i<count; i++ ){
814 if( !strcmp( val, values[i] ) ){
821 /* This chunk in the asserted value was NOT within the *value. */
827 /* Go on to the next word in the asserted value */
831 /* If some of the words were seen, call it a match */
832 if( nextavail > 0 ) {
841 for( i=0; i<count; i++ ) {
842 ch_free( values[i] );
858 struct berval *prefix,
859 struct berval **values,
860 struct berval ***keysp )
863 int i,j, len, wordcount, keycount=0;
864 struct berval **newkeys, **keys=NULL;
867 for( j=0; values[j] != NULL; j++ ) {
869 /* Isolate how many words there are. There will be a key for each */
870 val = ch_strdup( values[j]->bv_val );
871 for( wordcount=0,c=val; *c; c++) {
872 len = strcspn(c, SLAPD_APPROX_DELIMITER);
873 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
875 if (*c == '\0') break;
879 /* Allocate/increase storage to account for new keys */
880 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
881 * sizeof(struct berval *) );
882 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
883 if( keys ) ch_free( keys );
886 /* Get a phonetic copy of each word */
887 for( c=val,i=0; i<wordcount; c+=len+1 ) {
889 if( len < SLAPD_APPROX_WORDLEN ) continue;
890 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
891 keys[keycount]->bv_val = phonetic( c );
892 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
899 keys[keycount] = NULL;
912 struct berval *prefix,
914 struct berval ***keysp )
918 struct berval **keys;
921 /* Isolate how many words there are. There will be a key for each */
922 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
923 for( count=0,c=val; *c; c++) {
924 len = strcspn(c, SLAPD_APPROX_DELIMITER);
925 if( len >= SLAPD_APPROX_WORDLEN ) count++;
927 if (*c == '\0') break;
931 /* Allocate storage for new keys */
932 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
934 /* Get a phonetic copy of each word */
935 for( c=val,i=0; i<count; c+=len+1 ) {
937 if( len < SLAPD_APPROX_WORDLEN ) continue;
938 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
939 keys[i]->bv_val = phonetic( c );
940 keys[i]->bv_len = strlen( keys[i]->bv_val );
954 /* No other form of Approximate Matching is defined */
962 struct berval *value,
963 void *assertedValue )
965 char *vapprox, *avapprox;
967 vapprox = phonetic( value->bv_val );
968 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
970 *matchp = strcmp( vapprox, avapprox );
984 struct berval *prefix,
985 struct berval **values,
986 struct berval ***keysp )
989 struct berval **keys;
992 for( i=0; values[i] != NULL; i++ ) {
993 /* just count them */
997 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
999 /* Copy each value and run it through phonetic() */
1000 for( i=0; values[i] != NULL; i++ ) {
1001 keys[i] = ch_malloc( sizeof( struct berval * ) );
1002 keys[i]->bv_val = phonetic( values[i]->bv_val );
1003 keys[i]->bv_len = strlen( keys[i]->bv_val );
1008 return LDAP_SUCCESS;
1018 struct berval *prefix,
1020 struct berval ***keysp )
1022 struct berval **keys;
1025 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1027 /* Copy the value and run it through phonetic() */
1028 keys[0] = ch_malloc( sizeof( struct berval * ) );
1029 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
1030 keys[0]->bv_len = strlen( keys[0]->bv_val );
1034 return LDAP_SUCCESS;
1045 struct berval *value,
1046 void *assertedValue )
1048 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1051 match = strncmp( value->bv_val,
1052 ((struct berval *) assertedValue)->bv_val,
1057 return LDAP_SUCCESS;
1061 caseExactSubstringsMatch(
1066 struct berval *value,
1067 void *assertedValue )
1070 SubstringsAssertion *sub = assertedValue;
1071 struct berval left = *value;
1075 /* Add up asserted input length */
1076 if( sub->sa_initial ) {
1077 inlen += sub->sa_initial->bv_len;
1080 for(i=0; sub->sa_any[i] != NULL; i++) {
1081 inlen += sub->sa_any[i]->bv_len;
1084 if( sub->sa_final ) {
1085 inlen += sub->sa_final->bv_len;
1088 if( sub->sa_initial ) {
1089 if( inlen > left.bv_len ) {
1094 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1095 sub->sa_initial->bv_len );
1101 left.bv_val += sub->sa_initial->bv_len;
1102 left.bv_len -= sub->sa_initial->bv_len;
1103 inlen -= sub->sa_initial->bv_len;
1106 if( sub->sa_final ) {
1107 if( inlen > left.bv_len ) {
1112 match = strncmp( sub->sa_final->bv_val,
1113 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1114 sub->sa_final->bv_len );
1120 left.bv_len -= sub->sa_final->bv_len;
1121 inlen -= sub->sa_final->bv_len;
1125 for(i=0; sub->sa_any[i]; i++) {
1130 if( inlen > left.bv_len ) {
1131 /* not enough length */
1136 if( sub->sa_any[i]->bv_len == 0 ) {
1140 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1147 idx = p - left.bv_val;
1148 assert( idx < left.bv_len );
1150 if( idx >= left.bv_len ) {
1151 /* this shouldn't happen */
1158 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1159 /* not enough left */
1164 match = strncmp( left.bv_val,
1165 sub->sa_any[i]->bv_val,
1166 sub->sa_any[i]->bv_len );
1174 left.bv_val += sub->sa_any[i]->bv_len;
1175 left.bv_len -= sub->sa_any[i]->bv_len;
1176 inlen -= sub->sa_any[i]->bv_len;
1182 return LDAP_SUCCESS;
1185 /* Index generation function */
1186 int caseExactIndexer(
1191 struct berval *prefix,
1192 struct berval **values,
1193 struct berval ***keysp )
1197 struct berval **keys;
1198 HASH_CONTEXT HASHcontext;
1199 unsigned char HASHdigest[HASH_BYTES];
1200 struct berval digest;
1201 digest.bv_val = HASHdigest;
1202 digest.bv_len = sizeof(HASHdigest);
1204 /* we should have at least one value at this point */
1205 assert( values != NULL && values[0] != NULL );
1207 for( i=0; values[i] != NULL; i++ ) {
1208 /* just count them */
1211 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1213 slen = strlen( syntax->ssyn_oid );
1214 mlen = strlen( mr->smr_oid );
1216 for( i=0; values[i] != NULL; i++ ) {
1217 struct berval *value = values[i];
1219 HASH_Init( &HASHcontext );
1220 if( prefix != NULL && prefix->bv_len > 0 ) {
1221 HASH_Update( &HASHcontext,
1222 prefix->bv_val, prefix->bv_len );
1224 HASH_Update( &HASHcontext,
1225 syntax->ssyn_oid, slen );
1226 HASH_Update( &HASHcontext,
1227 mr->smr_oid, mlen );
1228 HASH_Update( &HASHcontext,
1229 value->bv_val, value->bv_len );
1230 HASH_Final( HASHdigest, &HASHcontext );
1232 keys[i] = ber_bvdup( &digest );
1237 return LDAP_SUCCESS;
1240 /* Index generation function */
1241 int caseExactFilter(
1246 struct berval *prefix,
1248 struct berval ***keysp )
1251 struct berval **keys;
1252 HASH_CONTEXT HASHcontext;
1253 unsigned char HASHdigest[HASH_BYTES];
1254 struct berval *value;
1255 struct berval digest;
1256 digest.bv_val = HASHdigest;
1257 digest.bv_len = sizeof(HASHdigest);
1259 slen = strlen( syntax->ssyn_oid );
1260 mlen = strlen( mr->smr_oid );
1262 value = (struct berval *) assertValue;
1264 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1266 HASH_Init( &HASHcontext );
1267 if( prefix != NULL && prefix->bv_len > 0 ) {
1268 HASH_Update( &HASHcontext,
1269 prefix->bv_val, prefix->bv_len );
1271 HASH_Update( &HASHcontext,
1272 syntax->ssyn_oid, slen );
1273 HASH_Update( &HASHcontext,
1274 mr->smr_oid, mlen );
1275 HASH_Update( &HASHcontext,
1276 value->bv_val, value->bv_len );
1277 HASH_Final( HASHdigest, &HASHcontext );
1279 keys[0] = ber_bvdup( &digest );
1283 return LDAP_SUCCESS;
1286 /* Substrings Index generation function */
1287 int caseExactSubstringsIndexer(
1292 struct berval *prefix,
1293 struct berval **values,
1294 struct berval ***keysp )
1298 struct berval **keys;
1299 HASH_CONTEXT HASHcontext;
1300 unsigned char HASHdigest[HASH_BYTES];
1301 struct berval digest;
1302 digest.bv_val = HASHdigest;
1303 digest.bv_len = sizeof(HASHdigest);
1305 /* we should have at least one value at this point */
1306 assert( values != NULL && values[0] != NULL );
1309 for( i=0; values[i] != NULL; i++ ) {
1310 /* count number of indices to generate */
1311 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1315 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1316 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1317 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1318 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1320 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1324 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1325 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1326 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1330 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1331 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1332 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1333 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1335 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1341 /* no keys to generate */
1343 return LDAP_SUCCESS;
1346 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1348 slen = strlen( syntax->ssyn_oid );
1349 mlen = strlen( mr->smr_oid );
1352 for( i=0; values[i] != NULL; i++ ) {
1354 struct berval *value;
1357 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1359 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1360 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1362 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1363 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1365 for( j=0; j<max; j++ ) {
1366 HASH_Init( &HASHcontext );
1367 if( prefix != NULL && prefix->bv_len > 0 ) {
1368 HASH_Update( &HASHcontext,
1369 prefix->bv_val, prefix->bv_len );
1372 HASH_Update( &HASHcontext,
1373 &pre, sizeof( pre ) );
1374 HASH_Update( &HASHcontext,
1375 syntax->ssyn_oid, slen );
1376 HASH_Update( &HASHcontext,
1377 mr->smr_oid, mlen );
1378 HASH_Update( &HASHcontext,
1380 SLAP_INDEX_SUBSTR_MAXLEN );
1381 HASH_Final( HASHdigest, &HASHcontext );
1383 keys[nkeys++] = ber_bvdup( &digest );
1387 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1388 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1390 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1393 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1394 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1395 HASH_Init( &HASHcontext );
1396 if( prefix != NULL && prefix->bv_len > 0 ) {
1397 HASH_Update( &HASHcontext,
1398 prefix->bv_val, prefix->bv_len );
1400 HASH_Update( &HASHcontext,
1401 &pre, sizeof( pre ) );
1402 HASH_Update( &HASHcontext,
1403 syntax->ssyn_oid, slen );
1404 HASH_Update( &HASHcontext,
1405 mr->smr_oid, mlen );
1406 HASH_Update( &HASHcontext,
1408 HASH_Final( HASHdigest, &HASHcontext );
1410 keys[nkeys++] = ber_bvdup( &digest );
1413 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1414 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1415 HASH_Init( &HASHcontext );
1416 if( prefix != NULL && prefix->bv_len > 0 ) {
1417 HASH_Update( &HASHcontext,
1418 prefix->bv_val, prefix->bv_len );
1420 HASH_Update( &HASHcontext,
1421 &pre, sizeof( pre ) );
1422 HASH_Update( &HASHcontext,
1423 syntax->ssyn_oid, slen );
1424 HASH_Update( &HASHcontext,
1425 mr->smr_oid, mlen );
1426 HASH_Update( &HASHcontext,
1427 &value->bv_val[value->bv_len-j], j );
1428 HASH_Final( HASHdigest, &HASHcontext );
1430 keys[nkeys++] = ber_bvdup( &digest );
1444 return LDAP_SUCCESS;
1447 int caseExactSubstringsFilter(
1452 struct berval *prefix,
1454 struct berval ***keysp )
1456 SubstringsAssertion *sa = assertValue;
1458 ber_len_t nkeys = 0;
1459 size_t slen, mlen, klen;
1460 struct berval **keys;
1461 HASH_CONTEXT HASHcontext;
1462 unsigned char HASHdigest[HASH_BYTES];
1463 struct berval *value;
1464 struct berval digest;
1466 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1467 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1472 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1474 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1475 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1476 /* don't bother accounting for stepping */
1477 nkeys += sa->sa_any[i]->bv_len -
1478 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1483 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1484 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1491 return LDAP_SUCCESS;
1494 digest.bv_val = HASHdigest;
1495 digest.bv_len = sizeof(HASHdigest);
1497 slen = strlen( syntax->ssyn_oid );
1498 mlen = strlen( mr->smr_oid );
1500 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1503 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1504 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1506 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1507 value = sa->sa_initial;
1509 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1510 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1512 HASH_Init( &HASHcontext );
1513 if( prefix != NULL && prefix->bv_len > 0 ) {
1514 HASH_Update( &HASHcontext,
1515 prefix->bv_val, prefix->bv_len );
1517 HASH_Update( &HASHcontext,
1518 &pre, sizeof( pre ) );
1519 HASH_Update( &HASHcontext,
1520 syntax->ssyn_oid, slen );
1521 HASH_Update( &HASHcontext,
1522 mr->smr_oid, mlen );
1523 HASH_Update( &HASHcontext,
1524 value->bv_val, klen );
1525 HASH_Final( HASHdigest, &HASHcontext );
1527 keys[nkeys++] = ber_bvdup( &digest );
1530 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1532 pre = SLAP_INDEX_SUBSTR_PREFIX;
1533 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1535 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1536 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1540 value = sa->sa_any[i];
1543 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1544 j += SLAP_INDEX_SUBSTR_STEP )
1546 HASH_Init( &HASHcontext );
1547 if( prefix != NULL && prefix->bv_len > 0 ) {
1548 HASH_Update( &HASHcontext,
1549 prefix->bv_val, prefix->bv_len );
1551 HASH_Update( &HASHcontext,
1552 &pre, sizeof( pre ) );
1553 HASH_Update( &HASHcontext,
1554 syntax->ssyn_oid, slen );
1555 HASH_Update( &HASHcontext,
1556 mr->smr_oid, mlen );
1557 HASH_Update( &HASHcontext,
1558 &value->bv_val[j], klen );
1559 HASH_Final( HASHdigest, &HASHcontext );
1561 keys[nkeys++] = ber_bvdup( &digest );
1566 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1567 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1569 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1570 value = sa->sa_final;
1572 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1573 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1575 HASH_Init( &HASHcontext );
1576 if( prefix != NULL && prefix->bv_len > 0 ) {
1577 HASH_Update( &HASHcontext,
1578 prefix->bv_val, prefix->bv_len );
1580 HASH_Update( &HASHcontext,
1581 &pre, sizeof( pre ) );
1582 HASH_Update( &HASHcontext,
1583 syntax->ssyn_oid, slen );
1584 HASH_Update( &HASHcontext,
1585 mr->smr_oid, mlen );
1586 HASH_Update( &HASHcontext,
1587 &value->bv_val[value->bv_len-klen], klen );
1588 HASH_Final( HASHdigest, &HASHcontext );
1590 keys[nkeys++] = ber_bvdup( &digest );
1601 return LDAP_SUCCESS;
1610 struct berval *value,
1611 void *assertedValue )
1614 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1616 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1619 match = strncasecmp( value->bv_val,
1620 ((struct berval *) assertedValue)->bv_val,
1626 return LDAP_SUCCESS;
1630 caseIgnoreSubstringsMatch(
1635 struct berval *value,
1636 void *assertedValue )
1639 SubstringsAssertion *sub = assertedValue;
1640 struct berval left = *value;
1644 /* Add up asserted input length */
1645 if( sub->sa_initial ) {
1646 inlen += sub->sa_initial->bv_len;
1649 for(i=0; sub->sa_any[i] != NULL; i++) {
1650 inlen += sub->sa_any[i]->bv_len;
1653 if( sub->sa_final ) {
1654 inlen += sub->sa_final->bv_len;
1657 if( sub->sa_initial ) {
1658 if( inlen > left.bv_len ) {
1664 match = UTF8oncasecmp( sub->sa_initial, &left,
1665 sub->sa_initial->bv_len, 0 );
1667 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1668 sub->sa_initial->bv_len );
1675 left.bv_val += sub->sa_initial->bv_len;
1676 left.bv_len -= sub->sa_initial->bv_len;
1677 inlen -= sub->sa_initial->bv_len;
1680 if( sub->sa_final ) {
1681 if( inlen > left.bv_len ) {
1687 match = UTF8oncasecmp( sub->sa_final, &left,
1688 sub->sa_final->bv_len,
1689 left.bv_len - sub->sa_final->bv_len );
1691 match = strncasecmp( sub->sa_final->bv_val,
1692 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1693 sub->sa_final->bv_len );
1700 left.bv_len -= sub->sa_final->bv_len;
1701 inlen -= sub->sa_final->bv_len;
1705 for(i=0; sub->sa_any[i]; i++) {
1710 if( inlen > left.bv_len ) {
1711 /* not enough length */
1716 if( sub->sa_any[i]->bv_len == 0 ) {
1721 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1723 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1731 idx = p - left.bv_val;
1732 assert( idx < left.bv_len );
1734 if( idx >= left.bv_len ) {
1735 /* this shouldn't happen */
1742 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1743 /* not enough left */
1749 match = UTF8oncasecmp( &left, sub->sa_any[i],
1750 sub->sa_any[i]->bv_len, 0 );
1753 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1759 match = strncasecmp( left.bv_val,
1760 sub->sa_any[i]->bv_val,
1761 sub->sa_any[i]->bv_len );
1771 left.bv_val += sub->sa_any[i]->bv_len;
1772 left.bv_len -= sub->sa_any[i]->bv_len;
1773 inlen -= sub->sa_any[i]->bv_len;
1779 return LDAP_SUCCESS;
1782 /* Index generation function */
1783 int caseIgnoreIndexer(
1788 struct berval *prefix,
1789 struct berval **values,
1790 struct berval ***keysp )
1794 struct berval **keys;
1795 HASH_CONTEXT HASHcontext;
1796 unsigned char HASHdigest[HASH_BYTES];
1797 struct berval digest;
1798 digest.bv_val = HASHdigest;
1799 digest.bv_len = sizeof(HASHdigest);
1801 /* we should have at least one value at this point */
1802 assert( values != NULL && values[0] != NULL );
1804 for( i=0; values[i] != NULL; i++ ) {
1805 /* just count them */
1808 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1810 slen = strlen( syntax->ssyn_oid );
1811 mlen = strlen( mr->smr_oid );
1813 for( i=0; values[i] != NULL; i++ ) {
1814 struct berval *value = ber_bvdup( values[i] );
1815 ldap_pvt_str2upper( value->bv_val );
1817 HASH_Init( &HASHcontext );
1818 if( prefix != NULL && prefix->bv_len > 0 ) {
1819 HASH_Update( &HASHcontext,
1820 prefix->bv_val, prefix->bv_len );
1822 HASH_Update( &HASHcontext,
1823 syntax->ssyn_oid, slen );
1824 HASH_Update( &HASHcontext,
1825 mr->smr_oid, mlen );
1826 HASH_Update( &HASHcontext,
1827 value->bv_val, value->bv_len );
1828 HASH_Final( HASHdigest, &HASHcontext );
1830 ber_bvfree( value );
1832 keys[i] = ber_bvdup( &digest );
1837 return LDAP_SUCCESS;
1840 /* Index generation function */
1841 int caseIgnoreFilter(
1846 struct berval *prefix,
1848 struct berval ***keysp )
1851 struct berval **keys;
1852 HASH_CONTEXT HASHcontext;
1853 unsigned char HASHdigest[HASH_BYTES];
1854 struct berval *value;
1855 struct berval digest;
1856 digest.bv_val = HASHdigest;
1857 digest.bv_len = sizeof(HASHdigest);
1859 slen = strlen( syntax->ssyn_oid );
1860 mlen = strlen( mr->smr_oid );
1862 value = ber_bvdup( (struct berval *) assertValue );
1863 ldap_pvt_str2upper( value->bv_val );
1865 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1867 HASH_Init( &HASHcontext );
1868 if( prefix != NULL && prefix->bv_len > 0 ) {
1869 HASH_Update( &HASHcontext,
1870 prefix->bv_val, prefix->bv_len );
1872 HASH_Update( &HASHcontext,
1873 syntax->ssyn_oid, slen );
1874 HASH_Update( &HASHcontext,
1875 mr->smr_oid, mlen );
1876 HASH_Update( &HASHcontext,
1877 value->bv_val, value->bv_len );
1878 HASH_Final( HASHdigest, &HASHcontext );
1880 keys[0] = ber_bvdup( &digest );
1883 ber_bvfree( value );
1887 return LDAP_SUCCESS;
1890 /* Substrings Index generation function */
1891 int caseIgnoreSubstringsIndexer(
1896 struct berval *prefix,
1897 struct berval **values,
1898 struct berval ***keysp )
1902 struct berval **keys;
1903 HASH_CONTEXT HASHcontext;
1904 unsigned char HASHdigest[HASH_BYTES];
1905 struct berval digest;
1906 digest.bv_val = HASHdigest;
1907 digest.bv_len = sizeof(HASHdigest);
1909 /* we should have at least one value at this point */
1910 assert( values != NULL && values[0] != NULL );
1913 for( i=0; values[i] != NULL; i++ ) {
1914 /* count number of indices to generate */
1915 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1919 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1920 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1921 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1922 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1924 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1928 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1929 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1930 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1934 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1935 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1936 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1937 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1939 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1945 /* no keys to generate */
1947 return LDAP_SUCCESS;
1950 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1952 slen = strlen( syntax->ssyn_oid );
1953 mlen = strlen( mr->smr_oid );
1956 for( i=0; values[i] != NULL; i++ ) {
1958 struct berval *value;
1960 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1962 value = ber_bvdup( values[i] );
1963 ldap_pvt_str2upper( value->bv_val );
1965 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1966 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1968 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1969 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1971 for( j=0; j<max; j++ ) {
1972 HASH_Init( &HASHcontext );
1973 if( prefix != NULL && prefix->bv_len > 0 ) {
1974 HASH_Update( &HASHcontext,
1975 prefix->bv_val, prefix->bv_len );
1978 HASH_Update( &HASHcontext,
1979 &pre, sizeof( pre ) );
1980 HASH_Update( &HASHcontext,
1981 syntax->ssyn_oid, slen );
1982 HASH_Update( &HASHcontext,
1983 mr->smr_oid, mlen );
1984 HASH_Update( &HASHcontext,
1986 SLAP_INDEX_SUBSTR_MAXLEN );
1987 HASH_Final( HASHdigest, &HASHcontext );
1989 keys[nkeys++] = ber_bvdup( &digest );
1993 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1994 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1996 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1999 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2000 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2001 HASH_Init( &HASHcontext );
2002 if( prefix != NULL && prefix->bv_len > 0 ) {
2003 HASH_Update( &HASHcontext,
2004 prefix->bv_val, prefix->bv_len );
2006 HASH_Update( &HASHcontext,
2007 &pre, sizeof( pre ) );
2008 HASH_Update( &HASHcontext,
2009 syntax->ssyn_oid, slen );
2010 HASH_Update( &HASHcontext,
2011 mr->smr_oid, mlen );
2012 HASH_Update( &HASHcontext,
2014 HASH_Final( HASHdigest, &HASHcontext );
2016 keys[nkeys++] = ber_bvdup( &digest );
2019 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2020 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2021 HASH_Init( &HASHcontext );
2022 if( prefix != NULL && prefix->bv_len > 0 ) {
2023 HASH_Update( &HASHcontext,
2024 prefix->bv_val, prefix->bv_len );
2026 HASH_Update( &HASHcontext,
2027 &pre, sizeof( pre ) );
2028 HASH_Update( &HASHcontext,
2029 syntax->ssyn_oid, slen );
2030 HASH_Update( &HASHcontext,
2031 mr->smr_oid, mlen );
2032 HASH_Update( &HASHcontext,
2033 &value->bv_val[value->bv_len-j], j );
2034 HASH_Final( HASHdigest, &HASHcontext );
2036 keys[nkeys++] = ber_bvdup( &digest );
2041 ber_bvfree( value );
2052 return LDAP_SUCCESS;
2055 int caseIgnoreSubstringsFilter(
2060 struct berval *prefix,
2062 struct berval ***keysp )
2064 SubstringsAssertion *sa = assertValue;
2066 ber_len_t nkeys = 0;
2067 size_t slen, mlen, klen;
2068 struct berval **keys;
2069 HASH_CONTEXT HASHcontext;
2070 unsigned char HASHdigest[HASH_BYTES];
2071 struct berval *value;
2072 struct berval digest;
2074 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2075 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2080 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2082 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2083 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2084 /* don't bother accounting for stepping */
2085 nkeys += sa->sa_any[i]->bv_len -
2086 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2091 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2092 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2099 return LDAP_SUCCESS;
2102 digest.bv_val = HASHdigest;
2103 digest.bv_len = sizeof(HASHdigest);
2105 slen = strlen( syntax->ssyn_oid );
2106 mlen = strlen( mr->smr_oid );
2108 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2111 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2112 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2114 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2115 value = ber_bvdup( sa->sa_initial );
2116 ldap_pvt_str2upper( value->bv_val );
2118 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2119 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2121 HASH_Init( &HASHcontext );
2122 if( prefix != NULL && prefix->bv_len > 0 ) {
2123 HASH_Update( &HASHcontext,
2124 prefix->bv_val, prefix->bv_len );
2126 HASH_Update( &HASHcontext,
2127 &pre, sizeof( pre ) );
2128 HASH_Update( &HASHcontext,
2129 syntax->ssyn_oid, slen );
2130 HASH_Update( &HASHcontext,
2131 mr->smr_oid, mlen );
2132 HASH_Update( &HASHcontext,
2133 value->bv_val, klen );
2134 HASH_Final( HASHdigest, &HASHcontext );
2136 ber_bvfree( value );
2137 keys[nkeys++] = ber_bvdup( &digest );
2140 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2142 pre = SLAP_INDEX_SUBSTR_PREFIX;
2143 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2145 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2146 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2150 value = ber_bvdup( sa->sa_any[i] );
2151 ldap_pvt_str2upper( value->bv_val );
2154 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2155 j += SLAP_INDEX_SUBSTR_STEP )
2157 HASH_Init( &HASHcontext );
2158 if( prefix != NULL && prefix->bv_len > 0 ) {
2159 HASH_Update( &HASHcontext,
2160 prefix->bv_val, prefix->bv_len );
2162 HASH_Update( &HASHcontext,
2163 &pre, sizeof( pre ) );
2164 HASH_Update( &HASHcontext,
2165 syntax->ssyn_oid, slen );
2166 HASH_Update( &HASHcontext,
2167 mr->smr_oid, mlen );
2168 HASH_Update( &HASHcontext,
2169 &value->bv_val[j], klen );
2170 HASH_Final( HASHdigest, &HASHcontext );
2172 keys[nkeys++] = ber_bvdup( &digest );
2175 ber_bvfree( value );
2179 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2180 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2182 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2183 value = ber_bvdup( sa->sa_final );
2184 ldap_pvt_str2upper( value->bv_val );
2186 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2187 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2189 HASH_Init( &HASHcontext );
2190 if( prefix != NULL && prefix->bv_len > 0 ) {
2191 HASH_Update( &HASHcontext,
2192 prefix->bv_val, prefix->bv_len );
2194 HASH_Update( &HASHcontext,
2195 &pre, sizeof( pre ) );
2196 HASH_Update( &HASHcontext,
2197 syntax->ssyn_oid, slen );
2198 HASH_Update( &HASHcontext,
2199 mr->smr_oid, mlen );
2200 HASH_Update( &HASHcontext,
2201 &value->bv_val[value->bv_len-klen], klen );
2202 HASH_Final( HASHdigest, &HASHcontext );
2204 ber_bvfree( value );
2205 keys[nkeys++] = ber_bvdup( &digest );
2216 return LDAP_SUCCESS;
2222 struct berval *val )
2226 if( val->bv_len == 0 ) {
2227 /* disallow empty strings */
2228 return LDAP_INVALID_SYNTAX;
2231 if( OID_LEADCHAR(val->bv_val[0]) ) {
2233 for(i=1; i < val->bv_len; i++) {
2234 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2235 if( dot++ ) return 1;
2236 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2239 return LDAP_INVALID_SYNTAX;
2243 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2245 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2246 for(i=1; i < val->bv_len; i++) {
2247 if( !DESC_CHAR(val->bv_val[i] ) ) {
2248 return LDAP_INVALID_SYNTAX;
2252 return LDAP_SUCCESS;
2255 return LDAP_INVALID_SYNTAX;
2261 struct berval *val )
2265 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2267 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2268 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2269 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2270 return LDAP_INVALID_SYNTAX;
2273 for(i=1; i < val->bv_len; i++) {
2274 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2277 return LDAP_SUCCESS;
2284 struct berval **normalized )
2287 struct berval *newval;
2293 negative = ( *p == '-' );
2294 if( *p == '-' || *p == '+' ) p++;
2296 /* Ignore leading zeros */
2297 while ( *p == '0' ) p++;
2299 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2302 newval->bv_val = ch_strdup("0");
2307 newval->bv_val = ch_malloc( val->bv_len + 1 );
2311 newval->bv_val[newval->bv_len++] = '-';
2314 for( ; *p != '\0'; p++ ) {
2315 newval->bv_val[newval->bv_len++] = *p;
2319 *normalized = newval;
2320 return LDAP_SUCCESS;
2324 countryStringValidate(
2326 struct berval *val )
2330 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2332 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2333 return LDAP_INVALID_SYNTAX;
2335 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2336 return LDAP_INVALID_SYNTAX;
2339 return LDAP_SUCCESS;
2343 printableStringValidate(
2345 struct berval *val )
2349 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2351 for(i=0; i < val->bv_len; i++) {
2352 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2353 return LDAP_INVALID_SYNTAX;
2357 return LDAP_SUCCESS;
2361 printablesStringValidate(
2363 struct berval *val )
2367 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2369 for(i=0; i < val->bv_len; i++) {
2370 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2371 return LDAP_INVALID_SYNTAX;
2375 return LDAP_SUCCESS;
2381 struct berval *val )
2385 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2387 for(i=0; i < val->bv_len; i++) {
2388 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2391 return LDAP_SUCCESS;
2398 struct berval **normalized )
2400 struct berval *newval;
2403 newval = ch_malloc( sizeof( struct berval ) );
2407 /* Ignore initial whitespace */
2408 while ( ASCII_SPACE( *p ) ) {
2414 return LDAP_INVALID_SYNTAX;
2417 newval->bv_val = ch_strdup( p );
2418 p = q = newval->bv_val;
2421 if ( ASCII_SPACE( *p ) ) {
2424 /* Ignore the extra whitespace */
2425 while ( ASCII_SPACE( *p ) ) {
2433 assert( *newval->bv_val );
2434 assert( newval->bv_val < p );
2437 /* cannot start with a space */
2438 assert( !ASCII_SPACE(*newval->bv_val) );
2441 * If the string ended in space, backup the pointer one
2442 * position. One is enough because the above loop collapsed
2443 * all whitespace to a single space.
2446 if ( ASCII_SPACE( q[-1] ) ) {
2450 /* cannot end with a space */
2451 assert( !ASCII_SPACE( q[-1] ) );
2453 /* null terminate */
2456 newval->bv_len = q - newval->bv_val;
2457 *normalized = newval;
2459 return LDAP_SUCCESS;
2468 struct berval *value,
2469 void *assertedValue )
2471 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2474 match = strncmp( value->bv_val,
2475 ((struct berval *) assertedValue)->bv_val,
2480 return LDAP_SUCCESS;
2484 caseExactIA5SubstringsMatch(
2489 struct berval *value,
2490 void *assertedValue )
2493 SubstringsAssertion *sub = assertedValue;
2494 struct berval left = *value;
2498 /* Add up asserted input length */
2499 if( sub->sa_initial ) {
2500 inlen += sub->sa_initial->bv_len;
2503 for(i=0; sub->sa_any[i] != NULL; i++) {
2504 inlen += sub->sa_any[i]->bv_len;
2507 if( sub->sa_final ) {
2508 inlen += sub->sa_final->bv_len;
2511 if( sub->sa_initial ) {
2512 if( inlen > left.bv_len ) {
2517 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2518 sub->sa_initial->bv_len );
2524 left.bv_val += sub->sa_initial->bv_len;
2525 left.bv_len -= sub->sa_initial->bv_len;
2526 inlen -= sub->sa_initial->bv_len;
2529 if( sub->sa_final ) {
2530 if( inlen > left.bv_len ) {
2535 match = strncmp( sub->sa_final->bv_val,
2536 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2537 sub->sa_final->bv_len );
2543 left.bv_len -= sub->sa_final->bv_len;
2544 inlen -= sub->sa_final->bv_len;
2548 for(i=0; sub->sa_any[i]; i++) {
2553 if( inlen > left.bv_len ) {
2554 /* not enough length */
2559 if( sub->sa_any[i]->bv_len == 0 ) {
2563 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2570 idx = p - left.bv_val;
2571 assert( idx < left.bv_len );
2573 if( idx >= left.bv_len ) {
2574 /* this shouldn't happen */
2581 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2582 /* not enough left */
2587 match = strncmp( left.bv_val,
2588 sub->sa_any[i]->bv_val,
2589 sub->sa_any[i]->bv_len );
2597 left.bv_val += sub->sa_any[i]->bv_len;
2598 left.bv_len -= sub->sa_any[i]->bv_len;
2599 inlen -= sub->sa_any[i]->bv_len;
2605 return LDAP_SUCCESS;
2608 /* Index generation function */
2609 int caseExactIA5Indexer(
2614 struct berval *prefix,
2615 struct berval **values,
2616 struct berval ***keysp )
2620 struct berval **keys;
2621 HASH_CONTEXT HASHcontext;
2622 unsigned char HASHdigest[HASH_BYTES];
2623 struct berval digest;
2624 digest.bv_val = HASHdigest;
2625 digest.bv_len = sizeof(HASHdigest);
2627 /* we should have at least one value at this point */
2628 assert( values != NULL && values[0] != NULL );
2630 for( i=0; values[i] != NULL; i++ ) {
2631 /* just count them */
2634 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2636 slen = strlen( syntax->ssyn_oid );
2637 mlen = strlen( mr->smr_oid );
2639 for( i=0; values[i] != NULL; i++ ) {
2640 struct berval *value = values[i];
2642 HASH_Init( &HASHcontext );
2643 if( prefix != NULL && prefix->bv_len > 0 ) {
2644 HASH_Update( &HASHcontext,
2645 prefix->bv_val, prefix->bv_len );
2647 HASH_Update( &HASHcontext,
2648 syntax->ssyn_oid, slen );
2649 HASH_Update( &HASHcontext,
2650 mr->smr_oid, mlen );
2651 HASH_Update( &HASHcontext,
2652 value->bv_val, value->bv_len );
2653 HASH_Final( HASHdigest, &HASHcontext );
2655 keys[i] = ber_bvdup( &digest );
2660 return LDAP_SUCCESS;
2663 /* Index generation function */
2664 int caseExactIA5Filter(
2669 struct berval *prefix,
2671 struct berval ***keysp )
2674 struct berval **keys;
2675 HASH_CONTEXT HASHcontext;
2676 unsigned char HASHdigest[HASH_BYTES];
2677 struct berval *value;
2678 struct berval digest;
2679 digest.bv_val = HASHdigest;
2680 digest.bv_len = sizeof(HASHdigest);
2682 slen = strlen( syntax->ssyn_oid );
2683 mlen = strlen( mr->smr_oid );
2685 value = (struct berval *) assertValue;
2687 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2689 HASH_Init( &HASHcontext );
2690 if( prefix != NULL && prefix->bv_len > 0 ) {
2691 HASH_Update( &HASHcontext,
2692 prefix->bv_val, prefix->bv_len );
2694 HASH_Update( &HASHcontext,
2695 syntax->ssyn_oid, slen );
2696 HASH_Update( &HASHcontext,
2697 mr->smr_oid, mlen );
2698 HASH_Update( &HASHcontext,
2699 value->bv_val, value->bv_len );
2700 HASH_Final( HASHdigest, &HASHcontext );
2702 keys[0] = ber_bvdup( &digest );
2706 return LDAP_SUCCESS;
2709 /* Substrings Index generation function */
2710 int caseExactIA5SubstringsIndexer(
2715 struct berval *prefix,
2716 struct berval **values,
2717 struct berval ***keysp )
2721 struct berval **keys;
2722 HASH_CONTEXT HASHcontext;
2723 unsigned char HASHdigest[HASH_BYTES];
2724 struct berval digest;
2725 digest.bv_val = HASHdigest;
2726 digest.bv_len = sizeof(HASHdigest);
2728 /* we should have at least one value at this point */
2729 assert( values != NULL && values[0] != NULL );
2732 for( i=0; values[i] != NULL; i++ ) {
2733 /* count number of indices to generate */
2734 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2738 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2739 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2740 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2741 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2743 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2747 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2748 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2749 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2753 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2754 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2755 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2756 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2758 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2764 /* no keys to generate */
2766 return LDAP_SUCCESS;
2769 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2771 slen = strlen( syntax->ssyn_oid );
2772 mlen = strlen( mr->smr_oid );
2775 for( i=0; values[i] != NULL; i++ ) {
2777 struct berval *value;
2780 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2782 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2783 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2785 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2786 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2788 for( j=0; j<max; j++ ) {
2789 HASH_Init( &HASHcontext );
2790 if( prefix != NULL && prefix->bv_len > 0 ) {
2791 HASH_Update( &HASHcontext,
2792 prefix->bv_val, prefix->bv_len );
2795 HASH_Update( &HASHcontext,
2796 &pre, sizeof( pre ) );
2797 HASH_Update( &HASHcontext,
2798 syntax->ssyn_oid, slen );
2799 HASH_Update( &HASHcontext,
2800 mr->smr_oid, mlen );
2801 HASH_Update( &HASHcontext,
2803 SLAP_INDEX_SUBSTR_MAXLEN );
2804 HASH_Final( HASHdigest, &HASHcontext );
2806 keys[nkeys++] = ber_bvdup( &digest );
2810 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2811 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2813 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2816 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2817 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2818 HASH_Init( &HASHcontext );
2819 if( prefix != NULL && prefix->bv_len > 0 ) {
2820 HASH_Update( &HASHcontext,
2821 prefix->bv_val, prefix->bv_len );
2823 HASH_Update( &HASHcontext,
2824 &pre, sizeof( pre ) );
2825 HASH_Update( &HASHcontext,
2826 syntax->ssyn_oid, slen );
2827 HASH_Update( &HASHcontext,
2828 mr->smr_oid, mlen );
2829 HASH_Update( &HASHcontext,
2831 HASH_Final( HASHdigest, &HASHcontext );
2833 keys[nkeys++] = ber_bvdup( &digest );
2836 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2837 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2838 HASH_Init( &HASHcontext );
2839 if( prefix != NULL && prefix->bv_len > 0 ) {
2840 HASH_Update( &HASHcontext,
2841 prefix->bv_val, prefix->bv_len );
2843 HASH_Update( &HASHcontext,
2844 &pre, sizeof( pre ) );
2845 HASH_Update( &HASHcontext,
2846 syntax->ssyn_oid, slen );
2847 HASH_Update( &HASHcontext,
2848 mr->smr_oid, mlen );
2849 HASH_Update( &HASHcontext,
2850 &value->bv_val[value->bv_len-j], j );
2851 HASH_Final( HASHdigest, &HASHcontext );
2853 keys[nkeys++] = ber_bvdup( &digest );
2867 return LDAP_SUCCESS;
2870 int caseExactIA5SubstringsFilter(
2875 struct berval *prefix,
2877 struct berval ***keysp )
2879 SubstringsAssertion *sa = assertValue;
2881 ber_len_t nkeys = 0;
2882 size_t slen, mlen, klen;
2883 struct berval **keys;
2884 HASH_CONTEXT HASHcontext;
2885 unsigned char HASHdigest[HASH_BYTES];
2886 struct berval *value;
2887 struct berval digest;
2889 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2890 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2895 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2897 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2898 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2899 /* don't bother accounting for stepping */
2900 nkeys += sa->sa_any[i]->bv_len -
2901 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2906 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2907 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2914 return LDAP_SUCCESS;
2917 digest.bv_val = HASHdigest;
2918 digest.bv_len = sizeof(HASHdigest);
2920 slen = strlen( syntax->ssyn_oid );
2921 mlen = strlen( mr->smr_oid );
2923 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2926 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2927 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2929 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2930 value = sa->sa_initial;
2932 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2933 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2935 HASH_Init( &HASHcontext );
2936 if( prefix != NULL && prefix->bv_len > 0 ) {
2937 HASH_Update( &HASHcontext,
2938 prefix->bv_val, prefix->bv_len );
2940 HASH_Update( &HASHcontext,
2941 &pre, sizeof( pre ) );
2942 HASH_Update( &HASHcontext,
2943 syntax->ssyn_oid, slen );
2944 HASH_Update( &HASHcontext,
2945 mr->smr_oid, mlen );
2946 HASH_Update( &HASHcontext,
2947 value->bv_val, klen );
2948 HASH_Final( HASHdigest, &HASHcontext );
2950 keys[nkeys++] = ber_bvdup( &digest );
2953 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2955 pre = SLAP_INDEX_SUBSTR_PREFIX;
2956 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2958 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2959 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2963 value = sa->sa_any[i];
2966 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2967 j += SLAP_INDEX_SUBSTR_STEP )
2969 HASH_Init( &HASHcontext );
2970 if( prefix != NULL && prefix->bv_len > 0 ) {
2971 HASH_Update( &HASHcontext,
2972 prefix->bv_val, prefix->bv_len );
2974 HASH_Update( &HASHcontext,
2975 &pre, sizeof( pre ) );
2976 HASH_Update( &HASHcontext,
2977 syntax->ssyn_oid, slen );
2978 HASH_Update( &HASHcontext,
2979 mr->smr_oid, mlen );
2980 HASH_Update( &HASHcontext,
2981 &value->bv_val[j], klen );
2982 HASH_Final( HASHdigest, &HASHcontext );
2984 keys[nkeys++] = ber_bvdup( &digest );
2989 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2990 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2992 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2993 value = sa->sa_final;
2995 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2996 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2998 HASH_Init( &HASHcontext );
2999 if( prefix != NULL && prefix->bv_len > 0 ) {
3000 HASH_Update( &HASHcontext,
3001 prefix->bv_val, prefix->bv_len );
3003 HASH_Update( &HASHcontext,
3004 &pre, sizeof( pre ) );
3005 HASH_Update( &HASHcontext,
3006 syntax->ssyn_oid, slen );
3007 HASH_Update( &HASHcontext,
3008 mr->smr_oid, mlen );
3009 HASH_Update( &HASHcontext,
3010 &value->bv_val[value->bv_len-klen], klen );
3011 HASH_Final( HASHdigest, &HASHcontext );
3013 keys[nkeys++] = ber_bvdup( &digest );
3024 return LDAP_SUCCESS;
3033 struct berval *value,
3034 void *assertedValue )
3036 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3039 match = strncasecmp( value->bv_val,
3040 ((struct berval *) assertedValue)->bv_val,
3045 return LDAP_SUCCESS;
3049 caseIgnoreIA5SubstringsMatch(
3054 struct berval *value,
3055 void *assertedValue )
3058 SubstringsAssertion *sub = assertedValue;
3059 struct berval left = *value;
3063 /* Add up asserted input length */
3064 if( sub->sa_initial ) {
3065 inlen += sub->sa_initial->bv_len;
3068 for(i=0; sub->sa_any[i] != NULL; i++) {
3069 inlen += sub->sa_any[i]->bv_len;
3072 if( sub->sa_final ) {
3073 inlen += sub->sa_final->bv_len;
3076 if( sub->sa_initial ) {
3077 if( inlen > left.bv_len ) {
3082 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3083 sub->sa_initial->bv_len );
3089 left.bv_val += sub->sa_initial->bv_len;
3090 left.bv_len -= sub->sa_initial->bv_len;
3091 inlen -= sub->sa_initial->bv_len;
3094 if( sub->sa_final ) {
3095 if( inlen > left.bv_len ) {
3100 match = strncasecmp( sub->sa_final->bv_val,
3101 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3102 sub->sa_final->bv_len );
3108 left.bv_len -= sub->sa_final->bv_len;
3109 inlen -= sub->sa_final->bv_len;
3113 for(i=0; sub->sa_any[i]; i++) {
3118 if( inlen > left.bv_len ) {
3119 /* not enough length */
3124 if( sub->sa_any[i]->bv_len == 0 ) {
3128 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3135 idx = p - left.bv_val;
3136 assert( idx < left.bv_len );
3138 if( idx >= left.bv_len ) {
3139 /* this shouldn't happen */
3146 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3147 /* not enough left */
3152 match = strncasecmp( left.bv_val,
3153 sub->sa_any[i]->bv_val,
3154 sub->sa_any[i]->bv_len );
3163 left.bv_val += sub->sa_any[i]->bv_len;
3164 left.bv_len -= sub->sa_any[i]->bv_len;
3165 inlen -= sub->sa_any[i]->bv_len;
3171 return LDAP_SUCCESS;
3174 /* Index generation function */
3175 int caseIgnoreIA5Indexer(
3180 struct berval *prefix,
3181 struct berval **values,
3182 struct berval ***keysp )
3186 struct berval **keys;
3187 HASH_CONTEXT HASHcontext;
3188 unsigned char HASHdigest[HASH_BYTES];
3189 struct berval digest;
3190 digest.bv_val = HASHdigest;
3191 digest.bv_len = sizeof(HASHdigest);
3193 /* we should have at least one value at this point */
3194 assert( values != NULL && values[0] != NULL );
3196 for( i=0; values[i] != NULL; i++ ) {
3197 /* just count them */
3200 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3202 slen = strlen( syntax->ssyn_oid );
3203 mlen = strlen( mr->smr_oid );
3205 for( i=0; values[i] != NULL; i++ ) {
3206 struct berval *value = ber_bvdup( values[i] );
3207 ldap_pvt_str2upper( value->bv_val );
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 ber_bvfree( value );
3224 keys[i] = ber_bvdup( &digest );
3229 return LDAP_SUCCESS;
3232 /* Index generation function */
3233 int caseIgnoreIA5Filter(
3238 struct berval *prefix,
3240 struct berval ***keysp )
3243 struct berval **keys;
3244 HASH_CONTEXT HASHcontext;
3245 unsigned char HASHdigest[HASH_BYTES];
3246 struct berval *value;
3247 struct berval digest;
3248 digest.bv_val = HASHdigest;
3249 digest.bv_len = sizeof(HASHdigest);
3251 slen = strlen( syntax->ssyn_oid );
3252 mlen = strlen( mr->smr_oid );
3254 value = ber_bvdup( (struct berval *) assertValue );
3255 ldap_pvt_str2upper( value->bv_val );
3257 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3259 HASH_Init( &HASHcontext );
3260 if( prefix != NULL && prefix->bv_len > 0 ) {
3261 HASH_Update( &HASHcontext,
3262 prefix->bv_val, prefix->bv_len );
3264 HASH_Update( &HASHcontext,
3265 syntax->ssyn_oid, slen );
3266 HASH_Update( &HASHcontext,
3267 mr->smr_oid, mlen );
3268 HASH_Update( &HASHcontext,
3269 value->bv_val, value->bv_len );
3270 HASH_Final( HASHdigest, &HASHcontext );
3272 keys[0] = ber_bvdup( &digest );
3275 ber_bvfree( value );
3279 return LDAP_SUCCESS;
3282 /* Substrings Index generation function */
3283 int caseIgnoreIA5SubstringsIndexer(
3288 struct berval *prefix,
3289 struct berval **values,
3290 struct berval ***keysp )
3294 struct berval **keys;
3295 HASH_CONTEXT HASHcontext;
3296 unsigned char HASHdigest[HASH_BYTES];
3297 struct berval digest;
3298 digest.bv_val = HASHdigest;
3299 digest.bv_len = sizeof(HASHdigest);
3301 /* we should have at least one value at this point */
3302 assert( values != NULL && values[0] != NULL );
3305 for( i=0; values[i] != NULL; i++ ) {
3306 /* count number of indices to generate */
3307 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3311 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3312 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3313 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3314 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3316 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3320 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3321 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3322 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3326 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3327 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3328 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3329 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3331 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3337 /* no keys to generate */
3339 return LDAP_SUCCESS;
3342 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3344 slen = strlen( syntax->ssyn_oid );
3345 mlen = strlen( mr->smr_oid );
3348 for( i=0; values[i] != NULL; i++ ) {
3350 struct berval *value;
3352 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3354 value = ber_bvdup( values[i] );
3355 ldap_pvt_str2upper( value->bv_val );
3357 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3358 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3360 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3361 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3363 for( j=0; j<max; j++ ) {
3364 HASH_Init( &HASHcontext );
3365 if( prefix != NULL && prefix->bv_len > 0 ) {
3366 HASH_Update( &HASHcontext,
3367 prefix->bv_val, prefix->bv_len );
3370 HASH_Update( &HASHcontext,
3371 &pre, sizeof( pre ) );
3372 HASH_Update( &HASHcontext,
3373 syntax->ssyn_oid, slen );
3374 HASH_Update( &HASHcontext,
3375 mr->smr_oid, mlen );
3376 HASH_Update( &HASHcontext,
3378 SLAP_INDEX_SUBSTR_MAXLEN );
3379 HASH_Final( HASHdigest, &HASHcontext );
3381 keys[nkeys++] = ber_bvdup( &digest );
3385 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3386 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3388 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3391 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3392 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3393 HASH_Init( &HASHcontext );
3394 if( prefix != NULL && prefix->bv_len > 0 ) {
3395 HASH_Update( &HASHcontext,
3396 prefix->bv_val, prefix->bv_len );
3398 HASH_Update( &HASHcontext,
3399 &pre, sizeof( pre ) );
3400 HASH_Update( &HASHcontext,
3401 syntax->ssyn_oid, slen );
3402 HASH_Update( &HASHcontext,
3403 mr->smr_oid, mlen );
3404 HASH_Update( &HASHcontext,
3406 HASH_Final( HASHdigest, &HASHcontext );
3408 keys[nkeys++] = ber_bvdup( &digest );
3411 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3412 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
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-j], j );
3426 HASH_Final( HASHdigest, &HASHcontext );
3428 keys[nkeys++] = ber_bvdup( &digest );
3433 ber_bvfree( value );
3444 return LDAP_SUCCESS;
3447 int caseIgnoreIA5SubstringsFilter(
3452 struct berval *prefix,
3454 struct berval ***keysp )
3456 SubstringsAssertion *sa = assertValue;
3458 ber_len_t nkeys = 0;
3459 size_t slen, mlen, klen;
3460 struct berval **keys;
3461 HASH_CONTEXT HASHcontext;
3462 unsigned char HASHdigest[HASH_BYTES];
3463 struct berval *value;
3464 struct berval digest;
3466 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3467 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3472 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3474 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3475 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3476 /* don't bother accounting for stepping */
3477 nkeys += sa->sa_any[i]->bv_len -
3478 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3483 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3484 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3491 return LDAP_SUCCESS;
3494 digest.bv_val = HASHdigest;
3495 digest.bv_len = sizeof(HASHdigest);
3497 slen = strlen( syntax->ssyn_oid );
3498 mlen = strlen( mr->smr_oid );
3500 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3503 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3504 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3506 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3507 value = ber_bvdup( sa->sa_initial );
3508 ldap_pvt_str2upper( value->bv_val );
3510 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3511 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3513 HASH_Init( &HASHcontext );
3514 if( prefix != NULL && prefix->bv_len > 0 ) {
3515 HASH_Update( &HASHcontext,
3516 prefix->bv_val, prefix->bv_len );
3518 HASH_Update( &HASHcontext,
3519 &pre, sizeof( pre ) );
3520 HASH_Update( &HASHcontext,
3521 syntax->ssyn_oid, slen );
3522 HASH_Update( &HASHcontext,
3523 mr->smr_oid, mlen );
3524 HASH_Update( &HASHcontext,
3525 value->bv_val, klen );
3526 HASH_Final( HASHdigest, &HASHcontext );
3528 ber_bvfree( value );
3529 keys[nkeys++] = ber_bvdup( &digest );
3532 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3534 pre = SLAP_INDEX_SUBSTR_PREFIX;
3535 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3537 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3538 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3542 value = ber_bvdup( sa->sa_any[i] );
3543 ldap_pvt_str2upper( value->bv_val );
3546 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3547 j += SLAP_INDEX_SUBSTR_STEP )
3549 HASH_Init( &HASHcontext );
3550 if( prefix != NULL && prefix->bv_len > 0 ) {
3551 HASH_Update( &HASHcontext,
3552 prefix->bv_val, prefix->bv_len );
3554 HASH_Update( &HASHcontext,
3555 &pre, sizeof( pre ) );
3556 HASH_Update( &HASHcontext,
3557 syntax->ssyn_oid, slen );
3558 HASH_Update( &HASHcontext,
3559 mr->smr_oid, mlen );
3560 HASH_Update( &HASHcontext,
3561 &value->bv_val[j], klen );
3562 HASH_Final( HASHdigest, &HASHcontext );
3564 keys[nkeys++] = ber_bvdup( &digest );
3567 ber_bvfree( value );
3571 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3572 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3574 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3575 value = ber_bvdup( sa->sa_final );
3576 ldap_pvt_str2upper( value->bv_val );
3578 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3579 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3581 HASH_Init( &HASHcontext );
3582 if( prefix != NULL && prefix->bv_len > 0 ) {
3583 HASH_Update( &HASHcontext,
3584 prefix->bv_val, prefix->bv_len );
3586 HASH_Update( &HASHcontext,
3587 &pre, sizeof( pre ) );
3588 HASH_Update( &HASHcontext,
3589 syntax->ssyn_oid, slen );
3590 HASH_Update( &HASHcontext,
3591 mr->smr_oid, mlen );
3592 HASH_Update( &HASHcontext,
3593 &value->bv_val[value->bv_len-klen], klen );
3594 HASH_Final( HASHdigest, &HASHcontext );
3596 ber_bvfree( value );
3597 keys[nkeys++] = ber_bvdup( &digest );
3608 return LDAP_SUCCESS;
3612 numericStringNormalize(
3615 struct berval **normalized )
3617 /* similiar to IA5StringNormalize except removes all spaces */
3618 struct berval *newval;
3621 newval = ch_malloc( sizeof( struct berval ) );
3625 /* Ignore initial whitespace */
3626 while ( ASCII_SPACE( *p ) ) {
3632 return LDAP_INVALID_SYNTAX;
3635 newval->bv_val = ch_strdup( p );
3636 p = q = newval->bv_val;
3639 if ( ASCII_SPACE( *p ) ) {
3640 /* Ignore whitespace */
3647 assert( *newval->bv_val );
3648 assert( newval->bv_val < p );
3651 /* cannot start with a space */
3652 assert( !ASCII_SPACE(*newval->bv_val) );
3654 /* cannot end with a space */
3655 assert( !ASCII_SPACE( q[-1] ) );
3657 /* null terminate */
3660 newval->bv_len = q - newval->bv_val;
3661 *normalized = newval;
3663 return LDAP_SUCCESS;
3667 objectIdentifierFirstComponentMatch(
3672 struct berval *value,
3673 void *assertedValue )
3675 int rc = LDAP_SUCCESS;
3677 struct berval *asserted = (struct berval *) assertedValue;
3681 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3682 return LDAP_INVALID_SYNTAX;
3685 /* trim leading white space */
3686 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3690 /* grab next word */
3691 oid.bv_val = &value->bv_val[i];
3692 oid.bv_len = value->bv_len - i;
3693 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3698 /* insert attributeTypes, objectclass check here */
3699 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3700 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3703 char *stored = ch_malloc( oid.bv_len + 1 );
3704 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3705 stored[oid.bv_len] = '\0';
3707 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3708 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3709 MatchingRule *stored_mr = mr_find( stored );
3711 if( asserted_mr == NULL ) {
3712 rc = SLAPD_COMPARE_UNDEFINED;
3714 match = asserted_mr != stored_mr;
3717 } else if ( !strcmp( syntax->ssyn_oid,
3718 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3720 AttributeType *asserted_at = at_find( asserted->bv_val );
3721 AttributeType *stored_at = at_find( stored );
3723 if( asserted_at == NULL ) {
3724 rc = SLAPD_COMPARE_UNDEFINED;
3726 match = asserted_at != stored_at;
3729 } else if ( !strcmp( syntax->ssyn_oid,
3730 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3732 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3733 ObjectClass *stored_oc = oc_find( stored );
3735 if( asserted_oc == NULL ) {
3736 rc = SLAPD_COMPARE_UNDEFINED;
3738 match = asserted_oc != stored_oc;
3746 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3747 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3748 match, value->bv_val, asserted->bv_val ));
3750 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3751 "%d\n\t\"%s\"\n\t\"%s\"\n",
3752 match, value->bv_val, asserted->bv_val );
3756 if( rc == LDAP_SUCCESS ) *matchp = match;
3761 check_time_syntax (struct berval *val,
3765 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3766 static int mdays[2][12] = {
3767 /* non-leap years */
3768 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3770 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3773 int part, c, tzoffset, leapyear = 0 ;
3775 if( val->bv_len == 0 ) {
3776 return LDAP_INVALID_SYNTAX;
3779 p = (char *)val->bv_val;
3780 e = p + val->bv_len;
3782 /* Ignore initial whitespace */
3783 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3787 if (e - p < 13 - (2 * start)) {
3788 return LDAP_INVALID_SYNTAX;
3791 for (part = 0; part < 9; part++) {
3795 for (part = start; part < 7; part++) {
3797 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3804 return LDAP_INVALID_SYNTAX;
3806 if (c < 0 || c > 9) {
3807 return LDAP_INVALID_SYNTAX;
3813 return LDAP_INVALID_SYNTAX;
3815 if (c < 0 || c > 9) {
3816 return LDAP_INVALID_SYNTAX;
3821 if (part == 2 || part == 3) {
3824 if (parts[part] < 0) {
3825 return LDAP_INVALID_SYNTAX;
3827 if (parts[part] > ceiling[part]) {
3828 return LDAP_INVALID_SYNTAX;
3832 /* leapyear check for the Gregorian calendar (year>1581) */
3833 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3834 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3839 if (parts[3] > mdays[leapyear][parts[2]]) {
3840 return LDAP_INVALID_SYNTAX;
3845 tzoffset = 0; /* UTC */
3846 } else if (c != '+' && c != '-') {
3847 return LDAP_INVALID_SYNTAX;
3851 } else /* c == '+' */ {
3856 return LDAP_INVALID_SYNTAX;
3859 for (part = 7; part < 9; part++) {
3861 if (c < 0 || c > 9) {
3862 return LDAP_INVALID_SYNTAX;
3867 if (c < 0 || c > 9) {
3868 return LDAP_INVALID_SYNTAX;
3872 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3873 return LDAP_INVALID_SYNTAX;
3878 /* Ignore trailing whitespace */
3879 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3883 return LDAP_INVALID_SYNTAX;
3886 switch ( tzoffset ) {
3887 case -1: /* negativ offset to UTC, ie west of Greenwich */
3888 parts[4] += parts[7];
3889 parts[5] += parts[8];
3890 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3894 c = mdays[leapyear][parts[2]];
3896 if (parts[part] > c) {
3897 parts[part] -= c + 1;
3902 case 1: /* positive offset to UTC, ie east of Greenwich */
3903 parts[4] -= parts[7];
3904 parts[5] -= parts[8];
3905 for (part = 6; --part > 0; ) {
3909 /* first arg to % needs to be non negativ */
3910 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3912 if (parts[part] < 0) {
3913 parts[part] += c + 1;
3918 case 0: /* already UTC */
3922 return LDAP_SUCCESS;
3929 struct berval **normalized )
3934 rc = check_time_syntax(val, 1, parts);
3935 if (rc != LDAP_SUCCESS) {
3940 out = ch_malloc( sizeof(struct berval) );
3942 return LBER_ERROR_MEMORY;
3945 out->bv_val = ch_malloc( 14 );
3946 if ( out->bv_val == NULL ) {
3948 return LBER_ERROR_MEMORY;
3951 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3952 parts[1], parts[2] + 1, parts[3] + 1,
3953 parts[4], parts[5], parts[6] );
3957 return LDAP_SUCCESS;
3967 return check_time_syntax(in, 1, parts);
3971 generalizedTimeValidate(
3977 return check_time_syntax(in, 0, parts);
3981 generalizedTimeNormalize(
3984 struct berval **normalized )
3989 rc = check_time_syntax(val, 0, parts);
3990 if (rc != LDAP_SUCCESS) {
3995 out = ch_malloc( sizeof(struct berval) );
3997 return LBER_ERROR_MEMORY;
4000 out->bv_val = ch_malloc( 16 );
4001 if ( out->bv_val == NULL ) {
4003 return LBER_ERROR_MEMORY;
4006 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4007 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4008 parts[4], parts[5], parts[6] );
4012 return LDAP_SUCCESS;
4016 nisNetgroupTripleValidate(
4018 struct berval *val )
4023 if ( val->bv_len == 0 ) {
4024 return LDAP_INVALID_SYNTAX;
4027 p = (char *)val->bv_val;
4028 e = p + val->bv_len;
4031 /* syntax does not allow leading white space */
4032 /* Ignore initial whitespace */
4033 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4038 if ( *p != '(' /*')'*/ ) {
4039 return LDAP_INVALID_SYNTAX;
4042 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4046 return LDAP_INVALID_SYNTAX;
4049 } else if ( !ATTR_CHAR( *p ) ) {
4050 return LDAP_INVALID_SYNTAX;
4054 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4055 return LDAP_INVALID_SYNTAX;
4061 /* syntax does not allow trailing white space */
4062 /* Ignore trailing whitespace */
4063 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4069 return LDAP_INVALID_SYNTAX;
4072 return LDAP_SUCCESS;
4076 bootParameterValidate(
4078 struct berval *val )
4082 if ( val->bv_len == 0 ) {
4083 return LDAP_INVALID_SYNTAX;
4086 p = (char *)val->bv_val;
4087 e = p + val->bv_len;
4090 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4091 if ( !ATTR_CHAR( *p ) ) {
4092 return LDAP_INVALID_SYNTAX;
4097 return LDAP_INVALID_SYNTAX;
4101 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4102 if ( !ATTR_CHAR( *p ) ) {
4103 return LDAP_INVALID_SYNTAX;
4108 return LDAP_INVALID_SYNTAX;
4112 for ( p++; p < e; p++ ) {
4113 if ( !ATTR_CHAR( *p ) ) {
4114 return LDAP_INVALID_SYNTAX;
4118 return LDAP_SUCCESS;
4121 struct syntax_defs_rec {
4124 slap_syntax_validate_func *sd_validate;
4125 slap_syntax_transform_func *sd_normalize;
4126 slap_syntax_transform_func *sd_pretty;
4127 #ifdef SLAPD_BINARY_CONVERSION
4128 slap_syntax_transform_func *sd_ber2str;
4129 slap_syntax_transform_func *sd_str2ber;
4133 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4134 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4136 struct syntax_defs_rec syntax_defs[] = {
4137 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4138 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4139 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4140 0, NULL, NULL, NULL},
4141 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4142 0, NULL, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4144 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4146 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4148 0, bitStringValidate, NULL, NULL },
4149 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4150 0, booleanValidate, NULL, NULL},
4151 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4152 X_BINARY X_NOT_H_R ")",
4153 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4154 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4155 X_BINARY X_NOT_H_R ")",
4156 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4158 X_BINARY X_NOT_H_R ")",
4159 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4160 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4161 0, countryStringValidate, IA5StringNormalize, NULL},
4162 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4163 0, dnValidate, dnNormalize, dnPretty},
4164 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4165 0, NULL, NULL, NULL},
4166 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4167 0, NULL, NULL, NULL},
4168 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4169 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4170 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4171 0, NULL, NULL, NULL},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4173 0, NULL, NULL, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4175 0, NULL, NULL, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4177 0, NULL, NULL, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4179 0, NULL, NULL, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4181 0, printablesStringValidate, IA5StringNormalize, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4183 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4185 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4187 0, NULL, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4189 0, IA5StringValidate, IA5StringNormalize, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4191 0, integerValidate, integerNormalize, integerPretty},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4193 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4195 0, NULL, NULL, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4197 0, NULL, NULL, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4199 0, NULL, NULL, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4201 0, NULL, NULL, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4203 0, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4205 0, nameUIDValidate, nameUIDNormalize, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4207 0, NULL, NULL, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4209 0, IA5StringValidate, numericStringNormalize, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4211 0, NULL, NULL, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4213 0, oidValidate, NULL, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4215 0, IA5StringValidate, IA5StringNormalize, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4217 0, blobValidate, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4219 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4221 0, NULL, NULL, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4223 0, NULL, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4225 0, printableStringValidate, IA5StringNormalize, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4227 X_BINARY X_NOT_H_R ")",
4228 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4229 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4230 0, printableStringValidate, IA5StringNormalize, NULL},
4231 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4232 0, NULL, NULL, NULL},
4233 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4234 0, printableStringValidate, IA5StringNormalize, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4236 0, utcTimeValidate, utcTimeNormalize, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4238 0, NULL, NULL, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4240 0, NULL, NULL, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4242 0, NULL, NULL, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4244 0, NULL, NULL, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4246 0, NULL, NULL, NULL},
4248 /* RFC 2307 NIS Syntaxes */
4249 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4250 0, nisNetgroupTripleValidate, NULL, NULL},
4251 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4252 0, bootParameterValidate, NULL, NULL},
4254 /* OpenLDAP Experimental Syntaxes */
4255 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4256 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4258 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4259 0, NULL, NULL, NULL},
4261 /* OpenLDAP Void Syntax */
4262 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4263 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4264 {NULL, 0, NULL, NULL, NULL}
4267 struct mrule_defs_rec {
4269 slap_mask_t mrd_usage;
4270 slap_mr_convert_func * mrd_convert;
4271 slap_mr_normalize_func * mrd_normalize;
4272 slap_mr_match_func * mrd_match;
4273 slap_mr_indexer_func * mrd_indexer;
4274 slap_mr_filter_func * mrd_filter;
4276 char * mrd_associated;
4280 * Other matching rules in X.520 that we do not use (yet):
4282 * 2.5.13.9 numericStringOrderingMatch
4283 * 2.5.13.15 integerOrderingMatch
4284 * 2.5.13.18 octetStringOrderingMatch
4285 * 2.5.13.19 octetStringSubstringsMatch
4286 * 2.5.13.25 uTCTimeMatch
4287 * 2.5.13.26 uTCTimeOrderingMatch
4288 * 2.5.13.31 directoryStringFirstComponentMatch
4289 * 2.5.13.32 wordMatch
4290 * 2.5.13.33 keywordMatch
4291 * 2.5.13.34 certificateExactMatch
4292 * 2.5.13.35 certificateMatch
4293 * 2.5.13.36 certificatePairExactMatch
4294 * 2.5.13.37 certificatePairMatch
4295 * 2.5.13.38 certificateListExactMatch
4296 * 2.5.13.39 certificateListMatch
4297 * 2.5.13.40 algorithmIdentifierMatch
4298 * 2.5.13.41 storedPrefixMatch
4299 * 2.5.13.42 attributeCertificateMatch
4300 * 2.5.13.43 readerAndKeyIDMatch
4301 * 2.5.13.44 attributeIntegrityMatch
4304 struct mrule_defs_rec mrule_defs[] = {
4306 * EQUALITY matching rules must be listed after associated APPROX
4307 * matching rules. So, we list all APPROX matching rules first.
4309 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4310 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4311 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4313 directoryStringApproxMatch, directoryStringApproxIndexer,
4314 directoryStringApproxFilter,
4317 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4318 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4319 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4321 IA5StringApproxMatch, IA5StringApproxIndexer,
4322 IA5StringApproxFilter,
4326 * Other matching rules
4329 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4330 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4331 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4333 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4336 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4337 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4338 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4340 dnMatch, dnIndexer, dnFilter,
4343 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4344 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4345 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4347 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4348 directoryStringApproxMatchOID },
4350 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4351 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4354 caseIgnoreOrderingMatch, NULL, NULL,
4357 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4358 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4359 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4361 caseIgnoreSubstringsMatch,
4362 caseIgnoreSubstringsIndexer,
4363 caseIgnoreSubstringsFilter,
4366 {"( 2.5.13.5 NAME 'caseExactMatch' "
4367 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4368 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4370 caseExactMatch, caseExactIndexer, caseExactFilter,
4371 directoryStringApproxMatchOID },
4373 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4374 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4377 caseExactOrderingMatch, NULL, NULL,
4380 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4381 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4382 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4384 caseExactSubstringsMatch,
4385 caseExactSubstringsIndexer,
4386 caseExactSubstringsFilter,
4389 {"( 2.5.13.8 NAME 'numericStringMatch' "
4390 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4391 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4394 caseIgnoreIA5Indexer,
4395 caseIgnoreIA5Filter,
4398 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4399 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4400 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4402 caseIgnoreIA5SubstringsMatch,
4403 caseIgnoreIA5SubstringsIndexer,
4404 caseIgnoreIA5SubstringsFilter,
4407 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4408 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4409 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4411 caseIgnoreListMatch, NULL, NULL,
4414 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4415 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4416 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4418 caseIgnoreListSubstringsMatch, NULL, NULL,
4421 {"( 2.5.13.13 NAME 'booleanMatch' "
4422 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4423 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4425 booleanMatch, NULL, NULL,
4428 {"( 2.5.13.14 NAME 'integerMatch' "
4429 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4430 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4432 integerMatch, integerIndexer, integerFilter,
4435 {"( 2.5.13.16 NAME 'bitStringMatch' "
4436 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4437 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4439 bitStringMatch, NULL, NULL,
4442 {"( 2.5.13.17 NAME 'octetStringMatch' "
4443 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4444 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4446 octetStringMatch, octetStringIndexer, octetStringFilter,
4449 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4450 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4451 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4453 telephoneNumberMatch, NULL, NULL,
4456 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4457 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4458 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4460 telephoneNumberSubstringsMatch, NULL, NULL,
4463 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4464 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4465 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4467 presentationAddressMatch, NULL, NULL,
4470 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4471 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4472 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4474 uniqueMemberMatch, NULL, NULL,
4477 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4478 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4479 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4481 protocolInformationMatch, NULL, NULL,
4484 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4485 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4486 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4488 generalizedTimeMatch, NULL, NULL,
4491 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4492 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4495 generalizedTimeOrderingMatch, NULL, NULL,
4498 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4499 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4500 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4502 integerFirstComponentMatch, NULL, NULL,
4505 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4506 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4507 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4509 objectIdentifierFirstComponentMatch, NULL, NULL,
4512 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4513 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4514 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4516 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4517 IA5StringApproxMatchOID },
4519 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4520 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4521 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4523 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4524 IA5StringApproxMatchOID },
4526 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4527 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4530 caseIgnoreIA5SubstringsMatch,
4531 caseIgnoreIA5SubstringsIndexer,
4532 caseIgnoreIA5SubstringsFilter,
4535 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4536 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4539 caseExactIA5SubstringsMatch,
4540 caseExactIA5SubstringsIndexer,
4541 caseExactIA5SubstringsFilter,
4544 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4545 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4548 authPasswordMatch, NULL, NULL,
4551 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4552 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4555 OpenLDAPaciMatch, NULL, NULL,
4558 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4567 /* we should only be called once (from main) */
4568 assert( schema_init_done == 0 );
4570 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4571 res = register_syntax( syntax_defs[i].sd_desc,
4572 syntax_defs[i].sd_flags,
4573 syntax_defs[i].sd_validate,
4574 syntax_defs[i].sd_normalize,
4575 syntax_defs[i].sd_pretty
4576 #ifdef SLAPD_BINARY_CONVERSION
4578 syntax_defs[i].sd_ber2str,
4579 syntax_defs[i].sd_str2ber
4584 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4585 syntax_defs[i].sd_desc );
4590 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4591 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4593 "schema_init: Ingoring unusable matching rule %s\n",
4594 mrule_defs[i].mrd_desc );
4598 res = register_matching_rule(
4599 mrule_defs[i].mrd_desc,
4600 mrule_defs[i].mrd_usage,
4601 mrule_defs[i].mrd_convert,
4602 mrule_defs[i].mrd_normalize,
4603 mrule_defs[i].mrd_match,
4604 mrule_defs[i].mrd_indexer,
4605 mrule_defs[i].mrd_filter,
4606 mrule_defs[i].mrd_associated );
4610 "schema_init: Error registering matching rule %s\n",
4611 mrule_defs[i].mrd_desc );
4615 schema_init_done = 1;
4616 return LDAP_SUCCESS;