1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
15 #include <ac/string.h>
16 #include <ac/socket.h>
21 #include "ldap_utf8.h"
23 #include "lutil_hash.h"
24 #define HASH_BYTES LUTIL_HASH_BYTES
25 #define HASH_CONTEXT lutil_HASH_CTX
26 #define HASH_Init(c) lutil_HASHInit(c)
27 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
28 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
30 /* recycled validatation routines */
31 #define berValidate blobValidate
33 /* unimplemented pretters */
34 #define integerPretty NULL
35 #define SLAP_LDAPDN_PRETTY 0x1
37 /* recycled matching routines */
38 #define bitStringMatch octetStringMatch
39 #define numericStringMatch caseIgnoreIA5Match
40 #define objectIdentifierMatch caseIgnoreIA5Match
41 #define telephoneNumberMatch caseIgnoreIA5Match
42 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
43 #define generalizedTimeMatch caseIgnoreIA5Match
44 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
45 #define uniqueMemberMatch dnMatch
47 /* approx matching rules */
48 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
49 #define directoryStringApproxMatch approxMatch
50 #define directoryStringApproxIndexer approxIndexer
51 #define directoryStringApproxFilter approxFilter
52 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
53 #define IA5StringApproxMatch approxMatch
54 #define IA5StringApproxIndexer approxIndexer
55 #define IA5StringApproxFilter approxFilter
57 /* orderring matching rules */
58 #define caseIgnoreOrderingMatch caseIgnoreMatch
59 #define caseExactOrderingMatch caseExactMatch
61 /* unimplemented matching routines */
62 #define caseIgnoreListMatch NULL
63 #define caseIgnoreListSubstringsMatch NULL
64 #define protocolInformationMatch NULL
65 #define integerFirstComponentMatch NULL
67 #define OpenLDAPaciMatch NULL
68 #define authPasswordMatch NULL
70 /* recycled indexing/filtering routines */
71 #define dnIndexer caseExactIgnoreIndexer
72 #define dnFilter caseExactIgnoreFilter
73 #define bitStringFilter octetStringFilter
74 #define bitStringIndexer octetStringIndexer
76 #define telephoneNumberIndexer caseIgnoreIA5Indexer
77 #define telephoneNumberFilter caseIgnoreIA5Filter
78 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
79 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
81 /* must match OIDs below */
82 #define caseExactMatchOID "2.5.13.5"
83 #define caseExactSubstringsMatchOID "2.5.13.7"
85 static char *strcasechr( const char *str, int c )
87 char *lower = strchr( str, TOLOWER(c) );
88 char *upper = strchr( str, TOUPPER(c) );
90 if( lower && upper ) {
91 return lower < upper ? lower : upper;
105 struct berval *value,
106 void *assertedValue )
108 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
111 match = memcmp( value->bv_val,
112 ((struct berval *) assertedValue)->bv_val,
120 /* Index generation function */
121 int octetStringIndexer(
126 struct berval *prefix,
127 struct berval **values,
128 struct berval ***keysp )
132 struct berval **keys;
133 HASH_CONTEXT HASHcontext;
134 unsigned char HASHdigest[HASH_BYTES];
135 struct berval digest;
136 digest.bv_val = HASHdigest;
137 digest.bv_len = sizeof(HASHdigest);
139 for( i=0; values[i] != NULL; i++ ) {
140 /* just count them */
143 /* we should have at least one value at this point */
146 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
148 slen = strlen( syntax->ssyn_oid );
149 mlen = strlen( mr->smr_oid );
151 for( i=0; values[i] != NULL; i++ ) {
152 HASH_Init( &HASHcontext );
153 if( prefix != NULL && prefix->bv_len > 0 ) {
154 HASH_Update( &HASHcontext,
155 prefix->bv_val, prefix->bv_len );
157 HASH_Update( &HASHcontext,
158 syntax->ssyn_oid, slen );
159 HASH_Update( &HASHcontext,
161 HASH_Update( &HASHcontext,
162 values[i]->bv_val, values[i]->bv_len );
163 HASH_Final( HASHdigest, &HASHcontext );
165 keys[i] = ber_bvdup( &digest );
175 /* Index generation function */
176 int octetStringFilter(
181 struct berval *prefix,
183 struct berval ***keysp )
186 struct berval **keys;
187 HASH_CONTEXT HASHcontext;
188 unsigned char HASHdigest[HASH_BYTES];
189 struct berval *value = (struct berval *) assertValue;
190 struct berval digest;
191 digest.bv_val = HASHdigest;
192 digest.bv_len = sizeof(HASHdigest);
194 slen = strlen( syntax->ssyn_oid );
195 mlen = strlen( mr->smr_oid );
197 keys = ch_malloc( sizeof( struct berval * ) * 2 );
199 HASH_Init( &HASHcontext );
200 if( prefix != NULL && prefix->bv_len > 0 ) {
201 HASH_Update( &HASHcontext,
202 prefix->bv_val, prefix->bv_len );
204 HASH_Update( &HASHcontext,
205 syntax->ssyn_oid, slen );
206 HASH_Update( &HASHcontext,
208 HASH_Update( &HASHcontext,
209 value->bv_val, value->bv_len );
210 HASH_Final( HASHdigest, &HASHcontext );
212 keys[0] = ber_bvdup( &digest );
221 * The DN syntax-related functions take advantage of the dn representation
222 * handling functions ldap_str2dn/ldap_dn2str. The latter are not schema-
223 * aware, so the attributes and their values need be validated (and possibly
224 * normalized). In the current implementation the required validation/nor-
225 * malization/"pretty"ing are done on newly created DN structural represen-
226 * tations; however the idea is to move towards DN handling in structural
227 * representation instead of the current string representation. To this
228 * purpose, we need to do only the required operations and keep track of
229 * what has been done to minimize their impact on performances.
231 * Developers are strongly encouraged to use this feature, to speed-up
235 #define AVA_PRIVATE( ava ) ( ( AttributeDescription * )(ava)->la_private )
238 * In-place, schema-aware validation of the
239 * structural representation of a distinguished name.
242 LDAPDN_validate( LDAPDN *dn )
249 for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
250 LDAPRDN *rdn = dn[ iRDN ][ 0 ];
255 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
256 LDAPAVA *ava = rdn[ iAVA ][ 0 ];
257 AttributeDescription *ad;
258 slap_syntax_validate_func *validate = NULL;
262 if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
263 const char *text = NULL;
265 rc = slap_bv2ad( ava->la_attr, &ad, &text );
266 if ( rc != LDAP_SUCCESS ) {
267 return LDAP_INVALID_SYNTAX;
270 ava->la_private = ( void * )ad;
274 * Replace attr oid/name with the canonical name
276 ber_bvfree( ava->la_attr );
277 ava->la_attr = ber_bvdup( &ad->ad_cname );
279 validate = ad->ad_type->sat_syntax->ssyn_validate;
283 * validate value by validate function
285 rc = ( *validate )( ad->ad_type->sat_syntax,
288 if ( rc != LDAP_SUCCESS ) {
289 return LDAP_INVALID_SYNTAX;
299 * dn validate routine
311 if ( in->bv_len == 0 ) {
312 return( LDAP_SUCCESS );
315 rc = ldap_str2dn( in->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
318 * Schema-aware validate
320 if ( rc == LDAP_SUCCESS ) {
321 rc = LDAPDN_validate( dn );
324 ldapava_free_dn( dn );
326 if ( rc != LDAP_SUCCESS ) {
327 return( LDAP_INVALID_SYNTAX );
330 return( LDAP_SUCCESS );
334 * AVA sorting inside a RDN
336 * rule: sort attributeTypes in alphabetical order; in case of multiple
337 * occurrences of the same attributeType, sort values in byte order
338 * (use memcmp, which implies alphabetical order in case of IA5 value;
339 * this should guarantee the repeatability of the operation).
341 * uses a linear search; should be fine since the number of AVAs in
342 * a RDN should be limited.
345 AVA_Sort( LDAPRDN *rdn, int iAVA )
348 LDAPAVA *ava_in = rdn[ iAVA ][ 0 ];
353 for ( i = 0; i < iAVA; i++ ) {
354 LDAPAVA *ava = rdn[ i ][ 0 ];
359 a = strcmp( ava_in->la_attr->bv_val, ava->la_attr->bv_val );
368 d = ava_in->la_value->bv_len - ava->la_value->bv_len;
370 v = memcmp( ava_in->la_value->bv_val,
371 ava->la_value->bv_val,
372 d <= 0 ? ava_in->la_value->bv_len
373 : ava->la_value->bv_len );
375 if ( v == 0 && d != 0 ) {
394 a = strcmp( ava_in->la_value->bv_val,
395 ava->la_value->bv_val );
401 for ( j = iAVA; j > i; j-- ) {
402 rdn[ j ][ 0 ] = rdn[ j - 1 ][ 0 ];
404 rdn[ i ][ 0 ] = ava_in;
411 * In-place, schema-aware normalization / "pretty"ing of the
412 * structural representation of a distinguished name.
415 LDAPDN_rewrite( LDAPDN *dn, unsigned flags )
422 for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
423 LDAPRDN *rdn = dn[ iRDN ][ 0 ];
428 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
429 LDAPAVA *ava = rdn[ iAVA ][ 0 ];
430 AttributeDescription *ad;
431 slap_syntax_transform_func *transf = NULL;
433 struct berval *bv = NULL;
437 if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
438 const char *text = NULL;
440 rc = slap_bv2ad( ava->la_attr, &ad, &text );
441 if ( rc != LDAP_SUCCESS ) {
442 return LDAP_INVALID_SYNTAX;
445 ava->la_private = ( void * )ad;
449 * Replace attr oid/name with the canonical name
451 ber_bvfree( ava->la_attr );
452 ava->la_attr = ber_bvdup( &ad->ad_cname );
454 if( flags & SLAP_LDAPDN_PRETTY ) {
455 transf = ad->ad_type->sat_syntax->ssyn_pretty;
458 transf = ad->ad_type->sat_syntax->ssyn_normalize;
459 mr = ad->ad_type->sat_equality;
464 * transform value by normalize/pretty function
466 rc = ( *transf )( ad->ad_type->sat_syntax,
467 ava->la_value, &bv );
469 if ( rc != LDAP_SUCCESS ) {
470 return LDAP_INVALID_SYNTAX;
474 if( mr && ( mr->smr_usage & SLAP_MR_DN_FOLD ) ) {
475 struct berval *s = bv;
477 bv = ber_bvstr( UTF8normalize( bv ? bv : ava->la_value,
484 ber_bvfree( ava->la_value );
488 AVA_Sort( rdn, iAVA );
496 * dn normalize routine
502 struct berval **normalized )
504 struct berval *out = NULL;
506 Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 );
509 assert( normalized );
511 if ( val->bv_len != 0 ) {
517 * Go to structural representation
519 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
520 if ( rc != LDAP_SUCCESS ) {
521 return LDAP_INVALID_SYNTAX;
525 * Schema-aware rewrite
527 if ( LDAPDN_rewrite( dn, 0 ) != LDAP_SUCCESS ) {
528 ldapava_free_dn( dn );
529 return LDAP_INVALID_SYNTAX;
533 * Back to string representation
535 rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
537 ldapava_free_dn( dn );
539 if ( rc != LDAP_SUCCESS ) {
540 return LDAP_INVALID_SYNTAX;
543 out = ber_bvstr( dn_out );
546 out = ber_bvdup( val );
549 Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val, 0, 0 );
557 * dn "pretty"ing routine
563 struct berval **pretty)
565 struct berval *out = NULL;
567 Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 );
572 if ( val->bv_len != 0 ) {
577 /* FIXME: should be liberal in what we accept */
578 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
579 if ( rc != LDAP_SUCCESS ) {
580 return LDAP_INVALID_SYNTAX;
584 * Schema-aware rewrite
586 if ( LDAPDN_rewrite( dn, SLAP_LDAPDN_PRETTY ) != LDAP_SUCCESS ) {
587 ldapava_free_dn( dn );
588 return LDAP_INVALID_SYNTAX;
591 /* FIXME: not sure why the default isn't pretty */
592 /* RE: the default is the form that is used as
593 * an internal representation; the pretty form
595 rc = ldap_dn2str( dn, &dn_out,
596 LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
598 ldapava_free_dn( dn );
600 if ( rc != LDAP_SUCCESS ) {
601 return LDAP_INVALID_SYNTAX;
604 out = ber_bvstr( dn_out );
607 out = ber_bvdup( val );
610 Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val, 0, 0 );
620 * note: uses exact string match (strcmp) because it is supposed to work
629 struct berval *value,
630 void *assertedValue )
633 struct berval *asserted = (struct berval *) assertedValue;
637 assert( assertedValue );
639 match = value->bv_len - asserted->bv_len;
642 match = strcmp( value->bv_val, asserted->bv_val );
646 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
647 "dnMatch: %d\n %s\n %s\n", match,
648 value->bv_val, asserted->bv_val ));
650 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
651 match, value->bv_val, asserted->bv_val );
655 return( LDAP_SUCCESS );
667 if( in->bv_len == 0 ) return LDAP_SUCCESS;
669 dn = ber_bvdup( in );
671 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
672 /* assume presence of optional UID */
675 for(i=dn->bv_len-2; i>2; i--) {
676 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
680 if( dn->bv_val[i] != '\'' ||
681 dn->bv_val[i-1] != 'B' ||
682 dn->bv_val[i-2] != '#' ) {
684 return LDAP_INVALID_SYNTAX;
687 /* trim the UID to allow use of dn_validate */
688 dn->bv_val[i-2] = '\0';
691 /* FIXME: should use dnValidate */
692 rc = dn_validate( dn->bv_val ) == NULL
693 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
703 struct berval **normalized )
705 struct berval *out = ber_bvdup( val );
707 if( out->bv_len != 0 ) {
711 ber_len_t uidlen = 0;
713 if( out->bv_val[out->bv_len-1] == '\'' ) {
714 /* assume presence of optional UID */
715 uid = strrchr( out->bv_val, '#' );
719 return LDAP_INVALID_SYNTAX;
722 uidlen = out->bv_len - (out->bv_val - uid);
723 /* temporarily trim the UID */
727 /* FIXME: should use dnNormalize */
728 #ifdef USE_DN_NORMALIZE
729 dn = dn_normalize( out->bv_val );
731 dn = dn_validate( out->bv_val );
736 return LDAP_INVALID_SYNTAX;
742 /* restore the separator */
745 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
749 out->bv_len = dnlen + uidlen;
761 /* any value allowed */
770 /* any value allowed */
781 /* very unforgiving validation, requires no normalization
782 * before simplistic matching
784 if( in->bv_len < 3 ) {
785 return LDAP_INVALID_SYNTAX;
789 * rfc 2252 section 6.3 Bit String
790 * bitstring = "'" *binary-digit "'"
791 * binary-digit = "0" / "1"
792 * example: '0101111101'B
795 if( in->bv_val[0] != '\'' ||
796 in->bv_val[in->bv_len-2] != '\'' ||
797 in->bv_val[in->bv_len-1] != 'B' )
799 return LDAP_INVALID_SYNTAX;
802 for( i=in->bv_len-3; i>0; i-- ) {
803 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
804 return LDAP_INVALID_SYNTAX;
815 struct berval **normalized )
818 * A normalized bitString is has no extaneous (leading) zero bits.
819 * That is, '00010'B is normalized to '10'B
820 * However, as a special case, '0'B requires no normalization.
822 struct berval *newval;
825 /* start at the first bit */
828 /* Find the first non-zero bit */
829 while ( *p == '0' ) p++;
831 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
834 /* no non-zero bits */
835 newval->bv_val = ch_strdup("\'0\'B");
836 newval->bv_len = sizeof("\'0\'B") - 1;
840 newval->bv_val = ch_malloc( val->bv_len + 1 );
842 newval->bv_val[0] = '\'';
845 for( ; *p != '\0'; p++ ) {
846 newval->bv_val[newval->bv_len++] = *p;
849 newval->bv_val[newval->bv_len] = '\0';
852 *normalized = newval;
857 * Handling boolean syntax and matching is quite rigid.
858 * A more flexible approach would be to allow a variety
859 * of strings to be normalized and prettied into TRUE
867 /* very unforgiving validation, requires no normalization
868 * before simplistic matching
871 if( in->bv_len == 4 ) {
872 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
875 } else if( in->bv_len == 5 ) {
876 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
881 return LDAP_INVALID_SYNTAX;
890 struct berval *value,
891 void *assertedValue )
893 /* simplistic matching allowed by rigid validation */
894 struct berval *asserted = (struct berval *) assertedValue;
895 *matchp = value->bv_len != asserted->bv_len;
906 unsigned char *u = in->bv_val;
908 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
910 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
911 /* get the length indicated by the first byte */
912 len = LDAP_UTF8_CHARLEN( u );
914 /* should not be zero */
915 if( len == 0 ) return LDAP_INVALID_SYNTAX;
917 /* make sure len corresponds with the offset
918 to the next character */
919 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
922 if( count != 0 ) return LDAP_INVALID_SYNTAX;
931 struct berval **normalized )
933 struct berval *newval;
936 newval = ch_malloc( sizeof( struct berval ) );
940 /* Ignore initial whitespace */
941 while ( ldap_utf8_isspace( p ) ) {
947 return LDAP_INVALID_SYNTAX;
950 newval->bv_val = ch_strdup( p );
951 p = q = newval->bv_val;
957 if ( ldap_utf8_isspace( p ) ) {
958 len = LDAP_UTF8_COPY(q,p);
963 /* Ignore the extra whitespace */
964 while ( ldap_utf8_isspace( p ) ) {
968 len = LDAP_UTF8_COPY(q,p);
975 assert( *newval->bv_val );
976 assert( newval->bv_val < p );
979 /* cannot start with a space */
980 assert( !ldap_utf8_isspace(newval->bv_val) );
983 * If the string ended in space, backup the pointer one
984 * position. One is enough because the above loop collapsed
985 * all whitespace to a single space.
992 /* cannot end with a space */
993 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
998 newval->bv_len = q - newval->bv_val;
999 *normalized = newval;
1001 return LDAP_SUCCESS;
1004 /* Returns Unicode cannonically normalized copy of a substring assertion
1005 * Skipping attribute description */
1006 SubstringsAssertion *
1007 UTF8SubstringsassertionNormalize(
1008 SubstringsAssertion *sa,
1011 SubstringsAssertion *nsa;
1014 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
1019 if( sa->sa_initial != NULL ) {
1020 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
1021 if( nsa->sa_initial == NULL ) {
1026 if( sa->sa_any != NULL ) {
1027 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1030 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
1031 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1032 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
1033 if( nsa->sa_any[i] == NULL ) {
1037 nsa->sa_any[i] = NULL;
1040 if( sa->sa_final != NULL ) {
1041 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
1042 if( nsa->sa_final == NULL ) {
1050 ber_bvfree( nsa->sa_final );
1051 ber_bvecfree( nsa->sa_any );
1052 ber_bvfree( nsa->sa_initial );
1057 /* Strip characters with the 8th bit set */
1070 while( *++q & 0x80 ) {
1073 p = memmove(p, q, strlen(q) + 1);
1081 #ifndef SLAPD_APPROX_OLDSINGLESTRING
1083 #if defined(SLAPD_APPROX_INITIALS)
1084 #define SLAPD_APPROX_DELIMITER "._ "
1085 #define SLAPD_APPROX_WORDLEN 2
1087 #define SLAPD_APPROX_DELIMITER " "
1088 #define SLAPD_APPROX_WORDLEN 1
1097 struct berval *value,
1098 void *assertedValue )
1100 char *val, *nval, *assertv, **values, **words, *c;
1101 int i, count, len, nextchunk=0, nextavail=0;
1104 /* Yes, this is necessary */
1105 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
1106 if( nval == NULL ) {
1108 return LDAP_SUCCESS;
1110 strip8bitChars( nval );
1112 /* Yes, this is necessary */
1113 assertv = UTF8normalize( ((struct berval *)assertedValue),
1115 if( assertv == NULL ) {
1118 return LDAP_SUCCESS;
1120 strip8bitChars( assertv );
1121 avlen = strlen( assertv );
1123 /* Isolate how many words there are */
1124 for( c=nval,count=1; *c; c++ ) {
1125 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
1126 if ( c == NULL ) break;
1131 /* Get a phonetic copy of each word */
1132 words = (char **)ch_malloc( count * sizeof(char *) );
1133 values = (char **)ch_malloc( count * sizeof(char *) );
1134 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
1136 values[i] = phonetic(c);
1139 /* Work through the asserted value's words, to see if at least some
1140 of the words are there, in the same order. */
1142 while ( (size_t) nextchunk < avlen ) {
1143 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
1148 #if defined(SLAPD_APPROX_INITIALS)
1149 else if( len == 1 ) {
1150 /* Single letter words need to at least match one word's initial */
1151 for( i=nextavail; i<count; i++ )
1152 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
1159 /* Isolate the next word in the asserted value and phonetic it */
1160 assertv[nextchunk+len] = '\0';
1161 val = phonetic( assertv + nextchunk );
1163 /* See if this phonetic chunk is in the remaining words of *value */
1164 for( i=nextavail; i<count; i++ ){
1165 if( !strcmp( val, values[i] ) ){
1173 /* This chunk in the asserted value was NOT within the *value. */
1179 /* Go on to the next word in the asserted value */
1183 /* If some of the words were seen, call it a match */
1184 if( nextavail > 0 ) {
1191 /* Cleanup allocs */
1193 for( i=0; i<count; i++ ) {
1194 ch_free( values[i] );
1200 return LDAP_SUCCESS;
1209 struct berval *prefix,
1210 struct berval **values,
1211 struct berval ***keysp )
1214 int i,j, len, wordcount, keycount=0;
1215 struct berval **newkeys, **keys=NULL;
1217 for( j=0; values[j] != NULL; j++ ) {
1218 /* Yes, this is necessary */
1219 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
1220 strip8bitChars( val );
1222 /* Isolate how many words there are. There will be a key for each */
1223 for( wordcount=0,c=val; *c; c++) {
1224 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1225 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
1227 if (*c == '\0') break;
1231 /* Allocate/increase storage to account for new keys */
1232 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
1233 * sizeof(struct berval *) );
1234 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
1235 if( keys ) ch_free( keys );
1238 /* Get a phonetic copy of each word */
1239 for( c=val,i=0; i<wordcount; c+=len+1 ) {
1241 if( len < SLAPD_APPROX_WORDLEN ) continue;
1242 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
1243 keys[keycount]->bv_val = phonetic( c );
1244 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
1251 keys[keycount] = NULL;
1254 return LDAP_SUCCESS;
1263 struct berval *prefix,
1265 struct berval ***keysp )
1269 struct berval **keys;
1271 /* Yes, this is necessary */
1272 val = UTF8normalize( ((struct berval *)assertValue),
1275 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
1278 return LDAP_SUCCESS;
1280 strip8bitChars( val );
1282 /* Isolate how many words there are. There will be a key for each */
1283 for( count=0,c=val; *c; c++) {
1284 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1285 if( len >= SLAPD_APPROX_WORDLEN ) count++;
1287 if (*c == '\0') break;
1291 /* Allocate storage for new keys */
1292 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
1294 /* Get a phonetic copy of each word */
1295 for( c=val,i=0; i<count; c+=len+1 ) {
1297 if( len < SLAPD_APPROX_WORDLEN ) continue;
1298 keys[i] = ber_bvstr( phonetic( c ) );
1307 return LDAP_SUCCESS;
1312 /* No other form of Approximate Matching is defined */
1320 struct berval *value,
1321 void *assertedValue )
1323 char *vapprox, *avapprox;
1326 /* Yes, this is necessary */
1327 s = UTF8normalize( value, UTF8_NOCASEFOLD );
1330 return LDAP_SUCCESS;
1333 /* Yes, this is necessary */
1334 t = UTF8normalize( ((struct berval *)assertedValue),
1339 return LDAP_SUCCESS;
1342 vapprox = phonetic( strip8bitChars( s ) );
1343 avapprox = phonetic( strip8bitChars( t ) );
1348 *matchp = strcmp( vapprox, avapprox );
1351 ch_free( avapprox );
1353 return LDAP_SUCCESS;
1362 struct berval *prefix,
1363 struct berval **values,
1364 struct berval ***keysp )
1367 struct berval **keys;
1370 for( i=0; values[i] != NULL; i++ ) {
1371 /* empty - just count them */
1374 /* we should have at least one value at this point */
1377 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
1379 /* Copy each value and run it through phonetic() */
1380 for( i=0; values[i] != NULL; i++ ) {
1381 /* Yes, this is necessary */
1382 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
1384 /* strip 8-bit chars and run through phonetic() */
1385 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1391 return LDAP_SUCCESS;
1401 struct berval *prefix,
1403 struct berval ***keysp )
1405 struct berval **keys;
1408 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1410 /* Yes, this is necessary */
1411 s = UTF8normalize( ((struct berval *)assertValue),
1416 /* strip 8-bit chars and run through phonetic() */
1417 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1423 return LDAP_SUCCESS;
1434 struct berval *value,
1435 void *assertedValue )
1437 *matchp = UTF8normcmp( value->bv_val,
1438 ((struct berval *) assertedValue)->bv_val,
1440 return LDAP_SUCCESS;
1444 caseExactIgnoreSubstringsMatch(
1449 struct berval *value,
1450 void *assertedValue )
1453 SubstringsAssertion *sub = NULL;
1457 char *nav, casefold;
1459 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1460 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1462 nav = UTF8normalize( value, casefold );
1468 left.bv_len = strlen( nav );
1470 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1476 /* Add up asserted input length */
1477 if( sub->sa_initial ) {
1478 inlen += sub->sa_initial->bv_len;
1481 for(i=0; sub->sa_any[i] != NULL; i++) {
1482 inlen += sub->sa_any[i]->bv_len;
1485 if( sub->sa_final ) {
1486 inlen += sub->sa_final->bv_len;
1489 if( sub->sa_initial ) {
1490 if( inlen > left.bv_len ) {
1495 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1496 sub->sa_initial->bv_len );
1502 left.bv_val += sub->sa_initial->bv_len;
1503 left.bv_len -= sub->sa_initial->bv_len;
1504 inlen -= sub->sa_initial->bv_len;
1507 if( sub->sa_final ) {
1508 if( inlen > left.bv_len ) {
1513 match = strncmp( sub->sa_final->bv_val,
1514 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1515 sub->sa_final->bv_len );
1521 left.bv_len -= sub->sa_final->bv_len;
1522 inlen -= sub->sa_final->bv_len;
1526 for(i=0; sub->sa_any[i]; i++) {
1531 if( inlen > left.bv_len ) {
1532 /* not enough length */
1537 if( sub->sa_any[i]->bv_len == 0 ) {
1541 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1548 idx = p - left.bv_val;
1549 assert( idx < left.bv_len );
1551 if( idx >= left.bv_len ) {
1552 /* this shouldn't happen */
1554 ch_free( sub->sa_final );
1555 ber_bvecfree( sub->sa_any );
1556 ch_free( sub->sa_initial );
1564 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1565 /* not enough left */
1570 match = strncmp( left.bv_val,
1571 sub->sa_any[i]->bv_val,
1572 sub->sa_any[i]->bv_len );
1580 left.bv_val += sub->sa_any[i]->bv_len;
1581 left.bv_len -= sub->sa_any[i]->bv_len;
1582 inlen -= sub->sa_any[i]->bv_len;
1589 ber_bvfree( sub->sa_final );
1590 ber_bvecfree( sub->sa_any );
1591 ber_bvfree( sub->sa_initial );
1595 return LDAP_SUCCESS;
1598 /* Index generation function */
1599 int caseExactIgnoreIndexer(
1604 struct berval *prefix,
1605 struct berval **values,
1606 struct berval ***keysp )
1611 struct berval **keys;
1612 HASH_CONTEXT HASHcontext;
1613 unsigned char HASHdigest[HASH_BYTES];
1614 struct berval digest;
1615 digest.bv_val = HASHdigest;
1616 digest.bv_len = sizeof(HASHdigest);
1618 for( i=0; values[i] != NULL; i++ ) {
1619 /* empty - just count them */
1622 /* we should have at least one value at this point */
1625 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1627 slen = strlen( syntax->ssyn_oid );
1628 mlen = strlen( mr->smr_oid );
1630 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1631 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1633 for( i=0; values[i] != NULL; i++ ) {
1634 struct berval *value;
1635 value = ber_bvstr( UTF8normalize( values[i],
1638 HASH_Init( &HASHcontext );
1639 if( prefix != NULL && prefix->bv_len > 0 ) {
1640 HASH_Update( &HASHcontext,
1641 prefix->bv_val, prefix->bv_len );
1643 HASH_Update( &HASHcontext,
1644 syntax->ssyn_oid, slen );
1645 HASH_Update( &HASHcontext,
1646 mr->smr_oid, mlen );
1647 HASH_Update( &HASHcontext,
1648 value->bv_val, value->bv_len );
1649 HASH_Final( HASHdigest, &HASHcontext );
1651 ber_bvfree( value );
1653 keys[i] = ber_bvdup( &digest );
1658 return LDAP_SUCCESS;
1661 /* Index generation function */
1662 int caseExactIgnoreFilter(
1667 struct berval *prefix,
1669 struct berval ***keysp )
1673 struct berval **keys;
1674 HASH_CONTEXT HASHcontext;
1675 unsigned char HASHdigest[HASH_BYTES];
1676 struct berval *value;
1677 struct berval digest;
1678 digest.bv_val = HASHdigest;
1679 digest.bv_len = sizeof(HASHdigest);
1681 slen = strlen( syntax->ssyn_oid );
1682 mlen = strlen( mr->smr_oid );
1684 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1685 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1687 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
1689 /* This usually happens if filter contains bad UTF8 */
1690 if( value == NULL ) {
1691 keys = ch_malloc( sizeof( struct berval * ) );
1693 return LDAP_SUCCESS;
1696 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1698 HASH_Init( &HASHcontext );
1699 if( prefix != NULL && prefix->bv_len > 0 ) {
1700 HASH_Update( &HASHcontext,
1701 prefix->bv_val, prefix->bv_len );
1703 HASH_Update( &HASHcontext,
1704 syntax->ssyn_oid, slen );
1705 HASH_Update( &HASHcontext,
1706 mr->smr_oid, mlen );
1707 HASH_Update( &HASHcontext,
1708 value->bv_val, value->bv_len );
1709 HASH_Final( HASHdigest, &HASHcontext );
1711 keys[0] = ber_bvdup( &digest );
1714 ber_bvfree( value );
1717 return LDAP_SUCCESS;
1720 /* Substrings Index generation function */
1721 int caseExactIgnoreSubstringsIndexer(
1726 struct berval *prefix,
1727 struct berval **values,
1728 struct berval ***keysp )
1733 struct berval **keys;
1734 struct berval **nvalues;
1736 HASH_CONTEXT HASHcontext;
1737 unsigned char HASHdigest[HASH_BYTES];
1738 struct berval digest;
1739 digest.bv_val = HASHdigest;
1740 digest.bv_len = sizeof(HASHdigest);
1744 for( i=0; values[i] != NULL; i++ ) {
1745 /* empty - just count them */
1748 /* we should have at least one value at this point */
1751 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1752 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1754 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1755 for( i=0; values[i] != NULL; i++ ) {
1756 nvalues[i] = ber_bvstr( UTF8normalize( values[i],
1762 for( i=0; values[i] != NULL; i++ ) {
1763 /* count number of indices to generate */
1764 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1768 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1769 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1770 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1771 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1773 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1777 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1778 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1779 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1783 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1784 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1785 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1786 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1788 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1794 /* no keys to generate */
1796 ber_bvecfree( nvalues );
1797 return LDAP_SUCCESS;
1800 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1802 slen = strlen( syntax->ssyn_oid );
1803 mlen = strlen( mr->smr_oid );
1806 for( i=0; values[i] != NULL; i++ ) {
1808 struct berval *value;
1810 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1814 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1815 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1817 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1818 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1820 for( j=0; j<max; j++ ) {
1821 HASH_Init( &HASHcontext );
1822 if( prefix != NULL && prefix->bv_len > 0 ) {
1823 HASH_Update( &HASHcontext,
1824 prefix->bv_val, prefix->bv_len );
1827 HASH_Update( &HASHcontext,
1828 &pre, sizeof( pre ) );
1829 HASH_Update( &HASHcontext,
1830 syntax->ssyn_oid, slen );
1831 HASH_Update( &HASHcontext,
1832 mr->smr_oid, mlen );
1833 HASH_Update( &HASHcontext,
1835 SLAP_INDEX_SUBSTR_MAXLEN );
1836 HASH_Final( HASHdigest, &HASHcontext );
1838 keys[nkeys++] = ber_bvdup( &digest );
1842 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1843 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1845 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1848 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1849 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1850 HASH_Init( &HASHcontext );
1851 if( prefix != NULL && prefix->bv_len > 0 ) {
1852 HASH_Update( &HASHcontext,
1853 prefix->bv_val, prefix->bv_len );
1855 HASH_Update( &HASHcontext,
1856 &pre, sizeof( pre ) );
1857 HASH_Update( &HASHcontext,
1858 syntax->ssyn_oid, slen );
1859 HASH_Update( &HASHcontext,
1860 mr->smr_oid, mlen );
1861 HASH_Update( &HASHcontext,
1863 HASH_Final( HASHdigest, &HASHcontext );
1865 keys[nkeys++] = ber_bvdup( &digest );
1868 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1869 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1870 HASH_Init( &HASHcontext );
1871 if( prefix != NULL && prefix->bv_len > 0 ) {
1872 HASH_Update( &HASHcontext,
1873 prefix->bv_val, prefix->bv_len );
1875 HASH_Update( &HASHcontext,
1876 &pre, sizeof( pre ) );
1877 HASH_Update( &HASHcontext,
1878 syntax->ssyn_oid, slen );
1879 HASH_Update( &HASHcontext,
1880 mr->smr_oid, mlen );
1881 HASH_Update( &HASHcontext,
1882 &value->bv_val[value->bv_len-j], j );
1883 HASH_Final( HASHdigest, &HASHcontext );
1885 keys[nkeys++] = ber_bvdup( &digest );
1900 ber_bvecfree( nvalues );
1902 return LDAP_SUCCESS;
1905 int caseExactIgnoreSubstringsFilter(
1910 struct berval *prefix,
1912 struct berval ***keysp )
1914 SubstringsAssertion *sa;
1916 ber_len_t nkeys = 0;
1917 size_t slen, mlen, klen;
1918 struct berval **keys;
1919 HASH_CONTEXT HASHcontext;
1920 unsigned char HASHdigest[HASH_BYTES];
1921 struct berval *value;
1922 struct berval digest;
1924 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1925 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1927 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1930 return LDAP_SUCCESS;
1933 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1934 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1939 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1941 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1942 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1943 /* don't bother accounting for stepping */
1944 nkeys += sa->sa_any[i]->bv_len -
1945 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1950 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1951 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1957 ber_bvfree( sa->sa_final );
1958 ber_bvecfree( sa->sa_any );
1959 ber_bvfree( sa->sa_initial );
1962 return LDAP_SUCCESS;
1965 digest.bv_val = HASHdigest;
1966 digest.bv_len = sizeof(HASHdigest);
1968 slen = strlen( syntax->ssyn_oid );
1969 mlen = strlen( mr->smr_oid );
1971 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1974 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1975 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1977 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1978 value = sa->sa_initial;
1980 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1981 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1983 HASH_Init( &HASHcontext );
1984 if( prefix != NULL && prefix->bv_len > 0 ) {
1985 HASH_Update( &HASHcontext,
1986 prefix->bv_val, prefix->bv_len );
1988 HASH_Update( &HASHcontext,
1989 &pre, sizeof( pre ) );
1990 HASH_Update( &HASHcontext,
1991 syntax->ssyn_oid, slen );
1992 HASH_Update( &HASHcontext,
1993 mr->smr_oid, mlen );
1994 HASH_Update( &HASHcontext,
1995 value->bv_val, klen );
1996 HASH_Final( HASHdigest, &HASHcontext );
1998 keys[nkeys++] = ber_bvdup( &digest );
2001 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2003 pre = SLAP_INDEX_SUBSTR_PREFIX;
2004 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2006 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2007 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2011 value = sa->sa_any[i];
2014 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2015 j += SLAP_INDEX_SUBSTR_STEP )
2017 HASH_Init( &HASHcontext );
2018 if( prefix != NULL && prefix->bv_len > 0 ) {
2019 HASH_Update( &HASHcontext,
2020 prefix->bv_val, prefix->bv_len );
2022 HASH_Update( &HASHcontext,
2023 &pre, sizeof( pre ) );
2024 HASH_Update( &HASHcontext,
2025 syntax->ssyn_oid, slen );
2026 HASH_Update( &HASHcontext,
2027 mr->smr_oid, mlen );
2028 HASH_Update( &HASHcontext,
2029 &value->bv_val[j], klen );
2030 HASH_Final( HASHdigest, &HASHcontext );
2032 keys[nkeys++] = ber_bvdup( &digest );
2038 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2039 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2041 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2042 value = sa->sa_final;
2044 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2045 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2047 HASH_Init( &HASHcontext );
2048 if( prefix != NULL && prefix->bv_len > 0 ) {
2049 HASH_Update( &HASHcontext,
2050 prefix->bv_val, prefix->bv_len );
2052 HASH_Update( &HASHcontext,
2053 &pre, sizeof( pre ) );
2054 HASH_Update( &HASHcontext,
2055 syntax->ssyn_oid, slen );
2056 HASH_Update( &HASHcontext,
2057 mr->smr_oid, mlen );
2058 HASH_Update( &HASHcontext,
2059 &value->bv_val[value->bv_len-klen], klen );
2060 HASH_Final( HASHdigest, &HASHcontext );
2062 keys[nkeys++] = ber_bvdup( &digest );
2072 ber_bvfree( sa->sa_final );
2073 ber_bvecfree( sa->sa_any );
2074 ber_bvfree( sa->sa_initial );
2077 return LDAP_SUCCESS;
2086 struct berval *value,
2087 void *assertedValue )
2089 *matchp = UTF8normcmp( value->bv_val,
2090 ((struct berval *) assertedValue)->bv_val,
2092 return LDAP_SUCCESS;
2098 struct berval *val )
2102 if( val->bv_len == 0 ) {
2103 /* disallow empty strings */
2104 return LDAP_INVALID_SYNTAX;
2107 if( OID_LEADCHAR(val->bv_val[0]) ) {
2109 for(i=1; i < val->bv_len; i++) {
2110 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2111 if( dot++ ) return 1;
2112 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2115 return LDAP_INVALID_SYNTAX;
2119 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2121 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2122 for(i=1; i < val->bv_len; i++) {
2123 if( !DESC_CHAR(val->bv_val[i] ) ) {
2124 return LDAP_INVALID_SYNTAX;
2128 return LDAP_SUCCESS;
2131 return LDAP_INVALID_SYNTAX;
2140 struct berval *value,
2141 void *assertedValue )
2144 int vsign=0, avsign=0;
2145 struct berval *asserted;
2146 ber_len_t vlen, avlen;
2149 /* Start off pessimistic */
2152 /* Skip past leading spaces/zeros, and get the sign of the *value number */
2154 vlen = value->bv_len;
2156 if( ASCII_SPACE(*v) || ( *v == '0' )) {
2157 /* empty -- skip spaces */
2159 else if ( *v == '+' ) {
2162 else if ( *v == '-' ) {
2165 else if ( ASCII_DIGIT(*v) ) {
2166 if ( vsign == 0 ) vsign = 1;
2174 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
2176 asserted = (struct berval *) assertedValue;
2177 av = asserted->bv_val;
2178 avlen = asserted->bv_len;
2180 if( ASCII_SPACE(*av) || ( *av == '0' )) {
2181 /* empty -- skip spaces */
2183 else if ( *av == '+' ) {
2186 else if ( *av == '-' ) {
2189 else if ( ASCII_DIGIT(*av) ) {
2190 if ( avsign == 0 ) avsign = 1;
2198 /* The two ?sign vars are now one of :
2199 -2 negative non-zero number
2201 0 0 collapse these three to 0
2203 +2 positive non-zero number
2205 if ( abs( vsign ) == 1 ) vsign = 0;
2206 if ( abs( avsign ) == 1 ) avsign = 0;
2208 if( vsign != avsign ) return LDAP_SUCCESS;
2210 /* Check the significant digits */
2211 while( vlen && avlen ) {
2212 if( *v != *av ) break;
2219 /* If all digits compared equal, the numbers are equal */
2220 if(( vlen == 0 ) && ( avlen == 0 )) {
2223 return LDAP_SUCCESS;
2229 struct berval *val )
2233 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2235 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
2236 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2237 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2238 return LDAP_INVALID_SYNTAX;
2241 for( i=1; i < val->bv_len; i++ ) {
2242 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2245 return LDAP_SUCCESS;
2252 struct berval **normalized )
2256 struct berval *newval;
2263 /* Ignore leading spaces */
2264 while ( len && ( *p == ' ' )) {
2271 negative = ( *p == '-' );
2272 if(( *p == '-' ) || ( *p == '+' )) {
2278 /* Ignore leading zeros */
2279 while ( len && ( *p == '0' )) {
2284 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2286 /* If there are no non-zero digits left, the number is zero, otherwise
2287 allocate space for the number and copy it into the buffer */
2289 newval->bv_val = ch_strdup("0");
2293 newval->bv_len = len+negative;
2294 newval->bv_val = ch_malloc( newval->bv_len );
2296 newval->bv_val[0] = '-';
2298 memcpy( newval->bv_val + negative, p, len );
2301 *normalized = newval;
2302 return LDAP_SUCCESS;
2305 /* Index generation function */
2311 struct berval *prefix,
2312 struct berval **values,
2313 struct berval ***keysp )
2316 struct berval **keys;
2318 /* we should have at least one value at this point */
2319 assert( values != NULL && values[0] != NULL );
2321 for( i=0; values[i] != NULL; i++ ) {
2322 /* empty -- just count them */
2325 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2327 for( i=0; values[i] != NULL; i++ ) {
2328 integerNormalize( syntax, values[i], &keys[i] );
2333 return LDAP_SUCCESS;
2336 /* Index generation function */
2342 struct berval *prefix,
2344 struct berval ***keysp )
2346 struct berval **keys;
2348 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2349 integerNormalize( syntax, assertValue, &keys[0] );
2353 return LDAP_SUCCESS;
2358 countryStringValidate(
2360 struct berval *val )
2362 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2364 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2365 return LDAP_INVALID_SYNTAX;
2367 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2368 return LDAP_INVALID_SYNTAX;
2371 return LDAP_SUCCESS;
2375 printableStringValidate(
2377 struct berval *val )
2381 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2383 for(i=0; i < val->bv_len; i++) {
2384 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2385 return LDAP_INVALID_SYNTAX;
2389 return LDAP_SUCCESS;
2393 printablesStringValidate(
2395 struct berval *val )
2399 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2401 for(i=0; i < val->bv_len; i++) {
2402 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2403 return LDAP_INVALID_SYNTAX;
2407 return LDAP_SUCCESS;
2413 struct berval *val )
2417 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2419 for(i=0; i < val->bv_len; i++) {
2420 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2423 return LDAP_SUCCESS;
2430 struct berval **normalized )
2432 struct berval *newval;
2435 newval = ch_malloc( sizeof( struct berval ) );
2439 /* Ignore initial whitespace */
2440 while ( ASCII_SPACE( *p ) ) {
2446 return LDAP_INVALID_SYNTAX;
2449 newval->bv_val = ch_strdup( p );
2450 p = q = newval->bv_val;
2453 if ( ASCII_SPACE( *p ) ) {
2456 /* Ignore the extra whitespace */
2457 while ( ASCII_SPACE( *p ) ) {
2465 assert( *newval->bv_val );
2466 assert( newval->bv_val < p );
2469 /* cannot start with a space */
2470 assert( !ASCII_SPACE(*newval->bv_val) );
2473 * If the string ended in space, backup the pointer one
2474 * position. One is enough because the above loop collapsed
2475 * all whitespace to a single space.
2478 if ( ASCII_SPACE( q[-1] ) ) {
2482 /* cannot end with a space */
2483 assert( !ASCII_SPACE( q[-1] ) );
2485 /* null terminate */
2488 newval->bv_len = q - newval->bv_val;
2489 *normalized = newval;
2491 return LDAP_SUCCESS;
2500 struct berval *value,
2501 void *assertedValue )
2503 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2506 match = strncmp( value->bv_val,
2507 ((struct berval *) assertedValue)->bv_val,
2512 return LDAP_SUCCESS;
2516 caseExactIA5SubstringsMatch(
2521 struct berval *value,
2522 void *assertedValue )
2525 SubstringsAssertion *sub = assertedValue;
2526 struct berval left = *value;
2530 /* Add up asserted input length */
2531 if( sub->sa_initial ) {
2532 inlen += sub->sa_initial->bv_len;
2535 for(i=0; sub->sa_any[i] != NULL; i++) {
2536 inlen += sub->sa_any[i]->bv_len;
2539 if( sub->sa_final ) {
2540 inlen += sub->sa_final->bv_len;
2543 if( sub->sa_initial ) {
2544 if( inlen > left.bv_len ) {
2549 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2550 sub->sa_initial->bv_len );
2556 left.bv_val += sub->sa_initial->bv_len;
2557 left.bv_len -= sub->sa_initial->bv_len;
2558 inlen -= sub->sa_initial->bv_len;
2561 if( sub->sa_final ) {
2562 if( inlen > left.bv_len ) {
2567 match = strncmp( sub->sa_final->bv_val,
2568 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2569 sub->sa_final->bv_len );
2575 left.bv_len -= sub->sa_final->bv_len;
2576 inlen -= sub->sa_final->bv_len;
2580 for(i=0; sub->sa_any[i]; i++) {
2585 if( inlen > left.bv_len ) {
2586 /* not enough length */
2591 if( sub->sa_any[i]->bv_len == 0 ) {
2595 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2602 idx = p - left.bv_val;
2603 assert( idx < left.bv_len );
2605 if( idx >= left.bv_len ) {
2606 /* this shouldn't happen */
2613 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2614 /* not enough left */
2619 match = strncmp( left.bv_val,
2620 sub->sa_any[i]->bv_val,
2621 sub->sa_any[i]->bv_len );
2629 left.bv_val += sub->sa_any[i]->bv_len;
2630 left.bv_len -= sub->sa_any[i]->bv_len;
2631 inlen -= sub->sa_any[i]->bv_len;
2637 return LDAP_SUCCESS;
2640 /* Index generation function */
2641 int caseExactIA5Indexer(
2646 struct berval *prefix,
2647 struct berval **values,
2648 struct berval ***keysp )
2652 struct berval **keys;
2653 HASH_CONTEXT HASHcontext;
2654 unsigned char HASHdigest[HASH_BYTES];
2655 struct berval digest;
2656 digest.bv_val = HASHdigest;
2657 digest.bv_len = sizeof(HASHdigest);
2659 for( i=0; values[i] != NULL; i++ ) {
2660 /* empty - just count them */
2663 /* we should have at least one value at this point */
2666 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2668 slen = strlen( syntax->ssyn_oid );
2669 mlen = strlen( mr->smr_oid );
2671 for( i=0; values[i] != NULL; i++ ) {
2672 struct berval *value = values[i];
2674 HASH_Init( &HASHcontext );
2675 if( prefix != NULL && prefix->bv_len > 0 ) {
2676 HASH_Update( &HASHcontext,
2677 prefix->bv_val, prefix->bv_len );
2679 HASH_Update( &HASHcontext,
2680 syntax->ssyn_oid, slen );
2681 HASH_Update( &HASHcontext,
2682 mr->smr_oid, mlen );
2683 HASH_Update( &HASHcontext,
2684 value->bv_val, value->bv_len );
2685 HASH_Final( HASHdigest, &HASHcontext );
2687 keys[i] = ber_bvdup( &digest );
2692 return LDAP_SUCCESS;
2695 /* Index generation function */
2696 int caseExactIA5Filter(
2701 struct berval *prefix,
2703 struct berval ***keysp )
2706 struct berval **keys;
2707 HASH_CONTEXT HASHcontext;
2708 unsigned char HASHdigest[HASH_BYTES];
2709 struct berval *value;
2710 struct berval digest;
2711 digest.bv_val = HASHdigest;
2712 digest.bv_len = sizeof(HASHdigest);
2714 slen = strlen( syntax->ssyn_oid );
2715 mlen = strlen( mr->smr_oid );
2717 value = (struct berval *) assertValue;
2719 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2721 HASH_Init( &HASHcontext );
2722 if( prefix != NULL && prefix->bv_len > 0 ) {
2723 HASH_Update( &HASHcontext,
2724 prefix->bv_val, prefix->bv_len );
2726 HASH_Update( &HASHcontext,
2727 syntax->ssyn_oid, slen );
2728 HASH_Update( &HASHcontext,
2729 mr->smr_oid, mlen );
2730 HASH_Update( &HASHcontext,
2731 value->bv_val, value->bv_len );
2732 HASH_Final( HASHdigest, &HASHcontext );
2734 keys[0] = ber_bvdup( &digest );
2738 return LDAP_SUCCESS;
2741 /* Substrings Index generation function */
2742 int caseExactIA5SubstringsIndexer(
2747 struct berval *prefix,
2748 struct berval **values,
2749 struct berval ***keysp )
2753 struct berval **keys;
2754 HASH_CONTEXT HASHcontext;
2755 unsigned char HASHdigest[HASH_BYTES];
2756 struct berval digest;
2757 digest.bv_val = HASHdigest;
2758 digest.bv_len = sizeof(HASHdigest);
2760 /* we should have at least one value at this point */
2761 assert( values != NULL && values[0] != NULL );
2764 for( i=0; values[i] != NULL; i++ ) {
2765 /* count number of indices to generate */
2766 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2770 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2771 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2772 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2773 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2775 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2779 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2780 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2781 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2785 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2786 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2787 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2788 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2790 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2796 /* no keys to generate */
2798 return LDAP_SUCCESS;
2801 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2803 slen = strlen( syntax->ssyn_oid );
2804 mlen = strlen( mr->smr_oid );
2807 for( i=0; values[i] != NULL; i++ ) {
2809 struct berval *value;
2812 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2814 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2815 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2817 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2818 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2820 for( j=0; j<max; j++ ) {
2821 HASH_Init( &HASHcontext );
2822 if( prefix != NULL && prefix->bv_len > 0 ) {
2823 HASH_Update( &HASHcontext,
2824 prefix->bv_val, prefix->bv_len );
2827 HASH_Update( &HASHcontext,
2828 &pre, sizeof( pre ) );
2829 HASH_Update( &HASHcontext,
2830 syntax->ssyn_oid, slen );
2831 HASH_Update( &HASHcontext,
2832 mr->smr_oid, mlen );
2833 HASH_Update( &HASHcontext,
2835 SLAP_INDEX_SUBSTR_MAXLEN );
2836 HASH_Final( HASHdigest, &HASHcontext );
2838 keys[nkeys++] = ber_bvdup( &digest );
2842 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2843 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2845 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2848 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2849 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2850 HASH_Init( &HASHcontext );
2851 if( prefix != NULL && prefix->bv_len > 0 ) {
2852 HASH_Update( &HASHcontext,
2853 prefix->bv_val, prefix->bv_len );
2855 HASH_Update( &HASHcontext,
2856 &pre, sizeof( pre ) );
2857 HASH_Update( &HASHcontext,
2858 syntax->ssyn_oid, slen );
2859 HASH_Update( &HASHcontext,
2860 mr->smr_oid, mlen );
2861 HASH_Update( &HASHcontext,
2863 HASH_Final( HASHdigest, &HASHcontext );
2865 keys[nkeys++] = ber_bvdup( &digest );
2868 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2869 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2870 HASH_Init( &HASHcontext );
2871 if( prefix != NULL && prefix->bv_len > 0 ) {
2872 HASH_Update( &HASHcontext,
2873 prefix->bv_val, prefix->bv_len );
2875 HASH_Update( &HASHcontext,
2876 &pre, sizeof( pre ) );
2877 HASH_Update( &HASHcontext,
2878 syntax->ssyn_oid, slen );
2879 HASH_Update( &HASHcontext,
2880 mr->smr_oid, mlen );
2881 HASH_Update( &HASHcontext,
2882 &value->bv_val[value->bv_len-j], j );
2883 HASH_Final( HASHdigest, &HASHcontext );
2885 keys[nkeys++] = ber_bvdup( &digest );
2899 return LDAP_SUCCESS;
2902 int caseExactIA5SubstringsFilter(
2907 struct berval *prefix,
2909 struct berval ***keysp )
2911 SubstringsAssertion *sa = assertValue;
2913 ber_len_t nkeys = 0;
2914 size_t slen, mlen, klen;
2915 struct berval **keys;
2916 HASH_CONTEXT HASHcontext;
2917 unsigned char HASHdigest[HASH_BYTES];
2918 struct berval *value;
2919 struct berval digest;
2921 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2922 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2927 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2929 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2930 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2931 /* don't bother accounting for stepping */
2932 nkeys += sa->sa_any[i]->bv_len -
2933 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2938 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2939 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2946 return LDAP_SUCCESS;
2949 digest.bv_val = HASHdigest;
2950 digest.bv_len = sizeof(HASHdigest);
2952 slen = strlen( syntax->ssyn_oid );
2953 mlen = strlen( mr->smr_oid );
2955 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2958 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2959 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2961 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2962 value = sa->sa_initial;
2964 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2965 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2967 HASH_Init( &HASHcontext );
2968 if( prefix != NULL && prefix->bv_len > 0 ) {
2969 HASH_Update( &HASHcontext,
2970 prefix->bv_val, prefix->bv_len );
2972 HASH_Update( &HASHcontext,
2973 &pre, sizeof( pre ) );
2974 HASH_Update( &HASHcontext,
2975 syntax->ssyn_oid, slen );
2976 HASH_Update( &HASHcontext,
2977 mr->smr_oid, mlen );
2978 HASH_Update( &HASHcontext,
2979 value->bv_val, klen );
2980 HASH_Final( HASHdigest, &HASHcontext );
2982 keys[nkeys++] = ber_bvdup( &digest );
2985 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2987 pre = SLAP_INDEX_SUBSTR_PREFIX;
2988 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2990 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2991 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2995 value = sa->sa_any[i];
2998 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2999 j += SLAP_INDEX_SUBSTR_STEP )
3001 HASH_Init( &HASHcontext );
3002 if( prefix != NULL && prefix->bv_len > 0 ) {
3003 HASH_Update( &HASHcontext,
3004 prefix->bv_val, prefix->bv_len );
3006 HASH_Update( &HASHcontext,
3007 &pre, sizeof( pre ) );
3008 HASH_Update( &HASHcontext,
3009 syntax->ssyn_oid, slen );
3010 HASH_Update( &HASHcontext,
3011 mr->smr_oid, mlen );
3012 HASH_Update( &HASHcontext,
3013 &value->bv_val[j], klen );
3014 HASH_Final( HASHdigest, &HASHcontext );
3016 keys[nkeys++] = ber_bvdup( &digest );
3021 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3022 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3024 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3025 value = sa->sa_final;
3027 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3028 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3030 HASH_Init( &HASHcontext );
3031 if( prefix != NULL && prefix->bv_len > 0 ) {
3032 HASH_Update( &HASHcontext,
3033 prefix->bv_val, prefix->bv_len );
3035 HASH_Update( &HASHcontext,
3036 &pre, sizeof( pre ) );
3037 HASH_Update( &HASHcontext,
3038 syntax->ssyn_oid, slen );
3039 HASH_Update( &HASHcontext,
3040 mr->smr_oid, mlen );
3041 HASH_Update( &HASHcontext,
3042 &value->bv_val[value->bv_len-klen], klen );
3043 HASH_Final( HASHdigest, &HASHcontext );
3045 keys[nkeys++] = ber_bvdup( &digest );
3056 return LDAP_SUCCESS;
3065 struct berval *value,
3066 void *assertedValue )
3068 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3070 if( match == 0 && value->bv_len ) {
3071 match = strncasecmp( value->bv_val,
3072 ((struct berval *) assertedValue)->bv_val,
3077 return LDAP_SUCCESS;
3081 caseIgnoreIA5SubstringsMatch(
3086 struct berval *value,
3087 void *assertedValue )
3090 SubstringsAssertion *sub = assertedValue;
3091 struct berval left = *value;
3095 /* Add up asserted input length */
3096 if( sub->sa_initial ) {
3097 inlen += sub->sa_initial->bv_len;
3100 for(i=0; sub->sa_any[i] != NULL; i++) {
3101 inlen += sub->sa_any[i]->bv_len;
3104 if( sub->sa_final ) {
3105 inlen += sub->sa_final->bv_len;
3108 if( sub->sa_initial ) {
3109 if( inlen > left.bv_len ) {
3114 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3115 sub->sa_initial->bv_len );
3121 left.bv_val += sub->sa_initial->bv_len;
3122 left.bv_len -= sub->sa_initial->bv_len;
3123 inlen -= sub->sa_initial->bv_len;
3126 if( sub->sa_final ) {
3127 if( inlen > left.bv_len ) {
3132 match = strncasecmp( sub->sa_final->bv_val,
3133 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3134 sub->sa_final->bv_len );
3140 left.bv_len -= sub->sa_final->bv_len;
3141 inlen -= sub->sa_final->bv_len;
3145 for(i=0; sub->sa_any[i]; i++) {
3150 if( inlen > left.bv_len ) {
3151 /* not enough length */
3156 if( sub->sa_any[i]->bv_len == 0 ) {
3160 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3167 idx = p - left.bv_val;
3168 assert( idx < left.bv_len );
3170 if( idx >= left.bv_len ) {
3171 /* this shouldn't happen */
3178 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3179 /* not enough left */
3184 match = strncasecmp( left.bv_val,
3185 sub->sa_any[i]->bv_val,
3186 sub->sa_any[i]->bv_len );
3195 left.bv_val += sub->sa_any[i]->bv_len;
3196 left.bv_len -= sub->sa_any[i]->bv_len;
3197 inlen -= sub->sa_any[i]->bv_len;
3203 return LDAP_SUCCESS;
3206 /* Index generation function */
3207 int caseIgnoreIA5Indexer(
3212 struct berval *prefix,
3213 struct berval **values,
3214 struct berval ***keysp )
3218 struct berval **keys;
3219 HASH_CONTEXT HASHcontext;
3220 unsigned char HASHdigest[HASH_BYTES];
3221 struct berval digest;
3222 digest.bv_val = HASHdigest;
3223 digest.bv_len = sizeof(HASHdigest);
3225 /* we should have at least one value at this point */
3226 assert( values != NULL && values[0] != NULL );
3228 for( i=0; values[i] != NULL; i++ ) {
3229 /* just count them */
3232 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3234 slen = strlen( syntax->ssyn_oid );
3235 mlen = strlen( mr->smr_oid );
3237 for( i=0; values[i] != NULL; i++ ) {
3238 struct berval *value = ber_bvdup( values[i] );
3239 ldap_pvt_str2upper( value->bv_val );
3241 HASH_Init( &HASHcontext );
3242 if( prefix != NULL && prefix->bv_len > 0 ) {
3243 HASH_Update( &HASHcontext,
3244 prefix->bv_val, prefix->bv_len );
3246 HASH_Update( &HASHcontext,
3247 syntax->ssyn_oid, slen );
3248 HASH_Update( &HASHcontext,
3249 mr->smr_oid, mlen );
3250 HASH_Update( &HASHcontext,
3251 value->bv_val, value->bv_len );
3252 HASH_Final( HASHdigest, &HASHcontext );
3254 ber_bvfree( value );
3256 keys[i] = ber_bvdup( &digest );
3261 return LDAP_SUCCESS;
3264 /* Index generation function */
3265 int caseIgnoreIA5Filter(
3270 struct berval *prefix,
3272 struct berval ***keysp )
3275 struct berval **keys;
3276 HASH_CONTEXT HASHcontext;
3277 unsigned char HASHdigest[HASH_BYTES];
3278 struct berval *value;
3279 struct berval digest;
3280 digest.bv_val = HASHdigest;
3281 digest.bv_len = sizeof(HASHdigest);
3283 slen = strlen( syntax->ssyn_oid );
3284 mlen = strlen( mr->smr_oid );
3286 value = ber_bvdup( (struct berval *) assertValue );
3287 ldap_pvt_str2upper( value->bv_val );
3289 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3291 HASH_Init( &HASHcontext );
3292 if( prefix != NULL && prefix->bv_len > 0 ) {
3293 HASH_Update( &HASHcontext,
3294 prefix->bv_val, prefix->bv_len );
3296 HASH_Update( &HASHcontext,
3297 syntax->ssyn_oid, slen );
3298 HASH_Update( &HASHcontext,
3299 mr->smr_oid, mlen );
3300 HASH_Update( &HASHcontext,
3301 value->bv_val, value->bv_len );
3302 HASH_Final( HASHdigest, &HASHcontext );
3304 keys[0] = ber_bvdup( &digest );
3307 ber_bvfree( value );
3311 return LDAP_SUCCESS;
3314 /* Substrings Index generation function */
3315 int caseIgnoreIA5SubstringsIndexer(
3320 struct berval *prefix,
3321 struct berval **values,
3322 struct berval ***keysp )
3326 struct berval **keys;
3327 HASH_CONTEXT HASHcontext;
3328 unsigned char HASHdigest[HASH_BYTES];
3329 struct berval digest;
3330 digest.bv_val = HASHdigest;
3331 digest.bv_len = sizeof(HASHdigest);
3333 /* we should have at least one value at this point */
3334 assert( values != NULL && values[0] != NULL );
3337 for( i=0; values[i] != NULL; i++ ) {
3338 /* count number of indices to generate */
3339 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3343 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3344 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3345 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3346 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3348 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3352 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3353 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3354 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3358 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3359 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3360 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3361 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3363 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3369 /* no keys to generate */
3371 return LDAP_SUCCESS;
3374 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3376 slen = strlen( syntax->ssyn_oid );
3377 mlen = strlen( mr->smr_oid );
3380 for( i=0; values[i] != NULL; i++ ) {
3382 struct berval *value;
3384 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3386 value = ber_bvdup( values[i] );
3387 ldap_pvt_str2upper( value->bv_val );
3389 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3390 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3392 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3393 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3395 for( j=0; j<max; j++ ) {
3396 HASH_Init( &HASHcontext );
3397 if( prefix != NULL && prefix->bv_len > 0 ) {
3398 HASH_Update( &HASHcontext,
3399 prefix->bv_val, prefix->bv_len );
3402 HASH_Update( &HASHcontext,
3403 &pre, sizeof( pre ) );
3404 HASH_Update( &HASHcontext,
3405 syntax->ssyn_oid, slen );
3406 HASH_Update( &HASHcontext,
3407 mr->smr_oid, mlen );
3408 HASH_Update( &HASHcontext,
3410 SLAP_INDEX_SUBSTR_MAXLEN );
3411 HASH_Final( HASHdigest, &HASHcontext );
3413 keys[nkeys++] = ber_bvdup( &digest );
3417 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3418 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3420 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3423 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3424 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3425 HASH_Init( &HASHcontext );
3426 if( prefix != NULL && prefix->bv_len > 0 ) {
3427 HASH_Update( &HASHcontext,
3428 prefix->bv_val, prefix->bv_len );
3430 HASH_Update( &HASHcontext,
3431 &pre, sizeof( pre ) );
3432 HASH_Update( &HASHcontext,
3433 syntax->ssyn_oid, slen );
3434 HASH_Update( &HASHcontext,
3435 mr->smr_oid, mlen );
3436 HASH_Update( &HASHcontext,
3438 HASH_Final( HASHdigest, &HASHcontext );
3440 keys[nkeys++] = ber_bvdup( &digest );
3443 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3444 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3445 HASH_Init( &HASHcontext );
3446 if( prefix != NULL && prefix->bv_len > 0 ) {
3447 HASH_Update( &HASHcontext,
3448 prefix->bv_val, prefix->bv_len );
3450 HASH_Update( &HASHcontext,
3451 &pre, sizeof( pre ) );
3452 HASH_Update( &HASHcontext,
3453 syntax->ssyn_oid, slen );
3454 HASH_Update( &HASHcontext,
3455 mr->smr_oid, mlen );
3456 HASH_Update( &HASHcontext,
3457 &value->bv_val[value->bv_len-j], j );
3458 HASH_Final( HASHdigest, &HASHcontext );
3460 keys[nkeys++] = ber_bvdup( &digest );
3465 ber_bvfree( value );
3476 return LDAP_SUCCESS;
3479 int caseIgnoreIA5SubstringsFilter(
3484 struct berval *prefix,
3486 struct berval ***keysp )
3488 SubstringsAssertion *sa = assertValue;
3490 ber_len_t nkeys = 0;
3491 size_t slen, mlen, klen;
3492 struct berval **keys;
3493 HASH_CONTEXT HASHcontext;
3494 unsigned char HASHdigest[HASH_BYTES];
3495 struct berval *value;
3496 struct berval digest;
3498 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3499 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3504 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3506 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3507 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3508 /* don't bother accounting for stepping */
3509 nkeys += sa->sa_any[i]->bv_len -
3510 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3515 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3516 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3523 return LDAP_SUCCESS;
3526 digest.bv_val = HASHdigest;
3527 digest.bv_len = sizeof(HASHdigest);
3529 slen = strlen( syntax->ssyn_oid );
3530 mlen = strlen( mr->smr_oid );
3532 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3535 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3536 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3538 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3539 value = ber_bvdup( sa->sa_initial );
3540 ldap_pvt_str2upper( value->bv_val );
3542 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3543 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3545 HASH_Init( &HASHcontext );
3546 if( prefix != NULL && prefix->bv_len > 0 ) {
3547 HASH_Update( &HASHcontext,
3548 prefix->bv_val, prefix->bv_len );
3550 HASH_Update( &HASHcontext,
3551 &pre, sizeof( pre ) );
3552 HASH_Update( &HASHcontext,
3553 syntax->ssyn_oid, slen );
3554 HASH_Update( &HASHcontext,
3555 mr->smr_oid, mlen );
3556 HASH_Update( &HASHcontext,
3557 value->bv_val, klen );
3558 HASH_Final( HASHdigest, &HASHcontext );
3560 ber_bvfree( value );
3561 keys[nkeys++] = ber_bvdup( &digest );
3564 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3566 pre = SLAP_INDEX_SUBSTR_PREFIX;
3567 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3569 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3570 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3574 value = ber_bvdup( sa->sa_any[i] );
3575 ldap_pvt_str2upper( value->bv_val );
3578 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3579 j += SLAP_INDEX_SUBSTR_STEP )
3581 HASH_Init( &HASHcontext );
3582 if( prefix != NULL && prefix->bv_len > 0 ) {
3583 HASH_Update( &HASHcontext,
3584 prefix->bv_val, prefix->bv_len );
3586 HASH_Update( &HASHcontext,
3587 &pre, sizeof( pre ) );
3588 HASH_Update( &HASHcontext,
3589 syntax->ssyn_oid, slen );
3590 HASH_Update( &HASHcontext,
3591 mr->smr_oid, mlen );
3592 HASH_Update( &HASHcontext,
3593 &value->bv_val[j], klen );
3594 HASH_Final( HASHdigest, &HASHcontext );
3596 keys[nkeys++] = ber_bvdup( &digest );
3599 ber_bvfree( value );
3603 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3604 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3606 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3607 value = ber_bvdup( sa->sa_final );
3608 ldap_pvt_str2upper( value->bv_val );
3610 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3611 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3613 HASH_Init( &HASHcontext );
3614 if( prefix != NULL && prefix->bv_len > 0 ) {
3615 HASH_Update( &HASHcontext,
3616 prefix->bv_val, prefix->bv_len );
3618 HASH_Update( &HASHcontext,
3619 &pre, sizeof( pre ) );
3620 HASH_Update( &HASHcontext,
3621 syntax->ssyn_oid, slen );
3622 HASH_Update( &HASHcontext,
3623 mr->smr_oid, mlen );
3624 HASH_Update( &HASHcontext,
3625 &value->bv_val[value->bv_len-klen], klen );
3626 HASH_Final( HASHdigest, &HASHcontext );
3628 ber_bvfree( value );
3629 keys[nkeys++] = ber_bvdup( &digest );
3640 return LDAP_SUCCESS;
3644 numericStringValidate(
3650 for(i=0; i < in->bv_len; i++) {
3651 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3652 return LDAP_INVALID_SYNTAX;
3656 return LDAP_SUCCESS;
3660 numericStringNormalize(
3663 struct berval **normalized )
3665 /* removal all spaces */
3666 struct berval *newval;
3669 newval = ch_malloc( sizeof( struct berval ) );
3670 newval->bv_val = ch_malloc( val->bv_len + 1 );
3676 if ( ASCII_SPACE( *p ) ) {
3677 /* Ignore whitespace */
3684 /* we should have copied no more then is in val */
3685 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3687 /* null terminate */
3690 newval->bv_len = q - newval->bv_val;
3691 *normalized = newval;
3693 return LDAP_SUCCESS;
3697 objectIdentifierFirstComponentMatch(
3702 struct berval *value,
3703 void *assertedValue )
3705 int rc = LDAP_SUCCESS;
3707 struct berval *asserted = (struct berval *) assertedValue;
3711 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3712 return LDAP_INVALID_SYNTAX;
3715 /* trim leading white space */
3716 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3720 /* grab next word */
3721 oid.bv_val = &value->bv_val[i];
3722 oid.bv_len = value->bv_len - i;
3723 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3728 /* insert attributeTypes, objectclass check here */
3729 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3730 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3733 char *stored = ch_malloc( oid.bv_len + 1 );
3734 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3735 stored[oid.bv_len] = '\0';
3737 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3738 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3739 MatchingRule *stored_mr = mr_find( stored );
3741 if( asserted_mr == NULL ) {
3742 rc = SLAPD_COMPARE_UNDEFINED;
3744 match = asserted_mr != stored_mr;
3747 } else if ( !strcmp( syntax->ssyn_oid,
3748 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3750 AttributeType *asserted_at = at_find( asserted->bv_val );
3751 AttributeType *stored_at = at_find( stored );
3753 if( asserted_at == NULL ) {
3754 rc = SLAPD_COMPARE_UNDEFINED;
3756 match = asserted_at != stored_at;
3759 } else if ( !strcmp( syntax->ssyn_oid,
3760 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3762 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3763 ObjectClass *stored_oc = oc_find( stored );
3765 if( asserted_oc == NULL ) {
3766 rc = SLAPD_COMPARE_UNDEFINED;
3768 match = asserted_oc != stored_oc;
3776 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3777 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3778 match, value->bv_val, asserted->bv_val ));
3780 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3781 "%d\n\t\"%s\"\n\t\"%s\"\n",
3782 match, value->bv_val, asserted->bv_val );
3786 if( rc == LDAP_SUCCESS ) *matchp = match;
3796 struct berval *value,
3797 void *assertedValue )
3799 long lValue, lAssertedValue;
3801 /* safe to assume integers are NUL terminated? */
3802 lValue = strtoul(value->bv_val, NULL, 10);
3803 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3804 return LDAP_CONSTRAINT_VIOLATION;
3806 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3807 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3808 return LDAP_CONSTRAINT_VIOLATION;
3810 *matchp = (lValue & lAssertedValue);
3811 return LDAP_SUCCESS;
3820 struct berval *value,
3821 void *assertedValue )
3823 long lValue, lAssertedValue;
3825 /* safe to assume integers are NUL terminated? */
3826 lValue = strtoul(value->bv_val, NULL, 10);
3827 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3828 return LDAP_CONSTRAINT_VIOLATION;
3830 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3831 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3832 return LDAP_CONSTRAINT_VIOLATION;
3834 *matchp = (lValue | lAssertedValue);
3835 return LDAP_SUCCESS;
3839 #include <openssl/x509.h>
3840 #include <openssl/err.h>
3841 char digit[] = "0123456789";
3844 * Next function returns a string representation of a ASN1_INTEGER.
3845 * It works for unlimited lengths.
3848 static struct berval *
3849 asn1_integer2str(ASN1_INTEGER *a)
3854 /* We work backwards, make it fill from the end of buf */
3855 p = buf + sizeof(buf) - 1;
3858 if ( a == NULL || a->length == 0 ) {
3866 /* We want to preserve the original */
3867 copy = ch_malloc(n*sizeof(unsigned int));
3868 for (i = 0; i<n; i++) {
3869 copy[i] = a->data[i];
3873 * base indicates the index of the most significant
3874 * byte that might be nonzero. When it goes off the
3875 * end, we now there is nothing left to do.
3881 for (i = base; i<n; i++ ) {
3882 copy[i] += carry*256;
3883 carry = copy[i] % 10;
3888 * Way too large, we need to leave
3889 * room for sign if negative
3894 *--p = digit[carry];
3895 if (copy[base] == 0)
3901 if ( a->type == V_ASN1_NEG_INTEGER ) {
3905 return ber_bvstrdup(p);
3908 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3909 static struct berval *
3910 dn_openssl2ldap(X509_NAME *name)
3912 char issuer_dn[1024];
3915 bio = BIO_new(BIO_s_mem());
3918 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3919 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3920 ERR_error_string(ERR_get_error(),NULL)));
3922 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3923 "error creating BIO: %s\n",
3924 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3928 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3930 BIO_gets(bio, issuer_dn, 1024);
3933 return ber_bvstrdup(issuer_dn);
3937 * Given a certificate in DER format, extract the corresponding
3938 * assertion value for certificateExactMatch
3941 certificateExactConvert(
3943 struct berval ** out )
3946 unsigned char *p = in->bv_val;
3947 struct berval *serial;
3948 struct berval *issuer_dn;
3949 struct berval *bv_tmp;
3951 xcert = d2i_X509(NULL, &p, in->bv_len);
3954 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3955 "certificateExactConvert: error parsing cert: %s\n",
3956 ERR_error_string(ERR_get_error(),NULL)));
3958 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3959 "error parsing cert: %s\n",
3960 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3962 return LDAP_INVALID_SYNTAX;
3965 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3968 return LDAP_INVALID_SYNTAX;
3970 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3974 return LDAP_INVALID_SYNTAX;
3976 /* Actually, dn_openssl2ldap returns in a normalized format, but
3977 it is different from our normalized format */
3979 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3983 return LDAP_INVALID_SYNTAX;
3989 *out = ch_malloc(sizeof(struct berval));
3990 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3991 (*out)->bv_val = ch_malloc((*out)->bv_len);
3993 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3994 p += serial->bv_len;
3995 AC_MEMCPY(p, " $ ", 3);
3997 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3998 p += issuer_dn->bv_len;
4002 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4003 "certificateExactConvert: \n %s\n",
4006 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
4008 (*out)->bv_val, NULL, NULL );
4012 ber_bvfree(issuer_dn);
4014 return LDAP_SUCCESS;
4018 serial_and_issuer_parse(
4019 struct berval *assertion,
4020 struct berval **serial,
4021 struct berval **issuer_dn
4029 begin = assertion->bv_val;
4030 end = assertion->bv_val+assertion->bv_len-1;
4031 for (p=begin; p<=end && *p != '$'; p++)
4034 return LDAP_INVALID_SYNTAX;
4036 /* p now points at the $ sign, now use begin and end to delimit the
4038 while (ASCII_SPACE(*begin))
4041 while (ASCII_SPACE(*end))
4044 q = ch_malloc( (end-begin+1)+1 );
4045 AC_MEMCPY( q, begin, end-begin+1 );
4046 q[end-begin+1] = '\0';
4047 *serial = ber_bvstr(q);
4049 /* now extract the issuer, remember p was at the dollar sign */
4051 end = assertion->bv_val+assertion->bv_len-1;
4052 while (ASCII_SPACE(*begin))
4054 /* should we trim spaces at the end too? is it safe always? */
4056 q = ch_malloc( (end-begin+1)+1 );
4057 AC_MEMCPY( q, begin, end-begin+1 );
4058 q[end-begin+1] = '\0';
4059 *issuer_dn = ber_bvstr(dn_normalize(q));
4061 return LDAP_SUCCESS;
4065 certificateExactMatch(
4070 struct berval *value,
4071 void *assertedValue )
4074 unsigned char *p = value->bv_val;
4075 struct berval *serial;
4076 struct berval *issuer_dn;
4077 struct berval *asserted_serial;
4078 struct berval *asserted_issuer_dn;
4081 xcert = d2i_X509(NULL, &p, value->bv_len);
4084 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4085 "certificateExactMatch: error parsing cert: %s\n",
4086 ERR_error_string(ERR_get_error(),NULL)));
4088 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
4089 "error parsing cert: %s\n",
4090 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4092 return LDAP_INVALID_SYNTAX;
4095 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4096 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4100 serial_and_issuer_parse(assertedValue,
4102 &asserted_issuer_dn);
4107 slap_schema.si_syn_integer,
4108 slap_schema.si_mr_integerMatch,
4111 if ( ret == LDAP_SUCCESS ) {
4112 if ( *matchp == 0 ) {
4113 /* We need to normalize everything for dnMatch */
4117 slap_schema.si_syn_distinguishedName,
4118 slap_schema.si_mr_distinguishedNameMatch,
4120 asserted_issuer_dn);
4125 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4126 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
4127 *matchp, serial->bv_val, issuer_dn->bv_val,
4128 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
4130 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
4131 "%d\n\t\"%s $ %s\"\n",
4132 *matchp, serial->bv_val, issuer_dn->bv_val );
4133 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
4134 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
4139 ber_bvfree(issuer_dn);
4140 ber_bvfree(asserted_serial);
4141 ber_bvfree(asserted_issuer_dn);
4147 * Index generation function
4148 * We just index the serials, in most scenarios the issuer DN is one of
4149 * a very small set of values.
4151 int certificateExactIndexer(
4156 struct berval *prefix,
4157 struct berval **values,
4158 struct berval ***keysp )
4161 struct berval **keys;
4164 struct berval * serial;
4166 /* we should have at least one value at this point */
4167 assert( values != NULL && values[0] != NULL );
4169 for( i=0; values[i] != NULL; i++ ) {
4170 /* empty -- just count them */
4173 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
4175 for( i=0; values[i] != NULL; i++ ) {
4176 p = values[i]->bv_val;
4177 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
4180 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4181 "certificateExactIndexer: error parsing cert: %s\n",
4182 ERR_error_string(ERR_get_error(),NULL)));
4184 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4185 "error parsing cert: %s\n",
4186 ERR_error_string(ERR_get_error(),NULL),
4189 /* Do we leak keys on error? */
4190 return LDAP_INVALID_SYNTAX;
4193 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4195 integerNormalize( slap_schema.si_syn_integer,
4200 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4201 "certificateExactIndexer: returning: %s\n",
4204 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4213 return LDAP_SUCCESS;
4216 /* Index generation function */
4217 /* We think this is always called with a value in matching rule syntax */
4218 int certificateExactFilter(
4223 struct berval *prefix,
4225 struct berval ***keysp )
4227 struct berval **keys;
4228 struct berval *asserted_serial;
4229 struct berval *asserted_issuer_dn;
4231 serial_and_issuer_parse(assertValue,
4233 &asserted_issuer_dn);
4235 keys = ch_malloc( sizeof( struct berval * ) * 2 );
4236 integerNormalize( syntax, asserted_serial, &keys[0] );
4240 ber_bvfree(asserted_serial);
4241 ber_bvfree(asserted_issuer_dn);
4242 return LDAP_SUCCESS;
4247 check_time_syntax (struct berval *val,
4251 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
4252 static int mdays[2][12] = {
4253 /* non-leap years */
4254 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
4256 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
4259 int part, c, tzoffset, leapyear = 0 ;
4261 if( val->bv_len == 0 ) {
4262 return LDAP_INVALID_SYNTAX;
4265 p = (char *)val->bv_val;
4266 e = p + val->bv_len;
4268 /* Ignore initial whitespace */
4269 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4273 if (e - p < 13 - (2 * start)) {
4274 return LDAP_INVALID_SYNTAX;
4277 for (part = 0; part < 9; part++) {
4281 for (part = start; part < 7; part++) {
4283 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
4290 return LDAP_INVALID_SYNTAX;
4292 if (c < 0 || c > 9) {
4293 return LDAP_INVALID_SYNTAX;
4299 return LDAP_INVALID_SYNTAX;
4301 if (c < 0 || c > 9) {
4302 return LDAP_INVALID_SYNTAX;
4307 if (part == 2 || part == 3) {
4310 if (parts[part] < 0) {
4311 return LDAP_INVALID_SYNTAX;
4313 if (parts[part] > ceiling[part]) {
4314 return LDAP_INVALID_SYNTAX;
4318 /* leapyear check for the Gregorian calendar (year>1581) */
4319 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
4320 ((parts[0] % 4 == 0) && (parts[1] == 0)))
4325 if (parts[3] > mdays[leapyear][parts[2]]) {
4326 return LDAP_INVALID_SYNTAX;
4331 tzoffset = 0; /* UTC */
4332 } else if (c != '+' && c != '-') {
4333 return LDAP_INVALID_SYNTAX;
4337 } else /* c == '+' */ {
4342 return LDAP_INVALID_SYNTAX;
4345 for (part = 7; part < 9; part++) {
4347 if (c < 0 || c > 9) {
4348 return LDAP_INVALID_SYNTAX;
4353 if (c < 0 || c > 9) {
4354 return LDAP_INVALID_SYNTAX;
4358 if (parts[part] < 0 || parts[part] > ceiling[part]) {
4359 return LDAP_INVALID_SYNTAX;
4364 /* Ignore trailing whitespace */
4365 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4369 return LDAP_INVALID_SYNTAX;
4372 switch ( tzoffset ) {
4373 case -1: /* negativ offset to UTC, ie west of Greenwich */
4374 parts[4] += parts[7];
4375 parts[5] += parts[8];
4376 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
4380 c = mdays[leapyear][parts[2]];
4382 if (parts[part] > c) {
4383 parts[part] -= c + 1;
4388 case 1: /* positive offset to UTC, ie east of Greenwich */
4389 parts[4] -= parts[7];
4390 parts[5] -= parts[8];
4391 for (part = 6; --part > 0; ) {
4395 /* first arg to % needs to be non negativ */
4396 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
4398 if (parts[part] < 0) {
4399 parts[part] += c + 1;
4404 case 0: /* already UTC */
4408 return LDAP_SUCCESS;
4415 struct berval **normalized )
4420 rc = check_time_syntax(val, 1, parts);
4421 if (rc != LDAP_SUCCESS) {
4426 out = ch_malloc( sizeof(struct berval) );
4428 return LBER_ERROR_MEMORY;
4431 out->bv_val = ch_malloc( 14 );
4432 if ( out->bv_val == NULL ) {
4434 return LBER_ERROR_MEMORY;
4437 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02dZ",
4438 parts[1], parts[2] + 1, parts[3] + 1,
4439 parts[4], parts[5], parts[6] );
4443 return LDAP_SUCCESS;
4453 return check_time_syntax(in, 1, parts);
4457 generalizedTimeValidate(
4463 return check_time_syntax(in, 0, parts);
4467 generalizedTimeNormalize(
4470 struct berval **normalized )
4475 rc = check_time_syntax(val, 0, parts);
4476 if (rc != LDAP_SUCCESS) {
4481 out = ch_malloc( sizeof(struct berval) );
4483 return LBER_ERROR_MEMORY;
4486 out->bv_val = ch_malloc( 16 );
4487 if ( out->bv_val == NULL ) {
4489 return LBER_ERROR_MEMORY;
4492 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4493 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4494 parts[4], parts[5], parts[6] );
4498 return LDAP_SUCCESS;
4502 nisNetgroupTripleValidate(
4504 struct berval *val )
4509 if ( val->bv_len == 0 ) {
4510 return LDAP_INVALID_SYNTAX;
4513 p = (char *)val->bv_val;
4514 e = p + val->bv_len;
4516 if ( *p != '(' /*')'*/ ) {
4517 return LDAP_INVALID_SYNTAX;
4520 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4524 return LDAP_INVALID_SYNTAX;
4527 } else if ( !ATTR_CHAR( *p ) ) {
4528 return LDAP_INVALID_SYNTAX;
4532 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4533 return LDAP_INVALID_SYNTAX;
4539 return LDAP_INVALID_SYNTAX;
4542 return LDAP_SUCCESS;
4546 bootParameterValidate(
4548 struct berval *val )
4552 if ( val->bv_len == 0 ) {
4553 return LDAP_INVALID_SYNTAX;
4556 p = (char *)val->bv_val;
4557 e = p + val->bv_len;
4560 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4561 if ( !ATTR_CHAR( *p ) ) {
4562 return LDAP_INVALID_SYNTAX;
4567 return LDAP_INVALID_SYNTAX;
4571 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4572 if ( !ATTR_CHAR( *p ) ) {
4573 return LDAP_INVALID_SYNTAX;
4578 return LDAP_INVALID_SYNTAX;
4582 for ( p++; p < e; p++ ) {
4583 if ( !ATTR_CHAR( *p ) ) {
4584 return LDAP_INVALID_SYNTAX;
4588 return LDAP_SUCCESS;
4591 struct syntax_defs_rec {
4594 slap_syntax_validate_func *sd_validate;
4595 slap_syntax_transform_func *sd_normalize;
4596 slap_syntax_transform_func *sd_pretty;
4597 #ifdef SLAPD_BINARY_CONVERSION
4598 slap_syntax_transform_func *sd_ber2str;
4599 slap_syntax_transform_func *sd_str2ber;
4603 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4604 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4606 struct syntax_defs_rec syntax_defs[] = {
4607 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4608 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4609 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4610 0, NULL, NULL, NULL},
4611 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4612 0, NULL, NULL, NULL},
4613 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4614 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4615 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4616 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4617 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4618 0, bitStringValidate, bitStringNormalize, NULL },
4619 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4620 0, booleanValidate, NULL, NULL},
4621 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4622 X_BINARY X_NOT_H_R ")",
4623 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4624 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4625 X_BINARY X_NOT_H_R ")",
4626 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4627 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4628 X_BINARY X_NOT_H_R ")",
4629 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4630 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4631 0, countryStringValidate, IA5StringNormalize, NULL},
4632 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4633 0, dnValidate, dnNormalize, dnPretty},
4634 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4635 0, NULL, NULL, NULL},
4636 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4637 0, NULL, NULL, NULL},
4638 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4639 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4640 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4641 0, NULL, NULL, NULL},
4642 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4643 0, NULL, NULL, NULL},
4644 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4645 0, NULL, NULL, NULL},
4646 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4647 0, NULL, NULL, NULL},
4648 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4649 0, NULL, NULL, NULL},
4650 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4651 0, printablesStringValidate, IA5StringNormalize, NULL},
4652 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4653 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4654 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4655 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4656 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4657 0, NULL, NULL, NULL},
4658 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4659 0, IA5StringValidate, IA5StringNormalize, NULL},
4660 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4661 0, integerValidate, integerNormalize, NULL},
4662 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4663 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4664 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4665 0, NULL, NULL, NULL},
4666 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4667 0, NULL, NULL, NULL},
4668 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4669 0, NULL, NULL, NULL},
4670 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4671 0, NULL, NULL, NULL},
4672 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4673 0, NULL, NULL, NULL},
4674 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4675 0, nameUIDValidate, nameUIDNormalize, NULL},
4676 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4677 0, NULL, NULL, NULL},
4678 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4679 0, numericStringValidate, numericStringNormalize, NULL},
4680 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4681 0, NULL, NULL, NULL},
4682 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4683 0, oidValidate, NULL, NULL},
4684 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4685 0, IA5StringValidate, IA5StringNormalize, NULL},
4686 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4687 0, blobValidate, NULL, NULL},
4688 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4689 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4690 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4691 0, NULL, NULL, NULL},
4692 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4693 0, NULL, NULL, NULL},
4694 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4695 0, printableStringValidate, IA5StringNormalize, NULL},
4696 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4697 X_BINARY X_NOT_H_R ")",
4698 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4699 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4700 0, printableStringValidate, IA5StringNormalize, NULL},
4701 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4702 0, NULL, NULL, NULL},
4703 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4704 0, printablesStringValidate, IA5StringNormalize, NULL},
4705 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4706 0, utcTimeValidate, utcTimeNormalize, NULL},
4707 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4708 0, NULL, NULL, NULL},
4709 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4710 0, NULL, NULL, NULL},
4711 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4712 0, NULL, NULL, NULL},
4713 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4714 0, NULL, NULL, NULL},
4715 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4716 0, NULL, NULL, NULL},
4718 /* RFC 2307 NIS Syntaxes */
4719 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4720 0, nisNetgroupTripleValidate, NULL, NULL},
4721 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4722 0, bootParameterValidate, NULL, NULL},
4726 /* These OIDs are not published yet, but will be in the next
4727 * I-D for PKIX LDAPv3 schema as have been advanced by David
4728 * Chadwick in private mail.
4730 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4731 0, NULL, NULL, NULL},
4734 /* OpenLDAP Experimental Syntaxes */
4735 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4737 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4740 /* needs updating */
4741 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4742 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4744 /* OpenLDAP Void Syntax */
4745 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4746 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4747 {NULL, 0, NULL, NULL, NULL}
4750 struct mrule_defs_rec {
4752 slap_mask_t mrd_usage;
4753 slap_mr_convert_func * mrd_convert;
4754 slap_mr_normalize_func * mrd_normalize;
4755 slap_mr_match_func * mrd_match;
4756 slap_mr_indexer_func * mrd_indexer;
4757 slap_mr_filter_func * mrd_filter;
4759 char * mrd_associated;
4763 * Other matching rules in X.520 that we do not use (yet):
4765 * 2.5.13.9 numericStringOrderingMatch
4766 * 2.5.13.15 integerOrderingMatch
4767 * 2.5.13.18 octetStringOrderingMatch
4768 * 2.5.13.19 octetStringSubstringsMatch
4769 * 2.5.13.25 uTCTimeMatch
4770 * 2.5.13.26 uTCTimeOrderingMatch
4771 * 2.5.13.31 directoryStringFirstComponentMatch
4772 * 2.5.13.32 wordMatch
4773 * 2.5.13.33 keywordMatch
4774 * 2.5.13.35 certificateMatch
4775 * 2.5.13.36 certificatePairExactMatch
4776 * 2.5.13.37 certificatePairMatch
4777 * 2.5.13.38 certificateListExactMatch
4778 * 2.5.13.39 certificateListMatch
4779 * 2.5.13.40 algorithmIdentifierMatch
4780 * 2.5.13.41 storedPrefixMatch
4781 * 2.5.13.42 attributeCertificateMatch
4782 * 2.5.13.43 readerAndKeyIDMatch
4783 * 2.5.13.44 attributeIntegrityMatch
4786 struct mrule_defs_rec mrule_defs[] = {
4788 * EQUALITY matching rules must be listed after associated APPROX
4789 * matching rules. So, we list all APPROX matching rules first.
4791 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4792 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4793 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4795 directoryStringApproxMatch,
4796 directoryStringApproxIndexer,
4797 directoryStringApproxFilter,
4800 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4801 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4802 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4804 IA5StringApproxMatch,
4805 IA5StringApproxIndexer,
4806 IA5StringApproxFilter,
4810 * Other matching rules
4813 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4814 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4815 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4817 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4820 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4821 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4822 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4824 dnMatch, dnIndexer, dnFilter,
4827 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4828 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4829 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4831 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4832 directoryStringApproxMatchOID },
4834 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4835 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4838 caseIgnoreOrderingMatch, NULL, NULL,
4841 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4842 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4843 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4845 caseExactIgnoreSubstringsMatch,
4846 caseExactIgnoreSubstringsIndexer,
4847 caseExactIgnoreSubstringsFilter,
4850 {"( 2.5.13.5 NAME 'caseExactMatch' "
4851 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4852 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4854 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4855 directoryStringApproxMatchOID },
4857 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4858 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4861 caseExactOrderingMatch, NULL, NULL,
4864 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4865 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4866 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4868 caseExactIgnoreSubstringsMatch,
4869 caseExactIgnoreSubstringsIndexer,
4870 caseExactIgnoreSubstringsFilter,
4873 {"( 2.5.13.8 NAME 'numericStringMatch' "
4874 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4875 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4878 caseIgnoreIA5Indexer,
4879 caseIgnoreIA5Filter,
4882 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4883 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4884 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4886 caseIgnoreIA5SubstringsMatch,
4887 caseIgnoreIA5SubstringsIndexer,
4888 caseIgnoreIA5SubstringsFilter,
4891 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4892 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4893 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4895 caseIgnoreListMatch, NULL, NULL,
4898 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4899 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4900 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4902 caseIgnoreListSubstringsMatch, NULL, NULL,
4905 {"( 2.5.13.13 NAME 'booleanMatch' "
4906 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4907 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4909 booleanMatch, NULL, NULL,
4912 {"( 2.5.13.14 NAME 'integerMatch' "
4913 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4914 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4916 integerMatch, integerIndexer, integerFilter,
4919 {"( 2.5.13.16 NAME 'bitStringMatch' "
4920 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4921 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4923 bitStringMatch, bitStringIndexer, bitStringFilter,
4926 {"( 2.5.13.17 NAME 'octetStringMatch' "
4927 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4928 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4930 octetStringMatch, octetStringIndexer, octetStringFilter,
4933 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4934 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4935 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4937 telephoneNumberMatch,
4938 telephoneNumberIndexer,
4939 telephoneNumberFilter,
4942 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4943 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4944 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4946 telephoneNumberSubstringsMatch,
4947 telephoneNumberSubstringsIndexer,
4948 telephoneNumberSubstringsFilter,
4951 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4952 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4953 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4958 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4959 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4960 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4962 uniqueMemberMatch, NULL, NULL,
4965 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4966 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4967 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4969 protocolInformationMatch, NULL, NULL,
4972 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4973 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4974 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4976 generalizedTimeMatch, NULL, NULL,
4979 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4980 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4983 generalizedTimeOrderingMatch, NULL, NULL,
4986 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4987 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4988 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4990 integerFirstComponentMatch, NULL, NULL,
4993 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4994 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4995 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4997 objectIdentifierFirstComponentMatch, NULL, NULL,
5001 {"( 2.5.13.34 NAME 'certificateExactMatch' "
5002 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
5003 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5004 certificateExactConvert, NULL,
5005 certificateExactMatch,
5006 certificateExactIndexer, certificateExactFilter,
5010 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
5011 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5012 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5014 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
5015 IA5StringApproxMatchOID },
5017 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
5018 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5019 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
5021 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
5022 IA5StringApproxMatchOID },
5024 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
5025 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5028 caseIgnoreIA5SubstringsMatch,
5029 caseIgnoreIA5SubstringsIndexer,
5030 caseIgnoreIA5SubstringsFilter,
5033 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
5034 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5037 caseExactIA5SubstringsMatch,
5038 caseExactIA5SubstringsIndexer,
5039 caseExactIA5SubstringsFilter,
5042 /* needs updating */
5043 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
5044 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
5047 authPasswordMatch, NULL, NULL,
5050 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
5051 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
5054 OpenLDAPaciMatch, NULL, NULL,
5057 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
5058 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5061 integerBitAndMatch, NULL, NULL,
5064 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
5065 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5068 integerBitOrMatch, NULL, NULL,
5071 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
5080 /* we should only be called once (from main) */
5081 assert( schema_init_done == 0 );
5083 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
5084 res = register_syntax( syntax_defs[i].sd_desc,
5085 syntax_defs[i].sd_flags,
5086 syntax_defs[i].sd_validate,
5087 syntax_defs[i].sd_normalize,
5088 syntax_defs[i].sd_pretty
5089 #ifdef SLAPD_BINARY_CONVERSION
5091 syntax_defs[i].sd_ber2str,
5092 syntax_defs[i].sd_str2ber
5097 fprintf( stderr, "schema_init: Error registering syntax %s\n",
5098 syntax_defs[i].sd_desc );
5103 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
5104 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
5106 "schema_init: Ingoring unusable matching rule %s\n",
5107 mrule_defs[i].mrd_desc );
5111 res = register_matching_rule(
5112 mrule_defs[i].mrd_desc,
5113 mrule_defs[i].mrd_usage,
5114 mrule_defs[i].mrd_convert,
5115 mrule_defs[i].mrd_normalize,
5116 mrule_defs[i].mrd_match,
5117 mrule_defs[i].mrd_indexer,
5118 mrule_defs[i].mrd_filter,
5119 mrule_defs[i].mrd_associated );
5123 "schema_init: Error registering matching rule %s\n",
5124 mrule_defs[i].mrd_desc );
5128 schema_init_done = 1;
5129 return LDAP_SUCCESS;
5133 schema_destroy( void )