1 /* schema_init.c - init builtin schema */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
20 #include "lutil_md5.h"
21 /* We should replace MD5 with a faster hash */
22 #define HASH_BYTES LUTIL_MD5_BYTES
23 #define HASH_CONTEXT lutil_MD5_CTX
24 #define HASH_Init(c) lutil_MD5Init(c)
25 #define HASH_Update(c,buf,len) lutil_MD5Update(c,buf,len)
26 #define HASH_Final(d,c) lutil_MD5Final(d,c)
28 #include "lutil_hash.h"
29 /* We should replace MD5 with a faster hash */
30 #define HASH_BYTES LUTIL_HASH_BYTES
31 #define HASH_CONTEXT lutil_HASH_CTX
32 #define HASH_Init(c) lutil_HASHInit(c)
33 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
34 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
37 /* recycled validatation routines */
38 #define berValidate blobValidate
40 /* recycled normalization routines */
41 #define faxNumberNormalize numericStringNormalize
42 #define phoneNumberNormalize numericStringNormalize
43 #define telexNumberNormalize numericStringNormalize
45 /* unimplemented pretters */
47 #define integerPretty NULL
49 /* recycled matching routines */
50 #define bitStringMatch octetStringMatch
51 #define integerMatch caseIgnoreIA5Match
52 #define numericStringMatch caseIgnoreMatch
53 #define objectIdentifierMatch numericStringMatch
54 #define telephoneNumberMatch numericStringMatch
55 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
56 #define generalizedTimeMatch numericStringMatch
57 #define generalizedTimeOrderingMatch numericStringMatch
58 #define uniqueMemberMatch dnMatch
60 /* approx matching rules */
61 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
62 #define directoryStringApproxMatch NULL
63 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
64 #define IA5StringApproxMatch NULL
66 /* orderring matching rules */
67 #define caseIgnoreOrderingMatch caseIgnoreMatch
68 #define caseExactOrderingMatch caseExactMatch
70 /* unimplemented matching routines */
71 #define caseIgnoreListMatch NULL
72 #define caseIgnoreListSubstringsMatch NULL
73 #define presentationAddressMatch NULL
74 #define protocolInformationMatch NULL
75 #define integerFirstComponentMatch NULL
77 #define OpenLDAPaciMatch NULL
78 #define authPasswordMatch NULL
80 /* recycled indexing/filtering routines */
81 #define dnIndexer caseIgnoreIndexer
82 #define dnFilter caseIgnoreFilter
83 #define integerIndexer caseIgnoreIA5Indexer
84 #define integerFilter caseIgnoreIA5Filter
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 /* we should have at least one value at this point */
141 assert( values != NULL && values[0] != NULL );
143 for( i=0; values[i] != NULL; i++ ) {
144 /* just count them */
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 );
233 rc = dn_validate( dn ) == NULL
234 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
244 struct berval **normalized )
246 struct berval *out = ber_bvdup( val );
248 if( out->bv_len != 0 ) {
250 #ifdef USE_DN_NORMALIZE
251 dn = dn_normalize( out->bv_val );
253 dn = dn_validate( out->bv_val );
258 return LDAP_INVALID_SYNTAX;
262 out->bv_len = strlen( dn );
275 struct berval *value,
276 void *assertedValue )
279 struct berval *asserted = (struct berval *) assertedValue;
281 match = value->bv_len - asserted->bv_len;
284 #ifdef USE_DN_NORMALIZE
285 match = strcmp( value->bv_val, asserted->bv_val );
287 match = strcasecmp( value->bv_val, asserted->bv_val );
291 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
292 match, value->bv_val, asserted->bv_val );
306 if( in->bv_len == 0 ) return LDAP_SUCCESS;
308 dn = ber_bvdup( in );
310 if( dn->bv_val[dn->bv_len-1] == '\'' ) {
311 /* assume presence of optional UID */
314 for(i=dn->bv_len-2; i>2; i--) {
315 if( dn->bv_val[i] != '0' && dn->bv_val[i] != '1' ) {
319 if( dn->bv_val[i] != '\'' ) {
320 return LDAP_INVALID_SYNTAX;
322 if( dn->bv_val[i-1] != 'B' ) {
323 return LDAP_INVALID_SYNTAX;
325 if( dn->bv_val[i-2] != '#' ) {
326 return LDAP_INVALID_SYNTAX;
329 /* trim the UID to allow use of dn_validate */
330 dn->bv_val[i-2] = '\0';
333 rc = dn_validate( dn->bv_val ) == NULL
334 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
344 struct berval **normalized )
346 struct berval *out = ber_bvdup( val );
348 if( out->bv_len != 0 ) {
352 ber_len_t uidlen = 0;
354 if( out->bv_val[out->bv_len-1] == '\'' ) {
355 /* assume presence of optional UID */
356 uid = strrchr( out->bv_val, '#' );
360 return LDAP_INVALID_SYNTAX;
363 uidlen = out->bv_len - (out->bv_val - uid);
364 /* temporarily trim the UID */
368 #ifdef USE_DN_NORMALIZE
369 dn = dn_normalize( out->bv_val );
371 dn = dn_validate( out->bv_val );
376 return LDAP_INVALID_SYNTAX;
382 /* restore the separator */
385 SAFEMEMCPY( &dn[dnlen], uid, uidlen );
389 out->bv_len = dnlen + uidlen;
401 /* any value allowed */
410 /* any value allowed */
421 /* very unforgiving validation, requires no normalization
422 * before simplistic matching
424 if( in->bv_len < 3 ) {
425 return LDAP_INVALID_SYNTAX;
427 if( in->bv_val[0] != 'B' ||
428 in->bv_val[1] != '\'' ||
429 in->bv_val[in->bv_len-1] != '\'' )
431 return LDAP_INVALID_SYNTAX;
434 for( i=in->bv_len-2; i>1; i-- ) {
435 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
436 return LDAP_INVALID_SYNTAX;
444 * Handling boolean syntax and matching is quite rigid.
445 * A more flexible approach would be to allow a variety
446 * of strings to be normalized and prettied into TRUE
454 /* very unforgiving validation, requires no normalization
455 * before simplistic matching
458 if( in->bv_len == 4 ) {
459 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
462 } else if( in->bv_len == 5 ) {
463 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
468 return LDAP_INVALID_SYNTAX;
477 struct berval *value,
478 void *assertedValue )
480 /* simplistic matching allowed by rigid validation */
481 struct berval *asserted = (struct berval *) assertedValue;
482 *matchp = value->bv_len != asserted->bv_len;
489 struct berval *right,
490 struct berval *left )
494 ldap_unicode_t ru, lu;
495 ldap_unicode_t ruu, luu;
498 r < right->bv_len && l < left->bv_len;
502 * XXYYZ: we convert to ucs4 even though -llunicode
503 * expects ucs2 in an unsigned long
505 ru = ldap_utf8_to_ucs4( &right->bv_val[r] );
506 if( ru == LDAP_UCS4_INVALID ) {
510 lu = ldap_utf8_to_ucs4( &left->bv_val[l] );
511 if( lu == LDAP_UCS4_INVALID ) {
515 ruu = uctoupper( ru );
516 luu = uctoupper( lu );
520 } else if( luu > ruu ) {
524 rlen = LDAP_UTF8_CHARLEN( &right->bv_val[r] );
525 llen = LDAP_UTF8_CHARLEN( &left->bv_val[l] );
528 if( r < right->bv_len ) {
533 if( l < left->bv_len ) {
549 unsigned char *u = in->bv_val;
551 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
553 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
554 /* get the length indicated by the first byte */
555 len = LDAP_UTF8_CHARLEN( u );
557 /* should not be zero */
558 if( len == 0 ) return LDAP_INVALID_SYNTAX;
560 /* make sure len corresponds with the offset
561 to the next character */
562 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
565 if( count != 0 ) return LDAP_INVALID_SYNTAX;
574 struct berval **normalized )
576 struct berval *newval;
579 newval = ch_malloc( sizeof( struct berval ) );
583 /* Ignore initial whitespace */
584 while ( ldap_utf8_isspace( p ) ) {
590 return LDAP_INVALID_SYNTAX;
593 newval->bv_val = ch_strdup( p );
594 p = q = newval->bv_val;
600 if ( ldap_utf8_isspace( p ) ) {
601 len = LDAP_UTF8_COPY(q,p);
606 /* Ignore the extra whitespace */
607 while ( ldap_utf8_isspace( p ) ) {
611 len = LDAP_UTF8_COPY(q,p);
618 assert( *newval->bv_val );
619 assert( newval->bv_val < p );
622 /* cannot start with a space */
623 assert( !ldap_utf8_isspace(newval->bv_val) );
626 * If the string ended in space, backup the pointer one
627 * position. One is enough because the above loop collapsed
628 * all whitespace to a single space.
635 /* cannot end with a space */
636 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
641 newval->bv_len = q - newval->bv_val;
642 *normalized = newval;
653 struct berval *value,
654 void *assertedValue )
656 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
659 match = strncmp( value->bv_val,
660 ((struct berval *) assertedValue)->bv_val,
669 caseExactSubstringsMatch(
674 struct berval *value,
675 void *assertedValue )
678 SubstringsAssertion *sub = assertedValue;
679 struct berval left = *value;
683 /* Add up asserted input length */
684 if( sub->sa_initial ) {
685 inlen += sub->sa_initial->bv_len;
688 for(i=0; sub->sa_any[i] != NULL; i++) {
689 inlen += sub->sa_any[i]->bv_len;
692 if( sub->sa_final ) {
693 inlen += sub->sa_final->bv_len;
696 if( sub->sa_initial ) {
697 if( inlen > left.bv_len ) {
702 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
703 sub->sa_initial->bv_len );
709 left.bv_val += sub->sa_initial->bv_len;
710 left.bv_len -= sub->sa_initial->bv_len;
711 inlen -= sub->sa_initial->bv_len;
714 if( sub->sa_final ) {
715 if( inlen > left.bv_len ) {
720 match = strncmp( sub->sa_final->bv_val,
721 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
722 sub->sa_final->bv_len );
728 left.bv_len -= sub->sa_final->bv_len;
729 inlen -= sub->sa_final->bv_len;
733 for(i=0; sub->sa_any[i]; i++) {
738 if( inlen > left.bv_len ) {
739 /* not enough length */
744 if( sub->sa_any[i]->bv_len == 0 ) {
748 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
755 idx = p - left.bv_val;
756 assert( idx < left.bv_len );
758 if( idx >= left.bv_len ) {
759 /* this shouldn't happen */
766 if( sub->sa_any[i]->bv_len > left.bv_len ) {
767 /* not enough left */
772 match = strncmp( left.bv_val,
773 sub->sa_any[i]->bv_val,
774 sub->sa_any[i]->bv_len );
782 left.bv_val += sub->sa_any[i]->bv_len;
783 left.bv_len -= sub->sa_any[i]->bv_len;
784 inlen -= sub->sa_any[i]->bv_len;
793 /* Index generation function */
794 int caseExactIndexer(
799 struct berval *prefix,
800 struct berval **values,
801 struct berval ***keysp )
805 struct berval **keys;
806 HASH_CONTEXT HASHcontext;
807 unsigned char HASHdigest[HASH_BYTES];
808 struct berval digest;
809 digest.bv_val = HASHdigest;
810 digest.bv_len = sizeof(HASHdigest);
812 /* we should have at least one value at this point */
813 assert( values != NULL && values[0] != NULL );
815 for( i=0; values[i] != NULL; i++ ) {
816 /* just count them */
819 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
821 slen = strlen( syntax->ssyn_oid );
822 mlen = strlen( mr->smr_oid );
824 for( i=0; values[i] != NULL; i++ ) {
825 struct berval *value = values[i];
827 HASH_Init( &HASHcontext );
828 if( prefix != NULL && prefix->bv_len > 0 ) {
829 HASH_Update( &HASHcontext,
830 prefix->bv_val, prefix->bv_len );
832 HASH_Update( &HASHcontext,
833 syntax->ssyn_oid, slen );
834 HASH_Update( &HASHcontext,
836 HASH_Update( &HASHcontext,
837 value->bv_val, value->bv_len );
838 HASH_Final( HASHdigest, &HASHcontext );
840 keys[i] = ber_bvdup( &digest );
848 /* Index generation function */
854 struct berval *prefix,
856 struct berval ***keysp )
859 struct berval **keys;
860 HASH_CONTEXT HASHcontext;
861 unsigned char HASHdigest[HASH_BYTES];
862 struct berval *value;
863 struct berval digest;
864 digest.bv_val = HASHdigest;
865 digest.bv_len = sizeof(HASHdigest);
867 slen = strlen( syntax->ssyn_oid );
868 mlen = strlen( mr->smr_oid );
870 value = (struct berval *) assertValue;
872 keys = ch_malloc( sizeof( struct berval * ) * 2 );
874 HASH_Init( &HASHcontext );
875 if( prefix != NULL && prefix->bv_len > 0 ) {
876 HASH_Update( &HASHcontext,
877 prefix->bv_val, prefix->bv_len );
879 HASH_Update( &HASHcontext,
880 syntax->ssyn_oid, slen );
881 HASH_Update( &HASHcontext,
883 HASH_Update( &HASHcontext,
884 value->bv_val, value->bv_len );
885 HASH_Final( HASHdigest, &HASHcontext );
887 keys[0] = ber_bvdup( &digest );
894 /* Substrings Index generation function */
895 int caseExactSubstringsIndexer(
900 struct berval *prefix,
901 struct berval **values,
902 struct berval ***keysp )
906 struct berval **keys;
907 HASH_CONTEXT HASHcontext;
908 unsigned char HASHdigest[HASH_BYTES];
909 struct berval digest;
910 digest.bv_val = HASHdigest;
911 digest.bv_len = sizeof(HASHdigest);
913 /* we should have at least one value at this point */
914 assert( values != NULL && values[0] != NULL );
917 for( i=0; values[i] != NULL; i++ ) {
918 /* count number of indices to generate */
919 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
923 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
924 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
925 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
926 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
928 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
932 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
933 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
934 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
938 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
939 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
940 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
941 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
943 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
949 /* no keys to generate */
954 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
956 slen = strlen( syntax->ssyn_oid );
957 mlen = strlen( mr->smr_oid );
960 for( i=0; values[i] != NULL; i++ ) {
962 struct berval *value;
965 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
967 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
968 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
970 char pre = SLAP_INDEX_SUBSTR_PREFIX;
971 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
973 for( j=0; j<max; j++ ) {
974 HASH_Init( &HASHcontext );
975 if( prefix != NULL && prefix->bv_len > 0 ) {
976 HASH_Update( &HASHcontext,
977 prefix->bv_val, prefix->bv_len );
980 HASH_Update( &HASHcontext,
981 &pre, sizeof( pre ) );
982 HASH_Update( &HASHcontext,
983 syntax->ssyn_oid, slen );
984 HASH_Update( &HASHcontext,
986 HASH_Update( &HASHcontext,
988 SLAP_INDEX_SUBSTR_MAXLEN );
989 HASH_Final( HASHdigest, &HASHcontext );
991 keys[nkeys++] = ber_bvdup( &digest );
995 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
996 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
998 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1001 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1002 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1003 HASH_Init( &HASHcontext );
1004 if( prefix != NULL && prefix->bv_len > 0 ) {
1005 HASH_Update( &HASHcontext,
1006 prefix->bv_val, prefix->bv_len );
1008 HASH_Update( &HASHcontext,
1009 &pre, sizeof( pre ) );
1010 HASH_Update( &HASHcontext,
1011 syntax->ssyn_oid, slen );
1012 HASH_Update( &HASHcontext,
1013 mr->smr_oid, mlen );
1014 HASH_Update( &HASHcontext,
1016 HASH_Final( HASHdigest, &HASHcontext );
1018 keys[nkeys++] = ber_bvdup( &digest );
1021 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1022 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1023 HASH_Init( &HASHcontext );
1024 if( prefix != NULL && prefix->bv_len > 0 ) {
1025 HASH_Update( &HASHcontext,
1026 prefix->bv_val, prefix->bv_len );
1028 HASH_Update( &HASHcontext,
1029 &pre, sizeof( pre ) );
1030 HASH_Update( &HASHcontext,
1031 syntax->ssyn_oid, slen );
1032 HASH_Update( &HASHcontext,
1033 mr->smr_oid, mlen );
1034 HASH_Update( &HASHcontext,
1035 &value->bv_val[value->bv_len-j], j );
1036 HASH_Final( HASHdigest, &HASHcontext );
1038 keys[nkeys++] = ber_bvdup( &digest );
1052 return LDAP_SUCCESS;
1055 int caseExactSubstringsFilter(
1060 struct berval *prefix,
1062 struct berval ***keysp )
1064 SubstringsAssertion *sa = assertValue;
1066 ber_len_t nkeys = 0;
1067 size_t slen, mlen, klen;
1068 struct berval **keys;
1069 HASH_CONTEXT HASHcontext;
1070 unsigned char HASHdigest[HASH_BYTES];
1071 struct berval *value;
1072 struct berval digest;
1074 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1075 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1080 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1082 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1083 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1084 /* don't bother accounting for stepping */
1085 nkeys += sa->sa_any[i]->bv_len -
1086 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1091 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1092 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1099 return LDAP_SUCCESS;
1102 digest.bv_val = HASHdigest;
1103 digest.bv_len = sizeof(HASHdigest);
1105 slen = strlen( syntax->ssyn_oid );
1106 mlen = strlen( mr->smr_oid );
1108 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1111 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
1112 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1114 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1115 value = sa->sa_initial;
1117 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1118 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1120 HASH_Init( &HASHcontext );
1121 if( prefix != NULL && prefix->bv_len > 0 ) {
1122 HASH_Update( &HASHcontext,
1123 prefix->bv_val, prefix->bv_len );
1125 HASH_Update( &HASHcontext,
1126 &pre, sizeof( pre ) );
1127 HASH_Update( &HASHcontext,
1128 syntax->ssyn_oid, slen );
1129 HASH_Update( &HASHcontext,
1130 mr->smr_oid, mlen );
1131 HASH_Update( &HASHcontext,
1132 value->bv_val, klen );
1133 HASH_Final( HASHdigest, &HASHcontext );
1135 keys[nkeys++] = ber_bvdup( &digest );
1138 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
1140 pre = SLAP_INDEX_SUBSTR_PREFIX;
1141 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1143 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1144 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1148 value = sa->sa_any[i];
1151 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1152 j += SLAP_INDEX_SUBSTR_STEP )
1154 HASH_Init( &HASHcontext );
1155 if( prefix != NULL && prefix->bv_len > 0 ) {
1156 HASH_Update( &HASHcontext,
1157 prefix->bv_val, prefix->bv_len );
1159 HASH_Update( &HASHcontext,
1160 &pre, sizeof( pre ) );
1161 HASH_Update( &HASHcontext,
1162 syntax->ssyn_oid, slen );
1163 HASH_Update( &HASHcontext,
1164 mr->smr_oid, mlen );
1165 HASH_Update( &HASHcontext,
1166 &value->bv_val[j], klen );
1167 HASH_Final( HASHdigest, &HASHcontext );
1169 keys[nkeys++] = ber_bvdup( &digest );
1174 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
1175 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1177 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1178 value = sa->sa_final;
1180 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1181 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1183 HASH_Init( &HASHcontext );
1184 if( prefix != NULL && prefix->bv_len > 0 ) {
1185 HASH_Update( &HASHcontext,
1186 prefix->bv_val, prefix->bv_len );
1188 HASH_Update( &HASHcontext,
1189 &pre, sizeof( pre ) );
1190 HASH_Update( &HASHcontext,
1191 syntax->ssyn_oid, slen );
1192 HASH_Update( &HASHcontext,
1193 mr->smr_oid, mlen );
1194 HASH_Update( &HASHcontext,
1195 &value->bv_val[value->bv_len-klen], klen );
1196 HASH_Final( HASHdigest, &HASHcontext );
1198 keys[nkeys++] = ber_bvdup( &digest );
1209 return LDAP_SUCCESS;
1218 struct berval *value,
1219 void *assertedValue )
1222 *matchp = UTF8casecmp( value, (struct berval *) assertedValue );
1224 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1227 match = strncasecmp( value->bv_val,
1228 ((struct berval *) assertedValue)->bv_val,
1234 return LDAP_SUCCESS;
1238 caseIgnoreSubstringsMatch(
1243 struct berval *value,
1244 void *assertedValue )
1247 SubstringsAssertion *sub = assertedValue;
1248 struct berval left = *value;
1252 /* Add up asserted input length */
1253 if( sub->sa_initial ) {
1254 inlen += sub->sa_initial->bv_len;
1257 for(i=0; sub->sa_any[i] != NULL; i++) {
1258 inlen += sub->sa_any[i]->bv_len;
1261 if( sub->sa_final ) {
1262 inlen += sub->sa_final->bv_len;
1265 if( sub->sa_initial ) {
1266 if( inlen > left.bv_len ) {
1271 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1272 sub->sa_initial->bv_len );
1278 left.bv_val += sub->sa_initial->bv_len;
1279 left.bv_len -= sub->sa_initial->bv_len;
1280 inlen -= sub->sa_initial->bv_len;
1283 if( sub->sa_final ) {
1284 if( inlen > left.bv_len ) {
1289 match = strncasecmp( sub->sa_final->bv_val,
1290 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1291 sub->sa_final->bv_len );
1297 left.bv_len -= sub->sa_final->bv_len;
1298 inlen -= sub->sa_final->bv_len;
1302 for(i=0; sub->sa_any[i]; i++) {
1307 if( inlen > left.bv_len ) {
1308 /* not enough length */
1313 if( sub->sa_any[i]->bv_len == 0 ) {
1317 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1324 idx = p - left.bv_val;
1325 assert( idx < left.bv_len );
1327 if( idx >= left.bv_len ) {
1328 /* this shouldn't happen */
1335 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1336 /* not enough left */
1341 match = strncasecmp( left.bv_val,
1342 sub->sa_any[i]->bv_val,
1343 sub->sa_any[i]->bv_len );
1352 left.bv_val += sub->sa_any[i]->bv_len;
1353 left.bv_len -= sub->sa_any[i]->bv_len;
1354 inlen -= sub->sa_any[i]->bv_len;
1360 return LDAP_SUCCESS;
1363 /* Index generation function */
1364 int caseIgnoreIndexer(
1369 struct berval *prefix,
1370 struct berval **values,
1371 struct berval ***keysp )
1375 struct berval **keys;
1376 HASH_CONTEXT HASHcontext;
1377 unsigned char HASHdigest[HASH_BYTES];
1378 struct berval digest;
1379 digest.bv_val = HASHdigest;
1380 digest.bv_len = sizeof(HASHdigest);
1382 /* we should have at least one value at this point */
1383 assert( values != NULL && values[0] != NULL );
1385 for( i=0; values[i] != NULL; i++ ) {
1386 /* just count them */
1389 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1391 slen = strlen( syntax->ssyn_oid );
1392 mlen = strlen( mr->smr_oid );
1394 for( i=0; values[i] != NULL; i++ ) {
1395 struct berval *value = ber_bvdup( values[i] );
1396 ldap_pvt_str2upper( value->bv_val );
1398 HASH_Init( &HASHcontext );
1399 if( prefix != NULL && prefix->bv_len > 0 ) {
1400 HASH_Update( &HASHcontext,
1401 prefix->bv_val, prefix->bv_len );
1403 HASH_Update( &HASHcontext,
1404 syntax->ssyn_oid, slen );
1405 HASH_Update( &HASHcontext,
1406 mr->smr_oid, mlen );
1407 HASH_Update( &HASHcontext,
1408 value->bv_val, value->bv_len );
1409 HASH_Final( HASHdigest, &HASHcontext );
1411 ber_bvfree( value );
1413 keys[i] = ber_bvdup( &digest );
1418 return LDAP_SUCCESS;
1421 /* Index generation function */
1422 int caseIgnoreFilter(
1427 struct berval *prefix,
1429 struct berval ***keysp )
1432 struct berval **keys;
1433 HASH_CONTEXT HASHcontext;
1434 unsigned char HASHdigest[HASH_BYTES];
1435 struct berval *value;
1436 struct berval digest;
1437 digest.bv_val = HASHdigest;
1438 digest.bv_len = sizeof(HASHdigest);
1440 slen = strlen( syntax->ssyn_oid );
1441 mlen = strlen( mr->smr_oid );
1443 value = ber_bvdup( (struct berval *) assertValue );
1444 ldap_pvt_str2upper( value->bv_val );
1446 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1448 HASH_Init( &HASHcontext );
1449 if( prefix != NULL && prefix->bv_len > 0 ) {
1450 HASH_Update( &HASHcontext,
1451 prefix->bv_val, prefix->bv_len );
1453 HASH_Update( &HASHcontext,
1454 syntax->ssyn_oid, slen );
1455 HASH_Update( &HASHcontext,
1456 mr->smr_oid, mlen );
1457 HASH_Update( &HASHcontext,
1458 value->bv_val, value->bv_len );
1459 HASH_Final( HASHdigest, &HASHcontext );
1461 keys[0] = ber_bvdup( &digest );
1464 ber_bvfree( value );
1468 return LDAP_SUCCESS;
1471 /* Substrings Index generation function */
1472 int caseIgnoreSubstringsIndexer(
1477 struct berval *prefix,
1478 struct berval **values,
1479 struct berval ***keysp )
1483 struct berval **keys;
1484 HASH_CONTEXT HASHcontext;
1485 unsigned char HASHdigest[HASH_BYTES];
1486 struct berval digest;
1487 digest.bv_val = HASHdigest;
1488 digest.bv_len = sizeof(HASHdigest);
1490 /* we should have at least one value at this point */
1491 assert( values != NULL && values[0] != NULL );
1494 for( i=0; values[i] != NULL; i++ ) {
1495 /* count number of indices to generate */
1496 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1500 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1501 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1502 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1503 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1505 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1509 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1510 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1511 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1515 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1516 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1517 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1518 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1520 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1526 /* no keys to generate */
1528 return LDAP_SUCCESS;
1531 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1533 slen = strlen( syntax->ssyn_oid );
1534 mlen = strlen( mr->smr_oid );
1537 for( i=0; values[i] != NULL; i++ ) {
1539 struct berval *value;
1541 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1543 value = ber_bvdup( values[i] );
1544 ldap_pvt_str2upper( value->bv_val );
1546 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1547 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
1549 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1550 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
1552 for( j=0; j<max; j++ ) {
1553 HASH_Init( &HASHcontext );
1554 if( prefix != NULL && prefix->bv_len > 0 ) {
1555 HASH_Update( &HASHcontext,
1556 prefix->bv_val, prefix->bv_len );
1559 HASH_Update( &HASHcontext,
1560 &pre, sizeof( pre ) );
1561 HASH_Update( &HASHcontext,
1562 syntax->ssyn_oid, slen );
1563 HASH_Update( &HASHcontext,
1564 mr->smr_oid, mlen );
1565 HASH_Update( &HASHcontext,
1567 SLAP_INDEX_SUBSTR_MAXLEN );
1568 HASH_Final( HASHdigest, &HASHcontext );
1570 keys[nkeys++] = ber_bvdup( &digest );
1574 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1575 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1577 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1580 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1581 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1582 HASH_Init( &HASHcontext );
1583 if( prefix != NULL && prefix->bv_len > 0 ) {
1584 HASH_Update( &HASHcontext,
1585 prefix->bv_val, prefix->bv_len );
1587 HASH_Update( &HASHcontext,
1588 &pre, sizeof( pre ) );
1589 HASH_Update( &HASHcontext,
1590 syntax->ssyn_oid, slen );
1591 HASH_Update( &HASHcontext,
1592 mr->smr_oid, mlen );
1593 HASH_Update( &HASHcontext,
1595 HASH_Final( HASHdigest, &HASHcontext );
1597 keys[nkeys++] = ber_bvdup( &digest );
1600 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1601 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1602 HASH_Init( &HASHcontext );
1603 if( prefix != NULL && prefix->bv_len > 0 ) {
1604 HASH_Update( &HASHcontext,
1605 prefix->bv_val, prefix->bv_len );
1607 HASH_Update( &HASHcontext,
1608 &pre, sizeof( pre ) );
1609 HASH_Update( &HASHcontext,
1610 syntax->ssyn_oid, slen );
1611 HASH_Update( &HASHcontext,
1612 mr->smr_oid, mlen );
1613 HASH_Update( &HASHcontext,
1614 &value->bv_val[value->bv_len-j], j );
1615 HASH_Final( HASHdigest, &HASHcontext );
1617 keys[nkeys++] = ber_bvdup( &digest );
1622 ber_bvfree( value );
1633 return LDAP_SUCCESS;
1636 int caseIgnoreSubstringsFilter(
1641 struct berval *prefix,
1643 struct berval ***keysp )
1645 SubstringsAssertion *sa = assertValue;
1647 ber_len_t nkeys = 0;
1648 size_t slen, mlen, klen;
1649 struct berval **keys;
1650 HASH_CONTEXT HASHcontext;
1651 unsigned char HASHdigest[HASH_BYTES];
1652 struct berval *value;
1653 struct berval digest;
1655 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1656 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1661 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1663 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1664 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1665 /* don't bother accounting for stepping */
1666 nkeys += sa->sa_any[i]->bv_len -
1667 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1672 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1673 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1680 return LDAP_SUCCESS;
1683 digest.bv_val = HASHdigest;
1684 digest.bv_len = sizeof(HASHdigest);
1686 slen = strlen( syntax->ssyn_oid );
1687 mlen = strlen( mr->smr_oid );
1689 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1692 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1693 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1695 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1696 value = ber_bvdup( sa->sa_initial );
1697 ldap_pvt_str2upper( value->bv_val );
1699 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1700 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1702 HASH_Init( &HASHcontext );
1703 if( prefix != NULL && prefix->bv_len > 0 ) {
1704 HASH_Update( &HASHcontext,
1705 prefix->bv_val, prefix->bv_len );
1707 HASH_Update( &HASHcontext,
1708 &pre, sizeof( pre ) );
1709 HASH_Update( &HASHcontext,
1710 syntax->ssyn_oid, slen );
1711 HASH_Update( &HASHcontext,
1712 mr->smr_oid, mlen );
1713 HASH_Update( &HASHcontext,
1714 value->bv_val, klen );
1715 HASH_Final( HASHdigest, &HASHcontext );
1717 ber_bvfree( value );
1718 keys[nkeys++] = ber_bvdup( &digest );
1721 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1723 pre = SLAP_INDEX_SUBSTR_PREFIX;
1724 klen = SLAP_INDEX_SUBSTR_MAXLEN;
1726 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1727 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
1731 value = ber_bvdup( sa->sa_any[i] );
1732 ldap_pvt_str2upper( value->bv_val );
1735 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
1736 j += SLAP_INDEX_SUBSTR_STEP )
1738 HASH_Init( &HASHcontext );
1739 if( prefix != NULL && prefix->bv_len > 0 ) {
1740 HASH_Update( &HASHcontext,
1741 prefix->bv_val, prefix->bv_len );
1743 HASH_Update( &HASHcontext,
1744 &pre, sizeof( pre ) );
1745 HASH_Update( &HASHcontext,
1746 syntax->ssyn_oid, slen );
1747 HASH_Update( &HASHcontext,
1748 mr->smr_oid, mlen );
1749 HASH_Update( &HASHcontext,
1750 &value->bv_val[j], klen );
1751 HASH_Final( HASHdigest, &HASHcontext );
1753 keys[nkeys++] = ber_bvdup( &digest );
1756 ber_bvfree( value );
1760 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1761 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1763 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1764 value = ber_bvdup( sa->sa_final );
1765 ldap_pvt_str2upper( value->bv_val );
1767 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1768 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1770 HASH_Init( &HASHcontext );
1771 if( prefix != NULL && prefix->bv_len > 0 ) {
1772 HASH_Update( &HASHcontext,
1773 prefix->bv_val, prefix->bv_len );
1775 HASH_Update( &HASHcontext,
1776 &pre, sizeof( pre ) );
1777 HASH_Update( &HASHcontext,
1778 syntax->ssyn_oid, slen );
1779 HASH_Update( &HASHcontext,
1780 mr->smr_oid, mlen );
1781 HASH_Update( &HASHcontext,
1782 &value->bv_val[value->bv_len-klen], klen );
1783 HASH_Final( HASHdigest, &HASHcontext );
1785 ber_bvfree( value );
1786 keys[nkeys++] = ber_bvdup( &digest );
1797 return LDAP_SUCCESS;
1803 struct berval *val )
1807 if( val->bv_len == 0 ) return 0;
1809 if( OID_LEADCHAR(val->bv_val[0]) ) {
1811 for(i=1; i < val->bv_len; i++) {
1812 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1813 if( dot++ ) return 1;
1814 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1817 return LDAP_INVALID_SYNTAX;
1821 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1823 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1824 for(i=1; i < val->bv_len; i++) {
1825 if( !DESC_CHAR(val->bv_val[i] ) ) {
1826 return LDAP_INVALID_SYNTAX;
1830 return LDAP_SUCCESS;
1833 return LDAP_INVALID_SYNTAX;
1839 struct berval *val )
1843 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1845 if( val->bv_val[0] == '+' || val->bv_val[0] == '-' ) {
1846 if( val->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
1847 } else if( !ASCII_DIGIT(val->bv_val[0]) ) {
1848 return LDAP_INVALID_SYNTAX;
1851 for(i=1; i < val->bv_len; i++) {
1852 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1855 return LDAP_SUCCESS;
1862 struct berval **normalized )
1865 struct berval *newval;
1871 negative = ( *p == '-' );
1872 if( *p == '-' || *p == '+' ) p++;
1874 /* Ignore leading zeros */
1875 while ( *p == '0' ) p++;
1877 newval = (struct berval *) ch_malloc( sizeof(struct berval) );
1880 newval->bv_val = ch_strdup("0");
1885 newval->bv_val = ch_malloc( val->bv_len + 1 );
1889 newval->bv_val[newval->bv_len++] = '-';
1892 for( ; *p != '\0'; p++ ) {
1893 newval->bv_val[newval->bv_len++] = *p;
1897 *normalized = newval;
1898 return LDAP_SUCCESS;
1902 printableStringValidate(
1904 struct berval *val )
1908 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1910 for(i=0; i < val->bv_len; i++) {
1911 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1914 return LDAP_SUCCESS;
1920 struct berval *val )
1924 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1926 for(i=0; i < val->bv_len; i++) {
1927 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1930 return LDAP_SUCCESS;
1937 struct berval **normalized )
1939 struct berval *newval;
1942 newval = ch_malloc( sizeof( struct berval ) );
1946 /* Ignore initial whitespace */
1947 while ( ASCII_SPACE( *p ) ) {
1953 return LDAP_INVALID_SYNTAX;
1956 newval->bv_val = ch_strdup( p );
1957 p = q = newval->bv_val;
1960 if ( ASCII_SPACE( *p ) ) {
1963 /* Ignore the extra whitespace */
1964 while ( ASCII_SPACE( *p ) ) {
1972 assert( *newval->bv_val );
1973 assert( newval->bv_val < p );
1976 /* cannot start with a space */
1977 assert( !ASCII_SPACE(*newval->bv_val) );
1980 * If the string ended in space, backup the pointer one
1981 * position. One is enough because the above loop collapsed
1982 * all whitespace to a single space.
1985 if ( ASCII_SPACE( q[-1] ) ) {
1989 /* cannot end with a space */
1990 assert( !ASCII_SPACE( q[-1] ) );
1992 /* null terminate */
1995 newval->bv_len = q - newval->bv_val;
1996 *normalized = newval;
1998 return LDAP_SUCCESS;
2007 struct berval *value,
2008 void *assertedValue )
2010 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2013 match = strncmp( value->bv_val,
2014 ((struct berval *) assertedValue)->bv_val,
2019 return LDAP_SUCCESS;
2023 caseExactIA5SubstringsMatch(
2028 struct berval *value,
2029 void *assertedValue )
2032 SubstringsAssertion *sub = assertedValue;
2033 struct berval left = *value;
2037 /* Add up asserted input length */
2038 if( sub->sa_initial ) {
2039 inlen += sub->sa_initial->bv_len;
2042 for(i=0; sub->sa_any[i] != NULL; i++) {
2043 inlen += sub->sa_any[i]->bv_len;
2046 if( sub->sa_final ) {
2047 inlen += sub->sa_final->bv_len;
2050 if( sub->sa_initial ) {
2051 if( inlen > left.bv_len ) {
2056 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
2057 sub->sa_initial->bv_len );
2063 left.bv_val += sub->sa_initial->bv_len;
2064 left.bv_len -= sub->sa_initial->bv_len;
2065 inlen -= sub->sa_initial->bv_len;
2068 if( sub->sa_final ) {
2069 if( inlen > left.bv_len ) {
2074 match = strncmp( sub->sa_final->bv_val,
2075 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2076 sub->sa_final->bv_len );
2082 left.bv_len -= sub->sa_final->bv_len;
2083 inlen -= sub->sa_final->bv_len;
2087 for(i=0; sub->sa_any[i]; i++) {
2092 if( inlen > left.bv_len ) {
2093 /* not enough length */
2098 if( sub->sa_any[i]->bv_len == 0 ) {
2102 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
2109 idx = p - left.bv_val;
2110 assert( idx < left.bv_len );
2112 if( idx >= left.bv_len ) {
2113 /* this shouldn't happen */
2120 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2121 /* not enough left */
2126 match = strncmp( left.bv_val,
2127 sub->sa_any[i]->bv_val,
2128 sub->sa_any[i]->bv_len );
2136 left.bv_val += sub->sa_any[i]->bv_len;
2137 left.bv_len -= sub->sa_any[i]->bv_len;
2138 inlen -= sub->sa_any[i]->bv_len;
2144 return LDAP_SUCCESS;
2147 /* Index generation function */
2148 int caseExactIA5Indexer(
2153 struct berval *prefix,
2154 struct berval **values,
2155 struct berval ***keysp )
2159 struct berval **keys;
2160 HASH_CONTEXT HASHcontext;
2161 unsigned char HASHdigest[HASH_BYTES];
2162 struct berval digest;
2163 digest.bv_val = HASHdigest;
2164 digest.bv_len = sizeof(HASHdigest);
2166 /* we should have at least one value at this point */
2167 assert( values != NULL && values[0] != NULL );
2169 for( i=0; values[i] != NULL; i++ ) {
2170 /* just count them */
2173 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2175 slen = strlen( syntax->ssyn_oid );
2176 mlen = strlen( mr->smr_oid );
2178 for( i=0; values[i] != NULL; i++ ) {
2179 struct berval *value = values[i];
2181 HASH_Init( &HASHcontext );
2182 if( prefix != NULL && prefix->bv_len > 0 ) {
2183 HASH_Update( &HASHcontext,
2184 prefix->bv_val, prefix->bv_len );
2186 HASH_Update( &HASHcontext,
2187 syntax->ssyn_oid, slen );
2188 HASH_Update( &HASHcontext,
2189 mr->smr_oid, mlen );
2190 HASH_Update( &HASHcontext,
2191 value->bv_val, value->bv_len );
2192 HASH_Final( HASHdigest, &HASHcontext );
2194 keys[i] = ber_bvdup( &digest );
2199 return LDAP_SUCCESS;
2202 /* Index generation function */
2203 int caseExactIA5Filter(
2208 struct berval *prefix,
2210 struct berval ***keysp )
2213 struct berval **keys;
2214 HASH_CONTEXT HASHcontext;
2215 unsigned char HASHdigest[HASH_BYTES];
2216 struct berval *value;
2217 struct berval digest;
2218 digest.bv_val = HASHdigest;
2219 digest.bv_len = sizeof(HASHdigest);
2221 slen = strlen( syntax->ssyn_oid );
2222 mlen = strlen( mr->smr_oid );
2224 value = (struct berval *) assertValue;
2226 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2228 HASH_Init( &HASHcontext );
2229 if( prefix != NULL && prefix->bv_len > 0 ) {
2230 HASH_Update( &HASHcontext,
2231 prefix->bv_val, prefix->bv_len );
2233 HASH_Update( &HASHcontext,
2234 syntax->ssyn_oid, slen );
2235 HASH_Update( &HASHcontext,
2236 mr->smr_oid, mlen );
2237 HASH_Update( &HASHcontext,
2238 value->bv_val, value->bv_len );
2239 HASH_Final( HASHdigest, &HASHcontext );
2241 keys[0] = ber_bvdup( &digest );
2245 return LDAP_SUCCESS;
2248 /* Substrings Index generation function */
2249 int caseExactIA5SubstringsIndexer(
2254 struct berval *prefix,
2255 struct berval **values,
2256 struct berval ***keysp )
2260 struct berval **keys;
2261 HASH_CONTEXT HASHcontext;
2262 unsigned char HASHdigest[HASH_BYTES];
2263 struct berval digest;
2264 digest.bv_val = HASHdigest;
2265 digest.bv_len = sizeof(HASHdigest);
2267 /* we should have at least one value at this point */
2268 assert( values != NULL && values[0] != NULL );
2271 for( i=0; values[i] != NULL; i++ ) {
2272 /* count number of indices to generate */
2273 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2277 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2278 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2279 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2280 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2282 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2286 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2287 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2288 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2292 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2293 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2294 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2295 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2297 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2303 /* no keys to generate */
2305 return LDAP_SUCCESS;
2308 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2310 slen = strlen( syntax->ssyn_oid );
2311 mlen = strlen( mr->smr_oid );
2314 for( i=0; values[i] != NULL; i++ ) {
2316 struct berval *value;
2319 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2321 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2322 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2324 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2325 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2327 for( j=0; j<max; j++ ) {
2328 HASH_Init( &HASHcontext );
2329 if( prefix != NULL && prefix->bv_len > 0 ) {
2330 HASH_Update( &HASHcontext,
2331 prefix->bv_val, prefix->bv_len );
2334 HASH_Update( &HASHcontext,
2335 &pre, sizeof( pre ) );
2336 HASH_Update( &HASHcontext,
2337 syntax->ssyn_oid, slen );
2338 HASH_Update( &HASHcontext,
2339 mr->smr_oid, mlen );
2340 HASH_Update( &HASHcontext,
2342 SLAP_INDEX_SUBSTR_MAXLEN );
2343 HASH_Final( HASHdigest, &HASHcontext );
2345 keys[nkeys++] = ber_bvdup( &digest );
2349 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2350 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2352 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2355 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2356 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2357 HASH_Init( &HASHcontext );
2358 if( prefix != NULL && prefix->bv_len > 0 ) {
2359 HASH_Update( &HASHcontext,
2360 prefix->bv_val, prefix->bv_len );
2362 HASH_Update( &HASHcontext,
2363 &pre, sizeof( pre ) );
2364 HASH_Update( &HASHcontext,
2365 syntax->ssyn_oid, slen );
2366 HASH_Update( &HASHcontext,
2367 mr->smr_oid, mlen );
2368 HASH_Update( &HASHcontext,
2370 HASH_Final( HASHdigest, &HASHcontext );
2372 keys[nkeys++] = ber_bvdup( &digest );
2375 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2376 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2377 HASH_Init( &HASHcontext );
2378 if( prefix != NULL && prefix->bv_len > 0 ) {
2379 HASH_Update( &HASHcontext,
2380 prefix->bv_val, prefix->bv_len );
2382 HASH_Update( &HASHcontext,
2383 &pre, sizeof( pre ) );
2384 HASH_Update( &HASHcontext,
2385 syntax->ssyn_oid, slen );
2386 HASH_Update( &HASHcontext,
2387 mr->smr_oid, mlen );
2388 HASH_Update( &HASHcontext,
2389 &value->bv_val[value->bv_len-j], j );
2390 HASH_Final( HASHdigest, &HASHcontext );
2392 keys[nkeys++] = ber_bvdup( &digest );
2406 return LDAP_SUCCESS;
2409 int caseExactIA5SubstringsFilter(
2414 struct berval *prefix,
2416 struct berval ***keysp )
2418 SubstringsAssertion *sa = assertValue;
2420 ber_len_t nkeys = 0;
2421 size_t slen, mlen, klen;
2422 struct berval **keys;
2423 HASH_CONTEXT HASHcontext;
2424 unsigned char HASHdigest[HASH_BYTES];
2425 struct berval *value;
2426 struct berval digest;
2428 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2429 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2434 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2436 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2437 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2438 /* don't bother accounting for stepping */
2439 nkeys += sa->sa_any[i]->bv_len -
2440 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2445 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2446 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2453 return LDAP_SUCCESS;
2456 digest.bv_val = HASHdigest;
2457 digest.bv_len = sizeof(HASHdigest);
2459 slen = strlen( syntax->ssyn_oid );
2460 mlen = strlen( mr->smr_oid );
2462 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2465 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2466 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2468 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2469 value = sa->sa_initial;
2471 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2472 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2474 HASH_Init( &HASHcontext );
2475 if( prefix != NULL && prefix->bv_len > 0 ) {
2476 HASH_Update( &HASHcontext,
2477 prefix->bv_val, prefix->bv_len );
2479 HASH_Update( &HASHcontext,
2480 &pre, sizeof( pre ) );
2481 HASH_Update( &HASHcontext,
2482 syntax->ssyn_oid, slen );
2483 HASH_Update( &HASHcontext,
2484 mr->smr_oid, mlen );
2485 HASH_Update( &HASHcontext,
2486 value->bv_val, klen );
2487 HASH_Final( HASHdigest, &HASHcontext );
2489 keys[nkeys++] = ber_bvdup( &digest );
2492 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2494 pre = SLAP_INDEX_SUBSTR_PREFIX;
2495 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2497 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2498 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2502 value = sa->sa_any[i];
2505 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2506 j += SLAP_INDEX_SUBSTR_STEP )
2508 HASH_Init( &HASHcontext );
2509 if( prefix != NULL && prefix->bv_len > 0 ) {
2510 HASH_Update( &HASHcontext,
2511 prefix->bv_val, prefix->bv_len );
2513 HASH_Update( &HASHcontext,
2514 &pre, sizeof( pre ) );
2515 HASH_Update( &HASHcontext,
2516 syntax->ssyn_oid, slen );
2517 HASH_Update( &HASHcontext,
2518 mr->smr_oid, mlen );
2519 HASH_Update( &HASHcontext,
2520 &value->bv_val[j], klen );
2521 HASH_Final( HASHdigest, &HASHcontext );
2523 keys[nkeys++] = ber_bvdup( &digest );
2528 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2529 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2531 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2532 value = sa->sa_final;
2534 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2535 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2537 HASH_Init( &HASHcontext );
2538 if( prefix != NULL && prefix->bv_len > 0 ) {
2539 HASH_Update( &HASHcontext,
2540 prefix->bv_val, prefix->bv_len );
2542 HASH_Update( &HASHcontext,
2543 &pre, sizeof( pre ) );
2544 HASH_Update( &HASHcontext,
2545 syntax->ssyn_oid, slen );
2546 HASH_Update( &HASHcontext,
2547 mr->smr_oid, mlen );
2548 HASH_Update( &HASHcontext,
2549 &value->bv_val[value->bv_len-klen], klen );
2550 HASH_Final( HASHdigest, &HASHcontext );
2552 keys[nkeys++] = ber_bvdup( &digest );
2563 return LDAP_SUCCESS;
2572 struct berval *value,
2573 void *assertedValue )
2575 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2578 match = strncasecmp( value->bv_val,
2579 ((struct berval *) assertedValue)->bv_val,
2584 return LDAP_SUCCESS;
2588 caseIgnoreIA5SubstringsMatch(
2593 struct berval *value,
2594 void *assertedValue )
2597 SubstringsAssertion *sub = assertedValue;
2598 struct berval left = *value;
2602 /* Add up asserted input length */
2603 if( sub->sa_initial ) {
2604 inlen += sub->sa_initial->bv_len;
2607 for(i=0; sub->sa_any[i] != NULL; i++) {
2608 inlen += sub->sa_any[i]->bv_len;
2611 if( sub->sa_final ) {
2612 inlen += sub->sa_final->bv_len;
2615 if( sub->sa_initial ) {
2616 if( inlen > left.bv_len ) {
2621 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2622 sub->sa_initial->bv_len );
2628 left.bv_val += sub->sa_initial->bv_len;
2629 left.bv_len -= sub->sa_initial->bv_len;
2630 inlen -= sub->sa_initial->bv_len;
2633 if( sub->sa_final ) {
2634 if( inlen > left.bv_len ) {
2639 match = strncasecmp( sub->sa_final->bv_val,
2640 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2641 sub->sa_final->bv_len );
2647 left.bv_len -= sub->sa_final->bv_len;
2648 inlen -= sub->sa_final->bv_len;
2652 for(i=0; sub->sa_any[i]; i++) {
2657 if( inlen > left.bv_len ) {
2658 /* not enough length */
2663 if( sub->sa_any[i]->bv_len == 0 ) {
2667 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2674 idx = p - left.bv_val;
2675 assert( idx < left.bv_len );
2677 if( idx >= left.bv_len ) {
2678 /* this shouldn't happen */
2685 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2686 /* not enough left */
2691 match = strncasecmp( left.bv_val,
2692 sub->sa_any[i]->bv_val,
2693 sub->sa_any[i]->bv_len );
2702 left.bv_val += sub->sa_any[i]->bv_len;
2703 left.bv_len -= sub->sa_any[i]->bv_len;
2704 inlen -= sub->sa_any[i]->bv_len;
2710 return LDAP_SUCCESS;
2713 /* Index generation function */
2714 int caseIgnoreIA5Indexer(
2719 struct berval *prefix,
2720 struct berval **values,
2721 struct berval ***keysp )
2725 struct berval **keys;
2726 HASH_CONTEXT HASHcontext;
2727 unsigned char HASHdigest[HASH_BYTES];
2728 struct berval digest;
2729 digest.bv_val = HASHdigest;
2730 digest.bv_len = sizeof(HASHdigest);
2732 /* we should have at least one value at this point */
2733 assert( values != NULL && values[0] != NULL );
2735 for( i=0; values[i] != NULL; i++ ) {
2736 /* just count them */
2739 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2741 slen = strlen( syntax->ssyn_oid );
2742 mlen = strlen( mr->smr_oid );
2744 for( i=0; values[i] != NULL; i++ ) {
2745 struct berval *value = ber_bvdup( values[i] );
2746 ldap_pvt_str2upper( value->bv_val );
2748 HASH_Init( &HASHcontext );
2749 if( prefix != NULL && prefix->bv_len > 0 ) {
2750 HASH_Update( &HASHcontext,
2751 prefix->bv_val, prefix->bv_len );
2753 HASH_Update( &HASHcontext,
2754 syntax->ssyn_oid, slen );
2755 HASH_Update( &HASHcontext,
2756 mr->smr_oid, mlen );
2757 HASH_Update( &HASHcontext,
2758 value->bv_val, value->bv_len );
2759 HASH_Final( HASHdigest, &HASHcontext );
2761 ber_bvfree( value );
2763 keys[i] = ber_bvdup( &digest );
2768 return LDAP_SUCCESS;
2771 /* Index generation function */
2772 int caseIgnoreIA5Filter(
2777 struct berval *prefix,
2779 struct berval ***keysp )
2782 struct berval **keys;
2783 HASH_CONTEXT HASHcontext;
2784 unsigned char HASHdigest[HASH_BYTES];
2785 struct berval *value;
2786 struct berval digest;
2787 digest.bv_val = HASHdigest;
2788 digest.bv_len = sizeof(HASHdigest);
2790 slen = strlen( syntax->ssyn_oid );
2791 mlen = strlen( mr->smr_oid );
2793 value = ber_bvdup( (struct berval *) assertValue );
2794 ldap_pvt_str2upper( value->bv_val );
2796 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2798 HASH_Init( &HASHcontext );
2799 if( prefix != NULL && prefix->bv_len > 0 ) {
2800 HASH_Update( &HASHcontext,
2801 prefix->bv_val, prefix->bv_len );
2803 HASH_Update( &HASHcontext,
2804 syntax->ssyn_oid, slen );
2805 HASH_Update( &HASHcontext,
2806 mr->smr_oid, mlen );
2807 HASH_Update( &HASHcontext,
2808 value->bv_val, value->bv_len );
2809 HASH_Final( HASHdigest, &HASHcontext );
2811 keys[0] = ber_bvdup( &digest );
2814 ber_bvfree( value );
2818 return LDAP_SUCCESS;
2821 /* Substrings Index generation function */
2822 int caseIgnoreIA5SubstringsIndexer(
2827 struct berval *prefix,
2828 struct berval **values,
2829 struct berval ***keysp )
2833 struct berval **keys;
2834 HASH_CONTEXT HASHcontext;
2835 unsigned char HASHdigest[HASH_BYTES];
2836 struct berval digest;
2837 digest.bv_val = HASHdigest;
2838 digest.bv_len = sizeof(HASHdigest);
2840 /* we should have at least one value at this point */
2841 assert( values != NULL && values[0] != NULL );
2844 for( i=0; values[i] != NULL; i++ ) {
2845 /* count number of indices to generate */
2846 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2850 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2851 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2852 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2853 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2855 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2859 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2860 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2861 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2865 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2866 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2867 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2868 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2870 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2876 /* no keys to generate */
2878 return LDAP_SUCCESS;
2881 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2883 slen = strlen( syntax->ssyn_oid );
2884 mlen = strlen( mr->smr_oid );
2887 for( i=0; values[i] != NULL; i++ ) {
2889 struct berval *value;
2891 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2893 value = ber_bvdup( values[i] );
2894 ldap_pvt_str2upper( value->bv_val );
2896 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2897 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2899 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2900 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2902 for( j=0; j<max; j++ ) {
2903 HASH_Init( &HASHcontext );
2904 if( prefix != NULL && prefix->bv_len > 0 ) {
2905 HASH_Update( &HASHcontext,
2906 prefix->bv_val, prefix->bv_len );
2909 HASH_Update( &HASHcontext,
2910 &pre, sizeof( pre ) );
2911 HASH_Update( &HASHcontext,
2912 syntax->ssyn_oid, slen );
2913 HASH_Update( &HASHcontext,
2914 mr->smr_oid, mlen );
2915 HASH_Update( &HASHcontext,
2917 SLAP_INDEX_SUBSTR_MAXLEN );
2918 HASH_Final( HASHdigest, &HASHcontext );
2920 keys[nkeys++] = ber_bvdup( &digest );
2924 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2925 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2927 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2930 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2931 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2932 HASH_Init( &HASHcontext );
2933 if( prefix != NULL && prefix->bv_len > 0 ) {
2934 HASH_Update( &HASHcontext,
2935 prefix->bv_val, prefix->bv_len );
2937 HASH_Update( &HASHcontext,
2938 &pre, sizeof( pre ) );
2939 HASH_Update( &HASHcontext,
2940 syntax->ssyn_oid, slen );
2941 HASH_Update( &HASHcontext,
2942 mr->smr_oid, mlen );
2943 HASH_Update( &HASHcontext,
2945 HASH_Final( HASHdigest, &HASHcontext );
2947 keys[nkeys++] = ber_bvdup( &digest );
2950 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2951 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2952 HASH_Init( &HASHcontext );
2953 if( prefix != NULL && prefix->bv_len > 0 ) {
2954 HASH_Update( &HASHcontext,
2955 prefix->bv_val, prefix->bv_len );
2957 HASH_Update( &HASHcontext,
2958 &pre, sizeof( pre ) );
2959 HASH_Update( &HASHcontext,
2960 syntax->ssyn_oid, slen );
2961 HASH_Update( &HASHcontext,
2962 mr->smr_oid, mlen );
2963 HASH_Update( &HASHcontext,
2964 &value->bv_val[value->bv_len-j], j );
2965 HASH_Final( HASHdigest, &HASHcontext );
2967 keys[nkeys++] = ber_bvdup( &digest );
2972 ber_bvfree( value );
2983 return LDAP_SUCCESS;
2986 int caseIgnoreIA5SubstringsFilter(
2991 struct berval *prefix,
2993 struct berval ***keysp )
2995 SubstringsAssertion *sa = assertValue;
2997 ber_len_t nkeys = 0;
2998 size_t slen, mlen, klen;
2999 struct berval **keys;
3000 HASH_CONTEXT HASHcontext;
3001 unsigned char HASHdigest[HASH_BYTES];
3002 struct berval *value;
3003 struct berval digest;
3005 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3006 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3011 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3013 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3014 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
3015 /* don't bother accounting for stepping */
3016 nkeys += sa->sa_any[i]->bv_len -
3017 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
3022 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3023 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3030 return LDAP_SUCCESS;
3033 digest.bv_val = HASHdigest;
3034 digest.bv_len = sizeof(HASHdigest);
3036 slen = strlen( syntax->ssyn_oid );
3037 mlen = strlen( mr->smr_oid );
3039 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
3042 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
3043 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3045 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
3046 value = ber_bvdup( sa->sa_initial );
3047 ldap_pvt_str2upper( value->bv_val );
3049 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3050 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3052 HASH_Init( &HASHcontext );
3053 if( prefix != NULL && prefix->bv_len > 0 ) {
3054 HASH_Update( &HASHcontext,
3055 prefix->bv_val, prefix->bv_len );
3057 HASH_Update( &HASHcontext,
3058 &pre, sizeof( pre ) );
3059 HASH_Update( &HASHcontext,
3060 syntax->ssyn_oid, slen );
3061 HASH_Update( &HASHcontext,
3062 mr->smr_oid, mlen );
3063 HASH_Update( &HASHcontext,
3064 value->bv_val, klen );
3065 HASH_Final( HASHdigest, &HASHcontext );
3067 ber_bvfree( value );
3068 keys[nkeys++] = ber_bvdup( &digest );
3071 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
3073 pre = SLAP_INDEX_SUBSTR_PREFIX;
3074 klen = SLAP_INDEX_SUBSTR_MAXLEN;
3076 for( i=0; sa->sa_any[i] != NULL; i++ ) {
3077 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
3081 value = ber_bvdup( sa->sa_any[i] );
3082 ldap_pvt_str2upper( value->bv_val );
3085 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
3086 j += SLAP_INDEX_SUBSTR_STEP )
3088 HASH_Init( &HASHcontext );
3089 if( prefix != NULL && prefix->bv_len > 0 ) {
3090 HASH_Update( &HASHcontext,
3091 prefix->bv_val, prefix->bv_len );
3093 HASH_Update( &HASHcontext,
3094 &pre, sizeof( pre ) );
3095 HASH_Update( &HASHcontext,
3096 syntax->ssyn_oid, slen );
3097 HASH_Update( &HASHcontext,
3098 mr->smr_oid, mlen );
3099 HASH_Update( &HASHcontext,
3100 &value->bv_val[j], klen );
3101 HASH_Final( HASHdigest, &HASHcontext );
3103 keys[nkeys++] = ber_bvdup( &digest );
3106 ber_bvfree( value );
3110 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
3111 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
3113 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
3114 value = ber_bvdup( sa->sa_final );
3115 ldap_pvt_str2upper( value->bv_val );
3117 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
3118 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
3120 HASH_Init( &HASHcontext );
3121 if( prefix != NULL && prefix->bv_len > 0 ) {
3122 HASH_Update( &HASHcontext,
3123 prefix->bv_val, prefix->bv_len );
3125 HASH_Update( &HASHcontext,
3126 &pre, sizeof( pre ) );
3127 HASH_Update( &HASHcontext,
3128 syntax->ssyn_oid, slen );
3129 HASH_Update( &HASHcontext,
3130 mr->smr_oid, mlen );
3131 HASH_Update( &HASHcontext,
3132 &value->bv_val[value->bv_len-klen], klen );
3133 HASH_Final( HASHdigest, &HASHcontext );
3135 ber_bvfree( value );
3136 keys[nkeys++] = ber_bvdup( &digest );
3147 return LDAP_SUCCESS;
3151 numericStringNormalize(
3154 struct berval **normalized )
3156 /* similiar to IA5StringNormalize except removes all spaces */
3157 struct berval *newval;
3160 newval = ch_malloc( sizeof( struct berval ) );
3164 /* Ignore initial whitespace */
3165 while ( ASCII_SPACE( *p ) ) {
3171 return LDAP_INVALID_SYNTAX;
3174 newval->bv_val = ch_strdup( p );
3175 p = q = newval->bv_val;
3178 if ( ASCII_SPACE( *p ) ) {
3179 /* Ignore whitespace */
3186 assert( *newval->bv_val );
3187 assert( newval->bv_val < p );
3190 /* cannot start with a space */
3191 assert( !ASCII_SPACE(*newval->bv_val) );
3193 /* cannot end with a space */
3194 assert( !ASCII_SPACE( q[-1] ) );
3196 /* null terminate */
3199 newval->bv_len = q - newval->bv_val;
3200 *normalized = newval;
3202 return LDAP_SUCCESS;
3206 objectIdentifierFirstComponentMatch(
3211 struct berval *value,
3212 void *assertedValue )
3214 int rc = LDAP_SUCCESS;
3216 struct berval *asserted = (struct berval *) assertedValue;
3220 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3221 return LDAP_INVALID_SYNTAX;
3224 /* trim leading white space */
3225 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3229 /* grab next word */
3230 oid.bv_val = &value->bv_val[i];
3231 oid.bv_len = value->bv_len - i;
3232 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3237 /* insert attributeTypes, objectclass check here */
3238 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3239 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3242 char *stored = ch_malloc( oid.bv_len + 1 );
3243 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3244 stored[oid.bv_len] = '\0';
3246 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3247 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3248 MatchingRule *stored_mr = mr_find( stored );
3250 if( asserted_mr == NULL ) {
3251 rc = SLAPD_COMPARE_UNDEFINED;
3253 match = asserted_mr != stored_mr;
3256 } else if ( !strcmp( syntax->ssyn_oid,
3257 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3259 AttributeType *asserted_at = at_find( asserted->bv_val );
3260 AttributeType *stored_at = at_find( stored );
3262 if( asserted_at == NULL ) {
3263 rc = SLAPD_COMPARE_UNDEFINED;
3265 match = asserted_at != stored_at;
3268 } else if ( !strcmp( syntax->ssyn_oid,
3269 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3271 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3272 ObjectClass *stored_oc = oc_find( stored );
3274 if( asserted_oc == NULL ) {
3275 rc = SLAPD_COMPARE_UNDEFINED;
3277 match = asserted_oc != stored_oc;
3284 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3285 "%d\n\t\"%s\"\n\t\"%s\"\n",
3286 match, value->bv_val, asserted->bv_val );
3288 if( rc == LDAP_SUCCESS ) *matchp = match;
3293 check_time_syntax (struct berval *val,
3297 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3298 static int mdays[2][12] = {
3299 /* non-leap years */
3300 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3302 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3305 int part, c, tzoffset, leapyear = 0 ;
3307 if( val->bv_len == 0 ) {
3308 return LDAP_INVALID_SYNTAX;
3311 p = (char *)val->bv_val;
3312 e = p + val->bv_len;
3314 /* Ignore initial whitespace */
3315 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3319 if (e - p < 13 - (2 * start)) {
3320 return LDAP_INVALID_SYNTAX;
3323 for (part = 0; part < 9; part++) {
3327 for (part = start; part < 7; part++) {
3329 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3336 return LDAP_INVALID_SYNTAX;
3338 if (c < 0 || c > 9) {
3339 return LDAP_INVALID_SYNTAX;
3345 return LDAP_INVALID_SYNTAX;
3347 if (c < 0 || c > 9) {
3348 return LDAP_INVALID_SYNTAX;
3353 if (part == 2 || part == 3) {
3356 if (parts[part] < 0) {
3357 return LDAP_INVALID_SYNTAX;
3359 if (parts[part] > ceiling[part]) {
3360 return LDAP_INVALID_SYNTAX;
3364 /* leapyear check for the Gregorian calendar (year>1581) */
3365 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3366 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3371 if (parts[3] > mdays[leapyear][parts[2]]) {
3372 return LDAP_INVALID_SYNTAX;
3377 tzoffset = 0; /* UTC */
3378 } else if (c != '+' && c != '-') {
3379 return LDAP_INVALID_SYNTAX;
3383 } else /* c == '+' */ {
3388 return LDAP_INVALID_SYNTAX;
3391 for (part = 7; part < 9; part++) {
3393 if (c < 0 || c > 9) {
3394 return LDAP_INVALID_SYNTAX;
3399 if (c < 0 || c > 9) {
3400 return LDAP_INVALID_SYNTAX;
3404 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3405 return LDAP_INVALID_SYNTAX;
3410 /* Ignore trailing whitespace */
3411 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3415 return LDAP_INVALID_SYNTAX;
3418 switch ( tzoffset ) {
3419 case -1: /* negativ offset to UTC, ie west of Greenwich */
3420 parts[4] += parts[7];
3421 parts[5] += parts[8];
3422 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3426 c = mdays[leapyear][parts[2]];
3428 if (parts[part] > c) {
3429 parts[part] -= c + 1;
3434 case 1: /* positive offset to UTC, ie east of Greenwich */
3435 parts[4] -= parts[7];
3436 parts[5] -= parts[8];
3437 for (part = 6; --part > 0; ) {
3441 /* first arg to % needs to be non negativ */
3442 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3444 if (parts[part] < 0) {
3445 parts[part] += c + 1;
3450 case 0: /* already UTC */
3454 return LDAP_SUCCESS;
3461 struct berval **normalized )
3466 rc = check_time_syntax(val, 1, parts);
3467 if (rc != LDAP_SUCCESS) {
3472 out = ch_malloc( sizeof(struct berval) );
3474 return LBER_ERROR_MEMORY;
3477 out->bv_val = ch_malloc( 14 );
3478 if ( out->bv_val == NULL ) {
3480 return LBER_ERROR_MEMORY;
3483 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3484 parts[1], parts[2] + 1, parts[3] + 1,
3485 parts[4], parts[5], parts[6] );
3489 return LDAP_SUCCESS;
3499 return check_time_syntax(in, 1, parts);
3503 generalizedTimeValidate(
3509 return check_time_syntax(in, 0, parts);
3513 generalizedTimeNormalize(
3516 struct berval **normalized )
3521 rc = check_time_syntax(val, 0, parts);
3522 if (rc != LDAP_SUCCESS) {
3527 out = ch_malloc( sizeof(struct berval) );
3529 return LBER_ERROR_MEMORY;
3532 out->bv_val = ch_malloc( 16 );
3533 if ( out->bv_val == NULL ) {
3535 return LBER_ERROR_MEMORY;
3538 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3539 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3540 parts[4], parts[5], parts[6] );
3544 return LDAP_SUCCESS;
3548 nisNetgroupTripleValidate(
3550 struct berval *val )
3555 if ( val->bv_len == 0 ) {
3556 return LDAP_INVALID_SYNTAX;
3559 p = (char *)val->bv_val;
3560 e = p + val->bv_len;
3563 /* syntax does not allow leading white space */
3564 /* Ignore initial whitespace */
3565 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3570 if ( *p != '(' /*')'*/ ) {
3571 return LDAP_INVALID_SYNTAX;
3574 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3578 return LDAP_INVALID_SYNTAX;
3581 } else if ( !ATTR_CHAR( *p ) ) {
3582 return LDAP_INVALID_SYNTAX;
3586 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3587 return LDAP_INVALID_SYNTAX;
3593 /* syntax does not allow trailing white space */
3594 /* Ignore trailing whitespace */
3595 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3601 return LDAP_INVALID_SYNTAX;
3604 return LDAP_SUCCESS;
3608 bootParameterValidate(
3610 struct berval *val )
3614 if ( val->bv_len == 0 ) {
3615 return LDAP_INVALID_SYNTAX;
3618 p = (char *)val->bv_val;
3619 e = p + val->bv_len;
3622 for (; ( p < e ) && ( *p != '=' ); p++ ) {
3623 if ( !ATTR_CHAR( *p ) ) {
3624 return LDAP_INVALID_SYNTAX;
3629 return LDAP_INVALID_SYNTAX;
3633 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
3634 if ( !ATTR_CHAR( *p ) ) {
3635 return LDAP_INVALID_SYNTAX;
3640 return LDAP_INVALID_SYNTAX;
3644 for ( p++; p < e; p++ ) {
3645 if ( !ATTR_CHAR( *p ) ) {
3646 return LDAP_INVALID_SYNTAX;
3650 return LDAP_SUCCESS;
3653 struct syntax_defs_rec {
3656 slap_syntax_validate_func *sd_validate;
3657 slap_syntax_transform_func *sd_normalize;
3658 slap_syntax_transform_func *sd_pretty;
3659 #ifdef SLAPD_BINARY_CONVERSION
3660 slap_syntax_transform_func *sd_ber2str;
3661 slap_syntax_transform_func *sd_str2ber;
3665 #define X_HIDE "X-HIDE 'TRUE' "
3666 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
3667 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
3669 struct syntax_defs_rec syntax_defs[] = {
3670 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
3671 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
3672 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
3673 0, NULL, NULL, NULL},
3674 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
3675 0, NULL, NULL, NULL},
3676 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
3677 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3678 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
3679 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3680 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
3681 0, bitStringValidate, NULL, NULL },
3682 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
3683 0, booleanValidate, NULL, NULL},
3684 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
3685 X_BINARY X_NOT_H_R ")",
3686 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3687 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
3688 X_BINARY X_NOT_H_R ")",
3689 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3690 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
3691 X_BINARY X_NOT_H_R ")",
3692 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3693 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
3694 0, NULL, NULL, NULL},
3695 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
3696 0, dnValidate, dnNormalize, dnPretty},
3697 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
3698 0, NULL, NULL, NULL},
3699 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
3700 0, NULL, NULL, NULL},
3701 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
3702 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3703 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
3704 0, NULL, NULL, NULL},
3705 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
3706 0, NULL, NULL, NULL},
3707 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
3708 0, NULL, NULL, NULL},
3709 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
3710 0, NULL, NULL, NULL},
3711 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
3712 0, NULL, NULL, NULL},
3713 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
3714 0, IA5StringValidate, faxNumberNormalize, NULL},
3715 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
3716 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
3717 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
3718 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
3719 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
3720 0, NULL, NULL, NULL},
3721 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
3722 0, IA5StringValidate, IA5StringNormalize, NULL},
3723 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
3724 0, integerValidate, integerNormalize, integerPretty},
3725 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
3726 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3727 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
3728 0, NULL, NULL, NULL},
3729 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
3730 0, NULL, NULL, NULL},
3731 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
3732 0, NULL, NULL, NULL},
3733 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
3734 0, NULL, NULL, NULL},
3735 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
3736 0, NULL, NULL, NULL},
3737 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
3738 0, nameUIDValidate, nameUIDNormalize, NULL},
3739 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
3740 0, NULL, NULL, NULL},
3741 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
3742 0, IA5StringValidate, numericStringNormalize, NULL},
3743 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
3744 0, NULL, NULL, NULL},
3745 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
3746 0, oidValidate, NULL, NULL},
3747 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
3748 0, NULL, NULL, NULL},
3749 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
3750 0, blobValidate, NULL, NULL},
3751 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
3752 0, blobValidate, NULL, NULL},
3753 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
3754 0, NULL, NULL, NULL},
3755 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
3756 0, NULL, NULL, NULL},
3757 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
3758 0, printableStringValidate, NULL, NULL},
3759 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
3760 X_BINARY X_NOT_H_R ")",
3761 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3762 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
3763 0, IA5StringValidate, phoneNumberNormalize, NULL},
3764 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
3765 0, NULL, NULL, NULL},
3766 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
3767 0, IA5StringValidate, telexNumberNormalize, NULL},
3768 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
3769 0, utcTimeValidate, utcTimeNormalize, NULL},
3770 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
3771 0, NULL, NULL, NULL},
3772 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
3773 0, NULL, NULL, NULL},
3774 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
3775 0, NULL, NULL, NULL},
3776 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
3777 0, NULL, NULL, NULL},
3778 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
3779 0, NULL, NULL, NULL},
3781 /* RFC 2307 NIS Syntaxes */
3782 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
3783 0, nisNetgroupTripleValidate, NULL, NULL},
3784 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
3785 0, bootParameterValidate, NULL, NULL},
3787 /* OpenLDAP Experimental Syntaxes */
3788 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
3789 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
3791 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
3792 0, NULL, NULL, NULL},
3794 /* OpenLDAP Void Syntax */
3795 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' " X_HIDE ")" ,
3796 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
3797 {NULL, 0, NULL, NULL, NULL}
3800 struct mrule_defs_rec {
3802 slap_mask_t mrd_usage;
3803 slap_mr_convert_func * mrd_convert;
3804 slap_mr_normalize_func * mrd_normalize;
3805 slap_mr_match_func * mrd_match;
3806 slap_mr_indexer_func * mrd_indexer;
3807 slap_mr_filter_func * mrd_filter;
3809 char * mrd_associated;
3813 * Other matching rules in X.520 that we do not use (yet):
3815 * 2.5.13.9 numericStringOrderingMatch
3816 * 2.5.13.15 integerOrderingMatch
3817 * 2.5.13.18 octetStringOrderingMatch
3818 * 2.5.13.19 octetStringSubstringsMatch
3819 * 2.5.13.25 uTCTimeMatch
3820 * 2.5.13.26 uTCTimeOrderingMatch
3821 * 2.5.13.31 directoryStringFirstComponentMatch
3822 * 2.5.13.32 wordMatch
3823 * 2.5.13.33 keywordMatch
3824 * 2.5.13.34 certificateExactMatch
3825 * 2.5.13.35 certificateMatch
3826 * 2.5.13.36 certificatePairExactMatch
3827 * 2.5.13.37 certificatePairMatch
3828 * 2.5.13.38 certificateListExactMatch
3829 * 2.5.13.39 certificateListMatch
3830 * 2.5.13.40 algorithmIdentifierMatch
3831 * 2.5.13.41 storedPrefixMatch
3832 * 2.5.13.42 attributeCertificateMatch
3833 * 2.5.13.43 readerAndKeyIDMatch
3834 * 2.5.13.44 attributeIntegrityMatch
3837 struct mrule_defs_rec mrule_defs[] = {
3839 * EQUALITY matching rules must be listed after associated APPROX
3840 * matching rules. So, we list all APPROX matching rules first.
3842 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
3843 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3844 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3846 directoryStringApproxMatch, NULL, NULL,
3849 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
3850 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3851 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3853 IA5StringApproxMatch, NULL, NULL,
3857 * Other matching rules
3860 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
3861 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3862 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3864 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
3867 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
3868 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
3869 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3871 dnMatch, dnIndexer, dnFilter,
3874 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
3875 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3876 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3878 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
3879 directoryStringApproxMatchOID },
3881 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
3882 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3885 caseIgnoreOrderingMatch, NULL, NULL,
3888 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
3889 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3890 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3892 caseIgnoreSubstringsMatch,
3893 caseIgnoreSubstringsIndexer,
3894 caseIgnoreSubstringsFilter,
3897 {"( 2.5.13.5 NAME 'caseExactMatch' "
3898 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3899 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3901 caseExactMatch, caseExactIndexer, caseExactFilter,
3902 directoryStringApproxMatchOID },
3904 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
3905 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3908 caseExactOrderingMatch, NULL, NULL,
3911 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
3912 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3913 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3915 caseExactSubstringsMatch,
3916 caseExactSubstringsIndexer,
3917 caseExactSubstringsFilter,
3920 {"( 2.5.13.8 NAME 'numericStringMatch' "
3921 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
3922 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3925 caseIgnoreIA5Indexer,
3926 caseIgnoreIA5Filter,
3929 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
3930 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3931 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3933 caseIgnoreIA5SubstringsMatch,
3934 caseIgnoreIA5SubstringsIndexer,
3935 caseIgnoreIA5SubstringsFilter,
3938 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
3939 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
3940 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3942 caseIgnoreListMatch, NULL, NULL,
3945 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
3946 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3947 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3949 caseIgnoreListSubstringsMatch, NULL, NULL,
3952 {"( 2.5.13.13 NAME 'booleanMatch' "
3953 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
3954 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3956 booleanMatch, NULL, NULL,
3959 {"( 2.5.13.14 NAME 'integerMatch' "
3960 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
3961 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3963 integerMatch, integerIndexer, integerFilter,
3966 {"( 2.5.13.16 NAME 'bitStringMatch' "
3967 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
3968 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3970 bitStringMatch, NULL, NULL,
3973 {"( 2.5.13.17 NAME 'octetStringMatch' "
3974 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
3975 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3977 octetStringMatch, octetStringIndexer, octetStringFilter,
3980 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
3981 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
3982 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3984 telephoneNumberMatch, NULL, NULL,
3987 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
3988 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3989 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3991 telephoneNumberSubstringsMatch, NULL, NULL,
3994 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
3995 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
3996 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3998 presentationAddressMatch, NULL, NULL,
4001 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4002 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4003 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4005 uniqueMemberMatch, NULL, NULL,
4008 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4009 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4010 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4012 protocolInformationMatch, NULL, NULL,
4015 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4016 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4017 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4019 generalizedTimeMatch, NULL, NULL,
4022 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4023 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4026 generalizedTimeOrderingMatch, NULL, NULL,
4029 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4030 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4031 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4033 integerFirstComponentMatch, NULL, NULL,
4036 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4037 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4038 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4040 objectIdentifierFirstComponentMatch, NULL, NULL,
4043 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4044 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4045 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4047 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
4048 IA5StringApproxMatchOID },
4050 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4051 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4052 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4054 caseIgnoreIA5Match, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
4055 IA5StringApproxMatchOID },
4057 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4058 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4061 caseIgnoreIA5SubstringsMatch,
4062 caseIgnoreIA5SubstringsIndexer,
4063 caseIgnoreIA5SubstringsFilter,
4066 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4067 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4070 caseExactIA5SubstringsMatch,
4071 caseExactIA5SubstringsIndexer,
4072 caseExactIA5SubstringsFilter,
4075 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4076 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4079 authPasswordMatch, NULL, NULL,
4082 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
4083 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
4086 OpenLDAPaciMatch, NULL, NULL,
4089 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
4098 /* we should only be called once (from main) */
4099 assert( schema_init_done == 0 );
4101 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4102 res = register_syntax( syntax_defs[i].sd_desc,
4103 syntax_defs[i].sd_flags,
4104 syntax_defs[i].sd_validate,
4105 syntax_defs[i].sd_normalize,
4106 syntax_defs[i].sd_pretty
4107 #ifdef SLAPD_BINARY_CONVERSION
4109 syntax_defs[i].sd_ber2str,
4110 syntax_defs[i].sd_str2ber
4115 fprintf( stderr, "schema_init: Error registering syntax %s\n",
4116 syntax_defs[i].sd_desc );
4121 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4122 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
4124 "schema_init: Ingoring unusable matching rule %s\n",
4125 mrule_defs[i].mrd_desc );
4129 res = register_matching_rule(
4130 mrule_defs[i].mrd_desc,
4131 mrule_defs[i].mrd_usage,
4132 mrule_defs[i].mrd_convert,
4133 mrule_defs[i].mrd_normalize,
4134 mrule_defs[i].mrd_match,
4135 mrule_defs[i].mrd_indexer,
4136 mrule_defs[i].mrd_filter,
4137 mrule_defs[i].mrd_associated );
4141 "schema_init: Error registering matching rule %s\n",
4142 mrule_defs[i].mrd_desc );
4146 schema_init_done = 1;
4147 return LDAP_SUCCESS;