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, (struct berval *) assertedValue, LDAP_UTF8_NOCASEFOLD );
1003 return LDAP_SUCCESS;
1007 caseExactIgnoreSubstringsMatch(
1012 struct berval *value,
1013 void *assertedValue )
1016 SubstringsAssertion *sub = NULL;
1017 struct berval left = { 0, NULL };
1023 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1024 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1026 if ( UTF8bvnormalize( value, &left, casefold ) == NULL ) {
1032 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1038 /* Add up asserted input length */
1039 if( sub->sa_initial.bv_val ) {
1040 inlen += sub->sa_initial.bv_len;
1043 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1044 inlen += sub->sa_any[i].bv_len;
1047 if( sub->sa_final.bv_val ) {
1048 inlen += sub->sa_final.bv_len;
1051 if( sub->sa_initial.bv_val ) {
1052 if( inlen > left.bv_len ) {
1057 match = memcmp( sub->sa_initial.bv_val, left.bv_val,
1058 sub->sa_initial.bv_len );
1064 left.bv_val += sub->sa_initial.bv_len;
1065 left.bv_len -= sub->sa_initial.bv_len;
1066 inlen -= sub->sa_initial.bv_len;
1069 if( sub->sa_final.bv_val ) {
1070 if( inlen > left.bv_len ) {
1075 match = memcmp( sub->sa_final.bv_val,
1076 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1077 sub->sa_final.bv_len );
1083 left.bv_len -= sub->sa_final.bv_len;
1084 inlen -= sub->sa_final.bv_len;
1088 for(i=0; sub->sa_any[i].bv_val; i++) {
1093 if( inlen > left.bv_len ) {
1094 /* not enough length */
1099 if( sub->sa_any[i].bv_len == 0 ) {
1103 p = ber_bvchr( &left, *sub->sa_any[i].bv_val );
1109 idx = p - left.bv_val;
1111 if( idx >= left.bv_len ) {
1112 /* this shouldn't happen */
1114 if ( sub->sa_final.bv_val )
1115 ch_free( sub->sa_final.bv_val );
1117 ber_bvarray_free( sub->sa_any );
1118 if ( sub->sa_initial.bv_val )
1119 ch_free( sub->sa_initial.bv_val );
1127 if( sub->sa_any[i].bv_len > left.bv_len ) {
1128 /* not enough left */
1133 match = memcmp( left.bv_val,
1134 sub->sa_any[i].bv_val,
1135 sub->sa_any[i].bv_len );
1143 left.bv_val += sub->sa_any[i].bv_len;
1144 left.bv_len -= sub->sa_any[i].bv_len;
1145 inlen -= sub->sa_any[i].bv_len;
1152 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1153 if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
1154 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1158 return LDAP_SUCCESS;
1161 /* Index generation function */
1162 static int caseExactIgnoreIndexer(
1167 struct berval *prefix,
1175 HASH_CONTEXT HASHcontext;
1176 unsigned char HASHdigest[HASH_BYTES];
1177 struct berval digest;
1178 digest.bv_val = HASHdigest;
1179 digest.bv_len = sizeof(HASHdigest);
1181 for( i=0; values[i].bv_val != NULL; i++ ) {
1182 /* empty - just count them */
1185 /* we should have at least one value at this point */
1188 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1190 slen = syntax->ssyn_oidlen;
1191 mlen = mr->smr_oidlen;
1193 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1194 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1196 for( i=0; values[i].bv_val != NULL; i++ ) {
1197 struct berval value;
1198 UTF8bvnormalize( &values[i], &value, casefold );
1200 HASH_Init( &HASHcontext );
1201 if( prefix != NULL && prefix->bv_len > 0 ) {
1202 HASH_Update( &HASHcontext,
1203 prefix->bv_val, prefix->bv_len );
1205 HASH_Update( &HASHcontext,
1206 syntax->ssyn_oid, slen );
1207 HASH_Update( &HASHcontext,
1208 mr->smr_oid, mlen );
1209 HASH_Update( &HASHcontext,
1210 value.bv_val, value.bv_len );
1211 HASH_Final( HASHdigest, &HASHcontext );
1213 free( value.bv_val );
1215 ber_dupbv( &keys[i], &digest );
1218 keys[i].bv_val = NULL;
1220 return LDAP_SUCCESS;
1223 /* Index generation function */
1224 static int caseExactIgnoreFilter(
1229 struct berval *prefix,
1236 HASH_CONTEXT HASHcontext;
1237 unsigned char HASHdigest[HASH_BYTES];
1238 struct berval value = { 0, NULL };
1239 struct berval digest;
1241 digest.bv_val = HASHdigest;
1242 digest.bv_len = sizeof(HASHdigest);
1244 slen = syntax->ssyn_oidlen;
1245 mlen = mr->smr_oidlen;
1247 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1248 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1250 UTF8bvnormalize( (struct berval *) assertValue, &value, casefold );
1251 /* This usually happens if filter contains bad UTF8 */
1252 if( value.bv_val == NULL ) {
1253 keys = ch_malloc( sizeof( struct berval ) );
1254 keys[0].bv_val = NULL;
1255 return LDAP_SUCCESS;
1258 keys = ch_malloc( sizeof( struct berval ) * 2 );
1260 HASH_Init( &HASHcontext );
1261 if( prefix != NULL && prefix->bv_len > 0 ) {
1262 HASH_Update( &HASHcontext,
1263 prefix->bv_val, prefix->bv_len );
1265 HASH_Update( &HASHcontext,
1266 syntax->ssyn_oid, slen );
1267 HASH_Update( &HASHcontext,
1268 mr->smr_oid, mlen );
1269 HASH_Update( &HASHcontext,
1270 value.bv_val, value.bv_len );
1271 HASH_Final( HASHdigest, &HASHcontext );
1273 ber_dupbv( keys, &digest );
1274 keys[1].bv_val = NULL;
1276 free( value.bv_val );
1279 return LDAP_SUCCESS;
1282 /* Substrings Index generation function */
1283 static int caseExactIgnoreSubstringsIndexer(
1288 struct berval *prefix,
1298 HASH_CONTEXT HASHcontext;
1299 unsigned char HASHdigest[HASH_BYTES];
1300 struct berval digest;
1301 digest.bv_val = HASHdigest;
1302 digest.bv_len = sizeof(HASHdigest);
1306 for( i=0; values[i].bv_val != NULL; i++ ) {
1307 /* empty - just count them */
1310 /* we should have at least one value at this point */
1313 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1314 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1316 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1317 for( i=0; values[i].bv_val != NULL; i++ ) {
1318 UTF8bvnormalize( &values[i], &nvalues[i], casefold );
1320 nvalues[i].bv_val = NULL;
1323 for( i=0; values[i].bv_val != NULL; i++ ) {
1324 /* count number of indices to generate */
1325 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1329 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1330 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1331 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1332 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1334 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1338 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1339 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1340 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1344 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1345 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1346 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1347 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1349 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1355 /* no keys to generate */
1357 ber_bvarray_free( nvalues );
1358 return LDAP_SUCCESS;
1361 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1363 slen = syntax->ssyn_oidlen;
1364 mlen = mr->smr_oidlen;
1367 for( i=0; values[i].bv_val != NULL; i++ ) {
1370 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1372 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1373 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1375 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1376 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1378 for( j=0; j<max; j++ ) {
1379 HASH_Init( &HASHcontext );
1380 if( prefix != NULL && prefix->bv_len > 0 ) {
1381 HASH_Update( &HASHcontext,
1382 prefix->bv_val, prefix->bv_len );
1385 HASH_Update( &HASHcontext,
1386 &pre, sizeof( pre ) );
1387 HASH_Update( &HASHcontext,
1388 syntax->ssyn_oid, slen );
1389 HASH_Update( &HASHcontext,
1390 mr->smr_oid, mlen );
1391 HASH_Update( &HASHcontext,
1392 &values[i].bv_val[j],
1393 SLAP_INDEX_SUBSTR_MAXLEN );
1394 HASH_Final( HASHdigest, &HASHcontext );
1396 ber_dupbv( &keys[nkeys++], &digest );
1400 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1401 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1403 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1406 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1407 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1408 HASH_Init( &HASHcontext );
1409 if( prefix != NULL && prefix->bv_len > 0 ) {
1410 HASH_Update( &HASHcontext,
1411 prefix->bv_val, prefix->bv_len );
1413 HASH_Update( &HASHcontext,
1414 &pre, sizeof( pre ) );
1415 HASH_Update( &HASHcontext,
1416 syntax->ssyn_oid, slen );
1417 HASH_Update( &HASHcontext,
1418 mr->smr_oid, mlen );
1419 HASH_Update( &HASHcontext,
1420 values[i].bv_val, j );
1421 HASH_Final( HASHdigest, &HASHcontext );
1423 ber_dupbv( &keys[nkeys++], &digest );
1426 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1427 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1428 HASH_Init( &HASHcontext );
1429 if( prefix != NULL && prefix->bv_len > 0 ) {
1430 HASH_Update( &HASHcontext,
1431 prefix->bv_val, prefix->bv_len );
1433 HASH_Update( &HASHcontext,
1434 &pre, sizeof( pre ) );
1435 HASH_Update( &HASHcontext,
1436 syntax->ssyn_oid, slen );
1437 HASH_Update( &HASHcontext,
1438 mr->smr_oid, mlen );
1439 HASH_Update( &HASHcontext,
1440 &values[i].bv_val[values[i].bv_len-j], j );
1441 HASH_Final( HASHdigest, &HASHcontext );
1443 ber_dupbv( &keys[nkeys++], &digest );
1451 keys[nkeys].bv_val = NULL;
1458 ber_bvarray_free( nvalues );
1460 return LDAP_SUCCESS;
1463 static int caseExactIgnoreSubstringsFilter(
1468 struct berval *prefix,
1472 SubstringsAssertion *sa;
1475 ber_len_t nkeys = 0;
1476 size_t slen, mlen, klen;
1478 HASH_CONTEXT HASHcontext;
1479 unsigned char HASHdigest[HASH_BYTES];
1480 struct berval *value;
1481 struct berval digest;
1483 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1484 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1486 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1489 return LDAP_SUCCESS;
1492 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1493 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1498 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1500 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1501 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1502 /* don't bother accounting for stepping */
1503 nkeys += sa->sa_any[i].bv_len -
1504 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1509 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1510 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1516 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1517 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1518 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1521 return LDAP_SUCCESS;
1524 digest.bv_val = HASHdigest;
1525 digest.bv_len = sizeof(HASHdigest);
1527 slen = syntax->ssyn_oidlen;
1528 mlen = mr->smr_oidlen;
1530 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1533 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1534 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1536 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1537 value = &sa->sa_initial;
1539 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1540 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1542 HASH_Init( &HASHcontext );
1543 if( prefix != NULL && prefix->bv_len > 0 ) {
1544 HASH_Update( &HASHcontext,
1545 prefix->bv_val, prefix->bv_len );
1547 HASH_Update( &HASHcontext,
1548 &pre, sizeof( pre ) );
1549 HASH_Update( &HASHcontext,
1550 syntax->ssyn_oid, slen );
1551 HASH_Update( &HASHcontext,
1552 mr->smr_oid, mlen );
1553 HASH_Update( &HASHcontext,
1554 value->bv_val, klen );
1555 HASH_Final( HASHdigest, &HASHcontext );
1557 ber_dupbv( &keys[nkeys++], &digest );
1560 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1562 pre = SLAP_INDEX_SUBSTR_PREFIX;
1563 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1565 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1566 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1570 value = &sa->sa_any[i];
1573 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1574 j += SLAP_INDEX_SUBSTR_STEP )
1576 HASH_Init( &HASHcontext );
1577 if( prefix != NULL && prefix->bv_len > 0 ) {
1578 HASH_Update( &HASHcontext,
1579 prefix->bv_val, prefix->bv_len );
1581 HASH_Update( &HASHcontext,
1582 &pre, sizeof( pre ) );
1583 HASH_Update( &HASHcontext,
1584 syntax->ssyn_oid, slen );
1585 HASH_Update( &HASHcontext,
1586 mr->smr_oid, mlen );
1587 HASH_Update( &HASHcontext,
1588 &value->bv_val[j], klen );
1589 HASH_Final( HASHdigest, &HASHcontext );
1591 ber_dupbv( &keys[nkeys++], &digest );
1597 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1598 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1600 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1601 value = &sa->sa_final;
1603 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1604 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1606 HASH_Init( &HASHcontext );
1607 if( prefix != NULL && prefix->bv_len > 0 ) {
1608 HASH_Update( &HASHcontext,
1609 prefix->bv_val, prefix->bv_len );
1611 HASH_Update( &HASHcontext,
1612 &pre, sizeof( pre ) );
1613 HASH_Update( &HASHcontext,
1614 syntax->ssyn_oid, slen );
1615 HASH_Update( &HASHcontext,
1616 mr->smr_oid, mlen );
1617 HASH_Update( &HASHcontext,
1618 &value->bv_val[value->bv_len-klen], klen );
1619 HASH_Final( HASHdigest, &HASHcontext );
1621 ber_dupbv( &keys[nkeys++], &digest );
1625 keys[nkeys].bv_val = NULL;
1631 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1632 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1633 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1636 return LDAP_SUCCESS;
1645 struct berval *value,
1646 void *assertedValue )
1648 *matchp = UTF8bvnormcmp( value, (struct berval *) assertedValue, LDAP_UTF8_CASEFOLD );
1649 return LDAP_SUCCESS;
1655 struct berval *val )
1659 if( val->bv_len == 0 ) {
1660 /* disallow empty strings */
1661 return LDAP_INVALID_SYNTAX;
1664 if( OID_LEADCHAR(val->bv_val[0]) ) {
1666 for(i=1; i < val->bv_len; i++) {
1667 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1668 if( dot++ ) return 1;
1669 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1672 return LDAP_INVALID_SYNTAX;
1676 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1678 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1679 for(i=1; i < val->bv_len; i++) {
1680 if( !DESC_CHAR(val->bv_val[i] ) ) {
1681 return LDAP_INVALID_SYNTAX;
1685 return LDAP_SUCCESS;
1688 return LDAP_INVALID_SYNTAX;
1697 struct berval *value,
1698 void *assertedValue )
1701 int vsign=0, avsign=0;
1702 struct berval *asserted;
1703 ber_len_t vlen, avlen;
1706 /* Start off pessimistic */
1709 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1711 vlen = value->bv_len;
1713 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1714 /* empty -- skip spaces */
1716 else if ( *v == '+' ) {
1719 else if ( *v == '-' ) {
1722 else if ( ASCII_DIGIT(*v) ) {
1723 if ( vsign == 0 ) vsign = 1;
1731 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1733 asserted = (struct berval *) assertedValue;
1734 av = asserted->bv_val;
1735 avlen = asserted->bv_len;
1737 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1738 /* empty -- skip spaces */
1740 else if ( *av == '+' ) {
1743 else if ( *av == '-' ) {
1746 else if ( ASCII_DIGIT(*av) ) {
1747 if ( avsign == 0 ) avsign = 1;
1755 /* The two ?sign vars are now one of :
1756 -2 negative non-zero number
1758 0 0 collapse these three to 0
1760 +2 positive non-zero number
1762 if ( abs( vsign ) == 1 ) vsign = 0;
1763 if ( abs( avsign ) == 1 ) avsign = 0;
1765 if( vsign != avsign ) return LDAP_SUCCESS;
1767 /* Check the significant digits */
1768 while( vlen && avlen ) {
1769 if( *v != *av ) break;
1776 /* If all digits compared equal, the numbers are equal */
1777 if(( vlen == 0 ) && ( avlen == 0 )) {
1780 return LDAP_SUCCESS;
1786 struct berval *val )
1790 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1792 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1793 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1794 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1795 return LDAP_INVALID_SYNTAX;
1798 for( i=1; i < val->bv_len; i++ ) {
1799 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1802 return LDAP_SUCCESS;
1809 struct berval *normalized )
1819 /* Ignore leading spaces */
1820 while ( len && ( *p == ' ' )) {
1827 negative = ( *p == '-' );
1828 if(( *p == '-' ) || ( *p == '+' )) {
1834 /* Ignore leading zeros */
1835 while ( len && ( *p == '0' )) {
1840 /* If there are no non-zero digits left, the number is zero, otherwise
1841 allocate space for the number and copy it into the buffer */
1843 normalized->bv_val = ch_strdup("0");
1844 normalized->bv_len = 1;
1847 normalized->bv_len = len+negative;
1848 normalized->bv_val = ch_malloc( normalized->bv_len );
1850 normalized->bv_val[0] = '-';
1852 AC_MEMCPY( normalized->bv_val + negative, p, len );
1855 return LDAP_SUCCESS;
1858 /* Index generation function */
1859 static int integerIndexer(
1864 struct berval *prefix,
1871 /* we should have at least one value at this point */
1872 assert( values != NULL && values[0].bv_val != NULL );
1874 for( i=0; values[i].bv_val != NULL; i++ ) {
1875 /* empty -- just count them */
1878 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1880 for( i=0; values[i].bv_val != NULL; i++ ) {
1881 integerNormalize( syntax, &values[i], &keys[i] );
1884 keys[i].bv_val = NULL;
1886 return LDAP_SUCCESS;
1889 /* Index generation function */
1890 static int integerFilter(
1895 struct berval *prefix,
1901 keys = ch_malloc( sizeof( struct berval ) * 2 );
1902 integerNormalize( syntax, assertValue, &keys[0] );
1903 keys[1].bv_val = NULL;
1906 return LDAP_SUCCESS;
1911 countryStringValidate(
1913 struct berval *val )
1915 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1917 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1918 return LDAP_INVALID_SYNTAX;
1920 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1921 return LDAP_INVALID_SYNTAX;
1924 return LDAP_SUCCESS;
1928 printableStringValidate(
1930 struct berval *val )
1934 for(i=0; i < val->bv_len; i++) {
1935 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1936 return LDAP_INVALID_SYNTAX;
1940 return LDAP_SUCCESS;
1944 printablesStringValidate(
1946 struct berval *val )
1950 for(i=0; i < val->bv_len; i++) {
1951 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1952 return LDAP_INVALID_SYNTAX;
1956 return LDAP_SUCCESS;
1962 struct berval *val )
1966 for(i=0; i < val->bv_len; i++) {
1967 if( !LDAP_ASCII(val->bv_val[i]) ) {
1968 return LDAP_INVALID_SYNTAX;
1972 return LDAP_SUCCESS;
1979 struct berval *normalized )
1985 /* Ignore initial whitespace */
1986 while ( ASCII_SPACE( *p ) ) {
1990 normalized->bv_val = ch_strdup( p );
1991 p = q = normalized->bv_val;
1994 if ( ASCII_SPACE( *p ) ) {
1997 /* Ignore the extra whitespace */
1998 while ( ASCII_SPACE( *p ) ) {
2006 assert( normalized->bv_val <= p );
2010 * If the string ended in space, backup the pointer one
2011 * position. One is enough because the above loop collapsed
2012 * all whitespace to a single space.
2015 if ( ASCII_SPACE( q[-1] ) ) {
2019 /* null terminate */
2022 normalized->bv_len = q - normalized->bv_val;
2024 return LDAP_SUCCESS;
2033 struct berval *value,
2034 void *assertedValue )
2036 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2039 match = strncmp( value->bv_val,
2040 ((struct berval *) assertedValue)->bv_val,
2045 return LDAP_SUCCESS;
2049 caseExactIA5SubstringsMatch(
2054 struct berval *value,
2055 void *assertedValue )
2058 SubstringsAssertion *sub = assertedValue;
2059 struct berval left = *value;
2063 /* Add up asserted input length */
2064 if( sub->sa_initial.bv_val ) {
2065 inlen += sub->sa_initial.bv_len;
2068 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2069 inlen += sub->sa_any[i].bv_len;
2072 if( sub->sa_final.bv_val ) {
2073 inlen += sub->sa_final.bv_len;
2076 if( sub->sa_initial.bv_val ) {
2077 if( inlen > left.bv_len ) {
2082 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2083 sub->sa_initial.bv_len );
2089 left.bv_val += sub->sa_initial.bv_len;
2090 left.bv_len -= sub->sa_initial.bv_len;
2091 inlen -= sub->sa_initial.bv_len;
2094 if( sub->sa_final.bv_val ) {
2095 if( inlen > left.bv_len ) {
2100 match = strncmp( sub->sa_final.bv_val,
2101 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2102 sub->sa_final.bv_len );
2108 left.bv_len -= sub->sa_final.bv_len;
2109 inlen -= sub->sa_final.bv_len;
2113 for(i=0; sub->sa_any[i].bv_val; i++) {
2118 if( inlen > left.bv_len ) {
2119 /* not enough length */
2124 if( sub->sa_any[i].bv_len == 0 ) {
2128 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2135 idx = p - left.bv_val;
2137 if( idx >= left.bv_len ) {
2138 /* this shouldn't happen */
2145 if( sub->sa_any[i].bv_len > left.bv_len ) {
2146 /* not enough left */
2151 match = strncmp( left.bv_val,
2152 sub->sa_any[i].bv_val,
2153 sub->sa_any[i].bv_len );
2161 left.bv_val += sub->sa_any[i].bv_len;
2162 left.bv_len -= sub->sa_any[i].bv_len;
2163 inlen -= sub->sa_any[i].bv_len;
2169 return LDAP_SUCCESS;
2172 /* Index generation function */
2173 static int caseExactIA5Indexer(
2178 struct berval *prefix,
2185 HASH_CONTEXT HASHcontext;
2186 unsigned char HASHdigest[HASH_BYTES];
2187 struct berval digest;
2188 digest.bv_val = HASHdigest;
2189 digest.bv_len = sizeof(HASHdigest);
2191 for( i=0; values[i].bv_val != NULL; i++ ) {
2192 /* empty - just count them */
2195 /* we should have at least one value at this point */
2198 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2200 slen = syntax->ssyn_oidlen;
2201 mlen = mr->smr_oidlen;
2203 for( i=0; values[i].bv_val != NULL; i++ ) {
2204 struct berval *value = &values[i];
2206 HASH_Init( &HASHcontext );
2207 if( prefix != NULL && prefix->bv_len > 0 ) {
2208 HASH_Update( &HASHcontext,
2209 prefix->bv_val, prefix->bv_len );
2211 HASH_Update( &HASHcontext,
2212 syntax->ssyn_oid, slen );
2213 HASH_Update( &HASHcontext,
2214 mr->smr_oid, mlen );
2215 HASH_Update( &HASHcontext,
2216 value->bv_val, value->bv_len );
2217 HASH_Final( HASHdigest, &HASHcontext );
2219 ber_dupbv( &keys[i], &digest );
2222 keys[i].bv_val = NULL;
2224 return LDAP_SUCCESS;
2227 /* Index generation function */
2228 static int caseExactIA5Filter(
2233 struct berval *prefix,
2239 HASH_CONTEXT HASHcontext;
2240 unsigned char HASHdigest[HASH_BYTES];
2241 struct berval *value;
2242 struct berval digest;
2243 digest.bv_val = HASHdigest;
2244 digest.bv_len = sizeof(HASHdigest);
2246 slen = syntax->ssyn_oidlen;
2247 mlen = mr->smr_oidlen;
2249 value = (struct berval *) assertValue;
2251 keys = ch_malloc( sizeof( struct berval ) * 2 );
2253 HASH_Init( &HASHcontext );
2254 if( prefix != NULL && prefix->bv_len > 0 ) {
2255 HASH_Update( &HASHcontext,
2256 prefix->bv_val, prefix->bv_len );
2258 HASH_Update( &HASHcontext,
2259 syntax->ssyn_oid, slen );
2260 HASH_Update( &HASHcontext,
2261 mr->smr_oid, mlen );
2262 HASH_Update( &HASHcontext,
2263 value->bv_val, value->bv_len );
2264 HASH_Final( HASHdigest, &HASHcontext );
2266 ber_dupbv( &keys[0], &digest );
2267 keys[1].bv_val = NULL;
2270 return LDAP_SUCCESS;
2273 /* Substrings Index generation function */
2274 static int caseExactIA5SubstringsIndexer(
2279 struct berval *prefix,
2286 HASH_CONTEXT HASHcontext;
2287 unsigned char HASHdigest[HASH_BYTES];
2288 struct berval digest;
2289 digest.bv_val = HASHdigest;
2290 digest.bv_len = sizeof(HASHdigest);
2292 /* we should have at least one value at this point */
2293 assert( values != NULL && values[0].bv_val != NULL );
2296 for( i=0; values[i].bv_val != NULL; i++ ) {
2297 /* count number of indices to generate */
2298 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2302 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2303 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2304 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2305 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2307 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2311 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2312 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2313 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2317 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2318 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2319 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2320 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2322 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2328 /* no keys to generate */
2330 return LDAP_SUCCESS;
2333 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2335 slen = syntax->ssyn_oidlen;
2336 mlen = mr->smr_oidlen;
2339 for( i=0; values[i].bv_val != NULL; i++ ) {
2341 struct berval *value;
2344 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2346 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2347 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2349 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2350 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2352 for( j=0; j<max; j++ ) {
2353 HASH_Init( &HASHcontext );
2354 if( prefix != NULL && prefix->bv_len > 0 ) {
2355 HASH_Update( &HASHcontext,
2356 prefix->bv_val, prefix->bv_len );
2359 HASH_Update( &HASHcontext,
2360 &pre, sizeof( pre ) );
2361 HASH_Update( &HASHcontext,
2362 syntax->ssyn_oid, slen );
2363 HASH_Update( &HASHcontext,
2364 mr->smr_oid, mlen );
2365 HASH_Update( &HASHcontext,
2367 SLAP_INDEX_SUBSTR_MAXLEN );
2368 HASH_Final( HASHdigest, &HASHcontext );
2370 ber_dupbv( &keys[nkeys++], &digest );
2374 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2375 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2377 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2380 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2381 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2382 HASH_Init( &HASHcontext );
2383 if( prefix != NULL && prefix->bv_len > 0 ) {
2384 HASH_Update( &HASHcontext,
2385 prefix->bv_val, prefix->bv_len );
2387 HASH_Update( &HASHcontext,
2388 &pre, sizeof( pre ) );
2389 HASH_Update( &HASHcontext,
2390 syntax->ssyn_oid, slen );
2391 HASH_Update( &HASHcontext,
2392 mr->smr_oid, mlen );
2393 HASH_Update( &HASHcontext,
2395 HASH_Final( HASHdigest, &HASHcontext );
2397 ber_dupbv( &keys[nkeys++], &digest );
2400 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2401 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2402 HASH_Init( &HASHcontext );
2403 if( prefix != NULL && prefix->bv_len > 0 ) {
2404 HASH_Update( &HASHcontext,
2405 prefix->bv_val, prefix->bv_len );
2407 HASH_Update( &HASHcontext,
2408 &pre, sizeof( pre ) );
2409 HASH_Update( &HASHcontext,
2410 syntax->ssyn_oid, slen );
2411 HASH_Update( &HASHcontext,
2412 mr->smr_oid, mlen );
2413 HASH_Update( &HASHcontext,
2414 &value->bv_val[value->bv_len-j], j );
2415 HASH_Final( HASHdigest, &HASHcontext );
2417 ber_dupbv( &keys[nkeys++], &digest );
2424 keys[nkeys].bv_val = NULL;
2431 return LDAP_SUCCESS;
2434 static int caseExactIA5SubstringsFilter(
2439 struct berval *prefix,
2443 SubstringsAssertion *sa = assertValue;
2445 ber_len_t nkeys = 0;
2446 size_t slen, mlen, klen;
2448 HASH_CONTEXT HASHcontext;
2449 unsigned char HASHdigest[HASH_BYTES];
2450 struct berval *value;
2451 struct berval digest;
2453 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2454 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2459 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2461 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2462 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2463 /* don't bother accounting for stepping */
2464 nkeys += sa->sa_any[i].bv_len -
2465 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2470 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2471 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2478 return LDAP_SUCCESS;
2481 digest.bv_val = HASHdigest;
2482 digest.bv_len = sizeof(HASHdigest);
2484 slen = syntax->ssyn_oidlen;
2485 mlen = mr->smr_oidlen;
2487 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2490 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2491 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2493 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2494 value = &sa->sa_initial;
2496 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2497 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2499 HASH_Init( &HASHcontext );
2500 if( prefix != NULL && prefix->bv_len > 0 ) {
2501 HASH_Update( &HASHcontext,
2502 prefix->bv_val, prefix->bv_len );
2504 HASH_Update( &HASHcontext,
2505 &pre, sizeof( pre ) );
2506 HASH_Update( &HASHcontext,
2507 syntax->ssyn_oid, slen );
2508 HASH_Update( &HASHcontext,
2509 mr->smr_oid, mlen );
2510 HASH_Update( &HASHcontext,
2511 value->bv_val, klen );
2512 HASH_Final( HASHdigest, &HASHcontext );
2514 ber_dupbv( &keys[nkeys++], &digest );
2517 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2519 pre = SLAP_INDEX_SUBSTR_PREFIX;
2520 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2522 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2523 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2527 value = &sa->sa_any[i];
2530 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2531 j += SLAP_INDEX_SUBSTR_STEP )
2533 HASH_Init( &HASHcontext );
2534 if( prefix != NULL && prefix->bv_len > 0 ) {
2535 HASH_Update( &HASHcontext,
2536 prefix->bv_val, prefix->bv_len );
2538 HASH_Update( &HASHcontext,
2539 &pre, sizeof( pre ) );
2540 HASH_Update( &HASHcontext,
2541 syntax->ssyn_oid, slen );
2542 HASH_Update( &HASHcontext,
2543 mr->smr_oid, mlen );
2544 HASH_Update( &HASHcontext,
2545 &value->bv_val[j], klen );
2546 HASH_Final( HASHdigest, &HASHcontext );
2548 ber_dupbv( &keys[nkeys++], &digest );
2553 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2554 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2556 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2557 value = &sa->sa_final;
2559 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2560 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2562 HASH_Init( &HASHcontext );
2563 if( prefix != NULL && prefix->bv_len > 0 ) {
2564 HASH_Update( &HASHcontext,
2565 prefix->bv_val, prefix->bv_len );
2567 HASH_Update( &HASHcontext,
2568 &pre, sizeof( pre ) );
2569 HASH_Update( &HASHcontext,
2570 syntax->ssyn_oid, slen );
2571 HASH_Update( &HASHcontext,
2572 mr->smr_oid, mlen );
2573 HASH_Update( &HASHcontext,
2574 &value->bv_val[value->bv_len-klen], klen );
2575 HASH_Final( HASHdigest, &HASHcontext );
2577 ber_dupbv( &keys[nkeys++], &digest );
2581 keys[nkeys].bv_val = NULL;
2588 return LDAP_SUCCESS;
2597 struct berval *value,
2598 void *assertedValue )
2600 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2602 if( match == 0 && value->bv_len ) {
2603 match = strncasecmp( value->bv_val,
2604 ((struct berval *) assertedValue)->bv_val,
2609 return LDAP_SUCCESS;
2613 caseIgnoreIA5SubstringsMatch(
2618 struct berval *value,
2619 void *assertedValue )
2622 SubstringsAssertion *sub = assertedValue;
2623 struct berval left = *value;
2627 /* Add up asserted input length */
2628 if( sub->sa_initial.bv_val ) {
2629 inlen += sub->sa_initial.bv_len;
2632 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2633 inlen += sub->sa_any[i].bv_len;
2636 if( sub->sa_final.bv_val ) {
2637 inlen += sub->sa_final.bv_len;
2640 if( sub->sa_initial.bv_val ) {
2641 if( inlen > left.bv_len ) {
2646 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2647 sub->sa_initial.bv_len );
2653 left.bv_val += sub->sa_initial.bv_len;
2654 left.bv_len -= sub->sa_initial.bv_len;
2655 inlen -= sub->sa_initial.bv_len;
2658 if( sub->sa_final.bv_val ) {
2659 if( inlen > left.bv_len ) {
2664 match = strncasecmp( sub->sa_final.bv_val,
2665 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2666 sub->sa_final.bv_len );
2672 left.bv_len -= sub->sa_final.bv_len;
2673 inlen -= sub->sa_final.bv_len;
2677 for(i=0; sub->sa_any[i].bv_val; i++) {
2682 if( inlen > left.bv_len ) {
2683 /* not enough length */
2688 if( sub->sa_any[i].bv_len == 0 ) {
2692 p = bvcasechr( &left, *sub->sa_any[i].bv_val, &idx );
2699 assert( idx < left.bv_len );
2700 if( idx >= left.bv_len ) {
2701 /* this shouldn't happen */
2708 if( sub->sa_any[i].bv_len > left.bv_len ) {
2709 /* not enough left */
2714 match = strncasecmp( left.bv_val,
2715 sub->sa_any[i].bv_val,
2716 sub->sa_any[i].bv_len );
2725 left.bv_val += sub->sa_any[i].bv_len;
2726 left.bv_len -= sub->sa_any[i].bv_len;
2727 inlen -= sub->sa_any[i].bv_len;
2733 return LDAP_SUCCESS;
2736 /* Index generation function */
2737 static int caseIgnoreIA5Indexer(
2742 struct berval *prefix,
2749 HASH_CONTEXT HASHcontext;
2750 unsigned char HASHdigest[HASH_BYTES];
2751 struct berval digest;
2752 digest.bv_val = HASHdigest;
2753 digest.bv_len = sizeof(HASHdigest);
2755 /* we should have at least one value at this point */
2756 assert( values != NULL && values[0].bv_val != NULL );
2758 for( i=0; values[i].bv_val != NULL; i++ ) {
2759 /* just count them */
2762 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2764 slen = syntax->ssyn_oidlen;
2765 mlen = mr->smr_oidlen;
2767 for( i=0; values[i].bv_val != NULL; i++ ) {
2768 struct berval value;
2769 ber_dupbv( &value, &values[i] );
2770 ldap_pvt_str2upper( value.bv_val );
2772 HASH_Init( &HASHcontext );
2773 if( prefix != NULL && prefix->bv_len > 0 ) {
2774 HASH_Update( &HASHcontext,
2775 prefix->bv_val, prefix->bv_len );
2777 HASH_Update( &HASHcontext,
2778 syntax->ssyn_oid, slen );
2779 HASH_Update( &HASHcontext,
2780 mr->smr_oid, mlen );
2781 HASH_Update( &HASHcontext,
2782 value.bv_val, value.bv_len );
2783 HASH_Final( HASHdigest, &HASHcontext );
2785 free( value.bv_val );
2787 ber_dupbv( &keys[i], &digest );
2790 keys[i].bv_val = NULL;
2792 return LDAP_SUCCESS;
2795 /* Index generation function */
2796 static int caseIgnoreIA5Filter(
2801 struct berval *prefix,
2807 HASH_CONTEXT HASHcontext;
2808 unsigned char HASHdigest[HASH_BYTES];
2809 struct berval value;
2810 struct berval digest;
2811 digest.bv_val = HASHdigest;
2812 digest.bv_len = sizeof(HASHdigest);
2814 slen = syntax->ssyn_oidlen;
2815 mlen = mr->smr_oidlen;
2817 ber_dupbv( &value, (struct berval *) assertValue );
2818 ldap_pvt_str2upper( value.bv_val );
2820 keys = ch_malloc( sizeof( struct berval ) * 2 );
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 syntax->ssyn_oid, slen );
2829 HASH_Update( &HASHcontext,
2830 mr->smr_oid, mlen );
2831 HASH_Update( &HASHcontext,
2832 value.bv_val, value.bv_len );
2833 HASH_Final( HASHdigest, &HASHcontext );
2835 ber_dupbv( &keys[0], &digest );
2836 keys[1].bv_val = NULL;
2838 free( value.bv_val );
2842 return LDAP_SUCCESS;
2845 /* Substrings Index generation function */
2846 static int caseIgnoreIA5SubstringsIndexer(
2851 struct berval *prefix,
2858 HASH_CONTEXT HASHcontext;
2859 unsigned char HASHdigest[HASH_BYTES];
2860 struct berval digest;
2861 digest.bv_val = HASHdigest;
2862 digest.bv_len = sizeof(HASHdigest);
2864 /* we should have at least one value at this point */
2865 assert( values != NULL && values[0].bv_val != NULL );
2868 for( i=0; values[i].bv_val != NULL; i++ ) {
2869 /* count number of indices to generate */
2870 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2874 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2875 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2876 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2877 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2879 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2883 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2884 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2885 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2889 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2890 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2891 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2892 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2894 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2900 /* no keys to generate */
2902 return LDAP_SUCCESS;
2905 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2907 slen = syntax->ssyn_oidlen;
2908 mlen = mr->smr_oidlen;
2911 for( i=0; values[i].bv_val != NULL; i++ ) {
2913 struct berval value;
2915 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2917 ber_dupbv( &value, &values[i] );
2918 ldap_pvt_str2upper( value.bv_val );
2920 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2921 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2923 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2924 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2926 for( j=0; j<max; j++ ) {
2927 HASH_Init( &HASHcontext );
2928 if( prefix != NULL && prefix->bv_len > 0 ) {
2929 HASH_Update( &HASHcontext,
2930 prefix->bv_val, prefix->bv_len );
2933 HASH_Update( &HASHcontext,
2934 &pre, sizeof( pre ) );
2935 HASH_Update( &HASHcontext,
2936 syntax->ssyn_oid, slen );
2937 HASH_Update( &HASHcontext,
2938 mr->smr_oid, mlen );
2939 HASH_Update( &HASHcontext,
2941 SLAP_INDEX_SUBSTR_MAXLEN );
2942 HASH_Final( HASHdigest, &HASHcontext );
2944 ber_dupbv( &keys[nkeys++], &digest );
2948 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2949 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2951 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2954 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2955 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2956 HASH_Init( &HASHcontext );
2957 if( prefix != NULL && prefix->bv_len > 0 ) {
2958 HASH_Update( &HASHcontext,
2959 prefix->bv_val, prefix->bv_len );
2961 HASH_Update( &HASHcontext,
2962 &pre, sizeof( pre ) );
2963 HASH_Update( &HASHcontext,
2964 syntax->ssyn_oid, slen );
2965 HASH_Update( &HASHcontext,
2966 mr->smr_oid, mlen );
2967 HASH_Update( &HASHcontext,
2969 HASH_Final( HASHdigest, &HASHcontext );
2971 ber_dupbv( &keys[nkeys++], &digest );
2974 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2975 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2976 HASH_Init( &HASHcontext );
2977 if( prefix != NULL && prefix->bv_len > 0 ) {
2978 HASH_Update( &HASHcontext,
2979 prefix->bv_val, prefix->bv_len );
2981 HASH_Update( &HASHcontext,
2982 &pre, sizeof( pre ) );
2983 HASH_Update( &HASHcontext,
2984 syntax->ssyn_oid, slen );
2985 HASH_Update( &HASHcontext,
2986 mr->smr_oid, mlen );
2987 HASH_Update( &HASHcontext,
2988 &value.bv_val[value.bv_len-j], j );
2989 HASH_Final( HASHdigest, &HASHcontext );
2991 ber_dupbv( &keys[nkeys++], &digest );
2996 free( value.bv_val );
3000 keys[nkeys].bv_val = NULL;
3007 return LDAP_SUCCESS;
3010 static int caseIgnoreIA5SubstringsFilter(
3015 struct berval *prefix,
3019 SubstringsAssertion *sa = assertValue;
3021 ber_len_t nkeys = 0;
3022 size_t slen, mlen, klen;
3024 HASH_CONTEXT HASHcontext;
3025 unsigned char HASHdigest[HASH_BYTES];
3026 struct berval value;
3027 struct berval digest;
3029 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3030 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3035 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3037 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3038 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3039 /* don't bother accounting for stepping */
3040 nkeys += sa->sa_any[i].bv_len -
3041 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3046 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3047 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3054 return LDAP_SUCCESS;
3057 digest.bv_val = HASHdigest;
3058 digest.bv_len = sizeof(HASHdigest);
3060 slen = syntax->ssyn_oidlen;
3061 mlen = mr->smr_oidlen;
3063 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3066 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3067 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3069 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3070 ber_dupbv( &value, &sa->sa_initial );
3071 ldap_pvt_str2upper( value.bv_val );
3073 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3074 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3076 HASH_Init( &HASHcontext );
3077 if( prefix != NULL && prefix->bv_len > 0 ) {
3078 HASH_Update( &HASHcontext,
3079 prefix->bv_val, prefix->bv_len );
3081 HASH_Update( &HASHcontext,
3082 &pre, sizeof( pre ) );
3083 HASH_Update( &HASHcontext,
3084 syntax->ssyn_oid, slen );
3085 HASH_Update( &HASHcontext,
3086 mr->smr_oid, mlen );
3087 HASH_Update( &HASHcontext,
3088 value.bv_val, klen );
3089 HASH_Final( HASHdigest, &HASHcontext );
3091 free( value.bv_val );
3092 ber_dupbv( &keys[nkeys++], &digest );
3095 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3097 pre = SLAP_INDEX_SUBSTR_PREFIX;
3098 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3100 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3101 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3105 ber_dupbv( &value, &sa->sa_any[i] );
3106 ldap_pvt_str2upper( value.bv_val );
3109 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3110 j += SLAP_INDEX_SUBSTR_STEP )
3112 HASH_Init( &HASHcontext );
3113 if( prefix != NULL && prefix->bv_len > 0 ) {
3114 HASH_Update( &HASHcontext,
3115 prefix->bv_val, prefix->bv_len );
3117 HASH_Update( &HASHcontext,
3118 &pre, sizeof( pre ) );
3119 HASH_Update( &HASHcontext,
3120 syntax->ssyn_oid, slen );
3121 HASH_Update( &HASHcontext,
3122 mr->smr_oid, mlen );
3123 HASH_Update( &HASHcontext,
3124 &value.bv_val[j], klen );
3125 HASH_Final( HASHdigest, &HASHcontext );
3127 ber_dupbv( &keys[nkeys++], &digest );
3130 free( value.bv_val );
3134 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3135 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3137 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3138 ber_dupbv( &value, &sa->sa_final );
3139 ldap_pvt_str2upper( value.bv_val );
3141 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3142 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3144 HASH_Init( &HASHcontext );
3145 if( prefix != NULL && prefix->bv_len > 0 ) {
3146 HASH_Update( &HASHcontext,
3147 prefix->bv_val, prefix->bv_len );
3149 HASH_Update( &HASHcontext,
3150 &pre, sizeof( pre ) );
3151 HASH_Update( &HASHcontext,
3152 syntax->ssyn_oid, slen );
3153 HASH_Update( &HASHcontext,
3154 mr->smr_oid, mlen );
3155 HASH_Update( &HASHcontext,
3156 &value.bv_val[value.bv_len-klen], klen );
3157 HASH_Final( HASHdigest, &HASHcontext );
3159 free( value.bv_val );
3160 ber_dupbv( &keys[nkeys++], &digest );
3164 keys[nkeys].bv_val = NULL;
3171 return LDAP_SUCCESS;
3175 numericStringValidate(
3181 for(i=0; i < in->bv_len; i++) {
3182 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3183 return LDAP_INVALID_SYNTAX;
3187 return LDAP_SUCCESS;
3191 numericStringNormalize(
3194 struct berval *normalized )
3196 /* removal all spaces */
3199 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3202 q = normalized->bv_val;
3205 if ( ASCII_SPACE( *p ) ) {
3206 /* Ignore whitespace */
3213 /* we should have copied no more then is in val */
3214 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3216 /* null terminate */
3219 normalized->bv_len = q - normalized->bv_val;
3221 return LDAP_SUCCESS;
3225 objectIdentifierFirstComponentMatch(
3230 struct berval *value,
3231 void *assertedValue )
3233 int rc = LDAP_SUCCESS;
3235 struct berval *asserted = (struct berval *) assertedValue;
3239 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3240 return LDAP_INVALID_SYNTAX;
3243 /* trim leading white space */
3244 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3248 /* grab next word */
3249 oid.bv_val = &value->bv_val[i];
3250 oid.bv_len = value->bv_len - i;
3251 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3256 /* insert attributeTypes, objectclass check here */
3257 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3258 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3261 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3262 MatchingRule *asserted_mr = mr_bvfind( asserted );
3263 MatchingRule *stored_mr = mr_bvfind( &oid );
3265 if( asserted_mr == NULL ) {
3266 rc = SLAPD_COMPARE_UNDEFINED;
3268 match = asserted_mr != stored_mr;
3271 } else if ( !strcmp( syntax->ssyn_oid,
3272 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3274 AttributeType *asserted_at = at_bvfind( asserted );
3275 AttributeType *stored_at = at_bvfind( &oid );
3277 if( asserted_at == NULL ) {
3278 rc = SLAPD_COMPARE_UNDEFINED;
3280 match = asserted_at != stored_at;
3283 } else if ( !strcmp( syntax->ssyn_oid,
3284 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3286 ObjectClass *asserted_oc = oc_bvfind( asserted );
3287 ObjectClass *stored_oc = oc_bvfind( &oid );
3289 if( asserted_oc == NULL ) {
3290 rc = SLAPD_COMPARE_UNDEFINED;
3292 match = asserted_oc != stored_oc;
3298 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3299 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3300 match, value->bv_val, asserted->bv_val ));
3302 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3303 "%d\n\t\"%s\"\n\t\"%s\"\n",
3304 match, value->bv_val, asserted->bv_val );
3308 if( rc == LDAP_SUCCESS ) *matchp = match;
3318 struct berval *value,
3319 void *assertedValue )
3321 long lValue, lAssertedValue;
3323 /* safe to assume integers are NUL terminated? */
3324 lValue = strtoul(value->bv_val, NULL, 10);
3325 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3326 return LDAP_CONSTRAINT_VIOLATION;
3328 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3329 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3330 return LDAP_CONSTRAINT_VIOLATION;
3332 *matchp = (lValue & lAssertedValue);
3333 return LDAP_SUCCESS;
3342 struct berval *value,
3343 void *assertedValue )
3345 long lValue, lAssertedValue;
3347 /* safe to assume integers are NUL terminated? */
3348 lValue = strtoul(value->bv_val, NULL, 10);
3349 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3350 return LDAP_CONSTRAINT_VIOLATION;
3352 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3353 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3354 return LDAP_CONSTRAINT_VIOLATION;
3356 *matchp = (lValue | lAssertedValue);
3357 return LDAP_SUCCESS;
3361 #include <openssl/x509.h>
3362 #include <openssl/err.h>
3363 char digit[] = "0123456789";
3366 * Next function returns a string representation of a ASN1_INTEGER.
3367 * It works for unlimited lengths.
3370 static struct berval *
3371 asn1_integer2str(ASN1_INTEGER *a)
3376 /* We work backwards, make it fill from the end of buf */
3377 p = buf + sizeof(buf) - 1;
3380 if ( a == NULL || a->length == 0 ) {
3388 /* We want to preserve the original */
3389 copy = ch_malloc(n*sizeof(unsigned int));
3390 for (i = 0; i<n; i++) {
3391 copy[i] = a->data[i];
3395 * base indicates the index of the most significant
3396 * byte that might be nonzero. When it goes off the
3397 * end, we now there is nothing left to do.
3403 for (i = base; i<n; i++ ) {
3404 copy[i] += carry*256;
3405 carry = copy[i] % 10;
3410 * Way too large, we need to leave
3411 * room for sign if negative
3416 *--p = digit[carry];
3417 if (copy[base] == 0)
3423 if ( a->type == V_ASN1_NEG_INTEGER ) {
3427 return ber_bvstrdup(p);
3430 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3431 static struct berval *
3432 dn_openssl2ldap(X509_NAME *name)
3434 char issuer_dn[1024];
3437 bio = BIO_new(BIO_s_mem());
3440 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3441 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3442 ERR_error_string(ERR_get_error(),NULL)));
3444 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3445 "error creating BIO: %s\n",
3446 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3450 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3452 BIO_gets(bio, issuer_dn, 1024);
3455 return ber_bvstrdup(issuer_dn);
3459 * Given a certificate in DER format, extract the corresponding
3460 * assertion value for certificateExactMatch
3463 certificateExactConvert(
3465 struct berval * out )
3468 unsigned char *p = in->bv_val;
3469 struct berval *serial;
3470 struct berval *issuer_dn;
3471 struct berval *bv_tmp;
3473 xcert = d2i_X509(NULL, &p, in->bv_len);
3476 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3477 "certificateExactConvert: error parsing cert: %s\n",
3478 ERR_error_string(ERR_get_error(),NULL)));
3480 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3481 "error parsing cert: %s\n",
3482 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3484 return LDAP_INVALID_SYNTAX;
3487 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3490 return LDAP_INVALID_SYNTAX;
3492 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3496 return LDAP_INVALID_SYNTAX;
3498 /* Actually, dn_openssl2ldap returns in a normalized format, but
3499 it is different from our normalized format */
3501 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3505 return LDAP_INVALID_SYNTAX;
3511 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3512 out->bv_val = ch_malloc(out->bv_len);
3514 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3515 p += serial->bv_len;
3516 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3518 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3519 p += issuer_dn->bv_len;
3523 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3524 "certificateExactConvert: \n %s\n",
3527 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3529 out->bv_val, NULL, NULL );
3533 ber_bvfree(issuer_dn);
3535 return LDAP_SUCCESS;
3539 serial_and_issuer_parse(
3540 struct berval *assertion,
3541 struct berval **serial,
3542 struct berval **issuer_dn
3550 begin = assertion->bv_val;
3551 end = assertion->bv_val+assertion->bv_len-1;
3552 for (p=begin; p<=end && *p != '$'; p++)
3555 return LDAP_INVALID_SYNTAX;
3557 /* p now points at the $ sign, now use begin and end to delimit the
3559 while (ASCII_SPACE(*begin))
3562 while (ASCII_SPACE(*end))
3565 bv.bv_len = end-begin+1;
3567 *serial = ber_dupbv(NULL, &bv);
3569 /* now extract the issuer, remember p was at the dollar sign */
3571 end = assertion->bv_val+assertion->bv_len-1;
3572 while (ASCII_SPACE(*begin))
3574 /* should we trim spaces at the end too? is it safe always? */
3576 bv.bv_len = end-begin+1;
3578 dnNormalize( NULL, &bv, issuer_dn );
3580 return LDAP_SUCCESS;
3584 certificateExactMatch(
3589 struct berval *value,
3590 void *assertedValue )
3593 unsigned char *p = value->bv_val;
3594 struct berval *serial;
3595 struct berval *issuer_dn;
3596 struct berval *asserted_serial;
3597 struct berval *asserted_issuer_dn;
3600 xcert = d2i_X509(NULL, &p, value->bv_len);
3603 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3604 "certificateExactMatch: error parsing cert: %s\n",
3605 ERR_error_string(ERR_get_error(),NULL)));
3607 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3608 "error parsing cert: %s\n",
3609 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3611 return LDAP_INVALID_SYNTAX;
3614 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3615 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3619 serial_and_issuer_parse(assertedValue,
3621 &asserted_issuer_dn);
3626 slap_schema.si_syn_integer,
3627 slap_schema.si_mr_integerMatch,
3630 if ( ret == LDAP_SUCCESS ) {
3631 if ( *matchp == 0 ) {
3632 /* We need to normalize everything for dnMatch */
3636 slap_schema.si_syn_distinguishedName,
3637 slap_schema.si_mr_distinguishedNameMatch,
3639 asserted_issuer_dn);
3644 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3645 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3646 *matchp, serial->bv_val, issuer_dn->bv_val,
3647 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3649 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3650 "%d\n\t\"%s $ %s\"\n",
3651 *matchp, serial->bv_val, issuer_dn->bv_val );
3652 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3653 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3658 ber_bvfree(issuer_dn);
3659 ber_bvfree(asserted_serial);
3660 ber_bvfree(asserted_issuer_dn);
3666 * Index generation function
3667 * We just index the serials, in most scenarios the issuer DN is one of
3668 * a very small set of values.
3670 static int certificateExactIndexer(
3675 struct berval *prefix,
3683 struct berval * serial;
3685 /* we should have at least one value at this point */
3686 assert( values != NULL && values[0].bv_val != NULL );
3688 for( i=0; values[i].bv_val != NULL; i++ ) {
3689 /* empty -- just count them */
3692 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3694 for( i=0; values[i].bv_val != NULL; i++ ) {
3695 p = values[i].bv_val;
3696 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3699 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3700 "certificateExactIndexer: error parsing cert: %s\n",
3701 ERR_error_string(ERR_get_error(),NULL)));
3703 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3704 "error parsing cert: %s\n",
3705 ERR_error_string(ERR_get_error(),NULL),
3708 /* Do we leak keys on error? */
3709 return LDAP_INVALID_SYNTAX;
3712 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3714 integerNormalize( slap_schema.si_syn_integer,
3719 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3720 "certificateExactIndexer: returning: %s\n",
3723 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3730 keys[i].bv_val = NULL;
3732 return LDAP_SUCCESS;
3735 /* Index generation function */
3736 /* We think this is always called with a value in matching rule syntax */
3737 static int certificateExactFilter(
3742 struct berval *prefix,
3747 struct berval *asserted_serial;
3748 struct berval *asserted_issuer_dn;
3750 serial_and_issuer_parse(assertValue,
3752 &asserted_issuer_dn);
3754 keys = ch_malloc( sizeof( struct berval ) * 2 );
3755 integerNormalize( syntax, asserted_serial, &keys[0] );
3756 keys[1].bv_val = NULL;
3759 ber_bvfree(asserted_serial);
3760 ber_bvfree(asserted_issuer_dn);
3761 return LDAP_SUCCESS;
3766 check_time_syntax (struct berval *val,
3770 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3771 static int mdays[2][12] = {
3772 /* non-leap years */
3773 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3775 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3778 int part, c, tzoffset, leapyear = 0 ;
3780 if( val->bv_len == 0 ) {
3781 return LDAP_INVALID_SYNTAX;
3784 p = (char *)val->bv_val;
3785 e = p + val->bv_len;
3787 /* Ignore initial whitespace */
3788 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3792 if (e - p < 13 - (2 * start)) {
3793 return LDAP_INVALID_SYNTAX;
3796 for (part = 0; part < 9; part++) {
3800 for (part = start; part < 7; part++) {
3802 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3809 return LDAP_INVALID_SYNTAX;
3811 if (c < 0 || c > 9) {
3812 return LDAP_INVALID_SYNTAX;
3818 return LDAP_INVALID_SYNTAX;
3820 if (c < 0 || c > 9) {
3821 return LDAP_INVALID_SYNTAX;
3826 if (part == 2 || part == 3) {
3829 if (parts[part] < 0) {
3830 return LDAP_INVALID_SYNTAX;
3832 if (parts[part] > ceiling[part]) {
3833 return LDAP_INVALID_SYNTAX;
3837 /* leapyear check for the Gregorian calendar (year>1581) */
3838 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3839 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3844 if (parts[3] > mdays[leapyear][parts[2]]) {
3845 return LDAP_INVALID_SYNTAX;
3850 tzoffset = 0; /* UTC */
3851 } else if (c != '+' && c != '-') {
3852 return LDAP_INVALID_SYNTAX;
3856 } else /* c == '+' */ {
3861 return LDAP_INVALID_SYNTAX;
3864 for (part = 7; part < 9; part++) {
3866 if (c < 0 || c > 9) {
3867 return LDAP_INVALID_SYNTAX;
3872 if (c < 0 || c > 9) {
3873 return LDAP_INVALID_SYNTAX;
3877 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3878 return LDAP_INVALID_SYNTAX;
3883 /* Ignore trailing whitespace */
3884 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3888 return LDAP_INVALID_SYNTAX;
3891 switch ( tzoffset ) {
3892 case -1: /* negativ offset to UTC, ie west of Greenwich */
3893 parts[4] += parts[7];
3894 parts[5] += parts[8];
3895 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3899 c = mdays[leapyear][parts[2]];
3901 if (parts[part] > c) {
3902 parts[part] -= c + 1;
3907 case 1: /* positive offset to UTC, ie east of Greenwich */
3908 parts[4] -= parts[7];
3909 parts[5] -= parts[8];
3910 for (part = 6; --part > 0; ) {
3914 /* first arg to % needs to be non negativ */
3915 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3917 if (parts[part] < 0) {
3918 parts[part] += c + 1;
3923 case 0: /* already UTC */
3927 return LDAP_SUCCESS;
3934 struct berval *normalized )
3938 rc = check_time_syntax(val, 1, parts);
3939 if (rc != LDAP_SUCCESS) {
3943 normalized->bv_val = ch_malloc( 14 );
3944 if ( normalized->bv_val == NULL ) {
3945 return LBER_ERROR_MEMORY;
3948 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3949 parts[1], parts[2] + 1, parts[3] + 1,
3950 parts[4], parts[5], parts[6] );
3951 normalized->bv_len = 13;
3953 return LDAP_SUCCESS;
3963 return check_time_syntax(in, 1, parts);
3967 generalizedTimeValidate(
3973 return check_time_syntax(in, 0, parts);
3977 generalizedTimeNormalize(
3980 struct berval *normalized )
3984 rc = check_time_syntax(val, 0, parts);
3985 if (rc != LDAP_SUCCESS) {
3989 normalized->bv_val = ch_malloc( 16 );
3990 if ( normalized->bv_val == NULL ) {
3991 return LBER_ERROR_MEMORY;
3994 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
3995 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3996 parts[4], parts[5], parts[6] );
3997 normalized->bv_len = 15;
3999 return LDAP_SUCCESS;
4003 nisNetgroupTripleValidate(
4005 struct berval *val )
4010 if ( val->bv_len == 0 ) {
4011 return LDAP_INVALID_SYNTAX;
4014 p = (char *)val->bv_val;
4015 e = p + val->bv_len;
4017 if ( *p != '(' /*')'*/ ) {
4018 return LDAP_INVALID_SYNTAX;
4021 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4025 return LDAP_INVALID_SYNTAX;
4028 } else if ( !ATTR_CHAR( *p ) ) {
4029 return LDAP_INVALID_SYNTAX;
4033 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4034 return LDAP_INVALID_SYNTAX;
4040 return LDAP_INVALID_SYNTAX;
4043 return LDAP_SUCCESS;
4047 bootParameterValidate(
4049 struct berval *val )
4053 if ( val->bv_len == 0 ) {
4054 return LDAP_INVALID_SYNTAX;
4057 p = (char *)val->bv_val;
4058 e = p + val->bv_len;
4061 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4062 if ( !ATTR_CHAR( *p ) ) {
4063 return LDAP_INVALID_SYNTAX;
4068 return LDAP_INVALID_SYNTAX;
4072 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4073 if ( !ATTR_CHAR( *p ) ) {
4074 return LDAP_INVALID_SYNTAX;
4079 return LDAP_INVALID_SYNTAX;
4083 for ( p++; p < e; p++ ) {
4084 if ( !ATTR_CHAR( *p ) ) {
4085 return LDAP_INVALID_SYNTAX;
4089 return LDAP_SUCCESS;
4092 static struct syntax_defs_rec {
4094 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4095 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4097 slap_syntax_validate_func *sd_validate;
4098 slap_syntax_transform_func *sd_normalize;
4099 slap_syntax_transform_func *sd_pretty;
4100 #ifdef SLAPD_BINARY_CONVERSION
4101 slap_syntax_transform_func *sd_ber2str;
4102 slap_syntax_transform_func *sd_str2ber;
4105 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4106 X_BINARY X_NOT_H_R ")",
4107 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4108 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4109 0, NULL, NULL, NULL},
4110 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4111 0, NULL, NULL, NULL},
4112 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4114 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4115 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4117 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4118 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4119 0, bitStringValidate, bitStringNormalize, NULL },
4120 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4121 0, booleanValidate, NULL, NULL},
4122 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4123 X_BINARY X_NOT_H_R ")",
4124 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4125 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4126 X_BINARY X_NOT_H_R ")",
4127 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4128 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4129 X_BINARY X_NOT_H_R ")",
4130 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4131 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4132 0, countryStringValidate, IA5StringNormalize, NULL},
4133 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4134 0, dnValidate, dnNormalize2, dnPretty2},
4135 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4136 0, NULL, NULL, NULL},
4137 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4138 0, NULL, NULL, NULL},
4139 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4140 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4141 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4142 0, NULL, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4144 0, NULL, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4146 0, NULL, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4148 0, NULL, NULL, NULL},
4149 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4150 0, NULL, NULL, NULL},
4151 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4152 0, printablesStringValidate, IA5StringNormalize, NULL},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4154 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4155 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4156 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4158 0, NULL, NULL, NULL},
4159 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4160 0, IA5StringValidate, IA5StringNormalize, NULL},
4161 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4162 0, integerValidate, integerNormalize, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4164 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4165 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4166 0, NULL, NULL, NULL},
4167 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4168 0, NULL, NULL, NULL},
4169 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4170 0, NULL, NULL, NULL},
4171 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4172 0, NULL, NULL, NULL},
4173 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4174 0, NULL, NULL, NULL},
4175 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4176 0, nameUIDValidate, nameUIDNormalize, NULL},
4177 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4178 0, NULL, NULL, NULL},
4179 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4180 0, numericStringValidate, numericStringNormalize, NULL},
4181 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4182 0, NULL, NULL, NULL},
4183 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4184 0, oidValidate, NULL, NULL},
4185 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4186 0, IA5StringValidate, IA5StringNormalize, NULL},
4187 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4188 0, blobValidate, NULL, NULL},
4189 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4190 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4191 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4192 0, NULL, NULL, NULL},
4193 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4194 0, NULL, NULL, NULL},
4195 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4196 0, printableStringValidate, IA5StringNormalize, NULL},
4197 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4198 X_BINARY X_NOT_H_R ")",
4199 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4201 X_BINARY X_NOT_H_R ")",
4202 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4204 0, printableStringValidate, IA5StringNormalize, NULL},
4205 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4206 0, NULL, NULL, NULL},
4207 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4208 0, printablesStringValidate, IA5StringNormalize, NULL},
4209 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4210 0, utcTimeValidate, utcTimeNormalize, NULL},
4211 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4212 0, NULL, NULL, NULL},
4213 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4214 0, NULL, NULL, NULL},
4215 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4216 0, NULL, NULL, NULL},
4217 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4218 0, NULL, NULL, NULL},
4219 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4220 0, NULL, NULL, NULL},
4222 /* RFC 2307 NIS Syntaxes */
4223 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4224 0, nisNetgroupTripleValidate, NULL, NULL},
4225 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4226 0, bootParameterValidate, NULL, NULL},
4230 /* These OIDs are not published yet, but will be in the next
4231 * I-D for PKIX LDAPv3 schema as have been advanced by David
4232 * Chadwick in private mail.
4234 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4235 0, NULL, NULL, NULL},
4238 /* OpenLDAP Experimental Syntaxes */
4239 #ifdef SLAPD_ACI_ENABLED
4240 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4242 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4246 #ifdef SLAPD_AUTHPASSWD
4247 /* needs updating */
4248 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4249 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4252 /* OpenLDAP Void Syntax */
4253 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4254 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4255 {NULL, 0, NULL, NULL, NULL}
4259 * Other matching rules in X.520 that we do not use (yet):
4261 * 2.5.13.9 numericStringOrderingMatch
4262 * 2.5.13.15 integerOrderingMatch
4263 * 2.5.13.18 octetStringOrderingMatch
4264 * 2.5.13.19 octetStringSubstringsMatch
4265 * 2.5.13.25 uTCTimeMatch
4266 * 2.5.13.26 uTCTimeOrderingMatch
4267 * 2.5.13.31 directoryStringFirstComponentMatch
4268 * 2.5.13.32 wordMatch
4269 * 2.5.13.33 keywordMatch
4270 * 2.5.13.35 certificateMatch
4271 * 2.5.13.36 certificatePairExactMatch
4272 * 2.5.13.37 certificatePairMatch
4273 * 2.5.13.38 certificateListExactMatch
4274 * 2.5.13.39 certificateListMatch
4275 * 2.5.13.40 algorithmIdentifierMatch
4276 * 2.5.13.41 storedPrefixMatch
4277 * 2.5.13.42 attributeCertificateMatch
4278 * 2.5.13.43 readerAndKeyIDMatch
4279 * 2.5.13.44 attributeIntegrityMatch
4281 static struct mrule_defs_rec {
4283 slap_mask_t mrd_usage;
4284 slap_mr_convert_func * mrd_convert;
4285 slap_mr_normalize_func * mrd_normalize;
4286 slap_mr_match_func * mrd_match;
4287 slap_mr_indexer_func * mrd_indexer;
4288 slap_mr_filter_func * mrd_filter;
4290 char * mrd_associated;
4293 * EQUALITY matching rules must be listed after associated APPROX
4294 * matching rules. So, we list all APPROX matching rules first.
4296 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4297 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4298 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4300 directoryStringApproxMatch,
4301 directoryStringApproxIndexer,
4302 directoryStringApproxFilter,
4305 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4306 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4307 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4309 IA5StringApproxMatch,
4310 IA5StringApproxIndexer,
4311 IA5StringApproxFilter,
4315 * Other matching rules
4318 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4319 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4320 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4322 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4325 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4326 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4327 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4329 dnMatch, dnIndexer, dnFilter,
4332 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4333 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4334 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4336 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4337 directoryStringApproxMatchOID },
4339 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4340 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4343 caseIgnoreOrderingMatch, NULL, NULL,
4346 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4347 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4348 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4350 caseExactIgnoreSubstringsMatch,
4351 caseExactIgnoreSubstringsIndexer,
4352 caseExactIgnoreSubstringsFilter,
4355 {"( 2.5.13.5 NAME 'caseExactMatch' "
4356 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4357 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4359 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4360 directoryStringApproxMatchOID },
4362 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4363 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4366 caseExactOrderingMatch, NULL, NULL,
4369 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4370 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4371 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4373 caseExactIgnoreSubstringsMatch,
4374 caseExactIgnoreSubstringsIndexer,
4375 caseExactIgnoreSubstringsFilter,
4378 {"( 2.5.13.8 NAME 'numericStringMatch' "
4379 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4380 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4383 caseIgnoreIA5Indexer,
4384 caseIgnoreIA5Filter,
4387 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4388 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4389 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4391 caseIgnoreIA5SubstringsMatch,
4392 caseIgnoreIA5SubstringsIndexer,
4393 caseIgnoreIA5SubstringsFilter,
4396 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4397 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4398 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4400 caseIgnoreListMatch, NULL, NULL,
4403 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4404 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4405 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4407 caseIgnoreListSubstringsMatch, NULL, NULL,
4410 {"( 2.5.13.13 NAME 'booleanMatch' "
4411 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4412 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4414 booleanMatch, NULL, NULL,
4417 {"( 2.5.13.14 NAME 'integerMatch' "
4418 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4419 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4421 integerMatch, integerIndexer, integerFilter,
4424 {"( 2.5.13.16 NAME 'bitStringMatch' "
4425 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4426 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4428 bitStringMatch, bitStringIndexer, bitStringFilter,
4431 {"( 2.5.13.17 NAME 'octetStringMatch' "
4432 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4433 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4435 octetStringMatch, octetStringIndexer, octetStringFilter,
4438 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4439 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4440 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4442 telephoneNumberMatch,
4443 telephoneNumberIndexer,
4444 telephoneNumberFilter,
4447 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4448 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4449 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4451 telephoneNumberSubstringsMatch,
4452 telephoneNumberSubstringsIndexer,
4453 telephoneNumberSubstringsFilter,
4456 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4457 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4458 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4463 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4464 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4465 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4467 uniqueMemberMatch, NULL, NULL,
4470 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4471 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4472 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4474 protocolInformationMatch, NULL, NULL,
4477 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4478 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4479 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4481 generalizedTimeMatch, NULL, NULL,
4484 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4485 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4488 generalizedTimeOrderingMatch, NULL, NULL,
4491 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4492 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4493 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4495 integerFirstComponentMatch, NULL, NULL,
4498 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4499 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4500 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4502 objectIdentifierFirstComponentMatch, NULL, NULL,
4506 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4507 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4508 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4509 certificateExactConvert, NULL,
4510 certificateExactMatch,
4511 certificateExactIndexer, certificateExactFilter,
4515 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4516 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4517 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4519 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4520 IA5StringApproxMatchOID },
4522 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4523 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4524 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4526 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4527 IA5StringApproxMatchOID },
4529 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4530 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4533 caseIgnoreIA5SubstringsMatch,
4534 caseIgnoreIA5SubstringsIndexer,
4535 caseIgnoreIA5SubstringsFilter,
4538 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4539 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4542 caseExactIA5SubstringsMatch,
4543 caseExactIA5SubstringsIndexer,
4544 caseExactIA5SubstringsFilter,
4547 #ifdef SLAPD_AUTHPASSWD
4548 /* needs updating */
4549 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4550 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4553 authPasswordMatch, NULL, NULL,
4557 #ifdef SLAPD_ACI_ENABLED
4558 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4559 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4562 OpenLDAPaciMatch, NULL, NULL,
4566 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4567 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4570 integerBitAndMatch, NULL, NULL,
4573 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4574 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4577 integerBitOrMatch, NULL, NULL,
4580 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4584 slap_schema_init( void )
4589 /* we should only be called once (from main) */
4590 assert( schema_init_done == 0 );
4592 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4593 res = register_syntax( syntax_defs[i].sd_desc,
4594 syntax_defs[i].sd_flags,
4595 syntax_defs[i].sd_validate,
4596 syntax_defs[i].sd_normalize,
4597 syntax_defs[i].sd_pretty
4598 #ifdef SLAPD_BINARY_CONVERSION
4600 syntax_defs[i].sd_ber2str,
4601 syntax_defs[i].sd_str2ber
4606 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4607 syntax_defs[i].sd_desc );
4612 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4613 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4615 "slap_schema_init: Ingoring unusable matching rule %s\n",
4616 mrule_defs[i].mrd_desc );
4620 res = register_matching_rule(
4621 mrule_defs[i].mrd_desc,
4622 mrule_defs[i].mrd_usage,
4623 mrule_defs[i].mrd_convert,
4624 mrule_defs[i].mrd_normalize,
4625 mrule_defs[i].mrd_match,
4626 mrule_defs[i].mrd_indexer,
4627 mrule_defs[i].mrd_filter,
4628 mrule_defs[i].mrd_associated );
4632 "slap_schema_init: Error registering matching rule %s\n",
4633 mrule_defs[i].mrd_desc );
4638 res = slap_schema_load();
4639 schema_init_done = 1;
4644 schema_destroy( void )