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
46 #define integerFirstComponentMatch integerMatch
48 /* approx matching rules */
49 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
50 #define directoryStringApproxMatch approxMatch
51 #define directoryStringApproxIndexer approxIndexer
52 #define directoryStringApproxFilter approxFilter
53 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
54 #define IA5StringApproxMatch approxMatch
55 #define IA5StringApproxIndexer approxIndexer
56 #define IA5StringApproxFilter approxFilter
58 /* ordering matching rules */
59 #define caseIgnoreOrderingMatch caseIgnoreMatch
60 #define caseExactOrderingMatch caseExactMatch
61 #define integerOrderingMatch integerMatch
63 /* unimplemented matching routines */
64 #define caseIgnoreListMatch NULL
65 #define caseIgnoreListSubstringsMatch NULL
66 #define protocolInformationMatch NULL
68 #ifdef SLAPD_ACI_ENABLED
69 #define OpenLDAPaciMatch NULL
71 #ifdef SLAPD_AUTHPASSWD
72 #define authPasswordMatch NULL
75 /* recycled indexing/filtering routines */
76 #define dnIndexer caseExactIgnoreIndexer
77 #define dnFilter caseExactIgnoreFilter
78 #define bitStringFilter octetStringFilter
79 #define bitStringIndexer octetStringIndexer
81 #define telephoneNumberIndexer caseIgnoreIA5Indexer
82 #define telephoneNumberFilter caseIgnoreIA5Filter
83 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
84 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
86 static MatchingRule *caseExactMatchingRule;
87 static MatchingRule *caseExactSubstringsMatchingRule;
88 static MatchingRule *integerFirstComponentMatchingRule;
90 static const struct MatchingRulePtr {
94 /* must match OIDs below */
95 { "2.5.13.5", &caseExactMatchingRule },
96 { "2.5.13.7", &caseExactSubstringsMatchingRule },
97 { "2.5.13.29", &integerFirstComponentMatchingRule }
101 static char *bvcasechr( struct berval *bv, int c, ber_len_t *len )
104 int lower = TOLOWER( c );
105 int upper = TOUPPER( c );
107 if( c == 0 ) return NULL;
109 for( i=0; i < bv->bv_len; i++ ) {
110 if( upper == bv->bv_val[i] || lower == bv->bv_val[i] ) {
112 return &bv->bv_val[i];
125 struct berval *value,
126 void *assertedValue )
128 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
131 match = memcmp( value->bv_val,
132 ((struct berval *) assertedValue)->bv_val,
140 /* Index generation function */
141 static int octetStringIndexer(
146 struct berval *prefix,
153 HASH_CONTEXT HASHcontext;
154 unsigned char HASHdigest[HASH_BYTES];
155 struct berval digest;
156 digest.bv_val = HASHdigest;
157 digest.bv_len = sizeof(HASHdigest);
159 for( i=0; values[i].bv_val != NULL; i++ ) {
160 /* just count them */
163 /* we should have at least one value at this point */
166 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
168 slen = syntax->ssyn_oidlen;
169 mlen = mr->smr_oidlen;
171 for( i=0; values[i].bv_val != NULL; i++ ) {
172 HASH_Init( &HASHcontext );
173 if( prefix != NULL && prefix->bv_len > 0 ) {
174 HASH_Update( &HASHcontext,
175 prefix->bv_val, prefix->bv_len );
177 HASH_Update( &HASHcontext,
178 syntax->ssyn_oid, slen );
179 HASH_Update( &HASHcontext,
181 HASH_Update( &HASHcontext,
182 values[i].bv_val, values[i].bv_len );
183 HASH_Final( HASHdigest, &HASHcontext );
185 ber_dupbv( &keys[i], &digest );
188 keys[i].bv_val = NULL;
195 /* Index generation function */
196 static int octetStringFilter(
201 struct berval *prefix,
207 HASH_CONTEXT HASHcontext;
208 unsigned char HASHdigest[HASH_BYTES];
209 struct berval *value = (struct berval *) assertValue;
210 struct berval digest;
211 digest.bv_val = HASHdigest;
212 digest.bv_len = sizeof(HASHdigest);
214 slen = syntax->ssyn_oidlen;
215 mlen = mr->smr_oidlen;
217 keys = ch_malloc( sizeof( struct berval ) * 2 );
219 HASH_Init( &HASHcontext );
220 if( prefix != NULL && prefix->bv_len > 0 ) {
221 HASH_Update( &HASHcontext,
222 prefix->bv_val, prefix->bv_len );
224 HASH_Update( &HASHcontext,
225 syntax->ssyn_oid, slen );
226 HASH_Update( &HASHcontext,
228 HASH_Update( &HASHcontext,
229 value->bv_val, value->bv_len );
230 HASH_Final( HASHdigest, &HASHcontext );
232 ber_dupbv( keys, &digest );
233 keys[1].bv_val = NULL;
248 if( in->bv_len == 0 ) return LDAP_SUCCESS;
250 ber_dupbv( &dn, in );
251 if( !dn.bv_val ) return LDAP_OTHER;
253 if( dn.bv_val[dn.bv_len-1] == 'B'
254 && dn.bv_val[dn.bv_len-2] == '\'' )
256 /* assume presence of optional UID */
259 for(i=dn.bv_len-3; i>1; i--) {
260 if( dn.bv_val[i] != '0' && dn.bv_val[i] != '1' ) {
264 if( dn.bv_val[i] != '\'' ||
265 dn.bv_val[i-1] != '#' ) {
266 ber_memfree( dn.bv_val );
267 return LDAP_INVALID_SYNTAX;
270 /* trim the UID to allow use of dnValidate */
271 dn.bv_val[i-1] = '\0';
275 rc = dnValidate( NULL, &dn );
285 struct berval *normalized )
290 ber_dupbv( &out, val );
291 if( out.bv_len != 0 ) {
294 ber_len_t uidlen = 0;
296 if( out.bv_val[out.bv_len-1] == '\'' ) {
297 /* assume presence of optional UID */
298 uid = strrchr( out.bv_val, '#' );
302 return LDAP_INVALID_SYNTAX;
305 uidlen = out.bv_len - (uid - out.bv_val);
306 /* temporarily trim the UID */
308 out.bv_len -= uidlen;
311 #ifdef USE_DN_NORMALIZE
312 rc = dnNormalize2( NULL, &out, normalized );
314 rc = dnPretty2( NULL, &out, normalized );
317 if( rc != LDAP_SUCCESS ) {
319 return LDAP_INVALID_SYNTAX;
322 dnlen = normalized->bv_len;
326 b2.bv_val = ch_malloc(dnlen + uidlen + 1);
327 AC_MEMCPY( b2.bv_val, normalized->bv_val, dnlen );
329 /* restore the separator */
332 AC_MEMCPY( normalized->bv_val+dnlen, uid, uidlen );
333 b2.bv_len = dnlen + uidlen;
334 normalized->bv_val[dnlen+uidlen] = '\0';
335 free(normalized->bv_val);
349 /* any value allowed */
358 /* any value allowed */
369 /* very unforgiving validation, requires no normalization
370 * before simplistic matching
372 if( in->bv_len < 3 ) {
373 return LDAP_INVALID_SYNTAX;
377 * rfc 2252 section 6.3 Bit String
378 * bitstring = "'" *binary-digit "'"
379 * binary-digit = "0" / "1"
380 * example: '0101111101'B
383 if( in->bv_val[0] != '\'' ||
384 in->bv_val[in->bv_len-2] != '\'' ||
385 in->bv_val[in->bv_len-1] != 'B' )
387 return LDAP_INVALID_SYNTAX;
390 for( i=in->bv_len-3; i>0; i-- ) {
391 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
392 return LDAP_INVALID_SYNTAX;
403 struct berval *normalized )
406 * A normalized bitString is has no extaneous (leading) zero bits.
407 * That is, '00010'B is normalized to '10'B
408 * However, as a special case, '0'B requires no normalization.
412 /* start at the first bit */
415 /* Find the first non-zero bit */
416 while ( *p == '0' ) p++;
419 /* no non-zero bits */
420 ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
424 normalized->bv_val = ch_malloc( val->bv_len + 1 );
426 normalized->bv_val[0] = '\'';
427 normalized->bv_len = 1;
429 for( ; *p != '\0'; p++ ) {
430 normalized->bv_val[normalized->bv_len++] = *p;
433 normalized->bv_val[normalized->bv_len] = '\0';
440 * Handling boolean syntax and matching is quite rigid.
441 * A more flexible approach would be to allow a variety
442 * of strings to be normalized and prettied into TRUE
450 /* very unforgiving validation, requires no normalization
451 * before simplistic matching
454 if( in->bv_len == 4 ) {
455 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
458 } else if( in->bv_len == 5 ) {
459 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
464 return LDAP_INVALID_SYNTAX;
473 struct berval *value,
474 void *assertedValue )
476 /* simplistic matching allowed by rigid validation */
477 struct berval *asserted = (struct berval *) assertedValue;
478 *matchp = value->bv_len != asserted->bv_len;
489 unsigned char *u = in->bv_val;
491 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
493 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
494 /* get the length indicated by the first byte */
495 len = LDAP_UTF8_CHARLEN2( u, len );
497 /* very basic checks */
500 if( (u[5] & 0xC0) != 0x80 ) {
501 return LDAP_INVALID_SYNTAX;
504 if( (u[4] & 0xC0) != 0x80 ) {
505 return LDAP_INVALID_SYNTAX;
508 if( (u[3] & 0xC0) != 0x80 ) {
509 return LDAP_INVALID_SYNTAX;
512 if( (u[2] & 0xC0 )!= 0x80 ) {
513 return LDAP_INVALID_SYNTAX;
516 if( (u[1] & 0xC0) != 0x80 ) {
517 return LDAP_INVALID_SYNTAX;
520 /* CHARLEN already validated it */
523 return LDAP_INVALID_SYNTAX;
526 /* make sure len corresponds with the offset
527 to the next character */
528 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
531 if( count != 0 ) return LDAP_INVALID_SYNTAX;
540 struct berval *normalized )
547 /* Ignore initial whitespace */
548 /* All space is ASCII. All ASCII is 1 byte */
549 for ( ; p < val->bv_val + val->bv_len && ASCII_SPACE( p[ 0 ] ); p++ );
551 ber_mem2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
552 e = normalized->bv_val + val->bv_len - (p - val->bv_val);
554 assert( normalized->bv_len );
555 assert( normalized->bv_val );
557 p = q = normalized->bv_val;
562 if ( ASCII_SPACE( *p ) ) {
567 /* Ignore the extra whitespace */
568 while ( ASCII_SPACE( *p ) ) {
572 len = LDAP_UTF8_COPY(q,p);
578 assert( normalized->bv_val < p );
579 assert( q+len <= p );
581 /* cannot start with a space */
582 assert( !ASCII_SPACE(normalized->bv_val[0]) );
585 * If the string ended in space, backup the pointer one
586 * position. One is enough because the above loop collapsed
587 * all whitespace to a single space.
595 /* cannot end with a space */
596 assert( !ASCII_SPACE( *q ) );
603 normalized->bv_len = q - normalized->bv_val;
608 /* Returns Unicode canonically normalized copy of a substring assertion
609 * Skipping attribute description */
610 static SubstringsAssertion *
611 UTF8SubstringsassertionNormalize(
612 SubstringsAssertion *sa,
615 SubstringsAssertion *nsa;
618 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
623 if( sa->sa_initial.bv_val != NULL ) {
624 UTF8bvnormalize( &sa->sa_initial, &nsa->sa_initial, casefold );
625 if( nsa->sa_initial.bv_val == NULL ) {
630 if( sa->sa_any != NULL ) {
631 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
634 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
635 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
636 UTF8bvnormalize( &sa->sa_any[i], &nsa->sa_any[i],
638 if( nsa->sa_any[i].bv_val == NULL ) {
642 nsa->sa_any[i].bv_val = NULL;
645 if( sa->sa_final.bv_val != NULL ) {
646 UTF8bvnormalize( &sa->sa_final, &nsa->sa_final, casefold );
647 if( nsa->sa_final.bv_val == NULL ) {
655 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
656 if ( nsa->sa_any )ber_bvarray_free( nsa->sa_any );
657 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
662 #ifndef SLAPD_APPROX_OLDSINGLESTRING
664 #if defined(SLAPD_APPROX_INITIALS)
665 #define SLAPD_APPROX_DELIMITER "._ "
666 #define SLAPD_APPROX_WORDLEN 2
668 #define SLAPD_APPROX_DELIMITER " "
669 #define SLAPD_APPROX_WORDLEN 1
678 struct berval *value,
679 void *assertedValue )
681 struct berval *nval, *assertv;
682 char *val, **values, **words, *c;
683 int i, count, len, nextchunk=0, nextavail=0;
685 /* Yes, this is necessary */
686 nval = UTF8bvnormalize( value, NULL, LDAP_UTF8_APPROX );
692 /* Yes, this is necessary */
693 assertv = UTF8bvnormalize( ((struct berval *)assertedValue), NULL, LDAP_UTF8_APPROX );
694 if( assertv == NULL ) {
700 /* Isolate how many words there are */
701 for ( c = nval->bv_val, count = 1; *c; c++ ) {
702 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
703 if ( c == NULL ) break;
708 /* Get a phonetic copy of each word */
709 words = (char **)ch_malloc( count * sizeof(char *) );
710 values = (char **)ch_malloc( count * sizeof(char *) );
711 for ( c = nval->bv_val, i = 0; i < count; i++, c += strlen(c) + 1 ) {
713 values[i] = phonetic(c);
716 /* Work through the asserted value's words, to see if at least some
717 of the words are there, in the same order. */
719 while ( (ber_len_t) nextchunk < assertv->bv_len ) {
720 len = strcspn( assertv->bv_val + nextchunk, SLAPD_APPROX_DELIMITER);
725 #if defined(SLAPD_APPROX_INITIALS)
726 else if( len == 1 ) {
727 /* Single letter words need to at least match one word's initial */
728 for( i=nextavail; i<count; i++ )
729 if( !strncasecmp( assertv->bv_val + nextchunk, words[i], 1 )) {
736 /* Isolate the next word in the asserted value and phonetic it */
737 assertv->bv_val[nextchunk+len] = '\0';
738 val = phonetic( assertv->bv_val + nextchunk );
740 /* See if this phonetic chunk is in the remaining words of *value */
741 for( i=nextavail; i<count; i++ ){
742 if( !strcmp( val, values[i] ) ){
750 /* This chunk in the asserted value was NOT within the *value. */
756 /* Go on to the next word in the asserted value */
760 /* If some of the words were seen, call it a match */
761 if( nextavail > 0 ) {
769 ber_bvfree( assertv );
770 for( i=0; i<count; i++ ) {
771 ch_free( values[i] );
786 struct berval *prefix,
791 int i,j, len, wordcount, keycount=0;
792 struct berval *newkeys;
795 for( j=0; values[j].bv_val != NULL; j++ ) {
796 struct berval val = { 0, NULL };
797 /* Yes, this is necessary */
798 UTF8bvnormalize( &values[j], &val, LDAP_UTF8_APPROX );
799 assert( val.bv_val != NULL );
801 /* Isolate how many words there are. There will be a key for each */
802 for( wordcount = 0, c = val.bv_val; *c; c++) {
803 len = strcspn(c, SLAPD_APPROX_DELIMITER);
804 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
806 if (*c == '\0') break;
810 /* Allocate/increase storage to account for new keys */
811 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
812 * sizeof(struct berval) );
813 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
814 if( keys ) ch_free( keys );
817 /* Get a phonetic copy of each word */
818 for( c = val.bv_val, i = 0; i < wordcount; c += len + 1 ) {
820 if( len < SLAPD_APPROX_WORDLEN ) continue;
821 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
826 ber_memfree( val.bv_val );
828 keys[keycount].bv_val = NULL;
840 struct berval *prefix,
849 /* Yes, this is necessary */
850 val = UTF8bvnormalize( ((struct berval *)assertValue), NULL, LDAP_UTF8_APPROX );
851 if( val == NULL || val->bv_val == NULL ) {
852 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
853 keys[0].bv_val = NULL;
859 /* Isolate how many words there are. There will be a key for each */
860 for( count = 0,c = val->bv_val; *c; c++) {
861 len = strcspn(c, SLAPD_APPROX_DELIMITER);
862 if( len >= SLAPD_APPROX_WORDLEN ) count++;
864 if (*c == '\0') break;
868 /* Allocate storage for new keys */
869 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
871 /* Get a phonetic copy of each word */
872 for( c = val->bv_val, i = 0; i < count; c += len + 1 ) {
874 if( len < SLAPD_APPROX_WORDLEN ) continue;
875 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
881 keys[count].bv_val = NULL;
889 /* No other form of Approximate Matching is defined */
897 struct berval *value,
898 void *assertedValue )
900 char *vapprox, *avapprox;
903 /* Yes, this is necessary */
904 s = UTF8normalize( value, UTF8_NOCASEFOLD );
910 /* Yes, this is necessary */
911 t = UTF8normalize( ((struct berval *)assertedValue),
919 vapprox = phonetic( strip8bitChars( s ) );
920 avapprox = phonetic( strip8bitChars( t ) );
925 *matchp = strcmp( vapprox, avapprox );
939 struct berval *prefix,
947 for( i=0; values[i].bv_val != NULL; i++ ) {
948 /* empty - just count them */
951 /* we should have at least one value at this point */
954 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
956 /* Copy each value and run it through phonetic() */
957 for( i=0; values[i].bv_val != NULL; i++ ) {
958 /* Yes, this is necessary */
959 s = UTF8normalize( &values[i], UTF8_NOCASEFOLD );
961 /* strip 8-bit chars and run through phonetic() */
962 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
965 keys[i].bv_val = NULL;
978 struct berval *prefix,
985 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
987 /* Yes, this is necessary */
988 s = UTF8normalize( ((struct berval *)assertValue),
993 /* strip 8-bit chars and run through phonetic() */
994 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1000 return LDAP_SUCCESS;
1011 struct berval *value,
1012 void *assertedValue )
1014 *matchp = UTF8bvnormcmp( value,
1015 (struct berval *) assertedValue,
1016 LDAP_UTF8_NOCASEFOLD );
1017 return LDAP_SUCCESS;
1021 caseExactIgnoreSubstringsMatch(
1026 struct berval *value,
1027 void *assertedValue )
1030 SubstringsAssertion *sub = NULL;
1031 struct berval left = { 0, NULL };
1037 casefold = ( mr != caseExactSubstringsMatchingRule )
1038 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1040 if ( UTF8bvnormalize( value, &left, casefold ) == NULL ) {
1046 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1052 /* Add up asserted input length */
1053 if( sub->sa_initial.bv_val ) {
1054 inlen += sub->sa_initial.bv_len;
1057 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1058 inlen += sub->sa_any[i].bv_len;
1061 if( sub->sa_final.bv_val ) {
1062 inlen += sub->sa_final.bv_len;
1065 if( sub->sa_initial.bv_val ) {
1066 if( inlen > left.bv_len ) {
1071 match = memcmp( sub->sa_initial.bv_val, left.bv_val,
1072 sub->sa_initial.bv_len );
1078 left.bv_val += sub->sa_initial.bv_len;
1079 left.bv_len -= sub->sa_initial.bv_len;
1080 inlen -= sub->sa_initial.bv_len;
1083 if( sub->sa_final.bv_val ) {
1084 if( inlen > left.bv_len ) {
1089 match = memcmp( sub->sa_final.bv_val,
1090 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1091 sub->sa_final.bv_len );
1097 left.bv_len -= sub->sa_final.bv_len;
1098 inlen -= sub->sa_final.bv_len;
1102 for(i=0; sub->sa_any[i].bv_val; i++) {
1107 if( inlen > left.bv_len ) {
1108 /* not enough length */
1113 if( sub->sa_any[i].bv_len == 0 ) {
1117 p = ber_bvchr( &left, *sub->sa_any[i].bv_val );
1123 idx = p - left.bv_val;
1125 if( idx >= left.bv_len ) {
1126 /* this shouldn't happen */
1128 if ( sub->sa_final.bv_val )
1129 ch_free( sub->sa_final.bv_val );
1131 ber_bvarray_free( sub->sa_any );
1132 if ( sub->sa_initial.bv_val )
1133 ch_free( sub->sa_initial.bv_val );
1141 if( sub->sa_any[i].bv_len > left.bv_len ) {
1142 /* not enough left */
1147 match = memcmp( left.bv_val,
1148 sub->sa_any[i].bv_val,
1149 sub->sa_any[i].bv_len );
1157 left.bv_val += sub->sa_any[i].bv_len;
1158 left.bv_len -= sub->sa_any[i].bv_len;
1159 inlen -= sub->sa_any[i].bv_len;
1166 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1167 if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
1168 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1172 return LDAP_SUCCESS;
1175 /* Index generation function */
1176 static int caseExactIgnoreIndexer(
1181 struct berval *prefix,
1189 HASH_CONTEXT HASHcontext;
1190 unsigned char HASHdigest[HASH_BYTES];
1191 struct berval digest;
1192 digest.bv_val = HASHdigest;
1193 digest.bv_len = sizeof(HASHdigest);
1195 for( i=0; values[i].bv_val != NULL; i++ ) {
1196 /* empty - just count them */
1199 /* we should have at least one value at this point */
1202 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1204 slen = syntax->ssyn_oidlen;
1205 mlen = mr->smr_oidlen;
1207 casefold = ( mr != caseExactMatchingRule )
1208 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1210 for( i=0; values[i].bv_val != NULL; i++ ) {
1211 struct berval value;
1212 UTF8bvnormalize( &values[i], &value, casefold );
1214 HASH_Init( &HASHcontext );
1215 if( prefix != NULL && prefix->bv_len > 0 ) {
1216 HASH_Update( &HASHcontext,
1217 prefix->bv_val, prefix->bv_len );
1219 HASH_Update( &HASHcontext,
1220 syntax->ssyn_oid, slen );
1221 HASH_Update( &HASHcontext,
1222 mr->smr_oid, mlen );
1223 HASH_Update( &HASHcontext,
1224 value.bv_val, value.bv_len );
1225 HASH_Final( HASHdigest, &HASHcontext );
1227 free( value.bv_val );
1229 ber_dupbv( &keys[i], &digest );
1232 keys[i].bv_val = NULL;
1234 return LDAP_SUCCESS;
1237 /* Index generation function */
1238 static int caseExactIgnoreFilter(
1243 struct berval *prefix,
1250 HASH_CONTEXT HASHcontext;
1251 unsigned char HASHdigest[HASH_BYTES];
1252 struct berval value = { 0, NULL };
1253 struct berval digest;
1255 digest.bv_val = HASHdigest;
1256 digest.bv_len = sizeof(HASHdigest);
1258 slen = syntax->ssyn_oidlen;
1259 mlen = mr->smr_oidlen;
1261 casefold = ( mr != caseExactMatchingRule )
1262 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1264 UTF8bvnormalize( (struct berval *) assertValue, &value, casefold );
1265 /* This usually happens if filter contains bad UTF8 */
1266 if( value.bv_val == NULL ) {
1267 keys = ch_malloc( sizeof( struct berval ) );
1268 keys[0].bv_val = NULL;
1269 return LDAP_SUCCESS;
1272 keys = ch_malloc( sizeof( struct berval ) * 2 );
1274 HASH_Init( &HASHcontext );
1275 if( prefix != NULL && prefix->bv_len > 0 ) {
1276 HASH_Update( &HASHcontext,
1277 prefix->bv_val, prefix->bv_len );
1279 HASH_Update( &HASHcontext,
1280 syntax->ssyn_oid, slen );
1281 HASH_Update( &HASHcontext,
1282 mr->smr_oid, mlen );
1283 HASH_Update( &HASHcontext,
1284 value.bv_val, value.bv_len );
1285 HASH_Final( HASHdigest, &HASHcontext );
1287 ber_dupbv( keys, &digest );
1288 keys[1].bv_val = NULL;
1290 free( value.bv_val );
1293 return LDAP_SUCCESS;
1296 /* Substrings Index generation function */
1297 static int caseExactIgnoreSubstringsIndexer(
1302 struct berval *prefix,
1312 HASH_CONTEXT HASHcontext;
1313 unsigned char HASHdigest[HASH_BYTES];
1314 struct berval digest;
1315 digest.bv_val = HASHdigest;
1316 digest.bv_len = sizeof(HASHdigest);
1320 for( i=0; values[i].bv_val != NULL; i++ ) {
1321 /* empty - just count them */
1324 /* we should have at least one value at this point */
1327 casefold = ( mr != caseExactSubstringsMatchingRule )
1328 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1330 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1331 for( i=0; values[i].bv_val != NULL; i++ ) {
1332 UTF8bvnormalize( &values[i], &nvalues[i], casefold );
1334 nvalues[i].bv_val = NULL;
1337 for( i=0; values[i].bv_val != NULL; i++ ) {
1338 /* count number of indices to generate */
1339 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1343 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1344 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1345 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1346 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1348 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1352 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1353 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1354 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1358 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1359 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1360 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1361 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1363 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1369 /* no keys to generate */
1371 ber_bvarray_free( nvalues );
1372 return LDAP_SUCCESS;
1375 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1377 slen = syntax->ssyn_oidlen;
1378 mlen = mr->smr_oidlen;
1381 for( i=0; values[i].bv_val != NULL; i++ ) {
1384 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1386 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1387 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1389 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1390 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1392 for( j=0; j<max; j++ ) {
1393 HASH_Init( &HASHcontext );
1394 if( prefix != NULL && prefix->bv_len > 0 ) {
1395 HASH_Update( &HASHcontext,
1396 prefix->bv_val, prefix->bv_len );
1399 HASH_Update( &HASHcontext,
1400 &pre, sizeof( pre ) );
1401 HASH_Update( &HASHcontext,
1402 syntax->ssyn_oid, slen );
1403 HASH_Update( &HASHcontext,
1404 mr->smr_oid, mlen );
1405 HASH_Update( &HASHcontext,
1406 &values[i].bv_val[j],
1407 SLAP_INDEX_SUBSTR_MAXLEN );
1408 HASH_Final( HASHdigest, &HASHcontext );
1410 ber_dupbv( &keys[nkeys++], &digest );
1414 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1415 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1417 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1420 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1421 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1422 HASH_Init( &HASHcontext );
1423 if( prefix != NULL && prefix->bv_len > 0 ) {
1424 HASH_Update( &HASHcontext,
1425 prefix->bv_val, prefix->bv_len );
1427 HASH_Update( &HASHcontext,
1428 &pre, sizeof( pre ) );
1429 HASH_Update( &HASHcontext,
1430 syntax->ssyn_oid, slen );
1431 HASH_Update( &HASHcontext,
1432 mr->smr_oid, mlen );
1433 HASH_Update( &HASHcontext,
1434 values[i].bv_val, j );
1435 HASH_Final( HASHdigest, &HASHcontext );
1437 ber_dupbv( &keys[nkeys++], &digest );
1440 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1441 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1442 HASH_Init( &HASHcontext );
1443 if( prefix != NULL && prefix->bv_len > 0 ) {
1444 HASH_Update( &HASHcontext,
1445 prefix->bv_val, prefix->bv_len );
1447 HASH_Update( &HASHcontext,
1448 &pre, sizeof( pre ) );
1449 HASH_Update( &HASHcontext,
1450 syntax->ssyn_oid, slen );
1451 HASH_Update( &HASHcontext,
1452 mr->smr_oid, mlen );
1453 HASH_Update( &HASHcontext,
1454 &values[i].bv_val[values[i].bv_len-j], j );
1455 HASH_Final( HASHdigest, &HASHcontext );
1457 ber_dupbv( &keys[nkeys++], &digest );
1465 keys[nkeys].bv_val = NULL;
1472 ber_bvarray_free( nvalues );
1474 return LDAP_SUCCESS;
1477 static int caseExactIgnoreSubstringsFilter(
1482 struct berval *prefix,
1486 SubstringsAssertion *sa;
1489 ber_len_t nkeys = 0;
1490 size_t slen, mlen, klen;
1492 HASH_CONTEXT HASHcontext;
1493 unsigned char HASHdigest[HASH_BYTES];
1494 struct berval *value;
1495 struct berval digest;
1497 casefold = ( mr != caseExactSubstringsMatchingRule )
1498 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1500 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1503 return LDAP_SUCCESS;
1506 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1507 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1512 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1514 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1515 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1516 /* don't bother accounting for stepping */
1517 nkeys += sa->sa_any[i].bv_len -
1518 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1523 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1524 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1530 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1531 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1532 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1535 return LDAP_SUCCESS;
1538 digest.bv_val = HASHdigest;
1539 digest.bv_len = sizeof(HASHdigest);
1541 slen = syntax->ssyn_oidlen;
1542 mlen = mr->smr_oidlen;
1544 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1547 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1548 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1550 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1551 value = &sa->sa_initial;
1553 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1554 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1556 HASH_Init( &HASHcontext );
1557 if( prefix != NULL && prefix->bv_len > 0 ) {
1558 HASH_Update( &HASHcontext,
1559 prefix->bv_val, prefix->bv_len );
1561 HASH_Update( &HASHcontext,
1562 &pre, sizeof( pre ) );
1563 HASH_Update( &HASHcontext,
1564 syntax->ssyn_oid, slen );
1565 HASH_Update( &HASHcontext,
1566 mr->smr_oid, mlen );
1567 HASH_Update( &HASHcontext,
1568 value->bv_val, klen );
1569 HASH_Final( HASHdigest, &HASHcontext );
1571 ber_dupbv( &keys[nkeys++], &digest );
1574 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1576 pre = SLAP_INDEX_SUBSTR_PREFIX;
1577 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1579 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1580 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1584 value = &sa->sa_any[i];
1587 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1588 j += SLAP_INDEX_SUBSTR_STEP )
1590 HASH_Init( &HASHcontext );
1591 if( prefix != NULL && prefix->bv_len > 0 ) {
1592 HASH_Update( &HASHcontext,
1593 prefix->bv_val, prefix->bv_len );
1595 HASH_Update( &HASHcontext,
1596 &pre, sizeof( pre ) );
1597 HASH_Update( &HASHcontext,
1598 syntax->ssyn_oid, slen );
1599 HASH_Update( &HASHcontext,
1600 mr->smr_oid, mlen );
1601 HASH_Update( &HASHcontext,
1602 &value->bv_val[j], klen );
1603 HASH_Final( HASHdigest, &HASHcontext );
1605 ber_dupbv( &keys[nkeys++], &digest );
1611 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1612 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1614 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1615 value = &sa->sa_final;
1617 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1618 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1620 HASH_Init( &HASHcontext );
1621 if( prefix != NULL && prefix->bv_len > 0 ) {
1622 HASH_Update( &HASHcontext,
1623 prefix->bv_val, prefix->bv_len );
1625 HASH_Update( &HASHcontext,
1626 &pre, sizeof( pre ) );
1627 HASH_Update( &HASHcontext,
1628 syntax->ssyn_oid, slen );
1629 HASH_Update( &HASHcontext,
1630 mr->smr_oid, mlen );
1631 HASH_Update( &HASHcontext,
1632 &value->bv_val[value->bv_len-klen], klen );
1633 HASH_Final( HASHdigest, &HASHcontext );
1635 ber_dupbv( &keys[nkeys++], &digest );
1639 keys[nkeys].bv_val = NULL;
1645 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1646 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1647 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1650 return LDAP_SUCCESS;
1659 struct berval *value,
1660 void *assertedValue )
1662 *matchp = UTF8bvnormcmp( value,
1663 (struct berval *) assertedValue,
1664 LDAP_UTF8_CASEFOLD );
1665 return LDAP_SUCCESS;
1668 /* Remove all spaces and '-' characters */
1670 telephoneNumberNormalize(
1673 struct berval *normalized )
1677 q = normalized->bv_val = ch_malloc( val->bv_len + 1 );
1679 for( p = val->bv_val; *p; p++ )
1680 if ( ! ( ASCII_SPACE( *p ) || *p == '-' ))
1684 normalized->bv_len = q - normalized->bv_val;
1686 return LDAP_SUCCESS;
1692 struct berval *val )
1696 if( val->bv_len == 0 ) {
1697 /* disallow empty strings */
1698 return LDAP_INVALID_SYNTAX;
1701 if( OID_LEADCHAR(val->bv_val[0]) ) {
1703 for(i=1; i < val->bv_len; i++) {
1704 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1705 if( dot++ ) return 1;
1706 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1709 return LDAP_INVALID_SYNTAX;
1713 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1715 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1716 for(i=1; i < val->bv_len; i++) {
1717 if( !DESC_CHAR(val->bv_val[i] ) ) {
1718 return LDAP_INVALID_SYNTAX;
1722 return LDAP_SUCCESS;
1725 return LDAP_INVALID_SYNTAX;
1734 struct berval *value,
1735 void *assertedValue )
1738 int vsign = 1, avsign = 1; /* default sign = '+' */
1739 struct berval *asserted;
1740 ber_len_t vlen, avlen;
1743 /* Skip leading space/sign/zeroes, and get the sign of the *value number */
1745 vlen = value->bv_len;
1746 if( mr == integerFirstComponentMatchingRule ) {
1747 char *tmp = memchr( v, '$', vlen );
1750 while( vlen && ASCII_SPACE( v[vlen-1] ))
1753 for( ; vlen && ( *v < '1' || '9' < *v ); v++, vlen-- ) /* ANSI 2.2.1 */
1759 /* Do the same with the *assertedValue number */
1760 asserted = (struct berval *) assertedValue;
1761 av = asserted->bv_val;
1762 avlen = asserted->bv_len;
1763 for( ; avlen && ( *av < '1' || '9' < *av ); av++, avlen-- )
1769 match = vsign - avsign;
1771 match = (vlen != avlen
1772 ? ( vlen < avlen ? -1 : 1 )
1773 : memcmp( v, av, vlen ));
1779 return LDAP_SUCCESS;
1785 struct berval *val )
1789 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1791 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1792 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1793 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1794 return LDAP_INVALID_SYNTAX;
1797 for( i=1; i < val->bv_len; i++ ) {
1798 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1801 return LDAP_SUCCESS;
1808 struct berval *normalized )
1818 /* Ignore leading spaces */
1819 while ( len && ( *p == ' ' )) {
1826 negative = ( *p == '-' );
1827 if(( *p == '-' ) || ( *p == '+' )) {
1833 /* Ignore leading zeros */
1834 while ( len && ( *p == '0' )) {
1839 /* If there are no non-zero digits left, the number is zero, otherwise
1840 allocate space for the number and copy it into the buffer */
1842 normalized->bv_val = ch_strdup("0");
1843 normalized->bv_len = 1;
1846 normalized->bv_len = len+negative;
1847 normalized->bv_val = ch_malloc( normalized->bv_len );
1849 normalized->bv_val[0] = '-';
1851 AC_MEMCPY( normalized->bv_val + negative, p, len );
1854 return LDAP_SUCCESS;
1857 /* Index generation function */
1858 static int integerIndexer(
1863 struct berval *prefix,
1870 /* we should have at least one value at this point */
1871 assert( values != NULL && values[0].bv_val != NULL );
1873 for( i=0; values[i].bv_val != NULL; i++ ) {
1874 /* empty -- just count them */
1877 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1879 for( i=0; values[i].bv_val != NULL; i++ ) {
1880 integerNormalize( syntax, &values[i], &keys[i] );
1883 keys[i].bv_val = NULL;
1885 return LDAP_SUCCESS;
1888 /* Index generation function */
1889 static int integerFilter(
1894 struct berval *prefix,
1900 keys = ch_malloc( sizeof( struct berval ) * 2 );
1901 integerNormalize( syntax, assertValue, &keys[0] );
1902 keys[1].bv_val = NULL;
1905 return LDAP_SUCCESS;
1910 countryStringValidate(
1912 struct berval *val )
1914 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1916 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1917 return LDAP_INVALID_SYNTAX;
1919 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1920 return LDAP_INVALID_SYNTAX;
1923 return LDAP_SUCCESS;
1927 printableStringValidate(
1929 struct berval *val )
1933 for(i=0; i < val->bv_len; i++) {
1934 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1935 return LDAP_INVALID_SYNTAX;
1939 return LDAP_SUCCESS;
1943 printablesStringValidate(
1945 struct berval *val )
1949 for(i=0; i < val->bv_len; i++) {
1950 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1951 return LDAP_INVALID_SYNTAX;
1955 return LDAP_SUCCESS;
1961 struct berval *val )
1965 for(i=0; i < val->bv_len; i++) {
1966 if( !LDAP_ASCII(val->bv_val[i]) ) {
1967 return LDAP_INVALID_SYNTAX;
1971 return LDAP_SUCCESS;
1978 struct berval *normalized )
1984 /* Ignore initial whitespace */
1985 while ( ASCII_SPACE( *p ) ) {
1989 normalized->bv_val = ch_strdup( p );
1990 p = q = normalized->bv_val;
1993 if ( ASCII_SPACE( *p ) ) {
1996 /* Ignore the extra whitespace */
1997 while ( ASCII_SPACE( *p ) ) {
2005 assert( normalized->bv_val <= p );
2009 * If the string ended in space, backup the pointer one
2010 * position. One is enough because the above loop collapsed
2011 * all whitespace to a single space.
2014 if ( ASCII_SPACE( q[-1] ) ) {
2018 /* null terminate */
2021 normalized->bv_len = q - normalized->bv_val;
2023 return LDAP_SUCCESS;
2032 struct berval *value,
2033 void *assertedValue )
2035 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2038 match = strncmp( value->bv_val,
2039 ((struct berval *) assertedValue)->bv_val,
2044 return LDAP_SUCCESS;
2048 caseExactIA5SubstringsMatch(
2053 struct berval *value,
2054 void *assertedValue )
2057 SubstringsAssertion *sub = assertedValue;
2058 struct berval left = *value;
2062 /* Add up asserted input length */
2063 if( sub->sa_initial.bv_val ) {
2064 inlen += sub->sa_initial.bv_len;
2067 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2068 inlen += sub->sa_any[i].bv_len;
2071 if( sub->sa_final.bv_val ) {
2072 inlen += sub->sa_final.bv_len;
2075 if( sub->sa_initial.bv_val ) {
2076 if( inlen > left.bv_len ) {
2081 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2082 sub->sa_initial.bv_len );
2088 left.bv_val += sub->sa_initial.bv_len;
2089 left.bv_len -= sub->sa_initial.bv_len;
2090 inlen -= sub->sa_initial.bv_len;
2093 if( sub->sa_final.bv_val ) {
2094 if( inlen > left.bv_len ) {
2099 match = strncmp( sub->sa_final.bv_val,
2100 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2101 sub->sa_final.bv_len );
2107 left.bv_len -= sub->sa_final.bv_len;
2108 inlen -= sub->sa_final.bv_len;
2112 for(i=0; sub->sa_any[i].bv_val; i++) {
2117 if( inlen > left.bv_len ) {
2118 /* not enough length */
2123 if( sub->sa_any[i].bv_len == 0 ) {
2127 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2134 idx = p - left.bv_val;
2136 if( idx >= left.bv_len ) {
2137 /* this shouldn't happen */
2144 if( sub->sa_any[i].bv_len > left.bv_len ) {
2145 /* not enough left */
2150 match = strncmp( left.bv_val,
2151 sub->sa_any[i].bv_val,
2152 sub->sa_any[i].bv_len );
2160 left.bv_val += sub->sa_any[i].bv_len;
2161 left.bv_len -= sub->sa_any[i].bv_len;
2162 inlen -= sub->sa_any[i].bv_len;
2168 return LDAP_SUCCESS;
2171 /* Index generation function */
2172 static int caseExactIA5Indexer(
2177 struct berval *prefix,
2184 HASH_CONTEXT HASHcontext;
2185 unsigned char HASHdigest[HASH_BYTES];
2186 struct berval digest;
2187 digest.bv_val = HASHdigest;
2188 digest.bv_len = sizeof(HASHdigest);
2190 for( i=0; values[i].bv_val != NULL; i++ ) {
2191 /* empty - just count them */
2194 /* we should have at least one value at this point */
2197 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2199 slen = syntax->ssyn_oidlen;
2200 mlen = mr->smr_oidlen;
2202 for( i=0; values[i].bv_val != NULL; i++ ) {
2203 struct berval *value = &values[i];
2205 HASH_Init( &HASHcontext );
2206 if( prefix != NULL && prefix->bv_len > 0 ) {
2207 HASH_Update( &HASHcontext,
2208 prefix->bv_val, prefix->bv_len );
2210 HASH_Update( &HASHcontext,
2211 syntax->ssyn_oid, slen );
2212 HASH_Update( &HASHcontext,
2213 mr->smr_oid, mlen );
2214 HASH_Update( &HASHcontext,
2215 value->bv_val, value->bv_len );
2216 HASH_Final( HASHdigest, &HASHcontext );
2218 ber_dupbv( &keys[i], &digest );
2221 keys[i].bv_val = NULL;
2223 return LDAP_SUCCESS;
2226 /* Index generation function */
2227 static int caseExactIA5Filter(
2232 struct berval *prefix,
2238 HASH_CONTEXT HASHcontext;
2239 unsigned char HASHdigest[HASH_BYTES];
2240 struct berval *value;
2241 struct berval digest;
2242 digest.bv_val = HASHdigest;
2243 digest.bv_len = sizeof(HASHdigest);
2245 slen = syntax->ssyn_oidlen;
2246 mlen = mr->smr_oidlen;
2248 value = (struct berval *) assertValue;
2250 keys = ch_malloc( sizeof( struct berval ) * 2 );
2252 HASH_Init( &HASHcontext );
2253 if( prefix != NULL && prefix->bv_len > 0 ) {
2254 HASH_Update( &HASHcontext,
2255 prefix->bv_val, prefix->bv_len );
2257 HASH_Update( &HASHcontext,
2258 syntax->ssyn_oid, slen );
2259 HASH_Update( &HASHcontext,
2260 mr->smr_oid, mlen );
2261 HASH_Update( &HASHcontext,
2262 value->bv_val, value->bv_len );
2263 HASH_Final( HASHdigest, &HASHcontext );
2265 ber_dupbv( &keys[0], &digest );
2266 keys[1].bv_val = NULL;
2269 return LDAP_SUCCESS;
2272 /* Substrings Index generation function */
2273 static int caseExactIA5SubstringsIndexer(
2278 struct berval *prefix,
2285 HASH_CONTEXT HASHcontext;
2286 unsigned char HASHdigest[HASH_BYTES];
2287 struct berval digest;
2288 digest.bv_val = HASHdigest;
2289 digest.bv_len = sizeof(HASHdigest);
2291 /* we should have at least one value at this point */
2292 assert( values != NULL && values[0].bv_val != NULL );
2295 for( i=0; values[i].bv_val != NULL; i++ ) {
2296 /* count number of indices to generate */
2297 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2301 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2302 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2303 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2304 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2306 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2310 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2311 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2312 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2316 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2317 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2318 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2319 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2321 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2327 /* no keys to generate */
2329 return LDAP_SUCCESS;
2332 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2334 slen = syntax->ssyn_oidlen;
2335 mlen = mr->smr_oidlen;
2338 for( i=0; values[i].bv_val != NULL; i++ ) {
2340 struct berval *value;
2343 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2345 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2346 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2348 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2349 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2351 for( j=0; j<max; j++ ) {
2352 HASH_Init( &HASHcontext );
2353 if( prefix != NULL && prefix->bv_len > 0 ) {
2354 HASH_Update( &HASHcontext,
2355 prefix->bv_val, prefix->bv_len );
2358 HASH_Update( &HASHcontext,
2359 &pre, sizeof( pre ) );
2360 HASH_Update( &HASHcontext,
2361 syntax->ssyn_oid, slen );
2362 HASH_Update( &HASHcontext,
2363 mr->smr_oid, mlen );
2364 HASH_Update( &HASHcontext,
2366 SLAP_INDEX_SUBSTR_MAXLEN );
2367 HASH_Final( HASHdigest, &HASHcontext );
2369 ber_dupbv( &keys[nkeys++], &digest );
2373 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2374 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2376 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2379 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2380 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2381 HASH_Init( &HASHcontext );
2382 if( prefix != NULL && prefix->bv_len > 0 ) {
2383 HASH_Update( &HASHcontext,
2384 prefix->bv_val, prefix->bv_len );
2386 HASH_Update( &HASHcontext,
2387 &pre, sizeof( pre ) );
2388 HASH_Update( &HASHcontext,
2389 syntax->ssyn_oid, slen );
2390 HASH_Update( &HASHcontext,
2391 mr->smr_oid, mlen );
2392 HASH_Update( &HASHcontext,
2394 HASH_Final( HASHdigest, &HASHcontext );
2396 ber_dupbv( &keys[nkeys++], &digest );
2399 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2400 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2401 HASH_Init( &HASHcontext );
2402 if( prefix != NULL && prefix->bv_len > 0 ) {
2403 HASH_Update( &HASHcontext,
2404 prefix->bv_val, prefix->bv_len );
2406 HASH_Update( &HASHcontext,
2407 &pre, sizeof( pre ) );
2408 HASH_Update( &HASHcontext,
2409 syntax->ssyn_oid, slen );
2410 HASH_Update( &HASHcontext,
2411 mr->smr_oid, mlen );
2412 HASH_Update( &HASHcontext,
2413 &value->bv_val[value->bv_len-j], j );
2414 HASH_Final( HASHdigest, &HASHcontext );
2416 ber_dupbv( &keys[nkeys++], &digest );
2423 keys[nkeys].bv_val = NULL;
2430 return LDAP_SUCCESS;
2433 static int caseExactIA5SubstringsFilter(
2438 struct berval *prefix,
2442 SubstringsAssertion *sa = assertValue;
2444 ber_len_t nkeys = 0;
2445 size_t slen, mlen, klen;
2447 HASH_CONTEXT HASHcontext;
2448 unsigned char HASHdigest[HASH_BYTES];
2449 struct berval *value;
2450 struct berval digest;
2452 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2453 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2458 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2460 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2461 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2462 /* don't bother accounting for stepping */
2463 nkeys += sa->sa_any[i].bv_len -
2464 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2469 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2470 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2477 return LDAP_SUCCESS;
2480 digest.bv_val = HASHdigest;
2481 digest.bv_len = sizeof(HASHdigest);
2483 slen = syntax->ssyn_oidlen;
2484 mlen = mr->smr_oidlen;
2486 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2489 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2490 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2492 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2493 value = &sa->sa_initial;
2495 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2496 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2498 HASH_Init( &HASHcontext );
2499 if( prefix != NULL && prefix->bv_len > 0 ) {
2500 HASH_Update( &HASHcontext,
2501 prefix->bv_val, prefix->bv_len );
2503 HASH_Update( &HASHcontext,
2504 &pre, sizeof( pre ) );
2505 HASH_Update( &HASHcontext,
2506 syntax->ssyn_oid, slen );
2507 HASH_Update( &HASHcontext,
2508 mr->smr_oid, mlen );
2509 HASH_Update( &HASHcontext,
2510 value->bv_val, klen );
2511 HASH_Final( HASHdigest, &HASHcontext );
2513 ber_dupbv( &keys[nkeys++], &digest );
2516 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2518 pre = SLAP_INDEX_SUBSTR_PREFIX;
2519 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2521 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2522 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2526 value = &sa->sa_any[i];
2529 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2530 j += SLAP_INDEX_SUBSTR_STEP )
2532 HASH_Init( &HASHcontext );
2533 if( prefix != NULL && prefix->bv_len > 0 ) {
2534 HASH_Update( &HASHcontext,
2535 prefix->bv_val, prefix->bv_len );
2537 HASH_Update( &HASHcontext,
2538 &pre, sizeof( pre ) );
2539 HASH_Update( &HASHcontext,
2540 syntax->ssyn_oid, slen );
2541 HASH_Update( &HASHcontext,
2542 mr->smr_oid, mlen );
2543 HASH_Update( &HASHcontext,
2544 &value->bv_val[j], klen );
2545 HASH_Final( HASHdigest, &HASHcontext );
2547 ber_dupbv( &keys[nkeys++], &digest );
2552 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2553 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2555 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2556 value = &sa->sa_final;
2558 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2559 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2561 HASH_Init( &HASHcontext );
2562 if( prefix != NULL && prefix->bv_len > 0 ) {
2563 HASH_Update( &HASHcontext,
2564 prefix->bv_val, prefix->bv_len );
2566 HASH_Update( &HASHcontext,
2567 &pre, sizeof( pre ) );
2568 HASH_Update( &HASHcontext,
2569 syntax->ssyn_oid, slen );
2570 HASH_Update( &HASHcontext,
2571 mr->smr_oid, mlen );
2572 HASH_Update( &HASHcontext,
2573 &value->bv_val[value->bv_len-klen], klen );
2574 HASH_Final( HASHdigest, &HASHcontext );
2576 ber_dupbv( &keys[nkeys++], &digest );
2580 keys[nkeys].bv_val = NULL;
2587 return LDAP_SUCCESS;
2596 struct berval *value,
2597 void *assertedValue )
2599 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2601 if( match == 0 && value->bv_len ) {
2602 match = strncasecmp( value->bv_val,
2603 ((struct berval *) assertedValue)->bv_val,
2608 return LDAP_SUCCESS;
2612 caseIgnoreIA5SubstringsMatch(
2617 struct berval *value,
2618 void *assertedValue )
2621 SubstringsAssertion *sub = assertedValue;
2622 struct berval left = *value;
2626 /* Add up asserted input length */
2627 if( sub->sa_initial.bv_val ) {
2628 inlen += sub->sa_initial.bv_len;
2631 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2632 inlen += sub->sa_any[i].bv_len;
2635 if( sub->sa_final.bv_val ) {
2636 inlen += sub->sa_final.bv_len;
2639 if( sub->sa_initial.bv_val ) {
2640 if( inlen > left.bv_len ) {
2645 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2646 sub->sa_initial.bv_len );
2652 left.bv_val += sub->sa_initial.bv_len;
2653 left.bv_len -= sub->sa_initial.bv_len;
2654 inlen -= sub->sa_initial.bv_len;
2657 if( sub->sa_final.bv_val ) {
2658 if( inlen > left.bv_len ) {
2663 match = strncasecmp( sub->sa_final.bv_val,
2664 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2665 sub->sa_final.bv_len );
2671 left.bv_len -= sub->sa_final.bv_len;
2672 inlen -= sub->sa_final.bv_len;
2676 for(i=0; sub->sa_any[i].bv_val; i++) {
2681 if( inlen > left.bv_len ) {
2682 /* not enough length */
2687 if( sub->sa_any[i].bv_len == 0 ) {
2691 p = bvcasechr( &left, *sub->sa_any[i].bv_val, &idx );
2698 assert( idx < left.bv_len );
2699 if( idx >= left.bv_len ) {
2700 /* this shouldn't happen */
2707 if( sub->sa_any[i].bv_len > left.bv_len ) {
2708 /* not enough left */
2713 match = strncasecmp( left.bv_val,
2714 sub->sa_any[i].bv_val,
2715 sub->sa_any[i].bv_len );
2724 left.bv_val += sub->sa_any[i].bv_len;
2725 left.bv_len -= sub->sa_any[i].bv_len;
2726 inlen -= sub->sa_any[i].bv_len;
2732 return LDAP_SUCCESS;
2735 /* Index generation function */
2736 static int caseIgnoreIA5Indexer(
2741 struct berval *prefix,
2748 HASH_CONTEXT HASHcontext;
2749 unsigned char HASHdigest[HASH_BYTES];
2750 struct berval digest;
2751 digest.bv_val = HASHdigest;
2752 digest.bv_len = sizeof(HASHdigest);
2754 /* we should have at least one value at this point */
2755 assert( values != NULL && values[0].bv_val != NULL );
2757 for( i=0; values[i].bv_val != NULL; i++ ) {
2758 /* just count them */
2761 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2763 slen = syntax->ssyn_oidlen;
2764 mlen = mr->smr_oidlen;
2766 for( i=0; values[i].bv_val != NULL; i++ ) {
2767 struct berval value;
2768 ber_dupbv( &value, &values[i] );
2769 ldap_pvt_str2lower( value.bv_val );
2771 HASH_Init( &HASHcontext );
2772 if( prefix != NULL && prefix->bv_len > 0 ) {
2773 HASH_Update( &HASHcontext,
2774 prefix->bv_val, prefix->bv_len );
2776 HASH_Update( &HASHcontext,
2777 syntax->ssyn_oid, slen );
2778 HASH_Update( &HASHcontext,
2779 mr->smr_oid, mlen );
2780 HASH_Update( &HASHcontext,
2781 value.bv_val, value.bv_len );
2782 HASH_Final( HASHdigest, &HASHcontext );
2784 free( value.bv_val );
2786 ber_dupbv( &keys[i], &digest );
2789 keys[i].bv_val = NULL;
2791 return LDAP_SUCCESS;
2794 /* Index generation function */
2795 static int caseIgnoreIA5Filter(
2800 struct berval *prefix,
2806 HASH_CONTEXT HASHcontext;
2807 unsigned char HASHdigest[HASH_BYTES];
2808 struct berval value;
2809 struct berval digest;
2810 digest.bv_val = HASHdigest;
2811 digest.bv_len = sizeof(HASHdigest);
2813 slen = syntax->ssyn_oidlen;
2814 mlen = mr->smr_oidlen;
2816 ber_dupbv( &value, (struct berval *) assertValue );
2817 ldap_pvt_str2lower( value.bv_val );
2819 keys = ch_malloc( sizeof( struct berval ) * 2 );
2821 HASH_Init( &HASHcontext );
2822 if( prefix != NULL && prefix->bv_len > 0 ) {
2823 HASH_Update( &HASHcontext,
2824 prefix->bv_val, prefix->bv_len );
2826 HASH_Update( &HASHcontext,
2827 syntax->ssyn_oid, slen );
2828 HASH_Update( &HASHcontext,
2829 mr->smr_oid, mlen );
2830 HASH_Update( &HASHcontext,
2831 value.bv_val, value.bv_len );
2832 HASH_Final( HASHdigest, &HASHcontext );
2834 ber_dupbv( &keys[0], &digest );
2835 keys[1].bv_val = NULL;
2837 free( value.bv_val );
2841 return LDAP_SUCCESS;
2844 /* Substrings Index generation function */
2845 static int caseIgnoreIA5SubstringsIndexer(
2850 struct berval *prefix,
2857 HASH_CONTEXT HASHcontext;
2858 unsigned char HASHdigest[HASH_BYTES];
2859 struct berval digest;
2860 digest.bv_val = HASHdigest;
2861 digest.bv_len = sizeof(HASHdigest);
2863 /* we should have at least one value at this point */
2864 assert( values != NULL && values[0].bv_val != NULL );
2867 for( i=0; values[i].bv_val != NULL; i++ ) {
2868 /* count number of indices to generate */
2869 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2873 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2874 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2875 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2876 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2878 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2882 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2883 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2884 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2888 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2889 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2890 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2891 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2893 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2899 /* no keys to generate */
2901 return LDAP_SUCCESS;
2904 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2906 slen = syntax->ssyn_oidlen;
2907 mlen = mr->smr_oidlen;
2910 for( i=0; values[i].bv_val != NULL; i++ ) {
2912 struct berval value;
2914 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2916 ber_dupbv( &value, &values[i] );
2917 ldap_pvt_str2lower( value.bv_val );
2919 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2920 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2922 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2923 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2925 for( j=0; j<max; j++ ) {
2926 HASH_Init( &HASHcontext );
2927 if( prefix != NULL && prefix->bv_len > 0 ) {
2928 HASH_Update( &HASHcontext,
2929 prefix->bv_val, prefix->bv_len );
2932 HASH_Update( &HASHcontext,
2933 &pre, sizeof( pre ) );
2934 HASH_Update( &HASHcontext,
2935 syntax->ssyn_oid, slen );
2936 HASH_Update( &HASHcontext,
2937 mr->smr_oid, mlen );
2938 HASH_Update( &HASHcontext,
2940 SLAP_INDEX_SUBSTR_MAXLEN );
2941 HASH_Final( HASHdigest, &HASHcontext );
2943 ber_dupbv( &keys[nkeys++], &digest );
2947 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2948 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2950 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2953 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2954 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2955 HASH_Init( &HASHcontext );
2956 if( prefix != NULL && prefix->bv_len > 0 ) {
2957 HASH_Update( &HASHcontext,
2958 prefix->bv_val, prefix->bv_len );
2960 HASH_Update( &HASHcontext,
2961 &pre, sizeof( pre ) );
2962 HASH_Update( &HASHcontext,
2963 syntax->ssyn_oid, slen );
2964 HASH_Update( &HASHcontext,
2965 mr->smr_oid, mlen );
2966 HASH_Update( &HASHcontext,
2968 HASH_Final( HASHdigest, &HASHcontext );
2970 ber_dupbv( &keys[nkeys++], &digest );
2973 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2974 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2975 HASH_Init( &HASHcontext );
2976 if( prefix != NULL && prefix->bv_len > 0 ) {
2977 HASH_Update( &HASHcontext,
2978 prefix->bv_val, prefix->bv_len );
2980 HASH_Update( &HASHcontext,
2981 &pre, sizeof( pre ) );
2982 HASH_Update( &HASHcontext,
2983 syntax->ssyn_oid, slen );
2984 HASH_Update( &HASHcontext,
2985 mr->smr_oid, mlen );
2986 HASH_Update( &HASHcontext,
2987 &value.bv_val[value.bv_len-j], j );
2988 HASH_Final( HASHdigest, &HASHcontext );
2990 ber_dupbv( &keys[nkeys++], &digest );
2995 free( value.bv_val );
2999 keys[nkeys].bv_val = NULL;
3006 return LDAP_SUCCESS;
3009 static int caseIgnoreIA5SubstringsFilter(
3014 struct berval *prefix,
3018 SubstringsAssertion *sa = assertValue;
3020 ber_len_t nkeys = 0;
3021 size_t slen, mlen, klen;
3023 HASH_CONTEXT HASHcontext;
3024 unsigned char HASHdigest[HASH_BYTES];
3025 struct berval value;
3026 struct berval digest;
3028 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3029 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3034 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3036 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3037 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3038 /* don't bother accounting for stepping */
3039 nkeys += sa->sa_any[i].bv_len -
3040 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3045 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3046 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3053 return LDAP_SUCCESS;
3056 digest.bv_val = HASHdigest;
3057 digest.bv_len = sizeof(HASHdigest);
3059 slen = syntax->ssyn_oidlen;
3060 mlen = mr->smr_oidlen;
3062 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3065 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3066 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3068 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3069 ber_dupbv( &value, &sa->sa_initial );
3070 ldap_pvt_str2lower( value.bv_val );
3072 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3073 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3075 HASH_Init( &HASHcontext );
3076 if( prefix != NULL && prefix->bv_len > 0 ) {
3077 HASH_Update( &HASHcontext,
3078 prefix->bv_val, prefix->bv_len );
3080 HASH_Update( &HASHcontext,
3081 &pre, sizeof( pre ) );
3082 HASH_Update( &HASHcontext,
3083 syntax->ssyn_oid, slen );
3084 HASH_Update( &HASHcontext,
3085 mr->smr_oid, mlen );
3086 HASH_Update( &HASHcontext,
3087 value.bv_val, klen );
3088 HASH_Final( HASHdigest, &HASHcontext );
3090 free( value.bv_val );
3091 ber_dupbv( &keys[nkeys++], &digest );
3094 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3096 pre = SLAP_INDEX_SUBSTR_PREFIX;
3097 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3099 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3100 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3104 ber_dupbv( &value, &sa->sa_any[i] );
3105 ldap_pvt_str2lower( value.bv_val );
3108 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3109 j += SLAP_INDEX_SUBSTR_STEP )
3111 HASH_Init( &HASHcontext );
3112 if( prefix != NULL && prefix->bv_len > 0 ) {
3113 HASH_Update( &HASHcontext,
3114 prefix->bv_val, prefix->bv_len );
3116 HASH_Update( &HASHcontext,
3117 &pre, sizeof( pre ) );
3118 HASH_Update( &HASHcontext,
3119 syntax->ssyn_oid, slen );
3120 HASH_Update( &HASHcontext,
3121 mr->smr_oid, mlen );
3122 HASH_Update( &HASHcontext,
3123 &value.bv_val[j], klen );
3124 HASH_Final( HASHdigest, &HASHcontext );
3126 ber_dupbv( &keys[nkeys++], &digest );
3129 free( value.bv_val );
3133 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3134 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3136 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3137 ber_dupbv( &value, &sa->sa_final );
3138 ldap_pvt_str2lower( value.bv_val );
3140 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3141 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3143 HASH_Init( &HASHcontext );
3144 if( prefix != NULL && prefix->bv_len > 0 ) {
3145 HASH_Update( &HASHcontext,
3146 prefix->bv_val, prefix->bv_len );
3148 HASH_Update( &HASHcontext,
3149 &pre, sizeof( pre ) );
3150 HASH_Update( &HASHcontext,
3151 syntax->ssyn_oid, slen );
3152 HASH_Update( &HASHcontext,
3153 mr->smr_oid, mlen );
3154 HASH_Update( &HASHcontext,
3155 &value.bv_val[value.bv_len-klen], klen );
3156 HASH_Final( HASHdigest, &HASHcontext );
3158 free( value.bv_val );
3159 ber_dupbv( &keys[nkeys++], &digest );
3163 keys[nkeys].bv_val = NULL;
3170 return LDAP_SUCCESS;
3174 numericStringValidate(
3180 for(i=0; i < in->bv_len; i++) {
3181 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3182 return LDAP_INVALID_SYNTAX;
3186 return LDAP_SUCCESS;
3190 numericStringNormalize(
3193 struct berval *normalized )
3195 /* removal all spaces */
3198 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3201 q = normalized->bv_val;
3204 if ( ASCII_SPACE( *p ) ) {
3205 /* Ignore whitespace */
3212 /* we should have copied no more then is in val */
3213 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3215 /* null terminate */
3218 normalized->bv_len = q - normalized->bv_val;
3220 return LDAP_SUCCESS;
3224 objectIdentifierFirstComponentMatch(
3229 struct berval *value,
3230 void *assertedValue )
3232 int rc = LDAP_SUCCESS;
3234 struct berval *asserted = (struct berval *) assertedValue;
3238 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3239 return LDAP_INVALID_SYNTAX;
3242 /* trim leading white space */
3243 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3247 /* grab next word */
3248 oid.bv_val = &value->bv_val[i];
3249 oid.bv_len = value->bv_len - i;
3250 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3255 /* insert attributeTypes, objectclass check here */
3256 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3257 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3260 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3261 MatchingRule *asserted_mr = mr_bvfind( asserted );
3262 MatchingRule *stored_mr = mr_bvfind( &oid );
3264 if( asserted_mr == NULL ) {
3265 rc = SLAPD_COMPARE_UNDEFINED;
3267 match = asserted_mr != stored_mr;
3270 } else if ( !strcmp( syntax->ssyn_oid,
3271 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3273 AttributeType *asserted_at = at_bvfind( asserted );
3274 AttributeType *stored_at = at_bvfind( &oid );
3276 if( asserted_at == NULL ) {
3277 rc = SLAPD_COMPARE_UNDEFINED;
3279 match = asserted_at != stored_at;
3282 } else if ( !strcmp( syntax->ssyn_oid,
3283 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3285 ObjectClass *asserted_oc = oc_bvfind( asserted );
3286 ObjectClass *stored_oc = oc_bvfind( &oid );
3288 if( asserted_oc == NULL ) {
3289 rc = SLAPD_COMPARE_UNDEFINED;
3291 match = asserted_oc != stored_oc;
3297 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3298 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3299 match, value->bv_val, asserted->bv_val ));
3301 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3302 "%d\n\t\"%s\"\n\t\"%s\"\n",
3303 match, value->bv_val, asserted->bv_val );
3307 if( rc == LDAP_SUCCESS ) *matchp = match;
3317 struct berval *value,
3318 void *assertedValue )
3320 long lValue, lAssertedValue;
3322 /* safe to assume integers are NUL terminated? */
3323 lValue = strtoul(value->bv_val, NULL, 10);
3324 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3325 return LDAP_CONSTRAINT_VIOLATION;
3327 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3328 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3329 return LDAP_CONSTRAINT_VIOLATION;
3331 *matchp = (lValue & lAssertedValue);
3332 return LDAP_SUCCESS;
3341 struct berval *value,
3342 void *assertedValue )
3344 long lValue, lAssertedValue;
3346 /* safe to assume integers are NUL terminated? */
3347 lValue = strtoul(value->bv_val, NULL, 10);
3348 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3349 return LDAP_CONSTRAINT_VIOLATION;
3351 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3352 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3353 return LDAP_CONSTRAINT_VIOLATION;
3355 *matchp = (lValue | lAssertedValue);
3356 return LDAP_SUCCESS;
3360 #include <openssl/x509.h>
3361 #include <openssl/err.h>
3362 char digit[] = "0123456789";
3365 * Next function returns a string representation of a ASN1_INTEGER.
3366 * It works for unlimited lengths.
3369 static struct berval *
3370 asn1_integer2str(ASN1_INTEGER *a)
3375 /* We work backwards, make it fill from the end of buf */
3376 p = buf + sizeof(buf) - 1;
3379 if ( a == NULL || a->length == 0 ) {
3387 /* We want to preserve the original */
3388 copy = ch_malloc(n*sizeof(unsigned int));
3389 for (i = 0; i<n; i++) {
3390 copy[i] = a->data[i];
3394 * base indicates the index of the most significant
3395 * byte that might be nonzero. When it goes off the
3396 * end, we now there is nothing left to do.
3402 for (i = base; i<n; i++ ) {
3403 copy[i] += carry*256;
3404 carry = copy[i] % 10;
3409 * Way too large, we need to leave
3410 * room for sign if negative
3415 *--p = digit[carry];
3416 if (copy[base] == 0)
3422 if ( a->type == V_ASN1_NEG_INTEGER ) {
3426 return ber_bvstrdup(p);
3429 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3430 static struct berval *
3431 dn_openssl2ldap(X509_NAME *name)
3433 char issuer_dn[1024];
3436 bio = BIO_new(BIO_s_mem());
3439 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3440 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3441 ERR_error_string(ERR_get_error(),NULL)));
3443 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3444 "error creating BIO: %s\n",
3445 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3449 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3451 BIO_gets(bio, issuer_dn, 1024);
3454 return ber_bvstrdup(issuer_dn);
3458 * Given a certificate in DER format, extract the corresponding
3459 * assertion value for certificateExactMatch
3462 certificateExactConvert(
3464 struct berval * out )
3467 unsigned char *p = in->bv_val;
3468 struct berval *serial;
3469 struct berval *issuer_dn;
3470 struct berval *bv_tmp;
3472 xcert = d2i_X509(NULL, &p, in->bv_len);
3475 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3476 "certificateExactConvert: error parsing cert: %s\n",
3477 ERR_error_string(ERR_get_error(),NULL)));
3479 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3480 "error parsing cert: %s\n",
3481 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3483 return LDAP_INVALID_SYNTAX;
3486 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3489 return LDAP_INVALID_SYNTAX;
3491 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3495 return LDAP_INVALID_SYNTAX;
3497 /* Actually, dn_openssl2ldap returns in a normalized format, but
3498 it is different from our normalized format */
3500 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3504 return LDAP_INVALID_SYNTAX;
3510 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3511 out->bv_val = ch_malloc(out->bv_len);
3513 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3514 p += serial->bv_len;
3515 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3517 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3518 p += issuer_dn->bv_len;
3522 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3523 "certificateExactConvert: \n %s\n",
3526 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3528 out->bv_val, NULL, NULL );
3532 ber_bvfree(issuer_dn);
3534 return LDAP_SUCCESS;
3538 serial_and_issuer_parse(
3539 struct berval *assertion,
3540 struct berval **serial,
3541 struct berval **issuer_dn
3549 begin = assertion->bv_val;
3550 end = assertion->bv_val+assertion->bv_len-1;
3551 for (p=begin; p<=end && *p != '$'; p++)
3554 return LDAP_INVALID_SYNTAX;
3556 /* p now points at the $ sign, now use begin and end to delimit the
3558 while (ASCII_SPACE(*begin))
3561 while (ASCII_SPACE(*end))
3564 bv.bv_len = end-begin+1;
3566 *serial = ber_dupbv(NULL, &bv);
3568 /* now extract the issuer, remember p was at the dollar sign */
3570 end = assertion->bv_val+assertion->bv_len-1;
3571 while (ASCII_SPACE(*begin))
3573 /* should we trim spaces at the end too? is it safe always? */
3575 bv.bv_len = end-begin+1;
3577 dnNormalize( NULL, &bv, issuer_dn );
3579 return LDAP_SUCCESS;
3583 certificateExactMatch(
3588 struct berval *value,
3589 void *assertedValue )
3592 unsigned char *p = value->bv_val;
3593 struct berval *serial;
3594 struct berval *issuer_dn;
3595 struct berval *asserted_serial;
3596 struct berval *asserted_issuer_dn;
3599 xcert = d2i_X509(NULL, &p, value->bv_len);
3602 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3603 "certificateExactMatch: error parsing cert: %s\n",
3604 ERR_error_string(ERR_get_error(),NULL)));
3606 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3607 "error parsing cert: %s\n",
3608 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3610 return LDAP_INVALID_SYNTAX;
3613 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3614 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3618 serial_and_issuer_parse(assertedValue,
3620 &asserted_issuer_dn);
3625 slap_schema.si_syn_integer,
3626 slap_schema.si_mr_integerMatch,
3629 if ( ret == LDAP_SUCCESS ) {
3630 if ( *matchp == 0 ) {
3631 /* We need to normalize everything for dnMatch */
3635 slap_schema.si_syn_distinguishedName,
3636 slap_schema.si_mr_distinguishedNameMatch,
3638 asserted_issuer_dn);
3643 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3644 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3645 *matchp, serial->bv_val, issuer_dn->bv_val,
3646 asserted_serial->bv_val, asserted_issuer_dn->bv_val));
3648 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3649 "%d\n\t\"%s $ %s\"\n",
3650 *matchp, serial->bv_val, issuer_dn->bv_val );
3651 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3652 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3657 ber_bvfree(issuer_dn);
3658 ber_bvfree(asserted_serial);
3659 ber_bvfree(asserted_issuer_dn);
3665 * Index generation function
3666 * We just index the serials, in most scenarios the issuer DN is one of
3667 * a very small set of values.
3669 static int certificateExactIndexer(
3674 struct berval *prefix,
3682 struct berval * serial;
3684 /* we should have at least one value at this point */
3685 assert( values != NULL && values[0].bv_val != NULL );
3687 for( i=0; values[i].bv_val != NULL; i++ ) {
3688 /* empty -- just count them */
3691 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3693 for( i=0; values[i].bv_val != NULL; i++ ) {
3694 p = values[i].bv_val;
3695 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3698 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3699 "certificateExactIndexer: error parsing cert: %s\n",
3700 ERR_error_string(ERR_get_error(),NULL)));
3702 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3703 "error parsing cert: %s\n",
3704 ERR_error_string(ERR_get_error(),NULL),
3707 /* Do we leak keys on error? */
3708 return LDAP_INVALID_SYNTAX;
3711 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3713 integerNormalize( slap_schema.si_syn_integer,
3718 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3719 "certificateExactIndexer: returning: %s\n",
3722 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3729 keys[i].bv_val = NULL;
3731 return LDAP_SUCCESS;
3734 /* Index generation function */
3735 /* We think this is always called with a value in matching rule syntax */
3736 static int certificateExactFilter(
3741 struct berval *prefix,
3746 struct berval *asserted_serial;
3747 struct berval *asserted_issuer_dn;
3749 serial_and_issuer_parse(assertValue,
3751 &asserted_issuer_dn);
3753 keys = ch_malloc( sizeof( struct berval ) * 2 );
3754 integerNormalize( syntax, asserted_serial, &keys[0] );
3755 keys[1].bv_val = NULL;
3758 ber_bvfree(asserted_serial);
3759 ber_bvfree(asserted_issuer_dn);
3760 return LDAP_SUCCESS;
3765 check_time_syntax (struct berval *val,
3769 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3770 static int mdays[2][12] = {
3771 /* non-leap years */
3772 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3774 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3777 int part, c, tzoffset, leapyear = 0 ;
3779 if( val->bv_len == 0 ) {
3780 return LDAP_INVALID_SYNTAX;
3783 p = (char *)val->bv_val;
3784 e = p + val->bv_len;
3786 /* Ignore initial whitespace */
3787 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3791 if (e - p < 13 - (2 * start)) {
3792 return LDAP_INVALID_SYNTAX;
3795 for (part = 0; part < 9; part++) {
3799 for (part = start; part < 7; part++) {
3801 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3808 return LDAP_INVALID_SYNTAX;
3810 if (c < 0 || c > 9) {
3811 return LDAP_INVALID_SYNTAX;
3817 return LDAP_INVALID_SYNTAX;
3819 if (c < 0 || c > 9) {
3820 return LDAP_INVALID_SYNTAX;
3825 if (part == 2 || part == 3) {
3828 if (parts[part] < 0) {
3829 return LDAP_INVALID_SYNTAX;
3831 if (parts[part] > ceiling[part]) {
3832 return LDAP_INVALID_SYNTAX;
3836 /* leapyear check for the Gregorian calendar (year>1581) */
3837 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3838 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3843 if (parts[3] > mdays[leapyear][parts[2]]) {
3844 return LDAP_INVALID_SYNTAX;
3849 tzoffset = 0; /* UTC */
3850 } else if (c != '+' && c != '-') {
3851 return LDAP_INVALID_SYNTAX;
3855 } else /* c == '+' */ {
3860 return LDAP_INVALID_SYNTAX;
3863 for (part = 7; part < 9; part++) {
3865 if (c < 0 || c > 9) {
3866 return LDAP_INVALID_SYNTAX;
3871 if (c < 0 || c > 9) {
3872 return LDAP_INVALID_SYNTAX;
3876 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3877 return LDAP_INVALID_SYNTAX;
3882 /* Ignore trailing whitespace */
3883 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3887 return LDAP_INVALID_SYNTAX;
3890 switch ( tzoffset ) {
3891 case -1: /* negativ offset to UTC, ie west of Greenwich */
3892 parts[4] += parts[7];
3893 parts[5] += parts[8];
3894 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3898 c = mdays[leapyear][parts[2]];
3900 if (parts[part] > c) {
3901 parts[part] -= c + 1;
3906 case 1: /* positive offset to UTC, ie east of Greenwich */
3907 parts[4] -= parts[7];
3908 parts[5] -= parts[8];
3909 for (part = 6; --part > 0; ) {
3913 /* first arg to % needs to be non negativ */
3914 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3916 if (parts[part] < 0) {
3917 parts[part] += c + 1;
3922 case 0: /* already UTC */
3926 return LDAP_SUCCESS;
3929 #ifdef SUPPORT_OBSOLETE_UTC_SYNTAX
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;
3957 #ifdef SUPPORT_OBSOLETE_UTC_SYNTAX
3965 return check_time_syntax(in, 1, parts);
3970 generalizedTimeValidate(
3976 return check_time_syntax(in, 0, parts);
3980 generalizedTimeNormalize(
3983 struct berval *normalized )
3987 rc = check_time_syntax(val, 0, parts);
3988 if (rc != LDAP_SUCCESS) {
3992 normalized->bv_val = ch_malloc( 16 );
3993 if ( normalized->bv_val == NULL ) {
3994 return LBER_ERROR_MEMORY;
3997 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
3998 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3999 parts[4], parts[5], parts[6] );
4000 normalized->bv_len = 15;
4002 return LDAP_SUCCESS;
4006 nisNetgroupTripleValidate(
4008 struct berval *val )
4013 if ( val->bv_len == 0 ) {
4014 return LDAP_INVALID_SYNTAX;
4017 p = (char *)val->bv_val;
4018 e = p + val->bv_len;
4020 if ( *p != '(' /*')'*/ ) {
4021 return LDAP_INVALID_SYNTAX;
4024 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4028 return LDAP_INVALID_SYNTAX;
4031 } else if ( !ATTR_CHAR( *p ) ) {
4032 return LDAP_INVALID_SYNTAX;
4036 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4037 return LDAP_INVALID_SYNTAX;
4043 return LDAP_INVALID_SYNTAX;
4046 return LDAP_SUCCESS;
4050 bootParameterValidate(
4052 struct berval *val )
4056 if ( val->bv_len == 0 ) {
4057 return LDAP_INVALID_SYNTAX;
4060 p = (char *)val->bv_val;
4061 e = p + val->bv_len;
4064 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4065 if ( !ATTR_CHAR( *p ) ) {
4066 return LDAP_INVALID_SYNTAX;
4071 return LDAP_INVALID_SYNTAX;
4075 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4076 if ( !ATTR_CHAR( *p ) ) {
4077 return LDAP_INVALID_SYNTAX;
4082 return LDAP_INVALID_SYNTAX;
4086 for ( p++; p < e; p++ ) {
4087 if ( !ATTR_CHAR( *p ) ) {
4088 return LDAP_INVALID_SYNTAX;
4092 return LDAP_SUCCESS;
4095 static struct syntax_defs_rec {
4097 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4098 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4100 slap_syntax_validate_func *sd_validate;
4101 slap_syntax_transform_func *sd_normalize;
4102 slap_syntax_transform_func *sd_pretty;
4103 #ifdef SLAPD_BINARY_CONVERSION
4104 slap_syntax_transform_func *sd_ber2str;
4105 slap_syntax_transform_func *sd_str2ber;
4108 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4109 X_BINARY X_NOT_H_R ")",
4110 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4111 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4112 0, NULL, NULL, NULL},
4113 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4114 0, NULL, NULL, NULL},
4115 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4117 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4118 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4120 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4121 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4122 0, bitStringValidate, bitStringNormalize, NULL },
4123 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4124 0, booleanValidate, NULL, NULL},
4125 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
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.9 DESC 'Certificate List' "
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.10 DESC 'Certificate Pair' "
4132 X_BINARY X_NOT_H_R ")",
4133 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4134 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4135 0, countryStringValidate, IA5StringNormalize, NULL},
4136 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4137 0, dnValidate, dnNormalize2, dnPretty2},
4138 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4139 0, NULL, NULL, NULL},
4140 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4141 0, NULL, NULL, NULL},
4142 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4143 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4144 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4145 0, NULL, NULL, NULL},
4146 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4147 0, NULL, NULL, NULL},
4148 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4149 0, NULL, NULL, NULL},
4150 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4151 0, NULL, NULL, NULL},
4152 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4153 0, NULL, NULL, NULL},
4154 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4155 0, printablesStringValidate, telephoneNumberNormalize, NULL},
4156 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4157 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4158 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4159 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4160 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4161 0, NULL, NULL, NULL},
4162 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4163 0, IA5StringValidate, IA5StringNormalize, NULL},
4164 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4165 0, integerValidate, integerNormalize, NULL},
4166 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4167 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4168 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4169 0, NULL, NULL, NULL},
4170 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4171 0, NULL, NULL, NULL},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4173 0, NULL, NULL, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4175 0, NULL, NULL, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4177 0, NULL, NULL, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4179 0, nameUIDValidate, nameUIDNormalize, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4181 0, NULL, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4183 0, numericStringValidate, numericStringNormalize, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4185 0, NULL, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4187 0, oidValidate, NULL, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4189 0, IA5StringValidate, IA5StringNormalize, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4191 0, blobValidate, NULL, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4193 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4195 0, NULL, NULL, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4197 0, NULL, NULL, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4199 0, printableStringValidate, IA5StringNormalize, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4201 X_BINARY X_NOT_H_R ")",
4202 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4203 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4204 X_BINARY X_NOT_H_R ")",
4205 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4207 0, printableStringValidate, telephoneNumberNormalize, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4209 0, NULL, NULL, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4211 0, printablesStringValidate, IA5StringNormalize, NULL},
4212 #ifdef SUPPORT_OBSOLETE_UTC_SYNTAX
4213 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4214 0, utcTimeValidate, utcTimeNormalize, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4217 0, NULL, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4219 0, NULL, NULL, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4221 0, NULL, NULL, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4223 0, NULL, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4225 0, NULL, NULL, NULL},
4227 /* RFC 2307 NIS Syntaxes */
4228 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4229 0, nisNetgroupTripleValidate, NULL, NULL},
4230 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4231 0, bootParameterValidate, NULL, NULL},
4235 /* These OIDs are not published yet, but will be in the next
4236 * I-D for PKIX LDAPv3 schema as have been advanced by David
4237 * Chadwick in private mail.
4239 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4240 0, NULL, NULL, NULL},
4243 /* OpenLDAP Experimental Syntaxes */
4244 #ifdef SLAPD_ACI_ENABLED
4245 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4247 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4251 #ifdef SLAPD_AUTHPASSWD
4252 /* needs updating */
4253 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4254 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4257 /* OpenLDAP Void Syntax */
4258 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4259 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4260 {NULL, 0, NULL, NULL, NULL}
4264 * Other matching rules in X.520 that we do not use (yet):
4266 * 2.5.13.9 numericStringOrderingMatch
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.15 NAME 'integerOrderingMatch' "
4429 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4432 integerOrderingMatch, NULL, NULL,
4435 {"( 2.5.13.16 NAME 'bitStringMatch' "
4436 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4437 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4439 bitStringMatch, bitStringIndexer, bitStringFilter,
4442 {"( 2.5.13.17 NAME 'octetStringMatch' "
4443 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4444 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4446 octetStringMatch, octetStringIndexer, octetStringFilter,
4449 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4450 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4451 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4453 telephoneNumberMatch,
4454 telephoneNumberIndexer,
4455 telephoneNumberFilter,
4458 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4459 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4460 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4462 telephoneNumberSubstringsMatch,
4463 telephoneNumberSubstringsIndexer,
4464 telephoneNumberSubstringsFilter,
4467 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4468 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4469 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4474 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4475 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4476 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4478 uniqueMemberMatch, NULL, NULL,
4481 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4482 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4483 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4485 protocolInformationMatch, NULL, NULL,
4488 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4489 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4490 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4492 generalizedTimeMatch, NULL, NULL,
4495 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4496 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4499 generalizedTimeOrderingMatch, NULL, NULL,
4502 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4503 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4504 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4506 integerFirstComponentMatch, NULL, NULL,
4509 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4510 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4511 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4513 objectIdentifierFirstComponentMatch, NULL, NULL,
4517 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4518 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4519 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4520 certificateExactConvert, NULL,
4521 certificateExactMatch,
4522 certificateExactIndexer, certificateExactFilter,
4526 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4527 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4528 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4530 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4531 IA5StringApproxMatchOID },
4533 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4534 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4535 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4537 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4538 IA5StringApproxMatchOID },
4540 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4541 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4544 caseIgnoreIA5SubstringsMatch,
4545 caseIgnoreIA5SubstringsIndexer,
4546 caseIgnoreIA5SubstringsFilter,
4549 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4550 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4553 caseExactIA5SubstringsMatch,
4554 caseExactIA5SubstringsIndexer,
4555 caseExactIA5SubstringsFilter,
4558 #ifdef SLAPD_AUTHPASSWD
4559 /* needs updating */
4560 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4561 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4564 authPasswordMatch, NULL, NULL,
4568 #ifdef SLAPD_ACI_ENABLED
4569 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4570 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4573 OpenLDAPaciMatch, NULL, NULL,
4577 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4578 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4581 integerBitAndMatch, NULL, NULL,
4584 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4585 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4588 integerBitOrMatch, NULL, NULL,
4591 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4595 slap_schema_init( void )
4600 /* we should only be called once (from main) */
4601 assert( schema_init_done == 0 );
4603 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4604 res = register_syntax( syntax_defs[i].sd_desc,
4605 syntax_defs[i].sd_flags,
4606 syntax_defs[i].sd_validate,
4607 syntax_defs[i].sd_normalize,
4608 syntax_defs[i].sd_pretty
4609 #ifdef SLAPD_BINARY_CONVERSION
4611 syntax_defs[i].sd_ber2str,
4612 syntax_defs[i].sd_str2ber
4617 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4618 syntax_defs[i].sd_desc );
4623 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4624 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4626 "slap_schema_init: Ingoring unusable matching rule %s\n",
4627 mrule_defs[i].mrd_desc );
4631 res = register_matching_rule(
4632 mrule_defs[i].mrd_desc,
4633 mrule_defs[i].mrd_usage,
4634 mrule_defs[i].mrd_convert,
4635 mrule_defs[i].mrd_normalize,
4636 mrule_defs[i].mrd_match,
4637 mrule_defs[i].mrd_indexer,
4638 mrule_defs[i].mrd_filter,
4639 mrule_defs[i].mrd_associated );
4643 "slap_schema_init: Error registering matching rule %s\n",
4644 mrule_defs[i].mrd_desc );
4649 for ( i=0; i < (int)(sizeof(mr_ptr)/sizeof(mr_ptr[0])); i++ )
4650 *mr_ptr[i].mr = mr_find( mr_ptr[i].oid );
4652 res = slap_schema_load();
4653 schema_init_done = 1;
4658 schema_destroy( void )
4664 for ( i=0; i < (int)(sizeof(mr_ptr)/sizeof(mr_ptr[0])); i++ )
4665 *mr_ptr[i].mr = NULL;