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 u = (ldap_unicode_t *) ch_malloc( bv->bv_len + sizeof(ldap_unicode_t) );
545 bv->bv_val = (char *) u;
547 for(i=0; i < len; i++ ) {
549 * IA5StringValidate should have been called to ensure
550 * input is limited to IA5.
552 u[i] = in->bv_val[i];
564 struct berval **normalized )
566 struct berval *newval;
569 newval = ch_malloc( sizeof( struct berval ) );
573 /* Ignore initial whitespace */
574 while ( ASCII_SPACE( *p ) ) {
580 return LDAP_INVALID_SYNTAX;
583 newval->bv_val = ch_strdup( p );
584 p = q = newval->bv_val;
587 if ( ASCII_SPACE( *p ) ) {
590 /* Ignore the extra whitespace */
591 while ( ASCII_SPACE( *p ) ) {
599 assert( *newval->bv_val );
600 assert( newval->bv_val < p );
603 /* cannot start with a space */
604 assert( !ASCII_SPACE(*newval->bv_val) );
607 * If the string ended in space, backup the pointer one
608 * position. One is enough because the above loop collapsed
609 * all whitespace to a single space.
612 if ( ASCII_SPACE( q[-1] ) ) {
616 /* cannot end with a space */
617 assert( !ASCII_SPACE( q[-1] ) );
622 newval->bv_len = q - newval->bv_val;
623 *normalized = newval;
634 struct berval *value,
635 void *assertedValue )
637 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
640 match = strncmp( value->bv_val,
641 ((struct berval *) assertedValue)->bv_val,
650 caseExactIA5SubstringsMatch(
655 struct berval *value,
656 void *assertedValue )
659 SubstringsAssertion *sub = assertedValue;
660 struct berval left = *value;
664 /* Add up asserted input length */
665 if( sub->sa_initial ) {
666 inlen += sub->sa_initial->bv_len;
669 for(i=0; sub->sa_any[i] != NULL; i++) {
670 inlen += sub->sa_any[i]->bv_len;
673 if( sub->sa_final ) {
674 inlen += sub->sa_final->bv_len;
677 if( sub->sa_initial ) {
678 if( inlen > left.bv_len ) {
683 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
684 sub->sa_initial->bv_len );
690 left.bv_val += sub->sa_initial->bv_len;
691 left.bv_len -= sub->sa_initial->bv_len;
692 inlen -= sub->sa_initial->bv_len;
695 if( sub->sa_final ) {
696 if( inlen > left.bv_len ) {
701 match = strncmp( sub->sa_final->bv_val,
702 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
703 sub->sa_final->bv_len );
709 left.bv_len -= sub->sa_final->bv_len;
710 inlen -= sub->sa_final->bv_len;
714 for(i=0; sub->sa_any[i]; i++) {
719 if( inlen > left.bv_len ) {
720 /* not enough length */
725 if( sub->sa_any[i]->bv_len == 0 ) {
729 p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
736 idx = p - left.bv_val;
737 assert( idx < left.bv_len );
739 if( idx >= left.bv_len ) {
740 /* this shouldn't happen */
747 if( sub->sa_any[i]->bv_len > left.bv_len ) {
748 /* not enough left */
753 match = strncmp( left.bv_val,
754 sub->sa_any[i]->bv_val,
755 sub->sa_any[i]->bv_len );
763 left.bv_val += sub->sa_any[i]->bv_len;
764 left.bv_len -= sub->sa_any[i]->bv_len;
765 inlen -= sub->sa_any[i]->bv_len;
774 /* Index generation function */
775 int caseExactIA5Indexer(
779 struct berval *prefix,
780 struct berval **values,
781 struct berval ***keysp )
785 struct berval **keys;
786 lutil_MD5_CTX MD5context;
787 unsigned char MD5digest[16];
788 struct berval digest;
789 digest.bv_val = MD5digest;
790 digest.bv_len = sizeof(MD5digest);
792 for( i=0; values[i] != NULL; i++ ) {
793 /* just count them */
798 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
800 slen = strlen( syntax->ssyn_oid );
801 mlen = strlen( mr->smr_oid );
803 for( i=0; values[i] != NULL; i++ ) {
804 struct berval *value = values[i];
806 lutil_MD5Init( &MD5context );
807 if( prefix != NULL && prefix->bv_len > 0 ) {
808 lutil_MD5Update( &MD5context,
809 prefix->bv_val, prefix->bv_len );
811 lutil_MD5Update( &MD5context,
812 syntax->ssyn_oid, slen );
813 lutil_MD5Update( &MD5context,
815 lutil_MD5Update( &MD5context,
816 value->bv_val, value->bv_len );
817 lutil_MD5Final( MD5digest, &MD5context );
819 keys[i] = ber_bvdup( &digest );
827 /* Index generation function */
828 int caseExactIA5Filter(
832 struct berval *prefix,
834 struct berval ***keysp )
837 struct berval **keys;
838 lutil_MD5_CTX MD5context;
839 unsigned char MD5digest[LUTIL_MD5_BYTES];
840 struct berval *value;
841 struct berval digest;
842 digest.bv_val = MD5digest;
843 digest.bv_len = sizeof(MD5digest);
845 slen = strlen( syntax->ssyn_oid );
846 mlen = strlen( mr->smr_oid );
848 value = (struct berval *) assertValue;
850 keys = ch_malloc( sizeof( struct berval * ) * 2 );
852 lutil_MD5Init( &MD5context );
853 if( prefix != NULL && prefix->bv_len > 0 ) {
854 lutil_MD5Update( &MD5context,
855 prefix->bv_val, prefix->bv_len );
857 lutil_MD5Update( &MD5context,
858 syntax->ssyn_oid, slen );
859 lutil_MD5Update( &MD5context,
861 lutil_MD5Update( &MD5context,
862 value->bv_val, value->bv_len );
863 lutil_MD5Final( MD5digest, &MD5context );
865 keys[0] = ber_bvdup( &digest );
871 /* Substrings Index generation function */
872 int caseExactIA5SubstringsIndexer(
876 struct berval *prefix,
877 struct berval **values,
878 struct berval ***keysp )
882 struct berval **keys;
883 lutil_MD5_CTX MD5context;
884 unsigned char MD5digest[16];
885 struct berval digest;
886 digest.bv_val = MD5digest;
887 digest.bv_len = sizeof(MD5digest);
890 if( flags & SLAP_MR_SUBSTR_INITIAL ) types++;
891 if( flags & SLAP_MR_SUBSTR_FINAL ) types++;
892 /* no SUBSTR_ANY indexing */
895 for( i=0; values[i] != NULL; i++ ) {
896 /* count number of indices to generate */
897 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
901 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
902 nkeys += SLAP_INDEX_SUBSTR_MAXLEN - ( SLAP_INDEX_SUBSTR_MINLEN - 1);
904 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
910 /* no keys to generate */
915 nkeys *= types; /* We need to generate keys for each type */
916 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
918 slen = strlen( syntax->ssyn_oid );
919 mlen = strlen( mr->smr_oid );
922 for( i=0; values[i] != NULL; i++ ) {
924 struct berval *value;
928 if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
930 max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
931 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
933 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
936 if( flags & SLAP_MR_SUBSTR_INITIAL ) {
937 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
938 lutil_MD5Init( &MD5context );
939 if( prefix != NULL && prefix->bv_len > 0 ) {
940 lutil_MD5Update( &MD5context,
941 prefix->bv_val, prefix->bv_len );
943 lutil_MD5Update( &MD5context,
944 &pre, sizeof( pre ) );
945 lutil_MD5Update( &MD5context,
946 syntax->ssyn_oid, slen );
947 lutil_MD5Update( &MD5context,
949 lutil_MD5Update( &MD5context,
951 lutil_MD5Final( MD5digest, &MD5context );
953 keys[nkeys++] = ber_bvdup( &digest );
956 if( flags & SLAP_MR_SUBSTR_FINAL ) {
957 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
958 lutil_MD5Init( &MD5context );
959 if( prefix != NULL && prefix->bv_len > 0 ) {
960 lutil_MD5Update( &MD5context,
961 prefix->bv_val, prefix->bv_len );
963 lutil_MD5Update( &MD5context,
964 &pre, sizeof( pre ) );
965 lutil_MD5Update( &MD5context,
966 syntax->ssyn_oid, slen );
967 lutil_MD5Update( &MD5context,
969 lutil_MD5Update( &MD5context,
970 &value->bv_val[value->bv_len-j], j );
971 lutil_MD5Final( MD5digest, &MD5context );
973 keys[nkeys++] = ber_bvdup( &digest );
984 int caseExactIA5SubstringsFilter(
988 struct berval *prefix,
990 struct berval ***keysp )
992 SubstringsAssertion *sa = assertValue;
995 size_t slen, mlen, klen;
996 struct berval **keys;
997 lutil_MD5_CTX MD5context;
998 unsigned char MD5digest[LUTIL_MD5_BYTES];
999 struct berval *value;
1000 struct berval digest;
1002 if( sa->sa_initial != NULL &&
1003 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1007 if( sa->sa_final != NULL &&
1008 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1015 return LDAP_SUCCESS;
1018 digest.bv_val = MD5digest;
1019 digest.bv_len = sizeof(MD5digest);
1021 slen = strlen( syntax->ssyn_oid );
1022 mlen = strlen( mr->smr_oid );
1024 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1027 if( sa->sa_initial != NULL &&
1028 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1030 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1031 value = sa->sa_initial;
1033 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1034 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1036 lutil_MD5Init( &MD5context );
1037 if( prefix != NULL && prefix->bv_len > 0 ) {
1038 lutil_MD5Update( &MD5context,
1039 prefix->bv_val, prefix->bv_len );
1041 lutil_MD5Update( &MD5context,
1042 &pre, sizeof( pre ) );
1043 lutil_MD5Update( &MD5context,
1044 syntax->ssyn_oid, slen );
1045 lutil_MD5Update( &MD5context,
1046 mr->smr_oid, mlen );
1047 lutil_MD5Update( &MD5context,
1048 value->bv_val, klen );
1049 lutil_MD5Final( MD5digest, &MD5context );
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 keys[nkeys++] = ber_bvdup( &digest );
1084 return LDAP_SUCCESS;
1093 struct berval *value,
1094 void *assertedValue )
1096 int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
1099 match = strncasecmp( value->bv_val,
1100 ((struct berval *) assertedValue)->bv_val,
1105 return LDAP_SUCCESS;
1108 static char *strcasechr( const char *str, int c )
1110 char *lower = strchr( str, TOLOWER(c) );
1111 char *upper = strchr( str, TOUPPER(c) );
1113 if( lower && upper ) {
1114 return lower < upper ? lower : upper;
1115 } else if ( lower ) {
1123 caseIgnoreIA5SubstringsMatch(
1128 struct berval *value,
1129 void *assertedValue )
1132 SubstringsAssertion *sub = assertedValue;
1133 struct berval left = *value;
1137 /* Add up asserted input length */
1138 if( sub->sa_initial ) {
1139 inlen += sub->sa_initial->bv_len;
1142 for(i=0; sub->sa_any[i] != NULL; i++) {
1143 inlen += sub->sa_any[i]->bv_len;
1146 if( sub->sa_final ) {
1147 inlen += sub->sa_final->bv_len;
1150 if( sub->sa_initial ) {
1151 if( inlen > left.bv_len ) {
1156 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
1157 sub->sa_initial->bv_len );
1163 left.bv_val += sub->sa_initial->bv_len;
1164 left.bv_len -= sub->sa_initial->bv_len;
1165 inlen -= sub->sa_initial->bv_len;
1168 if( sub->sa_final ) {
1169 if( inlen > left.bv_len ) {
1174 match = strncasecmp( sub->sa_final->bv_val,
1175 &left.bv_val[left.bv_len - sub->sa_final->bv_len],
1176 sub->sa_final->bv_len );
1182 left.bv_len -= sub->sa_final->bv_len;
1183 inlen -= sub->sa_final->bv_len;
1187 for(i=0; sub->sa_any[i]; i++) {
1192 if( inlen > left.bv_len ) {
1193 /* not enough length */
1198 if( sub->sa_any[i]->bv_len == 0 ) {
1202 p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
1209 idx = p - left.bv_val;
1210 assert( idx < left.bv_len );
1212 if( idx >= left.bv_len ) {
1213 /* this shouldn't happen */
1220 if( sub->sa_any[i]->bv_len > left.bv_len ) {
1221 /* not enough left */
1226 match = strncasecmp( left.bv_val,
1227 sub->sa_any[i]->bv_val,
1228 sub->sa_any[i]->bv_len );
1237 left.bv_val += sub->sa_any[i]->bv_len;
1238 left.bv_len -= sub->sa_any[i]->bv_len;
1239 inlen -= sub->sa_any[i]->bv_len;
1245 return LDAP_SUCCESS;
1248 /* Index generation function */
1249 int caseIgnoreIA5Indexer(
1253 struct berval *prefix,
1254 struct berval **values,
1255 struct berval ***keysp )
1259 struct berval **keys;
1260 lutil_MD5_CTX MD5context;
1261 unsigned char MD5digest[16];
1262 struct berval digest;
1263 digest.bv_val = MD5digest;
1264 digest.bv_len = sizeof(MD5digest);
1266 for( i=0; values[i] != NULL; i++ ) {
1267 /* just count them */
1272 keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
1274 slen = strlen( syntax->ssyn_oid );
1275 mlen = strlen( mr->smr_oid );
1277 for( i=0; values[i] != NULL; i++ ) {
1278 struct berval *value = ber_bvdup( values[i] );
1279 ldap_pvt_str2upper( value->bv_val );
1281 lutil_MD5Init( &MD5context );
1282 if( prefix != NULL && prefix->bv_len > 0 ) {
1283 lutil_MD5Update( &MD5context,
1284 prefix->bv_val, prefix->bv_len );
1286 lutil_MD5Update( &MD5context,
1287 syntax->ssyn_oid, slen );
1288 lutil_MD5Update( &MD5context,
1289 mr->smr_oid, mlen );
1290 lutil_MD5Update( &MD5context,
1291 value->bv_val, value->bv_len );
1292 lutil_MD5Final( MD5digest, &MD5context );
1294 ber_bvfree( value );
1296 keys[i] = ber_bvdup( &digest );
1301 return LDAP_SUCCESS;
1304 /* Index generation function */
1305 int caseIgnoreIA5Filter(
1309 struct berval *prefix,
1311 struct berval ***keysp )
1314 struct berval **keys;
1315 lutil_MD5_CTX MD5context;
1316 unsigned char MD5digest[LUTIL_MD5_BYTES];
1317 struct berval *value;
1318 struct berval digest;
1319 digest.bv_val = MD5digest;
1320 digest.bv_len = sizeof(MD5digest);
1322 slen = strlen( syntax->ssyn_oid );
1323 mlen = strlen( mr->smr_oid );
1325 value = ber_bvdup( (struct berval *) assertValue );
1326 ldap_pvt_str2upper( value->bv_val );
1328 keys = ch_malloc( sizeof( struct berval * ) * 2 );
1330 lutil_MD5Init( &MD5context );
1331 if( prefix != NULL && prefix->bv_len > 0 ) {
1332 lutil_MD5Update( &MD5context,
1333 prefix->bv_val, prefix->bv_len );
1335 lutil_MD5Update( &MD5context,
1336 syntax->ssyn_oid, slen );
1337 lutil_MD5Update( &MD5context,
1338 mr->smr_oid, mlen );
1339 lutil_MD5Update( &MD5context,
1340 value->bv_val, value->bv_len );
1341 lutil_MD5Final( MD5digest, &MD5context );
1343 keys[0] = ber_bvdup( &digest );
1346 ber_bvfree( value );
1349 return LDAP_SUCCESS;
1352 /* Substrings Index generation function */
1353 int caseIgnoreIA5SubstringsIndexer(
1357 struct berval *prefix,
1358 struct berval **values,
1359 struct berval ***keysp )
1361 int i, nkeys, types;
1363 struct berval **keys;
1364 lutil_MD5_CTX MD5context;
1365 unsigned char MD5digest[16];
1366 struct berval digest;
1367 digest.bv_val = MD5digest;
1368 digest.bv_len = sizeof(MD5digest);
1371 if( flags & SLAP_MR_SUBSTR_INITIAL ) types++;
1372 if( flags & SLAP_MR_SUBSTR_FINAL ) types++;
1373 /* no SUBSTR_ANY indexing */
1376 for( i=0; values[i] != NULL; i++ ) {
1377 /* count number of indices to generate */
1378 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) {
1382 if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
1383 nkeys += SLAP_INDEX_SUBSTR_MAXLEN - ( SLAP_INDEX_SUBSTR_MINLEN - 1);
1385 nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
1391 /* no keys to generate */
1393 return LDAP_SUCCESS;
1396 nkeys *= types; /* We need to generate keys for each type */
1397 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1399 slen = strlen( syntax->ssyn_oid );
1400 mlen = strlen( mr->smr_oid );
1403 for( i=0; values[i] != NULL; i++ ) {
1405 struct berval *value;
1407 if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
1409 max = SLAP_INDEX_SUBSTR_MAXLEN < values[i]->bv_len
1410 ? SLAP_INDEX_SUBSTR_MAXLEN : values[i]->bv_len;
1412 value = ber_bvdup( values[i] );
1413 ldap_pvt_str2upper( value->bv_val );
1415 for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
1418 if( flags & SLAP_MR_SUBSTR_INITIAL ) {
1419 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1420 lutil_MD5Init( &MD5context );
1421 if( prefix != NULL && prefix->bv_len > 0 ) {
1422 lutil_MD5Update( &MD5context,
1423 prefix->bv_val, prefix->bv_len );
1425 lutil_MD5Update( &MD5context,
1426 &pre, sizeof( pre ) );
1427 lutil_MD5Update( &MD5context,
1428 syntax->ssyn_oid, slen );
1429 lutil_MD5Update( &MD5context,
1430 mr->smr_oid, mlen );
1431 lutil_MD5Update( &MD5context,
1433 lutil_MD5Final( MD5digest, &MD5context );
1435 keys[nkeys++] = ber_bvdup( &digest );
1438 if( flags & SLAP_MR_SUBSTR_FINAL ) {
1439 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1440 lutil_MD5Init( &MD5context );
1441 if( prefix != NULL && prefix->bv_len > 0 ) {
1442 lutil_MD5Update( &MD5context,
1443 prefix->bv_val, prefix->bv_len );
1445 lutil_MD5Update( &MD5context,
1446 &pre, sizeof( pre ) );
1447 lutil_MD5Update( &MD5context,
1448 syntax->ssyn_oid, slen );
1449 lutil_MD5Update( &MD5context,
1450 mr->smr_oid, mlen );
1451 lutil_MD5Update( &MD5context,
1452 &value->bv_val[value->bv_len-j], j );
1453 lutil_MD5Final( MD5digest, &MD5context );
1455 keys[nkeys++] = ber_bvdup( &digest );
1460 ber_bvfree( value );
1465 return LDAP_SUCCESS;
1468 int caseIgnoreIA5SubstringsFilter(
1472 struct berval *prefix,
1474 struct berval ***keysp )
1476 SubstringsAssertion *sa = assertValue;
1479 size_t slen, mlen, klen;
1480 struct berval **keys;
1481 lutil_MD5_CTX MD5context;
1482 unsigned char MD5digest[LUTIL_MD5_BYTES];
1483 struct berval *value;
1484 struct berval digest;
1486 if( sa->sa_initial != NULL &&
1487 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1491 if( sa->sa_final != NULL &&
1492 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1499 return LDAP_SUCCESS;
1502 digest.bv_val = MD5digest;
1503 digest.bv_len = sizeof(MD5digest);
1505 slen = strlen( syntax->ssyn_oid );
1506 mlen = strlen( mr->smr_oid );
1508 keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
1511 if( sa->sa_initial != NULL &&
1512 sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1514 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
1515 value = ber_bvdup( sa->sa_initial );
1516 ldap_pvt_str2upper( value->bv_val );
1518 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1519 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1521 lutil_MD5Init( &MD5context );
1522 if( prefix != NULL && prefix->bv_len > 0 ) {
1523 lutil_MD5Update( &MD5context,
1524 prefix->bv_val, prefix->bv_len );
1526 lutil_MD5Update( &MD5context,
1527 &pre, sizeof( pre ) );
1528 lutil_MD5Update( &MD5context,
1529 syntax->ssyn_oid, slen );
1530 lutil_MD5Update( &MD5context,
1531 mr->smr_oid, mlen );
1532 lutil_MD5Update( &MD5context,
1533 value->bv_val, klen );
1534 lutil_MD5Final( MD5digest, &MD5context );
1536 ber_bvfree( value );
1537 keys[nkeys++] = ber_bvdup( &digest );
1540 if( sa->sa_final != NULL &&
1541 sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
1543 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
1544 value = ber_bvdup( sa->sa_final );
1545 ldap_pvt_str2upper( value->bv_val );
1547 klen = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
1548 ? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
1550 lutil_MD5Init( &MD5context );
1551 if( prefix != NULL && prefix->bv_len > 0 ) {
1552 lutil_MD5Update( &MD5context,
1553 prefix->bv_val, prefix->bv_len );
1555 lutil_MD5Update( &MD5context,
1556 &pre, sizeof( pre ) );
1557 lutil_MD5Update( &MD5context,
1558 syntax->ssyn_oid, slen );
1559 lutil_MD5Update( &MD5context,
1560 mr->smr_oid, mlen );
1561 lutil_MD5Update( &MD5context,
1562 &value->bv_val[value->bv_len-klen], klen );
1563 lutil_MD5Final( MD5digest, &MD5context );
1565 ber_bvfree( value );
1566 keys[nkeys++] = ber_bvdup( &digest );
1572 return LDAP_SUCCESS;
1576 numericStringNormalize(
1579 struct berval **normalized )
1581 /* similiar to IA5StringNormalize except removes all spaces */
1582 struct berval *newval;
1585 newval = ch_malloc( sizeof( struct berval ) );
1589 /* Ignore initial whitespace */
1590 while ( ASCII_SPACE( *p ) ) {
1596 return LDAP_INVALID_SYNTAX;
1599 newval->bv_val = ch_strdup( p );
1600 p = q = newval->bv_val;
1603 if ( ASCII_SPACE( *p ) ) {
1604 /* Ignore whitespace */
1611 assert( *newval->bv_val );
1612 assert( newval->bv_val < p );
1615 /* cannot start with a space */
1616 assert( !ASCII_SPACE(*newval->bv_val) );
1618 /* cannot end with a space */
1619 assert( !ASCII_SPACE( q[-1] ) );
1621 /* null terminate */
1624 newval->bv_len = q - newval->bv_val;
1625 *normalized = newval;
1627 return LDAP_SUCCESS;
1631 objectIdentifierFirstComponentMatch(
1636 struct berval *value,
1637 void *assertedValue )
1639 int rc = LDAP_SUCCESS;
1641 struct berval *asserted = (struct berval *) assertedValue;
1645 if( value->bv_len == 0 || value->bv_val[0] != '(' /*')'*/ ) {
1646 return LDAP_INVALID_SYNTAX;
1649 /* trim leading white space */
1650 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < value->bv_len; i++ ) {
1654 /* grab next word */
1655 oid.bv_val = &value->bv_val[i];
1656 oid.bv_len = value->bv_len - i;
1657 for( i=1; ASCII_SPACE(value->bv_val[i]) && i < oid.bv_len; i++ ) {
1662 /* insert attributeTypes, objectclass check here */
1663 if( OID_LEADCHAR(asserted->bv_val[0]) ) {
1664 rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
1667 char *stored = ch_malloc( oid.bv_len + 1 );
1668 AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
1669 stored[oid.bv_len] = '\0';
1671 if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
1672 MatchingRule *asserted_mr = mr_find( asserted->bv_val );
1673 MatchingRule *stored_mr = mr_find( stored );
1675 if( asserted_mr == NULL ) {
1676 rc = SLAPD_COMPARE_UNDEFINED;
1678 match = asserted_mr != stored_mr;
1681 } else if ( !strcmp( syntax->ssyn_oid,
1682 SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
1684 AttributeType *asserted_at = at_find( asserted->bv_val );
1685 AttributeType *stored_at = at_find( stored );
1687 if( asserted_at == NULL ) {
1688 rc = SLAPD_COMPARE_UNDEFINED;
1690 match = asserted_at != stored_at;
1693 } else if ( !strcmp( syntax->ssyn_oid,
1694 SLAP_SYNTAX_OBJECTCLASSES_OID ) )
1696 ObjectClass *asserted_oc = oc_find( asserted->bv_val );
1697 ObjectClass *stored_oc = oc_find( stored );
1699 if( asserted_oc == NULL ) {
1700 rc = SLAPD_COMPARE_UNDEFINED;
1702 match = asserted_oc != stored_oc;
1709 Debug( LDAP_DEBUG_ARGS, "objectIdentifierFirstComponentMatch "
1710 "%d\n\t\"%s\"\n\t\"%s\"\n",
1711 match, value->bv_val, asserted->bv_val );
1713 if( rc == LDAP_SUCCESS ) *matchp = match;
1718 check_time_syntax (struct berval *val,
1722 static int ceiling[9] = { 99, 99, 11, 30, 23, 59, 59, 12, 59 };
1723 static int mdays[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
1725 int part, c, neg = 0;
1727 if( val->bv_len == 0 )
1728 return LDAP_INVALID_SYNTAX;
1730 p = (char *)val->bv_val;
1731 e = p + val->bv_len;
1733 /* Ignore initial whitespace */
1734 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
1738 if (e - p < 13 - (2 * start))
1739 return LDAP_INVALID_SYNTAX;
1741 for (part = 0; part < 9; part++)
1744 for (part = start; part < 7; part++) {
1757 return LDAP_INVALID_SYNTAX;
1759 return LDAP_INVALID_SYNTAX;
1764 return LDAP_INVALID_SYNTAX;
1766 return LDAP_INVALID_SYNTAX;
1770 if (part == 2 || part == 3)
1772 if (parts[part] < 0)
1773 return LDAP_INVALID_SYNTAX;
1774 if (parts[part] > ceiling[part])
1775 return LDAP_INVALID_SYNTAX;
1777 if (parts[2] == 1) {
1778 if (parts[3] > mdays[parts[2]])
1779 return LDAP_INVALID_SYNTAX;
1780 if (parts[1] & 0x03) {
1781 /* FIXME: This is an incomplete leap-year
1782 * check that fails in 2100, 2200, 2300,
1783 * 2500, 2600, 2700, ...
1785 if (parts[3] > mdays[parts[2]] - 1)
1786 return LDAP_INVALID_SYNTAX;
1792 } else if (c != '+' && c != '-') {
1793 return LDAP_INVALID_SYNTAX;
1798 return LDAP_INVALID_SYNTAX;
1799 for (part = 7; part < 9; part++) {
1802 return LDAP_INVALID_SYNTAX;
1807 return LDAP_INVALID_SYNTAX;
1810 if (parts[part] < 0 || parts[part] > ceiling[part])
1811 return LDAP_INVALID_SYNTAX;
1815 /* Ignore trailing whitespace */
1816 while ( ( p < e ) && ASCII_SPACE( *p ) ) {
1820 return LDAP_INVALID_SYNTAX;
1823 parts[4] += parts[7];
1824 parts[5] += parts[8];
1825 for (part = 7; --part > 0; ) {
1829 /* FIXME: This is an incomplete leap-year
1830 * check that fails in 2100, 2200, 2300,
1831 * 2500, 2600, 2700, ...
1833 c = mdays[parts[2]];
1837 if (parts[part] > c) {
1838 parts[part] -= c + 1;
1843 parts[4] -= parts[7];
1844 parts[5] -= parts[8];
1845 for (part = 7; --part > 0; ) {
1849 /* FIXME: This is an incomplete leap-year
1850 * check that fails in 2100, 2200, 2300,
1851 * 2500, 2600, 2700, ...
1853 c = mdays[(parts[2] - 1) % 12];
1857 if (parts[part] < 0) {
1858 parts[part] += c + 1;
1864 return LDAP_SUCCESS;
1871 struct berval **normalized )
1876 rc = check_time_syntax(val, 1, parts);
1877 if (rc != LDAP_SUCCESS) {
1882 out = ch_malloc( sizeof(struct berval) );
1884 return LBER_ERROR_MEMORY;
1886 out->bv_val = ch_malloc( 14 );
1887 if ( out->bv_val == NULL ) {
1889 return LBER_ERROR_MEMORY;
1892 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ldZ",
1893 parts[1], parts[2] + 1, parts[3] + 1,
1894 parts[4], parts[5], parts[6] );
1898 return LDAP_SUCCESS;
1908 return check_time_syntax(in, 1, parts);
1912 generalizedTimeValidate(
1918 return check_time_syntax(in, 0, parts);
1922 generalizedTimeNormalize(
1925 struct berval **normalized )
1930 rc = check_time_syntax(val, 0, parts);
1931 if (rc != LDAP_SUCCESS) {
1936 out = ch_malloc( sizeof(struct berval) );
1938 return LBER_ERROR_MEMORY;
1940 out->bv_val = ch_malloc( 16 );
1941 if ( out->bv_val == NULL ) {
1943 return LBER_ERROR_MEMORY;
1946 sprintf( out->bv_val, "%02ld%02ld%02ld%02ld%02ld%02ld%02ldZ",
1947 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
1948 parts[4], parts[5], parts[6] );
1952 return LDAP_SUCCESS;
1955 struct syntax_defs_rec {
1958 slap_syntax_validate_func *sd_validate;
1959 slap_syntax_transform_func *sd_normalize;
1960 slap_syntax_transform_func *sd_pretty;
1961 #ifdef SLAPD_BINARY_CONVERSION
1962 slap_syntax_transform_func *sd_ber2str;
1963 slap_syntax_transform_func *sd_str2ber;
1967 #define X_HIDE "X-HIDE 'TRUE' "
1968 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
1969 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
1971 struct syntax_defs_rec syntax_defs[] = {
1972 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
1973 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
1974 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
1975 0, NULL, NULL, NULL},
1976 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
1977 0, NULL, NULL, NULL},
1978 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
1979 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
1980 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
1981 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1982 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
1983 0, bitStringValidate, bitStringNormalize, NULL },
1984 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
1985 0, booleanValidate, NULL, NULL},
1986 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
1987 X_BINARY X_NOT_H_R ")",
1988 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1989 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
1990 X_BINARY X_NOT_H_R ")",
1991 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1992 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
1993 X_BINARY X_NOT_H_R ")",
1994 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1995 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
1996 0, NULL, NULL, NULL},
1997 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
1998 0, dnValidate, dnNormalize, dnPretty},
1999 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
2000 0, NULL, NULL, NULL},
2001 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
2002 0, NULL, NULL, NULL},
2003 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
2004 0, UTF8StringValidate, UTF8StringNormalize, NULL},
2005 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
2006 0, NULL, NULL, NULL},
2007 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
2008 0, NULL, NULL, NULL},
2009 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
2010 0, NULL, NULL, NULL},
2011 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
2012 0, NULL, NULL, NULL},
2013 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
2014 0, NULL, NULL, NULL},
2015 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
2016 0, IA5StringValidate, faxNumberNormalize, NULL},
2017 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
2018 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
2019 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
2020 0, generalizedTimeValidate, generalizedTimeNormalize, NULL},
2021 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
2022 0, NULL, NULL, NULL},
2023 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
2024 0, IA5StringValidate, IA5StringNormalize, NULL},
2025 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
2026 0, integerValidate, integerNormalize, integerPretty},
2027 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
2028 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
2029 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
2030 0, NULL, NULL, NULL},
2031 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
2032 0, NULL, NULL, NULL},
2033 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
2034 0, NULL, NULL, NULL},
2035 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
2036 0, NULL, NULL, NULL},
2037 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
2038 0, NULL, NULL, NULL},
2039 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
2040 0, NULL, NULL, NULL},
2041 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
2042 0, NULL, NULL, NULL},
2043 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
2044 0, IA5StringValidate, numericStringNormalize, NULL},
2045 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
2046 0, NULL, NULL, NULL},
2047 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
2048 0, oidValidate, NULL, NULL},
2049 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
2050 0, NULL, NULL, NULL},
2051 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
2052 0, blobValidate, NULL, NULL},
2053 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
2054 0, blobValidate, NULL, NULL},
2055 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
2056 0, NULL, NULL, NULL},
2057 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
2058 0, NULL, NULL, NULL},
2059 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
2060 0, printableStringValidate, NULL, NULL},
2061 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
2062 X_BINARY X_NOT_H_R ")",
2063 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
2064 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
2065 0, IA5StringValidate, phoneNumberNormalize, NULL},
2066 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
2067 0, NULL, NULL, NULL},
2068 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
2069 0, IA5StringValidate, telexNumberNormalize, NULL},
2070 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
2071 0, utcTimeValidate, utcTimeNormalize, NULL},
2072 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
2073 0, NULL, NULL, NULL},
2074 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
2075 0, NULL, NULL, NULL},
2076 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
2077 0, NULL, NULL, NULL},
2078 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
2079 0, NULL, NULL, NULL},
2080 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
2081 0, NULL, NULL, NULL},
2083 /* OpenLDAP Experimental Syntaxes */
2084 {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
2085 0, IA5StringValidate /* THIS WILL CHANGE FOR NEW ACI SYNTAX */, NULL, NULL},
2086 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
2087 0, NULL, NULL, NULL},
2088 {"( 1.3.6.1.4.1.4203.666.2.3 DESC 'OpenLDAP void' " X_HIDE ")" ,
2089 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
2090 #if 0 /* not needed */
2091 {"( 1.3.6.1.4.1.4203.666.2.4 DESC 'OpenLDAP DN' " X_HIDE ")" ,
2092 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
2095 {NULL, 0, NULL, NULL, NULL}
2098 struct mrule_defs_rec {
2101 slap_mr_convert_func * mrd_convert;
2102 slap_mr_normalize_func * mrd_normalize;
2103 slap_mr_match_func * mrd_match;
2104 slap_mr_indexer_func * mrd_indexer;
2105 slap_mr_filter_func * mrd_filter;
2107 char * mrd_associated;
2111 * Other matching rules in X.520 that we do not use (yet):
2113 * 2.5.13.9 numericStringOrderingMatch
2114 * 2.5.13.13 booleanMatch
2115 * 2.5.13.15 integerOrderingMatch
2116 * 2.5.13.18 octetStringOrderingMatch
2117 * 2.5.13.19 octetStringSubstringsMatch
2118 * 2.5.13.25 uTCTimeMatch
2119 * 2.5.13.26 uTCTimeOrderingMatch
2120 * 2.5.13.31 directoryStringFirstComponentMatch
2121 * 2.5.13.32 wordMatch
2122 * 2.5.13.33 keywordMatch
2123 * 2.5.13.34 certificateExactMatch
2124 * 2.5.13.35 certificateMatch
2125 * 2.5.13.36 certificatePairExactMatch
2126 * 2.5.13.37 certificatePairMatch
2127 * 2.5.13.38 certificateListExactMatch
2128 * 2.5.13.39 certificateListMatch
2129 * 2.5.13.40 algorithmIdentifierMatch
2130 * 2.5.13.41 storedPrefixMatch
2131 * 2.5.13.42 attributeCertificateMatch
2132 * 2.5.13.43 readerAndKeyIDMatch
2133 * 2.5.13.44 attributeIntegrityMatch
2136 struct mrule_defs_rec mrule_defs[] = {
2138 * EQUALITY matching rules must be listed after associated APPROX
2139 * matching rules. So, we list all APPROX matching rules first.
2141 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
2142 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2143 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
2145 directoryStringApproxMatch, NULL, NULL,
2148 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
2149 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2150 SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT,
2152 IA5StringApproxMatch, NULL, NULL,
2156 * Other matching rules
2159 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
2160 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
2161 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2163 objectIdentifierMatch, caseIgnoreIA5Indexer, caseIgnoreIA5Filter,
2166 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
2167 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
2168 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2170 dnMatch, dnIndexer, dnFilter,
2173 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
2174 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2175 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2177 caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter,
2178 directoryStringApproxMatchOID },
2180 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
2181 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2184 caseIgnoreOrderingMatch, NULL, NULL,
2187 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
2188 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2189 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2191 caseIgnoreSubstringsMatch,
2192 caseIgnoreSubstringsIndexer,
2193 caseIgnoreSubstringsFilter,
2196 {"( 2.5.13.5 NAME 'caseExactMatch' "
2197 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2198 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2200 caseExactMatch, caseExactIndexer, caseExactFilter,
2201 directoryStringApproxMatchOID },
2203 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
2204 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
2207 caseExactOrderingMatch, NULL, NULL,
2210 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
2211 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2212 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2214 caseExactSubstringsMatch,
2215 caseExactSubstringsIndexer,
2216 caseExactSubstringsFilter,
2219 {"( 2.5.13.8 NAME 'numericStringMatch' "
2220 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
2221 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2223 caseIgnoreIA5Match, NULL, NULL,
2226 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
2227 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2228 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2230 caseIgnoreIA5SubstringsMatch,
2231 caseIgnoreIA5SubstringsIndexer,
2232 caseIgnoreIA5SubstringsFilter,
2235 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
2236 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
2237 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2239 caseIgnoreListMatch, NULL, NULL,
2242 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
2243 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2244 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2246 caseIgnoreListSubstringsMatch, NULL, NULL,
2249 {"( 2.5.13.13 NAME 'booleanMatch' "
2250 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
2251 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2253 booleanMatch, NULL, NULL,
2256 {"( 2.5.13.14 NAME 'integerMatch' "
2257 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
2258 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2260 integerMatch, NULL, NULL,
2263 {"( 2.5.13.16 NAME 'bitStringMatch' "
2264 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
2265 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2267 bitStringMatch, NULL, NULL,
2270 {"( 2.5.13.17 NAME 'octetStringMatch' "
2271 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
2272 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2274 octetStringMatch, octetStringIndexer, octetStringFilter,
2277 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
2278 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
2279 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2281 telephoneNumberMatch, NULL, NULL,
2284 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
2285 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
2286 SLAP_MR_SUBSTR | SLAP_MR_EXT,
2288 telephoneNumberSubstringsMatch, NULL, NULL,
2291 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
2292 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
2293 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2295 presentationAddressMatch, NULL, NULL,
2298 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
2299 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
2300 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2302 uniqueMemberMatch, NULL, NULL,
2305 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
2306 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
2307 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2309 protocolInformationMatch, NULL, NULL,
2312 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
2313 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
2314 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2316 generalizedTimeMatch, NULL, NULL,
2319 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
2320 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
2323 generalizedTimeOrderingMatch, NULL, NULL,
2326 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
2327 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
2328 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2330 integerFirstComponentMatch, NULL, NULL,
2333 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
2334 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
2335 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2337 objectIdentifierFirstComponentMatch, NULL, NULL,
2340 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
2341 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2342 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2344 caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
2345 IA5StringApproxMatchOID },
2347 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
2348 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2349 SLAP_MR_EQUALITY | SLAP_MR_EXT,
2351 caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter,
2352 IA5StringApproxMatchOID },
2354 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
2355 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2358 caseIgnoreIA5SubstringsMatch,
2359 caseIgnoreIA5SubstringsIndexer,
2360 caseIgnoreIA5SubstringsFilter,
2363 {"( 1.3.6.1.4.1.4203.666.4.3 NAME 'caseExactIA5SubstringsMatch' "
2364 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
2367 caseExactIA5SubstringsMatch,
2368 caseExactIA5SubstringsIndexer,
2369 caseExactIA5SubstringsFilter,
2372 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
2373 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
2376 authPasswordMatch, NULL, NULL,
2379 {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
2380 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
2383 OpenLDAPaciMatch, NULL, NULL,
2386 {NULL, SLAP_MR_NONE, NULL, NULL, NULL, NULL}
2395 /* we should only be called once (from main) */
2396 assert( schema_init_done == 0 );
2398 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
2399 res = register_syntax( syntax_defs[i].sd_desc,
2400 syntax_defs[i].sd_flags,
2401 syntax_defs[i].sd_validate,
2402 syntax_defs[i].sd_normalize,
2403 syntax_defs[i].sd_pretty
2404 #ifdef SLAPD_BINARY_CONVERSION
2406 syntax_defs[i].sd_ber2str,
2407 syntax_defs[i].sd_str2ber
2412 fprintf( stderr, "schema_init: Error registering syntax %s\n",
2413 syntax_defs[i].sd_desc );
2418 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
2419 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
2421 "schema_init: Ingoring unusable matching rule %s\n",
2422 mrule_defs[i].mrd_desc );
2426 res = register_matching_rule(
2427 mrule_defs[i].mrd_desc,
2428 mrule_defs[i].mrd_usage,
2429 mrule_defs[i].mrd_convert,
2430 mrule_defs[i].mrd_normalize,
2431 mrule_defs[i].mrd_match,
2432 mrule_defs[i].mrd_indexer,
2433 mrule_defs[i].mrd_filter,
2434 mrule_defs[i].mrd_associated );
2438 "schema_init: Error registering matching rule %s\n",
2439 mrule_defs[i].mrd_desc );
2443 schema_init_done = 1;
2444 return LDAP_SUCCESS;