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 #ifndef USE_LDAP_DN_PARSING
36 # define dnPretty NULL
38 # define SLAP_LDAPDN_PRETTY 0x1
39 #endif /* !USE_LDAP_DN_PARSING */
41 /* recycled matching routines */
42 #define bitStringMatch octetStringMatch
43 #define numericStringMatch caseIgnoreIA5Match
44 #define objectIdentifierMatch caseIgnoreIA5Match
45 #define telephoneNumberMatch caseIgnoreIA5Match
46 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
47 #define generalizedTimeMatch caseIgnoreIA5Match
48 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
49 #define uniqueMemberMatch dnMatch
51 /* approx matching rules */
52 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
53 #define directoryStringApproxMatch approxMatch
54 #define directoryStringApproxIndexer approxIndexer
55 #define directoryStringApproxFilter approxFilter
56 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
57 #define IA5StringApproxMatch approxMatch
58 #define IA5StringApproxIndexer approxIndexer
59 #define IA5StringApproxFilter approxFilter
61 /* orderring matching rules */
62 #define caseIgnoreOrderingMatch caseIgnoreMatch
63 #define caseExactOrderingMatch caseExactMatch
65 /* unimplemented matching routines */
66 #define caseIgnoreListMatch NULL
67 #define caseIgnoreListSubstringsMatch NULL
68 #define protocolInformationMatch NULL
69 #define integerFirstComponentMatch NULL
71 #define OpenLDAPaciMatch NULL
72 #define authPasswordMatch NULL
74 /* recycled indexing/filtering routines */
75 #define dnIndexer caseExactIgnoreIndexer
76 #define dnFilter caseExactIgnoreFilter
77 #define bitStringFilter octetStringFilter
78 #define bitStringIndexer octetStringIndexer
80 #define telephoneNumberIndexer caseIgnoreIA5Indexer
81 #define telephoneNumberFilter caseIgnoreIA5Filter
82 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
83 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
85 /* must match OIDs below */
86 #define caseExactMatchOID "2.5.13.5"
87 #define caseExactSubstringsMatchOID "2.5.13.7"
89 static char *strcasechr( const char *str, int c )
91 char *lower = strchr( str, TOLOWER(c) );
92 char *upper = strchr( str, TOUPPER(c) );
94 if( lower && upper ) {
95 return lower < upper ? lower : upper;
109 struct berval *value,
110 void *assertedValue )
112 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
115 match = memcmp( value->bv_val,
116 ((struct berval *) assertedValue)->bv_val,
124 /* Index generation function */
125 int octetStringIndexer(
130 struct berval *prefix,
131 struct berval **values,
132 struct berval ***keysp )
136 struct berval **keys;
137 HASH_CONTEXT HASHcontext;
138 unsigned char HASHdigest[HASH_BYTES];
139 struct berval digest;
140 digest.bv_val = HASHdigest;
141 digest.bv_len = sizeof(HASHdigest);
143 for( i=0; values[i] != NULL; i++ ) {
144 /* just count them */
147 /* we should have at least one value at this point */
150 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
152 slen = strlen( syntax->ssyn_oid );
153 mlen = strlen( mr->smr_oid );
155 for( i=0; values[i] != NULL; i++ ) {
156 HASH_Init( &HASHcontext );
157 if( prefix != NULL && prefix->bv_len > 0 ) {
158 HASH_Update( &HASHcontext,
159 prefix->bv_val, prefix->bv_len );
161 HASH_Update( &HASHcontext,
162 syntax->ssyn_oid, slen );
163 HASH_Update( &HASHcontext,
165 HASH_Update( &HASHcontext,
166 values[i]->bv_val, values[i]->bv_len );
167 HASH_Final( HASHdigest, &HASHcontext );
169 keys[i] = ber_bvdup( &digest );
179 /* Index generation function */
180 int octetStringFilter(
185 struct berval *prefix,
187 struct berval ***keysp )
190 struct berval **keys;
191 HASH_CONTEXT HASHcontext;
192 unsigned char HASHdigest[HASH_BYTES];
193 struct berval *value = (struct berval *) assertValue;
194 struct berval digest;
195 digest.bv_val = HASHdigest;
196 digest.bv_len = sizeof(HASHdigest);
198 slen = strlen( syntax->ssyn_oid );
199 mlen = strlen( mr->smr_oid );
201 keys = ch_malloc( sizeof( struct berval * ) * 2 );
203 HASH_Init( &HASHcontext );
204 if( prefix != NULL && prefix->bv_len > 0 ) {
205 HASH_Update( &HASHcontext,
206 prefix->bv_val, prefix->bv_len );
208 HASH_Update( &HASHcontext,
209 syntax->ssyn_oid, slen );
210 HASH_Update( &HASHcontext,
212 HASH_Update( &HASHcontext,
213 value->bv_val, value->bv_len );
214 HASH_Final( HASHdigest, &HASHcontext );
216 keys[0] = ber_bvdup( &digest );
224 #ifdef USE_LDAP_DN_PARSING
227 * The DN syntax-related functions take advantage of the dn representation
228 * handling functions ldap_str2dn/ldap_dn2str. The latter are not schema-
229 * aware, so the attributes and their values need be validated (and possibly
230 * normalized). In the current implementation the required validation/nor-
231 * malization/"pretty"ing are done on newly created DN structural represen-
232 * tations; however the idea is to move towards DN handling in structural
233 * representation instead of the current string representation. To this
234 * purpose, we need to do only the required operations and keep track of
235 * what has been done to minimize their impact on performances.
237 * Developers are strongly encouraged to use this feature, to speed-up
241 #define AVA_PRIVATE( ava ) ( ( AttributeDescription * )(ava)->la_private )
244 * In-place, schema-aware validation of the
245 * structural representation of a distinguished name.
248 LDAPDN_validate( LDAPDN *dn )
255 for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
256 LDAPRDN *rdn = dn[ iRDN ][ 0 ];
261 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
262 LDAPAVA *ava = rdn[ iAVA ][ 0 ];
263 AttributeDescription *ad;
264 slap_syntax_validate_func *validate = NULL;
268 if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
269 const char *text = NULL;
271 rc = slap_bv2ad( ava->la_attr, &ad, &text );
272 if ( rc != LDAP_SUCCESS ) {
273 return LDAP_INVALID_SYNTAX;
276 ava->la_private = ( void * )ad;
280 * Replace attr oid/name with the canonical name
282 ber_bvfree( ava->la_attr );
283 ava->la_attr = ber_bvdup( &ad->ad_cname );
285 validate = ad->ad_type->sat_syntax->ssyn_validate;
289 * validate value by validate function
291 rc = ( *validate )( ad->ad_type->sat_syntax,
294 if ( rc != LDAP_SUCCESS ) {
295 return LDAP_INVALID_SYNTAX;
305 * dn validate routine
317 if ( in->bv_len == 0 ) {
318 return( LDAP_SUCCESS );
321 rc = ldap_str2dn( in->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
324 * Schema-aware validate
326 if ( rc == LDAP_SUCCESS ) {
327 rc = LDAPDN_validate( dn );
330 ldapava_free_dn( dn );
332 if ( rc != LDAP_SUCCESS ) {
333 return( LDAP_INVALID_SYNTAX );
336 return( LDAP_SUCCESS );
340 * AVA sorting inside a RDN
342 * rule: sort attributeTypes in alphabetical order; in case of multiple
343 * occurrences of the same attributeType, sort values in byte order
344 * (use memcmp, which implies alphabetical order in case of IA5 value;
345 * this should guarantee the repeatability of the operation).
347 * uses a linear search; should be fine since the number of AVAs in
348 * a RDN should be limited.
351 AVA_Sort( LDAPRDN *rdn, int iAVA )
354 LDAPAVA *ava_in = rdn[ iAVA ][ 0 ];
359 for ( i = 0; i < iAVA; i++ ) {
360 LDAPAVA *ava = rdn[ i ][ 0 ];
365 a = strcmp( ava_in->la_attr->bv_val, ava->la_attr->bv_val );
374 d = ava_in->la_value->bv_len - ava->la_value->bv_len;
376 v = memcmp( ava_in->la_value->bv_val,
377 ava->la_value->bv_val,
378 d <= 0 ? ava_in->la_value->bv_len
379 : ava->la_value->bv_len );
381 if ( v == 0 && d != 0 ) {
400 a = strcmp( ava_in->la_value->bv_val,
401 ava->la_value->bv_val );
407 for ( j = iAVA; j > i; j-- ) {
408 rdn[ j ][ 0 ] = rdn[ j - 1 ][ 0 ];
410 rdn[ i ][ 0 ] = ava_in;
417 * In-place, schema-aware normalization / "pretty"ing of the
418 * structural representation of a distinguished name.
421 LDAPDN_rewrite( LDAPDN *dn, unsigned flags )
428 for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
429 LDAPRDN *rdn = dn[ iRDN ][ 0 ];
434 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
435 LDAPAVA *ava = rdn[ iAVA ][ 0 ];
436 AttributeDescription *ad;
437 slap_syntax_transform_func *transf = NULL;
439 struct berval *bv = NULL;
443 if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
444 const char *text = NULL;
446 rc = slap_bv2ad( ava->la_attr, &ad, &text );
447 if ( rc != LDAP_SUCCESS ) {
448 return LDAP_INVALID_SYNTAX;
451 ava->la_private = ( void * )ad;
455 * Replace attr oid/name with the canonical name
457 ber_bvfree( ava->la_attr );
458 ava->la_attr = ber_bvdup( &ad->ad_cname );
460 if( flags & SLAP_LDAPDN_PRETTY ) {
461 transf = ad->ad_type->sat_syntax->ssyn_pretty;
464 transf = ad->ad_type->sat_syntax->ssyn_normalize;
465 mr = ad->ad_type->sat_equality;
470 * transform value by normalize/pretty function
472 rc = ( *transf )( ad->ad_type->sat_syntax,
473 ava->la_value, &bv );
475 if ( rc != LDAP_SUCCESS ) {
476 return LDAP_INVALID_SYNTAX;
480 if( mr && ( mr->smr_usage & SLAP_MR_DN_FOLD ) ) {
481 struct berval *s = bv;
483 bv = ber_bvstr( UTF8normalize( bv ? bv : ava->la_value,
490 ber_bvfree( ava->la_value );
494 AVA_Sort( rdn, iAVA );
502 * dn normalize routine
508 struct berval **normalized )
510 struct berval *out = NULL;
512 Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 );
515 assert( normalized );
517 if ( val->bv_len != 0 ) {
523 * Go to structural representation
525 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
526 if ( rc != LDAP_SUCCESS ) {
527 return LDAP_INVALID_SYNTAX;
531 * Schema-aware rewrite
533 if ( LDAPDN_rewrite( dn, 0 ) != LDAP_SUCCESS ) {
534 ldapava_free_dn( dn );
535 return LDAP_INVALID_SYNTAX;
539 * Back to string representation
541 rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
543 ldapava_free_dn( dn );
545 if ( rc != LDAP_SUCCESS ) {
546 return LDAP_INVALID_SYNTAX;
549 out = ber_bvstr( dn_out );
552 out = ber_bvdup( val );
555 Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val, 0, 0 );
563 * dn "pretty"ing routine
569 struct berval **pretty)
571 struct berval *out = NULL;
573 Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 );
578 if ( val->bv_len != 0 ) {
583 /* FIXME: should be liberal in what we accept */
584 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
585 if ( rc != LDAP_SUCCESS ) {
586 return LDAP_INVALID_SYNTAX;
590 * Schema-aware rewrite
592 if ( LDAPDN_rewrite( dn, SLAP_LDAPDN_PRETTY ) != LDAP_SUCCESS ) {
593 ldapava_free_dn( dn );
594 return LDAP_INVALID_SYNTAX;
597 /* FIXME: not sure why the default isn't pretty */
598 /* RE: the default is the form that is used as
599 * an internal representation; the pretty form
601 rc = ldap_dn2str( dn, &dn_out,
602 LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
604 ldapava_free_dn( dn );
606 if ( rc != LDAP_SUCCESS ) {
607 return LDAP_INVALID_SYNTAX;
610 out = ber_bvstr( dn_out );
613 out = ber_bvdup( val );
616 Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val, 0, 0 );
626 * note: uses exact string match (strcmp) because it is supposed to work
635 struct berval *value,
636 void *assertedValue )
639 struct berval *asserted = (struct berval *) assertedValue;
643 assert( assertedValue );
645 match = value->bv_len - asserted->bv_len;
648 match = strcmp( value->bv_val, asserted->bv_val );
652 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
653 "dnMatch: %d\n %s\n %s\n", match,
654 value->bv_val, asserted->bv_val ));
656 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
657 match, value->bv_val, asserted->bv_val );
661 return( LDAP_SUCCESS );
664 #else /* !USE_LDAP_DN_PARSING */
674 if( in->bv_len == 0 ) return LDAP_SUCCESS;
676 dn = ch_strdup( in->bv_val );
679 return LDAP_INVALID_SYNTAX;
681 } else if ( strlen( in->bv_val ) != in->bv_len ) {
682 rc = LDAP_INVALID_SYNTAX;
684 } else if ( dn_validate( dn ) == NULL ) {
685 rc = LDAP_INVALID_SYNTAX;
699 struct berval **normalized )
703 if ( val->bv_len != 0 ) {
705 out = ber_bvstr( UTF8normalize( val, UTF8_CASEFOLD ) );
707 dn = dn_validate( out->bv_val );
711 return LDAP_INVALID_SYNTAX;
715 out->bv_len = strlen( dn );
717 out = ber_bvdup( val );
730 struct berval *value,
731 void *assertedValue )
734 struct berval *asserted = (struct berval *) assertedValue;
736 match = value->bv_len - asserted->bv_len;
739 #ifdef USE_DN_NORMALIZE
740 match = strcmp( value->bv_val, asserted->bv_val );
742 match = strcasecmp( value->bv_val, asserted->bv_val );
747 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
748 "dnMatch: %d\n %s\n %s\n", match,
749 value->bv_val, asserted->bv_val ));
751 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
752 match, value->bv_val, asserted->bv_val );
760 #endif /* !USE_LDAP_DN_PARSING */
770 if( in->bv_len == 0 ) return LDAP_SUCCESS;
772 dn = ber_bvdup( in );
774 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
775 /* assume presence of optional UID */
778 for(i=dn->bv_len-2; i>2; i--) {
779 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
783 if( dn->bv_val[i] != '\'' ||
784 dn->bv_val[i-1] != 'B' ||
785 dn->bv_val[i-2] != '#' ) {
787 return LDAP_INVALID_SYNTAX;
790 /* trim the UID to allow use of dn_validate */
791 dn->bv_val[i-2] = '\0';
794 /* FIXME: should use dnValidate */
795 rc = dn_validate( dn->bv_val ) == NULL
796 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
806 struct berval **normalized )
808 struct berval *out = ber_bvdup( val );
810 if( out->bv_len != 0 ) {
814 ber_len_t uidlen = 0;
816 if( out->bv_val[out->bv_len-1] == '\'' ) {
817 /* assume presence of optional UID */
818 uid = strrchr( out->bv_val, '#' );
822 return LDAP_INVALID_SYNTAX;
825 uidlen = out->bv_len - (out->bv_val - uid);
826 /* temporarily trim the UID */
830 /* FIXME: should use dnNormalize */
831 #ifdef USE_DN_NORMALIZE
832 dn = dn_normalize( out->bv_val );
834 dn = dn_validate( out->bv_val );
839 return LDAP_INVALID_SYNTAX;
845 /* restore the separator */
848 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
852 out->bv_len = dnlen + uidlen;
864 /* any value allowed */
873 /* any value allowed */
884 /* very unforgiving validation, requires no normalization
885 * before simplistic matching
887 if( in->bv_len < 3 ) {
888 return LDAP_INVALID_SYNTAX;
892 * rfc 2252 section 6.3 Bit String
893 * bitstring = "'" *binary-digit "'"
894 * binary-digit = "0" / "1"
895 * example: '0101111101'B
898 if( in->bv_val[0] != '\'' ||
899 in->bv_val[in->bv_len-2] != '\'' ||
900 in->bv_val[in->bv_len-1] != 'B' )
902 return LDAP_INVALID_SYNTAX;
905 for( i=in->bv_len-3; i>0; i-- ) {
906 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
907 return LDAP_INVALID_SYNTAX;
918 struct berval **normalized )
921 * A normalized bitString is has no extaneous (leading) zero bits.
922 * That is, '00010'B is normalized to '10'B
923 * However, as a special case, '0'B requires no normalization.
925 struct berval *newval;
928 /* start at the first bit */
931 /* Find the first non-zero bit */
932 while ( *p == '0' ) p++;
934 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
937 /* no non-zero bits */
938 newval->bv_val = ch_strdup("\'0\'B");
939 newval->bv_len = sizeof("\'0\'B") - 1;
943 newval->bv_val = ch_malloc( val->bv_len + 1 );
945 newval->bv_val[0] = '\'';
948 for( ; *p != '\0'; p++ ) {
949 newval->bv_val[newval->bv_len++] = *p;
952 newval->bv_val[newval->bv_len] = '\0';
955 *normalized = newval;
960 * Handling boolean syntax and matching is quite rigid.
961 * A more flexible approach would be to allow a variety
962 * of strings to be normalized and prettied into TRUE
970 /* very unforgiving validation, requires no normalization
971 * before simplistic matching
974 if( in->bv_len == 4 ) {
975 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
978 } else if( in->bv_len == 5 ) {
979 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
984 return LDAP_INVALID_SYNTAX;
993 struct berval *value,
994 void *assertedValue )
996 /* simplistic matching allowed by rigid validation */
997 struct berval *asserted = (struct berval *) assertedValue;
998 *matchp = value->bv_len != asserted->bv_len;
1009 unsigned char *u = in->bv_val;
1011 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
1013 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
1014 /* get the length indicated by the first byte */
1015 len = LDAP_UTF8_CHARLEN( u );
1017 /* should not be zero */
1018 if( len == 0 ) return LDAP_INVALID_SYNTAX;
1020 /* make sure len corresponds with the offset
1021 to the next character */
1022 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
1025 if( count != 0 ) return LDAP_INVALID_SYNTAX;
1027 return LDAP_SUCCESS;
1031 UTF8StringNormalize(
1034 struct berval **normalized )
1036 struct berval *newval;
1039 newval = ch_malloc( sizeof( struct berval ) );
1043 /* Ignore initial whitespace */
1044 while ( ldap_utf8_isspace( p ) ) {
1045 LDAP_UTF8_INCR( p );
1050 return LDAP_INVALID_SYNTAX;
1053 newval->bv_val = ch_strdup( p );
1054 p = q = newval->bv_val;
1060 if ( ldap_utf8_isspace( p ) ) {
1061 len = LDAP_UTF8_COPY(q,p);
1066 /* Ignore the extra whitespace */
1067 while ( ldap_utf8_isspace( p ) ) {
1068 LDAP_UTF8_INCR( p );
1071 len = LDAP_UTF8_COPY(q,p);
1078 assert( *newval->bv_val );
1079 assert( newval->bv_val < p );
1082 /* cannot start with a space */
1083 assert( !ldap_utf8_isspace(newval->bv_val) );
1086 * If the string ended in space, backup the pointer one
1087 * position. One is enough because the above loop collapsed
1088 * all whitespace to a single space.
1095 /* cannot end with a space */
1096 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
1098 /* null terminate */
1101 newval->bv_len = q - newval->bv_val;
1102 *normalized = newval;
1104 return LDAP_SUCCESS;
1107 /* Returns Unicode cannonically normalized copy of a substring assertion
1108 * Skipping attribute description */
1109 SubstringsAssertion *
1110 UTF8SubstringsassertionNormalize(
1111 SubstringsAssertion *sa,
1114 SubstringsAssertion *nsa;
1117 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
1122 if( sa->sa_initial != NULL ) {
1123 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
1124 if( nsa->sa_initial == NULL ) {
1129 if( sa->sa_any != NULL ) {
1130 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1133 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
1134 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1135 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
1136 if( nsa->sa_any[i] == NULL ) {
1140 nsa->sa_any[i] = NULL;
1143 if( sa->sa_final != NULL ) {
1144 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
1145 if( nsa->sa_final == NULL ) {
1153 ber_bvfree( nsa->sa_final );
1154 ber_bvecfree( nsa->sa_any );
1155 ber_bvfree( nsa->sa_initial );
1160 /* Strip characters with the 8th bit set */
1173 while( *++q & 0x80 ) {
1176 p = memmove(p, q, strlen(q) + 1);
1184 #ifndef SLAPD_APPROX_OLDSINGLESTRING
1186 #if defined(SLAPD_APPROX_INITIALS)
1187 #define SLAPD_APPROX_DELIMITER "._ "
1188 #define SLAPD_APPROX_WORDLEN 2
1190 #define SLAPD_APPROX_DELIMITER " "
1191 #define SLAPD_APPROX_WORDLEN 1
1200 struct berval *value,
1201 void *assertedValue )
1203 char *val, *nval, *assertv, **values, **words, *c;
1204 int i, count, len, nextchunk=0, nextavail=0;
1207 /* Yes, this is necessary */
1208 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
1209 if( nval == NULL ) {
1211 return LDAP_SUCCESS;
1213 strip8bitChars( nval );
1215 /* Yes, this is necessary */
1216 assertv = UTF8normalize( ((struct berval *)assertedValue),
1218 if( assertv == NULL ) {
1221 return LDAP_SUCCESS;
1223 strip8bitChars( assertv );
1224 avlen = strlen( assertv );
1226 /* Isolate how many words there are */
1227 for( c=nval,count=1; *c; c++ ) {
1228 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
1229 if ( c == NULL ) break;
1234 /* Get a phonetic copy of each word */
1235 words = (char **)ch_malloc( count * sizeof(char *) );
1236 values = (char **)ch_malloc( count * sizeof(char *) );
1237 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
1239 values[i] = phonetic(c);
1242 /* Work through the asserted value's words, to see if at least some
1243 of the words are there, in the same order. */
1245 while ( (size_t) nextchunk < avlen ) {
1246 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
1251 #if defined(SLAPD_APPROX_INITIALS)
1252 else if( len == 1 ) {
1253 /* Single letter words need to at least match one word's initial */
1254 for( i=nextavail; i<count; i++ )
1255 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
1262 /* Isolate the next word in the asserted value and phonetic it */
1263 assertv[nextchunk+len] = '\0';
1264 val = phonetic( assertv + nextchunk );
1266 /* See if this phonetic chunk is in the remaining words of *value */
1267 for( i=nextavail; i<count; i++ ){
1268 if( !strcmp( val, values[i] ) ){
1276 /* This chunk in the asserted value was NOT within the *value. */
1282 /* Go on to the next word in the asserted value */
1286 /* If some of the words were seen, call it a match */
1287 if( nextavail > 0 ) {
1294 /* Cleanup allocs */
1296 for( i=0; i<count; i++ ) {
1297 ch_free( values[i] );
1303 return LDAP_SUCCESS;
1312 struct berval *prefix,
1313 struct berval **values,
1314 struct berval ***keysp )
1317 int i,j, len, wordcount, keycount=0;
1318 struct berval **newkeys, **keys=NULL;
1320 for( j=0; values[j] != NULL; j++ ) {
1321 /* Yes, this is necessary */
1322 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
1323 strip8bitChars( val );
1325 /* Isolate how many words there are. There will be a key for each */
1326 for( wordcount=0,c=val; *c; c++) {
1327 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1328 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
1330 if (*c == '\0') break;
1334 /* Allocate/increase storage to account for new keys */
1335 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
1336 * sizeof(struct berval *) );
1337 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
1338 if( keys ) ch_free( keys );
1341 /* Get a phonetic copy of each word */
1342 for( c=val,i=0; i<wordcount; c+=len+1 ) {
1344 if( len < SLAPD_APPROX_WORDLEN ) continue;
1345 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
1346 keys[keycount]->bv_val = phonetic( c );
1347 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
1354 keys[keycount] = NULL;
1357 return LDAP_SUCCESS;
1366 struct berval *prefix,
1368 struct berval ***keysp )
1372 struct berval **keys;
1374 /* Yes, this is necessary */
1375 val = UTF8normalize( ((struct berval *)assertValue),
1378 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
1381 return LDAP_SUCCESS;
1383 strip8bitChars( val );
1385 /* Isolate how many words there are. There will be a key for each */
1386 for( count=0,c=val; *c; c++) {
1387 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1388 if( len >= SLAPD_APPROX_WORDLEN ) count++;
1390 if (*c == '\0') break;
1394 /* Allocate storage for new keys */
1395 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
1397 /* Get a phonetic copy of each word */
1398 for( c=val,i=0; i<count; c+=len+1 ) {
1400 if( len < SLAPD_APPROX_WORDLEN ) continue;
1401 keys[i] = ber_bvstr( phonetic( c ) );
1410 return LDAP_SUCCESS;
1415 /* No other form of Approximate Matching is defined */
1423 struct berval *value,
1424 void *assertedValue )
1426 char *vapprox, *avapprox;
1429 /* Yes, this is necessary */
1430 s = UTF8normalize( value, UTF8_NOCASEFOLD );
1433 return LDAP_SUCCESS;
1436 /* Yes, this is necessary */
1437 t = UTF8normalize( ((struct berval *)assertedValue),
1442 return LDAP_SUCCESS;
1445 vapprox = phonetic( strip8bitChars( s ) );
1446 avapprox = phonetic( strip8bitChars( t ) );
1451 *matchp = strcmp( vapprox, avapprox );
1454 ch_free( avapprox );
1456 return LDAP_SUCCESS;
1465 struct berval *prefix,
1466 struct berval **values,
1467 struct berval ***keysp )
1470 struct berval **keys;
1473 for( i=0; values[i] != NULL; i++ ) {
1474 /* empty - just count them */
1477 /* we should have at least one value at this point */
1480 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
1482 /* Copy each value and run it through phonetic() */
1483 for( i=0; values[i] != NULL; i++ ) {
1484 /* Yes, this is necessary */
1485 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
1487 /* strip 8-bit chars and run through phonetic() */
1488 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1494 return LDAP_SUCCESS;
1504 struct berval *prefix,
1506 struct berval ***keysp )
1508 struct berval **keys;
1511 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1513 /* Yes, this is necessary */
1514 s = UTF8normalize( ((struct berval *)assertValue),
1519 /* strip 8-bit chars and run through phonetic() */
1520 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1526 return LDAP_SUCCESS;
1537 struct berval *value,
1538 void *assertedValue )
1540 *matchp = UTF8normcmp( value->bv_val,
1541 ((struct berval *) assertedValue)->bv_val,
1543 return LDAP_SUCCESS;
1547 caseExactIgnoreSubstringsMatch(
1552 struct berval *value,
1553 void *assertedValue )
1556 SubstringsAssertion *sub = NULL;
1560 char *nav, casefold;
1562 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1563 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1565 nav = UTF8normalize( value, casefold );
1571 left.bv_len = strlen( nav );
1573 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1579 /* Add up asserted input length */
1580 if( sub->sa_initial ) {
1581 inlen += sub->sa_initial->bv_len;
1584 for(i=0; sub->sa_any[i] != NULL; i++) {
1585 inlen += sub->sa_any[i]->bv_len;
1588 if( sub->sa_final ) {
1589 inlen += sub->sa_final->bv_len;
1592 if( sub->sa_initial ) {
1593 if( inlen > left.bv_len ) {
1598 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1599 sub->sa_initial->bv_len );
1605 left.bv_val += sub->sa_initial->bv_len;
1606 left.bv_len -= sub->sa_initial->bv_len;
1607 inlen -= sub->sa_initial->bv_len;
1610 if( sub->sa_final ) {
1611 if( inlen > left.bv_len ) {
1616 match = strncmp( sub->sa_final->bv_val,
1617 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1618 sub->sa_final->bv_len );
1624 left.bv_len -= sub->sa_final->bv_len;
1625 inlen -= sub->sa_final->bv_len;
1629 for(i=0; sub->sa_any[i]; i++) {
1634 if( inlen > left.bv_len ) {
1635 /* not enough length */
1640 if( sub->sa_any[i]->bv_len == 0 ) {
1644 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1651 idx = p - left.bv_val;
1652 assert( idx < left.bv_len );
1654 if( idx >= left.bv_len ) {
1655 /* this shouldn't happen */
1657 ch_free( sub->sa_final );
1658 ber_bvecfree( sub->sa_any );
1659 ch_free( sub->sa_initial );
1667 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1668 /* not enough left */
1673 match = strncmp( left.bv_val,
1674 sub->sa_any[i]->bv_val,
1675 sub->sa_any[i]->bv_len );
1683 left.bv_val += sub->sa_any[i]->bv_len;
1684 left.bv_len -= sub->sa_any[i]->bv_len;
1685 inlen -= sub->sa_any[i]->bv_len;
1692 ber_bvfree( sub->sa_final );
1693 ber_bvecfree( sub->sa_any );
1694 ber_bvfree( sub->sa_initial );
1698 return LDAP_SUCCESS;
1701 /* Index generation function */
1702 int caseExactIgnoreIndexer(
1707 struct berval *prefix,
1708 struct berval **values,
1709 struct berval ***keysp )
1714 struct berval **keys;
1715 HASH_CONTEXT HASHcontext;
1716 unsigned char HASHdigest[HASH_BYTES];
1717 struct berval digest;
1718 digest.bv_val = HASHdigest;
1719 digest.bv_len = sizeof(HASHdigest);
1721 for( i=0; values[i] != NULL; i++ ) {
1722 /* empty - just count them */
1725 /* we should have at least one value at this point */
1728 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1730 slen = strlen( syntax->ssyn_oid );
1731 mlen = strlen( mr->smr_oid );
1733 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1734 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1736 for( i=0; values[i] != NULL; i++ ) {
1737 struct berval *value;
1738 value = ber_bvstr( UTF8normalize( values[i],
1741 HASH_Init( &HASHcontext );
1742 if( prefix != NULL && prefix->bv_len > 0 ) {
1743 HASH_Update( &HASHcontext,
1744 prefix->bv_val, prefix->bv_len );
1746 HASH_Update( &HASHcontext,
1747 syntax->ssyn_oid, slen );
1748 HASH_Update( &HASHcontext,
1749 mr->smr_oid, mlen );
1750 HASH_Update( &HASHcontext,
1751 value->bv_val, value->bv_len );
1752 HASH_Final( HASHdigest, &HASHcontext );
1754 ber_bvfree( value );
1756 keys[i] = ber_bvdup( &digest );
1761 return LDAP_SUCCESS;
1764 /* Index generation function */
1765 int caseExactIgnoreFilter(
1770 struct berval *prefix,
1772 struct berval ***keysp )
1776 struct berval **keys;
1777 HASH_CONTEXT HASHcontext;
1778 unsigned char HASHdigest[HASH_BYTES];
1779 struct berval *value;
1780 struct berval digest;
1781 digest.bv_val = HASHdigest;
1782 digest.bv_len = sizeof(HASHdigest);
1784 slen = strlen( syntax->ssyn_oid );
1785 mlen = strlen( mr->smr_oid );
1787 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1788 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1790 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
1792 /* This usually happens if filter contains bad UTF8 */
1793 if( value == NULL ) {
1794 keys = ch_malloc( sizeof( struct berval * ) );
1796 return LDAP_SUCCESS;
1799 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1801 HASH_Init( &HASHcontext );
1802 if( prefix != NULL && prefix->bv_len > 0 ) {
1803 HASH_Update( &HASHcontext,
1804 prefix->bv_val, prefix->bv_len );
1806 HASH_Update( &HASHcontext,
1807 syntax->ssyn_oid, slen );
1808 HASH_Update( &HASHcontext,
1809 mr->smr_oid, mlen );
1810 HASH_Update( &HASHcontext,
1811 value->bv_val, value->bv_len );
1812 HASH_Final( HASHdigest, &HASHcontext );
1814 keys[0] = ber_bvdup( &digest );
1817 ber_bvfree( value );
1820 return LDAP_SUCCESS;
1823 /* Substrings Index generation function */
1824 int caseExactIgnoreSubstringsIndexer(
1829 struct berval *prefix,
1830 struct berval **values,
1831 struct berval ***keysp )
1836 struct berval **keys;
1837 struct berval **nvalues;
1839 HASH_CONTEXT HASHcontext;
1840 unsigned char HASHdigest[HASH_BYTES];
1841 struct berval digest;
1842 digest.bv_val = HASHdigest;
1843 digest.bv_len = sizeof(HASHdigest);
1847 for( i=0; values[i] != NULL; i++ ) {
1848 /* empty - just count them */
1851 /* we should have at least one value at this point */
1854 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1855 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1857 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1858 for( i=0; values[i] != NULL; i++ ) {
1859 nvalues[i] = ber_bvstr( UTF8normalize( values[i],
1865 for( i=0; values[i] != NULL; i++ ) {
1866 /* count number of indices to generate */
1867 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1871 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1872 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1873 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1874 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1876 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1880 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1881 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1882 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1886 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1887 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1888 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1889 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1891 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1897 /* no keys to generate */
1899 ber_bvecfree( nvalues );
1900 return LDAP_SUCCESS;
1903 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1905 slen = strlen( syntax->ssyn_oid );
1906 mlen = strlen( mr->smr_oid );
1909 for( i=0; values[i] != NULL; i++ ) {
1911 struct berval *value;
1913 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1917 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1918 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1920 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1921 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1923 for( j=0; j<max; j++ ) {
1924 HASH_Init( &HASHcontext );
1925 if( prefix != NULL && prefix->bv_len > 0 ) {
1926 HASH_Update( &HASHcontext,
1927 prefix->bv_val, prefix->bv_len );
1930 HASH_Update( &HASHcontext,
1931 &pre, sizeof( pre ) );
1932 HASH_Update( &HASHcontext,
1933 syntax->ssyn_oid, slen );
1934 HASH_Update( &HASHcontext,
1935 mr->smr_oid, mlen );
1936 HASH_Update( &HASHcontext,
1938 SLAP_INDEX_SUBSTR_MAXLEN );
1939 HASH_Final( HASHdigest, &HASHcontext );
1941 keys[nkeys++] = ber_bvdup( &digest );
1945 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1946 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1948 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1951 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1952 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1953 HASH_Init( &HASHcontext );
1954 if( prefix != NULL && prefix->bv_len > 0 ) {
1955 HASH_Update( &HASHcontext,
1956 prefix->bv_val, prefix->bv_len );
1958 HASH_Update( &HASHcontext,
1959 &pre, sizeof( pre ) );
1960 HASH_Update( &HASHcontext,
1961 syntax->ssyn_oid, slen );
1962 HASH_Update( &HASHcontext,
1963 mr->smr_oid, mlen );
1964 HASH_Update( &HASHcontext,
1966 HASH_Final( HASHdigest, &HASHcontext );
1968 keys[nkeys++] = ber_bvdup( &digest );
1971 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1972 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1973 HASH_Init( &HASHcontext );
1974 if( prefix != NULL && prefix->bv_len > 0 ) {
1975 HASH_Update( &HASHcontext,
1976 prefix->bv_val, prefix->bv_len );
1978 HASH_Update( &HASHcontext,
1979 &pre, sizeof( pre ) );
1980 HASH_Update( &HASHcontext,
1981 syntax->ssyn_oid, slen );
1982 HASH_Update( &HASHcontext,
1983 mr->smr_oid, mlen );
1984 HASH_Update( &HASHcontext,
1985 &value->bv_val[value->bv_len-j], j );
1986 HASH_Final( HASHdigest, &HASHcontext );
1988 keys[nkeys++] = ber_bvdup( &digest );
2003 ber_bvecfree( nvalues );
2005 return LDAP_SUCCESS;
2008 int caseExactIgnoreSubstringsFilter(
2013 struct berval *prefix,
2015 struct berval ***keysp )
2017 SubstringsAssertion *sa;
2019 ber_len_t nkeys = 0;
2020 size_t slen, mlen, klen;
2021 struct berval **keys;
2022 HASH_CONTEXT HASHcontext;
2023 unsigned char HASHdigest[HASH_BYTES];
2024 struct berval *value;
2025 struct berval digest;
2027 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
2028 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
2030 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
2033 return LDAP_SUCCESS;
2036 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2037 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2042 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2044 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2045 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2046 /* don't bother accounting for stepping */
2047 nkeys += sa->sa_any[i]->bv_len -
2048 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2053 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2054 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2060 ber_bvfree( sa->sa_final );
2061 ber_bvecfree( sa->sa_any );
2062 ber_bvfree( sa->sa_initial );
2065 return LDAP_SUCCESS;
2068 digest.bv_val = HASHdigest;
2069 digest.bv_len = sizeof(HASHdigest);
2071 slen = strlen( syntax->ssyn_oid );
2072 mlen = strlen( mr->smr_oid );
2074 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2077 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2078 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2080 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2081 value = sa->sa_initial;
2083 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2084 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2086 HASH_Init( &HASHcontext );
2087 if( prefix != NULL && prefix->bv_len > 0 ) {
2088 HASH_Update( &HASHcontext,
2089 prefix->bv_val, prefix->bv_len );
2091 HASH_Update( &HASHcontext,
2092 &pre, sizeof( pre ) );
2093 HASH_Update( &HASHcontext,
2094 syntax->ssyn_oid, slen );
2095 HASH_Update( &HASHcontext,
2096 mr->smr_oid, mlen );
2097 HASH_Update( &HASHcontext,
2098 value->bv_val, klen );
2099 HASH_Final( HASHdigest, &HASHcontext );
2101 keys[nkeys++] = ber_bvdup( &digest );
2104 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2106 pre = SLAP_INDEX_SUBSTR_PREFIX;
2107 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2109 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2110 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2114 value = sa->sa_any[i];
2117 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2118 j += SLAP_INDEX_SUBSTR_STEP )
2120 HASH_Init( &HASHcontext );
2121 if( prefix != NULL && prefix->bv_len > 0 ) {
2122 HASH_Update( &HASHcontext,
2123 prefix->bv_val, prefix->bv_len );
2125 HASH_Update( &HASHcontext,
2126 &pre, sizeof( pre ) );
2127 HASH_Update( &HASHcontext,
2128 syntax->ssyn_oid, slen );
2129 HASH_Update( &HASHcontext,
2130 mr->smr_oid, mlen );
2131 HASH_Update( &HASHcontext,
2132 &value->bv_val[j], klen );
2133 HASH_Final( HASHdigest, &HASHcontext );
2135 keys[nkeys++] = ber_bvdup( &digest );
2141 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2142 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2144 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2145 value = sa->sa_final;
2147 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2148 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2150 HASH_Init( &HASHcontext );
2151 if( prefix != NULL && prefix->bv_len > 0 ) {
2152 HASH_Update( &HASHcontext,
2153 prefix->bv_val, prefix->bv_len );
2155 HASH_Update( &HASHcontext,
2156 &pre, sizeof( pre ) );
2157 HASH_Update( &HASHcontext,
2158 syntax->ssyn_oid, slen );
2159 HASH_Update( &HASHcontext,
2160 mr->smr_oid, mlen );
2161 HASH_Update( &HASHcontext,
2162 &value->bv_val[value->bv_len-klen], klen );
2163 HASH_Final( HASHdigest, &HASHcontext );
2165 keys[nkeys++] = ber_bvdup( &digest );
2175 ber_bvfree( sa->sa_final );
2176 ber_bvecfree( sa->sa_any );
2177 ber_bvfree( sa->sa_initial );
2180 return LDAP_SUCCESS;
2189 struct berval *value,
2190 void *assertedValue )
2192 *matchp = UTF8normcmp( value->bv_val,
2193 ((struct berval *) assertedValue)->bv_val,
2195 return LDAP_SUCCESS;
2201 struct berval *val )
2205 if( val->bv_len == 0 ) {
2206 /* disallow empty strings */
2207 return LDAP_INVALID_SYNTAX;
2210 if( OID_LEADCHAR(val->bv_val[0]) ) {
2212 for(i=1; i < val->bv_len; i++) {
2213 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2214 if( dot++ ) return 1;
2215 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2218 return LDAP_INVALID_SYNTAX;
2222 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2224 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2225 for(i=1; i < val->bv_len; i++) {
2226 if( !DESC_CHAR(val->bv_val[i] ) ) {
2227 return LDAP_INVALID_SYNTAX;
2231 return LDAP_SUCCESS;
2234 return LDAP_INVALID_SYNTAX;
2243 struct berval *value,
2244 void *assertedValue )
2247 int vsign=0, avsign=0;
2248 struct berval *asserted;
2249 ber_len_t vlen, avlen;
2252 /* Start off pessimistic */
2255 /* Skip past leading spaces/zeros, and get the sign of the *value number */
2257 vlen = value->bv_len;
2259 if( ASCII_SPACE(*v) || ( *v == '0' )) {
2260 /* empty -- skip spaces */
2262 else if ( *v == '+' ) {
2265 else if ( *v == '-' ) {
2268 else if ( ASCII_DIGIT(*v) ) {
2269 if ( vsign == 0 ) vsign = 1;
2277 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
2279 asserted = (struct berval *) assertedValue;
2280 av = asserted->bv_val;
2281 avlen = asserted->bv_len;
2283 if( ASCII_SPACE(*av) || ( *av == '0' )) {
2284 /* empty -- skip spaces */
2286 else if ( *av == '+' ) {
2289 else if ( *av == '-' ) {
2292 else if ( ASCII_DIGIT(*av) ) {
2293 if ( avsign == 0 ) avsign = 1;
2301 /* The two ?sign vars are now one of :
2302 -2 negative non-zero number
2304 0 0 collapse these three to 0
2306 +2 positive non-zero number
2308 if ( abs( vsign ) == 1 ) vsign = 0;
2309 if ( abs( avsign ) == 1 ) avsign = 0;
2311 if( vsign != avsign ) return LDAP_SUCCESS;
2313 /* Check the significant digits */
2314 while( vlen && avlen ) {
2315 if( *v != *av ) break;
2322 /* If all digits compared equal, the numbers are equal */
2323 if(( vlen == 0 ) && ( avlen == 0 )) {
2326 return LDAP_SUCCESS;
2332 struct berval *val )
2336 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2338 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
2339 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2340 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2341 return LDAP_INVALID_SYNTAX;
2344 for( i=1; i < val->bv_len; i++ ) {
2345 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2348 return LDAP_SUCCESS;
2355 struct berval **normalized )
2359 struct berval *newval;
2366 /* Ignore leading spaces */
2367 while ( len && ( *p == ' ' )) {
2374 negative = ( *p == '-' );
2375 if(( *p == '-' ) || ( *p == '+' )) {
2381 /* Ignore leading zeros */
2382 while ( len && ( *p == '0' )) {
2387 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2389 /* If there are no non-zero digits left, the number is zero, otherwise
2390 allocate space for the number and copy it into the buffer */
2392 newval->bv_val = ch_strdup("0");
2396 newval->bv_len = len+negative;
2397 newval->bv_val = ch_malloc( newval->bv_len );
2399 newval->bv_val[0] = '-';
2401 memcpy( newval->bv_val + negative, p, len );
2404 *normalized = newval;
2405 return LDAP_SUCCESS;
2408 /* Index generation function */
2414 struct berval *prefix,
2415 struct berval **values,
2416 struct berval ***keysp )
2419 struct berval **keys;
2421 /* we should have at least one value at this point */
2422 assert( values != NULL && values[0] != NULL );
2424 for( i=0; values[i] != NULL; i++ ) {
2425 /* empty -- just count them */
2428 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2430 for( i=0; values[i] != NULL; i++ ) {
2431 integerNormalize( syntax, values[i], &keys[i] );
2436 return LDAP_SUCCESS;
2439 /* Index generation function */
2445 struct berval *prefix,
2447 struct berval ***keysp )
2449 struct berval **keys;
2451 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2452 integerNormalize( syntax, assertValue, &keys[0] );
2456 return LDAP_SUCCESS;
2461 countryStringValidate(
2463 struct berval *val )
2465 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2467 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2468 return LDAP_INVALID_SYNTAX;
2470 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2471 return LDAP_INVALID_SYNTAX;
2474 return LDAP_SUCCESS;
2478 printableStringValidate(
2480 struct berval *val )
2484 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2486 for(i=0; i < val->bv_len; i++) {
2487 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2488 return LDAP_INVALID_SYNTAX;
2492 return LDAP_SUCCESS;
2496 printablesStringValidate(
2498 struct berval *val )
2502 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2504 for(i=0; i < val->bv_len; i++) {
2505 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2506 return LDAP_INVALID_SYNTAX;
2510 return LDAP_SUCCESS;
2516 struct berval *val )
2520 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2522 for(i=0; i < val->bv_len; i++) {
2523 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2526 return LDAP_SUCCESS;
2533 struct berval **normalized )
2535 struct berval *newval;
2538 newval = ch_malloc( sizeof( struct berval ) );
2542 /* Ignore initial whitespace */
2543 while ( ASCII_SPACE( *p ) ) {
2549 return LDAP_INVALID_SYNTAX;
2552 newval->bv_val = ch_strdup( p );
2553 p = q = newval->bv_val;
2556 if ( ASCII_SPACE( *p ) ) {
2559 /* Ignore the extra whitespace */
2560 while ( ASCII_SPACE( *p ) ) {
2568 assert( *newval->bv_val );
2569 assert( newval->bv_val < p );
2572 /* cannot start with a space */
2573 assert( !ASCII_SPACE(*newval->bv_val) );
2576 * If the string ended in space, backup the pointer one
2577 * position. One is enough because the above loop collapsed
2578 * all whitespace to a single space.
2581 if ( ASCII_SPACE( q[-1] ) ) {
2585 /* cannot end with a space */
2586 assert( !ASCII_SPACE( q[-1] ) );
2588 /* null terminate */
2591 newval->bv_len = q - newval->bv_val;
2592 *normalized = newval;
2594 return LDAP_SUCCESS;
2603 struct berval *value,
2604 void *assertedValue )
2606 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2609 match = strncmp( value->bv_val,
2610 ((struct berval *) assertedValue)->bv_val,
2615 return LDAP_SUCCESS;
2619 caseExactIA5SubstringsMatch(
2624 struct berval *value,
2625 void *assertedValue )
2628 SubstringsAssertion *sub = assertedValue;
2629 struct berval left = *value;
2633 /* Add up asserted input length */
2634 if( sub->sa_initial ) {
2635 inlen += sub->sa_initial->bv_len;
2638 for(i=0; sub->sa_any[i] != NULL; i++) {
2639 inlen += sub->sa_any[i]->bv_len;
2642 if( sub->sa_final ) {
2643 inlen += sub->sa_final->bv_len;
2646 if( sub->sa_initial ) {
2647 if( inlen > left.bv_len ) {
2652 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2653 sub->sa_initial->bv_len );
2659 left.bv_val += sub->sa_initial->bv_len;
2660 left.bv_len -= sub->sa_initial->bv_len;
2661 inlen -= sub->sa_initial->bv_len;
2664 if( sub->sa_final ) {
2665 if( inlen > left.bv_len ) {
2670 match = strncmp( sub->sa_final->bv_val,
2671 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2672 sub->sa_final->bv_len );
2678 left.bv_len -= sub->sa_final->bv_len;
2679 inlen -= sub->sa_final->bv_len;
2683 for(i=0; sub->sa_any[i]; i++) {
2688 if( inlen > left.bv_len ) {
2689 /* not enough length */
2694 if( sub->sa_any[i]->bv_len == 0 ) {
2698 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2705 idx = p - left.bv_val;
2706 assert( idx < left.bv_len );
2708 if( idx >= left.bv_len ) {
2709 /* this shouldn't happen */
2716 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2717 /* not enough left */
2722 match = strncmp( left.bv_val,
2723 sub->sa_any[i]->bv_val,
2724 sub->sa_any[i]->bv_len );
2732 left.bv_val += sub->sa_any[i]->bv_len;
2733 left.bv_len -= sub->sa_any[i]->bv_len;
2734 inlen -= sub->sa_any[i]->bv_len;
2740 return LDAP_SUCCESS;
2743 /* Index generation function */
2744 int caseExactIA5Indexer(
2749 struct berval *prefix,
2750 struct berval **values,
2751 struct berval ***keysp )
2755 struct berval **keys;
2756 HASH_CONTEXT HASHcontext;
2757 unsigned char HASHdigest[HASH_BYTES];
2758 struct berval digest;
2759 digest.bv_val = HASHdigest;
2760 digest.bv_len = sizeof(HASHdigest);
2762 for( i=0; values[i] != NULL; i++ ) {
2763 /* empty - just count them */
2766 /* we should have at least one value at this point */
2769 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2771 slen = strlen( syntax->ssyn_oid );
2772 mlen = strlen( mr->smr_oid );
2774 for( i=0; values[i] != NULL; i++ ) {
2775 struct berval *value = values[i];
2777 HASH_Init( &HASHcontext );
2778 if( prefix != NULL && prefix->bv_len > 0 ) {
2779 HASH_Update( &HASHcontext,
2780 prefix->bv_val, prefix->bv_len );
2782 HASH_Update( &HASHcontext,
2783 syntax->ssyn_oid, slen );
2784 HASH_Update( &HASHcontext,
2785 mr->smr_oid, mlen );
2786 HASH_Update( &HASHcontext,
2787 value->bv_val, value->bv_len );
2788 HASH_Final( HASHdigest, &HASHcontext );
2790 keys[i] = ber_bvdup( &digest );
2795 return LDAP_SUCCESS;
2798 /* Index generation function */
2799 int caseExactIA5Filter(
2804 struct berval *prefix,
2806 struct berval ***keysp )
2809 struct berval **keys;
2810 HASH_CONTEXT HASHcontext;
2811 unsigned char HASHdigest[HASH_BYTES];
2812 struct berval *value;
2813 struct berval digest;
2814 digest.bv_val = HASHdigest;
2815 digest.bv_len = sizeof(HASHdigest);
2817 slen = strlen( syntax->ssyn_oid );
2818 mlen = strlen( mr->smr_oid );
2820 value = (struct berval *) assertValue;
2822 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2824 HASH_Init( &HASHcontext );
2825 if( prefix != NULL && prefix->bv_len > 0 ) {
2826 HASH_Update( &HASHcontext,
2827 prefix->bv_val, prefix->bv_len );
2829 HASH_Update( &HASHcontext,
2830 syntax->ssyn_oid, slen );
2831 HASH_Update( &HASHcontext,
2832 mr->smr_oid, mlen );
2833 HASH_Update( &HASHcontext,
2834 value->bv_val, value->bv_len );
2835 HASH_Final( HASHdigest, &HASHcontext );
2837 keys[0] = ber_bvdup( &digest );
2841 return LDAP_SUCCESS;
2844 /* Substrings Index generation function */
2845 int caseExactIA5SubstringsIndexer(
2850 struct berval *prefix,
2851 struct berval **values,
2852 struct berval ***keysp )
2856 struct berval **keys;
2857 HASH_CONTEXT HASHcontext;
2858 unsigned char HASHdigest[HASH_BYTES];
2859 struct berval digest;
2860 digest.bv_val = HASHdigest;
2861 digest.bv_len = sizeof(HASHdigest);
2863 /* we should have at least one value at this point */
2864 assert( values != NULL && values[0] != NULL );
2867 for( i=0; values[i] != NULL; i++ ) {
2868 /* count number of indices to generate */
2869 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2873 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2874 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2875 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2876 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2878 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2882 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2883 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2884 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2888 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2889 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2890 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2891 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2893 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2899 /* no keys to generate */
2901 return LDAP_SUCCESS;
2904 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2906 slen = strlen( syntax->ssyn_oid );
2907 mlen = strlen( mr->smr_oid );
2910 for( i=0; values[i] != NULL; i++ ) {
2912 struct berval *value;
2915 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2917 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2918 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2920 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2921 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2923 for( j=0; j<max; j++ ) {
2924 HASH_Init( &HASHcontext );
2925 if( prefix != NULL && prefix->bv_len > 0 ) {
2926 HASH_Update( &HASHcontext,
2927 prefix->bv_val, prefix->bv_len );
2930 HASH_Update( &HASHcontext,
2931 &pre, sizeof( pre ) );
2932 HASH_Update( &HASHcontext,
2933 syntax->ssyn_oid, slen );
2934 HASH_Update( &HASHcontext,
2935 mr->smr_oid, mlen );
2936 HASH_Update( &HASHcontext,
2938 SLAP_INDEX_SUBSTR_MAXLEN );
2939 HASH_Final( HASHdigest, &HASHcontext );
2941 keys[nkeys++] = ber_bvdup( &digest );
2945 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2946 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2948 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2951 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2952 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2953 HASH_Init( &HASHcontext );
2954 if( prefix != NULL && prefix->bv_len > 0 ) {
2955 HASH_Update( &HASHcontext,
2956 prefix->bv_val, prefix->bv_len );
2958 HASH_Update( &HASHcontext,
2959 &pre, sizeof( pre ) );
2960 HASH_Update( &HASHcontext,
2961 syntax->ssyn_oid, slen );
2962 HASH_Update( &HASHcontext,
2963 mr->smr_oid, mlen );
2964 HASH_Update( &HASHcontext,
2966 HASH_Final( HASHdigest, &HASHcontext );
2968 keys[nkeys++] = ber_bvdup( &digest );
2971 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2972 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2973 HASH_Init( &HASHcontext );
2974 if( prefix != NULL && prefix->bv_len > 0 ) {
2975 HASH_Update( &HASHcontext,
2976 prefix->bv_val, prefix->bv_len );
2978 HASH_Update( &HASHcontext,
2979 &pre, sizeof( pre ) );
2980 HASH_Update( &HASHcontext,
2981 syntax->ssyn_oid, slen );
2982 HASH_Update( &HASHcontext,
2983 mr->smr_oid, mlen );
2984 HASH_Update( &HASHcontext,
2985 &value->bv_val[value->bv_len-j], j );
2986 HASH_Final( HASHdigest, &HASHcontext );
2988 keys[nkeys++] = ber_bvdup( &digest );
3002 return LDAP_SUCCESS;
3005 int caseExactIA5SubstringsFilter(
3010 struct berval *prefix,
3012 struct berval ***keysp )
3014 SubstringsAssertion *sa = assertValue;
3016 ber_len_t nkeys = 0;
3017 size_t slen, mlen, klen;
3018 struct berval **keys;
3019 HASH_CONTEXT HASHcontext;
3020 unsigned char HASHdigest[HASH_BYTES];
3021 struct berval *value;
3022 struct berval digest;
3024 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
3025 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3030 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
3032 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3033 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3034 /* don't bother accounting for stepping */
3035 nkeys += sa->sa_any[i]->bv_len -
3036 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3041 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3042 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3049 return LDAP_SUCCESS;
3052 digest.bv_val = HASHdigest;
3053 digest.bv_len = sizeof(HASHdigest);
3055 slen = strlen( syntax->ssyn_oid );
3056 mlen = strlen( mr->smr_oid );
3058 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3061 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
3062 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3064 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3065 value = sa->sa_initial;
3067 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3068 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3070 HASH_Init( &HASHcontext );
3071 if( prefix != NULL && prefix->bv_len > 0 ) {
3072 HASH_Update( &HASHcontext,
3073 prefix->bv_val, prefix->bv_len );
3075 HASH_Update( &HASHcontext,
3076 &pre, sizeof( pre ) );
3077 HASH_Update( &HASHcontext,
3078 syntax->ssyn_oid, slen );
3079 HASH_Update( &HASHcontext,
3080 mr->smr_oid, mlen );
3081 HASH_Update( &HASHcontext,
3082 value->bv_val, klen );
3083 HASH_Final( HASHdigest, &HASHcontext );
3085 keys[nkeys++] = ber_bvdup( &digest );
3088 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
3090 pre = SLAP_INDEX_SUBSTR_PREFIX;
3091 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3093 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3094 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3098 value = sa->sa_any[i];
3101 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3102 j += SLAP_INDEX_SUBSTR_STEP )
3104 HASH_Init( &HASHcontext );
3105 if( prefix != NULL && prefix->bv_len > 0 ) {
3106 HASH_Update( &HASHcontext,
3107 prefix->bv_val, prefix->bv_len );
3109 HASH_Update( &HASHcontext,
3110 &pre, sizeof( pre ) );
3111 HASH_Update( &HASHcontext,
3112 syntax->ssyn_oid, slen );
3113 HASH_Update( &HASHcontext,
3114 mr->smr_oid, mlen );
3115 HASH_Update( &HASHcontext,
3116 &value->bv_val[j], klen );
3117 HASH_Final( HASHdigest, &HASHcontext );
3119 keys[nkeys++] = ber_bvdup( &digest );
3124 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3125 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3127 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3128 value = sa->sa_final;
3130 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3131 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3133 HASH_Init( &HASHcontext );
3134 if( prefix != NULL && prefix->bv_len > 0 ) {
3135 HASH_Update( &HASHcontext,
3136 prefix->bv_val, prefix->bv_len );
3138 HASH_Update( &HASHcontext,
3139 &pre, sizeof( pre ) );
3140 HASH_Update( &HASHcontext,
3141 syntax->ssyn_oid, slen );
3142 HASH_Update( &HASHcontext,
3143 mr->smr_oid, mlen );
3144 HASH_Update( &HASHcontext,
3145 &value->bv_val[value->bv_len-klen], klen );
3146 HASH_Final( HASHdigest, &HASHcontext );
3148 keys[nkeys++] = ber_bvdup( &digest );
3159 return LDAP_SUCCESS;
3168 struct berval *value,
3169 void *assertedValue )
3171 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3173 if( match == 0 && value->bv_len ) {
3174 match = strncasecmp( value->bv_val,
3175 ((struct berval *) assertedValue)->bv_val,
3180 return LDAP_SUCCESS;
3184 caseIgnoreIA5SubstringsMatch(
3189 struct berval *value,
3190 void *assertedValue )
3193 SubstringsAssertion *sub = assertedValue;
3194 struct berval left = *value;
3198 /* Add up asserted input length */
3199 if( sub->sa_initial ) {
3200 inlen += sub->sa_initial->bv_len;
3203 for(i=0; sub->sa_any[i] != NULL; i++) {
3204 inlen += sub->sa_any[i]->bv_len;
3207 if( sub->sa_final ) {
3208 inlen += sub->sa_final->bv_len;
3211 if( sub->sa_initial ) {
3212 if( inlen > left.bv_len ) {
3217 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3218 sub->sa_initial->bv_len );
3224 left.bv_val += sub->sa_initial->bv_len;
3225 left.bv_len -= sub->sa_initial->bv_len;
3226 inlen -= sub->sa_initial->bv_len;
3229 if( sub->sa_final ) {
3230 if( inlen > left.bv_len ) {
3235 match = strncasecmp( sub->sa_final->bv_val,
3236 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3237 sub->sa_final->bv_len );
3243 left.bv_len -= sub->sa_final->bv_len;
3244 inlen -= sub->sa_final->bv_len;
3248 for(i=0; sub->sa_any[i]; i++) {
3253 if( inlen > left.bv_len ) {
3254 /* not enough length */
3259 if( sub->sa_any[i]->bv_len == 0 ) {
3263 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3270 idx = p - left.bv_val;
3271 assert( idx < left.bv_len );
3273 if( idx >= left.bv_len ) {
3274 /* this shouldn't happen */
3281 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3282 /* not enough left */
3287 match = strncasecmp( left.bv_val,
3288 sub->sa_any[i]->bv_val,
3289 sub->sa_any[i]->bv_len );
3298 left.bv_val += sub->sa_any[i]->bv_len;
3299 left.bv_len -= sub->sa_any[i]->bv_len;
3300 inlen -= sub->sa_any[i]->bv_len;
3306 return LDAP_SUCCESS;
3309 /* Index generation function */
3310 int caseIgnoreIA5Indexer(
3315 struct berval *prefix,
3316 struct berval **values,
3317 struct berval ***keysp )
3321 struct berval **keys;
3322 HASH_CONTEXT HASHcontext;
3323 unsigned char HASHdigest[HASH_BYTES];
3324 struct berval digest;
3325 digest.bv_val = HASHdigest;
3326 digest.bv_len = sizeof(HASHdigest);
3328 /* we should have at least one value at this point */
3329 assert( values != NULL && values[0] != NULL );
3331 for( i=0; values[i] != NULL; i++ ) {
3332 /* just count them */
3335 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3337 slen = strlen( syntax->ssyn_oid );
3338 mlen = strlen( mr->smr_oid );
3340 for( i=0; values[i] != NULL; i++ ) {
3341 struct berval *value = ber_bvdup( values[i] );
3342 ldap_pvt_str2upper( value->bv_val );
3344 HASH_Init( &HASHcontext );
3345 if( prefix != NULL && prefix->bv_len > 0 ) {
3346 HASH_Update( &HASHcontext,
3347 prefix->bv_val, prefix->bv_len );
3349 HASH_Update( &HASHcontext,
3350 syntax->ssyn_oid, slen );
3351 HASH_Update( &HASHcontext,
3352 mr->smr_oid, mlen );
3353 HASH_Update( &HASHcontext,
3354 value->bv_val, value->bv_len );
3355 HASH_Final( HASHdigest, &HASHcontext );
3357 ber_bvfree( value );
3359 keys[i] = ber_bvdup( &digest );
3364 return LDAP_SUCCESS;
3367 /* Index generation function */
3368 int caseIgnoreIA5Filter(
3373 struct berval *prefix,
3375 struct berval ***keysp )
3378 struct berval **keys;
3379 HASH_CONTEXT HASHcontext;
3380 unsigned char HASHdigest[HASH_BYTES];
3381 struct berval *value;
3382 struct berval digest;
3383 digest.bv_val = HASHdigest;
3384 digest.bv_len = sizeof(HASHdigest);
3386 slen = strlen( syntax->ssyn_oid );
3387 mlen = strlen( mr->smr_oid );
3389 value = ber_bvdup( (struct berval *) assertValue );
3390 ldap_pvt_str2upper( value->bv_val );
3392 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3394 HASH_Init( &HASHcontext );
3395 if( prefix != NULL && prefix->bv_len > 0 ) {
3396 HASH_Update( &HASHcontext,
3397 prefix->bv_val, prefix->bv_len );
3399 HASH_Update( &HASHcontext,
3400 syntax->ssyn_oid, slen );
3401 HASH_Update( &HASHcontext,
3402 mr->smr_oid, mlen );
3403 HASH_Update( &HASHcontext,
3404 value->bv_val, value->bv_len );
3405 HASH_Final( HASHdigest, &HASHcontext );
3407 keys[0] = ber_bvdup( &digest );
3410 ber_bvfree( value );
3414 return LDAP_SUCCESS;
3417 /* Substrings Index generation function */
3418 int caseIgnoreIA5SubstringsIndexer(
3423 struct berval *prefix,
3424 struct berval **values,
3425 struct berval ***keysp )
3429 struct berval **keys;
3430 HASH_CONTEXT HASHcontext;
3431 unsigned char HASHdigest[HASH_BYTES];
3432 struct berval digest;
3433 digest.bv_val = HASHdigest;
3434 digest.bv_len = sizeof(HASHdigest);
3436 /* we should have at least one value at this point */
3437 assert( values != NULL && values[0] != NULL );
3440 for( i=0; values[i] != NULL; i++ ) {
3441 /* count number of indices to generate */
3442 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3446 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3447 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3448 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3449 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3451 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3455 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3456 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3457 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3461 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3462 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3463 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3464 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3466 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3472 /* no keys to generate */
3474 return LDAP_SUCCESS;
3477 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3479 slen = strlen( syntax->ssyn_oid );
3480 mlen = strlen( mr->smr_oid );
3483 for( i=0; values[i] != NULL; i++ ) {
3485 struct berval *value;
3487 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3489 value = ber_bvdup( values[i] );
3490 ldap_pvt_str2upper( value->bv_val );
3492 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3493 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3495 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3496 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3498 for( j=0; j<max; j++ ) {
3499 HASH_Init( &HASHcontext );
3500 if( prefix != NULL && prefix->bv_len > 0 ) {
3501 HASH_Update( &HASHcontext,
3502 prefix->bv_val, prefix->bv_len );
3505 HASH_Update( &HASHcontext,
3506 &pre, sizeof( pre ) );
3507 HASH_Update( &HASHcontext,
3508 syntax->ssyn_oid, slen );
3509 HASH_Update( &HASHcontext,
3510 mr->smr_oid, mlen );
3511 HASH_Update( &HASHcontext,
3513 SLAP_INDEX_SUBSTR_MAXLEN );
3514 HASH_Final( HASHdigest, &HASHcontext );
3516 keys[nkeys++] = ber_bvdup( &digest );
3520 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3521 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3523 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3526 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3527 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3528 HASH_Init( &HASHcontext );
3529 if( prefix != NULL && prefix->bv_len > 0 ) {
3530 HASH_Update( &HASHcontext,
3531 prefix->bv_val, prefix->bv_len );
3533 HASH_Update( &HASHcontext,
3534 &pre, sizeof( pre ) );
3535 HASH_Update( &HASHcontext,
3536 syntax->ssyn_oid, slen );
3537 HASH_Update( &HASHcontext,
3538 mr->smr_oid, mlen );
3539 HASH_Update( &HASHcontext,
3541 HASH_Final( HASHdigest, &HASHcontext );
3543 keys[nkeys++] = ber_bvdup( &digest );
3546 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3547 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3548 HASH_Init( &HASHcontext );
3549 if( prefix != NULL && prefix->bv_len > 0 ) {
3550 HASH_Update( &HASHcontext,
3551 prefix->bv_val, prefix->bv_len );
3553 HASH_Update( &HASHcontext,
3554 &pre, sizeof( pre ) );
3555 HASH_Update( &HASHcontext,
3556 syntax->ssyn_oid, slen );
3557 HASH_Update( &HASHcontext,
3558 mr->smr_oid, mlen );
3559 HASH_Update( &HASHcontext,
3560 &value->bv_val[value->bv_len-j], j );
3561 HASH_Final( HASHdigest, &HASHcontext );
3563 keys[nkeys++] = ber_bvdup( &digest );
3568 ber_bvfree( value );
3579 return LDAP_SUCCESS;
3582 int caseIgnoreIA5SubstringsFilter(
3587 struct berval *prefix,
3589 struct berval ***keysp )
3591 SubstringsAssertion *sa = assertValue;
3593 ber_len_t nkeys = 0;
3594 size_t slen, mlen, klen;
3595 struct berval **keys;
3596 HASH_CONTEXT HASHcontext;
3597 unsigned char HASHdigest[HASH_BYTES];
3598 struct berval *value;
3599 struct berval digest;
3601 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3602 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3607 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3609 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3610 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3611 /* don't bother accounting for stepping */
3612 nkeys += sa->sa_any[i]->bv_len -
3613 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3618 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3619 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3626 return LDAP_SUCCESS;
3629 digest.bv_val = HASHdigest;
3630 digest.bv_len = sizeof(HASHdigest);
3632 slen = strlen( syntax->ssyn_oid );
3633 mlen = strlen( mr->smr_oid );
3635 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3638 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3639 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3641 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3642 value = ber_bvdup( sa->sa_initial );
3643 ldap_pvt_str2upper( value->bv_val );
3645 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3646 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3648 HASH_Init( &HASHcontext );
3649 if( prefix != NULL && prefix->bv_len > 0 ) {
3650 HASH_Update( &HASHcontext,
3651 prefix->bv_val, prefix->bv_len );
3653 HASH_Update( &HASHcontext,
3654 &pre, sizeof( pre ) );
3655 HASH_Update( &HASHcontext,
3656 syntax->ssyn_oid, slen );
3657 HASH_Update( &HASHcontext,
3658 mr->smr_oid, mlen );
3659 HASH_Update( &HASHcontext,
3660 value->bv_val, klen );
3661 HASH_Final( HASHdigest, &HASHcontext );
3663 ber_bvfree( value );
3664 keys[nkeys++] = ber_bvdup( &digest );
3667 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3669 pre = SLAP_INDEX_SUBSTR_PREFIX;
3670 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3672 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3673 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3677 value = ber_bvdup( sa->sa_any[i] );
3678 ldap_pvt_str2upper( value->bv_val );
3681 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3682 j += SLAP_INDEX_SUBSTR_STEP )
3684 HASH_Init( &HASHcontext );
3685 if( prefix != NULL && prefix->bv_len > 0 ) {
3686 HASH_Update( &HASHcontext,
3687 prefix->bv_val, prefix->bv_len );
3689 HASH_Update( &HASHcontext,
3690 &pre, sizeof( pre ) );
3691 HASH_Update( &HASHcontext,
3692 syntax->ssyn_oid, slen );
3693 HASH_Update( &HASHcontext,
3694 mr->smr_oid, mlen );
3695 HASH_Update( &HASHcontext,
3696 &value->bv_val[j], klen );
3697 HASH_Final( HASHdigest, &HASHcontext );
3699 keys[nkeys++] = ber_bvdup( &digest );
3702 ber_bvfree( value );
3706 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3707 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3709 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3710 value = ber_bvdup( sa->sa_final );
3711 ldap_pvt_str2upper( value->bv_val );
3713 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3714 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3716 HASH_Init( &HASHcontext );
3717 if( prefix != NULL && prefix->bv_len > 0 ) {
3718 HASH_Update( &HASHcontext,
3719 prefix->bv_val, prefix->bv_len );
3721 HASH_Update( &HASHcontext,
3722 &pre, sizeof( pre ) );
3723 HASH_Update( &HASHcontext,
3724 syntax->ssyn_oid, slen );
3725 HASH_Update( &HASHcontext,
3726 mr->smr_oid, mlen );
3727 HASH_Update( &HASHcontext,
3728 &value->bv_val[value->bv_len-klen], klen );
3729 HASH_Final( HASHdigest, &HASHcontext );
3731 ber_bvfree( value );
3732 keys[nkeys++] = ber_bvdup( &digest );
3743 return LDAP_SUCCESS;
3747 numericStringValidate(
3753 for(i=0; i < in->bv_len; i++) {
3754 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3755 return LDAP_INVALID_SYNTAX;
3759 return LDAP_SUCCESS;
3763 numericStringNormalize(
3766 struct berval **normalized )
3768 /* removal all spaces */
3769 struct berval *newval;
3772 newval = ch_malloc( sizeof( struct berval ) );
3773 newval->bv_val = ch_malloc( val->bv_len + 1 );
3779 if ( ASCII_SPACE( *p ) ) {
3780 /* Ignore whitespace */
3787 /* we should have copied no more then is in val */
3788 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3790 /* null terminate */
3793 newval->bv_len = q - newval->bv_val;
3794 *normalized = newval;
3796 return LDAP_SUCCESS;
3800 objectIdentifierFirstComponentMatch(
3805 struct berval *value,
3806 void *assertedValue )
3808 int rc = LDAP_SUCCESS;
3810 struct berval *asserted = (struct berval *) assertedValue;
3814 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3815 return LDAP_INVALID_SYNTAX;
3818 /* trim leading white space */
3819 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3823 /* grab next word */
3824 oid.bv_val = &value->bv_val[i];
3825 oid.bv_len = value->bv_len - i;
3826 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3831 /* insert attributeTypes, objectclass check here */
3832 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3833 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3836 char *stored = ch_malloc( oid.bv_len + 1 );
3837 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3838 stored[oid.bv_len] = '\0';
3840 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3841 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3842 MatchingRule *stored_mr = mr_find( stored );
3844 if( asserted_mr == NULL ) {
3845 rc = SLAPD_COMPARE_UNDEFINED;
3847 match = asserted_mr != stored_mr;
3850 } else if ( !strcmp( syntax->ssyn_oid,
3851 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3853 AttributeType *asserted_at = at_find( asserted->bv_val );
3854 AttributeType *stored_at = at_find( stored );
3856 if( asserted_at == NULL ) {
3857 rc = SLAPD_COMPARE_UNDEFINED;
3859 match = asserted_at != stored_at;
3862 } else if ( !strcmp( syntax->ssyn_oid,
3863 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3865 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3866 ObjectClass *stored_oc = oc_find( stored );
3868 if( asserted_oc == NULL ) {
3869 rc = SLAPD_COMPARE_UNDEFINED;
3871 match = asserted_oc != stored_oc;
3879 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3880 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3881 match, value->bv_val, asserted->bv_val ));
3883 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3884 "%d\n\t\"%s\"\n\t\"%s\"\n",
3885 match, value->bv_val, asserted->bv_val );
3889 if( rc == LDAP_SUCCESS ) *matchp = match;
3899 struct berval *value,
3900 void *assertedValue )
3902 long lValue, lAssertedValue;
3904 /* safe to assume integers are NUL terminated? */
3905 lValue = strtoul(value->bv_val, NULL, 10);
3906 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3907 return LDAP_CONSTRAINT_VIOLATION;
3909 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3910 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3911 return LDAP_CONSTRAINT_VIOLATION;
3913 *matchp = (lValue & lAssertedValue);
3914 return LDAP_SUCCESS;
3923 struct berval *value,
3924 void *assertedValue )
3926 long lValue, lAssertedValue;
3928 /* safe to assume integers are NUL terminated? */
3929 lValue = strtoul(value->bv_val, NULL, 10);
3930 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3931 return LDAP_CONSTRAINT_VIOLATION;
3933 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3934 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3935 return LDAP_CONSTRAINT_VIOLATION;
3937 *matchp = (lValue | lAssertedValue);
3938 return LDAP_SUCCESS;
3942 #include <openssl/x509.h>
3943 #include <openssl/err.h>
3944 char digit[] = "0123456789";
3947 * Next function returns a string representation of a ASN1_INTEGER.
3948 * It works for unlimited lengths.
3951 static struct berval *
3952 asn1_integer2str(ASN1_INTEGER *a)
3957 /* We work backwards, make it fill from the end of buf */
3958 p = buf + sizeof(buf) - 1;
3961 if ( a == NULL || a->length == 0 ) {
3969 /* We want to preserve the original */
3970 copy = ch_malloc(n*sizeof(unsigned int));
3971 for (i = 0; i<n; i++) {
3972 copy[i] = a->data[i];
3976 * base indicates the index of the most significant
3977 * byte that might be nonzero. When it goes off the
3978 * end, we now there is nothing left to do.
3984 for (i = base; i<n; i++ ) {
3985 copy[i] += carry*256;
3986 carry = copy[i] % 10;
3991 * Way too large, we need to leave
3992 * room for sign if negative
3997 *--p = digit[carry];
3998 if (copy[base] == 0)
4004 if ( a->type == V_ASN1_NEG_INTEGER ) {
4008 return ber_bvstrdup(p);
4011 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
4012 static struct berval *
4013 dn_openssl2ldap(X509_NAME *name)
4015 char issuer_dn[1024];
4018 bio = BIO_new(BIO_s_mem());
4021 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4022 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
4023 ERR_error_string(ERR_get_error(),NULL)));
4025 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
4026 "error creating BIO: %s\n",
4027 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4031 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
4033 BIO_gets(bio, issuer_dn, 1024);
4036 return ber_bvstrdup(issuer_dn);
4040 * Given a certificate in DER format, extract the corresponding
4041 * assertion value for certificateExactMatch
4044 certificateExactConvert(
4046 struct berval ** out )
4049 unsigned char *p = in->bv_val;
4050 struct berval *serial;
4051 struct berval *issuer_dn;
4052 struct berval *bv_tmp;
4054 xcert = d2i_X509(NULL, &p, in->bv_len);
4057 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4058 "certificateExactConvert: error parsing cert: %s\n",
4059 ERR_error_string(ERR_get_error(),NULL)));
4061 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
4062 "error parsing cert: %s\n",
4063 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4065 return LDAP_INVALID_SYNTAX;
4068 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4071 return LDAP_INVALID_SYNTAX;
4073 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4077 return LDAP_INVALID_SYNTAX;
4079 /* Actually, dn_openssl2ldap returns in a normalized format, but
4080 it is different from our normalized format */
4082 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
4086 return LDAP_INVALID_SYNTAX;
4092 *out = ch_malloc(sizeof(struct berval));
4093 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
4094 (*out)->bv_val = ch_malloc((*out)->bv_len);
4096 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
4097 p += serial->bv_len;
4098 AC_MEMCPY(p, " $ ", 3);
4100 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
4101 p += issuer_dn->bv_len;
4105 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4106 "certificateExactConvert: \n %s\n",
4109 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
4111 (*out)->bv_val, NULL, NULL );
4115 ber_bvfree(issuer_dn);
4117 return LDAP_SUCCESS;
4121 serial_and_issuer_parse(
4122 struct berval *assertion,
4123 struct berval **serial,
4124 struct berval **issuer_dn
4132 begin = assertion->bv_val;
4133 end = assertion->bv_val+assertion->bv_len-1;
4134 for (p=begin; p<=end && *p != '$'; p++)
4137 return LDAP_INVALID_SYNTAX;
4139 /* p now points at the $ sign, now use begin and end to delimit the
4141 while (ASCII_SPACE(*begin))
4144 while (ASCII_SPACE(*end))
4147 q = ch_malloc( (end-begin+1)+1 );
4148 AC_MEMCPY( q, begin, end-begin+1 );
4149 q[end-begin+1] = '\0';
4150 *serial = ber_bvstr(q);
4152 /* now extract the issuer, remember p was at the dollar sign */
4154 end = assertion->bv_val+assertion->bv_len-1;
4155 while (ASCII_SPACE(*begin))
4157 /* should we trim spaces at the end too? is it safe always? */
4159 q = ch_malloc( (end-begin+1)+1 );
4160 AC_MEMCPY( q, begin, end-begin+1 );
4161 q[end-begin+1] = '\0';
4162 *issuer_dn = ber_bvstr(dn_normalize(q));
4164 return LDAP_SUCCESS;
4168 certificateExactMatch(
4173 struct berval *value,
4174 void *assertedValue )
4177 unsigned char *p = value->bv_val;
4178 struct berval *serial;
4179 struct berval *issuer_dn;
4180 struct berval *asserted_serial;
4181 struct berval *asserted_issuer_dn;
4184 xcert = d2i_X509(NULL, &p, value->bv_len);
4187 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4188 "certificateExactMatch: error parsing cert: %s\n",
4189 ERR_error_string(ERR_get_error(),NULL)));
4191 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
4192 "error parsing cert: %s\n",
4193 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4195 return LDAP_INVALID_SYNTAX;
4198 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4199 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4203 serial_and_issuer_parse(assertedValue,
4205 &asserted_issuer_dn);
4210 slap_schema.si_syn_integer,
4211 slap_schema.si_mr_integerMatch,
4214 if ( ret == LDAP_SUCCESS ) {
4215 if ( *matchp == 0 ) {
4216 /* We need to normalize everything for dnMatch */
4220 slap_schema.si_syn_distinguishedName,
4221 slap_schema.si_mr_distinguishedNameMatch,
4223 asserted_issuer_dn);
4228 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4229 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
4230 *matchp, serial->bv_val, issuer_dn->bv_val,
4231 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
4233 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
4234 "%d\n\t\"%s $ %s\"\n",
4235 *matchp, serial->bv_val, issuer_dn->bv_val );
4236 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
4237 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
4242 ber_bvfree(issuer_dn);
4243 ber_bvfree(asserted_serial);
4244 ber_bvfree(asserted_issuer_dn);
4250 * Index generation function
4251 * We just index the serials, in most scenarios the issuer DN is one of
4252 * a very small set of values.
4254 int certificateExactIndexer(
4259 struct berval *prefix,
4260 struct berval **values,
4261 struct berval ***keysp )
4264 struct berval **keys;
4267 struct berval * serial;
4269 /* we should have at least one value at this point */
4270 assert( values != NULL && values[0] != NULL );
4272 for( i=0; values[i] != NULL; i++ ) {
4273 /* empty -- just count them */
4276 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
4278 for( i=0; values[i] != NULL; i++ ) {
4279 p = values[i]->bv_val;
4280 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
4283 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4284 "certificateExactIndexer: error parsing cert: %s\n",
4285 ERR_error_string(ERR_get_error(),NULL)));
4287 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4288 "error parsing cert: %s\n",
4289 ERR_error_string(ERR_get_error(),NULL),
4292 /* Do we leak keys on error? */
4293 return LDAP_INVALID_SYNTAX;
4296 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4298 integerNormalize( slap_schema.si_syn_integer,
4303 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4304 "certificateExactIndexer: returning: %s\n",
4307 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4316 return LDAP_SUCCESS;
4319 /* Index generation function */
4320 /* We think this is always called with a value in matching rule syntax */
4321 int certificateExactFilter(
4326 struct berval *prefix,
4328 struct berval ***keysp )
4330 struct berval **keys;
4331 struct berval *asserted_serial;
4332 struct berval *asserted_issuer_dn;
4334 serial_and_issuer_parse(assertValue,
4336 &asserted_issuer_dn);
4338 keys = ch_malloc( sizeof( struct berval * ) * 2 );
4339 integerNormalize( syntax, asserted_serial, &keys[0] );
4343 ber_bvfree(asserted_serial);
4344 ber_bvfree(asserted_issuer_dn);
4345 return LDAP_SUCCESS;
4350 check_time_syntax (struct berval *val,
4354 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
4355 static int mdays[2][12] = {
4356 /* non-leap years */
4357 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
4359 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
4362 int part, c, tzoffset, leapyear = 0 ;
4364 if( val->bv_len == 0 ) {
4365 return LDAP_INVALID_SYNTAX;
4368 p = (char *)val->bv_val;
4369 e = p + val->bv_len;
4371 /* Ignore initial whitespace */
4372 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4376 if (e - p < 13 - (2 * start)) {
4377 return LDAP_INVALID_SYNTAX;
4380 for (part = 0; part < 9; part++) {
4384 for (part = start; part < 7; part++) {
4386 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
4393 return LDAP_INVALID_SYNTAX;
4395 if (c < 0 || c > 9) {
4396 return LDAP_INVALID_SYNTAX;
4402 return LDAP_INVALID_SYNTAX;
4404 if (c < 0 || c > 9) {
4405 return LDAP_INVALID_SYNTAX;
4410 if (part == 2 || part == 3) {
4413 if (parts[part] < 0) {
4414 return LDAP_INVALID_SYNTAX;
4416 if (parts[part] > ceiling[part]) {
4417 return LDAP_INVALID_SYNTAX;
4421 /* leapyear check for the Gregorian calendar (year>1581) */
4422 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
4423 ((parts[0] % 4 == 0) && (parts[1] == 0)))
4428 if (parts[3] > mdays[leapyear][parts[2]]) {
4429 return LDAP_INVALID_SYNTAX;
4434 tzoffset = 0; /* UTC */
4435 } else if (c != '+' && c != '-') {
4436 return LDAP_INVALID_SYNTAX;
4440 } else /* c == '+' */ {
4445 return LDAP_INVALID_SYNTAX;
4448 for (part = 7; part < 9; part++) {
4450 if (c < 0 || c > 9) {
4451 return LDAP_INVALID_SYNTAX;
4456 if (c < 0 || c > 9) {
4457 return LDAP_INVALID_SYNTAX;
4461 if (parts[part] < 0 || parts[part] > ceiling[part]) {
4462 return LDAP_INVALID_SYNTAX;
4467 /* Ignore trailing whitespace */
4468 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4472 return LDAP_INVALID_SYNTAX;
4475 switch ( tzoffset ) {
4476 case -1: /* negativ offset to UTC, ie west of Greenwich */
4477 parts[4] += parts[7];
4478 parts[5] += parts[8];
4479 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
4483 c = mdays[leapyear][parts[2]];
4485 if (parts[part] > c) {
4486 parts[part] -= c + 1;
4491 case 1: /* positive offset to UTC, ie east of Greenwich */
4492 parts[4] -= parts[7];
4493 parts[5] -= parts[8];
4494 for (part = 6; --part > 0; ) {
4498 /* first arg to % needs to be non negativ */
4499 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
4501 if (parts[part] < 0) {
4502 parts[part] += c + 1;
4507 case 0: /* already UTC */
4511 return LDAP_SUCCESS;
4518 struct berval **normalized )
4523 rc = check_time_syntax(val, 1, parts);
4524 if (rc != LDAP_SUCCESS) {
4529 out = ch_malloc( sizeof(struct berval) );
4531 return LBER_ERROR_MEMORY;
4534 out->bv_val = ch_malloc( 14 );
4535 if ( out->bv_val == NULL ) {
4537 return LBER_ERROR_MEMORY;
4540 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02dZ",
4541 parts[1], parts[2] + 1, parts[3] + 1,
4542 parts[4], parts[5], parts[6] );
4546 return LDAP_SUCCESS;
4556 return check_time_syntax(in, 1, parts);
4560 generalizedTimeValidate(
4566 return check_time_syntax(in, 0, parts);
4570 generalizedTimeNormalize(
4573 struct berval **normalized )
4578 rc = check_time_syntax(val, 0, parts);
4579 if (rc != LDAP_SUCCESS) {
4584 out = ch_malloc( sizeof(struct berval) );
4586 return LBER_ERROR_MEMORY;
4589 out->bv_val = ch_malloc( 16 );
4590 if ( out->bv_val == NULL ) {
4592 return LBER_ERROR_MEMORY;
4595 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4596 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4597 parts[4], parts[5], parts[6] );
4601 return LDAP_SUCCESS;
4605 nisNetgroupTripleValidate(
4607 struct berval *val )
4612 if ( val->bv_len == 0 ) {
4613 return LDAP_INVALID_SYNTAX;
4616 p = (char *)val->bv_val;
4617 e = p + val->bv_len;
4619 if ( *p != '(' /*')'*/ ) {
4620 return LDAP_INVALID_SYNTAX;
4623 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4627 return LDAP_INVALID_SYNTAX;
4630 } else if ( !ATTR_CHAR( *p ) ) {
4631 return LDAP_INVALID_SYNTAX;
4635 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4636 return LDAP_INVALID_SYNTAX;
4642 return LDAP_INVALID_SYNTAX;
4645 return LDAP_SUCCESS;
4649 bootParameterValidate(
4651 struct berval *val )
4655 if ( val->bv_len == 0 ) {
4656 return LDAP_INVALID_SYNTAX;
4659 p = (char *)val->bv_val;
4660 e = p + val->bv_len;
4663 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4664 if ( !ATTR_CHAR( *p ) ) {
4665 return LDAP_INVALID_SYNTAX;
4670 return LDAP_INVALID_SYNTAX;
4674 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4675 if ( !ATTR_CHAR( *p ) ) {
4676 return LDAP_INVALID_SYNTAX;
4681 return LDAP_INVALID_SYNTAX;
4685 for ( p++; p < e; p++ ) {
4686 if ( !ATTR_CHAR( *p ) ) {
4687 return LDAP_INVALID_SYNTAX;
4691 return LDAP_SUCCESS;
4694 struct syntax_defs_rec {
4697 slap_syntax_validate_func *sd_validate;
4698 slap_syntax_transform_func *sd_normalize;
4699 slap_syntax_transform_func *sd_pretty;
4700 #ifdef SLAPD_BINARY_CONVERSION
4701 slap_syntax_transform_func *sd_ber2str;
4702 slap_syntax_transform_func *sd_str2ber;
4706 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4707 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4709 struct syntax_defs_rec syntax_defs[] = {
4710 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4711 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4712 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4713 0, NULL, NULL, NULL},
4714 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4715 0, NULL, NULL, NULL},
4716 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4717 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4718 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4719 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4720 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4721 0, bitStringValidate, bitStringNormalize, NULL },
4722 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4723 0, booleanValidate, NULL, NULL},
4724 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4725 X_BINARY X_NOT_H_R ")",
4726 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4727 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4728 X_BINARY X_NOT_H_R ")",
4729 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4730 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4731 X_BINARY X_NOT_H_R ")",
4732 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4733 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4734 0, countryStringValidate, IA5StringNormalize, NULL},
4735 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4736 0, dnValidate, dnNormalize, dnPretty},
4737 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4738 0, NULL, NULL, NULL},
4739 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4740 0, NULL, NULL, NULL},
4741 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4742 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4743 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4744 0, NULL, NULL, NULL},
4745 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4746 0, NULL, NULL, NULL},
4747 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4748 0, NULL, NULL, NULL},
4749 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4750 0, NULL, NULL, NULL},
4751 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4752 0, NULL, NULL, NULL},
4753 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4754 0, printablesStringValidate, IA5StringNormalize, NULL},
4755 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4756 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4757 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4758 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4759 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4760 0, NULL, NULL, NULL},
4761 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4762 0, IA5StringValidate, IA5StringNormalize, NULL},
4763 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4764 0, integerValidate, integerNormalize, NULL},
4765 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4766 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4767 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4768 0, NULL, NULL, NULL},
4769 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4770 0, NULL, NULL, NULL},
4771 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4772 0, NULL, NULL, NULL},
4773 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4774 0, NULL, NULL, NULL},
4775 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4776 0, NULL, NULL, NULL},
4777 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4778 0, nameUIDValidate, nameUIDNormalize, NULL},
4779 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4780 0, NULL, NULL, NULL},
4781 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4782 0, numericStringValidate, numericStringNormalize, NULL},
4783 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4784 0, NULL, NULL, NULL},
4785 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4786 0, oidValidate, NULL, NULL},
4787 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4788 0, IA5StringValidate, IA5StringNormalize, NULL},
4789 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4790 0, blobValidate, NULL, NULL},
4791 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4792 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4793 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4794 0, NULL, NULL, NULL},
4795 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4796 0, NULL, NULL, NULL},
4797 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4798 0, printableStringValidate, IA5StringNormalize, NULL},
4799 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4800 X_BINARY X_NOT_H_R ")",
4801 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4802 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4803 0, printableStringValidate, IA5StringNormalize, NULL},
4804 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4805 0, NULL, NULL, NULL},
4806 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4807 0, printablesStringValidate, IA5StringNormalize, NULL},
4808 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4809 0, utcTimeValidate, utcTimeNormalize, NULL},
4810 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4811 0, NULL, NULL, NULL},
4812 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4813 0, NULL, NULL, NULL},
4814 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4815 0, NULL, NULL, NULL},
4816 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4817 0, NULL, NULL, NULL},
4818 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4819 0, NULL, NULL, NULL},
4821 /* RFC 2307 NIS Syntaxes */
4822 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4823 0, nisNetgroupTripleValidate, NULL, NULL},
4824 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4825 0, bootParameterValidate, NULL, NULL},
4829 /* These OIDs are not published yet, but will be in the next
4830 * I-D for PKIX LDAPv3 schema as have been advanced by David
4831 * Chadwick in private mail.
4833 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4834 0, NULL, NULL, NULL},
4837 /* OpenLDAP Experimental Syntaxes */
4838 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4840 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4843 /* needs updating */
4844 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4845 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4847 /* OpenLDAP Void Syntax */
4848 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4849 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4850 {NULL, 0, NULL, NULL, NULL}
4853 struct mrule_defs_rec {
4855 slap_mask_t mrd_usage;
4856 slap_mr_convert_func * mrd_convert;
4857 slap_mr_normalize_func * mrd_normalize;
4858 slap_mr_match_func * mrd_match;
4859 slap_mr_indexer_func * mrd_indexer;
4860 slap_mr_filter_func * mrd_filter;
4862 char * mrd_associated;
4866 * Other matching rules in X.520 that we do not use (yet):
4868 * 2.5.13.9 numericStringOrderingMatch
4869 * 2.5.13.15 integerOrderingMatch
4870 * 2.5.13.18 octetStringOrderingMatch
4871 * 2.5.13.19 octetStringSubstringsMatch
4872 * 2.5.13.25 uTCTimeMatch
4873 * 2.5.13.26 uTCTimeOrderingMatch
4874 * 2.5.13.31 directoryStringFirstComponentMatch
4875 * 2.5.13.32 wordMatch
4876 * 2.5.13.33 keywordMatch
4877 * 2.5.13.35 certificateMatch
4878 * 2.5.13.36 certificatePairExactMatch
4879 * 2.5.13.37 certificatePairMatch
4880 * 2.5.13.38 certificateListExactMatch
4881 * 2.5.13.39 certificateListMatch
4882 * 2.5.13.40 algorithmIdentifierMatch
4883 * 2.5.13.41 storedPrefixMatch
4884 * 2.5.13.42 attributeCertificateMatch
4885 * 2.5.13.43 readerAndKeyIDMatch
4886 * 2.5.13.44 attributeIntegrityMatch
4889 struct mrule_defs_rec mrule_defs[] = {
4891 * EQUALITY matching rules must be listed after associated APPROX
4892 * matching rules. So, we list all APPROX matching rules first.
4894 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4895 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4896 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4898 directoryStringApproxMatch,
4899 directoryStringApproxIndexer,
4900 directoryStringApproxFilter,
4903 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4904 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4905 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4907 IA5StringApproxMatch,
4908 IA5StringApproxIndexer,
4909 IA5StringApproxFilter,
4913 * Other matching rules
4916 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4917 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4918 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4920 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4923 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4924 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4925 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4927 dnMatch, dnIndexer, dnFilter,
4930 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4931 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4932 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4934 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4935 directoryStringApproxMatchOID },
4937 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4938 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4941 caseIgnoreOrderingMatch, NULL, NULL,
4944 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4945 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4946 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4948 caseExactIgnoreSubstringsMatch,
4949 caseExactIgnoreSubstringsIndexer,
4950 caseExactIgnoreSubstringsFilter,
4953 {"( 2.5.13.5 NAME 'caseExactMatch' "
4954 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4955 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4957 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4958 directoryStringApproxMatchOID },
4960 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4961 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4964 caseExactOrderingMatch, NULL, NULL,
4967 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4968 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4969 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4971 caseExactIgnoreSubstringsMatch,
4972 caseExactIgnoreSubstringsIndexer,
4973 caseExactIgnoreSubstringsFilter,
4976 {"( 2.5.13.8 NAME 'numericStringMatch' "
4977 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4978 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4981 caseIgnoreIA5Indexer,
4982 caseIgnoreIA5Filter,
4985 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4986 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4987 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4989 caseIgnoreIA5SubstringsMatch,
4990 caseIgnoreIA5SubstringsIndexer,
4991 caseIgnoreIA5SubstringsFilter,
4994 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4995 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4996 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4998 caseIgnoreListMatch, NULL, NULL,
5001 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
5002 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
5003 SLAP_MR_SUBSTR | SLAP_MR_EXT,
5005 caseIgnoreListSubstringsMatch, NULL, NULL,
5008 {"( 2.5.13.13 NAME 'booleanMatch' "
5009 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
5010 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5012 booleanMatch, NULL, NULL,
5015 {"( 2.5.13.14 NAME 'integerMatch' "
5016 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5017 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5019 integerMatch, integerIndexer, integerFilter,
5022 {"( 2.5.13.16 NAME 'bitStringMatch' "
5023 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
5024 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5026 bitStringMatch, bitStringIndexer, bitStringFilter,
5029 {"( 2.5.13.17 NAME 'octetStringMatch' "
5030 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
5031 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5033 octetStringMatch, octetStringIndexer, octetStringFilter,
5036 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
5037 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
5038 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
5040 telephoneNumberMatch,
5041 telephoneNumberIndexer,
5042 telephoneNumberFilter,
5045 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
5046 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
5047 SLAP_MR_SUBSTR | SLAP_MR_EXT,
5049 telephoneNumberSubstringsMatch,
5050 telephoneNumberSubstringsIndexer,
5051 telephoneNumberSubstringsFilter,
5054 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
5055 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
5056 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5061 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
5062 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
5063 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5065 uniqueMemberMatch, NULL, NULL,
5068 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
5069 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
5070 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5072 protocolInformationMatch, NULL, NULL,
5075 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
5076 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
5077 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5079 generalizedTimeMatch, NULL, NULL,
5082 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
5083 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
5086 generalizedTimeOrderingMatch, NULL, NULL,
5089 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
5090 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5091 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5093 integerFirstComponentMatch, NULL, NULL,
5096 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
5097 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
5098 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5100 objectIdentifierFirstComponentMatch, NULL, NULL,
5104 {"( 2.5.13.34 NAME 'certificateExactMatch' "
5105 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
5106 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5107 certificateExactConvert, NULL,
5108 certificateExactMatch,
5109 certificateExactIndexer, certificateExactFilter,
5113 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
5114 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5115 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5117 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
5118 IA5StringApproxMatchOID },
5120 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
5121 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5122 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
5124 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
5125 IA5StringApproxMatchOID },
5127 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
5128 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5131 caseIgnoreIA5SubstringsMatch,
5132 caseIgnoreIA5SubstringsIndexer,
5133 caseIgnoreIA5SubstringsFilter,
5136 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
5137 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5140 caseExactIA5SubstringsMatch,
5141 caseExactIA5SubstringsIndexer,
5142 caseExactIA5SubstringsFilter,
5145 /* needs updating */
5146 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
5147 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
5150 authPasswordMatch, NULL, NULL,
5153 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
5154 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
5157 OpenLDAPaciMatch, NULL, NULL,
5160 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
5161 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5164 integerBitAndMatch, NULL, NULL,
5167 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
5168 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5171 integerBitOrMatch, NULL, NULL,
5174 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
5183 /* we should only be called once (from main) */
5184 assert( schema_init_done == 0 );
5186 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
5187 res = register_syntax( syntax_defs[i].sd_desc,
5188 syntax_defs[i].sd_flags,
5189 syntax_defs[i].sd_validate,
5190 syntax_defs[i].sd_normalize,
5191 syntax_defs[i].sd_pretty
5192 #ifdef SLAPD_BINARY_CONVERSION
5194 syntax_defs[i].sd_ber2str,
5195 syntax_defs[i].sd_str2ber
5200 fprintf( stderr, "schema_init: Error registering syntax %s\n",
5201 syntax_defs[i].sd_desc );
5206 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
5207 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
5209 "schema_init: Ingoring unusable matching rule %s\n",
5210 mrule_defs[i].mrd_desc );
5214 res = register_matching_rule(
5215 mrule_defs[i].mrd_desc,
5216 mrule_defs[i].mrd_usage,
5217 mrule_defs[i].mrd_convert,
5218 mrule_defs[i].mrd_normalize,
5219 mrule_defs[i].mrd_match,
5220 mrule_defs[i].mrd_indexer,
5221 mrule_defs[i].mrd_filter,
5222 mrule_defs[i].mrd_associated );
5226 "schema_init: Error registering matching rule %s\n",
5227 mrule_defs[i].mrd_desc );
5231 schema_init_done = 1;
5232 return LDAP_SUCCESS;
5236 schema_destroy( void )