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 caseIgnoreIA5Match
50 #define objectIdentifierMatch caseIgnoreIA5Match
51 #define telephoneNumberMatch caseIgnoreIA5Match
52 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
53 #define generalizedTimeMatch caseIgnoreIA5Match
54 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
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 )
249 if ( val->bv_len != 0 ) {
251 #ifdef USE_DN_NORMALIZE
252 out = ber_bvstr( UTF8normalize( val->bv_val, UTF8_CASEFOLD ) );
254 out = ber_bvdup( val );
255 ldap_pvt_str2upper( out->bv_val );
257 dn = dn_validate( out->bv_val );
261 return LDAP_INVALID_SYNTAX;
265 out->bv_len = strlen( dn );
267 out = ber_bvdup( val );
280 struct berval *value,
281 void *assertedValue )
284 struct berval *asserted = (struct berval *) assertedValue;
286 match = value->bv_len - asserted->bv_len;
289 #ifdef USE_DN_NORMALIZE
290 match = strcmp( value->bv_val, asserted->bv_val );
292 match = strcasecmp( value->bv_val, asserted->bv_val );
297 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
298 "dnMatch: %d\n %s\n %s\n", match,
299 value->bv_val, asserted->bv_val ));
301 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
302 match, value->bv_val, asserted->bv_val );
318 if( in->bv_len == 0 ) return LDAP_SUCCESS;
320 dn = ber_bvdup( in );
322 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
323 /* assume presence of optional UID */
326 for(i=dn->bv_len-2; i>2; i--) {
327 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
331 if( dn->bv_val[i] != '\'' ) {
332 return LDAP_INVALID_SYNTAX;
334 if( dn->bv_val[i-1] != 'B' ) {
335 return LDAP_INVALID_SYNTAX;
337 if( dn->bv_val[i-2] != '#' ) {
338 return LDAP_INVALID_SYNTAX;
341 /* trim the UID to allow use of dn_validate */
342 dn->bv_val[i-2] = '\0';
345 rc = dn_validate( dn->bv_val ) == NULL
346 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
356 struct berval **normalized )
358 struct berval *out = ber_bvdup( val );
360 if( out->bv_len != 0 ) {
364 ber_len_t uidlen = 0;
366 if( out->bv_val[out->bv_len-1] == '\'' ) {
367 /* assume presence of optional UID */
368 uid = strrchr( out->bv_val, '#' );
372 return LDAP_INVALID_SYNTAX;
375 uidlen = out->bv_len - (out->bv_val - uid);
376 /* temporarily trim the UID */
380 #ifdef USE_DN_NORMALIZE
381 dn = dn_normalize( out->bv_val );
383 dn = dn_validate( out->bv_val );
388 return LDAP_INVALID_SYNTAX;
394 /* restore the separator */
397 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
401 out->bv_len = dnlen + uidlen;
413 /* any value allowed */
422 /* any value allowed */
433 /* very unforgiving validation, requires no normalization
434 * before simplistic matching
436 if( in->bv_len < 3 ) {
437 return LDAP_INVALID_SYNTAX;
439 if( in->bv_val[0] != 'B' ||
440 in->bv_val[1] != '\'' ||
441 in->bv_val[in->bv_len-1] != '\'' )
443 return LDAP_INVALID_SYNTAX;
446 for( i=in->bv_len-2; i>1; i-- ) {
447 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
448 return LDAP_INVALID_SYNTAX;
456 * Handling boolean syntax and matching is quite rigid.
457 * A more flexible approach would be to allow a variety
458 * of strings to be normalized and prettied into TRUE
466 /* very unforgiving validation, requires no normalization
467 * before simplistic matching
470 if( in->bv_len == 4 ) {
471 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
474 } else if( in->bv_len == 5 ) {
475 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
480 return LDAP_INVALID_SYNTAX;
489 struct berval *value,
490 void *assertedValue )
492 /* simplistic matching allowed by rigid validation */
493 struct berval *asserted = (struct berval *) assertedValue;
494 *matchp = value->bv_len != asserted->bv_len;
501 struct berval *right,
502 struct berval *left )
506 ldap_unicode_t ru, lu;
507 ldap_unicode_t ruu, luu;
510 r < right->bv_len && l < left->bv_len;
514 * XXYYZ: we convert to ucs4 even though -llunicode
515 * expects ucs2 in an unsigned long
517 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
518 if( ru == LDAP_UCS4_INVALID ) {
522 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
523 if( lu == LDAP_UCS4_INVALID ) {
527 ruu = uctoupper( ru );
528 luu = uctoupper( lu );
532 } else if( luu > ruu ) {
536 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
537 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
540 if( r < right->bv_len ) {
545 if( l < left->bv_len ) {
553 /* case insensitive UTF8 strncmp with offset for second string */
556 struct berval *right,
564 ldap_unicode_t ru, lu;
565 ldap_unicode_t ruu, luu;
567 rslen = len < right->bv_len ? len : right->bv_len;
568 lslen = len + offset < left->bv_len ? len : left->bv_len;
570 for( r = 0, l = offset;
571 r < rslen && l < lslen;
575 * XXYYZ: we convert to ucs4 even though -llunicode
576 * expects ucs2 in an unsigned long
578 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
579 if( ru == LDAP_UCS4_INVALID ) {
583 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
584 if( lu == LDAP_UCS4_INVALID ) {
588 ruu = uctoupper( ru );
589 luu = uctoupper( lu );
593 } else if( luu > ruu ) {
597 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
598 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
614 static char *UTF8casechr( const char *str, const char *c )
616 char *p, *lower, *upper;
617 ldap_ucs4_t tch, ch = ldap_utf8_to_ucs4(c);
619 tch = uctolower ( ch );
620 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
621 if( ldap_utf8_to_ucs4( p ) == tch ) {
625 lower = *p != '\0' ? p : NULL;
627 tch = uctoupper ( ch );
628 for( p = (char *) str; *p != '\0'; LDAP_UTF8_INCR(p) ) {
629 if( ldap_utf8_to_ucs4( p ) == tch ) {
633 upper = *p != '\0' ? p : NULL;
635 if( lower && upper ) {
636 return lower < upper ? lower : upper;
637 } else if ( lower ) {
652 unsigned char *u = in->bv_val;
654 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
656 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
657 /* get the length indicated by the first byte */
658 len = LDAP_UTF8_CHARLEN( u );
660 /* should not be zero */
661 if( len == 0 ) return LDAP_INVALID_SYNTAX;
663 /* make sure len corresponds with the offset
664 to the next character */
665 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
668 if( count != 0 ) return LDAP_INVALID_SYNTAX;
677 struct berval **normalized )
679 struct berval *newval;
682 newval = ch_malloc( sizeof( struct berval ) );
686 /* Ignore initial whitespace */
687 while ( ldap_utf8_isspace( p ) ) {
693 return LDAP_INVALID_SYNTAX;
696 newval->bv_val = ch_strdup( p );
697 p = q = newval->bv_val;
703 if ( ldap_utf8_isspace( p ) ) {
704 len = LDAP_UTF8_COPY(q,p);
709 /* Ignore the extra whitespace */
710 while ( ldap_utf8_isspace( p ) ) {
714 len = LDAP_UTF8_COPY(q,p);
721 assert( *newval->bv_val );
722 assert( newval->bv_val < p );
725 /* cannot start with a space */
726 assert( !ldap_utf8_isspace(newval->bv_val) );
729 * If the string ended in space, backup the pointer one
730 * position. One is enough because the above loop collapsed
731 * all whitespace to a single space.
738 /* cannot end with a space */
739 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
744 newval->bv_len = q - newval->bv_val;
745 *normalized = newval;
750 #if defined(SLAPD_APPROX_MULTISTRING)
752 #if defined(SLAPD_APPROX_INITIALS)
753 #define SLAPD_APPROX_DELIMITER "._ "
754 #define SLAPD_APPROX_WORDLEN 2
756 #define SLAPD_APPROX_DELIMITER " "
757 #define SLAPD_APPROX_WORDLEN 1
766 struct berval *value,
767 void *assertedValue )
769 char *val, *assertv, **values, **words, *c;
770 int i, count, len, nextchunk=0, nextavail=0;
773 /* Isolate how many words there are */
774 val = ch_strdup( value->bv_val );
775 for( c=val,count=1; *c; c++ ) {
776 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
777 if ( c == NULL ) break;
782 /* Get a phonetic copy of each word */
783 words = (char **)ch_malloc( count * sizeof(char *) );
784 values = (char **)ch_malloc( count * sizeof(char *) );
785 for( c=val,i=0; i<count; i++,c+=strlen(c)+1 ) {
787 values[i] = phonetic(c);
791 /* Work through the asserted value's words, to see if at least some
792 of the words are there, in the same order. */
793 assertv = ch_strdup( ((struct berval *)assertedValue)->bv_val );
795 while ( nextchunk < ((struct berval *)assertedValue)->bv_len ) {
796 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
801 #if defined(SLAPD_APPROX_INITIALS)
802 else if( len == 1 ) {
803 /* Single letter words need to at least match one word's initial */
804 for( i=nextavail; i<count; i++ )
805 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
812 /* Isolate the next word in the asserted value and phonetic it */
813 assertv[nextchunk+len] = '\0';
814 val = phonetic( assertv + nextchunk );
816 /* See if this phonetic chunk is in the remaining words of *value */
817 for( i=nextavail; i<count; i++ ){
818 if( !strcmp( val, values[i] ) ){
825 /* This chunk in the asserted value was NOT within the *value. */
831 /* Go on to the next word in the asserted value */
835 /* If some of the words were seen, call it a match */
836 if( nextavail > 0 ) {
845 for( i=0; i<count; i++ ) {
846 ch_free( values[i] );
862 struct berval *prefix,
863 struct berval **values,
864 struct berval ***keysp )
867 int i,j, len, wordcount, keycount=0;
868 struct berval **newkeys, **keys=NULL;
871 for( j=0; values[j] != NULL; j++ ) {
873 /* Isolate how many words there are. There will be a key for each */
874 val = ch_strdup( values[j]->bv_val );
875 for( wordcount=0,c=val; *c; c++) {
876 len = strcspn(c, SLAPD_APPROX_DELIMITER);
877 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
879 if (*c == '\0') break;
883 /* Allocate/increase storage to account for new keys */
884 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
885 * sizeof(struct berval *) );
886 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
887 if( keys ) ch_free( keys );
890 /* Get a phonetic copy of each word */
891 for( c=val,i=0; i<wordcount; c+=len+1 ) {
893 if( len < SLAPD_APPROX_WORDLEN ) continue;
894 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
895 keys[keycount]->bv_val = phonetic( c );
896 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
903 keys[keycount] = NULL;
916 struct berval *prefix,
918 struct berval ***keysp )
922 struct berval **keys;
925 /* Isolate how many words there are. There will be a key for each */
926 val = ch_strdup( ((struct berval *)assertValue)->bv_val );
927 for( count=0,c=val; *c; c++) {
928 len = strcspn(c, SLAPD_APPROX_DELIMITER);
929 if( len >= SLAPD_APPROX_WORDLEN ) count++;
931 if (*c == '\0') break;
935 /* Allocate storage for new keys */
936 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
938 /* Get a phonetic copy of each word */
939 for( c=val,i=0; i<count; c+=len+1 ) {
941 if( len < SLAPD_APPROX_WORDLEN ) continue;
942 keys[i] = (struct berval *)ch_malloc( sizeof(struct berval) );
943 keys[i]->bv_val = phonetic( c );
944 keys[i]->bv_len = strlen( keys[i]->bv_val );
958 /* No other form of Approximate Matching is defined */
966 struct berval *value,
967 void *assertedValue )
969 char *vapprox, *avapprox;
971 vapprox = phonetic( value->bv_val );
972 avapprox = phonetic( ((struct berval *)assertedValue)->bv_val);
974 *matchp = strcmp( vapprox, avapprox );
988 struct berval *prefix,
989 struct berval **values,
990 struct berval ***keysp )
993 struct berval **keys;
996 for( i=0; values[i] != NULL; i++ ) {
997 /* just count them */
1001 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
1003 /* Copy each value and run it through phonetic() */
1004 for( i=0; values[i] != NULL; i++ ) {
1005 keys[i] = ch_malloc( sizeof( struct berval * ) );
1006 keys[i]->bv_val = phonetic( values[i]->bv_val );
1007 keys[i]->bv_len = strlen( keys[i]->bv_val );
1012 return LDAP_SUCCESS;
1022 struct berval *prefix,
1024 struct berval ***keysp )
1026 struct berval **keys;
1029 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1031 /* Copy the value and run it through phonetic() */
1032 keys[0] = ch_malloc( sizeof( struct berval * ) );
1033 keys[0]->bv_val = phonetic( ((struct berval *)assertValue)->bv_val );
1034 keys[0]->bv_len = strlen( keys[0]->bv_val );
1038 return LDAP_SUCCESS;
1049 struct berval *value,
1050 void *assertedValue )
1052 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1055 match = strncmp( value->bv_val,
1056 ((struct berval *) assertedValue)->bv_val,
1061 return LDAP_SUCCESS;
1065 caseExactSubstringsMatch(
1070 struct berval *value,
1071 void *assertedValue )
1074 SubstringsAssertion *sub = assertedValue;
1075 struct berval left = *value;
1079 /* Add up asserted input length */
1080 if( sub->sa_initial ) {
1081 inlen += sub->sa_initial->bv_len;
1084 for(i=0; sub->sa_any[i] != NULL; i++) {
1085 inlen += sub->sa_any[i]->bv_len;
1088 if( sub->sa_final ) {
1089 inlen += sub->sa_final->bv_len;
1092 if( sub->sa_initial ) {
1093 if( inlen > left.bv_len ) {
1098 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1099 sub->sa_initial->bv_len );
1105 left.bv_val += sub->sa_initial->bv_len;
1106 left.bv_len -= sub->sa_initial->bv_len;
1107 inlen -= sub->sa_initial->bv_len;
1110 if( sub->sa_final ) {
1111 if( inlen > left.bv_len ) {
1116 match = strncmp( sub->sa_final->bv_val,
1117 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1118 sub->sa_final->bv_len );
1124 left.bv_len -= sub->sa_final->bv_len;
1125 inlen -= sub->sa_final->bv_len;
1129 for(i=0; sub->sa_any[i]; i++) {
1134 if( inlen > left.bv_len ) {
1135 /* not enough length */
1140 if( sub->sa_any[i]->bv_len == 0 ) {
1144 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1151 idx = p - left.bv_val;
1152 assert( idx < left.bv_len );
1154 if( idx >= left.bv_len ) {
1155 /* this shouldn't happen */
1162 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1163 /* not enough left */
1168 match = strncmp( left.bv_val,
1169 sub->sa_any[i]->bv_val,
1170 sub->sa_any[i]->bv_len );
1178 left.bv_val += sub->sa_any[i]->bv_len;
1179 left.bv_len -= sub->sa_any[i]->bv_len;
1180 inlen -= sub->sa_any[i]->bv_len;
1186 return LDAP_SUCCESS;
1189 /* Index generation function */
1190 int caseExactIndexer(
1195 struct berval *prefix,
1196 struct berval **values,
1197 struct berval ***keysp )
1201 struct berval **keys;
1202 HASH_CONTEXT HASHcontext;
1203 unsigned char HASHdigest[HASH_BYTES];
1204 struct berval digest;
1205 digest.bv_val = HASHdigest;
1206 digest.bv_len = sizeof(HASHdigest);
1208 /* we should have at least one value at this point */
1209 assert( values != NULL && values[0] != NULL );
1211 for( i=0; values[i] != NULL; i++ ) {
1212 /* just count them */
1215 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1217 slen = strlen( syntax->ssyn_oid );
1218 mlen = strlen( mr->smr_oid );
1220 for( i=0; values[i] != NULL; i++ ) {
1221 struct berval *value = values[i];
1223 HASH_Init( &HASHcontext );
1224 if( prefix != NULL && prefix->bv_len > 0 ) {
1225 HASH_Update( &HASHcontext,
1226 prefix->bv_val, prefix->bv_len );
1228 HASH_Update( &HASHcontext,
1229 syntax->ssyn_oid, slen );
1230 HASH_Update( &HASHcontext,
1231 mr->smr_oid, mlen );
1232 HASH_Update( &HASHcontext,
1233 value->bv_val, value->bv_len );
1234 HASH_Final( HASHdigest, &HASHcontext );
1236 keys[i] = ber_bvdup( &digest );
1241 return LDAP_SUCCESS;
1244 /* Index generation function */
1245 int caseExactFilter(
1250 struct berval *prefix,
1252 struct berval ***keysp )
1255 struct berval **keys;
1256 HASH_CONTEXT HASHcontext;
1257 unsigned char HASHdigest[HASH_BYTES];
1258 struct berval *value;
1259 struct berval digest;
1260 digest.bv_val = HASHdigest;
1261 digest.bv_len = sizeof(HASHdigest);
1263 slen = strlen( syntax->ssyn_oid );
1264 mlen = strlen( mr->smr_oid );
1266 value = (struct berval *) assertValue;
1268 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1270 HASH_Init( &HASHcontext );
1271 if( prefix != NULL && prefix->bv_len > 0 ) {
1272 HASH_Update( &HASHcontext,
1273 prefix->bv_val, prefix->bv_len );
1275 HASH_Update( &HASHcontext,
1276 syntax->ssyn_oid, slen );
1277 HASH_Update( &HASHcontext,
1278 mr->smr_oid, mlen );
1279 HASH_Update( &HASHcontext,
1280 value->bv_val, value->bv_len );
1281 HASH_Final( HASHdigest, &HASHcontext );
1283 keys[0] = ber_bvdup( &digest );
1287 return LDAP_SUCCESS;
1290 /* Substrings Index generation function */
1291 int caseExactSubstringsIndexer(
1296 struct berval *prefix,
1297 struct berval **values,
1298 struct berval ***keysp )
1302 struct berval **keys;
1303 HASH_CONTEXT HASHcontext;
1304 unsigned char HASHdigest[HASH_BYTES];
1305 struct berval digest;
1306 digest.bv_val = HASHdigest;
1307 digest.bv_len = sizeof(HASHdigest);
1309 /* we should have at least one value at this point */
1310 assert( values != NULL && values[0] != NULL );
1313 for( i=0; values[i] != NULL; i++ ) {
1314 /* count number of indices to generate */
1315 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1319 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1320 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1321 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1322 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1324 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1328 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1329 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1330 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1334 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1335 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1336 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1337 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1339 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1345 /* no keys to generate */
1347 return LDAP_SUCCESS;
1350 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1352 slen = strlen( syntax->ssyn_oid );
1353 mlen = strlen( mr->smr_oid );
1356 for( i=0; values[i] != NULL; i++ ) {
1358 struct berval *value;
1361 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1363 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1364 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1366 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1367 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1369 for( j=0; j<max; j++ ) {
1370 HASH_Init( &HASHcontext );
1371 if( prefix != NULL && prefix->bv_len > 0 ) {
1372 HASH_Update( &HASHcontext,
1373 prefix->bv_val, prefix->bv_len );
1376 HASH_Update( &HASHcontext,
1377 &pre, sizeof( pre ) );
1378 HASH_Update( &HASHcontext,
1379 syntax->ssyn_oid, slen );
1380 HASH_Update( &HASHcontext,
1381 mr->smr_oid, mlen );
1382 HASH_Update( &HASHcontext,
1384 SLAP_INDEX_SUBSTR_MAXLEN );
1385 HASH_Final( HASHdigest, &HASHcontext );
1387 keys[nkeys++] = ber_bvdup( &digest );
1391 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1392 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1394 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1397 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1398 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1399 HASH_Init( &HASHcontext );
1400 if( prefix != NULL && prefix->bv_len > 0 ) {
1401 HASH_Update( &HASHcontext,
1402 prefix->bv_val, prefix->bv_len );
1404 HASH_Update( &HASHcontext,
1405 &pre, sizeof( pre ) );
1406 HASH_Update( &HASHcontext,
1407 syntax->ssyn_oid, slen );
1408 HASH_Update( &HASHcontext,
1409 mr->smr_oid, mlen );
1410 HASH_Update( &HASHcontext,
1412 HASH_Final( HASHdigest, &HASHcontext );
1414 keys[nkeys++] = ber_bvdup( &digest );
1417 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1418 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1419 HASH_Init( &HASHcontext );
1420 if( prefix != NULL && prefix->bv_len > 0 ) {
1421 HASH_Update( &HASHcontext,
1422 prefix->bv_val, prefix->bv_len );
1424 HASH_Update( &HASHcontext,
1425 &pre, sizeof( pre ) );
1426 HASH_Update( &HASHcontext,
1427 syntax->ssyn_oid, slen );
1428 HASH_Update( &HASHcontext,
1429 mr->smr_oid, mlen );
1430 HASH_Update( &HASHcontext,
1431 &value->bv_val[value->bv_len-j], j );
1432 HASH_Final( HASHdigest, &HASHcontext );
1434 keys[nkeys++] = ber_bvdup( &digest );
1448 return LDAP_SUCCESS;
1451 int caseExactSubstringsFilter(
1456 struct berval *prefix,
1458 struct berval ***keysp )
1460 SubstringsAssertion *sa = assertValue;
1462 ber_len_t nkeys = 0;
1463 size_t slen, mlen, klen;
1464 struct berval **keys;
1465 HASH_CONTEXT HASHcontext;
1466 unsigned char HASHdigest[HASH_BYTES];
1467 struct berval *value;
1468 struct berval digest;
1470 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1471 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1476 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1478 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1479 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1480 /* don't bother accounting for stepping */
1481 nkeys += sa->sa_any[i]->bv_len -
1482 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1487 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1488 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1495 return LDAP_SUCCESS;
1498 digest.bv_val = HASHdigest;
1499 digest.bv_len = sizeof(HASHdigest);
1501 slen = strlen( syntax->ssyn_oid );
1502 mlen = strlen( mr->smr_oid );
1504 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1507 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1508 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1510 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1511 value = sa->sa_initial;
1513 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1514 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1516 HASH_Init( &HASHcontext );
1517 if( prefix != NULL && prefix->bv_len > 0 ) {
1518 HASH_Update( &HASHcontext,
1519 prefix->bv_val, prefix->bv_len );
1521 HASH_Update( &HASHcontext,
1522 &pre, sizeof( pre ) );
1523 HASH_Update( &HASHcontext,
1524 syntax->ssyn_oid, slen );
1525 HASH_Update( &HASHcontext,
1526 mr->smr_oid, mlen );
1527 HASH_Update( &HASHcontext,
1528 value->bv_val, klen );
1529 HASH_Final( HASHdigest, &HASHcontext );
1531 keys[nkeys++] = ber_bvdup( &digest );
1534 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1536 pre = SLAP_INDEX_SUBSTR_PREFIX;
1537 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1539 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1540 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1544 value = sa->sa_any[i];
1547 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1548 j += SLAP_INDEX_SUBSTR_STEP )
1550 HASH_Init( &HASHcontext );
1551 if( prefix != NULL && prefix->bv_len > 0 ) {
1552 HASH_Update( &HASHcontext,
1553 prefix->bv_val, prefix->bv_len );
1555 HASH_Update( &HASHcontext,
1556 &pre, sizeof( pre ) );
1557 HASH_Update( &HASHcontext,
1558 syntax->ssyn_oid, slen );
1559 HASH_Update( &HASHcontext,
1560 mr->smr_oid, mlen );
1561 HASH_Update( &HASHcontext,
1562 &value->bv_val[j], klen );
1563 HASH_Final( HASHdigest, &HASHcontext );
1565 keys[nkeys++] = ber_bvdup( &digest );
1570 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1571 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1573 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1574 value = sa->sa_final;
1576 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1577 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1579 HASH_Init( &HASHcontext );
1580 if( prefix != NULL && prefix->bv_len > 0 ) {
1581 HASH_Update( &HASHcontext,
1582 prefix->bv_val, prefix->bv_len );
1584 HASH_Update( &HASHcontext,
1585 &pre, sizeof( pre ) );
1586 HASH_Update( &HASHcontext,
1587 syntax->ssyn_oid, slen );
1588 HASH_Update( &HASHcontext,
1589 mr->smr_oid, mlen );
1590 HASH_Update( &HASHcontext,
1591 &value->bv_val[value->bv_len-klen], klen );
1592 HASH_Final( HASHdigest, &HASHcontext );
1594 keys[nkeys++] = ber_bvdup( &digest );
1605 return LDAP_SUCCESS;
1614 struct berval *value,
1615 void *assertedValue )
1618 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1620 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1623 match = strncasecmp( value->bv_val,
1624 ((struct berval *) assertedValue)->bv_val,
1630 return LDAP_SUCCESS;
1634 caseIgnoreSubstringsMatch(
1639 struct berval *value,
1640 void *assertedValue )
1643 SubstringsAssertion *sub = assertedValue;
1644 struct berval left = *value;
1648 /* Add up asserted input length */
1649 if( sub->sa_initial ) {
1650 inlen += sub->sa_initial->bv_len;
1653 for(i=0; sub->sa_any[i] != NULL; i++) {
1654 inlen += sub->sa_any[i]->bv_len;
1657 if( sub->sa_final ) {
1658 inlen += sub->sa_final->bv_len;
1661 if( sub->sa_initial ) {
1662 if( inlen > left.bv_len ) {
1668 match = UTF8oncasecmp( sub->sa_initial, &left,
1669 sub->sa_initial->bv_len, 0 );
1671 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1672 sub->sa_initial->bv_len );
1679 left.bv_val += sub->sa_initial->bv_len;
1680 left.bv_len -= sub->sa_initial->bv_len;
1681 inlen -= sub->sa_initial->bv_len;
1684 if( sub->sa_final ) {
1685 if( inlen > left.bv_len ) {
1691 match = UTF8oncasecmp( sub->sa_final, &left,
1692 sub->sa_final->bv_len,
1693 left.bv_len - sub->sa_final->bv_len );
1695 match = strncasecmp( sub->sa_final->bv_val,
1696 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1697 sub->sa_final->bv_len );
1704 left.bv_len -= sub->sa_final->bv_len;
1705 inlen -= sub->sa_final->bv_len;
1709 for(i=0; sub->sa_any[i]; i++) {
1714 if( inlen > left.bv_len ) {
1715 /* not enough length */
1720 if( sub->sa_any[i]->bv_len == 0 ) {
1725 p = UTF8casechr( left.bv_val, sub->sa_any[i]->bv_val );
1727 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1735 idx = p - left.bv_val;
1736 assert( idx < left.bv_len );
1738 if( idx >= left.bv_len ) {
1739 /* this shouldn't happen */
1746 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1747 /* not enough left */
1753 match = UTF8oncasecmp( &left, sub->sa_any[i],
1754 sub->sa_any[i]->bv_len, 0 );
1757 int len = LDAP_UTF8_CHARLEN( left.bv_val );
1763 match = strncasecmp( left.bv_val,
1764 sub->sa_any[i]->bv_val,
1765 sub->sa_any[i]->bv_len );
1775 left.bv_val += sub->sa_any[i]->bv_len;
1776 left.bv_len -= sub->sa_any[i]->bv_len;
1777 inlen -= sub->sa_any[i]->bv_len;
1783 return LDAP_SUCCESS;
1786 /* Index generation function */
1787 int caseIgnoreIndexer(
1792 struct berval *prefix,
1793 struct berval **values,
1794 struct berval ***keysp )
1798 struct berval **keys;
1799 HASH_CONTEXT HASHcontext;
1800 unsigned char HASHdigest[HASH_BYTES];
1801 struct berval digest;
1802 digest.bv_val = HASHdigest;
1803 digest.bv_len = sizeof(HASHdigest);
1805 /* we should have at least one value at this point */
1806 assert( values != NULL && values[0] != NULL );
1808 for( i=0; values[i] != NULL; i++ ) {
1809 /* just count them */
1812 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1814 slen = strlen( syntax->ssyn_oid );
1815 mlen = strlen( mr->smr_oid );
1817 for( i=0; values[i] != NULL; i++ ) {
1818 struct berval *value = ber_bvdup( values[i] );
1819 ldap_pvt_str2upper( value->bv_val );
1821 HASH_Init( &HASHcontext );
1822 if( prefix != NULL && prefix->bv_len > 0 ) {
1823 HASH_Update( &HASHcontext,
1824 prefix->bv_val, prefix->bv_len );
1826 HASH_Update( &HASHcontext,
1827 syntax->ssyn_oid, slen );
1828 HASH_Update( &HASHcontext,
1829 mr->smr_oid, mlen );
1830 HASH_Update( &HASHcontext,
1831 value->bv_val, value->bv_len );
1832 HASH_Final( HASHdigest, &HASHcontext );
1834 ber_bvfree( value );
1836 keys[i] = ber_bvdup( &digest );
1841 return LDAP_SUCCESS;
1844 /* Index generation function */
1845 int caseIgnoreFilter(
1850 struct berval *prefix,
1852 struct berval ***keysp )
1855 struct berval **keys;
1856 HASH_CONTEXT HASHcontext;
1857 unsigned char HASHdigest[HASH_BYTES];
1858 struct berval *value;
1859 struct berval digest;
1860 digest.bv_val = HASHdigest;
1861 digest.bv_len = sizeof(HASHdigest);
1863 slen = strlen( syntax->ssyn_oid );
1864 mlen = strlen( mr->smr_oid );
1866 value = ber_bvdup( (struct berval *) assertValue );
1867 ldap_pvt_str2upper( value->bv_val );
1869 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1871 HASH_Init( &HASHcontext );
1872 if( prefix != NULL && prefix->bv_len > 0 ) {
1873 HASH_Update( &HASHcontext,
1874 prefix->bv_val, prefix->bv_len );
1876 HASH_Update( &HASHcontext,
1877 syntax->ssyn_oid, slen );
1878 HASH_Update( &HASHcontext,
1879 mr->smr_oid, mlen );
1880 HASH_Update( &HASHcontext,
1881 value->bv_val, value->bv_len );
1882 HASH_Final( HASHdigest, &HASHcontext );
1884 keys[0] = ber_bvdup( &digest );
1887 ber_bvfree( value );
1891 return LDAP_SUCCESS;
1894 /* Substrings Index generation function */
1895 int caseIgnoreSubstringsIndexer(
1900 struct berval *prefix,
1901 struct berval **values,
1902 struct berval ***keysp )
1906 struct berval **keys;
1907 HASH_CONTEXT HASHcontext;
1908 unsigned char HASHdigest[HASH_BYTES];
1909 struct berval digest;
1910 digest.bv_val = HASHdigest;
1911 digest.bv_len = sizeof(HASHdigest);
1913 /* we should have at least one value at this point */
1914 assert( values != NULL && values[0] != NULL );
1917 for( i=0; values[i] != NULL; i++ ) {
1918 /* count number of indices to generate */
1919 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1923 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1924 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1925 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1926 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1928 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1932 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1933 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1934 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1938 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1939 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1940 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1941 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1943 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1949 /* no keys to generate */
1951 return LDAP_SUCCESS;
1954 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1956 slen = strlen( syntax->ssyn_oid );
1957 mlen = strlen( mr->smr_oid );
1960 for( i=0; values[i] != NULL; i++ ) {
1962 struct berval *value;
1964 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1966 value = ber_bvdup( values[i] );
1967 ldap_pvt_str2upper( value->bv_val );
1969 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1970 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1972 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1973 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1975 for( j=0; j<max; j++ ) {
1976 HASH_Init( &HASHcontext );
1977 if( prefix != NULL && prefix->bv_len > 0 ) {
1978 HASH_Update( &HASHcontext,
1979 prefix->bv_val, prefix->bv_len );
1982 HASH_Update( &HASHcontext,
1983 &pre, sizeof( pre ) );
1984 HASH_Update( &HASHcontext,
1985 syntax->ssyn_oid, slen );
1986 HASH_Update( &HASHcontext,
1987 mr->smr_oid, mlen );
1988 HASH_Update( &HASHcontext,
1990 SLAP_INDEX_SUBSTR_MAXLEN );
1991 HASH_Final( HASHdigest, &HASHcontext );
1993 keys[nkeys++] = ber_bvdup( &digest );
1997 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1998 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2000 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2003 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2004 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2005 HASH_Init( &HASHcontext );
2006 if( prefix != NULL && prefix->bv_len > 0 ) {
2007 HASH_Update( &HASHcontext,
2008 prefix->bv_val, prefix->bv_len );
2010 HASH_Update( &HASHcontext,
2011 &pre, sizeof( pre ) );
2012 HASH_Update( &HASHcontext,
2013 syntax->ssyn_oid, slen );
2014 HASH_Update( &HASHcontext,
2015 mr->smr_oid, mlen );
2016 HASH_Update( &HASHcontext,
2018 HASH_Final( HASHdigest, &HASHcontext );
2020 keys[nkeys++] = ber_bvdup( &digest );
2023 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2024 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2025 HASH_Init( &HASHcontext );
2026 if( prefix != NULL && prefix->bv_len > 0 ) {
2027 HASH_Update( &HASHcontext,
2028 prefix->bv_val, prefix->bv_len );
2030 HASH_Update( &HASHcontext,
2031 &pre, sizeof( pre ) );
2032 HASH_Update( &HASHcontext,
2033 syntax->ssyn_oid, slen );
2034 HASH_Update( &HASHcontext,
2035 mr->smr_oid, mlen );
2036 HASH_Update( &HASHcontext,
2037 &value->bv_val[value->bv_len-j], j );
2038 HASH_Final( HASHdigest, &HASHcontext );
2040 keys[nkeys++] = ber_bvdup( &digest );
2045 ber_bvfree( value );
2056 return LDAP_SUCCESS;
2059 int caseIgnoreSubstringsFilter(
2064 struct berval *prefix,
2066 struct berval ***keysp )
2068 SubstringsAssertion *sa = assertValue;
2070 ber_len_t nkeys = 0;
2071 size_t slen, mlen, klen;
2072 struct berval **keys;
2073 HASH_CONTEXT HASHcontext;
2074 unsigned char HASHdigest[HASH_BYTES];
2075 struct berval *value;
2076 struct berval digest;
2078 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2079 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2084 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2086 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2087 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2088 /* don't bother accounting for stepping */
2089 nkeys += sa->sa_any[i]->bv_len -
2090 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2095 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2096 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2103 return LDAP_SUCCESS;
2106 digest.bv_val = HASHdigest;
2107 digest.bv_len = sizeof(HASHdigest);
2109 slen = strlen( syntax->ssyn_oid );
2110 mlen = strlen( mr->smr_oid );
2112 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2115 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2116 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2118 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2119 value = ber_bvdup( sa->sa_initial );
2120 ldap_pvt_str2upper( value->bv_val );
2122 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2123 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2125 HASH_Init( &HASHcontext );
2126 if( prefix != NULL && prefix->bv_len > 0 ) {
2127 HASH_Update( &HASHcontext,
2128 prefix->bv_val, prefix->bv_len );
2130 HASH_Update( &HASHcontext,
2131 &pre, sizeof( pre ) );
2132 HASH_Update( &HASHcontext,
2133 syntax->ssyn_oid, slen );
2134 HASH_Update( &HASHcontext,
2135 mr->smr_oid, mlen );
2136 HASH_Update( &HASHcontext,
2137 value->bv_val, klen );
2138 HASH_Final( HASHdigest, &HASHcontext );
2140 ber_bvfree( value );
2141 keys[nkeys++] = ber_bvdup( &digest );
2144 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2146 pre = SLAP_INDEX_SUBSTR_PREFIX;
2147 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2149 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2150 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2154 value = ber_bvdup( sa->sa_any[i] );
2155 ldap_pvt_str2upper( value->bv_val );
2158 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2159 j += SLAP_INDEX_SUBSTR_STEP )
2161 HASH_Init( &HASHcontext );
2162 if( prefix != NULL && prefix->bv_len > 0 ) {
2163 HASH_Update( &HASHcontext,
2164 prefix->bv_val, prefix->bv_len );
2166 HASH_Update( &HASHcontext,
2167 &pre, sizeof( pre ) );
2168 HASH_Update( &HASHcontext,
2169 syntax->ssyn_oid, slen );
2170 HASH_Update( &HASHcontext,
2171 mr->smr_oid, mlen );
2172 HASH_Update( &HASHcontext,
2173 &value->bv_val[j], klen );
2174 HASH_Final( HASHdigest, &HASHcontext );
2176 keys[nkeys++] = ber_bvdup( &digest );
2179 ber_bvfree( value );
2183 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2184 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2186 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2187 value = ber_bvdup( sa->sa_final );
2188 ldap_pvt_str2upper( value->bv_val );
2190 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2191 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2193 HASH_Init( &HASHcontext );
2194 if( prefix != NULL && prefix->bv_len > 0 ) {
2195 HASH_Update( &HASHcontext,
2196 prefix->bv_val, prefix->bv_len );
2198 HASH_Update( &HASHcontext,
2199 &pre, sizeof( pre ) );
2200 HASH_Update( &HASHcontext,
2201 syntax->ssyn_oid, slen );
2202 HASH_Update( &HASHcontext,
2203 mr->smr_oid, mlen );
2204 HASH_Update( &HASHcontext,
2205 &value->bv_val[value->bv_len-klen], klen );
2206 HASH_Final( HASHdigest, &HASHcontext );
2208 ber_bvfree( value );
2209 keys[nkeys++] = ber_bvdup( &digest );
2220 return LDAP_SUCCESS;
2226 struct berval *val )
2230 if( val->bv_len == 0 ) {
2231 /* disallow empty strings */
2232 return LDAP_INVALID_SYNTAX;
2235 if( OID_LEADCHAR(val->bv_val[0]) ) {
2237 for(i=1; i < val->bv_len; i++) {
2238 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2239 if( dot++ ) return 1;
2240 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2243 return LDAP_INVALID_SYNTAX;
2247 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2249 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2250 for(i=1; i < val->bv_len; i++) {
2251 if( !DESC_CHAR(val->bv_val[i] ) ) {
2252 return LDAP_INVALID_SYNTAX;
2256 return LDAP_SUCCESS;
2259 return LDAP_INVALID_SYNTAX;
2265 struct berval *val )
2269 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2271 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
2272 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2273 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2274 return LDAP_INVALID_SYNTAX;
2277 for(i=1; i < val->bv_len; i++) {
2278 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2281 return LDAP_SUCCESS;
2288 struct berval **normalized )
2291 struct berval *newval;
2297 negative = ( *p == '-' );
2298 if( *p == '-' || *p == '+' ) p++;
2300 /* Ignore leading zeros */
2301 while ( *p == '0' ) p++;
2303 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2306 newval->bv_val = ch_strdup("0");
2311 newval->bv_val = ch_malloc( val->bv_len + 1 );
2315 newval->bv_val[newval->bv_len++] = '-';
2318 for( ; *p != '\0'; p++ ) {
2319 newval->bv_val[newval->bv_len++] = *p;
2323 *normalized = newval;
2324 return LDAP_SUCCESS;
2328 countryStringValidate(
2330 struct berval *val )
2334 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2336 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2337 return LDAP_INVALID_SYNTAX;
2339 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2340 return LDAP_INVALID_SYNTAX;
2343 return LDAP_SUCCESS;
2347 printableStringValidate(
2349 struct berval *val )
2353 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2355 for(i=0; i < val->bv_len; i++) {
2356 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2357 return LDAP_INVALID_SYNTAX;
2361 return LDAP_SUCCESS;
2365 printablesStringValidate(
2367 struct berval *val )
2371 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2373 for(i=0; i < val->bv_len; i++) {
2374 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2375 return LDAP_INVALID_SYNTAX;
2379 return LDAP_SUCCESS;
2385 struct berval *val )
2389 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2391 for(i=0; i < val->bv_len; i++) {
2392 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2395 return LDAP_SUCCESS;
2402 struct berval **normalized )
2404 struct berval *newval;
2407 newval = ch_malloc( sizeof( struct berval ) );
2411 /* Ignore initial whitespace */
2412 while ( ASCII_SPACE( *p ) ) {
2418 return LDAP_INVALID_SYNTAX;
2421 newval->bv_val = ch_strdup( p );
2422 p = q = newval->bv_val;
2425 if ( ASCII_SPACE( *p ) ) {
2428 /* Ignore the extra whitespace */
2429 while ( ASCII_SPACE( *p ) ) {
2437 assert( *newval->bv_val );
2438 assert( newval->bv_val < p );
2441 /* cannot start with a space */
2442 assert( !ASCII_SPACE(*newval->bv_val) );
2445 * If the string ended in space, backup the pointer one
2446 * position. One is enough because the above loop collapsed
2447 * all whitespace to a single space.
2450 if ( ASCII_SPACE( q[-1] ) ) {
2454 /* cannot end with a space */
2455 assert( !ASCII_SPACE( q[-1] ) );
2457 /* null terminate */
2460 newval->bv_len = q - newval->bv_val;
2461 *normalized = newval;
2463 return LDAP_SUCCESS;
2472 struct berval *value,
2473 void *assertedValue )
2475 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2478 match = strncmp( value->bv_val,
2479 ((struct berval *) assertedValue)->bv_val,
2484 return LDAP_SUCCESS;
2488 caseExactIA5SubstringsMatch(
2493 struct berval *value,
2494 void *assertedValue )
2497 SubstringsAssertion *sub = assertedValue;
2498 struct berval left = *value;
2502 /* Add up asserted input length */
2503 if( sub->sa_initial ) {
2504 inlen += sub->sa_initial->bv_len;
2507 for(i=0; sub->sa_any[i] != NULL; i++) {
2508 inlen += sub->sa_any[i]->bv_len;
2511 if( sub->sa_final ) {
2512 inlen += sub->sa_final->bv_len;
2515 if( sub->sa_initial ) {
2516 if( inlen > left.bv_len ) {
2521 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2522 sub->sa_initial->bv_len );
2528 left.bv_val += sub->sa_initial->bv_len;
2529 left.bv_len -= sub->sa_initial->bv_len;
2530 inlen -= sub->sa_initial->bv_len;
2533 if( sub->sa_final ) {
2534 if( inlen > left.bv_len ) {
2539 match = strncmp( sub->sa_final->bv_val,
2540 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2541 sub->sa_final->bv_len );
2547 left.bv_len -= sub->sa_final->bv_len;
2548 inlen -= sub->sa_final->bv_len;
2552 for(i=0; sub->sa_any[i]; i++) {
2557 if( inlen > left.bv_len ) {
2558 /* not enough length */
2563 if( sub->sa_any[i]->bv_len == 0 ) {
2567 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2574 idx = p - left.bv_val;
2575 assert( idx < left.bv_len );
2577 if( idx >= left.bv_len ) {
2578 /* this shouldn't happen */
2585 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2586 /* not enough left */
2591 match = strncmp( left.bv_val,
2592 sub->sa_any[i]->bv_val,
2593 sub->sa_any[i]->bv_len );
2601 left.bv_val += sub->sa_any[i]->bv_len;
2602 left.bv_len -= sub->sa_any[i]->bv_len;
2603 inlen -= sub->sa_any[i]->bv_len;
2609 return LDAP_SUCCESS;
2612 /* Index generation function */
2613 int caseExactIA5Indexer(
2618 struct berval *prefix,
2619 struct berval **values,
2620 struct berval ***keysp )
2624 struct berval **keys;
2625 HASH_CONTEXT HASHcontext;
2626 unsigned char HASHdigest[HASH_BYTES];
2627 struct berval digest;
2628 digest.bv_val = HASHdigest;
2629 digest.bv_len = sizeof(HASHdigest);
2631 /* we should have at least one value at this point */
2632 assert( values != NULL && values[0] != NULL );
2634 for( i=0; values[i] != NULL; i++ ) {
2635 /* just count them */
2638 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2640 slen = strlen( syntax->ssyn_oid );
2641 mlen = strlen( mr->smr_oid );
2643 for( i=0; values[i] != NULL; i++ ) {
2644 struct berval *value = values[i];
2646 HASH_Init( &HASHcontext );
2647 if( prefix != NULL && prefix->bv_len > 0 ) {
2648 HASH_Update( &HASHcontext,
2649 prefix->bv_val, prefix->bv_len );
2651 HASH_Update( &HASHcontext,
2652 syntax->ssyn_oid, slen );
2653 HASH_Update( &HASHcontext,
2654 mr->smr_oid, mlen );
2655 HASH_Update( &HASHcontext,
2656 value->bv_val, value->bv_len );
2657 HASH_Final( HASHdigest, &HASHcontext );
2659 keys[i] = ber_bvdup( &digest );
2664 return LDAP_SUCCESS;
2667 /* Index generation function */
2668 int caseExactIA5Filter(
2673 struct berval *prefix,
2675 struct berval ***keysp )
2678 struct berval **keys;
2679 HASH_CONTEXT HASHcontext;
2680 unsigned char HASHdigest[HASH_BYTES];
2681 struct berval *value;
2682 struct berval digest;
2683 digest.bv_val = HASHdigest;
2684 digest.bv_len = sizeof(HASHdigest);
2686 slen = strlen( syntax->ssyn_oid );
2687 mlen = strlen( mr->smr_oid );
2689 value = (struct berval *) assertValue;
2691 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2693 HASH_Init( &HASHcontext );
2694 if( prefix != NULL && prefix->bv_len > 0 ) {
2695 HASH_Update( &HASHcontext,
2696 prefix->bv_val, prefix->bv_len );
2698 HASH_Update( &HASHcontext,
2699 syntax->ssyn_oid, slen );
2700 HASH_Update( &HASHcontext,
2701 mr->smr_oid, mlen );
2702 HASH_Update( &HASHcontext,
2703 value->bv_val, value->bv_len );
2704 HASH_Final( HASHdigest, &HASHcontext );
2706 keys[0] = ber_bvdup( &digest );
2710 return LDAP_SUCCESS;
2713 /* Substrings Index generation function */
2714 int caseExactIA5SubstringsIndexer(
2719 struct berval *prefix,
2720 struct berval **values,
2721 struct berval ***keysp )
2725 struct berval **keys;
2726 HASH_CONTEXT HASHcontext;
2727 unsigned char HASHdigest[HASH_BYTES];
2728 struct berval digest;
2729 digest.bv_val = HASHdigest;
2730 digest.bv_len = sizeof(HASHdigest);
2732 /* we should have at least one value at this point */
2733 assert( values != NULL && values[0] != NULL );
2736 for( i=0; values[i] != NULL; i++ ) {
2737 /* count number of indices to generate */
2738 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2742 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2743 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2744 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2745 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2747 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2751 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2752 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2753 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2757 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2758 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2759 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2760 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2762 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2768 /* no keys to generate */
2770 return LDAP_SUCCESS;
2773 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2775 slen = strlen( syntax->ssyn_oid );
2776 mlen = strlen( mr->smr_oid );
2779 for( i=0; values[i] != NULL; i++ ) {
2781 struct berval *value;
2784 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2786 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2787 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2789 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2790 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2792 for( j=0; j<max; j++ ) {
2793 HASH_Init( &HASHcontext );
2794 if( prefix != NULL && prefix->bv_len > 0 ) {
2795 HASH_Update( &HASHcontext,
2796 prefix->bv_val, prefix->bv_len );
2799 HASH_Update( &HASHcontext,
2800 &pre, sizeof( pre ) );
2801 HASH_Update( &HASHcontext,
2802 syntax->ssyn_oid, slen );
2803 HASH_Update( &HASHcontext,
2804 mr->smr_oid, mlen );
2805 HASH_Update( &HASHcontext,
2807 SLAP_INDEX_SUBSTR_MAXLEN );
2808 HASH_Final( HASHdigest, &HASHcontext );
2810 keys[nkeys++] = ber_bvdup( &digest );
2814 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2815 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2817 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2820 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2821 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2822 HASH_Init( &HASHcontext );
2823 if( prefix != NULL && prefix->bv_len > 0 ) {
2824 HASH_Update( &HASHcontext,
2825 prefix->bv_val, prefix->bv_len );
2827 HASH_Update( &HASHcontext,
2828 &pre, sizeof( pre ) );
2829 HASH_Update( &HASHcontext,
2830 syntax->ssyn_oid, slen );
2831 HASH_Update( &HASHcontext,
2832 mr->smr_oid, mlen );
2833 HASH_Update( &HASHcontext,
2835 HASH_Final( HASHdigest, &HASHcontext );
2837 keys[nkeys++] = ber_bvdup( &digest );
2840 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2841 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2842 HASH_Init( &HASHcontext );
2843 if( prefix != NULL && prefix->bv_len > 0 ) {
2844 HASH_Update( &HASHcontext,
2845 prefix->bv_val, prefix->bv_len );
2847 HASH_Update( &HASHcontext,
2848 &pre, sizeof( pre ) );
2849 HASH_Update( &HASHcontext,
2850 syntax->ssyn_oid, slen );
2851 HASH_Update( &HASHcontext,
2852 mr->smr_oid, mlen );
2853 HASH_Update( &HASHcontext,
2854 &value->bv_val[value->bv_len-j], j );
2855 HASH_Final( HASHdigest, &HASHcontext );
2857 keys[nkeys++] = ber_bvdup( &digest );
2871 return LDAP_SUCCESS;
2874 int caseExactIA5SubstringsFilter(
2879 struct berval *prefix,
2881 struct berval ***keysp )
2883 SubstringsAssertion *sa = assertValue;
2885 ber_len_t nkeys = 0;
2886 size_t slen, mlen, klen;
2887 struct berval **keys;
2888 HASH_CONTEXT HASHcontext;
2889 unsigned char HASHdigest[HASH_BYTES];
2890 struct berval *value;
2891 struct berval digest;
2893 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2894 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2899 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2901 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2902 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2903 /* don't bother accounting for stepping */
2904 nkeys += sa->sa_any[i]->bv_len -
2905 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2910 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2911 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2918 return LDAP_SUCCESS;
2921 digest.bv_val = HASHdigest;
2922 digest.bv_len = sizeof(HASHdigest);
2924 slen = strlen( syntax->ssyn_oid );
2925 mlen = strlen( mr->smr_oid );
2927 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2930 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2931 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2933 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2934 value = sa->sa_initial;
2936 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2937 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2939 HASH_Init( &HASHcontext );
2940 if( prefix != NULL && prefix->bv_len > 0 ) {
2941 HASH_Update( &HASHcontext,
2942 prefix->bv_val, prefix->bv_len );
2944 HASH_Update( &HASHcontext,
2945 &pre, sizeof( pre ) );
2946 HASH_Update( &HASHcontext,
2947 syntax->ssyn_oid, slen );
2948 HASH_Update( &HASHcontext,
2949 mr->smr_oid, mlen );
2950 HASH_Update( &HASHcontext,
2951 value->bv_val, klen );
2952 HASH_Final( HASHdigest, &HASHcontext );
2954 keys[nkeys++] = ber_bvdup( &digest );
2957 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2959 pre = SLAP_INDEX_SUBSTR_PREFIX;
2960 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2962 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2963 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2967 value = sa->sa_any[i];
2970 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2971 j += SLAP_INDEX_SUBSTR_STEP )
2973 HASH_Init( &HASHcontext );
2974 if( prefix != NULL && prefix->bv_len > 0 ) {
2975 HASH_Update( &HASHcontext,
2976 prefix->bv_val, prefix->bv_len );
2978 HASH_Update( &HASHcontext,
2979 &pre, sizeof( pre ) );
2980 HASH_Update( &HASHcontext,
2981 syntax->ssyn_oid, slen );
2982 HASH_Update( &HASHcontext,
2983 mr->smr_oid, mlen );
2984 HASH_Update( &HASHcontext,
2985 &value->bv_val[j], klen );
2986 HASH_Final( HASHdigest, &HASHcontext );
2988 keys[nkeys++] = ber_bvdup( &digest );
2993 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2994 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2996 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2997 value = sa->sa_final;
2999 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3000 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3002 HASH_Init( &HASHcontext );
3003 if( prefix != NULL && prefix->bv_len > 0 ) {
3004 HASH_Update( &HASHcontext,
3005 prefix->bv_val, prefix->bv_len );
3007 HASH_Update( &HASHcontext,
3008 &pre, sizeof( pre ) );
3009 HASH_Update( &HASHcontext,
3010 syntax->ssyn_oid, slen );
3011 HASH_Update( &HASHcontext,
3012 mr->smr_oid, mlen );
3013 HASH_Update( &HASHcontext,
3014 &value->bv_val[value->bv_len-klen], klen );
3015 HASH_Final( HASHdigest, &HASHcontext );
3017 keys[nkeys++] = ber_bvdup( &digest );
3028 return LDAP_SUCCESS;
3037 struct berval *value,
3038 void *assertedValue )
3040 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3042 if( match == 0 && value->bv_len ) {
3043 match = strncasecmp( value->bv_val,
3044 ((struct berval *) assertedValue)->bv_val,
3049 return LDAP_SUCCESS;
3053 caseIgnoreIA5SubstringsMatch(
3058 struct berval *value,
3059 void *assertedValue )
3062 SubstringsAssertion *sub = assertedValue;
3063 struct berval left = *value;
3067 /* Add up asserted input length */
3068 if( sub->sa_initial ) {
3069 inlen += sub->sa_initial->bv_len;
3072 for(i=0; sub->sa_any[i] != NULL; i++) {
3073 inlen += sub->sa_any[i]->bv_len;
3076 if( sub->sa_final ) {
3077 inlen += sub->sa_final->bv_len;
3080 if( sub->sa_initial ) {
3081 if( inlen > left.bv_len ) {
3086 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3087 sub->sa_initial->bv_len );
3093 left.bv_val += sub->sa_initial->bv_len;
3094 left.bv_len -= sub->sa_initial->bv_len;
3095 inlen -= sub->sa_initial->bv_len;
3098 if( sub->sa_final ) {
3099 if( inlen > left.bv_len ) {
3104 match = strncasecmp( sub->sa_final->bv_val,
3105 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3106 sub->sa_final->bv_len );
3112 left.bv_len -= sub->sa_final->bv_len;
3113 inlen -= sub->sa_final->bv_len;
3117 for(i=0; sub->sa_any[i]; i++) {
3122 if( inlen > left.bv_len ) {
3123 /* not enough length */
3128 if( sub->sa_any[i]->bv_len == 0 ) {
3132 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3139 idx = p - left.bv_val;
3140 assert( idx < left.bv_len );
3142 if( idx >= left.bv_len ) {
3143 /* this shouldn't happen */
3150 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3151 /* not enough left */
3156 match = strncasecmp( left.bv_val,
3157 sub->sa_any[i]->bv_val,
3158 sub->sa_any[i]->bv_len );
3167 left.bv_val += sub->sa_any[i]->bv_len;
3168 left.bv_len -= sub->sa_any[i]->bv_len;
3169 inlen -= sub->sa_any[i]->bv_len;
3175 return LDAP_SUCCESS;
3178 /* Index generation function */
3179 int caseIgnoreIA5Indexer(
3184 struct berval *prefix,
3185 struct berval **values,
3186 struct berval ***keysp )
3190 struct berval **keys;
3191 HASH_CONTEXT HASHcontext;
3192 unsigned char HASHdigest[HASH_BYTES];
3193 struct berval digest;
3194 digest.bv_val = HASHdigest;
3195 digest.bv_len = sizeof(HASHdigest);
3197 /* we should have at least one value at this point */
3198 assert( values != NULL && values[0] != NULL );
3200 for( i=0; values[i] != NULL; i++ ) {
3201 /* just count them */
3204 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3206 slen = strlen( syntax->ssyn_oid );
3207 mlen = strlen( mr->smr_oid );
3209 for( i=0; values[i] != NULL; i++ ) {
3210 struct berval *value = ber_bvdup( values[i] );
3211 ldap_pvt_str2upper( value->bv_val );
3213 HASH_Init( &HASHcontext );
3214 if( prefix != NULL && prefix->bv_len > 0 ) {
3215 HASH_Update( &HASHcontext,
3216 prefix->bv_val, prefix->bv_len );
3218 HASH_Update( &HASHcontext,
3219 syntax->ssyn_oid, slen );
3220 HASH_Update( &HASHcontext,
3221 mr->smr_oid, mlen );
3222 HASH_Update( &HASHcontext,
3223 value->bv_val, value->bv_len );
3224 HASH_Final( HASHdigest, &HASHcontext );
3226 ber_bvfree( value );
3228 keys[i] = ber_bvdup( &digest );
3233 return LDAP_SUCCESS;
3236 /* Index generation function */
3237 int caseIgnoreIA5Filter(
3242 struct berval *prefix,
3244 struct berval ***keysp )
3247 struct berval **keys;
3248 HASH_CONTEXT HASHcontext;
3249 unsigned char HASHdigest[HASH_BYTES];
3250 struct berval *value;
3251 struct berval digest;
3252 digest.bv_val = HASHdigest;
3253 digest.bv_len = sizeof(HASHdigest);
3255 slen = strlen( syntax->ssyn_oid );
3256 mlen = strlen( mr->smr_oid );
3258 value = ber_bvdup( (struct berval *) assertValue );
3259 ldap_pvt_str2upper( value->bv_val );
3261 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3263 HASH_Init( &HASHcontext );
3264 if( prefix != NULL && prefix->bv_len > 0 ) {
3265 HASH_Update( &HASHcontext,
3266 prefix->bv_val, prefix->bv_len );
3268 HASH_Update( &HASHcontext,
3269 syntax->ssyn_oid, slen );
3270 HASH_Update( &HASHcontext,
3271 mr->smr_oid, mlen );
3272 HASH_Update( &HASHcontext,
3273 value->bv_val, value->bv_len );
3274 HASH_Final( HASHdigest, &HASHcontext );
3276 keys[0] = ber_bvdup( &digest );
3279 ber_bvfree( value );
3283 return LDAP_SUCCESS;
3286 /* Substrings Index generation function */
3287 int caseIgnoreIA5SubstringsIndexer(
3292 struct berval *prefix,
3293 struct berval **values,
3294 struct berval ***keysp )
3298 struct berval **keys;
3299 HASH_CONTEXT HASHcontext;
3300 unsigned char HASHdigest[HASH_BYTES];
3301 struct berval digest;
3302 digest.bv_val = HASHdigest;
3303 digest.bv_len = sizeof(HASHdigest);
3305 /* we should have at least one value at this point */
3306 assert( values != NULL && values[0] != NULL );
3309 for( i=0; values[i] != NULL; i++ ) {
3310 /* count number of indices to generate */
3311 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3315 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3316 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3317 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3318 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3320 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3324 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3325 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3326 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3330 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3331 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3332 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3333 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3335 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3341 /* no keys to generate */
3343 return LDAP_SUCCESS;
3346 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3348 slen = strlen( syntax->ssyn_oid );
3349 mlen = strlen( mr->smr_oid );
3352 for( i=0; values[i] != NULL; i++ ) {
3354 struct berval *value;
3356 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3358 value = ber_bvdup( values[i] );
3359 ldap_pvt_str2upper( value->bv_val );
3361 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3362 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3364 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3365 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3367 for( j=0; j<max; j++ ) {
3368 HASH_Init( &HASHcontext );
3369 if( prefix != NULL && prefix->bv_len > 0 ) {
3370 HASH_Update( &HASHcontext,
3371 prefix->bv_val, prefix->bv_len );
3374 HASH_Update( &HASHcontext,
3375 &pre, sizeof( pre ) );
3376 HASH_Update( &HASHcontext,
3377 syntax->ssyn_oid, slen );
3378 HASH_Update( &HASHcontext,
3379 mr->smr_oid, mlen );
3380 HASH_Update( &HASHcontext,
3382 SLAP_INDEX_SUBSTR_MAXLEN );
3383 HASH_Final( HASHdigest, &HASHcontext );
3385 keys[nkeys++] = ber_bvdup( &digest );
3389 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3390 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3392 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3395 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3396 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3397 HASH_Init( &HASHcontext );
3398 if( prefix != NULL && prefix->bv_len > 0 ) {
3399 HASH_Update( &HASHcontext,
3400 prefix->bv_val, prefix->bv_len );
3402 HASH_Update( &HASHcontext,
3403 &pre, sizeof( pre ) );
3404 HASH_Update( &HASHcontext,
3405 syntax->ssyn_oid, slen );
3406 HASH_Update( &HASHcontext,
3407 mr->smr_oid, mlen );
3408 HASH_Update( &HASHcontext,
3410 HASH_Final( HASHdigest, &HASHcontext );
3412 keys[nkeys++] = ber_bvdup( &digest );
3415 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3416 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3417 HASH_Init( &HASHcontext );
3418 if( prefix != NULL && prefix->bv_len > 0 ) {
3419 HASH_Update( &HASHcontext,
3420 prefix->bv_val, prefix->bv_len );
3422 HASH_Update( &HASHcontext,
3423 &pre, sizeof( pre ) );
3424 HASH_Update( &HASHcontext,
3425 syntax->ssyn_oid, slen );
3426 HASH_Update( &HASHcontext,
3427 mr->smr_oid, mlen );
3428 HASH_Update( &HASHcontext,
3429 &value->bv_val[value->bv_len-j], j );
3430 HASH_Final( HASHdigest, &HASHcontext );
3432 keys[nkeys++] = ber_bvdup( &digest );
3437 ber_bvfree( value );
3448 return LDAP_SUCCESS;
3451 int caseIgnoreIA5SubstringsFilter(
3456 struct berval *prefix,
3458 struct berval ***keysp )
3460 SubstringsAssertion *sa = assertValue;
3462 ber_len_t nkeys = 0;
3463 size_t slen, mlen, klen;
3464 struct berval **keys;
3465 HASH_CONTEXT HASHcontext;
3466 unsigned char HASHdigest[HASH_BYTES];
3467 struct berval *value;
3468 struct berval digest;
3470 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3471 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3476 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3478 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3479 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3480 /* don't bother accounting for stepping */
3481 nkeys += sa->sa_any[i]->bv_len -
3482 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3487 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3488 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3495 return LDAP_SUCCESS;
3498 digest.bv_val = HASHdigest;
3499 digest.bv_len = sizeof(HASHdigest);
3501 slen = strlen( syntax->ssyn_oid );
3502 mlen = strlen( mr->smr_oid );
3504 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3507 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3508 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3510 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3511 value = ber_bvdup( sa->sa_initial );
3512 ldap_pvt_str2upper( value->bv_val );
3514 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3515 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3517 HASH_Init( &HASHcontext );
3518 if( prefix != NULL && prefix->bv_len > 0 ) {
3519 HASH_Update( &HASHcontext,
3520 prefix->bv_val, prefix->bv_len );
3522 HASH_Update( &HASHcontext,
3523 &pre, sizeof( pre ) );
3524 HASH_Update( &HASHcontext,
3525 syntax->ssyn_oid, slen );
3526 HASH_Update( &HASHcontext,
3527 mr->smr_oid, mlen );
3528 HASH_Update( &HASHcontext,
3529 value->bv_val, klen );
3530 HASH_Final( HASHdigest, &HASHcontext );
3532 ber_bvfree( value );
3533 keys[nkeys++] = ber_bvdup( &digest );
3536 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3538 pre = SLAP_INDEX_SUBSTR_PREFIX;
3539 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3541 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3542 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3546 value = ber_bvdup( sa->sa_any[i] );
3547 ldap_pvt_str2upper( value->bv_val );
3550 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3551 j += SLAP_INDEX_SUBSTR_STEP )
3553 HASH_Init( &HASHcontext );
3554 if( prefix != NULL && prefix->bv_len > 0 ) {
3555 HASH_Update( &HASHcontext,
3556 prefix->bv_val, prefix->bv_len );
3558 HASH_Update( &HASHcontext,
3559 &pre, sizeof( pre ) );
3560 HASH_Update( &HASHcontext,
3561 syntax->ssyn_oid, slen );
3562 HASH_Update( &HASHcontext,
3563 mr->smr_oid, mlen );
3564 HASH_Update( &HASHcontext,
3565 &value->bv_val[j], klen );
3566 HASH_Final( HASHdigest, &HASHcontext );
3568 keys[nkeys++] = ber_bvdup( &digest );
3571 ber_bvfree( value );
3575 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3576 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3578 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3579 value = ber_bvdup( sa->sa_final );
3580 ldap_pvt_str2upper( value->bv_val );
3582 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3583 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3585 HASH_Init( &HASHcontext );
3586 if( prefix != NULL && prefix->bv_len > 0 ) {
3587 HASH_Update( &HASHcontext,
3588 prefix->bv_val, prefix->bv_len );
3590 HASH_Update( &HASHcontext,
3591 &pre, sizeof( pre ) );
3592 HASH_Update( &HASHcontext,
3593 syntax->ssyn_oid, slen );
3594 HASH_Update( &HASHcontext,
3595 mr->smr_oid, mlen );
3596 HASH_Update( &HASHcontext,
3597 &value->bv_val[value->bv_len-klen], klen );
3598 HASH_Final( HASHdigest, &HASHcontext );
3600 ber_bvfree( value );
3601 keys[nkeys++] = ber_bvdup( &digest );
3612 return LDAP_SUCCESS;
3616 numericStringValidate(
3622 /* disallow empty numeric strings */
3624 for(i=0; i < in->bv_len; i++) {
3625 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3626 return LDAP_INVALID_SYNTAX;
3630 return LDAP_SUCCESS;
3634 numericStringNormalize(
3637 struct berval **normalized )
3639 /* removal all spaces */
3640 struct berval *newval;
3643 newval = ch_malloc( sizeof( struct berval ) );
3644 newval->bv_val = ch_malloc( val->bv_len + 1 );
3650 if ( ASCII_SPACE( *p ) ) {
3651 /* Ignore whitespace */
3658 assert( newval->bv_val < p );
3661 /* null terminate */
3664 newval->bv_len = q - newval->bv_val;
3665 *normalized = newval;
3667 return LDAP_SUCCESS;
3671 objectIdentifierFirstComponentMatch(
3676 struct berval *value,
3677 void *assertedValue )
3679 int rc = LDAP_SUCCESS;
3681 struct berval *asserted = (struct berval *) assertedValue;
3685 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3686 return LDAP_INVALID_SYNTAX;
3689 /* trim leading white space */
3690 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3694 /* grab next word */
3695 oid.bv_val = &value->bv_val[i];
3696 oid.bv_len = value->bv_len - i;
3697 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3702 /* insert attributeTypes, objectclass check here */
3703 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3704 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3707 char *stored = ch_malloc( oid.bv_len + 1 );
3708 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3709 stored[oid.bv_len] = '\0';
3711 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3712 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3713 MatchingRule *stored_mr = mr_find( stored );
3715 if( asserted_mr == NULL ) {
3716 rc = SLAPD_COMPARE_UNDEFINED;
3718 match = asserted_mr != stored_mr;
3721 } else if ( !strcmp( syntax->ssyn_oid,
3722 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3724 AttributeType *asserted_at = at_find( asserted->bv_val );
3725 AttributeType *stored_at = at_find( stored );
3727 if( asserted_at == NULL ) {
3728 rc = SLAPD_COMPARE_UNDEFINED;
3730 match = asserted_at != stored_at;
3733 } else if ( !strcmp( syntax->ssyn_oid,
3734 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3736 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3737 ObjectClass *stored_oc = oc_find( stored );
3739 if( asserted_oc == NULL ) {
3740 rc = SLAPD_COMPARE_UNDEFINED;
3742 match = asserted_oc != stored_oc;
3750 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3751 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3752 match, value->bv_val, asserted->bv_val ));
3754 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3755 "%d\n\t\"%s\"\n\t\"%s\"\n",
3756 match, value->bv_val, asserted->bv_val );
3760 if( rc == LDAP_SUCCESS ) *matchp = match;
3765 check_time_syntax (struct berval *val,
3769 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3770 static int mdays[2][12] = {
3771 /* non-leap years */
3772 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3774 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3777 int part, c, tzoffset, leapyear = 0 ;
3779 if( val->bv_len == 0 ) {
3780 return LDAP_INVALID_SYNTAX;
3783 p = (char *)val->bv_val;
3784 e = p + val->bv_len;
3786 /* Ignore initial whitespace */
3787 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3791 if (e - p < 13 - (2 * start)) {
3792 return LDAP_INVALID_SYNTAX;
3795 for (part = 0; part < 9; part++) {
3799 for (part = start; part < 7; part++) {
3801 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3808 return LDAP_INVALID_SYNTAX;
3810 if (c < 0 || c > 9) {
3811 return LDAP_INVALID_SYNTAX;
3817 return LDAP_INVALID_SYNTAX;
3819 if (c < 0 || c > 9) {
3820 return LDAP_INVALID_SYNTAX;
3825 if (part == 2 || part == 3) {
3828 if (parts[part] < 0) {
3829 return LDAP_INVALID_SYNTAX;
3831 if (parts[part] > ceiling[part]) {
3832 return LDAP_INVALID_SYNTAX;
3836 /* leapyear check for the Gregorian calendar (year>1581) */
3837 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3838 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3843 if (parts[3] > mdays[leapyear][parts[2]]) {
3844 return LDAP_INVALID_SYNTAX;
3849 tzoffset = 0; /* UTC */
3850 } else if (c != '+' && c != '-') {
3851 return LDAP_INVALID_SYNTAX;
3855 } else /* c == '+' */ {
3860 return LDAP_INVALID_SYNTAX;
3863 for (part = 7; part < 9; part++) {
3865 if (c < 0 || c > 9) {
3866 return LDAP_INVALID_SYNTAX;
3871 if (c < 0 || c > 9) {
3872 return LDAP_INVALID_SYNTAX;
3876 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3877 return LDAP_INVALID_SYNTAX;
3882 /* Ignore trailing whitespace */
3883 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3887 return LDAP_INVALID_SYNTAX;
3890 switch ( tzoffset ) {
3891 case -1: /* negativ offset to UTC, ie west of Greenwich */
3892 parts[4] += parts[7];
3893 parts[5] += parts[8];
3894 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3898 c = mdays[leapyear][parts[2]];
3900 if (parts[part] > c) {
3901 parts[part] -= c + 1;
3906 case 1: /* positive offset to UTC, ie east of Greenwich */
3907 parts[4] -= parts[7];
3908 parts[5] -= parts[8];
3909 for (part = 6; --part > 0; ) {
3913 /* first arg to % needs to be non negativ */
3914 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3916 if (parts[part] < 0) {
3917 parts[part] += c + 1;
3922 case 0: /* already UTC */
3926 return LDAP_SUCCESS;
3933 struct berval **normalized )
3938 rc = check_time_syntax(val, 1, parts);
3939 if (rc != LDAP_SUCCESS) {
3944 out = ch_malloc( sizeof(struct berval) );
3946 return LBER_ERROR_MEMORY;
3949 out->bv_val = ch_malloc( 14 );
3950 if ( out->bv_val == NULL ) {
3952 return LBER_ERROR_MEMORY;
3955 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3956 parts[1], parts[2] + 1, parts[3] + 1,
3957 parts[4], parts[5], parts[6] );
3961 return LDAP_SUCCESS;
3971 return check_time_syntax(in, 1, parts);
3975 generalizedTimeValidate(
3981 return check_time_syntax(in, 0, parts);
3985 generalizedTimeNormalize(
3988 struct berval **normalized )
3993 rc = check_time_syntax(val, 0, parts);
3994 if (rc != LDAP_SUCCESS) {
3999 out = ch_malloc( sizeof(struct berval) );
4001 return LBER_ERROR_MEMORY;
4004 out->bv_val = ch_malloc( 16 );
4005 if ( out->bv_val == NULL ) {
4007 return LBER_ERROR_MEMORY;
4010 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
4011 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4012 parts[4], parts[5], parts[6] );
4016 return LDAP_SUCCESS;
4020 nisNetgroupTripleValidate(
4022 struct berval *val )
4027 if ( val->bv_len == 0 ) {
4028 return LDAP_INVALID_SYNTAX;
4031 p = (char *)val->bv_val;
4032 e = p + val->bv_len;
4035 /* syntax does not allow leading white space */
4036 /* Ignore initial whitespace */
4037 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4042 if ( *p != '(' /*')'*/ ) {
4043 return LDAP_INVALID_SYNTAX;
4046 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4050 return LDAP_INVALID_SYNTAX;
4053 } else if ( !ATTR_CHAR( *p ) ) {
4054 return LDAP_INVALID_SYNTAX;
4058 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4059 return LDAP_INVALID_SYNTAX;
4065 /* syntax does not allow trailing white space */
4066 /* Ignore trailing whitespace */
4067 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4073 return LDAP_INVALID_SYNTAX;
4076 return LDAP_SUCCESS;
4080 bootParameterValidate(
4082 struct berval *val )
4086 if ( val->bv_len == 0 ) {
4087 return LDAP_INVALID_SYNTAX;
4090 p = (char *)val->bv_val;
4091 e = p + val->bv_len;
4094 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4095 if ( !ATTR_CHAR( *p ) ) {
4096 return LDAP_INVALID_SYNTAX;
4101 return LDAP_INVALID_SYNTAX;
4105 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4106 if ( !ATTR_CHAR( *p ) ) {
4107 return LDAP_INVALID_SYNTAX;
4112 return LDAP_INVALID_SYNTAX;
4116 for ( p++; p < e; p++ ) {
4117 if ( !ATTR_CHAR( *p ) ) {
4118 return LDAP_INVALID_SYNTAX;
4122 return LDAP_SUCCESS;
4125 struct syntax_defs_rec {
4128 slap_syntax_validate_func *sd_validate;
4129 slap_syntax_transform_func *sd_normalize;
4130 slap_syntax_transform_func *sd_pretty;
4131 #ifdef SLAPD_BINARY_CONVERSION
4132 slap_syntax_transform_func *sd_ber2str;
4133 slap_syntax_transform_func *sd_str2ber;
4137 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4138 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4140 struct syntax_defs_rec syntax_defs[] = {
4141 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4142 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4144 0, NULL, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4146 0, NULL, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4148 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4149 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4150 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4151 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4152 0, bitStringValidate, NULL, NULL },
4153 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4154 0, booleanValidate, NULL, NULL},
4155 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4156 X_BINARY X_NOT_H_R ")",
4157 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4158 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4159 X_BINARY X_NOT_H_R ")",
4160 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4161 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4162 X_BINARY X_NOT_H_R ")",
4163 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4164 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4165 0, countryStringValidate, IA5StringNormalize, NULL},
4166 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4167 0, dnValidate, dnNormalize, dnPretty},
4168 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4169 0, NULL, NULL, NULL},
4170 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4171 0, NULL, NULL, NULL},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4173 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4175 0, NULL, NULL, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4177 0, NULL, NULL, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4179 0, NULL, NULL, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4181 0, NULL, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4183 0, NULL, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4185 0, printablesStringValidate, IA5StringNormalize, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4187 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4189 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4191 0, NULL, NULL, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4193 0, IA5StringValidate, IA5StringNormalize, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4195 0, integerValidate, integerNormalize, integerPretty},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4197 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4199 0, NULL, NULL, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4201 0, NULL, NULL, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4203 0, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4205 0, NULL, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4207 0, NULL, NULL, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4209 0, nameUIDValidate, nameUIDNormalize, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4211 0, NULL, NULL, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4213 0, numericStringValidate, numericStringNormalize, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4215 0, NULL, NULL, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4217 0, oidValidate, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4219 0, IA5StringValidate, IA5StringNormalize, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4221 0, blobValidate, NULL, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4223 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4225 0, NULL, NULL, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4227 0, NULL, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4229 0, printableStringValidate, IA5StringNormalize, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4231 X_BINARY X_NOT_H_R ")",
4232 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4233 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4234 0, printableStringValidate, IA5StringNormalize, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4236 0, NULL, NULL, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4238 0, printableStringValidate, IA5StringNormalize, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4240 0, utcTimeValidate, utcTimeNormalize, NULL},
4241 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4242 0, NULL, NULL, NULL},
4243 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4244 0, NULL, NULL, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4246 0, NULL, NULL, NULL},
4247 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4248 0, NULL, NULL, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4250 0, NULL, NULL, NULL},
4252 /* RFC 2307 NIS Syntaxes */
4253 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4254 0, nisNetgroupTripleValidate, NULL, NULL},
4255 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4256 0, bootParameterValidate, NULL, NULL},
4258 /* OpenLDAP Experimental Syntaxes */
4259 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4260 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4262 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4263 0, NULL, NULL, NULL},
4265 /* OpenLDAP Void Syntax */
4266 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4267 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4268 {NULL, 0, NULL, NULL, NULL}
4271 struct mrule_defs_rec {
4273 slap_mask_t mrd_usage;
4274 slap_mr_convert_func * mrd_convert;
4275 slap_mr_normalize_func * mrd_normalize;
4276 slap_mr_match_func * mrd_match;
4277 slap_mr_indexer_func * mrd_indexer;
4278 slap_mr_filter_func * mrd_filter;
4280 char * mrd_associated;
4284 * Other matching rules in X.520 that we do not use (yet):
4286 * 2.5.13.9 numericStringOrderingMatch
4287 * 2.5.13.15 integerOrderingMatch
4288 * 2.5.13.18 octetStringOrderingMatch
4289 * 2.5.13.19 octetStringSubstringsMatch
4290 * 2.5.13.25 uTCTimeMatch
4291 * 2.5.13.26 uTCTimeOrderingMatch
4292 * 2.5.13.31 directoryStringFirstComponentMatch
4293 * 2.5.13.32 wordMatch
4294 * 2.5.13.33 keywordMatch
4295 * 2.5.13.34 certificateExactMatch
4296 * 2.5.13.35 certificateMatch
4297 * 2.5.13.36 certificatePairExactMatch
4298 * 2.5.13.37 certificatePairMatch
4299 * 2.5.13.38 certificateListExactMatch
4300 * 2.5.13.39 certificateListMatch
4301 * 2.5.13.40 algorithmIdentifierMatch
4302 * 2.5.13.41 storedPrefixMatch
4303 * 2.5.13.42 attributeCertificateMatch
4304 * 2.5.13.43 readerAndKeyIDMatch
4305 * 2.5.13.44 attributeIntegrityMatch
4308 struct mrule_defs_rec mrule_defs[] = {
4310 * EQUALITY matching rules must be listed after associated APPROX
4311 * matching rules. So, we list all APPROX matching rules first.
4313 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4314 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4315 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4317 directoryStringApproxMatch,
4318 directoryStringApproxIndexer,
4319 directoryStringApproxFilter,
4322 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4323 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4324 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4326 IA5StringApproxMatch,
4327 IA5StringApproxIndexer,
4328 IA5StringApproxFilter,
4332 * Other matching rules
4335 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4336 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4337 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4339 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4342 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4343 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4344 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4346 dnMatch, dnIndexer, dnFilter,
4349 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4350 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4351 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4353 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
4354 directoryStringApproxMatchOID },
4356 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4357 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4360 caseIgnoreOrderingMatch, NULL, NULL,
4363 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4364 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4365 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4367 caseIgnoreSubstringsMatch,
4368 caseIgnoreSubstringsIndexer,
4369 caseIgnoreSubstringsFilter,
4372 {"( 2.5.13.5 NAME 'caseExactMatch' "
4373 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4374 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4376 caseExactMatch, caseExactIndexer, caseExactFilter,
4377 directoryStringApproxMatchOID },
4379 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4380 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4383 caseExactOrderingMatch, NULL, NULL,
4386 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4387 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4388 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4390 caseExactSubstringsMatch,
4391 caseExactSubstringsIndexer,
4392 caseExactSubstringsFilter,
4395 {"( 2.5.13.8 NAME 'numericStringMatch' "
4396 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4397 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4400 caseIgnoreIA5Indexer,
4401 caseIgnoreIA5Filter,
4404 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4405 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4406 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4408 caseIgnoreIA5SubstringsMatch,
4409 caseIgnoreIA5SubstringsIndexer,
4410 caseIgnoreIA5SubstringsFilter,
4413 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4414 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4415 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4417 caseIgnoreListMatch, NULL, NULL,
4420 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4421 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4422 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4424 caseIgnoreListSubstringsMatch, NULL, NULL,
4427 {"( 2.5.13.13 NAME 'booleanMatch' "
4428 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4429 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4431 booleanMatch, NULL, NULL,
4434 {"( 2.5.13.14 NAME 'integerMatch' "
4435 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4436 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4438 integerMatch, integerIndexer, integerFilter,
4441 {"( 2.5.13.16 NAME 'bitStringMatch' "
4442 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4443 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4445 bitStringMatch, NULL, NULL,
4448 {"( 2.5.13.17 NAME 'octetStringMatch' "
4449 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4450 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4452 octetStringMatch, octetStringIndexer, octetStringFilter,
4455 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4456 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4457 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4459 telephoneNumberMatch, NULL, NULL,
4462 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4463 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4464 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4466 telephoneNumberSubstringsMatch, NULL, NULL,
4469 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4470 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4471 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4473 presentationAddressMatch, NULL, NULL,
4476 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4477 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4478 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4480 uniqueMemberMatch, NULL, NULL,
4483 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4484 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4485 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4487 protocolInformationMatch, NULL, NULL,
4490 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4491 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4492 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4494 generalizedTimeMatch, NULL, NULL,
4497 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4498 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4501 generalizedTimeOrderingMatch, NULL, NULL,
4504 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4505 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4506 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4508 integerFirstComponentMatch, NULL, NULL,
4511 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4512 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4513 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4515 objectIdentifierFirstComponentMatch, NULL, NULL,
4518 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4519 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4520 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4522 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4523 IA5StringApproxMatchOID },
4525 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4526 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4527 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4529 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4530 IA5StringApproxMatchOID },
4532 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4533 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4536 caseIgnoreIA5SubstringsMatch,
4537 caseIgnoreIA5SubstringsIndexer,
4538 caseIgnoreIA5SubstringsFilter,
4541 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4542 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4545 caseExactIA5SubstringsMatch,
4546 caseExactIA5SubstringsIndexer,
4547 caseExactIA5SubstringsFilter,
4550 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4551 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4554 authPasswordMatch, NULL, NULL,
4557 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4558 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4561 OpenLDAPaciMatch, NULL, NULL,
4564 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4573 /* we should only be called once (from main) */
4574 assert( schema_init_done == 0 );
4576 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4577 res = register_syntax( syntax_defs[i].sd_desc,
4578 syntax_defs[i].sd_flags,
4579 syntax_defs[i].sd_validate,
4580 syntax_defs[i].sd_normalize,
4581 syntax_defs[i].sd_pretty
4582 #ifdef SLAPD_BINARY_CONVERSION
4584 syntax_defs[i].sd_ber2str,
4585 syntax_defs[i].sd_str2ber
4590 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4591 syntax_defs[i].sd_desc );
4596 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4597 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4599 "schema_init: Ingoring unusable matching rule %s\n",
4600 mrule_defs[i].mrd_desc );
4604 res = register_matching_rule(
4605 mrule_defs[i].mrd_desc,
4606 mrule_defs[i].mrd_usage,
4607 mrule_defs[i].mrd_convert,
4608 mrule_defs[i].mrd_normalize,
4609 mrule_defs[i].mrd_match,
4610 mrule_defs[i].mrd_indexer,
4611 mrule_defs[i].mrd_filter,
4612 mrule_defs[i].mrd_associated );
4616 "schema_init: Error registering matching rule %s\n",
4617 mrule_defs[i].mrd_desc );
4621 schema_init_done = 1;
4622 return LDAP_SUCCESS;