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
226 #define AVA_PRIVATE( ava ) ( ( AttributeDescription * )(ava)->la_private )
229 * In-place, schema-aware validation of the
230 * structural representation of a distinguished name.
233 LDAPDN_validate( LDAPDN *dn )
240 for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
241 LDAPRDN *rdn = dn[ iRDN ][ 0 ];
244 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
245 LDAPAVA *ava = rdn[ iAVA ][ 0 ];
246 AttributeDescription *ad;
247 slap_syntax_validate_func *validate = NULL;
249 if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
250 const char *text = NULL;
252 rc = slap_bv2ad( ava->la_attr, &ad, &text );
253 if ( rc != LDAP_SUCCESS ) {
254 return LDAP_INVALID_SYNTAX;
257 ava->la_private = ( void * )ad;
261 * Replace attr oid/name with the canonical name
263 ber_bvfree( ava->la_attr );
264 ava->la_attr = ber_bvdup( &ad->ad_cname );
266 validate = ad->ad_type->sat_syntax->ssyn_validate;
270 * validate value by validate function
272 rc = ( *validate )( ad->ad_type->sat_syntax,
275 if ( rc != LDAP_SUCCESS ) {
276 return LDAP_INVALID_SYNTAX;
293 if ( in->bv_len == 0 ) {
294 return( LDAP_SUCCESS );
297 rc = ldap_str2dn( in->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
300 * Schema-aware validate
302 if ( rc == LDAP_SUCCESS ) {
303 rc = LDAPDN_validate( dn );
306 ldapava_free_dn( dn );
308 if ( rc != LDAP_SUCCESS ) {
309 return( LDAP_INVALID_SYNTAX );
312 return( LDAP_SUCCESS );
316 AVA_Sort( LDAPRDN *rdn, int iAVA )
319 LDAPAVA *ava_in = rdn[ iAVA ][ 0 ];
321 for ( i = 0; i < iAVA; i++ ) {
322 LDAPAVA *ava = rdn[ i ][ 0 ];
325 a = strcmp( ava_in->la_attr->bv_val, ava->la_attr->bv_val );
334 d = ava_in->la_value->bv_len - ava->la_value->bv_len;
336 v = memcmp( ava_in->la_value->bv_val,
337 ava->la_value->bv_val,
338 d <= 0 ? ava_in->la_value->bv_len
339 : ava->la_value->bv_len );
341 if ( v == 0 && d != 0 ) {
360 a = strcmp( ava_in->la_value->bv_val,
361 ava->la_value->bv_val );
367 for ( j = iAVA; j > i; j-- ) {
368 rdn[ j ][ 0 ] = rdn[ j - 1 ][ 0 ];
370 rdn[ i ][ 0 ] = ava_in;
377 * In-place, schema-aware normalization / "pretty"ing of the
378 * structural representation of a distinguished name.
381 LDAPDN_rewrite( LDAPDN *dn, unsigned flags )
388 for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
389 LDAPRDN *rdn = dn[ iRDN ][ 0 ];
392 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
393 LDAPAVA *ava = rdn[ iAVA ][ 0 ];
394 AttributeDescription *ad;
395 slap_syntax_transform_func *transf = NULL;
397 struct berval *bv = NULL;
399 if ( ( ad = AVA_PRIVATE( ava ) ) == NULL ) {
400 const char *text = NULL;
402 rc = slap_bv2ad( ava->la_attr, &ad, &text );
403 if ( rc != LDAP_SUCCESS ) {
404 return LDAP_INVALID_SYNTAX;
407 ava->la_private = ( void * )ad;
411 * Replace attr oid/name with the canonical name
413 ber_bvfree( ava->la_attr );
414 ava->la_attr = ber_bvdup( &ad->ad_cname );
416 if( flags & SLAP_LDAPDN_PRETTY ) {
417 transf = ad->ad_type->sat_syntax->ssyn_pretty;
420 transf = ad->ad_type->sat_syntax->ssyn_normalize;
421 mr = ad->ad_type->sat_equality;
426 * transform value by normalize/pretty function
428 rc = ( *transf )( ad->ad_type->sat_syntax,
429 ava->la_value, &bv );
431 if ( rc != LDAP_SUCCESS ) {
432 return LDAP_INVALID_SYNTAX;
436 if( mr && ( mr->smr_usage & SLAP_MR_DN_FOLD ) ) {
437 struct berval *s = bv;
439 bv = ber_bvstr( UTF8normalize( bv ? bv : ava->la_value,
446 ber_bvfree( ava->la_value );
450 AVA_Sort( rdn, iAVA );
461 struct berval **normalized )
463 struct berval *out = NULL;
465 Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 );
467 if ( val->bv_len != 0 ) {
473 * Go to structural representation
475 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
476 if ( rc != LDAP_SUCCESS ) {
477 return LDAP_INVALID_SYNTAX;
481 * Schema-aware rewrite
483 if ( LDAPDN_rewrite( dn, 0 ) != LDAP_SUCCESS ) {
484 ldapava_free_dn( dn );
485 return LDAP_INVALID_SYNTAX;
489 * Back to string representation
491 rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
493 ldapava_free_dn( dn );
495 if ( rc != LDAP_SUCCESS ) {
496 return LDAP_INVALID_SYNTAX;
499 out = ber_bvstr( dn_out );
502 out = ber_bvdup( val );
505 Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val, 0, 0 );
516 struct berval **pretty)
518 struct berval *out = NULL;
520 Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 );
522 if ( val->bv_len != 0 ) {
527 /* FIXME: should be liberal in what we accept */
528 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
529 if ( rc != LDAP_SUCCESS ) {
530 return LDAP_INVALID_SYNTAX;
534 * Schema-aware rewrite
536 if ( LDAPDN_rewrite( dn, SLAP_LDAPDN_PRETTY ) != LDAP_SUCCESS ) {
537 ldapava_free_dn( dn );
538 return LDAP_INVALID_SYNTAX;
541 /* FIXME: not sure why the default isn't pretty */
542 rc = ldap_dn2str( dn, &dn_out,
543 LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
545 ldapava_free_dn( dn );
547 if ( rc != LDAP_SUCCESS ) {
548 return LDAP_INVALID_SYNTAX;
551 out = ber_bvstr( dn_out );
554 out = ber_bvdup( val );
557 Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val, 0, 0 );
570 struct berval *value,
571 void *assertedValue )
574 struct berval *asserted = (struct berval *) assertedValue;
576 match = value->bv_len - asserted->bv_len;
579 match = strcmp( value->bv_val, asserted->bv_val );
583 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
584 "dnMatch: %d\n %s\n %s\n", match,
585 value->bv_val, asserted->bv_val ));
587 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
588 match, value->bv_val, asserted->bv_val );
592 return( LDAP_SUCCESS );
595 #else /* !USE_LDAP_DN_PARSING */
605 if( in->bv_len == 0 ) return LDAP_SUCCESS;
607 dn = ch_strdup( in->bv_val );
610 return LDAP_INVALID_SYNTAX;
612 } else if ( strlen( in->bv_val ) != in->bv_len ) {
613 rc = LDAP_INVALID_SYNTAX;
615 } else if ( dn_validate( dn ) == NULL ) {
616 rc = LDAP_INVALID_SYNTAX;
630 struct berval **normalized )
634 if ( val->bv_len != 0 ) {
636 out = ber_bvstr( UTF8normalize( val, UTF8_CASEFOLD ) );
638 dn = dn_validate( out->bv_val );
642 return LDAP_INVALID_SYNTAX;
646 out->bv_len = strlen( dn );
648 out = ber_bvdup( val );
661 struct berval *value,
662 void *assertedValue )
665 struct berval *asserted = (struct berval *) assertedValue;
667 match = value->bv_len - asserted->bv_len;
670 #ifdef USE_DN_NORMALIZE
671 match = strcmp( value->bv_val, asserted->bv_val );
673 match = strcasecmp( value->bv_val, asserted->bv_val );
678 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
679 "dnMatch: %d\n %s\n %s\n", match,
680 value->bv_val, asserted->bv_val ));
682 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
683 match, value->bv_val, asserted->bv_val );
691 #endif /* !USE_LDAP_DN_PARSING */
701 if( in->bv_len == 0 ) return LDAP_SUCCESS;
703 dn = ber_bvdup( in );
705 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
706 /* assume presence of optional UID */
709 for(i=dn->bv_len-2; i>2; i--) {
710 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
714 if( dn->bv_val[i] != '\'' ||
715 dn->bv_val[i-1] != 'B' ||
716 dn->bv_val[i-2] != '#' ) {
718 return LDAP_INVALID_SYNTAX;
721 /* trim the UID to allow use of dn_validate */
722 dn->bv_val[i-2] = '\0';
725 rc = dn_validate( dn->bv_val ) == NULL
726 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
736 struct berval **normalized )
738 struct berval *out = ber_bvdup( val );
740 if( out->bv_len != 0 ) {
744 ber_len_t uidlen = 0;
746 if( out->bv_val[out->bv_len-1] == '\'' ) {
747 /* assume presence of optional UID */
748 uid = strrchr( out->bv_val, '#' );
752 return LDAP_INVALID_SYNTAX;
755 uidlen = out->bv_len - (out->bv_val - uid);
756 /* temporarily trim the UID */
760 #ifdef USE_DN_NORMALIZE
761 dn = dn_normalize( out->bv_val );
763 dn = dn_validate( out->bv_val );
768 return LDAP_INVALID_SYNTAX;
774 /* restore the separator */
777 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
781 out->bv_len = dnlen + uidlen;
793 /* any value allowed */
802 /* any value allowed */
813 /* very unforgiving validation, requires no normalization
814 * before simplistic matching
816 if( in->bv_len < 3 ) {
817 return LDAP_INVALID_SYNTAX;
821 * rfc 2252 section 6.3 Bit String
822 * bitstring = "'" *binary-digit "'"
823 * binary-digit = "0" / "1"
824 * example: '0101111101'B
827 if( in->bv_val[0] != '\'' ||
828 in->bv_val[in->bv_len-2] != '\'' ||
829 in->bv_val[in->bv_len-1] != 'B' )
831 return LDAP_INVALID_SYNTAX;
834 for( i=in->bv_len-3; i>0; i-- ) {
835 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
836 return LDAP_INVALID_SYNTAX;
847 struct berval **normalized )
850 * A normalized bitString is has no extaneous (leading) zero bits.
851 * That is, '00010'B is normalized to '10'B
852 * However, as a special case, '0'B requires no normalization.
854 struct berval *newval;
857 /* start at the first bit */
860 /* Find the first non-zero bit */
861 while ( *p == '0' ) p++;
863 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
866 /* no non-zero bits */
867 newval->bv_val = ch_strdup("\'0\'B");
868 newval->bv_len = sizeof("\'0\'B") - 1;
872 newval->bv_val = ch_malloc( val->bv_len + 1 );
874 newval->bv_val[0] = '\'';
877 for( ; *p != '\0'; p++ ) {
878 newval->bv_val[newval->bv_len++] = *p;
881 newval->bv_val[newval->bv_len] = '\0';
884 *normalized = newval;
889 * Handling boolean syntax and matching is quite rigid.
890 * A more flexible approach would be to allow a variety
891 * of strings to be normalized and prettied into TRUE
899 /* very unforgiving validation, requires no normalization
900 * before simplistic matching
903 if( in->bv_len == 4 ) {
904 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
907 } else if( in->bv_len == 5 ) {
908 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
913 return LDAP_INVALID_SYNTAX;
922 struct berval *value,
923 void *assertedValue )
925 /* simplistic matching allowed by rigid validation */
926 struct berval *asserted = (struct berval *) assertedValue;
927 *matchp = value->bv_len != asserted->bv_len;
938 unsigned char *u = in->bv_val;
940 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
942 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
943 /* get the length indicated by the first byte */
944 len = LDAP_UTF8_CHARLEN( u );
946 /* should not be zero */
947 if( len == 0 ) return LDAP_INVALID_SYNTAX;
949 /* make sure len corresponds with the offset
950 to the next character */
951 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
954 if( count != 0 ) return LDAP_INVALID_SYNTAX;
963 struct berval **normalized )
965 struct berval *newval;
968 newval = ch_malloc( sizeof( struct berval ) );
972 /* Ignore initial whitespace */
973 while ( ldap_utf8_isspace( p ) ) {
979 return LDAP_INVALID_SYNTAX;
982 newval->bv_val = ch_strdup( p );
983 p = q = newval->bv_val;
989 if ( ldap_utf8_isspace( p ) ) {
990 len = LDAP_UTF8_COPY(q,p);
995 /* Ignore the extra whitespace */
996 while ( ldap_utf8_isspace( p ) ) {
1000 len = LDAP_UTF8_COPY(q,p);
1007 assert( *newval->bv_val );
1008 assert( newval->bv_val < p );
1011 /* cannot start with a space */
1012 assert( !ldap_utf8_isspace(newval->bv_val) );
1015 * If the string ended in space, backup the pointer one
1016 * position. One is enough because the above loop collapsed
1017 * all whitespace to a single space.
1024 /* cannot end with a space */
1025 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
1027 /* null terminate */
1030 newval->bv_len = q - newval->bv_val;
1031 *normalized = newval;
1033 return LDAP_SUCCESS;
1036 /* Returns Unicode cannonically normalized copy of a substring assertion
1037 * Skipping attribute description */
1038 SubstringsAssertion *
1039 UTF8SubstringsassertionNormalize(
1040 SubstringsAssertion *sa,
1043 SubstringsAssertion *nsa;
1046 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
1051 if( sa->sa_initial != NULL ) {
1052 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
1053 if( nsa->sa_initial == NULL ) {
1058 if( sa->sa_any != NULL ) {
1059 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1062 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
1063 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1064 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
1065 if( nsa->sa_any[i] == NULL ) {
1069 nsa->sa_any[i] = NULL;
1072 if( sa->sa_final != NULL ) {
1073 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
1074 if( nsa->sa_final == NULL ) {
1082 ber_bvfree( nsa->sa_final );
1083 ber_bvecfree( nsa->sa_any );
1084 ber_bvfree( nsa->sa_initial );
1089 /* Strip characters with the 8th bit set */
1102 while( *++q & 0x80 ) {
1105 p = memmove(p, q, strlen(q) + 1);
1113 #ifndef SLAPD_APPROX_OLDSINGLESTRING
1115 #if defined(SLAPD_APPROX_INITIALS)
1116 #define SLAPD_APPROX_DELIMITER "._ "
1117 #define SLAPD_APPROX_WORDLEN 2
1119 #define SLAPD_APPROX_DELIMITER " "
1120 #define SLAPD_APPROX_WORDLEN 1
1129 struct berval *value,
1130 void *assertedValue )
1132 char *val, *nval, *assertv, **values, **words, *c;
1133 int i, count, len, nextchunk=0, nextavail=0;
1136 /* Yes, this is necessary */
1137 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
1138 if( nval == NULL ) {
1140 return LDAP_SUCCESS;
1142 strip8bitChars( nval );
1144 /* Yes, this is necessary */
1145 assertv = UTF8normalize( ((struct berval *)assertedValue),
1147 if( assertv == NULL ) {
1150 return LDAP_SUCCESS;
1152 strip8bitChars( assertv );
1153 avlen = strlen( assertv );
1155 /* Isolate how many words there are */
1156 for( c=nval,count=1; *c; c++ ) {
1157 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
1158 if ( c == NULL ) break;
1163 /* Get a phonetic copy of each word */
1164 words = (char **)ch_malloc( count * sizeof(char *) );
1165 values = (char **)ch_malloc( count * sizeof(char *) );
1166 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
1168 values[i] = phonetic(c);
1171 /* Work through the asserted value's words, to see if at least some
1172 of the words are there, in the same order. */
1174 while ( nextchunk < avlen ) {
1175 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
1180 #if defined(SLAPD_APPROX_INITIALS)
1181 else if( len == 1 ) {
1182 /* Single letter words need to at least match one word's initial */
1183 for( i=nextavail; i<count; i++ )
1184 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
1191 /* Isolate the next word in the asserted value and phonetic it */
1192 assertv[nextchunk+len] = '\0';
1193 val = phonetic( assertv + nextchunk );
1195 /* See if this phonetic chunk is in the remaining words of *value */
1196 for( i=nextavail; i<count; i++ ){
1197 if( !strcmp( val, values[i] ) ){
1205 /* This chunk in the asserted value was NOT within the *value. */
1211 /* Go on to the next word in the asserted value */
1215 /* If some of the words were seen, call it a match */
1216 if( nextavail > 0 ) {
1223 /* Cleanup allocs */
1225 for( i=0; i<count; i++ ) {
1226 ch_free( values[i] );
1232 return LDAP_SUCCESS;
1241 struct berval *prefix,
1242 struct berval **values,
1243 struct berval ***keysp )
1246 int i,j, len, wordcount, keycount=0;
1247 struct berval **newkeys, **keys=NULL;
1249 for( j=0; values[j] != NULL; j++ ) {
1250 /* Yes, this is necessary */
1251 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
1252 strip8bitChars( val );
1254 /* Isolate how many words there are. There will be a key for each */
1255 for( wordcount=0,c=val; *c; c++) {
1256 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1257 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
1259 if (*c == '\0') break;
1263 /* Allocate/increase storage to account for new keys */
1264 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
1265 * sizeof(struct berval *) );
1266 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
1267 if( keys ) ch_free( keys );
1270 /* Get a phonetic copy of each word */
1271 for( c=val,i=0; i<wordcount; c+=len+1 ) {
1273 if( len < SLAPD_APPROX_WORDLEN ) continue;
1274 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
1275 keys[keycount]->bv_val = phonetic( c );
1276 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
1283 keys[keycount] = NULL;
1286 return LDAP_SUCCESS;
1295 struct berval *prefix,
1297 struct berval ***keysp )
1301 struct berval **keys;
1303 /* Yes, this is necessary */
1304 val = UTF8normalize( ((struct berval *)assertValue),
1307 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
1310 return LDAP_SUCCESS;
1312 strip8bitChars( val );
1314 /* Isolate how many words there are. There will be a key for each */
1315 for( count=0,c=val; *c; c++) {
1316 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1317 if( len >= SLAPD_APPROX_WORDLEN ) count++;
1319 if (*c == '\0') break;
1323 /* Allocate storage for new keys */
1324 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
1326 /* Get a phonetic copy of each word */
1327 for( c=val,i=0; i<count; c+=len+1 ) {
1329 if( len < SLAPD_APPROX_WORDLEN ) continue;
1330 keys[i] = ber_bvstr( phonetic( c ) );
1339 return LDAP_SUCCESS;
1344 /* No other form of Approximate Matching is defined */
1352 struct berval *value,
1353 void *assertedValue )
1355 char *vapprox, *avapprox;
1358 /* Yes, this is necessary */
1359 s = UTF8normalize( value, UTF8_NOCASEFOLD );
1362 return LDAP_SUCCESS;
1365 /* Yes, this is necessary */
1366 t = UTF8normalize( ((struct berval *)assertedValue),
1371 return LDAP_SUCCESS;
1374 vapprox = phonetic( strip8bitChars( s ) );
1375 avapprox = phonetic( strip8bitChars( t ) );
1380 *matchp = strcmp( vapprox, avapprox );
1383 ch_free( avapprox );
1385 return LDAP_SUCCESS;
1394 struct berval *prefix,
1395 struct berval **values,
1396 struct berval ***keysp )
1399 struct berval **keys;
1402 for( i=0; values[i] != NULL; i++ ) {
1403 /* empty - just count them */
1406 /* we should have at least one value at this point */
1409 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
1411 /* Copy each value and run it through phonetic() */
1412 for( i=0; values[i] != NULL; i++ ) {
1413 /* Yes, this is necessary */
1414 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
1416 /* strip 8-bit chars and run through phonetic() */
1417 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1423 return LDAP_SUCCESS;
1433 struct berval *prefix,
1435 struct berval ***keysp )
1437 struct berval **keys;
1440 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1442 /* Yes, this is necessary */
1443 s = UTF8normalize( ((struct berval *)assertValue),
1448 /* strip 8-bit chars and run through phonetic() */
1449 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1455 return LDAP_SUCCESS;
1466 struct berval *value,
1467 void *assertedValue )
1469 *matchp = UTF8normcmp( value->bv_val,
1470 ((struct berval *) assertedValue)->bv_val,
1472 return LDAP_SUCCESS;
1476 caseExactIgnoreSubstringsMatch(
1481 struct berval *value,
1482 void *assertedValue )
1485 SubstringsAssertion *sub = NULL;
1489 char *nav, casefold;
1491 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1492 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1494 nav = UTF8normalize( value, casefold );
1500 left.bv_len = strlen( nav );
1502 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1508 /* Add up asserted input length */
1509 if( sub->sa_initial ) {
1510 inlen += sub->sa_initial->bv_len;
1513 for(i=0; sub->sa_any[i] != NULL; i++) {
1514 inlen += sub->sa_any[i]->bv_len;
1517 if( sub->sa_final ) {
1518 inlen += sub->sa_final->bv_len;
1521 if( sub->sa_initial ) {
1522 if( inlen > left.bv_len ) {
1527 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1528 sub->sa_initial->bv_len );
1534 left.bv_val += sub->sa_initial->bv_len;
1535 left.bv_len -= sub->sa_initial->bv_len;
1536 inlen -= sub->sa_initial->bv_len;
1539 if( sub->sa_final ) {
1540 if( inlen > left.bv_len ) {
1545 match = strncmp( sub->sa_final->bv_val,
1546 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1547 sub->sa_final->bv_len );
1553 left.bv_len -= sub->sa_final->bv_len;
1554 inlen -= sub->sa_final->bv_len;
1558 for(i=0; sub->sa_any[i]; i++) {
1563 if( inlen > left.bv_len ) {
1564 /* not enough length */
1569 if( sub->sa_any[i]->bv_len == 0 ) {
1573 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1580 idx = p - left.bv_val;
1581 assert( idx < left.bv_len );
1583 if( idx >= left.bv_len ) {
1584 /* this shouldn't happen */
1586 ch_free( sub->sa_final );
1587 ber_bvecfree( sub->sa_any );
1588 ch_free( sub->sa_initial );
1596 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1597 /* not enough left */
1602 match = strncmp( left.bv_val,
1603 sub->sa_any[i]->bv_val,
1604 sub->sa_any[i]->bv_len );
1612 left.bv_val += sub->sa_any[i]->bv_len;
1613 left.bv_len -= sub->sa_any[i]->bv_len;
1614 inlen -= sub->sa_any[i]->bv_len;
1621 ber_bvfree( sub->sa_final );
1622 ber_bvecfree( sub->sa_any );
1623 ber_bvfree( sub->sa_initial );
1627 return LDAP_SUCCESS;
1630 /* Index generation function */
1631 int caseExactIgnoreIndexer(
1636 struct berval *prefix,
1637 struct berval **values,
1638 struct berval ***keysp )
1643 struct berval **keys;
1644 HASH_CONTEXT HASHcontext;
1645 unsigned char HASHdigest[HASH_BYTES];
1646 struct berval digest;
1647 digest.bv_val = HASHdigest;
1648 digest.bv_len = sizeof(HASHdigest);
1650 for( i=0; values[i] != NULL; i++ ) {
1651 /* empty - just count them */
1654 /* we should have at least one value at this point */
1657 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1659 slen = strlen( syntax->ssyn_oid );
1660 mlen = strlen( mr->smr_oid );
1662 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1663 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1665 for( i=0; values[i] != NULL; i++ ) {
1666 struct berval *value;
1667 value = ber_bvstr( UTF8normalize( values[i],
1670 HASH_Init( &HASHcontext );
1671 if( prefix != NULL && prefix->bv_len > 0 ) {
1672 HASH_Update( &HASHcontext,
1673 prefix->bv_val, prefix->bv_len );
1675 HASH_Update( &HASHcontext,
1676 syntax->ssyn_oid, slen );
1677 HASH_Update( &HASHcontext,
1678 mr->smr_oid, mlen );
1679 HASH_Update( &HASHcontext,
1680 value->bv_val, value->bv_len );
1681 HASH_Final( HASHdigest, &HASHcontext );
1683 ber_bvfree( value );
1685 keys[i] = ber_bvdup( &digest );
1690 return LDAP_SUCCESS;
1693 /* Index generation function */
1694 int caseExactIgnoreFilter(
1699 struct berval *prefix,
1701 struct berval ***keysp )
1705 struct berval **keys;
1706 HASH_CONTEXT HASHcontext;
1707 unsigned char HASHdigest[HASH_BYTES];
1708 struct berval *value;
1709 struct berval digest;
1710 digest.bv_val = HASHdigest;
1711 digest.bv_len = sizeof(HASHdigest);
1713 slen = strlen( syntax->ssyn_oid );
1714 mlen = strlen( mr->smr_oid );
1716 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1717 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1719 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
1721 /* This usually happens if filter contains bad UTF8 */
1722 if( value == NULL ) {
1723 keys = ch_malloc( sizeof( struct berval * ) );
1725 return LDAP_SUCCESS;
1728 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1730 HASH_Init( &HASHcontext );
1731 if( prefix != NULL && prefix->bv_len > 0 ) {
1732 HASH_Update( &HASHcontext,
1733 prefix->bv_val, prefix->bv_len );
1735 HASH_Update( &HASHcontext,
1736 syntax->ssyn_oid, slen );
1737 HASH_Update( &HASHcontext,
1738 mr->smr_oid, mlen );
1739 HASH_Update( &HASHcontext,
1740 value->bv_val, value->bv_len );
1741 HASH_Final( HASHdigest, &HASHcontext );
1743 keys[0] = ber_bvdup( &digest );
1746 ber_bvfree( value );
1749 return LDAP_SUCCESS;
1752 /* Substrings Index generation function */
1753 int caseExactIgnoreSubstringsIndexer(
1758 struct berval *prefix,
1759 struct berval **values,
1760 struct berval ***keysp )
1765 struct berval **keys;
1766 struct berval **nvalues;
1768 HASH_CONTEXT HASHcontext;
1769 unsigned char HASHdigest[HASH_BYTES];
1770 struct berval digest;
1771 digest.bv_val = HASHdigest;
1772 digest.bv_len = sizeof(HASHdigest);
1776 for( i=0; values[i] != NULL; i++ ) {
1777 /* empty - just count them */
1780 /* we should have at least one value at this point */
1783 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1784 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1786 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1787 for( i=0; values[i] != NULL; i++ ) {
1788 nvalues[i] = ber_bvstr( UTF8normalize( values[i],
1794 for( i=0; values[i] != NULL; i++ ) {
1795 /* count number of indices to generate */
1796 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1800 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1801 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1802 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1803 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1805 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1809 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1810 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1811 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1815 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1816 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1817 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1818 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1820 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1826 /* no keys to generate */
1828 ber_bvecfree( nvalues );
1829 return LDAP_SUCCESS;
1832 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1834 slen = strlen( syntax->ssyn_oid );
1835 mlen = strlen( mr->smr_oid );
1838 for( i=0; values[i] != NULL; i++ ) {
1840 struct berval *value;
1842 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1846 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1847 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1849 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1850 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1852 for( j=0; j<max; j++ ) {
1853 HASH_Init( &HASHcontext );
1854 if( prefix != NULL && prefix->bv_len > 0 ) {
1855 HASH_Update( &HASHcontext,
1856 prefix->bv_val, prefix->bv_len );
1859 HASH_Update( &HASHcontext,
1860 &pre, sizeof( pre ) );
1861 HASH_Update( &HASHcontext,
1862 syntax->ssyn_oid, slen );
1863 HASH_Update( &HASHcontext,
1864 mr->smr_oid, mlen );
1865 HASH_Update( &HASHcontext,
1867 SLAP_INDEX_SUBSTR_MAXLEN );
1868 HASH_Final( HASHdigest, &HASHcontext );
1870 keys[nkeys++] = ber_bvdup( &digest );
1874 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1875 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1877 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1880 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1881 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1882 HASH_Init( &HASHcontext );
1883 if( prefix != NULL && prefix->bv_len > 0 ) {
1884 HASH_Update( &HASHcontext,
1885 prefix->bv_val, prefix->bv_len );
1887 HASH_Update( &HASHcontext,
1888 &pre, sizeof( pre ) );
1889 HASH_Update( &HASHcontext,
1890 syntax->ssyn_oid, slen );
1891 HASH_Update( &HASHcontext,
1892 mr->smr_oid, mlen );
1893 HASH_Update( &HASHcontext,
1895 HASH_Final( HASHdigest, &HASHcontext );
1897 keys[nkeys++] = ber_bvdup( &digest );
1900 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1901 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1902 HASH_Init( &HASHcontext );
1903 if( prefix != NULL && prefix->bv_len > 0 ) {
1904 HASH_Update( &HASHcontext,
1905 prefix->bv_val, prefix->bv_len );
1907 HASH_Update( &HASHcontext,
1908 &pre, sizeof( pre ) );
1909 HASH_Update( &HASHcontext,
1910 syntax->ssyn_oid, slen );
1911 HASH_Update( &HASHcontext,
1912 mr->smr_oid, mlen );
1913 HASH_Update( &HASHcontext,
1914 &value->bv_val[value->bv_len-j], j );
1915 HASH_Final( HASHdigest, &HASHcontext );
1917 keys[nkeys++] = ber_bvdup( &digest );
1932 ber_bvecfree( nvalues );
1934 return LDAP_SUCCESS;
1937 int caseExactIgnoreSubstringsFilter(
1942 struct berval *prefix,
1944 struct berval ***keysp )
1946 SubstringsAssertion *sa;
1948 ber_len_t nkeys = 0;
1949 size_t slen, mlen, klen;
1950 struct berval **keys;
1951 HASH_CONTEXT HASHcontext;
1952 unsigned char HASHdigest[HASH_BYTES];
1953 struct berval *value;
1954 struct berval digest;
1956 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1957 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1959 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1962 return LDAP_SUCCESS;
1965 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1966 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1971 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1973 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1974 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1975 /* don't bother accounting for stepping */
1976 nkeys += sa->sa_any[i]->bv_len -
1977 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1982 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1983 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1989 ber_bvfree( sa->sa_final );
1990 ber_bvecfree( sa->sa_any );
1991 ber_bvfree( sa->sa_initial );
1994 return LDAP_SUCCESS;
1997 digest.bv_val = HASHdigest;
1998 digest.bv_len = sizeof(HASHdigest);
2000 slen = strlen( syntax->ssyn_oid );
2001 mlen = strlen( mr->smr_oid );
2003 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2006 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2007 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2009 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2010 value = sa->sa_initial;
2012 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2013 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2015 HASH_Init( &HASHcontext );
2016 if( prefix != NULL && prefix->bv_len > 0 ) {
2017 HASH_Update( &HASHcontext,
2018 prefix->bv_val, prefix->bv_len );
2020 HASH_Update( &HASHcontext,
2021 &pre, sizeof( pre ) );
2022 HASH_Update( &HASHcontext,
2023 syntax->ssyn_oid, slen );
2024 HASH_Update( &HASHcontext,
2025 mr->smr_oid, mlen );
2026 HASH_Update( &HASHcontext,
2027 value->bv_val, klen );
2028 HASH_Final( HASHdigest, &HASHcontext );
2030 keys[nkeys++] = ber_bvdup( &digest );
2033 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2035 pre = SLAP_INDEX_SUBSTR_PREFIX;
2036 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2038 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2039 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2043 value = sa->sa_any[i];
2046 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2047 j += SLAP_INDEX_SUBSTR_STEP )
2049 HASH_Init( &HASHcontext );
2050 if( prefix != NULL && prefix->bv_len > 0 ) {
2051 HASH_Update( &HASHcontext,
2052 prefix->bv_val, prefix->bv_len );
2054 HASH_Update( &HASHcontext,
2055 &pre, sizeof( pre ) );
2056 HASH_Update( &HASHcontext,
2057 syntax->ssyn_oid, slen );
2058 HASH_Update( &HASHcontext,
2059 mr->smr_oid, mlen );
2060 HASH_Update( &HASHcontext,
2061 &value->bv_val[j], klen );
2062 HASH_Final( HASHdigest, &HASHcontext );
2064 keys[nkeys++] = ber_bvdup( &digest );
2070 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2071 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2073 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2074 value = sa->sa_final;
2076 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2077 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2079 HASH_Init( &HASHcontext );
2080 if( prefix != NULL && prefix->bv_len > 0 ) {
2081 HASH_Update( &HASHcontext,
2082 prefix->bv_val, prefix->bv_len );
2084 HASH_Update( &HASHcontext,
2085 &pre, sizeof( pre ) );
2086 HASH_Update( &HASHcontext,
2087 syntax->ssyn_oid, slen );
2088 HASH_Update( &HASHcontext,
2089 mr->smr_oid, mlen );
2090 HASH_Update( &HASHcontext,
2091 &value->bv_val[value->bv_len-klen], klen );
2092 HASH_Final( HASHdigest, &HASHcontext );
2094 keys[nkeys++] = ber_bvdup( &digest );
2104 ber_bvfree( sa->sa_final );
2105 ber_bvecfree( sa->sa_any );
2106 ber_bvfree( sa->sa_initial );
2109 return LDAP_SUCCESS;
2118 struct berval *value,
2119 void *assertedValue )
2121 *matchp = UTF8normcmp( value->bv_val,
2122 ((struct berval *) assertedValue)->bv_val,
2124 return LDAP_SUCCESS;
2130 struct berval *val )
2134 if( val->bv_len == 0 ) {
2135 /* disallow empty strings */
2136 return LDAP_INVALID_SYNTAX;
2139 if( OID_LEADCHAR(val->bv_val[0]) ) {
2141 for(i=1; i < val->bv_len; i++) {
2142 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2143 if( dot++ ) return 1;
2144 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2147 return LDAP_INVALID_SYNTAX;
2151 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2153 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2154 for(i=1; i < val->bv_len; i++) {
2155 if( !DESC_CHAR(val->bv_val[i] ) ) {
2156 return LDAP_INVALID_SYNTAX;
2160 return LDAP_SUCCESS;
2163 return LDAP_INVALID_SYNTAX;
2172 struct berval *value,
2173 void *assertedValue )
2176 int vsign=0, avsign=0;
2177 struct berval *asserted;
2178 ber_len_t vlen, avlen;
2181 /* Start off pessimistic */
2184 /* Skip past leading spaces/zeros, and get the sign of the *value number */
2186 vlen = value->bv_len;
2188 if( ASCII_SPACE(*v) || ( *v == '0' )) {
2189 /* empty -- skip spaces */
2191 else if ( *v == '+' ) {
2194 else if ( *v == '-' ) {
2197 else if ( ASCII_DIGIT(*v) ) {
2198 if ( vsign == 0 ) vsign = 1;
2206 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
2208 asserted = (struct berval *) assertedValue;
2209 av = asserted->bv_val;
2210 avlen = asserted->bv_len;
2212 if( ASCII_SPACE(*av) || ( *av == '0' )) {
2213 /* empty -- skip spaces */
2215 else if ( *av == '+' ) {
2218 else if ( *av == '-' ) {
2221 else if ( ASCII_DIGIT(*av) ) {
2222 if ( avsign == 0 ) avsign = 1;
2230 /* The two ?sign vars are now one of :
2231 -2 negative non-zero number
2233 0 0 collapse these three to 0
2235 +2 positive non-zero number
2237 if ( abs( vsign ) == 1 ) vsign = 0;
2238 if ( abs( avsign ) == 1 ) avsign = 0;
2240 if( vsign != avsign ) return LDAP_SUCCESS;
2242 /* Check the significant digits */
2243 while( vlen && avlen ) {
2244 if( *v != *av ) break;
2251 /* If all digits compared equal, the numbers are equal */
2252 if(( vlen == 0 ) && ( avlen == 0 )) {
2255 return LDAP_SUCCESS;
2261 struct berval *val )
2265 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2267 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
2268 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2269 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2270 return LDAP_INVALID_SYNTAX;
2273 for( i=1; i < val->bv_len; i++ ) {
2274 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2277 return LDAP_SUCCESS;
2284 struct berval **normalized )
2288 struct berval *newval;
2295 /* Ignore leading spaces */
2296 while ( len && ( *p == ' ' )) {
2303 negative = ( *p == '-' );
2304 if(( *p == '-' ) || ( *p == '+' )) {
2310 /* Ignore leading zeros */
2311 while ( len && ( *p == '0' )) {
2316 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2318 /* If there are no non-zero digits left, the number is zero, otherwise
2319 allocate space for the number and copy it into the buffer */
2321 newval->bv_val = ch_strdup("0");
2325 newval->bv_len = len+negative;
2326 newval->bv_val = ch_malloc( newval->bv_len );
2328 newval->bv_val[0] = '-';
2330 memcpy( newval->bv_val + negative, p, len );
2333 *normalized = newval;
2334 return LDAP_SUCCESS;
2337 /* Index generation function */
2343 struct berval *prefix,
2344 struct berval **values,
2345 struct berval ***keysp )
2348 struct berval **keys;
2350 /* we should have at least one value at this point */
2351 assert( values != NULL && values[0] != NULL );
2353 for( i=0; values[i] != NULL; i++ ) {
2354 /* empty -- just count them */
2357 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2359 for( i=0; values[i] != NULL; i++ ) {
2360 integerNormalize( syntax, values[i], &keys[i] );
2365 return LDAP_SUCCESS;
2368 /* Index generation function */
2374 struct berval *prefix,
2376 struct berval ***keysp )
2378 struct berval **keys;
2380 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2381 integerNormalize( syntax, assertValue, &keys[0] );
2385 return LDAP_SUCCESS;
2390 countryStringValidate(
2392 struct berval *val )
2394 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2396 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2397 return LDAP_INVALID_SYNTAX;
2399 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2400 return LDAP_INVALID_SYNTAX;
2403 return LDAP_SUCCESS;
2407 printableStringValidate(
2409 struct berval *val )
2413 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2415 for(i=0; i < val->bv_len; i++) {
2416 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2417 return LDAP_INVALID_SYNTAX;
2421 return LDAP_SUCCESS;
2425 printablesStringValidate(
2427 struct berval *val )
2431 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2433 for(i=0; i < val->bv_len; i++) {
2434 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2435 return LDAP_INVALID_SYNTAX;
2439 return LDAP_SUCCESS;
2445 struct berval *val )
2449 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2451 for(i=0; i < val->bv_len; i++) {
2452 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2455 return LDAP_SUCCESS;
2462 struct berval **normalized )
2464 struct berval *newval;
2467 newval = ch_malloc( sizeof( struct berval ) );
2471 /* Ignore initial whitespace */
2472 while ( ASCII_SPACE( *p ) ) {
2478 return LDAP_INVALID_SYNTAX;
2481 newval->bv_val = ch_strdup( p );
2482 p = q = newval->bv_val;
2485 if ( ASCII_SPACE( *p ) ) {
2488 /* Ignore the extra whitespace */
2489 while ( ASCII_SPACE( *p ) ) {
2497 assert( *newval->bv_val );
2498 assert( newval->bv_val < p );
2501 /* cannot start with a space */
2502 assert( !ASCII_SPACE(*newval->bv_val) );
2505 * If the string ended in space, backup the pointer one
2506 * position. One is enough because the above loop collapsed
2507 * all whitespace to a single space.
2510 if ( ASCII_SPACE( q[-1] ) ) {
2514 /* cannot end with a space */
2515 assert( !ASCII_SPACE( q[-1] ) );
2517 /* null terminate */
2520 newval->bv_len = q - newval->bv_val;
2521 *normalized = newval;
2523 return LDAP_SUCCESS;
2532 struct berval *value,
2533 void *assertedValue )
2535 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2538 match = strncmp( value->bv_val,
2539 ((struct berval *) assertedValue)->bv_val,
2544 return LDAP_SUCCESS;
2548 caseExactIA5SubstringsMatch(
2553 struct berval *value,
2554 void *assertedValue )
2557 SubstringsAssertion *sub = assertedValue;
2558 struct berval left = *value;
2562 /* Add up asserted input length */
2563 if( sub->sa_initial ) {
2564 inlen += sub->sa_initial->bv_len;
2567 for(i=0; sub->sa_any[i] != NULL; i++) {
2568 inlen += sub->sa_any[i]->bv_len;
2571 if( sub->sa_final ) {
2572 inlen += sub->sa_final->bv_len;
2575 if( sub->sa_initial ) {
2576 if( inlen > left.bv_len ) {
2581 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2582 sub->sa_initial->bv_len );
2588 left.bv_val += sub->sa_initial->bv_len;
2589 left.bv_len -= sub->sa_initial->bv_len;
2590 inlen -= sub->sa_initial->bv_len;
2593 if( sub->sa_final ) {
2594 if( inlen > left.bv_len ) {
2599 match = strncmp( sub->sa_final->bv_val,
2600 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2601 sub->sa_final->bv_len );
2607 left.bv_len -= sub->sa_final->bv_len;
2608 inlen -= sub->sa_final->bv_len;
2612 for(i=0; sub->sa_any[i]; i++) {
2617 if( inlen > left.bv_len ) {
2618 /* not enough length */
2623 if( sub->sa_any[i]->bv_len == 0 ) {
2627 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2634 idx = p - left.bv_val;
2635 assert( idx < left.bv_len );
2637 if( idx >= left.bv_len ) {
2638 /* this shouldn't happen */
2645 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2646 /* not enough left */
2651 match = strncmp( left.bv_val,
2652 sub->sa_any[i]->bv_val,
2653 sub->sa_any[i]->bv_len );
2661 left.bv_val += sub->sa_any[i]->bv_len;
2662 left.bv_len -= sub->sa_any[i]->bv_len;
2663 inlen -= sub->sa_any[i]->bv_len;
2669 return LDAP_SUCCESS;
2672 /* Index generation function */
2673 int caseExactIA5Indexer(
2678 struct berval *prefix,
2679 struct berval **values,
2680 struct berval ***keysp )
2684 struct berval **keys;
2685 HASH_CONTEXT HASHcontext;
2686 unsigned char HASHdigest[HASH_BYTES];
2687 struct berval digest;
2688 digest.bv_val = HASHdigest;
2689 digest.bv_len = sizeof(HASHdigest);
2691 for( i=0; values[i] != NULL; i++ ) {
2692 /* empty - just count them */
2695 /* we should have at least one value at this point */
2698 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2700 slen = strlen( syntax->ssyn_oid );
2701 mlen = strlen( mr->smr_oid );
2703 for( i=0; values[i] != NULL; i++ ) {
2704 struct berval *value = values[i];
2706 HASH_Init( &HASHcontext );
2707 if( prefix != NULL && prefix->bv_len > 0 ) {
2708 HASH_Update( &HASHcontext,
2709 prefix->bv_val, prefix->bv_len );
2711 HASH_Update( &HASHcontext,
2712 syntax->ssyn_oid, slen );
2713 HASH_Update( &HASHcontext,
2714 mr->smr_oid, mlen );
2715 HASH_Update( &HASHcontext,
2716 value->bv_val, value->bv_len );
2717 HASH_Final( HASHdigest, &HASHcontext );
2719 keys[i] = ber_bvdup( &digest );
2724 return LDAP_SUCCESS;
2727 /* Index generation function */
2728 int caseExactIA5Filter(
2733 struct berval *prefix,
2735 struct berval ***keysp )
2738 struct berval **keys;
2739 HASH_CONTEXT HASHcontext;
2740 unsigned char HASHdigest[HASH_BYTES];
2741 struct berval *value;
2742 struct berval digest;
2743 digest.bv_val = HASHdigest;
2744 digest.bv_len = sizeof(HASHdigest);
2746 slen = strlen( syntax->ssyn_oid );
2747 mlen = strlen( mr->smr_oid );
2749 value = (struct berval *) assertValue;
2751 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2753 HASH_Init( &HASHcontext );
2754 if( prefix != NULL && prefix->bv_len > 0 ) {
2755 HASH_Update( &HASHcontext,
2756 prefix->bv_val, prefix->bv_len );
2758 HASH_Update( &HASHcontext,
2759 syntax->ssyn_oid, slen );
2760 HASH_Update( &HASHcontext,
2761 mr->smr_oid, mlen );
2762 HASH_Update( &HASHcontext,
2763 value->bv_val, value->bv_len );
2764 HASH_Final( HASHdigest, &HASHcontext );
2766 keys[0] = ber_bvdup( &digest );
2770 return LDAP_SUCCESS;
2773 /* Substrings Index generation function */
2774 int caseExactIA5SubstringsIndexer(
2779 struct berval *prefix,
2780 struct berval **values,
2781 struct berval ***keysp )
2785 struct berval **keys;
2786 HASH_CONTEXT HASHcontext;
2787 unsigned char HASHdigest[HASH_BYTES];
2788 struct berval digest;
2789 digest.bv_val = HASHdigest;
2790 digest.bv_len = sizeof(HASHdigest);
2792 /* we should have at least one value at this point */
2793 assert( values != NULL && values[0] != NULL );
2796 for( i=0; values[i] != NULL; i++ ) {
2797 /* count number of indices to generate */
2798 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2802 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2803 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2804 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2805 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2807 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2811 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2812 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2813 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2817 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2818 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2819 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2820 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2822 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2828 /* no keys to generate */
2830 return LDAP_SUCCESS;
2833 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2835 slen = strlen( syntax->ssyn_oid );
2836 mlen = strlen( mr->smr_oid );
2839 for( i=0; values[i] != NULL; i++ ) {
2841 struct berval *value;
2844 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2846 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2847 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2849 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2850 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2852 for( j=0; j<max; j++ ) {
2853 HASH_Init( &HASHcontext );
2854 if( prefix != NULL && prefix->bv_len > 0 ) {
2855 HASH_Update( &HASHcontext,
2856 prefix->bv_val, prefix->bv_len );
2859 HASH_Update( &HASHcontext,
2860 &pre, sizeof( pre ) );
2861 HASH_Update( &HASHcontext,
2862 syntax->ssyn_oid, slen );
2863 HASH_Update( &HASHcontext,
2864 mr->smr_oid, mlen );
2865 HASH_Update( &HASHcontext,
2867 SLAP_INDEX_SUBSTR_MAXLEN );
2868 HASH_Final( HASHdigest, &HASHcontext );
2870 keys[nkeys++] = ber_bvdup( &digest );
2874 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2875 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2877 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2880 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2881 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2882 HASH_Init( &HASHcontext );
2883 if( prefix != NULL && prefix->bv_len > 0 ) {
2884 HASH_Update( &HASHcontext,
2885 prefix->bv_val, prefix->bv_len );
2887 HASH_Update( &HASHcontext,
2888 &pre, sizeof( pre ) );
2889 HASH_Update( &HASHcontext,
2890 syntax->ssyn_oid, slen );
2891 HASH_Update( &HASHcontext,
2892 mr->smr_oid, mlen );
2893 HASH_Update( &HASHcontext,
2895 HASH_Final( HASHdigest, &HASHcontext );
2897 keys[nkeys++] = ber_bvdup( &digest );
2900 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2901 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2902 HASH_Init( &HASHcontext );
2903 if( prefix != NULL && prefix->bv_len > 0 ) {
2904 HASH_Update( &HASHcontext,
2905 prefix->bv_val, prefix->bv_len );
2907 HASH_Update( &HASHcontext,
2908 &pre, sizeof( pre ) );
2909 HASH_Update( &HASHcontext,
2910 syntax->ssyn_oid, slen );
2911 HASH_Update( &HASHcontext,
2912 mr->smr_oid, mlen );
2913 HASH_Update( &HASHcontext,
2914 &value->bv_val[value->bv_len-j], j );
2915 HASH_Final( HASHdigest, &HASHcontext );
2917 keys[nkeys++] = ber_bvdup( &digest );
2931 return LDAP_SUCCESS;
2934 int caseExactIA5SubstringsFilter(
2939 struct berval *prefix,
2941 struct berval ***keysp )
2943 SubstringsAssertion *sa = assertValue;
2945 ber_len_t nkeys = 0;
2946 size_t slen, mlen, klen;
2947 struct berval **keys;
2948 HASH_CONTEXT HASHcontext;
2949 unsigned char HASHdigest[HASH_BYTES];
2950 struct berval *value;
2951 struct berval digest;
2953 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2954 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2959 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2961 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2962 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2963 /* don't bother accounting for stepping */
2964 nkeys += sa->sa_any[i]->bv_len -
2965 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2970 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2971 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2978 return LDAP_SUCCESS;
2981 digest.bv_val = HASHdigest;
2982 digest.bv_len = sizeof(HASHdigest);
2984 slen = strlen( syntax->ssyn_oid );
2985 mlen = strlen( mr->smr_oid );
2987 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2990 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2991 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2993 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2994 value = sa->sa_initial;
2996 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2997 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2999 HASH_Init( &HASHcontext );
3000 if( prefix != NULL && prefix->bv_len > 0 ) {
3001 HASH_Update( &HASHcontext,
3002 prefix->bv_val, prefix->bv_len );
3004 HASH_Update( &HASHcontext,
3005 &pre, sizeof( pre ) );
3006 HASH_Update( &HASHcontext,
3007 syntax->ssyn_oid, slen );
3008 HASH_Update( &HASHcontext,
3009 mr->smr_oid, mlen );
3010 HASH_Update( &HASHcontext,
3011 value->bv_val, klen );
3012 HASH_Final( HASHdigest, &HASHcontext );
3014 keys[nkeys++] = ber_bvdup( &digest );
3017 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
3019 pre = SLAP_INDEX_SUBSTR_PREFIX;
3020 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3022 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3023 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3027 value = sa->sa_any[i];
3030 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3031 j += SLAP_INDEX_SUBSTR_STEP )
3033 HASH_Init( &HASHcontext );
3034 if( prefix != NULL && prefix->bv_len > 0 ) {
3035 HASH_Update( &HASHcontext,
3036 prefix->bv_val, prefix->bv_len );
3038 HASH_Update( &HASHcontext,
3039 &pre, sizeof( pre ) );
3040 HASH_Update( &HASHcontext,
3041 syntax->ssyn_oid, slen );
3042 HASH_Update( &HASHcontext,
3043 mr->smr_oid, mlen );
3044 HASH_Update( &HASHcontext,
3045 &value->bv_val[j], klen );
3046 HASH_Final( HASHdigest, &HASHcontext );
3048 keys[nkeys++] = ber_bvdup( &digest );
3053 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
3054 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3056 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3057 value = sa->sa_final;
3059 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3060 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3062 HASH_Init( &HASHcontext );
3063 if( prefix != NULL && prefix->bv_len > 0 ) {
3064 HASH_Update( &HASHcontext,
3065 prefix->bv_val, prefix->bv_len );
3067 HASH_Update( &HASHcontext,
3068 &pre, sizeof( pre ) );
3069 HASH_Update( &HASHcontext,
3070 syntax->ssyn_oid, slen );
3071 HASH_Update( &HASHcontext,
3072 mr->smr_oid, mlen );
3073 HASH_Update( &HASHcontext,
3074 &value->bv_val[value->bv_len-klen], klen );
3075 HASH_Final( HASHdigest, &HASHcontext );
3077 keys[nkeys++] = ber_bvdup( &digest );
3088 return LDAP_SUCCESS;
3097 struct berval *value,
3098 void *assertedValue )
3100 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3102 if( match == 0 && value->bv_len ) {
3103 match = strncasecmp( value->bv_val,
3104 ((struct berval *) assertedValue)->bv_val,
3109 return LDAP_SUCCESS;
3113 caseIgnoreIA5SubstringsMatch(
3118 struct berval *value,
3119 void *assertedValue )
3122 SubstringsAssertion *sub = assertedValue;
3123 struct berval left = *value;
3127 /* Add up asserted input length */
3128 if( sub->sa_initial ) {
3129 inlen += sub->sa_initial->bv_len;
3132 for(i=0; sub->sa_any[i] != NULL; i++) {
3133 inlen += sub->sa_any[i]->bv_len;
3136 if( sub->sa_final ) {
3137 inlen += sub->sa_final->bv_len;
3140 if( sub->sa_initial ) {
3141 if( inlen > left.bv_len ) {
3146 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3147 sub->sa_initial->bv_len );
3153 left.bv_val += sub->sa_initial->bv_len;
3154 left.bv_len -= sub->sa_initial->bv_len;
3155 inlen -= sub->sa_initial->bv_len;
3158 if( sub->sa_final ) {
3159 if( inlen > left.bv_len ) {
3164 match = strncasecmp( sub->sa_final->bv_val,
3165 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3166 sub->sa_final->bv_len );
3172 left.bv_len -= sub->sa_final->bv_len;
3173 inlen -= sub->sa_final->bv_len;
3177 for(i=0; sub->sa_any[i]; i++) {
3182 if( inlen > left.bv_len ) {
3183 /* not enough length */
3188 if( sub->sa_any[i]->bv_len == 0 ) {
3192 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3199 idx = p - left.bv_val;
3200 assert( idx < left.bv_len );
3202 if( idx >= left.bv_len ) {
3203 /* this shouldn't happen */
3210 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3211 /* not enough left */
3216 match = strncasecmp( left.bv_val,
3217 sub->sa_any[i]->bv_val,
3218 sub->sa_any[i]->bv_len );
3227 left.bv_val += sub->sa_any[i]->bv_len;
3228 left.bv_len -= sub->sa_any[i]->bv_len;
3229 inlen -= sub->sa_any[i]->bv_len;
3235 return LDAP_SUCCESS;
3238 /* Index generation function */
3239 int caseIgnoreIA5Indexer(
3244 struct berval *prefix,
3245 struct berval **values,
3246 struct berval ***keysp )
3250 struct berval **keys;
3251 HASH_CONTEXT HASHcontext;
3252 unsigned char HASHdigest[HASH_BYTES];
3253 struct berval digest;
3254 digest.bv_val = HASHdigest;
3255 digest.bv_len = sizeof(HASHdigest);
3257 /* we should have at least one value at this point */
3258 assert( values != NULL && values[0] != NULL );
3260 for( i=0; values[i] != NULL; i++ ) {
3261 /* just count them */
3264 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3266 slen = strlen( syntax->ssyn_oid );
3267 mlen = strlen( mr->smr_oid );
3269 for( i=0; values[i] != NULL; i++ ) {
3270 struct berval *value = ber_bvdup( values[i] );
3271 ldap_pvt_str2upper( value->bv_val );
3273 HASH_Init( &HASHcontext );
3274 if( prefix != NULL && prefix->bv_len > 0 ) {
3275 HASH_Update( &HASHcontext,
3276 prefix->bv_val, prefix->bv_len );
3278 HASH_Update( &HASHcontext,
3279 syntax->ssyn_oid, slen );
3280 HASH_Update( &HASHcontext,
3281 mr->smr_oid, mlen );
3282 HASH_Update( &HASHcontext,
3283 value->bv_val, value->bv_len );
3284 HASH_Final( HASHdigest, &HASHcontext );
3286 ber_bvfree( value );
3288 keys[i] = ber_bvdup( &digest );
3293 return LDAP_SUCCESS;
3296 /* Index generation function */
3297 int caseIgnoreIA5Filter(
3302 struct berval *prefix,
3304 struct berval ***keysp )
3307 struct berval **keys;
3308 HASH_CONTEXT HASHcontext;
3309 unsigned char HASHdigest[HASH_BYTES];
3310 struct berval *value;
3311 struct berval digest;
3312 digest.bv_val = HASHdigest;
3313 digest.bv_len = sizeof(HASHdigest);
3315 slen = strlen( syntax->ssyn_oid );
3316 mlen = strlen( mr->smr_oid );
3318 value = ber_bvdup( (struct berval *) assertValue );
3319 ldap_pvt_str2upper( value->bv_val );
3321 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3323 HASH_Init( &HASHcontext );
3324 if( prefix != NULL && prefix->bv_len > 0 ) {
3325 HASH_Update( &HASHcontext,
3326 prefix->bv_val, prefix->bv_len );
3328 HASH_Update( &HASHcontext,
3329 syntax->ssyn_oid, slen );
3330 HASH_Update( &HASHcontext,
3331 mr->smr_oid, mlen );
3332 HASH_Update( &HASHcontext,
3333 value->bv_val, value->bv_len );
3334 HASH_Final( HASHdigest, &HASHcontext );
3336 keys[0] = ber_bvdup( &digest );
3339 ber_bvfree( value );
3343 return LDAP_SUCCESS;
3346 /* Substrings Index generation function */
3347 int caseIgnoreIA5SubstringsIndexer(
3352 struct berval *prefix,
3353 struct berval **values,
3354 struct berval ***keysp )
3358 struct berval **keys;
3359 HASH_CONTEXT HASHcontext;
3360 unsigned char HASHdigest[HASH_BYTES];
3361 struct berval digest;
3362 digest.bv_val = HASHdigest;
3363 digest.bv_len = sizeof(HASHdigest);
3365 /* we should have at least one value at this point */
3366 assert( values != NULL && values[0] != NULL );
3369 for( i=0; values[i] != NULL; i++ ) {
3370 /* count number of indices to generate */
3371 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3375 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3376 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3377 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3378 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3380 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3384 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3385 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3386 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3390 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3391 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3392 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3393 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3395 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3401 /* no keys to generate */
3403 return LDAP_SUCCESS;
3406 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3408 slen = strlen( syntax->ssyn_oid );
3409 mlen = strlen( mr->smr_oid );
3412 for( i=0; values[i] != NULL; i++ ) {
3414 struct berval *value;
3416 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3418 value = ber_bvdup( values[i] );
3419 ldap_pvt_str2upper( value->bv_val );
3421 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3422 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3424 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3425 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3427 for( j=0; j<max; j++ ) {
3428 HASH_Init( &HASHcontext );
3429 if( prefix != NULL && prefix->bv_len > 0 ) {
3430 HASH_Update( &HASHcontext,
3431 prefix->bv_val, prefix->bv_len );
3434 HASH_Update( &HASHcontext,
3435 &pre, sizeof( pre ) );
3436 HASH_Update( &HASHcontext,
3437 syntax->ssyn_oid, slen );
3438 HASH_Update( &HASHcontext,
3439 mr->smr_oid, mlen );
3440 HASH_Update( &HASHcontext,
3442 SLAP_INDEX_SUBSTR_MAXLEN );
3443 HASH_Final( HASHdigest, &HASHcontext );
3445 keys[nkeys++] = ber_bvdup( &digest );
3449 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3450 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3452 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3455 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3456 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3457 HASH_Init( &HASHcontext );
3458 if( prefix != NULL && prefix->bv_len > 0 ) {
3459 HASH_Update( &HASHcontext,
3460 prefix->bv_val, prefix->bv_len );
3462 HASH_Update( &HASHcontext,
3463 &pre, sizeof( pre ) );
3464 HASH_Update( &HASHcontext,
3465 syntax->ssyn_oid, slen );
3466 HASH_Update( &HASHcontext,
3467 mr->smr_oid, mlen );
3468 HASH_Update( &HASHcontext,
3470 HASH_Final( HASHdigest, &HASHcontext );
3472 keys[nkeys++] = ber_bvdup( &digest );
3475 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3476 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3477 HASH_Init( &HASHcontext );
3478 if( prefix != NULL && prefix->bv_len > 0 ) {
3479 HASH_Update( &HASHcontext,
3480 prefix->bv_val, prefix->bv_len );
3482 HASH_Update( &HASHcontext,
3483 &pre, sizeof( pre ) );
3484 HASH_Update( &HASHcontext,
3485 syntax->ssyn_oid, slen );
3486 HASH_Update( &HASHcontext,
3487 mr->smr_oid, mlen );
3488 HASH_Update( &HASHcontext,
3489 &value->bv_val[value->bv_len-j], j );
3490 HASH_Final( HASHdigest, &HASHcontext );
3492 keys[nkeys++] = ber_bvdup( &digest );
3497 ber_bvfree( value );
3508 return LDAP_SUCCESS;
3511 int caseIgnoreIA5SubstringsFilter(
3516 struct berval *prefix,
3518 struct berval ***keysp )
3520 SubstringsAssertion *sa = assertValue;
3522 ber_len_t nkeys = 0;
3523 size_t slen, mlen, klen;
3524 struct berval **keys;
3525 HASH_CONTEXT HASHcontext;
3526 unsigned char HASHdigest[HASH_BYTES];
3527 struct berval *value;
3528 struct berval digest;
3530 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3531 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3536 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3538 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3539 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3540 /* don't bother accounting for stepping */
3541 nkeys += sa->sa_any[i]->bv_len -
3542 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3547 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3548 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3555 return LDAP_SUCCESS;
3558 digest.bv_val = HASHdigest;
3559 digest.bv_len = sizeof(HASHdigest);
3561 slen = strlen( syntax->ssyn_oid );
3562 mlen = strlen( mr->smr_oid );
3564 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3567 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3568 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3570 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3571 value = ber_bvdup( sa->sa_initial );
3572 ldap_pvt_str2upper( value->bv_val );
3574 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3575 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3577 HASH_Init( &HASHcontext );
3578 if( prefix != NULL && prefix->bv_len > 0 ) {
3579 HASH_Update( &HASHcontext,
3580 prefix->bv_val, prefix->bv_len );
3582 HASH_Update( &HASHcontext,
3583 &pre, sizeof( pre ) );
3584 HASH_Update( &HASHcontext,
3585 syntax->ssyn_oid, slen );
3586 HASH_Update( &HASHcontext,
3587 mr->smr_oid, mlen );
3588 HASH_Update( &HASHcontext,
3589 value->bv_val, klen );
3590 HASH_Final( HASHdigest, &HASHcontext );
3592 ber_bvfree( value );
3593 keys[nkeys++] = ber_bvdup( &digest );
3596 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3598 pre = SLAP_INDEX_SUBSTR_PREFIX;
3599 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3601 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3602 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3606 value = ber_bvdup( sa->sa_any[i] );
3607 ldap_pvt_str2upper( value->bv_val );
3610 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3611 j += SLAP_INDEX_SUBSTR_STEP )
3613 HASH_Init( &HASHcontext );
3614 if( prefix != NULL && prefix->bv_len > 0 ) {
3615 HASH_Update( &HASHcontext,
3616 prefix->bv_val, prefix->bv_len );
3618 HASH_Update( &HASHcontext,
3619 &pre, sizeof( pre ) );
3620 HASH_Update( &HASHcontext,
3621 syntax->ssyn_oid, slen );
3622 HASH_Update( &HASHcontext,
3623 mr->smr_oid, mlen );
3624 HASH_Update( &HASHcontext,
3625 &value->bv_val[j], klen );
3626 HASH_Final( HASHdigest, &HASHcontext );
3628 keys[nkeys++] = ber_bvdup( &digest );
3631 ber_bvfree( value );
3635 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3636 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3638 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3639 value = ber_bvdup( sa->sa_final );
3640 ldap_pvt_str2upper( value->bv_val );
3642 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3643 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3645 HASH_Init( &HASHcontext );
3646 if( prefix != NULL && prefix->bv_len > 0 ) {
3647 HASH_Update( &HASHcontext,
3648 prefix->bv_val, prefix->bv_len );
3650 HASH_Update( &HASHcontext,
3651 &pre, sizeof( pre ) );
3652 HASH_Update( &HASHcontext,
3653 syntax->ssyn_oid, slen );
3654 HASH_Update( &HASHcontext,
3655 mr->smr_oid, mlen );
3656 HASH_Update( &HASHcontext,
3657 &value->bv_val[value->bv_len-klen], klen );
3658 HASH_Final( HASHdigest, &HASHcontext );
3660 ber_bvfree( value );
3661 keys[nkeys++] = ber_bvdup( &digest );
3672 return LDAP_SUCCESS;
3676 numericStringValidate(
3682 for(i=0; i < in->bv_len; i++) {
3683 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3684 return LDAP_INVALID_SYNTAX;
3688 return LDAP_SUCCESS;
3692 numericStringNormalize(
3695 struct berval **normalized )
3697 /* removal all spaces */
3698 struct berval *newval;
3701 newval = ch_malloc( sizeof( struct berval ) );
3702 newval->bv_val = ch_malloc( val->bv_len + 1 );
3708 if ( ASCII_SPACE( *p ) ) {
3709 /* Ignore whitespace */
3716 /* we should have copied no more then is in val */
3717 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3719 /* null terminate */
3722 newval->bv_len = q - newval->bv_val;
3723 *normalized = newval;
3725 return LDAP_SUCCESS;
3729 objectIdentifierFirstComponentMatch(
3734 struct berval *value,
3735 void *assertedValue )
3737 int rc = LDAP_SUCCESS;
3739 struct berval *asserted = (struct berval *) assertedValue;
3743 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3744 return LDAP_INVALID_SYNTAX;
3747 /* trim leading white space */
3748 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3752 /* grab next word */
3753 oid.bv_val = &value->bv_val[i];
3754 oid.bv_len = value->bv_len - i;
3755 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3760 /* insert attributeTypes, objectclass check here */
3761 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3762 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3765 char *stored = ch_malloc( oid.bv_len + 1 );
3766 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3767 stored[oid.bv_len] = '\0';
3769 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3770 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3771 MatchingRule *stored_mr = mr_find( stored );
3773 if( asserted_mr == NULL ) {
3774 rc = SLAPD_COMPARE_UNDEFINED;
3776 match = asserted_mr != stored_mr;
3779 } else if ( !strcmp( syntax->ssyn_oid,
3780 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3782 AttributeType *asserted_at = at_find( asserted->bv_val );
3783 AttributeType *stored_at = at_find( stored );
3785 if( asserted_at == NULL ) {
3786 rc = SLAPD_COMPARE_UNDEFINED;
3788 match = asserted_at != stored_at;
3791 } else if ( !strcmp( syntax->ssyn_oid,
3792 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3794 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3795 ObjectClass *stored_oc = oc_find( stored );
3797 if( asserted_oc == NULL ) {
3798 rc = SLAPD_COMPARE_UNDEFINED;
3800 match = asserted_oc != stored_oc;
3808 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3809 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3810 match, value->bv_val, asserted->bv_val ));
3812 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3813 "%d\n\t\"%s\"\n\t\"%s\"\n",
3814 match, value->bv_val, asserted->bv_val );
3818 if( rc == LDAP_SUCCESS ) *matchp = match;
3828 struct berval *value,
3829 void *assertedValue )
3831 long lValue, lAssertedValue;
3833 /* safe to assume integers are NUL terminated? */
3834 lValue = strtoul(value->bv_val, NULL, 10);
3835 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3836 return LDAP_CONSTRAINT_VIOLATION;
3838 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3839 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3840 return LDAP_CONSTRAINT_VIOLATION;
3842 *matchp = (lValue & lAssertedValue);
3843 return LDAP_SUCCESS;
3852 struct berval *value,
3853 void *assertedValue )
3855 long lValue, lAssertedValue;
3857 /* safe to assume integers are NUL terminated? */
3858 lValue = strtoul(value->bv_val, NULL, 10);
3859 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3860 return LDAP_CONSTRAINT_VIOLATION;
3862 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3863 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3864 return LDAP_CONSTRAINT_VIOLATION;
3866 *matchp = (lValue | lAssertedValue);
3867 return LDAP_SUCCESS;
3871 #include <openssl/x509.h>
3872 #include <openssl/err.h>
3873 char digit[] = "0123456789";
3876 * Next function returns a string representation of a ASN1_INTEGER.
3877 * It works for unlimited lengths.
3880 static struct berval *
3881 asn1_integer2str(ASN1_INTEGER *a)
3886 /* We work backwards, make it fill from the end of buf */
3887 p = buf + sizeof(buf) - 1;
3890 if ( a == NULL || a->length == 0 ) {
3898 /* We want to preserve the original */
3899 copy = ch_malloc(n*sizeof(unsigned int));
3900 for (i = 0; i<n; i++) {
3901 copy[i] = a->data[i];
3905 * base indicates the index of the most significant
3906 * byte that might be nonzero. When it goes off the
3907 * end, we now there is nothing left to do.
3913 for (i = base; i<n; i++ ) {
3914 copy[i] += carry*256;
3915 carry = copy[i] % 10;
3920 * Way too large, we need to leave
3921 * room for sign if negative
3926 *--p = digit[carry];
3927 if (copy[base] == 0)
3933 if ( a->type == V_ASN1_NEG_INTEGER ) {
3937 return ber_bvstrdup(p);
3940 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3941 static struct berval *
3942 dn_openssl2ldap(X509_NAME *name)
3944 char issuer_dn[1024];
3947 bio = BIO_new(BIO_s_mem());
3950 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3951 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3952 ERR_error_string(ERR_get_error(),NULL)));
3954 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3955 "error creating BIO: %s\n",
3956 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3960 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3962 BIO_gets(bio, issuer_dn, 1024);
3965 return ber_bvstrdup(issuer_dn);
3969 * Given a certificate in DER format, extract the corresponding
3970 * assertion value for certificateExactMatch
3973 certificateExactConvert(
3975 struct berval ** out )
3978 unsigned char *p = in->bv_val;
3979 struct berval *serial;
3980 struct berval *issuer_dn;
3981 struct berval *bv_tmp;
3983 xcert = d2i_X509(NULL, &p, in->bv_len);
3986 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3987 "certificateExactConvert: error parsing cert: %s\n",
3988 ERR_error_string(ERR_get_error(),NULL)));
3990 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3991 "error parsing cert: %s\n",
3992 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3994 return LDAP_INVALID_SYNTAX;
3997 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4000 return LDAP_INVALID_SYNTAX;
4002 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4006 return LDAP_INVALID_SYNTAX;
4008 /* Actually, dn_openssl2ldap returns in a normalized format, but
4009 it is different from our normalized format */
4011 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
4015 return LDAP_INVALID_SYNTAX;
4021 *out = ch_malloc(sizeof(struct berval));
4022 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
4023 (*out)->bv_val = ch_malloc((*out)->bv_len);
4025 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
4026 p += serial->bv_len;
4027 AC_MEMCPY(p, " $ ", 3);
4029 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
4030 p += issuer_dn->bv_len;
4034 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4035 "certificateExactConvert: \n %s\n",
4038 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
4040 (*out)->bv_val, NULL, NULL );
4044 ber_bvfree(issuer_dn);
4046 return LDAP_SUCCESS;
4050 serial_and_issuer_parse(
4051 struct berval *assertion,
4052 struct berval **serial,
4053 struct berval **issuer_dn
4061 begin = assertion->bv_val;
4062 end = assertion->bv_val+assertion->bv_len-1;
4063 for (p=begin; p<=end && *p != '$'; p++)
4066 return LDAP_INVALID_SYNTAX;
4068 /* p now points at the $ sign, now use begin and end to delimit the
4070 while (ASCII_SPACE(*begin))
4073 while (ASCII_SPACE(*end))
4076 q = ch_malloc( (end-begin+1)+1 );
4077 AC_MEMCPY( q, begin, end-begin+1 );
4078 q[end-begin+1] = '\0';
4079 *serial = ber_bvstr(q);
4081 /* now extract the issuer, remember p was at the dollar sign */
4083 end = assertion->bv_val+assertion->bv_len-1;
4084 while (ASCII_SPACE(*begin))
4086 /* should we trim spaces at the end too? is it safe always? */
4088 q = ch_malloc( (end-begin+1)+1 );
4089 AC_MEMCPY( q, begin, end-begin+1 );
4090 q[end-begin+1] = '\0';
4091 *issuer_dn = ber_bvstr(dn_normalize(q));
4093 return LDAP_SUCCESS;
4097 certificateExactMatch(
4102 struct berval *value,
4103 void *assertedValue )
4106 unsigned char *p = value->bv_val;
4107 struct berval *serial;
4108 struct berval *issuer_dn;
4109 struct berval *asserted_serial;
4110 struct berval *asserted_issuer_dn;
4113 xcert = d2i_X509(NULL, &p, value->bv_len);
4116 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4117 "certificateExactMatch: error parsing cert: %s\n",
4118 ERR_error_string(ERR_get_error(),NULL)));
4120 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
4121 "error parsing cert: %s\n",
4122 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4124 return LDAP_INVALID_SYNTAX;
4127 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4128 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4132 serial_and_issuer_parse(assertedValue,
4134 &asserted_issuer_dn);
4139 slap_schema.si_syn_integer,
4140 slap_schema.si_mr_integerMatch,
4143 if ( ret == LDAP_SUCCESS ) {
4144 if ( *matchp == 0 ) {
4145 /* We need to normalize everything for dnMatch */
4149 slap_schema.si_syn_distinguishedName,
4150 slap_schema.si_mr_distinguishedNameMatch,
4152 asserted_issuer_dn);
4157 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4158 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
4159 *matchp, serial->bv_val, issuer_dn->bv_val,
4160 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
4162 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
4163 "%d\n\t\"%s $ %s\"\n",
4164 *matchp, serial->bv_val, issuer_dn->bv_val );
4165 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
4166 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
4171 ber_bvfree(issuer_dn);
4172 ber_bvfree(asserted_serial);
4173 ber_bvfree(asserted_issuer_dn);
4179 * Index generation function
4180 * We just index the serials, in most scenarios the issuer DN is one of
4181 * a very small set of values.
4183 int certificateExactIndexer(
4188 struct berval *prefix,
4189 struct berval **values,
4190 struct berval ***keysp )
4193 struct berval **keys;
4196 struct berval * serial;
4198 /* we should have at least one value at this point */
4199 assert( values != NULL && values[0] != NULL );
4201 for( i=0; values[i] != NULL; i++ ) {
4202 /* empty -- just count them */
4205 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
4207 for( i=0; values[i] != NULL; i++ ) {
4208 p = values[i]->bv_val;
4209 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
4212 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4213 "certificateExactIndexer: error parsing cert: %s\n",
4214 ERR_error_string(ERR_get_error(),NULL)));
4216 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4217 "error parsing cert: %s\n",
4218 ERR_error_string(ERR_get_error(),NULL),
4221 /* Do we leak keys on error? */
4222 return LDAP_INVALID_SYNTAX;
4225 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4227 integerNormalize( slap_schema.si_syn_integer,
4232 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4233 "certificateExactIndexer: returning: %s\n",
4236 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4245 return LDAP_SUCCESS;
4248 /* Index generation function */
4249 /* We think this is always called with a value in matching rule syntax */
4250 int certificateExactFilter(
4255 struct berval *prefix,
4257 struct berval ***keysp )
4259 struct berval **keys;
4260 struct berval *asserted_serial;
4261 struct berval *asserted_issuer_dn;
4263 serial_and_issuer_parse(assertValue,
4265 &asserted_issuer_dn);
4267 keys = ch_malloc( sizeof( struct berval * ) * 2 );
4268 integerNormalize( syntax, asserted_serial, &keys[0] );
4272 ber_bvfree(asserted_serial);
4273 ber_bvfree(asserted_issuer_dn);
4274 return LDAP_SUCCESS;
4279 check_time_syntax (struct berval *val,
4283 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
4284 static int mdays[2][12] = {
4285 /* non-leap years */
4286 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
4288 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
4291 int part, c, tzoffset, leapyear = 0 ;
4293 if( val->bv_len == 0 ) {
4294 return LDAP_INVALID_SYNTAX;
4297 p = (char *)val->bv_val;
4298 e = p + val->bv_len;
4300 /* Ignore initial whitespace */
4301 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4305 if (e - p < 13 - (2 * start)) {
4306 return LDAP_INVALID_SYNTAX;
4309 for (part = 0; part < 9; part++) {
4313 for (part = start; part < 7; part++) {
4315 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
4322 return LDAP_INVALID_SYNTAX;
4324 if (c < 0 || c > 9) {
4325 return LDAP_INVALID_SYNTAX;
4331 return LDAP_INVALID_SYNTAX;
4333 if (c < 0 || c > 9) {
4334 return LDAP_INVALID_SYNTAX;
4339 if (part == 2 || part == 3) {
4342 if (parts[part] < 0) {
4343 return LDAP_INVALID_SYNTAX;
4345 if (parts[part] > ceiling[part]) {
4346 return LDAP_INVALID_SYNTAX;
4350 /* leapyear check for the Gregorian calendar (year>1581) */
4351 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
4352 ((parts[0] % 4 == 0) && (parts[1] == 0)))
4357 if (parts[3] > mdays[leapyear][parts[2]]) {
4358 return LDAP_INVALID_SYNTAX;
4363 tzoffset = 0; /* UTC */
4364 } else if (c != '+' && c != '-') {
4365 return LDAP_INVALID_SYNTAX;
4369 } else /* c == '+' */ {
4374 return LDAP_INVALID_SYNTAX;
4377 for (part = 7; part < 9; part++) {
4379 if (c < 0 || c > 9) {
4380 return LDAP_INVALID_SYNTAX;
4385 if (c < 0 || c > 9) {
4386 return LDAP_INVALID_SYNTAX;
4390 if (parts[part] < 0 || parts[part] > ceiling[part]) {
4391 return LDAP_INVALID_SYNTAX;
4396 /* Ignore trailing whitespace */
4397 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4401 return LDAP_INVALID_SYNTAX;
4404 switch ( tzoffset ) {
4405 case -1: /* negativ offset to UTC, ie west of Greenwich */
4406 parts[4] += parts[7];
4407 parts[5] += parts[8];
4408 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
4412 c = mdays[leapyear][parts[2]];
4414 if (parts[part] > c) {
4415 parts[part] -= c + 1;
4420 case 1: /* positive offset to UTC, ie east of Greenwich */
4421 parts[4] -= parts[7];
4422 parts[5] -= parts[8];
4423 for (part = 6; --part > 0; ) {
4427 /* first arg to % needs to be non negativ */
4428 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
4430 if (parts[part] < 0) {
4431 parts[part] += c + 1;
4436 case 0: /* already UTC */
4440 return LDAP_SUCCESS;
4447 struct berval **normalized )
4452 rc = check_time_syntax(val, 1, parts);
4453 if (rc != LDAP_SUCCESS) {
4458 out = ch_malloc( sizeof(struct berval) );
4460 return LBER_ERROR_MEMORY;
4463 out->bv_val = ch_malloc( 14 );
4464 if ( out->bv_val == NULL ) {
4466 return LBER_ERROR_MEMORY;
4469 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02dZ",
4470 parts[1], parts[2] + 1, parts[3] + 1,
4471 parts[4], parts[5], parts[6] );
4475 return LDAP_SUCCESS;
4485 return check_time_syntax(in, 1, parts);
4489 generalizedTimeValidate(
4495 return check_time_syntax(in, 0, parts);
4499 generalizedTimeNormalize(
4502 struct berval **normalized )
4507 rc = check_time_syntax(val, 0, parts);
4508 if (rc != LDAP_SUCCESS) {
4513 out = ch_malloc( sizeof(struct berval) );
4515 return LBER_ERROR_MEMORY;
4518 out->bv_val = ch_malloc( 16 );
4519 if ( out->bv_val == NULL ) {
4521 return LBER_ERROR_MEMORY;
4524 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4525 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4526 parts[4], parts[5], parts[6] );
4530 return LDAP_SUCCESS;
4534 nisNetgroupTripleValidate(
4536 struct berval *val )
4541 if ( val->bv_len == 0 ) {
4542 return LDAP_INVALID_SYNTAX;
4545 p = (char *)val->bv_val;
4546 e = p + val->bv_len;
4548 if ( *p != '(' /*')'*/ ) {
4549 return LDAP_INVALID_SYNTAX;
4552 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4556 return LDAP_INVALID_SYNTAX;
4559 } else if ( !ATTR_CHAR( *p ) ) {
4560 return LDAP_INVALID_SYNTAX;
4564 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4565 return LDAP_INVALID_SYNTAX;
4571 return LDAP_INVALID_SYNTAX;
4574 return LDAP_SUCCESS;
4578 bootParameterValidate(
4580 struct berval *val )
4584 if ( val->bv_len == 0 ) {
4585 return LDAP_INVALID_SYNTAX;
4588 p = (char *)val->bv_val;
4589 e = p + val->bv_len;
4592 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4593 if ( !ATTR_CHAR( *p ) ) {
4594 return LDAP_INVALID_SYNTAX;
4599 return LDAP_INVALID_SYNTAX;
4603 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4604 if ( !ATTR_CHAR( *p ) ) {
4605 return LDAP_INVALID_SYNTAX;
4610 return LDAP_INVALID_SYNTAX;
4614 for ( p++; p < e; p++ ) {
4615 if ( !ATTR_CHAR( *p ) ) {
4616 return LDAP_INVALID_SYNTAX;
4620 return LDAP_SUCCESS;
4623 struct syntax_defs_rec {
4626 slap_syntax_validate_func *sd_validate;
4627 slap_syntax_transform_func *sd_normalize;
4628 slap_syntax_transform_func *sd_pretty;
4629 #ifdef SLAPD_BINARY_CONVERSION
4630 slap_syntax_transform_func *sd_ber2str;
4631 slap_syntax_transform_func *sd_str2ber;
4635 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4636 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4638 struct syntax_defs_rec syntax_defs[] = {
4639 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4640 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4641 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4642 0, NULL, NULL, NULL},
4643 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4644 0, NULL, NULL, NULL},
4645 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4646 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4647 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4648 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4649 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4650 0, bitStringValidate, bitStringNormalize, NULL },
4651 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4652 0, booleanValidate, NULL, NULL},
4653 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4654 X_BINARY X_NOT_H_R ")",
4655 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4656 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4657 X_BINARY X_NOT_H_R ")",
4658 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4659 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4660 X_BINARY X_NOT_H_R ")",
4661 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4662 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4663 0, countryStringValidate, IA5StringNormalize, NULL},
4664 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4665 0, dnValidate, dnNormalize, dnPretty},
4666 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4667 0, NULL, NULL, NULL},
4668 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4669 0, NULL, NULL, NULL},
4670 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4671 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4672 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4673 0, NULL, NULL, NULL},
4674 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4675 0, NULL, NULL, NULL},
4676 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4677 0, NULL, NULL, NULL},
4678 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4679 0, NULL, NULL, NULL},
4680 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4681 0, NULL, NULL, NULL},
4682 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4683 0, printablesStringValidate, IA5StringNormalize, NULL},
4684 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4685 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4686 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4687 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4688 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4689 0, NULL, NULL, NULL},
4690 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4691 0, IA5StringValidate, IA5StringNormalize, NULL},
4692 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4693 0, integerValidate, integerNormalize, NULL},
4694 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4695 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4696 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4697 0, NULL, NULL, NULL},
4698 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4699 0, NULL, NULL, NULL},
4700 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4701 0, NULL, NULL, NULL},
4702 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4703 0, NULL, NULL, NULL},
4704 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4705 0, NULL, NULL, NULL},
4706 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4707 0, nameUIDValidate, nameUIDNormalize, NULL},
4708 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4709 0, NULL, NULL, NULL},
4710 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4711 0, numericStringValidate, numericStringNormalize, NULL},
4712 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4713 0, NULL, NULL, NULL},
4714 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4715 0, oidValidate, NULL, NULL},
4716 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4717 0, IA5StringValidate, IA5StringNormalize, NULL},
4718 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4719 0, blobValidate, NULL, NULL},
4720 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4721 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4722 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4723 0, NULL, NULL, NULL},
4724 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4725 0, NULL, NULL, NULL},
4726 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4727 0, printableStringValidate, IA5StringNormalize, NULL},
4728 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
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.50 DESC 'Telephone Number' )",
4732 0, printableStringValidate, IA5StringNormalize, NULL},
4733 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4734 0, NULL, NULL, NULL},
4735 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4736 0, printablesStringValidate, IA5StringNormalize, NULL},
4737 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4738 0, utcTimeValidate, utcTimeNormalize, NULL},
4739 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4740 0, NULL, NULL, NULL},
4741 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4742 0, NULL, NULL, NULL},
4743 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4744 0, NULL, NULL, NULL},
4745 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4746 0, NULL, NULL, NULL},
4747 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4748 0, NULL, NULL, NULL},
4750 /* RFC 2307 NIS Syntaxes */
4751 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4752 0, nisNetgroupTripleValidate, NULL, NULL},
4753 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4754 0, bootParameterValidate, NULL, NULL},
4758 /* These OIDs are not published yet, but will be in the next
4759 * I-D for PKIX LDAPv3 schema as have been advanced by David
4760 * Chadwick in private mail.
4762 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4763 0, NULL, NULL, NULL},
4766 /* OpenLDAP Experimental Syntaxes */
4767 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4769 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4772 /* needs updating */
4773 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4774 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4776 /* OpenLDAP Void Syntax */
4777 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4778 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4779 {NULL, 0, NULL, NULL, NULL}
4782 struct mrule_defs_rec {
4784 slap_mask_t mrd_usage;
4785 slap_mr_convert_func * mrd_convert;
4786 slap_mr_normalize_func * mrd_normalize;
4787 slap_mr_match_func * mrd_match;
4788 slap_mr_indexer_func * mrd_indexer;
4789 slap_mr_filter_func * mrd_filter;
4791 char * mrd_associated;
4795 * Other matching rules in X.520 that we do not use (yet):
4797 * 2.5.13.9 numericStringOrderingMatch
4798 * 2.5.13.15 integerOrderingMatch
4799 * 2.5.13.18 octetStringOrderingMatch
4800 * 2.5.13.19 octetStringSubstringsMatch
4801 * 2.5.13.25 uTCTimeMatch
4802 * 2.5.13.26 uTCTimeOrderingMatch
4803 * 2.5.13.31 directoryStringFirstComponentMatch
4804 * 2.5.13.32 wordMatch
4805 * 2.5.13.33 keywordMatch
4806 * 2.5.13.35 certificateMatch
4807 * 2.5.13.36 certificatePairExactMatch
4808 * 2.5.13.37 certificatePairMatch
4809 * 2.5.13.38 certificateListExactMatch
4810 * 2.5.13.39 certificateListMatch
4811 * 2.5.13.40 algorithmIdentifierMatch
4812 * 2.5.13.41 storedPrefixMatch
4813 * 2.5.13.42 attributeCertificateMatch
4814 * 2.5.13.43 readerAndKeyIDMatch
4815 * 2.5.13.44 attributeIntegrityMatch
4818 struct mrule_defs_rec mrule_defs[] = {
4820 * EQUALITY matching rules must be listed after associated APPROX
4821 * matching rules. So, we list all APPROX matching rules first.
4823 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4824 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4825 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4827 directoryStringApproxMatch,
4828 directoryStringApproxIndexer,
4829 directoryStringApproxFilter,
4832 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4833 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4834 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4836 IA5StringApproxMatch,
4837 IA5StringApproxIndexer,
4838 IA5StringApproxFilter,
4842 * Other matching rules
4845 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4846 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4847 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4849 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4852 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4853 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4854 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4856 dnMatch, dnIndexer, dnFilter,
4859 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4860 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4861 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4863 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4864 directoryStringApproxMatchOID },
4866 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4867 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4870 caseIgnoreOrderingMatch, NULL, NULL,
4873 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4874 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4875 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4877 caseExactIgnoreSubstringsMatch,
4878 caseExactIgnoreSubstringsIndexer,
4879 caseExactIgnoreSubstringsFilter,
4882 {"( 2.5.13.5 NAME 'caseExactMatch' "
4883 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4884 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4886 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4887 directoryStringApproxMatchOID },
4889 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4890 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4893 caseExactOrderingMatch, NULL, NULL,
4896 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4897 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4898 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4900 caseExactIgnoreSubstringsMatch,
4901 caseExactIgnoreSubstringsIndexer,
4902 caseExactIgnoreSubstringsFilter,
4905 {"( 2.5.13.8 NAME 'numericStringMatch' "
4906 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4907 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4910 caseIgnoreIA5Indexer,
4911 caseIgnoreIA5Filter,
4914 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4915 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4916 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4918 caseIgnoreIA5SubstringsMatch,
4919 caseIgnoreIA5SubstringsIndexer,
4920 caseIgnoreIA5SubstringsFilter,
4923 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4924 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4925 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4927 caseIgnoreListMatch, NULL, NULL,
4930 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4931 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4932 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4934 caseIgnoreListSubstringsMatch, NULL, NULL,
4937 {"( 2.5.13.13 NAME 'booleanMatch' "
4938 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4939 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4941 booleanMatch, NULL, NULL,
4944 {"( 2.5.13.14 NAME 'integerMatch' "
4945 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4946 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4948 integerMatch, integerIndexer, integerFilter,
4951 {"( 2.5.13.16 NAME 'bitStringMatch' "
4952 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4953 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4955 bitStringMatch, bitStringIndexer, bitStringFilter,
4958 {"( 2.5.13.17 NAME 'octetStringMatch' "
4959 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4960 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4962 octetStringMatch, octetStringIndexer, octetStringFilter,
4965 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4966 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4967 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4969 telephoneNumberMatch,
4970 telephoneNumberIndexer,
4971 telephoneNumberFilter,
4974 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4975 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4976 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4978 telephoneNumberSubstringsMatch,
4979 telephoneNumberSubstringsIndexer,
4980 telephoneNumberSubstringsFilter,
4983 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4984 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4985 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4990 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4991 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4992 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4994 uniqueMemberMatch, NULL, NULL,
4997 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4998 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4999 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5001 protocolInformationMatch, NULL, NULL,
5004 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
5005 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
5006 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5008 generalizedTimeMatch, NULL, NULL,
5011 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
5012 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
5015 generalizedTimeOrderingMatch, NULL, NULL,
5018 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
5019 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5020 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5022 integerFirstComponentMatch, NULL, NULL,
5025 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
5026 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
5027 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5029 objectIdentifierFirstComponentMatch, NULL, NULL,
5033 {"( 2.5.13.34 NAME 'certificateExactMatch' "
5034 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
5035 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5036 certificateExactConvert, NULL,
5037 certificateExactMatch,
5038 certificateExactIndexer, certificateExactFilter,
5042 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
5043 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5044 SLAP_MR_EQUALITY | SLAP_MR_EXT,
5046 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
5047 IA5StringApproxMatchOID },
5049 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
5050 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5051 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
5053 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
5054 IA5StringApproxMatchOID },
5056 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
5057 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5060 caseIgnoreIA5SubstringsMatch,
5061 caseIgnoreIA5SubstringsIndexer,
5062 caseIgnoreIA5SubstringsFilter,
5065 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
5066 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5069 caseExactIA5SubstringsMatch,
5070 caseExactIA5SubstringsIndexer,
5071 caseExactIA5SubstringsFilter,
5074 /* needs updating */
5075 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
5076 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
5079 authPasswordMatch, NULL, NULL,
5082 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
5083 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
5086 OpenLDAPaciMatch, NULL, NULL,
5089 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
5090 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5093 integerBitAndMatch, NULL, NULL,
5096 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
5097 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5100 integerBitOrMatch, NULL, NULL,
5103 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
5112 /* we should only be called once (from main) */
5113 assert( schema_init_done == 0 );
5115 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
5116 res = register_syntax( syntax_defs[i].sd_desc,
5117 syntax_defs[i].sd_flags,
5118 syntax_defs[i].sd_validate,
5119 syntax_defs[i].sd_normalize,
5120 syntax_defs[i].sd_pretty
5121 #ifdef SLAPD_BINARY_CONVERSION
5123 syntax_defs[i].sd_ber2str,
5124 syntax_defs[i].sd_str2ber
5129 fprintf( stderr, "schema_init: Error registering syntax %s\n",
5130 syntax_defs[i].sd_desc );
5135 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
5136 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
5138 "schema_init: Ingoring unusable matching rule %s\n",
5139 mrule_defs[i].mrd_desc );
5143 res = register_matching_rule(
5144 mrule_defs[i].mrd_desc,
5145 mrule_defs[i].mrd_usage,
5146 mrule_defs[i].mrd_convert,
5147 mrule_defs[i].mrd_normalize,
5148 mrule_defs[i].mrd_match,
5149 mrule_defs[i].mrd_indexer,
5150 mrule_defs[i].mrd_filter,
5151 mrule_defs[i].mrd_associated );
5155 "schema_init: Error registering matching rule %s\n",
5156 mrule_defs[i].mrd_desc );
5160 schema_init_done = 1;
5161 return LDAP_SUCCESS;
5165 schema_destroy( void )