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 */
36 #define integerPretty NULL
38 /* recycled matching routines */
39 #define bitStringMatch octetStringMatch
40 #define numericStringMatch caseIgnoreIA5Match
41 #define objectIdentifierMatch caseIgnoreIA5Match
42 #define telephoneNumberMatch caseIgnoreIA5Match
43 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
44 #define generalizedTimeMatch caseIgnoreIA5Match
45 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
46 #define uniqueMemberMatch dnMatch
48 /* approx matching rules */
49 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
50 #define directoryStringApproxMatch approxMatch
51 #define directoryStringApproxIndexer approxIndexer
52 #define directoryStringApproxFilter approxFilter
53 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
54 #define IA5StringApproxMatch approxMatch
55 #define IA5StringApproxIndexer approxIndexer
56 #define IA5StringApproxFilter approxFilter
58 /* orderring matching rules */
59 #define caseIgnoreOrderingMatch caseIgnoreMatch
60 #define caseExactOrderingMatch caseExactMatch
62 /* unimplemented matching routines */
63 #define caseIgnoreListMatch NULL
64 #define caseIgnoreListSubstringsMatch NULL
65 #define protocolInformationMatch NULL
66 #define integerFirstComponentMatch NULL
68 #define OpenLDAPaciMatch NULL
69 #define authPasswordMatch NULL
71 /* recycled indexing/filtering routines */
72 #define dnIndexer caseExactIgnoreIndexer
73 #define dnFilter caseExactIgnoreFilter
74 #define bitStringFilter octetStringFilter
75 #define bitStringIndexer octetStringIndexer
77 #define telephoneNumberIndexer caseIgnoreIA5Indexer
78 #define telephoneNumberFilter caseIgnoreIA5Filter
79 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
80 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
82 /* must match OIDs below */
83 #define caseExactMatchOID "2.5.13.5"
84 #define caseExactSubstringsMatchOID "2.5.13.7"
86 static char *strcasechr( const char *str, int c )
88 char *lower = strchr( str, TOLOWER(c) );
89 char *upper = strchr( str, TOUPPER(c) );
91 if( lower && upper ) {
92 return lower < upper ? lower : upper;
106 struct berval *value,
107 void *assertedValue )
109 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
112 match = memcmp( value->bv_val,
113 ((struct berval *) assertedValue)->bv_val,
121 /* Index generation function */
122 int octetStringIndexer(
127 struct berval *prefix,
128 struct berval **values,
129 struct berval ***keysp )
133 struct berval **keys;
134 HASH_CONTEXT HASHcontext;
135 unsigned char HASHdigest[HASH_BYTES];
136 struct berval digest;
137 digest.bv_val = HASHdigest;
138 digest.bv_len = sizeof(HASHdigest);
140 for( i=0; values[i] != NULL; i++ ) {
141 /* just count them */
144 /* we should have at least one value at this point */
147 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
149 slen = strlen( syntax->ssyn_oid );
150 mlen = strlen( mr->smr_oid );
152 for( i=0; values[i] != NULL; i++ ) {
153 HASH_Init( &HASHcontext );
154 if( prefix != NULL && prefix->bv_len > 0 ) {
155 HASH_Update( &HASHcontext,
156 prefix->bv_val, prefix->bv_len );
158 HASH_Update( &HASHcontext,
159 syntax->ssyn_oid, slen );
160 HASH_Update( &HASHcontext,
162 HASH_Update( &HASHcontext,
163 values[i]->bv_val, values[i]->bv_len );
164 HASH_Final( HASHdigest, &HASHcontext );
166 keys[i] = ber_bvdup( &digest );
176 /* Index generation function */
177 int octetStringFilter(
182 struct berval *prefix,
184 struct berval ***keysp )
187 struct berval **keys;
188 HASH_CONTEXT HASHcontext;
189 unsigned char HASHdigest[HASH_BYTES];
190 struct berval *value = (struct berval *) assertValue;
191 struct berval digest;
192 digest.bv_val = HASHdigest;
193 digest.bv_len = sizeof(HASHdigest);
195 slen = strlen( syntax->ssyn_oid );
196 mlen = strlen( mr->smr_oid );
198 keys = ch_malloc( sizeof( struct berval * ) * 2 );
200 HASH_Init( &HASHcontext );
201 if( prefix != NULL && prefix->bv_len > 0 ) {
202 HASH_Update( &HASHcontext,
203 prefix->bv_val, prefix->bv_len );
205 HASH_Update( &HASHcontext,
206 syntax->ssyn_oid, slen );
207 HASH_Update( &HASHcontext,
209 HASH_Update( &HASHcontext,
210 value->bv_val, value->bv_len );
211 HASH_Final( HASHdigest, &HASHcontext );
213 keys[0] = ber_bvdup( &digest );
229 if( in->bv_len == 0 ) return LDAP_SUCCESS;
231 dn = ch_strdup( in->bv_val );
234 return LDAP_INVALID_SYNTAX;
236 } else if ( strlen( in->bv_val ) != in->bv_len ) {
237 rc = LDAP_INVALID_SYNTAX;
239 } else if ( dn_validate( dn ) == NULL ) {
240 rc = LDAP_INVALID_SYNTAX;
254 struct berval **normalized )
258 if ( val->bv_len != 0 ) {
260 out = ber_bvstr( UTF8normalize( val, UTF8_CASEFOLD ) );
262 dn = dn_validate( out->bv_val );
266 return LDAP_INVALID_SYNTAX;
270 out->bv_len = strlen( dn );
272 out = ber_bvdup( val );
285 struct berval *value,
286 void *assertedValue )
289 struct berval *asserted = (struct berval *) assertedValue;
291 match = value->bv_len - asserted->bv_len;
294 #ifdef USE_DN_NORMALIZE
295 match = strcmp( value->bv_val, asserted->bv_val );
297 match = strcasecmp( value->bv_val, asserted->bv_val );
302 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
303 "dnMatch: %d\n %s\n %s\n", match,
304 value->bv_val, asserted->bv_val ));
306 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
307 match, value->bv_val, asserted->bv_val );
323 if( in->bv_len == 0 ) return LDAP_SUCCESS;
325 dn = ber_bvdup( in );
327 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
328 /* assume presence of optional UID */
331 for(i=dn->bv_len-2; i>2; i--) {
332 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
336 if( dn->bv_val[i] != '\'' ||
337 dn->bv_val[i-1] != 'B' ||
338 dn->bv_val[i-2] != '#' ) {
340 return LDAP_INVALID_SYNTAX;
343 /* trim the UID to allow use of dn_validate */
344 dn->bv_val[i-2] = '\0';
347 rc = dn_validate( dn->bv_val ) == NULL
348 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
358 struct berval **normalized )
360 struct berval *out = ber_bvdup( val );
362 if( out->bv_len != 0 ) {
366 ber_len_t uidlen = 0;
368 if( out->bv_val[out->bv_len-1] == '\'' ) {
369 /* assume presence of optional UID */
370 uid = strrchr( out->bv_val, '#' );
374 return LDAP_INVALID_SYNTAX;
377 uidlen = out->bv_len - (out->bv_val - uid);
378 /* temporarily trim the UID */
382 #ifdef USE_DN_NORMALIZE
383 dn = dn_normalize( out->bv_val );
385 dn = dn_validate( out->bv_val );
390 return LDAP_INVALID_SYNTAX;
396 /* restore the separator */
399 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
403 out->bv_len = dnlen + uidlen;
415 /* any value allowed */
424 /* any value allowed */
435 /* very unforgiving validation, requires no normalization
436 * before simplistic matching
438 if( in->bv_len < 3 ) {
439 return LDAP_INVALID_SYNTAX;
443 * rfc 2252 section 6.3 Bit String
444 * bitstring = "'" *binary-digit "'"
445 * binary-digit = "0" / "1"
446 * example: '0101111101'B
449 if( in->bv_val[0] != '\'' ||
450 in->bv_val[in->bv_len-2] != '\'' ||
451 in->bv_val[in->bv_len-1] != 'B' )
453 return LDAP_INVALID_SYNTAX;
456 for( i=in->bv_len-3; i>0; i-- ) {
457 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
458 return LDAP_INVALID_SYNTAX;
469 struct berval **normalized )
472 * A normalized bitString is has no extaneous (leading) zero bits.
473 * That is, '00010'B is normalized to '10'B
474 * However, as a special case, '0'B requires no normalization.
476 struct berval *newval;
479 /* start at the first bit */
482 /* Find the first non-zero bit */
483 while ( *p == '0' ) p++;
485 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
488 /* no non-zero bits */
489 newval->bv_val = ch_strdup("\'0\'B");
490 newval->bv_len = sizeof("\'0\'B") - 1;
494 newval->bv_val = ch_malloc( val->bv_len + 1 );
496 newval->bv_val[0] = '\'';
499 for( ; *p != '\0'; p++ ) {
500 newval->bv_val[newval->bv_len++] = *p;
503 newval->bv_val[newval->bv_len] = '\0';
506 *normalized = newval;
511 * Handling boolean syntax and matching is quite rigid.
512 * A more flexible approach would be to allow a variety
513 * of strings to be normalized and prettied into TRUE
521 /* very unforgiving validation, requires no normalization
522 * before simplistic matching
525 if( in->bv_len == 4 ) {
526 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
529 } else if( in->bv_len == 5 ) {
530 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
535 return LDAP_INVALID_SYNTAX;
544 struct berval *value,
545 void *assertedValue )
547 /* simplistic matching allowed by rigid validation */
548 struct berval *asserted = (struct berval *) assertedValue;
549 *matchp = value->bv_len != asserted->bv_len;
560 unsigned char *u = in->bv_val;
562 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
564 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
565 /* get the length indicated by the first byte */
566 len = LDAP_UTF8_CHARLEN( u );
568 /* should not be zero */
569 if( len == 0 ) return LDAP_INVALID_SYNTAX;
571 /* make sure len corresponds with the offset
572 to the next character */
573 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
576 if( count != 0 ) return LDAP_INVALID_SYNTAX;
585 struct berval **normalized )
587 struct berval *newval;
590 newval = ch_malloc( sizeof( struct berval ) );
594 /* Ignore initial whitespace */
595 while ( ldap_utf8_isspace( p ) ) {
601 return LDAP_INVALID_SYNTAX;
604 newval->bv_val = ch_strdup( p );
605 p = q = newval->bv_val;
611 if ( ldap_utf8_isspace( p ) ) {
612 len = LDAP_UTF8_COPY(q,p);
617 /* Ignore the extra whitespace */
618 while ( ldap_utf8_isspace( p ) ) {
622 len = LDAP_UTF8_COPY(q,p);
629 assert( *newval->bv_val );
630 assert( newval->bv_val < p );
633 /* cannot start with a space */
634 assert( !ldap_utf8_isspace(newval->bv_val) );
637 * If the string ended in space, backup the pointer one
638 * position. One is enough because the above loop collapsed
639 * all whitespace to a single space.
646 /* cannot end with a space */
647 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
652 newval->bv_len = q - newval->bv_val;
653 *normalized = newval;
658 /* Returns Unicode cannonically normalized copy of a substring assertion
659 * Skipping attribute description */
660 SubstringsAssertion *
661 UTF8SubstringsassertionNormalize(
662 SubstringsAssertion *sa,
665 SubstringsAssertion *nsa;
668 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
673 if( sa->sa_initial != NULL ) {
674 nsa->sa_initial = ber_bvstr( UTF8normalize( sa->sa_initial, casefold ) );
675 if( nsa->sa_initial == NULL ) {
680 if( sa->sa_any != NULL ) {
681 for( i=0; sa->sa_any[i] != NULL; i++ ) {
684 nsa->sa_any = (struct berval **)ch_malloc( (i + 1) * sizeof(struct berval *) );
685 for( i=0; sa->sa_any[i] != NULL; i++ ) {
686 nsa->sa_any[i] = ber_bvstr( UTF8normalize( sa->sa_any[i], casefold ) );
687 if( nsa->sa_any[i] == NULL ) {
691 nsa->sa_any[i] = NULL;
694 if( sa->sa_final != NULL ) {
695 nsa->sa_final = ber_bvstr( UTF8normalize( sa->sa_final, casefold ) );
696 if( nsa->sa_final == NULL ) {
704 ber_bvfree( nsa->sa_final );
705 ber_bvecfree( nsa->sa_any );
706 ber_bvfree( nsa->sa_initial );
711 /* Strip characters with the 8th bit set */
724 while( *++q & 0x80 ) {
727 p = memmove(p, q, strlen(q) + 1);
735 #ifndef SLAPD_APPROX_OLDSINGLESTRING
737 #if defined(SLAPD_APPROX_INITIALS)
738 #define SLAPD_APPROX_DELIMITER "._ "
739 #define SLAPD_APPROX_WORDLEN 2
741 #define SLAPD_APPROX_DELIMITER " "
742 #define SLAPD_APPROX_WORDLEN 1
751 struct berval *value,
752 void *assertedValue )
754 char *val, *nval, *assertv, **values, **words, *c;
755 int i, count, len, nextchunk=0, nextavail=0;
758 /* Yes, this is necessary */
759 nval = UTF8normalize( value, UTF8_NOCASEFOLD );
764 strip8bitChars( nval );
766 /* Yes, this is necessary */
767 assertv = UTF8normalize( ((struct berval *)assertedValue),
769 if( assertv == NULL ) {
774 strip8bitChars( assertv );
775 avlen = strlen( assertv );
777 /* Isolate how many words there are */
778 for( c=nval,count=1; *c; c++ ) {
779 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
780 if ( c == NULL ) break;
785 /* Get a phonetic copy of each word */
786 words = (char **)ch_malloc( count * sizeof(char *) );
787 values = (char **)ch_malloc( count * sizeof(char *) );
788 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
790 values[i] = phonetic(c);
793 /* Work through the asserted value's words, to see if at least some
794 of the words are there, in the same order. */
796 while ( nextchunk < avlen ) {
797 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
802 #if defined(SLAPD_APPROX_INITIALS)
803 else if( len == 1 ) {
804 /* Single letter words need to at least match one word's initial */
805 for( i=nextavail; i<count; i++ )
806 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
813 /* Isolate the next word in the asserted value and phonetic it */
814 assertv[nextchunk+len] = '\0';
815 val = phonetic( assertv + nextchunk );
817 /* See if this phonetic chunk is in the remaining words of *value */
818 for( i=nextavail; i<count; i++ ){
819 if( !strcmp( val, values[i] ) ){
827 /* This chunk in the asserted value was NOT within the *value. */
833 /* Go on to the next word in the asserted value */
837 /* If some of the words were seen, call it a match */
838 if( nextavail > 0 ) {
847 for( i=0; i<count; i++ ) {
848 ch_free( values[i] );
863 struct berval *prefix,
864 struct berval **values,
865 struct berval ***keysp )
868 int i,j, len, wordcount, keycount=0;
869 struct berval **newkeys, **keys=NULL;
871 for( j=0; values[j] != NULL; j++ ) {
872 /* Yes, this is necessary */
873 val = UTF8normalize( values[j], UTF8_NOCASEFOLD );
874 strip8bitChars( val );
876 /* Isolate how many words there are. There will be a key for each */
877 for( wordcount=0,c=val; *c; c++) {
878 len = strcspn(c, SLAPD_APPROX_DELIMITER);
879 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
881 if (*c == '\0') break;
885 /* Allocate/increase storage to account for new keys */
886 newkeys = (struct berval **)ch_malloc( (keycount + wordcount + 1)
887 * sizeof(struct berval *) );
888 memcpy( newkeys, keys, keycount * sizeof(struct berval *) );
889 if( keys ) ch_free( keys );
892 /* Get a phonetic copy of each word */
893 for( c=val,i=0; i<wordcount; c+=len+1 ) {
895 if( len < SLAPD_APPROX_WORDLEN ) continue;
896 keys[keycount] = (struct berval *)ch_malloc( sizeof(struct berval) );
897 keys[keycount]->bv_val = phonetic( c );
898 keys[keycount]->bv_len = strlen( keys[keycount]->bv_val );
905 keys[keycount] = NULL;
917 struct berval *prefix,
919 struct berval ***keysp )
923 struct berval **keys;
925 /* Yes, this is necessary */
926 val = UTF8normalize( ((struct berval *)assertValue),
929 keys = (struct berval **)ch_malloc( sizeof(struct berval *) );
934 strip8bitChars( val );
936 /* Isolate how many words there are. There will be a key for each */
937 for( count=0,c=val; *c; c++) {
938 len = strcspn(c, SLAPD_APPROX_DELIMITER);
939 if( len >= SLAPD_APPROX_WORDLEN ) count++;
941 if (*c == '\0') break;
945 /* Allocate storage for new keys */
946 keys = (struct berval **)ch_malloc( (count + 1) * sizeof(struct berval *) );
948 /* Get a phonetic copy of each word */
949 for( c=val,i=0; i<count; c+=len+1 ) {
951 if( len < SLAPD_APPROX_WORDLEN ) continue;
952 keys[i] = ber_bvstr( phonetic( c ) );
966 /* No other form of Approximate Matching is defined */
974 struct berval *value,
975 void *assertedValue )
977 char *vapprox, *avapprox;
980 /* Yes, this is necessary */
981 s = UTF8normalize( value, UTF8_NOCASEFOLD );
987 /* Yes, this is necessary */
988 t = UTF8normalize( ((struct berval *)assertedValue),
996 vapprox = phonetic( strip8bitChars( s ) );
997 avapprox = phonetic( strip8bitChars( t ) );
1002 *matchp = strcmp( vapprox, avapprox );
1005 ch_free( avapprox );
1007 return LDAP_SUCCESS;
1016 struct berval *prefix,
1017 struct berval **values,
1018 struct berval ***keysp )
1021 struct berval **keys;
1024 for( i=0; values[i] != NULL; i++ ) {
1025 /* empty - just count them */
1028 /* we should have at least one value at this point */
1031 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * (i+1) );
1033 /* Copy each value and run it through phonetic() */
1034 for( i=0; values[i] != NULL; i++ ) {
1035 /* Yes, this is necessary */
1036 s = UTF8normalize( values[i], UTF8_NOCASEFOLD );
1038 /* strip 8-bit chars and run through phonetic() */
1039 keys[i] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1045 return LDAP_SUCCESS;
1055 struct berval *prefix,
1057 struct berval ***keysp )
1059 struct berval **keys;
1062 keys = (struct berval **)ch_malloc( sizeof( struct berval * ) * 2 );
1064 /* Yes, this is necessary */
1065 s = UTF8normalize( ((struct berval *)assertValue),
1070 /* strip 8-bit chars and run through phonetic() */
1071 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1077 return LDAP_SUCCESS;
1088 struct berval *value,
1089 void *assertedValue )
1091 *matchp = UTF8normcmp( value->bv_val,
1092 ((struct berval *) assertedValue)->bv_val,
1094 return LDAP_SUCCESS;
1098 caseExactIgnoreSubstringsMatch(
1103 struct berval *value,
1104 void *assertedValue )
1107 SubstringsAssertion *sub = NULL;
1111 char *nav, casefold;
1113 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1114 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1116 nav = UTF8normalize( value, casefold );
1122 left.bv_len = strlen( nav );
1124 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1130 /* Add up asserted input length */
1131 if( sub->sa_initial ) {
1132 inlen += sub->sa_initial->bv_len;
1135 for(i=0; sub->sa_any[i] != NULL; i++) {
1136 inlen += sub->sa_any[i]->bv_len;
1139 if( sub->sa_final ) {
1140 inlen += sub->sa_final->bv_len;
1143 if( sub->sa_initial ) {
1144 if( inlen > left.bv_len ) {
1149 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1150 sub->sa_initial->bv_len );
1156 left.bv_val += sub->sa_initial->bv_len;
1157 left.bv_len -= sub->sa_initial->bv_len;
1158 inlen -= sub->sa_initial->bv_len;
1161 if( sub->sa_final ) {
1162 if( inlen > left.bv_len ) {
1167 match = strncmp( sub->sa_final->bv_val,
1168 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1169 sub->sa_final->bv_len );
1175 left.bv_len -= sub->sa_final->bv_len;
1176 inlen -= sub->sa_final->bv_len;
1180 for(i=0; sub->sa_any[i]; i++) {
1185 if( inlen > left.bv_len ) {
1186 /* not enough length */
1191 if( sub->sa_any[i]->bv_len == 0 ) {
1195 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1202 idx = p - left.bv_val;
1203 assert( idx < left.bv_len );
1205 if( idx >= left.bv_len ) {
1206 /* this shouldn't happen */
1208 ch_free( sub->sa_final );
1209 ber_bvecfree( sub->sa_any );
1210 ch_free( sub->sa_initial );
1218 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1219 /* not enough left */
1224 match = strncmp( left.bv_val,
1225 sub->sa_any[i]->bv_val,
1226 sub->sa_any[i]->bv_len );
1234 left.bv_val += sub->sa_any[i]->bv_len;
1235 left.bv_len -= sub->sa_any[i]->bv_len;
1236 inlen -= sub->sa_any[i]->bv_len;
1243 ber_bvfree( sub->sa_final );
1244 ber_bvecfree( sub->sa_any );
1245 ber_bvfree( sub->sa_initial );
1249 return LDAP_SUCCESS;
1252 /* Index generation function */
1253 int caseExactIgnoreIndexer(
1258 struct berval *prefix,
1259 struct berval **values,
1260 struct berval ***keysp )
1265 struct berval **keys;
1266 HASH_CONTEXT HASHcontext;
1267 unsigned char HASHdigest[HASH_BYTES];
1268 struct berval digest;
1269 digest.bv_val = HASHdigest;
1270 digest.bv_len = sizeof(HASHdigest);
1272 for( i=0; values[i] != NULL; i++ ) {
1273 /* empty - just count them */
1276 /* we should have at least one value at this point */
1279 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1281 slen = strlen( syntax->ssyn_oid );
1282 mlen = strlen( mr->smr_oid );
1284 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1285 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1287 for( i=0; values[i] != NULL; i++ ) {
1288 struct berval *value;
1289 value = ber_bvstr( UTF8normalize( values[i],
1292 HASH_Init( &HASHcontext );
1293 if( prefix != NULL && prefix->bv_len > 0 ) {
1294 HASH_Update( &HASHcontext,
1295 prefix->bv_val, prefix->bv_len );
1297 HASH_Update( &HASHcontext,
1298 syntax->ssyn_oid, slen );
1299 HASH_Update( &HASHcontext,
1300 mr->smr_oid, mlen );
1301 HASH_Update( &HASHcontext,
1302 value->bv_val, value->bv_len );
1303 HASH_Final( HASHdigest, &HASHcontext );
1305 ber_bvfree( value );
1307 keys[i] = ber_bvdup( &digest );
1312 return LDAP_SUCCESS;
1315 /* Index generation function */
1316 int caseExactIgnoreFilter(
1321 struct berval *prefix,
1323 struct berval ***keysp )
1327 struct berval **keys;
1328 HASH_CONTEXT HASHcontext;
1329 unsigned char HASHdigest[HASH_BYTES];
1330 struct berval *value;
1331 struct berval digest;
1332 digest.bv_val = HASHdigest;
1333 digest.bv_len = sizeof(HASHdigest);
1335 slen = strlen( syntax->ssyn_oid );
1336 mlen = strlen( mr->smr_oid );
1338 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1339 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1341 value = ber_bvstr( UTF8normalize( ((struct berval *) assertValue),
1343 /* This usually happens if filter contains bad UTF8 */
1344 if( value == NULL ) {
1345 keys = ch_malloc( sizeof( struct berval * ) );
1347 return LDAP_SUCCESS;
1350 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1352 HASH_Init( &HASHcontext );
1353 if( prefix != NULL && prefix->bv_len > 0 ) {
1354 HASH_Update( &HASHcontext,
1355 prefix->bv_val, prefix->bv_len );
1357 HASH_Update( &HASHcontext,
1358 syntax->ssyn_oid, slen );
1359 HASH_Update( &HASHcontext,
1360 mr->smr_oid, mlen );
1361 HASH_Update( &HASHcontext,
1362 value->bv_val, value->bv_len );
1363 HASH_Final( HASHdigest, &HASHcontext );
1365 keys[0] = ber_bvdup( &digest );
1368 ber_bvfree( value );
1371 return LDAP_SUCCESS;
1374 /* Substrings Index generation function */
1375 int caseExactIgnoreSubstringsIndexer(
1380 struct berval *prefix,
1381 struct berval **values,
1382 struct berval ***keysp )
1387 struct berval **keys;
1388 struct berval **nvalues;
1390 HASH_CONTEXT HASHcontext;
1391 unsigned char HASHdigest[HASH_BYTES];
1392 struct berval digest;
1393 digest.bv_val = HASHdigest;
1394 digest.bv_len = sizeof(HASHdigest);
1398 for( i=0; values[i] != NULL; i++ ) {
1399 /* empty - just count them */
1402 /* we should have at least one value at this point */
1405 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1406 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1408 nvalues = ch_malloc( sizeof( struct berval * ) * (i+1) );
1409 for( i=0; values[i] != NULL; i++ ) {
1410 nvalues[i] = ber_bvstr( UTF8normalize( values[i],
1416 for( i=0; values[i] != NULL; i++ ) {
1417 /* count number of indices to generate */
1418 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1422 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1423 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1424 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1425 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1427 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1431 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1432 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1433 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1437 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1438 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1439 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1440 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1442 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1448 /* no keys to generate */
1450 ber_bvecfree( nvalues );
1451 return LDAP_SUCCESS;
1454 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1456 slen = strlen( syntax->ssyn_oid );
1457 mlen = strlen( mr->smr_oid );
1460 for( i=0; values[i] != NULL; i++ ) {
1462 struct berval *value;
1464 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1468 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1469 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1471 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1472 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1474 for( j=0; j<max; j++ ) {
1475 HASH_Init( &HASHcontext );
1476 if( prefix != NULL && prefix->bv_len > 0 ) {
1477 HASH_Update( &HASHcontext,
1478 prefix->bv_val, prefix->bv_len );
1481 HASH_Update( &HASHcontext,
1482 &pre, sizeof( pre ) );
1483 HASH_Update( &HASHcontext,
1484 syntax->ssyn_oid, slen );
1485 HASH_Update( &HASHcontext,
1486 mr->smr_oid, mlen );
1487 HASH_Update( &HASHcontext,
1489 SLAP_INDEX_SUBSTR_MAXLEN );
1490 HASH_Final( HASHdigest, &HASHcontext );
1492 keys[nkeys++] = ber_bvdup( &digest );
1496 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1497 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1499 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1502 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1503 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1504 HASH_Init( &HASHcontext );
1505 if( prefix != NULL && prefix->bv_len > 0 ) {
1506 HASH_Update( &HASHcontext,
1507 prefix->bv_val, prefix->bv_len );
1509 HASH_Update( &HASHcontext,
1510 &pre, sizeof( pre ) );
1511 HASH_Update( &HASHcontext,
1512 syntax->ssyn_oid, slen );
1513 HASH_Update( &HASHcontext,
1514 mr->smr_oid, mlen );
1515 HASH_Update( &HASHcontext,
1517 HASH_Final( HASHdigest, &HASHcontext );
1519 keys[nkeys++] = ber_bvdup( &digest );
1522 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1523 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1524 HASH_Init( &HASHcontext );
1525 if( prefix != NULL && prefix->bv_len > 0 ) {
1526 HASH_Update( &HASHcontext,
1527 prefix->bv_val, prefix->bv_len );
1529 HASH_Update( &HASHcontext,
1530 &pre, sizeof( pre ) );
1531 HASH_Update( &HASHcontext,
1532 syntax->ssyn_oid, slen );
1533 HASH_Update( &HASHcontext,
1534 mr->smr_oid, mlen );
1535 HASH_Update( &HASHcontext,
1536 &value->bv_val[value->bv_len-j], j );
1537 HASH_Final( HASHdigest, &HASHcontext );
1539 keys[nkeys++] = ber_bvdup( &digest );
1554 ber_bvecfree( nvalues );
1556 return LDAP_SUCCESS;
1559 int caseExactIgnoreSubstringsFilter(
1564 struct berval *prefix,
1566 struct berval ***keysp )
1568 SubstringsAssertion *sa;
1570 ber_len_t nkeys = 0;
1571 size_t slen, mlen, klen;
1572 struct berval **keys;
1573 HASH_CONTEXT HASHcontext;
1574 unsigned char HASHdigest[HASH_BYTES];
1575 struct berval *value;
1576 struct berval digest;
1578 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1579 ? UTF8_CASEFOLD : UTF8_NOCASEFOLD;
1581 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1584 return LDAP_SUCCESS;
1587 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1588 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1593 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1595 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1596 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1597 /* don't bother accounting for stepping */
1598 nkeys += sa->sa_any[i]->bv_len -
1599 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1604 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1605 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1611 ber_bvfree( sa->sa_final );
1612 ber_bvecfree( sa->sa_any );
1613 ber_bvfree( sa->sa_initial );
1616 return LDAP_SUCCESS;
1619 digest.bv_val = HASHdigest;
1620 digest.bv_len = sizeof(HASHdigest);
1622 slen = strlen( syntax->ssyn_oid );
1623 mlen = strlen( mr->smr_oid );
1625 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1628 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1629 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1631 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1632 value = sa->sa_initial;
1634 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1635 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1637 HASH_Init( &HASHcontext );
1638 if( prefix != NULL && prefix->bv_len > 0 ) {
1639 HASH_Update( &HASHcontext,
1640 prefix->bv_val, prefix->bv_len );
1642 HASH_Update( &HASHcontext,
1643 &pre, sizeof( pre ) );
1644 HASH_Update( &HASHcontext,
1645 syntax->ssyn_oid, slen );
1646 HASH_Update( &HASHcontext,
1647 mr->smr_oid, mlen );
1648 HASH_Update( &HASHcontext,
1649 value->bv_val, klen );
1650 HASH_Final( HASHdigest, &HASHcontext );
1652 keys[nkeys++] = ber_bvdup( &digest );
1655 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1657 pre = SLAP_INDEX_SUBSTR_PREFIX;
1658 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1660 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1661 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1665 value = sa->sa_any[i];
1668 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1669 j += SLAP_INDEX_SUBSTR_STEP )
1671 HASH_Init( &HASHcontext );
1672 if( prefix != NULL && prefix->bv_len > 0 ) {
1673 HASH_Update( &HASHcontext,
1674 prefix->bv_val, prefix->bv_len );
1676 HASH_Update( &HASHcontext,
1677 &pre, sizeof( pre ) );
1678 HASH_Update( &HASHcontext,
1679 syntax->ssyn_oid, slen );
1680 HASH_Update( &HASHcontext,
1681 mr->smr_oid, mlen );
1682 HASH_Update( &HASHcontext,
1683 &value->bv_val[j], klen );
1684 HASH_Final( HASHdigest, &HASHcontext );
1686 keys[nkeys++] = ber_bvdup( &digest );
1692 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1693 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1695 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1696 value = sa->sa_final;
1698 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1699 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1701 HASH_Init( &HASHcontext );
1702 if( prefix != NULL && prefix->bv_len > 0 ) {
1703 HASH_Update( &HASHcontext,
1704 prefix->bv_val, prefix->bv_len );
1706 HASH_Update( &HASHcontext,
1707 &pre, sizeof( pre ) );
1708 HASH_Update( &HASHcontext,
1709 syntax->ssyn_oid, slen );
1710 HASH_Update( &HASHcontext,
1711 mr->smr_oid, mlen );
1712 HASH_Update( &HASHcontext,
1713 &value->bv_val[value->bv_len-klen], klen );
1714 HASH_Final( HASHdigest, &HASHcontext );
1716 keys[nkeys++] = ber_bvdup( &digest );
1726 ber_bvfree( sa->sa_final );
1727 ber_bvecfree( sa->sa_any );
1728 ber_bvfree( sa->sa_initial );
1731 return LDAP_SUCCESS;
1740 struct berval *value,
1741 void *assertedValue )
1743 *matchp = UTF8normcmp( value->bv_val,
1744 ((struct berval *) assertedValue)->bv_val,
1746 return LDAP_SUCCESS;
1752 struct berval *val )
1756 if( val->bv_len == 0 ) {
1757 /* disallow empty strings */
1758 return LDAP_INVALID_SYNTAX;
1761 if( OID_LEADCHAR(val->bv_val[0]) ) {
1763 for(i=1; i < val->bv_len; i++) {
1764 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1765 if( dot++ ) return 1;
1766 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1769 return LDAP_INVALID_SYNTAX;
1773 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1775 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1776 for(i=1; i < val->bv_len; i++) {
1777 if( !DESC_CHAR(val->bv_val[i] ) ) {
1778 return LDAP_INVALID_SYNTAX;
1782 return LDAP_SUCCESS;
1785 return LDAP_INVALID_SYNTAX;
1794 struct berval *value,
1795 void *assertedValue )
1798 int vsign=0, avsign=0;
1799 struct berval *asserted;
1800 ber_len_t vlen, avlen;
1803 /* Start off pessimistic */
1806 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1808 vlen = value->bv_len;
1810 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1811 /* empty -- skip spaces */
1813 else if ( *v == '+' ) {
1816 else if ( *v == '-' ) {
1819 else if ( ASCII_DIGIT(*v) ) {
1820 if ( vsign == 0 ) vsign = 1;
1828 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1830 asserted = (struct berval *) assertedValue;
1831 av = asserted->bv_val;
1832 avlen = asserted->bv_len;
1834 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1835 /* empty -- skip spaces */
1837 else if ( *av == '+' ) {
1840 else if ( *av == '-' ) {
1843 else if ( ASCII_DIGIT(*av) ) {
1844 if ( avsign == 0 ) avsign = 1;
1852 /* The two ?sign vars are now one of :
1853 -2 negative non-zero number
1855 0 0 collapse these three to 0
1857 +2 positive non-zero number
1859 if ( abs( vsign ) == 1 ) vsign = 0;
1860 if ( abs( avsign ) == 1 ) avsign = 0;
1862 if( vsign != avsign ) return LDAP_SUCCESS;
1864 /* Check the significant digits */
1865 while( vlen && avlen ) {
1866 if( *v != *av ) break;
1873 /* If all digits compared equal, the numbers are equal */
1874 if(( vlen == 0 ) && ( avlen == 0 )) {
1877 return LDAP_SUCCESS;
1883 struct berval *val )
1887 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1889 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1890 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1891 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1892 return LDAP_INVALID_SYNTAX;
1895 for( i=1; i < val->bv_len; i++ ) {
1896 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1899 return LDAP_SUCCESS;
1906 struct berval **normalized )
1910 struct berval *newval;
1917 /* Ignore leading spaces */
1918 while ( len && ( *p == ' ' )) {
1925 negative = ( *p == '-' );
1926 if(( *p == '-' ) || ( *p == '+' )) {
1932 /* Ignore leading zeros */
1933 while ( len && ( *p == '0' )) {
1938 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
1940 /* If there are no non-zero digits left, the number is zero, otherwise
1941 allocate space for the number and copy it into the buffer */
1943 newval->bv_val = ch_strdup("0");
1947 newval->bv_len = len+negative;
1948 newval->bv_val = ch_malloc( newval->bv_len );
1950 newval->bv_val[0] = '-';
1952 memcpy( newval->bv_val + negative, p, len );
1955 *normalized = newval;
1956 return LDAP_SUCCESS;
1959 /* Index generation function */
1965 struct berval *prefix,
1966 struct berval **values,
1967 struct berval ***keysp )
1970 struct berval **keys;
1972 /* we should have at least one value at this point */
1973 assert( values != NULL && values[0] != NULL );
1975 for( i=0; values[i] != NULL; i++ ) {
1976 /* empty -- just count them */
1979 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1981 for( i=0; values[i] != NULL; i++ ) {
1982 integerNormalize( syntax, values[i], &keys[i] );
1987 return LDAP_SUCCESS;
1990 /* Index generation function */
1996 struct berval *prefix,
1998 struct berval ***keysp )
2000 struct berval **keys;
2002 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2003 integerNormalize( syntax, assertValue, &keys[0] );
2007 return LDAP_SUCCESS;
2012 countryStringValidate(
2014 struct berval *val )
2016 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2018 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2019 return LDAP_INVALID_SYNTAX;
2021 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2022 return LDAP_INVALID_SYNTAX;
2025 return LDAP_SUCCESS;
2029 printableStringValidate(
2031 struct berval *val )
2035 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2037 for(i=0; i < val->bv_len; i++) {
2038 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2039 return LDAP_INVALID_SYNTAX;
2043 return LDAP_SUCCESS;
2047 printablesStringValidate(
2049 struct berval *val )
2053 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2055 for(i=0; i < val->bv_len; i++) {
2056 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
2057 return LDAP_INVALID_SYNTAX;
2061 return LDAP_SUCCESS;
2067 struct berval *val )
2071 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
2073 for(i=0; i < val->bv_len; i++) {
2074 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
2077 return LDAP_SUCCESS;
2084 struct berval **normalized )
2086 struct berval *newval;
2089 newval = ch_malloc( sizeof( struct berval ) );
2093 /* Ignore initial whitespace */
2094 while ( ASCII_SPACE( *p ) ) {
2100 return LDAP_INVALID_SYNTAX;
2103 newval->bv_val = ch_strdup( p );
2104 p = q = newval->bv_val;
2107 if ( ASCII_SPACE( *p ) ) {
2110 /* Ignore the extra whitespace */
2111 while ( ASCII_SPACE( *p ) ) {
2119 assert( *newval->bv_val );
2120 assert( newval->bv_val < p );
2123 /* cannot start with a space */
2124 assert( !ASCII_SPACE(*newval->bv_val) );
2127 * If the string ended in space, backup the pointer one
2128 * position. One is enough because the above loop collapsed
2129 * all whitespace to a single space.
2132 if ( ASCII_SPACE( q[-1] ) ) {
2136 /* cannot end with a space */
2137 assert( !ASCII_SPACE( q[-1] ) );
2139 /* null terminate */
2142 newval->bv_len = q - newval->bv_val;
2143 *normalized = newval;
2145 return LDAP_SUCCESS;
2154 struct berval *value,
2155 void *assertedValue )
2157 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2160 match = strncmp( value->bv_val,
2161 ((struct berval *) assertedValue)->bv_val,
2166 return LDAP_SUCCESS;
2170 caseExactIA5SubstringsMatch(
2175 struct berval *value,
2176 void *assertedValue )
2179 SubstringsAssertion *sub = assertedValue;
2180 struct berval left = *value;
2184 /* Add up asserted input length */
2185 if( sub->sa_initial ) {
2186 inlen += sub->sa_initial->bv_len;
2189 for(i=0; sub->sa_any[i] != NULL; i++) {
2190 inlen += sub->sa_any[i]->bv_len;
2193 if( sub->sa_final ) {
2194 inlen += sub->sa_final->bv_len;
2197 if( sub->sa_initial ) {
2198 if( inlen > left.bv_len ) {
2203 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2204 sub->sa_initial->bv_len );
2210 left.bv_val += sub->sa_initial->bv_len;
2211 left.bv_len -= sub->sa_initial->bv_len;
2212 inlen -= sub->sa_initial->bv_len;
2215 if( sub->sa_final ) {
2216 if( inlen > left.bv_len ) {
2221 match = strncmp( sub->sa_final->bv_val,
2222 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2223 sub->sa_final->bv_len );
2229 left.bv_len -= sub->sa_final->bv_len;
2230 inlen -= sub->sa_final->bv_len;
2234 for(i=0; sub->sa_any[i]; i++) {
2239 if( inlen > left.bv_len ) {
2240 /* not enough length */
2245 if( sub->sa_any[i]->bv_len == 0 ) {
2249 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2256 idx = p - left.bv_val;
2257 assert( idx < left.bv_len );
2259 if( idx >= left.bv_len ) {
2260 /* this shouldn't happen */
2267 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2268 /* not enough left */
2273 match = strncmp( left.bv_val,
2274 sub->sa_any[i]->bv_val,
2275 sub->sa_any[i]->bv_len );
2283 left.bv_val += sub->sa_any[i]->bv_len;
2284 left.bv_len -= sub->sa_any[i]->bv_len;
2285 inlen -= sub->sa_any[i]->bv_len;
2291 return LDAP_SUCCESS;
2294 /* Index generation function */
2295 int caseExactIA5Indexer(
2300 struct berval *prefix,
2301 struct berval **values,
2302 struct berval ***keysp )
2306 struct berval **keys;
2307 HASH_CONTEXT HASHcontext;
2308 unsigned char HASHdigest[HASH_BYTES];
2309 struct berval digest;
2310 digest.bv_val = HASHdigest;
2311 digest.bv_len = sizeof(HASHdigest);
2313 for( i=0; values[i] != NULL; i++ ) {
2314 /* empty - just count them */
2317 /* we should have at least one value at this point */
2320 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2322 slen = strlen( syntax->ssyn_oid );
2323 mlen = strlen( mr->smr_oid );
2325 for( i=0; values[i] != NULL; i++ ) {
2326 struct berval *value = values[i];
2328 HASH_Init( &HASHcontext );
2329 if( prefix != NULL && prefix->bv_len > 0 ) {
2330 HASH_Update( &HASHcontext,
2331 prefix->bv_val, prefix->bv_len );
2333 HASH_Update( &HASHcontext,
2334 syntax->ssyn_oid, slen );
2335 HASH_Update( &HASHcontext,
2336 mr->smr_oid, mlen );
2337 HASH_Update( &HASHcontext,
2338 value->bv_val, value->bv_len );
2339 HASH_Final( HASHdigest, &HASHcontext );
2341 keys[i] = ber_bvdup( &digest );
2346 return LDAP_SUCCESS;
2349 /* Index generation function */
2350 int caseExactIA5Filter(
2355 struct berval *prefix,
2357 struct berval ***keysp )
2360 struct berval **keys;
2361 HASH_CONTEXT HASHcontext;
2362 unsigned char HASHdigest[HASH_BYTES];
2363 struct berval *value;
2364 struct berval digest;
2365 digest.bv_val = HASHdigest;
2366 digest.bv_len = sizeof(HASHdigest);
2368 slen = strlen( syntax->ssyn_oid );
2369 mlen = strlen( mr->smr_oid );
2371 value = (struct berval *) assertValue;
2373 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2375 HASH_Init( &HASHcontext );
2376 if( prefix != NULL && prefix->bv_len > 0 ) {
2377 HASH_Update( &HASHcontext,
2378 prefix->bv_val, prefix->bv_len );
2380 HASH_Update( &HASHcontext,
2381 syntax->ssyn_oid, slen );
2382 HASH_Update( &HASHcontext,
2383 mr->smr_oid, mlen );
2384 HASH_Update( &HASHcontext,
2385 value->bv_val, value->bv_len );
2386 HASH_Final( HASHdigest, &HASHcontext );
2388 keys[0] = ber_bvdup( &digest );
2392 return LDAP_SUCCESS;
2395 /* Substrings Index generation function */
2396 int caseExactIA5SubstringsIndexer(
2401 struct berval *prefix,
2402 struct berval **values,
2403 struct berval ***keysp )
2407 struct berval **keys;
2408 HASH_CONTEXT HASHcontext;
2409 unsigned char HASHdigest[HASH_BYTES];
2410 struct berval digest;
2411 digest.bv_val = HASHdigest;
2412 digest.bv_len = sizeof(HASHdigest);
2414 /* we should have at least one value at this point */
2415 assert( values != NULL && values[0] != NULL );
2418 for( i=0; values[i] != NULL; i++ ) {
2419 /* count number of indices to generate */
2420 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2424 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2425 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2426 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2427 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2429 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2433 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2434 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2435 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2439 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2440 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2441 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2442 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2444 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2450 /* no keys to generate */
2452 return LDAP_SUCCESS;
2455 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2457 slen = strlen( syntax->ssyn_oid );
2458 mlen = strlen( mr->smr_oid );
2461 for( i=0; values[i] != NULL; i++ ) {
2463 struct berval *value;
2466 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2468 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2469 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2471 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2472 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2474 for( j=0; j<max; j++ ) {
2475 HASH_Init( &HASHcontext );
2476 if( prefix != NULL && prefix->bv_len > 0 ) {
2477 HASH_Update( &HASHcontext,
2478 prefix->bv_val, prefix->bv_len );
2481 HASH_Update( &HASHcontext,
2482 &pre, sizeof( pre ) );
2483 HASH_Update( &HASHcontext,
2484 syntax->ssyn_oid, slen );
2485 HASH_Update( &HASHcontext,
2486 mr->smr_oid, mlen );
2487 HASH_Update( &HASHcontext,
2489 SLAP_INDEX_SUBSTR_MAXLEN );
2490 HASH_Final( HASHdigest, &HASHcontext );
2492 keys[nkeys++] = ber_bvdup( &digest );
2496 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2497 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2499 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2502 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2503 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2504 HASH_Init( &HASHcontext );
2505 if( prefix != NULL && prefix->bv_len > 0 ) {
2506 HASH_Update( &HASHcontext,
2507 prefix->bv_val, prefix->bv_len );
2509 HASH_Update( &HASHcontext,
2510 &pre, sizeof( pre ) );
2511 HASH_Update( &HASHcontext,
2512 syntax->ssyn_oid, slen );
2513 HASH_Update( &HASHcontext,
2514 mr->smr_oid, mlen );
2515 HASH_Update( &HASHcontext,
2517 HASH_Final( HASHdigest, &HASHcontext );
2519 keys[nkeys++] = ber_bvdup( &digest );
2522 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2523 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2524 HASH_Init( &HASHcontext );
2525 if( prefix != NULL && prefix->bv_len > 0 ) {
2526 HASH_Update( &HASHcontext,
2527 prefix->bv_val, prefix->bv_len );
2529 HASH_Update( &HASHcontext,
2530 &pre, sizeof( pre ) );
2531 HASH_Update( &HASHcontext,
2532 syntax->ssyn_oid, slen );
2533 HASH_Update( &HASHcontext,
2534 mr->smr_oid, mlen );
2535 HASH_Update( &HASHcontext,
2536 &value->bv_val[value->bv_len-j], j );
2537 HASH_Final( HASHdigest, &HASHcontext );
2539 keys[nkeys++] = ber_bvdup( &digest );
2553 return LDAP_SUCCESS;
2556 int caseExactIA5SubstringsFilter(
2561 struct berval *prefix,
2563 struct berval ***keysp )
2565 SubstringsAssertion *sa = assertValue;
2567 ber_len_t nkeys = 0;
2568 size_t slen, mlen, klen;
2569 struct berval **keys;
2570 HASH_CONTEXT HASHcontext;
2571 unsigned char HASHdigest[HASH_BYTES];
2572 struct berval *value;
2573 struct berval digest;
2575 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2576 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2581 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2583 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2584 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2585 /* don't bother accounting for stepping */
2586 nkeys += sa->sa_any[i]->bv_len -
2587 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2592 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2593 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2600 return LDAP_SUCCESS;
2603 digest.bv_val = HASHdigest;
2604 digest.bv_len = sizeof(HASHdigest);
2606 slen = strlen( syntax->ssyn_oid );
2607 mlen = strlen( mr->smr_oid );
2609 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2612 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2613 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2615 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2616 value = sa->sa_initial;
2618 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2619 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2621 HASH_Init( &HASHcontext );
2622 if( prefix != NULL && prefix->bv_len > 0 ) {
2623 HASH_Update( &HASHcontext,
2624 prefix->bv_val, prefix->bv_len );
2626 HASH_Update( &HASHcontext,
2627 &pre, sizeof( pre ) );
2628 HASH_Update( &HASHcontext,
2629 syntax->ssyn_oid, slen );
2630 HASH_Update( &HASHcontext,
2631 mr->smr_oid, mlen );
2632 HASH_Update( &HASHcontext,
2633 value->bv_val, klen );
2634 HASH_Final( HASHdigest, &HASHcontext );
2636 keys[nkeys++] = ber_bvdup( &digest );
2639 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2641 pre = SLAP_INDEX_SUBSTR_PREFIX;
2642 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2644 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2645 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2649 value = sa->sa_any[i];
2652 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2653 j += SLAP_INDEX_SUBSTR_STEP )
2655 HASH_Init( &HASHcontext );
2656 if( prefix != NULL && prefix->bv_len > 0 ) {
2657 HASH_Update( &HASHcontext,
2658 prefix->bv_val, prefix->bv_len );
2660 HASH_Update( &HASHcontext,
2661 &pre, sizeof( pre ) );
2662 HASH_Update( &HASHcontext,
2663 syntax->ssyn_oid, slen );
2664 HASH_Update( &HASHcontext,
2665 mr->smr_oid, mlen );
2666 HASH_Update( &HASHcontext,
2667 &value->bv_val[j], klen );
2668 HASH_Final( HASHdigest, &HASHcontext );
2670 keys[nkeys++] = ber_bvdup( &digest );
2675 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2676 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2678 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2679 value = sa->sa_final;
2681 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2682 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2684 HASH_Init( &HASHcontext );
2685 if( prefix != NULL && prefix->bv_len > 0 ) {
2686 HASH_Update( &HASHcontext,
2687 prefix->bv_val, prefix->bv_len );
2689 HASH_Update( &HASHcontext,
2690 &pre, sizeof( pre ) );
2691 HASH_Update( &HASHcontext,
2692 syntax->ssyn_oid, slen );
2693 HASH_Update( &HASHcontext,
2694 mr->smr_oid, mlen );
2695 HASH_Update( &HASHcontext,
2696 &value->bv_val[value->bv_len-klen], klen );
2697 HASH_Final( HASHdigest, &HASHcontext );
2699 keys[nkeys++] = ber_bvdup( &digest );
2710 return LDAP_SUCCESS;
2719 struct berval *value,
2720 void *assertedValue )
2722 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2724 if( match == 0 && value->bv_len ) {
2725 match = strncasecmp( value->bv_val,
2726 ((struct berval *) assertedValue)->bv_val,
2731 return LDAP_SUCCESS;
2735 caseIgnoreIA5SubstringsMatch(
2740 struct berval *value,
2741 void *assertedValue )
2744 SubstringsAssertion *sub = assertedValue;
2745 struct berval left = *value;
2749 /* Add up asserted input length */
2750 if( sub->sa_initial ) {
2751 inlen += sub->sa_initial->bv_len;
2754 for(i=0; sub->sa_any[i] != NULL; i++) {
2755 inlen += sub->sa_any[i]->bv_len;
2758 if( sub->sa_final ) {
2759 inlen += sub->sa_final->bv_len;
2762 if( sub->sa_initial ) {
2763 if( inlen > left.bv_len ) {
2768 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2769 sub->sa_initial->bv_len );
2775 left.bv_val += sub->sa_initial->bv_len;
2776 left.bv_len -= sub->sa_initial->bv_len;
2777 inlen -= sub->sa_initial->bv_len;
2780 if( sub->sa_final ) {
2781 if( inlen > left.bv_len ) {
2786 match = strncasecmp( sub->sa_final->bv_val,
2787 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2788 sub->sa_final->bv_len );
2794 left.bv_len -= sub->sa_final->bv_len;
2795 inlen -= sub->sa_final->bv_len;
2799 for(i=0; sub->sa_any[i]; i++) {
2804 if( inlen > left.bv_len ) {
2805 /* not enough length */
2810 if( sub->sa_any[i]->bv_len == 0 ) {
2814 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2821 idx = p - left.bv_val;
2822 assert( idx < left.bv_len );
2824 if( idx >= left.bv_len ) {
2825 /* this shouldn't happen */
2832 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2833 /* not enough left */
2838 match = strncasecmp( left.bv_val,
2839 sub->sa_any[i]->bv_val,
2840 sub->sa_any[i]->bv_len );
2849 left.bv_val += sub->sa_any[i]->bv_len;
2850 left.bv_len -= sub->sa_any[i]->bv_len;
2851 inlen -= sub->sa_any[i]->bv_len;
2857 return LDAP_SUCCESS;
2860 /* Index generation function */
2861 int caseIgnoreIA5Indexer(
2866 struct berval *prefix,
2867 struct berval **values,
2868 struct berval ***keysp )
2872 struct berval **keys;
2873 HASH_CONTEXT HASHcontext;
2874 unsigned char HASHdigest[HASH_BYTES];
2875 struct berval digest;
2876 digest.bv_val = HASHdigest;
2877 digest.bv_len = sizeof(HASHdigest);
2879 /* we should have at least one value at this point */
2880 assert( values != NULL && values[0] != NULL );
2882 for( i=0; values[i] != NULL; i++ ) {
2883 /* just count them */
2886 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2888 slen = strlen( syntax->ssyn_oid );
2889 mlen = strlen( mr->smr_oid );
2891 for( i=0; values[i] != NULL; i++ ) {
2892 struct berval *value = ber_bvdup( values[i] );
2893 ldap_pvt_str2upper( value->bv_val );
2895 HASH_Init( &HASHcontext );
2896 if( prefix != NULL && prefix->bv_len > 0 ) {
2897 HASH_Update( &HASHcontext,
2898 prefix->bv_val, prefix->bv_len );
2900 HASH_Update( &HASHcontext,
2901 syntax->ssyn_oid, slen );
2902 HASH_Update( &HASHcontext,
2903 mr->smr_oid, mlen );
2904 HASH_Update( &HASHcontext,
2905 value->bv_val, value->bv_len );
2906 HASH_Final( HASHdigest, &HASHcontext );
2908 ber_bvfree( value );
2910 keys[i] = ber_bvdup( &digest );
2915 return LDAP_SUCCESS;
2918 /* Index generation function */
2919 int caseIgnoreIA5Filter(
2924 struct berval *prefix,
2926 struct berval ***keysp )
2929 struct berval **keys;
2930 HASH_CONTEXT HASHcontext;
2931 unsigned char HASHdigest[HASH_BYTES];
2932 struct berval *value;
2933 struct berval digest;
2934 digest.bv_val = HASHdigest;
2935 digest.bv_len = sizeof(HASHdigest);
2937 slen = strlen( syntax->ssyn_oid );
2938 mlen = strlen( mr->smr_oid );
2940 value = ber_bvdup( (struct berval *) assertValue );
2941 ldap_pvt_str2upper( value->bv_val );
2943 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2945 HASH_Init( &HASHcontext );
2946 if( prefix != NULL && prefix->bv_len > 0 ) {
2947 HASH_Update( &HASHcontext,
2948 prefix->bv_val, prefix->bv_len );
2950 HASH_Update( &HASHcontext,
2951 syntax->ssyn_oid, slen );
2952 HASH_Update( &HASHcontext,
2953 mr->smr_oid, mlen );
2954 HASH_Update( &HASHcontext,
2955 value->bv_val, value->bv_len );
2956 HASH_Final( HASHdigest, &HASHcontext );
2958 keys[0] = ber_bvdup( &digest );
2961 ber_bvfree( value );
2965 return LDAP_SUCCESS;
2968 /* Substrings Index generation function */
2969 int caseIgnoreIA5SubstringsIndexer(
2974 struct berval *prefix,
2975 struct berval **values,
2976 struct berval ***keysp )
2980 struct berval **keys;
2981 HASH_CONTEXT HASHcontext;
2982 unsigned char HASHdigest[HASH_BYTES];
2983 struct berval digest;
2984 digest.bv_val = HASHdigest;
2985 digest.bv_len = sizeof(HASHdigest);
2987 /* we should have at least one value at this point */
2988 assert( values != NULL && values[0] != NULL );
2991 for( i=0; values[i] != NULL; i++ ) {
2992 /* count number of indices to generate */
2993 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2997 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2998 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2999 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3000 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3002 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3006 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
3007 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3008 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3012 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3013 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3014 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
3015 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
3017 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
3023 /* no keys to generate */
3025 return LDAP_SUCCESS;
3028 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3030 slen = strlen( syntax->ssyn_oid );
3031 mlen = strlen( mr->smr_oid );
3034 for( i=0; values[i] != NULL; i++ ) {
3036 struct berval *value;
3038 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
3040 value = ber_bvdup( values[i] );
3041 ldap_pvt_str2upper( value->bv_val );
3043 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
3044 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
3046 char pre = SLAP_INDEX_SUBSTR_PREFIX;
3047 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
3049 for( j=0; j<max; j++ ) {
3050 HASH_Init( &HASHcontext );
3051 if( prefix != NULL && prefix->bv_len > 0 ) {
3052 HASH_Update( &HASHcontext,
3053 prefix->bv_val, prefix->bv_len );
3056 HASH_Update( &HASHcontext,
3057 &pre, sizeof( pre ) );
3058 HASH_Update( &HASHcontext,
3059 syntax->ssyn_oid, slen );
3060 HASH_Update( &HASHcontext,
3061 mr->smr_oid, mlen );
3062 HASH_Update( &HASHcontext,
3064 SLAP_INDEX_SUBSTR_MAXLEN );
3065 HASH_Final( HASHdigest, &HASHcontext );
3067 keys[nkeys++] = ber_bvdup( &digest );
3071 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3072 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3074 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
3077 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
3078 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3079 HASH_Init( &HASHcontext );
3080 if( prefix != NULL && prefix->bv_len > 0 ) {
3081 HASH_Update( &HASHcontext,
3082 prefix->bv_val, prefix->bv_len );
3084 HASH_Update( &HASHcontext,
3085 &pre, sizeof( pre ) );
3086 HASH_Update( &HASHcontext,
3087 syntax->ssyn_oid, slen );
3088 HASH_Update( &HASHcontext,
3089 mr->smr_oid, mlen );
3090 HASH_Update( &HASHcontext,
3092 HASH_Final( HASHdigest, &HASHcontext );
3094 keys[nkeys++] = ber_bvdup( &digest );
3097 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3098 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3099 HASH_Init( &HASHcontext );
3100 if( prefix != NULL && prefix->bv_len > 0 ) {
3101 HASH_Update( &HASHcontext,
3102 prefix->bv_val, prefix->bv_len );
3104 HASH_Update( &HASHcontext,
3105 &pre, sizeof( pre ) );
3106 HASH_Update( &HASHcontext,
3107 syntax->ssyn_oid, slen );
3108 HASH_Update( &HASHcontext,
3109 mr->smr_oid, mlen );
3110 HASH_Update( &HASHcontext,
3111 &value->bv_val[value->bv_len-j], j );
3112 HASH_Final( HASHdigest, &HASHcontext );
3114 keys[nkeys++] = ber_bvdup( &digest );
3119 ber_bvfree( value );
3130 return LDAP_SUCCESS;
3133 int caseIgnoreIA5SubstringsFilter(
3138 struct berval *prefix,
3140 struct berval ***keysp )
3142 SubstringsAssertion *sa = assertValue;
3144 ber_len_t nkeys = 0;
3145 size_t slen, mlen, klen;
3146 struct berval **keys;
3147 HASH_CONTEXT HASHcontext;
3148 unsigned char HASHdigest[HASH_BYTES];
3149 struct berval *value;
3150 struct berval digest;
3152 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3153 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3158 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3160 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3161 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3162 /* don't bother accounting for stepping */
3163 nkeys += sa->sa_any[i]->bv_len -
3164 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3169 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3170 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3177 return LDAP_SUCCESS;
3180 digest.bv_val = HASHdigest;
3181 digest.bv_len = sizeof(HASHdigest);
3183 slen = strlen( syntax->ssyn_oid );
3184 mlen = strlen( mr->smr_oid );
3186 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3189 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3190 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3192 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3193 value = ber_bvdup( sa->sa_initial );
3194 ldap_pvt_str2upper( value->bv_val );
3196 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3197 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3199 HASH_Init( &HASHcontext );
3200 if( prefix != NULL && prefix->bv_len > 0 ) {
3201 HASH_Update( &HASHcontext,
3202 prefix->bv_val, prefix->bv_len );
3204 HASH_Update( &HASHcontext,
3205 &pre, sizeof( pre ) );
3206 HASH_Update( &HASHcontext,
3207 syntax->ssyn_oid, slen );
3208 HASH_Update( &HASHcontext,
3209 mr->smr_oid, mlen );
3210 HASH_Update( &HASHcontext,
3211 value->bv_val, klen );
3212 HASH_Final( HASHdigest, &HASHcontext );
3214 ber_bvfree( value );
3215 keys[nkeys++] = ber_bvdup( &digest );
3218 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3220 pre = SLAP_INDEX_SUBSTR_PREFIX;
3221 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3223 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3224 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3228 value = ber_bvdup( sa->sa_any[i] );
3229 ldap_pvt_str2upper( value->bv_val );
3232 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3233 j += SLAP_INDEX_SUBSTR_STEP )
3235 HASH_Init( &HASHcontext );
3236 if( prefix != NULL && prefix->bv_len > 0 ) {
3237 HASH_Update( &HASHcontext,
3238 prefix->bv_val, prefix->bv_len );
3240 HASH_Update( &HASHcontext,
3241 &pre, sizeof( pre ) );
3242 HASH_Update( &HASHcontext,
3243 syntax->ssyn_oid, slen );
3244 HASH_Update( &HASHcontext,
3245 mr->smr_oid, mlen );
3246 HASH_Update( &HASHcontext,
3247 &value->bv_val[j], klen );
3248 HASH_Final( HASHdigest, &HASHcontext );
3250 keys[nkeys++] = ber_bvdup( &digest );
3253 ber_bvfree( value );
3257 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3258 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3260 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3261 value = ber_bvdup( sa->sa_final );
3262 ldap_pvt_str2upper( value->bv_val );
3264 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3265 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3267 HASH_Init( &HASHcontext );
3268 if( prefix != NULL && prefix->bv_len > 0 ) {
3269 HASH_Update( &HASHcontext,
3270 prefix->bv_val, prefix->bv_len );
3272 HASH_Update( &HASHcontext,
3273 &pre, sizeof( pre ) );
3274 HASH_Update( &HASHcontext,
3275 syntax->ssyn_oid, slen );
3276 HASH_Update( &HASHcontext,
3277 mr->smr_oid, mlen );
3278 HASH_Update( &HASHcontext,
3279 &value->bv_val[value->bv_len-klen], klen );
3280 HASH_Final( HASHdigest, &HASHcontext );
3282 ber_bvfree( value );
3283 keys[nkeys++] = ber_bvdup( &digest );
3294 return LDAP_SUCCESS;
3298 numericStringValidate(
3304 for(i=0; i < in->bv_len; i++) {
3305 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3306 return LDAP_INVALID_SYNTAX;
3310 return LDAP_SUCCESS;
3314 numericStringNormalize(
3317 struct berval **normalized )
3319 /* removal all spaces */
3320 struct berval *newval;
3323 newval = ch_malloc( sizeof( struct berval ) );
3324 newval->bv_val = ch_malloc( val->bv_len + 1 );
3330 if ( ASCII_SPACE( *p ) ) {
3331 /* Ignore whitespace */
3338 /* we should have copied no more then is in val */
3339 assert( (q - newval->bv_val) <= (p - val->bv_val) );
3341 /* null terminate */
3344 newval->bv_len = q - newval->bv_val;
3345 *normalized = newval;
3347 return LDAP_SUCCESS;
3351 objectIdentifierFirstComponentMatch(
3356 struct berval *value,
3357 void *assertedValue )
3359 int rc = LDAP_SUCCESS;
3361 struct berval *asserted = (struct berval *) assertedValue;
3365 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3366 return LDAP_INVALID_SYNTAX;
3369 /* trim leading white space */
3370 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3374 /* grab next word */
3375 oid.bv_val = &value->bv_val[i];
3376 oid.bv_len = value->bv_len - i;
3377 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3382 /* insert attributeTypes, objectclass check here */
3383 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3384 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3387 char *stored = ch_malloc( oid.bv_len + 1 );
3388 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3389 stored[oid.bv_len] = '\0';
3391 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3392 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3393 MatchingRule *stored_mr = mr_find( stored );
3395 if( asserted_mr == NULL ) {
3396 rc = SLAPD_COMPARE_UNDEFINED;
3398 match = asserted_mr != stored_mr;
3401 } else if ( !strcmp( syntax->ssyn_oid,
3402 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3404 AttributeType *asserted_at = at_find( asserted->bv_val );
3405 AttributeType *stored_at = at_find( stored );
3407 if( asserted_at == NULL ) {
3408 rc = SLAPD_COMPARE_UNDEFINED;
3410 match = asserted_at != stored_at;
3413 } else if ( !strcmp( syntax->ssyn_oid,
3414 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3416 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3417 ObjectClass *stored_oc = oc_find( stored );
3419 if( asserted_oc == NULL ) {
3420 rc = SLAPD_COMPARE_UNDEFINED;
3422 match = asserted_oc != stored_oc;
3430 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3431 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3432 match, value->bv_val, asserted->bv_val ));
3434 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3435 "%d\n\t\"%s\"\n\t\"%s\"\n",
3436 match, value->bv_val, asserted->bv_val );
3440 if( rc == LDAP_SUCCESS ) *matchp = match;
3450 struct berval *value,
3451 void *assertedValue )
3453 long lValue, lAssertedValue;
3455 /* safe to assume integers are NUL terminated? */
3456 lValue = strtoul(value->bv_val, NULL, 10);
3457 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3458 return LDAP_CONSTRAINT_VIOLATION;
3460 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3461 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3462 return LDAP_CONSTRAINT_VIOLATION;
3464 *matchp = (lValue & lAssertedValue);
3465 return LDAP_SUCCESS;
3474 struct berval *value,
3475 void *assertedValue )
3477 long lValue, lAssertedValue;
3479 /* safe to assume integers are NUL terminated? */
3480 lValue = strtoul(value->bv_val, NULL, 10);
3481 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3482 return LDAP_CONSTRAINT_VIOLATION;
3484 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3485 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3486 return LDAP_CONSTRAINT_VIOLATION;
3488 *matchp = (lValue | lAssertedValue);
3489 return LDAP_SUCCESS;
3493 #include <openssl/x509.h>
3494 #include <openssl/err.h>
3495 char digit[] = "0123456789";
3498 * Next function returns a string representation of a ASN1_INTEGER.
3499 * It works for unlimited lengths.
3502 static struct berval *
3503 asn1_integer2str(ASN1_INTEGER *a)
3508 /* We work backwards, make it fill from the end of buf */
3509 p = buf + sizeof(buf) - 1;
3512 if ( a == NULL || a->length == 0 ) {
3520 /* We want to preserve the original */
3521 copy = ch_malloc(n*sizeof(unsigned int));
3522 for (i = 0; i<n; i++) {
3523 copy[i] = a->data[i];
3527 * base indicates the index of the most significant
3528 * byte that might be nonzero. When it goes off the
3529 * end, we now there is nothing left to do.
3535 for (i = base; i<n; i++ ) {
3536 copy[i] += carry*256;
3537 carry = copy[i] % 10;
3542 * Way too large, we need to leave
3543 * room for sign if negative
3548 *--p = digit[carry];
3549 if (copy[base] == 0)
3555 if ( a->type == V_ASN1_NEG_INTEGER ) {
3559 return ber_bvstrdup(p);
3562 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3563 static struct berval *
3564 dn_openssl2ldap(X509_NAME *name)
3566 char issuer_dn[1024];
3569 bio = BIO_new(BIO_s_mem());
3572 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3573 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3574 ERR_error_string(ERR_get_error(),NULL)));
3576 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3577 "error creating BIO: %s\n",
3578 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3582 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3584 BIO_gets(bio, issuer_dn, 1024);
3587 return ber_bvstrdup(issuer_dn);
3591 * Given a certificate in DER format, extract the corresponding
3592 * assertion value for certificateExactMatch
3595 certificateExactConvert(
3597 struct berval ** out )
3600 unsigned char *p = in->bv_val;
3601 struct berval *serial;
3602 struct berval *issuer_dn;
3603 struct berval *bv_tmp;
3605 xcert = d2i_X509(NULL, &p, in->bv_len);
3608 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3609 "certificateExactConvert: error parsing cert: %s\n",
3610 ERR_error_string(ERR_get_error(),NULL)));
3612 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3613 "error parsing cert: %s\n",
3614 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3616 return LDAP_INVALID_SYNTAX;
3619 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3622 return LDAP_INVALID_SYNTAX;
3624 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3628 return LDAP_INVALID_SYNTAX;
3630 /* Actually, dn_openssl2ldap returns in a normalized format, but
3631 it is different from our normalized format */
3633 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3637 return LDAP_INVALID_SYNTAX;
3643 *out = ch_malloc(sizeof(struct berval));
3644 (*out)->bv_len = serial->bv_len + 3 + issuer_dn->bv_len + 1;
3645 (*out)->bv_val = ch_malloc((*out)->bv_len);
3647 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3648 p += serial->bv_len;
3649 AC_MEMCPY(p, " $ ", 3);
3651 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3652 p += issuer_dn->bv_len;
3656 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3657 "certificateExactConvert: \n %s\n",
3660 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3662 (*out)->bv_val, NULL, NULL );
3666 ber_bvfree(issuer_dn);
3668 return LDAP_SUCCESS;
3672 serial_and_issuer_parse(
3673 struct berval *assertion,
3674 struct berval **serial,
3675 struct berval **issuer_dn
3683 begin = assertion->bv_val;
3684 end = assertion->bv_val+assertion->bv_len-1;
3685 for (p=begin; p<=end && *p != '$'; p++)
3688 return LDAP_INVALID_SYNTAX;
3690 /* p now points at the $ sign, now use begin and end to delimit the
3692 while (ASCII_SPACE(*begin))
3695 while (ASCII_SPACE(*end))
3698 q = ch_malloc( (end-begin+1)+1 );
3699 AC_MEMCPY( q, begin, end-begin+1 );
3700 q[end-begin+1] = '\0';
3701 *serial = ber_bvstr(q);
3703 /* now extract the issuer, remember p was at the dollar sign */
3705 end = assertion->bv_val+assertion->bv_len-1;
3706 while (ASCII_SPACE(*begin))
3708 /* should we trim spaces at the end too? is it safe always? */
3710 q = ch_malloc( (end-begin+1)+1 );
3711 AC_MEMCPY( q, begin, end-begin+1 );
3712 q[end-begin+1] = '\0';
3713 *issuer_dn = ber_bvstr(dn_normalize(q));
3715 return LDAP_SUCCESS;
3719 certificateExactMatch(
3724 struct berval *value,
3725 void *assertedValue )
3728 unsigned char *p = value->bv_val;
3729 struct berval *serial;
3730 struct berval *issuer_dn;
3731 struct berval *asserted_serial;
3732 struct berval *asserted_issuer_dn;
3735 xcert = d2i_X509(NULL, &p, value->bv_len);
3738 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3739 "certificateExactMatch: error parsing cert: %s\n",
3740 ERR_error_string(ERR_get_error(),NULL)));
3742 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3743 "error parsing cert: %s\n",
3744 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3746 return LDAP_INVALID_SYNTAX;
3749 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3750 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3754 serial_and_issuer_parse(assertedValue,
3756 &asserted_issuer_dn);
3761 slap_schema.si_syn_integer,
3762 slap_schema.si_mr_integerMatch,
3765 if ( ret == LDAP_SUCCESS ) {
3766 if ( *matchp == 0 ) {
3767 /* We need to normalize everything for dnMatch */
3771 slap_schema.si_syn_distinguishedName,
3772 slap_schema.si_mr_distinguishedNameMatch,
3774 asserted_issuer_dn);
3779 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3780 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3781 *matchp, serial->bv_val, issuer_dn->bv_val,
3782 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3784 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3785 "%d\n\t\"%s $ %s\"\n",
3786 *matchp, serial->bv_val, issuer_dn->bv_val );
3787 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3788 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3793 ber_bvfree(issuer_dn);
3794 ber_bvfree(asserted_serial);
3795 ber_bvfree(asserted_issuer_dn);
3801 * Index generation function
3802 * We just index the serials, in most scenarios the issuer DN is one of
3803 * a very small set of values.
3805 int certificateExactIndexer(
3810 struct berval *prefix,
3811 struct berval **values,
3812 struct berval ***keysp )
3815 struct berval **keys;
3818 struct berval * serial;
3820 /* we should have at least one value at this point */
3821 assert( values != NULL && values[0] != NULL );
3823 for( i=0; values[i] != NULL; i++ ) {
3824 /* empty -- just count them */
3827 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
3829 for( i=0; values[i] != NULL; i++ ) {
3830 p = values[i]->bv_val;
3831 xcert = d2i_X509(NULL, &p, values[i]->bv_len);
3834 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3835 "certificateExactIndexer: error parsing cert: %s\n",
3836 ERR_error_string(ERR_get_error(),NULL)));
3838 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3839 "error parsing cert: %s\n",
3840 ERR_error_string(ERR_get_error(),NULL),
3843 /* Do we leak keys on error? */
3844 return LDAP_INVALID_SYNTAX;
3847 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3849 integerNormalize( slap_schema.si_syn_integer,
3854 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3855 "certificateExactIndexer: returning: %s\n",
3858 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3867 return LDAP_SUCCESS;
3870 /* Index generation function */
3871 /* We think this is always called with a value in matching rule syntax */
3872 int certificateExactFilter(
3877 struct berval *prefix,
3879 struct berval ***keysp )
3881 struct berval **keys;
3882 struct berval *asserted_serial;
3883 struct berval *asserted_issuer_dn;
3885 serial_and_issuer_parse(assertValue,
3887 &asserted_issuer_dn);
3889 keys = ch_malloc( sizeof( struct berval * ) * 2 );
3890 integerNormalize( syntax, asserted_serial, &keys[0] );
3894 ber_bvfree(asserted_serial);
3895 ber_bvfree(asserted_issuer_dn);
3896 return LDAP_SUCCESS;
3901 check_time_syntax (struct berval *val,
3905 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3906 static int mdays[2][12] = {
3907 /* non-leap years */
3908 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3910 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3913 int part, c, tzoffset, leapyear = 0 ;
3915 if( val->bv_len == 0 ) {
3916 return LDAP_INVALID_SYNTAX;
3919 p = (char *)val->bv_val;
3920 e = p + val->bv_len;
3922 /* Ignore initial whitespace */
3923 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3927 if (e - p < 13 - (2 * start)) {
3928 return LDAP_INVALID_SYNTAX;
3931 for (part = 0; part < 9; part++) {
3935 for (part = start; part < 7; part++) {
3937 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3944 return LDAP_INVALID_SYNTAX;
3946 if (c < 0 || c > 9) {
3947 return LDAP_INVALID_SYNTAX;
3953 return LDAP_INVALID_SYNTAX;
3955 if (c < 0 || c > 9) {
3956 return LDAP_INVALID_SYNTAX;
3961 if (part == 2 || part == 3) {
3964 if (parts[part] < 0) {
3965 return LDAP_INVALID_SYNTAX;
3967 if (parts[part] > ceiling[part]) {
3968 return LDAP_INVALID_SYNTAX;
3972 /* leapyear check for the Gregorian calendar (year>1581) */
3973 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3974 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3979 if (parts[3] > mdays[leapyear][parts[2]]) {
3980 return LDAP_INVALID_SYNTAX;
3985 tzoffset = 0; /* UTC */
3986 } else if (c != '+' && c != '-') {
3987 return LDAP_INVALID_SYNTAX;
3991 } else /* c == '+' */ {
3996 return LDAP_INVALID_SYNTAX;
3999 for (part = 7; part < 9; part++) {
4001 if (c < 0 || c > 9) {
4002 return LDAP_INVALID_SYNTAX;
4007 if (c < 0 || c > 9) {
4008 return LDAP_INVALID_SYNTAX;
4012 if (parts[part] < 0 || parts[part] > ceiling[part]) {
4013 return LDAP_INVALID_SYNTAX;
4018 /* Ignore trailing whitespace */
4019 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
4023 return LDAP_INVALID_SYNTAX;
4026 switch ( tzoffset ) {
4027 case -1: /* negativ offset to UTC, ie west of Greenwich */
4028 parts[4] += parts[7];
4029 parts[5] += parts[8];
4030 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
4034 c = mdays[leapyear][parts[2]];
4036 if (parts[part] > c) {
4037 parts[part] -= c + 1;
4042 case 1: /* positive offset to UTC, ie east of Greenwich */
4043 parts[4] -= parts[7];
4044 parts[5] -= parts[8];
4045 for (part = 6; --part > 0; ) {
4049 /* first arg to % needs to be non negativ */
4050 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
4052 if (parts[part] < 0) {
4053 parts[part] += c + 1;
4058 case 0: /* already UTC */
4062 return LDAP_SUCCESS;
4069 struct berval **normalized )
4074 rc = check_time_syntax(val, 1, parts);
4075 if (rc != LDAP_SUCCESS) {
4080 out = ch_malloc( sizeof(struct berval) );
4082 return LBER_ERROR_MEMORY;
4085 out->bv_val = ch_malloc( 14 );
4086 if ( out->bv_val == NULL ) {
4088 return LBER_ERROR_MEMORY;
4091 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02dZ",
4092 parts[1], parts[2] + 1, parts[3] + 1,
4093 parts[4], parts[5], parts[6] );
4097 return LDAP_SUCCESS;
4107 return check_time_syntax(in, 1, parts);
4111 generalizedTimeValidate(
4117 return check_time_syntax(in, 0, parts);
4121 generalizedTimeNormalize(
4124 struct berval **normalized )
4129 rc = check_time_syntax(val, 0, parts);
4130 if (rc != LDAP_SUCCESS) {
4135 out = ch_malloc( sizeof(struct berval) );
4137 return LBER_ERROR_MEMORY;
4140 out->bv_val = ch_malloc( 16 );
4141 if ( out->bv_val == NULL ) {
4143 return LBER_ERROR_MEMORY;
4146 sprintf( out->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4147 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4148 parts[4], parts[5], parts[6] );
4152 return LDAP_SUCCESS;
4156 nisNetgroupTripleValidate(
4158 struct berval *val )
4163 if ( val->bv_len == 0 ) {
4164 return LDAP_INVALID_SYNTAX;
4167 p = (char *)val->bv_val;
4168 e = p + val->bv_len;
4170 if ( *p != '(' /*')'*/ ) {
4171 return LDAP_INVALID_SYNTAX;
4174 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
4178 return LDAP_INVALID_SYNTAX;
4181 } else if ( !ATTR_CHAR( *p ) ) {
4182 return LDAP_INVALID_SYNTAX;
4186 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4187 return LDAP_INVALID_SYNTAX;
4193 return LDAP_INVALID_SYNTAX;
4196 return LDAP_SUCCESS;
4200 bootParameterValidate(
4202 struct berval *val )
4206 if ( val->bv_len == 0 ) {
4207 return LDAP_INVALID_SYNTAX;
4210 p = (char *)val->bv_val;
4211 e = p + val->bv_len;
4214 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4215 if ( !ATTR_CHAR( *p ) ) {
4216 return LDAP_INVALID_SYNTAX;
4221 return LDAP_INVALID_SYNTAX;
4225 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4226 if ( !ATTR_CHAR( *p ) ) {
4227 return LDAP_INVALID_SYNTAX;
4232 return LDAP_INVALID_SYNTAX;
4236 for ( p++; p < e; p++ ) {
4237 if ( !ATTR_CHAR( *p ) ) {
4238 return LDAP_INVALID_SYNTAX;
4242 return LDAP_SUCCESS;
4245 struct syntax_defs_rec {
4248 slap_syntax_validate_func *sd_validate;
4249 slap_syntax_transform_func *sd_normalize;
4250 slap_syntax_transform_func *sd_pretty;
4251 #ifdef SLAPD_BINARY_CONVERSION
4252 slap_syntax_transform_func *sd_ber2str;
4253 slap_syntax_transform_func *sd_str2ber;
4257 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4258 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4260 struct syntax_defs_rec syntax_defs[] = {
4261 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
4262 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4263 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4264 0, NULL, NULL, NULL},
4265 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4266 0, NULL, NULL, NULL},
4267 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
4268 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4269 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_NOT_H_R ")",
4270 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4271 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4272 0, bitStringValidate, bitStringNormalize, NULL },
4273 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4274 0, booleanValidate, NULL, NULL},
4275 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4276 X_BINARY X_NOT_H_R ")",
4277 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4278 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4279 X_BINARY X_NOT_H_R ")",
4280 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4281 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4282 X_BINARY X_NOT_H_R ")",
4283 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4284 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4285 0, countryStringValidate, IA5StringNormalize, NULL},
4286 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4287 0, dnValidate, dnNormalize, dnPretty},
4288 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4289 0, NULL, NULL, NULL},
4290 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4291 0, NULL, NULL, NULL},
4292 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4293 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4294 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4295 0, NULL, NULL, NULL},
4296 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4297 0, NULL, NULL, NULL},
4298 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4299 0, NULL, NULL, NULL},
4300 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4301 0, NULL, NULL, NULL},
4302 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4303 0, NULL, NULL, NULL},
4304 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4305 0, printablesStringValidate, IA5StringNormalize, NULL},
4306 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4307 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4308 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4309 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4310 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4311 0, NULL, NULL, NULL},
4312 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4313 0, IA5StringValidate, IA5StringNormalize, NULL},
4314 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4315 0, integerValidate, integerNormalize, NULL},
4316 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4317 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4318 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4319 0, NULL, NULL, NULL},
4320 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4321 0, NULL, NULL, NULL},
4322 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4323 0, NULL, NULL, NULL},
4324 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4325 0, NULL, NULL, NULL},
4326 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4327 0, NULL, NULL, NULL},
4328 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4329 0, nameUIDValidate, nameUIDNormalize, NULL},
4330 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4331 0, NULL, NULL, NULL},
4332 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4333 0, numericStringValidate, numericStringNormalize, NULL},
4334 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4335 0, NULL, NULL, NULL},
4336 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4337 0, oidValidate, NULL, NULL},
4338 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4339 0, IA5StringValidate, IA5StringNormalize, NULL},
4340 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4341 0, blobValidate, NULL, NULL},
4342 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4343 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4344 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4345 0, NULL, NULL, NULL},
4346 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4347 0, NULL, NULL, NULL},
4348 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4349 0, printableStringValidate, IA5StringNormalize, NULL},
4350 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4351 X_BINARY X_NOT_H_R ")",
4352 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4353 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4354 0, printableStringValidate, IA5StringNormalize, NULL},
4355 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4356 0, NULL, NULL, NULL},
4357 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4358 0, printablesStringValidate, IA5StringNormalize, NULL},
4359 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4360 0, utcTimeValidate, utcTimeNormalize, NULL},
4361 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4362 0, NULL, NULL, NULL},
4363 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4364 0, NULL, NULL, NULL},
4365 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4366 0, NULL, NULL, NULL},
4367 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4368 0, NULL, NULL, NULL},
4369 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4370 0, NULL, NULL, NULL},
4372 /* RFC 2307 NIS Syntaxes */
4373 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4374 0, nisNetgroupTripleValidate, NULL, NULL},
4375 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4376 0, bootParameterValidate, NULL, NULL},
4380 /* These OIDs are not published yet, but will be in the next
4381 * I-D for PKIX LDAPv3 schema as have been advanced by David
4382 * Chadwick in private mail.
4384 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4385 0, NULL, NULL, NULL},
4388 /* OpenLDAP Experimental Syntaxes */
4389 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4391 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4394 /* needs updating */
4395 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4396 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4398 /* OpenLDAP Void Syntax */
4399 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4400 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4401 {NULL, 0, NULL, NULL, NULL}
4404 struct mrule_defs_rec {
4406 slap_mask_t mrd_usage;
4407 slap_mr_convert_func * mrd_convert;
4408 slap_mr_normalize_func * mrd_normalize;
4409 slap_mr_match_func * mrd_match;
4410 slap_mr_indexer_func * mrd_indexer;
4411 slap_mr_filter_func * mrd_filter;
4413 char * mrd_associated;
4417 * Other matching rules in X.520 that we do not use (yet):
4419 * 2.5.13.9 numericStringOrderingMatch
4420 * 2.5.13.15 integerOrderingMatch
4421 * 2.5.13.18 octetStringOrderingMatch
4422 * 2.5.13.19 octetStringSubstringsMatch
4423 * 2.5.13.25 uTCTimeMatch
4424 * 2.5.13.26 uTCTimeOrderingMatch
4425 * 2.5.13.31 directoryStringFirstComponentMatch
4426 * 2.5.13.32 wordMatch
4427 * 2.5.13.33 keywordMatch
4428 * 2.5.13.35 certificateMatch
4429 * 2.5.13.36 certificatePairExactMatch
4430 * 2.5.13.37 certificatePairMatch
4431 * 2.5.13.38 certificateListExactMatch
4432 * 2.5.13.39 certificateListMatch
4433 * 2.5.13.40 algorithmIdentifierMatch
4434 * 2.5.13.41 storedPrefixMatch
4435 * 2.5.13.42 attributeCertificateMatch
4436 * 2.5.13.43 readerAndKeyIDMatch
4437 * 2.5.13.44 attributeIntegrityMatch
4440 struct mrule_defs_rec mrule_defs[] = {
4442 * EQUALITY matching rules must be listed after associated APPROX
4443 * matching rules. So, we list all APPROX matching rules first.
4445 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4446 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4447 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4449 directoryStringApproxMatch,
4450 directoryStringApproxIndexer,
4451 directoryStringApproxFilter,
4454 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4455 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4456 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4458 IA5StringApproxMatch,
4459 IA5StringApproxIndexer,
4460 IA5StringApproxFilter,
4464 * Other matching rules
4467 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4468 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4469 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4471 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4474 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4475 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4476 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4478 dnMatch, dnIndexer, dnFilter,
4481 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4482 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4483 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4485 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4486 directoryStringApproxMatchOID },
4488 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4489 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4492 caseIgnoreOrderingMatch, NULL, NULL,
4495 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4496 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4497 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4499 caseExactIgnoreSubstringsMatch,
4500 caseExactIgnoreSubstringsIndexer,
4501 caseExactIgnoreSubstringsFilter,
4504 {"( 2.5.13.5 NAME 'caseExactMatch' "
4505 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4506 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4508 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4509 directoryStringApproxMatchOID },
4511 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4512 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4515 caseExactOrderingMatch, NULL, NULL,
4518 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4519 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4520 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4522 caseExactIgnoreSubstringsMatch,
4523 caseExactIgnoreSubstringsIndexer,
4524 caseExactIgnoreSubstringsFilter,
4527 {"( 2.5.13.8 NAME 'numericStringMatch' "
4528 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4529 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4532 caseIgnoreIA5Indexer,
4533 caseIgnoreIA5Filter,
4536 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4537 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4538 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4540 caseIgnoreIA5SubstringsMatch,
4541 caseIgnoreIA5SubstringsIndexer,
4542 caseIgnoreIA5SubstringsFilter,
4545 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4546 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4547 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4549 caseIgnoreListMatch, NULL, NULL,
4552 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4553 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4554 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4556 caseIgnoreListSubstringsMatch, NULL, NULL,
4559 {"( 2.5.13.13 NAME 'booleanMatch' "
4560 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4561 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4563 booleanMatch, NULL, NULL,
4566 {"( 2.5.13.14 NAME 'integerMatch' "
4567 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4568 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4570 integerMatch, integerIndexer, integerFilter,
4573 {"( 2.5.13.16 NAME 'bitStringMatch' "
4574 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4575 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4577 bitStringMatch, bitStringIndexer, bitStringFilter,
4580 {"( 2.5.13.17 NAME 'octetStringMatch' "
4581 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4582 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4584 octetStringMatch, octetStringIndexer, octetStringFilter,
4587 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4588 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4589 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4591 telephoneNumberMatch,
4592 telephoneNumberIndexer,
4593 telephoneNumberFilter,
4596 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4597 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4598 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4600 telephoneNumberSubstringsMatch,
4601 telephoneNumberSubstringsIndexer,
4602 telephoneNumberSubstringsFilter,
4605 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4606 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4607 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4612 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4613 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4614 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4616 uniqueMemberMatch, NULL, NULL,
4619 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4620 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4621 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4623 protocolInformationMatch, NULL, NULL,
4626 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4627 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4628 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4630 generalizedTimeMatch, NULL, NULL,
4633 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4634 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4637 generalizedTimeOrderingMatch, NULL, NULL,
4640 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4641 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4642 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4644 integerFirstComponentMatch, NULL, NULL,
4647 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4648 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4649 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4651 objectIdentifierFirstComponentMatch, NULL, NULL,
4655 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4656 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4657 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4658 certificateExactConvert, NULL,
4659 certificateExactMatch,
4660 certificateExactIndexer, certificateExactFilter,
4664 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4665 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4666 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4668 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4669 IA5StringApproxMatchOID },
4671 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4672 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4673 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4675 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4676 IA5StringApproxMatchOID },
4678 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4679 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4682 caseIgnoreIA5SubstringsMatch,
4683 caseIgnoreIA5SubstringsIndexer,
4684 caseIgnoreIA5SubstringsFilter,
4687 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4688 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4691 caseExactIA5SubstringsMatch,
4692 caseExactIA5SubstringsIndexer,
4693 caseExactIA5SubstringsFilter,
4696 /* needs updating */
4697 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4698 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4701 authPasswordMatch, NULL, NULL,
4704 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4705 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4708 OpenLDAPaciMatch, NULL, NULL,
4711 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4712 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4715 integerBitAndMatch, NULL, NULL,
4718 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4719 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4722 integerBitOrMatch, NULL, NULL,
4725 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4734 /* we should only be called once (from main) */
4735 assert( schema_init_done == 0 );
4737 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4738 res = register_syntax( syntax_defs[i].sd_desc,
4739 syntax_defs[i].sd_flags,
4740 syntax_defs[i].sd_validate,
4741 syntax_defs[i].sd_normalize,
4742 syntax_defs[i].sd_pretty
4743 #ifdef SLAPD_BINARY_CONVERSION
4745 syntax_defs[i].sd_ber2str,
4746 syntax_defs[i].sd_str2ber
4751 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4752 syntax_defs[i].sd_desc );
4757 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4758 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4760 "schema_init: Ingoring unusable matching rule %s\n",
4761 mrule_defs[i].mrd_desc );
4765 res = register_matching_rule(
4766 mrule_defs[i].mrd_desc,
4767 mrule_defs[i].mrd_usage,
4768 mrule_defs[i].mrd_convert,
4769 mrule_defs[i].mrd_normalize,
4770 mrule_defs[i].mrd_match,
4771 mrule_defs[i].mrd_indexer,
4772 mrule_defs[i].mrd_filter,
4773 mrule_defs[i].mrd_associated );
4777 "schema_init: Error registering matching rule %s\n",
4778 mrule_defs[i].mrd_desc );
4782 schema_init_done = 1;
4783 return LDAP_SUCCESS;
4787 schema_destroy( void )