1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
15 #include <ac/string.h>
16 #include <ac/socket.h>
21 #include "ldap_utf8.h"
23 #include "lutil_hash.h"
24 #define HASH_BYTES LUTIL_HASH_BYTES
25 #define HASH_CONTEXT lutil_HASH_CTX
26 #define HASH_Init(c) lutil_HASHInit(c)
27 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
28 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
30 /* recycled validatation routines */
31 #define berValidate blobValidate
33 /* unimplemented pretters */
34 #define integerPretty NULL
36 /* recycled matching routines */
37 #define bitStringMatch octetStringMatch
38 #define numericStringMatch caseIgnoreIA5Match
39 #define objectIdentifierMatch caseIgnoreIA5Match
40 #define telephoneNumberMatch caseIgnoreIA5Match
41 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
42 #define generalizedTimeMatch caseIgnoreIA5Match
43 #define generalizedTimeOrderingMatch caseIgnoreIA5Match
44 #define uniqueMemberMatch dnMatch
46 /* approx matching rules */
47 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
48 #define directoryStringApproxMatch approxMatch
49 #define directoryStringApproxIndexer approxIndexer
50 #define directoryStringApproxFilter approxFilter
51 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
52 #define IA5StringApproxMatch approxMatch
53 #define IA5StringApproxIndexer approxIndexer
54 #define IA5StringApproxFilter approxFilter
56 /* orderring matching rules */
57 #define caseIgnoreOrderingMatch caseIgnoreMatch
58 #define caseExactOrderingMatch caseExactMatch
60 /* unimplemented matching routines */
61 #define caseIgnoreListMatch NULL
62 #define caseIgnoreListSubstringsMatch NULL
63 #define protocolInformationMatch NULL
64 #define integerFirstComponentMatch NULL
66 #define OpenLDAPaciMatch NULL
67 #define authPasswordMatch NULL
69 /* recycled indexing/filtering routines */
70 #define dnIndexer caseExactIgnoreIndexer
71 #define dnFilter caseExactIgnoreFilter
72 #define bitStringFilter octetStringFilter
73 #define bitStringIndexer octetStringIndexer
75 #define telephoneNumberIndexer caseIgnoreIA5Indexer
76 #define telephoneNumberFilter caseIgnoreIA5Filter
77 #define telephoneNumberSubstringsIndexer caseIgnoreIA5SubstringsIndexer
78 #define telephoneNumberSubstringsFilter caseIgnoreIA5SubstringsFilter
80 /* must match OIDs below */
81 #define caseExactMatchOID "2.5.13.5"
82 #define caseExactSubstringsMatchOID "2.5.13.7"
84 static char *strcasechr( const char *str, int c )
86 char *lower = strchr( str, TOLOWER(c) );
87 char *upper = strchr( str, TOUPPER(c) );
89 if( lower && upper ) {
90 return lower < upper ? lower : upper;
104 struct berval *value,
105 void *assertedValue )
107 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
110 match = memcmp( value->bv_val,
111 ((struct berval *) assertedValue)->bv_val,
119 /* Index generation function */
120 static int octetStringIndexer(
125 struct berval *prefix,
132 HASH_CONTEXT HASHcontext;
133 unsigned char HASHdigest[HASH_BYTES];
134 struct berval digest;
135 digest.bv_val = HASHdigest;
136 digest.bv_len = sizeof(HASHdigest);
138 for( i=0; values[i].bv_val != NULL; i++ ) {
139 /* just count them */
142 /* we should have at least one value at this point */
145 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
147 slen = syntax->ssyn_oidlen;
148 mlen = mr->smr_oidlen;
150 for( i=0; values[i].bv_val != NULL; i++ ) {
151 HASH_Init( &HASHcontext );
152 if( prefix != NULL && prefix->bv_len > 0 ) {
153 HASH_Update( &HASHcontext,
154 prefix->bv_val, prefix->bv_len );
156 HASH_Update( &HASHcontext,
157 syntax->ssyn_oid, slen );
158 HASH_Update( &HASHcontext,
160 HASH_Update( &HASHcontext,
161 values[i].bv_val, values[i].bv_len );
162 HASH_Final( HASHdigest, &HASHcontext );
164 ber_dupbv( &keys[i], &digest );
167 keys[i].bv_val = NULL;
174 /* Index generation function */
175 static int octetStringFilter(
180 struct berval *prefix,
186 HASH_CONTEXT HASHcontext;
187 unsigned char HASHdigest[HASH_BYTES];
188 struct berval *value = (struct berval *) assertValue;
189 struct berval digest;
190 digest.bv_val = HASHdigest;
191 digest.bv_len = sizeof(HASHdigest);
193 slen = syntax->ssyn_oidlen;
194 mlen = mr->smr_oidlen;
196 keys = ch_malloc( sizeof( struct berval ) * 2 );
198 HASH_Init( &HASHcontext );
199 if( prefix != NULL && prefix->bv_len > 0 ) {
200 HASH_Update( &HASHcontext,
201 prefix->bv_val, prefix->bv_len );
203 HASH_Update( &HASHcontext,
204 syntax->ssyn_oid, slen );
205 HASH_Update( &HASHcontext,
207 HASH_Update( &HASHcontext,
208 value->bv_val, value->bv_len );
209 HASH_Final( HASHdigest, &HASHcontext );
211 ber_dupbv( keys, &digest );
212 keys[1].bv_val = NULL;
227 if( in->bv_len == 0 ) return LDAP_SUCCESS;
229 ber_dupbv( &dn, in );
230 if( !dn.bv_val ) return LDAP_OTHER;
232 if( dn.bv_val[dn.bv_len-1] == 'B'
233 && dn.bv_val[dn.bv_len-2] == '\'' )
235 /* assume presence of optional UID */
238 for(i=dn.bv_len-3; i>1; i--) {
239 if( dn.bv_val[i] != '0' && dn.bv_val[i] != '1' ) {
243 if( dn.bv_val[i] != '\'' ||
244 dn.bv_val[i-1] != '#' ) {
245 ber_memfree( dn.bv_val );
246 return LDAP_INVALID_SYNTAX;
249 /* trim the UID to allow use of dnValidate */
250 dn.bv_val[i-1] = '\0';
254 rc = dnValidate( NULL, &dn );
264 struct berval *normalized )
269 ber_dupbv( &out, val );
270 if( out.bv_len != 0 ) {
273 ber_len_t uidlen = 0;
275 if( out.bv_val[out.bv_len-1] == '\'' ) {
276 /* assume presence of optional UID */
277 uid = strrchr( out.bv_val, '#' );
281 return LDAP_INVALID_SYNTAX;
284 uidlen = out.bv_len - (uid - out.bv_val);
285 /* temporarily trim the UID */
287 out.bv_len -= uidlen;
290 #ifdef USE_DN_NORMALIZE
291 rc = dnNormalize2( NULL, &out, normalized );
293 rc = dnPretty2( NULL, &out, normalized );
296 if( rc != LDAP_SUCCESS ) {
298 return LDAP_INVALID_SYNTAX;
301 dnlen = normalized->bv_len;
305 b2.bv_val = ch_malloc(dnlen + uidlen + 1);
306 AC_MEMCPY( b2.bv_val, normalized->bv_val, dnlen );
308 /* restore the separator */
311 AC_MEMCPY( normalized->bv_val+dnlen, uid, uidlen );
312 b2.bv_len = dnlen + uidlen;
313 normalized->bv_val[dnlen+uidlen] = '\0';
314 free(normalized->bv_val);
328 /* any value allowed */
337 /* any value allowed */
348 /* very unforgiving validation, requires no normalization
349 * before simplistic matching
351 if( in->bv_len < 3 ) {
352 return LDAP_INVALID_SYNTAX;
356 * rfc 2252 section 6.3 Bit String
357 * bitstring = "'" *binary-digit "'"
358 * binary-digit = "0" / "1"
359 * example: '0101111101'B
362 if( in->bv_val[0] != '\'' ||
363 in->bv_val[in->bv_len-2] != '\'' ||
364 in->bv_val[in->bv_len-1] != 'B' )
366 return LDAP_INVALID_SYNTAX;
369 for( i=in->bv_len-3; i>0; i-- ) {
370 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
371 return LDAP_INVALID_SYNTAX;
382 struct berval *normalized )
385 * A normalized bitString is has no extaneous (leading) zero bits.
386 * That is, '00010'B is normalized to '10'B
387 * However, as a special case, '0'B requires no normalization.
391 /* start at the first bit */
394 /* Find the first non-zero bit */
395 while ( *p == '0' ) p++;
398 /* no non-zero bits */
399 ber_str2bv( "\'0\'B", sizeof("\'0\'B") - 1, 1, normalized );
403 normalized->bv_val = ch_malloc( val->bv_len + 1 );
405 normalized->bv_val[0] = '\'';
406 normalized->bv_len = 1;
408 for( ; *p != '\0'; p++ ) {
409 normalized->bv_val[normalized->bv_len++] = *p;
412 normalized->bv_val[normalized->bv_len] = '\0';
419 * Handling boolean syntax and matching is quite rigid.
420 * A more flexible approach would be to allow a variety
421 * of strings to be normalized and prettied into TRUE
429 /* very unforgiving validation, requires no normalization
430 * before simplistic matching
433 if( in->bv_len == 4 ) {
434 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
437 } else if( in->bv_len == 5 ) {
438 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
443 return LDAP_INVALID_SYNTAX;
452 struct berval *value,
453 void *assertedValue )
455 /* simplistic matching allowed by rigid validation */
456 struct berval *asserted = (struct berval *) assertedValue;
457 *matchp = value->bv_len != asserted->bv_len;
468 unsigned char *u = in->bv_val;
470 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
472 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
473 /* get the length indicated by the first byte */
474 len = LDAP_UTF8_CHARLEN2( u, len );
476 /* very basic checks */
479 if( (u[5] & 0xC0) != 0x80 ) {
480 return LDAP_INVALID_SYNTAX;
483 if( (u[4] & 0xC0) != 0x80 ) {
484 return LDAP_INVALID_SYNTAX;
487 if( (u[3] & 0xC0) != 0x80 ) {
488 return LDAP_INVALID_SYNTAX;
491 if( (u[2] & 0xC0 )!= 0x80 ) {
492 return LDAP_INVALID_SYNTAX;
495 if( (u[1] & 0xC0) != 0x80 ) {
496 return LDAP_INVALID_SYNTAX;
500 return LDAP_INVALID_SYNTAX;
504 return LDAP_INVALID_SYNTAX;
507 /* make sure len corresponds with the offset
508 to the next character */
509 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
512 if( count != 0 ) return LDAP_INVALID_SYNTAX;
521 struct berval *normalized )
528 /* Ignore initial whitespace */
529 /* All space is ASCII. All ASCII is 1 byte */
530 while ( ASCII_SPACE( *p ) ) {
535 return LDAP_INVALID_SYNTAX;
538 ber_str2bv( p, val->bv_len - (p - val->bv_val), 1, normalized );
540 assert( normalized->bv_val );
542 p = q = normalized->bv_val;
547 if ( ASCII_SPACE( *p ) ) {
552 /* Ignore the extra whitespace */
553 while ( ASCII_SPACE( *p ) ) {
557 len = LDAP_UTF8_COPY(q,p);
563 assert( normalized->bv_val < p );
564 assert( q+len <= p );
566 /* cannot start with a space */
567 assert( !ASCII_SPACE(normalized->bv_val[0]) );
570 * If the string ended in space, backup the pointer one
571 * position. One is enough because the above loop collapsed
572 * all whitespace to a single space.
580 /* cannot end with a space */
581 assert( !ASCII_SPACE( *q ) );
588 normalized->bv_len = q - normalized->bv_val;
593 /* Returns Unicode canonically normalized copy of a substring assertion
594 * Skipping attribute description */
595 static SubstringsAssertion *
596 UTF8SubstringsassertionNormalize(
597 SubstringsAssertion *sa,
600 SubstringsAssertion *nsa;
603 nsa = (SubstringsAssertion *)ch_calloc( 1, sizeof(SubstringsAssertion) );
608 if( sa->sa_initial.bv_val != NULL ) {
609 ber_str2bv( UTF8normalize( &sa->sa_initial, casefold ), 0,
610 0, &nsa->sa_initial );
611 if( nsa->sa_initial.bv_val == NULL ) {
616 if( sa->sa_any != NULL ) {
617 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
620 nsa->sa_any = (struct berval *)ch_malloc( (i + 1) * sizeof(struct berval) );
621 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
622 ber_str2bv( UTF8normalize( &sa->sa_any[i], casefold ),
623 0, 0, &nsa->sa_any[i] );
624 if( nsa->sa_any[i].bv_val == NULL ) {
628 nsa->sa_any[i].bv_val = NULL;
631 if( sa->sa_final.bv_val != NULL ) {
632 ber_str2bv( UTF8normalize( &sa->sa_final, casefold ), 0,
634 if( nsa->sa_final.bv_val == NULL ) {
642 if ( nsa->sa_final.bv_val ) free( nsa->sa_final.bv_val );
643 if ( nsa->sa_any )ber_bvarray_free( nsa->sa_any );
644 if ( nsa->sa_initial.bv_val ) free( nsa->sa_initial.bv_val );
649 /* Strip characters with the 8th bit set */
662 while( *++q & 0x80 ) {
665 p = AC_MEMCPY(p, q, strlen(q) + 1);
673 #ifndef SLAPD_APPROX_OLDSINGLESTRING
675 #if defined(SLAPD_APPROX_INITIALS)
676 #define SLAPD_APPROX_DELIMITER "._ "
677 #define SLAPD_APPROX_WORDLEN 2
679 #define SLAPD_APPROX_DELIMITER " "
680 #define SLAPD_APPROX_WORDLEN 1
689 struct berval *value,
690 void *assertedValue )
692 char *val, *nval, *assertv, **values, **words, *c;
693 int i, count, len, nextchunk=0, nextavail=0;
696 /* Yes, this is necessary */
697 nval = UTF8normalize( value, LDAP_UTF8_NOCASEFOLD );
702 strip8bitChars( nval );
704 /* Yes, this is necessary */
705 assertv = UTF8normalize( ((struct berval *)assertedValue),
706 LDAP_UTF8_NOCASEFOLD );
707 if( assertv == NULL ) {
712 strip8bitChars( assertv );
713 avlen = strlen( assertv );
715 /* Isolate how many words there are */
716 for( c=nval,count=1; *c; c++ ) {
717 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
718 if ( c == NULL ) break;
723 /* Get a phonetic copy of each word */
724 words = (char **)ch_malloc( count * sizeof(char *) );
725 values = (char **)ch_malloc( count * sizeof(char *) );
726 for( c=nval,i=0; i<count; i++,c+=strlen(c)+1 ) {
728 values[i] = phonetic(c);
731 /* Work through the asserted value's words, to see if at least some
732 of the words are there, in the same order. */
734 while ( (size_t) nextchunk < avlen ) {
735 len = strcspn( assertv + nextchunk, SLAPD_APPROX_DELIMITER);
740 #if defined(SLAPD_APPROX_INITIALS)
741 else if( len == 1 ) {
742 /* Single letter words need to at least match one word's initial */
743 for( i=nextavail; i<count; i++ )
744 if( !strncasecmp( assertv+nextchunk, words[i], 1 )) {
751 /* Isolate the next word in the asserted value and phonetic it */
752 assertv[nextchunk+len] = '\0';
753 val = phonetic( assertv + nextchunk );
755 /* See if this phonetic chunk is in the remaining words of *value */
756 for( i=nextavail; i<count; i++ ){
757 if( !strcmp( val, values[i] ) ){
765 /* This chunk in the asserted value was NOT within the *value. */
771 /* Go on to the next word in the asserted value */
775 /* If some of the words were seen, call it a match */
776 if( nextavail > 0 ) {
785 for( i=0; i<count; i++ ) {
786 ch_free( values[i] );
801 struct berval *prefix,
806 int i,j, len, wordcount, keycount=0;
807 struct berval *newkeys;
810 for( j=0; values[j].bv_val != NULL; j++ ) {
811 /* Yes, this is necessary */
812 val = UTF8normalize( &values[j], LDAP_UTF8_NOCASEFOLD );
813 strip8bitChars( val );
815 /* Isolate how many words there are. There will be a key for each */
816 for( wordcount=0,c=val; *c; c++) {
817 len = strcspn(c, SLAPD_APPROX_DELIMITER);
818 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
820 if (*c == '\0') break;
824 /* Allocate/increase storage to account for new keys */
825 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
826 * sizeof(struct berval) );
827 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
828 if( keys ) ch_free( keys );
831 /* Get a phonetic copy of each word */
832 for( c=val,i=0; i<wordcount; c+=len+1 ) {
834 if( len < SLAPD_APPROX_WORDLEN ) continue;
835 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
842 keys[keycount].bv_val = NULL;
854 struct berval *prefix,
862 /* Yes, this is necessary */
863 val = UTF8normalize( ((struct berval *)assertValue),
864 LDAP_UTF8_NOCASEFOLD );
866 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
867 keys[0].bv_val = NULL;
871 strip8bitChars( val );
873 /* Isolate how many words there are. There will be a key for each */
874 for( count=0,c=val; *c; c++) {
875 len = strcspn(c, SLAPD_APPROX_DELIMITER);
876 if( len >= SLAPD_APPROX_WORDLEN ) count++;
878 if (*c == '\0') break;
882 /* Allocate storage for new keys */
883 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
885 /* Get a phonetic copy of each word */
886 for( c=val,i=0; i<count; c+=len+1 ) {
888 if( len < SLAPD_APPROX_WORDLEN ) continue;
889 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
895 keys[count].bv_val = NULL;
903 /* No other form of Approximate Matching is defined */
911 struct berval *value,
912 void *assertedValue )
914 char *vapprox, *avapprox;
917 /* Yes, this is necessary */
918 s = UTF8normalize( value, UTF8_NOCASEFOLD );
924 /* Yes, this is necessary */
925 t = UTF8normalize( ((struct berval *)assertedValue),
933 vapprox = phonetic( strip8bitChars( s ) );
934 avapprox = phonetic( strip8bitChars( t ) );
939 *matchp = strcmp( vapprox, avapprox );
953 struct berval *prefix,
961 for( i=0; values[i].bv_val != NULL; i++ ) {
962 /* empty - just count them */
965 /* we should have at least one value at this point */
968 keys = (struct berval *)ch_malloc( sizeof( struct berval ) * (i+1) );
970 /* Copy each value and run it through phonetic() */
971 for( i=0; values[i].bv_val != NULL; i++ ) {
972 /* Yes, this is necessary */
973 s = UTF8normalize( &values[i], UTF8_NOCASEFOLD );
975 /* strip 8-bit chars and run through phonetic() */
976 ber_str2bv( phonetic( strip8bitChars( s ) ), 0, 0, &keys[i] );
979 keys[i].bv_val = NULL;
992 struct berval *prefix,
999 keys = (struct berval *)ch_malloc( sizeof( struct berval * ) * 2 );
1001 /* Yes, this is necessary */
1002 s = UTF8normalize( ((struct berval *)assertValue),
1007 /* strip 8-bit chars and run through phonetic() */
1008 keys[0] = ber_bvstr( phonetic( strip8bitChars( s ) ) );
1014 return LDAP_SUCCESS;
1025 struct berval *value,
1026 void *assertedValue )
1028 *matchp = UTF8normcmp( value->bv_val,
1029 ((struct berval *) assertedValue)->bv_val,
1030 LDAP_UTF8_NOCASEFOLD );
1031 return LDAP_SUCCESS;
1035 caseExactIgnoreSubstringsMatch(
1040 struct berval *value,
1041 void *assertedValue )
1044 SubstringsAssertion *sub = NULL;
1051 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1052 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1054 nav = UTF8normalize( value, casefold );
1060 left.bv_len = strlen( nav );
1062 sub = UTF8SubstringsassertionNormalize( assertedValue, casefold );
1068 /* Add up asserted input length */
1069 if( sub->sa_initial.bv_val ) {
1070 inlen += sub->sa_initial.bv_len;
1073 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
1074 inlen += sub->sa_any[i].bv_len;
1077 if( sub->sa_final.bv_val ) {
1078 inlen += sub->sa_final.bv_len;
1081 if( sub->sa_initial.bv_val ) {
1082 if( inlen > left.bv_len ) {
1087 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
1088 sub->sa_initial.bv_len );
1094 left.bv_val += sub->sa_initial.bv_len;
1095 left.bv_len -= sub->sa_initial.bv_len;
1096 inlen -= sub->sa_initial.bv_len;
1099 if( sub->sa_final.bv_val ) {
1100 if( inlen > left.bv_len ) {
1105 match = strncmp( sub->sa_final.bv_val,
1106 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1107 sub->sa_final.bv_len );
1113 left.bv_len -= sub->sa_final.bv_len;
1114 inlen -= sub->sa_final.bv_len;
1118 for(i=0; sub->sa_any[i].bv_val; i++) {
1123 if( inlen > left.bv_len ) {
1124 /* not enough length */
1129 if( sub->sa_any[i].bv_len == 0 ) {
1133 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
1140 idx = p - left.bv_val;
1142 if( idx >= left.bv_len ) {
1143 /* this shouldn't happen */
1145 if ( sub->sa_final.bv_val )
1146 ch_free( sub->sa_final.bv_val );
1148 ber_bvarray_free( sub->sa_any );
1149 if ( sub->sa_initial.bv_val )
1150 ch_free( sub->sa_initial.bv_val );
1158 if( sub->sa_any[i].bv_len > left.bv_len ) {
1159 /* not enough left */
1164 match = strncmp( left.bv_val,
1165 sub->sa_any[i].bv_val,
1166 sub->sa_any[i].bv_len );
1174 left.bv_val += sub->sa_any[i].bv_len;
1175 left.bv_len -= sub->sa_any[i].bv_len;
1176 inlen -= sub->sa_any[i].bv_len;
1183 if ( sub->sa_final.bv_val ) free( sub->sa_final.bv_val );
1184 if ( sub->sa_any ) ber_bvarray_free( sub->sa_any );
1185 if ( sub->sa_initial.bv_val ) free( sub->sa_initial.bv_val );
1189 return LDAP_SUCCESS;
1192 /* Index generation function */
1193 static int caseExactIgnoreIndexer(
1198 struct berval *prefix,
1206 HASH_CONTEXT HASHcontext;
1207 unsigned char HASHdigest[HASH_BYTES];
1208 struct berval digest;
1209 digest.bv_val = HASHdigest;
1210 digest.bv_len = sizeof(HASHdigest);
1212 for( i=0; values[i].bv_val != NULL; i++ ) {
1213 /* empty - just count them */
1216 /* we should have at least one value at this point */
1219 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1221 slen = syntax->ssyn_oidlen;
1222 mlen = mr->smr_oidlen;
1224 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1225 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1227 for( i=0; values[i].bv_val != NULL; i++ ) {
1228 struct berval value;
1229 ber_str2bv( UTF8normalize( &values[i], casefold ), 0, 0,
1232 HASH_Init( &HASHcontext );
1233 if( prefix != NULL && prefix->bv_len > 0 ) {
1234 HASH_Update( &HASHcontext,
1235 prefix->bv_val, prefix->bv_len );
1237 HASH_Update( &HASHcontext,
1238 syntax->ssyn_oid, slen );
1239 HASH_Update( &HASHcontext,
1240 mr->smr_oid, mlen );
1241 HASH_Update( &HASHcontext,
1242 value.bv_val, value.bv_len );
1243 HASH_Final( HASHdigest, &HASHcontext );
1245 free( value.bv_val );
1247 ber_dupbv( &keys[i], &digest );
1250 keys[i].bv_val = NULL;
1252 return LDAP_SUCCESS;
1255 /* Index generation function */
1256 static int caseExactIgnoreFilter(
1261 struct berval *prefix,
1268 HASH_CONTEXT HASHcontext;
1269 unsigned char HASHdigest[HASH_BYTES];
1270 struct berval value;
1271 struct berval digest;
1272 digest.bv_val = HASHdigest;
1273 digest.bv_len = sizeof(HASHdigest);
1275 slen = syntax->ssyn_oidlen;
1276 mlen = mr->smr_oidlen;
1278 casefold = strcmp( mr->smr_oid, caseExactMatchOID )
1279 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1281 ber_str2bv( UTF8normalize( ((struct berval *) assertValue), casefold ),
1283 /* This usually happens if filter contains bad UTF8 */
1284 if( value.bv_val == NULL ) {
1285 keys = ch_malloc( sizeof( struct berval ) );
1286 keys[0].bv_val = NULL;
1287 return LDAP_SUCCESS;
1290 keys = ch_malloc( sizeof( struct berval ) * 2 );
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_dupbv( keys, &digest );
1306 keys[1].bv_val = NULL;
1308 free( value.bv_val );
1311 return LDAP_SUCCESS;
1314 /* Substrings Index generation function */
1315 static int caseExactIgnoreSubstringsIndexer(
1320 struct berval *prefix,
1330 HASH_CONTEXT HASHcontext;
1331 unsigned char HASHdigest[HASH_BYTES];
1332 struct berval digest;
1333 digest.bv_val = HASHdigest;
1334 digest.bv_len = sizeof(HASHdigest);
1338 for( i=0; values[i].bv_val != NULL; i++ ) {
1339 /* empty - just count them */
1342 /* we should have at least one value at this point */
1345 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1346 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1348 nvalues = ch_malloc( sizeof( struct berval ) * (i+1) );
1349 for( i=0; values[i].bv_val != NULL; i++ ) {
1350 ber_str2bv( UTF8normalize( &values[i], casefold ),
1351 0, 0, &nvalues[i] );
1353 nvalues[i].bv_val = NULL;
1356 for( i=0; values[i].bv_val != NULL; i++ ) {
1357 /* count number of indices to generate */
1358 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1362 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1363 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1364 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1365 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1367 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1371 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1372 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1373 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1377 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1378 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1379 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1380 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1382 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1388 /* no keys to generate */
1390 ber_bvarray_free( nvalues );
1391 return LDAP_SUCCESS;
1394 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1396 slen = syntax->ssyn_oidlen;
1397 mlen = mr->smr_oidlen;
1400 for( i=0; values[i].bv_val != NULL; i++ ) {
1403 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1405 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1406 ( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1408 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1409 max = values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1411 for( j=0; j<max; j++ ) {
1412 HASH_Init( &HASHcontext );
1413 if( prefix != NULL && prefix->bv_len > 0 ) {
1414 HASH_Update( &HASHcontext,
1415 prefix->bv_val, prefix->bv_len );
1418 HASH_Update( &HASHcontext,
1419 &pre, sizeof( pre ) );
1420 HASH_Update( &HASHcontext,
1421 syntax->ssyn_oid, slen );
1422 HASH_Update( &HASHcontext,
1423 mr->smr_oid, mlen );
1424 HASH_Update( &HASHcontext,
1425 &values[i].bv_val[j],
1426 SLAP_INDEX_SUBSTR_MAXLEN );
1427 HASH_Final( HASHdigest, &HASHcontext );
1429 ber_dupbv( &keys[nkeys++], &digest );
1433 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i].bv_len
1434 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i].bv_len;
1436 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1439 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1440 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1441 HASH_Init( &HASHcontext );
1442 if( prefix != NULL && prefix->bv_len > 0 ) {
1443 HASH_Update( &HASHcontext,
1444 prefix->bv_val, prefix->bv_len );
1446 HASH_Update( &HASHcontext,
1447 &pre, sizeof( pre ) );
1448 HASH_Update( &HASHcontext,
1449 syntax->ssyn_oid, slen );
1450 HASH_Update( &HASHcontext,
1451 mr->smr_oid, mlen );
1452 HASH_Update( &HASHcontext,
1453 values[i].bv_val, j );
1454 HASH_Final( HASHdigest, &HASHcontext );
1456 ber_dupbv( &keys[nkeys++], &digest );
1459 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1460 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1461 HASH_Init( &HASHcontext );
1462 if( prefix != NULL && prefix->bv_len > 0 ) {
1463 HASH_Update( &HASHcontext,
1464 prefix->bv_val, prefix->bv_len );
1466 HASH_Update( &HASHcontext,
1467 &pre, sizeof( pre ) );
1468 HASH_Update( &HASHcontext,
1469 syntax->ssyn_oid, slen );
1470 HASH_Update( &HASHcontext,
1471 mr->smr_oid, mlen );
1472 HASH_Update( &HASHcontext,
1473 &values[i].bv_val[values[i].bv_len-j], j );
1474 HASH_Final( HASHdigest, &HASHcontext );
1476 ber_dupbv( &keys[nkeys++], &digest );
1484 keys[nkeys].bv_val = NULL;
1491 ber_bvarray_free( nvalues );
1493 return LDAP_SUCCESS;
1496 static int caseExactIgnoreSubstringsFilter(
1501 struct berval *prefix,
1505 SubstringsAssertion *sa;
1508 ber_len_t nkeys = 0;
1509 size_t slen, mlen, klen;
1511 HASH_CONTEXT HASHcontext;
1512 unsigned char HASHdigest[HASH_BYTES];
1513 struct berval *value;
1514 struct berval digest;
1516 casefold = strcmp( mr->smr_oid, caseExactSubstringsMatchOID )
1517 ? LDAP_UTF8_CASEFOLD : LDAP_UTF8_NOCASEFOLD;
1519 sa = UTF8SubstringsassertionNormalize( assertValue, casefold );
1522 return LDAP_SUCCESS;
1525 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1526 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1531 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1533 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1534 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1535 /* don't bother accounting for stepping */
1536 nkeys += sa->sa_any[i].bv_len -
1537 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1542 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1543 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1549 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1550 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1551 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1554 return LDAP_SUCCESS;
1557 digest.bv_val = HASHdigest;
1558 digest.bv_len = sizeof(HASHdigest);
1560 slen = syntax->ssyn_oidlen;
1561 mlen = mr->smr_oidlen;
1563 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
1566 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
1567 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1569 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1570 value = &sa->sa_initial;
1572 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1573 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1575 HASH_Init( &HASHcontext );
1576 if( prefix != NULL && prefix->bv_len > 0 ) {
1577 HASH_Update( &HASHcontext,
1578 prefix->bv_val, prefix->bv_len );
1580 HASH_Update( &HASHcontext,
1581 &pre, sizeof( pre ) );
1582 HASH_Update( &HASHcontext,
1583 syntax->ssyn_oid, slen );
1584 HASH_Update( &HASHcontext,
1585 mr->smr_oid, mlen );
1586 HASH_Update( &HASHcontext,
1587 value->bv_val, klen );
1588 HASH_Final( HASHdigest, &HASHcontext );
1590 ber_dupbv( &keys[nkeys++], &digest );
1593 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1595 pre = SLAP_INDEX_SUBSTR_PREFIX;
1596 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1598 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
1599 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1603 value = &sa->sa_any[i];
1606 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1607 j += SLAP_INDEX_SUBSTR_STEP )
1609 HASH_Init( &HASHcontext );
1610 if( prefix != NULL && prefix->bv_len > 0 ) {
1611 HASH_Update( &HASHcontext,
1612 prefix->bv_val, prefix->bv_len );
1614 HASH_Update( &HASHcontext,
1615 &pre, sizeof( pre ) );
1616 HASH_Update( &HASHcontext,
1617 syntax->ssyn_oid, slen );
1618 HASH_Update( &HASHcontext,
1619 mr->smr_oid, mlen );
1620 HASH_Update( &HASHcontext,
1621 &value->bv_val[j], klen );
1622 HASH_Final( HASHdigest, &HASHcontext );
1624 ber_dupbv( &keys[nkeys++], &digest );
1630 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
1631 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1633 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1634 value = &sa->sa_final;
1636 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1637 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1639 HASH_Init( &HASHcontext );
1640 if( prefix != NULL && prefix->bv_len > 0 ) {
1641 HASH_Update( &HASHcontext,
1642 prefix->bv_val, prefix->bv_len );
1644 HASH_Update( &HASHcontext,
1645 &pre, sizeof( pre ) );
1646 HASH_Update( &HASHcontext,
1647 syntax->ssyn_oid, slen );
1648 HASH_Update( &HASHcontext,
1649 mr->smr_oid, mlen );
1650 HASH_Update( &HASHcontext,
1651 &value->bv_val[value->bv_len-klen], klen );
1652 HASH_Final( HASHdigest, &HASHcontext );
1654 ber_dupbv( &keys[nkeys++], &digest );
1658 keys[nkeys].bv_val = NULL;
1664 if ( sa->sa_final.bv_val ) free( sa->sa_final.bv_val );
1665 if ( sa->sa_any ) ber_bvarray_free( sa->sa_any );
1666 if ( sa->sa_initial.bv_val ) free( sa->sa_initial.bv_val );
1669 return LDAP_SUCCESS;
1678 struct berval *value,
1679 void *assertedValue )
1681 *matchp = UTF8normcmp( value->bv_val,
1682 ((struct berval *) assertedValue)->bv_val,
1683 LDAP_UTF8_CASEFOLD );
1684 return LDAP_SUCCESS;
1690 struct berval *val )
1694 if( val->bv_len == 0 ) {
1695 /* disallow empty strings */
1696 return LDAP_INVALID_SYNTAX;
1699 if( OID_LEADCHAR(val->bv_val[0]) ) {
1701 for(i=1; i < val->bv_len; i++) {
1702 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1703 if( dot++ ) return 1;
1704 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1707 return LDAP_INVALID_SYNTAX;
1711 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1713 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1714 for(i=1; i < val->bv_len; i++) {
1715 if( !DESC_CHAR(val->bv_val[i] ) ) {
1716 return LDAP_INVALID_SYNTAX;
1720 return LDAP_SUCCESS;
1723 return LDAP_INVALID_SYNTAX;
1732 struct berval *value,
1733 void *assertedValue )
1736 int vsign=0, avsign=0;
1737 struct berval *asserted;
1738 ber_len_t vlen, avlen;
1741 /* Start off pessimistic */
1744 /* Skip past leading spaces/zeros, and get the sign of the *value number */
1746 vlen = value->bv_len;
1748 if( ASCII_SPACE(*v) || ( *v == '0' )) {
1749 /* empty -- skip spaces */
1751 else if ( *v == '+' ) {
1754 else if ( *v == '-' ) {
1757 else if ( ASCII_DIGIT(*v) ) {
1758 if ( vsign == 0 ) vsign = 1;
1766 /* Skip past leading spaces/zeros, and get the sign of the *assertedValue
1768 asserted = (struct berval *) assertedValue;
1769 av = asserted->bv_val;
1770 avlen = asserted->bv_len;
1772 if( ASCII_SPACE(*av) || ( *av == '0' )) {
1773 /* empty -- skip spaces */
1775 else if ( *av == '+' ) {
1778 else if ( *av == '-' ) {
1781 else if ( ASCII_DIGIT(*av) ) {
1782 if ( avsign == 0 ) avsign = 1;
1790 /* The two ?sign vars are now one of :
1791 -2 negative non-zero number
1793 0 0 collapse these three to 0
1795 +2 positive non-zero number
1797 if ( abs( vsign ) == 1 ) vsign = 0;
1798 if ( abs( avsign ) == 1 ) avsign = 0;
1800 if( vsign != avsign ) return LDAP_SUCCESS;
1802 /* Check the significant digits */
1803 while( vlen && avlen ) {
1804 if( *v != *av ) break;
1811 /* If all digits compared equal, the numbers are equal */
1812 if(( vlen == 0 ) && ( avlen == 0 )) {
1815 return LDAP_SUCCESS;
1821 struct berval *val )
1825 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1827 if(( val->bv_val[0] == '+' ) || ( val->bv_val[0] == '-' )) {
1828 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1829 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1830 return LDAP_INVALID_SYNTAX;
1833 for( i=1; i < val->bv_len; i++ ) {
1834 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1837 return LDAP_SUCCESS;
1844 struct berval *normalized )
1854 /* Ignore leading spaces */
1855 while ( len && ( *p == ' ' )) {
1862 negative = ( *p == '-' );
1863 if(( *p == '-' ) || ( *p == '+' )) {
1869 /* Ignore leading zeros */
1870 while ( len && ( *p == '0' )) {
1875 /* If there are no non-zero digits left, the number is zero, otherwise
1876 allocate space for the number and copy it into the buffer */
1878 normalized->bv_val = ch_strdup("0");
1879 normalized->bv_len = 1;
1882 normalized->bv_len = len+negative;
1883 normalized->bv_val = ch_malloc( normalized->bv_len );
1885 normalized->bv_val[0] = '-';
1887 AC_MEMCPY( normalized->bv_val + negative, p, len );
1890 return LDAP_SUCCESS;
1893 /* Index generation function */
1894 static int integerIndexer(
1899 struct berval *prefix,
1906 /* we should have at least one value at this point */
1907 assert( values != NULL && values[0].bv_val != NULL );
1909 for( i=0; values[i].bv_val != NULL; i++ ) {
1910 /* empty -- just count them */
1913 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
1915 for( i=0; values[i].bv_val != NULL; i++ ) {
1916 integerNormalize( syntax, &values[i], &keys[i] );
1919 keys[i].bv_val = NULL;
1921 return LDAP_SUCCESS;
1924 /* Index generation function */
1925 static int integerFilter(
1930 struct berval *prefix,
1936 keys = ch_malloc( sizeof( struct berval ) * 2 );
1937 integerNormalize( syntax, assertValue, &keys[0] );
1938 keys[1].bv_val = NULL;
1941 return LDAP_SUCCESS;
1946 countryStringValidate(
1948 struct berval *val )
1950 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
1952 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
1953 return LDAP_INVALID_SYNTAX;
1955 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
1956 return LDAP_INVALID_SYNTAX;
1959 return LDAP_SUCCESS;
1963 printableStringValidate(
1965 struct berval *val )
1969 for(i=0; i < val->bv_len; i++) {
1970 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
1971 return LDAP_INVALID_SYNTAX;
1975 return LDAP_SUCCESS;
1979 printablesStringValidate(
1981 struct berval *val )
1985 for(i=0; i < val->bv_len; i++) {
1986 if( !SLAP_PRINTABLES(val->bv_val[i]) ) {
1987 return LDAP_INVALID_SYNTAX;
1991 return LDAP_SUCCESS;
1997 struct berval *val )
2001 for(i=0; i < val->bv_len; i++) {
2002 if( !LDAP_ASCII(val->bv_val[i]) ) {
2003 return LDAP_INVALID_SYNTAX;
2007 return LDAP_SUCCESS;
2014 struct berval *normalized )
2020 /* Ignore initial whitespace */
2021 while ( ASCII_SPACE( *p ) ) {
2025 normalized->bv_val = ch_strdup( p );
2026 p = q = normalized->bv_val;
2029 if ( ASCII_SPACE( *p ) ) {
2032 /* Ignore the extra whitespace */
2033 while ( ASCII_SPACE( *p ) ) {
2041 assert( normalized->bv_val <= p );
2045 * If the string ended in space, backup the pointer one
2046 * position. One is enough because the above loop collapsed
2047 * all whitespace to a single space.
2050 if ( ASCII_SPACE( q[-1] ) ) {
2054 /* null terminate */
2057 normalized->bv_len = q - normalized->bv_val;
2059 return LDAP_SUCCESS;
2068 struct berval *value,
2069 void *assertedValue )
2071 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2074 match = strncmp( value->bv_val,
2075 ((struct berval *) assertedValue)->bv_val,
2080 return LDAP_SUCCESS;
2084 caseExactIA5SubstringsMatch(
2089 struct berval *value,
2090 void *assertedValue )
2093 SubstringsAssertion *sub = assertedValue;
2094 struct berval left = *value;
2098 /* Add up asserted input length */
2099 if( sub->sa_initial.bv_val ) {
2100 inlen += sub->sa_initial.bv_len;
2103 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2104 inlen += sub->sa_any[i].bv_len;
2107 if( sub->sa_final.bv_val ) {
2108 inlen += sub->sa_final.bv_len;
2111 if( sub->sa_initial.bv_val ) {
2112 if( inlen > left.bv_len ) {
2117 match = strncmp( sub->sa_initial.bv_val, left.bv_val,
2118 sub->sa_initial.bv_len );
2124 left.bv_val += sub->sa_initial.bv_len;
2125 left.bv_len -= sub->sa_initial.bv_len;
2126 inlen -= sub->sa_initial.bv_len;
2129 if( sub->sa_final.bv_val ) {
2130 if( inlen > left.bv_len ) {
2135 match = strncmp( sub->sa_final.bv_val,
2136 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2137 sub->sa_final.bv_len );
2143 left.bv_len -= sub->sa_final.bv_len;
2144 inlen -= sub->sa_final.bv_len;
2148 for(i=0; sub->sa_any[i].bv_val; i++) {
2153 if( inlen > left.bv_len ) {
2154 /* not enough length */
2159 if( sub->sa_any[i].bv_len == 0 ) {
2163 p = strchr( left.bv_val, *sub->sa_any[i].bv_val );
2170 idx = p - left.bv_val;
2172 if( idx >= left.bv_len ) {
2173 /* this shouldn't happen */
2180 if( sub->sa_any[i].bv_len > left.bv_len ) {
2181 /* not enough left */
2186 match = strncmp( left.bv_val,
2187 sub->sa_any[i].bv_val,
2188 sub->sa_any[i].bv_len );
2196 left.bv_val += sub->sa_any[i].bv_len;
2197 left.bv_len -= sub->sa_any[i].bv_len;
2198 inlen -= sub->sa_any[i].bv_len;
2204 return LDAP_SUCCESS;
2207 /* Index generation function */
2208 static int caseExactIA5Indexer(
2213 struct berval *prefix,
2220 HASH_CONTEXT HASHcontext;
2221 unsigned char HASHdigest[HASH_BYTES];
2222 struct berval digest;
2223 digest.bv_val = HASHdigest;
2224 digest.bv_len = sizeof(HASHdigest);
2226 for( i=0; values[i].bv_val != NULL; i++ ) {
2227 /* empty - just count them */
2230 /* we should have at least one value at this point */
2233 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2235 slen = syntax->ssyn_oidlen;
2236 mlen = mr->smr_oidlen;
2238 for( i=0; values[i].bv_val != NULL; i++ ) {
2239 struct berval *value = &values[i];
2241 HASH_Init( &HASHcontext );
2242 if( prefix != NULL && prefix->bv_len > 0 ) {
2243 HASH_Update( &HASHcontext,
2244 prefix->bv_val, prefix->bv_len );
2246 HASH_Update( &HASHcontext,
2247 syntax->ssyn_oid, slen );
2248 HASH_Update( &HASHcontext,
2249 mr->smr_oid, mlen );
2250 HASH_Update( &HASHcontext,
2251 value->bv_val, value->bv_len );
2252 HASH_Final( HASHdigest, &HASHcontext );
2254 ber_dupbv( &keys[i], &digest );
2257 keys[i].bv_val = NULL;
2259 return LDAP_SUCCESS;
2262 /* Index generation function */
2263 static int caseExactIA5Filter(
2268 struct berval *prefix,
2274 HASH_CONTEXT HASHcontext;
2275 unsigned char HASHdigest[HASH_BYTES];
2276 struct berval *value;
2277 struct berval digest;
2278 digest.bv_val = HASHdigest;
2279 digest.bv_len = sizeof(HASHdigest);
2281 slen = syntax->ssyn_oidlen;
2282 mlen = mr->smr_oidlen;
2284 value = (struct berval *) assertValue;
2286 keys = ch_malloc( sizeof( struct berval ) * 2 );
2288 HASH_Init( &HASHcontext );
2289 if( prefix != NULL && prefix->bv_len > 0 ) {
2290 HASH_Update( &HASHcontext,
2291 prefix->bv_val, prefix->bv_len );
2293 HASH_Update( &HASHcontext,
2294 syntax->ssyn_oid, slen );
2295 HASH_Update( &HASHcontext,
2296 mr->smr_oid, mlen );
2297 HASH_Update( &HASHcontext,
2298 value->bv_val, value->bv_len );
2299 HASH_Final( HASHdigest, &HASHcontext );
2301 ber_dupbv( &keys[0], &digest );
2302 keys[1].bv_val = NULL;
2305 return LDAP_SUCCESS;
2308 /* Substrings Index generation function */
2309 static int caseExactIA5SubstringsIndexer(
2314 struct berval *prefix,
2321 HASH_CONTEXT HASHcontext;
2322 unsigned char HASHdigest[HASH_BYTES];
2323 struct berval digest;
2324 digest.bv_val = HASHdigest;
2325 digest.bv_len = sizeof(HASHdigest);
2327 /* we should have at least one value at this point */
2328 assert( values != NULL && values[0].bv_val != NULL );
2331 for( i=0; values[i].bv_val != NULL; i++ ) {
2332 /* count number of indices to generate */
2333 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2337 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2338 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2339 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2340 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2342 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2346 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2347 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2348 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2352 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2353 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2354 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2355 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2357 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2363 /* no keys to generate */
2365 return LDAP_SUCCESS;
2368 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2370 slen = syntax->ssyn_oidlen;
2371 mlen = mr->smr_oidlen;
2374 for( i=0; values[i].bv_val != NULL; i++ ) {
2376 struct berval *value;
2379 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2381 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2382 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2384 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2385 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2387 for( j=0; j<max; j++ ) {
2388 HASH_Init( &HASHcontext );
2389 if( prefix != NULL && prefix->bv_len > 0 ) {
2390 HASH_Update( &HASHcontext,
2391 prefix->bv_val, prefix->bv_len );
2394 HASH_Update( &HASHcontext,
2395 &pre, sizeof( pre ) );
2396 HASH_Update( &HASHcontext,
2397 syntax->ssyn_oid, slen );
2398 HASH_Update( &HASHcontext,
2399 mr->smr_oid, mlen );
2400 HASH_Update( &HASHcontext,
2402 SLAP_INDEX_SUBSTR_MAXLEN );
2403 HASH_Final( HASHdigest, &HASHcontext );
2405 ber_dupbv( &keys[nkeys++], &digest );
2409 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2410 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2412 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2415 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2416 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2417 HASH_Init( &HASHcontext );
2418 if( prefix != NULL && prefix->bv_len > 0 ) {
2419 HASH_Update( &HASHcontext,
2420 prefix->bv_val, prefix->bv_len );
2422 HASH_Update( &HASHcontext,
2423 &pre, sizeof( pre ) );
2424 HASH_Update( &HASHcontext,
2425 syntax->ssyn_oid, slen );
2426 HASH_Update( &HASHcontext,
2427 mr->smr_oid, mlen );
2428 HASH_Update( &HASHcontext,
2430 HASH_Final( HASHdigest, &HASHcontext );
2432 ber_dupbv( &keys[nkeys++], &digest );
2435 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2436 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2437 HASH_Init( &HASHcontext );
2438 if( prefix != NULL && prefix->bv_len > 0 ) {
2439 HASH_Update( &HASHcontext,
2440 prefix->bv_val, prefix->bv_len );
2442 HASH_Update( &HASHcontext,
2443 &pre, sizeof( pre ) );
2444 HASH_Update( &HASHcontext,
2445 syntax->ssyn_oid, slen );
2446 HASH_Update( &HASHcontext,
2447 mr->smr_oid, mlen );
2448 HASH_Update( &HASHcontext,
2449 &value->bv_val[value->bv_len-j], j );
2450 HASH_Final( HASHdigest, &HASHcontext );
2452 ber_dupbv( &keys[nkeys++], &digest );
2459 keys[nkeys].bv_val = NULL;
2466 return LDAP_SUCCESS;
2469 static int caseExactIA5SubstringsFilter(
2474 struct berval *prefix,
2478 SubstringsAssertion *sa = assertValue;
2480 ber_len_t nkeys = 0;
2481 size_t slen, mlen, klen;
2483 HASH_CONTEXT HASHcontext;
2484 unsigned char HASHdigest[HASH_BYTES];
2485 struct berval *value;
2486 struct berval digest;
2488 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2489 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2494 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2496 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2497 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2498 /* don't bother accounting for stepping */
2499 nkeys += sa->sa_any[i].bv_len -
2500 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2505 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2506 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2513 return LDAP_SUCCESS;
2516 digest.bv_val = HASHdigest;
2517 digest.bv_len = sizeof(HASHdigest);
2519 slen = syntax->ssyn_oidlen;
2520 mlen = mr->smr_oidlen;
2522 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2525 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial.bv_val != NULL &&
2526 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2528 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2529 value = &sa->sa_initial;
2531 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2532 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2534 HASH_Init( &HASHcontext );
2535 if( prefix != NULL && prefix->bv_len > 0 ) {
2536 HASH_Update( &HASHcontext,
2537 prefix->bv_val, prefix->bv_len );
2539 HASH_Update( &HASHcontext,
2540 &pre, sizeof( pre ) );
2541 HASH_Update( &HASHcontext,
2542 syntax->ssyn_oid, slen );
2543 HASH_Update( &HASHcontext,
2544 mr->smr_oid, mlen );
2545 HASH_Update( &HASHcontext,
2546 value->bv_val, klen );
2547 HASH_Final( HASHdigest, &HASHcontext );
2549 ber_dupbv( &keys[nkeys++], &digest );
2552 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2554 pre = SLAP_INDEX_SUBSTR_PREFIX;
2555 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2557 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
2558 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2562 value = &sa->sa_any[i];
2565 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2566 j += SLAP_INDEX_SUBSTR_STEP )
2568 HASH_Init( &HASHcontext );
2569 if( prefix != NULL && prefix->bv_len > 0 ) {
2570 HASH_Update( &HASHcontext,
2571 prefix->bv_val, prefix->bv_len );
2573 HASH_Update( &HASHcontext,
2574 &pre, sizeof( pre ) );
2575 HASH_Update( &HASHcontext,
2576 syntax->ssyn_oid, slen );
2577 HASH_Update( &HASHcontext,
2578 mr->smr_oid, mlen );
2579 HASH_Update( &HASHcontext,
2580 &value->bv_val[j], klen );
2581 HASH_Final( HASHdigest, &HASHcontext );
2583 ber_dupbv( &keys[nkeys++], &digest );
2588 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final.bv_val != NULL &&
2589 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2591 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2592 value = &sa->sa_final;
2594 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2595 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2597 HASH_Init( &HASHcontext );
2598 if( prefix != NULL && prefix->bv_len > 0 ) {
2599 HASH_Update( &HASHcontext,
2600 prefix->bv_val, prefix->bv_len );
2602 HASH_Update( &HASHcontext,
2603 &pre, sizeof( pre ) );
2604 HASH_Update( &HASHcontext,
2605 syntax->ssyn_oid, slen );
2606 HASH_Update( &HASHcontext,
2607 mr->smr_oid, mlen );
2608 HASH_Update( &HASHcontext,
2609 &value->bv_val[value->bv_len-klen], klen );
2610 HASH_Final( HASHdigest, &HASHcontext );
2612 ber_dupbv( &keys[nkeys++], &digest );
2616 keys[nkeys].bv_val = NULL;
2623 return LDAP_SUCCESS;
2632 struct berval *value,
2633 void *assertedValue )
2635 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2637 if( match == 0 && value->bv_len ) {
2638 match = strncasecmp( value->bv_val,
2639 ((struct berval *) assertedValue)->bv_val,
2644 return LDAP_SUCCESS;
2648 caseIgnoreIA5SubstringsMatch(
2653 struct berval *value,
2654 void *assertedValue )
2657 SubstringsAssertion *sub = assertedValue;
2658 struct berval left = *value;
2662 /* Add up asserted input length */
2663 if( sub->sa_initial.bv_val ) {
2664 inlen += sub->sa_initial.bv_len;
2667 for(i=0; sub->sa_any[i].bv_val != NULL; i++) {
2668 inlen += sub->sa_any[i].bv_len;
2671 if( sub->sa_final.bv_val ) {
2672 inlen += sub->sa_final.bv_len;
2675 if( sub->sa_initial.bv_val ) {
2676 if( inlen > left.bv_len ) {
2681 match = strncasecmp( sub->sa_initial.bv_val, left.bv_val,
2682 sub->sa_initial.bv_len );
2688 left.bv_val += sub->sa_initial.bv_len;
2689 left.bv_len -= sub->sa_initial.bv_len;
2690 inlen -= sub->sa_initial.bv_len;
2693 if( sub->sa_final.bv_val ) {
2694 if( inlen > left.bv_len ) {
2699 match = strncasecmp( sub->sa_final.bv_val,
2700 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
2701 sub->sa_final.bv_len );
2707 left.bv_len -= sub->sa_final.bv_len;
2708 inlen -= sub->sa_final.bv_len;
2712 for(i=0; sub->sa_any[i].bv_val; i++) {
2717 if( inlen > left.bv_len ) {
2718 /* not enough length */
2723 if( sub->sa_any[i].bv_len == 0 ) {
2727 p = strcasechr( left.bv_val, *sub->sa_any[i].bv_val );
2734 idx = p - left.bv_val;
2735 if( idx >= left.bv_len ) {
2736 /* this shouldn't happen */
2743 if( sub->sa_any[i].bv_len > left.bv_len ) {
2744 /* not enough left */
2749 match = strncasecmp( left.bv_val,
2750 sub->sa_any[i].bv_val,
2751 sub->sa_any[i].bv_len );
2760 left.bv_val += sub->sa_any[i].bv_len;
2761 left.bv_len -= sub->sa_any[i].bv_len;
2762 inlen -= sub->sa_any[i].bv_len;
2768 return LDAP_SUCCESS;
2771 /* Index generation function */
2772 static int caseIgnoreIA5Indexer(
2777 struct berval *prefix,
2784 HASH_CONTEXT HASHcontext;
2785 unsigned char HASHdigest[HASH_BYTES];
2786 struct berval digest;
2787 digest.bv_val = HASHdigest;
2788 digest.bv_len = sizeof(HASHdigest);
2790 /* we should have at least one value at this point */
2791 assert( values != NULL && values[0].bv_val != NULL );
2793 for( i=0; values[i].bv_val != NULL; i++ ) {
2794 /* just count them */
2797 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
2799 slen = syntax->ssyn_oidlen;
2800 mlen = mr->smr_oidlen;
2802 for( i=0; values[i].bv_val != NULL; i++ ) {
2803 struct berval value;
2804 ber_dupbv( &value, &values[i] );
2805 ldap_pvt_str2upper( value.bv_val );
2807 HASH_Init( &HASHcontext );
2808 if( prefix != NULL && prefix->bv_len > 0 ) {
2809 HASH_Update( &HASHcontext,
2810 prefix->bv_val, prefix->bv_len );
2812 HASH_Update( &HASHcontext,
2813 syntax->ssyn_oid, slen );
2814 HASH_Update( &HASHcontext,
2815 mr->smr_oid, mlen );
2816 HASH_Update( &HASHcontext,
2817 value.bv_val, value.bv_len );
2818 HASH_Final( HASHdigest, &HASHcontext );
2820 free( value.bv_val );
2822 ber_dupbv( &keys[i], &digest );
2825 keys[i].bv_val = NULL;
2827 return LDAP_SUCCESS;
2830 /* Index generation function */
2831 static int caseIgnoreIA5Filter(
2836 struct berval *prefix,
2842 HASH_CONTEXT HASHcontext;
2843 unsigned char HASHdigest[HASH_BYTES];
2844 struct berval value;
2845 struct berval digest;
2846 digest.bv_val = HASHdigest;
2847 digest.bv_len = sizeof(HASHdigest);
2849 slen = syntax->ssyn_oidlen;
2850 mlen = mr->smr_oidlen;
2852 ber_dupbv( &value, (struct berval *) assertValue );
2853 ldap_pvt_str2upper( value.bv_val );
2855 keys = ch_malloc( sizeof( struct berval ) * 2 );
2857 HASH_Init( &HASHcontext );
2858 if( prefix != NULL && prefix->bv_len > 0 ) {
2859 HASH_Update( &HASHcontext,
2860 prefix->bv_val, prefix->bv_len );
2862 HASH_Update( &HASHcontext,
2863 syntax->ssyn_oid, slen );
2864 HASH_Update( &HASHcontext,
2865 mr->smr_oid, mlen );
2866 HASH_Update( &HASHcontext,
2867 value.bv_val, value.bv_len );
2868 HASH_Final( HASHdigest, &HASHcontext );
2870 ber_dupbv( &keys[0], &digest );
2871 keys[1].bv_val = NULL;
2873 free( value.bv_val );
2877 return LDAP_SUCCESS;
2880 /* Substrings Index generation function */
2881 static int caseIgnoreIA5SubstringsIndexer(
2886 struct berval *prefix,
2893 HASH_CONTEXT HASHcontext;
2894 unsigned char HASHdigest[HASH_BYTES];
2895 struct berval digest;
2896 digest.bv_val = HASHdigest;
2897 digest.bv_len = sizeof(HASHdigest);
2899 /* we should have at least one value at this point */
2900 assert( values != NULL && values[0].bv_val != NULL );
2903 for( i=0; values[i].bv_val != NULL; i++ ) {
2904 /* count number of indices to generate */
2905 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2909 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2910 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2911 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2912 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2914 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2918 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2919 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2920 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2924 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2925 if( values[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2926 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2927 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2929 nkeys += values[i].bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2935 /* no keys to generate */
2937 return LDAP_SUCCESS;
2940 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
2942 slen = syntax->ssyn_oidlen;
2943 mlen = mr->smr_oidlen;
2946 for( i=0; values[i].bv_val != NULL; i++ ) {
2948 struct berval value;
2950 if( values[i].bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2952 ber_dupbv( &value, &values[i] );
2953 ldap_pvt_str2upper( value.bv_val );
2955 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2956 ( value.bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2958 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2959 max = value.bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2961 for( j=0; j<max; j++ ) {
2962 HASH_Init( &HASHcontext );
2963 if( prefix != NULL && prefix->bv_len > 0 ) {
2964 HASH_Update( &HASHcontext,
2965 prefix->bv_val, prefix->bv_len );
2968 HASH_Update( &HASHcontext,
2969 &pre, sizeof( pre ) );
2970 HASH_Update( &HASHcontext,
2971 syntax->ssyn_oid, slen );
2972 HASH_Update( &HASHcontext,
2973 mr->smr_oid, mlen );
2974 HASH_Update( &HASHcontext,
2976 SLAP_INDEX_SUBSTR_MAXLEN );
2977 HASH_Final( HASHdigest, &HASHcontext );
2979 ber_dupbv( &keys[nkeys++], &digest );
2983 max = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
2984 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
2986 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2989 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2990 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2991 HASH_Init( &HASHcontext );
2992 if( prefix != NULL && prefix->bv_len > 0 ) {
2993 HASH_Update( &HASHcontext,
2994 prefix->bv_val, prefix->bv_len );
2996 HASH_Update( &HASHcontext,
2997 &pre, sizeof( pre ) );
2998 HASH_Update( &HASHcontext,
2999 syntax->ssyn_oid, slen );
3000 HASH_Update( &HASHcontext,
3001 mr->smr_oid, mlen );
3002 HASH_Update( &HASHcontext,
3004 HASH_Final( HASHdigest, &HASHcontext );
3006 ber_dupbv( &keys[nkeys++], &digest );
3009 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
3010 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3011 HASH_Init( &HASHcontext );
3012 if( prefix != NULL && prefix->bv_len > 0 ) {
3013 HASH_Update( &HASHcontext,
3014 prefix->bv_val, prefix->bv_len );
3016 HASH_Update( &HASHcontext,
3017 &pre, sizeof( pre ) );
3018 HASH_Update( &HASHcontext,
3019 syntax->ssyn_oid, slen );
3020 HASH_Update( &HASHcontext,
3021 mr->smr_oid, mlen );
3022 HASH_Update( &HASHcontext,
3023 &value.bv_val[value.bv_len-j], j );
3024 HASH_Final( HASHdigest, &HASHcontext );
3026 ber_dupbv( &keys[nkeys++], &digest );
3031 free( value.bv_val );
3035 keys[nkeys].bv_val = NULL;
3042 return LDAP_SUCCESS;
3045 static int caseIgnoreIA5SubstringsFilter(
3050 struct berval *prefix,
3054 SubstringsAssertion *sa = assertValue;
3056 ber_len_t nkeys = 0;
3057 size_t slen, mlen, klen;
3059 HASH_CONTEXT HASHcontext;
3060 unsigned char HASHdigest[HASH_BYTES];
3061 struct berval value;
3062 struct berval digest;
3064 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3065 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3070 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3072 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3073 if( sa->sa_any[i].bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3074 /* don't bother accounting for stepping */
3075 nkeys += sa->sa_any[i].bv_len -
3076 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3081 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3082 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3089 return LDAP_SUCCESS;
3092 digest.bv_val = HASHdigest;
3093 digest.bv_len = sizeof(HASHdigest);
3095 slen = syntax->ssyn_oidlen;
3096 mlen = mr->smr_oidlen;
3098 keys = ch_malloc( sizeof( struct berval ) * (nkeys+1) );
3101 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial.bv_val != NULL &&
3102 sa->sa_initial.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3104 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3105 ber_dupbv( &value, &sa->sa_initial );
3106 ldap_pvt_str2upper( value.bv_val );
3108 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3109 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3111 HASH_Init( &HASHcontext );
3112 if( prefix != NULL && prefix->bv_len > 0 ) {
3113 HASH_Update( &HASHcontext,
3114 prefix->bv_val, prefix->bv_len );
3116 HASH_Update( &HASHcontext,
3117 &pre, sizeof( pre ) );
3118 HASH_Update( &HASHcontext,
3119 syntax->ssyn_oid, slen );
3120 HASH_Update( &HASHcontext,
3121 mr->smr_oid, mlen );
3122 HASH_Update( &HASHcontext,
3123 value.bv_val, klen );
3124 HASH_Final( HASHdigest, &HASHcontext );
3126 free( value.bv_val );
3127 ber_dupbv( &keys[nkeys++], &digest );
3130 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3132 pre = SLAP_INDEX_SUBSTR_PREFIX;
3133 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3135 for( i=0; sa->sa_any[i].bv_val != NULL; i++ ) {
3136 if( sa->sa_any[i].bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3140 ber_dupbv( &value, &sa->sa_any[i] );
3141 ldap_pvt_str2upper( value.bv_val );
3144 j <= value.bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3145 j += SLAP_INDEX_SUBSTR_STEP )
3147 HASH_Init( &HASHcontext );
3148 if( prefix != NULL && prefix->bv_len > 0 ) {
3149 HASH_Update( &HASHcontext,
3150 prefix->bv_val, prefix->bv_len );
3152 HASH_Update( &HASHcontext,
3153 &pre, sizeof( pre ) );
3154 HASH_Update( &HASHcontext,
3155 syntax->ssyn_oid, slen );
3156 HASH_Update( &HASHcontext,
3157 mr->smr_oid, mlen );
3158 HASH_Update( &HASHcontext,
3159 &value.bv_val[j], klen );
3160 HASH_Final( HASHdigest, &HASHcontext );
3162 ber_dupbv( &keys[nkeys++], &digest );
3165 free( value.bv_val );
3169 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final.bv_val != NULL &&
3170 sa->sa_final.bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3172 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3173 ber_dupbv( &value, &sa->sa_final );
3174 ldap_pvt_str2upper( value.bv_val );
3176 klen = SLAP_INDEX_SUBSTR_MAXLEN < value.bv_len
3177 ? SLAP_INDEX_SUBSTR_MAXLEN : value.bv_len;
3179 HASH_Init( &HASHcontext );
3180 if( prefix != NULL && prefix->bv_len > 0 ) {
3181 HASH_Update( &HASHcontext,
3182 prefix->bv_val, prefix->bv_len );
3184 HASH_Update( &HASHcontext,
3185 &pre, sizeof( pre ) );
3186 HASH_Update( &HASHcontext,
3187 syntax->ssyn_oid, slen );
3188 HASH_Update( &HASHcontext,
3189 mr->smr_oid, mlen );
3190 HASH_Update( &HASHcontext,
3191 &value.bv_val[value.bv_len-klen], klen );
3192 HASH_Final( HASHdigest, &HASHcontext );
3194 free( value.bv_val );
3195 ber_dupbv( &keys[nkeys++], &digest );
3199 keys[nkeys].bv_val = NULL;
3206 return LDAP_SUCCESS;
3210 numericStringValidate(
3216 for(i=0; i < in->bv_len; i++) {
3217 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
3218 return LDAP_INVALID_SYNTAX;
3222 return LDAP_SUCCESS;
3226 numericStringNormalize(
3229 struct berval *normalized )
3231 /* removal all spaces */
3234 normalized->bv_val = ch_malloc( val->bv_len + 1 );
3237 q = normalized->bv_val;
3240 if ( ASCII_SPACE( *p ) ) {
3241 /* Ignore whitespace */
3248 /* we should have copied no more then is in val */
3249 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
3251 /* null terminate */
3254 normalized->bv_len = q - normalized->bv_val;
3256 return LDAP_SUCCESS;
3260 objectIdentifierFirstComponentMatch(
3265 struct berval *value,
3266 void *assertedValue )
3268 int rc = LDAP_SUCCESS;
3270 struct berval *asserted = (struct berval *) assertedValue;
3274 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3275 return LDAP_INVALID_SYNTAX;
3278 /* trim leading white space */
3279 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3283 /* grab next word */
3284 oid.bv_val = &value->bv_val[i];
3285 oid.bv_len = value->bv_len - i;
3286 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3291 /* insert attributeTypes, objectclass check here */
3292 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3293 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3296 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3297 MatchingRule *asserted_mr = mr_bvfind( asserted );
3298 MatchingRule *stored_mr = mr_bvfind( &oid );
3300 if( asserted_mr == NULL ) {
3301 rc = SLAPD_COMPARE_UNDEFINED;
3303 match = asserted_mr != stored_mr;
3306 } else if ( !strcmp( syntax->ssyn_oid,
3307 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3309 AttributeType *asserted_at = at_bvfind( asserted );
3310 AttributeType *stored_at = at_bvfind( &oid );
3312 if( asserted_at == NULL ) {
3313 rc = SLAPD_COMPARE_UNDEFINED;
3315 match = asserted_at != stored_at;
3318 } else if ( !strcmp( syntax->ssyn_oid,
3319 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3321 ObjectClass *asserted_oc = oc_bvfind( asserted );
3322 ObjectClass *stored_oc = oc_bvfind( &oid );
3324 if( asserted_oc == NULL ) {
3325 rc = SLAPD_COMPARE_UNDEFINED;
3327 match = asserted_oc != stored_oc;
3333 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3334 "objectIdentifierFirstComponentMatch: %d\n %s\n %s\n",
3335 match, value->bv_val, asserted->bv_val ));
3337 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3338 "%d\n\t\"%s\"\n\t\"%s\"\n",
3339 match, value->bv_val, asserted->bv_val );
3343 if( rc == LDAP_SUCCESS ) *matchp = match;
3353 struct berval *value,
3354 void *assertedValue )
3356 long lValue, lAssertedValue;
3358 /* safe to assume integers are NUL terminated? */
3359 lValue = strtoul(value->bv_val, NULL, 10);
3360 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3361 return LDAP_CONSTRAINT_VIOLATION;
3363 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3364 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3365 return LDAP_CONSTRAINT_VIOLATION;
3367 *matchp = (lValue & lAssertedValue);
3368 return LDAP_SUCCESS;
3377 struct berval *value,
3378 void *assertedValue )
3380 long lValue, lAssertedValue;
3382 /* safe to assume integers are NUL terminated? */
3383 lValue = strtoul(value->bv_val, NULL, 10);
3384 if(( lValue == LONG_MIN || lValue == LONG_MAX) && errno == ERANGE )
3385 return LDAP_CONSTRAINT_VIOLATION;
3387 lAssertedValue = strtol(((struct berval *)assertedValue)->bv_val, NULL, 10);
3388 if(( lAssertedValue == LONG_MIN || lAssertedValue == LONG_MAX) && errno == ERANGE )
3389 return LDAP_CONSTRAINT_VIOLATION;
3391 *matchp = (lValue | lAssertedValue);
3392 return LDAP_SUCCESS;
3396 #include <openssl/x509.h>
3397 #include <openssl/err.h>
3398 char digit[] = "0123456789";
3401 * Next function returns a string representation of a ASN1_INTEGER.
3402 * It works for unlimited lengths.
3405 static struct berval *
3406 asn1_integer2str(ASN1_INTEGER *a)
3411 /* We work backwards, make it fill from the end of buf */
3412 p = buf + sizeof(buf) - 1;
3415 if ( a == NULL || a->length == 0 ) {
3423 /* We want to preserve the original */
3424 copy = ch_malloc(n*sizeof(unsigned int));
3425 for (i = 0; i<n; i++) {
3426 copy[i] = a->data[i];
3430 * base indicates the index of the most significant
3431 * byte that might be nonzero. When it goes off the
3432 * end, we now there is nothing left to do.
3438 for (i = base; i<n; i++ ) {
3439 copy[i] += carry*256;
3440 carry = copy[i] % 10;
3445 * Way too large, we need to leave
3446 * room for sign if negative
3451 *--p = digit[carry];
3452 if (copy[base] == 0)
3458 if ( a->type == V_ASN1_NEG_INTEGER ) {
3462 return ber_bvstrdup(p);
3465 /* Get a DN in RFC2253 format from a X509_NAME internal struct */
3466 static struct berval *
3467 dn_openssl2ldap(X509_NAME *name)
3469 char issuer_dn[1024];
3472 bio = BIO_new(BIO_s_mem());
3475 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3476 "dn_openssl2ldap: error creating BIO_s_mem: %s\n",
3477 ERR_error_string(ERR_get_error(),NULL)));
3479 Debug( LDAP_DEBUG_ARGS, "dn_openssl2ldap: "
3480 "error creating BIO: %s\n",
3481 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3485 X509_NAME_print_ex(bio, name, 0, XN_FLAG_RFC2253);
3487 BIO_gets(bio, issuer_dn, 1024);
3490 return ber_bvstrdup(issuer_dn);
3494 * Given a certificate in DER format, extract the corresponding
3495 * assertion value for certificateExactMatch
3498 certificateExactConvert(
3500 struct berval * out )
3503 unsigned char *p = in->bv_val;
3504 struct berval *serial;
3505 struct berval *issuer_dn;
3506 struct berval *bv_tmp;
3508 xcert = d2i_X509(NULL, &p, in->bv_len);
3511 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3512 "certificateExactConvert: error parsing cert: %s\n",
3513 ERR_error_string(ERR_get_error(),NULL)));
3515 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert: "
3516 "error parsing cert: %s\n",
3517 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3519 return LDAP_INVALID_SYNTAX;
3522 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3525 return LDAP_INVALID_SYNTAX;
3527 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3531 return LDAP_INVALID_SYNTAX;
3533 /* Actually, dn_openssl2ldap returns in a normalized format, but
3534 it is different from our normalized format */
3536 if ( dnNormalize(NULL, bv_tmp, &issuer_dn) != LDAP_SUCCESS ) {
3540 return LDAP_INVALID_SYNTAX;
3546 out->bv_len = serial->bv_len + issuer_dn->bv_len + sizeof(" $ ");
3547 out->bv_val = ch_malloc(out->bv_len);
3549 AC_MEMCPY(p, serial->bv_val, serial->bv_len);
3550 p += serial->bv_len;
3551 AC_MEMCPY(p, " $ ", sizeof(" $ ")-1);
3553 AC_MEMCPY(p, issuer_dn->bv_val, issuer_dn->bv_len);
3554 p += issuer_dn->bv_len;
3558 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3559 "certificateExactConvert: \n %s\n",
3562 Debug( LDAP_DEBUG_ARGS, "certificateExactConvert "
3564 out->bv_val, NULL, NULL );
3568 ber_bvfree(issuer_dn);
3570 return LDAP_SUCCESS;
3574 serial_and_issuer_parse(
3575 struct berval *assertion,
3576 struct berval **serial,
3577 struct berval **issuer_dn
3585 begin = assertion->bv_val;
3586 end = assertion->bv_val+assertion->bv_len-1;
3587 for (p=begin; p<=end && *p != '$'; p++)
3590 return LDAP_INVALID_SYNTAX;
3592 /* p now points at the $ sign, now use begin and end to delimit the
3594 while (ASCII_SPACE(*begin))
3597 while (ASCII_SPACE(*end))
3600 bv.bv_len = end-begin+1;
3602 *serial = ber_dupbv(NULL, &bv);
3604 /* now extract the issuer, remember p was at the dollar sign */
3606 end = assertion->bv_val+assertion->bv_len-1;
3607 while (ASCII_SPACE(*begin))
3609 /* should we trim spaces at the end too? is it safe always? */
3611 bv.bv_len = end-begin+1;
3613 dnNormalize( NULL, &bv, issuer_dn );
3615 return LDAP_SUCCESS;
3619 certificateExactMatch(
3624 struct berval *value,
3625 void *assertedValue )
3628 unsigned char *p = value->bv_val;
3629 struct berval *serial;
3630 struct berval *issuer_dn;
3631 struct berval *asserted_serial;
3632 struct berval *asserted_issuer_dn;
3635 xcert = d2i_X509(NULL, &p, value->bv_len);
3638 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3639 "certificateExactMatch: error parsing cert: %s\n",
3640 ERR_error_string(ERR_get_error(),NULL)));
3642 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch: "
3643 "error parsing cert: %s\n",
3644 ERR_error_string(ERR_get_error(),NULL), NULL, NULL );
3646 return LDAP_INVALID_SYNTAX;
3649 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3650 issuer_dn = dn_openssl2ldap(X509_get_issuer_name(xcert));
3654 serial_and_issuer_parse(assertedValue,
3656 &asserted_issuer_dn);
3661 slap_schema.si_syn_integer,
3662 slap_schema.si_mr_integerMatch,
3665 if ( ret == LDAP_SUCCESS ) {
3666 if ( *matchp == 0 ) {
3667 /* We need to normalize everything for dnMatch */
3671 slap_schema.si_syn_distinguishedName,
3672 slap_schema.si_mr_distinguishedNameMatch,
3674 asserted_issuer_dn);
3679 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3680 "certificateExactMatch: %d\n %s $ %s\n %s $ %s\n",
3681 *matchp, serial->bv_val, issuer_dn->bv_val,
3682 asserted->serial->bv_val, asserted_issuer_dn->bv_val));
3684 Debug( LDAP_DEBUG_ARGS, "certificateExactMatch "
3685 "%d\n\t\"%s $ %s\"\n",
3686 *matchp, serial->bv_val, issuer_dn->bv_val );
3687 Debug( LDAP_DEBUG_ARGS, "\t\"%s $ %s\"\n",
3688 asserted_serial->bv_val, asserted_issuer_dn->bv_val,
3693 ber_bvfree(issuer_dn);
3694 ber_bvfree(asserted_serial);
3695 ber_bvfree(asserted_issuer_dn);
3701 * Index generation function
3702 * We just index the serials, in most scenarios the issuer DN is one of
3703 * a very small set of values.
3705 static int certificateExactIndexer(
3710 struct berval *prefix,
3718 struct berval * serial;
3720 /* we should have at least one value at this point */
3721 assert( values != NULL && values[0].bv_val != NULL );
3723 for( i=0; values[i].bv_val != NULL; i++ ) {
3724 /* empty -- just count them */
3727 keys = ch_malloc( sizeof( struct berval ) * (i+1) );
3729 for( i=0; values[i].bv_val != NULL; i++ ) {
3730 p = values[i].bv_val;
3731 xcert = d2i_X509(NULL, &p, values[i].bv_len);
3734 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3735 "certificateExactIndexer: error parsing cert: %s\n",
3736 ERR_error_string(ERR_get_error(),NULL)));
3738 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3739 "error parsing cert: %s\n",
3740 ERR_error_string(ERR_get_error(),NULL),
3743 /* Do we leak keys on error? */
3744 return LDAP_INVALID_SYNTAX;
3747 serial = asn1_integer2str(xcert->cert_info->serialNumber);
3749 integerNormalize( slap_schema.si_syn_integer,
3754 LDAP_LOG(( "schema", LDAP_LEVEL_ENTRY,
3755 "certificateExactIndexer: returning: %s\n",
3758 Debug( LDAP_DEBUG_ARGS, "certificateExactIndexer: "
3765 keys[i].bv_val = NULL;
3767 return LDAP_SUCCESS;
3770 /* Index generation function */
3771 /* We think this is always called with a value in matching rule syntax */
3772 static int certificateExactFilter(
3777 struct berval *prefix,
3782 struct berval *asserted_serial;
3783 struct berval *asserted_issuer_dn;
3785 serial_and_issuer_parse(assertValue,
3787 &asserted_issuer_dn);
3789 keys = ch_malloc( sizeof( struct berval ) * 2 );
3790 integerNormalize( syntax, asserted_serial, &keys[0] );
3791 keys[1].bv_val = NULL;
3794 ber_bvfree(asserted_serial);
3795 ber_bvfree(asserted_issuer_dn);
3796 return LDAP_SUCCESS;
3801 check_time_syntax (struct berval *val,
3805 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3806 static int mdays[2][12] = {
3807 /* non-leap years */
3808 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3810 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3813 int part, c, tzoffset, leapyear = 0 ;
3815 if( val->bv_len == 0 ) {
3816 return LDAP_INVALID_SYNTAX;
3819 p = (char *)val->bv_val;
3820 e = p + val->bv_len;
3822 /* Ignore initial whitespace */
3823 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3827 if (e - p < 13 - (2 * start)) {
3828 return LDAP_INVALID_SYNTAX;
3831 for (part = 0; part < 9; part++) {
3835 for (part = start; part < 7; part++) {
3837 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3844 return LDAP_INVALID_SYNTAX;
3846 if (c < 0 || c > 9) {
3847 return LDAP_INVALID_SYNTAX;
3853 return LDAP_INVALID_SYNTAX;
3855 if (c < 0 || c > 9) {
3856 return LDAP_INVALID_SYNTAX;
3861 if (part == 2 || part == 3) {
3864 if (parts[part] < 0) {
3865 return LDAP_INVALID_SYNTAX;
3867 if (parts[part] > ceiling[part]) {
3868 return LDAP_INVALID_SYNTAX;
3872 /* leapyear check for the Gregorian calendar (year>1581) */
3873 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3874 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3879 if (parts[3] > mdays[leapyear][parts[2]]) {
3880 return LDAP_INVALID_SYNTAX;
3885 tzoffset = 0; /* UTC */
3886 } else if (c != '+' && c != '-') {
3887 return LDAP_INVALID_SYNTAX;
3891 } else /* c == '+' */ {
3896 return LDAP_INVALID_SYNTAX;
3899 for (part = 7; part < 9; part++) {
3901 if (c < 0 || c > 9) {
3902 return LDAP_INVALID_SYNTAX;
3907 if (c < 0 || c > 9) {
3908 return LDAP_INVALID_SYNTAX;
3912 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3913 return LDAP_INVALID_SYNTAX;
3918 /* Ignore trailing whitespace */
3919 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3923 return LDAP_INVALID_SYNTAX;
3926 switch ( tzoffset ) {
3927 case -1: /* negativ offset to UTC, ie west of Greenwich */
3928 parts[4] += parts[7];
3929 parts[5] += parts[8];
3930 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3934 c = mdays[leapyear][parts[2]];
3936 if (parts[part] > c) {
3937 parts[part] -= c + 1;
3942 case 1: /* positive offset to UTC, ie east of Greenwich */
3943 parts[4] -= parts[7];
3944 parts[5] -= parts[8];
3945 for (part = 6; --part > 0; ) {
3949 /* first arg to % needs to be non negativ */
3950 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3952 if (parts[part] < 0) {
3953 parts[part] += c + 1;
3958 case 0: /* already UTC */
3962 return LDAP_SUCCESS;
3969 struct berval *normalized )
3973 rc = check_time_syntax(val, 1, parts);
3974 if (rc != LDAP_SUCCESS) {
3978 normalized->bv_val = ch_malloc( 14 );
3979 if ( normalized->bv_val == NULL ) {
3980 return LBER_ERROR_MEMORY;
3983 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3984 parts[1], parts[2] + 1, parts[3] + 1,
3985 parts[4], parts[5], parts[6] );
3986 normalized->bv_len = 13;
3988 return LDAP_SUCCESS;
3998 return check_time_syntax(in, 1, parts);
4002 generalizedTimeValidate(
4008 return check_time_syntax(in, 0, parts);
4012 generalizedTimeNormalize(
4015 struct berval *normalized )
4019 rc = check_time_syntax(val, 0, parts);
4020 if (rc != LDAP_SUCCESS) {
4024 normalized->bv_val = ch_malloc( 16 );
4025 if ( normalized->bv_val == NULL ) {
4026 return LBER_ERROR_MEMORY;
4029 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02dZ",
4030 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
4031 parts[4], parts[5], parts[6] );
4032 normalized->bv_len = 15;
4034 return LDAP_SUCCESS;
4038 nisNetgroupTripleValidate(
4040 struct berval *val )
4045 if ( val->bv_len == 0 ) {
4046 return LDAP_INVALID_SYNTAX;
4049 p = (char *)val->bv_val;
4050 e = p + val->bv_len;
4052 if ( *p != '(' /*')'*/ ) {
4053 return LDAP_INVALID_SYNTAX;
4056 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4060 return LDAP_INVALID_SYNTAX;
4063 } else if ( !ATTR_CHAR( *p ) ) {
4064 return LDAP_INVALID_SYNTAX;
4068 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4069 return LDAP_INVALID_SYNTAX;
4075 return LDAP_INVALID_SYNTAX;
4078 return LDAP_SUCCESS;
4082 bootParameterValidate(
4084 struct berval *val )
4088 if ( val->bv_len == 0 ) {
4089 return LDAP_INVALID_SYNTAX;
4092 p = (char *)val->bv_val;
4093 e = p + val->bv_len;
4096 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4097 if ( !ATTR_CHAR( *p ) ) {
4098 return LDAP_INVALID_SYNTAX;
4103 return LDAP_INVALID_SYNTAX;
4107 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4108 if ( !ATTR_CHAR( *p ) ) {
4109 return LDAP_INVALID_SYNTAX;
4114 return LDAP_INVALID_SYNTAX;
4118 for ( p++; p < e; p++ ) {
4119 if ( !ATTR_CHAR( *p ) ) {
4120 return LDAP_INVALID_SYNTAX;
4124 return LDAP_SUCCESS;
4127 static struct syntax_defs_rec {
4129 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4130 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4132 slap_syntax_validate_func *sd_validate;
4133 slap_syntax_transform_func *sd_normalize;
4134 slap_syntax_transform_func *sd_pretty;
4135 #ifdef SLAPD_BINARY_CONVERSION
4136 slap_syntax_transform_func *sd_ber2str;
4137 slap_syntax_transform_func *sd_str2ber;
4140 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4141 X_BINARY X_NOT_H_R ")",
4142 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4143 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4144 0, NULL, NULL, NULL},
4145 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4146 0, NULL, NULL, NULL},
4147 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4149 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4150 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4152 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4153 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4154 0, bitStringValidate, bitStringNormalize, NULL },
4155 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4156 0, booleanValidate, NULL, NULL},
4157 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4158 X_BINARY X_NOT_H_R ")",
4159 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4160 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4161 X_BINARY X_NOT_H_R ")",
4162 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4163 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4164 X_BINARY X_NOT_H_R ")",
4165 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4166 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4167 0, countryStringValidate, IA5StringNormalize, NULL},
4168 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4169 0, dnValidate, dnNormalize2, dnPretty2},
4170 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4171 0, NULL, NULL, NULL},
4172 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4173 0, NULL, NULL, NULL},
4174 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4175 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4176 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4177 0, NULL, NULL, NULL},
4178 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4179 0, NULL, NULL, NULL},
4180 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4181 0, NULL, NULL, NULL},
4182 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4183 0, NULL, NULL, NULL},
4184 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4185 0, NULL, NULL, NULL},
4186 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4187 0, printablesStringValidate, IA5StringNormalize, NULL},
4188 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4189 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4190 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4191 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
4192 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4193 0, NULL, NULL, NULL},
4194 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4195 0, IA5StringValidate, IA5StringNormalize, NULL},
4196 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4197 0, integerValidate, integerNormalize, NULL},
4198 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4199 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
4200 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4201 0, NULL, NULL, NULL},
4202 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4203 0, NULL, NULL, NULL},
4204 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4205 0, NULL, NULL, NULL},
4206 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4207 0, NULL, NULL, NULL},
4208 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4209 0, NULL, NULL, NULL},
4210 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4211 0, nameUIDValidate, nameUIDNormalize, NULL},
4212 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4213 0, NULL, NULL, NULL},
4214 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4215 0, numericStringValidate, numericStringNormalize, NULL},
4216 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4217 0, NULL, NULL, NULL},
4218 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4219 0, oidValidate, NULL, NULL},
4220 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4221 0, IA5StringValidate, IA5StringNormalize, NULL},
4222 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4223 0, blobValidate, NULL, NULL},
4224 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4225 0, UTF8StringValidate, UTF8StringNormalize, NULL},
4226 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4227 0, NULL, NULL, NULL},
4228 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4229 0, NULL, NULL, NULL},
4230 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4231 0, printableStringValidate, IA5StringNormalize, NULL},
4232 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' "
4233 X_BINARY X_NOT_H_R ")",
4234 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4236 X_BINARY X_NOT_H_R ")",
4237 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
4238 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4239 0, printableStringValidate, IA5StringNormalize, NULL},
4240 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4241 0, NULL, NULL, NULL},
4242 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4243 0, printablesStringValidate, IA5StringNormalize, NULL},
4244 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4245 0, utcTimeValidate, utcTimeNormalize, NULL},
4246 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4247 0, NULL, NULL, NULL},
4248 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4249 0, NULL, NULL, NULL},
4250 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4251 0, NULL, NULL, NULL},
4252 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4253 0, NULL, NULL, NULL},
4254 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4255 0, NULL, NULL, NULL},
4257 /* RFC 2307 NIS Syntaxes */
4258 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4259 0, nisNetgroupTripleValidate, NULL, NULL},
4260 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4261 0, bootParameterValidate, NULL, NULL},
4265 /* These OIDs are not published yet, but will be in the next
4266 * I-D for PKIX LDAPv3 schema as have been advanced by David
4267 * Chadwick in private mail.
4269 {"( 1.2.826.0.1.3344810.7.1 DESC 'Serial Number and Issuer' )",
4270 0, NULL, NULL, NULL},
4273 /* OpenLDAP Experimental Syntaxes */
4274 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
4276 UTF8StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
4279 #ifdef SLAPD_AUTHPASSWD
4280 /* needs updating */
4281 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4282 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4285 /* OpenLDAP Void Syntax */
4286 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4287 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
4288 {NULL, 0, NULL, NULL, NULL}
4292 * Other matching rules in X.520 that we do not use (yet):
4294 * 2.5.13.9 numericStringOrderingMatch
4295 * 2.5.13.15 integerOrderingMatch
4296 * 2.5.13.18 octetStringOrderingMatch
4297 * 2.5.13.19 octetStringSubstringsMatch
4298 * 2.5.13.25 uTCTimeMatch
4299 * 2.5.13.26 uTCTimeOrderingMatch
4300 * 2.5.13.31 directoryStringFirstComponentMatch
4301 * 2.5.13.32 wordMatch
4302 * 2.5.13.33 keywordMatch
4303 * 2.5.13.35 certificateMatch
4304 * 2.5.13.36 certificatePairExactMatch
4305 * 2.5.13.37 certificatePairMatch
4306 * 2.5.13.38 certificateListExactMatch
4307 * 2.5.13.39 certificateListMatch
4308 * 2.5.13.40 algorithmIdentifierMatch
4309 * 2.5.13.41 storedPrefixMatch
4310 * 2.5.13.42 attributeCertificateMatch
4311 * 2.5.13.43 readerAndKeyIDMatch
4312 * 2.5.13.44 attributeIntegrityMatch
4314 static struct mrule_defs_rec {
4316 slap_mask_t mrd_usage;
4317 slap_mr_convert_func * mrd_convert;
4318 slap_mr_normalize_func * mrd_normalize;
4319 slap_mr_match_func * mrd_match;
4320 slap_mr_indexer_func * mrd_indexer;
4321 slap_mr_filter_func * mrd_filter;
4323 char * mrd_associated;
4326 * EQUALITY matching rules must be listed after associated APPROX
4327 * matching rules. So, we list all APPROX matching rules first.
4329 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4330 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4331 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4333 directoryStringApproxMatch,
4334 directoryStringApproxIndexer,
4335 directoryStringApproxFilter,
4338 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4339 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4340 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
4342 IA5StringApproxMatch,
4343 IA5StringApproxIndexer,
4344 IA5StringApproxFilter,
4348 * Other matching rules
4351 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4352 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4353 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4355 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4358 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4359 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4360 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4362 dnMatch, dnIndexer, dnFilter,
4365 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4366 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4367 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4369 caseIgnoreMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4370 directoryStringApproxMatchOID },
4372 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4373 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4376 caseIgnoreOrderingMatch, NULL, NULL,
4379 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4380 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4381 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4383 caseExactIgnoreSubstringsMatch,
4384 caseExactIgnoreSubstringsIndexer,
4385 caseExactIgnoreSubstringsFilter,
4388 {"( 2.5.13.5 NAME 'caseExactMatch' "
4389 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4390 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4392 caseExactMatch, caseExactIgnoreIndexer, caseExactIgnoreFilter,
4393 directoryStringApproxMatchOID },
4395 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4396 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4399 caseExactOrderingMatch, NULL, NULL,
4402 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4403 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4404 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4406 caseExactIgnoreSubstringsMatch,
4407 caseExactIgnoreSubstringsIndexer,
4408 caseExactIgnoreSubstringsFilter,
4411 {"( 2.5.13.8 NAME 'numericStringMatch' "
4412 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4413 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4416 caseIgnoreIA5Indexer,
4417 caseIgnoreIA5Filter,
4420 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4421 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4422 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4424 caseIgnoreIA5SubstringsMatch,
4425 caseIgnoreIA5SubstringsIndexer,
4426 caseIgnoreIA5SubstringsFilter,
4429 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4430 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4431 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4433 caseIgnoreListMatch, NULL, NULL,
4436 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4437 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4438 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4440 caseIgnoreListSubstringsMatch, NULL, NULL,
4443 {"( 2.5.13.13 NAME 'booleanMatch' "
4444 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4445 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4447 booleanMatch, NULL, NULL,
4450 {"( 2.5.13.14 NAME 'integerMatch' "
4451 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4452 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4454 integerMatch, integerIndexer, integerFilter,
4457 {"( 2.5.13.16 NAME 'bitStringMatch' "
4458 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4459 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4461 bitStringMatch, bitStringIndexer, bitStringFilter,
4464 {"( 2.5.13.17 NAME 'octetStringMatch' "
4465 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4466 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4468 octetStringMatch, octetStringIndexer, octetStringFilter,
4471 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4472 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4473 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4475 telephoneNumberMatch,
4476 telephoneNumberIndexer,
4477 telephoneNumberFilter,
4480 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4481 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4482 SLAP_MR_SUBSTR | SLAP_MR_EXT,
4484 telephoneNumberSubstringsMatch,
4485 telephoneNumberSubstringsIndexer,
4486 telephoneNumberSubstringsFilter,
4489 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4490 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4491 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4496 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4497 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4498 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4500 uniqueMemberMatch, NULL, NULL,
4503 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4504 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4505 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4507 protocolInformationMatch, NULL, NULL,
4510 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4511 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4512 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4514 generalizedTimeMatch, NULL, NULL,
4517 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4518 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4521 generalizedTimeOrderingMatch, NULL, NULL,
4524 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4525 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4526 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4528 integerFirstComponentMatch, NULL, NULL,
4531 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4532 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4533 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4535 objectIdentifierFirstComponentMatch, NULL, NULL,
4539 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4540 "SYNTAX 1.2.826.0.1.3344810.7.1 )",
4541 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4542 certificateExactConvert, NULL,
4543 certificateExactMatch,
4544 certificateExactIndexer, certificateExactFilter,
4548 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4549 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4550 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4552 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4553 IA5StringApproxMatchOID },
4555 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4556 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4557 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_DN_FOLD,
4559 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4560 IA5StringApproxMatchOID },
4562 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4563 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4566 caseIgnoreIA5SubstringsMatch,
4567 caseIgnoreIA5SubstringsIndexer,
4568 caseIgnoreIA5SubstringsFilter,
4571 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4572 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4575 caseExactIA5SubstringsMatch,
4576 caseExactIA5SubstringsIndexer,
4577 caseExactIA5SubstringsFilter,
4580 #ifdef SLAPD_AUTHPASSWD
4581 /* needs updating */
4582 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4583 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4586 authPasswordMatch, NULL, NULL,
4590 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4591 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4594 OpenLDAPaciMatch, NULL, NULL,
4597 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4598 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4601 integerBitAndMatch, NULL, NULL,
4604 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4605 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4608 integerBitOrMatch, NULL, NULL,
4611 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4615 slap_schema_init( void )
4620 /* we should only be called once (from main) */
4621 assert( schema_init_done == 0 );
4623 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4624 res = register_syntax( syntax_defs[i].sd_desc,
4625 syntax_defs[i].sd_flags,
4626 syntax_defs[i].sd_validate,
4627 syntax_defs[i].sd_normalize,
4628 syntax_defs[i].sd_pretty
4629 #ifdef SLAPD_BINARY_CONVERSION
4631 syntax_defs[i].sd_ber2str,
4632 syntax_defs[i].sd_str2ber
4637 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4638 syntax_defs[i].sd_desc );
4643 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4644 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4646 "slap_schema_init: Ingoring unusable matching rule %s\n",
4647 mrule_defs[i].mrd_desc );
4651 res = register_matching_rule(
4652 mrule_defs[i].mrd_desc,
4653 mrule_defs[i].mrd_usage,
4654 mrule_defs[i].mrd_convert,
4655 mrule_defs[i].mrd_normalize,
4656 mrule_defs[i].mrd_match,
4657 mrule_defs[i].mrd_indexer,
4658 mrule_defs[i].mrd_filter,
4659 mrule_defs[i].mrd_associated );
4663 "slap_schema_init: Error registering matching rule %s\n",
4664 mrule_defs[i].mrd_desc );
4669 res = slap_schema_load();
4670 schema_init_done = 1;
4675 schema_destroy( void )