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 #ifndef USE_LDAP_DN_PARSING
37 #endif /* !USE_LDAP_DN_PARSING */
38 #define integerPretty NULL
40 /* recycled matching routines */
41 #define bitStringMatch octetStringMatch
42 #define numericStringMatch caseIgnoreIA5Match
43 #define objectIdentifierMatch caseIgnoreIA5Match
44 #define telephoneNumberMatch caseIgnoreIA5Match
45 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
46 #define generalizedTimeMatch caseIgnoreIA5Match
47 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
48 #define uniqueMemberMatch dnMatch
50 /* approx matching rules */
51 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
52 #define directoryStringApproxMatch approxMatch
53 #define directoryStringApproxIndexer approxIndexer
54 #define directoryStringApproxFilter approxFilter
55 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
56 #define IA5StringApproxMatch approxMatch
57 #define IA5StringApproxIndexer approxIndexer
58 #define IA5StringApproxFilter approxFilter
60 /* orderring matching rules */
61 #define caseIgnoreOrderingMatch caseIgnoreMatch
62 #define caseExactOrderingMatch caseExactMatch
64 /* unimplemented matching routines */
65 #define caseIgnoreListMatch NULL
66 #define caseIgnoreListSubstringsMatch NULL
67 #define protocolInformationMatch NULL
68 #define integerFirstComponentMatch NULL
70 #define OpenLDAPaciMatch NULL
71 #define authPasswordMatch NULL
73 /* recycled indexing/filtering routines */
74 #define dnIndexer caseExactIgnoreIndexer
75 #define dnFilter caseExactIgnoreFilter
76 #define bitStringFilter octetStringFilter
77 #define bitStringIndexer octetStringIndexer
79 #define telephoneNumberIndexer caseIgnoreIA5Indexer
80 #define telephoneNumberFilter caseIgnoreIA5Filter
81 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
82 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
84 /* must match OIDs below */
85 #define caseExactMatchOID "2.5.13.5"
86 #define caseExactSubstringsMatchOID "2.5.13.7"
88 static char *strcasechr( const char *str, int c )
90 char *lower = strchr( str, TOLOWER(c) );
91 char *upper = strchr( str, TOUPPER(c) );
93 if( lower && upper ) {
94 return lower < upper ? lower : upper;
108 struct berval *value,
109 void *assertedValue )
111 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
114 match = memcmp( value->bv_val,
115 ((struct berval *) assertedValue)->bv_val,
123 /* Index generation function */
124 int octetStringIndexer(
129 struct berval *prefix,
130 struct berval **values,
131 struct berval ***keysp )
135 struct berval **keys;
136 HASH_CONTEXT HASHcontext;
137 unsigned char HASHdigest[HASH_BYTES];
138 struct berval digest;
139 digest.bv_val = HASHdigest;
140 digest.bv_len = sizeof(HASHdigest);
142 for( i=0; values[i] != NULL; i++ ) {
143 /* just count them */
146 /* we should have at least one value at this point */
149 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
151 slen = strlen( syntax->ssyn_oid );
152 mlen = strlen( mr->smr_oid );
154 for( i=0; values[i] != NULL; i++ ) {
155 HASH_Init( &HASHcontext );
156 if( prefix != NULL && prefix->bv_len > 0 ) {
157 HASH_Update( &HASHcontext,
158 prefix->bv_val, prefix->bv_len );
160 HASH_Update( &HASHcontext,
161 syntax->ssyn_oid, slen );
162 HASH_Update( &HASHcontext,
164 HASH_Update( &HASHcontext,
165 values[i]->bv_val, values[i]->bv_len );
166 HASH_Final( HASHdigest, &HASHcontext );
168 keys[i] = ber_bvdup( &digest );
178 /* Index generation function */
179 int octetStringFilter(
184 struct berval *prefix,
186 struct berval ***keysp )
189 struct berval **keys;
190 HASH_CONTEXT HASHcontext;
191 unsigned char HASHdigest[HASH_BYTES];
192 struct berval *value = (struct berval *) assertValue;
193 struct berval digest;
194 digest.bv_val = HASHdigest;
195 digest.bv_len = sizeof(HASHdigest);
197 slen = strlen( syntax->ssyn_oid );
198 mlen = strlen( mr->smr_oid );
200 keys = ch_malloc( sizeof( struct berval * ) * 2 );
202 HASH_Init( &HASHcontext );
203 if( prefix != NULL && prefix->bv_len > 0 ) {
204 HASH_Update( &HASHcontext,
205 prefix->bv_val, prefix->bv_len );
207 HASH_Update( &HASHcontext,
208 syntax->ssyn_oid, slen );
209 HASH_Update( &HASHcontext,
211 HASH_Update( &HASHcontext,
212 value->bv_val, value->bv_len );
213 HASH_Final( HASHdigest, &HASHcontext );
215 keys[0] = ber_bvdup( &digest );
223 #ifdef USE_LDAP_DN_PARSING
232 if ( in->bv_len == 0 ) {
233 return( LDAP_SUCCESS );
236 rc = ldap_str2dn( in->bv_val, &dn, LDAP_DN_FORMAT_LDAPV3 );
237 ldapava_free_dn( dn );
239 if ( rc != LDAP_SUCCESS ) {
240 return( LDAP_INVALID_SYNTAX );
243 return( LDAP_SUCCESS );
247 AVA_Sort( LDAPRDN *rdn, int iAVA )
250 LDAPAVA *ava_in = rdn[ iAVA ][ 0 ];
252 for ( i = 0; i < iAVA; i++ ) {
253 LDAPAVA *ava = rdn[ i ][ 0 ];
256 a = strcmp( ava_in->la_attr->bv_val, ava->la_attr->bv_val );
265 d = ava_in->la_value->bv_len - ava->la_value->bv_len;
267 v = memcmp( ava_in->la_value->bv_val,
268 ava->la_value->bv_val,
269 d <= 0 ? ava_in->la_value->bv_len
270 : ava->la_value->bv_len );
272 if ( v == 0 && d != 0 ) {
291 a = strcmp( ava_in->la_value->bv_val,
292 ava->la_value->bv_val );
298 for ( j = iAVA; j > i; j-- ) {
299 rdn[ j ][ 0 ] = rdn[ j - 1 ][ 0 ];
301 rdn[ i ][ 0 ] = ava_in;
308 * In-place normalization of the structural representation
309 * of a distinguished name
312 DN_Normalize( LDAPDN *dn )
319 for ( iRDN = 0; dn[ iRDN ]; iRDN++ ) {
320 LDAPRDN *rdn = dn[ iRDN ][ 0 ];
323 for ( iAVA = 0; rdn[ iAVA ]; iAVA++ ) {
324 LDAPAVA *ava = rdn[ iAVA ][ 0 ];
325 AttributeDescription *ad = NULL;
326 const char *text = NULL;
327 slap_syntax_transform_func *nf = NULL;
328 struct berval *bv = NULL;
330 rc = slap_bv2ad( ava->la_attr, &ad, &text );
331 if ( rc != LDAP_SUCCESS ) {
332 return( LDAP_INVALID_SYNTAX );
336 * FIXME: is this required?
338 ber_bvfree( ava->la_attr );
339 ava->la_attr = ber_bvdup( &ad->ad_cname );
342 * FIXME: What is this intended for?
344 nf = ad->ad_type->sat_syntax->ssyn_normalize;
349 rc = ( *nf )( ad->ad_type->sat_syntax,
350 ava->la_value, &bv );
352 if ( rc != LDAP_SUCCESS ) {
353 return( LDAP_INVALID_SYNTAX );
357 * FIXME: shouldn't this happen inside
358 * ssyn_normalize if the syntax is case
361 if ( !( ava->la_flags & LDAP_AVA_BINARY ) ) {
362 struct berval *s = bv;
364 bv = ber_bvstr( UTF8normalize( bv,
369 ber_bvfree( ava->la_value );
372 AVA_Sort( rdn, iAVA );
376 return( LDAP_SUCCESS );
383 struct berval **normalized )
385 struct berval *out = NULL;
387 Debug( LDAP_DEBUG_TRACE, ">>> dnNormalize: %s\n", val->bv_val, 0, 0 );
389 if ( val->bv_len != 0 ) {
395 * Go to structural representation
397 rc = ldap_str2dn( val->bv_val, &dn, LDAP_DN_FORMAT_LDAPV3 );
398 if ( rc != LDAP_SUCCESS ) {
399 return( LDAP_INVALID_SYNTAX );
403 * Add schema-aware normalization stuff
405 if ( DN_Normalize( dn ) != LDAP_SUCCESS ) {
410 * Back to string representation
412 rc = ldap_dn2str( dn, &dn_out, LDAP_DN_FORMAT_LDAPV3 );
414 if ( rc != LDAP_SUCCESS ) {
416 ldapava_free_dn( dn );
417 return( LDAP_INVALID_SYNTAX );
420 ldapava_free_dn( dn );
422 out = ber_bvstr( dn_out );
425 out = ber_bvdup( val );
428 Debug( LDAP_DEBUG_TRACE, "<<< dnNormalize: %s\n", out->bv_val, 0, 0 );
432 return( LDAP_SUCCESS );
439 struct berval **normalized)
441 struct berval *out = NULL;
443 if ( val->bv_len != 0 ) {
446 unsigned flags = LDAP_DN_FORMAT_LDAPV3;
449 rc = ldap_str2dn( val->bv_val, &dn, flags );
450 if ( rc != LDAP_SUCCESS ) {
451 return( LDAP_INVALID_SYNTAX );
454 flags |= LDAP_DN_PRETTY;
456 rc = ldap_dn2str( dn, &dn_out, flags );
457 ldapava_free_dn( dn );
459 if ( rc != LDAP_SUCCESS ) {
460 return( LDAP_INVALID_SYNTAX );
463 out = ber_bvstr( dn_out );
466 out = ber_bvdup( val );
471 return( LDAP_SUCCESS );
480 struct berval *value,
481 void *assertedValue )
484 struct berval *asserted = (struct berval *) assertedValue;
486 match = value->bv_len - asserted->bv_len;
489 #ifdef USE_DN_NORMALIZE
490 match = strcmp( value->bv_val, asserted->bv_val );
491 fprintf(stderr, "USE_DN_NORMALIZE :(\n");
493 match = strcasecmp( value->bv_val, asserted->bv_val );
494 fprintf(stderr, "!USE_DN_NORMALIZE :)\n");
499 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
500 "dnMatch: %d\n %s\n %s\n", match,
501 value->bv_val, asserted->bv_val ));
503 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
504 match, value->bv_val, asserted->bv_val );
508 return( LDAP_SUCCESS );
511 #else /* !USE_LDAP_DN_PARSING */
521 if( in->bv_len == 0 ) return LDAP_SUCCESS;
523 dn = ch_strdup( in->bv_val );
526 return LDAP_INVALID_SYNTAX;
528 } else if ( strlen( in->bv_val ) != in->bv_len ) {
529 rc = LDAP_INVALID_SYNTAX;
531 } else if ( dn_validate( dn ) == NULL ) {
532 rc = LDAP_INVALID_SYNTAX;
546 struct berval **normalized )
550 if ( val->bv_len != 0 ) {
552 out = ber_bvstr( UTF8normalize( val, UTF8_CASEFOLD ) );
554 dn = dn_validate( out->bv_val );
558 return LDAP_INVALID_SYNTAX;
562 out->bv_len = strlen( dn );
564 out = ber_bvdup( val );
577 struct berval *value,
578 void *assertedValue )
581 struct berval *asserted = (struct berval *) assertedValue;
583 match = value->bv_len - asserted->bv_len;
586 #ifdef USE_DN_NORMALIZE
587 match = strcmp( value->bv_val, asserted->bv_val );
589 match = strcasecmp( value->bv_val, asserted->bv_val );
594 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
595 "dnMatch: %d\n %s\n %s\n", match,
596 value->bv_val, asserted->bv_val ));
598 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
599 match, value->bv_val, asserted->bv_val );
607 #endif /* !USE_LDAP_DN_PARSING */
617 if( in->bv_len == 0 ) return LDAP_SUCCESS;
619 dn = ber_bvdup( in );
621 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
622 /* assume presence of optional UID */
625 for(i=dn->bv_len-2; i>2; i--) {
626 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
630 if( dn->bv_val[i] != '\'' ||
631 dn->bv_val[i-1] != 'B' ||
632 dn->bv_val[i-2] != '#' ) {
634 return LDAP_INVALID_SYNTAX;
637 /* trim the UID to allow use of dn_validate */
638 dn->bv_val[i-2] = '\0';
641 rc = dn_validate( dn->bv_val ) == NULL
642 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
652 struct berval **normalized )
654 struct berval *out = ber_bvdup( val );
656 if( out->bv_len != 0 ) {
660 ber_len_t uidlen = 0;
662 if( out->bv_val[out->bv_len-1] == '\'' ) {
663 /* assume presence of optional UID */
664 uid = strrchr( out->bv_val, '#' );
668 return LDAP_INVALID_SYNTAX;
671 uidlen = out->bv_len - (out->bv_val - uid);
672 /* temporarily trim the UID */
676 #ifdef USE_DN_NORMALIZE
677 dn = dn_normalize( out->bv_val );
679 dn = dn_validate( out->bv_val );
684 return LDAP_INVALID_SYNTAX;
690 /* restore the separator */
693 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
697 out->bv_len = dnlen + uidlen;
709 /* any value allowed */
718 /* any value allowed */
729 /* very unforgiving validation, requires no normalization
730 * before simplistic matching
732 if( in->bv_len < 3 ) {
733 return LDAP_INVALID_SYNTAX;
737 * rfc 2252 section 6.3 Bit String
738 * bitstring = "'" *binary-digit "'"
739 * binary-digit = "0" / "1"
740 * example: '0101111101'B
743 if( in->bv_val[0] != '\'' ||
744 in->bv_val[in->bv_len-2] != '\'' ||
745 in->bv_val[in->bv_len-1] != 'B' )
747 return LDAP_INVALID_SYNTAX;
750 for( i=in->bv_len-3; i>0; i-- ) {
751 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
752 return LDAP_INVALID_SYNTAX;
763 struct berval **normalized )
766 * A normalized bitString is has no extaneous (leading) zero bits.
767 * That is, '00010'B is normalized to '10'B
768 * However, as a special case, '0'B requires no normalization.
770 struct berval *newval;
773 /* start at the first bit */
776 /* Find the first non-zero bit */
777 while ( *p == '0' ) p++;
779 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
782 /* no non-zero bits */
783 newval->bv_val = ch_strdup("\'0\'B");
784 newval->bv_len = sizeof("\'0\'B") - 1;
788 newval->bv_val = ch_malloc( val->bv_len + 1 );
790 newval->bv_val[0] = '\'';
793 for( ; *p != '\0'; p++ ) {
794 newval->bv_val[newval->bv_len++] = *p;
797 newval->bv_val[newval->bv_len] = '\0';
800 *normalized = newval;
805 * Handling boolean syntax and matching is quite rigid.
806 * A more flexible approach would be to allow a variety
807 * of strings to be normalized and prettied into TRUE
815 /* very unforgiving validation, requires no normalization
816 * before simplistic matching
819 if( in->bv_len == 4 ) {
820 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
823 } else if( in->bv_len == 5 ) {
824 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
829 return LDAP_INVALID_SYNTAX;
838 struct berval *value,
839 void *assertedValue )
841 /* simplistic matching allowed by rigid validation */
842 struct berval *asserted = (struct berval *) assertedValue;
843 *matchp = value->bv_len != asserted->bv_len;
854 unsigned char *u = in->bv_val;
856 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
858 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
859 /* get the length indicated by the first byte */
860 len = LDAP_UTF8_CHARLEN( u );
862 /* should not be zero */
863 if( len == 0 ) return LDAP_INVALID_SYNTAX;
865 /* make sure len corresponds with the offset
866 to the next character */
867 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
870 if( count != 0 ) return LDAP_INVALID_SYNTAX;
879 struct berval **normalized )
881 struct berval *newval;
884 newval = ch_malloc( sizeof( struct berval ) );
888 /* Ignore initial whitespace */
889 while ( ldap_utf8_isspace( p ) ) {
895 return LDAP_INVALID_SYNTAX;
898 newval->bv_val = ch_strdup( p );
899 p = q = newval->bv_val;
905 if ( ldap_utf8_isspace( p ) ) {
906 len = LDAP_UTF8_COPY(q,p);
911 /* Ignore the extra whitespace */
912 while ( ldap_utf8_isspace( p ) ) {
916 len = LDAP_UTF8_COPY(q,p);
923 assert( *newval->bv_val );
924 assert( newval->bv_val < p );
927 /* cannot start with a space */
928 assert( !ldap_utf8_isspace(newval->bv_val) );
931 * If the string ended in space, backup the pointer one
932 * position. One is enough because the above loop collapsed
933 * all whitespace to a single space.
940 /* cannot end with a space */
941 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
946 newval->bv_len = q - newval->bv_val;
947 *normalized = newval;
952 /* Returns Unicode cannonically normalized copy of a substring assertion
953 * Skipping attribute description */
954 SubstringsAssertion *
955 UTF8SubstringsassertionNormalize(
956 SubstringsAssertion *sa,
959 SubstringsAssertion *nsa;
962 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
967 if( sa->sa_initial != NULL ) {
968 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
969 if( nsa->sa_initial == NULL ) {
974 if( sa->sa_any != NULL ) {
975 for( i=0; sa->sa_any[i] != NULL; i++ ) {
978 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
979 for( i=0; sa->sa_any[i] != NULL; i++ ) {
980 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
981 if( nsa->sa_any[i] == NULL ) {
985 nsa->sa_any[i] = NULL;
988 if( sa->sa_final != NULL ) {
989 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
990 if( nsa->sa_final == NULL ) {
998 ber_bvfree( nsa->sa_final );
999 ber_bvecfree( nsa->sa_any );
1000 ber_bvfree( nsa->sa_initial );
1005 /* Strip characters with the 8th bit set */
1018 while( *++q & 0x80 ) {
1021 p = memmove(p, q, strlen(q) + 1);
1029 #ifndef SLAPD_APPROX_OLDSINGLESTRING
1031 #if defined(SLAPD_APPROX_INITIALS)
1032 #define SLAPD_APPROX_DELIMITER "._ "
1033 #define SLAPD_APPROX_WORDLEN 2
1035 #define SLAPD_APPROX_DELIMITER " "
1036 #define SLAPD_APPROX_WORDLEN 1
1045 struct berval *value,
1046 void *assertedValue )
1048 char *val, *nval, *assertv, **values, **words, *c;
1049 int i, count, len, nextchunk=0, nextavail=0;
1052 /* Yes, this is necessary */
1053 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
1054 if( nval == NULL ) {
1056 return LDAP_SUCCESS;
1058 strip8bitChars( nval );
1060 /* Yes, this is necessary */
1061 assertv = UTF8normalize( ((struct berval *)assertedValue),
1063 if( assertv == NULL ) {
1066 return LDAP_SUCCESS;
1068 strip8bitChars( assertv );
1069 avlen = strlen( assertv );
1071 /* Isolate how many words there are */
1072 for( c=nval,count=1; *c; c++ ) {
1073 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
1074 if ( c == NULL ) break;
1079 /* Get a phonetic copy of each word */
1080 words = (char **)ch_malloc( count * sizeof(char *) );
1081 values = (char **)ch_malloc( count * sizeof(char *) );
1082 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
1084 values[i] = phonetic(c);
1087 /* Work through the asserted value's words, to see if at least some
1088 of the words are there, in the same order. */
1090 while ( nextchunk < avlen ) {
1091 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
1096 #if defined(SLAPD_APPROX_INITIALS)
1097 else if( len == 1 ) {
1098 /* Single letter words need to at least match one word's initial */
1099 for( i=nextavail; i<count; i++ )
1100 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
1107 /* Isolate the next word in the asserted value and phonetic it */
1108 assertv[nextchunk+len] = '\0';
1109 val = phonetic( assertv + nextchunk );
1111 /* See if this phonetic chunk is in the remaining words of *value */
1112 for( i=nextavail; i<count; i++ ){
1113 if( !strcmp( val, values[i] ) ){
1121 /* This chunk in the asserted value was NOT within the *value. */
1127 /* Go on to the next word in the asserted value */
1131 /* If some of the words were seen, call it a match */
1132 if( nextavail > 0 ) {
1139 /* Cleanup allocs */
1141 for( i=0; i<count; i++ ) {
1142 ch_free( values[i] );
1148 return LDAP_SUCCESS;
1157 struct berval *prefix,
1158 struct berval **values,
1159 struct berval ***keysp )
1162 int i,j, len, wordcount, keycount=0;
1163 struct berval **newkeys, **keys=NULL;
1165 for( j=0; values[j] != NULL; j++ ) {
1166 /* Yes, this is necessary */
1167 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
1168 strip8bitChars( val );
1170 /* Isolate how many words there are. There will be a key for each */
1171 for( wordcount=0,c=val; *c; c++) {
1172 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1173 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
1175 if (*c == '\0') break;
1179 /* Allocate/increase storage to account for new keys */
1180 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
1181 * sizeof(struct berval *) );
1182 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
1183 if( keys ) ch_free( keys );
1186 /* Get a phonetic copy of each word */
1187 for( c=val,i=0; i<wordcount; c+=len+1 ) {
1189 if( len < SLAPD_APPROX_WORDLEN ) continue;
1190 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
1191 keys[keycount]->bv_val = phonetic( c );
1192 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
1199 keys[keycount] = NULL;
1202 return LDAP_SUCCESS;
1211 struct berval *prefix,
1213 struct berval ***keysp )
1217 struct berval **keys;
1219 /* Yes, this is necessary */
1220 val = UTF8normalize( ((struct berval *)assertValue),
1223 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
1226 return LDAP_SUCCESS;
1228 strip8bitChars( val );
1230 /* Isolate how many words there are. There will be a key for each */
1231 for( count=0,c=val; *c; c++) {
1232 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1233 if( len >= SLAPD_APPROX_WORDLEN ) count++;
1235 if (*c == '\0') break;
1239 /* Allocate storage for new keys */
1240 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
1242 /* Get a phonetic copy of each word */
1243 for( c=val,i=0; i<count; c+=len+1 ) {
1245 if( len < SLAPD_APPROX_WORDLEN ) continue;
1246 keys[i] = ber_bvstr( phonetic( c ) );
1255 return LDAP_SUCCESS;
1260 /* No other form of Approximate Matching is defined */
1268 struct berval *value,
1269 void *assertedValue )
1271 char *vapprox, *avapprox;
1274 /* Yes, this is necessary */
1275 s = UTF8normalize( value, UTF8_NOCASEFOLD );
1278 return LDAP_SUCCESS;
1281 /* Yes, this is necessary */
1282 t = UTF8normalize( ((struct berval *)assertedValue),
1287 return LDAP_SUCCESS;
1290 vapprox = phonetic( strip8bitChars( s ) );
1291 avapprox = phonetic( strip8bitChars( t ) );
1296 *matchp = strcmp( vapprox, avapprox );
1299 ch_free( avapprox );
1301 return LDAP_SUCCESS;
1310 struct berval *prefix,
1311 struct berval **values,
1312 struct berval ***keysp )
1315 struct berval **keys;
1318 for( i=0; values[i] != NULL; i++ ) {
1319 /* empty - just count them */
1322 /* we should have at least one value at this point */
1325 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
1327 /* Copy each value and run it through phonetic() */
1328 for( i=0; values[i] != NULL; i++ ) {
1329 /* Yes, this is necessary */
1330 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
1332 /* strip 8-bit chars and run through phonetic() */
1333 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1339 return LDAP_SUCCESS;
1349 struct berval *prefix,
1351 struct berval ***keysp )
1353 struct berval **keys;
1356 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1358 /* Yes, this is necessary */
1359 s = UTF8normalize( ((struct berval *)assertValue),
1364 /* strip 8-bit chars and run through phonetic() */
1365 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1371 return LDAP_SUCCESS;
1382 struct berval *value,
1383 void *assertedValue )
1385 *matchp = UTF8normcmp( value->bv_val,
1386 ((struct berval *) assertedValue)->bv_val,
1388 return LDAP_SUCCESS;
1392 caseExactIgnoreSubstringsMatch(
1397 struct berval *value,
1398 void *assertedValue )
1401 SubstringsAssertion *sub = NULL;
1405 char *nav, casefold;
1407 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1408 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1410 nav = UTF8normalize( value, casefold );
1416 left.bv_len = strlen( nav );
1418 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1424 /* Add up asserted input length */
1425 if( sub->sa_initial ) {
1426 inlen += sub->sa_initial->bv_len;
1429 for(i=0; sub->sa_any[i] != NULL; i++) {
1430 inlen += sub->sa_any[i]->bv_len;
1433 if( sub->sa_final ) {
1434 inlen += sub->sa_final->bv_len;
1437 if( sub->sa_initial ) {
1438 if( inlen > left.bv_len ) {
1443 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1444 sub->sa_initial->bv_len );
1450 left.bv_val += sub->sa_initial->bv_len;
1451 left.bv_len -= sub->sa_initial->bv_len;
1452 inlen -= sub->sa_initial->bv_len;
1455 if( sub->sa_final ) {
1456 if( inlen > left.bv_len ) {
1461 match = strncmp( sub->sa_final->bv_val,
1462 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1463 sub->sa_final->bv_len );
1469 left.bv_len -= sub->sa_final->bv_len;
1470 inlen -= sub->sa_final->bv_len;
1474 for(i=0; sub->sa_any[i]; i++) {
1479 if( inlen > left.bv_len ) {
1480 /* not enough length */
1485 if( sub->sa_any[i]->bv_len == 0 ) {
1489 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1496 idx = p - left.bv_val;
1497 assert( idx < left.bv_len );
1499 if( idx >= left.bv_len ) {
1500 /* this shouldn't happen */
1502 ch_free( sub->sa_final );
1503 ber_bvecfree( sub->sa_any );
1504 ch_free( sub->sa_initial );
1512 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1513 /* not enough left */
1518 match = strncmp( left.bv_val,
1519 sub->sa_any[i]->bv_val,
1520 sub->sa_any[i]->bv_len );
1528 left.bv_val += sub->sa_any[i]->bv_len;
1529 left.bv_len -= sub->sa_any[i]->bv_len;
1530 inlen -= sub->sa_any[i]->bv_len;
1537 ber_bvfree( sub->sa_final );
1538 ber_bvecfree( sub->sa_any );
1539 ber_bvfree( sub->sa_initial );
1543 return LDAP_SUCCESS;
1546 /* Index generation function */
1547 int caseExactIgnoreIndexer(
1552 struct berval *prefix,
1553 struct berval **values,
1554 struct berval ***keysp )
1559 struct berval **keys;
1560 HASH_CONTEXT HASHcontext;
1561 unsigned char HASHdigest[HASH_BYTES];
1562 struct berval digest;
1563 digest.bv_val = HASHdigest;
1564 digest.bv_len = sizeof(HASHdigest);
1566 for( i=0; values[i] != NULL; i++ ) {
1567 /* empty - just count them */
1570 /* we should have at least one value at this point */
1573 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1575 slen = strlen( syntax->ssyn_oid );
1576 mlen = strlen( mr->smr_oid );
1578 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1579 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1581 for( i=0; values[i] != NULL; i++ ) {
1582 struct berval *value;
1583 value = ber_bvstr( UTF8normalize( values[i],
1586 HASH_Init( &HASHcontext );
1587 if( prefix != NULL && prefix->bv_len > 0 ) {
1588 HASH_Update( &HASHcontext,
1589 prefix->bv_val, prefix->bv_len );
1591 HASH_Update( &HASHcontext,
1592 syntax->ssyn_oid, slen );
1593 HASH_Update( &HASHcontext,
1594 mr->smr_oid, mlen );
1595 HASH_Update( &HASHcontext,
1596 value->bv_val, value->bv_len );
1597 HASH_Final( HASHdigest, &HASHcontext );
1599 ber_bvfree( value );
1601 keys[i] = ber_bvdup( &digest );
1606 return LDAP_SUCCESS;
1609 /* Index generation function */
1610 int caseExactIgnoreFilter(
1615 struct berval *prefix,
1617 struct berval ***keysp )
1621 struct berval **keys;
1622 HASH_CONTEXT HASHcontext;
1623 unsigned char HASHdigest[HASH_BYTES];
1624 struct berval *value;
1625 struct berval digest;
1626 digest.bv_val = HASHdigest;
1627 digest.bv_len = sizeof(HASHdigest);
1629 slen = strlen( syntax->ssyn_oid );
1630 mlen = strlen( mr->smr_oid );
1632 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1633 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1635 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
1637 /* This usually happens if filter contains bad UTF8 */
1638 if( value == NULL ) {
1639 keys = ch_malloc( sizeof( struct berval * ) );
1641 return LDAP_SUCCESS;
1644 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1646 HASH_Init( &HASHcontext );
1647 if( prefix != NULL && prefix->bv_len > 0 ) {
1648 HASH_Update( &HASHcontext,
1649 prefix->bv_val, prefix->bv_len );
1651 HASH_Update( &HASHcontext,
1652 syntax->ssyn_oid, slen );
1653 HASH_Update( &HASHcontext,
1654 mr->smr_oid, mlen );
1655 HASH_Update( &HASHcontext,
1656 value->bv_val, value->bv_len );
1657 HASH_Final( HASHdigest, &HASHcontext );
1659 keys[0] = ber_bvdup( &digest );
1662 ber_bvfree( value );
1665 return LDAP_SUCCESS;
1668 /* Substrings Index generation function */
1669 int caseExactIgnoreSubstringsIndexer(
1674 struct berval *prefix,
1675 struct berval **values,
1676 struct berval ***keysp )
1681 struct berval **keys;
1682 struct berval **nvalues;
1684 HASH_CONTEXT HASHcontext;
1685 unsigned char HASHdigest[HASH_BYTES];
1686 struct berval digest;
1687 digest.bv_val = HASHdigest;
1688 digest.bv_len = sizeof(HASHdigest);
1692 for( i=0; values[i] != NULL; i++ ) {
1693 /* empty - just count them */
1696 /* we should have at least one value at this point */
1699 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1700 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1702 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1703 for( i=0; values[i] != NULL; i++ ) {
1704 nvalues[i] = ber_bvstr( UTF8normalize( values[i],
1710 for( i=0; values[i] != NULL; i++ ) {
1711 /* count number of indices to generate */
1712 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1716 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1717 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1718 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1719 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1721 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1725 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1726 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1727 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1731 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1732 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1733 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1734 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1736 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1742 /* no keys to generate */
1744 ber_bvecfree( nvalues );
1745 return LDAP_SUCCESS;
1748 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1750 slen = strlen( syntax->ssyn_oid );
1751 mlen = strlen( mr->smr_oid );
1754 for( i=0; values[i] != NULL; i++ ) {
1756 struct berval *value;
1758 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1762 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1763 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1765 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1766 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1768 for( j=0; j<max; j++ ) {
1769 HASH_Init( &HASHcontext );
1770 if( prefix != NULL && prefix->bv_len > 0 ) {
1771 HASH_Update( &HASHcontext,
1772 prefix->bv_val, prefix->bv_len );
1775 HASH_Update( &HASHcontext,
1776 &pre, sizeof( pre ) );
1777 HASH_Update( &HASHcontext,
1778 syntax->ssyn_oid, slen );
1779 HASH_Update( &HASHcontext,
1780 mr->smr_oid, mlen );
1781 HASH_Update( &HASHcontext,
1783 SLAP_INDEX_SUBSTR_MAXLEN );
1784 HASH_Final( HASHdigest, &HASHcontext );
1786 keys[nkeys++] = ber_bvdup( &digest );
1790 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1791 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1793 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1796 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1797 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1798 HASH_Init( &HASHcontext );
1799 if( prefix != NULL && prefix->bv_len > 0 ) {
1800 HASH_Update( &HASHcontext,
1801 prefix->bv_val, prefix->bv_len );
1803 HASH_Update( &HASHcontext,
1804 &pre, sizeof( pre ) );
1805 HASH_Update( &HASHcontext,
1806 syntax->ssyn_oid, slen );
1807 HASH_Update( &HASHcontext,
1808 mr->smr_oid, mlen );
1809 HASH_Update( &HASHcontext,
1811 HASH_Final( HASHdigest, &HASHcontext );
1813 keys[nkeys++] = ber_bvdup( &digest );
1816 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1817 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1818 HASH_Init( &HASHcontext );
1819 if( prefix != NULL && prefix->bv_len > 0 ) {
1820 HASH_Update( &HASHcontext,
1821 prefix->bv_val, prefix->bv_len );
1823 HASH_Update( &HASHcontext,
1824 &pre, sizeof( pre ) );
1825 HASH_Update( &HASHcontext,
1826 syntax->ssyn_oid, slen );
1827 HASH_Update( &HASHcontext,
1828 mr->smr_oid, mlen );
1829 HASH_Update( &HASHcontext,
1830 &value->bv_val[value->bv_len-j], j );
1831 HASH_Final( HASHdigest, &HASHcontext );
1833 keys[nkeys++] = ber_bvdup( &digest );
1848 ber_bvecfree( nvalues );
1850 return LDAP_SUCCESS;
1853 int caseExactIgnoreSubstringsFilter(
1858 struct berval *prefix,
1860 struct berval ***keysp )
1862 SubstringsAssertion *sa;
1864 ber_len_t nkeys = 0;
1865 size_t slen, mlen, klen;
1866 struct berval **keys;
1867 HASH_CONTEXT HASHcontext;
1868 unsigned char HASHdigest[HASH_BYTES];
1869 struct berval *value;
1870 struct berval digest;
1872 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1873 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1875 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1878 return LDAP_SUCCESS;
1881 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1882 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1887 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1889 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1890 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1891 /* don't bother accounting for stepping */
1892 nkeys += sa->sa_any[i]->bv_len -
1893 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1898 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1899 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1905 ber_bvfree( sa->sa_final );
1906 ber_bvecfree( sa->sa_any );
1907 ber_bvfree( sa->sa_initial );
1910 return LDAP_SUCCESS;
1913 digest.bv_val = HASHdigest;
1914 digest.bv_len = sizeof(HASHdigest);
1916 slen = strlen( syntax->ssyn_oid );
1917 mlen = strlen( mr->smr_oid );
1919 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1922 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1923 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1925 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1926 value = sa->sa_initial;
1928 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1929 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1931 HASH_Init( &HASHcontext );
1932 if( prefix != NULL && prefix->bv_len > 0 ) {
1933 HASH_Update( &HASHcontext,
1934 prefix->bv_val, prefix->bv_len );
1936 HASH_Update( &HASHcontext,
1937 &pre, sizeof( pre ) );
1938 HASH_Update( &HASHcontext,
1939 syntax->ssyn_oid, slen );
1940 HASH_Update( &HASHcontext,
1941 mr->smr_oid, mlen );
1942 HASH_Update( &HASHcontext,
1943 value->bv_val, klen );
1944 HASH_Final( HASHdigest, &HASHcontext );
1946 keys[nkeys++] = ber_bvdup( &digest );
1949 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1951 pre = SLAP_INDEX_SUBSTR_PREFIX;
1952 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1954 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1955 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1959 value = sa->sa_any[i];
1962 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1963 j += SLAP_INDEX_SUBSTR_STEP )
1965 HASH_Init( &HASHcontext );
1966 if( prefix != NULL && prefix->bv_len > 0 ) {
1967 HASH_Update( &HASHcontext,
1968 prefix->bv_val, prefix->bv_len );
1970 HASH_Update( &HASHcontext,
1971 &pre, sizeof( pre ) );
1972 HASH_Update( &HASHcontext,
1973 syntax->ssyn_oid, slen );
1974 HASH_Update( &HASHcontext,
1975 mr->smr_oid, mlen );
1976 HASH_Update( &HASHcontext,
1977 &value->bv_val[j], klen );
1978 HASH_Final( HASHdigest, &HASHcontext );
1980 keys[nkeys++] = ber_bvdup( &digest );
1986 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1987 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1989 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1990 value = sa->sa_final;
1992 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1993 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1995 HASH_Init( &HASHcontext );
1996 if( prefix != NULL && prefix->bv_len > 0 ) {
1997 HASH_Update( &HASHcontext,
1998 prefix->bv_val, prefix->bv_len );
2000 HASH_Update( &HASHcontext,
2001 &pre, sizeof( pre ) );
2002 HASH_Update( &HASHcontext,
2003 syntax->ssyn_oid, slen );
2004 HASH_Update( &HASHcontext,
2005 mr->smr_oid, mlen );
2006 HASH_Update( &HASHcontext,
2007 &value->bv_val[value->bv_len-klen], klen );
2008 HASH_Final( HASHdigest, &HASHcontext );
2010 keys[nkeys++] = ber_bvdup( &digest );
2020 ber_bvfree( sa->sa_final );
2021 ber_bvecfree( sa->sa_any );
2022 ber_bvfree( sa->sa_initial );
2025 return LDAP_SUCCESS;
2034 struct berval *value,
2035 void *assertedValue )
2037 *matchp = UTF8normcmp( value->bv_val,
2038 ((struct berval *) assertedValue)->bv_val,
2040 return LDAP_SUCCESS;
2046 struct berval *val )
2050 if( val->bv_len == 0 ) {
2051 /* disallow empty strings */
2052 return LDAP_INVALID_SYNTAX;
2055 if( OID_LEADCHAR(val->bv_val[0]) ) {
2057 for(i=1; i < val->bv_len; i++) {
2058 if( OID_SEPARATOR( val->bv_val[i] ) ) {
2059 if( dot++ ) return 1;
2060 } else if ( OID_CHAR( val->bv_val[i] ) ) {
2063 return LDAP_INVALID_SYNTAX;
2067 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
2069 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
2070 for(i=1; i < val->bv_len; i++) {
2071 if( !DESC_CHAR(val->bv_val[i] ) ) {
2072 return LDAP_INVALID_SYNTAX;
2076 return LDAP_SUCCESS;
2079 return LDAP_INVALID_SYNTAX;
2088 struct berval *value,
2089 void *assertedValue )
2092 int vsign=0, avsign=0;
2093 struct berval *asserted;
2094 ber_len_t vlen, avlen;
2097 /* Start off pessimistic */
2100 /* Skip past leading spaces/zeros, and get the sign of the *value number */
2102 vlen = value->bv_len;
2104 if( ASCII_SPACE(*v) || ( *v == '0' )) {
2105 /* empty -- skip spaces */
2107 else if ( *v == '+' ) {
2110 else if ( *v == '-' ) {
2113 else if ( ASCII_DIGIT(*v) ) {
2114 if ( vsign == 0 ) vsign = 1;
2122 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
2124 asserted = (struct berval *) assertedValue;
2125 av = asserted->bv_val;
2126 avlen = asserted->bv_len;
2128 if( ASCII_SPACE(*av) || ( *av == '0' )) {
2129 /* empty -- skip spaces */
2131 else if ( *av == '+' ) {
2134 else if ( *av == '-' ) {
2137 else if ( ASCII_DIGIT(*av) ) {
2138 if ( avsign == 0 ) avsign = 1;
2146 /* The two ?sign vars are now one of :
2147 -2 negative non-zero number
2149 0 0 collapse these three to 0
2151 +2 positive non-zero number
2153 if ( abs( vsign ) == 1 ) vsign = 0;
2154 if ( abs( avsign ) == 1 ) avsign = 0;
2156 if( vsign != avsign ) return LDAP_SUCCESS;
2158 /* Check the significant digits */
2159 while( vlen && avlen ) {
2160 if( *v != *av ) break;
2167 /* If all digits compared equal, the numbers are equal */
2168 if(( vlen == 0 ) && ( avlen == 0 )) {
2171 return LDAP_SUCCESS;
2177 struct berval *val )
2181 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2183 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
2184 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
2185 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
2186 return LDAP_INVALID_SYNTAX;
2189 for( i=1; i < val->bv_len; i++ ) {
2190 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2193 return LDAP_SUCCESS;
2200 struct berval **normalized )
2204 struct berval *newval;
2211 /* Ignore leading spaces */
2212 while ( len && ( *p == ' ' )) {
2219 negative = ( *p == '-' );
2220 if(( *p == '-' ) || ( *p == '+' )) {
2226 /* Ignore leading zeros */
2227 while ( len && ( *p == '0' )) {
2232 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
2234 /* If there are no non-zero digits left, the number is zero, otherwise
2235 allocate space for the number and copy it into the buffer */
2237 newval->bv_val = ch_strdup("0");
2241 newval->bv_len = len+negative;
2242 newval->bv_val = ch_malloc( newval->bv_len );
2244 newval->bv_val[0] = '-';
2246 memcpy( newval->bv_val + negative, p, len );
2249 *normalized = newval;
2250 return LDAP_SUCCESS;
2253 /* Index generation function */
2259 struct berval *prefix,
2260 struct berval **values,
2261 struct berval ***keysp )
2264 struct berval **keys;
2266 /* we should have at least one value at this point */
2267 assert( values != NULL && values[0] != NULL );
2269 for( i=0; values[i] != NULL; i++ ) {
2270 /* empty -- just count them */
2273 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2275 for( i=0; values[i] != NULL; i++ ) {
2276 integerNormalize( syntax, values[i], &keys[i] );
2281 return LDAP_SUCCESS;
2284 /* Index generation function */
2290 struct berval *prefix,
2292 struct berval ***keysp )
2294 struct berval **keys;
2296 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2297 integerNormalize( syntax, assertValue, &keys[0] );
2301 return LDAP_SUCCESS;
2306 countryStringValidate(
2308 struct berval *val )
2310 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2312 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2313 return LDAP_INVALID_SYNTAX;
2315 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2316 return LDAP_INVALID_SYNTAX;
2319 return LDAP_SUCCESS;
2323 printableStringValidate(
2325 struct berval *val )
2329 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2331 for(i=0; i < val->bv_len; i++) {
2332 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2333 return LDAP_INVALID_SYNTAX;
2337 return LDAP_SUCCESS;
2341 printablesStringValidate(
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_PRINTABLES(val->bv_val[i]) ) {
2351 return LDAP_INVALID_SYNTAX;
2355 return LDAP_SUCCESS;
2361 struct berval *val )
2365 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2367 for(i=0; i < val->bv_len; i++) {
2368 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2371 return LDAP_SUCCESS;
2378 struct berval **normalized )
2380 struct berval *newval;
2383 newval = ch_malloc( sizeof( struct berval ) );
2387 /* Ignore initial whitespace */
2388 while ( ASCII_SPACE( *p ) ) {
2394 return LDAP_INVALID_SYNTAX;
2397 newval->bv_val = ch_strdup( p );
2398 p = q = newval->bv_val;
2401 if ( ASCII_SPACE( *p ) ) {
2404 /* Ignore the extra whitespace */
2405 while ( ASCII_SPACE( *p ) ) {
2413 assert( *newval->bv_val );
2414 assert( newval->bv_val < p );
2417 /* cannot start with a space */
2418 assert( !ASCII_SPACE(*newval->bv_val) );
2421 * If the string ended in space, backup the pointer one
2422 * position. One is enough because the above loop collapsed
2423 * all whitespace to a single space.
2426 if ( ASCII_SPACE( q[-1] ) ) {
2430 /* cannot end with a space */
2431 assert( !ASCII_SPACE( q[-1] ) );
2433 /* null terminate */
2436 newval->bv_len = q - newval->bv_val;
2437 *normalized = newval;
2439 return LDAP_SUCCESS;
2448 struct berval *value,
2449 void *assertedValue )
2451 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2454 match = strncmp( value->bv_val,
2455 ((struct berval *) assertedValue)->bv_val,
2460 return LDAP_SUCCESS;
2464 caseExactIA5SubstringsMatch(
2469 struct berval *value,
2470 void *assertedValue )
2473 SubstringsAssertion *sub = assertedValue;
2474 struct berval left = *value;
2478 /* Add up asserted input length */
2479 if( sub->sa_initial ) {
2480 inlen += sub->sa_initial->bv_len;
2483 for(i=0; sub->sa_any[i] != NULL; i++) {
2484 inlen += sub->sa_any[i]->bv_len;
2487 if( sub->sa_final ) {
2488 inlen += sub->sa_final->bv_len;
2491 if( sub->sa_initial ) {
2492 if( inlen > left.bv_len ) {
2497 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2498 sub->sa_initial->bv_len );
2504 left.bv_val += sub->sa_initial->bv_len;
2505 left.bv_len -= sub->sa_initial->bv_len;
2506 inlen -= sub->sa_initial->bv_len;
2509 if( sub->sa_final ) {
2510 if( inlen > left.bv_len ) {
2515 match = strncmp( sub->sa_final->bv_val,
2516 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2517 sub->sa_final->bv_len );
2523 left.bv_len -= sub->sa_final->bv_len;
2524 inlen -= sub->sa_final->bv_len;
2528 for(i=0; sub->sa_any[i]; i++) {
2533 if( inlen > left.bv_len ) {
2534 /* not enough length */
2539 if( sub->sa_any[i]->bv_len == 0 ) {
2543 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2550 idx = p - left.bv_val;
2551 assert( idx < left.bv_len );
2553 if( idx >= left.bv_len ) {
2554 /* this shouldn't happen */
2561 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2562 /* not enough left */
2567 match = strncmp( left.bv_val,
2568 sub->sa_any[i]->bv_val,
2569 sub->sa_any[i]->bv_len );
2577 left.bv_val += sub->sa_any[i]->bv_len;
2578 left.bv_len -= sub->sa_any[i]->bv_len;
2579 inlen -= sub->sa_any[i]->bv_len;
2585 return LDAP_SUCCESS;
2588 /* Index generation function */
2589 int caseExactIA5Indexer(
2594 struct berval *prefix,
2595 struct berval **values,
2596 struct berval ***keysp )
2600 struct berval **keys;
2601 HASH_CONTEXT HASHcontext;
2602 unsigned char HASHdigest[HASH_BYTES];
2603 struct berval digest;
2604 digest.bv_val = HASHdigest;
2605 digest.bv_len = sizeof(HASHdigest);
2607 for( i=0; values[i] != NULL; i++ ) {
2608 /* empty - just count them */
2611 /* we should have at least one value at this point */
2614 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2616 slen = strlen( syntax->ssyn_oid );
2617 mlen = strlen( mr->smr_oid );
2619 for( i=0; values[i] != NULL; i++ ) {
2620 struct berval *value = values[i];
2622 HASH_Init( &HASHcontext );
2623 if( prefix != NULL && prefix->bv_len > 0 ) {
2624 HASH_Update( &HASHcontext,
2625 prefix->bv_val, prefix->bv_len );
2627 HASH_Update( &HASHcontext,
2628 syntax->ssyn_oid, slen );
2629 HASH_Update( &HASHcontext,
2630 mr->smr_oid, mlen );
2631 HASH_Update( &HASHcontext,
2632 value->bv_val, value->bv_len );
2633 HASH_Final( HASHdigest, &HASHcontext );
2635 keys[i] = ber_bvdup( &digest );
2640 return LDAP_SUCCESS;
2643 /* Index generation function */
2644 int caseExactIA5Filter(
2649 struct berval *prefix,
2651 struct berval ***keysp )
2654 struct berval **keys;
2655 HASH_CONTEXT HASHcontext;
2656 unsigned char HASHdigest[HASH_BYTES];
2657 struct berval *value;
2658 struct berval digest;
2659 digest.bv_val = HASHdigest;
2660 digest.bv_len = sizeof(HASHdigest);
2662 slen = strlen( syntax->ssyn_oid );
2663 mlen = strlen( mr->smr_oid );
2665 value = (struct berval *) assertValue;
2667 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2669 HASH_Init( &HASHcontext );
2670 if( prefix != NULL && prefix->bv_len > 0 ) {
2671 HASH_Update( &HASHcontext,
2672 prefix->bv_val, prefix->bv_len );
2674 HASH_Update( &HASHcontext,
2675 syntax->ssyn_oid, slen );
2676 HASH_Update( &HASHcontext,
2677 mr->smr_oid, mlen );
2678 HASH_Update( &HASHcontext,
2679 value->bv_val, value->bv_len );
2680 HASH_Final( HASHdigest, &HASHcontext );
2682 keys[0] = ber_bvdup( &digest );
2686 return LDAP_SUCCESS;
2689 /* Substrings Index generation function */
2690 int caseExactIA5SubstringsIndexer(
2695 struct berval *prefix,
2696 struct berval **values,
2697 struct berval ***keysp )
2701 struct berval **keys;
2702 HASH_CONTEXT HASHcontext;
2703 unsigned char HASHdigest[HASH_BYTES];
2704 struct berval digest;
2705 digest.bv_val = HASHdigest;
2706 digest.bv_len = sizeof(HASHdigest);
2708 /* we should have at least one value at this point */
2709 assert( values != NULL && values[0] != NULL );
2712 for( i=0; values[i] != NULL; i++ ) {
2713 /* count number of indices to generate */
2714 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2718 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2719 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2720 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2721 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2723 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2727 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2728 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2729 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2733 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2734 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2735 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2736 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2738 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2744 /* no keys to generate */
2746 return LDAP_SUCCESS;
2749 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2751 slen = strlen( syntax->ssyn_oid );
2752 mlen = strlen( mr->smr_oid );
2755 for( i=0; values[i] != NULL; i++ ) {
2757 struct berval *value;
2760 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2762 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2763 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2765 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2766 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2768 for( j=0; j<max; j++ ) {
2769 HASH_Init( &HASHcontext );
2770 if( prefix != NULL && prefix->bv_len > 0 ) {
2771 HASH_Update( &HASHcontext,
2772 prefix->bv_val, prefix->bv_len );
2775 HASH_Update( &HASHcontext,
2776 &pre, sizeof( pre ) );
2777 HASH_Update( &HASHcontext,
2778 syntax->ssyn_oid, slen );
2779 HASH_Update( &HASHcontext,
2780 mr->smr_oid, mlen );
2781 HASH_Update( &HASHcontext,
2783 SLAP_INDEX_SUBSTR_MAXLEN );
2784 HASH_Final( HASHdigest, &HASHcontext );
2786 keys[nkeys++] = ber_bvdup( &digest );
2790 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2791 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2793 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2796 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2797 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2798 HASH_Init( &HASHcontext );
2799 if( prefix != NULL && prefix->bv_len > 0 ) {
2800 HASH_Update( &HASHcontext,
2801 prefix->bv_val, prefix->bv_len );
2803 HASH_Update( &HASHcontext,
2804 &pre, sizeof( pre ) );
2805 HASH_Update( &HASHcontext,
2806 syntax->ssyn_oid, slen );
2807 HASH_Update( &HASHcontext,
2808 mr->smr_oid, mlen );
2809 HASH_Update( &HASHcontext,
2811 HASH_Final( HASHdigest, &HASHcontext );
2813 keys[nkeys++] = ber_bvdup( &digest );
2816 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2817 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2818 HASH_Init( &HASHcontext );
2819 if( prefix != NULL && prefix->bv_len > 0 ) {
2820 HASH_Update( &HASHcontext,
2821 prefix->bv_val, prefix->bv_len );
2823 HASH_Update( &HASHcontext,
2824 &pre, sizeof( pre ) );
2825 HASH_Update( &HASHcontext,
2826 syntax->ssyn_oid, slen );
2827 HASH_Update( &HASHcontext,
2828 mr->smr_oid, mlen );
2829 HASH_Update( &HASHcontext,
2830 &value->bv_val[value->bv_len-j], j );
2831 HASH_Final( HASHdigest, &HASHcontext );
2833 keys[nkeys++] = ber_bvdup( &digest );
2847 return LDAP_SUCCESS;
2850 int caseExactIA5SubstringsFilter(
2855 struct berval *prefix,
2857 struct berval ***keysp )
2859 SubstringsAssertion *sa = assertValue;
2861 ber_len_t nkeys = 0;
2862 size_t slen, mlen, klen;
2863 struct berval **keys;
2864 HASH_CONTEXT HASHcontext;
2865 unsigned char HASHdigest[HASH_BYTES];
2866 struct berval *value;
2867 struct berval digest;
2869 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2870 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2875 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2877 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2878 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2879 /* don't bother accounting for stepping */
2880 nkeys += sa->sa_any[i]->bv_len -
2881 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2886 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2887 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2894 return LDAP_SUCCESS;
2897 digest.bv_val = HASHdigest;
2898 digest.bv_len = sizeof(HASHdigest);
2900 slen = strlen( syntax->ssyn_oid );
2901 mlen = strlen( mr->smr_oid );
2903 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2906 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2907 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2909 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2910 value = sa->sa_initial;
2912 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2913 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2915 HASH_Init( &HASHcontext );
2916 if( prefix != NULL && prefix->bv_len > 0 ) {
2917 HASH_Update( &HASHcontext,
2918 prefix->bv_val, prefix->bv_len );
2920 HASH_Update( &HASHcontext,
2921 &pre, sizeof( pre ) );
2922 HASH_Update( &HASHcontext,
2923 syntax->ssyn_oid, slen );
2924 HASH_Update( &HASHcontext,
2925 mr->smr_oid, mlen );
2926 HASH_Update( &HASHcontext,
2927 value->bv_val, klen );
2928 HASH_Final( HASHdigest, &HASHcontext );
2930 keys[nkeys++] = ber_bvdup( &digest );
2933 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2935 pre = SLAP_INDEX_SUBSTR_PREFIX;
2936 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2938 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2939 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2943 value = sa->sa_any[i];
2946 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2947 j += SLAP_INDEX_SUBSTR_STEP )
2949 HASH_Init( &HASHcontext );
2950 if( prefix != NULL && prefix->bv_len > 0 ) {
2951 HASH_Update( &HASHcontext,
2952 prefix->bv_val, prefix->bv_len );
2954 HASH_Update( &HASHcontext,
2955 &pre, sizeof( pre ) );
2956 HASH_Update( &HASHcontext,
2957 syntax->ssyn_oid, slen );
2958 HASH_Update( &HASHcontext,
2959 mr->smr_oid, mlen );
2960 HASH_Update( &HASHcontext,
2961 &value->bv_val[j], klen );
2962 HASH_Final( HASHdigest, &HASHcontext );
2964 keys[nkeys++] = ber_bvdup( &digest );
2969 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2970 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2972 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2973 value = sa->sa_final;
2975 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2976 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2978 HASH_Init( &HASHcontext );
2979 if( prefix != NULL && prefix->bv_len > 0 ) {
2980 HASH_Update( &HASHcontext,
2981 prefix->bv_val, prefix->bv_len );
2983 HASH_Update( &HASHcontext,
2984 &pre, sizeof( pre ) );
2985 HASH_Update( &HASHcontext,
2986 syntax->ssyn_oid, slen );
2987 HASH_Update( &HASHcontext,
2988 mr->smr_oid, mlen );
2989 HASH_Update( &HASHcontext,
2990 &value->bv_val[value->bv_len-klen], klen );
2991 HASH_Final( HASHdigest, &HASHcontext );
2993 keys[nkeys++] = ber_bvdup( &digest );
3004 return LDAP_SUCCESS;
3013 struct berval *value,
3014 void *assertedValue )
3016 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
3018 if( match == 0 && value->bv_len ) {
3019 match = strncasecmp( value->bv_val,
3020 ((struct berval *) assertedValue)->bv_val,
3025 return LDAP_SUCCESS;
3029 caseIgnoreIA5SubstringsMatch(
3034 struct berval *value,
3035 void *assertedValue )
3038 SubstringsAssertion *sub = assertedValue;
3039 struct berval left = *value;
3043 /* Add up asserted input length */
3044 if( sub->sa_initial ) {
3045 inlen += sub->sa_initial->bv_len;
3048 for(i=0; sub->sa_any[i] != NULL; i++) {
3049 inlen += sub->sa_any[i]->bv_len;
3052 if( sub->sa_final ) {
3053 inlen += sub->sa_final->bv_len;
3056 if( sub->sa_initial ) {
3057 if( inlen > left.bv_len ) {
3062 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
3063 sub->sa_initial->bv_len );
3069 left.bv_val += sub->sa_initial->bv_len;
3070 left.bv_len -= sub->sa_initial->bv_len;
3071 inlen -= sub->sa_initial->bv_len;
3074 if( sub->sa_final ) {
3075 if( inlen > left.bv_len ) {
3080 match = strncasecmp( sub->sa_final->bv_val,
3081 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
3082 sub->sa_final->bv_len );
3088 left.bv_len -= sub->sa_final->bv_len;
3089 inlen -= sub->sa_final->bv_len;
3093 for(i=0; sub->sa_any[i]; i++) {
3098 if( inlen > left.bv_len ) {
3099 /* not enough length */
3104 if( sub->sa_any[i]->bv_len == 0 ) {
3108 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
3115 idx = p - left.bv_val;
3116 assert( idx < left.bv_len );
3118 if( idx >= left.bv_len ) {
3119 /* this shouldn't happen */
3126 if( sub->sa_any[i]->bv_len > left.bv_len ) {
3127 /* not enough left */
3132 match = strncasecmp( left.bv_val,
3133 sub->sa_any[i]->bv_val,
3134 sub->sa_any[i]->bv_len );
3143 left.bv_val += sub->sa_any[i]->bv_len;
3144 left.bv_len -= sub->sa_any[i]->bv_len;
3145 inlen -= sub->sa_any[i]->bv_len;
3151 return LDAP_SUCCESS;
3154 /* Index generation function */
3155 int caseIgnoreIA5Indexer(
3160 struct berval *prefix,
3161 struct berval **values,
3162 struct berval ***keysp )
3166 struct berval **keys;
3167 HASH_CONTEXT HASHcontext;
3168 unsigned char HASHdigest[HASH_BYTES];
3169 struct berval digest;
3170 digest.bv_val = HASHdigest;
3171 digest.bv_len = sizeof(HASHdigest);
3173 /* we should have at least one value at this point */
3174 assert( values != NULL && values[0] != NULL );
3176 for( i=0; values[i] != NULL; i++ ) {
3177 /* just count them */
3180 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3182 slen = strlen( syntax->ssyn_oid );
3183 mlen = strlen( mr->smr_oid );
3185 for( i=0; values[i] != NULL; i++ ) {
3186 struct berval *value = ber_bvdup( values[i] );
3187 ldap_pvt_str2upper( value->bv_val );
3189 HASH_Init( &HASHcontext );
3190 if( prefix != NULL && prefix->bv_len > 0 ) {
3191 HASH_Update( &HASHcontext,
3192 prefix->bv_val, prefix->bv_len );
3194 HASH_Update( &HASHcontext,
3195 syntax->ssyn_oid, slen );
3196 HASH_Update( &HASHcontext,
3197 mr->smr_oid, mlen );
3198 HASH_Update( &HASHcontext,
3199 value->bv_val, value->bv_len );
3200 HASH_Final( HASHdigest, &HASHcontext );
3202 ber_bvfree( value );
3204 keys[i] = ber_bvdup( &digest );
3209 return LDAP_SUCCESS;
3212 /* Index generation function */
3213 int caseIgnoreIA5Filter(
3218 struct berval *prefix,
3220 struct berval ***keysp )
3223 struct berval **keys;
3224 HASH_CONTEXT HASHcontext;
3225 unsigned char HASHdigest[HASH_BYTES];
3226 struct berval *value;
3227 struct berval digest;
3228 digest.bv_val = HASHdigest;
3229 digest.bv_len = sizeof(HASHdigest);
3231 slen = strlen( syntax->ssyn_oid );
3232 mlen = strlen( mr->smr_oid );
3234 value = ber_bvdup( (struct berval *) assertValue );
3235 ldap_pvt_str2upper( value->bv_val );
3237 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3239 HASH_Init( &HASHcontext );
3240 if( prefix != NULL && prefix->bv_len > 0 ) {
3241 HASH_Update( &HASHcontext,
3242 prefix->bv_val, prefix->bv_len );
3244 HASH_Update( &HASHcontext,
3245 syntax->ssyn_oid, slen );
3246 HASH_Update( &HASHcontext,
3247 mr->smr_oid, mlen );
3248 HASH_Update( &HASHcontext,
3249 value->bv_val, value->bv_len );
3250 HASH_Final( HASHdigest, &HASHcontext );
3252 keys[0] = ber_bvdup( &digest );
3255 ber_bvfree( value );
3259 return LDAP_SUCCESS;
3262 /* Substrings Index generation function */
3263 int caseIgnoreIA5SubstringsIndexer(
3268 struct berval *prefix,
3269 struct berval **values,
3270 struct berval ***keysp )
3274 struct berval **keys;
3275 HASH_CONTEXT HASHcontext;
3276 unsigned char HASHdigest[HASH_BYTES];
3277 struct berval digest;
3278 digest.bv_val = HASHdigest;
3279 digest.bv_len = sizeof(HASHdigest);
3281 /* we should have at least one value at this point */
3282 assert( values != NULL && values[0] != NULL );
3285 for( i=0; values[i] != NULL; i++ ) {
3286 /* count number of indices to generate */
3287 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
3291 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3292 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3293 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3294 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3296 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3300 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3301 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3302 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3306 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3307 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3308 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3309 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3311 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3317 /* no keys to generate */
3319 return LDAP_SUCCESS;
3322 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3324 slen = strlen( syntax->ssyn_oid );
3325 mlen = strlen( mr->smr_oid );
3328 for( i=0; values[i] != NULL; i++ ) {
3330 struct berval *value;
3332 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3334 value = ber_bvdup( values[i] );
3335 ldap_pvt_str2upper( value->bv_val );
3337 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3338 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3340 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3341 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3343 for( j=0; j<max; j++ ) {
3344 HASH_Init( &HASHcontext );
3345 if( prefix != NULL && prefix->bv_len > 0 ) {
3346 HASH_Update( &HASHcontext,
3347 prefix->bv_val, prefix->bv_len );
3350 HASH_Update( &HASHcontext,
3351 &pre, sizeof( pre ) );
3352 HASH_Update( &HASHcontext,
3353 syntax->ssyn_oid, slen );
3354 HASH_Update( &HASHcontext,
3355 mr->smr_oid, mlen );
3356 HASH_Update( &HASHcontext,
3358 SLAP_INDEX_SUBSTR_MAXLEN );
3359 HASH_Final( HASHdigest, &HASHcontext );
3361 keys[nkeys++] = ber_bvdup( &digest );
3365 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3366 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3368 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3371 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3372 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3373 HASH_Init( &HASHcontext );
3374 if( prefix != NULL && prefix->bv_len > 0 ) {
3375 HASH_Update( &HASHcontext,
3376 prefix->bv_val, prefix->bv_len );
3378 HASH_Update( &HASHcontext,
3379 &pre, sizeof( pre ) );
3380 HASH_Update( &HASHcontext,
3381 syntax->ssyn_oid, slen );
3382 HASH_Update( &HASHcontext,
3383 mr->smr_oid, mlen );
3384 HASH_Update( &HASHcontext,
3386 HASH_Final( HASHdigest, &HASHcontext );
3388 keys[nkeys++] = ber_bvdup( &digest );
3391 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3392 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3393 HASH_Init( &HASHcontext );
3394 if( prefix != NULL && prefix->bv_len > 0 ) {
3395 HASH_Update( &HASHcontext,
3396 prefix->bv_val, prefix->bv_len );
3398 HASH_Update( &HASHcontext,
3399 &pre, sizeof( pre ) );
3400 HASH_Update( &HASHcontext,
3401 syntax->ssyn_oid, slen );
3402 HASH_Update( &HASHcontext,
3403 mr->smr_oid, mlen );
3404 HASH_Update( &HASHcontext,
3405 &value->bv_val[value->bv_len-j], j );
3406 HASH_Final( HASHdigest, &HASHcontext );
3408 keys[nkeys++] = ber_bvdup( &digest );
3413 ber_bvfree( value );
3424 return LDAP_SUCCESS;
3427 int caseIgnoreIA5SubstringsFilter(
3432 struct berval *prefix,
3434 struct berval ***keysp )
3436 SubstringsAssertion *sa = assertValue;
3438 ber_len_t nkeys = 0;
3439 size_t slen, mlen, klen;
3440 struct berval **keys;
3441 HASH_CONTEXT HASHcontext;
3442 unsigned char HASHdigest[HASH_BYTES];
3443 struct berval *value;
3444 struct berval digest;
3446 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3447 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3452 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3454 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3455 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3456 /* don't bother accounting for stepping */
3457 nkeys += sa->sa_any[i]->bv_len -
3458 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3463 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3464 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3471 return LDAP_SUCCESS;
3474 digest.bv_val = HASHdigest;
3475 digest.bv_len = sizeof(HASHdigest);
3477 slen = strlen( syntax->ssyn_oid );
3478 mlen = strlen( mr->smr_oid );
3480 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3483 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3484 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3486 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3487 value = ber_bvdup( sa->sa_initial );
3488 ldap_pvt_str2upper( value->bv_val );
3490 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3491 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3493 HASH_Init( &HASHcontext );
3494 if( prefix != NULL && prefix->bv_len > 0 ) {
3495 HASH_Update( &HASHcontext,
3496 prefix->bv_val, prefix->bv_len );
3498 HASH_Update( &HASHcontext,
3499 &pre, sizeof( pre ) );
3500 HASH_Update( &HASHcontext,
3501 syntax->ssyn_oid, slen );
3502 HASH_Update( &HASHcontext,
3503 mr->smr_oid, mlen );
3504 HASH_Update( &HASHcontext,
3505 value->bv_val, klen );
3506 HASH_Final( HASHdigest, &HASHcontext );
3508 ber_bvfree( value );
3509 keys[nkeys++] = ber_bvdup( &digest );
3512 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3514 pre = SLAP_INDEX_SUBSTR_PREFIX;
3515 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3517 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3518 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3522 value = ber_bvdup( sa->sa_any[i] );
3523 ldap_pvt_str2upper( value->bv_val );
3526 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3527 j += SLAP_INDEX_SUBSTR_STEP )
3529 HASH_Init( &HASHcontext );
3530 if( prefix != NULL && prefix->bv_len > 0 ) {
3531 HASH_Update( &HASHcontext,
3532 prefix->bv_val, prefix->bv_len );
3534 HASH_Update( &HASHcontext,
3535 &pre, sizeof( pre ) );
3536 HASH_Update( &HASHcontext,
3537 syntax->ssyn_oid, slen );
3538 HASH_Update( &HASHcontext,
3539 mr->smr_oid, mlen );
3540 HASH_Update( &HASHcontext,
3541 &value->bv_val[j], klen );
3542 HASH_Final( HASHdigest, &HASHcontext );
3544 keys[nkeys++] = ber_bvdup( &digest );
3547 ber_bvfree( value );
3551 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3552 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3554 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3555 value = ber_bvdup( sa->sa_final );
3556 ldap_pvt_str2upper( value->bv_val );
3558 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3559 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3561 HASH_Init( &HASHcontext );
3562 if( prefix != NULL && prefix->bv_len > 0 ) {
3563 HASH_Update( &HASHcontext,
3564 prefix->bv_val, prefix->bv_len );
3566 HASH_Update( &HASHcontext,
3567 &pre, sizeof( pre ) );
3568 HASH_Update( &HASHcontext,
3569 syntax->ssyn_oid, slen );
3570 HASH_Update( &HASHcontext,
3571 mr->smr_oid, mlen );
3572 HASH_Update( &HASHcontext,
3573 &value->bv_val[value->bv_len-klen], klen );
3574 HASH_Final( HASHdigest, &HASHcontext );
3576 ber_bvfree( value );
3577 keys[nkeys++] = ber_bvdup( &digest );
3588 return LDAP_SUCCESS;
3592 numericStringValidate(
3598 for(i=0; i < in->bv_len; i++) {
3599 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3600 return LDAP_INVALID_SYNTAX;
3604 return LDAP_SUCCESS;
3608 numericStringNormalize(
3611 struct berval **normalized )
3613 /* removal all spaces */
3614 struct berval *newval;
3617 newval = ch_malloc( sizeof( struct berval ) );
3618 newval->bv_val = ch_malloc( val->bv_len + 1 );
3624 if ( ASCII_SPACE( *p ) ) {
3625 /* Ignore whitespace */
3632 /* we should have copied no more then is in val */
3633 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3635 /* null terminate */
3638 newval->bv_len = q - newval->bv_val;
3639 *normalized = newval;
3641 return LDAP_SUCCESS;
3645 objectIdentifierFirstComponentMatch(
3650 struct berval *value,
3651 void *assertedValue )
3653 int rc = LDAP_SUCCESS;
3655 struct berval *asserted = (struct berval *) assertedValue;
3659 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3660 return LDAP_INVALID_SYNTAX;
3663 /* trim leading white space */
3664 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3668 /* grab next word */
3669 oid.bv_val = &value->bv_val[i];
3670 oid.bv_len = value->bv_len - i;
3671 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3676 /* insert attributeTypes, objectclass check here */
3677 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3678 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3681 char *stored = ch_malloc( oid.bv_len + 1 );
3682 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3683 stored[oid.bv_len] = '\0';
3685 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3686 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3687 MatchingRule *stored_mr = mr_find( stored );
3689 if( asserted_mr == NULL ) {
3690 rc = SLAPD_COMPARE_UNDEFINED;
3692 match = asserted_mr != stored_mr;
3695 } else if ( !strcmp( syntax->ssyn_oid,
3696 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3698 AttributeType *asserted_at = at_find( asserted->bv_val );
3699 AttributeType *stored_at = at_find( stored );
3701 if( asserted_at == NULL ) {
3702 rc = SLAPD_COMPARE_UNDEFINED;
3704 match = asserted_at != stored_at;
3707 } else if ( !strcmp( syntax->ssyn_oid,
3708 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3710 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3711 ObjectClass *stored_oc = oc_find( stored );
3713 if( asserted_oc == NULL ) {
3714 rc = SLAPD_COMPARE_UNDEFINED;
3716 match = asserted_oc != stored_oc;
3724 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3725 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3726 match, value->bv_val, asserted->bv_val ));
3728 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3729 "%d\n\t\"%s\"\n\t\"%s\"\n",
3730 match, value->bv_val, asserted->bv_val );
3734 if( rc == LDAP_SUCCESS ) *matchp = match;
3744 struct berval *value,
3745 void *assertedValue )
3747 long lValue, lAssertedValue;
3749 /* safe to assume integers are NUL terminated? */
3750 lValue = strtoul(value->bv_val, NULL, 10);
3751 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3752 return LDAP_CONSTRAINT_VIOLATION;
3754 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3755 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3756 return LDAP_CONSTRAINT_VIOLATION;
3758 *matchp = (lValue & lAssertedValue);
3759 return LDAP_SUCCESS;
3768 struct berval *value,
3769 void *assertedValue )
3771 long lValue, lAssertedValue;
3773 /* safe to assume integers are NUL terminated? */
3774 lValue = strtoul(value->bv_val, NULL, 10);
3775 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3776 return LDAP_CONSTRAINT_VIOLATION;
3778 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3779 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3780 return LDAP_CONSTRAINT_VIOLATION;
3782 *matchp = (lValue | lAssertedValue);
3783 return LDAP_SUCCESS;
3787 #include <openssl/x509.h>
3788 #include <openssl/err.h>
3789 char digit[] = "0123456789";
3792 * Next function returns a string representation of a ASN1_INTEGER.
3793 * It works for unlimited lengths.
3796 static struct berval *
3797 asn1_integer2str(ASN1_INTEGER *a)
3802 /* We work backwards, make it fill from the end of buf */
3803 p = buf + sizeof(buf) - 1;
3806 if ( a == NULL || a->length == 0 ) {
3814 /* We want to preserve the original */
3815 copy = ch_malloc(n*sizeof(unsigned int));
3816 for (i = 0; i<n; i++) {
3817 copy[i] = a->data[i];
3821 * base indicates the index of the most significant
3822 * byte that might be nonzero. When it goes off the
3823 * end, we now there is nothing left to do.
3829 for (i = base; i<n; i++ ) {
3830 copy[i] += carry*256;
3831 carry = copy[i] % 10;
3836 * Way too large, we need to leave
3837 * room for sign if negative
3842 *--p = digit[carry];
3843 if (copy[base] == 0)
3849 if ( a->type == V_ASN1_NEG_INTEGER ) {
3853 return ber_bvstrdup(p);
3856 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3857 static struct berval *
3858 dn_openssl2ldap(X509_NAME *name)
3860 char issuer_dn[1024];
3863 bio = BIO_new(BIO_s_mem());
3866 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3867 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3868 ERR_error_string(ERR_get_error(),NULL)));
3870 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3871 "error creating BIO: %s\n",
3872 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3876 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3878 BIO_gets(bio, issuer_dn, 1024);
3881 return ber_bvstrdup(issuer_dn);
3885 * Given a certificate in DER format, extract the corresponding
3886 * assertion value for certificateExactMatch
3889 certificateExactConvert(
3891 struct berval ** out )
3894 unsigned char *p = in->bv_val;
3895 struct berval *serial;
3896 struct berval *issuer_dn;
3897 struct berval *bv_tmp;
3899 xcert = d2i_X509(NULL, &p, in->bv_len);
3902 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3903 "certificateExactConvert: error parsing cert: %s\n",
3904 ERR_error_string(ERR_get_error(),NULL)));
3906 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3907 "error parsing cert: %s\n",
3908 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3910 return LDAP_INVALID_SYNTAX;
3913 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3916 return LDAP_INVALID_SYNTAX;
3918 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3922 return LDAP_INVALID_SYNTAX;
3924 /* Actually, dn_openssl2ldap returns in a normalized format, but
3925 it is different from our normalized format */
3927 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3931 return LDAP_INVALID_SYNTAX;
3937 *out = ch_malloc(sizeof(struct berval));
3938 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3939 (*out)->bv_val = ch_malloc((*out)->bv_len);
3941 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3942 p += serial->bv_len;
3943 AC_MEMCPY(p, " $ ", 3);
3945 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3946 p += issuer_dn->bv_len;
3950 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3951 "certificateExactConvert: \n %s\n",
3954 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3956 (*out)->bv_val, NULL, NULL );
3960 ber_bvfree(issuer_dn);
3962 return LDAP_SUCCESS;
3966 serial_and_issuer_parse(
3967 struct berval *assertion,
3968 struct berval **serial,
3969 struct berval **issuer_dn
3977 begin = assertion->bv_val;
3978 end = assertion->bv_val+assertion->bv_len-1;
3979 for (p=begin; p<=end && *p != '$'; p++)
3982 return LDAP_INVALID_SYNTAX;
3984 /* p now points at the $ sign, now use begin and end to delimit the
3986 while (ASCII_SPACE(*begin))
3989 while (ASCII_SPACE(*end))
3992 q = ch_malloc( (end-begin+1)+1 );
3993 AC_MEMCPY( q, begin, end-begin+1 );
3994 q[end-begin+1] = '\0';
3995 *serial = ber_bvstr(q);
3997 /* now extract the issuer, remember p was at the dollar sign */
3999 end = assertion->bv_val+assertion->bv_len-1;
4000 while (ASCII_SPACE(*begin))
4002 /* should we trim spaces at the end too? is it safe always? */
4004 q = ch_malloc( (end-begin+1)+1 );
4005 AC_MEMCPY( q, begin, end-begin+1 );
4006 q[end-begin+1] = '\0';
4007 *issuer_dn = ber_bvstr(dn_normalize(q));
4009 return LDAP_SUCCESS;
4013 certificateExactMatch(
4018 struct berval *value,
4019 void *assertedValue )
4022 unsigned char *p = value->bv_val;
4023 struct berval *serial;
4024 struct berval *issuer_dn;
4025 struct berval *asserted_serial;
4026 struct berval *asserted_issuer_dn;
4029 xcert = d2i_X509(NULL, &p, value->bv_len);
4032 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4033 "certificateExactMatch: error parsing cert: %s\n",
4034 ERR_error_string(ERR_get_error(),NULL)));
4036 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
4037 "error parsing cert: %s\n",
4038 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
4040 return LDAP_INVALID_SYNTAX;
4043 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4044 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
4048 serial_and_issuer_parse(assertedValue,
4050 &asserted_issuer_dn);
4055 slap_schema.si_syn_integer,
4056 slap_schema.si_mr_integerMatch,
4059 if ( ret == LDAP_SUCCESS ) {
4060 if ( *matchp == 0 ) {
4061 /* We need to normalize everything for dnMatch */
4065 slap_schema.si_syn_distinguishedName,
4066 slap_schema.si_mr_distinguishedNameMatch,
4068 asserted_issuer_dn);
4073 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4074 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
4075 *matchp, serial->bv_val, issuer_dn->bv_val,
4076 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
4078 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
4079 "%d\n\t\"%s $ %s\"\n",
4080 *matchp, serial->bv_val, issuer_dn->bv_val );
4081 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
4082 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
4087 ber_bvfree(issuer_dn);
4088 ber_bvfree(asserted_serial);
4089 ber_bvfree(asserted_issuer_dn);
4095 * Index generation function
4096 * We just index the serials, in most scenarios the issuer DN is one of
4097 * a very small set of values.
4099 int certificateExactIndexer(
4104 struct berval *prefix,
4105 struct berval **values,
4106 struct berval ***keysp )
4109 struct berval **keys;
4112 struct berval * serial;
4114 /* we should have at least one value at this point */
4115 assert( values != NULL && values[0] != NULL );
4117 for( i=0; values[i] != NULL; i++ ) {
4118 /* empty -- just count them */
4121 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
4123 for( i=0; values[i] != NULL; i++ ) {
4124 p = values[i]->bv_val;
4125 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
4128 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4129 "certificateExactIndexer: error parsing cert: %s\n",
4130 ERR_error_string(ERR_get_error(),NULL)));
4132 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4133 "error parsing cert: %s\n",
4134 ERR_error_string(ERR_get_error(),NULL),
4137 /* Do we leak keys on error? */
4138 return LDAP_INVALID_SYNTAX;
4141 serial = asn1_integer2str(xcert->cert_info->serialNumber);
4143 integerNormalize( slap_schema.si_syn_integer,
4148 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
4149 "certificateExactIndexer: returning: %s\n",
4152 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
4161 return LDAP_SUCCESS;
4164 /* Index generation function */
4165 /* We think this is always called with a value in matching rule syntax */
4166 int certificateExactFilter(
4171 struct berval *prefix,
4173 struct berval ***keysp )
4175 struct berval **keys;
4176 struct berval *asserted_serial;
4177 struct berval *asserted_issuer_dn;
4179 serial_and_issuer_parse(assertValue,
4181 &asserted_issuer_dn);
4183 keys = ch_malloc( sizeof( struct berval * ) * 2 );
4184 integerNormalize( syntax, asserted_serial, &keys[0] );
4188 ber_bvfree(asserted_serial);
4189 ber_bvfree(asserted_issuer_dn);
4190 return LDAP_SUCCESS;
4195 check_time_syntax (struct berval *val,
4199 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
4200 static int mdays[2][12] = {
4201 /* non-leap years */
4202 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
4204 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
4207 int part, c, tzoffset, leapyear = 0 ;
4209 if( val->bv_len == 0 ) {
4210 return LDAP_INVALID_SYNTAX;
4213 p = (char *)val->bv_val;
4214 e = p + val->bv_len;
4216 /* Ignore initial whitespace */
4217 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4221 if (e - p < 13 - (2 * start)) {
4222 return LDAP_INVALID_SYNTAX;
4225 for (part = 0; part < 9; part++) {
4229 for (part = start; part < 7; part++) {
4231 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
4238 return LDAP_INVALID_SYNTAX;
4240 if (c < 0 || c > 9) {
4241 return LDAP_INVALID_SYNTAX;
4247 return LDAP_INVALID_SYNTAX;
4249 if (c < 0 || c > 9) {
4250 return LDAP_INVALID_SYNTAX;
4255 if (part == 2 || part == 3) {
4258 if (parts[part] < 0) {
4259 return LDAP_INVALID_SYNTAX;
4261 if (parts[part] > ceiling[part]) {
4262 return LDAP_INVALID_SYNTAX;
4266 /* leapyear check for the Gregorian calendar (year>1581) */
4267 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
4268 ((parts[0] % 4 == 0) && (parts[1] == 0)))
4273 if (parts[3] > mdays[leapyear][parts[2]]) {
4274 return LDAP_INVALID_SYNTAX;
4279 tzoffset = 0; /* UTC */
4280 } else if (c != '+' && c != '-') {
4281 return LDAP_INVALID_SYNTAX;
4285 } else /* c == '+' */ {
4290 return LDAP_INVALID_SYNTAX;
4293 for (part = 7; part < 9; part++) {
4295 if (c < 0 || c > 9) {
4296 return LDAP_INVALID_SYNTAX;
4301 if (c < 0 || c > 9) {
4302 return LDAP_INVALID_SYNTAX;
4306 if (parts[part] < 0 || parts[part] > ceiling[part]) {
4307 return LDAP_INVALID_SYNTAX;
4312 /* Ignore trailing whitespace */
4313 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4317 return LDAP_INVALID_SYNTAX;
4320 switch ( tzoffset ) {
4321 case -1: /* negativ offset to UTC, ie west of Greenwich */
4322 parts[4] += parts[7];
4323 parts[5] += parts[8];
4324 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
4328 c = mdays[leapyear][parts[2]];
4330 if (parts[part] > c) {
4331 parts[part] -= c + 1;
4336 case 1: /* positive offset to UTC, ie east of Greenwich */
4337 parts[4] -= parts[7];
4338 parts[5] -= parts[8];
4339 for (part = 6; --part > 0; ) {
4343 /* first arg to % needs to be non negativ */
4344 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
4346 if (parts[part] < 0) {
4347 parts[part] += c + 1;
4352 case 0: /* already UTC */
4356 return LDAP_SUCCESS;
4363 struct berval **normalized )
4368 rc = check_time_syntax(val, 1, parts);
4369 if (rc != LDAP_SUCCESS) {
4374 out = ch_malloc( sizeof(struct berval) );
4376 return LBER_ERROR_MEMORY;
4379 out->bv_val = ch_malloc( 14 );
4380 if ( out->bv_val == NULL ) {
4382 return LBER_ERROR_MEMORY;
4385 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02dZ",
4386 parts[1], parts[2] + 1, parts[3] + 1,
4387 parts[4], parts[5], parts[6] );
4391 return LDAP_SUCCESS;
4401 return check_time_syntax(in, 1, parts);
4405 generalizedTimeValidate(
4411 return check_time_syntax(in, 0, parts);
4415 generalizedTimeNormalize(
4418 struct berval **normalized )
4423 rc = check_time_syntax(val, 0, parts);
4424 if (rc != LDAP_SUCCESS) {
4429 out = ch_malloc( sizeof(struct berval) );
4431 return LBER_ERROR_MEMORY;
4434 out->bv_val = ch_malloc( 16 );
4435 if ( out->bv_val == NULL ) {
4437 return LBER_ERROR_MEMORY;
4440 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4441 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4442 parts[4], parts[5], parts[6] );
4446 return LDAP_SUCCESS;
4450 nisNetgroupTripleValidate(
4452 struct berval *val )
4457 if ( val->bv_len == 0 ) {
4458 return LDAP_INVALID_SYNTAX;
4461 p = (char *)val->bv_val;
4462 e = p + val->bv_len;
4464 if ( *p != '(' /*')'*/ ) {
4465 return LDAP_INVALID_SYNTAX;
4468 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4472 return LDAP_INVALID_SYNTAX;
4475 } else if ( !ATTR_CHAR( *p ) ) {
4476 return LDAP_INVALID_SYNTAX;
4480 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4481 return LDAP_INVALID_SYNTAX;
4487 return LDAP_INVALID_SYNTAX;
4490 return LDAP_SUCCESS;
4494 bootParameterValidate(
4496 struct berval *val )
4500 if ( val->bv_len == 0 ) {
4501 return LDAP_INVALID_SYNTAX;
4504 p = (char *)val->bv_val;
4505 e = p + val->bv_len;
4508 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4509 if ( !ATTR_CHAR( *p ) ) {
4510 return LDAP_INVALID_SYNTAX;
4515 return LDAP_INVALID_SYNTAX;
4519 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4520 if ( !ATTR_CHAR( *p ) ) {
4521 return LDAP_INVALID_SYNTAX;
4526 return LDAP_INVALID_SYNTAX;
4530 for ( p++; p < e; p++ ) {
4531 if ( !ATTR_CHAR( *p ) ) {
4532 return LDAP_INVALID_SYNTAX;
4536 return LDAP_SUCCESS;
4539 struct syntax_defs_rec {
4542 slap_syntax_validate_func *sd_validate;
4543 slap_syntax_transform_func *sd_normalize;
4544 slap_syntax_transform_func *sd_pretty;
4545 #ifdef SLAPD_BINARY_CONVERSION
4546 slap_syntax_transform_func *sd_ber2str;
4547 slap_syntax_transform_func *sd_str2ber;
4551 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4552 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4554 struct syntax_defs_rec syntax_defs[] = {
4555 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4556 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4557 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4558 0, NULL, NULL, NULL},
4559 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4560 0, NULL, NULL, NULL},
4561 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4562 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4563 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4564 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4565 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4566 0, bitStringValidate, bitStringNormalize, NULL },
4567 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4568 0, booleanValidate, NULL, NULL},
4569 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4570 X_BINARY X_NOT_H_R ")",
4571 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4572 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4573 X_BINARY X_NOT_H_R ")",
4574 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4575 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4576 X_BINARY X_NOT_H_R ")",
4577 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4578 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4579 0, countryStringValidate, IA5StringNormalize, NULL},
4580 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4581 0, dnValidate, dnNormalize, dnPretty},
4582 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4583 0, NULL, NULL, NULL},
4584 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4585 0, NULL, NULL, NULL},
4586 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4587 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4588 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4589 0, NULL, NULL, NULL},
4590 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4591 0, NULL, NULL, NULL},
4592 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4593 0, NULL, NULL, NULL},
4594 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4595 0, NULL, NULL, NULL},
4596 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4597 0, NULL, NULL, NULL},
4598 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4599 0, printablesStringValidate, IA5StringNormalize, NULL},
4600 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4601 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4602 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4603 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4604 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4605 0, NULL, NULL, NULL},
4606 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4607 0, IA5StringValidate, IA5StringNormalize, NULL},
4608 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4609 0, integerValidate, integerNormalize, NULL},
4610 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4611 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4612 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4613 0, NULL, NULL, NULL},
4614 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4615 0, NULL, NULL, NULL},
4616 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4617 0, NULL, NULL, NULL},
4618 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4619 0, NULL, NULL, NULL},
4620 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4621 0, NULL, NULL, NULL},
4622 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4623 0, nameUIDValidate, nameUIDNormalize, NULL},
4624 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4625 0, NULL, NULL, NULL},
4626 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4627 0, numericStringValidate, numericStringNormalize, NULL},
4628 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4629 0, NULL, NULL, NULL},
4630 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4631 0, oidValidate, NULL, NULL},
4632 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4633 0, IA5StringValidate, IA5StringNormalize, NULL},
4634 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4635 0, blobValidate, NULL, NULL},
4636 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4637 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4638 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4639 0, NULL, NULL, NULL},
4640 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4641 0, NULL, NULL, NULL},
4642 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4643 0, printableStringValidate, IA5StringNormalize, NULL},
4644 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4645 X_BINARY X_NOT_H_R ")",
4646 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4647 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4648 0, printableStringValidate, IA5StringNormalize, NULL},
4649 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4650 0, NULL, NULL, NULL},
4651 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4652 0, printablesStringValidate, IA5StringNormalize, NULL},
4653 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4654 0, utcTimeValidate, utcTimeNormalize, NULL},
4655 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4656 0, NULL, NULL, NULL},
4657 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4658 0, NULL, NULL, NULL},
4659 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4660 0, NULL, NULL, NULL},
4661 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4662 0, NULL, NULL, NULL},
4663 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4664 0, NULL, NULL, NULL},
4666 /* RFC 2307 NIS Syntaxes */
4667 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4668 0, nisNetgroupTripleValidate, NULL, NULL},
4669 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4670 0, bootParameterValidate, NULL, NULL},
4674 /* These OIDs are not published yet, but will be in the next
4675 * I-D for PKIX LDAPv3 schema as have been advanced by David
4676 * Chadwick in private mail.
4678 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4679 0, NULL, NULL, NULL},
4682 /* OpenLDAP Experimental Syntaxes */
4683 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4685 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4688 /* needs updating */
4689 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4690 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4692 /* OpenLDAP Void Syntax */
4693 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4694 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4695 {NULL, 0, NULL, NULL, NULL}
4698 struct mrule_defs_rec {
4700 slap_mask_t mrd_usage;
4701 slap_mr_convert_func * mrd_convert;
4702 slap_mr_normalize_func * mrd_normalize;
4703 slap_mr_match_func * mrd_match;
4704 slap_mr_indexer_func * mrd_indexer;
4705 slap_mr_filter_func * mrd_filter;
4707 char * mrd_associated;
4711 * Other matching rules in X.520 that we do not use (yet):
4713 * 2.5.13.9 numericStringOrderingMatch
4714 * 2.5.13.15 integerOrderingMatch
4715 * 2.5.13.18 octetStringOrderingMatch
4716 * 2.5.13.19 octetStringSubstringsMatch
4717 * 2.5.13.25 uTCTimeMatch
4718 * 2.5.13.26 uTCTimeOrderingMatch
4719 * 2.5.13.31 directoryStringFirstComponentMatch
4720 * 2.5.13.32 wordMatch
4721 * 2.5.13.33 keywordMatch
4722 * 2.5.13.35 certificateMatch
4723 * 2.5.13.36 certificatePairExactMatch
4724 * 2.5.13.37 certificatePairMatch
4725 * 2.5.13.38 certificateListExactMatch
4726 * 2.5.13.39 certificateListMatch
4727 * 2.5.13.40 algorithmIdentifierMatch
4728 * 2.5.13.41 storedPrefixMatch
4729 * 2.5.13.42 attributeCertificateMatch
4730 * 2.5.13.43 readerAndKeyIDMatch
4731 * 2.5.13.44 attributeIntegrityMatch
4734 struct mrule_defs_rec mrule_defs[] = {
4736 * EQUALITY matching rules must be listed after associated APPROX
4737 * matching rules. So, we list all APPROX matching rules first.
4739 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4740 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4741 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4743 directoryStringApproxMatch,
4744 directoryStringApproxIndexer,
4745 directoryStringApproxFilter,
4748 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4749 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4750 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4752 IA5StringApproxMatch,
4753 IA5StringApproxIndexer,
4754 IA5StringApproxFilter,
4758 * Other matching rules
4761 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4762 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4763 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4765 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4768 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4769 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4770 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4772 dnMatch, dnIndexer, dnFilter,
4775 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4776 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4777 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4779 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4780 directoryStringApproxMatchOID },
4782 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4783 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4786 caseIgnoreOrderingMatch, NULL, NULL,
4789 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4790 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4791 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4793 caseExactIgnoreSubstringsMatch,
4794 caseExactIgnoreSubstringsIndexer,
4795 caseExactIgnoreSubstringsFilter,
4798 {"( 2.5.13.5 NAME 'caseExactMatch' "
4799 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4800 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4802 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4803 directoryStringApproxMatchOID },
4805 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4806 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4809 caseExactOrderingMatch, NULL, NULL,
4812 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4813 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4814 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4816 caseExactIgnoreSubstringsMatch,
4817 caseExactIgnoreSubstringsIndexer,
4818 caseExactIgnoreSubstringsFilter,
4821 {"( 2.5.13.8 NAME 'numericStringMatch' "
4822 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4823 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4826 caseIgnoreIA5Indexer,
4827 caseIgnoreIA5Filter,
4830 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4831 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4832 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4834 caseIgnoreIA5SubstringsMatch,
4835 caseIgnoreIA5SubstringsIndexer,
4836 caseIgnoreIA5SubstringsFilter,
4839 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4840 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4841 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4843 caseIgnoreListMatch, NULL, NULL,
4846 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4847 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4848 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4850 caseIgnoreListSubstringsMatch, NULL, NULL,
4853 {"( 2.5.13.13 NAME 'booleanMatch' "
4854 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4855 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4857 booleanMatch, NULL, NULL,
4860 {"( 2.5.13.14 NAME 'integerMatch' "
4861 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4862 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4864 integerMatch, integerIndexer, integerFilter,
4867 {"( 2.5.13.16 NAME 'bitStringMatch' "
4868 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4869 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4871 bitStringMatch, bitStringIndexer, bitStringFilter,
4874 {"( 2.5.13.17 NAME 'octetStringMatch' "
4875 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4876 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4878 octetStringMatch, octetStringIndexer, octetStringFilter,
4881 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4882 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4883 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4885 telephoneNumberMatch,
4886 telephoneNumberIndexer,
4887 telephoneNumberFilter,
4890 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4891 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4892 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4894 telephoneNumberSubstringsMatch,
4895 telephoneNumberSubstringsIndexer,
4896 telephoneNumberSubstringsFilter,
4899 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4900 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4901 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4906 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4907 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4908 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4910 uniqueMemberMatch, NULL, NULL,
4913 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4914 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4915 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4917 protocolInformationMatch, NULL, NULL,
4920 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4921 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4922 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4924 generalizedTimeMatch, NULL, NULL,
4927 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4928 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4931 generalizedTimeOrderingMatch, NULL, NULL,
4934 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4935 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4936 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4938 integerFirstComponentMatch, NULL, NULL,
4941 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4942 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4943 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4945 objectIdentifierFirstComponentMatch, NULL, NULL,
4949 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4950 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4951 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4952 certificateExactConvert, NULL,
4953 certificateExactMatch,
4954 certificateExactIndexer, certificateExactFilter,
4958 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4959 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4960 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4962 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4963 IA5StringApproxMatchOID },
4965 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4966 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4967 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4969 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4970 IA5StringApproxMatchOID },
4972 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4973 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4976 caseIgnoreIA5SubstringsMatch,
4977 caseIgnoreIA5SubstringsIndexer,
4978 caseIgnoreIA5SubstringsFilter,
4981 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4982 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4985 caseExactIA5SubstringsMatch,
4986 caseExactIA5SubstringsIndexer,
4987 caseExactIA5SubstringsFilter,
4990 /* needs updating */
4991 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4992 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4995 authPasswordMatch, NULL, NULL,
4998 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4999 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
5002 OpenLDAPaciMatch, NULL, NULL,
5005 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
5006 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5009 integerBitAndMatch, NULL, NULL,
5012 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
5013 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
5016 integerBitOrMatch, NULL, NULL,
5019 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
5028 /* we should only be called once (from main) */
5029 assert( schema_init_done == 0 );
5031 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
5032 res = register_syntax( syntax_defs[i].sd_desc,
5033 syntax_defs[i].sd_flags,
5034 syntax_defs[i].sd_validate,
5035 syntax_defs[i].sd_normalize,
5036 syntax_defs[i].sd_pretty
5037 #ifdef SLAPD_BINARY_CONVERSION
5039 syntax_defs[i].sd_ber2str,
5040 syntax_defs[i].sd_str2ber
5045 fprintf( stderr, "schema_init: Error registering syntax %s\n",
5046 syntax_defs[i].sd_desc );
5051 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
5052 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
5054 "schema_init: Ingoring unusable matching rule %s\n",
5055 mrule_defs[i].mrd_desc );
5059 res = register_matching_rule(
5060 mrule_defs[i].mrd_desc,
5061 mrule_defs[i].mrd_usage,
5062 mrule_defs[i].mrd_convert,
5063 mrule_defs[i].mrd_normalize,
5064 mrule_defs[i].mrd_match,
5065 mrule_defs[i].mrd_indexer,
5066 mrule_defs[i].mrd_filter,
5067 mrule_defs[i].mrd_associated );
5071 "schema_init: Error registering matching rule %s\n",
5072 mrule_defs[i].mrd_desc );
5076 schema_init_done = 1;
5077 return LDAP_SUCCESS;
5081 schema_destroy( void )