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 /* We should replace MD5 with a faster hash */
25 #define HASH_BYTES LUTIL_HASH_BYTES
26 #define HASH_CONTEXT lutil_HASH_CTX
27 #define HASH_Init(c) lutil_HASHInit(c)
28 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
29 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
31 /* recycled validatation routines */
32 #define berValidate blobValidate
34 /* unimplemented pretters */
35 #define integerPretty NULL
36 #ifndef USE_LDAP_DN_PARSING
37 # define dnPretty NULL
39 # define SLAP_LDAPDN_PRETTY 0x1
40 #endif /* !USE_LDAP_DN_PARSING */
42 /* recycled matching routines */
43 #define bitStringMatch octetStringMatch
44 #define numericStringMatch caseIgnoreIA5Match
45 #define objectIdentifierMatch caseIgnoreIA5Match
46 #define telephoneNumberMatch caseIgnoreIA5Match
47 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
48 #define generalizedTimeMatch caseIgnoreIA5Match
49 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
50 #define uniqueMemberMatch dnMatch
52 /* approx matching rules */
53 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
54 #define directoryStringApproxMatch approxMatch
55 #define directoryStringApproxIndexer approxIndexer
56 #define directoryStringApproxFilter approxFilter
57 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
58 #define IA5StringApproxMatch approxMatch
59 #define IA5StringApproxIndexer approxIndexer
60 #define IA5StringApproxFilter approxFilter
62 /* orderring matching rules */
63 #define caseIgnoreOrderingMatch caseIgnoreMatch
64 #define caseExactOrderingMatch caseExactMatch
66 /* unimplemented matching routines */
67 #define caseIgnoreListMatch NULL
68 #define caseIgnoreListSubstringsMatch NULL
69 #define protocolInformationMatch NULL
70 #define integerFirstComponentMatch NULL
72 #define OpenLDAPaciMatch NULL
73 #define authPasswordMatch NULL
75 /* recycled indexing/filtering routines */
76 #define dnIndexer caseExactIgnoreIndexer
77 #define dnFilter caseExactIgnoreFilter
78 #define bitStringFilter octetStringFilter
79 #define bitStringIndexer octetStringIndexer
81 #define telephoneNumberIndexer caseIgnoreIA5Indexer
82 #define telephoneNumberFilter caseIgnoreIA5Filter
83 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
84 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
86 /* must match OIDs below */
87 #define caseExactMatchOID "2.5.13.5"
88 #define caseExactSubstringsMatchOID "2.5.13.7"
90 static char *strcasechr( const char *str, int c )
92 char *lower = strchr( str, TOLOWER(c) );
93 char *upper = strchr( str, TOUPPER(c) );
95 if( lower && upper ) {
96 return lower < upper ? lower : upper;
110 struct berval *value,
111 void *assertedValue )
113 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
116 match = memcmp( value->bv_val,
117 ((struct berval *) assertedValue)->bv_val,
125 /* Index generation function */
126 int octetStringIndexer(
131 struct berval *prefix,
132 struct berval **values,
133 struct berval ***keysp )
137 struct berval **keys;
138 HASH_CONTEXT HASHcontext;
139 unsigned char HASHdigest[HASH_BYTES];
140 struct berval digest;
141 digest.bv_val = HASHdigest;
142 digest.bv_len = sizeof(HASHdigest);
144 for( i=0; values[i] != NULL; i++ ) {
145 /* just count them */
148 /* we should have at least one value at this point */
151 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
153 slen = strlen( syntax->ssyn_oid );
154 mlen = strlen( mr->smr_oid );
156 for( i=0; values[i] != NULL; i++ ) {
157 HASH_Init( &HASHcontext );
158 if( prefix != NULL && prefix->bv_len > 0 ) {
159 HASH_Update( &HASHcontext,
160 prefix->bv_val, prefix->bv_len );
162 HASH_Update( &HASHcontext,
163 syntax->ssyn_oid, slen );
164 HASH_Update( &HASHcontext,
166 HASH_Update( &HASHcontext,
167 values[i]->bv_val, values[i]->bv_len );
168 HASH_Final( HASHdigest, &HASHcontext );
170 keys[i] = ber_bvdup( &digest );
180 /* Index generation function */
181 int octetStringFilter(
186 struct berval *prefix,
188 struct berval ***keysp )
191 struct berval **keys;
192 HASH_CONTEXT HASHcontext;
193 unsigned char HASHdigest[HASH_BYTES];
194 struct berval *value = (struct berval *) assertValue;
195 struct berval digest;
196 digest.bv_val = HASHdigest;
197 digest.bv_len = sizeof(HASHdigest);
199 slen = strlen( syntax->ssyn_oid );
200 mlen = strlen( mr->smr_oid );
202 keys = ch_malloc( sizeof( struct berval * ) * 2 );
204 HASH_Init( &HASHcontext );
205 if( prefix != NULL && prefix->bv_len > 0 ) {
206 HASH_Update( &HASHcontext,
207 prefix->bv_val, prefix->bv_len );
209 HASH_Update( &HASHcontext,
210 syntax->ssyn_oid, slen );
211 HASH_Update( &HASHcontext,
213 HASH_Update( &HASHcontext,
214 value->bv_val, value->bv_len );
215 HASH_Final( HASHdigest, &HASHcontext );
217 keys[0] = ber_bvdup( &digest );
225 #ifdef USE_LDAP_DN_PARSING
234 if ( in->bv_len == 0 ) {
235 return( LDAP_SUCCESS );
238 rc = ldap_str2dn( in->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
241 * Fixme: should we also validate each DN component?
243 ldapava_free_dn( dn );
245 if ( rc != LDAP_SUCCESS ) {
246 return( LDAP_INVALID_SYNTAX );
249 return( LDAP_SUCCESS );
253 AVA_Sort( LDAPRDN *rdn, int iAVA )
256 LDAPAVA *ava_in = rdn[ iAVA ][ 0 ];
258 for ( i = 0; i < iAVA; i++ ) {
259 LDAPAVA *ava = rdn[ i ][ 0 ];
262 a = strcmp( ava_in->la_attr->bv_val, ava->la_attr->bv_val );
271 d = ava_in->la_value->bv_len - ava->la_value->bv_len;
273 v = memcmp( ava_in->la_value->bv_val,
274 ava->la_value->bv_val,
275 d <= 0 ? ava_in->la_value->bv_len
276 : ava->la_value->bv_len );
278 if ( v == 0 && d != 0 ) {
297 a = strcmp( ava_in->la_value->bv_val,
298 ava->la_value->bv_val );
304 for ( j = iAVA; j > i; j-- ) {
305 rdn[ j ][ 0 ] = rdn[ j - 1 ][ 0 ];
307 rdn[ i ][ 0 ] = ava_in;
314 * In-place, schema-aware normalization / "pretty"ing of the
315 * structural representation of a distinguished name.
318 LDAPDN_rewrite( LDAPDN *dn, unsigned flags )
325 for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
326 LDAPRDN *rdn = dn[ iRDN ][ 0 ];
329 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
330 LDAPAVA *ava = rdn[ iAVA ][ 0 ];
331 AttributeDescription *ad = NULL;
332 const char *text = NULL;
333 slap_syntax_transform_func *transf = NULL;
335 struct berval *bv = NULL;
337 rc = slap_bv2ad( ava->la_attr, &ad, &text );
338 if ( rc != LDAP_SUCCESS ) {
339 return LDAP_INVALID_SYNTAX;
343 * Replace attr oid/name with the canonical name
345 ber_bvfree( ava->la_attr );
346 ava->la_attr = ber_bvdup( &ad->ad_cname );
348 if( flags & SLAP_LDAPDN_PRETTY ) {
349 transf = ad->ad_type->sat_syntax->ssyn_pretty;
352 transf = ad->ad_type->sat_syntax->ssyn_normalize;
353 mr = ad->ad_type->sat_equality;
358 * transform value by normalize/pretty function
360 rc = ( *transf )( ad->ad_type->sat_syntax,
361 ava->la_value, &bv );
363 if ( rc != LDAP_SUCCESS ) {
364 return LDAP_INVALID_SYNTAX;
368 if( mr && ( mr->smr_usage & SLAP_MR_DN_FOLD ) ) {
369 struct berval *s = bv;
371 bv = ber_bvstr( UTF8normalize( bv ? bv : ava->la_value,
378 ber_bvfree( ava->la_value );
382 AVA_Sort( rdn, iAVA );
393 struct berval **normalized )
395 struct berval *out = NULL;
397 Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 );
399 if ( val->bv_len != 0 ) {
405 * Go to structural representation
407 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
408 if ( rc != LDAP_SUCCESS ) {
409 return LDAP_INVALID_SYNTAX;
413 * Schema-aware rewrite
415 if ( LDAPDN_rewrite( dn, 0 ) != LDAP_SUCCESS ) {
416 ldapava_free_dn( dn );
417 return LDAP_INVALID_SYNTAX;
421 * Back to string representation
423 rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
425 ldapava_free_dn( dn );
427 if ( rc != LDAP_SUCCESS ) {
428 return LDAP_INVALID_SYNTAX;
431 out = ber_bvstr( dn_out );
434 out = ber_bvdup( val );
437 Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val, 0, 0 );
448 struct berval **pretty)
450 struct berval *out = NULL;
452 Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 );
454 if ( val->bv_len != 0 ) {
459 /* FIXME: should be liberal in what we accept */
460 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAP );
461 if ( rc != LDAP_SUCCESS ) {
462 return LDAP_INVALID_SYNTAX;
466 * Schema-aware rewrite
468 if ( LDAPDN_rewrite( dn, SLAP_LDAPDN_PRETTY ) != LDAP_SUCCESS ) {
469 ldapava_free_dn( dn );
470 return LDAP_INVALID_SYNTAX;
473 /* FIXME: not sure why the default isn't pretty */
474 rc = ldap_dn2str( dn, &dn_out,
475 LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
477 ldapava_free_dn( dn );
479 if ( rc != LDAP_SUCCESS ) {
480 return LDAP_INVALID_SYNTAX;
483 out = ber_bvstr( dn_out );
486 out = ber_bvdup( val );
489 Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val, 0, 0 );
502 struct berval *value,
503 void *assertedValue )
506 struct berval *asserted = (struct berval *) assertedValue;
508 match = value->bv_len - asserted->bv_len;
511 match = strcmp( value->bv_val, asserted->bv_val );
515 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
516 "dnMatch: %d\n %s\n %s\n", match,
517 value->bv_val, asserted->bv_val ));
519 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
520 match, value->bv_val, asserted->bv_val );
524 return( LDAP_SUCCESS );
527 #else /* !USE_LDAP_DN_PARSING */
537 if( in->bv_len == 0 ) return LDAP_SUCCESS;
539 dn = ch_strdup( in->bv_val );
542 return LDAP_INVALID_SYNTAX;
544 } else if ( strlen( in->bv_val ) != in->bv_len ) {
545 rc = LDAP_INVALID_SYNTAX;
547 } else if ( dn_validate( dn ) == NULL ) {
548 rc = LDAP_INVALID_SYNTAX;
562 struct berval **normalized )
566 if ( val->bv_len != 0 ) {
568 out = ber_bvstr( UTF8normalize( val, UTF8_CASEFOLD ) );
570 dn = dn_validate( out->bv_val );
574 return LDAP_INVALID_SYNTAX;
578 out->bv_len = strlen( dn );
580 out = ber_bvdup( val );
593 struct berval *value,
594 void *assertedValue )
597 struct berval *asserted = (struct berval *) assertedValue;
599 match = value->bv_len - asserted->bv_len;
602 #ifdef USE_DN_NORMALIZE
603 match = strcmp( value->bv_val, asserted->bv_val );
605 match = strcasecmp( value->bv_val, asserted->bv_val );
610 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
611 "dnMatch: %d\n %s\n %s\n", match,
612 value->bv_val, asserted->bv_val ));
614 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
615 match, value->bv_val, asserted->bv_val );
623 #endif /* !USE_LDAP_DN_PARSING */
633 if( in->bv_len == 0 ) return LDAP_SUCCESS;
635 dn = ber_bvdup( in );
637 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
638 /* assume presence of optional UID */
641 for(i=dn->bv_len-2; i>2; i--) {
642 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
646 if( dn->bv_val[i] != '\'' ||
647 dn->bv_val[i-1] != 'B' ||
648 dn->bv_val[i-2] != '#' ) {
650 return LDAP_INVALID_SYNTAX;
653 /* trim the UID to allow use of dn_validate */
654 dn->bv_val[i-2] = '\0';
657 rc = dn_validate( dn->bv_val ) == NULL
658 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
668 struct berval **normalized )
670 struct berval *out = ber_bvdup( val );
672 if( out->bv_len != 0 ) {
676 ber_len_t uidlen = 0;
678 if( out->bv_val[out->bv_len-1] == '\'' ) {
679 /* assume presence of optional UID */
680 uid = strrchr( out->bv_val, '#' );
684 return LDAP_INVALID_SYNTAX;
687 uidlen = out->bv_len - (out->bv_val - uid);
688 /* temporarily trim the UID */
692 #ifdef USE_DN_NORMALIZE
693 dn = dn_normalize( out->bv_val );
695 dn = dn_validate( out->bv_val );
700 return LDAP_INVALID_SYNTAX;
706 /* restore the separator */
709 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
713 out->bv_len = dnlen + uidlen;
725 /* any value allowed */
734 /* any value allowed */
745 /* very unforgiving validation, requires no normalization
746 * before simplistic matching
748 if( in->bv_len < 3 ) {
749 return LDAP_INVALID_SYNTAX;
753 * rfc 2252 section 6.3 Bit String
754 * bitstring = "'" *binary-digit "'"
755 * binary-digit = "0" / "1"
756 * example: '0101111101'B
759 if( in->bv_val[0] != '\'' ||
760 in->bv_val[in->bv_len-2] != '\'' ||
761 in->bv_val[in->bv_len-1] != 'B' )
763 return LDAP_INVALID_SYNTAX;
766 for( i=in->bv_len-3; i>0; i-- ) {
767 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
768 return LDAP_INVALID_SYNTAX;
779 struct berval **normalized )
782 * A normalized bitString is has no extaneous (leading) zero bits.
783 * That is, '00010'B is normalized to '10'B
784 * However, as a special case, '0'B requires no normalization.
786 struct berval *newval;
789 /* start at the first bit */
792 /* Find the first non-zero bit */
793 while ( *p == '0' ) p++;
795 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
798 /* no non-zero bits */
799 newval->bv_val = ch_strdup("\'0\'B");
800 newval->bv_len = sizeof("\'0\'B") - 1;
804 newval->bv_val = ch_malloc( val->bv_len + 1 );
806 newval->bv_val[0] = '\'';
809 for( ; *p != '\0'; p++ ) {
810 newval->bv_val[newval->bv_len++] = *p;
813 newval->bv_val[newval->bv_len] = '\0';
816 *normalized = newval;
821 * Handling boolean syntax and matching is quite rigid.
822 * A more flexible approach would be to allow a variety
823 * of strings to be normalized and prettied into TRUE
831 /* very unforgiving validation, requires no normalization
832 * before simplistic matching
835 if( in->bv_len == 4 ) {
836 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
839 } else if( in->bv_len == 5 ) {
840 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
845 return LDAP_INVALID_SYNTAX;
854 struct berval *value,
855 void *assertedValue )
857 /* simplistic matching allowed by rigid validation */
858 struct berval *asserted = (struct berval *) assertedValue;
859 *matchp = value->bv_len != asserted->bv_len;
870 unsigned char *u = in->bv_val;
872 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
874 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
875 /* get the length indicated by the first byte */
876 len = LDAP_UTF8_CHARLEN( u );
878 /* should not be zero */
879 if( len == 0 ) return LDAP_INVALID_SYNTAX;
881 /* make sure len corresponds with the offset
882 to the next character */
883 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
886 if( count != 0 ) return LDAP_INVALID_SYNTAX;
895 struct berval **normalized )
897 struct berval *newval;
900 newval = ch_malloc( sizeof( struct berval ) );
904 /* Ignore initial whitespace */
905 while ( ldap_utf8_isspace( p ) ) {
911 return LDAP_INVALID_SYNTAX;
914 newval->bv_val = ch_strdup( p );
915 p = q = newval->bv_val;
921 if ( ldap_utf8_isspace( p ) ) {
922 len = LDAP_UTF8_COPY(q,p);
927 /* Ignore the extra whitespace */
928 while ( ldap_utf8_isspace( p ) ) {
932 len = LDAP_UTF8_COPY(q,p);
939 assert( *newval->bv_val );
940 assert( newval->bv_val < p );
943 /* cannot start with a space */
944 assert( !ldap_utf8_isspace(newval->bv_val) );
947 * If the string ended in space, backup the pointer one
948 * position. One is enough because the above loop collapsed
949 * all whitespace to a single space.
956 /* cannot end with a space */
957 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
962 newval->bv_len = q - newval->bv_val;
963 *normalized = newval;
968 /* Returns Unicode cannonically normalized copy of a substring assertion
969 * Skipping attribute description */
970 SubstringsAssertion *
971 UTF8SubstringsassertionNormalize(
972 SubstringsAssertion *sa,
975 SubstringsAssertion *nsa;
978 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
983 if( sa->sa_initial != NULL ) {
984 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
985 if( nsa->sa_initial == NULL ) {
990 if( sa->sa_any != NULL ) {
991 for( i=0; sa->sa_any[i] != NULL; i++ ) {
994 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
995 for( i=0; sa->sa_any[i] != NULL; i++ ) {
996 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
997 if( nsa->sa_any[i] == NULL ) {
1001 nsa->sa_any[i] = NULL;
1004 if( sa->sa_final != NULL ) {
1005 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
1006 if( nsa->sa_final == NULL ) {
1014 ber_bvfree( nsa->sa_final );
1015 ber_bvecfree( nsa->sa_any );
1016 ber_bvfree( nsa->sa_initial );
1021 /* Strip characters with the 8th bit set */
1034 while( *++q & 0x80 ) {
1037 p = memmove(p, q, strlen(q) + 1);
1045 #ifndef SLAPD_APPROX_OLDSINGLESTRING
1047 #if defined(SLAPD_APPROX_INITIALS)
1048 #define SLAPD_APPROX_DELIMITER "._ "
1049 #define SLAPD_APPROX_WORDLEN 2
1051 #define SLAPD_APPROX_DELIMITER " "
1052 #define SLAPD_APPROX_WORDLEN 1
1061 struct berval *value,
1062 void *assertedValue )
1064 char *val, *nval, *assertv, **values, **words, *c;
1065 int i, count, len, nextchunk=0, nextavail=0;
1068 /* Yes, this is necessary */
1069 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
1070 if( nval == NULL ) {
1072 return LDAP_SUCCESS;
1074 strip8bitChars( nval );
1076 /* Yes, this is necessary */
1077 assertv = UTF8normalize( ((struct berval *)assertedValue),
1079 if( assertv == NULL ) {
1082 return LDAP_SUCCESS;
1084 strip8bitChars( assertv );
1085 avlen = strlen( assertv );
1087 /* Isolate how many words there are */
1088 for( c=nval,count=1; *c; c++ ) {
1089 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
1090 if ( c == NULL ) break;
1095 /* Get a phonetic copy of each word */
1096 words = (char **)ch_malloc( count * sizeof(char *) );
1097 values = (char **)ch_malloc( count * sizeof(char *) );
1098 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
1100 values[i] = phonetic(c);
1103 /* Work through the asserted value's words, to see if at least some
1104 of the words are there, in the same order. */
1106 while ( nextchunk < avlen ) {
1107 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
1112 #if defined(SLAPD_APPROX_INITIALS)
1113 else if( len == 1 ) {
1114 /* Single letter words need to at least match one word's initial */
1115 for( i=nextavail; i<count; i++ )
1116 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
1123 /* Isolate the next word in the asserted value and phonetic it */
1124 assertv[nextchunk+len] = '\0';
1125 val = phonetic( assertv + nextchunk );
1127 /* See if this phonetic chunk is in the remaining words of *value */
1128 for( i=nextavail; i<count; i++ ){
1129 if( !strcmp( val, values[i] ) ){
1137 /* This chunk in the asserted value was NOT within the *value. */
1143 /* Go on to the next word in the asserted value */
1147 /* If some of the words were seen, call it a match */
1148 if( nextavail > 0 ) {
1155 /* Cleanup allocs */
1157 for( i=0; i<count; i++ ) {
1158 ch_free( values[i] );
1164 return LDAP_SUCCESS;
1173 struct berval *prefix,
1174 struct berval **values,
1175 struct berval ***keysp )
1178 int i,j, len, wordcount, keycount=0;
1179 struct berval **newkeys, **keys=NULL;
1181 for( j=0; values[j] != NULL; j++ ) {
1182 /* Yes, this is necessary */
1183 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
1184 strip8bitChars( val );
1186 /* Isolate how many words there are. There will be a key for each */
1187 for( wordcount=0,c=val; *c; c++) {
1188 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1189 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
1191 if (*c == '\0') break;
1195 /* Allocate/increase storage to account for new keys */
1196 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
1197 * sizeof(struct berval *) );
1198 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
1199 if( keys ) ch_free( keys );
1202 /* Get a phonetic copy of each word */
1203 for( c=val,i=0; i<wordcount; c+=len+1 ) {
1205 if( len < SLAPD_APPROX_WORDLEN ) continue;
1206 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
1207 keys[keycount]->bv_val = phonetic( c );
1208 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
1215 keys[keycount] = NULL;
1218 return LDAP_SUCCESS;
1227 struct berval *prefix,
1229 struct berval ***keysp )
1233 struct berval **keys;
1235 /* Yes, this is necessary */
1236 val = UTF8normalize( ((struct berval *)assertValue),
1239 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
1242 return LDAP_SUCCESS;
1244 strip8bitChars( val );
1246 /* Isolate how many words there are. There will be a key for each */
1247 for( count=0,c=val; *c; c++) {
1248 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1249 if( len >= SLAPD_APPROX_WORDLEN ) count++;
1251 if (*c == '\0') break;
1255 /* Allocate storage for new keys */
1256 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
1258 /* Get a phonetic copy of each word */
1259 for( c=val,i=0; i<count; c+=len+1 ) {
1261 if( len < SLAPD_APPROX_WORDLEN ) continue;
1262 keys[i] = ber_bvstr( phonetic( c ) );
1271 return LDAP_SUCCESS;
1276 /* No other form of Approximate Matching is defined */
1284 struct berval *value,
1285 void *assertedValue )
1287 char *vapprox, *avapprox;
1290 /* Yes, this is necessary */
1291 s = UTF8normalize( value, UTF8_NOCASEFOLD );
1294 return LDAP_SUCCESS;
1297 /* Yes, this is necessary */
1298 t = UTF8normalize( ((struct berval *)assertedValue),
1303 return LDAP_SUCCESS;
1306 vapprox = phonetic( strip8bitChars( s ) );
1307 avapprox = phonetic( strip8bitChars( t ) );
1312 *matchp = strcmp( vapprox, avapprox );
1315 ch_free( avapprox );
1317 return LDAP_SUCCESS;
1326 struct berval *prefix,
1327 struct berval **values,
1328 struct berval ***keysp )
1331 struct berval **keys;
1334 for( i=0; values[i] != NULL; i++ ) {
1335 /* empty - just count them */
1338 /* we should have at least one value at this point */
1341 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
1343 /* Copy each value and run it through phonetic() */
1344 for( i=0; values[i] != NULL; i++ ) {
1345 /* Yes, this is necessary */
1346 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
1348 /* strip 8-bit chars and run through phonetic() */
1349 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1355 return LDAP_SUCCESS;
1365 struct berval *prefix,
1367 struct berval ***keysp )
1369 struct berval **keys;
1372 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1374 /* Yes, this is necessary */
1375 s = UTF8normalize( ((struct berval *)assertValue),
1380 /* strip 8-bit chars and run through phonetic() */
1381 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1387 return LDAP_SUCCESS;
1398 struct berval *value,
1399 void *assertedValue )
1401 *matchp = UTF8normcmp( value->bv_val,
1402 ((struct berval *) assertedValue)->bv_val,
1404 return LDAP_SUCCESS;
1408 caseExactIgnoreSubstringsMatch(
1413 struct berval *value,
1414 void *assertedValue )
1417 SubstringsAssertion *sub = NULL;
1421 char *nav, casefold;
1423 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1424 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1426 nav = UTF8normalize( value, casefold );
1432 left.bv_len = strlen( nav );
1434 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1440 /* Add up asserted input length */
1441 if( sub->sa_initial ) {
1442 inlen += sub->sa_initial->bv_len;
1445 for(i=0; sub->sa_any[i] != NULL; i++) {
1446 inlen += sub->sa_any[i]->bv_len;
1449 if( sub->sa_final ) {
1450 inlen += sub->sa_final->bv_len;
1453 if( sub->sa_initial ) {
1454 if( inlen > left.bv_len ) {
1459 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1460 sub->sa_initial->bv_len );
1466 left.bv_val += sub->sa_initial->bv_len;
1467 left.bv_len -= sub->sa_initial->bv_len;
1468 inlen -= sub->sa_initial->bv_len;
1471 if( sub->sa_final ) {
1472 if( inlen > left.bv_len ) {
1477 match = strncmp( sub->sa_final->bv_val,
1478 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1479 sub->sa_final->bv_len );
1485 left.bv_len -= sub->sa_final->bv_len;
1486 inlen -= sub->sa_final->bv_len;
1490 for(i=0; sub->sa_any[i]; i++) {
1495 if( inlen > left.bv_len ) {
1496 /* not enough length */
1501 if( sub->sa_any[i]->bv_len == 0 ) {
1505 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1512 idx = p - left.bv_val;
1513 assert( idx < left.bv_len );
1515 if( idx >= left.bv_len ) {
1516 /* this shouldn't happen */
1518 ch_free( sub->sa_final );
1519 ber_bvecfree( sub->sa_any );
1520 ch_free( sub->sa_initial );
1528 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1529 /* not enough left */
1534 match = strncmp( left.bv_val,
1535 sub->sa_any[i]->bv_val,
1536 sub->sa_any[i]->bv_len );
1544 left.bv_val += sub->sa_any[i]->bv_len;
1545 left.bv_len -= sub->sa_any[i]->bv_len;
1546 inlen -= sub->sa_any[i]->bv_len;
1553 ber_bvfree( sub->sa_final );
1554 ber_bvecfree( sub->sa_any );
1555 ber_bvfree( sub->sa_initial );
1559 return LDAP_SUCCESS;
1562 /* Index generation function */
1563 int caseExactIgnoreIndexer(
1568 struct berval *prefix,
1569 struct berval **values,
1570 struct berval ***keysp )
1575 struct berval **keys;
1576 HASH_CONTEXT HASHcontext;
1577 unsigned char HASHdigest[HASH_BYTES];
1578 struct berval digest;
1579 digest.bv_val = HASHdigest;
1580 digest.bv_len = sizeof(HASHdigest);
1582 for( i=0; values[i] != NULL; i++ ) {
1583 /* empty - just count them */
1586 /* we should have at least one value at this point */
1589 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1591 slen = strlen( syntax->ssyn_oid );
1592 mlen = strlen( mr->smr_oid );
1594 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1595 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1597 for( i=0; values[i] != NULL; i++ ) {
1598 struct berval *value;
1599 value = ber_bvstr( UTF8normalize( values[i],
1602 HASH_Init( &HASHcontext );
1603 if( prefix != NULL && prefix->bv_len > 0 ) {
1604 HASH_Update( &HASHcontext,
1605 prefix->bv_val, prefix->bv_len );
1607 HASH_Update( &HASHcontext,
1608 syntax->ssyn_oid, slen );
1609 HASH_Update( &HASHcontext,
1610 mr->smr_oid, mlen );
1611 HASH_Update( &HASHcontext,
1612 value->bv_val, value->bv_len );
1613 HASH_Final( HASHdigest, &HASHcontext );
1615 ber_bvfree( value );
1617 keys[i] = ber_bvdup( &digest );
1622 return LDAP_SUCCESS;
1625 /* Index generation function */
1626 int caseExactIgnoreFilter(
1631 struct berval *prefix,
1633 struct berval ***keysp )
1637 struct berval **keys;
1638 HASH_CONTEXT HASHcontext;
1639 unsigned char HASHdigest[HASH_BYTES];
1640 struct berval *value;
1641 struct berval digest;
1642 digest.bv_val = HASHdigest;
1643 digest.bv_len = sizeof(HASHdigest);
1645 slen = strlen( syntax->ssyn_oid );
1646 mlen = strlen( mr->smr_oid );
1648 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1649 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1651 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
1653 /* This usually happens if filter contains bad UTF8 */
1654 if( value == NULL ) {
1655 keys = ch_malloc( sizeof( struct berval * ) );
1657 return LDAP_SUCCESS;
1660 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1662 HASH_Init( &HASHcontext );
1663 if( prefix != NULL && prefix->bv_len > 0 ) {
1664 HASH_Update( &HASHcontext,
1665 prefix->bv_val, prefix->bv_len );
1667 HASH_Update( &HASHcontext,
1668 syntax->ssyn_oid, slen );
1669 HASH_Update( &HASHcontext,
1670 mr->smr_oid, mlen );
1671 HASH_Update( &HASHcontext,
1672 value->bv_val, value->bv_len );
1673 HASH_Final( HASHdigest, &HASHcontext );
1675 keys[0] = ber_bvdup( &digest );
1678 ber_bvfree( value );
1681 return LDAP_SUCCESS;
1684 /* Substrings Index generation function */
1685 int caseExactIgnoreSubstringsIndexer(
1690 struct berval *prefix,
1691 struct berval **values,
1692 struct berval ***keysp )
1697 struct berval **keys;
1698 struct berval **nvalues;
1700 HASH_CONTEXT HASHcontext;
1701 unsigned char HASHdigest[HASH_BYTES];
1702 struct berval digest;
1703 digest.bv_val = HASHdigest;
1704 digest.bv_len = sizeof(HASHdigest);
1708 for( i=0; values[i] != NULL; i++ ) {
1709 /* empty - just count them */
1712 /* we should have at least one value at this point */
1715 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1716 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1718 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1719 for( i=0; values[i] != NULL; i++ ) {
1720 nvalues[i] = ber_bvstr( UTF8normalize( values[i],
1726 for( i=0; values[i] != NULL; i++ ) {
1727 /* count number of indices to generate */
1728 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1732 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1733 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1734 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1735 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1737 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1741 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1742 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1743 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1747 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1748 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1749 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1750 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1752 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1758 /* no keys to generate */
1760 ber_bvecfree( nvalues );
1761 return LDAP_SUCCESS;
1764 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1766 slen = strlen( syntax->ssyn_oid );
1767 mlen = strlen( mr->smr_oid );
1770 for( i=0; values[i] != NULL; i++ ) {
1772 struct berval *value;
1774 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1778 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1779 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1781 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1782 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1784 for( j=0; j<max; j++ ) {
1785 HASH_Init( &HASHcontext );
1786 if( prefix != NULL && prefix->bv_len > 0 ) {
1787 HASH_Update( &HASHcontext,
1788 prefix->bv_val, prefix->bv_len );
1791 HASH_Update( &HASHcontext,
1792 &pre, sizeof( pre ) );
1793 HASH_Update( &HASHcontext,
1794 syntax->ssyn_oid, slen );
1795 HASH_Update( &HASHcontext,
1796 mr->smr_oid, mlen );
1797 HASH_Update( &HASHcontext,
1799 SLAP_INDEX_SUBSTR_MAXLEN );
1800 HASH_Final( HASHdigest, &HASHcontext );
1802 keys[nkeys++] = ber_bvdup( &digest );
1806 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1807 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1809 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1812 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1813 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1814 HASH_Init( &HASHcontext );
1815 if( prefix != NULL && prefix->bv_len > 0 ) {
1816 HASH_Update( &HASHcontext,
1817 prefix->bv_val, prefix->bv_len );
1819 HASH_Update( &HASHcontext,
1820 &pre, sizeof( pre ) );
1821 HASH_Update( &HASHcontext,
1822 syntax->ssyn_oid, slen );
1823 HASH_Update( &HASHcontext,
1824 mr->smr_oid, mlen );
1825 HASH_Update( &HASHcontext,
1827 HASH_Final( HASHdigest, &HASHcontext );
1829 keys[nkeys++] = ber_bvdup( &digest );
1832 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1833 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1834 HASH_Init( &HASHcontext );
1835 if( prefix != NULL && prefix->bv_len > 0 ) {
1836 HASH_Update( &HASHcontext,
1837 prefix->bv_val, prefix->bv_len );
1839 HASH_Update( &HASHcontext,
1840 &pre, sizeof( pre ) );
1841 HASH_Update( &HASHcontext,
1842 syntax->ssyn_oid, slen );
1843 HASH_Update( &HASHcontext,
1844 mr->smr_oid, mlen );
1845 HASH_Update( &HASHcontext,
1846 &value->bv_val[value->bv_len-j], j );
1847 HASH_Final( HASHdigest, &HASHcontext );
1849 keys[nkeys++] = ber_bvdup( &digest );
1864 ber_bvecfree( nvalues );
1866 return LDAP_SUCCESS;
1869 int caseExactIgnoreSubstringsFilter(
1874 struct berval *prefix,
1876 struct berval ***keysp )
1878 SubstringsAssertion *sa;
1880 ber_len_t nkeys = 0;
1881 size_t slen, mlen, klen;
1882 struct berval **keys;
1883 HASH_CONTEXT HASHcontext;
1884 unsigned char HASHdigest[HASH_BYTES];
1885 struct berval *value;
1886 struct berval digest;
1888 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1889 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1891 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1894 return LDAP_SUCCESS;
1897 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1898 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1903 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1905 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1906 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1907 /* don't bother accounting for stepping */
1908 nkeys += sa->sa_any[i]->bv_len -
1909 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1914 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1915 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1921 ber_bvfree( sa->sa_final );
1922 ber_bvecfree( sa->sa_any );
1923 ber_bvfree( sa->sa_initial );
1926 return LDAP_SUCCESS;
1929 digest.bv_val = HASHdigest;
1930 digest.bv_len = sizeof(HASHdigest);
1932 slen = strlen( syntax->ssyn_oid );
1933 mlen = strlen( mr->smr_oid );
1935 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1938 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1939 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1941 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1942 value = sa->sa_initial;
1944 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1945 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1947 HASH_Init( &HASHcontext );
1948 if( prefix != NULL && prefix->bv_len > 0 ) {
1949 HASH_Update( &HASHcontext,
1950 prefix->bv_val, prefix->bv_len );
1952 HASH_Update( &HASHcontext,
1953 &pre, sizeof( pre ) );
1954 HASH_Update( &HASHcontext,
1955 syntax->ssyn_oid, slen );
1956 HASH_Update( &HASHcontext,
1957 mr->smr_oid, mlen );
1958 HASH_Update( &HASHcontext,
1959 value->bv_val, klen );
1960 HASH_Final( HASHdigest, &HASHcontext );
1962 keys[nkeys++] = ber_bvdup( &digest );
1965 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1967 pre = SLAP_INDEX_SUBSTR_PREFIX;
1968 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1970 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1971 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1975 value = sa->sa_any[i];
1978 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1979 j += SLAP_INDEX_SUBSTR_STEP )
1981 HASH_Init( &HASHcontext );
1982 if( prefix != NULL && prefix->bv_len > 0 ) {
1983 HASH_Update( &HASHcontext,
1984 prefix->bv_val, prefix->bv_len );
1986 HASH_Update( &HASHcontext,
1987 &pre, sizeof( pre ) );
1988 HASH_Update( &HASHcontext,
1989 syntax->ssyn_oid, slen );
1990 HASH_Update( &HASHcontext,
1991 mr->smr_oid, mlen );
1992 HASH_Update( &HASHcontext,
1993 &value->bv_val[j], klen );
1994 HASH_Final( HASHdigest, &HASHcontext );
1996 keys[nkeys++] = ber_bvdup( &digest );
2002 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2003 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2005 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2006 value = sa->sa_final;
2008 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2009 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2011 HASH_Init( &HASHcontext );
2012 if( prefix != NULL && prefix->bv_len > 0 ) {
2013 HASH_Update( &HASHcontext,
2014 prefix->bv_val, prefix->bv_len );
2016 HASH_Update( &HASHcontext,
2017 &pre, sizeof( pre ) );
2018 HASH_Update( &HASHcontext,
2019 syntax->ssyn_oid, slen );
2020 HASH_Update( &HASHcontext,
2021 mr->smr_oid, mlen );
2022 HASH_Update( &HASHcontext,
2023 &value->bv_val[value->bv_len-klen], klen );
2024 HASH_Final( HASHdigest, &HASHcontext );
2026 keys[nkeys++] = ber_bvdup( &digest );
2036 ber_bvfree( sa->sa_final );
2037 ber_bvecfree( sa->sa_any );
2038 ber_bvfree( sa->sa_initial );
2041 return LDAP_SUCCESS;
2050 struct berval *value,
2051 void *assertedValue )
2053 *matchp = UTF8normcmp( value->bv_val,
2054 ((struct berval *) assertedValue)->bv_val,
2056 return LDAP_SUCCESS;
2062 struct berval *val )
2066 if( val->bv_len == 0 ) {
2067 /* disallow empty strings */
2068 return LDAP_INVALID_SYNTAX;
2071 if( OID_LEADCHAR(val->bv_val[0]) ) {
2073 for(i=1; i < val->bv_len; i++) {
2074 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2075 if( dot++ ) return 1;
2076 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2079 return LDAP_INVALID_SYNTAX;
2083 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2085 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2086 for(i=1; i < val->bv_len; i++) {
2087 if( !DESC_CHAR(val->bv_val[i] ) ) {
2088 return LDAP_INVALID_SYNTAX;
2092 return LDAP_SUCCESS;
2095 return LDAP_INVALID_SYNTAX;
2104 struct berval *value,
2105 void *assertedValue )
2108 int vsign=0, avsign=0;
2109 struct berval *asserted;
2110 ber_len_t vlen, avlen;
2113 /* Start off pessimistic */
2116 /* Skip past leading spaces/zeros, and get the sign of the *value number */
2118 vlen = value->bv_len;
2120 if( ASCII_SPACE(*v) || ( *v == '0' )) {
2121 /* empty -- skip spaces */
2123 else if ( *v == '+' ) {
2126 else if ( *v == '-' ) {
2129 else if ( ASCII_DIGIT(*v) ) {
2130 if ( vsign == 0 ) vsign = 1;
2138 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
2140 asserted = (struct berval *) assertedValue;
2141 av = asserted->bv_val;
2142 avlen = asserted->bv_len;
2144 if( ASCII_SPACE(*av) || ( *av == '0' )) {
2145 /* empty -- skip spaces */
2147 else if ( *av == '+' ) {
2150 else if ( *av == '-' ) {
2153 else if ( ASCII_DIGIT(*av) ) {
2154 if ( avsign == 0 ) avsign = 1;
2162 /* The two ?sign vars are now one of :
2163 -2 negative non-zero number
2165 0 0 collapse these three to 0
2167 +2 positive non-zero number
2169 if ( abs( vsign ) == 1 ) vsign = 0;
2170 if ( abs( avsign ) == 1 ) avsign = 0;
2172 if( vsign != avsign ) return LDAP_SUCCESS;
2174 /* Check the significant digits */
2175 while( vlen && avlen ) {
2176 if( *v != *av ) break;
2183 /* If all digits compared equal, the numbers are equal */
2184 if(( vlen == 0 ) && ( avlen == 0 )) {
2187 return LDAP_SUCCESS;
2193 struct berval *val )
2197 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2199 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
2200 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2201 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2202 return LDAP_INVALID_SYNTAX;
2205 for( i=1; i < val->bv_len; i++ ) {
2206 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2209 return LDAP_SUCCESS;
2216 struct berval **normalized )
2220 struct berval *newval;
2227 /* Ignore leading spaces */
2228 while ( len && ( *p == ' ' )) {
2235 negative = ( *p == '-' );
2236 if(( *p == '-' ) || ( *p == '+' )) {
2242 /* Ignore leading zeros */
2243 while ( len && ( *p == '0' )) {
2248 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2250 /* If there are no non-zero digits left, the number is zero, otherwise
2251 allocate space for the number and copy it into the buffer */
2253 newval->bv_val = ch_strdup("0");
2257 newval->bv_len = len+negative;
2258 newval->bv_val = ch_malloc( newval->bv_len );
2260 newval->bv_val[0] = '-';
2262 memcpy( newval->bv_val + negative, p, len );
2265 *normalized = newval;
2266 return LDAP_SUCCESS;
2269 /* Index generation function */
2275 struct berval *prefix,
2276 struct berval **values,
2277 struct berval ***keysp )
2280 struct berval **keys;
2282 /* we should have at least one value at this point */
2283 assert( values != NULL && values[0] != NULL );
2285 for( i=0; values[i] != NULL; i++ ) {
2286 /* empty -- just count them */
2289 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2291 for( i=0; values[i] != NULL; i++ ) {
2292 integerNormalize( syntax, values[i], &keys[i] );
2297 return LDAP_SUCCESS;
2300 /* Index generation function */
2306 struct berval *prefix,
2308 struct berval ***keysp )
2310 struct berval **keys;
2312 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2313 integerNormalize( syntax, assertValue, &keys[0] );
2317 return LDAP_SUCCESS;
2322 countryStringValidate(
2324 struct berval *val )
2326 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2328 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2329 return LDAP_INVALID_SYNTAX;
2331 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2332 return LDAP_INVALID_SYNTAX;
2335 return LDAP_SUCCESS;
2339 printableStringValidate(
2341 struct berval *val )
2345 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2347 for(i=0; i < val->bv_len; i++) {
2348 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2349 return LDAP_INVALID_SYNTAX;
2353 return LDAP_SUCCESS;
2357 printablesStringValidate(
2359 struct berval *val )
2363 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2365 for(i=0; i < val->bv_len; i++) {
2366 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2367 return LDAP_INVALID_SYNTAX;
2371 return LDAP_SUCCESS;
2377 struct berval *val )
2381 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2383 for(i=0; i < val->bv_len; i++) {
2384 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2387 return LDAP_SUCCESS;
2394 struct berval **normalized )
2396 struct berval *newval;
2399 newval = ch_malloc( sizeof( struct berval ) );
2403 /* Ignore initial whitespace */
2404 while ( ASCII_SPACE( *p ) ) {
2410 return LDAP_INVALID_SYNTAX;
2413 newval->bv_val = ch_strdup( p );
2414 p = q = newval->bv_val;
2417 if ( ASCII_SPACE( *p ) ) {
2420 /* Ignore the extra whitespace */
2421 while ( ASCII_SPACE( *p ) ) {
2429 assert( *newval->bv_val );
2430 assert( newval->bv_val < p );
2433 /* cannot start with a space */
2434 assert( !ASCII_SPACE(*newval->bv_val) );
2437 * If the string ended in space, backup the pointer one
2438 * position. One is enough because the above loop collapsed
2439 * all whitespace to a single space.
2442 if ( ASCII_SPACE( q[-1] ) ) {
2446 /* cannot end with a space */
2447 assert( !ASCII_SPACE( q[-1] ) );
2449 /* null terminate */
2452 newval->bv_len = q - newval->bv_val;
2453 *normalized = newval;
2455 return LDAP_SUCCESS;
2464 struct berval *value,
2465 void *assertedValue )
2467 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2470 match = strncmp( value->bv_val,
2471 ((struct berval *) assertedValue)->bv_val,
2476 return LDAP_SUCCESS;
2480 caseExactIA5SubstringsMatch(
2485 struct berval *value,
2486 void *assertedValue )
2489 SubstringsAssertion *sub = assertedValue;
2490 struct berval left = *value;
2494 /* Add up asserted input length */
2495 if( sub->sa_initial ) {
2496 inlen += sub->sa_initial->bv_len;
2499 for(i=0; sub->sa_any[i] != NULL; i++) {
2500 inlen += sub->sa_any[i]->bv_len;
2503 if( sub->sa_final ) {
2504 inlen += sub->sa_final->bv_len;
2507 if( sub->sa_initial ) {
2508 if( inlen > left.bv_len ) {
2513 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2514 sub->sa_initial->bv_len );
2520 left.bv_val += sub->sa_initial->bv_len;
2521 left.bv_len -= sub->sa_initial->bv_len;
2522 inlen -= sub->sa_initial->bv_len;
2525 if( sub->sa_final ) {
2526 if( inlen > left.bv_len ) {
2531 match = strncmp( sub->sa_final->bv_val,
2532 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2533 sub->sa_final->bv_len );
2539 left.bv_len -= sub->sa_final->bv_len;
2540 inlen -= sub->sa_final->bv_len;
2544 for(i=0; sub->sa_any[i]; i++) {
2549 if( inlen > left.bv_len ) {
2550 /* not enough length */
2555 if( sub->sa_any[i]->bv_len == 0 ) {
2559 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2566 idx = p - left.bv_val;
2567 assert( idx < left.bv_len );
2569 if( idx >= left.bv_len ) {
2570 /* this shouldn't happen */
2577 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2578 /* not enough left */
2583 match = strncmp( left.bv_val,
2584 sub->sa_any[i]->bv_val,
2585 sub->sa_any[i]->bv_len );
2593 left.bv_val += sub->sa_any[i]->bv_len;
2594 left.bv_len -= sub->sa_any[i]->bv_len;
2595 inlen -= sub->sa_any[i]->bv_len;
2601 return LDAP_SUCCESS;
2604 /* Index generation function */
2605 int caseExactIA5Indexer(
2610 struct berval *prefix,
2611 struct berval **values,
2612 struct berval ***keysp )
2616 struct berval **keys;
2617 HASH_CONTEXT HASHcontext;
2618 unsigned char HASHdigest[HASH_BYTES];
2619 struct berval digest;
2620 digest.bv_val = HASHdigest;
2621 digest.bv_len = sizeof(HASHdigest);
2623 for( i=0; values[i] != NULL; i++ ) {
2624 /* empty - just count them */
2627 /* we should have at least one value at this point */
2630 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2632 slen = strlen( syntax->ssyn_oid );
2633 mlen = strlen( mr->smr_oid );
2635 for( i=0; values[i] != NULL; i++ ) {
2636 struct berval *value = values[i];
2638 HASH_Init( &HASHcontext );
2639 if( prefix != NULL && prefix->bv_len > 0 ) {
2640 HASH_Update( &HASHcontext,
2641 prefix->bv_val, prefix->bv_len );
2643 HASH_Update( &HASHcontext,
2644 syntax->ssyn_oid, slen );
2645 HASH_Update( &HASHcontext,
2646 mr->smr_oid, mlen );
2647 HASH_Update( &HASHcontext,
2648 value->bv_val, value->bv_len );
2649 HASH_Final( HASHdigest, &HASHcontext );
2651 keys[i] = ber_bvdup( &digest );
2656 return LDAP_SUCCESS;
2659 /* Index generation function */
2660 int caseExactIA5Filter(
2665 struct berval *prefix,
2667 struct berval ***keysp )
2670 struct berval **keys;
2671 HASH_CONTEXT HASHcontext;
2672 unsigned char HASHdigest[HASH_BYTES];
2673 struct berval *value;
2674 struct berval digest;
2675 digest.bv_val = HASHdigest;
2676 digest.bv_len = sizeof(HASHdigest);
2678 slen = strlen( syntax->ssyn_oid );
2679 mlen = strlen( mr->smr_oid );
2681 value = (struct berval *) assertValue;
2683 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2685 HASH_Init( &HASHcontext );
2686 if( prefix != NULL && prefix->bv_len > 0 ) {
2687 HASH_Update( &HASHcontext,
2688 prefix->bv_val, prefix->bv_len );
2690 HASH_Update( &HASHcontext,
2691 syntax->ssyn_oid, slen );
2692 HASH_Update( &HASHcontext,
2693 mr->smr_oid, mlen );
2694 HASH_Update( &HASHcontext,
2695 value->bv_val, value->bv_len );
2696 HASH_Final( HASHdigest, &HASHcontext );
2698 keys[0] = ber_bvdup( &digest );
2702 return LDAP_SUCCESS;
2705 /* Substrings Index generation function */
2706 int caseExactIA5SubstringsIndexer(
2711 struct berval *prefix,
2712 struct berval **values,
2713 struct berval ***keysp )
2717 struct berval **keys;
2718 HASH_CONTEXT HASHcontext;
2719 unsigned char HASHdigest[HASH_BYTES];
2720 struct berval digest;
2721 digest.bv_val = HASHdigest;
2722 digest.bv_len = sizeof(HASHdigest);
2724 /* we should have at least one value at this point */
2725 assert( values != NULL && values[0] != NULL );
2728 for( i=0; values[i] != NULL; i++ ) {
2729 /* count number of indices to generate */
2730 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2734 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2735 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2736 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2737 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2739 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2743 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2744 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2745 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2749 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2750 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2751 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2752 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2754 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2760 /* no keys to generate */
2762 return LDAP_SUCCESS;
2765 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2767 slen = strlen( syntax->ssyn_oid );
2768 mlen = strlen( mr->smr_oid );
2771 for( i=0; values[i] != NULL; i++ ) {
2773 struct berval *value;
2776 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2778 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2779 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2781 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2782 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2784 for( j=0; j<max; j++ ) {
2785 HASH_Init( &HASHcontext );
2786 if( prefix != NULL && prefix->bv_len > 0 ) {
2787 HASH_Update( &HASHcontext,
2788 prefix->bv_val, prefix->bv_len );
2791 HASH_Update( &HASHcontext,
2792 &pre, sizeof( pre ) );
2793 HASH_Update( &HASHcontext,
2794 syntax->ssyn_oid, slen );
2795 HASH_Update( &HASHcontext,
2796 mr->smr_oid, mlen );
2797 HASH_Update( &HASHcontext,
2799 SLAP_INDEX_SUBSTR_MAXLEN );
2800 HASH_Final( HASHdigest, &HASHcontext );
2802 keys[nkeys++] = ber_bvdup( &digest );
2806 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2807 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2809 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2812 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2813 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2814 HASH_Init( &HASHcontext );
2815 if( prefix != NULL && prefix->bv_len > 0 ) {
2816 HASH_Update( &HASHcontext,
2817 prefix->bv_val, prefix->bv_len );
2819 HASH_Update( &HASHcontext,
2820 &pre, sizeof( pre ) );
2821 HASH_Update( &HASHcontext,
2822 syntax->ssyn_oid, slen );
2823 HASH_Update( &HASHcontext,
2824 mr->smr_oid, mlen );
2825 HASH_Update( &HASHcontext,
2827 HASH_Final( HASHdigest, &HASHcontext );
2829 keys[nkeys++] = ber_bvdup( &digest );
2832 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2833 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2834 HASH_Init( &HASHcontext );
2835 if( prefix != NULL && prefix->bv_len > 0 ) {
2836 HASH_Update( &HASHcontext,
2837 prefix->bv_val, prefix->bv_len );
2839 HASH_Update( &HASHcontext,
2840 &pre, sizeof( pre ) );
2841 HASH_Update( &HASHcontext,
2842 syntax->ssyn_oid, slen );
2843 HASH_Update( &HASHcontext,
2844 mr->smr_oid, mlen );
2845 HASH_Update( &HASHcontext,
2846 &value->bv_val[value->bv_len-j], j );
2847 HASH_Final( HASHdigest, &HASHcontext );
2849 keys[nkeys++] = ber_bvdup( &digest );
2863 return LDAP_SUCCESS;
2866 int caseExactIA5SubstringsFilter(
2871 struct berval *prefix,
2873 struct berval ***keysp )
2875 SubstringsAssertion *sa = assertValue;
2877 ber_len_t nkeys = 0;
2878 size_t slen, mlen, klen;
2879 struct berval **keys;
2880 HASH_CONTEXT HASHcontext;
2881 unsigned char HASHdigest[HASH_BYTES];
2882 struct berval *value;
2883 struct berval digest;
2885 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2886 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2891 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2893 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2894 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2895 /* don't bother accounting for stepping */
2896 nkeys += sa->sa_any[i]->bv_len -
2897 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2902 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2903 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2910 return LDAP_SUCCESS;
2913 digest.bv_val = HASHdigest;
2914 digest.bv_len = sizeof(HASHdigest);
2916 slen = strlen( syntax->ssyn_oid );
2917 mlen = strlen( mr->smr_oid );
2919 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2922 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2923 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2925 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2926 value = sa->sa_initial;
2928 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2929 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2931 HASH_Init( &HASHcontext );
2932 if( prefix != NULL && prefix->bv_len > 0 ) {
2933 HASH_Update( &HASHcontext,
2934 prefix->bv_val, prefix->bv_len );
2936 HASH_Update( &HASHcontext,
2937 &pre, sizeof( pre ) );
2938 HASH_Update( &HASHcontext,
2939 syntax->ssyn_oid, slen );
2940 HASH_Update( &HASHcontext,
2941 mr->smr_oid, mlen );
2942 HASH_Update( &HASHcontext,
2943 value->bv_val, klen );
2944 HASH_Final( HASHdigest, &HASHcontext );
2946 keys[nkeys++] = ber_bvdup( &digest );
2949 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2951 pre = SLAP_INDEX_SUBSTR_PREFIX;
2952 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2954 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2955 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2959 value = sa->sa_any[i];
2962 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2963 j += SLAP_INDEX_SUBSTR_STEP )
2965 HASH_Init( &HASHcontext );
2966 if( prefix != NULL && prefix->bv_len > 0 ) {
2967 HASH_Update( &HASHcontext,
2968 prefix->bv_val, prefix->bv_len );
2970 HASH_Update( &HASHcontext,
2971 &pre, sizeof( pre ) );
2972 HASH_Update( &HASHcontext,
2973 syntax->ssyn_oid, slen );
2974 HASH_Update( &HASHcontext,
2975 mr->smr_oid, mlen );
2976 HASH_Update( &HASHcontext,
2977 &value->bv_val[j], klen );
2978 HASH_Final( HASHdigest, &HASHcontext );
2980 keys[nkeys++] = ber_bvdup( &digest );
2985 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2986 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2988 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2989 value = sa->sa_final;
2991 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2992 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2994 HASH_Init( &HASHcontext );
2995 if( prefix != NULL && prefix->bv_len > 0 ) {
2996 HASH_Update( &HASHcontext,
2997 prefix->bv_val, prefix->bv_len );
2999 HASH_Update( &HASHcontext,
3000 &pre, sizeof( pre ) );
3001 HASH_Update( &HASHcontext,
3002 syntax->ssyn_oid, slen );
3003 HASH_Update( &HASHcontext,
3004 mr->smr_oid, mlen );
3005 HASH_Update( &HASHcontext,
3006 &value->bv_val[value->bv_len-klen], klen );
3007 HASH_Final( HASHdigest, &HASHcontext );
3009 keys[nkeys++] = ber_bvdup( &digest );
3020 return LDAP_SUCCESS;
3029 struct berval *value,
3030 void *assertedValue )
3032 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3034 if( match == 0 && value->bv_len ) {
3035 match = strncasecmp( value->bv_val,
3036 ((struct berval *) assertedValue)->bv_val,
3041 return LDAP_SUCCESS;
3045 caseIgnoreIA5SubstringsMatch(
3050 struct berval *value,
3051 void *assertedValue )
3054 SubstringsAssertion *sub = assertedValue;
3055 struct berval left = *value;
3059 /* Add up asserted input length */
3060 if( sub->sa_initial ) {
3061 inlen += sub->sa_initial->bv_len;
3064 for(i=0; sub->sa_any[i] != NULL; i++) {
3065 inlen += sub->sa_any[i]->bv_len;
3068 if( sub->sa_final ) {
3069 inlen += sub->sa_final->bv_len;
3072 if( sub->sa_initial ) {
3073 if( inlen > left.bv_len ) {
3078 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3079 sub->sa_initial->bv_len );
3085 left.bv_val += sub->sa_initial->bv_len;
3086 left.bv_len -= sub->sa_initial->bv_len;
3087 inlen -= sub->sa_initial->bv_len;
3090 if( sub->sa_final ) {
3091 if( inlen > left.bv_len ) {
3096 match = strncasecmp( sub->sa_final->bv_val,
3097 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3098 sub->sa_final->bv_len );
3104 left.bv_len -= sub->sa_final->bv_len;
3105 inlen -= sub->sa_final->bv_len;
3109 for(i=0; sub->sa_any[i]; i++) {
3114 if( inlen > left.bv_len ) {
3115 /* not enough length */
3120 if( sub->sa_any[i]->bv_len == 0 ) {
3124 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3131 idx = p - left.bv_val;
3132 assert( idx < left.bv_len );
3134 if( idx >= left.bv_len ) {
3135 /* this shouldn't happen */
3142 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3143 /* not enough left */
3148 match = strncasecmp( left.bv_val,
3149 sub->sa_any[i]->bv_val,
3150 sub->sa_any[i]->bv_len );
3159 left.bv_val += sub->sa_any[i]->bv_len;
3160 left.bv_len -= sub->sa_any[i]->bv_len;
3161 inlen -= sub->sa_any[i]->bv_len;
3167 return LDAP_SUCCESS;
3170 /* Index generation function */
3171 int caseIgnoreIA5Indexer(
3176 struct berval *prefix,
3177 struct berval **values,
3178 struct berval ***keysp )
3182 struct berval **keys;
3183 HASH_CONTEXT HASHcontext;
3184 unsigned char HASHdigest[HASH_BYTES];
3185 struct berval digest;
3186 digest.bv_val = HASHdigest;
3187 digest.bv_len = sizeof(HASHdigest);
3189 /* we should have at least one value at this point */
3190 assert( values != NULL && values[0] != NULL );
3192 for( i=0; values[i] != NULL; i++ ) {
3193 /* just count them */
3196 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3198 slen = strlen( syntax->ssyn_oid );
3199 mlen = strlen( mr->smr_oid );
3201 for( i=0; values[i] != NULL; i++ ) {
3202 struct berval *value = ber_bvdup( values[i] );
3203 ldap_pvt_str2upper( value->bv_val );
3205 HASH_Init( &HASHcontext );
3206 if( prefix != NULL && prefix->bv_len > 0 ) {
3207 HASH_Update( &HASHcontext,
3208 prefix->bv_val, prefix->bv_len );
3210 HASH_Update( &HASHcontext,
3211 syntax->ssyn_oid, slen );
3212 HASH_Update( &HASHcontext,
3213 mr->smr_oid, mlen );
3214 HASH_Update( &HASHcontext,
3215 value->bv_val, value->bv_len );
3216 HASH_Final( HASHdigest, &HASHcontext );
3218 ber_bvfree( value );
3220 keys[i] = ber_bvdup( &digest );
3225 return LDAP_SUCCESS;
3228 /* Index generation function */
3229 int caseIgnoreIA5Filter(
3234 struct berval *prefix,
3236 struct berval ***keysp )
3239 struct berval **keys;
3240 HASH_CONTEXT HASHcontext;
3241 unsigned char HASHdigest[HASH_BYTES];
3242 struct berval *value;
3243 struct berval digest;
3244 digest.bv_val = HASHdigest;
3245 digest.bv_len = sizeof(HASHdigest);
3247 slen = strlen( syntax->ssyn_oid );
3248 mlen = strlen( mr->smr_oid );
3250 value = ber_bvdup( (struct berval *) assertValue );
3251 ldap_pvt_str2upper( value->bv_val );
3253 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3255 HASH_Init( &HASHcontext );
3256 if( prefix != NULL && prefix->bv_len > 0 ) {
3257 HASH_Update( &HASHcontext,
3258 prefix->bv_val, prefix->bv_len );
3260 HASH_Update( &HASHcontext,
3261 syntax->ssyn_oid, slen );
3262 HASH_Update( &HASHcontext,
3263 mr->smr_oid, mlen );
3264 HASH_Update( &HASHcontext,
3265 value->bv_val, value->bv_len );
3266 HASH_Final( HASHdigest, &HASHcontext );
3268 keys[0] = ber_bvdup( &digest );
3271 ber_bvfree( value );
3275 return LDAP_SUCCESS;
3278 /* Substrings Index generation function */
3279 int caseIgnoreIA5SubstringsIndexer(
3284 struct berval *prefix,
3285 struct berval **values,
3286 struct berval ***keysp )
3290 struct berval **keys;
3291 HASH_CONTEXT HASHcontext;
3292 unsigned char HASHdigest[HASH_BYTES];
3293 struct berval digest;
3294 digest.bv_val = HASHdigest;
3295 digest.bv_len = sizeof(HASHdigest);
3297 /* we should have at least one value at this point */
3298 assert( values != NULL && values[0] != NULL );
3301 for( i=0; values[i] != NULL; i++ ) {
3302 /* count number of indices to generate */
3303 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3307 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3308 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3309 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3310 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3312 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3316 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3317 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3318 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3322 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3323 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3324 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3325 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3327 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3333 /* no keys to generate */
3335 return LDAP_SUCCESS;
3338 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3340 slen = strlen( syntax->ssyn_oid );
3341 mlen = strlen( mr->smr_oid );
3344 for( i=0; values[i] != NULL; i++ ) {
3346 struct berval *value;
3348 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3350 value = ber_bvdup( values[i] );
3351 ldap_pvt_str2upper( value->bv_val );
3353 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3354 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3356 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3357 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3359 for( j=0; j<max; j++ ) {
3360 HASH_Init( &HASHcontext );
3361 if( prefix != NULL && prefix->bv_len > 0 ) {
3362 HASH_Update( &HASHcontext,
3363 prefix->bv_val, prefix->bv_len );
3366 HASH_Update( &HASHcontext,
3367 &pre, sizeof( pre ) );
3368 HASH_Update( &HASHcontext,
3369 syntax->ssyn_oid, slen );
3370 HASH_Update( &HASHcontext,
3371 mr->smr_oid, mlen );
3372 HASH_Update( &HASHcontext,
3374 SLAP_INDEX_SUBSTR_MAXLEN );
3375 HASH_Final( HASHdigest, &HASHcontext );
3377 keys[nkeys++] = ber_bvdup( &digest );
3381 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3382 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3384 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3387 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3388 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3389 HASH_Init( &HASHcontext );
3390 if( prefix != NULL && prefix->bv_len > 0 ) {
3391 HASH_Update( &HASHcontext,
3392 prefix->bv_val, prefix->bv_len );
3394 HASH_Update( &HASHcontext,
3395 &pre, sizeof( pre ) );
3396 HASH_Update( &HASHcontext,
3397 syntax->ssyn_oid, slen );
3398 HASH_Update( &HASHcontext,
3399 mr->smr_oid, mlen );
3400 HASH_Update( &HASHcontext,
3402 HASH_Final( HASHdigest, &HASHcontext );
3404 keys[nkeys++] = ber_bvdup( &digest );
3407 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3408 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3409 HASH_Init( &HASHcontext );
3410 if( prefix != NULL && prefix->bv_len > 0 ) {
3411 HASH_Update( &HASHcontext,
3412 prefix->bv_val, prefix->bv_len );
3414 HASH_Update( &HASHcontext,
3415 &pre, sizeof( pre ) );
3416 HASH_Update( &HASHcontext,
3417 syntax->ssyn_oid, slen );
3418 HASH_Update( &HASHcontext,
3419 mr->smr_oid, mlen );
3420 HASH_Update( &HASHcontext,
3421 &value->bv_val[value->bv_len-j], j );
3422 HASH_Final( HASHdigest, &HASHcontext );
3424 keys[nkeys++] = ber_bvdup( &digest );
3429 ber_bvfree( value );
3440 return LDAP_SUCCESS;
3443 int caseIgnoreIA5SubstringsFilter(
3448 struct berval *prefix,
3450 struct berval ***keysp )
3452 SubstringsAssertion *sa = assertValue;
3454 ber_len_t nkeys = 0;
3455 size_t slen, mlen, klen;
3456 struct berval **keys;
3457 HASH_CONTEXT HASHcontext;
3458 unsigned char HASHdigest[HASH_BYTES];
3459 struct berval *value;
3460 struct berval digest;
3462 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3463 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3468 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3470 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3471 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3472 /* don't bother accounting for stepping */
3473 nkeys += sa->sa_any[i]->bv_len -
3474 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3479 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3480 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3487 return LDAP_SUCCESS;
3490 digest.bv_val = HASHdigest;
3491 digest.bv_len = sizeof(HASHdigest);
3493 slen = strlen( syntax->ssyn_oid );
3494 mlen = strlen( mr->smr_oid );
3496 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3499 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3500 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3502 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3503 value = ber_bvdup( sa->sa_initial );
3504 ldap_pvt_str2upper( value->bv_val );
3506 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3507 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3509 HASH_Init( &HASHcontext );
3510 if( prefix != NULL && prefix->bv_len > 0 ) {
3511 HASH_Update( &HASHcontext,
3512 prefix->bv_val, prefix->bv_len );
3514 HASH_Update( &HASHcontext,
3515 &pre, sizeof( pre ) );
3516 HASH_Update( &HASHcontext,
3517 syntax->ssyn_oid, slen );
3518 HASH_Update( &HASHcontext,
3519 mr->smr_oid, mlen );
3520 HASH_Update( &HASHcontext,
3521 value->bv_val, klen );
3522 HASH_Final( HASHdigest, &HASHcontext );
3524 ber_bvfree( value );
3525 keys[nkeys++] = ber_bvdup( &digest );
3528 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3530 pre = SLAP_INDEX_SUBSTR_PREFIX;
3531 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3533 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3534 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3538 value = ber_bvdup( sa->sa_any[i] );
3539 ldap_pvt_str2upper( value->bv_val );
3542 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3543 j += SLAP_INDEX_SUBSTR_STEP )
3545 HASH_Init( &HASHcontext );
3546 if( prefix != NULL && prefix->bv_len > 0 ) {
3547 HASH_Update( &HASHcontext,
3548 prefix->bv_val, prefix->bv_len );
3550 HASH_Update( &HASHcontext,
3551 &pre, sizeof( pre ) );
3552 HASH_Update( &HASHcontext,
3553 syntax->ssyn_oid, slen );
3554 HASH_Update( &HASHcontext,
3555 mr->smr_oid, mlen );
3556 HASH_Update( &HASHcontext,
3557 &value->bv_val[j], klen );
3558 HASH_Final( HASHdigest, &HASHcontext );
3560 keys[nkeys++] = ber_bvdup( &digest );
3563 ber_bvfree( value );
3567 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3568 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3570 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3571 value = ber_bvdup( sa->sa_final );
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[value->bv_len-klen], klen );
3590 HASH_Final( HASHdigest, &HASHcontext );
3592 ber_bvfree( value );
3593 keys[nkeys++] = ber_bvdup( &digest );
3604 return LDAP_SUCCESS;
3608 numericStringValidate(
3614 for(i=0; i < in->bv_len; i++) {
3615 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3616 return LDAP_INVALID_SYNTAX;
3620 return LDAP_SUCCESS;
3624 numericStringNormalize(
3627 struct berval **normalized )
3629 /* removal all spaces */
3630 struct berval *newval;
3633 newval = ch_malloc( sizeof( struct berval ) );
3634 newval->bv_val = ch_malloc( val->bv_len + 1 );
3640 if ( ASCII_SPACE( *p ) ) {
3641 /* Ignore whitespace */
3648 /* we should have copied no more then is in val */
3649 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3651 /* null terminate */
3654 newval->bv_len = q - newval->bv_val;
3655 *normalized = newval;
3657 return LDAP_SUCCESS;
3661 objectIdentifierFirstComponentMatch(
3666 struct berval *value,
3667 void *assertedValue )
3669 int rc = LDAP_SUCCESS;
3671 struct berval *asserted = (struct berval *) assertedValue;
3675 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3676 return LDAP_INVALID_SYNTAX;
3679 /* trim leading white space */
3680 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3684 /* grab next word */
3685 oid.bv_val = &value->bv_val[i];
3686 oid.bv_len = value->bv_len - i;
3687 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3692 /* insert attributeTypes, objectclass check here */
3693 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3694 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3697 char *stored = ch_malloc( oid.bv_len + 1 );
3698 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3699 stored[oid.bv_len] = '\0';
3701 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3702 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3703 MatchingRule *stored_mr = mr_find( stored );
3705 if( asserted_mr == NULL ) {
3706 rc = SLAPD_COMPARE_UNDEFINED;
3708 match = asserted_mr != stored_mr;
3711 } else if ( !strcmp( syntax->ssyn_oid,
3712 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3714 AttributeType *asserted_at = at_find( asserted->bv_val );
3715 AttributeType *stored_at = at_find( stored );
3717 if( asserted_at == NULL ) {
3718 rc = SLAPD_COMPARE_UNDEFINED;
3720 match = asserted_at != stored_at;
3723 } else if ( !strcmp( syntax->ssyn_oid,
3724 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3726 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3727 ObjectClass *stored_oc = oc_find( stored );
3729 if( asserted_oc == NULL ) {
3730 rc = SLAPD_COMPARE_UNDEFINED;
3732 match = asserted_oc != stored_oc;
3740 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3741 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3742 match, value->bv_val, asserted->bv_val ));
3744 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3745 "%d\n\t\"%s\"\n\t\"%s\"\n",
3746 match, value->bv_val, asserted->bv_val );
3750 if( rc == LDAP_SUCCESS ) *matchp = match;
3760 struct berval *value,
3761 void *assertedValue )
3763 long lValue, lAssertedValue;
3765 /* safe to assume integers are NUL terminated? */
3766 lValue = strtoul(value->bv_val, NULL, 10);
3767 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3768 return LDAP_CONSTRAINT_VIOLATION;
3770 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3771 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3772 return LDAP_CONSTRAINT_VIOLATION;
3774 *matchp = (lValue & lAssertedValue);
3775 return LDAP_SUCCESS;
3784 struct berval *value,
3785 void *assertedValue )
3787 long lValue, lAssertedValue;
3789 /* safe to assume integers are NUL terminated? */
3790 lValue = strtoul(value->bv_val, NULL, 10);
3791 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3792 return LDAP_CONSTRAINT_VIOLATION;
3794 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3795 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3796 return LDAP_CONSTRAINT_VIOLATION;
3798 *matchp = (lValue | lAssertedValue);
3799 return LDAP_SUCCESS;
3803 #include <openssl/x509.h>
3804 #include <openssl/err.h>
3805 char digit[] = "0123456789";
3808 * Next function returns a string representation of a ASN1_INTEGER.
3809 * It works for unlimited lengths.
3812 static struct berval *
3813 asn1_integer2str(ASN1_INTEGER *a)
3818 /* We work backwards, make it fill from the end of buf */
3819 p = buf + sizeof(buf) - 1;
3822 if ( a == NULL || a->length == 0 ) {
3830 /* We want to preserve the original */
3831 copy = ch_malloc(n*sizeof(unsigned int));
3832 for (i = 0; i<n; i++) {
3833 copy[i] = a->data[i];
3837 * base indicates the index of the most significant
3838 * byte that might be nonzero. When it goes off the
3839 * end, we now there is nothing left to do.
3845 for (i = base; i<n; i++ ) {
3846 copy[i] += carry*256;
3847 carry = copy[i] % 10;
3852 * Way too large, we need to leave
3853 * room for sign if negative
3858 *--p = digit[carry];
3859 if (copy[base] == 0)
3865 if ( a->type == V_ASN1_NEG_INTEGER ) {
3869 return ber_bvstrdup(p);
3872 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3873 static struct berval *
3874 dn_openssl2ldap(X509_NAME *name)
3876 char issuer_dn[1024];
3879 bio = BIO_new(BIO_s_mem());
3882 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3883 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3884 ERR_error_string(ERR_get_error(),NULL)));
3886 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3887 "error creating BIO: %s\n",
3888 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3892 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3894 BIO_gets(bio, issuer_dn, 1024);
3897 return ber_bvstrdup(issuer_dn);
3901 * Given a certificate in DER format, extract the corresponding
3902 * assertion value for certificateExactMatch
3905 certificateExactConvert(
3907 struct berval ** out )
3910 unsigned char *p = in->bv_val;
3911 struct berval *serial;
3912 struct berval *issuer_dn;
3913 struct berval *bv_tmp;
3915 xcert = d2i_X509(NULL, &p, in->bv_len);
3918 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3919 "certificateExactConvert: error parsing cert: %s\n",
3920 ERR_error_string(ERR_get_error(),NULL)));
3922 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3923 "error parsing cert: %s\n",
3924 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3926 return LDAP_INVALID_SYNTAX;
3929 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3932 return LDAP_INVALID_SYNTAX;
3934 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3938 return LDAP_INVALID_SYNTAX;
3940 /* Actually, dn_openssl2ldap returns in a normalized format, but
3941 it is different from our normalized format */
3943 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3947 return LDAP_INVALID_SYNTAX;
3953 *out = ch_malloc(sizeof(struct berval));
3954 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3955 (*out)->bv_val = ch_malloc((*out)->bv_len);
3957 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3958 p += serial->bv_len;
3959 AC_MEMCPY(p, " $ ", 3);
3961 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3962 p += issuer_dn->bv_len;
3966 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3967 "certificateExactConvert: \n %s\n",
3970 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3972 (*out)->bv_val, NULL, NULL );
3976 ber_bvfree(issuer_dn);
3978 return LDAP_SUCCESS;
3982 serial_and_issuer_parse(
3983 struct berval *assertion,
3984 struct berval **serial,
3985 struct berval **issuer_dn
3993 begin = assertion->bv_val;
3994 end = assertion->bv_val+assertion->bv_len-1;
3995 for (p=begin; p<=end && *p != '$'; p++)
3998 return LDAP_INVALID_SYNTAX;
4000 /* p now points at the $ sign, now use begin and end to delimit the
4002 while (ASCII_SPACE(*begin))
4005 while (ASCII_SPACE(*end))
4008 q = ch_malloc( (end-begin+1)+1 );
4009 AC_MEMCPY( q, begin, end-begin+1 );
4010 q[end-begin+1] = '\0';
4011 *serial = ber_bvstr(q);
4013 /* now extract the issuer, remember p was at the dollar sign */
4015 end = assertion->bv_val+assertion->bv_len-1;
4016 while (ASCII_SPACE(*begin))
4018 /* should we trim spaces at the end too? is it safe always? */
4020 q = ch_malloc( (end-begin+1)+1 );
4021 AC_MEMCPY( q, begin, end-begin+1 );
4022 q[end-begin+1] = '\0';
4023 *issuer_dn = ber_bvstr(dn_normalize(q));
4025 return LDAP_SUCCESS;
4029 certificateExactMatch(
4034 struct berval *value,
4035 void *assertedValue )
4038 unsigned char *p = value->bv_val;
4039 struct berval *serial;
4040 struct berval *issuer_dn;
4041 struct berval *asserted_serial;
4042 struct berval *asserted_issuer_dn;
4045 xcert = d2i_X509(NULL, &p, value->bv_len);
4048 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4049 "certificateExactMatch: error parsing cert: %s\n",
4050 ERR_error_string(ERR_get_error(),NULL)));
4052 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
4053 "error parsing cert: %s\n",
4054 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4056 return LDAP_INVALID_SYNTAX;
4059 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4060 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4064 serial_and_issuer_parse(assertedValue,
4066 &asserted_issuer_dn);
4071 slap_schema.si_syn_integer,
4072 slap_schema.si_mr_integerMatch,
4075 if ( ret == LDAP_SUCCESS ) {
4076 if ( *matchp == 0 ) {
4077 /* We need to normalize everything for dnMatch */
4081 slap_schema.si_syn_distinguishedName,
4082 slap_schema.si_mr_distinguishedNameMatch,
4084 asserted_issuer_dn);
4089 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4090 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
4091 *matchp, serial->bv_val, issuer_dn->bv_val,
4092 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
4094 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
4095 "%d\n\t\"%s $ %s\"\n",
4096 *matchp, serial->bv_val, issuer_dn->bv_val );
4097 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
4098 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
4103 ber_bvfree(issuer_dn);
4104 ber_bvfree(asserted_serial);
4105 ber_bvfree(asserted_issuer_dn);
4111 * Index generation function
4112 * We just index the serials, in most scenarios the issuer DN is one of
4113 * a very small set of values.
4115 int certificateExactIndexer(
4120 struct berval *prefix,
4121 struct berval **values,
4122 struct berval ***keysp )
4125 struct berval **keys;
4128 struct berval * serial;
4130 /* we should have at least one value at this point */
4131 assert( values != NULL && values[0] != NULL );
4133 for( i=0; values[i] != NULL; i++ ) {
4134 /* empty -- just count them */
4137 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
4139 for( i=0; values[i] != NULL; i++ ) {
4140 p = values[i]->bv_val;
4141 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
4144 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4145 "certificateExactIndexer: error parsing cert: %s\n",
4146 ERR_error_string(ERR_get_error(),NULL)));
4148 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4149 "error parsing cert: %s\n",
4150 ERR_error_string(ERR_get_error(),NULL),
4153 /* Do we leak keys on error? */
4154 return LDAP_INVALID_SYNTAX;
4157 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4159 integerNormalize( slap_schema.si_syn_integer,
4164 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4165 "certificateExactIndexer: returning: %s\n",
4168 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4177 return LDAP_SUCCESS;
4180 /* Index generation function */
4181 /* We think this is always called with a value in matching rule syntax */
4182 int certificateExactFilter(
4187 struct berval *prefix,
4189 struct berval ***keysp )
4191 struct berval **keys;
4192 struct berval *asserted_serial;
4193 struct berval *asserted_issuer_dn;
4195 serial_and_issuer_parse(assertValue,
4197 &asserted_issuer_dn);
4199 keys = ch_malloc( sizeof( struct berval * ) * 2 );
4200 integerNormalize( syntax, asserted_serial, &keys[0] );
4204 ber_bvfree(asserted_serial);
4205 ber_bvfree(asserted_issuer_dn);
4206 return LDAP_SUCCESS;
4211 check_time_syntax (struct berval *val,
4215 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
4216 static int mdays[2][12] = {
4217 /* non-leap years */
4218 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
4220 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
4223 int part, c, tzoffset, leapyear = 0 ;
4225 if( val->bv_len == 0 ) {
4226 return LDAP_INVALID_SYNTAX;
4229 p = (char *)val->bv_val;
4230 e = p + val->bv_len;
4232 /* Ignore initial whitespace */
4233 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4237 if (e - p < 13 - (2 * start)) {
4238 return LDAP_INVALID_SYNTAX;
4241 for (part = 0; part < 9; part++) {
4245 for (part = start; part < 7; part++) {
4247 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
4254 return LDAP_INVALID_SYNTAX;
4256 if (c < 0 || c > 9) {
4257 return LDAP_INVALID_SYNTAX;
4263 return LDAP_INVALID_SYNTAX;
4265 if (c < 0 || c > 9) {
4266 return LDAP_INVALID_SYNTAX;
4271 if (part == 2 || part == 3) {
4274 if (parts[part] < 0) {
4275 return LDAP_INVALID_SYNTAX;
4277 if (parts[part] > ceiling[part]) {
4278 return LDAP_INVALID_SYNTAX;
4282 /* leapyear check for the Gregorian calendar (year>1581) */
4283 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
4284 ((parts[0] % 4 == 0) && (parts[1] == 0)))
4289 if (parts[3] > mdays[leapyear][parts[2]]) {
4290 return LDAP_INVALID_SYNTAX;
4295 tzoffset = 0; /* UTC */
4296 } else if (c != '+' && c != '-') {
4297 return LDAP_INVALID_SYNTAX;
4301 } else /* c == '+' */ {
4306 return LDAP_INVALID_SYNTAX;
4309 for (part = 7; part < 9; part++) {
4311 if (c < 0 || c > 9) {
4312 return LDAP_INVALID_SYNTAX;
4317 if (c < 0 || c > 9) {
4318 return LDAP_INVALID_SYNTAX;
4322 if (parts[part] < 0 || parts[part] > ceiling[part]) {
4323 return LDAP_INVALID_SYNTAX;
4328 /* Ignore trailing whitespace */
4329 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4333 return LDAP_INVALID_SYNTAX;
4336 switch ( tzoffset ) {
4337 case -1: /* negativ offset to UTC, ie west of Greenwich */
4338 parts[4] += parts[7];
4339 parts[5] += parts[8];
4340 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
4344 c = mdays[leapyear][parts[2]];
4346 if (parts[part] > c) {
4347 parts[part] -= c + 1;
4352 case 1: /* positive offset to UTC, ie east of Greenwich */
4353 parts[4] -= parts[7];
4354 parts[5] -= parts[8];
4355 for (part = 6; --part > 0; ) {
4359 /* first arg to % needs to be non negativ */
4360 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
4362 if (parts[part] < 0) {
4363 parts[part] += c + 1;
4368 case 0: /* already UTC */
4372 return LDAP_SUCCESS;
4379 struct berval **normalized )
4384 rc = check_time_syntax(val, 1, parts);
4385 if (rc != LDAP_SUCCESS) {
4390 out = ch_malloc( sizeof(struct berval) );
4392 return LBER_ERROR_MEMORY;
4395 out->bv_val = ch_malloc( 14 );
4396 if ( out->bv_val == NULL ) {
4398 return LBER_ERROR_MEMORY;
4401 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02dZ",
4402 parts[1], parts[2] + 1, parts[3] + 1,
4403 parts[4], parts[5], parts[6] );
4407 return LDAP_SUCCESS;
4417 return check_time_syntax(in, 1, parts);
4421 generalizedTimeValidate(
4427 return check_time_syntax(in, 0, parts);
4431 generalizedTimeNormalize(
4434 struct berval **normalized )
4439 rc = check_time_syntax(val, 0, parts);
4440 if (rc != LDAP_SUCCESS) {
4445 out = ch_malloc( sizeof(struct berval) );
4447 return LBER_ERROR_MEMORY;
4450 out->bv_val = ch_malloc( 16 );
4451 if ( out->bv_val == NULL ) {
4453 return LBER_ERROR_MEMORY;
4456 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4457 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4458 parts[4], parts[5], parts[6] );
4462 return LDAP_SUCCESS;
4466 nisNetgroupTripleValidate(
4468 struct berval *val )
4473 if ( val->bv_len == 0 ) {
4474 return LDAP_INVALID_SYNTAX;
4477 p = (char *)val->bv_val;
4478 e = p + val->bv_len;
4480 if ( *p != '(' /*')'*/ ) {
4481 return LDAP_INVALID_SYNTAX;
4484 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4488 return LDAP_INVALID_SYNTAX;
4491 } else if ( !ATTR_CHAR( *p ) ) {
4492 return LDAP_INVALID_SYNTAX;
4496 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4497 return LDAP_INVALID_SYNTAX;
4503 return LDAP_INVALID_SYNTAX;
4506 return LDAP_SUCCESS;
4510 bootParameterValidate(
4512 struct berval *val )
4516 if ( val->bv_len == 0 ) {
4517 return LDAP_INVALID_SYNTAX;
4520 p = (char *)val->bv_val;
4521 e = p + val->bv_len;
4524 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4525 if ( !ATTR_CHAR( *p ) ) {
4526 return LDAP_INVALID_SYNTAX;
4531 return LDAP_INVALID_SYNTAX;
4535 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4536 if ( !ATTR_CHAR( *p ) ) {
4537 return LDAP_INVALID_SYNTAX;
4542 return LDAP_INVALID_SYNTAX;
4546 for ( p++; p < e; p++ ) {
4547 if ( !ATTR_CHAR( *p ) ) {
4548 return LDAP_INVALID_SYNTAX;
4552 return LDAP_SUCCESS;
4555 struct syntax_defs_rec {
4558 slap_syntax_validate_func *sd_validate;
4559 slap_syntax_transform_func *sd_normalize;
4560 slap_syntax_transform_func *sd_pretty;
4561 #ifdef SLAPD_BINARY_CONVERSION
4562 slap_syntax_transform_func *sd_ber2str;
4563 slap_syntax_transform_func *sd_str2ber;
4567 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4568 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4570 struct syntax_defs_rec syntax_defs[] = {
4571 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4572 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4573 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4574 0, NULL, NULL, NULL},
4575 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4576 0, NULL, NULL, NULL},
4577 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4578 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4579 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4580 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4581 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4582 0, bitStringValidate, bitStringNormalize, NULL },
4583 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4584 0, booleanValidate, NULL, NULL},
4585 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4586 X_BINARY X_NOT_H_R ")",
4587 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4588 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4589 X_BINARY X_NOT_H_R ")",
4590 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4591 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4592 X_BINARY X_NOT_H_R ")",
4593 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4594 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4595 0, countryStringValidate, IA5StringNormalize, NULL},
4596 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4597 0, dnValidate, dnNormalize, dnPretty},
4598 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4599 0, NULL, NULL, NULL},
4600 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4601 0, NULL, NULL, NULL},
4602 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4603 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4604 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4605 0, NULL, NULL, NULL},
4606 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4607 0, NULL, NULL, NULL},
4608 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4609 0, NULL, NULL, NULL},
4610 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4611 0, NULL, NULL, NULL},
4612 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4613 0, NULL, NULL, NULL},
4614 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4615 0, printablesStringValidate, IA5StringNormalize, NULL},
4616 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4617 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4618 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4619 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4620 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4621 0, NULL, NULL, NULL},
4622 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4623 0, IA5StringValidate, IA5StringNormalize, NULL},
4624 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4625 0, integerValidate, integerNormalize, NULL},
4626 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4627 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4628 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4629 0, NULL, NULL, NULL},
4630 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4631 0, NULL, NULL, NULL},
4632 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4633 0, NULL, NULL, NULL},
4634 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4635 0, NULL, NULL, NULL},
4636 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4637 0, NULL, NULL, NULL},
4638 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4639 0, nameUIDValidate, nameUIDNormalize, NULL},
4640 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4641 0, NULL, NULL, NULL},
4642 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4643 0, numericStringValidate, numericStringNormalize, NULL},
4644 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4645 0, NULL, NULL, NULL},
4646 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4647 0, oidValidate, NULL, NULL},
4648 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4649 0, IA5StringValidate, IA5StringNormalize, NULL},
4650 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4651 0, blobValidate, NULL, NULL},
4652 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4653 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4654 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4655 0, NULL, NULL, NULL},
4656 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4657 0, NULL, NULL, NULL},
4658 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4659 0, printableStringValidate, IA5StringNormalize, NULL},
4660 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4661 X_BINARY X_NOT_H_R ")",
4662 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4663 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4664 0, printableStringValidate, IA5StringNormalize, NULL},
4665 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4666 0, NULL, NULL, NULL},
4667 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4668 0, printablesStringValidate, IA5StringNormalize, NULL},
4669 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4670 0, utcTimeValidate, utcTimeNormalize, NULL},
4671 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4672 0, NULL, NULL, NULL},
4673 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4674 0, NULL, NULL, NULL},
4675 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4676 0, NULL, NULL, NULL},
4677 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4678 0, NULL, NULL, NULL},
4679 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4680 0, NULL, NULL, NULL},
4682 /* RFC 2307 NIS Syntaxes */
4683 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4684 0, nisNetgroupTripleValidate, NULL, NULL},
4685 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4686 0, bootParameterValidate, NULL, NULL},
4690 /* These OIDs are not published yet, but will be in the next
4691 * I-D for PKIX LDAPv3 schema as have been advanced by David
4692 * Chadwick in private mail.
4694 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4695 0, NULL, NULL, NULL},
4698 /* OpenLDAP Experimental Syntaxes */
4699 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4701 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4704 /* needs updating */
4705 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4706 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4708 /* OpenLDAP Void Syntax */
4709 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4710 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4711 {NULL, 0, NULL, NULL, NULL}
4714 struct mrule_defs_rec {
4716 slap_mask_t mrd_usage;
4717 slap_mr_convert_func * mrd_convert;
4718 slap_mr_normalize_func * mrd_normalize;
4719 slap_mr_match_func * mrd_match;
4720 slap_mr_indexer_func * mrd_indexer;
4721 slap_mr_filter_func * mrd_filter;
4723 char * mrd_associated;
4727 * Other matching rules in X.520 that we do not use (yet):
4729 * 2.5.13.9 numericStringOrderingMatch
4730 * 2.5.13.15 integerOrderingMatch
4731 * 2.5.13.18 octetStringOrderingMatch
4732 * 2.5.13.19 octetStringSubstringsMatch
4733 * 2.5.13.25 uTCTimeMatch
4734 * 2.5.13.26 uTCTimeOrderingMatch
4735 * 2.5.13.31 directoryStringFirstComponentMatch
4736 * 2.5.13.32 wordMatch
4737 * 2.5.13.33 keywordMatch
4738 * 2.5.13.35 certificateMatch
4739 * 2.5.13.36 certificatePairExactMatch
4740 * 2.5.13.37 certificatePairMatch
4741 * 2.5.13.38 certificateListExactMatch
4742 * 2.5.13.39 certificateListMatch
4743 * 2.5.13.40 algorithmIdentifierMatch
4744 * 2.5.13.41 storedPrefixMatch
4745 * 2.5.13.42 attributeCertificateMatch
4746 * 2.5.13.43 readerAndKeyIDMatch
4747 * 2.5.13.44 attributeIntegrityMatch
4750 struct mrule_defs_rec mrule_defs[] = {
4752 * EQUALITY matching rules must be listed after associated APPROX
4753 * matching rules. So, we list all APPROX matching rules first.
4755 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4756 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4757 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4759 directoryStringApproxMatch,
4760 directoryStringApproxIndexer,
4761 directoryStringApproxFilter,
4764 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4765 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4766 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4768 IA5StringApproxMatch,
4769 IA5StringApproxIndexer,
4770 IA5StringApproxFilter,
4774 * Other matching rules
4777 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4778 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4779 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4781 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4784 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4785 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4786 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4788 dnMatch, dnIndexer, dnFilter,
4791 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4792 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4793 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4795 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4796 directoryStringApproxMatchOID },
4798 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4799 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4802 caseIgnoreOrderingMatch, NULL, NULL,
4805 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4806 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4807 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4809 caseExactIgnoreSubstringsMatch,
4810 caseExactIgnoreSubstringsIndexer,
4811 caseExactIgnoreSubstringsFilter,
4814 {"( 2.5.13.5 NAME 'caseExactMatch' "
4815 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4816 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4818 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4819 directoryStringApproxMatchOID },
4821 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4822 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4825 caseExactOrderingMatch, NULL, NULL,
4828 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4829 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4830 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4832 caseExactIgnoreSubstringsMatch,
4833 caseExactIgnoreSubstringsIndexer,
4834 caseExactIgnoreSubstringsFilter,
4837 {"( 2.5.13.8 NAME 'numericStringMatch' "
4838 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4839 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4842 caseIgnoreIA5Indexer,
4843 caseIgnoreIA5Filter,
4846 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4847 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4848 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4850 caseIgnoreIA5SubstringsMatch,
4851 caseIgnoreIA5SubstringsIndexer,
4852 caseIgnoreIA5SubstringsFilter,
4855 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4856 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4857 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4859 caseIgnoreListMatch, NULL, NULL,
4862 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4863 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4864 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4866 caseIgnoreListSubstringsMatch, NULL, NULL,
4869 {"( 2.5.13.13 NAME 'booleanMatch' "
4870 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4871 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4873 booleanMatch, NULL, NULL,
4876 {"( 2.5.13.14 NAME 'integerMatch' "
4877 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4878 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4880 integerMatch, integerIndexer, integerFilter,
4883 {"( 2.5.13.16 NAME 'bitStringMatch' "
4884 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4885 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4887 bitStringMatch, bitStringIndexer, bitStringFilter,
4890 {"( 2.5.13.17 NAME 'octetStringMatch' "
4891 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4892 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4894 octetStringMatch, octetStringIndexer, octetStringFilter,
4897 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4898 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4899 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4901 telephoneNumberMatch,
4902 telephoneNumberIndexer,
4903 telephoneNumberFilter,
4906 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4907 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4908 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4910 telephoneNumberSubstringsMatch,
4911 telephoneNumberSubstringsIndexer,
4912 telephoneNumberSubstringsFilter,
4915 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4916 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4917 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4922 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4923 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4924 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4926 uniqueMemberMatch, NULL, NULL,
4929 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4930 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4931 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4933 protocolInformationMatch, NULL, NULL,
4936 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4937 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4938 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4940 generalizedTimeMatch, NULL, NULL,
4943 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4944 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4947 generalizedTimeOrderingMatch, NULL, NULL,
4950 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4951 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4952 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4954 integerFirstComponentMatch, NULL, NULL,
4957 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4958 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4959 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4961 objectIdentifierFirstComponentMatch, NULL, NULL,
4965 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4966 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4967 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4968 certificateExactConvert, NULL,
4969 certificateExactMatch,
4970 certificateExactIndexer, certificateExactFilter,
4974 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4975 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4976 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4978 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4979 IA5StringApproxMatchOID },
4981 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4982 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4983 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4985 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4986 IA5StringApproxMatchOID },
4988 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4989 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4992 caseIgnoreIA5SubstringsMatch,
4993 caseIgnoreIA5SubstringsIndexer,
4994 caseIgnoreIA5SubstringsFilter,
4997 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4998 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5001 caseExactIA5SubstringsMatch,
5002 caseExactIA5SubstringsIndexer,
5003 caseExactIA5SubstringsFilter,
5006 /* needs updating */
5007 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
5008 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
5011 authPasswordMatch, NULL, NULL,
5014 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
5015 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
5018 OpenLDAPaciMatch, NULL, NULL,
5021 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
5022 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5025 integerBitAndMatch, NULL, NULL,
5028 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
5029 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5032 integerBitOrMatch, NULL, NULL,
5035 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
5044 /* we should only be called once (from main) */
5045 assert( schema_init_done == 0 );
5047 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
5048 res = register_syntax( syntax_defs[i].sd_desc,
5049 syntax_defs[i].sd_flags,
5050 syntax_defs[i].sd_validate,
5051 syntax_defs[i].sd_normalize,
5052 syntax_defs[i].sd_pretty
5053 #ifdef SLAPD_BINARY_CONVERSION
5055 syntax_defs[i].sd_ber2str,
5056 syntax_defs[i].sd_str2ber
5061 fprintf( stderr, "schema_init: Error registering syntax %s\n",
5062 syntax_defs[i].sd_desc );
5067 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
5068 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
5070 "schema_init: Ingoring unusable matching rule %s\n",
5071 mrule_defs[i].mrd_desc );
5075 res = register_matching_rule(
5076 mrule_defs[i].mrd_desc,
5077 mrule_defs[i].mrd_usage,
5078 mrule_defs[i].mrd_convert,
5079 mrule_defs[i].mrd_normalize,
5080 mrule_defs[i].mrd_match,
5081 mrule_defs[i].mrd_indexer,
5082 mrule_defs[i].mrd_filter,
5083 mrule_defs[i].mrd_associated );
5087 "schema_init: Error registering matching rule %s\n",
5088 mrule_defs[i].mrd_desc );
5092 schema_init_done = 1;
5093 return LDAP_SUCCESS;
5097 schema_destroy( void )