1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
15 #include <ac/string.h>
16 #include <ac/socket.h>
22 #include "ldap_utf8.h"
24 #include "lutil_hash.h"
25 #define HASH_BYTES LUTIL_HASH_BYTES
26 #define HASH_CONTEXT lutil_HASH_CTX
27 #define HASH_Init(c) lutil_HASHInit(c)
28 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
29 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
31 /* recycled validatation routines */
32 #define berValidate blobValidate
34 /* unimplemented pretters */
35 #define integerPretty NULL
37 /* recycled matching routines */
38 #define bitStringMatch octetStringMatch
39 #define numericStringMatch caseIgnoreIA5Match
40 #define objectIdentifierMatch caseIgnoreIA5Match
41 #define telephoneNumberMatch caseIgnoreIA5Match
42 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
43 #define generalizedTimeMatch caseIgnoreIA5Match
44 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
45 #define uniqueMemberMatch dnMatch
47 /* approx matching rules */
48 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
49 #define directoryStringApproxMatch approxMatch
50 #define directoryStringApproxIndexer approxIndexer
51 #define directoryStringApproxFilter approxFilter
52 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
53 #define IA5StringApproxMatch approxMatch
54 #define IA5StringApproxIndexer approxIndexer
55 #define IA5StringApproxFilter approxFilter
57 /* orderring matching rules */
58 #define caseIgnoreOrderingMatch caseIgnoreMatch
59 #define caseExactOrderingMatch caseExactMatch
61 /* unimplemented matching routines */
62 #define caseIgnoreListMatch NULL
63 #define caseIgnoreListSubstringsMatch NULL
64 #define protocolInformationMatch NULL
65 #define integerFirstComponentMatch NULL
67 #ifdef SLAPD_ACI_ENABLED
68 #define OpenLDAPaciMatch NULL
70 #ifdef SLAPD_AUTHPASSWD
71 #define authPasswordMatch NULL
74 /* recycled indexing/filtering routines */
75 #define dnIndexer caseExactIgnoreIndexer
76 #define dnFilter caseExactIgnoreFilter
77 #define bitStringFilter octetStringFilter
78 #define bitStringIndexer octetStringIndexer
80 #define telephoneNumberIndexer caseIgnoreIA5Indexer
81 #define telephoneNumberFilter caseIgnoreIA5Filter
82 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
83 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
85 /* must match OIDs below */
86 #define caseExactMatchOID "2.5.13.5"
87 #define caseExactSubstringsMatchOID "2.5.13.7"
89 static char *bvcasechr( struct berval *bv, int c, ber_len_t *len )
92 int lower = TOLOWER( c );
93 int upper = TOUPPER( c );
95 if( c == 0 ) return NULL;
97 for( i=0; i < bv->bv_len; i++ ) {
98 if( upper == bv->bv_val[i] || lower == bv->bv_val[i] ) {
100 return &bv->bv_val[i];
113 struct berval *value,
114 void *assertedValue )
116 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
119 match = memcmp( value->bv_val,
120 ((struct berval *) assertedValue)->bv_val,
128 /* Index generation function */
129 static int octetStringIndexer(
134 struct berval *prefix,
141 HASH_CONTEXT HASHcontext;
142 unsigned char HASHdigest[HASH_BYTES];
143 struct berval digest;
144 digest.bv_val = HASHdigest;
145 digest.bv_len = sizeof(HASHdigest);
147 for( i=0; values[i].bv_val != NULL; i++ ) {
148 /* just count them */
151 /* we should have at least one value at this point */
154 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
156 slen = syntax->ssyn_oidlen;
157 mlen = mr->smr_oidlen;
159 for( i=0; values[i].bv_val != NULL; i++ ) {
160 HASH_Init( &HASHcontext );
161 if( prefix != NULL && prefix->bv_len > 0 ) {
162 HASH_Update( &HASHcontext,
163 prefix->bv_val, prefix->bv_len );
165 HASH_Update( &HASHcontext,
166 syntax->ssyn_oid, slen );
167 HASH_Update( &HASHcontext,
169 HASH_Update( &HASHcontext,
170 values[i].bv_val, values[i].bv_len );
171 HASH_Final( HASHdigest, &HASHcontext );
173 ber_dupbv( &keys[i], &digest );
176 keys[i].bv_val = NULL;
183 /* Index generation function */
184 static int octetStringFilter(
189 struct berval *prefix,
195 HASH_CONTEXT HASHcontext;
196 unsigned char HASHdigest[HASH_BYTES];
197 struct berval *value = (struct berval *) assertValue;
198 struct berval digest;
199 digest.bv_val = HASHdigest;
200 digest.bv_len = sizeof(HASHdigest);
202 slen = syntax->ssyn_oidlen;
203 mlen = mr->smr_oidlen;
205 keys = ch_malloc( sizeof( struct berval ) * 2 );
207 HASH_Init( &HASHcontext );
208 if( prefix != NULL && prefix->bv_len > 0 ) {
209 HASH_Update( &HASHcontext,
210 prefix->bv_val, prefix->bv_len );
212 HASH_Update( &HASHcontext,
213 syntax->ssyn_oid, slen );
214 HASH_Update( &HASHcontext,
216 HASH_Update( &HASHcontext,
217 value->bv_val, value->bv_len );
218 HASH_Final( HASHdigest, &HASHcontext );
220 ber_dupbv( keys, &digest );
221 keys[1].bv_val = NULL;
236 if( in->bv_len == 0 ) return LDAP_SUCCESS;
238 ber_dupbv( &dn, in );
239 if( !dn.bv_val ) return LDAP_OTHER;
241 if( dn.bv_val[dn.bv_len-1] == 'B'
242 && dn.bv_val[dn.bv_len-2] == '\'' )
244 /* assume presence of optional UID */
247 for(i=dn.bv_len-3; i>1; i--) {
248 if( dn.bv_val[i] != '0' && dn.bv_val[i] != '1' ) {
252 if( dn.bv_val[i] != '\'' ||
253 dn.bv_val[i-1] != '#' ) {
254 ber_memfree( dn.bv_val );
255 return LDAP_INVALID_SYNTAX;
258 /* trim the UID to allow use of dnValidate */
259 dn.bv_val[i-1] = '\0';
263 rc = dnValidate( NULL, &dn );
273 struct berval *normalized )
278 ber_dupbv( &out, val );
279 if( out.bv_len != 0 ) {
282 ber_len_t uidlen = 0;
284 if( out.bv_val[out.bv_len-1] == '\'' ) {
285 /* assume presence of optional UID */
286 uid = strrchr( out.bv_val, '#' );
290 return LDAP_INVALID_SYNTAX;
293 uidlen = out.bv_len - (uid - out.bv_val);
294 /* temporarily trim the UID */
296 out.bv_len -= uidlen;
299 #ifdef USE_DN_NORMALIZE
300 rc = dnNormalize2( NULL, &out, normalized );
302 rc = dnPretty2( NULL, &out, normalized );
305 if( rc != LDAP_SUCCESS ) {
307 return LDAP_INVALID_SYNTAX;
310 dnlen = normalized->bv_len;
314 b2.bv_val = ch_malloc(dnlen + uidlen + 1);
315 AC_MEMCPY( b2.bv_val, normalized->bv_val, dnlen );
317 /* restore the separator */
320 AC_MEMCPY( normalized->bv_val+dnlen, uid, uidlen );
321 b2.bv_len = dnlen + uidlen;
322 normalized->bv_val[dnlen+uidlen] = '\0';
323 free(normalized->bv_val);
337 /* any value allowed */
346 /* any value allowed */
357 /* very unforgiving validation, requires no normalization
358 * before simplistic matching
360 if( in->bv_len < 3 ) {
361 return LDAP_INVALID_SYNTAX;
365 * rfc 2252 section 6.3 Bit String
366 * bitstring = "'" *binary-digit "'"
367 * binary-digit = "0" / "1"
368 * example: '0101111101'B
371 if( in->bv_val[0] != '\'' ||
372 in->bv_val[in->bv_len-2] != '\'' ||
373 in->bv_val[in->bv_len-1] != 'B' )
375 return LDAP_INVALID_SYNTAX;
378 for( i=in->bv_len-3; i>0; i-- ) {
379 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
380 return LDAP_INVALID_SYNTAX;
391 struct berval *normalized )
394 * A normalized bitString is has no extaneous (leading) zero bits.
395 * That is, '00010'B is normalized to '10'B
396 * However, as a special case, '0'B requires no normalization.
400 /* start at the first bit */
403 /* Find the first non-zero bit */
404 while ( *p == '0' ) p++;
407 /* no non-zero bits */
408 ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
412 normalized->bv_val = ch_malloc( val->bv_len + 1 );
414 normalized->bv_val[0] = '\'';
415 normalized->bv_len = 1;
417 for( ; *p != '\0'; p++ ) {
418 normalized->bv_val[normalized->bv_len++] = *p;
421 normalized->bv_val[normalized->bv_len] = '\0';
428 * Handling boolean syntax and matching is quite rigid.
429 * A more flexible approach would be to allow a variety
430 * of strings to be normalized and prettied into TRUE
438 /* very unforgiving validation, requires no normalization
439 * before simplistic matching
442 if( in->bv_len == 4 ) {
443 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
446 } else if( in->bv_len == 5 ) {
447 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
452 return LDAP_INVALID_SYNTAX;
461 struct berval *value,
462 void *assertedValue )
464 /* simplistic matching allowed by rigid validation */
465 struct berval *asserted = (struct berval *) assertedValue;
466 *matchp = value->bv_len != asserted->bv_len;
477 unsigned char *u = in->bv_val;
479 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
481 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
482 /* get the length indicated by the first byte */
483 len = LDAP_UTF8_CHARLEN2( u, len );
485 /* very basic checks */
488 if( (u[5] & 0xC0) != 0x80 ) {
489 return LDAP_INVALID_SYNTAX;
492 if( (u[4] & 0xC0) != 0x80 ) {
493 return LDAP_INVALID_SYNTAX;
496 if( (u[3] & 0xC0) != 0x80 ) {
497 return LDAP_INVALID_SYNTAX;
500 if( (u[2] & 0xC0 )!= 0x80 ) {
501 return LDAP_INVALID_SYNTAX;
504 if( (u[1] & 0xC0) != 0x80 ) {
505 return LDAP_INVALID_SYNTAX;
508 /* CHARLEN already validated it */
511 return LDAP_INVALID_SYNTAX;
514 /* make sure len corresponds with the offset
515 to the next character */
516 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
519 if( count != 0 ) return LDAP_INVALID_SYNTAX;
528 struct berval *normalized )
535 /* Ignore initial whitespace */
536 /* All space is ASCII. All ASCII is 1 byte */
537 for ( ; p < val->bv_val + val->bv_len && ASCII_SPACE( p[ 0 ] ); p++ );
539 ber_mem2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
540 e = normalized->bv_val + val->bv_len - (p - val->bv_val);
542 assert( normalized->bv_len );
543 assert( normalized->bv_val );
545 p = q = normalized->bv_val;
550 if ( ASCII_SPACE( *p ) ) {
555 /* Ignore the extra whitespace */
556 while ( ASCII_SPACE( *p ) ) {
560 len = LDAP_UTF8_COPY(q,p);
566 assert( normalized->bv_val < p );
567 assert( q+len <= p );
569 /* cannot start with a space */
570 assert( !ASCII_SPACE(normalized->bv_val[0]) );
573 * If the string ended in space, backup the pointer one
574 * position. One is enough because the above loop collapsed
575 * all whitespace to a single space.
583 /* cannot end with a space */
584 assert( !ASCII_SPACE( *q ) );
591 normalized->bv_len = q - normalized->bv_val;
596 /* Returns Unicode canonically normalized copy of a substring assertion
597 * Skipping attribute description */
598 static SubstringsAssertion *
599 UTF8SubstringsassertionNormalize(
600 SubstringsAssertion *sa,
603 SubstringsAssertion *nsa;
606 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
611 if( sa->sa_initial.bv_val != NULL ) {
612 UTF8bvnormalize( &sa->sa_initial, &nsa->sa_initial, casefold );
613 if( nsa->sa_initial.bv_val == NULL ) {
618 if( sa->sa_any != NULL ) {
619 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
622 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
623 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
624 UTF8bvnormalize( &sa->sa_any[i], &nsa->sa_any[i],
626 if( nsa->sa_any[i].bv_val == NULL ) {
630 nsa->sa_any[i].bv_val = NULL;
633 if( sa->sa_final.bv_val != NULL ) {
634 UTF8bvnormalize( &sa->sa_final, &nsa->sa_final, casefold );
635 if( nsa->sa_final.bv_val == NULL ) {
643 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
644 if ( nsa->sa_any )ber_bvarray_free( nsa->sa_any );
645 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
650 #ifndef SLAPD_APPROX_OLDSINGLESTRING
652 #if defined(SLAPD_APPROX_INITIALS)
653 #define SLAPD_APPROX_DELIMITER "._ "
654 #define SLAPD_APPROX_WORDLEN 2
656 #define SLAPD_APPROX_DELIMITER " "
657 #define SLAPD_APPROX_WORDLEN 1
666 struct berval *value,
667 void *assertedValue )
669 struct berval *nval, *assertv;
670 char *val, **values, **words, *c;
671 int i, count, len, nextchunk=0, nextavail=0;
673 /* Yes, this is necessary */
674 nval = UTF8bvnormalize( value, NULL, LDAP_UTF8_APPROX );
680 /* Yes, this is necessary */
681 assertv = UTF8bvnormalize( ((struct berval *)assertedValue), NULL, LDAP_UTF8_APPROX );
682 if( assertv == NULL ) {
688 /* Isolate how many words there are */
689 for ( c = nval->bv_val, count = 1; *c; c++ ) {
690 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
691 if ( c == NULL ) break;
696 /* Get a phonetic copy of each word */
697 words = (char **)ch_malloc( count * sizeof(char *) );
698 values = (char **)ch_malloc( count * sizeof(char *) );
699 for ( c = nval->bv_val, i = 0; i < count; i++, c += strlen(c) + 1 ) {
701 values[i] = phonetic(c);
704 /* Work through the asserted value's words, to see if at least some
705 of the words are there, in the same order. */
707 while ( (ber_len_t) nextchunk < assertv->bv_len ) {
708 len = strcspn( assertv->bv_val + nextchunk, SLAPD_APPROX_DELIMITER);
713 #if defined(SLAPD_APPROX_INITIALS)
714 else if( len == 1 ) {
715 /* Single letter words need to at least match one word's initial */
716 for( i=nextavail; i<count; i++ )
717 if( !strncasecmp( assertv->bv_val + nextchunk, words[i], 1 )) {
724 /* Isolate the next word in the asserted value and phonetic it */
725 assertv->bv_val[nextchunk+len] = '\0';
726 val = phonetic( assertv->bv_val + nextchunk );
728 /* See if this phonetic chunk is in the remaining words of *value */
729 for( i=nextavail; i<count; i++ ){
730 if( !strcmp( val, values[i] ) ){
738 /* This chunk in the asserted value was NOT within the *value. */
744 /* Go on to the next word in the asserted value */
748 /* If some of the words were seen, call it a match */
749 if( nextavail > 0 ) {
757 ber_bvfree( assertv );
758 for( i=0; i<count; i++ ) {
759 ch_free( values[i] );
774 struct berval *prefix,
779 int i,j, len, wordcount, keycount=0;
780 struct berval *newkeys;
783 for( j=0; values[j].bv_val != NULL; j++ ) {
784 struct berval val = { 0, NULL };
785 /* Yes, this is necessary */
786 UTF8bvnormalize( &values[j], &val, LDAP_UTF8_APPROX );
787 assert( val.bv_val != NULL );
789 /* Isolate how many words there are. There will be a key for each */
790 for( wordcount = 0, c = val.bv_val; *c; c++) {
791 len = strcspn(c, SLAPD_APPROX_DELIMITER);
792 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
794 if (*c == '\0') break;
798 /* Allocate/increase storage to account for new keys */
799 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
800 * sizeof(struct berval) );
801 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
802 if( keys ) ch_free( keys );
805 /* Get a phonetic copy of each word */
806 for( c = val.bv_val, i = 0; i < wordcount; c += len + 1 ) {
808 if( len < SLAPD_APPROX_WORDLEN ) continue;
809 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
814 ber_memfree( val.bv_val );
816 keys[keycount].bv_val = NULL;
828 struct berval *prefix,
837 /* Yes, this is necessary */
838 val = UTF8bvnormalize( ((struct berval *)assertValue), NULL, LDAP_UTF8_APPROX );
839 if( val == NULL || val->bv_val == NULL ) {
840 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
841 keys[0].bv_val = NULL;
847 /* Isolate how many words there are. There will be a key for each */
848 for( count = 0,c = val->bv_val; *c; c++) {
849 len = strcspn(c, SLAPD_APPROX_DELIMITER);
850 if( len >= SLAPD_APPROX_WORDLEN ) count++;
852 if (*c == '\0') break;
856 /* Allocate storage for new keys */
857 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
859 /* Get a phonetic copy of each word */
860 for( c = val->bv_val, i = 0; i < count; c += len + 1 ) {
862 if( len < SLAPD_APPROX_WORDLEN ) continue;
863 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
869 keys[count].bv_val = NULL;
877 /* No other form of Approximate Matching is defined */
885 struct berval *value,
886 void *assertedValue )
888 char *vapprox, *avapprox;
891 /* Yes, this is necessary */
892 s = UTF8normalize( value, UTF8_NOCASEFOLD );
898 /* Yes, this is necessary */
899 t = UTF8normalize( ((struct berval *)assertedValue),
907 vapprox = phonetic( strip8bitChars( s ) );
908 avapprox = phonetic( strip8bitChars( t ) );
913 *matchp = strcmp( vapprox, avapprox );
927 struct berval *prefix,
935 for( i=0; values[i].bv_val != NULL; i++ ) {
936 /* empty - just count them */
939 /* we should have at least one value at this point */
942 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
944 /* Copy each value and run it through phonetic() */
945 for( i=0; values[i].bv_val != NULL; i++ ) {
946 /* Yes, this is necessary */
947 s = UTF8normalize( &values[i], UTF8_NOCASEFOLD );
949 /* strip 8-bit chars and run through phonetic() */
950 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
953 keys[i].bv_val = NULL;
966 struct berval *prefix,
973 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
975 /* Yes, this is necessary */
976 s = UTF8normalize( ((struct berval *)assertValue),
981 /* strip 8-bit chars and run through phonetic() */
982 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
999 struct berval *value,
1000 void *assertedValue )
1002 *matchp = UTF8bvnormcmp( value,
1003 (struct berval *) assertedValue,
1004 LDAP_UTF8_NOCASEFOLD );
1005 return LDAP_SUCCESS;
1009 caseExactIgnoreSubstringsMatch(
1014 struct berval *value,
1015 void *assertedValue )
1018 SubstringsAssertion *sub = NULL;
1019 struct berval left = { 0, NULL };
1025 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1026 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1028 if ( UTF8bvnormalize( value, &left, casefold ) == NULL ) {
1034 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1040 /* Add up asserted input length */
1041 if( sub->sa_initial.bv_val ) {
1042 inlen += sub->sa_initial.bv_len;
1045 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1046 inlen += sub->sa_any[i].bv_len;
1049 if( sub->sa_final.bv_val ) {
1050 inlen += sub->sa_final.bv_len;
1053 if( sub->sa_initial.bv_val ) {
1054 if( inlen > left.bv_len ) {
1059 match = memcmp( sub->sa_initial.bv_val, left.bv_val,
1060 sub->sa_initial.bv_len );
1066 left.bv_val += sub->sa_initial.bv_len;
1067 left.bv_len -= sub->sa_initial.bv_len;
1068 inlen -= sub->sa_initial.bv_len;
1071 if( sub->sa_final.bv_val ) {
1072 if( inlen > left.bv_len ) {
1077 match = memcmp( sub->sa_final.bv_val,
1078 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1079 sub->sa_final.bv_len );
1085 left.bv_len -= sub->sa_final.bv_len;
1086 inlen -= sub->sa_final.bv_len;
1090 for(i=0; sub->sa_any[i].bv_val; i++) {
1095 if( inlen > left.bv_len ) {
1096 /* not enough length */
1101 if( sub->sa_any[i].bv_len == 0 ) {
1105 p = ber_bvchr( &left, *sub->sa_any[i].bv_val );
1111 idx = p - left.bv_val;
1113 if( idx >= left.bv_len ) {
1114 /* this shouldn't happen */
1116 if ( sub->sa_final.bv_val )
1117 ch_free( sub->sa_final.bv_val );
1119 ber_bvarray_free( sub->sa_any );
1120 if ( sub->sa_initial.bv_val )
1121 ch_free( sub->sa_initial.bv_val );
1129 if( sub->sa_any[i].bv_len > left.bv_len ) {
1130 /* not enough left */
1135 match = memcmp( left.bv_val,
1136 sub->sa_any[i].bv_val,
1137 sub->sa_any[i].bv_len );
1145 left.bv_val += sub->sa_any[i].bv_len;
1146 left.bv_len -= sub->sa_any[i].bv_len;
1147 inlen -= sub->sa_any[i].bv_len;
1154 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1155 if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
1156 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1160 return LDAP_SUCCESS;
1163 /* Index generation function */
1164 static int caseExactIgnoreIndexer(
1169 struct berval *prefix,
1177 HASH_CONTEXT HASHcontext;
1178 unsigned char HASHdigest[HASH_BYTES];
1179 struct berval digest;
1180 digest.bv_val = HASHdigest;
1181 digest.bv_len = sizeof(HASHdigest);
1183 for( i=0; values[i].bv_val != NULL; i++ ) {
1184 /* empty - just count them */
1187 /* we should have at least one value at this point */
1190 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1192 slen = syntax->ssyn_oidlen;
1193 mlen = mr->smr_oidlen;
1195 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1196 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1198 for( i=0; values[i].bv_val != NULL; i++ ) {
1199 struct berval value;
1200 UTF8bvnormalize( &values[i], &value, casefold );
1202 HASH_Init( &HASHcontext );
1203 if( prefix != NULL && prefix->bv_len > 0 ) {
1204 HASH_Update( &HASHcontext,
1205 prefix->bv_val, prefix->bv_len );
1207 HASH_Update( &HASHcontext,
1208 syntax->ssyn_oid, slen );
1209 HASH_Update( &HASHcontext,
1210 mr->smr_oid, mlen );
1211 HASH_Update( &HASHcontext,
1212 value.bv_val, value.bv_len );
1213 HASH_Final( HASHdigest, &HASHcontext );
1215 free( value.bv_val );
1217 ber_dupbv( &keys[i], &digest );
1220 keys[i].bv_val = NULL;
1222 return LDAP_SUCCESS;
1225 /* Index generation function */
1226 static int caseExactIgnoreFilter(
1231 struct berval *prefix,
1238 HASH_CONTEXT HASHcontext;
1239 unsigned char HASHdigest[HASH_BYTES];
1240 struct berval value = { 0, NULL };
1241 struct berval digest;
1243 digest.bv_val = HASHdigest;
1244 digest.bv_len = sizeof(HASHdigest);
1246 slen = syntax->ssyn_oidlen;
1247 mlen = mr->smr_oidlen;
1249 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1250 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1252 UTF8bvnormalize( (struct berval *) assertValue, &value, casefold );
1253 /* This usually happens if filter contains bad UTF8 */
1254 if( value.bv_val == NULL ) {
1255 keys = ch_malloc( sizeof( struct berval ) );
1256 keys[0].bv_val = NULL;
1257 return LDAP_SUCCESS;
1260 keys = ch_malloc( sizeof( struct berval ) * 2 );
1262 HASH_Init( &HASHcontext );
1263 if( prefix != NULL && prefix->bv_len > 0 ) {
1264 HASH_Update( &HASHcontext,
1265 prefix->bv_val, prefix->bv_len );
1267 HASH_Update( &HASHcontext,
1268 syntax->ssyn_oid, slen );
1269 HASH_Update( &HASHcontext,
1270 mr->smr_oid, mlen );
1271 HASH_Update( &HASHcontext,
1272 value.bv_val, value.bv_len );
1273 HASH_Final( HASHdigest, &HASHcontext );
1275 ber_dupbv( keys, &digest );
1276 keys[1].bv_val = NULL;
1278 free( value.bv_val );
1281 return LDAP_SUCCESS;
1284 /* Substrings Index generation function */
1285 static int caseExactIgnoreSubstringsIndexer(
1290 struct berval *prefix,
1300 HASH_CONTEXT HASHcontext;
1301 unsigned char HASHdigest[HASH_BYTES];
1302 struct berval digest;
1303 digest.bv_val = HASHdigest;
1304 digest.bv_len = sizeof(HASHdigest);
1308 for( i=0; values[i].bv_val != NULL; i++ ) {
1309 /* empty - just count them */
1312 /* we should have at least one value at this point */
1315 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1316 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1318 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1319 for( i=0; values[i].bv_val != NULL; i++ ) {
1320 UTF8bvnormalize( &values[i], &nvalues[i], casefold );
1322 nvalues[i].bv_val = NULL;
1325 for( i=0; values[i].bv_val != NULL; i++ ) {
1326 /* count number of indices to generate */
1327 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1331 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1332 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1333 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1334 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1336 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1340 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1341 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1342 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1346 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1347 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1348 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1349 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1351 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1357 /* no keys to generate */
1359 ber_bvarray_free( nvalues );
1360 return LDAP_SUCCESS;
1363 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1365 slen = syntax->ssyn_oidlen;
1366 mlen = mr->smr_oidlen;
1369 for( i=0; values[i].bv_val != NULL; i++ ) {
1372 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1374 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1375 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1377 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1378 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1380 for( j=0; j<max; j++ ) {
1381 HASH_Init( &HASHcontext );
1382 if( prefix != NULL && prefix->bv_len > 0 ) {
1383 HASH_Update( &HASHcontext,
1384 prefix->bv_val, prefix->bv_len );
1387 HASH_Update( &HASHcontext,
1388 &pre, sizeof( pre ) );
1389 HASH_Update( &HASHcontext,
1390 syntax->ssyn_oid, slen );
1391 HASH_Update( &HASHcontext,
1392 mr->smr_oid, mlen );
1393 HASH_Update( &HASHcontext,
1394 &values[i].bv_val[j],
1395 SLAP_INDEX_SUBSTR_MAXLEN );
1396 HASH_Final( HASHdigest, &HASHcontext );
1398 ber_dupbv( &keys[nkeys++], &digest );
1402 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1403 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1405 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1408 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1409 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1410 HASH_Init( &HASHcontext );
1411 if( prefix != NULL && prefix->bv_len > 0 ) {
1412 HASH_Update( &HASHcontext,
1413 prefix->bv_val, prefix->bv_len );
1415 HASH_Update( &HASHcontext,
1416 &pre, sizeof( pre ) );
1417 HASH_Update( &HASHcontext,
1418 syntax->ssyn_oid, slen );
1419 HASH_Update( &HASHcontext,
1420 mr->smr_oid, mlen );
1421 HASH_Update( &HASHcontext,
1422 values[i].bv_val, j );
1423 HASH_Final( HASHdigest, &HASHcontext );
1425 ber_dupbv( &keys[nkeys++], &digest );
1428 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1429 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1430 HASH_Init( &HASHcontext );
1431 if( prefix != NULL && prefix->bv_len > 0 ) {
1432 HASH_Update( &HASHcontext,
1433 prefix->bv_val, prefix->bv_len );
1435 HASH_Update( &HASHcontext,
1436 &pre, sizeof( pre ) );
1437 HASH_Update( &HASHcontext,
1438 syntax->ssyn_oid, slen );
1439 HASH_Update( &HASHcontext,
1440 mr->smr_oid, mlen );
1441 HASH_Update( &HASHcontext,
1442 &values[i].bv_val[values[i].bv_len-j], j );
1443 HASH_Final( HASHdigest, &HASHcontext );
1445 ber_dupbv( &keys[nkeys++], &digest );
1453 keys[nkeys].bv_val = NULL;
1460 ber_bvarray_free( nvalues );
1462 return LDAP_SUCCESS;
1465 static int caseExactIgnoreSubstringsFilter(
1470 struct berval *prefix,
1474 SubstringsAssertion *sa;
1477 ber_len_t nkeys = 0;
1478 size_t slen, mlen, klen;
1480 HASH_CONTEXT HASHcontext;
1481 unsigned char HASHdigest[HASH_BYTES];
1482 struct berval *value;
1483 struct berval digest;
1485 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1486 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1488 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1491 return LDAP_SUCCESS;
1494 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1495 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1500 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1502 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1503 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1504 /* don't bother accounting for stepping */
1505 nkeys += sa->sa_any[i].bv_len -
1506 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1511 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1512 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1518 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1519 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1520 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1523 return LDAP_SUCCESS;
1526 digest.bv_val = HASHdigest;
1527 digest.bv_len = sizeof(HASHdigest);
1529 slen = syntax->ssyn_oidlen;
1530 mlen = mr->smr_oidlen;
1532 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1535 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1536 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1538 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1539 value = &sa->sa_initial;
1541 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1542 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1544 HASH_Init( &HASHcontext );
1545 if( prefix != NULL && prefix->bv_len > 0 ) {
1546 HASH_Update( &HASHcontext,
1547 prefix->bv_val, prefix->bv_len );
1549 HASH_Update( &HASHcontext,
1550 &pre, sizeof( pre ) );
1551 HASH_Update( &HASHcontext,
1552 syntax->ssyn_oid, slen );
1553 HASH_Update( &HASHcontext,
1554 mr->smr_oid, mlen );
1555 HASH_Update( &HASHcontext,
1556 value->bv_val, klen );
1557 HASH_Final( HASHdigest, &HASHcontext );
1559 ber_dupbv( &keys[nkeys++], &digest );
1562 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1564 pre = SLAP_INDEX_SUBSTR_PREFIX;
1565 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1567 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1568 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1572 value = &sa->sa_any[i];
1575 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1576 j += SLAP_INDEX_SUBSTR_STEP )
1578 HASH_Init( &HASHcontext );
1579 if( prefix != NULL && prefix->bv_len > 0 ) {
1580 HASH_Update( &HASHcontext,
1581 prefix->bv_val, prefix->bv_len );
1583 HASH_Update( &HASHcontext,
1584 &pre, sizeof( pre ) );
1585 HASH_Update( &HASHcontext,
1586 syntax->ssyn_oid, slen );
1587 HASH_Update( &HASHcontext,
1588 mr->smr_oid, mlen );
1589 HASH_Update( &HASHcontext,
1590 &value->bv_val[j], klen );
1591 HASH_Final( HASHdigest, &HASHcontext );
1593 ber_dupbv( &keys[nkeys++], &digest );
1599 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1600 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1602 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1603 value = &sa->sa_final;
1605 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1606 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1608 HASH_Init( &HASHcontext );
1609 if( prefix != NULL && prefix->bv_len > 0 ) {
1610 HASH_Update( &HASHcontext,
1611 prefix->bv_val, prefix->bv_len );
1613 HASH_Update( &HASHcontext,
1614 &pre, sizeof( pre ) );
1615 HASH_Update( &HASHcontext,
1616 syntax->ssyn_oid, slen );
1617 HASH_Update( &HASHcontext,
1618 mr->smr_oid, mlen );
1619 HASH_Update( &HASHcontext,
1620 &value->bv_val[value->bv_len-klen], klen );
1621 HASH_Final( HASHdigest, &HASHcontext );
1623 ber_dupbv( &keys[nkeys++], &digest );
1627 keys[nkeys].bv_val = NULL;
1633 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1634 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1635 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1638 return LDAP_SUCCESS;
1647 struct berval *value,
1648 void *assertedValue )
1650 *matchp = UTF8bvnormcmp( value,
1651 (struct berval *) assertedValue,
1652 LDAP_UTF8_CASEFOLD );
1653 return LDAP_SUCCESS;
1659 struct berval *val )
1663 if( val->bv_len == 0 ) {
1664 /* disallow empty strings */
1665 return LDAP_INVALID_SYNTAX;
1668 if( OID_LEADCHAR(val->bv_val[0]) ) {
1670 for(i=1; i < val->bv_len; i++) {
1671 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1672 if( dot++ ) return 1;
1673 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1676 return LDAP_INVALID_SYNTAX;
1680 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1682 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1683 for(i=1; i < val->bv_len; i++) {
1684 if( !DESC_CHAR(val->bv_val[i] ) ) {
1685 return LDAP_INVALID_SYNTAX;
1689 return LDAP_SUCCESS;
1692 return LDAP_INVALID_SYNTAX;
1701 struct berval *value,
1702 void *assertedValue )
1705 int vsign=0, avsign=0;
1706 struct berval *asserted;
1707 ber_len_t vlen, avlen;
1710 /* Start off pessimistic */
1713 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1715 vlen = value->bv_len;
1717 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1718 /* empty -- skip spaces */
1720 else if ( *v == '+' ) {
1723 else if ( *v == '-' ) {
1726 else if ( ASCII_DIGIT(*v) ) {
1727 if ( vsign == 0 ) vsign = 1;
1735 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1737 asserted = (struct berval *) assertedValue;
1738 av = asserted->bv_val;
1739 avlen = asserted->bv_len;
1741 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1742 /* empty -- skip spaces */
1744 else if ( *av == '+' ) {
1747 else if ( *av == '-' ) {
1750 else if ( ASCII_DIGIT(*av) ) {
1751 if ( avsign == 0 ) avsign = 1;
1759 /* The two ?sign vars are now one of :
1760 -2 negative non-zero number
1762 0 0 collapse these three to 0
1764 +2 positive non-zero number
1766 if ( abs( vsign ) == 1 ) vsign = 0;
1767 if ( abs( avsign ) == 1 ) avsign = 0;
1769 if( vsign != avsign ) return LDAP_SUCCESS;
1771 /* Check the significant digits */
1772 while( vlen && avlen ) {
1773 if( *v != *av ) break;
1780 /* If all digits compared equal, the numbers are equal */
1781 if(( vlen == 0 ) && ( avlen == 0 )) {
1784 return LDAP_SUCCESS;
1790 struct berval *val )
1794 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1796 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1797 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1798 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1799 return LDAP_INVALID_SYNTAX;
1802 for( i=1; i < val->bv_len; i++ ) {
1803 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1806 return LDAP_SUCCESS;
1813 struct berval *normalized )
1823 /* Ignore leading spaces */
1824 while ( len && ( *p == ' ' )) {
1831 negative = ( *p == '-' );
1832 if(( *p == '-' ) || ( *p == '+' )) {
1838 /* Ignore leading zeros */
1839 while ( len && ( *p == '0' )) {
1844 /* If there are no non-zero digits left, the number is zero, otherwise
1845 allocate space for the number and copy it into the buffer */
1847 normalized->bv_val = ch_strdup("0");
1848 normalized->bv_len = 1;
1851 normalized->bv_len = len+negative;
1852 normalized->bv_val = ch_malloc( normalized->bv_len );
1854 normalized->bv_val[0] = '-';
1856 AC_MEMCPY( normalized->bv_val + negative, p, len );
1859 return LDAP_SUCCESS;
1862 /* Index generation function */
1863 static int integerIndexer(
1868 struct berval *prefix,
1875 /* we should have at least one value at this point */
1876 assert( values != NULL && values[0].bv_val != NULL );
1878 for( i=0; values[i].bv_val != NULL; i++ ) {
1879 /* empty -- just count them */
1882 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1884 for( i=0; values[i].bv_val != NULL; i++ ) {
1885 integerNormalize( syntax, &values[i], &keys[i] );
1888 keys[i].bv_val = NULL;
1890 return LDAP_SUCCESS;
1893 /* Index generation function */
1894 static int integerFilter(
1899 struct berval *prefix,
1905 keys = ch_malloc( sizeof( struct berval ) * 2 );
1906 integerNormalize( syntax, assertValue, &keys[0] );
1907 keys[1].bv_val = NULL;
1910 return LDAP_SUCCESS;
1915 countryStringValidate(
1917 struct berval *val )
1919 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1921 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1922 return LDAP_INVALID_SYNTAX;
1924 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1925 return LDAP_INVALID_SYNTAX;
1928 return LDAP_SUCCESS;
1932 printableStringValidate(
1934 struct berval *val )
1938 for(i=0; i < val->bv_len; i++) {
1939 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1940 return LDAP_INVALID_SYNTAX;
1944 return LDAP_SUCCESS;
1948 printablesStringValidate(
1950 struct berval *val )
1954 for(i=0; i < val->bv_len; i++) {
1955 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1956 return LDAP_INVALID_SYNTAX;
1960 return LDAP_SUCCESS;
1966 struct berval *val )
1970 for(i=0; i < val->bv_len; i++) {
1971 if( !LDAP_ASCII(val->bv_val[i]) ) {
1972 return LDAP_INVALID_SYNTAX;
1976 return LDAP_SUCCESS;
1983 struct berval *normalized )
1989 /* Ignore initial whitespace */
1990 while ( ASCII_SPACE( *p ) ) {
1994 normalized->bv_val = ch_strdup( p );
1995 p = q = normalized->bv_val;
1998 if ( ASCII_SPACE( *p ) ) {
2001 /* Ignore the extra whitespace */
2002 while ( ASCII_SPACE( *p ) ) {
2010 assert( normalized->bv_val <= p );
2014 * If the string ended in space, backup the pointer one
2015 * position. One is enough because the above loop collapsed
2016 * all whitespace to a single space.
2019 if ( ASCII_SPACE( q[-1] ) ) {
2023 /* null terminate */
2026 normalized->bv_len = q - normalized->bv_val;
2028 return LDAP_SUCCESS;
2037 struct berval *value,
2038 void *assertedValue )
2040 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2043 match = strncmp( value->bv_val,
2044 ((struct berval *) assertedValue)->bv_val,
2049 return LDAP_SUCCESS;
2053 caseExactIA5SubstringsMatch(
2058 struct berval *value,
2059 void *assertedValue )
2062 SubstringsAssertion *sub = assertedValue;
2063 struct berval left = *value;
2067 /* Add up asserted input length */
2068 if( sub->sa_initial.bv_val ) {
2069 inlen += sub->sa_initial.bv_len;
2072 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2073 inlen += sub->sa_any[i].bv_len;
2076 if( sub->sa_final.bv_val ) {
2077 inlen += sub->sa_final.bv_len;
2080 if( sub->sa_initial.bv_val ) {
2081 if( inlen > left.bv_len ) {
2086 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2087 sub->sa_initial.bv_len );
2093 left.bv_val += sub->sa_initial.bv_len;
2094 left.bv_len -= sub->sa_initial.bv_len;
2095 inlen -= sub->sa_initial.bv_len;
2098 if( sub->sa_final.bv_val ) {
2099 if( inlen > left.bv_len ) {
2104 match = strncmp( sub->sa_final.bv_val,
2105 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2106 sub->sa_final.bv_len );
2112 left.bv_len -= sub->sa_final.bv_len;
2113 inlen -= sub->sa_final.bv_len;
2117 for(i=0; sub->sa_any[i].bv_val; i++) {
2122 if( inlen > left.bv_len ) {
2123 /* not enough length */
2128 if( sub->sa_any[i].bv_len == 0 ) {
2132 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2139 idx = p - left.bv_val;
2141 if( idx >= left.bv_len ) {
2142 /* this shouldn't happen */
2149 if( sub->sa_any[i].bv_len > left.bv_len ) {
2150 /* not enough left */
2155 match = strncmp( left.bv_val,
2156 sub->sa_any[i].bv_val,
2157 sub->sa_any[i].bv_len );
2165 left.bv_val += sub->sa_any[i].bv_len;
2166 left.bv_len -= sub->sa_any[i].bv_len;
2167 inlen -= sub->sa_any[i].bv_len;
2173 return LDAP_SUCCESS;
2176 /* Index generation function */
2177 static int caseExactIA5Indexer(
2182 struct berval *prefix,
2189 HASH_CONTEXT HASHcontext;
2190 unsigned char HASHdigest[HASH_BYTES];
2191 struct berval digest;
2192 digest.bv_val = HASHdigest;
2193 digest.bv_len = sizeof(HASHdigest);
2195 for( i=0; values[i].bv_val != NULL; i++ ) {
2196 /* empty - just count them */
2199 /* we should have at least one value at this point */
2202 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2204 slen = syntax->ssyn_oidlen;
2205 mlen = mr->smr_oidlen;
2207 for( i=0; values[i].bv_val != NULL; i++ ) {
2208 struct berval *value = &values[i];
2210 HASH_Init( &HASHcontext );
2211 if( prefix != NULL && prefix->bv_len > 0 ) {
2212 HASH_Update( &HASHcontext,
2213 prefix->bv_val, prefix->bv_len );
2215 HASH_Update( &HASHcontext,
2216 syntax->ssyn_oid, slen );
2217 HASH_Update( &HASHcontext,
2218 mr->smr_oid, mlen );
2219 HASH_Update( &HASHcontext,
2220 value->bv_val, value->bv_len );
2221 HASH_Final( HASHdigest, &HASHcontext );
2223 ber_dupbv( &keys[i], &digest );
2226 keys[i].bv_val = NULL;
2228 return LDAP_SUCCESS;
2231 /* Index generation function */
2232 static int caseExactIA5Filter(
2237 struct berval *prefix,
2243 HASH_CONTEXT HASHcontext;
2244 unsigned char HASHdigest[HASH_BYTES];
2245 struct berval *value;
2246 struct berval digest;
2247 digest.bv_val = HASHdigest;
2248 digest.bv_len = sizeof(HASHdigest);
2250 slen = syntax->ssyn_oidlen;
2251 mlen = mr->smr_oidlen;
2253 value = (struct berval *) assertValue;
2255 keys = ch_malloc( sizeof( struct berval ) * 2 );
2257 HASH_Init( &HASHcontext );
2258 if( prefix != NULL && prefix->bv_len > 0 ) {
2259 HASH_Update( &HASHcontext,
2260 prefix->bv_val, prefix->bv_len );
2262 HASH_Update( &HASHcontext,
2263 syntax->ssyn_oid, slen );
2264 HASH_Update( &HASHcontext,
2265 mr->smr_oid, mlen );
2266 HASH_Update( &HASHcontext,
2267 value->bv_val, value->bv_len );
2268 HASH_Final( HASHdigest, &HASHcontext );
2270 ber_dupbv( &keys[0], &digest );
2271 keys[1].bv_val = NULL;
2274 return LDAP_SUCCESS;
2277 /* Substrings Index generation function */
2278 static int caseExactIA5SubstringsIndexer(
2283 struct berval *prefix,
2290 HASH_CONTEXT HASHcontext;
2291 unsigned char HASHdigest[HASH_BYTES];
2292 struct berval digest;
2293 digest.bv_val = HASHdigest;
2294 digest.bv_len = sizeof(HASHdigest);
2296 /* we should have at least one value at this point */
2297 assert( values != NULL && values[0].bv_val != NULL );
2300 for( i=0; values[i].bv_val != NULL; i++ ) {
2301 /* count number of indices to generate */
2302 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2306 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2307 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2308 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2309 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2311 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2315 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2316 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2317 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2321 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2322 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2323 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2324 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2326 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2332 /* no keys to generate */
2334 return LDAP_SUCCESS;
2337 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2339 slen = syntax->ssyn_oidlen;
2340 mlen = mr->smr_oidlen;
2343 for( i=0; values[i].bv_val != NULL; i++ ) {
2345 struct berval *value;
2348 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2350 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2351 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2353 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2354 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2356 for( j=0; j<max; j++ ) {
2357 HASH_Init( &HASHcontext );
2358 if( prefix != NULL && prefix->bv_len > 0 ) {
2359 HASH_Update( &HASHcontext,
2360 prefix->bv_val, prefix->bv_len );
2363 HASH_Update( &HASHcontext,
2364 &pre, sizeof( pre ) );
2365 HASH_Update( &HASHcontext,
2366 syntax->ssyn_oid, slen );
2367 HASH_Update( &HASHcontext,
2368 mr->smr_oid, mlen );
2369 HASH_Update( &HASHcontext,
2371 SLAP_INDEX_SUBSTR_MAXLEN );
2372 HASH_Final( HASHdigest, &HASHcontext );
2374 ber_dupbv( &keys[nkeys++], &digest );
2378 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2379 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2381 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2384 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2385 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2386 HASH_Init( &HASHcontext );
2387 if( prefix != NULL && prefix->bv_len > 0 ) {
2388 HASH_Update( &HASHcontext,
2389 prefix->bv_val, prefix->bv_len );
2391 HASH_Update( &HASHcontext,
2392 &pre, sizeof( pre ) );
2393 HASH_Update( &HASHcontext,
2394 syntax->ssyn_oid, slen );
2395 HASH_Update( &HASHcontext,
2396 mr->smr_oid, mlen );
2397 HASH_Update( &HASHcontext,
2399 HASH_Final( HASHdigest, &HASHcontext );
2401 ber_dupbv( &keys[nkeys++], &digest );
2404 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2405 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2406 HASH_Init( &HASHcontext );
2407 if( prefix != NULL && prefix->bv_len > 0 ) {
2408 HASH_Update( &HASHcontext,
2409 prefix->bv_val, prefix->bv_len );
2411 HASH_Update( &HASHcontext,
2412 &pre, sizeof( pre ) );
2413 HASH_Update( &HASHcontext,
2414 syntax->ssyn_oid, slen );
2415 HASH_Update( &HASHcontext,
2416 mr->smr_oid, mlen );
2417 HASH_Update( &HASHcontext,
2418 &value->bv_val[value->bv_len-j], j );
2419 HASH_Final( HASHdigest, &HASHcontext );
2421 ber_dupbv( &keys[nkeys++], &digest );
2428 keys[nkeys].bv_val = NULL;
2435 return LDAP_SUCCESS;
2438 static int caseExactIA5SubstringsFilter(
2443 struct berval *prefix,
2447 SubstringsAssertion *sa = assertValue;
2449 ber_len_t nkeys = 0;
2450 size_t slen, mlen, klen;
2452 HASH_CONTEXT HASHcontext;
2453 unsigned char HASHdigest[HASH_BYTES];
2454 struct berval *value;
2455 struct berval digest;
2457 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2458 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2463 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2465 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2466 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2467 /* don't bother accounting for stepping */
2468 nkeys += sa->sa_any[i].bv_len -
2469 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2474 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2475 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2482 return LDAP_SUCCESS;
2485 digest.bv_val = HASHdigest;
2486 digest.bv_len = sizeof(HASHdigest);
2488 slen = syntax->ssyn_oidlen;
2489 mlen = mr->smr_oidlen;
2491 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2494 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2495 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2497 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2498 value = &sa->sa_initial;
2500 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2501 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2503 HASH_Init( &HASHcontext );
2504 if( prefix != NULL && prefix->bv_len > 0 ) {
2505 HASH_Update( &HASHcontext,
2506 prefix->bv_val, prefix->bv_len );
2508 HASH_Update( &HASHcontext,
2509 &pre, sizeof( pre ) );
2510 HASH_Update( &HASHcontext,
2511 syntax->ssyn_oid, slen );
2512 HASH_Update( &HASHcontext,
2513 mr->smr_oid, mlen );
2514 HASH_Update( &HASHcontext,
2515 value->bv_val, klen );
2516 HASH_Final( HASHdigest, &HASHcontext );
2518 ber_dupbv( &keys[nkeys++], &digest );
2521 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2523 pre = SLAP_INDEX_SUBSTR_PREFIX;
2524 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2526 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2527 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2531 value = &sa->sa_any[i];
2534 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2535 j += SLAP_INDEX_SUBSTR_STEP )
2537 HASH_Init( &HASHcontext );
2538 if( prefix != NULL && prefix->bv_len > 0 ) {
2539 HASH_Update( &HASHcontext,
2540 prefix->bv_val, prefix->bv_len );
2542 HASH_Update( &HASHcontext,
2543 &pre, sizeof( pre ) );
2544 HASH_Update( &HASHcontext,
2545 syntax->ssyn_oid, slen );
2546 HASH_Update( &HASHcontext,
2547 mr->smr_oid, mlen );
2548 HASH_Update( &HASHcontext,
2549 &value->bv_val[j], klen );
2550 HASH_Final( HASHdigest, &HASHcontext );
2552 ber_dupbv( &keys[nkeys++], &digest );
2557 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2558 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2560 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2561 value = &sa->sa_final;
2563 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2564 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2566 HASH_Init( &HASHcontext );
2567 if( prefix != NULL && prefix->bv_len > 0 ) {
2568 HASH_Update( &HASHcontext,
2569 prefix->bv_val, prefix->bv_len );
2571 HASH_Update( &HASHcontext,
2572 &pre, sizeof( pre ) );
2573 HASH_Update( &HASHcontext,
2574 syntax->ssyn_oid, slen );
2575 HASH_Update( &HASHcontext,
2576 mr->smr_oid, mlen );
2577 HASH_Update( &HASHcontext,
2578 &value->bv_val[value->bv_len-klen], klen );
2579 HASH_Final( HASHdigest, &HASHcontext );
2581 ber_dupbv( &keys[nkeys++], &digest );
2585 keys[nkeys].bv_val = NULL;
2592 return LDAP_SUCCESS;
2601 struct berval *value,
2602 void *assertedValue )
2604 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2606 if( match == 0 && value->bv_len ) {
2607 match = strncasecmp( value->bv_val,
2608 ((struct berval *) assertedValue)->bv_val,
2613 return LDAP_SUCCESS;
2617 caseIgnoreIA5SubstringsMatch(
2622 struct berval *value,
2623 void *assertedValue )
2626 SubstringsAssertion *sub = assertedValue;
2627 struct berval left = *value;
2631 /* Add up asserted input length */
2632 if( sub->sa_initial.bv_val ) {
2633 inlen += sub->sa_initial.bv_len;
2636 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2637 inlen += sub->sa_any[i].bv_len;
2640 if( sub->sa_final.bv_val ) {
2641 inlen += sub->sa_final.bv_len;
2644 if( sub->sa_initial.bv_val ) {
2645 if( inlen > left.bv_len ) {
2650 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2651 sub->sa_initial.bv_len );
2657 left.bv_val += sub->sa_initial.bv_len;
2658 left.bv_len -= sub->sa_initial.bv_len;
2659 inlen -= sub->sa_initial.bv_len;
2662 if( sub->sa_final.bv_val ) {
2663 if( inlen > left.bv_len ) {
2668 match = strncasecmp( sub->sa_final.bv_val,
2669 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2670 sub->sa_final.bv_len );
2676 left.bv_len -= sub->sa_final.bv_len;
2677 inlen -= sub->sa_final.bv_len;
2681 for(i=0; sub->sa_any[i].bv_val; i++) {
2686 if( inlen > left.bv_len ) {
2687 /* not enough length */
2692 if( sub->sa_any[i].bv_len == 0 ) {
2696 p = bvcasechr( &left, *sub->sa_any[i].bv_val, &idx );
2703 assert( idx < left.bv_len );
2704 if( idx >= left.bv_len ) {
2705 /* this shouldn't happen */
2712 if( sub->sa_any[i].bv_len > left.bv_len ) {
2713 /* not enough left */
2718 match = strncasecmp( left.bv_val,
2719 sub->sa_any[i].bv_val,
2720 sub->sa_any[i].bv_len );
2729 left.bv_val += sub->sa_any[i].bv_len;
2730 left.bv_len -= sub->sa_any[i].bv_len;
2731 inlen -= sub->sa_any[i].bv_len;
2737 return LDAP_SUCCESS;
2740 /* Index generation function */
2741 static int caseIgnoreIA5Indexer(
2746 struct berval *prefix,
2753 HASH_CONTEXT HASHcontext;
2754 unsigned char HASHdigest[HASH_BYTES];
2755 struct berval digest;
2756 digest.bv_val = HASHdigest;
2757 digest.bv_len = sizeof(HASHdigest);
2759 /* we should have at least one value at this point */
2760 assert( values != NULL && values[0].bv_val != NULL );
2762 for( i=0; values[i].bv_val != NULL; i++ ) {
2763 /* just count them */
2766 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2768 slen = syntax->ssyn_oidlen;
2769 mlen = mr->smr_oidlen;
2771 for( i=0; values[i].bv_val != NULL; i++ ) {
2772 struct berval value;
2773 ber_dupbv( &value, &values[i] );
2774 ldap_pvt_str2upper( value.bv_val );
2776 HASH_Init( &HASHcontext );
2777 if( prefix != NULL && prefix->bv_len > 0 ) {
2778 HASH_Update( &HASHcontext,
2779 prefix->bv_val, prefix->bv_len );
2781 HASH_Update( &HASHcontext,
2782 syntax->ssyn_oid, slen );
2783 HASH_Update( &HASHcontext,
2784 mr->smr_oid, mlen );
2785 HASH_Update( &HASHcontext,
2786 value.bv_val, value.bv_len );
2787 HASH_Final( HASHdigest, &HASHcontext );
2789 free( value.bv_val );
2791 ber_dupbv( &keys[i], &digest );
2794 keys[i].bv_val = NULL;
2796 return LDAP_SUCCESS;
2799 /* Index generation function */
2800 static int caseIgnoreIA5Filter(
2805 struct berval *prefix,
2811 HASH_CONTEXT HASHcontext;
2812 unsigned char HASHdigest[HASH_BYTES];
2813 struct berval value;
2814 struct berval digest;
2815 digest.bv_val = HASHdigest;
2816 digest.bv_len = sizeof(HASHdigest);
2818 slen = syntax->ssyn_oidlen;
2819 mlen = mr->smr_oidlen;
2821 ber_dupbv( &value, (struct berval *) assertValue );
2822 ldap_pvt_str2upper( value.bv_val );
2824 keys = ch_malloc( sizeof( struct berval ) * 2 );
2826 HASH_Init( &HASHcontext );
2827 if( prefix != NULL && prefix->bv_len > 0 ) {
2828 HASH_Update( &HASHcontext,
2829 prefix->bv_val, prefix->bv_len );
2831 HASH_Update( &HASHcontext,
2832 syntax->ssyn_oid, slen );
2833 HASH_Update( &HASHcontext,
2834 mr->smr_oid, mlen );
2835 HASH_Update( &HASHcontext,
2836 value.bv_val, value.bv_len );
2837 HASH_Final( HASHdigest, &HASHcontext );
2839 ber_dupbv( &keys[0], &digest );
2840 keys[1].bv_val = NULL;
2842 free( value.bv_val );
2846 return LDAP_SUCCESS;
2849 /* Substrings Index generation function */
2850 static int caseIgnoreIA5SubstringsIndexer(
2855 struct berval *prefix,
2862 HASH_CONTEXT HASHcontext;
2863 unsigned char HASHdigest[HASH_BYTES];
2864 struct berval digest;
2865 digest.bv_val = HASHdigest;
2866 digest.bv_len = sizeof(HASHdigest);
2868 /* we should have at least one value at this point */
2869 assert( values != NULL && values[0].bv_val != NULL );
2872 for( i=0; values[i].bv_val != NULL; i++ ) {
2873 /* count number of indices to generate */
2874 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2878 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2879 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2880 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2881 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2883 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2887 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2888 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2889 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2893 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2894 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2895 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2896 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2898 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2904 /* no keys to generate */
2906 return LDAP_SUCCESS;
2909 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2911 slen = syntax->ssyn_oidlen;
2912 mlen = mr->smr_oidlen;
2915 for( i=0; values[i].bv_val != NULL; i++ ) {
2917 struct berval value;
2919 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2921 ber_dupbv( &value, &values[i] );
2922 ldap_pvt_str2upper( value.bv_val );
2924 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2925 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2927 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2928 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2930 for( j=0; j<max; j++ ) {
2931 HASH_Init( &HASHcontext );
2932 if( prefix != NULL && prefix->bv_len > 0 ) {
2933 HASH_Update( &HASHcontext,
2934 prefix->bv_val, prefix->bv_len );
2937 HASH_Update( &HASHcontext,
2938 &pre, sizeof( pre ) );
2939 HASH_Update( &HASHcontext,
2940 syntax->ssyn_oid, slen );
2941 HASH_Update( &HASHcontext,
2942 mr->smr_oid, mlen );
2943 HASH_Update( &HASHcontext,
2945 SLAP_INDEX_SUBSTR_MAXLEN );
2946 HASH_Final( HASHdigest, &HASHcontext );
2948 ber_dupbv( &keys[nkeys++], &digest );
2952 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2953 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2955 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2958 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2959 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2960 HASH_Init( &HASHcontext );
2961 if( prefix != NULL && prefix->bv_len > 0 ) {
2962 HASH_Update( &HASHcontext,
2963 prefix->bv_val, prefix->bv_len );
2965 HASH_Update( &HASHcontext,
2966 &pre, sizeof( pre ) );
2967 HASH_Update( &HASHcontext,
2968 syntax->ssyn_oid, slen );
2969 HASH_Update( &HASHcontext,
2970 mr->smr_oid, mlen );
2971 HASH_Update( &HASHcontext,
2973 HASH_Final( HASHdigest, &HASHcontext );
2975 ber_dupbv( &keys[nkeys++], &digest );
2978 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2979 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2980 HASH_Init( &HASHcontext );
2981 if( prefix != NULL && prefix->bv_len > 0 ) {
2982 HASH_Update( &HASHcontext,
2983 prefix->bv_val, prefix->bv_len );
2985 HASH_Update( &HASHcontext,
2986 &pre, sizeof( pre ) );
2987 HASH_Update( &HASHcontext,
2988 syntax->ssyn_oid, slen );
2989 HASH_Update( &HASHcontext,
2990 mr->smr_oid, mlen );
2991 HASH_Update( &HASHcontext,
2992 &value.bv_val[value.bv_len-j], j );
2993 HASH_Final( HASHdigest, &HASHcontext );
2995 ber_dupbv( &keys[nkeys++], &digest );
3000 free( value.bv_val );
3004 keys[nkeys].bv_val = NULL;
3011 return LDAP_SUCCESS;
3014 static int caseIgnoreIA5SubstringsFilter(
3019 struct berval *prefix,
3023 SubstringsAssertion *sa = assertValue;
3025 ber_len_t nkeys = 0;
3026 size_t slen, mlen, klen;
3028 HASH_CONTEXT HASHcontext;
3029 unsigned char HASHdigest[HASH_BYTES];
3030 struct berval value;
3031 struct berval digest;
3033 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3034 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3039 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3041 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3042 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3043 /* don't bother accounting for stepping */
3044 nkeys += sa->sa_any[i].bv_len -
3045 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3050 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3051 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3058 return LDAP_SUCCESS;
3061 digest.bv_val = HASHdigest;
3062 digest.bv_len = sizeof(HASHdigest);
3064 slen = syntax->ssyn_oidlen;
3065 mlen = mr->smr_oidlen;
3067 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3070 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3071 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3073 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3074 ber_dupbv( &value, &sa->sa_initial );
3075 ldap_pvt_str2upper( value.bv_val );
3077 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3078 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3080 HASH_Init( &HASHcontext );
3081 if( prefix != NULL && prefix->bv_len > 0 ) {
3082 HASH_Update( &HASHcontext,
3083 prefix->bv_val, prefix->bv_len );
3085 HASH_Update( &HASHcontext,
3086 &pre, sizeof( pre ) );
3087 HASH_Update( &HASHcontext,
3088 syntax->ssyn_oid, slen );
3089 HASH_Update( &HASHcontext,
3090 mr->smr_oid, mlen );
3091 HASH_Update( &HASHcontext,
3092 value.bv_val, klen );
3093 HASH_Final( HASHdigest, &HASHcontext );
3095 free( value.bv_val );
3096 ber_dupbv( &keys[nkeys++], &digest );
3099 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3101 pre = SLAP_INDEX_SUBSTR_PREFIX;
3102 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3104 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3105 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3109 ber_dupbv( &value, &sa->sa_any[i] );
3110 ldap_pvt_str2upper( value.bv_val );
3113 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3114 j += SLAP_INDEX_SUBSTR_STEP )
3116 HASH_Init( &HASHcontext );
3117 if( prefix != NULL && prefix->bv_len > 0 ) {
3118 HASH_Update( &HASHcontext,
3119 prefix->bv_val, prefix->bv_len );
3121 HASH_Update( &HASHcontext,
3122 &pre, sizeof( pre ) );
3123 HASH_Update( &HASHcontext,
3124 syntax->ssyn_oid, slen );
3125 HASH_Update( &HASHcontext,
3126 mr->smr_oid, mlen );
3127 HASH_Update( &HASHcontext,
3128 &value.bv_val[j], klen );
3129 HASH_Final( HASHdigest, &HASHcontext );
3131 ber_dupbv( &keys[nkeys++], &digest );
3134 free( value.bv_val );
3138 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3139 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3141 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3142 ber_dupbv( &value, &sa->sa_final );
3143 ldap_pvt_str2upper( value.bv_val );
3145 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3146 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3148 HASH_Init( &HASHcontext );
3149 if( prefix != NULL && prefix->bv_len > 0 ) {
3150 HASH_Update( &HASHcontext,
3151 prefix->bv_val, prefix->bv_len );
3153 HASH_Update( &HASHcontext,
3154 &pre, sizeof( pre ) );
3155 HASH_Update( &HASHcontext,
3156 syntax->ssyn_oid, slen );
3157 HASH_Update( &HASHcontext,
3158 mr->smr_oid, mlen );
3159 HASH_Update( &HASHcontext,
3160 &value.bv_val[value.bv_len-klen], klen );
3161 HASH_Final( HASHdigest, &HASHcontext );
3163 free( value.bv_val );
3164 ber_dupbv( &keys[nkeys++], &digest );
3168 keys[nkeys].bv_val = NULL;
3175 return LDAP_SUCCESS;
3179 numericStringValidate(
3185 for(i=0; i < in->bv_len; i++) {
3186 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3187 return LDAP_INVALID_SYNTAX;
3191 return LDAP_SUCCESS;
3195 numericStringNormalize(
3198 struct berval *normalized )
3200 /* removal all spaces */
3203 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3206 q = normalized->bv_val;
3209 if ( ASCII_SPACE( *p ) ) {
3210 /* Ignore whitespace */
3217 /* we should have copied no more then is in val */
3218 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3220 /* null terminate */
3223 normalized->bv_len = q - normalized->bv_val;
3225 return LDAP_SUCCESS;
3229 objectIdentifierFirstComponentMatch(
3234 struct berval *value,
3235 void *assertedValue )
3237 int rc = LDAP_SUCCESS;
3239 struct berval *asserted = (struct berval *) assertedValue;
3243 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3244 return LDAP_INVALID_SYNTAX;
3247 /* trim leading white space */
3248 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3252 /* grab next word */
3253 oid.bv_val = &value->bv_val[i];
3254 oid.bv_len = value->bv_len - i;
3255 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3260 /* insert attributeTypes, objectclass check here */
3261 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3262 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3265 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3266 MatchingRule *asserted_mr = mr_bvfind( asserted );
3267 MatchingRule *stored_mr = mr_bvfind( &oid );
3269 if( asserted_mr == NULL ) {
3270 rc = SLAPD_COMPARE_UNDEFINED;
3272 match = asserted_mr != stored_mr;
3275 } else if ( !strcmp( syntax->ssyn_oid,
3276 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3278 AttributeType *asserted_at = at_bvfind( asserted );
3279 AttributeType *stored_at = at_bvfind( &oid );
3281 if( asserted_at == NULL ) {
3282 rc = SLAPD_COMPARE_UNDEFINED;
3284 match = asserted_at != stored_at;
3287 } else if ( !strcmp( syntax->ssyn_oid,
3288 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3290 ObjectClass *asserted_oc = oc_bvfind( asserted );
3291 ObjectClass *stored_oc = oc_bvfind( &oid );
3293 if( asserted_oc == NULL ) {
3294 rc = SLAPD_COMPARE_UNDEFINED;
3296 match = asserted_oc != stored_oc;
3302 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3303 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3304 match, value->bv_val, asserted->bv_val ));
3306 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3307 "%d\n\t\"%s\"\n\t\"%s\"\n",
3308 match, value->bv_val, asserted->bv_val );
3312 if( rc == LDAP_SUCCESS ) *matchp = match;
3322 struct berval *value,
3323 void *assertedValue )
3325 long lValue, lAssertedValue;
3327 /* safe to assume integers are NUL terminated? */
3328 lValue = strtoul(value->bv_val, NULL, 10);
3329 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3330 return LDAP_CONSTRAINT_VIOLATION;
3332 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3333 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3334 return LDAP_CONSTRAINT_VIOLATION;
3336 *matchp = (lValue & lAssertedValue);
3337 return LDAP_SUCCESS;
3346 struct berval *value,
3347 void *assertedValue )
3349 long lValue, lAssertedValue;
3351 /* safe to assume integers are NUL terminated? */
3352 lValue = strtoul(value->bv_val, NULL, 10);
3353 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3354 return LDAP_CONSTRAINT_VIOLATION;
3356 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3357 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3358 return LDAP_CONSTRAINT_VIOLATION;
3360 *matchp = (lValue | lAssertedValue);
3361 return LDAP_SUCCESS;
3365 #include <openssl/x509.h>
3366 #include <openssl/err.h>
3367 char digit[] = "0123456789";
3370 * Next function returns a string representation of a ASN1_INTEGER.
3371 * It works for unlimited lengths.
3374 static struct berval *
3375 asn1_integer2str(ASN1_INTEGER *a)
3380 /* We work backwards, make it fill from the end of buf */
3381 p = buf + sizeof(buf) - 1;
3384 if ( a == NULL || a->length == 0 ) {
3392 /* We want to preserve the original */
3393 copy = ch_malloc(n*sizeof(unsigned int));
3394 for (i = 0; i<n; i++) {
3395 copy[i] = a->data[i];
3399 * base indicates the index of the most significant
3400 * byte that might be nonzero. When it goes off the
3401 * end, we now there is nothing left to do.
3407 for (i = base; i<n; i++ ) {
3408 copy[i] += carry*256;
3409 carry = copy[i] % 10;
3414 * Way too large, we need to leave
3415 * room for sign if negative
3420 *--p = digit[carry];
3421 if (copy[base] == 0)
3427 if ( a->type == V_ASN1_NEG_INTEGER ) {
3431 return ber_bvstrdup(p);
3434 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3435 static struct berval *
3436 dn_openssl2ldap(X509_NAME *name)
3438 char issuer_dn[1024];
3441 bio = BIO_new(BIO_s_mem());
3444 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3445 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3446 ERR_error_string(ERR_get_error(),NULL)));
3448 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3449 "error creating BIO: %s\n",
3450 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3454 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3456 BIO_gets(bio, issuer_dn, 1024);
3459 return ber_bvstrdup(issuer_dn);
3463 * Given a certificate in DER format, extract the corresponding
3464 * assertion value for certificateExactMatch
3467 certificateExactConvert(
3469 struct berval * out )
3472 unsigned char *p = in->bv_val;
3473 struct berval *serial;
3474 struct berval *issuer_dn;
3475 struct berval *bv_tmp;
3477 xcert = d2i_X509(NULL, &p, in->bv_len);
3480 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3481 "certificateExactConvert: error parsing cert: %s\n",
3482 ERR_error_string(ERR_get_error(),NULL)));
3484 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3485 "error parsing cert: %s\n",
3486 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3488 return LDAP_INVALID_SYNTAX;
3491 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3494 return LDAP_INVALID_SYNTAX;
3496 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3500 return LDAP_INVALID_SYNTAX;
3502 /* Actually, dn_openssl2ldap returns in a normalized format, but
3503 it is different from our normalized format */
3505 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3509 return LDAP_INVALID_SYNTAX;
3515 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3516 out->bv_val = ch_malloc(out->bv_len);
3518 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3519 p += serial->bv_len;
3520 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3522 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3523 p += issuer_dn->bv_len;
3527 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3528 "certificateExactConvert: \n %s\n",
3531 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3533 out->bv_val, NULL, NULL );
3537 ber_bvfree(issuer_dn);
3539 return LDAP_SUCCESS;
3543 serial_and_issuer_parse(
3544 struct berval *assertion,
3545 struct berval **serial,
3546 struct berval **issuer_dn
3554 begin = assertion->bv_val;
3555 end = assertion->bv_val+assertion->bv_len-1;
3556 for (p=begin; p<=end && *p != '$'; p++)
3559 return LDAP_INVALID_SYNTAX;
3561 /* p now points at the $ sign, now use begin and end to delimit the
3563 while (ASCII_SPACE(*begin))
3566 while (ASCII_SPACE(*end))
3569 bv.bv_len = end-begin+1;
3571 *serial = ber_dupbv(NULL, &bv);
3573 /* now extract the issuer, remember p was at the dollar sign */
3575 end = assertion->bv_val+assertion->bv_len-1;
3576 while (ASCII_SPACE(*begin))
3578 /* should we trim spaces at the end too? is it safe always? */
3580 bv.bv_len = end-begin+1;
3582 dnNormalize( NULL, &bv, issuer_dn );
3584 return LDAP_SUCCESS;
3588 certificateExactMatch(
3593 struct berval *value,
3594 void *assertedValue )
3597 unsigned char *p = value->bv_val;
3598 struct berval *serial;
3599 struct berval *issuer_dn;
3600 struct berval *asserted_serial;
3601 struct berval *asserted_issuer_dn;
3604 xcert = d2i_X509(NULL, &p, value->bv_len);
3607 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3608 "certificateExactMatch: error parsing cert: %s\n",
3609 ERR_error_string(ERR_get_error(),NULL)));
3611 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3612 "error parsing cert: %s\n",
3613 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3615 return LDAP_INVALID_SYNTAX;
3618 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3619 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3623 serial_and_issuer_parse(assertedValue,
3625 &asserted_issuer_dn);
3630 slap_schema.si_syn_integer,
3631 slap_schema.si_mr_integerMatch,
3634 if ( ret == LDAP_SUCCESS ) {
3635 if ( *matchp == 0 ) {
3636 /* We need to normalize everything for dnMatch */
3640 slap_schema.si_syn_distinguishedName,
3641 slap_schema.si_mr_distinguishedNameMatch,
3643 asserted_issuer_dn);
3648 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3649 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3650 *matchp, serial->bv_val, issuer_dn->bv_val,
3651 asserted_serial->bv_val, asserted_issuer_dn->bv_val));
3653 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3654 "%d\n\t\"%s $ %s\"\n",
3655 *matchp, serial->bv_val, issuer_dn->bv_val );
3656 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3657 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3662 ber_bvfree(issuer_dn);
3663 ber_bvfree(asserted_serial);
3664 ber_bvfree(asserted_issuer_dn);
3670 * Index generation function
3671 * We just index the serials, in most scenarios the issuer DN is one of
3672 * a very small set of values.
3674 static int certificateExactIndexer(
3679 struct berval *prefix,
3687 struct berval * serial;
3689 /* we should have at least one value at this point */
3690 assert( values != NULL && values[0].bv_val != NULL );
3692 for( i=0; values[i].bv_val != NULL; i++ ) {
3693 /* empty -- just count them */
3696 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3698 for( i=0; values[i].bv_val != NULL; i++ ) {
3699 p = values[i].bv_val;
3700 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3703 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3704 "certificateExactIndexer: error parsing cert: %s\n",
3705 ERR_error_string(ERR_get_error(),NULL)));
3707 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3708 "error parsing cert: %s\n",
3709 ERR_error_string(ERR_get_error(),NULL),
3712 /* Do we leak keys on error? */
3713 return LDAP_INVALID_SYNTAX;
3716 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3718 integerNormalize( slap_schema.si_syn_integer,
3723 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3724 "certificateExactIndexer: returning: %s\n",
3727 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3734 keys[i].bv_val = NULL;
3736 return LDAP_SUCCESS;
3739 /* Index generation function */
3740 /* We think this is always called with a value in matching rule syntax */
3741 static int certificateExactFilter(
3746 struct berval *prefix,
3751 struct berval *asserted_serial;
3752 struct berval *asserted_issuer_dn;
3754 serial_and_issuer_parse(assertValue,
3756 &asserted_issuer_dn);
3758 keys = ch_malloc( sizeof( struct berval ) * 2 );
3759 integerNormalize( syntax, asserted_serial, &keys[0] );
3760 keys[1].bv_val = NULL;
3763 ber_bvfree(asserted_serial);
3764 ber_bvfree(asserted_issuer_dn);
3765 return LDAP_SUCCESS;
3770 check_time_syntax (struct berval *val,
3774 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3775 static int mdays[2][12] = {
3776 /* non-leap years */
3777 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3779 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3782 int part, c, tzoffset, leapyear = 0 ;
3784 if( val->bv_len == 0 ) {
3785 return LDAP_INVALID_SYNTAX;
3788 p = (char *)val->bv_val;
3789 e = p + val->bv_len;
3791 /* Ignore initial whitespace */
3792 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3796 if (e - p < 13 - (2 * start)) {
3797 return LDAP_INVALID_SYNTAX;
3800 for (part = 0; part < 9; part++) {
3804 for (part = start; part < 7; part++) {
3806 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3813 return LDAP_INVALID_SYNTAX;
3815 if (c < 0 || c > 9) {
3816 return LDAP_INVALID_SYNTAX;
3822 return LDAP_INVALID_SYNTAX;
3824 if (c < 0 || c > 9) {
3825 return LDAP_INVALID_SYNTAX;
3830 if (part == 2 || part == 3) {
3833 if (parts[part] < 0) {
3834 return LDAP_INVALID_SYNTAX;
3836 if (parts[part] > ceiling[part]) {
3837 return LDAP_INVALID_SYNTAX;
3841 /* leapyear check for the Gregorian calendar (year>1581) */
3842 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3843 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3848 if (parts[3] > mdays[leapyear][parts[2]]) {
3849 return LDAP_INVALID_SYNTAX;
3854 tzoffset = 0; /* UTC */
3855 } else if (c != '+' && c != '-') {
3856 return LDAP_INVALID_SYNTAX;
3860 } else /* c == '+' */ {
3865 return LDAP_INVALID_SYNTAX;
3868 for (part = 7; part < 9; part++) {
3870 if (c < 0 || c > 9) {
3871 return LDAP_INVALID_SYNTAX;
3876 if (c < 0 || c > 9) {
3877 return LDAP_INVALID_SYNTAX;
3881 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3882 return LDAP_INVALID_SYNTAX;
3887 /* Ignore trailing whitespace */
3888 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3892 return LDAP_INVALID_SYNTAX;
3895 switch ( tzoffset ) {
3896 case -1: /* negativ offset to UTC, ie west of Greenwich */
3897 parts[4] += parts[7];
3898 parts[5] += parts[8];
3899 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3903 c = mdays[leapyear][parts[2]];
3905 if (parts[part] > c) {
3906 parts[part] -= c + 1;
3911 case 1: /* positive offset to UTC, ie east of Greenwich */
3912 parts[4] -= parts[7];
3913 parts[5] -= parts[8];
3914 for (part = 6; --part > 0; ) {
3918 /* first arg to % needs to be non negativ */
3919 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3921 if (parts[part] < 0) {
3922 parts[part] += c + 1;
3927 case 0: /* already UTC */
3931 return LDAP_SUCCESS;
3938 struct berval *normalized )
3942 rc = check_time_syntax(val, 1, parts);
3943 if (rc != LDAP_SUCCESS) {
3947 normalized->bv_val = ch_malloc( 14 );
3948 if ( normalized->bv_val == NULL ) {
3949 return LBER_ERROR_MEMORY;
3952 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3953 parts[1], parts[2] + 1, parts[3] + 1,
3954 parts[4], parts[5], parts[6] );
3955 normalized->bv_len = 13;
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 )
3988 rc = check_time_syntax(val, 0, parts);
3989 if (rc != LDAP_SUCCESS) {
3993 normalized->bv_val = ch_malloc( 16 );
3994 if ( normalized->bv_val == NULL ) {
3995 return LBER_ERROR_MEMORY;
3998 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
3999 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4000 parts[4], parts[5], parts[6] );
4001 normalized->bv_len = 15;
4003 return LDAP_SUCCESS;
4007 nisNetgroupTripleValidate(
4009 struct berval *val )
4014 if ( val->bv_len == 0 ) {
4015 return LDAP_INVALID_SYNTAX;
4018 p = (char *)val->bv_val;
4019 e = p + val->bv_len;
4021 if ( *p != '(' /*')'*/ ) {
4022 return LDAP_INVALID_SYNTAX;
4025 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4029 return LDAP_INVALID_SYNTAX;
4032 } else if ( !ATTR_CHAR( *p ) ) {
4033 return LDAP_INVALID_SYNTAX;
4037 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4038 return LDAP_INVALID_SYNTAX;
4044 return LDAP_INVALID_SYNTAX;
4047 return LDAP_SUCCESS;
4051 bootParameterValidate(
4053 struct berval *val )
4057 if ( val->bv_len == 0 ) {
4058 return LDAP_INVALID_SYNTAX;
4061 p = (char *)val->bv_val;
4062 e = p + val->bv_len;
4065 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4066 if ( !ATTR_CHAR( *p ) ) {
4067 return LDAP_INVALID_SYNTAX;
4072 return LDAP_INVALID_SYNTAX;
4076 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4077 if ( !ATTR_CHAR( *p ) ) {
4078 return LDAP_INVALID_SYNTAX;
4083 return LDAP_INVALID_SYNTAX;
4087 for ( p++; p < e; p++ ) {
4088 if ( !ATTR_CHAR( *p ) ) {
4089 return LDAP_INVALID_SYNTAX;
4093 return LDAP_SUCCESS;
4096 static struct syntax_defs_rec {
4098 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4099 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4101 slap_syntax_validate_func *sd_validate;
4102 slap_syntax_transform_func *sd_normalize;
4103 slap_syntax_transform_func *sd_pretty;
4104 #ifdef SLAPD_BINARY_CONVERSION
4105 slap_syntax_transform_func *sd_ber2str;
4106 slap_syntax_transform_func *sd_str2ber;
4109 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4110 X_BINARY X_NOT_H_R ")",
4111 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4112 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4113 0, NULL, NULL, NULL},
4114 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4115 0, NULL, NULL, NULL},
4116 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4118 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4119 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4121 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4122 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4123 0, bitStringValidate, bitStringNormalize, NULL },
4124 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4125 0, booleanValidate, NULL, NULL},
4126 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4127 X_BINARY X_NOT_H_R ")",
4128 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4129 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4130 X_BINARY X_NOT_H_R ")",
4131 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4132 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4133 X_BINARY X_NOT_H_R ")",
4134 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4135 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4136 0, countryStringValidate, IA5StringNormalize, NULL},
4137 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4138 0, dnValidate, dnNormalize2, dnPretty2},
4139 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4140 0, NULL, NULL, NULL},
4141 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4142 0, NULL, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4144 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4146 0, NULL, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4148 0, NULL, NULL, NULL},
4149 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4150 0, NULL, NULL, NULL},
4151 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4152 0, NULL, NULL, NULL},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4154 0, NULL, NULL, NULL},
4155 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4156 0, printablesStringValidate, IA5StringNormalize, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4158 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4160 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4161 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4162 0, NULL, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4164 0, IA5StringValidate, IA5StringNormalize, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4166 0, integerValidate, integerNormalize, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4168 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4170 0, NULL, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4172 0, NULL, NULL, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4174 0, NULL, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4176 0, NULL, NULL, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4178 0, NULL, NULL, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4180 0, nameUIDValidate, nameUIDNormalize, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4182 0, NULL, NULL, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4184 0, numericStringValidate, numericStringNormalize, NULL},
4185 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4186 0, NULL, NULL, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4188 0, oidValidate, NULL, NULL},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4190 0, IA5StringValidate, IA5StringNormalize, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4192 0, blobValidate, NULL, NULL},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4194 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4196 0, NULL, NULL, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4198 0, NULL, NULL, NULL},
4199 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4200 0, printableStringValidate, IA5StringNormalize, NULL},
4201 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4202 X_BINARY X_NOT_H_R ")",
4203 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4205 X_BINARY X_NOT_H_R ")",
4206 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4208 0, printableStringValidate, IA5StringNormalize, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4210 0, NULL, NULL, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4212 0, printablesStringValidate, IA5StringNormalize, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4214 0, utcTimeValidate, utcTimeNormalize, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4216 0, NULL, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4218 0, NULL, NULL, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4220 0, NULL, NULL, NULL},
4221 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4222 0, NULL, NULL, NULL},
4223 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4224 0, NULL, NULL, NULL},
4226 /* RFC 2307 NIS Syntaxes */
4227 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4228 0, nisNetgroupTripleValidate, NULL, NULL},
4229 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4230 0, bootParameterValidate, NULL, NULL},
4234 /* These OIDs are not published yet, but will be in the next
4235 * I-D for PKIX LDAPv3 schema as have been advanced by David
4236 * Chadwick in private mail.
4238 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4239 0, NULL, NULL, NULL},
4242 /* OpenLDAP Experimental Syntaxes */
4243 #ifdef SLAPD_ACI_ENABLED
4244 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4246 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4250 #ifdef SLAPD_AUTHPASSWD
4251 /* needs updating */
4252 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4253 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4256 /* OpenLDAP Void Syntax */
4257 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4258 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4259 {NULL, 0, NULL, NULL, NULL}
4263 * Other matching rules in X.520 that we do not use (yet):
4265 * 2.5.13.9 numericStringOrderingMatch
4266 * 2.5.13.15 integerOrderingMatch
4267 * 2.5.13.18 octetStringOrderingMatch
4268 * 2.5.13.19 octetStringSubstringsMatch
4269 * 2.5.13.25 uTCTimeMatch
4270 * 2.5.13.26 uTCTimeOrderingMatch
4271 * 2.5.13.31 directoryStringFirstComponentMatch
4272 * 2.5.13.32 wordMatch
4273 * 2.5.13.33 keywordMatch
4274 * 2.5.13.35 certificateMatch
4275 * 2.5.13.36 certificatePairExactMatch
4276 * 2.5.13.37 certificatePairMatch
4277 * 2.5.13.38 certificateListExactMatch
4278 * 2.5.13.39 certificateListMatch
4279 * 2.5.13.40 algorithmIdentifierMatch
4280 * 2.5.13.41 storedPrefixMatch
4281 * 2.5.13.42 attributeCertificateMatch
4282 * 2.5.13.43 readerAndKeyIDMatch
4283 * 2.5.13.44 attributeIntegrityMatch
4285 static struct mrule_defs_rec {
4287 slap_mask_t mrd_usage;
4288 slap_mr_convert_func * mrd_convert;
4289 slap_mr_normalize_func * mrd_normalize;
4290 slap_mr_match_func * mrd_match;
4291 slap_mr_indexer_func * mrd_indexer;
4292 slap_mr_filter_func * mrd_filter;
4294 char * mrd_associated;
4297 * EQUALITY matching rules must be listed after associated APPROX
4298 * matching rules. So, we list all APPROX matching rules first.
4300 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4301 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4302 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4304 directoryStringApproxMatch,
4305 directoryStringApproxIndexer,
4306 directoryStringApproxFilter,
4309 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4310 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4311 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4313 IA5StringApproxMatch,
4314 IA5StringApproxIndexer,
4315 IA5StringApproxFilter,
4319 * Other matching rules
4322 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4323 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4324 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4326 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4329 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4330 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4331 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4333 dnMatch, dnIndexer, dnFilter,
4336 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4337 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4338 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4340 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4341 directoryStringApproxMatchOID },
4343 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4344 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4347 caseIgnoreOrderingMatch, NULL, NULL,
4350 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4351 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4352 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4354 caseExactIgnoreSubstringsMatch,
4355 caseExactIgnoreSubstringsIndexer,
4356 caseExactIgnoreSubstringsFilter,
4359 {"( 2.5.13.5 NAME 'caseExactMatch' "
4360 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4361 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4363 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4364 directoryStringApproxMatchOID },
4366 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4367 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4370 caseExactOrderingMatch, NULL, NULL,
4373 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4374 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4375 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4377 caseExactIgnoreSubstringsMatch,
4378 caseExactIgnoreSubstringsIndexer,
4379 caseExactIgnoreSubstringsFilter,
4382 {"( 2.5.13.8 NAME 'numericStringMatch' "
4383 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4384 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4387 caseIgnoreIA5Indexer,
4388 caseIgnoreIA5Filter,
4391 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4392 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4393 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4395 caseIgnoreIA5SubstringsMatch,
4396 caseIgnoreIA5SubstringsIndexer,
4397 caseIgnoreIA5SubstringsFilter,
4400 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4401 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4402 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4404 caseIgnoreListMatch, NULL, NULL,
4407 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4408 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4409 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4411 caseIgnoreListSubstringsMatch, NULL, NULL,
4414 {"( 2.5.13.13 NAME 'booleanMatch' "
4415 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4416 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4418 booleanMatch, NULL, NULL,
4421 {"( 2.5.13.14 NAME 'integerMatch' "
4422 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4423 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4425 integerMatch, integerIndexer, integerFilter,
4428 {"( 2.5.13.16 NAME 'bitStringMatch' "
4429 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4430 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4432 bitStringMatch, bitStringIndexer, bitStringFilter,
4435 {"( 2.5.13.17 NAME 'octetStringMatch' "
4436 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4437 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4439 octetStringMatch, octetStringIndexer, octetStringFilter,
4442 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4443 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4444 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4446 telephoneNumberMatch,
4447 telephoneNumberIndexer,
4448 telephoneNumberFilter,
4451 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4452 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4453 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4455 telephoneNumberSubstringsMatch,
4456 telephoneNumberSubstringsIndexer,
4457 telephoneNumberSubstringsFilter,
4460 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4461 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4462 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4467 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4468 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4469 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4471 uniqueMemberMatch, NULL, NULL,
4474 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4475 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4476 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4478 protocolInformationMatch, NULL, NULL,
4481 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4482 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4483 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4485 generalizedTimeMatch, NULL, NULL,
4488 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4489 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4492 generalizedTimeOrderingMatch, NULL, NULL,
4495 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4496 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4497 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4499 integerFirstComponentMatch, NULL, NULL,
4502 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4503 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4504 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4506 objectIdentifierFirstComponentMatch, NULL, NULL,
4510 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4511 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4512 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4513 certificateExactConvert, NULL,
4514 certificateExactMatch,
4515 certificateExactIndexer, certificateExactFilter,
4519 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4520 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4521 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4523 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4524 IA5StringApproxMatchOID },
4526 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4527 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4528 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4530 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4531 IA5StringApproxMatchOID },
4533 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4534 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4537 caseIgnoreIA5SubstringsMatch,
4538 caseIgnoreIA5SubstringsIndexer,
4539 caseIgnoreIA5SubstringsFilter,
4542 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4543 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4546 caseExactIA5SubstringsMatch,
4547 caseExactIA5SubstringsIndexer,
4548 caseExactIA5SubstringsFilter,
4551 #ifdef SLAPD_AUTHPASSWD
4552 /* needs updating */
4553 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4554 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4557 authPasswordMatch, NULL, NULL,
4561 #ifdef SLAPD_ACI_ENABLED
4562 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4563 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4566 OpenLDAPaciMatch, NULL, NULL,
4570 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4571 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4574 integerBitAndMatch, NULL, NULL,
4577 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4578 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4581 integerBitOrMatch, NULL, NULL,
4584 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4588 slap_schema_init( void )
4593 /* we should only be called once (from main) */
4594 assert( schema_init_done == 0 );
4596 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4597 res = register_syntax( syntax_defs[i].sd_desc,
4598 syntax_defs[i].sd_flags,
4599 syntax_defs[i].sd_validate,
4600 syntax_defs[i].sd_normalize,
4601 syntax_defs[i].sd_pretty
4602 #ifdef SLAPD_BINARY_CONVERSION
4604 syntax_defs[i].sd_ber2str,
4605 syntax_defs[i].sd_str2ber
4610 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4611 syntax_defs[i].sd_desc );
4616 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4617 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4619 "slap_schema_init: Ingoring unusable matching rule %s\n",
4620 mrule_defs[i].mrd_desc );
4624 res = register_matching_rule(
4625 mrule_defs[i].mrd_desc,
4626 mrule_defs[i].mrd_usage,
4627 mrule_defs[i].mrd_convert,
4628 mrule_defs[i].mrd_normalize,
4629 mrule_defs[i].mrd_match,
4630 mrule_defs[i].mrd_indexer,
4631 mrule_defs[i].mrd_filter,
4632 mrule_defs[i].mrd_associated );
4636 "slap_schema_init: Error registering matching rule %s\n",
4637 mrule_defs[i].mrd_desc );
4642 res = slap_schema_load();
4643 schema_init_done = 1;
4648 schema_destroy( void )