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>
18 #include "ldap_pvt_uc.h"
19 #include "lutil_md5.h"
21 /* recycled validatation routines */
22 #define berValidate blobValidate
23 #define nameUIDValidate dnValidate
25 /* unimplemented validators */
26 #define bitStringValidate NULL
28 /* recycled normalization routines */
29 #define faxNumberNormalize numericStringNormalize
30 #define phoneNumberNormalize numericStringNormalize
31 #define telexNumberNormalize numericStringNormalize
32 #define integerNormalize numericStringNormalize
33 #define nameUIDNormalize dnNormalize
35 /* unimplemented normalizers */
36 #define bitStringNormalize NULL
38 /* unimplemented pretters */
40 #define integerPretty NULL
42 /* recyclied pretters */
43 #define nameUIDPretty dnPretty
45 /* recycled matching routines */
46 #define numericStringMatch caseIgnoreMatch
47 #define objectIdentifierMatch numericStringMatch
48 #define integerMatch numericStringMatch
49 #define telephoneNumberMatch numericStringMatch
50 #define telephoneNumberSubstringsMatch caseIgnoreSubstringsMatch
51 #define generalizedTimeMatch numericStringMatch
52 #define generalizedTimeOrderingMatch numericStringMatch
53 #define uniqueMemberMatch dnMatch
55 /* approx matching rules */
56 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
57 #define directoryStringApproxMatch NULL
58 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
59 #define IA5StringApproxMatch NULL
61 /* orderring matching rules */
62 #define caseIgnoreOrderingMatch caseIgnoreMatch
63 #define caseExactOrderingMatch caseExactMatch
65 /* unimplemented matching routines */
66 #define caseIgnoreListMatch NULL
67 #define caseIgnoreListSubstringsMatch NULL
68 #define bitStringMatch NULL
69 #define presentationAddressMatch NULL
70 #define protocolInformationMatch NULL
71 #define integerFirstComponentMatch NULL
73 #define OpenLDAPaciMatch NULL
74 #define authPasswordMatch NULL
76 /* recycled indexing/filtering routines */
77 #define dnIndexer caseIgnoreIndexer
78 #define dnFilter caseIgnoreFilter
80 static char *strcasechr( const char *str, int c )
82 char *lower = strchr( str, TOLOWER(c) );
83 char *upper = strchr( str, TOUPPER(c) );
85 if( lower && upper ) {
86 return lower < upper ? lower : upper;
100 struct berval *value,
101 void *assertedValue )
103 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
106 match = memcmp( value->bv_val,
107 ((struct berval *) assertedValue)->bv_val,
115 /* Index generation function */
116 int octetStringIndexer(
121 struct berval *prefix,
122 struct berval **values,
123 struct berval ***keysp )
127 struct berval **keys;
128 lutil_MD5_CTX MD5context;
129 unsigned char MD5digest[16];
130 struct berval digest;
131 digest.bv_val = MD5digest;
132 digest.bv_len = sizeof(MD5digest);
134 for( i=0; values[i] != NULL; i++ ) {
135 /* just count them */
140 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
142 slen = strlen( syntax->ssyn_oid );
143 mlen = strlen( mr->smr_oid );
145 for( i=0; values[i] != NULL; i++ ) {
146 lutil_MD5Init( &MD5context );
147 if( prefix != NULL && prefix->bv_len > 0 ) {
148 lutil_MD5Update( &MD5context,
149 prefix->bv_val, prefix->bv_len );
151 lutil_MD5Update( &MD5context,
152 syntax->ssyn_oid, slen );
153 lutil_MD5Update( &MD5context,
155 lutil_MD5Update( &MD5context,
156 values[i]->bv_val, values[i]->bv_len );
157 lutil_MD5Final( MD5digest, &MD5context );
159 keys[i] = ber_bvdup( &digest );
169 /* Index generation function */
170 int octetStringFilter(
175 struct berval *prefix,
177 struct berval ***keysp )
180 struct berval **keys;
181 lutil_MD5_CTX MD5context;
182 unsigned char MD5digest[LUTIL_MD5_BYTES];
183 struct berval *value = (struct berval *) assertValue;
184 struct berval digest;
185 digest.bv_val = MD5digest;
186 digest.bv_len = sizeof(MD5digest);
188 slen = strlen( syntax->ssyn_oid );
189 mlen = strlen( mr->smr_oid );
191 keys = ch_malloc( sizeof( struct berval * ) * 2 );
193 lutil_MD5Init( &MD5context );
194 if( prefix != NULL && prefix->bv_len > 0 ) {
195 lutil_MD5Update( &MD5context,
196 prefix->bv_val, prefix->bv_len );
198 lutil_MD5Update( &MD5context,
199 syntax->ssyn_oid, slen );
200 lutil_MD5Update( &MD5context,
202 lutil_MD5Update( &MD5context,
203 value->bv_val, value->bv_len );
204 lutil_MD5Final( MD5digest, &MD5context );
206 keys[0] = ber_bvdup( &digest );
222 if( in->bv_len == 0 ) return LDAP_SUCCESS;
224 dn = ch_strdup( in->bv_val );
226 rc = dn_validate( dn ) == NULL
227 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
237 struct berval **normalized )
239 struct berval *out = ber_bvdup( val );
241 if( out->bv_len != 0 ) {
243 #ifdef USE_DN_NORMALIZE
244 dn = dn_normalize( out->bv_val );
246 dn = dn_validate( out->bv_val );
251 return LDAP_INVALID_SYNTAX;
255 out->bv_len = strlen( dn );
268 struct berval *value,
269 void *assertedValue )
272 struct berval *asserted = (struct berval *) assertedValue;
274 match = value->bv_len - asserted->bv_len;
277 #ifdef USE_DN_NORMALIZE
278 match = strcmp( value->bv_val, asserted->bv_val );
280 match = strcasecmp( value->bv_val, asserted->bv_val );
284 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
285 match, value->bv_val, asserted->bv_val );
296 /* any value allowed */
305 /* any value allowed */
310 * Handling boolean syntax and matching is quite rigid.
311 * A more flexible approach would be to allow a variety
312 * of strings to be normalized and prettied into TRUE
320 /* very unforgiving validation, requires no normalization
321 * before simplistic matching
324 if( in->bv_len == 4 ) {
325 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
328 } else if( in->bv_len == 5 ) {
329 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
334 return LDAP_INVALID_SYNTAX;
343 struct berval *value,
344 void *assertedValue )
346 /* simplistic matching allowed by rigid validation */
347 struct berval *asserted = (struct berval *) assertedValue;
348 *matchp = value->bv_len != asserted->bv_len;
359 unsigned char *u = in->bv_val;
361 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
363 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
364 /* get the length indicated by the first byte */
365 len = LDAP_UTF8_CHARLEN( u );
367 /* should not be zero */
368 if( len == 0 ) return LDAP_INVALID_SYNTAX;
370 /* make sure len corresponds with the offset
371 to the next character */
372 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
375 if( count != 0 ) return LDAP_INVALID_SYNTAX;
380 #define UNICODE2LEN(n) ((n)*sizeof(ldap_unicode_t))
381 #define LEN2UNICODE(n) ((n)/sizeof(ldap_unicode_t))
383 #define SLAP_INDEX_SUBSTR_UMINLEN UNICODE2LEN(SLAP_INDEX_SUBSTR_MINLEN)
384 #define SLAP_INDEX_SUBSTR_UMAXLEN UNICODE2LEN(SLAP_INDEX_SUBSTR_MAXLEN)
385 #define SLAP_INDEX_SUBSTR_USTEP UNICODE2LEN(SLAP_INDEX_SUBSTR_STEP)
391 struct berval **normalized )
397 struct berval *newval;
400 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
406 for( bcount = val->bv_len; bcount > 0; bcount-=len, u+=len ) {
407 /* get the length indicated by the first byte */
408 len = LDAP_UTF8_CHARLEN( u );
410 /* should not be zero */
411 if( len == 0 ) return LDAP_INVALID_SYNTAX;
413 if( ldap_utf8_isspace( u ) ) {
414 if( space ) continue;
423 return LDAP_INVALID_SYNTAX;
430 newval = ch_malloc( sizeof( struct berval ) );
431 newval->bv_val = ch_malloc( UNICODE2LEN(ucount+1) );
432 uc = (ldap_unicode_t *) newval->bv_val;
438 for( bcount = val->bv_len; bcount > 0; bcount-=len, u+=len ) {
439 /* get the length indicated by the first byte */
440 len = LDAP_UTF8_CHARLEN( u );
442 /* should not be zero */
443 if( len == 0 ) return LDAP_INVALID_SYNTAX;
445 if( ldap_utf8_isspace( u ) ) {
446 if( space ) continue;
451 uc[ucount++] = ldap_utf8_to_unicode( u );
454 if( space ) ucount--;
457 newval->bv_len = UNICODE2LEN(ucount);
467 struct berval *value,
468 void *assertedValue )
470 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
473 match = ucstrncmp( (ldap_unicode_t *) value->bv_val,
474 (ldap_unicode_t *) ((struct berval *) assertedValue)->bv_val,
475 LEN2UNICODE(value->bv_len) );
483 caseExactSubstringsMatch(
488 struct berval *value,
489 void *assertedValue )
492 SubstringsAssertion *sub = assertedValue;
493 struct berval left = *value;
497 /* Add up asserted input length */
498 if( sub->sa_initial ) {
499 inlen += sub->sa_initial->bv_len;
502 for(i=0; sub->sa_any[i] != NULL; i++) {
503 inlen += sub->sa_any[i]->bv_len;
506 if( sub->sa_final ) {
507 inlen += sub->sa_final->bv_len;
510 if( sub->sa_initial ) {
511 if( inlen > left.bv_len ) {
517 (ldap_unicode_t *) sub->sa_initial->bv_val,
518 (ldap_unicode_t *) left.bv_val,
519 LEN2UNICODE(sub->sa_initial->bv_len) );
525 left.bv_val += sub->sa_initial->bv_len;
526 left.bv_len -= sub->sa_initial->bv_len;
527 inlen -= sub->sa_initial->bv_len;
530 if( sub->sa_final ) {
531 if( inlen > left.bv_len ) {
537 (ldap_unicode_t *) sub->sa_final->bv_val,
538 (ldap_unicode_t *) &left.bv_val[left.bv_len - sub->sa_final->bv_len],
539 LEN2UNICODE(sub->sa_final->bv_len) );
545 left.bv_len -= sub->sa_final->bv_len;
546 inlen -= sub->sa_final->bv_len;
550 for(i=0; sub->sa_any[i]; i++) {
555 if( inlen > left.bv_len ) {
556 /* not enough length */
561 if( sub->sa_any[i]->bv_len == 0 ) {
565 p = (char *) ucstrnchr(
566 (ldap_unicode_t *) left.bv_val,
567 LEN2UNICODE(left.bv_len),
568 ((ldap_unicode_t *) sub->sa_any[i]->bv_val)[0] );
576 idx = p - left.bv_val;
577 assert( idx < left.bv_len );
579 if( idx >= left.bv_len ) {
580 /* this shouldn't happen */
587 if( sub->sa_any[i]->bv_len > left.bv_len ) {
588 /* not enough left */
594 (ldap_unicode_t *) left.bv_val,
595 (ldap_unicode_t *) sub->sa_any[i]->bv_val,
596 LEN2UNICODE(sub->sa_any[i]->bv_len) );
599 left.bv_val += UNICODE2LEN(1);
600 left.bv_len -= UNICODE2LEN(1);
604 left.bv_val += sub->sa_any[i]->bv_len;
605 left.bv_len -= sub->sa_any[i]->bv_len;
606 inlen -= sub->sa_any[i]->bv_len;
615 /* Index generation function */
616 int caseExactIndexer(
621 struct berval *prefix,
622 struct berval **values,
623 struct berval ***keysp )
627 struct berval **keys;
628 lutil_MD5_CTX MD5context;
629 unsigned char MD5digest[16];
630 struct berval digest;
631 digest.bv_val = MD5digest;
632 digest.bv_len = sizeof(MD5digest);
634 for( i=0; values[i] != NULL; i++ ) {
635 /* just count them */
640 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
642 slen = strlen( syntax->ssyn_oid );
643 mlen = strlen( mr->smr_oid );
645 for( i=0; values[i] != NULL; i++ ) {
646 struct berval *value = values[i];
648 lutil_MD5Init( &MD5context );
649 if( prefix != NULL && prefix->bv_len > 0 ) {
650 lutil_MD5Update( &MD5context,
651 prefix->bv_val, prefix->bv_len );
653 lutil_MD5Update( &MD5context,
654 syntax->ssyn_oid, slen );
655 lutil_MD5Update( &MD5context,
657 lutil_MD5Update( &MD5context,
658 value->bv_val, value->bv_len );
659 lutil_MD5Final( MD5digest, &MD5context );
661 keys[i] = ber_bvdup( &digest );
669 /* Index generation function */
675 struct berval *prefix,
677 struct berval ***keysp )
680 struct berval **keys;
681 lutil_MD5_CTX MD5context;
682 unsigned char MD5digest[LUTIL_MD5_BYTES];
683 struct berval *value;
684 struct berval digest;
685 digest.bv_val = MD5digest;
686 digest.bv_len = sizeof(MD5digest);
688 slen = strlen( syntax->ssyn_oid );
689 mlen = strlen( mr->smr_oid );
691 value = (struct berval *) assertValue;
693 keys = ch_malloc( sizeof( struct berval * ) * 2 );
695 lutil_MD5Init( &MD5context );
696 if( prefix != NULL && prefix->bv_len > 0 ) {
697 lutil_MD5Update( &MD5context,
698 prefix->bv_val, prefix->bv_len );
700 lutil_MD5Update( &MD5context,
701 syntax->ssyn_oid, slen );
702 lutil_MD5Update( &MD5context,
704 lutil_MD5Update( &MD5context,
705 value->bv_val, value->bv_len );
706 lutil_MD5Final( MD5digest, &MD5context );
708 keys[0] = ber_bvdup( &digest );
715 /* Substrings Index generation function */
716 int caseExactSubstringsIndexer(
721 struct berval *prefix,
722 struct berval **values,
723 struct berval ***keysp )
727 struct berval **keys;
728 lutil_MD5_CTX MD5context;
729 unsigned char MD5digest[16];
730 struct berval digest;
731 digest.bv_val = MD5digest;
732 digest.bv_len = sizeof(MD5digest);
735 for( i=0; values[i] != NULL; i++ ) {
736 /* count number of indices to generate */
737 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_UMINLEN ) {
741 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
742 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) {
743 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
744 ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
746 nkeys += LEN2UNICODE(values[i]->bv_len) -
747 ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
751 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
752 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) {
753 nkeys += LEN2UNICODE(values[i]->bv_len) -
754 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
758 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
759 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) {
760 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
761 ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
763 nkeys += LEN2UNICODE(values[i]->bv_len) -
764 ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
771 /* no keys to generate */
776 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
778 slen = strlen( syntax->ssyn_oid );
779 mlen = strlen( mr->smr_oid );
782 for( i=0; values[i] != NULL; i++ ) {
784 struct berval *value;
787 if( value->bv_len < SLAP_INDEX_SUBSTR_UMINLEN ) continue;
789 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
790 ( value->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) )
792 char pre = SLAP_INDEX_SUBSTR_PREFIX;
793 max = value->bv_len -
794 ( SLAP_INDEX_SUBSTR_UMAXLEN - UNICODE2LEN(1));
796 for( j=0; j<max; j+=UNICODE2LEN(1) ) {
797 lutil_MD5Init( &MD5context );
798 if( prefix != NULL && prefix->bv_len > 0 ) {
799 lutil_MD5Update( &MD5context,
800 prefix->bv_val, prefix->bv_len );
802 lutil_MD5Update( &MD5context,
803 &pre, sizeof( pre ) );
804 lutil_MD5Update( &MD5context,
805 syntax->ssyn_oid, slen );
806 lutil_MD5Update( &MD5context,
808 lutil_MD5Update( &MD5context,
809 &value->bv_val[j], SLAP_INDEX_SUBSTR_UMAXLEN );
810 lutil_MD5Final( MD5digest, &MD5context );
812 keys[nkeys++] = ber_bvdup( &digest );
816 max = SLAP_INDEX_SUBSTR_UMAXLEN < value->bv_len
817 ? SLAP_INDEX_SUBSTR_UMAXLEN : value->bv_len;
819 for( j=SLAP_INDEX_SUBSTR_UMINLEN; j<=max; j+=UNICODE2LEN(1) ) {
822 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
823 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
824 lutil_MD5Init( &MD5context );
825 if( prefix != NULL && prefix->bv_len > 0 ) {
826 lutil_MD5Update( &MD5context,
827 prefix->bv_val, prefix->bv_len );
829 lutil_MD5Update( &MD5context,
830 &pre, sizeof( pre ) );
831 lutil_MD5Update( &MD5context,
832 syntax->ssyn_oid, slen );
833 lutil_MD5Update( &MD5context,
835 lutil_MD5Update( &MD5context,
837 lutil_MD5Final( MD5digest, &MD5context );
839 keys[nkeys++] = ber_bvdup( &digest );
842 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
843 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
844 lutil_MD5Init( &MD5context );
845 if( prefix != NULL && prefix->bv_len > 0 ) {
846 lutil_MD5Update( &MD5context,
847 prefix->bv_val, prefix->bv_len );
849 lutil_MD5Update( &MD5context,
850 &pre, sizeof( pre ) );
851 lutil_MD5Update( &MD5context,
852 syntax->ssyn_oid, slen );
853 lutil_MD5Update( &MD5context,
855 lutil_MD5Update( &MD5context,
856 &value->bv_val[value->bv_len-j], j );
857 lutil_MD5Final( MD5digest, &MD5context );
859 keys[nkeys++] = ber_bvdup( &digest );
876 int caseExactSubstringsFilter(
881 struct berval *prefix,
883 struct berval ***keysp )
885 SubstringsAssertion *sa = assertValue;
888 size_t slen, mlen, klen;
889 struct berval **keys;
890 lutil_MD5_CTX MD5context;
891 unsigned char MD5digest[LUTIL_MD5_BYTES];
892 struct berval *value;
893 struct berval digest;
895 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
896 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_UMINLEN )
901 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
903 for( i=0; sa->sa_any[i] != NULL; i++ ) {
904 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) {
905 /* don't bother accounting for stepping */
906 nkeys += LEN2UNICODE(sa->sa_any[i]->bv_len) -
907 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
912 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
913 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_UMINLEN )
923 digest.bv_val = MD5digest;
924 digest.bv_len = sizeof(MD5digest);
926 slen = strlen( syntax->ssyn_oid );
927 mlen = strlen( mr->smr_oid );
929 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
932 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
933 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_UMINLEN )
935 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
936 value = sa->sa_initial;
938 klen = SLAP_INDEX_SUBSTR_UMAXLEN < value->bv_len
939 ? SLAP_INDEX_SUBSTR_UMAXLEN : value->bv_len;
941 lutil_MD5Init( &MD5context );
942 if( prefix != NULL && prefix->bv_len > 0 ) {
943 lutil_MD5Update( &MD5context,
944 prefix->bv_val, prefix->bv_len );
946 lutil_MD5Update( &MD5context,
947 &pre, sizeof( pre ) );
948 lutil_MD5Update( &MD5context,
949 syntax->ssyn_oid, slen );
950 lutil_MD5Update( &MD5context,
952 lutil_MD5Update( &MD5context,
953 value->bv_val, klen );
954 lutil_MD5Final( MD5digest, &MD5context );
956 keys[nkeys++] = ber_bvdup( &digest );
959 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
961 pre = SLAP_INDEX_SUBSTR_PREFIX;
962 klen = SLAP_INDEX_SUBSTR_UMAXLEN;
964 for( i=0; sa->sa_any[i] != NULL; i++ ) {
965 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_UMAXLEN ) {
969 value = sa->sa_any[i];
972 j <= value->bv_len - SLAP_INDEX_SUBSTR_UMAXLEN;
973 j += SLAP_INDEX_SUBSTR_USTEP )
975 lutil_MD5Init( &MD5context );
976 if( prefix != NULL && prefix->bv_len > 0 ) {
977 lutil_MD5Update( &MD5context,
978 prefix->bv_val, prefix->bv_len );
980 lutil_MD5Update( &MD5context,
981 &pre, sizeof( pre ) );
982 lutil_MD5Update( &MD5context,
983 syntax->ssyn_oid, slen );
984 lutil_MD5Update( &MD5context,
986 lutil_MD5Update( &MD5context,
987 &value->bv_val[j], klen );
988 lutil_MD5Final( MD5digest, &MD5context );
990 keys[nkeys++] = ber_bvdup( &digest );
995 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
996 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_UMINLEN )
998 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
999 value = sa->sa_final;
1001 klen = SLAP_INDEX_SUBSTR_UMAXLEN < value->bv_len
1002 ? SLAP_INDEX_SUBSTR_UMAXLEN : value->bv_len;
1004 lutil_MD5Init( &MD5context );
1005 if( prefix != NULL && prefix->bv_len > 0 ) {
1006 lutil_MD5Update( &MD5context,
1007 prefix->bv_val, prefix->bv_len );
1009 lutil_MD5Update( &MD5context,
1010 &pre, sizeof( pre ) );
1011 lutil_MD5Update( &MD5context,
1012 syntax->ssyn_oid, slen );
1013 lutil_MD5Update( &MD5context,
1014 mr->smr_oid, mlen );
1015 lutil_MD5Update( &MD5context,
1016 &value->bv_val[value->bv_len-klen], klen );
1017 lutil_MD5Final( MD5digest, &MD5context );
1019 keys[nkeys++] = ber_bvdup( &digest );
1030 return LDAP_SUCCESS;
1039 struct berval *value,
1040 void *assertedValue )
1042 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1045 match = ucstrncasecmp(
1046 (ldap_unicode_t *) value->bv_val,
1047 (ldap_unicode_t *) ((struct berval *) assertedValue)->bv_val,
1048 LEN2UNICODE(value->bv_len) );
1052 return LDAP_SUCCESS;
1056 caseIgnoreSubstringsMatch(
1061 struct berval *value,
1062 void *assertedValue )
1065 SubstringsAssertion *sub = assertedValue;
1066 struct berval left = *value;
1070 /* Add up asserted input length */
1071 if( sub->sa_initial ) {
1072 inlen += sub->sa_initial->bv_len;
1075 for(i=0; sub->sa_any[i] != NULL; i++) {
1076 inlen += sub->sa_any[i]->bv_len;
1079 if( sub->sa_final ) {
1080 inlen += sub->sa_final->bv_len;
1083 if( sub->sa_initial ) {
1084 if( inlen > left.bv_len ) {
1089 match = ucstrncasecmp(
1090 (ldap_unicode_t *) sub->sa_initial->bv_val,
1091 (ldap_unicode_t *) left.bv_val,
1092 LEN2UNICODE(sub->sa_initial->bv_len) );
1098 left.bv_val += sub->sa_initial->bv_len;
1099 left.bv_len -= sub->sa_initial->bv_len;
1100 inlen -= sub->sa_initial->bv_len;
1103 if( sub->sa_final ) {
1104 if( inlen > left.bv_len ) {
1109 match = ucstrncasecmp(
1110 (ldap_unicode_t *) sub->sa_final->bv_val,
1111 (ldap_unicode_t *) &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1112 LEN2UNICODE(sub->sa_final->bv_len) );
1118 left.bv_len -= sub->sa_final->bv_len;
1119 inlen -= sub->sa_final->bv_len;
1123 for(i=0; sub->sa_any[i]; i++) {
1128 if( inlen > left.bv_len ) {
1129 /* not enough length */
1134 if( sub->sa_any[i]->bv_len == 0 ) {
1138 p = (char *) ucstrncasechr(
1139 (ldap_unicode_t *) left.bv_val,
1140 LEN2UNICODE(left.bv_len),
1141 ((ldap_unicode_t *) sub->sa_any[i]->bv_val)[0] );
1148 idx = p - left.bv_val;
1149 assert( idx < left.bv_len );
1151 if( idx >= left.bv_len ) {
1152 /* this shouldn't happen */
1159 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1160 /* not enough left */
1165 match = ucstrncasecmp(
1166 (ldap_unicode_t *) left.bv_val,
1167 (ldap_unicode_t *) sub->sa_any[i]->bv_val,
1168 LEN2UNICODE(sub->sa_any[i]->bv_len) );
1171 left.bv_val += UNICODE2LEN(1);
1172 left.bv_len -= UNICODE2LEN(1);
1177 left.bv_val += sub->sa_any[i]->bv_len;
1178 left.bv_len -= sub->sa_any[i]->bv_len;
1179 inlen -= sub->sa_any[i]->bv_len;
1185 return LDAP_SUCCESS;
1188 /* Index generation function */
1189 int caseIgnoreIndexer(
1194 struct berval *prefix,
1195 struct berval **values,
1196 struct berval ***keysp )
1200 struct berval **keys;
1201 lutil_MD5_CTX MD5context;
1202 unsigned char MD5digest[16];
1203 struct berval digest;
1204 digest.bv_val = MD5digest;
1205 digest.bv_len = sizeof(MD5digest);
1207 for( i=0; values[i] != NULL; i++ ) {
1208 /* just count them */
1213 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1215 slen = strlen( syntax->ssyn_oid );
1216 mlen = strlen( mr->smr_oid );
1218 for( i=0; values[i] != NULL; i++ ) {
1219 struct berval *value = ber_bvdup( values[i] );
1220 ucstr2upper( (ldap_unicode_t *) value->bv_val,
1221 LEN2UNICODE(value->bv_len) );
1223 lutil_MD5Init( &MD5context );
1224 if( prefix != NULL && prefix->bv_len > 0 ) {
1225 lutil_MD5Update( &MD5context,
1226 prefix->bv_val, prefix->bv_len );
1228 lutil_MD5Update( &MD5context,
1229 syntax->ssyn_oid, slen );
1230 lutil_MD5Update( &MD5context,
1231 mr->smr_oid, mlen );
1232 lutil_MD5Update( &MD5context,
1233 value->bv_val, value->bv_len );
1234 lutil_MD5Final( MD5digest, &MD5context );
1236 ber_bvfree( value );
1237 keys[i] = ber_bvdup( &digest );
1242 return LDAP_SUCCESS;
1245 /* Index generation function */
1246 int caseIgnoreFilter(
1251 struct berval *prefix,
1253 struct berval ***keysp )
1256 struct berval **keys;
1257 lutil_MD5_CTX MD5context;
1258 unsigned char MD5digest[LUTIL_MD5_BYTES];
1259 struct berval *value;
1260 struct berval digest;
1261 digest.bv_val = MD5digest;
1262 digest.bv_len = sizeof(MD5digest);
1264 slen = strlen( syntax->ssyn_oid );
1265 mlen = strlen( mr->smr_oid );
1267 value = ber_bvdup( (struct berval *) assertValue );
1268 ucstr2upper( (ldap_unicode_t *) value->bv_val,
1269 LEN2UNICODE(value->bv_len) );
1271 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1273 lutil_MD5Init( &MD5context );
1274 if( prefix != NULL && prefix->bv_len > 0 ) {
1275 lutil_MD5Update( &MD5context,
1276 prefix->bv_val, prefix->bv_len );
1278 lutil_MD5Update( &MD5context,
1279 syntax->ssyn_oid, slen );
1280 lutil_MD5Update( &MD5context,
1281 mr->smr_oid, mlen );
1282 lutil_MD5Update( &MD5context,
1283 value->bv_val, value->bv_len );
1284 lutil_MD5Final( MD5digest, &MD5context );
1286 keys[0] = ber_bvdup( &digest );
1289 ber_bvfree( value );
1293 return LDAP_SUCCESS;
1296 /* Substrings Index generation function */
1297 int caseIgnoreSubstringsIndexer(
1302 struct berval *prefix,
1303 struct berval **values,
1304 struct berval ***keysp )
1308 struct berval **keys;
1309 lutil_MD5_CTX MD5context;
1310 unsigned char MD5digest[16];
1311 struct berval digest;
1312 digest.bv_val = MD5digest;
1313 digest.bv_len = sizeof(MD5digest);
1316 for( i=0; values[i] != NULL; i++ ) {
1317 /* count number of indices to generate */
1318 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_UMINLEN ) {
1322 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1323 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) {
1324 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1325 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1327 nkeys += LEN2UNICODE(values[i]->bv_len) -
1328 ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1332 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
1333 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) {
1334 nkeys += LEN2UNICODE(values[i]->bv_len) -
1335 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1339 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1340 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) {
1341 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
1342 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1344 nkeys += LEN2UNICODE(values[i]->bv_len) -
1345 ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1352 /* no keys to generate */
1354 return LDAP_SUCCESS;
1357 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1359 slen = strlen( syntax->ssyn_oid );
1360 mlen = strlen( mr->smr_oid );
1363 for( i=0; values[i] != NULL; i++ ) {
1365 struct berval *value;
1367 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_UMINLEN ) continue;
1369 value = ber_bvdup( values[i] );
1370 ucstr2upper( (ldap_unicode_t *) value->bv_val,
1371 LEN2UNICODE(value->bv_len) );
1373 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
1374 ( value->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) )
1376 char pre = SLAP_INDEX_SUBSTR_PREFIX;
1377 max = value->bv_len -
1378 ( SLAP_INDEX_SUBSTR_UMAXLEN - UNICODE2LEN(1));
1380 for( j=0; j<max; j+=UNICODE2LEN(1) ) {
1381 lutil_MD5Init( &MD5context );
1382 if( prefix != NULL && prefix->bv_len > 0 ) {
1383 lutil_MD5Update( &MD5context,
1384 prefix->bv_val, prefix->bv_len );
1386 lutil_MD5Update( &MD5context,
1387 &pre, sizeof( pre ) );
1388 lutil_MD5Update( &MD5context,
1389 syntax->ssyn_oid, slen );
1390 lutil_MD5Update( &MD5context,
1391 mr->smr_oid, mlen );
1392 lutil_MD5Update( &MD5context,
1394 SLAP_INDEX_SUBSTR_UMAXLEN );
1395 lutil_MD5Final( MD5digest, &MD5context );
1397 keys[nkeys++] = ber_bvdup( &digest );
1401 max = SLAP_INDEX_SUBSTR_UMAXLEN < value->bv_len
1402 ? SLAP_INDEX_SUBSTR_UMAXLEN : value->bv_len;
1404 for( j=SLAP_INDEX_SUBSTR_UMINLEN; j<=max; j+=UNICODE2LEN(1) ) {
1407 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
1408 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1409 lutil_MD5Init( &MD5context );
1410 if( prefix != NULL && prefix->bv_len > 0 ) {
1411 lutil_MD5Update( &MD5context,
1412 prefix->bv_val, prefix->bv_len );
1414 lutil_MD5Update( &MD5context,
1415 &pre, sizeof( pre ) );
1416 lutil_MD5Update( &MD5context,
1417 syntax->ssyn_oid, slen );
1418 lutil_MD5Update( &MD5context,
1419 mr->smr_oid, mlen );
1420 lutil_MD5Update( &MD5context,
1422 lutil_MD5Final( MD5digest, &MD5context );
1424 keys[nkeys++] = ber_bvdup( &digest );
1427 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
1428 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1429 lutil_MD5Init( &MD5context );
1430 if( prefix != NULL && prefix->bv_len > 0 ) {
1431 lutil_MD5Update( &MD5context,
1432 prefix->bv_val, prefix->bv_len );
1434 lutil_MD5Update( &MD5context,
1435 &pre, sizeof( pre ) );
1436 lutil_MD5Update( &MD5context,
1437 syntax->ssyn_oid, slen );
1438 lutil_MD5Update( &MD5context,
1439 mr->smr_oid, mlen );
1440 lutil_MD5Update( &MD5context,
1441 &value->bv_val[value->bv_len-j], j );
1442 lutil_MD5Final( MD5digest, &MD5context );
1444 keys[nkeys++] = ber_bvdup( &digest );
1449 ber_bvfree( value );
1460 return LDAP_SUCCESS;
1463 int caseIgnoreSubstringsFilter(
1468 struct berval *prefix,
1470 struct berval ***keysp )
1472 SubstringsAssertion *sa = assertValue;
1474 ber_len_t nkeys = 0;
1475 size_t slen, mlen, klen;
1476 struct berval **keys;
1477 lutil_MD5_CTX MD5context;
1478 unsigned char MD5digest[LUTIL_MD5_BYTES];
1479 struct berval *value;
1480 struct berval digest;
1482 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1483 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_UMINLEN )
1488 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1490 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1491 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_UMAXLEN ) {
1492 /* don't bother accounting for stepping */
1493 nkeys += LEN2UNICODE(sa->sa_any[i]->bv_len) -
1494 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
1499 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1500 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_UMINLEN )
1507 return LDAP_SUCCESS;
1510 digest.bv_val = MD5digest;
1511 digest.bv_len = sizeof(MD5digest);
1513 slen = strlen( syntax->ssyn_oid );
1514 mlen = strlen( mr->smr_oid );
1516 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1519 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
1520 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_UMINLEN )
1522 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1523 value = ber_bvdup( sa->sa_initial );
1524 ucstr2upper( (ldap_unicode_t *) value->bv_val,
1525 LEN2UNICODE(value->bv_len) );
1527 klen = SLAP_INDEX_SUBSTR_UMAXLEN < value->bv_len
1528 ? SLAP_INDEX_SUBSTR_UMAXLEN : value->bv_len;
1530 lutil_MD5Init( &MD5context );
1531 if( prefix != NULL && prefix->bv_len > 0 ) {
1532 lutil_MD5Update( &MD5context,
1533 prefix->bv_val, prefix->bv_len );
1535 lutil_MD5Update( &MD5context,
1536 &pre, sizeof( pre ) );
1537 lutil_MD5Update( &MD5context,
1538 syntax->ssyn_oid, slen );
1539 lutil_MD5Update( &MD5context,
1540 mr->smr_oid, mlen );
1541 lutil_MD5Update( &MD5context,
1542 value->bv_val, klen );
1543 lutil_MD5Final( MD5digest, &MD5context );
1545 ber_bvfree( value );
1546 keys[nkeys++] = ber_bvdup( &digest );
1549 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
1551 pre = SLAP_INDEX_SUBSTR_PREFIX;
1552 klen = SLAP_INDEX_SUBSTR_UMAXLEN;
1554 for( i=0; sa->sa_any[i] != NULL; i++ ) {
1555 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_UMAXLEN ) {
1559 value = ber_bvdup( sa->sa_any[i] );
1560 ucstr2upper( (ldap_unicode_t *) value->bv_val,
1561 LEN2UNICODE(value->bv_len) );
1564 j <= value->bv_len - SLAP_INDEX_SUBSTR_UMAXLEN;
1565 j += SLAP_INDEX_SUBSTR_USTEP )
1567 lutil_MD5Init( &MD5context );
1568 if( prefix != NULL && prefix->bv_len > 0 ) {
1569 lutil_MD5Update( &MD5context,
1570 prefix->bv_val, prefix->bv_len );
1572 lutil_MD5Update( &MD5context,
1573 &pre, sizeof( pre ) );
1574 lutil_MD5Update( &MD5context,
1575 syntax->ssyn_oid, slen );
1576 lutil_MD5Update( &MD5context,
1577 mr->smr_oid, mlen );
1578 lutil_MD5Update( &MD5context,
1579 &value->bv_val[j], klen );
1580 lutil_MD5Final( MD5digest, &MD5context );
1582 keys[nkeys++] = ber_bvdup( &digest );
1585 ber_bvfree( value );
1589 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
1590 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_UMINLEN )
1592 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1593 value = ber_bvdup( sa->sa_final );
1594 ucstr2upper( (ldap_unicode_t *) value->bv_val,
1595 LEN2UNICODE(value->bv_len) );
1597 klen = SLAP_INDEX_SUBSTR_UMAXLEN < value->bv_len
1598 ? SLAP_INDEX_SUBSTR_UMAXLEN : value->bv_len;
1600 lutil_MD5Init( &MD5context );
1601 if( prefix != NULL && prefix->bv_len > 0 ) {
1602 lutil_MD5Update( &MD5context,
1603 prefix->bv_val, prefix->bv_len );
1605 lutil_MD5Update( &MD5context,
1606 &pre, sizeof( pre ) );
1607 lutil_MD5Update( &MD5context,
1608 syntax->ssyn_oid, slen );
1609 lutil_MD5Update( &MD5context,
1610 mr->smr_oid, mlen );
1611 lutil_MD5Update( &MD5context,
1612 &value->bv_val[value->bv_len-klen], klen );
1613 lutil_MD5Final( MD5digest, &MD5context );
1615 ber_bvfree( value );
1616 keys[nkeys++] = ber_bvdup( &digest );
1627 return LDAP_SUCCESS;
1633 struct berval *val )
1637 if( val->bv_len == 0 ) return 0;
1639 if( OID_LEADCHAR(val->bv_val[0]) ) {
1641 for(i=1; i < val->bv_len; i++) {
1642 if( OID_SEPARATOR( val->bv_val[i] ) ) {
1643 if( dot++ ) return 1;
1644 } else if ( OID_CHAR( val->bv_val[i] ) ) {
1647 return LDAP_INVALID_SYNTAX;
1651 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
1653 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
1654 for(i=1; i < val->bv_len; i++) {
1655 if( !DESC_CHAR(val->bv_val[i] ) ) {
1656 return LDAP_INVALID_SYNTAX;
1660 return LDAP_SUCCESS;
1663 return LDAP_INVALID_SYNTAX;
1669 struct berval *val )
1673 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1675 for(i=0; i < val->bv_len; i++) {
1676 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1679 return LDAP_SUCCESS;
1683 printableStringValidate(
1685 struct berval *val )
1689 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1691 for(i=0; i < val->bv_len; i++) {
1692 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1695 return LDAP_SUCCESS;
1701 struct berval *val )
1705 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
1707 for(i=0; i < val->bv_len; i++) {
1708 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
1711 return LDAP_SUCCESS;
1718 struct berval **out )
1721 ber_len_t i, len = in->bv_len;
1722 struct berval *bv = ch_malloc( sizeof(struct berval) );
1724 bv->bv_len = len * sizeof( ldap_unicode_t );
1725 u = (ldap_unicode_t *) ch_malloc( bv->bv_len + sizeof(ldap_unicode_t) );
1726 bv->bv_val = (char *) u;
1728 for(i=0; i < len; i++ ) {
1730 * IA5StringValidate should have been called to ensure
1731 * input is limited to IA5.
1733 u[i] = in->bv_val[i];
1738 return LDAP_SUCCESS;
1745 struct berval **normalized )
1747 struct berval *newval;
1750 newval = ch_malloc( sizeof( struct berval ) );
1754 /* Ignore initial whitespace */
1755 while ( ASCII_SPACE( *p ) ) {
1761 return LDAP_INVALID_SYNTAX;
1764 newval->bv_val = ch_strdup( p );
1765 p = q = newval->bv_val;
1768 if ( ASCII_SPACE( *p ) ) {
1771 /* Ignore the extra whitespace */
1772 while ( ASCII_SPACE( *p ) ) {
1780 assert( *newval->bv_val );
1781 assert( newval->bv_val < p );
1784 /* cannot start with a space */
1785 assert( !ASCII_SPACE(*newval->bv_val) );
1788 * If the string ended in space, backup the pointer one
1789 * position. One is enough because the above loop collapsed
1790 * all whitespace to a single space.
1793 if ( ASCII_SPACE( q[-1] ) ) {
1797 /* cannot end with a space */
1798 assert( !ASCII_SPACE( q[-1] ) );
1800 /* null terminate */
1803 newval->bv_len = q - newval->bv_val;
1804 *normalized = newval;
1806 return LDAP_SUCCESS;
1815 struct berval *value,
1816 void *assertedValue )
1818 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1821 match = strncmp( value->bv_val,
1822 ((struct berval *) assertedValue)->bv_val,
1827 return LDAP_SUCCESS;
1831 caseExactIA5SubstringsMatch(
1836 struct berval *value,
1837 void *assertedValue )
1840 SubstringsAssertion *sub = assertedValue;
1841 struct berval left = *value;
1845 /* Add up asserted input length */
1846 if( sub->sa_initial ) {
1847 inlen += sub->sa_initial->bv_len;
1850 for(i=0; sub->sa_any[i] != NULL; i++) {
1851 inlen += sub->sa_any[i]->bv_len;
1854 if( sub->sa_final ) {
1855 inlen += sub->sa_final->bv_len;
1858 if( sub->sa_initial ) {
1859 if( inlen > left.bv_len ) {
1864 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
1865 sub->sa_initial->bv_len );
1871 left.bv_val += sub->sa_initial->bv_len;
1872 left.bv_len -= sub->sa_initial->bv_len;
1873 inlen -= sub->sa_initial->bv_len;
1876 if( sub->sa_final ) {
1877 if( inlen > left.bv_len ) {
1882 match = strncmp( sub->sa_final->bv_val,
1883 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1884 sub->sa_final->bv_len );
1890 left.bv_len -= sub->sa_final->bv_len;
1891 inlen -= sub->sa_final->bv_len;
1895 for(i=0; sub->sa_any[i]; i++) {
1900 if( inlen > left.bv_len ) {
1901 /* not enough length */
1906 if( sub->sa_any[i]->bv_len == 0 ) {
1910 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
1917 idx = p - left.bv_val;
1918 assert( idx < left.bv_len );
1920 if( idx >= left.bv_len ) {
1921 /* this shouldn't happen */
1928 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1929 /* not enough left */
1934 match = strncmp( left.bv_val,
1935 sub->sa_any[i]->bv_val,
1936 sub->sa_any[i]->bv_len );
1944 left.bv_val += sub->sa_any[i]->bv_len;
1945 left.bv_len -= sub->sa_any[i]->bv_len;
1946 inlen -= sub->sa_any[i]->bv_len;
1952 return LDAP_SUCCESS;
1955 /* Index generation function */
1956 int caseExactIA5Indexer(
1961 struct berval *prefix,
1962 struct berval **values,
1963 struct berval ***keysp )
1967 struct berval **keys;
1968 lutil_MD5_CTX MD5context;
1969 unsigned char MD5digest[16];
1970 struct berval digest;
1971 digest.bv_val = MD5digest;
1972 digest.bv_len = sizeof(MD5digest);
1974 for( i=0; values[i] != NULL; i++ ) {
1975 /* just count them */
1980 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1982 slen = strlen( syntax->ssyn_oid );
1983 mlen = strlen( mr->smr_oid );
1985 for( i=0; values[i] != NULL; i++ ) {
1986 struct berval *value = values[i];
1988 lutil_MD5Init( &MD5context );
1989 if( prefix != NULL && prefix->bv_len > 0 ) {
1990 lutil_MD5Update( &MD5context,
1991 prefix->bv_val, prefix->bv_len );
1993 lutil_MD5Update( &MD5context,
1994 syntax->ssyn_oid, slen );
1995 lutil_MD5Update( &MD5context,
1996 mr->smr_oid, mlen );
1997 lutil_MD5Update( &MD5context,
1998 value->bv_val, value->bv_len );
1999 lutil_MD5Final( MD5digest, &MD5context );
2001 keys[i] = ber_bvdup( &digest );
2006 return LDAP_SUCCESS;
2009 /* Index generation function */
2010 int caseExactIA5Filter(
2015 struct berval *prefix,
2017 struct berval ***keysp )
2020 struct berval **keys;
2021 lutil_MD5_CTX MD5context;
2022 unsigned char MD5digest[LUTIL_MD5_BYTES];
2023 struct berval *value;
2024 struct berval digest;
2025 digest.bv_val = MD5digest;
2026 digest.bv_len = sizeof(MD5digest);
2028 slen = strlen( syntax->ssyn_oid );
2029 mlen = strlen( mr->smr_oid );
2031 value = (struct berval *) assertValue;
2033 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2035 lutil_MD5Init( &MD5context );
2036 if( prefix != NULL && prefix->bv_len > 0 ) {
2037 lutil_MD5Update( &MD5context,
2038 prefix->bv_val, prefix->bv_len );
2040 lutil_MD5Update( &MD5context,
2041 syntax->ssyn_oid, slen );
2042 lutil_MD5Update( &MD5context,
2043 mr->smr_oid, mlen );
2044 lutil_MD5Update( &MD5context,
2045 value->bv_val, value->bv_len );
2046 lutil_MD5Final( MD5digest, &MD5context );
2048 keys[0] = ber_bvdup( &digest );
2052 return LDAP_SUCCESS;
2055 /* Substrings Index generation function */
2056 int caseExactIA5SubstringsIndexer(
2061 struct berval *prefix,
2062 struct berval **values,
2063 struct berval ***keysp )
2067 struct berval **keys;
2068 lutil_MD5_CTX MD5context;
2069 unsigned char MD5digest[16];
2070 struct berval digest;
2071 digest.bv_val = MD5digest;
2072 digest.bv_len = sizeof(MD5digest);
2075 for( i=0; values[i] != NULL; i++ ) {
2076 /* count number of indices to generate */
2077 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2081 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2082 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2083 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2084 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2086 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2090 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2091 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2092 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2096 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2097 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2098 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2099 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2101 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2108 /* no keys to generate */
2110 return LDAP_SUCCESS;
2113 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2115 slen = strlen( syntax->ssyn_oid );
2116 mlen = strlen( mr->smr_oid );
2119 for( i=0; values[i] != NULL; i++ ) {
2121 struct berval *value;
2124 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2126 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2127 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2129 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2130 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2132 for( j=0; j<max; j++ ) {
2133 lutil_MD5Init( &MD5context );
2134 if( prefix != NULL && prefix->bv_len > 0 ) {
2135 lutil_MD5Update( &MD5context,
2136 prefix->bv_val, prefix->bv_len );
2138 lutil_MD5Update( &MD5context,
2139 &pre, sizeof( pre ) );
2140 lutil_MD5Update( &MD5context,
2141 syntax->ssyn_oid, slen );
2142 lutil_MD5Update( &MD5context,
2143 mr->smr_oid, mlen );
2144 lutil_MD5Update( &MD5context,
2146 SLAP_INDEX_SUBSTR_MAXLEN );
2147 lutil_MD5Final( MD5digest, &MD5context );
2149 keys[nkeys++] = ber_bvdup( &digest );
2153 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2154 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2156 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2159 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2160 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2161 lutil_MD5Init( &MD5context );
2162 if( prefix != NULL && prefix->bv_len > 0 ) {
2163 lutil_MD5Update( &MD5context,
2164 prefix->bv_val, prefix->bv_len );
2166 lutil_MD5Update( &MD5context,
2167 &pre, sizeof( pre ) );
2168 lutil_MD5Update( &MD5context,
2169 syntax->ssyn_oid, slen );
2170 lutil_MD5Update( &MD5context,
2171 mr->smr_oid, mlen );
2172 lutil_MD5Update( &MD5context,
2174 lutil_MD5Final( MD5digest, &MD5context );
2176 keys[nkeys++] = ber_bvdup( &digest );
2179 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2180 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2181 lutil_MD5Init( &MD5context );
2182 if( prefix != NULL && prefix->bv_len > 0 ) {
2183 lutil_MD5Update( &MD5context,
2184 prefix->bv_val, prefix->bv_len );
2186 lutil_MD5Update( &MD5context,
2187 &pre, sizeof( pre ) );
2188 lutil_MD5Update( &MD5context,
2189 syntax->ssyn_oid, slen );
2190 lutil_MD5Update( &MD5context,
2191 mr->smr_oid, mlen );
2192 lutil_MD5Update( &MD5context,
2193 &value->bv_val[value->bv_len-j], j );
2194 lutil_MD5Final( MD5digest, &MD5context );
2196 keys[nkeys++] = ber_bvdup( &digest );
2210 return LDAP_SUCCESS;
2213 int caseExactIA5SubstringsFilter(
2218 struct berval *prefix,
2220 struct berval ***keysp )
2222 SubstringsAssertion *sa = assertValue;
2224 ber_len_t nkeys = 0;
2225 size_t slen, mlen, klen;
2226 struct berval **keys;
2227 lutil_MD5_CTX MD5context;
2228 unsigned char MD5digest[LUTIL_MD5_BYTES];
2229 struct berval *value;
2230 struct berval digest;
2232 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2233 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2238 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2240 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2241 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2242 /* don't bother accounting for stepping */
2243 nkeys += sa->sa_any[i]->bv_len -
2244 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2249 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2250 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2257 return LDAP_SUCCESS;
2260 digest.bv_val = MD5digest;
2261 digest.bv_len = sizeof(MD5digest);
2263 slen = strlen( syntax->ssyn_oid );
2264 mlen = strlen( mr->smr_oid );
2266 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2269 if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
2270 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2272 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2273 value = sa->sa_initial;
2275 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2276 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2278 lutil_MD5Init( &MD5context );
2279 if( prefix != NULL && prefix->bv_len > 0 ) {
2280 lutil_MD5Update( &MD5context,
2281 prefix->bv_val, prefix->bv_len );
2283 lutil_MD5Update( &MD5context,
2284 &pre, sizeof( pre ) );
2285 lutil_MD5Update( &MD5context,
2286 syntax->ssyn_oid, slen );
2287 lutil_MD5Update( &MD5context,
2288 mr->smr_oid, mlen );
2289 lutil_MD5Update( &MD5context,
2290 value->bv_val, klen );
2291 lutil_MD5Final( MD5digest, &MD5context );
2293 keys[nkeys++] = ber_bvdup( &digest );
2296 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
2298 pre = SLAP_INDEX_SUBSTR_PREFIX;
2299 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2301 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2302 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2306 value = sa->sa_any[i];
2309 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2310 j += SLAP_INDEX_SUBSTR_STEP )
2312 lutil_MD5Init( &MD5context );
2313 if( prefix != NULL && prefix->bv_len > 0 ) {
2314 lutil_MD5Update( &MD5context,
2315 prefix->bv_val, prefix->bv_len );
2317 lutil_MD5Update( &MD5context,
2318 &pre, sizeof( pre ) );
2319 lutil_MD5Update( &MD5context,
2320 syntax->ssyn_oid, slen );
2321 lutil_MD5Update( &MD5context,
2322 mr->smr_oid, mlen );
2323 lutil_MD5Update( &MD5context,
2324 &value->bv_val[j], klen );
2325 lutil_MD5Final( MD5digest, &MD5context );
2327 keys[nkeys++] = ber_bvdup( &digest );
2332 if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
2333 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2335 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2336 value = sa->sa_final;
2338 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2339 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2341 lutil_MD5Init( &MD5context );
2342 if( prefix != NULL && prefix->bv_len > 0 ) {
2343 lutil_MD5Update( &MD5context,
2344 prefix->bv_val, prefix->bv_len );
2346 lutil_MD5Update( &MD5context,
2347 &pre, sizeof( pre ) );
2348 lutil_MD5Update( &MD5context,
2349 syntax->ssyn_oid, slen );
2350 lutil_MD5Update( &MD5context,
2351 mr->smr_oid, mlen );
2352 lutil_MD5Update( &MD5context,
2353 &value->bv_val[value->bv_len-klen], klen );
2354 lutil_MD5Final( MD5digest, &MD5context );
2356 keys[nkeys++] = ber_bvdup( &digest );
2367 return LDAP_SUCCESS;
2376 struct berval *value,
2377 void *assertedValue )
2379 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
2382 match = strncasecmp( value->bv_val,
2383 ((struct berval *) assertedValue)->bv_val,
2388 return LDAP_SUCCESS;
2392 caseIgnoreIA5SubstringsMatch(
2397 struct berval *value,
2398 void *assertedValue )
2401 SubstringsAssertion *sub = assertedValue;
2402 struct berval left = *value;
2406 /* Add up asserted input length */
2407 if( sub->sa_initial ) {
2408 inlen += sub->sa_initial->bv_len;
2411 for(i=0; sub->sa_any[i] != NULL; i++) {
2412 inlen += sub->sa_any[i]->bv_len;
2415 if( sub->sa_final ) {
2416 inlen += sub->sa_final->bv_len;
2419 if( sub->sa_initial ) {
2420 if( inlen > left.bv_len ) {
2425 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
2426 sub->sa_initial->bv_len );
2432 left.bv_val += sub->sa_initial->bv_len;
2433 left.bv_len -= sub->sa_initial->bv_len;
2434 inlen -= sub->sa_initial->bv_len;
2437 if( sub->sa_final ) {
2438 if( inlen > left.bv_len ) {
2443 match = strncasecmp( sub->sa_final->bv_val,
2444 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
2445 sub->sa_final->bv_len );
2451 left.bv_len -= sub->sa_final->bv_len;
2452 inlen -= sub->sa_final->bv_len;
2456 for(i=0; sub->sa_any[i]; i++) {
2461 if( inlen > left.bv_len ) {
2462 /* not enough length */
2467 if( sub->sa_any[i]->bv_len == 0 ) {
2471 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
2478 idx = p - left.bv_val;
2479 assert( idx < left.bv_len );
2481 if( idx >= left.bv_len ) {
2482 /* this shouldn't happen */
2489 if( sub->sa_any[i]->bv_len > left.bv_len ) {
2490 /* not enough left */
2495 match = strncasecmp( left.bv_val,
2496 sub->sa_any[i]->bv_val,
2497 sub->sa_any[i]->bv_len );
2506 left.bv_val += sub->sa_any[i]->bv_len;
2507 left.bv_len -= sub->sa_any[i]->bv_len;
2508 inlen -= sub->sa_any[i]->bv_len;
2514 return LDAP_SUCCESS;
2517 /* Index generation function */
2518 int caseIgnoreIA5Indexer(
2523 struct berval *prefix,
2524 struct berval **values,
2525 struct berval ***keysp )
2529 struct berval **keys;
2530 lutil_MD5_CTX MD5context;
2531 unsigned char MD5digest[16];
2532 struct berval digest;
2533 digest.bv_val = MD5digest;
2534 digest.bv_len = sizeof(MD5digest);
2536 for( i=0; values[i] != NULL; i++ ) {
2537 /* just count them */
2542 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
2544 slen = strlen( syntax->ssyn_oid );
2545 mlen = strlen( mr->smr_oid );
2547 for( i=0; values[i] != NULL; i++ ) {
2548 struct berval *value = ber_bvdup( values[i] );
2549 ldap_pvt_str2upper( value->bv_val );
2551 lutil_MD5Init( &MD5context );
2552 if( prefix != NULL && prefix->bv_len > 0 ) {
2553 lutil_MD5Update( &MD5context,
2554 prefix->bv_val, prefix->bv_len );
2556 lutil_MD5Update( &MD5context,
2557 syntax->ssyn_oid, slen );
2558 lutil_MD5Update( &MD5context,
2559 mr->smr_oid, mlen );
2560 lutil_MD5Update( &MD5context,
2561 value->bv_val, value->bv_len );
2562 lutil_MD5Final( MD5digest, &MD5context );
2564 ber_bvfree( value );
2566 keys[i] = ber_bvdup( &digest );
2571 return LDAP_SUCCESS;
2574 /* Index generation function */
2575 int caseIgnoreIA5Filter(
2580 struct berval *prefix,
2582 struct berval ***keysp )
2585 struct berval **keys;
2586 lutil_MD5_CTX MD5context;
2587 unsigned char MD5digest[LUTIL_MD5_BYTES];
2588 struct berval *value;
2589 struct berval digest;
2590 digest.bv_val = MD5digest;
2591 digest.bv_len = sizeof(MD5digest);
2593 slen = strlen( syntax->ssyn_oid );
2594 mlen = strlen( mr->smr_oid );
2596 value = ber_bvdup( (struct berval *) assertValue );
2597 ldap_pvt_str2upper( value->bv_val );
2599 keys = ch_malloc( sizeof( struct berval * ) * 2 );
2601 lutil_MD5Init( &MD5context );
2602 if( prefix != NULL && prefix->bv_len > 0 ) {
2603 lutil_MD5Update( &MD5context,
2604 prefix->bv_val, prefix->bv_len );
2606 lutil_MD5Update( &MD5context,
2607 syntax->ssyn_oid, slen );
2608 lutil_MD5Update( &MD5context,
2609 mr->smr_oid, mlen );
2610 lutil_MD5Update( &MD5context,
2611 value->bv_val, value->bv_len );
2612 lutil_MD5Final( MD5digest, &MD5context );
2614 keys[0] = ber_bvdup( &digest );
2617 ber_bvfree( value );
2621 return LDAP_SUCCESS;
2624 /* Substrings Index generation function */
2625 int caseIgnoreIA5SubstringsIndexer(
2630 struct berval *prefix,
2631 struct berval **values,
2632 struct berval ***keysp )
2636 struct berval **keys;
2637 lutil_MD5_CTX MD5context;
2638 unsigned char MD5digest[16];
2639 struct berval digest;
2640 digest.bv_val = MD5digest;
2641 digest.bv_len = sizeof(MD5digest);
2644 for( i=0; values[i] != NULL; i++ ) {
2645 /* count number of indices to generate */
2646 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
2650 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2651 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2652 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2653 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2655 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2659 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
2660 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2661 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2665 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2666 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2667 nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
2668 ( SLAP_INDEX_SUBSTR_MINLEN - 1);
2670 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
2677 /* no keys to generate */
2679 return LDAP_SUCCESS;
2682 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2684 slen = strlen( syntax->ssyn_oid );
2685 mlen = strlen( mr->smr_oid );
2688 for( i=0; values[i] != NULL; i++ ) {
2690 struct berval *value;
2692 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
2694 value = ber_bvdup( values[i] );
2695 ldap_pvt_str2upper( value->bv_val );
2697 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
2698 ( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
2700 char pre = SLAP_INDEX_SUBSTR_PREFIX;
2701 max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
2703 for( j=0; j<max; j++ ) {
2704 lutil_MD5Init( &MD5context );
2705 if( prefix != NULL && prefix->bv_len > 0 ) {
2706 lutil_MD5Update( &MD5context,
2707 prefix->bv_val, prefix->bv_len );
2709 lutil_MD5Update( &MD5context,
2710 &pre, sizeof( pre ) );
2711 lutil_MD5Update( &MD5context,
2712 syntax->ssyn_oid, slen );
2713 lutil_MD5Update( &MD5context,
2714 mr->smr_oid, mlen );
2715 lutil_MD5Update( &MD5context,
2717 SLAP_INDEX_SUBSTR_MAXLEN );
2718 lutil_MD5Final( MD5digest, &MD5context );
2720 keys[nkeys++] = ber_bvdup( &digest );
2724 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2725 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2727 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
2730 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
2731 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2732 lutil_MD5Init( &MD5context );
2733 if( prefix != NULL && prefix->bv_len > 0 ) {
2734 lutil_MD5Update( &MD5context,
2735 prefix->bv_val, prefix->bv_len );
2737 lutil_MD5Update( &MD5context,
2738 &pre, sizeof( pre ) );
2739 lutil_MD5Update( &MD5context,
2740 syntax->ssyn_oid, slen );
2741 lutil_MD5Update( &MD5context,
2742 mr->smr_oid, mlen );
2743 lutil_MD5Update( &MD5context,
2745 lutil_MD5Final( MD5digest, &MD5context );
2747 keys[nkeys++] = ber_bvdup( &digest );
2750 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
2751 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2752 lutil_MD5Init( &MD5context );
2753 if( prefix != NULL && prefix->bv_len > 0 ) {
2754 lutil_MD5Update( &MD5context,
2755 prefix->bv_val, prefix->bv_len );
2757 lutil_MD5Update( &MD5context,
2758 &pre, sizeof( pre ) );
2759 lutil_MD5Update( &MD5context,
2760 syntax->ssyn_oid, slen );
2761 lutil_MD5Update( &MD5context,
2762 mr->smr_oid, mlen );
2763 lutil_MD5Update( &MD5context,
2764 &value->bv_val[value->bv_len-j], j );
2765 lutil_MD5Final( MD5digest, &MD5context );
2767 keys[nkeys++] = ber_bvdup( &digest );
2772 ber_bvfree( value );
2783 return LDAP_SUCCESS;
2786 int caseIgnoreIA5SubstringsFilter(
2791 struct berval *prefix,
2793 struct berval ***keysp )
2795 SubstringsAssertion *sa = assertValue;
2797 ber_len_t nkeys = 0;
2798 size_t slen, mlen, klen;
2799 struct berval **keys;
2800 lutil_MD5_CTX MD5context;
2801 unsigned char MD5digest[LUTIL_MD5_BYTES];
2802 struct berval *value;
2803 struct berval digest;
2805 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2806 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2811 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2813 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2814 if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
2815 /* don't bother accounting for stepping */
2816 nkeys += sa->sa_any[i]->bv_len -
2817 ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
2822 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2823 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2830 return LDAP_SUCCESS;
2833 digest.bv_val = MD5digest;
2834 digest.bv_len = sizeof(MD5digest);
2836 slen = strlen( syntax->ssyn_oid );
2837 mlen = strlen( mr->smr_oid );
2839 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
2842 if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
2843 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2845 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
2846 value = ber_bvdup( sa->sa_initial );
2847 ldap_pvt_str2upper( value->bv_val );
2849 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2850 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2852 lutil_MD5Init( &MD5context );
2853 if( prefix != NULL && prefix->bv_len > 0 ) {
2854 lutil_MD5Update( &MD5context,
2855 prefix->bv_val, prefix->bv_len );
2857 lutil_MD5Update( &MD5context,
2858 &pre, sizeof( pre ) );
2859 lutil_MD5Update( &MD5context,
2860 syntax->ssyn_oid, slen );
2861 lutil_MD5Update( &MD5context,
2862 mr->smr_oid, mlen );
2863 lutil_MD5Update( &MD5context,
2864 value->bv_val, klen );
2865 lutil_MD5Final( MD5digest, &MD5context );
2867 ber_bvfree( value );
2868 keys[nkeys++] = ber_bvdup( &digest );
2871 if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
2873 pre = SLAP_INDEX_SUBSTR_PREFIX;
2874 klen = SLAP_INDEX_SUBSTR_MAXLEN;
2876 for( i=0; sa->sa_any[i] != NULL; i++ ) {
2877 if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
2881 value = ber_bvdup( sa->sa_any[i] );
2882 ldap_pvt_str2upper( value->bv_val );
2885 j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
2886 j += SLAP_INDEX_SUBSTR_STEP )
2888 lutil_MD5Init( &MD5context );
2889 if( prefix != NULL && prefix->bv_len > 0 ) {
2890 lutil_MD5Update( &MD5context,
2891 prefix->bv_val, prefix->bv_len );
2893 lutil_MD5Update( &MD5context,
2894 &pre, sizeof( pre ) );
2895 lutil_MD5Update( &MD5context,
2896 syntax->ssyn_oid, slen );
2897 lutil_MD5Update( &MD5context,
2898 mr->smr_oid, mlen );
2899 lutil_MD5Update( &MD5context,
2900 &value->bv_val[j], klen );
2901 lutil_MD5Final( MD5digest, &MD5context );
2903 keys[nkeys++] = ber_bvdup( &digest );
2906 ber_bvfree( value );
2910 if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
2911 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
2913 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
2914 value = ber_bvdup( sa->sa_final );
2915 ldap_pvt_str2upper( value->bv_val );
2917 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
2918 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
2920 lutil_MD5Init( &MD5context );
2921 if( prefix != NULL && prefix->bv_len > 0 ) {
2922 lutil_MD5Update( &MD5context,
2923 prefix->bv_val, prefix->bv_len );
2925 lutil_MD5Update( &MD5context,
2926 &pre, sizeof( pre ) );
2927 lutil_MD5Update( &MD5context,
2928 syntax->ssyn_oid, slen );
2929 lutil_MD5Update( &MD5context,
2930 mr->smr_oid, mlen );
2931 lutil_MD5Update( &MD5context,
2932 &value->bv_val[value->bv_len-klen], klen );
2933 lutil_MD5Final( MD5digest, &MD5context );
2935 ber_bvfree( value );
2936 keys[nkeys++] = ber_bvdup( &digest );
2947 return LDAP_SUCCESS;
2951 numericStringNormalize(
2954 struct berval **normalized )
2956 /* similiar to IA5StringNormalize except removes all spaces */
2957 struct berval *newval;
2960 newval = ch_malloc( sizeof( struct berval ) );
2964 /* Ignore initial whitespace */
2965 while ( ASCII_SPACE( *p ) ) {
2971 return LDAP_INVALID_SYNTAX;
2974 newval->bv_val = ch_strdup( p );
2975 p = q = newval->bv_val;
2978 if ( ASCII_SPACE( *p ) ) {
2979 /* Ignore whitespace */
2986 assert( *newval->bv_val );
2987 assert( newval->bv_val < p );
2990 /* cannot start with a space */
2991 assert( !ASCII_SPACE(*newval->bv_val) );
2993 /* cannot end with a space */
2994 assert( !ASCII_SPACE( q[-1] ) );
2996 /* null terminate */
2999 newval->bv_len = q - newval->bv_val;
3000 *normalized = newval;
3002 return LDAP_SUCCESS;
3006 objectIdentifierFirstComponentMatch(
3011 struct berval *value,
3012 void *assertedValue )
3014 int rc = LDAP_SUCCESS;
3016 struct berval *asserted = (struct berval *) assertedValue;
3020 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
3021 return LDAP_INVALID_SYNTAX;
3024 /* trim leading white space */
3025 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
3029 /* grab next word */
3030 oid.bv_val = &value->bv_val[i];
3031 oid.bv_len = value->bv_len - i;
3032 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
3037 /* insert attributeTypes, objectclass check here */
3038 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
3039 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
3042 char *stored = ch_malloc( oid.bv_len + 1 );
3043 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
3044 stored[oid.bv_len] = '\0';
3046 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
3047 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
3048 MatchingRule *stored_mr = mr_find( stored );
3050 if( asserted_mr == NULL ) {
3051 rc = SLAPD_COMPARE_UNDEFINED;
3053 match = asserted_mr != stored_mr;
3056 } else if ( !strcmp( syntax->ssyn_oid,
3057 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
3059 AttributeType *asserted_at = at_find( asserted->bv_val );
3060 AttributeType *stored_at = at_find( stored );
3062 if( asserted_at == NULL ) {
3063 rc = SLAPD_COMPARE_UNDEFINED;
3065 match = asserted_at != stored_at;
3068 } else if ( !strcmp( syntax->ssyn_oid,
3069 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
3071 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
3072 ObjectClass *stored_oc = oc_find( stored );
3074 if( asserted_oc == NULL ) {
3075 rc = SLAPD_COMPARE_UNDEFINED;
3077 match = asserted_oc != stored_oc;
3084 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
3085 "%d\n\t\"%s\"\n\t\"%s\"\n",
3086 match, value->bv_val, asserted->bv_val );
3088 if( rc == LDAP_SUCCESS ) *matchp = match;
3093 check_time_syntax (struct berval *val,
3097 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
3098 static int mdays[2][12] = {
3099 /* non-leap years */
3100 { 30, 27, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 },
3102 { 30, 28, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30 }
3105 int part, c, tzoffset, leapyear = 0 ;
3107 if( val->bv_len == 0 ) {
3108 return LDAP_INVALID_SYNTAX;
3111 p = (char *)val->bv_val;
3112 e = p + val->bv_len;
3114 /* Ignore initial whitespace */
3115 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3119 if (e - p < 13 - (2 * start)) {
3120 return LDAP_INVALID_SYNTAX;
3123 for (part = 0; part < 9; part++) {
3127 for (part = start; part < 7; part++) {
3129 if ((part == 6) && (c == 'Z' || c == '+' || c == '-')) {
3136 return LDAP_INVALID_SYNTAX;
3138 if (c < 0 || c > 9) {
3139 return LDAP_INVALID_SYNTAX;
3145 return LDAP_INVALID_SYNTAX;
3147 if (c < 0 || c > 9) {
3148 return LDAP_INVALID_SYNTAX;
3153 if (part == 2 || part == 3) {
3156 if (parts[part] < 0) {
3157 return LDAP_INVALID_SYNTAX;
3159 if (parts[part] > ceiling[part]) {
3160 return LDAP_INVALID_SYNTAX;
3164 /* leapyear check for the Gregorian calendar (year>1581) */
3165 if (((parts[1] % 4 == 0) && (parts[1] != 0)) ||
3166 ((parts[0] % 4 == 0) && (parts[1] == 0)))
3171 if (parts[3] > mdays[leapyear][parts[2]]) {
3172 return LDAP_INVALID_SYNTAX;
3177 tzoffset = 0; /* UTC */
3178 } else if (c != '+' && c != '-') {
3179 return LDAP_INVALID_SYNTAX;
3183 } else /* c == '+' */ {
3188 return LDAP_INVALID_SYNTAX;
3191 for (part = 7; part < 9; part++) {
3193 if (c < 0 || c > 9) {
3194 return LDAP_INVALID_SYNTAX;
3199 if (c < 0 || c > 9) {
3200 return LDAP_INVALID_SYNTAX;
3204 if (parts[part] < 0 || parts[part] > ceiling[part]) {
3205 return LDAP_INVALID_SYNTAX;
3210 /* Ignore trailing whitespace */
3211 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3215 return LDAP_INVALID_SYNTAX;
3218 switch ( tzoffset ) {
3219 case -1: /* negativ offset to UTC, ie west of Greenwich */
3220 parts[4] += parts[7];
3221 parts[5] += parts[8];
3222 for (part = 6; --part > 0; ) { /* offset is just hhmm, no seconds */
3226 c = mdays[leapyear][parts[2]];
3228 if (parts[part] > c) {
3229 parts[part] -= c + 1;
3234 case 1: /* positive offset to UTC, ie east of Greenwich */
3235 parts[4] -= parts[7];
3236 parts[5] -= parts[8];
3237 for (part = 6; --part > 0; ) {
3241 /* first arg to % needs to be non negativ */
3242 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3244 if (parts[part] < 0) {
3245 parts[part] += c + 1;
3250 case 0: /* already UTC */
3254 return LDAP_SUCCESS;
3261 struct berval **normalized )
3266 rc = check_time_syntax(val, 1, parts);
3267 if (rc != LDAP_SUCCESS) {
3272 out = ch_malloc( sizeof(struct berval) );
3274 return LBER_ERROR_MEMORY;
3277 out->bv_val = ch_malloc( 14 );
3278 if ( out->bv_val == NULL ) {
3280 return LBER_ERROR_MEMORY;
3283 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
3284 parts[1], parts[2] + 1, parts[3] + 1,
3285 parts[4], parts[5], parts[6] );
3289 return LDAP_SUCCESS;
3299 return check_time_syntax(in, 1, parts);
3303 generalizedTimeValidate(
3309 return check_time_syntax(in, 0, parts);
3313 generalizedTimeNormalize(
3316 struct berval **normalized )
3321 rc = check_time_syntax(val, 0, parts);
3322 if (rc != LDAP_SUCCESS) {
3327 out = ch_malloc( sizeof(struct berval) );
3329 return LBER_ERROR_MEMORY;
3332 out->bv_val = ch_malloc( 16 );
3333 if ( out->bv_val == NULL ) {
3335 return LBER_ERROR_MEMORY;
3338 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
3339 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3340 parts[4], parts[5], parts[6] );
3344 return LDAP_SUCCESS;
3348 nisNetgroupTripleValidate(
3350 struct berval *val )
3355 if ( val->bv_len == 0 ) {
3356 return LDAP_INVALID_SYNTAX;
3359 p = (char *)val->bv_val;
3360 e = p + val->bv_len;
3363 /* syntax does not allow leading white space */
3364 /* Ignore initial whitespace */
3365 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3370 if ( *p != '(' /*')'*/ ) {
3371 return LDAP_INVALID_SYNTAX;
3374 for ( p++; ( p < e ) && ( *p != ')' ); p++ ) {
3378 return LDAP_INVALID_SYNTAX;
3381 } else if ( !ATTR_CHAR( *p ) ) {
3382 return LDAP_INVALID_SYNTAX;
3386 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
3387 return LDAP_INVALID_SYNTAX;
3393 /* syntax does not allow trailing white space */
3394 /* Ignore trailing whitespace */
3395 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
3401 return LDAP_INVALID_SYNTAX;
3404 return LDAP_SUCCESS;
3408 bootParameterValidate(
3410 struct berval *val )
3414 if ( val->bv_len == 0 ) {
3415 return LDAP_INVALID_SYNTAX;
3418 p = (char *)val->bv_val;
3419 e = p + val->bv_len;
3422 for (; ( p < e ) && ( *p != '=' ); p++ ) {
3423 if ( !ATTR_CHAR( *p ) ) {
3424 return LDAP_INVALID_SYNTAX;
3429 return LDAP_INVALID_SYNTAX;
3433 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
3434 if ( !ATTR_CHAR( *p ) ) {
3435 return LDAP_INVALID_SYNTAX;
3440 return LDAP_INVALID_SYNTAX;
3444 for ( p++; p < e; p++ ) {
3445 if ( !ATTR_CHAR( *p ) ) {
3446 return LDAP_INVALID_SYNTAX;
3450 return LDAP_SUCCESS;
3453 struct syntax_defs_rec {
3456 slap_syntax_validate_func *sd_validate;
3457 slap_syntax_transform_func *sd_normalize;
3458 slap_syntax_transform_func *sd_pretty;
3459 #ifdef SLAPD_BINARY_CONVERSION
3460 slap_syntax_transform_func *sd_ber2str;
3461 slap_syntax_transform_func *sd_str2ber;
3465 #define X_HIDE "X-HIDE 'TRUE' "
3466 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
3467 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
3469 struct syntax_defs_rec syntax_defs[] = {
3470 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
3471 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
3472 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
3473 0, NULL, NULL, NULL},
3474 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
3475 0, NULL, NULL, NULL},
3476 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
3477 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3478 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
3479 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3480 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
3481 0, bitStringValidate, bitStringNormalize, NULL },
3482 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
3483 0, booleanValidate, NULL, NULL},
3484 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
3485 X_BINARY X_NOT_H_R ")",
3486 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3487 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
3488 X_BINARY X_NOT_H_R ")",
3489 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3490 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
3491 X_BINARY X_NOT_H_R ")",
3492 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3493 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
3494 0, NULL, NULL, NULL},
3495 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
3496 0, dnValidate, dnNormalize, dnPretty},
3497 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
3498 0, NULL, NULL, NULL},
3499 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
3500 0, NULL, NULL, NULL},
3501 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
3502 0, UTF8StringValidate, UTF8StringNormalize, NULL},
3503 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
3504 0, NULL, NULL, NULL},
3505 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
3506 0, NULL, NULL, NULL},
3507 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
3508 0, NULL, NULL, NULL},
3509 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
3510 0, NULL, NULL, NULL},
3511 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
3512 0, NULL, NULL, NULL},
3513 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
3514 0, IA5StringValidate, faxNumberNormalize, NULL},
3515 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
3516 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
3517 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
3518 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
3519 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
3520 0, NULL, NULL, NULL},
3521 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
3522 0, IA5StringValidate, IA5StringNormalize, NULL},
3523 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
3524 0, integerValidate, integerNormalize, integerPretty},
3525 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
3526 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
3527 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
3528 0, NULL, NULL, NULL},
3529 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
3530 0, NULL, NULL, NULL},
3531 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
3532 0, NULL, NULL, NULL},
3533 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
3534 0, NULL, NULL, NULL},
3535 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
3536 0, NULL, NULL, NULL},
3537 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
3538 0, nameUIDValidate, nameUIDNormalize, nameUIDPretty},
3539 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
3540 0, NULL, NULL, NULL},
3541 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
3542 0, IA5StringValidate, numericStringNormalize, NULL},
3543 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
3544 0, NULL, NULL, NULL},
3545 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
3546 0, oidValidate, NULL, NULL},
3547 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
3548 0, NULL, NULL, NULL},
3549 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
3550 0, blobValidate, NULL, NULL},
3551 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
3552 0, blobValidate, NULL, NULL},
3553 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
3554 0, NULL, NULL, NULL},
3555 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
3556 0, NULL, NULL, NULL},
3557 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
3558 0, printableStringValidate, NULL, NULL},
3559 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
3560 X_BINARY X_NOT_H_R ")",
3561 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
3562 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
3563 0, IA5StringValidate, phoneNumberNormalize, NULL},
3564 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
3565 0, NULL, NULL, NULL},
3566 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
3567 0, IA5StringValidate, telexNumberNormalize, NULL},
3568 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
3569 0, utcTimeValidate, utcTimeNormalize, NULL},
3570 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
3571 0, NULL, NULL, NULL},
3572 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
3573 0, NULL, NULL, NULL},
3574 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
3575 0, NULL, NULL, NULL},
3576 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
3577 0, NULL, NULL, NULL},
3578 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
3579 0, NULL, NULL, NULL},
3581 /* RFC 2307 NIS Syntaxes */
3582 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Triple' )",
3583 0, nisNetgroupTripleValidate, NULL, NULL},
3584 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
3585 0, bootParameterValidate, NULL, NULL},
3587 /* OpenLDAP Experimental Syntaxes */
3588 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
3589 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */,
3591 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
3592 0, NULL, NULL, NULL},
3594 /* OpenLDAP Void Syntax */
3595 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' " X_HIDE ")" ,
3596 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
3597 {NULL, 0, NULL, NULL, NULL}
3600 struct mrule_defs_rec {
3602 slap_mask_t mrd_usage;
3603 slap_mr_convert_func * mrd_convert;
3604 slap_mr_normalize_func * mrd_normalize;
3605 slap_mr_match_func * mrd_match;
3606 slap_mr_indexer_func * mrd_indexer;
3607 slap_mr_filter_func * mrd_filter;
3609 char * mrd_associated;
3613 * Other matching rules in X.520 that we do not use (yet):
3615 * 2.5.13.9 numericStringOrderingMatch
3616 * 2.5.13.13 booleanMatch
3617 * 2.5.13.15 integerOrderingMatch
3618 * 2.5.13.18 octetStringOrderingMatch
3619 * 2.5.13.19 octetStringSubstringsMatch
3620 * 2.5.13.25 uTCTimeMatch
3621 * 2.5.13.26 uTCTimeOrderingMatch
3622 * 2.5.13.31 directoryStringFirstComponentMatch
3623 * 2.5.13.32 wordMatch
3624 * 2.5.13.33 keywordMatch
3625 * 2.5.13.34 certificateExactMatch
3626 * 2.5.13.35 certificateMatch
3627 * 2.5.13.36 certificatePairExactMatch
3628 * 2.5.13.37 certificatePairMatch
3629 * 2.5.13.38 certificateListExactMatch
3630 * 2.5.13.39 certificateListMatch
3631 * 2.5.13.40 algorithmIdentifierMatch
3632 * 2.5.13.41 storedPrefixMatch
3633 * 2.5.13.42 attributeCertificateMatch
3634 * 2.5.13.43 readerAndKeyIDMatch
3635 * 2.5.13.44 attributeIntegrityMatch
3638 struct mrule_defs_rec mrule_defs[] = {
3640 * EQUALITY matching rules must be listed after associated APPROX
3641 * matching rules. So, we list all APPROX matching rules first.
3643 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
3644 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3645 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3647 directoryStringApproxMatch, NULL, NULL,
3650 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
3651 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3652 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
3654 IA5StringApproxMatch, NULL, NULL,
3658 * Other matching rules
3661 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
3662 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3663 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3665 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
3668 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
3669 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
3670 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3672 dnMatch, dnIndexer, dnFilter,
3675 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
3676 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3677 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3679 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
3680 directoryStringApproxMatchOID },
3682 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
3683 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3686 caseIgnoreOrderingMatch, NULL, NULL,
3689 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
3690 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3691 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3693 caseIgnoreSubstringsMatch,
3694 caseIgnoreSubstringsIndexer,
3695 caseIgnoreSubstringsFilter,
3698 {"( 2.5.13.5 NAME 'caseExactMatch' "
3699 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3700 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3702 caseExactMatch, caseExactIndexer, caseExactFilter,
3703 directoryStringApproxMatchOID },
3705 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
3706 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
3709 caseExactOrderingMatch, NULL, NULL,
3712 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
3713 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3714 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3716 caseExactSubstringsMatch,
3717 caseExactSubstringsIndexer,
3718 caseExactSubstringsFilter,
3721 {"( 2.5.13.8 NAME 'numericStringMatch' "
3722 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
3723 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3725 caseIgnoreIA5Match, NULL, NULL,
3728 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
3729 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3730 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3732 caseIgnoreIA5SubstringsMatch,
3733 caseIgnoreIA5SubstringsIndexer,
3734 caseIgnoreIA5SubstringsFilter,
3737 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
3738 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
3739 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3741 caseIgnoreListMatch, NULL, NULL,
3744 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
3745 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3746 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3748 caseIgnoreListSubstringsMatch, NULL, NULL,
3751 {"( 2.5.13.13 NAME 'booleanMatch' "
3752 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
3753 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3755 booleanMatch, NULL, NULL,
3758 {"( 2.5.13.14 NAME 'integerMatch' "
3759 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
3760 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3762 integerMatch, NULL, NULL,
3765 {"( 2.5.13.16 NAME 'bitStringMatch' "
3766 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
3767 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3769 bitStringMatch, NULL, NULL,
3772 {"( 2.5.13.17 NAME 'octetStringMatch' "
3773 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
3774 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3776 octetStringMatch, octetStringIndexer, octetStringFilter,
3779 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
3780 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
3781 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3783 telephoneNumberMatch, NULL, NULL,
3786 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
3787 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
3788 SLAP_MR_SUBSTR | SLAP_MR_EXT,
3790 telephoneNumberSubstringsMatch, NULL, NULL,
3793 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
3794 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
3795 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3797 presentationAddressMatch, NULL, NULL,
3800 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
3801 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
3802 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3804 uniqueMemberMatch, NULL, NULL,
3807 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
3808 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
3809 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3811 protocolInformationMatch, NULL, NULL,
3814 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
3815 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
3816 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3818 generalizedTimeMatch, NULL, NULL,
3821 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
3822 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
3825 generalizedTimeOrderingMatch, NULL, NULL,
3828 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
3829 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
3830 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3832 integerFirstComponentMatch, NULL, NULL,
3835 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
3836 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
3837 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3839 objectIdentifierFirstComponentMatch, NULL, NULL,
3842 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
3843 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3844 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3846 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
3847 IA5StringApproxMatchOID },
3849 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
3850 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3851 SLAP_MR_EQUALITY | SLAP_MR_EXT,
3853 caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
3854 IA5StringApproxMatchOID },
3856 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
3857 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3860 caseIgnoreIA5SubstringsMatch,
3861 caseIgnoreIA5SubstringsIndexer,
3862 caseIgnoreIA5SubstringsFilter,
3865 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
3866 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
3869 caseExactIA5SubstringsMatch,
3870 caseExactIA5SubstringsIndexer,
3871 caseExactIA5SubstringsFilter,
3874 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
3875 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
3878 authPasswordMatch, NULL, NULL,
3881 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
3882 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
3885 OpenLDAPaciMatch, NULL, NULL,
3888 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
3897 /* we should only be called once (from main) */
3898 assert( schema_init_done == 0 );
3900 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
3901 res = register_syntax( syntax_defs[i].sd_desc,
3902 syntax_defs[i].sd_flags,
3903 syntax_defs[i].sd_validate,
3904 syntax_defs[i].sd_normalize,
3905 syntax_defs[i].sd_pretty
3906 #ifdef SLAPD_BINARY_CONVERSION
3908 syntax_defs[i].sd_ber2str,
3909 syntax_defs[i].sd_str2ber
3914 fprintf( stderr, "schema_init: Error registering syntax %s\n",
3915 syntax_defs[i].sd_desc );
3920 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
3921 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
3923 "schema_init: Ingoring unusable matching rule %s\n",
3924 mrule_defs[i].mrd_desc );
3928 res = register_matching_rule(
3929 mrule_defs[i].mrd_desc,
3930 mrule_defs[i].mrd_usage,
3931 mrule_defs[i].mrd_convert,
3932 mrule_defs[i].mrd_normalize,
3933 mrule_defs[i].mrd_match,
3934 mrule_defs[i].mrd_indexer,
3935 mrule_defs[i].mrd_filter,
3936 mrule_defs[i].mrd_associated );
3940 "schema_init: Error registering matching rule %s\n",
3941 mrule_defs[i].mrd_desc );
3945 schema_init_done = 1;
3946 return LDAP_SUCCESS;