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_LDAPV3 );
239 ldapava_free_dn( dn );
241 if ( rc != LDAP_SUCCESS ) {
242 return( LDAP_INVALID_SYNTAX );
245 return( LDAP_SUCCESS );
249 AVA_Sort( LDAPRDN *rdn, int iAVA )
252 LDAPAVA *ava_in = rdn[ iAVA ][ 0 ];
254 for ( i = 0; i < iAVA; i++ ) {
255 LDAPAVA *ava = rdn[ i ][ 0 ];
258 a = strcmp( ava_in->la_attr->bv_val, ava->la_attr->bv_val );
267 d = ava_in->la_value->bv_len - ava->la_value->bv_len;
269 v = memcmp( ava_in->la_value->bv_val,
270 ava->la_value->bv_val,
271 d <= 0 ? ava_in->la_value->bv_len
272 : ava->la_value->bv_len );
274 if ( v == 0 && d != 0 ) {
293 a = strcmp( ava_in->la_value->bv_val,
294 ava->la_value->bv_val );
300 for ( j = iAVA; j > i; j-- ) {
301 rdn[ j ][ 0 ] = rdn[ j - 1 ][ 0 ];
303 rdn[ i ][ 0 ] = ava_in;
310 * In-place, schema-aware normalization / "pretty"ing of the
311 * structural representation of a distinguished name.
314 LDAPDN_rewrite( LDAPDN *dn, unsigned flags )
321 for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
322 LDAPRDN *rdn = dn[ iRDN ][ 0 ];
325 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
326 LDAPAVA *ava = rdn[ iAVA ][ 0 ];
327 AttributeDescription *ad = NULL;
328 const char *text = NULL;
329 slap_syntax_transform_func *transf = NULL;
331 struct berval *bv = NULL;
333 rc = slap_bv2ad( ava->la_attr, &ad, &text );
334 if ( rc != LDAP_SUCCESS ) {
335 return LDAP_INVALID_SYNTAX;
339 * Replace attr oid/name with the canonical name
341 ber_bvfree( ava->la_attr );
342 ava->la_attr = ber_bvdup( &ad->ad_cname );
344 if( flags & SLAP_LDAPDN_PRETTY ) {
345 transf = ad->ad_type->sat_syntax->ssyn_pretty;
348 transf = ad->ad_type->sat_syntax->ssyn_normalize;
349 mr = ad->ad_type->sat_equality;
354 * transform value by normalize/pretty function
356 rc = ( *transf )( ad->ad_type->sat_syntax,
357 ava->la_value, &bv );
359 if ( rc != LDAP_SUCCESS ) {
360 return LDAP_INVALID_SYNTAX;
364 if( mr && ( mr->smr_usage & SLAP_MR_DN_FOLD ) ) {
365 struct berval *s = bv;
367 bv = ber_bvstr( UTF8normalize( bv ? bv : ava->la_value,
374 ber_bvfree( ava->la_value );
378 AVA_Sort( rdn, iAVA );
389 struct berval **normalized )
391 struct berval *out = NULL;
393 Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: <%s>\n", val->bv_val, 0, 0 );
395 if ( val->bv_len != 0 ) {
401 * Go to structural representation
403 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAPV3 );
404 if ( rc != LDAP_SUCCESS ) {
405 return LDAP_INVALID_SYNTAX;
409 * Schema-aware rewrite
411 if ( LDAPDN_rewrite( dn, 0 ) != LDAP_SUCCESS ) {
412 ldapava_free_dn( dn );
413 return LDAP_INVALID_SYNTAX;
417 * Back to string representation
419 rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
421 ldapava_free_dn( dn );
423 if ( rc != LDAP_SUCCESS ) {
424 return LDAP_INVALID_SYNTAX;
427 out = ber_bvstr( dn_out );
430 out = ber_bvdup( val );
433 Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: <%s>\n", out->bv_val, 0, 0 );
444 struct berval **pretty)
446 struct berval *out = NULL;
448 Debug( LDAP_DEBUG_TRACE, ">>> dnPretty: <%s>\n", val->bv_val, 0, 0 );
450 if ( val->bv_len != 0 ) {
455 /* FIXME: should be liberal in what we accept */
456 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAPV3 );
457 if ( rc != LDAP_SUCCESS ) {
458 return LDAP_INVALID_SYNTAX;
462 * Schema-aware rewrite
464 if ( LDAPDN_rewrite( dn, SLAP_LDAPDN_PRETTY ) != LDAP_SUCCESS ) {
465 ldapava_free_dn( dn );
466 return LDAP_INVALID_SYNTAX;
469 /* FIXME: not sure why the default isn't pretty */
470 rc = ldap_dn2str( dn, &dn_out,
471 LDAP_DN_FORMAT_LDAPV3 | LDAP_DN_PRETTY );
473 ldapava_free_dn( dn );
475 if ( rc != LDAP_SUCCESS ) {
476 return LDAP_INVALID_SYNTAX;
479 out = ber_bvstr( dn_out );
482 out = ber_bvdup( val );
485 Debug( LDAP_DEBUG_TRACE, "<<< dnPretty: <%s>\n", out->bv_val, 0, 0 );
498 struct berval *value,
499 void *assertedValue )
502 struct berval *asserted = (struct berval *) assertedValue;
504 match = value->bv_len - asserted->bv_len;
507 #ifdef USE_DN_NORMALIZE
508 match = strcmp( value->bv_val, asserted->bv_val );
509 fprintf(stderr, "USE_DN_NORMALIZE :(\n");
511 match = strcasecmp( value->bv_val, asserted->bv_val );
512 fprintf(stderr, "!USE_DN_NORMALIZE :)\n");
517 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
518 "dnMatch: %d\n %s\n %s\n", match,
519 value->bv_val, asserted->bv_val ));
521 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
522 match, value->bv_val, asserted->bv_val );
526 return( LDAP_SUCCESS );
529 #else /* !USE_LDAP_DN_PARSING */
539 if( in->bv_len == 0 ) return LDAP_SUCCESS;
541 dn = ch_strdup( in->bv_val );
544 return LDAP_INVALID_SYNTAX;
546 } else if ( strlen( in->bv_val ) != in->bv_len ) {
547 rc = LDAP_INVALID_SYNTAX;
549 } else if ( dn_validate( dn ) == NULL ) {
550 rc = LDAP_INVALID_SYNTAX;
564 struct berval **normalized )
568 if ( val->bv_len != 0 ) {
570 out = ber_bvstr( UTF8normalize( val, UTF8_CASEFOLD ) );
572 dn = dn_validate( out->bv_val );
576 return LDAP_INVALID_SYNTAX;
580 out->bv_len = strlen( dn );
582 out = ber_bvdup( val );
595 struct berval *value,
596 void *assertedValue )
599 struct berval *asserted = (struct berval *) assertedValue;
601 match = value->bv_len - asserted->bv_len;
604 #ifdef USE_DN_NORMALIZE
605 match = strcmp( value->bv_val, asserted->bv_val );
607 match = strcasecmp( value->bv_val, asserted->bv_val );
612 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
613 "dnMatch: %d\n %s\n %s\n", match,
614 value->bv_val, asserted->bv_val ));
616 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
617 match, value->bv_val, asserted->bv_val );
625 #endif /* !USE_LDAP_DN_PARSING */
635 if( in->bv_len == 0 ) return LDAP_SUCCESS;
637 dn = ber_bvdup( in );
639 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
640 /* assume presence of optional UID */
643 for(i=dn->bv_len-2; i>2; i--) {
644 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
648 if( dn->bv_val[i] != '\'' ||
649 dn->bv_val[i-1] != 'B' ||
650 dn->bv_val[i-2] != '#' ) {
652 return LDAP_INVALID_SYNTAX;
655 /* trim the UID to allow use of dn_validate */
656 dn->bv_val[i-2] = '\0';
659 rc = dn_validate( dn->bv_val ) == NULL
660 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
670 struct berval **normalized )
672 struct berval *out = ber_bvdup( val );
674 if( out->bv_len != 0 ) {
678 ber_len_t uidlen = 0;
680 if( out->bv_val[out->bv_len-1] == '\'' ) {
681 /* assume presence of optional UID */
682 uid = strrchr( out->bv_val, '#' );
686 return LDAP_INVALID_SYNTAX;
689 uidlen = out->bv_len - (out->bv_val - uid);
690 /* temporarily trim the UID */
694 #ifdef USE_DN_NORMALIZE
695 dn = dn_normalize( out->bv_val );
697 dn = dn_validate( out->bv_val );
702 return LDAP_INVALID_SYNTAX;
708 /* restore the separator */
711 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
715 out->bv_len = dnlen + uidlen;
727 /* any value allowed */
736 /* any value allowed */
747 /* very unforgiving validation, requires no normalization
748 * before simplistic matching
750 if( in->bv_len < 3 ) {
751 return LDAP_INVALID_SYNTAX;
755 * rfc 2252 section 6.3 Bit String
756 * bitstring = "'" *binary-digit "'"
757 * binary-digit = "0" / "1"
758 * example: '0101111101'B
761 if( in->bv_val[0] != '\'' ||
762 in->bv_val[in->bv_len-2] != '\'' ||
763 in->bv_val[in->bv_len-1] != 'B' )
765 return LDAP_INVALID_SYNTAX;
768 for( i=in->bv_len-3; i>0; i-- ) {
769 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
770 return LDAP_INVALID_SYNTAX;
781 struct berval **normalized )
784 * A normalized bitString is has no extaneous (leading) zero bits.
785 * That is, '00010'B is normalized to '10'B
786 * However, as a special case, '0'B requires no normalization.
788 struct berval *newval;
791 /* start at the first bit */
794 /* Find the first non-zero bit */
795 while ( *p == '0' ) p++;
797 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
800 /* no non-zero bits */
801 newval->bv_val = ch_strdup("\'0\'B");
802 newval->bv_len = sizeof("\'0\'B") - 1;
806 newval->bv_val = ch_malloc( val->bv_len + 1 );
808 newval->bv_val[0] = '\'';
811 for( ; *p != '\0'; p++ ) {
812 newval->bv_val[newval->bv_len++] = *p;
815 newval->bv_val[newval->bv_len] = '\0';
818 *normalized = newval;
823 * Handling boolean syntax and matching is quite rigid.
824 * A more flexible approach would be to allow a variety
825 * of strings to be normalized and prettied into TRUE
833 /* very unforgiving validation, requires no normalization
834 * before simplistic matching
837 if( in->bv_len == 4 ) {
838 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
841 } else if( in->bv_len == 5 ) {
842 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
847 return LDAP_INVALID_SYNTAX;
856 struct berval *value,
857 void *assertedValue )
859 /* simplistic matching allowed by rigid validation */
860 struct berval *asserted = (struct berval *) assertedValue;
861 *matchp = value->bv_len != asserted->bv_len;
872 unsigned char *u = in->bv_val;
874 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
876 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
877 /* get the length indicated by the first byte */
878 len = LDAP_UTF8_CHARLEN( u );
880 /* should not be zero */
881 if( len == 0 ) return LDAP_INVALID_SYNTAX;
883 /* make sure len corresponds with the offset
884 to the next character */
885 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
888 if( count != 0 ) return LDAP_INVALID_SYNTAX;
897 struct berval **normalized )
899 struct berval *newval;
902 newval = ch_malloc( sizeof( struct berval ) );
906 /* Ignore initial whitespace */
907 while ( ldap_utf8_isspace( p ) ) {
913 return LDAP_INVALID_SYNTAX;
916 newval->bv_val = ch_strdup( p );
917 p = q = newval->bv_val;
923 if ( ldap_utf8_isspace( p ) ) {
924 len = LDAP_UTF8_COPY(q,p);
929 /* Ignore the extra whitespace */
930 while ( ldap_utf8_isspace( p ) ) {
934 len = LDAP_UTF8_COPY(q,p);
941 assert( *newval->bv_val );
942 assert( newval->bv_val < p );
945 /* cannot start with a space */
946 assert( !ldap_utf8_isspace(newval->bv_val) );
949 * If the string ended in space, backup the pointer one
950 * position. One is enough because the above loop collapsed
951 * all whitespace to a single space.
958 /* cannot end with a space */
959 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
964 newval->bv_len = q - newval->bv_val;
965 *normalized = newval;
970 /* Returns Unicode cannonically normalized copy of a substring assertion
971 * Skipping attribute description */
972 SubstringsAssertion *
973 UTF8SubstringsassertionNormalize(
974 SubstringsAssertion *sa,
977 SubstringsAssertion *nsa;
980 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
985 if( sa->sa_initial != NULL ) {
986 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
987 if( nsa->sa_initial == NULL ) {
992 if( sa->sa_any != NULL ) {
993 for( i=0; sa->sa_any[i] != NULL; i++ ) {
996 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
997 for( i=0; sa->sa_any[i] != NULL; i++ ) {
998 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
999 if( nsa->sa_any[i] == NULL ) {
1003 nsa->sa_any[i] = NULL;
1006 if( sa->sa_final != NULL ) {
1007 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
1008 if( nsa->sa_final == NULL ) {
1016 ber_bvfree( nsa->sa_final );
1017 ber_bvecfree( nsa->sa_any );
1018 ber_bvfree( nsa->sa_initial );
1023 /* Strip characters with the 8th bit set */
1036 while( *++q & 0x80 ) {
1039 p = memmove(p, q, strlen(q) + 1);
1047 #ifndef SLAPD_APPROX_OLDSINGLESTRING
1049 #if defined(SLAPD_APPROX_INITIALS)
1050 #define SLAPD_APPROX_DELIMITER "._ "
1051 #define SLAPD_APPROX_WORDLEN 2
1053 #define SLAPD_APPROX_DELIMITER " "
1054 #define SLAPD_APPROX_WORDLEN 1
1063 struct berval *value,
1064 void *assertedValue )
1066 char *val, *nval, *assertv, **values, **words, *c;
1067 int i, count, len, nextchunk=0, nextavail=0;
1070 /* Yes, this is necessary */
1071 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
1072 if( nval == NULL ) {
1074 return LDAP_SUCCESS;
1076 strip8bitChars( nval );
1078 /* Yes, this is necessary */
1079 assertv = UTF8normalize( ((struct berval *)assertedValue),
1081 if( assertv == NULL ) {
1084 return LDAP_SUCCESS;
1086 strip8bitChars( assertv );
1087 avlen = strlen( assertv );
1089 /* Isolate how many words there are */
1090 for( c=nval,count=1; *c; c++ ) {
1091 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
1092 if ( c == NULL ) break;
1097 /* Get a phonetic copy of each word */
1098 words = (char **)ch_malloc( count * sizeof(char *) );
1099 values = (char **)ch_malloc( count * sizeof(char *) );
1100 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
1102 values[i] = phonetic(c);
1105 /* Work through the asserted value's words, to see if at least some
1106 of the words are there, in the same order. */
1108 while ( nextchunk < avlen ) {
1109 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
1114 #if defined(SLAPD_APPROX_INITIALS)
1115 else if( len == 1 ) {
1116 /* Single letter words need to at least match one word's initial */
1117 for( i=nextavail; i<count; i++ )
1118 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
1125 /* Isolate the next word in the asserted value and phonetic it */
1126 assertv[nextchunk+len] = '\0';
1127 val = phonetic( assertv + nextchunk );
1129 /* See if this phonetic chunk is in the remaining words of *value */
1130 for( i=nextavail; i<count; i++ ){
1131 if( !strcmp( val, values[i] ) ){
1139 /* This chunk in the asserted value was NOT within the *value. */
1145 /* Go on to the next word in the asserted value */
1149 /* If some of the words were seen, call it a match */
1150 if( nextavail > 0 ) {
1157 /* Cleanup allocs */
1159 for( i=0; i<count; i++ ) {
1160 ch_free( values[i] );
1166 return LDAP_SUCCESS;
1175 struct berval *prefix,
1176 struct berval **values,
1177 struct berval ***keysp )
1180 int i,j, len, wordcount, keycount=0;
1181 struct berval **newkeys, **keys=NULL;
1183 for( j=0; values[j] != NULL; j++ ) {
1184 /* Yes, this is necessary */
1185 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
1186 strip8bitChars( val );
1188 /* Isolate how many words there are. There will be a key for each */
1189 for( wordcount=0,c=val; *c; c++) {
1190 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1191 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
1193 if (*c == '\0') break;
1197 /* Allocate/increase storage to account for new keys */
1198 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
1199 * sizeof(struct berval *) );
1200 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
1201 if( keys ) ch_free( keys );
1204 /* Get a phonetic copy of each word */
1205 for( c=val,i=0; i<wordcount; c+=len+1 ) {
1207 if( len < SLAPD_APPROX_WORDLEN ) continue;
1208 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
1209 keys[keycount]->bv_val = phonetic( c );
1210 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
1217 keys[keycount] = NULL;
1220 return LDAP_SUCCESS;
1229 struct berval *prefix,
1231 struct berval ***keysp )
1235 struct berval **keys;
1237 /* Yes, this is necessary */
1238 val = UTF8normalize( ((struct berval *)assertValue),
1241 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
1244 return LDAP_SUCCESS;
1246 strip8bitChars( val );
1248 /* Isolate how many words there are. There will be a key for each */
1249 for( count=0,c=val; *c; c++) {
1250 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1251 if( len >= SLAPD_APPROX_WORDLEN ) count++;
1253 if (*c == '\0') break;
1257 /* Allocate storage for new keys */
1258 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
1260 /* Get a phonetic copy of each word */
1261 for( c=val,i=0; i<count; c+=len+1 ) {
1263 if( len < SLAPD_APPROX_WORDLEN ) continue;
1264 keys[i] = ber_bvstr( phonetic( c ) );
1273 return LDAP_SUCCESS;
1278 /* No other form of Approximate Matching is defined */
1286 struct berval *value,
1287 void *assertedValue )
1289 char *vapprox, *avapprox;
1292 /* Yes, this is necessary */
1293 s = UTF8normalize( value, UTF8_NOCASEFOLD );
1296 return LDAP_SUCCESS;
1299 /* Yes, this is necessary */
1300 t = UTF8normalize( ((struct berval *)assertedValue),
1305 return LDAP_SUCCESS;
1308 vapprox = phonetic( strip8bitChars( s ) );
1309 avapprox = phonetic( strip8bitChars( t ) );
1314 *matchp = strcmp( vapprox, avapprox );
1317 ch_free( avapprox );
1319 return LDAP_SUCCESS;
1328 struct berval *prefix,
1329 struct berval **values,
1330 struct berval ***keysp )
1333 struct berval **keys;
1336 for( i=0; values[i] != NULL; i++ ) {
1337 /* empty - just count them */
1340 /* we should have at least one value at this point */
1343 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
1345 /* Copy each value and run it through phonetic() */
1346 for( i=0; values[i] != NULL; i++ ) {
1347 /* Yes, this is necessary */
1348 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
1350 /* strip 8-bit chars and run through phonetic() */
1351 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1357 return LDAP_SUCCESS;
1367 struct berval *prefix,
1369 struct berval ***keysp )
1371 struct berval **keys;
1374 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1376 /* Yes, this is necessary */
1377 s = UTF8normalize( ((struct berval *)assertValue),
1382 /* strip 8-bit chars and run through phonetic() */
1383 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1389 return LDAP_SUCCESS;
1400 struct berval *value,
1401 void *assertedValue )
1403 *matchp = UTF8normcmp( value->bv_val,
1404 ((struct berval *) assertedValue)->bv_val,
1406 return LDAP_SUCCESS;
1410 caseExactIgnoreSubstringsMatch(
1415 struct berval *value,
1416 void *assertedValue )
1419 SubstringsAssertion *sub = NULL;
1423 char *nav, casefold;
1425 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1426 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1428 nav = UTF8normalize( value, casefold );
1434 left.bv_len = strlen( nav );
1436 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1442 /* Add up asserted input length */
1443 if( sub->sa_initial ) {
1444 inlen += sub->sa_initial->bv_len;
1447 for(i=0; sub->sa_any[i] != NULL; i++) {
1448 inlen += sub->sa_any[i]->bv_len;
1451 if( sub->sa_final ) {
1452 inlen += sub->sa_final->bv_len;
1455 if( sub->sa_initial ) {
1456 if( inlen > left.bv_len ) {
1461 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1462 sub->sa_initial->bv_len );
1468 left.bv_val += sub->sa_initial->bv_len;
1469 left.bv_len -= sub->sa_initial->bv_len;
1470 inlen -= sub->sa_initial->bv_len;
1473 if( sub->sa_final ) {
1474 if( inlen > left.bv_len ) {
1479 match = strncmp( sub->sa_final->bv_val,
1480 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1481 sub->sa_final->bv_len );
1487 left.bv_len -= sub->sa_final->bv_len;
1488 inlen -= sub->sa_final->bv_len;
1492 for(i=0; sub->sa_any[i]; i++) {
1497 if( inlen > left.bv_len ) {
1498 /* not enough length */
1503 if( sub->sa_any[i]->bv_len == 0 ) {
1507 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1514 idx = p - left.bv_val;
1515 assert( idx < left.bv_len );
1517 if( idx >= left.bv_len ) {
1518 /* this shouldn't happen */
1520 ch_free( sub->sa_final );
1521 ber_bvecfree( sub->sa_any );
1522 ch_free( sub->sa_initial );
1530 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1531 /* not enough left */
1536 match = strncmp( left.bv_val,
1537 sub->sa_any[i]->bv_val,
1538 sub->sa_any[i]->bv_len );
1546 left.bv_val += sub->sa_any[i]->bv_len;
1547 left.bv_len -= sub->sa_any[i]->bv_len;
1548 inlen -= sub->sa_any[i]->bv_len;
1555 ber_bvfree( sub->sa_final );
1556 ber_bvecfree( sub->sa_any );
1557 ber_bvfree( sub->sa_initial );
1561 return LDAP_SUCCESS;
1564 /* Index generation function */
1565 int caseExactIgnoreIndexer(
1570 struct berval *prefix,
1571 struct berval **values,
1572 struct berval ***keysp )
1577 struct berval **keys;
1578 HASH_CONTEXT HASHcontext;
1579 unsigned char HASHdigest[HASH_BYTES];
1580 struct berval digest;
1581 digest.bv_val = HASHdigest;
1582 digest.bv_len = sizeof(HASHdigest);
1584 for( i=0; values[i] != NULL; i++ ) {
1585 /* empty - just count them */
1588 /* we should have at least one value at this point */
1591 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1593 slen = strlen( syntax->ssyn_oid );
1594 mlen = strlen( mr->smr_oid );
1596 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1597 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1599 for( i=0; values[i] != NULL; i++ ) {
1600 struct berval *value;
1601 value = ber_bvstr( UTF8normalize( values[i],
1604 HASH_Init( &HASHcontext );
1605 if( prefix != NULL && prefix->bv_len > 0 ) {
1606 HASH_Update( &HASHcontext,
1607 prefix->bv_val, prefix->bv_len );
1609 HASH_Update( &HASHcontext,
1610 syntax->ssyn_oid, slen );
1611 HASH_Update( &HASHcontext,
1612 mr->smr_oid, mlen );
1613 HASH_Update( &HASHcontext,
1614 value->bv_val, value->bv_len );
1615 HASH_Final( HASHdigest, &HASHcontext );
1617 ber_bvfree( value );
1619 keys[i] = ber_bvdup( &digest );
1624 return LDAP_SUCCESS;
1627 /* Index generation function */
1628 int caseExactIgnoreFilter(
1633 struct berval *prefix,
1635 struct berval ***keysp )
1639 struct berval **keys;
1640 HASH_CONTEXT HASHcontext;
1641 unsigned char HASHdigest[HASH_BYTES];
1642 struct berval *value;
1643 struct berval digest;
1644 digest.bv_val = HASHdigest;
1645 digest.bv_len = sizeof(HASHdigest);
1647 slen = strlen( syntax->ssyn_oid );
1648 mlen = strlen( mr->smr_oid );
1650 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1651 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1653 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
1655 /* This usually happens if filter contains bad UTF8 */
1656 if( value == NULL ) {
1657 keys = ch_malloc( sizeof( struct berval * ) );
1659 return LDAP_SUCCESS;
1662 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1664 HASH_Init( &HASHcontext );
1665 if( prefix != NULL && prefix->bv_len > 0 ) {
1666 HASH_Update( &HASHcontext,
1667 prefix->bv_val, prefix->bv_len );
1669 HASH_Update( &HASHcontext,
1670 syntax->ssyn_oid, slen );
1671 HASH_Update( &HASHcontext,
1672 mr->smr_oid, mlen );
1673 HASH_Update( &HASHcontext,
1674 value->bv_val, value->bv_len );
1675 HASH_Final( HASHdigest, &HASHcontext );
1677 keys[0] = ber_bvdup( &digest );
1680 ber_bvfree( value );
1683 return LDAP_SUCCESS;
1686 /* Substrings Index generation function */
1687 int caseExactIgnoreSubstringsIndexer(
1692 struct berval *prefix,
1693 struct berval **values,
1694 struct berval ***keysp )
1699 struct berval **keys;
1700 struct berval **nvalues;
1702 HASH_CONTEXT HASHcontext;
1703 unsigned char HASHdigest[HASH_BYTES];
1704 struct berval digest;
1705 digest.bv_val = HASHdigest;
1706 digest.bv_len = sizeof(HASHdigest);
1710 for( i=0; values[i] != NULL; i++ ) {
1711 /* empty - just count them */
1714 /* we should have at least one value at this point */
1717 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1718 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1720 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1721 for( i=0; values[i] != NULL; i++ ) {
1722 nvalues[i] = ber_bvstr( UTF8normalize( values[i],
1728 for( i=0; values[i] != NULL; i++ ) {
1729 /* count number of indices to generate */
1730 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1734 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1735 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1736 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1737 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1739 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1743 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1744 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1745 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1749 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1750 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1751 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1752 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1754 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1760 /* no keys to generate */
1762 ber_bvecfree( nvalues );
1763 return LDAP_SUCCESS;
1766 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1768 slen = strlen( syntax->ssyn_oid );
1769 mlen = strlen( mr->smr_oid );
1772 for( i=0; values[i] != NULL; i++ ) {
1774 struct berval *value;
1776 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1780 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1781 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1783 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1784 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1786 for( j=0; j<max; j++ ) {
1787 HASH_Init( &HASHcontext );
1788 if( prefix != NULL && prefix->bv_len > 0 ) {
1789 HASH_Update( &HASHcontext,
1790 prefix->bv_val, prefix->bv_len );
1793 HASH_Update( &HASHcontext,
1794 &pre, sizeof( pre ) );
1795 HASH_Update( &HASHcontext,
1796 syntax->ssyn_oid, slen );
1797 HASH_Update( &HASHcontext,
1798 mr->smr_oid, mlen );
1799 HASH_Update( &HASHcontext,
1801 SLAP_INDEX_SUBSTR_MAXLEN );
1802 HASH_Final( HASHdigest, &HASHcontext );
1804 keys[nkeys++] = ber_bvdup( &digest );
1808 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1809 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1811 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1814 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1815 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1816 HASH_Init( &HASHcontext );
1817 if( prefix != NULL && prefix->bv_len > 0 ) {
1818 HASH_Update( &HASHcontext,
1819 prefix->bv_val, prefix->bv_len );
1821 HASH_Update( &HASHcontext,
1822 &pre, sizeof( pre ) );
1823 HASH_Update( &HASHcontext,
1824 syntax->ssyn_oid, slen );
1825 HASH_Update( &HASHcontext,
1826 mr->smr_oid, mlen );
1827 HASH_Update( &HASHcontext,
1829 HASH_Final( HASHdigest, &HASHcontext );
1831 keys[nkeys++] = ber_bvdup( &digest );
1834 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1835 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1836 HASH_Init( &HASHcontext );
1837 if( prefix != NULL && prefix->bv_len > 0 ) {
1838 HASH_Update( &HASHcontext,
1839 prefix->bv_val, prefix->bv_len );
1841 HASH_Update( &HASHcontext,
1842 &pre, sizeof( pre ) );
1843 HASH_Update( &HASHcontext,
1844 syntax->ssyn_oid, slen );
1845 HASH_Update( &HASHcontext,
1846 mr->smr_oid, mlen );
1847 HASH_Update( &HASHcontext,
1848 &value->bv_val[value->bv_len-j], j );
1849 HASH_Final( HASHdigest, &HASHcontext );
1851 keys[nkeys++] = ber_bvdup( &digest );
1866 ber_bvecfree( nvalues );
1868 return LDAP_SUCCESS;
1871 int caseExactIgnoreSubstringsFilter(
1876 struct berval *prefix,
1878 struct berval ***keysp )
1880 SubstringsAssertion *sa;
1882 ber_len_t nkeys = 0;
1883 size_t slen, mlen, klen;
1884 struct berval **keys;
1885 HASH_CONTEXT HASHcontext;
1886 unsigned char HASHdigest[HASH_BYTES];
1887 struct berval *value;
1888 struct berval digest;
1890 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1891 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1893 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1896 return LDAP_SUCCESS;
1899 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1900 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1905 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1907 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1908 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1909 /* don't bother accounting for stepping */
1910 nkeys += sa->sa_any[i]->bv_len -
1911 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1916 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1917 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1923 ber_bvfree( sa->sa_final );
1924 ber_bvecfree( sa->sa_any );
1925 ber_bvfree( sa->sa_initial );
1928 return LDAP_SUCCESS;
1931 digest.bv_val = HASHdigest;
1932 digest.bv_len = sizeof(HASHdigest);
1934 slen = strlen( syntax->ssyn_oid );
1935 mlen = strlen( mr->smr_oid );
1937 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1940 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1941 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1943 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1944 value = sa->sa_initial;
1946 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1947 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1949 HASH_Init( &HASHcontext );
1950 if( prefix != NULL && prefix->bv_len > 0 ) {
1951 HASH_Update( &HASHcontext,
1952 prefix->bv_val, prefix->bv_len );
1954 HASH_Update( &HASHcontext,
1955 &pre, sizeof( pre ) );
1956 HASH_Update( &HASHcontext,
1957 syntax->ssyn_oid, slen );
1958 HASH_Update( &HASHcontext,
1959 mr->smr_oid, mlen );
1960 HASH_Update( &HASHcontext,
1961 value->bv_val, klen );
1962 HASH_Final( HASHdigest, &HASHcontext );
1964 keys[nkeys++] = ber_bvdup( &digest );
1967 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1969 pre = SLAP_INDEX_SUBSTR_PREFIX;
1970 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1972 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1973 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1977 value = sa->sa_any[i];
1980 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1981 j += SLAP_INDEX_SUBSTR_STEP )
1983 HASH_Init( &HASHcontext );
1984 if( prefix != NULL && prefix->bv_len > 0 ) {
1985 HASH_Update( &HASHcontext,
1986 prefix->bv_val, prefix->bv_len );
1988 HASH_Update( &HASHcontext,
1989 &pre, sizeof( pre ) );
1990 HASH_Update( &HASHcontext,
1991 syntax->ssyn_oid, slen );
1992 HASH_Update( &HASHcontext,
1993 mr->smr_oid, mlen );
1994 HASH_Update( &HASHcontext,
1995 &value->bv_val[j], klen );
1996 HASH_Final( HASHdigest, &HASHcontext );
1998 keys[nkeys++] = ber_bvdup( &digest );
2004 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2005 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2007 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2008 value = sa->sa_final;
2010 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2011 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2013 HASH_Init( &HASHcontext );
2014 if( prefix != NULL && prefix->bv_len > 0 ) {
2015 HASH_Update( &HASHcontext,
2016 prefix->bv_val, prefix->bv_len );
2018 HASH_Update( &HASHcontext,
2019 &pre, sizeof( pre ) );
2020 HASH_Update( &HASHcontext,
2021 syntax->ssyn_oid, slen );
2022 HASH_Update( &HASHcontext,
2023 mr->smr_oid, mlen );
2024 HASH_Update( &HASHcontext,
2025 &value->bv_val[value->bv_len-klen], klen );
2026 HASH_Final( HASHdigest, &HASHcontext );
2028 keys[nkeys++] = ber_bvdup( &digest );
2038 ber_bvfree( sa->sa_final );
2039 ber_bvecfree( sa->sa_any );
2040 ber_bvfree( sa->sa_initial );
2043 return LDAP_SUCCESS;
2052 struct berval *value,
2053 void *assertedValue )
2055 *matchp = UTF8normcmp( value->bv_val,
2056 ((struct berval *) assertedValue)->bv_val,
2058 return LDAP_SUCCESS;
2064 struct berval *val )
2068 if( val->bv_len == 0 ) {
2069 /* disallow empty strings */
2070 return LDAP_INVALID_SYNTAX;
2073 if( OID_LEADCHAR(val->bv_val[0]) ) {
2075 for(i=1; i < val->bv_len; i++) {
2076 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2077 if( dot++ ) return 1;
2078 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2081 return LDAP_INVALID_SYNTAX;
2085 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2087 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2088 for(i=1; i < val->bv_len; i++) {
2089 if( !DESC_CHAR(val->bv_val[i] ) ) {
2090 return LDAP_INVALID_SYNTAX;
2094 return LDAP_SUCCESS;
2097 return LDAP_INVALID_SYNTAX;
2106 struct berval *value,
2107 void *assertedValue )
2110 int vsign=0, avsign=0;
2111 struct berval *asserted;
2112 ber_len_t vlen, avlen;
2115 /* Start off pessimistic */
2118 /* Skip past leading spaces/zeros, and get the sign of the *value number */
2120 vlen = value->bv_len;
2122 if( ASCII_SPACE(*v) || ( *v == '0' )) {
2123 /* empty -- skip spaces */
2125 else if ( *v == '+' ) {
2128 else if ( *v == '-' ) {
2131 else if ( ASCII_DIGIT(*v) ) {
2132 if ( vsign == 0 ) vsign = 1;
2140 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
2142 asserted = (struct berval *) assertedValue;
2143 av = asserted->bv_val;
2144 avlen = asserted->bv_len;
2146 if( ASCII_SPACE(*av) || ( *av == '0' )) {
2147 /* empty -- skip spaces */
2149 else if ( *av == '+' ) {
2152 else if ( *av == '-' ) {
2155 else if ( ASCII_DIGIT(*av) ) {
2156 if ( avsign == 0 ) avsign = 1;
2164 /* The two ?sign vars are now one of :
2165 -2 negative non-zero number
2167 0 0 collapse these three to 0
2169 +2 positive non-zero number
2171 if ( abs( vsign ) == 1 ) vsign = 0;
2172 if ( abs( avsign ) == 1 ) avsign = 0;
2174 if( vsign != avsign ) return LDAP_SUCCESS;
2176 /* Check the significant digits */
2177 while( vlen && avlen ) {
2178 if( *v != *av ) break;
2185 /* If all digits compared equal, the numbers are equal */
2186 if(( vlen == 0 ) && ( avlen == 0 )) {
2189 return LDAP_SUCCESS;
2195 struct berval *val )
2199 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2201 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
2202 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2203 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2204 return LDAP_INVALID_SYNTAX;
2207 for( i=1; i < val->bv_len; i++ ) {
2208 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2211 return LDAP_SUCCESS;
2218 struct berval **normalized )
2222 struct berval *newval;
2229 /* Ignore leading spaces */
2230 while ( len && ( *p == ' ' )) {
2237 negative = ( *p == '-' );
2238 if(( *p == '-' ) || ( *p == '+' )) {
2244 /* Ignore leading zeros */
2245 while ( len && ( *p == '0' )) {
2250 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2252 /* If there are no non-zero digits left, the number is zero, otherwise
2253 allocate space for the number and copy it into the buffer */
2255 newval->bv_val = ch_strdup("0");
2259 newval->bv_len = len+negative;
2260 newval->bv_val = ch_malloc( newval->bv_len );
2262 newval->bv_val[0] = '-';
2264 memcpy( newval->bv_val + negative, p, len );
2267 *normalized = newval;
2268 return LDAP_SUCCESS;
2271 /* Index generation function */
2277 struct berval *prefix,
2278 struct berval **values,
2279 struct berval ***keysp )
2282 struct berval **keys;
2284 /* we should have at least one value at this point */
2285 assert( values != NULL && values[0] != NULL );
2287 for( i=0; values[i] != NULL; i++ ) {
2288 /* empty -- just count them */
2291 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2293 for( i=0; values[i] != NULL; i++ ) {
2294 integerNormalize( syntax, values[i], &keys[i] );
2299 return LDAP_SUCCESS;
2302 /* Index generation function */
2308 struct berval *prefix,
2310 struct berval ***keysp )
2312 struct berval **keys;
2314 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2315 integerNormalize( syntax, assertValue, &keys[0] );
2319 return LDAP_SUCCESS;
2324 countryStringValidate(
2326 struct berval *val )
2328 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2330 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2331 return LDAP_INVALID_SYNTAX;
2333 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2334 return LDAP_INVALID_SYNTAX;
2337 return LDAP_SUCCESS;
2341 printableStringValidate(
2343 struct berval *val )
2347 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2349 for(i=0; i < val->bv_len; i++) {
2350 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2351 return LDAP_INVALID_SYNTAX;
2355 return LDAP_SUCCESS;
2359 printablesStringValidate(
2361 struct berval *val )
2365 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2367 for(i=0; i < val->bv_len; i++) {
2368 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2369 return LDAP_INVALID_SYNTAX;
2373 return LDAP_SUCCESS;
2379 struct berval *val )
2383 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2385 for(i=0; i < val->bv_len; i++) {
2386 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2389 return LDAP_SUCCESS;
2396 struct berval **normalized )
2398 struct berval *newval;
2401 newval = ch_malloc( sizeof( struct berval ) );
2405 /* Ignore initial whitespace */
2406 while ( ASCII_SPACE( *p ) ) {
2412 return LDAP_INVALID_SYNTAX;
2415 newval->bv_val = ch_strdup( p );
2416 p = q = newval->bv_val;
2419 if ( ASCII_SPACE( *p ) ) {
2422 /* Ignore the extra whitespace */
2423 while ( ASCII_SPACE( *p ) ) {
2431 assert( *newval->bv_val );
2432 assert( newval->bv_val < p );
2435 /* cannot start with a space */
2436 assert( !ASCII_SPACE(*newval->bv_val) );
2439 * If the string ended in space, backup the pointer one
2440 * position. One is enough because the above loop collapsed
2441 * all whitespace to a single space.
2444 if ( ASCII_SPACE( q[-1] ) ) {
2448 /* cannot end with a space */
2449 assert( !ASCII_SPACE( q[-1] ) );
2451 /* null terminate */
2454 newval->bv_len = q - newval->bv_val;
2455 *normalized = newval;
2457 return LDAP_SUCCESS;
2466 struct berval *value,
2467 void *assertedValue )
2469 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2472 match = strncmp( value->bv_val,
2473 ((struct berval *) assertedValue)->bv_val,
2478 return LDAP_SUCCESS;
2482 caseExactIA5SubstringsMatch(
2487 struct berval *value,
2488 void *assertedValue )
2491 SubstringsAssertion *sub = assertedValue;
2492 struct berval left = *value;
2496 /* Add up asserted input length */
2497 if( sub->sa_initial ) {
2498 inlen += sub->sa_initial->bv_len;
2501 for(i=0; sub->sa_any[i] != NULL; i++) {
2502 inlen += sub->sa_any[i]->bv_len;
2505 if( sub->sa_final ) {
2506 inlen += sub->sa_final->bv_len;
2509 if( sub->sa_initial ) {
2510 if( inlen > left.bv_len ) {
2515 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2516 sub->sa_initial->bv_len );
2522 left.bv_val += sub->sa_initial->bv_len;
2523 left.bv_len -= sub->sa_initial->bv_len;
2524 inlen -= sub->sa_initial->bv_len;
2527 if( sub->sa_final ) {
2528 if( inlen > left.bv_len ) {
2533 match = strncmp( sub->sa_final->bv_val,
2534 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2535 sub->sa_final->bv_len );
2541 left.bv_len -= sub->sa_final->bv_len;
2542 inlen -= sub->sa_final->bv_len;
2546 for(i=0; sub->sa_any[i]; i++) {
2551 if( inlen > left.bv_len ) {
2552 /* not enough length */
2557 if( sub->sa_any[i]->bv_len == 0 ) {
2561 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2568 idx = p - left.bv_val;
2569 assert( idx < left.bv_len );
2571 if( idx >= left.bv_len ) {
2572 /* this shouldn't happen */
2579 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2580 /* not enough left */
2585 match = strncmp( left.bv_val,
2586 sub->sa_any[i]->bv_val,
2587 sub->sa_any[i]->bv_len );
2595 left.bv_val += sub->sa_any[i]->bv_len;
2596 left.bv_len -= sub->sa_any[i]->bv_len;
2597 inlen -= sub->sa_any[i]->bv_len;
2603 return LDAP_SUCCESS;
2606 /* Index generation function */
2607 int caseExactIA5Indexer(
2612 struct berval *prefix,
2613 struct berval **values,
2614 struct berval ***keysp )
2618 struct berval **keys;
2619 HASH_CONTEXT HASHcontext;
2620 unsigned char HASHdigest[HASH_BYTES];
2621 struct berval digest;
2622 digest.bv_val = HASHdigest;
2623 digest.bv_len = sizeof(HASHdigest);
2625 for( i=0; values[i] != NULL; i++ ) {
2626 /* empty - just count them */
2629 /* we should have at least one value at this point */
2632 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2634 slen = strlen( syntax->ssyn_oid );
2635 mlen = strlen( mr->smr_oid );
2637 for( i=0; values[i] != NULL; i++ ) {
2638 struct berval *value = values[i];
2640 HASH_Init( &HASHcontext );
2641 if( prefix != NULL && prefix->bv_len > 0 ) {
2642 HASH_Update( &HASHcontext,
2643 prefix->bv_val, prefix->bv_len );
2645 HASH_Update( &HASHcontext,
2646 syntax->ssyn_oid, slen );
2647 HASH_Update( &HASHcontext,
2648 mr->smr_oid, mlen );
2649 HASH_Update( &HASHcontext,
2650 value->bv_val, value->bv_len );
2651 HASH_Final( HASHdigest, &HASHcontext );
2653 keys[i] = ber_bvdup( &digest );
2658 return LDAP_SUCCESS;
2661 /* Index generation function */
2662 int caseExactIA5Filter(
2667 struct berval *prefix,
2669 struct berval ***keysp )
2672 struct berval **keys;
2673 HASH_CONTEXT HASHcontext;
2674 unsigned char HASHdigest[HASH_BYTES];
2675 struct berval *value;
2676 struct berval digest;
2677 digest.bv_val = HASHdigest;
2678 digest.bv_len = sizeof(HASHdigest);
2680 slen = strlen( syntax->ssyn_oid );
2681 mlen = strlen( mr->smr_oid );
2683 value = (struct berval *) assertValue;
2685 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2687 HASH_Init( &HASHcontext );
2688 if( prefix != NULL && prefix->bv_len > 0 ) {
2689 HASH_Update( &HASHcontext,
2690 prefix->bv_val, prefix->bv_len );
2692 HASH_Update( &HASHcontext,
2693 syntax->ssyn_oid, slen );
2694 HASH_Update( &HASHcontext,
2695 mr->smr_oid, mlen );
2696 HASH_Update( &HASHcontext,
2697 value->bv_val, value->bv_len );
2698 HASH_Final( HASHdigest, &HASHcontext );
2700 keys[0] = ber_bvdup( &digest );
2704 return LDAP_SUCCESS;
2707 /* Substrings Index generation function */
2708 int caseExactIA5SubstringsIndexer(
2713 struct berval *prefix,
2714 struct berval **values,
2715 struct berval ***keysp )
2719 struct berval **keys;
2720 HASH_CONTEXT HASHcontext;
2721 unsigned char HASHdigest[HASH_BYTES];
2722 struct berval digest;
2723 digest.bv_val = HASHdigest;
2724 digest.bv_len = sizeof(HASHdigest);
2726 /* we should have at least one value at this point */
2727 assert( values != NULL && values[0] != NULL );
2730 for( i=0; values[i] != NULL; i++ ) {
2731 /* count number of indices to generate */
2732 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2736 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2737 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2738 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2739 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2741 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2745 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2746 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2747 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2751 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2752 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2753 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2754 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2756 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2762 /* no keys to generate */
2764 return LDAP_SUCCESS;
2767 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2769 slen = strlen( syntax->ssyn_oid );
2770 mlen = strlen( mr->smr_oid );
2773 for( i=0; values[i] != NULL; i++ ) {
2775 struct berval *value;
2778 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2780 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2781 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2783 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2784 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2786 for( j=0; j<max; j++ ) {
2787 HASH_Init( &HASHcontext );
2788 if( prefix != NULL && prefix->bv_len > 0 ) {
2789 HASH_Update( &HASHcontext,
2790 prefix->bv_val, prefix->bv_len );
2793 HASH_Update( &HASHcontext,
2794 &pre, sizeof( pre ) );
2795 HASH_Update( &HASHcontext,
2796 syntax->ssyn_oid, slen );
2797 HASH_Update( &HASHcontext,
2798 mr->smr_oid, mlen );
2799 HASH_Update( &HASHcontext,
2801 SLAP_INDEX_SUBSTR_MAXLEN );
2802 HASH_Final( HASHdigest, &HASHcontext );
2804 keys[nkeys++] = ber_bvdup( &digest );
2808 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2809 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2811 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2814 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2815 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2816 HASH_Init( &HASHcontext );
2817 if( prefix != NULL && prefix->bv_len > 0 ) {
2818 HASH_Update( &HASHcontext,
2819 prefix->bv_val, prefix->bv_len );
2821 HASH_Update( &HASHcontext,
2822 &pre, sizeof( pre ) );
2823 HASH_Update( &HASHcontext,
2824 syntax->ssyn_oid, slen );
2825 HASH_Update( &HASHcontext,
2826 mr->smr_oid, mlen );
2827 HASH_Update( &HASHcontext,
2829 HASH_Final( HASHdigest, &HASHcontext );
2831 keys[nkeys++] = ber_bvdup( &digest );
2834 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2835 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2836 HASH_Init( &HASHcontext );
2837 if( prefix != NULL && prefix->bv_len > 0 ) {
2838 HASH_Update( &HASHcontext,
2839 prefix->bv_val, prefix->bv_len );
2841 HASH_Update( &HASHcontext,
2842 &pre, sizeof( pre ) );
2843 HASH_Update( &HASHcontext,
2844 syntax->ssyn_oid, slen );
2845 HASH_Update( &HASHcontext,
2846 mr->smr_oid, mlen );
2847 HASH_Update( &HASHcontext,
2848 &value->bv_val[value->bv_len-j], j );
2849 HASH_Final( HASHdigest, &HASHcontext );
2851 keys[nkeys++] = ber_bvdup( &digest );
2865 return LDAP_SUCCESS;
2868 int caseExactIA5SubstringsFilter(
2873 struct berval *prefix,
2875 struct berval ***keysp )
2877 SubstringsAssertion *sa = assertValue;
2879 ber_len_t nkeys = 0;
2880 size_t slen, mlen, klen;
2881 struct berval **keys;
2882 HASH_CONTEXT HASHcontext;
2883 unsigned char HASHdigest[HASH_BYTES];
2884 struct berval *value;
2885 struct berval digest;
2887 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2888 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2893 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2895 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2896 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2897 /* don't bother accounting for stepping */
2898 nkeys += sa->sa_any[i]->bv_len -
2899 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2904 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2905 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2912 return LDAP_SUCCESS;
2915 digest.bv_val = HASHdigest;
2916 digest.bv_len = sizeof(HASHdigest);
2918 slen = strlen( syntax->ssyn_oid );
2919 mlen = strlen( mr->smr_oid );
2921 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2924 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2925 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2927 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2928 value = sa->sa_initial;
2930 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2931 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2933 HASH_Init( &HASHcontext );
2934 if( prefix != NULL && prefix->bv_len > 0 ) {
2935 HASH_Update( &HASHcontext,
2936 prefix->bv_val, prefix->bv_len );
2938 HASH_Update( &HASHcontext,
2939 &pre, sizeof( pre ) );
2940 HASH_Update( &HASHcontext,
2941 syntax->ssyn_oid, slen );
2942 HASH_Update( &HASHcontext,
2943 mr->smr_oid, mlen );
2944 HASH_Update( &HASHcontext,
2945 value->bv_val, klen );
2946 HASH_Final( HASHdigest, &HASHcontext );
2948 keys[nkeys++] = ber_bvdup( &digest );
2951 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2953 pre = SLAP_INDEX_SUBSTR_PREFIX;
2954 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2956 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2957 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2961 value = sa->sa_any[i];
2964 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2965 j += SLAP_INDEX_SUBSTR_STEP )
2967 HASH_Init( &HASHcontext );
2968 if( prefix != NULL && prefix->bv_len > 0 ) {
2969 HASH_Update( &HASHcontext,
2970 prefix->bv_val, prefix->bv_len );
2972 HASH_Update( &HASHcontext,
2973 &pre, sizeof( pre ) );
2974 HASH_Update( &HASHcontext,
2975 syntax->ssyn_oid, slen );
2976 HASH_Update( &HASHcontext,
2977 mr->smr_oid, mlen );
2978 HASH_Update( &HASHcontext,
2979 &value->bv_val[j], klen );
2980 HASH_Final( HASHdigest, &HASHcontext );
2982 keys[nkeys++] = ber_bvdup( &digest );
2987 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2988 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2990 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2991 value = sa->sa_final;
2993 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2994 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2996 HASH_Init( &HASHcontext );
2997 if( prefix != NULL && prefix->bv_len > 0 ) {
2998 HASH_Update( &HASHcontext,
2999 prefix->bv_val, prefix->bv_len );
3001 HASH_Update( &HASHcontext,
3002 &pre, sizeof( pre ) );
3003 HASH_Update( &HASHcontext,
3004 syntax->ssyn_oid, slen );
3005 HASH_Update( &HASHcontext,
3006 mr->smr_oid, mlen );
3007 HASH_Update( &HASHcontext,
3008 &value->bv_val[value->bv_len-klen], klen );
3009 HASH_Final( HASHdigest, &HASHcontext );
3011 keys[nkeys++] = ber_bvdup( &digest );
3022 return LDAP_SUCCESS;
3031 struct berval *value,
3032 void *assertedValue )
3034 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3036 if( match == 0 && value->bv_len ) {
3037 match = strncasecmp( value->bv_val,
3038 ((struct berval *) assertedValue)->bv_val,
3043 return LDAP_SUCCESS;
3047 caseIgnoreIA5SubstringsMatch(
3052 struct berval *value,
3053 void *assertedValue )
3056 SubstringsAssertion *sub = assertedValue;
3057 struct berval left = *value;
3061 /* Add up asserted input length */
3062 if( sub->sa_initial ) {
3063 inlen += sub->sa_initial->bv_len;
3066 for(i=0; sub->sa_any[i] != NULL; i++) {
3067 inlen += sub->sa_any[i]->bv_len;
3070 if( sub->sa_final ) {
3071 inlen += sub->sa_final->bv_len;
3074 if( sub->sa_initial ) {
3075 if( inlen > left.bv_len ) {
3080 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3081 sub->sa_initial->bv_len );
3087 left.bv_val += sub->sa_initial->bv_len;
3088 left.bv_len -= sub->sa_initial->bv_len;
3089 inlen -= sub->sa_initial->bv_len;
3092 if( sub->sa_final ) {
3093 if( inlen > left.bv_len ) {
3098 match = strncasecmp( sub->sa_final->bv_val,
3099 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3100 sub->sa_final->bv_len );
3106 left.bv_len -= sub->sa_final->bv_len;
3107 inlen -= sub->sa_final->bv_len;
3111 for(i=0; sub->sa_any[i]; i++) {
3116 if( inlen > left.bv_len ) {
3117 /* not enough length */
3122 if( sub->sa_any[i]->bv_len == 0 ) {
3126 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3133 idx = p - left.bv_val;
3134 assert( idx < left.bv_len );
3136 if( idx >= left.bv_len ) {
3137 /* this shouldn't happen */
3144 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3145 /* not enough left */
3150 match = strncasecmp( left.bv_val,
3151 sub->sa_any[i]->bv_val,
3152 sub->sa_any[i]->bv_len );
3161 left.bv_val += sub->sa_any[i]->bv_len;
3162 left.bv_len -= sub->sa_any[i]->bv_len;
3163 inlen -= sub->sa_any[i]->bv_len;
3169 return LDAP_SUCCESS;
3172 /* Index generation function */
3173 int caseIgnoreIA5Indexer(
3178 struct berval *prefix,
3179 struct berval **values,
3180 struct berval ***keysp )
3184 struct berval **keys;
3185 HASH_CONTEXT HASHcontext;
3186 unsigned char HASHdigest[HASH_BYTES];
3187 struct berval digest;
3188 digest.bv_val = HASHdigest;
3189 digest.bv_len = sizeof(HASHdigest);
3191 /* we should have at least one value at this point */
3192 assert( values != NULL && values[0] != NULL );
3194 for( i=0; values[i] != NULL; i++ ) {
3195 /* just count them */
3198 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3200 slen = strlen( syntax->ssyn_oid );
3201 mlen = strlen( mr->smr_oid );
3203 for( i=0; values[i] != NULL; i++ ) {
3204 struct berval *value = ber_bvdup( values[i] );
3205 ldap_pvt_str2upper( value->bv_val );
3207 HASH_Init( &HASHcontext );
3208 if( prefix != NULL && prefix->bv_len > 0 ) {
3209 HASH_Update( &HASHcontext,
3210 prefix->bv_val, prefix->bv_len );
3212 HASH_Update( &HASHcontext,
3213 syntax->ssyn_oid, slen );
3214 HASH_Update( &HASHcontext,
3215 mr->smr_oid, mlen );
3216 HASH_Update( &HASHcontext,
3217 value->bv_val, value->bv_len );
3218 HASH_Final( HASHdigest, &HASHcontext );
3220 ber_bvfree( value );
3222 keys[i] = ber_bvdup( &digest );
3227 return LDAP_SUCCESS;
3230 /* Index generation function */
3231 int caseIgnoreIA5Filter(
3236 struct berval *prefix,
3238 struct berval ***keysp )
3241 struct berval **keys;
3242 HASH_CONTEXT HASHcontext;
3243 unsigned char HASHdigest[HASH_BYTES];
3244 struct berval *value;
3245 struct berval digest;
3246 digest.bv_val = HASHdigest;
3247 digest.bv_len = sizeof(HASHdigest);
3249 slen = strlen( syntax->ssyn_oid );
3250 mlen = strlen( mr->smr_oid );
3252 value = ber_bvdup( (struct berval *) assertValue );
3253 ldap_pvt_str2upper( value->bv_val );
3255 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3257 HASH_Init( &HASHcontext );
3258 if( prefix != NULL && prefix->bv_len > 0 ) {
3259 HASH_Update( &HASHcontext,
3260 prefix->bv_val, prefix->bv_len );
3262 HASH_Update( &HASHcontext,
3263 syntax->ssyn_oid, slen );
3264 HASH_Update( &HASHcontext,
3265 mr->smr_oid, mlen );
3266 HASH_Update( &HASHcontext,
3267 value->bv_val, value->bv_len );
3268 HASH_Final( HASHdigest, &HASHcontext );
3270 keys[0] = ber_bvdup( &digest );
3273 ber_bvfree( value );
3277 return LDAP_SUCCESS;
3280 /* Substrings Index generation function */
3281 int caseIgnoreIA5SubstringsIndexer(
3286 struct berval *prefix,
3287 struct berval **values,
3288 struct berval ***keysp )
3292 struct berval **keys;
3293 HASH_CONTEXT HASHcontext;
3294 unsigned char HASHdigest[HASH_BYTES];
3295 struct berval digest;
3296 digest.bv_val = HASHdigest;
3297 digest.bv_len = sizeof(HASHdigest);
3299 /* we should have at least one value at this point */
3300 assert( values != NULL && values[0] != NULL );
3303 for( i=0; values[i] != NULL; i++ ) {
3304 /* count number of indices to generate */
3305 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3309 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3310 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3311 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3312 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3314 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3318 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3319 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3320 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3324 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3325 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3326 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3327 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3329 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3335 /* no keys to generate */
3337 return LDAP_SUCCESS;
3340 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3342 slen = strlen( syntax->ssyn_oid );
3343 mlen = strlen( mr->smr_oid );
3346 for( i=0; values[i] != NULL; i++ ) {
3348 struct berval *value;
3350 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3352 value = ber_bvdup( values[i] );
3353 ldap_pvt_str2upper( value->bv_val );
3355 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3356 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3358 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3359 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3361 for( j=0; j<max; j++ ) {
3362 HASH_Init( &HASHcontext );
3363 if( prefix != NULL && prefix->bv_len > 0 ) {
3364 HASH_Update( &HASHcontext,
3365 prefix->bv_val, prefix->bv_len );
3368 HASH_Update( &HASHcontext,
3369 &pre, sizeof( pre ) );
3370 HASH_Update( &HASHcontext,
3371 syntax->ssyn_oid, slen );
3372 HASH_Update( &HASHcontext,
3373 mr->smr_oid, mlen );
3374 HASH_Update( &HASHcontext,
3376 SLAP_INDEX_SUBSTR_MAXLEN );
3377 HASH_Final( HASHdigest, &HASHcontext );
3379 keys[nkeys++] = ber_bvdup( &digest );
3383 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3384 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3386 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3389 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3390 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3391 HASH_Init( &HASHcontext );
3392 if( prefix != NULL && prefix->bv_len > 0 ) {
3393 HASH_Update( &HASHcontext,
3394 prefix->bv_val, prefix->bv_len );
3396 HASH_Update( &HASHcontext,
3397 &pre, sizeof( pre ) );
3398 HASH_Update( &HASHcontext,
3399 syntax->ssyn_oid, slen );
3400 HASH_Update( &HASHcontext,
3401 mr->smr_oid, mlen );
3402 HASH_Update( &HASHcontext,
3404 HASH_Final( HASHdigest, &HASHcontext );
3406 keys[nkeys++] = ber_bvdup( &digest );
3409 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3410 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3411 HASH_Init( &HASHcontext );
3412 if( prefix != NULL && prefix->bv_len > 0 ) {
3413 HASH_Update( &HASHcontext,
3414 prefix->bv_val, prefix->bv_len );
3416 HASH_Update( &HASHcontext,
3417 &pre, sizeof( pre ) );
3418 HASH_Update( &HASHcontext,
3419 syntax->ssyn_oid, slen );
3420 HASH_Update( &HASHcontext,
3421 mr->smr_oid, mlen );
3422 HASH_Update( &HASHcontext,
3423 &value->bv_val[value->bv_len-j], j );
3424 HASH_Final( HASHdigest, &HASHcontext );
3426 keys[nkeys++] = ber_bvdup( &digest );
3431 ber_bvfree( value );
3442 return LDAP_SUCCESS;
3445 int caseIgnoreIA5SubstringsFilter(
3450 struct berval *prefix,
3452 struct berval ***keysp )
3454 SubstringsAssertion *sa = assertValue;
3456 ber_len_t nkeys = 0;
3457 size_t slen, mlen, klen;
3458 struct berval **keys;
3459 HASH_CONTEXT HASHcontext;
3460 unsigned char HASHdigest[HASH_BYTES];
3461 struct berval *value;
3462 struct berval digest;
3464 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3465 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3470 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3472 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3473 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3474 /* don't bother accounting for stepping */
3475 nkeys += sa->sa_any[i]->bv_len -
3476 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3481 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3482 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3489 return LDAP_SUCCESS;
3492 digest.bv_val = HASHdigest;
3493 digest.bv_len = sizeof(HASHdigest);
3495 slen = strlen( syntax->ssyn_oid );
3496 mlen = strlen( mr->smr_oid );
3498 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3501 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3502 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3504 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3505 value = ber_bvdup( sa->sa_initial );
3506 ldap_pvt_str2upper( value->bv_val );
3508 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3509 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3511 HASH_Init( &HASHcontext );
3512 if( prefix != NULL && prefix->bv_len > 0 ) {
3513 HASH_Update( &HASHcontext,
3514 prefix->bv_val, prefix->bv_len );
3516 HASH_Update( &HASHcontext,
3517 &pre, sizeof( pre ) );
3518 HASH_Update( &HASHcontext,
3519 syntax->ssyn_oid, slen );
3520 HASH_Update( &HASHcontext,
3521 mr->smr_oid, mlen );
3522 HASH_Update( &HASHcontext,
3523 value->bv_val, klen );
3524 HASH_Final( HASHdigest, &HASHcontext );
3526 ber_bvfree( value );
3527 keys[nkeys++] = ber_bvdup( &digest );
3530 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3532 pre = SLAP_INDEX_SUBSTR_PREFIX;
3533 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3535 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3536 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3540 value = ber_bvdup( sa->sa_any[i] );
3541 ldap_pvt_str2upper( value->bv_val );
3544 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3545 j += SLAP_INDEX_SUBSTR_STEP )
3547 HASH_Init( &HASHcontext );
3548 if( prefix != NULL && prefix->bv_len > 0 ) {
3549 HASH_Update( &HASHcontext,
3550 prefix->bv_val, prefix->bv_len );
3552 HASH_Update( &HASHcontext,
3553 &pre, sizeof( pre ) );
3554 HASH_Update( &HASHcontext,
3555 syntax->ssyn_oid, slen );
3556 HASH_Update( &HASHcontext,
3557 mr->smr_oid, mlen );
3558 HASH_Update( &HASHcontext,
3559 &value->bv_val[j], klen );
3560 HASH_Final( HASHdigest, &HASHcontext );
3562 keys[nkeys++] = ber_bvdup( &digest );
3565 ber_bvfree( value );
3569 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3570 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3572 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3573 value = ber_bvdup( sa->sa_final );
3574 ldap_pvt_str2upper( value->bv_val );
3576 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3577 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3579 HASH_Init( &HASHcontext );
3580 if( prefix != NULL && prefix->bv_len > 0 ) {
3581 HASH_Update( &HASHcontext,
3582 prefix->bv_val, prefix->bv_len );
3584 HASH_Update( &HASHcontext,
3585 &pre, sizeof( pre ) );
3586 HASH_Update( &HASHcontext,
3587 syntax->ssyn_oid, slen );
3588 HASH_Update( &HASHcontext,
3589 mr->smr_oid, mlen );
3590 HASH_Update( &HASHcontext,
3591 &value->bv_val[value->bv_len-klen], klen );
3592 HASH_Final( HASHdigest, &HASHcontext );
3594 ber_bvfree( value );
3595 keys[nkeys++] = ber_bvdup( &digest );
3606 return LDAP_SUCCESS;
3610 numericStringValidate(
3616 for(i=0; i < in->bv_len; i++) {
3617 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3618 return LDAP_INVALID_SYNTAX;
3622 return LDAP_SUCCESS;
3626 numericStringNormalize(
3629 struct berval **normalized )
3631 /* removal all spaces */
3632 struct berval *newval;
3635 newval = ch_malloc( sizeof( struct berval ) );
3636 newval->bv_val = ch_malloc( val->bv_len + 1 );
3642 if ( ASCII_SPACE( *p ) ) {
3643 /* Ignore whitespace */
3650 /* we should have copied no more then is in val */
3651 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3653 /* null terminate */
3656 newval->bv_len = q - newval->bv_val;
3657 *normalized = newval;
3659 return LDAP_SUCCESS;
3663 objectIdentifierFirstComponentMatch(
3668 struct berval *value,
3669 void *assertedValue )
3671 int rc = LDAP_SUCCESS;
3673 struct berval *asserted = (struct berval *) assertedValue;
3677 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3678 return LDAP_INVALID_SYNTAX;
3681 /* trim leading white space */
3682 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3686 /* grab next word */
3687 oid.bv_val = &value->bv_val[i];
3688 oid.bv_len = value->bv_len - i;
3689 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3694 /* insert attributeTypes, objectclass check here */
3695 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3696 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3699 char *stored = ch_malloc( oid.bv_len + 1 );
3700 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3701 stored[oid.bv_len] = '\0';
3703 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3704 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3705 MatchingRule *stored_mr = mr_find( stored );
3707 if( asserted_mr == NULL ) {
3708 rc = SLAPD_COMPARE_UNDEFINED;
3710 match = asserted_mr != stored_mr;
3713 } else if ( !strcmp( syntax->ssyn_oid,
3714 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3716 AttributeType *asserted_at = at_find( asserted->bv_val );
3717 AttributeType *stored_at = at_find( stored );
3719 if( asserted_at == NULL ) {
3720 rc = SLAPD_COMPARE_UNDEFINED;
3722 match = asserted_at != stored_at;
3725 } else if ( !strcmp( syntax->ssyn_oid,
3726 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3728 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3729 ObjectClass *stored_oc = oc_find( stored );
3731 if( asserted_oc == NULL ) {
3732 rc = SLAPD_COMPARE_UNDEFINED;
3734 match = asserted_oc != stored_oc;
3742 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3743 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3744 match, value->bv_val, asserted->bv_val ));
3746 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3747 "%d\n\t\"%s\"\n\t\"%s\"\n",
3748 match, value->bv_val, asserted->bv_val );
3752 if( rc == LDAP_SUCCESS ) *matchp = match;
3762 struct berval *value,
3763 void *assertedValue )
3765 long lValue, lAssertedValue;
3767 /* safe to assume integers are NUL terminated? */
3768 lValue = strtoul(value->bv_val, NULL, 10);
3769 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3770 return LDAP_CONSTRAINT_VIOLATION;
3772 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3773 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3774 return LDAP_CONSTRAINT_VIOLATION;
3776 *matchp = (lValue & lAssertedValue);
3777 return LDAP_SUCCESS;
3786 struct berval *value,
3787 void *assertedValue )
3789 long lValue, lAssertedValue;
3791 /* safe to assume integers are NUL terminated? */
3792 lValue = strtoul(value->bv_val, NULL, 10);
3793 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3794 return LDAP_CONSTRAINT_VIOLATION;
3796 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3797 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3798 return LDAP_CONSTRAINT_VIOLATION;
3800 *matchp = (lValue | lAssertedValue);
3801 return LDAP_SUCCESS;
3805 #include <openssl/x509.h>
3806 #include <openssl/err.h>
3807 char digit[] = "0123456789";
3810 * Next function returns a string representation of a ASN1_INTEGER.
3811 * It works for unlimited lengths.
3814 static struct berval *
3815 asn1_integer2str(ASN1_INTEGER *a)
3820 /* We work backwards, make it fill from the end of buf */
3821 p = buf + sizeof(buf) - 1;
3824 if ( a == NULL || a->length == 0 ) {
3832 /* We want to preserve the original */
3833 copy = ch_malloc(n*sizeof(unsigned int));
3834 for (i = 0; i<n; i++) {
3835 copy[i] = a->data[i];
3839 * base indicates the index of the most significant
3840 * byte that might be nonzero. When it goes off the
3841 * end, we now there is nothing left to do.
3847 for (i = base; i<n; i++ ) {
3848 copy[i] += carry*256;
3849 carry = copy[i] % 10;
3854 * Way too large, we need to leave
3855 * room for sign if negative
3860 *--p = digit[carry];
3861 if (copy[base] == 0)
3867 if ( a->type == V_ASN1_NEG_INTEGER ) {
3871 return ber_bvstrdup(p);
3874 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3875 static struct berval *
3876 dn_openssl2ldap(X509_NAME *name)
3878 char issuer_dn[1024];
3881 bio = BIO_new(BIO_s_mem());
3884 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3885 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3886 ERR_error_string(ERR_get_error(),NULL)));
3888 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3889 "error creating BIO: %s\n",
3890 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3894 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3896 BIO_gets(bio, issuer_dn, 1024);
3899 return ber_bvstrdup(issuer_dn);
3903 * Given a certificate in DER format, extract the corresponding
3904 * assertion value for certificateExactMatch
3907 certificateExactConvert(
3909 struct berval ** out )
3912 unsigned char *p = in->bv_val;
3913 struct berval *serial;
3914 struct berval *issuer_dn;
3915 struct berval *bv_tmp;
3917 xcert = d2i_X509(NULL, &p, in->bv_len);
3920 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3921 "certificateExactConvert: error parsing cert: %s\n",
3922 ERR_error_string(ERR_get_error(),NULL)));
3924 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3925 "error parsing cert: %s\n",
3926 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3928 return LDAP_INVALID_SYNTAX;
3931 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3934 return LDAP_INVALID_SYNTAX;
3936 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3940 return LDAP_INVALID_SYNTAX;
3942 /* Actually, dn_openssl2ldap returns in a normalized format, but
3943 it is different from our normalized format */
3945 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3949 return LDAP_INVALID_SYNTAX;
3955 *out = ch_malloc(sizeof(struct berval));
3956 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3957 (*out)->bv_val = ch_malloc((*out)->bv_len);
3959 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3960 p += serial->bv_len;
3961 AC_MEMCPY(p, " $ ", 3);
3963 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3964 p += issuer_dn->bv_len;
3968 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3969 "certificateExactConvert: \n %s\n",
3972 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3974 (*out)->bv_val, NULL, NULL );
3978 ber_bvfree(issuer_dn);
3980 return LDAP_SUCCESS;
3984 serial_and_issuer_parse(
3985 struct berval *assertion,
3986 struct berval **serial,
3987 struct berval **issuer_dn
3995 begin = assertion->bv_val;
3996 end = assertion->bv_val+assertion->bv_len-1;
3997 for (p=begin; p<=end && *p != '$'; p++)
4000 return LDAP_INVALID_SYNTAX;
4002 /* p now points at the $ sign, now use begin and end to delimit the
4004 while (ASCII_SPACE(*begin))
4007 while (ASCII_SPACE(*end))
4010 q = ch_malloc( (end-begin+1)+1 );
4011 AC_MEMCPY( q, begin, end-begin+1 );
4012 q[end-begin+1] = '\0';
4013 *serial = ber_bvstr(q);
4015 /* now extract the issuer, remember p was at the dollar sign */
4017 end = assertion->bv_val+assertion->bv_len-1;
4018 while (ASCII_SPACE(*begin))
4020 /* should we trim spaces at the end too? is it safe always? */
4022 q = ch_malloc( (end-begin+1)+1 );
4023 AC_MEMCPY( q, begin, end-begin+1 );
4024 q[end-begin+1] = '\0';
4025 *issuer_dn = ber_bvstr(dn_normalize(q));
4027 return LDAP_SUCCESS;
4031 certificateExactMatch(
4036 struct berval *value,
4037 void *assertedValue )
4040 unsigned char *p = value->bv_val;
4041 struct berval *serial;
4042 struct berval *issuer_dn;
4043 struct berval *asserted_serial;
4044 struct berval *asserted_issuer_dn;
4047 xcert = d2i_X509(NULL, &p, value->bv_len);
4050 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4051 "certificateExactMatch: error parsing cert: %s\n",
4052 ERR_error_string(ERR_get_error(),NULL)));
4054 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
4055 "error parsing cert: %s\n",
4056 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4058 return LDAP_INVALID_SYNTAX;
4061 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4062 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4066 serial_and_issuer_parse(assertedValue,
4068 &asserted_issuer_dn);
4073 slap_schema.si_syn_integer,
4074 slap_schema.si_mr_integerMatch,
4077 if ( ret == LDAP_SUCCESS ) {
4078 if ( *matchp == 0 ) {
4079 /* We need to normalize everything for dnMatch */
4083 slap_schema.si_syn_distinguishedName,
4084 slap_schema.si_mr_distinguishedNameMatch,
4086 asserted_issuer_dn);
4091 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4092 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
4093 *matchp, serial->bv_val, issuer_dn->bv_val,
4094 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
4096 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
4097 "%d\n\t\"%s $ %s\"\n",
4098 *matchp, serial->bv_val, issuer_dn->bv_val );
4099 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
4100 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
4105 ber_bvfree(issuer_dn);
4106 ber_bvfree(asserted_serial);
4107 ber_bvfree(asserted_issuer_dn);
4113 * Index generation function
4114 * We just index the serials, in most scenarios the issuer DN is one of
4115 * a very small set of values.
4117 int certificateExactIndexer(
4122 struct berval *prefix,
4123 struct berval **values,
4124 struct berval ***keysp )
4127 struct berval **keys;
4130 struct berval * serial;
4132 /* we should have at least one value at this point */
4133 assert( values != NULL && values[0] != NULL );
4135 for( i=0; values[i] != NULL; i++ ) {
4136 /* empty -- just count them */
4139 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
4141 for( i=0; values[i] != NULL; i++ ) {
4142 p = values[i]->bv_val;
4143 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
4146 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4147 "certificateExactIndexer: error parsing cert: %s\n",
4148 ERR_error_string(ERR_get_error(),NULL)));
4150 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4151 "error parsing cert: %s\n",
4152 ERR_error_string(ERR_get_error(),NULL),
4155 /* Do we leak keys on error? */
4156 return LDAP_INVALID_SYNTAX;
4159 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4161 integerNormalize( slap_schema.si_syn_integer,
4166 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4167 "certificateExactIndexer: returning: %s\n",
4170 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4179 return LDAP_SUCCESS;
4182 /* Index generation function */
4183 /* We think this is always called with a value in matching rule syntax */
4184 int certificateExactFilter(
4189 struct berval *prefix,
4191 struct berval ***keysp )
4193 struct berval **keys;
4194 struct berval *asserted_serial;
4195 struct berval *asserted_issuer_dn;
4197 serial_and_issuer_parse(assertValue,
4199 &asserted_issuer_dn);
4201 keys = ch_malloc( sizeof( struct berval * ) * 2 );
4202 integerNormalize( syntax, asserted_serial, &keys[0] );
4206 ber_bvfree(asserted_serial);
4207 ber_bvfree(asserted_issuer_dn);
4208 return LDAP_SUCCESS;
4213 check_time_syntax (struct berval *val,
4217 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
4218 static int mdays[2][12] = {
4219 /* non-leap years */
4220 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
4222 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
4225 int part, c, tzoffset, leapyear = 0 ;
4227 if( val->bv_len == 0 ) {
4228 return LDAP_INVALID_SYNTAX;
4231 p = (char *)val->bv_val;
4232 e = p + val->bv_len;
4234 /* Ignore initial whitespace */
4235 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4239 if (e - p < 13 - (2 * start)) {
4240 return LDAP_INVALID_SYNTAX;
4243 for (part = 0; part < 9; part++) {
4247 for (part = start; part < 7; part++) {
4249 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
4256 return LDAP_INVALID_SYNTAX;
4258 if (c < 0 || c > 9) {
4259 return LDAP_INVALID_SYNTAX;
4265 return LDAP_INVALID_SYNTAX;
4267 if (c < 0 || c > 9) {
4268 return LDAP_INVALID_SYNTAX;
4273 if (part == 2 || part == 3) {
4276 if (parts[part] < 0) {
4277 return LDAP_INVALID_SYNTAX;
4279 if (parts[part] > ceiling[part]) {
4280 return LDAP_INVALID_SYNTAX;
4284 /* leapyear check for the Gregorian calendar (year>1581) */
4285 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
4286 ((parts[0] % 4 == 0) && (parts[1] == 0)))
4291 if (parts[3] > mdays[leapyear][parts[2]]) {
4292 return LDAP_INVALID_SYNTAX;
4297 tzoffset = 0; /* UTC */
4298 } else if (c != '+' && c != '-') {
4299 return LDAP_INVALID_SYNTAX;
4303 } else /* c == '+' */ {
4308 return LDAP_INVALID_SYNTAX;
4311 for (part = 7; part < 9; part++) {
4313 if (c < 0 || c > 9) {
4314 return LDAP_INVALID_SYNTAX;
4319 if (c < 0 || c > 9) {
4320 return LDAP_INVALID_SYNTAX;
4324 if (parts[part] < 0 || parts[part] > ceiling[part]) {
4325 return LDAP_INVALID_SYNTAX;
4330 /* Ignore trailing whitespace */
4331 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4335 return LDAP_INVALID_SYNTAX;
4338 switch ( tzoffset ) {
4339 case -1: /* negativ offset to UTC, ie west of Greenwich */
4340 parts[4] += parts[7];
4341 parts[5] += parts[8];
4342 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
4346 c = mdays[leapyear][parts[2]];
4348 if (parts[part] > c) {
4349 parts[part] -= c + 1;
4354 case 1: /* positive offset to UTC, ie east of Greenwich */
4355 parts[4] -= parts[7];
4356 parts[5] -= parts[8];
4357 for (part = 6; --part > 0; ) {
4361 /* first arg to % needs to be non negativ */
4362 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
4364 if (parts[part] < 0) {
4365 parts[part] += c + 1;
4370 case 0: /* already UTC */
4374 return LDAP_SUCCESS;
4381 struct berval **normalized )
4386 rc = check_time_syntax(val, 1, parts);
4387 if (rc != LDAP_SUCCESS) {
4392 out = ch_malloc( sizeof(struct berval) );
4394 return LBER_ERROR_MEMORY;
4397 out->bv_val = ch_malloc( 14 );
4398 if ( out->bv_val == NULL ) {
4400 return LBER_ERROR_MEMORY;
4403 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02dZ",
4404 parts[1], parts[2] + 1, parts[3] + 1,
4405 parts[4], parts[5], parts[6] );
4409 return LDAP_SUCCESS;
4419 return check_time_syntax(in, 1, parts);
4423 generalizedTimeValidate(
4429 return check_time_syntax(in, 0, parts);
4433 generalizedTimeNormalize(
4436 struct berval **normalized )
4441 rc = check_time_syntax(val, 0, parts);
4442 if (rc != LDAP_SUCCESS) {
4447 out = ch_malloc( sizeof(struct berval) );
4449 return LBER_ERROR_MEMORY;
4452 out->bv_val = ch_malloc( 16 );
4453 if ( out->bv_val == NULL ) {
4455 return LBER_ERROR_MEMORY;
4458 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4459 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4460 parts[4], parts[5], parts[6] );
4464 return LDAP_SUCCESS;
4468 nisNetgroupTripleValidate(
4470 struct berval *val )
4475 if ( val->bv_len == 0 ) {
4476 return LDAP_INVALID_SYNTAX;
4479 p = (char *)val->bv_val;
4480 e = p + val->bv_len;
4482 if ( *p != '(' /*')'*/ ) {
4483 return LDAP_INVALID_SYNTAX;
4486 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4490 return LDAP_INVALID_SYNTAX;
4493 } else if ( !ATTR_CHAR( *p ) ) {
4494 return LDAP_INVALID_SYNTAX;
4498 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4499 return LDAP_INVALID_SYNTAX;
4505 return LDAP_INVALID_SYNTAX;
4508 return LDAP_SUCCESS;
4512 bootParameterValidate(
4514 struct berval *val )
4518 if ( val->bv_len == 0 ) {
4519 return LDAP_INVALID_SYNTAX;
4522 p = (char *)val->bv_val;
4523 e = p + val->bv_len;
4526 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4527 if ( !ATTR_CHAR( *p ) ) {
4528 return LDAP_INVALID_SYNTAX;
4533 return LDAP_INVALID_SYNTAX;
4537 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4538 if ( !ATTR_CHAR( *p ) ) {
4539 return LDAP_INVALID_SYNTAX;
4544 return LDAP_INVALID_SYNTAX;
4548 for ( p++; p < e; p++ ) {
4549 if ( !ATTR_CHAR( *p ) ) {
4550 return LDAP_INVALID_SYNTAX;
4554 return LDAP_SUCCESS;
4557 struct syntax_defs_rec {
4560 slap_syntax_validate_func *sd_validate;
4561 slap_syntax_transform_func *sd_normalize;
4562 slap_syntax_transform_func *sd_pretty;
4563 #ifdef SLAPD_BINARY_CONVERSION
4564 slap_syntax_transform_func *sd_ber2str;
4565 slap_syntax_transform_func *sd_str2ber;
4569 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4570 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4572 struct syntax_defs_rec syntax_defs[] = {
4573 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4574 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4575 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4576 0, NULL, NULL, NULL},
4577 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4578 0, NULL, NULL, NULL},
4579 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4580 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4581 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4582 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4583 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4584 0, bitStringValidate, bitStringNormalize, NULL },
4585 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4586 0, booleanValidate, NULL, NULL},
4587 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4588 X_BINARY X_NOT_H_R ")",
4589 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4590 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4591 X_BINARY X_NOT_H_R ")",
4592 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4593 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4594 X_BINARY X_NOT_H_R ")",
4595 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4596 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4597 0, countryStringValidate, IA5StringNormalize, NULL},
4598 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4599 0, dnValidate, dnNormalize, dnPretty},
4600 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4601 0, NULL, NULL, NULL},
4602 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4603 0, NULL, NULL, NULL},
4604 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4605 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4606 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4607 0, NULL, NULL, NULL},
4608 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4609 0, NULL, NULL, NULL},
4610 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4611 0, NULL, NULL, NULL},
4612 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4613 0, NULL, NULL, NULL},
4614 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4615 0, NULL, NULL, NULL},
4616 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4617 0, printablesStringValidate, IA5StringNormalize, NULL},
4618 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4619 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4620 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4621 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4622 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4623 0, NULL, NULL, NULL},
4624 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4625 0, IA5StringValidate, IA5StringNormalize, NULL},
4626 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4627 0, integerValidate, integerNormalize, NULL},
4628 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4629 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4630 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4631 0, NULL, NULL, NULL},
4632 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4633 0, NULL, NULL, NULL},
4634 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4635 0, NULL, NULL, NULL},
4636 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4637 0, NULL, NULL, NULL},
4638 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4639 0, NULL, NULL, NULL},
4640 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4641 0, nameUIDValidate, nameUIDNormalize, NULL},
4642 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4643 0, NULL, NULL, NULL},
4644 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4645 0, numericStringValidate, numericStringNormalize, NULL},
4646 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4647 0, NULL, NULL, NULL},
4648 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4649 0, oidValidate, NULL, NULL},
4650 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4651 0, IA5StringValidate, IA5StringNormalize, NULL},
4652 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4653 0, blobValidate, NULL, NULL},
4654 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4655 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4656 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4657 0, NULL, NULL, NULL},
4658 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4659 0, NULL, NULL, NULL},
4660 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4661 0, printableStringValidate, IA5StringNormalize, NULL},
4662 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4663 X_BINARY X_NOT_H_R ")",
4664 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4665 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4666 0, printableStringValidate, IA5StringNormalize, NULL},
4667 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4668 0, NULL, NULL, NULL},
4669 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4670 0, printablesStringValidate, IA5StringNormalize, NULL},
4671 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4672 0, utcTimeValidate, utcTimeNormalize, NULL},
4673 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4674 0, NULL, NULL, NULL},
4675 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4676 0, NULL, NULL, NULL},
4677 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4678 0, NULL, NULL, NULL},
4679 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4680 0, NULL, NULL, NULL},
4681 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4682 0, NULL, NULL, NULL},
4684 /* RFC 2307 NIS Syntaxes */
4685 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4686 0, nisNetgroupTripleValidate, NULL, NULL},
4687 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4688 0, bootParameterValidate, NULL, NULL},
4692 /* These OIDs are not published yet, but will be in the next
4693 * I-D for PKIX LDAPv3 schema as have been advanced by David
4694 * Chadwick in private mail.
4696 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4697 0, NULL, NULL, NULL},
4700 /* OpenLDAP Experimental Syntaxes */
4701 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4703 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4706 /* needs updating */
4707 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4708 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4710 /* OpenLDAP Void Syntax */
4711 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4712 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4713 {NULL, 0, NULL, NULL, NULL}
4716 struct mrule_defs_rec {
4718 slap_mask_t mrd_usage;
4719 slap_mr_convert_func * mrd_convert;
4720 slap_mr_normalize_func * mrd_normalize;
4721 slap_mr_match_func * mrd_match;
4722 slap_mr_indexer_func * mrd_indexer;
4723 slap_mr_filter_func * mrd_filter;
4725 char * mrd_associated;
4729 * Other matching rules in X.520 that we do not use (yet):
4731 * 2.5.13.9 numericStringOrderingMatch
4732 * 2.5.13.15 integerOrderingMatch
4733 * 2.5.13.18 octetStringOrderingMatch
4734 * 2.5.13.19 octetStringSubstringsMatch
4735 * 2.5.13.25 uTCTimeMatch
4736 * 2.5.13.26 uTCTimeOrderingMatch
4737 * 2.5.13.31 directoryStringFirstComponentMatch
4738 * 2.5.13.32 wordMatch
4739 * 2.5.13.33 keywordMatch
4740 * 2.5.13.35 certificateMatch
4741 * 2.5.13.36 certificatePairExactMatch
4742 * 2.5.13.37 certificatePairMatch
4743 * 2.5.13.38 certificateListExactMatch
4744 * 2.5.13.39 certificateListMatch
4745 * 2.5.13.40 algorithmIdentifierMatch
4746 * 2.5.13.41 storedPrefixMatch
4747 * 2.5.13.42 attributeCertificateMatch
4748 * 2.5.13.43 readerAndKeyIDMatch
4749 * 2.5.13.44 attributeIntegrityMatch
4752 struct mrule_defs_rec mrule_defs[] = {
4754 * EQUALITY matching rules must be listed after associated APPROX
4755 * matching rules. So, we list all APPROX matching rules first.
4757 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4758 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4759 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4761 directoryStringApproxMatch,
4762 directoryStringApproxIndexer,
4763 directoryStringApproxFilter,
4766 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4767 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4768 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4770 IA5StringApproxMatch,
4771 IA5StringApproxIndexer,
4772 IA5StringApproxFilter,
4776 * Other matching rules
4779 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4780 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4781 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4783 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4786 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4787 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4788 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4790 dnMatch, dnIndexer, dnFilter,
4793 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4794 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4795 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4797 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4798 directoryStringApproxMatchOID },
4800 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4801 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4804 caseIgnoreOrderingMatch, NULL, NULL,
4807 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4808 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4809 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4811 caseExactIgnoreSubstringsMatch,
4812 caseExactIgnoreSubstringsIndexer,
4813 caseExactIgnoreSubstringsFilter,
4816 {"( 2.5.13.5 NAME 'caseExactMatch' "
4817 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4818 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4820 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4821 directoryStringApproxMatchOID },
4823 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4824 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4827 caseExactOrderingMatch, NULL, NULL,
4830 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4831 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4832 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4834 caseExactIgnoreSubstringsMatch,
4835 caseExactIgnoreSubstringsIndexer,
4836 caseExactIgnoreSubstringsFilter,
4839 {"( 2.5.13.8 NAME 'numericStringMatch' "
4840 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4841 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4844 caseIgnoreIA5Indexer,
4845 caseIgnoreIA5Filter,
4848 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4849 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4850 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4852 caseIgnoreIA5SubstringsMatch,
4853 caseIgnoreIA5SubstringsIndexer,
4854 caseIgnoreIA5SubstringsFilter,
4857 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4858 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4859 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4861 caseIgnoreListMatch, NULL, NULL,
4864 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4865 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4866 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4868 caseIgnoreListSubstringsMatch, NULL, NULL,
4871 {"( 2.5.13.13 NAME 'booleanMatch' "
4872 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4873 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4875 booleanMatch, NULL, NULL,
4878 {"( 2.5.13.14 NAME 'integerMatch' "
4879 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4880 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4882 integerMatch, integerIndexer, integerFilter,
4885 {"( 2.5.13.16 NAME 'bitStringMatch' "
4886 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4887 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4889 bitStringMatch, bitStringIndexer, bitStringFilter,
4892 {"( 2.5.13.17 NAME 'octetStringMatch' "
4893 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4894 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4896 octetStringMatch, octetStringIndexer, octetStringFilter,
4899 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4900 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4901 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4903 telephoneNumberMatch,
4904 telephoneNumberIndexer,
4905 telephoneNumberFilter,
4908 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4909 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4910 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4912 telephoneNumberSubstringsMatch,
4913 telephoneNumberSubstringsIndexer,
4914 telephoneNumberSubstringsFilter,
4917 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4918 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4919 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4924 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4925 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4926 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4928 uniqueMemberMatch, NULL, NULL,
4931 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4932 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4933 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4935 protocolInformationMatch, NULL, NULL,
4938 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4939 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4940 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4942 generalizedTimeMatch, NULL, NULL,
4945 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4946 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4949 generalizedTimeOrderingMatch, NULL, NULL,
4952 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4953 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4954 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4956 integerFirstComponentMatch, NULL, NULL,
4959 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4960 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4961 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4963 objectIdentifierFirstComponentMatch, NULL, NULL,
4967 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4968 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4969 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4970 certificateExactConvert, NULL,
4971 certificateExactMatch,
4972 certificateExactIndexer, certificateExactFilter,
4976 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4977 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4978 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4980 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4981 IA5StringApproxMatchOID },
4983 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4984 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4985 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4987 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4988 IA5StringApproxMatchOID },
4990 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4991 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4994 caseIgnoreIA5SubstringsMatch,
4995 caseIgnoreIA5SubstringsIndexer,
4996 caseIgnoreIA5SubstringsFilter,
4999 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
5000 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
5003 caseExactIA5SubstringsMatch,
5004 caseExactIA5SubstringsIndexer,
5005 caseExactIA5SubstringsFilter,
5008 /* needs updating */
5009 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
5010 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
5013 authPasswordMatch, NULL, NULL,
5016 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
5017 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
5020 OpenLDAPaciMatch, NULL, NULL,
5023 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
5024 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5027 integerBitAndMatch, NULL, NULL,
5030 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
5031 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5034 integerBitOrMatch, NULL, NULL,
5037 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
5046 /* we should only be called once (from main) */
5047 assert( schema_init_done == 0 );
5049 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
5050 res = register_syntax( syntax_defs[i].sd_desc,
5051 syntax_defs[i].sd_flags,
5052 syntax_defs[i].sd_validate,
5053 syntax_defs[i].sd_normalize,
5054 syntax_defs[i].sd_pretty
5055 #ifdef SLAPD_BINARY_CONVERSION
5057 syntax_defs[i].sd_ber2str,
5058 syntax_defs[i].sd_str2ber
5063 fprintf( stderr, "schema_init: Error registering syntax %s\n",
5064 syntax_defs[i].sd_desc );
5069 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
5070 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
5072 "schema_init: Ingoring unusable matching rule %s\n",
5073 mrule_defs[i].mrd_desc );
5077 res = register_matching_rule(
5078 mrule_defs[i].mrd_desc,
5079 mrule_defs[i].mrd_usage,
5080 mrule_defs[i].mrd_convert,
5081 mrule_defs[i].mrd_normalize,
5082 mrule_defs[i].mrd_match,
5083 mrule_defs[i].mrd_indexer,
5084 mrule_defs[i].mrd_filter,
5085 mrule_defs[i].mrd_associated );
5089 "schema_init: Error registering matching rule %s\n",
5090 mrule_defs[i].mrd_desc );
5094 schema_init_done = 1;
5095 return LDAP_SUCCESS;
5099 schema_destroy( void )