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 "lutil_md5.h"
20 /* recycled validatation routines */
21 #define berValidate blobValidate
23 /* unimplemented validators */
24 #define bitStringValidate NULL
26 /* recycled normalization routines */
27 #define faxNumberNormalize numericStringNormalize
28 #define phoneNumberNormalize numericStringNormalize
29 #define telexNumberNormalize numericStringNormalize
30 #define integerNormalize numericStringNormalize
32 /* unimplemented normalizers */
33 #define bitStringNormalize NULL
35 /* unimplemented pretters */
37 #define integerPretty NULL
39 /* recycled matching routines */
40 #define caseIgnoreMatch caseIgnoreIA5Match
41 #define caseIgnoreOrderingMatch caseIgnoreMatch
42 #define caseIgnoreSubstringsMatch caseIgnoreIA5SubstringsMatch
44 #define caseExactMatch caseExactIA5Match
45 #define caseExactOrderingMatch caseExactMatch
46 #define caseExactSubstringsMatch caseExactIA5SubstringsMatch
48 #define numericStringMatch caseIgnoreMatch
49 #define objectIdentifierMatch numericStringMatch
50 #define integerMatch numericStringMatch
51 #define telephoneNumberMatch numericStringMatch
52 #define telephoneNumberSubstringsMatch caseIgnoreIA5SubstringsMatch
53 #define generalizedTimeMatch numericStringMatch
54 #define generalizedTimeOrderingMatch numericStringMatch
56 /* approx matching rules */
57 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
58 #define directoryStringApproxMatch NULL
59 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
60 #define IA5StringApproxMatch NULL
62 /* unimplemented matching routines */
63 #define caseIgnoreListMatch NULL
64 #define caseIgnoreListSubstringsMatch NULL
65 #define bitStringMatch NULL
66 #define presentationAddressMatch NULL
67 #define uniqueMemberMatch NULL
68 #define protocolInformationMatch NULL
69 #define integerFirstComponentMatch NULL
71 #define OpenLDAPaciMatch NULL
72 #define authPasswordMatch NULL
74 /* recycled indexing/filtering routines */
75 #define caseIgnoreIndexer caseIgnoreIA5Indexer
76 #define caseIgnoreFilter caseIgnoreIA5Filter
77 #define caseExactIndexer caseExactIA5Indexer
78 #define caseExactFilter caseExactIA5Filter
79 #define dnIndexer caseIgnoreIndexer
80 #define dnFilter caseIgnoreFilter
82 #define caseIgnoreSubstringsIndexer caseIgnoreIA5SubstringsIndexer
83 #define caseIgnoreSubstringsFilter caseIgnoreIA5SubstringsFilter
84 #define caseExactSubstringsIndexer caseExactIA5SubstringsIndexer
85 #define caseExactSubstringsFilter caseExactIA5SubstringsFilter
97 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
100 match = memcmp( value->bv_val,
101 ((struct berval *) assertedValue)->bv_val,
109 /* Index generation function */
110 int octetStringIndexer(
114 struct berval *prefix,
115 struct berval **values,
116 struct berval ***keysp )
120 struct berval **keys;
121 lutil_MD5_CTX MD5context;
122 unsigned char MD5digest[16];
123 struct berval digest;
124 digest.bv_val = MD5digest;
125 digest.bv_len = sizeof(MD5digest);
127 for( i=0; values[i] != NULL; i++ ) {
128 /* just count them */
133 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
135 slen = strlen( syntax->ssyn_oid );
136 mlen = strlen( mr->smr_oid );
138 for( i=0; values[i] != NULL; i++ ) {
139 lutil_MD5Init( &MD5context );
140 if( prefix != NULL && prefix->bv_len > 0 ) {
141 lutil_MD5Update( &MD5context,
142 prefix->bv_val, prefix->bv_len );
144 lutil_MD5Update( &MD5context,
145 syntax->ssyn_oid, slen );
146 lutil_MD5Update( &MD5context,
148 lutil_MD5Update( &MD5context,
149 values[i]->bv_val, values[i]->bv_len );
150 lutil_MD5Final( MD5digest, &MD5context );
152 keys[i] = ber_bvdup( &digest );
162 /* Index generation function */
163 int octetStringFilter(
167 struct berval *prefix,
169 struct berval ***keysp )
172 struct berval **keys;
173 lutil_MD5_CTX MD5context;
174 unsigned char MD5digest[LUTIL_MD5_BYTES];
175 struct berval *value = (struct berval *) assertValue;
176 struct berval digest;
177 digest.bv_val = MD5digest;
178 digest.bv_len = sizeof(MD5digest);
180 slen = strlen( syntax->ssyn_oid );
181 mlen = strlen( mr->smr_oid );
183 keys = ch_malloc( sizeof( struct berval * ) * 2 );
185 lutil_MD5Init( &MD5context );
186 if( prefix != NULL && prefix->bv_len > 0 ) {
187 lutil_MD5Update( &MD5context,
188 prefix->bv_val, prefix->bv_len );
190 lutil_MD5Update( &MD5context,
191 syntax->ssyn_oid, slen );
192 lutil_MD5Update( &MD5context,
194 lutil_MD5Update( &MD5context,
195 value->bv_val, value->bv_len );
196 lutil_MD5Final( MD5digest, &MD5context );
198 keys[0] = ber_bvdup( &digest );
214 if( in->bv_len == 0 ) return LDAP_SUCCESS;
216 dn = ch_strdup( in->bv_val );
218 rc = dn_validate( dn ) == NULL
219 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
229 struct berval **normalized )
231 struct berval *out = ber_bvdup( val );
233 if( out->bv_len != 0 ) {
235 #ifdef USE_DN_NORMALIZE
236 dn = dn_normalize( out->bv_val );
238 dn = dn_validate( out->bv_val );
243 return LDAP_INVALID_SYNTAX;
247 out->bv_len = strlen( dn );
260 struct berval *value,
261 void *assertedValue )
264 struct berval *asserted = (struct berval *) assertedValue;
266 match = value->bv_len - asserted->bv_len;
269 #ifdef USE_DN_NORMALIZE
270 match = strcmp( value->bv_val, asserted->bv_val );
272 match = strcasecmp( value->bv_val, asserted->bv_val );
276 Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
277 match, value->bv_val, asserted->bv_val );
288 /* any value allowed */
297 /* any value allowed */
302 * Handling boolean syntax and matching is quite rigid.
303 * A more flexible approach would be to allow a variety
304 * of strings to be normalized and prettied into TRUE
312 /* very unforgiving validation, requires no normalization
313 * before simplistic matching
316 if( in->bv_len == 4 ) {
317 if( !memcmp( in->bv_val, "TRUE", 4 ) ) {
320 } else if( in->bv_len == 5 ) {
321 if( !memcmp( in->bv_val, "FALSE", 5 ) ) {
326 return LDAP_INVALID_SYNTAX;
335 struct berval *value,
336 void *assertedValue )
338 /* simplistic matching allowed by rigid validation */
339 struct berval *asserted = (struct berval *) assertedValue;
340 *matchp = value->bv_len != asserted->bv_len;
351 unsigned char *u = in->bv_val;
353 if( !in->bv_len ) return LDAP_INVALID_SYNTAX;
355 for( count = in->bv_len; count > 0; count-=len, u+=len ) {
356 /* get the length indicated by the first byte */
357 len = LDAP_UTF8_CHARLEN( u );
359 /* should not be zero */
360 if( len == 0 ) return LDAP_INVALID_SYNTAX;
362 /* make sure len corresponds with the offset
363 to the next character */
364 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
367 if( count != 0 ) return LDAP_INVALID_SYNTAX;
376 struct berval **normalized )
378 struct berval *newval;
381 newval = ch_malloc( sizeof( struct berval ) );
385 /* Ignore initial whitespace */
386 while ( ldap_utf8_isspace( p ) ) {
392 return LDAP_INVALID_SYNTAX;
395 newval->bv_val = ch_strdup( p );
396 p = q = newval->bv_val;
402 if ( ldap_utf8_isspace( p ) ) {
403 len = LDAP_UTF8_COPY(q,p);
408 /* Ignore the extra whitespace */
409 while ( ldap_utf8_isspace( p ) ) {
413 len = LDAP_UTF8_COPY(q,p);
420 assert( *newval->bv_val );
421 assert( newval->bv_val < p );
424 /* cannot start with a space */
425 assert( !ldap_utf8_isspace(newval->bv_val) );
428 * If the string ended in space, backup the pointer one
429 * position. One is enough because the above loop collapsed
430 * all whitespace to a single space.
437 /* cannot end with a space */
438 assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
443 newval->bv_len = q - newval->bv_val;
444 *normalized = newval;
456 if( val->bv_len == 0 ) return 0;
458 if( OID_LEADCHAR(val->bv_val[0]) ) {
460 for(i=1; i < val->bv_len; i++) {
461 if( OID_SEPARATOR( val->bv_val[i] ) ) {
462 if( dot++ ) return 1;
463 } else if ( OID_CHAR( val->bv_val[i] ) ) {
466 return LDAP_INVALID_SYNTAX;
470 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
472 } else if( DESC_LEADCHAR(val->bv_val[0]) ) {
473 for(i=1; i < val->bv_len; i++) {
474 if( !DESC_CHAR(val->bv_val[i] ) ) {
475 return LDAP_INVALID_SYNTAX;
482 return LDAP_INVALID_SYNTAX;
492 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
494 for(i=0; i < val->bv_len; i++) {
495 if( !ASCII_DIGIT(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
502 printableStringValidate(
508 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
510 for(i=0; i < val->bv_len; i++) {
511 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
524 if( !val->bv_len ) return LDAP_INVALID_SYNTAX;
526 for(i=0; i < val->bv_len; i++) {
527 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
537 struct berval **out )
540 ber_len_t i, len = in->bv_len;
541 struct berval *bv = ch_malloc( sizeof(struct berval) );
543 bv->bv_len = len * sizeof( ldap_unicode_t );
544 bv->bv_val = (char *) u = ch_malloc( bv->bv_len + sizeof(ldap_unicode_t) );
546 for(i=0; i < len; i++ ) {
548 * IA5StringValidate should have been called to ensure
549 * input is limited to IA5.
551 u[i] = in->bv_val[i];
563 struct berval **normalized )
565 struct berval *newval;
568 newval = ch_malloc( sizeof( struct berval ) );
572 /* Ignore initial whitespace */
573 while ( ASCII_SPACE( *p ) ) {
579 return LDAP_INVALID_SYNTAX;
582 newval->bv_val = ch_strdup( p );
583 p = q = newval->bv_val;
586 if ( ASCII_SPACE( *p ) ) {
589 /* Ignore the extra whitespace */
590 while ( ASCII_SPACE( *p ) ) {
598 assert( *newval->bv_val );
599 assert( newval->bv_val < p );
602 /* cannot start with a space */
603 assert( !ASCII_SPACE(*newval->bv_val) );
606 * If the string ended in space, backup the pointer one
607 * position. One is enough because the above loop collapsed
608 * all whitespace to a single space.
611 if ( ASCII_SPACE( q[-1] ) ) {
615 /* cannot end with a space */
616 assert( !ASCII_SPACE( q[-1] ) );
621 newval->bv_len = q - newval->bv_val;
622 *normalized = newval;
633 struct berval *value,
634 void *assertedValue )
636 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
639 match = strncmp( value->bv_val,
640 ((struct berval *) assertedValue)->bv_val,
649 caseExactIA5SubstringsMatch(
654 struct berval *value,
655 void *assertedValue )
658 SubstringsAssertion *sub = assertedValue;
659 struct berval left = *value;
663 /* Add up asserted input length */
664 if( sub->sa_initial ) {
665 inlen += sub->sa_initial->bv_len;
668 for(i=0; sub->sa_any[i] != NULL; i++) {
669 inlen += sub->sa_any[i]->bv_len;
672 if( sub->sa_final ) {
673 inlen += sub->sa_final->bv_len;
676 if( sub->sa_initial ) {
677 if( inlen > left.bv_len ) {
682 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
683 sub->sa_initial->bv_len );
689 left.bv_val += sub->sa_initial->bv_len;
690 left.bv_len -= sub->sa_initial->bv_len;
691 inlen -= sub->sa_initial->bv_len;
694 if( sub->sa_final ) {
695 if( inlen > left.bv_len ) {
700 match = strncmp( sub->sa_final->bv_val,
701 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
702 sub->sa_final->bv_len );
708 left.bv_len -= sub->sa_final->bv_len;
709 inlen -= sub->sa_final->bv_len;
713 for(i=0; sub->sa_any[i]; i++) {
718 if( inlen > left.bv_len ) {
719 /* not enough length */
724 if( sub->sa_any[i]->bv_len == 0 ) {
728 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
735 idx = p - left.bv_val;
736 assert( idx < left.bv_len );
738 if( idx >= left.bv_len ) {
739 /* this shouldn't happen */
746 if( sub->sa_any[i]->bv_len > left.bv_len ) {
747 /* not enough left */
752 match = strncmp( left.bv_val,
753 sub->sa_any[i]->bv_val,
754 sub->sa_any[i]->bv_len );
762 left.bv_val += sub->sa_any[i]->bv_len;
763 left.bv_len -= sub->sa_any[i]->bv_len;
764 inlen -= sub->sa_any[i]->bv_len;
773 /* Index generation function */
774 int caseExactIA5Indexer(
778 struct berval *prefix,
779 struct berval **values,
780 struct berval ***keysp )
784 struct berval **keys;
785 lutil_MD5_CTX MD5context;
786 unsigned char MD5digest[16];
787 struct berval digest;
788 digest.bv_val = MD5digest;
789 digest.bv_len = sizeof(MD5digest);
791 for( i=0; values[i] != NULL; i++ ) {
792 /* just count them */
797 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
799 slen = strlen( syntax->ssyn_oid );
800 mlen = strlen( mr->smr_oid );
802 for( i=0; values[i] != NULL; i++ ) {
803 struct berval *value = values[i];
805 lutil_MD5Init( &MD5context );
806 if( prefix != NULL && prefix->bv_len > 0 ) {
807 lutil_MD5Update( &MD5context,
808 prefix->bv_val, prefix->bv_len );
810 lutil_MD5Update( &MD5context,
811 syntax->ssyn_oid, slen );
812 lutil_MD5Update( &MD5context,
814 lutil_MD5Update( &MD5context,
815 value->bv_val, value->bv_len );
816 lutil_MD5Final( MD5digest, &MD5context );
818 keys[i] = ber_bvdup( &digest );
826 /* Index generation function */
827 int caseExactIA5Filter(
831 struct berval *prefix,
833 struct berval ***keysp )
836 struct berval **keys;
837 lutil_MD5_CTX MD5context;
838 unsigned char MD5digest[LUTIL_MD5_BYTES];
839 struct berval *value;
840 struct berval digest;
841 digest.bv_val = MD5digest;
842 digest.bv_len = sizeof(MD5digest);
844 slen = strlen( syntax->ssyn_oid );
845 mlen = strlen( mr->smr_oid );
847 value = (struct berval *) assertValue;
849 keys = ch_malloc( sizeof( struct berval * ) * 2 );
851 lutil_MD5Init( &MD5context );
852 if( prefix != NULL && prefix->bv_len > 0 ) {
853 lutil_MD5Update( &MD5context,
854 prefix->bv_val, prefix->bv_len );
856 lutil_MD5Update( &MD5context,
857 syntax->ssyn_oid, slen );
858 lutil_MD5Update( &MD5context,
860 lutil_MD5Update( &MD5context,
861 value->bv_val, value->bv_len );
862 lutil_MD5Final( MD5digest, &MD5context );
864 keys[0] = ber_bvdup( &digest );
870 /* Substrings Index generation function */
871 int caseExactIA5SubstringsIndexer(
875 struct berval *prefix,
876 struct berval **values,
877 struct berval ***keysp )
881 struct berval **keys;
882 lutil_MD5_CTX MD5context;
883 unsigned char MD5digest[16];
884 struct berval digest;
885 digest.bv_val = MD5digest;
886 digest.bv_len = sizeof(MD5digest);
889 if( flags & SLAP_MR_SUBSTR_INITIAL ) types++;
890 if( flags & SLAP_MR_SUBSTR_FINAL ) types++;
891 /* no SUBSTR_ANY indexing */
894 for( i=0; values[i] != NULL; i++ ) {
895 /* count number of indices to generate */
896 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
900 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
901 nkeys += SLAP_INDEX_SUBSTR_MAXLEN - ( SLAP_INDEX_SUBSTR_MINLEN - 1);
903 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
909 /* no keys to generate */
914 nkeys *= types; /* We need to generate keys for each type */
915 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
917 slen = strlen( syntax->ssyn_oid );
918 mlen = strlen( mr->smr_oid );
921 for( i=0; values[i] != NULL; i++ ) {
923 struct berval *value;
925 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
927 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
928 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
932 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
935 if( flags & SLAP_MR_SUBSTR_INITIAL ) {
936 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
937 lutil_MD5Init( &MD5context );
938 if( prefix != NULL && prefix->bv_len > 0 ) {
939 lutil_MD5Update( &MD5context,
940 prefix->bv_val, prefix->bv_len );
942 lutil_MD5Update( &MD5context,
943 &pre, sizeof( pre ) );
944 lutil_MD5Update( &MD5context,
945 syntax->ssyn_oid, slen );
946 lutil_MD5Update( &MD5context,
948 lutil_MD5Update( &MD5context,
950 lutil_MD5Final( MD5digest, &MD5context );
952 keys[nkeys++] = ber_bvdup( &digest );
955 if( flags & SLAP_MR_SUBSTR_FINAL ) {
956 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
957 lutil_MD5Init( &MD5context );
958 if( prefix != NULL && prefix->bv_len > 0 ) {
959 lutil_MD5Update( &MD5context,
960 prefix->bv_val, prefix->bv_len );
962 lutil_MD5Update( &MD5context,
963 &pre, sizeof( pre ) );
964 lutil_MD5Update( &MD5context,
965 syntax->ssyn_oid, slen );
966 lutil_MD5Update( &MD5context,
968 lutil_MD5Update( &MD5context,
969 &value->bv_val[value->bv_len-j], j );
970 lutil_MD5Final( MD5digest, &MD5context );
972 keys[nkeys++] = ber_bvdup( &digest );
983 int caseExactIA5SubstringsFilter(
987 struct berval *prefix,
989 struct berval ***keysp )
991 SubstringsAssertion *sa = assertValue;
994 size_t slen, mlen, klen;
995 struct berval **keys;
996 lutil_MD5_CTX MD5context;
997 unsigned char MD5digest[LUTIL_MD5_BYTES];
998 struct berval *value;
999 struct berval digest;
1001 if( sa->sa_initial != NULL &&
1002 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1006 if( sa->sa_final != NULL &&
1007 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1014 return LDAP_SUCCESS;
1017 digest.bv_val = MD5digest;
1018 digest.bv_len = sizeof(MD5digest);
1020 slen = strlen( syntax->ssyn_oid );
1021 mlen = strlen( mr->smr_oid );
1023 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1026 if( sa->sa_initial != NULL &&
1027 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1029 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1030 value = sa->sa_initial;
1032 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1033 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1035 lutil_MD5Init( &MD5context );
1036 if( prefix != NULL && prefix->bv_len > 0 ) {
1037 lutil_MD5Update( &MD5context,
1038 prefix->bv_val, prefix->bv_len );
1040 lutil_MD5Update( &MD5context,
1041 &pre, sizeof( pre ) );
1042 lutil_MD5Update( &MD5context,
1043 syntax->ssyn_oid, slen );
1044 lutil_MD5Update( &MD5context,
1045 mr->smr_oid, mlen );
1046 lutil_MD5Update( &MD5context,
1047 value->bv_val, klen );
1048 lutil_MD5Final( MD5digest, &MD5context );
1050 ber_bvfree( value );
1051 keys[nkeys++] = ber_bvdup( &digest );
1054 if( sa->sa_final != NULL &&
1055 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1057 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1058 value = sa->sa_final;
1060 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1061 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1063 lutil_MD5Init( &MD5context );
1064 if( prefix != NULL && prefix->bv_len > 0 ) {
1065 lutil_MD5Update( &MD5context,
1066 prefix->bv_val, prefix->bv_len );
1068 lutil_MD5Update( &MD5context,
1069 &pre, sizeof( pre ) );
1070 lutil_MD5Update( &MD5context,
1071 syntax->ssyn_oid, slen );
1072 lutil_MD5Update( &MD5context,
1073 mr->smr_oid, mlen );
1074 lutil_MD5Update( &MD5context,
1075 &value->bv_val[value->bv_len-klen], klen );
1076 lutil_MD5Final( MD5digest, &MD5context );
1078 ber_bvfree( value );
1079 keys[nkeys++] = ber_bvdup( &digest );
1085 return LDAP_SUCCESS;
1094 struct berval *value,
1095 void *assertedValue )
1097 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1100 match = strncasecmp( value->bv_val,
1101 ((struct berval *) assertedValue)->bv_val,
1106 return LDAP_SUCCESS;
1109 static char *strcasechr( const char *str, int c )
1111 char *lower = strchr( str, TOLOWER(c) );
1112 char *upper = strchr( str, TOUPPER(c) );
1114 if( lower && upper ) {
1115 return lower < upper ? lower : upper;
1116 } else if ( lower ) {
1124 caseIgnoreIA5SubstringsMatch(
1129 struct berval *value,
1130 void *assertedValue )
1133 SubstringsAssertion *sub = assertedValue;
1134 struct berval left = *value;
1138 /* Add up asserted input length */
1139 if( sub->sa_initial ) {
1140 inlen += sub->sa_initial->bv_len;
1143 for(i=0; sub->sa_any[i] != NULL; i++) {
1144 inlen += sub->sa_any[i]->bv_len;
1147 if( sub->sa_final ) {
1148 inlen += sub->sa_final->bv_len;
1151 if( sub->sa_initial ) {
1152 if( inlen > left.bv_len ) {
1157 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1158 sub->sa_initial->bv_len );
1164 left.bv_val += sub->sa_initial->bv_len;
1165 left.bv_len -= sub->sa_initial->bv_len;
1166 inlen -= sub->sa_initial->bv_len;
1169 if( sub->sa_final ) {
1170 if( inlen > left.bv_len ) {
1175 match = strncasecmp( sub->sa_final->bv_val,
1176 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1177 sub->sa_final->bv_len );
1183 left.bv_len -= sub->sa_final->bv_len;
1184 inlen -= sub->sa_final->bv_len;
1188 for(i=0; sub->sa_any[i]; i++) {
1193 if( inlen > left.bv_len ) {
1194 /* not enough length */
1199 if( sub->sa_any[i]->bv_len == 0 ) {
1203 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1210 idx = p - left.bv_val;
1211 assert( idx < left.bv_len );
1213 if( idx >= left.bv_len ) {
1214 /* this shouldn't happen */
1221 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1222 /* not enough left */
1227 match = strncasecmp( left.bv_val,
1228 sub->sa_any[i]->bv_val,
1229 sub->sa_any[i]->bv_len );
1238 left.bv_val += sub->sa_any[i]->bv_len;
1239 left.bv_len -= sub->sa_any[i]->bv_len;
1240 inlen -= sub->sa_any[i]->bv_len;
1246 return LDAP_SUCCESS;
1249 /* Index generation function */
1250 int caseIgnoreIA5Indexer(
1254 struct berval *prefix,
1255 struct berval **values,
1256 struct berval ***keysp )
1260 struct berval **keys;
1261 lutil_MD5_CTX MD5context;
1262 unsigned char MD5digest[16];
1263 struct berval digest;
1264 digest.bv_val = MD5digest;
1265 digest.bv_len = sizeof(MD5digest);
1267 for( i=0; values[i] != NULL; i++ ) {
1268 /* just count them */
1273 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1275 slen = strlen( syntax->ssyn_oid );
1276 mlen = strlen( mr->smr_oid );
1278 for( i=0; values[i] != NULL; i++ ) {
1279 struct berval *value = ber_bvdup( values[i] );
1280 ldap_pvt_str2upper( value->bv_val );
1282 lutil_MD5Init( &MD5context );
1283 if( prefix != NULL && prefix->bv_len > 0 ) {
1284 lutil_MD5Update( &MD5context,
1285 prefix->bv_val, prefix->bv_len );
1287 lutil_MD5Update( &MD5context,
1288 syntax->ssyn_oid, slen );
1289 lutil_MD5Update( &MD5context,
1290 mr->smr_oid, mlen );
1291 lutil_MD5Update( &MD5context,
1292 value->bv_val, value->bv_len );
1293 lutil_MD5Final( MD5digest, &MD5context );
1295 ber_bvfree( value );
1297 keys[i] = ber_bvdup( &digest );
1302 return LDAP_SUCCESS;
1305 /* Index generation function */
1306 int caseIgnoreIA5Filter(
1310 struct berval *prefix,
1312 struct berval ***keysp )
1315 struct berval **keys;
1316 lutil_MD5_CTX MD5context;
1317 unsigned char MD5digest[LUTIL_MD5_BYTES];
1318 struct berval *value;
1319 struct berval digest;
1320 digest.bv_val = MD5digest;
1321 digest.bv_len = sizeof(MD5digest);
1323 slen = strlen( syntax->ssyn_oid );
1324 mlen = strlen( mr->smr_oid );
1326 value = ber_bvdup( (struct berval *) assertValue );
1327 ldap_pvt_str2upper( value->bv_val );
1329 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1331 lutil_MD5Init( &MD5context );
1332 if( prefix != NULL && prefix->bv_len > 0 ) {
1333 lutil_MD5Update( &MD5context,
1334 prefix->bv_val, prefix->bv_len );
1336 lutil_MD5Update( &MD5context,
1337 syntax->ssyn_oid, slen );
1338 lutil_MD5Update( &MD5context,
1339 mr->smr_oid, mlen );
1340 lutil_MD5Update( &MD5context,
1341 value->bv_val, value->bv_len );
1342 lutil_MD5Final( MD5digest, &MD5context );
1344 keys[0] = ber_bvdup( &digest );
1347 ber_bvfree( value );
1350 return LDAP_SUCCESS;
1353 /* Substrings Index generation function */
1354 int caseIgnoreIA5SubstringsIndexer(
1358 struct berval *prefix,
1359 struct berval **values,
1360 struct berval ***keysp )
1362 int i, nkeys, types;
1364 struct berval **keys;
1365 lutil_MD5_CTX MD5context;
1366 unsigned char MD5digest[16];
1367 struct berval digest;
1368 digest.bv_val = MD5digest;
1369 digest.bv_len = sizeof(MD5digest);
1372 if( flags & SLAP_MR_SUBSTR_INITIAL ) types++;
1373 if( flags & SLAP_MR_SUBSTR_FINAL ) types++;
1374 /* no SUBSTR_ANY indexing */
1377 for( i=0; values[i] != NULL; i++ ) {
1378 /* count number of indices to generate */
1379 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1383 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1384 nkeys += SLAP_INDEX_SUBSTR_MAXLEN - ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1386 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1392 /* no keys to generate */
1394 return LDAP_SUCCESS;
1397 nkeys *= types; /* We need to generate keys for each type */
1398 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1400 slen = strlen( syntax->ssyn_oid );
1401 mlen = strlen( mr->smr_oid );
1404 for( i=0; values[i] != NULL; i++ ) {
1406 struct berval *value;
1408 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1410 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i]->bv_len
1411 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i]->bv_len;
1413 value = ber_bvdup( values[i] );
1414 ldap_pvt_str2upper( value->bv_val );
1416 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1419 if( flags & SLAP_MR_SUBSTR_INITIAL ) {
1420 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1421 lutil_MD5Init( &MD5context );
1422 if( prefix != NULL && prefix->bv_len > 0 ) {
1423 lutil_MD5Update( &MD5context,
1424 prefix->bv_val, prefix->bv_len );
1426 lutil_MD5Update( &MD5context,
1427 &pre, sizeof( pre ) );
1428 lutil_MD5Update( &MD5context,
1429 syntax->ssyn_oid, slen );
1430 lutil_MD5Update( &MD5context,
1431 mr->smr_oid, mlen );
1432 lutil_MD5Update( &MD5context,
1434 lutil_MD5Final( MD5digest, &MD5context );
1436 keys[nkeys++] = ber_bvdup( &digest );
1439 if( flags & SLAP_MR_SUBSTR_FINAL ) {
1440 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1441 lutil_MD5Init( &MD5context );
1442 if( prefix != NULL && prefix->bv_len > 0 ) {
1443 lutil_MD5Update( &MD5context,
1444 prefix->bv_val, prefix->bv_len );
1446 lutil_MD5Update( &MD5context,
1447 &pre, sizeof( pre ) );
1448 lutil_MD5Update( &MD5context,
1449 syntax->ssyn_oid, slen );
1450 lutil_MD5Update( &MD5context,
1451 mr->smr_oid, mlen );
1452 lutil_MD5Update( &MD5context,
1453 &value->bv_val[value->bv_len-j], j );
1454 lutil_MD5Final( MD5digest, &MD5context );
1456 keys[nkeys++] = ber_bvdup( &digest );
1461 ber_bvfree( value );
1466 return LDAP_SUCCESS;
1469 int caseIgnoreIA5SubstringsFilter(
1473 struct berval *prefix,
1475 struct berval ***keysp )
1477 SubstringsAssertion *sa = assertValue;
1480 size_t slen, mlen, klen;
1481 struct berval **keys;
1482 lutil_MD5_CTX MD5context;
1483 unsigned char MD5digest[LUTIL_MD5_BYTES];
1484 struct berval *value;
1485 struct berval digest;
1487 if( sa->sa_initial != NULL &&
1488 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1492 if( sa->sa_final != NULL &&
1493 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1500 return LDAP_SUCCESS;
1503 digest.bv_val = MD5digest;
1504 digest.bv_len = sizeof(MD5digest);
1506 slen = strlen( syntax->ssyn_oid );
1507 mlen = strlen( mr->smr_oid );
1509 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1512 if( sa->sa_initial != NULL &&
1513 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1515 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1516 value = ber_bvdup( sa->sa_initial );
1517 ldap_pvt_str2upper( value->bv_val );
1519 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1520 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1522 lutil_MD5Init( &MD5context );
1523 if( prefix != NULL && prefix->bv_len > 0 ) {
1524 lutil_MD5Update( &MD5context,
1525 prefix->bv_val, prefix->bv_len );
1527 lutil_MD5Update( &MD5context,
1528 &pre, sizeof( pre ) );
1529 lutil_MD5Update( &MD5context,
1530 syntax->ssyn_oid, slen );
1531 lutil_MD5Update( &MD5context,
1532 mr->smr_oid, mlen );
1533 lutil_MD5Update( &MD5context,
1534 value->bv_val, klen );
1535 lutil_MD5Final( MD5digest, &MD5context );
1537 ber_bvfree( value );
1538 keys[nkeys++] = ber_bvdup( &digest );
1541 if( sa->sa_final != NULL &&
1542 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1544 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1545 value = ber_bvdup( sa->sa_final );
1546 ldap_pvt_str2upper( value->bv_val );
1548 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1549 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1551 lutil_MD5Init( &MD5context );
1552 if( prefix != NULL && prefix->bv_len > 0 ) {
1553 lutil_MD5Update( &MD5context,
1554 prefix->bv_val, prefix->bv_len );
1556 lutil_MD5Update( &MD5context,
1557 &pre, sizeof( pre ) );
1558 lutil_MD5Update( &MD5context,
1559 syntax->ssyn_oid, slen );
1560 lutil_MD5Update( &MD5context,
1561 mr->smr_oid, mlen );
1562 lutil_MD5Update( &MD5context,
1563 &value->bv_val[value->bv_len-klen], klen );
1564 lutil_MD5Final( MD5digest, &MD5context );
1566 ber_bvfree( value );
1567 keys[nkeys++] = ber_bvdup( &digest );
1573 return LDAP_SUCCESS;
1577 numericStringNormalize(
1580 struct berval **normalized )
1582 /* similiar to IA5StringNormalize except removes all spaces */
1583 struct berval *newval;
1586 newval = ch_malloc( sizeof( struct berval ) );
1590 /* Ignore initial whitespace */
1591 while ( ASCII_SPACE( *p ) ) {
1597 return LDAP_INVALID_SYNTAX;
1600 newval->bv_val = ch_strdup( p );
1601 p = q = newval->bv_val;
1604 if ( ASCII_SPACE( *p ) ) {
1605 /* Ignore whitespace */
1612 assert( *newval->bv_val );
1613 assert( newval->bv_val < p );
1616 /* cannot start with a space */
1617 assert( !ASCII_SPACE(*newval->bv_val) );
1619 /* cannot end with a space */
1620 assert( !ASCII_SPACE( q[-1] ) );
1622 /* null terminate */
1625 newval->bv_len = q - newval->bv_val;
1626 *normalized = newval;
1628 return LDAP_SUCCESS;
1632 objectIdentifierFirstComponentMatch(
1637 struct berval *value,
1638 void *assertedValue )
1640 int rc = LDAP_SUCCESS;
1642 struct berval *asserted = (struct berval *) assertedValue;
1646 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
1647 return LDAP_INVALID_SYNTAX;
1650 /* trim leading white space */
1651 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
1655 /* grab next word */
1656 oid.bv_val = &value->bv_val[i];
1657 oid.bv_len = value->bv_len - i;
1658 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
1663 /* insert attributeTypes, objectclass check here */
1664 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
1665 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
1668 char *stored = ch_malloc( oid.bv_len + 1 );
1669 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
1670 stored[oid.bv_len] = '\0';
1672 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
1673 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
1674 MatchingRule *stored_mr = mr_find( stored );
1676 if( asserted_mr == NULL ) {
1677 rc = SLAPD_COMPARE_UNDEFINED;
1679 match = asserted_mr != stored_mr;
1682 } else if ( !strcmp( syntax->ssyn_oid,
1683 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
1685 AttributeType *asserted_at = at_find( asserted->bv_val );
1686 AttributeType *stored_at = at_find( stored );
1688 if( asserted_at == NULL ) {
1689 rc = SLAPD_COMPARE_UNDEFINED;
1691 match = asserted_at != stored_at;
1694 } else if ( !strcmp( syntax->ssyn_oid,
1695 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
1697 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
1698 ObjectClass *stored_oc = oc_find( stored );
1700 if( asserted_oc == NULL ) {
1701 rc = SLAPD_COMPARE_UNDEFINED;
1703 match = asserted_oc != stored_oc;
1710 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
1711 "%d\n\t\"%s\"\n\t\"%s\"\n",
1712 match, value->bv_val, asserted->bv_val );
1714 if( rc == LDAP_SUCCESS ) *matchp = match;
1719 check_time_syntax (struct berval *val,
1723 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
1724 static int mdays[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
1726 int part, c, neg = 0;
1728 if( val->bv_len == 0 )
1729 return LDAP_INVALID_SYNTAX;
1731 p = (char *)val->bv_val;
1732 e = p + val->bv_len;
1734 /* Ignore initial whitespace */
1735 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
1739 if (e - p < 13 - (2 * start))
1740 return LDAP_INVALID_SYNTAX;
1742 for (part = 0; part < 9; part++)
1745 for (part = start; part < 7; part++) {
1758 return LDAP_INVALID_SYNTAX;
1760 return LDAP_INVALID_SYNTAX;
1765 return LDAP_INVALID_SYNTAX;
1767 return LDAP_INVALID_SYNTAX;
1771 if (part == 2 || part == 3)
1773 if (parts[part] < 0)
1774 return LDAP_INVALID_SYNTAX;
1775 if (parts[part] > ceiling[part])
1776 return LDAP_INVALID_SYNTAX;
1778 if (parts[2] == 1) {
1779 if (parts[3] > mdays[parts[2]])
1780 return LDAP_INVALID_SYNTAX;
1781 if (parts[1] & 0x03) {
1782 /* FIXME: This is an incomplete leap-year
1783 * check that fails in 2100, 2200, 2300,
1784 * 2500, 2600, 2700, ...
1786 if (parts[3] > mdays[parts[2]] - 1)
1787 return LDAP_INVALID_SYNTAX;
1793 } else if (c != '+' && c != '-') {
1794 return LDAP_INVALID_SYNTAX;
1799 return LDAP_INVALID_SYNTAX;
1800 for (part = 7; part < 9; part++) {
1803 return LDAP_INVALID_SYNTAX;
1808 return LDAP_INVALID_SYNTAX;
1811 if (parts[part] < 0 || parts[part] > ceiling[part])
1812 return LDAP_INVALID_SYNTAX;
1816 /* Ignore trailing whitespace */
1817 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
1821 return LDAP_INVALID_SYNTAX;
1824 parts[4] += parts[7];
1825 parts[5] += parts[8];
1826 for (part = 7; --part > 0; ) {
1830 /* FIXME: This is an incomplete leap-year
1831 * check that fails in 2100, 2200, 2300,
1832 * 2500, 2600, 2700, ...
1834 c = mdays[parts[2]];
1838 if (parts[part] > c) {
1839 parts[part] -= c + 1;
1844 parts[4] -= parts[7];
1845 parts[5] -= parts[8];
1846 for (part = 7; --part > 0; ) {
1850 /* FIXME: This is an incomplete leap-year
1851 * check that fails in 2100, 2200, 2300,
1852 * 2500, 2600, 2700, ...
1854 c = mdays[(parts[2] - 1) % 12];
1858 if (parts[part] < 0) {
1859 parts[part] += c + 1;
1865 return LDAP_SUCCESS;
1872 struct berval **normalized )
1877 rc = check_time_syntax(val, 1, parts);
1878 if (rc != LDAP_SUCCESS) {
1883 out = ch_malloc( sizeof(struct berval) );
1885 return LBER_ERROR_MEMORY;
1887 out->bv_val = ch_malloc( 14 );
1888 if ( out->bv_val == NULL ) {
1890 return LBER_ERROR_MEMORY;
1893 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
1894 parts[1], parts[2] + 1, parts[3] + 1,
1895 parts[4], parts[5], parts[6] );
1899 return LDAP_SUCCESS;
1909 return check_time_syntax(in, 1, parts);
1913 generalizedTimeValidate(
1919 return check_time_syntax(in, 0, parts);
1923 generalizedTimeNormalize(
1926 struct berval **normalized )
1931 rc = check_time_syntax(val, 0, parts);
1932 if (rc != LDAP_SUCCESS) {
1937 out = ch_malloc( sizeof(struct berval) );
1939 return LBER_ERROR_MEMORY;
1941 out->bv_val = ch_malloc( 16 );
1942 if ( out->bv_val == NULL ) {
1944 return LBER_ERROR_MEMORY;
1947 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
1948 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
1949 parts[4], parts[5], parts[6] );
1953 return LDAP_SUCCESS;
1956 struct syntax_defs_rec {
1959 slap_syntax_validate_func *sd_validate;
1960 slap_syntax_transform_func *sd_normalize;
1961 slap_syntax_transform_func *sd_pretty;
1962 #ifdef SLAPD_BINARY_CONVERSION
1963 slap_syntax_transform_func *sd_ber2str;
1964 slap_syntax_transform_func *sd_str2ber;
1968 #define X_HIDE "X-HIDE 'TRUE' "
1969 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
1970 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
1972 struct syntax_defs_rec syntax_defs[] = {
1973 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
1974 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
1975 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
1976 0, NULL, NULL, NULL},
1977 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
1978 0, NULL, NULL, NULL},
1979 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
1980 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
1981 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
1982 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1983 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
1984 0, bitStringValidate, bitStringNormalize, NULL },
1985 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
1986 0, booleanValidate, NULL, NULL},
1987 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
1988 X_BINARY X_NOT_H_R ")",
1989 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1990 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
1991 X_BINARY X_NOT_H_R ")",
1992 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1993 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
1994 X_BINARY X_NOT_H_R ")",
1995 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1996 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
1997 0, NULL, NULL, NULL},
1998 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
1999 0, dnValidate, dnNormalize, dnPretty},
2000 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
2001 0, NULL, NULL, NULL},
2002 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
2003 0, NULL, NULL, NULL},
2004 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
2005 0, UTF8StringValidate, UTF8StringNormalize, NULL},
2006 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
2007 0, NULL, NULL, NULL},
2008 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
2009 0, NULL, NULL, NULL},
2010 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
2011 0, NULL, NULL, NULL},
2012 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
2013 0, NULL, NULL, NULL},
2014 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
2015 0, NULL, NULL, NULL},
2016 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
2017 0, IA5StringValidate, faxNumberNormalize, NULL},
2018 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
2019 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
2020 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
2021 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
2022 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
2023 0, NULL, NULL, NULL},
2024 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
2025 0, IA5StringValidate, IA5StringNormalize, NULL},
2026 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
2027 0, integerValidate, integerNormalize, integerPretty},
2028 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
2029 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
2030 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
2031 0, NULL, NULL, NULL},
2032 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
2033 0, NULL, NULL, NULL},
2034 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
2035 0, NULL, NULL, NULL},
2036 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
2037 0, NULL, NULL, NULL},
2038 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
2039 0, NULL, NULL, NULL},
2040 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
2041 0, NULL, NULL, NULL},
2042 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
2043 0, NULL, NULL, NULL},
2044 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
2045 0, IA5StringValidate, numericStringNormalize, NULL},
2046 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
2047 0, NULL, NULL, NULL},
2048 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
2049 0, oidValidate, NULL, NULL},
2050 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
2051 0, NULL, NULL, NULL},
2052 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
2053 0, blobValidate, NULL, NULL},
2054 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
2055 0, blobValidate, NULL, NULL},
2056 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
2057 0, NULL, NULL, NULL},
2058 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
2059 0, NULL, NULL, NULL},
2060 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
2061 0, printableStringValidate, NULL, NULL},
2062 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
2063 X_BINARY X_NOT_H_R ")",
2064 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
2065 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
2066 0, IA5StringValidate, phoneNumberNormalize, NULL},
2067 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
2068 0, NULL, NULL, NULL},
2069 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
2070 0, IA5StringValidate, telexNumberNormalize, NULL},
2071 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
2072 0, utcTimeValidate, utcTimeNormalize, NULL},
2073 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
2074 0, NULL, NULL, NULL},
2075 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
2076 0, NULL, NULL, NULL},
2077 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
2078 0, NULL, NULL, NULL},
2079 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
2080 0, NULL, NULL, NULL},
2081 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
2082 0, NULL, NULL, NULL},
2084 /* OpenLDAP Experimental Syntaxes */
2085 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
2086 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */, NULL, NULL},
2087 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
2088 0, NULL, NULL, NULL},
2089 {"( 1.3.6.1.4.1.4203.666.2.3 DESC 'OpenLDAP void' " X_HIDE ")" ,
2090 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
2091 #if 0 /* not needed */
2092 {"( 1.3.6.1.4.1.4203.666.2.4 DESC 'OpenLDAP DN' " X_HIDE ")" ,
2093 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
2096 {NULL, 0, NULL, NULL, NULL}
2099 struct mrule_defs_rec {
2102 slap_mr_convert_func * mrd_convert;
2103 slap_mr_normalize_func * mrd_normalize;
2104 slap_mr_match_func * mrd_match;
2105 slap_mr_indexer_func * mrd_indexer;
2106 slap_mr_filter_func * mrd_filter;
2108 char * mrd_associated;
2112 * Other matching rules in X.520 that we do not use (yet):
2114 * 2.5.13.9 numericStringOrderingMatch
2115 * 2.5.13.13 booleanMatch
2116 * 2.5.13.15 integerOrderingMatch
2117 * 2.5.13.18 octetStringOrderingMatch
2118 * 2.5.13.19 octetStringSubstringsMatch
2119 * 2.5.13.25 uTCTimeMatch
2120 * 2.5.13.26 uTCTimeOrderingMatch
2121 * 2.5.13.31 directoryStringFirstComponentMatch
2122 * 2.5.13.32 wordMatch
2123 * 2.5.13.33 keywordMatch
2124 * 2.5.13.34 certificateExactMatch
2125 * 2.5.13.35 certificateMatch
2126 * 2.5.13.36 certificatePairExactMatch
2127 * 2.5.13.37 certificatePairMatch
2128 * 2.5.13.38 certificateListExactMatch
2129 * 2.5.13.39 certificateListMatch
2130 * 2.5.13.40 algorithmIdentifierMatch
2131 * 2.5.13.41 storedPrefixMatch
2132 * 2.5.13.42 attributeCertificateMatch
2133 * 2.5.13.43 readerAndKeyIDMatch
2134 * 2.5.13.44 attributeIntegrityMatch
2137 struct mrule_defs_rec mrule_defs[] = {
2139 * EQUALITY matching rules must be listed after associated APPROX
2140 * matching rules. So, we list all APPROX matching rules first.
2142 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
2143 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2144 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
2146 directoryStringApproxMatch, NULL, NULL,
2149 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
2150 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2151 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
2153 IA5StringApproxMatch, NULL, NULL,
2157 * Other matching rules
2160 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
2161 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
2162 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2164 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
2167 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
2168 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
2169 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2171 dnMatch, dnIndexer, dnFilter,
2174 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
2175 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2176 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2178 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
2179 directoryStringApproxMatchOID },
2181 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
2182 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2185 caseIgnoreOrderingMatch, NULL, NULL,
2188 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
2189 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2190 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2192 caseIgnoreSubstringsMatch,
2193 caseIgnoreSubstringsIndexer,
2194 caseIgnoreSubstringsFilter,
2197 {"( 2.5.13.5 NAME 'caseExactMatch' "
2198 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2199 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2201 caseExactMatch, caseExactIndexer, caseExactFilter,
2202 directoryStringApproxMatchOID },
2204 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
2205 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2208 caseExactOrderingMatch, NULL, NULL,
2211 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
2212 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2213 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2215 caseExactSubstringsMatch,
2216 caseExactSubstringsIndexer,
2217 caseExactSubstringsFilter,
2220 {"( 2.5.13.8 NAME 'numericStringMatch' "
2221 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
2222 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2224 caseIgnoreIA5Match, NULL, NULL,
2227 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
2228 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2229 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2231 caseIgnoreIA5SubstringsMatch,
2232 caseIgnoreIA5SubstringsIndexer,
2233 caseIgnoreIA5SubstringsFilter,
2236 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
2237 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
2238 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2240 caseIgnoreListMatch, NULL, NULL,
2243 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
2244 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2245 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2247 caseIgnoreListSubstringsMatch, NULL, NULL,
2250 {"( 2.5.13.13 NAME 'booleanMatch' "
2251 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
2252 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2254 booleanMatch, NULL, NULL,
2257 {"( 2.5.13.14 NAME 'integerMatch' "
2258 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
2259 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2261 integerMatch, NULL, NULL,
2264 {"( 2.5.13.16 NAME 'bitStringMatch' "
2265 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
2266 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2268 bitStringMatch, NULL, NULL,
2271 {"( 2.5.13.17 NAME 'octetStringMatch' "
2272 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
2273 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2275 octetStringMatch, octetStringIndexer, octetStringFilter,
2278 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
2279 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
2280 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2282 telephoneNumberMatch, NULL, NULL,
2285 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
2286 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2287 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2289 telephoneNumberSubstringsMatch, NULL, NULL,
2292 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
2293 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
2294 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2296 presentationAddressMatch, NULL, NULL,
2299 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
2300 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
2301 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2303 uniqueMemberMatch, NULL, NULL,
2306 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
2307 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
2308 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2310 protocolInformationMatch, NULL, NULL,
2313 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
2314 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
2315 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2317 generalizedTimeMatch, NULL, NULL,
2320 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
2321 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
2324 generalizedTimeOrderingMatch, NULL, NULL,
2327 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
2328 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
2329 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2331 integerFirstComponentMatch, NULL, NULL,
2334 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
2335 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
2336 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2338 objectIdentifierFirstComponentMatch, NULL, NULL,
2341 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
2342 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2343 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2345 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
2346 IA5StringApproxMatchOID },
2348 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
2349 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2350 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2352 caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
2353 IA5StringApproxMatchOID },
2355 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
2356 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2359 caseIgnoreIA5SubstringsMatch,
2360 caseIgnoreIA5SubstringsIndexer,
2361 caseIgnoreIA5SubstringsFilter,
2364 {"( 1.3.6.1.4.1.4203.666.4.3 NAME 'caseExactIA5SubstringsMatch' "
2365 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2368 caseExactIA5SubstringsMatch,
2369 caseExactIA5SubstringsIndexer,
2370 caseExactIA5SubstringsFilter,
2373 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
2374 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
2377 authPasswordMatch, NULL, NULL,
2380 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
2381 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
2384 OpenLDAPaciMatch, NULL, NULL,
2387 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
2396 /* we should only be called once (from main) */
2397 assert( schema_init_done == 0 );
2399 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
2400 res = register_syntax( syntax_defs[i].sd_desc,
2401 syntax_defs[i].sd_flags,
2402 syntax_defs[i].sd_validate,
2403 syntax_defs[i].sd_normalize,
2404 syntax_defs[i].sd_pretty
2405 #ifdef SLAPD_BINARY_CONVERSION
2407 syntax_defs[i].sd_ber2str,
2408 syntax_defs[i].sd_str2ber
2413 fprintf( stderr, "schema_init: Error registering syntax %s\n",
2414 syntax_defs[i].sd_desc );
2419 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
2420 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
2422 "schema_init: Ingoring unusable matching rule %s\n",
2423 mrule_defs[i].mrd_desc );
2427 res = register_matching_rule(
2428 mrule_defs[i].mrd_desc,
2429 mrule_defs[i].mrd_usage,
2430 mrule_defs[i].mrd_convert,
2431 mrule_defs[i].mrd_normalize,
2432 mrule_defs[i].mrd_match,
2433 mrule_defs[i].mrd_indexer,
2434 mrule_defs[i].mrd_filter,
2435 mrule_defs[i].mrd_associated );
2439 "schema_init: Error registering matching rule %s\n",
2440 mrule_defs[i].mrd_desc );
2444 schema_init_done = 1;
2445 return LDAP_SUCCESS;