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 rc = dn_validate( dn->bv_val ) == NULL
795 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
805 struct berval **normalized )
807 struct berval *out = ber_bvdup( val );
809 if( out->bv_len != 0 ) {
813 ber_len_t uidlen = 0;
815 if( out->bv_val[out->bv_len-1] == '\'' ) {
816 /* assume presence of optional UID */
817 uid = strrchr( out->bv_val, '#' );
821 return LDAP_INVALID_SYNTAX;
824 uidlen = out->bv_len - (out->bv_val - uid);
825 /* temporarily trim the UID */
829 #ifdef USE_DN_NORMALIZE
830 dn = dn_normalize( out->bv_val );
832 dn = dn_validate( out->bv_val );
837 return LDAP_INVALID_SYNTAX;
843 /* restore the separator */
846 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
850 out->bv_len = dnlen + uidlen;
862 /* any value allowed */
871 /* any value allowed */
882 /* very unforgiving validation, requires no normalization
883 * before simplistic matching
885 if( in->bv_len < 3 ) {
886 return LDAP_INVALID_SYNTAX;
890 * rfc 2252 section 6.3 Bit String
891 * bitstring = "'" *binary-digit "'"
892 * binary-digit = "0" / "1"
893 * example: '0101111101'B
896 if( in->bv_val[0] != '\'' ||
897 in->bv_val[in->bv_len-2] != '\'' ||
898 in->bv_val[in->bv_len-1] != 'B' )
900 return LDAP_INVALID_SYNTAX;
903 for( i=in->bv_len-3; i>0; i-- ) {
904 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
905 return LDAP_INVALID_SYNTAX;
916 struct berval **normalized )
919 * A normalized bitString is has no extaneous (leading) zero bits.
920 * That is, '00010'B is normalized to '10'B
921 * However, as a special case, '0'B requires no normalization.
923 struct berval *newval;
926 /* start at the first bit */
929 /* Find the first non-zero bit */
930 while ( *p == '0' ) p++;
932 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
935 /* no non-zero bits */
936 newval->bv_val = ch_strdup("\'0\'B");
937 newval->bv_len = sizeof("\'0\'B") - 1;
941 newval->bv_val = ch_malloc( val->bv_len + 1 );
943 newval->bv_val[0] = '\'';
946 for( ; *p != '\0'; p++ ) {
947 newval->bv_val[newval->bv_len++] = *p;
950 newval->bv_val[newval->bv_len] = '\0';
953 *normalized = newval;
958 * Handling boolean syntax and matching is quite rigid.
959 * A more flexible approach would be to allow a variety
960 * of strings to be normalized and prettied into TRUE
968 /* very unforgiving validation, requires no normalization
969 * before simplistic matching
972 if( in->bv_len == 4 ) {
973 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
976 } else if( in->bv_len == 5 ) {
977 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
982 return LDAP_INVALID_SYNTAX;
991 struct berval *value,
992 void *assertedValue )
994 /* simplistic matching allowed by rigid validation */
995 struct berval *asserted = (struct berval *) assertedValue;
996 *matchp = value->bv_len != asserted->bv_len;
1007 unsigned char *u = in->bv_val;
1009 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
1011 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
1012 /* get the length indicated by the first byte */
1013 len = LDAP_UTF8_CHARLEN( u );
1015 /* should not be zero */
1016 if( len == 0 ) return LDAP_INVALID_SYNTAX;
1018 /* make sure len corresponds with the offset
1019 to the next character */
1020 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
1023 if( count != 0 ) return LDAP_INVALID_SYNTAX;
1025 return LDAP_SUCCESS;
1029 UTF8StringNormalize(
1032 struct berval **normalized )
1034 struct berval *newval;
1037 newval = ch_malloc( sizeof( struct berval ) );
1041 /* Ignore initial whitespace */
1042 while ( ldap_utf8_isspace( p ) ) {
1043 LDAP_UTF8_INCR( p );
1048 return LDAP_INVALID_SYNTAX;
1051 newval->bv_val = ch_strdup( p );
1052 p = q = newval->bv_val;
1058 if ( ldap_utf8_isspace( p ) ) {
1059 len = LDAP_UTF8_COPY(q,p);
1064 /* Ignore the extra whitespace */
1065 while ( ldap_utf8_isspace( p ) ) {
1066 LDAP_UTF8_INCR( p );
1069 len = LDAP_UTF8_COPY(q,p);
1076 assert( *newval->bv_val );
1077 assert( newval->bv_val < p );
1080 /* cannot start with a space */
1081 assert( !ldap_utf8_isspace(newval->bv_val) );
1084 * If the string ended in space, backup the pointer one
1085 * position. One is enough because the above loop collapsed
1086 * all whitespace to a single space.
1093 /* cannot end with a space */
1094 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
1096 /* null terminate */
1099 newval->bv_len = q - newval->bv_val;
1100 *normalized = newval;
1102 return LDAP_SUCCESS;
1105 /* Returns Unicode cannonically normalized copy of a substring assertion
1106 * Skipping attribute description */
1107 SubstringsAssertion *
1108 UTF8SubstringsassertionNormalize(
1109 SubstringsAssertion *sa,
1112 SubstringsAssertion *nsa;
1115 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
1120 if( sa->sa_initial != NULL ) {
1121 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
1122 if( nsa->sa_initial == NULL ) {
1127 if( sa->sa_any != NULL ) {
1128 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1131 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
1132 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1133 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
1134 if( nsa->sa_any[i] == NULL ) {
1138 nsa->sa_any[i] = NULL;
1141 if( sa->sa_final != NULL ) {
1142 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
1143 if( nsa->sa_final == NULL ) {
1151 ber_bvfree( nsa->sa_final );
1152 ber_bvecfree( nsa->sa_any );
1153 ber_bvfree( nsa->sa_initial );
1158 /* Strip characters with the 8th bit set */
1171 while( *++q & 0x80 ) {
1174 p = memmove(p, q, strlen(q) + 1);
1182 #ifndef SLAPD_APPROX_OLDSINGLESTRING
1184 #if defined(SLAPD_APPROX_INITIALS)
1185 #define SLAPD_APPROX_DELIMITER "._ "
1186 #define SLAPD_APPROX_WORDLEN 2
1188 #define SLAPD_APPROX_DELIMITER " "
1189 #define SLAPD_APPROX_WORDLEN 1
1198 struct berval *value,
1199 void *assertedValue )
1201 char *val, *nval, *assertv, **values, **words, *c;
1202 int i, count, len, nextchunk=0, nextavail=0;
1205 /* Yes, this is necessary */
1206 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
1207 if( nval == NULL ) {
1209 return LDAP_SUCCESS;
1211 strip8bitChars( nval );
1213 /* Yes, this is necessary */
1214 assertv = UTF8normalize( ((struct berval *)assertedValue),
1216 if( assertv == NULL ) {
1219 return LDAP_SUCCESS;
1221 strip8bitChars( assertv );
1222 avlen = strlen( assertv );
1224 /* Isolate how many words there are */
1225 for( c=nval,count=1; *c; c++ ) {
1226 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
1227 if ( c == NULL ) break;
1232 /* Get a phonetic copy of each word */
1233 words = (char **)ch_malloc( count * sizeof(char *) );
1234 values = (char **)ch_malloc( count * sizeof(char *) );
1235 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
1237 values[i] = phonetic(c);
1240 /* Work through the asserted value's words, to see if at least some
1241 of the words are there, in the same order. */
1243 while ( (size_t) nextchunk < avlen ) {
1244 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
1249 #if defined(SLAPD_APPROX_INITIALS)
1250 else if( len == 1 ) {
1251 /* Single letter words need to at least match one word's initial */
1252 for( i=nextavail; i<count; i++ )
1253 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
1260 /* Isolate the next word in the asserted value and phonetic it */
1261 assertv[nextchunk+len] = '\0';
1262 val = phonetic( assertv + nextchunk );
1264 /* See if this phonetic chunk is in the remaining words of *value */
1265 for( i=nextavail; i<count; i++ ){
1266 if( !strcmp( val, values[i] ) ){
1274 /* This chunk in the asserted value was NOT within the *value. */
1280 /* Go on to the next word in the asserted value */
1284 /* If some of the words were seen, call it a match */
1285 if( nextavail > 0 ) {
1292 /* Cleanup allocs */
1294 for( i=0; i<count; i++ ) {
1295 ch_free( values[i] );
1301 return LDAP_SUCCESS;
1310 struct berval *prefix,
1311 struct berval **values,
1312 struct berval ***keysp )
1315 int i,j, len, wordcount, keycount=0;
1316 struct berval **newkeys, **keys=NULL;
1318 for( j=0; values[j] != NULL; j++ ) {
1319 /* Yes, this is necessary */
1320 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
1321 strip8bitChars( val );
1323 /* Isolate how many words there are. There will be a key for each */
1324 for( wordcount=0,c=val; *c; c++) {
1325 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1326 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
1328 if (*c == '\0') break;
1332 /* Allocate/increase storage to account for new keys */
1333 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
1334 * sizeof(struct berval *) );
1335 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
1336 if( keys ) ch_free( keys );
1339 /* Get a phonetic copy of each word */
1340 for( c=val,i=0; i<wordcount; c+=len+1 ) {
1342 if( len < SLAPD_APPROX_WORDLEN ) continue;
1343 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
1344 keys[keycount]->bv_val = phonetic( c );
1345 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
1352 keys[keycount] = NULL;
1355 return LDAP_SUCCESS;
1364 struct berval *prefix,
1366 struct berval ***keysp )
1370 struct berval **keys;
1372 /* Yes, this is necessary */
1373 val = UTF8normalize( ((struct berval *)assertValue),
1376 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
1379 return LDAP_SUCCESS;
1381 strip8bitChars( val );
1383 /* Isolate how many words there are. There will be a key for each */
1384 for( count=0,c=val; *c; c++) {
1385 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1386 if( len >= SLAPD_APPROX_WORDLEN ) count++;
1388 if (*c == '\0') break;
1392 /* Allocate storage for new keys */
1393 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
1395 /* Get a phonetic copy of each word */
1396 for( c=val,i=0; i<count; c+=len+1 ) {
1398 if( len < SLAPD_APPROX_WORDLEN ) continue;
1399 keys[i] = ber_bvstr( phonetic( c ) );
1408 return LDAP_SUCCESS;
1413 /* No other form of Approximate Matching is defined */
1421 struct berval *value,
1422 void *assertedValue )
1424 char *vapprox, *avapprox;
1427 /* Yes, this is necessary */
1428 s = UTF8normalize( value, UTF8_NOCASEFOLD );
1431 return LDAP_SUCCESS;
1434 /* Yes, this is necessary */
1435 t = UTF8normalize( ((struct berval *)assertedValue),
1440 return LDAP_SUCCESS;
1443 vapprox = phonetic( strip8bitChars( s ) );
1444 avapprox = phonetic( strip8bitChars( t ) );
1449 *matchp = strcmp( vapprox, avapprox );
1452 ch_free( avapprox );
1454 return LDAP_SUCCESS;
1463 struct berval *prefix,
1464 struct berval **values,
1465 struct berval ***keysp )
1468 struct berval **keys;
1471 for( i=0; values[i] != NULL; i++ ) {
1472 /* empty - just count them */
1475 /* we should have at least one value at this point */
1478 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
1480 /* Copy each value and run it through phonetic() */
1481 for( i=0; values[i] != NULL; i++ ) {
1482 /* Yes, this is necessary */
1483 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
1485 /* strip 8-bit chars and run through phonetic() */
1486 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1492 return LDAP_SUCCESS;
1502 struct berval *prefix,
1504 struct berval ***keysp )
1506 struct berval **keys;
1509 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1511 /* Yes, this is necessary */
1512 s = UTF8normalize( ((struct berval *)assertValue),
1517 /* strip 8-bit chars and run through phonetic() */
1518 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1524 return LDAP_SUCCESS;
1535 struct berval *value,
1536 void *assertedValue )
1538 *matchp = UTF8normcmp( value->bv_val,
1539 ((struct berval *) assertedValue)->bv_val,
1541 return LDAP_SUCCESS;
1545 caseExactIgnoreSubstringsMatch(
1550 struct berval *value,
1551 void *assertedValue )
1554 SubstringsAssertion *sub = NULL;
1558 char *nav, casefold;
1560 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1561 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1563 nav = UTF8normalize( value, casefold );
1569 left.bv_len = strlen( nav );
1571 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1577 /* Add up asserted input length */
1578 if( sub->sa_initial ) {
1579 inlen += sub->sa_initial->bv_len;
1582 for(i=0; sub->sa_any[i] != NULL; i++) {
1583 inlen += sub->sa_any[i]->bv_len;
1586 if( sub->sa_final ) {
1587 inlen += sub->sa_final->bv_len;
1590 if( sub->sa_initial ) {
1591 if( inlen > left.bv_len ) {
1596 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1597 sub->sa_initial->bv_len );
1603 left.bv_val += sub->sa_initial->bv_len;
1604 left.bv_len -= sub->sa_initial->bv_len;
1605 inlen -= sub->sa_initial->bv_len;
1608 if( sub->sa_final ) {
1609 if( inlen > left.bv_len ) {
1614 match = strncmp( sub->sa_final->bv_val,
1615 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1616 sub->sa_final->bv_len );
1622 left.bv_len -= sub->sa_final->bv_len;
1623 inlen -= sub->sa_final->bv_len;
1627 for(i=0; sub->sa_any[i]; i++) {
1632 if( inlen > left.bv_len ) {
1633 /* not enough length */
1638 if( sub->sa_any[i]->bv_len == 0 ) {
1642 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1649 idx = p - left.bv_val;
1650 assert( idx < left.bv_len );
1652 if( idx >= left.bv_len ) {
1653 /* this shouldn't happen */
1655 ch_free( sub->sa_final );
1656 ber_bvecfree( sub->sa_any );
1657 ch_free( sub->sa_initial );
1665 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1666 /* not enough left */
1671 match = strncmp( left.bv_val,
1672 sub->sa_any[i]->bv_val,
1673 sub->sa_any[i]->bv_len );
1681 left.bv_val += sub->sa_any[i]->bv_len;
1682 left.bv_len -= sub->sa_any[i]->bv_len;
1683 inlen -= sub->sa_any[i]->bv_len;
1690 ber_bvfree( sub->sa_final );
1691 ber_bvecfree( sub->sa_any );
1692 ber_bvfree( sub->sa_initial );
1696 return LDAP_SUCCESS;
1699 /* Index generation function */
1700 int caseExactIgnoreIndexer(
1705 struct berval *prefix,
1706 struct berval **values,
1707 struct berval ***keysp )
1712 struct berval **keys;
1713 HASH_CONTEXT HASHcontext;
1714 unsigned char HASHdigest[HASH_BYTES];
1715 struct berval digest;
1716 digest.bv_val = HASHdigest;
1717 digest.bv_len = sizeof(HASHdigest);
1719 for( i=0; values[i] != NULL; i++ ) {
1720 /* empty - just count them */
1723 /* we should have at least one value at this point */
1726 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1728 slen = strlen( syntax->ssyn_oid );
1729 mlen = strlen( mr->smr_oid );
1731 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1732 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1734 for( i=0; values[i] != NULL; i++ ) {
1735 struct berval *value;
1736 value = ber_bvstr( UTF8normalize( values[i],
1739 HASH_Init( &HASHcontext );
1740 if( prefix != NULL && prefix->bv_len > 0 ) {
1741 HASH_Update( &HASHcontext,
1742 prefix->bv_val, prefix->bv_len );
1744 HASH_Update( &HASHcontext,
1745 syntax->ssyn_oid, slen );
1746 HASH_Update( &HASHcontext,
1747 mr->smr_oid, mlen );
1748 HASH_Update( &HASHcontext,
1749 value->bv_val, value->bv_len );
1750 HASH_Final( HASHdigest, &HASHcontext );
1752 ber_bvfree( value );
1754 keys[i] = ber_bvdup( &digest );
1759 return LDAP_SUCCESS;
1762 /* Index generation function */
1763 int caseExactIgnoreFilter(
1768 struct berval *prefix,
1770 struct berval ***keysp )
1774 struct berval **keys;
1775 HASH_CONTEXT HASHcontext;
1776 unsigned char HASHdigest[HASH_BYTES];
1777 struct berval *value;
1778 struct berval digest;
1779 digest.bv_val = HASHdigest;
1780 digest.bv_len = sizeof(HASHdigest);
1782 slen = strlen( syntax->ssyn_oid );
1783 mlen = strlen( mr->smr_oid );
1785 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1786 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1788 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
1790 /* This usually happens if filter contains bad UTF8 */
1791 if( value == NULL ) {
1792 keys = ch_malloc( sizeof( struct berval * ) );
1794 return LDAP_SUCCESS;
1797 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1799 HASH_Init( &HASHcontext );
1800 if( prefix != NULL && prefix->bv_len > 0 ) {
1801 HASH_Update( &HASHcontext,
1802 prefix->bv_val, prefix->bv_len );
1804 HASH_Update( &HASHcontext,
1805 syntax->ssyn_oid, slen );
1806 HASH_Update( &HASHcontext,
1807 mr->smr_oid, mlen );
1808 HASH_Update( &HASHcontext,
1809 value->bv_val, value->bv_len );
1810 HASH_Final( HASHdigest, &HASHcontext );
1812 keys[0] = ber_bvdup( &digest );
1815 ber_bvfree( value );
1818 return LDAP_SUCCESS;
1821 /* Substrings Index generation function */
1822 int caseExactIgnoreSubstringsIndexer(
1827 struct berval *prefix,
1828 struct berval **values,
1829 struct berval ***keysp )
1834 struct berval **keys;
1835 struct berval **nvalues;
1837 HASH_CONTEXT HASHcontext;
1838 unsigned char HASHdigest[HASH_BYTES];
1839 struct berval digest;
1840 digest.bv_val = HASHdigest;
1841 digest.bv_len = sizeof(HASHdigest);
1845 for( i=0; values[i] != NULL; i++ ) {
1846 /* empty - just count them */
1849 /* we should have at least one value at this point */
1852 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1853 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1855 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1856 for( i=0; values[i] != NULL; i++ ) {
1857 nvalues[i] = ber_bvstr( UTF8normalize( values[i],
1863 for( i=0; values[i] != NULL; i++ ) {
1864 /* count number of indices to generate */
1865 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1869 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1870 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1871 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1872 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1874 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1878 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1879 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1880 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1884 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1885 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1886 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1887 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1889 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1895 /* no keys to generate */
1897 ber_bvecfree( nvalues );
1898 return LDAP_SUCCESS;
1901 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1903 slen = strlen( syntax->ssyn_oid );
1904 mlen = strlen( mr->smr_oid );
1907 for( i=0; values[i] != NULL; i++ ) {
1909 struct berval *value;
1911 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1915 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1916 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1918 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1919 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1921 for( j=0; j<max; j++ ) {
1922 HASH_Init( &HASHcontext );
1923 if( prefix != NULL && prefix->bv_len > 0 ) {
1924 HASH_Update( &HASHcontext,
1925 prefix->bv_val, prefix->bv_len );
1928 HASH_Update( &HASHcontext,
1929 &pre, sizeof( pre ) );
1930 HASH_Update( &HASHcontext,
1931 syntax->ssyn_oid, slen );
1932 HASH_Update( &HASHcontext,
1933 mr->smr_oid, mlen );
1934 HASH_Update( &HASHcontext,
1936 SLAP_INDEX_SUBSTR_MAXLEN );
1937 HASH_Final( HASHdigest, &HASHcontext );
1939 keys[nkeys++] = ber_bvdup( &digest );
1943 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1944 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1946 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1949 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1950 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1951 HASH_Init( &HASHcontext );
1952 if( prefix != NULL && prefix->bv_len > 0 ) {
1953 HASH_Update( &HASHcontext,
1954 prefix->bv_val, prefix->bv_len );
1956 HASH_Update( &HASHcontext,
1957 &pre, sizeof( pre ) );
1958 HASH_Update( &HASHcontext,
1959 syntax->ssyn_oid, slen );
1960 HASH_Update( &HASHcontext,
1961 mr->smr_oid, mlen );
1962 HASH_Update( &HASHcontext,
1964 HASH_Final( HASHdigest, &HASHcontext );
1966 keys[nkeys++] = ber_bvdup( &digest );
1969 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1970 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1971 HASH_Init( &HASHcontext );
1972 if( prefix != NULL && prefix->bv_len > 0 ) {
1973 HASH_Update( &HASHcontext,
1974 prefix->bv_val, prefix->bv_len );
1976 HASH_Update( &HASHcontext,
1977 &pre, sizeof( pre ) );
1978 HASH_Update( &HASHcontext,
1979 syntax->ssyn_oid, slen );
1980 HASH_Update( &HASHcontext,
1981 mr->smr_oid, mlen );
1982 HASH_Update( &HASHcontext,
1983 &value->bv_val[value->bv_len-j], j );
1984 HASH_Final( HASHdigest, &HASHcontext );
1986 keys[nkeys++] = ber_bvdup( &digest );
2001 ber_bvecfree( nvalues );
2003 return LDAP_SUCCESS;
2006 int caseExactIgnoreSubstringsFilter(
2011 struct berval *prefix,
2013 struct berval ***keysp )
2015 SubstringsAssertion *sa;
2017 ber_len_t nkeys = 0;
2018 size_t slen, mlen, klen;
2019 struct berval **keys;
2020 HASH_CONTEXT HASHcontext;
2021 unsigned char HASHdigest[HASH_BYTES];
2022 struct berval *value;
2023 struct berval digest;
2025 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
2026 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
2028 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
2031 return LDAP_SUCCESS;
2034 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2035 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2040 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2042 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2043 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2044 /* don't bother accounting for stepping */
2045 nkeys += sa->sa_any[i]->bv_len -
2046 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2051 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2052 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2058 ber_bvfree( sa->sa_final );
2059 ber_bvecfree( sa->sa_any );
2060 ber_bvfree( sa->sa_initial );
2063 return LDAP_SUCCESS;
2066 digest.bv_val = HASHdigest;
2067 digest.bv_len = sizeof(HASHdigest);
2069 slen = strlen( syntax->ssyn_oid );
2070 mlen = strlen( mr->smr_oid );
2072 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2075 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2076 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2078 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2079 value = sa->sa_initial;
2081 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2082 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2084 HASH_Init( &HASHcontext );
2085 if( prefix != NULL && prefix->bv_len > 0 ) {
2086 HASH_Update( &HASHcontext,
2087 prefix->bv_val, prefix->bv_len );
2089 HASH_Update( &HASHcontext,
2090 &pre, sizeof( pre ) );
2091 HASH_Update( &HASHcontext,
2092 syntax->ssyn_oid, slen );
2093 HASH_Update( &HASHcontext,
2094 mr->smr_oid, mlen );
2095 HASH_Update( &HASHcontext,
2096 value->bv_val, klen );
2097 HASH_Final( HASHdigest, &HASHcontext );
2099 keys[nkeys++] = ber_bvdup( &digest );
2102 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2104 pre = SLAP_INDEX_SUBSTR_PREFIX;
2105 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2107 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2108 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2112 value = sa->sa_any[i];
2115 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2116 j += SLAP_INDEX_SUBSTR_STEP )
2118 HASH_Init( &HASHcontext );
2119 if( prefix != NULL && prefix->bv_len > 0 ) {
2120 HASH_Update( &HASHcontext,
2121 prefix->bv_val, prefix->bv_len );
2123 HASH_Update( &HASHcontext,
2124 &pre, sizeof( pre ) );
2125 HASH_Update( &HASHcontext,
2126 syntax->ssyn_oid, slen );
2127 HASH_Update( &HASHcontext,
2128 mr->smr_oid, mlen );
2129 HASH_Update( &HASHcontext,
2130 &value->bv_val[j], klen );
2131 HASH_Final( HASHdigest, &HASHcontext );
2133 keys[nkeys++] = ber_bvdup( &digest );
2139 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2140 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2142 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2143 value = sa->sa_final;
2145 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2146 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2148 HASH_Init( &HASHcontext );
2149 if( prefix != NULL && prefix->bv_len > 0 ) {
2150 HASH_Update( &HASHcontext,
2151 prefix->bv_val, prefix->bv_len );
2153 HASH_Update( &HASHcontext,
2154 &pre, sizeof( pre ) );
2155 HASH_Update( &HASHcontext,
2156 syntax->ssyn_oid, slen );
2157 HASH_Update( &HASHcontext,
2158 mr->smr_oid, mlen );
2159 HASH_Update( &HASHcontext,
2160 &value->bv_val[value->bv_len-klen], klen );
2161 HASH_Final( HASHdigest, &HASHcontext );
2163 keys[nkeys++] = ber_bvdup( &digest );
2173 ber_bvfree( sa->sa_final );
2174 ber_bvecfree( sa->sa_any );
2175 ber_bvfree( sa->sa_initial );
2178 return LDAP_SUCCESS;
2187 struct berval *value,
2188 void *assertedValue )
2190 *matchp = UTF8normcmp( value->bv_val,
2191 ((struct berval *) assertedValue)->bv_val,
2193 return LDAP_SUCCESS;
2199 struct berval *val )
2203 if( val->bv_len == 0 ) {
2204 /* disallow empty strings */
2205 return LDAP_INVALID_SYNTAX;
2208 if( OID_LEADCHAR(val->bv_val[0]) ) {
2210 for(i=1; i < val->bv_len; i++) {
2211 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2212 if( dot++ ) return 1;
2213 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2216 return LDAP_INVALID_SYNTAX;
2220 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2222 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2223 for(i=1; i < val->bv_len; i++) {
2224 if( !DESC_CHAR(val->bv_val[i] ) ) {
2225 return LDAP_INVALID_SYNTAX;
2229 return LDAP_SUCCESS;
2232 return LDAP_INVALID_SYNTAX;
2241 struct berval *value,
2242 void *assertedValue )
2245 int vsign=0, avsign=0;
2246 struct berval *asserted;
2247 ber_len_t vlen, avlen;
2250 /* Start off pessimistic */
2253 /* Skip past leading spaces/zeros, and get the sign of the *value number */
2255 vlen = value->bv_len;
2257 if( ASCII_SPACE(*v) || ( *v == '0' )) {
2258 /* empty -- skip spaces */
2260 else if ( *v == '+' ) {
2263 else if ( *v == '-' ) {
2266 else if ( ASCII_DIGIT(*v) ) {
2267 if ( vsign == 0 ) vsign = 1;
2275 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
2277 asserted = (struct berval *) assertedValue;
2278 av = asserted->bv_val;
2279 avlen = asserted->bv_len;
2281 if( ASCII_SPACE(*av) || ( *av == '0' )) {
2282 /* empty -- skip spaces */
2284 else if ( *av == '+' ) {
2287 else if ( *av == '-' ) {
2290 else if ( ASCII_DIGIT(*av) ) {
2291 if ( avsign == 0 ) avsign = 1;
2299 /* The two ?sign vars are now one of :
2300 -2 negative non-zero number
2302 0 0 collapse these three to 0
2304 +2 positive non-zero number
2306 if ( abs( vsign ) == 1 ) vsign = 0;
2307 if ( abs( avsign ) == 1 ) avsign = 0;
2309 if( vsign != avsign ) return LDAP_SUCCESS;
2311 /* Check the significant digits */
2312 while( vlen && avlen ) {
2313 if( *v != *av ) break;
2320 /* If all digits compared equal, the numbers are equal */
2321 if(( vlen == 0 ) && ( avlen == 0 )) {
2324 return LDAP_SUCCESS;
2330 struct berval *val )
2334 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2336 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
2337 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2338 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2339 return LDAP_INVALID_SYNTAX;
2342 for( i=1; i < val->bv_len; i++ ) {
2343 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2346 return LDAP_SUCCESS;
2353 struct berval **normalized )
2357 struct berval *newval;
2364 /* Ignore leading spaces */
2365 while ( len && ( *p == ' ' )) {
2372 negative = ( *p == '-' );
2373 if(( *p == '-' ) || ( *p == '+' )) {
2379 /* Ignore leading zeros */
2380 while ( len && ( *p == '0' )) {
2385 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2387 /* If there are no non-zero digits left, the number is zero, otherwise
2388 allocate space for the number and copy it into the buffer */
2390 newval->bv_val = ch_strdup("0");
2394 newval->bv_len = len+negative;
2395 newval->bv_val = ch_malloc( newval->bv_len );
2397 newval->bv_val[0] = '-';
2399 memcpy( newval->bv_val + negative, p, len );
2402 *normalized = newval;
2403 return LDAP_SUCCESS;
2406 /* Index generation function */
2412 struct berval *prefix,
2413 struct berval **values,
2414 struct berval ***keysp )
2417 struct berval **keys;
2419 /* we should have at least one value at this point */
2420 assert( values != NULL && values[0] != NULL );
2422 for( i=0; values[i] != NULL; i++ ) {
2423 /* empty -- just count them */
2426 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2428 for( i=0; values[i] != NULL; i++ ) {
2429 integerNormalize( syntax, values[i], &keys[i] );
2434 return LDAP_SUCCESS;
2437 /* Index generation function */
2443 struct berval *prefix,
2445 struct berval ***keysp )
2447 struct berval **keys;
2449 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2450 integerNormalize( syntax, assertValue, &keys[0] );
2454 return LDAP_SUCCESS;
2459 countryStringValidate(
2461 struct berval *val )
2463 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2465 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2466 return LDAP_INVALID_SYNTAX;
2468 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2469 return LDAP_INVALID_SYNTAX;
2472 return LDAP_SUCCESS;
2476 printableStringValidate(
2478 struct berval *val )
2482 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2484 for(i=0; i < val->bv_len; i++) {
2485 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2486 return LDAP_INVALID_SYNTAX;
2490 return LDAP_SUCCESS;
2494 printablesStringValidate(
2496 struct berval *val )
2500 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2502 for(i=0; i < val->bv_len; i++) {
2503 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2504 return LDAP_INVALID_SYNTAX;
2508 return LDAP_SUCCESS;
2514 struct berval *val )
2518 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2520 for(i=0; i < val->bv_len; i++) {
2521 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2524 return LDAP_SUCCESS;
2531 struct berval **normalized )
2533 struct berval *newval;
2536 newval = ch_malloc( sizeof( struct berval ) );
2540 /* Ignore initial whitespace */
2541 while ( ASCII_SPACE( *p ) ) {
2547 return LDAP_INVALID_SYNTAX;
2550 newval->bv_val = ch_strdup( p );
2551 p = q = newval->bv_val;
2554 if ( ASCII_SPACE( *p ) ) {
2557 /* Ignore the extra whitespace */
2558 while ( ASCII_SPACE( *p ) ) {
2566 assert( *newval->bv_val );
2567 assert( newval->bv_val < p );
2570 /* cannot start with a space */
2571 assert( !ASCII_SPACE(*newval->bv_val) );
2574 * If the string ended in space, backup the pointer one
2575 * position. One is enough because the above loop collapsed
2576 * all whitespace to a single space.
2579 if ( ASCII_SPACE( q[-1] ) ) {
2583 /* cannot end with a space */
2584 assert( !ASCII_SPACE( q[-1] ) );
2586 /* null terminate */
2589 newval->bv_len = q - newval->bv_val;
2590 *normalized = newval;
2592 return LDAP_SUCCESS;
2601 struct berval *value,
2602 void *assertedValue )
2604 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2607 match = strncmp( value->bv_val,
2608 ((struct berval *) assertedValue)->bv_val,
2613 return LDAP_SUCCESS;
2617 caseExactIA5SubstringsMatch(
2622 struct berval *value,
2623 void *assertedValue )
2626 SubstringsAssertion *sub = assertedValue;
2627 struct berval left = *value;
2631 /* Add up asserted input length */
2632 if( sub->sa_initial ) {
2633 inlen += sub->sa_initial->bv_len;
2636 for(i=0; sub->sa_any[i] != NULL; i++) {
2637 inlen += sub->sa_any[i]->bv_len;
2640 if( sub->sa_final ) {
2641 inlen += sub->sa_final->bv_len;
2644 if( sub->sa_initial ) {
2645 if( inlen > left.bv_len ) {
2650 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2651 sub->sa_initial->bv_len );
2657 left.bv_val += sub->sa_initial->bv_len;
2658 left.bv_len -= sub->sa_initial->bv_len;
2659 inlen -= sub->sa_initial->bv_len;
2662 if( sub->sa_final ) {
2663 if( inlen > left.bv_len ) {
2668 match = strncmp( sub->sa_final->bv_val,
2669 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2670 sub->sa_final->bv_len );
2676 left.bv_len -= sub->sa_final->bv_len;
2677 inlen -= sub->sa_final->bv_len;
2681 for(i=0; sub->sa_any[i]; i++) {
2686 if( inlen > left.bv_len ) {
2687 /* not enough length */
2692 if( sub->sa_any[i]->bv_len == 0 ) {
2696 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2703 idx = p - left.bv_val;
2704 assert( idx < left.bv_len );
2706 if( idx >= left.bv_len ) {
2707 /* this shouldn't happen */
2714 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2715 /* not enough left */
2720 match = strncmp( left.bv_val,
2721 sub->sa_any[i]->bv_val,
2722 sub->sa_any[i]->bv_len );
2730 left.bv_val += sub->sa_any[i]->bv_len;
2731 left.bv_len -= sub->sa_any[i]->bv_len;
2732 inlen -= sub->sa_any[i]->bv_len;
2738 return LDAP_SUCCESS;
2741 /* Index generation function */
2742 int caseExactIA5Indexer(
2747 struct berval *prefix,
2748 struct berval **values,
2749 struct berval ***keysp )
2753 struct berval **keys;
2754 HASH_CONTEXT HASHcontext;
2755 unsigned char HASHdigest[HASH_BYTES];
2756 struct berval digest;
2757 digest.bv_val = HASHdigest;
2758 digest.bv_len = sizeof(HASHdigest);
2760 for( i=0; values[i] != NULL; i++ ) {
2761 /* empty - just count them */
2764 /* we should have at least one value at this point */
2767 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2769 slen = strlen( syntax->ssyn_oid );
2770 mlen = strlen( mr->smr_oid );
2772 for( i=0; values[i] != NULL; i++ ) {
2773 struct berval *value = values[i];
2775 HASH_Init( &HASHcontext );
2776 if( prefix != NULL && prefix->bv_len > 0 ) {
2777 HASH_Update( &HASHcontext,
2778 prefix->bv_val, prefix->bv_len );
2780 HASH_Update( &HASHcontext,
2781 syntax->ssyn_oid, slen );
2782 HASH_Update( &HASHcontext,
2783 mr->smr_oid, mlen );
2784 HASH_Update( &HASHcontext,
2785 value->bv_val, value->bv_len );
2786 HASH_Final( HASHdigest, &HASHcontext );
2788 keys[i] = ber_bvdup( &digest );
2793 return LDAP_SUCCESS;
2796 /* Index generation function */
2797 int caseExactIA5Filter(
2802 struct berval *prefix,
2804 struct berval ***keysp )
2807 struct berval **keys;
2808 HASH_CONTEXT HASHcontext;
2809 unsigned char HASHdigest[HASH_BYTES];
2810 struct berval *value;
2811 struct berval digest;
2812 digest.bv_val = HASHdigest;
2813 digest.bv_len = sizeof(HASHdigest);
2815 slen = strlen( syntax->ssyn_oid );
2816 mlen = strlen( mr->smr_oid );
2818 value = (struct berval *) assertValue;
2820 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2822 HASH_Init( &HASHcontext );
2823 if( prefix != NULL && prefix->bv_len > 0 ) {
2824 HASH_Update( &HASHcontext,
2825 prefix->bv_val, prefix->bv_len );
2827 HASH_Update( &HASHcontext,
2828 syntax->ssyn_oid, slen );
2829 HASH_Update( &HASHcontext,
2830 mr->smr_oid, mlen );
2831 HASH_Update( &HASHcontext,
2832 value->bv_val, value->bv_len );
2833 HASH_Final( HASHdigest, &HASHcontext );
2835 keys[0] = ber_bvdup( &digest );
2839 return LDAP_SUCCESS;
2842 /* Substrings Index generation function */
2843 int caseExactIA5SubstringsIndexer(
2848 struct berval *prefix,
2849 struct berval **values,
2850 struct berval ***keysp )
2854 struct berval **keys;
2855 HASH_CONTEXT HASHcontext;
2856 unsigned char HASHdigest[HASH_BYTES];
2857 struct berval digest;
2858 digest.bv_val = HASHdigest;
2859 digest.bv_len = sizeof(HASHdigest);
2861 /* we should have at least one value at this point */
2862 assert( values != NULL && values[0] != NULL );
2865 for( i=0; values[i] != NULL; i++ ) {
2866 /* count number of indices to generate */
2867 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2871 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2872 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2873 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2874 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2876 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2880 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2881 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2882 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2886 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2887 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2888 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2889 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2891 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2897 /* no keys to generate */
2899 return LDAP_SUCCESS;
2902 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2904 slen = strlen( syntax->ssyn_oid );
2905 mlen = strlen( mr->smr_oid );
2908 for( i=0; values[i] != NULL; i++ ) {
2910 struct berval *value;
2913 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2915 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2916 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2918 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2919 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2921 for( j=0; j<max; j++ ) {
2922 HASH_Init( &HASHcontext );
2923 if( prefix != NULL && prefix->bv_len > 0 ) {
2924 HASH_Update( &HASHcontext,
2925 prefix->bv_val, prefix->bv_len );
2928 HASH_Update( &HASHcontext,
2929 &pre, sizeof( pre ) );
2930 HASH_Update( &HASHcontext,
2931 syntax->ssyn_oid, slen );
2932 HASH_Update( &HASHcontext,
2933 mr->smr_oid, mlen );
2934 HASH_Update( &HASHcontext,
2936 SLAP_INDEX_SUBSTR_MAXLEN );
2937 HASH_Final( HASHdigest, &HASHcontext );
2939 keys[nkeys++] = ber_bvdup( &digest );
2943 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2944 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2946 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2949 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2950 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2951 HASH_Init( &HASHcontext );
2952 if( prefix != NULL && prefix->bv_len > 0 ) {
2953 HASH_Update( &HASHcontext,
2954 prefix->bv_val, prefix->bv_len );
2956 HASH_Update( &HASHcontext,
2957 &pre, sizeof( pre ) );
2958 HASH_Update( &HASHcontext,
2959 syntax->ssyn_oid, slen );
2960 HASH_Update( &HASHcontext,
2961 mr->smr_oid, mlen );
2962 HASH_Update( &HASHcontext,
2964 HASH_Final( HASHdigest, &HASHcontext );
2966 keys[nkeys++] = ber_bvdup( &digest );
2969 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2970 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2971 HASH_Init( &HASHcontext );
2972 if( prefix != NULL && prefix->bv_len > 0 ) {
2973 HASH_Update( &HASHcontext,
2974 prefix->bv_val, prefix->bv_len );
2976 HASH_Update( &HASHcontext,
2977 &pre, sizeof( pre ) );
2978 HASH_Update( &HASHcontext,
2979 syntax->ssyn_oid, slen );
2980 HASH_Update( &HASHcontext,
2981 mr->smr_oid, mlen );
2982 HASH_Update( &HASHcontext,
2983 &value->bv_val[value->bv_len-j], j );
2984 HASH_Final( HASHdigest, &HASHcontext );
2986 keys[nkeys++] = ber_bvdup( &digest );
3000 return LDAP_SUCCESS;
3003 int caseExactIA5SubstringsFilter(
3008 struct berval *prefix,
3010 struct berval ***keysp )
3012 SubstringsAssertion *sa = assertValue;
3014 ber_len_t nkeys = 0;
3015 size_t slen, mlen, klen;
3016 struct berval **keys;
3017 HASH_CONTEXT HASHcontext;
3018 unsigned char HASHdigest[HASH_BYTES];
3019 struct berval *value;
3020 struct berval digest;
3022 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
3023 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3028 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
3030 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3031 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3032 /* don't bother accounting for stepping */
3033 nkeys += sa->sa_any[i]->bv_len -
3034 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3039 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3040 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3047 return LDAP_SUCCESS;
3050 digest.bv_val = HASHdigest;
3051 digest.bv_len = sizeof(HASHdigest);
3053 slen = strlen( syntax->ssyn_oid );
3054 mlen = strlen( mr->smr_oid );
3056 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3059 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
3060 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3062 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3063 value = sa->sa_initial;
3065 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3066 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3068 HASH_Init( &HASHcontext );
3069 if( prefix != NULL && prefix->bv_len > 0 ) {
3070 HASH_Update( &HASHcontext,
3071 prefix->bv_val, prefix->bv_len );
3073 HASH_Update( &HASHcontext,
3074 &pre, sizeof( pre ) );
3075 HASH_Update( &HASHcontext,
3076 syntax->ssyn_oid, slen );
3077 HASH_Update( &HASHcontext,
3078 mr->smr_oid, mlen );
3079 HASH_Update( &HASHcontext,
3080 value->bv_val, klen );
3081 HASH_Final( HASHdigest, &HASHcontext );
3083 keys[nkeys++] = ber_bvdup( &digest );
3086 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
3088 pre = SLAP_INDEX_SUBSTR_PREFIX;
3089 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3091 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3092 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3096 value = sa->sa_any[i];
3099 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3100 j += SLAP_INDEX_SUBSTR_STEP )
3102 HASH_Init( &HASHcontext );
3103 if( prefix != NULL && prefix->bv_len > 0 ) {
3104 HASH_Update( &HASHcontext,
3105 prefix->bv_val, prefix->bv_len );
3107 HASH_Update( &HASHcontext,
3108 &pre, sizeof( pre ) );
3109 HASH_Update( &HASHcontext,
3110 syntax->ssyn_oid, slen );
3111 HASH_Update( &HASHcontext,
3112 mr->smr_oid, mlen );
3113 HASH_Update( &HASHcontext,
3114 &value->bv_val[j], klen );
3115 HASH_Final( HASHdigest, &HASHcontext );
3117 keys[nkeys++] = ber_bvdup( &digest );
3122 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3123 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3125 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3126 value = sa->sa_final;
3128 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3129 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3131 HASH_Init( &HASHcontext );
3132 if( prefix != NULL && prefix->bv_len > 0 ) {
3133 HASH_Update( &HASHcontext,
3134 prefix->bv_val, prefix->bv_len );
3136 HASH_Update( &HASHcontext,
3137 &pre, sizeof( pre ) );
3138 HASH_Update( &HASHcontext,
3139 syntax->ssyn_oid, slen );
3140 HASH_Update( &HASHcontext,
3141 mr->smr_oid, mlen );
3142 HASH_Update( &HASHcontext,
3143 &value->bv_val[value->bv_len-klen], klen );
3144 HASH_Final( HASHdigest, &HASHcontext );
3146 keys[nkeys++] = ber_bvdup( &digest );
3157 return LDAP_SUCCESS;
3166 struct berval *value,
3167 void *assertedValue )
3169 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3171 if( match == 0 && value->bv_len ) {
3172 match = strncasecmp( value->bv_val,
3173 ((struct berval *) assertedValue)->bv_val,
3178 return LDAP_SUCCESS;
3182 caseIgnoreIA5SubstringsMatch(
3187 struct berval *value,
3188 void *assertedValue )
3191 SubstringsAssertion *sub = assertedValue;
3192 struct berval left = *value;
3196 /* Add up asserted input length */
3197 if( sub->sa_initial ) {
3198 inlen += sub->sa_initial->bv_len;
3201 for(i=0; sub->sa_any[i] != NULL; i++) {
3202 inlen += sub->sa_any[i]->bv_len;
3205 if( sub->sa_final ) {
3206 inlen += sub->sa_final->bv_len;
3209 if( sub->sa_initial ) {
3210 if( inlen > left.bv_len ) {
3215 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3216 sub->sa_initial->bv_len );
3222 left.bv_val += sub->sa_initial->bv_len;
3223 left.bv_len -= sub->sa_initial->bv_len;
3224 inlen -= sub->sa_initial->bv_len;
3227 if( sub->sa_final ) {
3228 if( inlen > left.bv_len ) {
3233 match = strncasecmp( sub->sa_final->bv_val,
3234 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3235 sub->sa_final->bv_len );
3241 left.bv_len -= sub->sa_final->bv_len;
3242 inlen -= sub->sa_final->bv_len;
3246 for(i=0; sub->sa_any[i]; i++) {
3251 if( inlen > left.bv_len ) {
3252 /* not enough length */
3257 if( sub->sa_any[i]->bv_len == 0 ) {
3261 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3268 idx = p - left.bv_val;
3269 assert( idx < left.bv_len );
3271 if( idx >= left.bv_len ) {
3272 /* this shouldn't happen */
3279 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3280 /* not enough left */
3285 match = strncasecmp( left.bv_val,
3286 sub->sa_any[i]->bv_val,
3287 sub->sa_any[i]->bv_len );
3296 left.bv_val += sub->sa_any[i]->bv_len;
3297 left.bv_len -= sub->sa_any[i]->bv_len;
3298 inlen -= sub->sa_any[i]->bv_len;
3304 return LDAP_SUCCESS;
3307 /* Index generation function */
3308 int caseIgnoreIA5Indexer(
3313 struct berval *prefix,
3314 struct berval **values,
3315 struct berval ***keysp )
3319 struct berval **keys;
3320 HASH_CONTEXT HASHcontext;
3321 unsigned char HASHdigest[HASH_BYTES];
3322 struct berval digest;
3323 digest.bv_val = HASHdigest;
3324 digest.bv_len = sizeof(HASHdigest);
3326 /* we should have at least one value at this point */
3327 assert( values != NULL && values[0] != NULL );
3329 for( i=0; values[i] != NULL; i++ ) {
3330 /* just count them */
3333 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3335 slen = strlen( syntax->ssyn_oid );
3336 mlen = strlen( mr->smr_oid );
3338 for( i=0; values[i] != NULL; i++ ) {
3339 struct berval *value = ber_bvdup( values[i] );
3340 ldap_pvt_str2upper( value->bv_val );
3342 HASH_Init( &HASHcontext );
3343 if( prefix != NULL && prefix->bv_len > 0 ) {
3344 HASH_Update( &HASHcontext,
3345 prefix->bv_val, prefix->bv_len );
3347 HASH_Update( &HASHcontext,
3348 syntax->ssyn_oid, slen );
3349 HASH_Update( &HASHcontext,
3350 mr->smr_oid, mlen );
3351 HASH_Update( &HASHcontext,
3352 value->bv_val, value->bv_len );
3353 HASH_Final( HASHdigest, &HASHcontext );
3355 ber_bvfree( value );
3357 keys[i] = ber_bvdup( &digest );
3362 return LDAP_SUCCESS;
3365 /* Index generation function */
3366 int caseIgnoreIA5Filter(
3371 struct berval *prefix,
3373 struct berval ***keysp )
3376 struct berval **keys;
3377 HASH_CONTEXT HASHcontext;
3378 unsigned char HASHdigest[HASH_BYTES];
3379 struct berval *value;
3380 struct berval digest;
3381 digest.bv_val = HASHdigest;
3382 digest.bv_len = sizeof(HASHdigest);
3384 slen = strlen( syntax->ssyn_oid );
3385 mlen = strlen( mr->smr_oid );
3387 value = ber_bvdup( (struct berval *) assertValue );
3388 ldap_pvt_str2upper( value->bv_val );
3390 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3392 HASH_Init( &HASHcontext );
3393 if( prefix != NULL && prefix->bv_len > 0 ) {
3394 HASH_Update( &HASHcontext,
3395 prefix->bv_val, prefix->bv_len );
3397 HASH_Update( &HASHcontext,
3398 syntax->ssyn_oid, slen );
3399 HASH_Update( &HASHcontext,
3400 mr->smr_oid, mlen );
3401 HASH_Update( &HASHcontext,
3402 value->bv_val, value->bv_len );
3403 HASH_Final( HASHdigest, &HASHcontext );
3405 keys[0] = ber_bvdup( &digest );
3408 ber_bvfree( value );
3412 return LDAP_SUCCESS;
3415 /* Substrings Index generation function */
3416 int caseIgnoreIA5SubstringsIndexer(
3421 struct berval *prefix,
3422 struct berval **values,
3423 struct berval ***keysp )
3427 struct berval **keys;
3428 HASH_CONTEXT HASHcontext;
3429 unsigned char HASHdigest[HASH_BYTES];
3430 struct berval digest;
3431 digest.bv_val = HASHdigest;
3432 digest.bv_len = sizeof(HASHdigest);
3434 /* we should have at least one value at this point */
3435 assert( values != NULL && values[0] != NULL );
3438 for( i=0; values[i] != NULL; i++ ) {
3439 /* count number of indices to generate */
3440 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3444 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3445 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3446 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3447 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3449 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3453 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3454 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3455 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3459 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3460 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3461 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3462 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3464 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3470 /* no keys to generate */
3472 return LDAP_SUCCESS;
3475 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3477 slen = strlen( syntax->ssyn_oid );
3478 mlen = strlen( mr->smr_oid );
3481 for( i=0; values[i] != NULL; i++ ) {
3483 struct berval *value;
3485 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3487 value = ber_bvdup( values[i] );
3488 ldap_pvt_str2upper( value->bv_val );
3490 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3491 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3493 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3494 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3496 for( j=0; j<max; j++ ) {
3497 HASH_Init( &HASHcontext );
3498 if( prefix != NULL && prefix->bv_len > 0 ) {
3499 HASH_Update( &HASHcontext,
3500 prefix->bv_val, prefix->bv_len );
3503 HASH_Update( &HASHcontext,
3504 &pre, sizeof( pre ) );
3505 HASH_Update( &HASHcontext,
3506 syntax->ssyn_oid, slen );
3507 HASH_Update( &HASHcontext,
3508 mr->smr_oid, mlen );
3509 HASH_Update( &HASHcontext,
3511 SLAP_INDEX_SUBSTR_MAXLEN );
3512 HASH_Final( HASHdigest, &HASHcontext );
3514 keys[nkeys++] = ber_bvdup( &digest );
3518 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3519 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3521 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3524 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3525 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3526 HASH_Init( &HASHcontext );
3527 if( prefix != NULL && prefix->bv_len > 0 ) {
3528 HASH_Update( &HASHcontext,
3529 prefix->bv_val, prefix->bv_len );
3531 HASH_Update( &HASHcontext,
3532 &pre, sizeof( pre ) );
3533 HASH_Update( &HASHcontext,
3534 syntax->ssyn_oid, slen );
3535 HASH_Update( &HASHcontext,
3536 mr->smr_oid, mlen );
3537 HASH_Update( &HASHcontext,
3539 HASH_Final( HASHdigest, &HASHcontext );
3541 keys[nkeys++] = ber_bvdup( &digest );
3544 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3545 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3546 HASH_Init( &HASHcontext );
3547 if( prefix != NULL && prefix->bv_len > 0 ) {
3548 HASH_Update( &HASHcontext,
3549 prefix->bv_val, prefix->bv_len );
3551 HASH_Update( &HASHcontext,
3552 &pre, sizeof( pre ) );
3553 HASH_Update( &HASHcontext,
3554 syntax->ssyn_oid, slen );
3555 HASH_Update( &HASHcontext,
3556 mr->smr_oid, mlen );
3557 HASH_Update( &HASHcontext,
3558 &value->bv_val[value->bv_len-j], j );
3559 HASH_Final( HASHdigest, &HASHcontext );
3561 keys[nkeys++] = ber_bvdup( &digest );
3566 ber_bvfree( value );
3577 return LDAP_SUCCESS;
3580 int caseIgnoreIA5SubstringsFilter(
3585 struct berval *prefix,
3587 struct berval ***keysp )
3589 SubstringsAssertion *sa = assertValue;
3591 ber_len_t nkeys = 0;
3592 size_t slen, mlen, klen;
3593 struct berval **keys;
3594 HASH_CONTEXT HASHcontext;
3595 unsigned char HASHdigest[HASH_BYTES];
3596 struct berval *value;
3597 struct berval digest;
3599 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3600 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3605 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3607 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3608 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3609 /* don't bother accounting for stepping */
3610 nkeys += sa->sa_any[i]->bv_len -
3611 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3616 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3617 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3624 return LDAP_SUCCESS;
3627 digest.bv_val = HASHdigest;
3628 digest.bv_len = sizeof(HASHdigest);
3630 slen = strlen( syntax->ssyn_oid );
3631 mlen = strlen( mr->smr_oid );
3633 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3636 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3637 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3639 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3640 value = ber_bvdup( sa->sa_initial );
3641 ldap_pvt_str2upper( value->bv_val );
3643 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3644 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3646 HASH_Init( &HASHcontext );
3647 if( prefix != NULL && prefix->bv_len > 0 ) {
3648 HASH_Update( &HASHcontext,
3649 prefix->bv_val, prefix->bv_len );
3651 HASH_Update( &HASHcontext,
3652 &pre, sizeof( pre ) );
3653 HASH_Update( &HASHcontext,
3654 syntax->ssyn_oid, slen );
3655 HASH_Update( &HASHcontext,
3656 mr->smr_oid, mlen );
3657 HASH_Update( &HASHcontext,
3658 value->bv_val, klen );
3659 HASH_Final( HASHdigest, &HASHcontext );
3661 ber_bvfree( value );
3662 keys[nkeys++] = ber_bvdup( &digest );
3665 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3667 pre = SLAP_INDEX_SUBSTR_PREFIX;
3668 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3670 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3671 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3675 value = ber_bvdup( sa->sa_any[i] );
3676 ldap_pvt_str2upper( value->bv_val );
3679 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3680 j += SLAP_INDEX_SUBSTR_STEP )
3682 HASH_Init( &HASHcontext );
3683 if( prefix != NULL && prefix->bv_len > 0 ) {
3684 HASH_Update( &HASHcontext,
3685 prefix->bv_val, prefix->bv_len );
3687 HASH_Update( &HASHcontext,
3688 &pre, sizeof( pre ) );
3689 HASH_Update( &HASHcontext,
3690 syntax->ssyn_oid, slen );
3691 HASH_Update( &HASHcontext,
3692 mr->smr_oid, mlen );
3693 HASH_Update( &HASHcontext,
3694 &value->bv_val[j], klen );
3695 HASH_Final( HASHdigest, &HASHcontext );
3697 keys[nkeys++] = ber_bvdup( &digest );
3700 ber_bvfree( value );
3704 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3705 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3707 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3708 value = ber_bvdup( sa->sa_final );
3709 ldap_pvt_str2upper( value->bv_val );
3711 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3712 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3714 HASH_Init( &HASHcontext );
3715 if( prefix != NULL && prefix->bv_len > 0 ) {
3716 HASH_Update( &HASHcontext,
3717 prefix->bv_val, prefix->bv_len );
3719 HASH_Update( &HASHcontext,
3720 &pre, sizeof( pre ) );
3721 HASH_Update( &HASHcontext,
3722 syntax->ssyn_oid, slen );
3723 HASH_Update( &HASHcontext,
3724 mr->smr_oid, mlen );
3725 HASH_Update( &HASHcontext,
3726 &value->bv_val[value->bv_len-klen], klen );
3727 HASH_Final( HASHdigest, &HASHcontext );
3729 ber_bvfree( value );
3730 keys[nkeys++] = ber_bvdup( &digest );
3741 return LDAP_SUCCESS;
3745 numericStringValidate(
3751 for(i=0; i < in->bv_len; i++) {
3752 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3753 return LDAP_INVALID_SYNTAX;
3757 return LDAP_SUCCESS;
3761 numericStringNormalize(
3764 struct berval **normalized )
3766 /* removal all spaces */
3767 struct berval *newval;
3770 newval = ch_malloc( sizeof( struct berval ) );
3771 newval->bv_val = ch_malloc( val->bv_len + 1 );
3777 if ( ASCII_SPACE( *p ) ) {
3778 /* Ignore whitespace */
3785 /* we should have copied no more then is in val */
3786 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3788 /* null terminate */
3791 newval->bv_len = q - newval->bv_val;
3792 *normalized = newval;
3794 return LDAP_SUCCESS;
3798 objectIdentifierFirstComponentMatch(
3803 struct berval *value,
3804 void *assertedValue )
3806 int rc = LDAP_SUCCESS;
3808 struct berval *asserted = (struct berval *) assertedValue;
3812 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3813 return LDAP_INVALID_SYNTAX;
3816 /* trim leading white space */
3817 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3821 /* grab next word */
3822 oid.bv_val = &value->bv_val[i];
3823 oid.bv_len = value->bv_len - i;
3824 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3829 /* insert attributeTypes, objectclass check here */
3830 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3831 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3834 char *stored = ch_malloc( oid.bv_len + 1 );
3835 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3836 stored[oid.bv_len] = '\0';
3838 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3839 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3840 MatchingRule *stored_mr = mr_find( stored );
3842 if( asserted_mr == NULL ) {
3843 rc = SLAPD_COMPARE_UNDEFINED;
3845 match = asserted_mr != stored_mr;
3848 } else if ( !strcmp( syntax->ssyn_oid,
3849 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3851 AttributeType *asserted_at = at_find( asserted->bv_val );
3852 AttributeType *stored_at = at_find( stored );
3854 if( asserted_at == NULL ) {
3855 rc = SLAPD_COMPARE_UNDEFINED;
3857 match = asserted_at != stored_at;
3860 } else if ( !strcmp( syntax->ssyn_oid,
3861 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3863 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3864 ObjectClass *stored_oc = oc_find( stored );
3866 if( asserted_oc == NULL ) {
3867 rc = SLAPD_COMPARE_UNDEFINED;
3869 match = asserted_oc != stored_oc;
3877 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3878 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3879 match, value->bv_val, asserted->bv_val ));
3881 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3882 "%d\n\t\"%s\"\n\t\"%s\"\n",
3883 match, value->bv_val, asserted->bv_val );
3887 if( rc == LDAP_SUCCESS ) *matchp = match;
3897 struct berval *value,
3898 void *assertedValue )
3900 long lValue, lAssertedValue;
3902 /* safe to assume integers are NUL terminated? */
3903 lValue = strtoul(value->bv_val, NULL, 10);
3904 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3905 return LDAP_CONSTRAINT_VIOLATION;
3907 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3908 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3909 return LDAP_CONSTRAINT_VIOLATION;
3911 *matchp = (lValue & lAssertedValue);
3912 return LDAP_SUCCESS;
3921 struct berval *value,
3922 void *assertedValue )
3924 long lValue, lAssertedValue;
3926 /* safe to assume integers are NUL terminated? */
3927 lValue = strtoul(value->bv_val, NULL, 10);
3928 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3929 return LDAP_CONSTRAINT_VIOLATION;
3931 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3932 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3933 return LDAP_CONSTRAINT_VIOLATION;
3935 *matchp = (lValue | lAssertedValue);
3936 return LDAP_SUCCESS;
3940 #include <openssl/x509.h>
3941 #include <openssl/err.h>
3942 char digit[] = "0123456789";
3945 * Next function returns a string representation of a ASN1_INTEGER.
3946 * It works for unlimited lengths.
3949 static struct berval *
3950 asn1_integer2str(ASN1_INTEGER *a)
3955 /* We work backwards, make it fill from the end of buf */
3956 p = buf + sizeof(buf) - 1;
3959 if ( a == NULL || a->length == 0 ) {
3967 /* We want to preserve the original */
3968 copy = ch_malloc(n*sizeof(unsigned int));
3969 for (i = 0; i<n; i++) {
3970 copy[i] = a->data[i];
3974 * base indicates the index of the most significant
3975 * byte that might be nonzero. When it goes off the
3976 * end, we now there is nothing left to do.
3982 for (i = base; i<n; i++ ) {
3983 copy[i] += carry*256;
3984 carry = copy[i] % 10;
3989 * Way too large, we need to leave
3990 * room for sign if negative
3995 *--p = digit[carry];
3996 if (copy[base] == 0)
4002 if ( a->type == V_ASN1_NEG_INTEGER ) {
4006 return ber_bvstrdup(p);
4009 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
4010 static struct berval *
4011 dn_openssl2ldap(X509_NAME *name)
4013 char issuer_dn[1024];
4016 bio = BIO_new(BIO_s_mem());
4019 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4020 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
4021 ERR_error_string(ERR_get_error(),NULL)));
4023 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
4024 "error creating BIO: %s\n",
4025 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4029 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
4031 BIO_gets(bio, issuer_dn, 1024);
4034 return ber_bvstrdup(issuer_dn);
4038 * Given a certificate in DER format, extract the corresponding
4039 * assertion value for certificateExactMatch
4042 certificateExactConvert(
4044 struct berval ** out )
4047 unsigned char *p = in->bv_val;
4048 struct berval *serial;
4049 struct berval *issuer_dn;
4050 struct berval *bv_tmp;
4052 xcert = d2i_X509(NULL, &p, in->bv_len);
4055 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4056 "certificateExactConvert: error parsing cert: %s\n",
4057 ERR_error_string(ERR_get_error(),NULL)));
4059 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
4060 "error parsing cert: %s\n",
4061 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4063 return LDAP_INVALID_SYNTAX;
4066 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4069 return LDAP_INVALID_SYNTAX;
4071 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4075 return LDAP_INVALID_SYNTAX;
4077 /* Actually, dn_openssl2ldap returns in a normalized format, but
4078 it is different from our normalized format */
4080 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
4084 return LDAP_INVALID_SYNTAX;
4090 *out = ch_malloc(sizeof(struct berval));
4091 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
4092 (*out)->bv_val = ch_malloc((*out)->bv_len);
4094 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
4095 p += serial->bv_len;
4096 AC_MEMCPY(p, " $ ", 3);
4098 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
4099 p += issuer_dn->bv_len;
4103 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4104 "certificateExactConvert: \n %s\n",
4107 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
4109 (*out)->bv_val, NULL, NULL );
4113 ber_bvfree(issuer_dn);
4115 return LDAP_SUCCESS;
4119 serial_and_issuer_parse(
4120 struct berval *assertion,
4121 struct berval **serial,
4122 struct berval **issuer_dn
4130 begin = assertion->bv_val;
4131 end = assertion->bv_val+assertion->bv_len-1;
4132 for (p=begin; p<=end && *p != '$'; p++)
4135 return LDAP_INVALID_SYNTAX;
4137 /* p now points at the $ sign, now use begin and end to delimit the
4139 while (ASCII_SPACE(*begin))
4142 while (ASCII_SPACE(*end))
4145 q = ch_malloc( (end-begin+1)+1 );
4146 AC_MEMCPY( q, begin, end-begin+1 );
4147 q[end-begin+1] = '\0';
4148 *serial = ber_bvstr(q);
4150 /* now extract the issuer, remember p was at the dollar sign */
4152 end = assertion->bv_val+assertion->bv_len-1;
4153 while (ASCII_SPACE(*begin))
4155 /* should we trim spaces at the end too? is it safe always? */
4157 q = ch_malloc( (end-begin+1)+1 );
4158 AC_MEMCPY( q, begin, end-begin+1 );
4159 q[end-begin+1] = '\0';
4160 *issuer_dn = ber_bvstr(dn_normalize(q));
4162 return LDAP_SUCCESS;
4166 certificateExactMatch(
4171 struct berval *value,
4172 void *assertedValue )
4175 unsigned char *p = value->bv_val;
4176 struct berval *serial;
4177 struct berval *issuer_dn;
4178 struct berval *asserted_serial;
4179 struct berval *asserted_issuer_dn;
4182 xcert = d2i_X509(NULL, &p, value->bv_len);
4185 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4186 "certificateExactMatch: error parsing cert: %s\n",
4187 ERR_error_string(ERR_get_error(),NULL)));
4189 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
4190 "error parsing cert: %s\n",
4191 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4193 return LDAP_INVALID_SYNTAX;
4196 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4197 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4201 serial_and_issuer_parse(assertedValue,
4203 &asserted_issuer_dn);
4208 slap_schema.si_syn_integer,
4209 slap_schema.si_mr_integerMatch,
4212 if ( ret == LDAP_SUCCESS ) {
4213 if ( *matchp == 0 ) {
4214 /* We need to normalize everything for dnMatch */
4218 slap_schema.si_syn_distinguishedName,
4219 slap_schema.si_mr_distinguishedNameMatch,
4221 asserted_issuer_dn);
4226 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4227 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
4228 *matchp, serial->bv_val, issuer_dn->bv_val,
4229 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
4231 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
4232 "%d\n\t\"%s $ %s\"\n",
4233 *matchp, serial->bv_val, issuer_dn->bv_val );
4234 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
4235 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
4240 ber_bvfree(issuer_dn);
4241 ber_bvfree(asserted_serial);
4242 ber_bvfree(asserted_issuer_dn);
4248 * Index generation function
4249 * We just index the serials, in most scenarios the issuer DN is one of
4250 * a very small set of values.
4252 int certificateExactIndexer(
4257 struct berval *prefix,
4258 struct berval **values,
4259 struct berval ***keysp )
4262 struct berval **keys;
4265 struct berval * serial;
4267 /* we should have at least one value at this point */
4268 assert( values != NULL && values[0] != NULL );
4270 for( i=0; values[i] != NULL; i++ ) {
4271 /* empty -- just count them */
4274 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
4276 for( i=0; values[i] != NULL; i++ ) {
4277 p = values[i]->bv_val;
4278 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
4281 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4282 "certificateExactIndexer: error parsing cert: %s\n",
4283 ERR_error_string(ERR_get_error(),NULL)));
4285 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4286 "error parsing cert: %s\n",
4287 ERR_error_string(ERR_get_error(),NULL),
4290 /* Do we leak keys on error? */
4291 return LDAP_INVALID_SYNTAX;
4294 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4296 integerNormalize( slap_schema.si_syn_integer,
4301 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4302 "certificateExactIndexer: returning: %s\n",
4305 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4314 return LDAP_SUCCESS;
4317 /* Index generation function */
4318 /* We think this is always called with a value in matching rule syntax */
4319 int certificateExactFilter(
4324 struct berval *prefix,
4326 struct berval ***keysp )
4328 struct berval **keys;
4329 struct berval *asserted_serial;
4330 struct berval *asserted_issuer_dn;
4332 serial_and_issuer_parse(assertValue,
4334 &asserted_issuer_dn);
4336 keys = ch_malloc( sizeof( struct berval * ) * 2 );
4337 integerNormalize( syntax, asserted_serial, &keys[0] );
4341 ber_bvfree(asserted_serial);
4342 ber_bvfree(asserted_issuer_dn);
4343 return LDAP_SUCCESS;
4348 check_time_syntax (struct berval *val,
4352 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
4353 static int mdays[2][12] = {
4354 /* non-leap years */
4355 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
4357 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
4360 int part, c, tzoffset, leapyear = 0 ;
4362 if( val->bv_len == 0 ) {
4363 return LDAP_INVALID_SYNTAX;
4366 p = (char *)val->bv_val;
4367 e = p + val->bv_len;
4369 /* Ignore initial whitespace */
4370 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4374 if (e - p < 13 - (2 * start)) {
4375 return LDAP_INVALID_SYNTAX;
4378 for (part = 0; part < 9; part++) {
4382 for (part = start; part < 7; part++) {
4384 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
4391 return LDAP_INVALID_SYNTAX;
4393 if (c < 0 || c > 9) {
4394 return LDAP_INVALID_SYNTAX;
4400 return LDAP_INVALID_SYNTAX;
4402 if (c < 0 || c > 9) {
4403 return LDAP_INVALID_SYNTAX;
4408 if (part == 2 || part == 3) {
4411 if (parts[part] < 0) {
4412 return LDAP_INVALID_SYNTAX;
4414 if (parts[part] > ceiling[part]) {
4415 return LDAP_INVALID_SYNTAX;
4419 /* leapyear check for the Gregorian calendar (year>1581) */
4420 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
4421 ((parts[0] % 4 == 0) && (parts[1] == 0)))
4426 if (parts[3] > mdays[leapyear][parts[2]]) {
4427 return LDAP_INVALID_SYNTAX;
4432 tzoffset = 0; /* UTC */
4433 } else if (c != '+' && c != '-') {
4434 return LDAP_INVALID_SYNTAX;
4438 } else /* c == '+' */ {
4443 return LDAP_INVALID_SYNTAX;
4446 for (part = 7; part < 9; part++) {
4448 if (c < 0 || c > 9) {
4449 return LDAP_INVALID_SYNTAX;
4454 if (c < 0 || c > 9) {
4455 return LDAP_INVALID_SYNTAX;
4459 if (parts[part] < 0 || parts[part] > ceiling[part]) {
4460 return LDAP_INVALID_SYNTAX;
4465 /* Ignore trailing whitespace */
4466 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4470 return LDAP_INVALID_SYNTAX;
4473 switch ( tzoffset ) {
4474 case -1: /* negativ offset to UTC, ie west of Greenwich */
4475 parts[4] += parts[7];
4476 parts[5] += parts[8];
4477 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
4481 c = mdays[leapyear][parts[2]];
4483 if (parts[part] > c) {
4484 parts[part] -= c + 1;
4489 case 1: /* positive offset to UTC, ie east of Greenwich */
4490 parts[4] -= parts[7];
4491 parts[5] -= parts[8];
4492 for (part = 6; --part > 0; ) {
4496 /* first arg to % needs to be non negativ */
4497 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
4499 if (parts[part] < 0) {
4500 parts[part] += c + 1;
4505 case 0: /* already UTC */
4509 return LDAP_SUCCESS;
4516 struct berval **normalized )
4521 rc = check_time_syntax(val, 1, parts);
4522 if (rc != LDAP_SUCCESS) {
4527 out = ch_malloc( sizeof(struct berval) );
4529 return LBER_ERROR_MEMORY;
4532 out->bv_val = ch_malloc( 14 );
4533 if ( out->bv_val == NULL ) {
4535 return LBER_ERROR_MEMORY;
4538 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02dZ",
4539 parts[1], parts[2] + 1, parts[3] + 1,
4540 parts[4], parts[5], parts[6] );
4544 return LDAP_SUCCESS;
4554 return check_time_syntax(in, 1, parts);
4558 generalizedTimeValidate(
4564 return check_time_syntax(in, 0, parts);
4568 generalizedTimeNormalize(
4571 struct berval **normalized )
4576 rc = check_time_syntax(val, 0, parts);
4577 if (rc != LDAP_SUCCESS) {
4582 out = ch_malloc( sizeof(struct berval) );
4584 return LBER_ERROR_MEMORY;
4587 out->bv_val = ch_malloc( 16 );
4588 if ( out->bv_val == NULL ) {
4590 return LBER_ERROR_MEMORY;
4593 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4594 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4595 parts[4], parts[5], parts[6] );
4599 return LDAP_SUCCESS;
4603 nisNetgroupTripleValidate(
4605 struct berval *val )
4610 if ( val->bv_len == 0 ) {
4611 return LDAP_INVALID_SYNTAX;
4614 p = (char *)val->bv_val;
4615 e = p + val->bv_len;
4617 if ( *p != '(' /*')'*/ ) {
4618 return LDAP_INVALID_SYNTAX;
4621 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4625 return LDAP_INVALID_SYNTAX;
4628 } else if ( !ATTR_CHAR( *p ) ) {
4629 return LDAP_INVALID_SYNTAX;
4633 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4634 return LDAP_INVALID_SYNTAX;
4640 return LDAP_INVALID_SYNTAX;
4643 return LDAP_SUCCESS;
4647 bootParameterValidate(
4649 struct berval *val )
4653 if ( val->bv_len == 0 ) {
4654 return LDAP_INVALID_SYNTAX;
4657 p = (char *)val->bv_val;
4658 e = p + val->bv_len;
4661 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4662 if ( !ATTR_CHAR( *p ) ) {
4663 return LDAP_INVALID_SYNTAX;
4668 return LDAP_INVALID_SYNTAX;
4672 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4673 if ( !ATTR_CHAR( *p ) ) {
4674 return LDAP_INVALID_SYNTAX;
4679 return LDAP_INVALID_SYNTAX;
4683 for ( p++; p < e; p++ ) {
4684 if ( !ATTR_CHAR( *p ) ) {
4685 return LDAP_INVALID_SYNTAX;
4689 return LDAP_SUCCESS;
4692 struct syntax_defs_rec {
4695 slap_syntax_validate_func *sd_validate;
4696 slap_syntax_transform_func *sd_normalize;
4697 slap_syntax_transform_func *sd_pretty;
4698 #ifdef SLAPD_BINARY_CONVERSION
4699 slap_syntax_transform_func *sd_ber2str;
4700 slap_syntax_transform_func *sd_str2ber;
4704 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4705 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4707 struct syntax_defs_rec syntax_defs[] = {
4708 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4709 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4710 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4711 0, NULL, NULL, NULL},
4712 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4713 0, NULL, NULL, NULL},
4714 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4715 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4716 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4717 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4718 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4719 0, bitStringValidate, bitStringNormalize, NULL },
4720 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4721 0, booleanValidate, NULL, NULL},
4722 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4723 X_BINARY X_NOT_H_R ")",
4724 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4725 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4726 X_BINARY X_NOT_H_R ")",
4727 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4728 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4729 X_BINARY X_NOT_H_R ")",
4730 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4731 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4732 0, countryStringValidate, IA5StringNormalize, NULL},
4733 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4734 0, dnValidate, dnNormalize, dnPretty},
4735 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4736 0, NULL, NULL, NULL},
4737 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4738 0, NULL, NULL, NULL},
4739 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4740 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4741 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4742 0, NULL, NULL, NULL},
4743 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4744 0, NULL, NULL, NULL},
4745 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4746 0, NULL, NULL, NULL},
4747 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4748 0, NULL, NULL, NULL},
4749 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4750 0, NULL, NULL, NULL},
4751 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4752 0, printablesStringValidate, IA5StringNormalize, NULL},
4753 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4754 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4755 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4756 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4757 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4758 0, NULL, NULL, NULL},
4759 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4760 0, IA5StringValidate, IA5StringNormalize, NULL},
4761 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4762 0, integerValidate, integerNormalize, NULL},
4763 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4764 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4765 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4766 0, NULL, NULL, NULL},
4767 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4768 0, NULL, NULL, NULL},
4769 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4770 0, NULL, NULL, NULL},
4771 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4772 0, NULL, NULL, NULL},
4773 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4774 0, NULL, NULL, NULL},
4775 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4776 0, nameUIDValidate, nameUIDNormalize, NULL},
4777 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4778 0, NULL, NULL, NULL},
4779 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4780 0, numericStringValidate, numericStringNormalize, NULL},
4781 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4782 0, NULL, NULL, NULL},
4783 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4784 0, oidValidate, NULL, NULL},
4785 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4786 0, IA5StringValidate, IA5StringNormalize, NULL},
4787 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4788 0, blobValidate, NULL, NULL},
4789 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4790 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4791 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4792 0, NULL, NULL, NULL},
4793 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4794 0, NULL, NULL, NULL},
4795 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4796 0, printableStringValidate, IA5StringNormalize, NULL},
4797 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4798 X_BINARY X_NOT_H_R ")",
4799 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4800 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4801 0, printableStringValidate, IA5StringNormalize, NULL},
4802 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4803 0, NULL, NULL, NULL},
4804 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4805 0, printablesStringValidate, IA5StringNormalize, NULL},
4806 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4807 0, utcTimeValidate, utcTimeNormalize, NULL},
4808 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4809 0, NULL, NULL, NULL},
4810 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4811 0, NULL, NULL, NULL},
4812 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4813 0, NULL, NULL, NULL},
4814 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4815 0, NULL, NULL, NULL},
4816 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4817 0, NULL, NULL, NULL},
4819 /* RFC 2307 NIS Syntaxes */
4820 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4821 0, nisNetgroupTripleValidate, NULL, NULL},
4822 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4823 0, bootParameterValidate, NULL, NULL},
4827 /* These OIDs are not published yet, but will be in the next
4828 * I-D for PKIX LDAPv3 schema as have been advanced by David
4829 * Chadwick in private mail.
4831 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4832 0, NULL, NULL, NULL},
4835 /* OpenLDAP Experimental Syntaxes */
4836 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4838 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4841 /* needs updating */
4842 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4843 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4845 /* OpenLDAP Void Syntax */
4846 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4847 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4848 {NULL, 0, NULL, NULL, NULL}
4851 struct mrule_defs_rec {
4853 slap_mask_t mrd_usage;
4854 slap_mr_convert_func * mrd_convert;
4855 slap_mr_normalize_func * mrd_normalize;
4856 slap_mr_match_func * mrd_match;
4857 slap_mr_indexer_func * mrd_indexer;
4858 slap_mr_filter_func * mrd_filter;
4860 char * mrd_associated;
4864 * Other matching rules in X.520 that we do not use (yet):
4866 * 2.5.13.9 numericStringOrderingMatch
4867 * 2.5.13.15 integerOrderingMatch
4868 * 2.5.13.18 octetStringOrderingMatch
4869 * 2.5.13.19 octetStringSubstringsMatch
4870 * 2.5.13.25 uTCTimeMatch
4871 * 2.5.13.26 uTCTimeOrderingMatch
4872 * 2.5.13.31 directoryStringFirstComponentMatch
4873 * 2.5.13.32 wordMatch
4874 * 2.5.13.33 keywordMatch
4875 * 2.5.13.35 certificateMatch
4876 * 2.5.13.36 certificatePairExactMatch
4877 * 2.5.13.37 certificatePairMatch
4878 * 2.5.13.38 certificateListExactMatch
4879 * 2.5.13.39 certificateListMatch
4880 * 2.5.13.40 algorithmIdentifierMatch
4881 * 2.5.13.41 storedPrefixMatch
4882 * 2.5.13.42 attributeCertificateMatch
4883 * 2.5.13.43 readerAndKeyIDMatch
4884 * 2.5.13.44 attributeIntegrityMatch
4887 struct mrule_defs_rec mrule_defs[] = {
4889 * EQUALITY matching rules must be listed after associated APPROX
4890 * matching rules. So, we list all APPROX matching rules first.
4892 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4893 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4894 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4896 directoryStringApproxMatch,
4897 directoryStringApproxIndexer,
4898 directoryStringApproxFilter,
4901 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4902 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4903 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4905 IA5StringApproxMatch,
4906 IA5StringApproxIndexer,
4907 IA5StringApproxFilter,
4911 * Other matching rules
4914 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4915 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4916 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4918 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4921 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4922 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4923 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4925 dnMatch, dnIndexer, dnFilter,
4928 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4929 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4930 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4932 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4933 directoryStringApproxMatchOID },
4935 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4936 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4939 caseIgnoreOrderingMatch, NULL, NULL,
4942 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4943 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4944 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4946 caseExactIgnoreSubstringsMatch,
4947 caseExactIgnoreSubstringsIndexer,
4948 caseExactIgnoreSubstringsFilter,
4951 {"( 2.5.13.5 NAME 'caseExactMatch' "
4952 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4953 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4955 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4956 directoryStringApproxMatchOID },
4958 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4959 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4962 caseExactOrderingMatch, NULL, NULL,
4965 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4966 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4967 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4969 caseExactIgnoreSubstringsMatch,
4970 caseExactIgnoreSubstringsIndexer,
4971 caseExactIgnoreSubstringsFilter,
4974 {"( 2.5.13.8 NAME 'numericStringMatch' "
4975 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4976 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4979 caseIgnoreIA5Indexer,
4980 caseIgnoreIA5Filter,
4983 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4984 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4985 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4987 caseIgnoreIA5SubstringsMatch,
4988 caseIgnoreIA5SubstringsIndexer,
4989 caseIgnoreIA5SubstringsFilter,
4992 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4993 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4994 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4996 caseIgnoreListMatch, NULL, NULL,
4999 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
5000 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
5001 SLAP_MR_SUBSTR | SLAP_MR_EXT,
5003 caseIgnoreListSubstringsMatch, NULL, NULL,
5006 {"( 2.5.13.13 NAME 'booleanMatch' "
5007 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
5008 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5010 booleanMatch, NULL, NULL,
5013 {"( 2.5.13.14 NAME 'integerMatch' "
5014 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5015 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5017 integerMatch, integerIndexer, integerFilter,
5020 {"( 2.5.13.16 NAME 'bitStringMatch' "
5021 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
5022 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5024 bitStringMatch, bitStringIndexer, bitStringFilter,
5027 {"( 2.5.13.17 NAME 'octetStringMatch' "
5028 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
5029 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5031 octetStringMatch, octetStringIndexer, octetStringFilter,
5034 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
5035 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
5036 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
5038 telephoneNumberMatch,
5039 telephoneNumberIndexer,
5040 telephoneNumberFilter,
5043 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
5044 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
5045 SLAP_MR_SUBSTR | SLAP_MR_EXT,
5047 telephoneNumberSubstringsMatch,
5048 telephoneNumberSubstringsIndexer,
5049 telephoneNumberSubstringsFilter,
5052 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
5053 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
5054 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5059 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
5060 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
5061 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5063 uniqueMemberMatch, NULL, NULL,
5066 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
5067 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
5068 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5070 protocolInformationMatch, NULL, NULL,
5073 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
5074 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
5075 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5077 generalizedTimeMatch, NULL, NULL,
5080 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
5081 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
5084 generalizedTimeOrderingMatch, NULL, NULL,
5087 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
5088 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5089 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5091 integerFirstComponentMatch, NULL, NULL,
5094 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
5095 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
5096 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5098 objectIdentifierFirstComponentMatch, NULL, NULL,
5102 {"( 2.5.13.34 NAME 'certificateExactMatch' "
5103 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
5104 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5105 certificateExactConvert, NULL,
5106 certificateExactMatch,
5107 certificateExactIndexer, certificateExactFilter,
5111 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
5112 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5113 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5115 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
5116 IA5StringApproxMatchOID },
5118 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
5119 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5120 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
5122 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
5123 IA5StringApproxMatchOID },
5125 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
5126 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5129 caseIgnoreIA5SubstringsMatch,
5130 caseIgnoreIA5SubstringsIndexer,
5131 caseIgnoreIA5SubstringsFilter,
5134 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
5135 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5138 caseExactIA5SubstringsMatch,
5139 caseExactIA5SubstringsIndexer,
5140 caseExactIA5SubstringsFilter,
5143 /* needs updating */
5144 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
5145 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
5148 authPasswordMatch, NULL, NULL,
5151 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
5152 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
5155 OpenLDAPaciMatch, NULL, NULL,
5158 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
5159 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5162 integerBitAndMatch, NULL, NULL,
5165 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
5166 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5169 integerBitOrMatch, NULL, NULL,
5172 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
5181 /* we should only be called once (from main) */
5182 assert( schema_init_done == 0 );
5184 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
5185 res = register_syntax( syntax_defs[i].sd_desc,
5186 syntax_defs[i].sd_flags,
5187 syntax_defs[i].sd_validate,
5188 syntax_defs[i].sd_normalize,
5189 syntax_defs[i].sd_pretty
5190 #ifdef SLAPD_BINARY_CONVERSION
5192 syntax_defs[i].sd_ber2str,
5193 syntax_defs[i].sd_str2ber
5198 fprintf( stderr, "schema_init: Error registering syntax %s\n",
5199 syntax_defs[i].sd_desc );
5204 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
5205 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
5207 "schema_init: Ingoring unusable matching rule %s\n",
5208 mrule_defs[i].mrd_desc );
5212 res = register_matching_rule(
5213 mrule_defs[i].mrd_desc,
5214 mrule_defs[i].mrd_usage,
5215 mrule_defs[i].mrd_convert,
5216 mrule_defs[i].mrd_normalize,
5217 mrule_defs[i].mrd_match,
5218 mrule_defs[i].mrd_indexer,
5219 mrule_defs[i].mrd_filter,
5220 mrule_defs[i].mrd_associated );
5224 "schema_init: Error registering matching rule %s\n",
5225 mrule_defs[i].mrd_desc );
5229 schema_init_done = 1;
5230 return LDAP_SUCCESS;
5234 schema_destroy( void )