1 /* schema_init.c - init builtin schema */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2007 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
26 #include <ac/string.h>
27 #include <ac/socket.h>
30 #include "../../libraries/liblber/lber-int.h" /* get ber_ptrlen() */
32 #include "ldap_utf8.h"
35 #include "lutil_hash.h"
36 #define HASH_BYTES LUTIL_HASH_BYTES
37 #define HASH_CONTEXT lutil_HASH_CTX
38 #define HASH_Init(c) lutil_HASHInit(c)
39 #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len)
40 #define HASH_Final(d,c) lutil_HASHFinal(d,c)
42 /* approx matching rules */
43 #define directoryStringApproxMatchOID "1.3.6.1.4.1.4203.666.4.4"
44 #define directoryStringApproxMatch approxMatch
45 #define directoryStringApproxIndexer approxIndexer
46 #define directoryStringApproxFilter approxFilter
47 #define IA5StringApproxMatchOID "1.3.6.1.4.1.4203.666.4.5"
48 #define IA5StringApproxMatch approxMatch
49 #define IA5StringApproxIndexer approxIndexer
50 #define IA5StringApproxFilter approxFilter
52 /* Change Sequence Number (CSN) - much of this will change */
53 #define csnMatch octetStringMatch
54 #define csnOrderingMatch octetStringOrderingMatch
55 #define csnIndexer generalizedTimeIndexer
56 #define csnFilter generalizedTimeFilter
58 #define authzMatch octetStringMatch
60 unsigned int index_substr_if_minlen = SLAP_INDEX_SUBSTR_IF_MINLEN_DEFAULT;
61 unsigned int index_substr_if_maxlen = SLAP_INDEX_SUBSTR_IF_MAXLEN_DEFAULT;
62 unsigned int index_substr_any_len = SLAP_INDEX_SUBSTR_ANY_LEN_DEFAULT;
63 unsigned int index_substr_any_step = SLAP_INDEX_SUBSTR_ANY_STEP_DEFAULT;
65 ldap_pvt_thread_mutex_t ad_undef_mutex;
66 ldap_pvt_thread_mutex_t oc_undef_mutex;
69 generalizedTimeValidate(
78 /* no value allowed */
79 return LDAP_INVALID_SYNTAX;
87 /* any value allowed */
91 #define berValidate blobValidate
98 if ( in->bv_len < 2 ) return LDAP_INVALID_SYNTAX;
99 if ( in->bv_val[0] != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
104 /* X.509 related stuff */
112 #define SLAP_X509_OPTION (LBER_CLASS_CONTEXT|LBER_CONSTRUCTED)
115 SLAP_X509_OPT_C_VERSION = SLAP_X509_OPTION + 0,
116 SLAP_X509_OPT_C_ISSUERUNIQUEID = SLAP_X509_OPTION + 1,
117 SLAP_X509_OPT_C_SUBJECTUNIQUEID = SLAP_X509_OPTION + 2,
118 SLAP_X509_OPT_C_EXTENSIONS = SLAP_X509_OPTION + 3
122 SLAP_X509_OPT_CL_CRLEXTENSIONS = SLAP_X509_OPTION + 0
125 /* X.509 certificate validation */
126 static int certificateValidate( Syntax *syntax, struct berval *in )
128 BerElementBuffer berbuf;
129 BerElement *ber = (BerElement *)&berbuf;
132 ber_int_t version = SLAP_X509_V1;
134 ber_init2( ber, in, LBER_USE_DER );
135 tag = ber_skip_tag( ber, &len ); /* Signed wrapper */
136 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
137 tag = ber_skip_tag( ber, &len ); /* Sequence */
138 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
139 tag = ber_peek_tag( ber, &len );
140 /* Optional version */
141 if ( tag == SLAP_X509_OPT_C_VERSION ) {
142 tag = ber_skip_tag( ber, &len );
143 tag = ber_get_int( ber, &version );
144 if ( tag != LBER_INTEGER ) return LDAP_INVALID_SYNTAX;
146 /* NOTE: don't try to parse Serial, because it might be longer
147 * than sizeof(ber_int_t); deferred to certificateExactNormalize() */
148 tag = ber_skip_tag( ber, &len ); /* Serial */
149 if ( tag != LBER_INTEGER ) return LDAP_INVALID_SYNTAX;
150 ber_skip_data( ber, len );
151 tag = ber_skip_tag( ber, &len ); /* Signature Algorithm */
152 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
153 ber_skip_data( ber, len );
154 tag = ber_skip_tag( ber, &len ); /* Issuer DN */
155 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
156 ber_skip_data( ber, len );
157 tag = ber_skip_tag( ber, &len ); /* Validity */
158 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
159 ber_skip_data( ber, len );
160 tag = ber_skip_tag( ber, &len ); /* Subject DN */
161 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
162 ber_skip_data( ber, len );
163 tag = ber_skip_tag( ber, &len ); /* Subject PublicKeyInfo */
164 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
165 ber_skip_data( ber, len );
166 tag = ber_skip_tag( ber, &len );
167 if ( tag == SLAP_X509_OPT_C_ISSUERUNIQUEID ) { /* issuerUniqueID */
168 if ( version < SLAP_X509_V2 ) return LDAP_INVALID_SYNTAX;
169 ber_skip_data( ber, len );
170 tag = ber_skip_tag( ber, &len );
172 if ( tag == SLAP_X509_OPT_C_SUBJECTUNIQUEID ) { /* subjectUniqueID */
173 if ( version < SLAP_X509_V2 ) return LDAP_INVALID_SYNTAX;
174 ber_skip_data( ber, len );
175 tag = ber_skip_tag( ber, &len );
177 if ( tag == SLAP_X509_OPT_C_EXTENSIONS ) { /* Extensions */
178 if ( version < SLAP_X509_V3 ) return LDAP_INVALID_SYNTAX;
179 tag = ber_skip_tag( ber, &len );
180 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
181 ber_skip_data( ber, len );
182 tag = ber_skip_tag( ber, &len );
184 /* signatureAlgorithm */
185 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
186 ber_skip_data( ber, len );
187 tag = ber_skip_tag( ber, &len );
189 if ( tag != LBER_BITSTRING ) return LDAP_INVALID_SYNTAX;
190 ber_skip_data( ber, len );
191 tag = ber_skip_tag( ber, &len );
192 /* Must be at end now */
193 if ( len || tag != LBER_DEFAULT ) return LDAP_INVALID_SYNTAX;
197 /* X.509 certificate list validation */
198 static int certificateListValidate( Syntax *syntax, struct berval *in )
200 BerElementBuffer berbuf;
201 BerElement *ber = (BerElement *)&berbuf;
204 ber_int_t version = SLAP_X509_V1;
206 ber_init2( ber, in, LBER_USE_DER );
207 tag = ber_skip_tag( ber, &len ); /* Signed wrapper */
208 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
209 tag = ber_skip_tag( ber, &len ); /* Sequence */
210 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
211 tag = ber_peek_tag( ber, &len );
212 /* Optional version */
213 if ( tag == LBER_INTEGER ) {
214 tag = ber_get_int( ber, &version );
215 assert( tag == LBER_INTEGER );
216 if ( version != SLAP_X509_V2 ) return LDAP_INVALID_SYNTAX;
218 tag = ber_skip_tag( ber, &len ); /* Signature Algorithm */
219 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
220 ber_skip_data( ber, len );
221 tag = ber_skip_tag( ber, &len ); /* Issuer DN */
222 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
223 ber_skip_data( ber, len );
224 tag = ber_skip_tag( ber, &len ); /* thisUpdate */
225 /* Time is a CHOICE { UTCTime, GeneralizedTime } */
226 if ( tag != 0x17U && tag != 0x18U ) return LDAP_INVALID_SYNTAX;
227 ber_skip_data( ber, len );
228 /* Optional nextUpdate */
229 tag = ber_skip_tag( ber, &len );
230 if ( tag == 0x17U || tag == 0x18U ) {
231 ber_skip_data( ber, len );
232 tag = ber_skip_tag( ber, &len );
234 /* revokedCertificates - Sequence of Sequence, Optional */
235 if ( tag == LBER_SEQUENCE ) {
237 if ( ber_peek_tag( ber, &seqlen ) == LBER_SEQUENCE ) {
238 /* Should NOT be empty */
239 ber_skip_data( ber, len );
240 tag = ber_skip_tag( ber, &len );
243 /* Optional Extensions */
244 if ( tag == SLAP_X509_OPT_CL_CRLEXTENSIONS ) { /* ? */
245 if ( version != SLAP_X509_V2 ) return LDAP_INVALID_SYNTAX;
246 tag = ber_skip_tag( ber, &len );
247 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
248 ber_skip_data( ber, len );
249 tag = ber_skip_tag( ber, &len );
251 /* signatureAlgorithm */
252 if ( tag != LBER_SEQUENCE ) return LDAP_INVALID_SYNTAX;
253 ber_skip_data( ber, len );
254 tag = ber_skip_tag( ber, &len );
256 if ( tag != LBER_BITSTRING ) return LDAP_INVALID_SYNTAX;
257 ber_skip_data( ber, len );
258 tag = ber_skip_tag( ber, &len );
259 /* Must be at end now */
260 if ( len || tag != LBER_DEFAULT ) return LDAP_INVALID_SYNTAX;
270 struct berval *value,
271 void *assertedValue )
273 struct berval *asserted = (struct berval *) assertedValue;
274 int match = value->bv_len - asserted->bv_len;
277 match = memcmp( value->bv_val, asserted->bv_val, value->bv_len );
285 octetStringOrderingMatch(
290 struct berval *value,
291 void *assertedValue )
293 struct berval *asserted = (struct berval *) assertedValue;
294 ber_len_t v_len = value->bv_len;
295 ber_len_t av_len = asserted->bv_len;
297 int match = memcmp( value->bv_val, asserted->bv_val,
298 (v_len < av_len ? v_len : av_len) );
300 if( match == 0 ) match = v_len - av_len;
308 HASH_CONTEXT *HASHcontext,
309 struct berval *prefix,
314 HASH_Init(HASHcontext);
315 if(prefix && prefix->bv_len > 0) {
316 HASH_Update(HASHcontext,
317 (unsigned char *)prefix->bv_val, prefix->bv_len);
319 if(pre) HASH_Update(HASHcontext, (unsigned char*)&pre, sizeof(pre));
320 HASH_Update(HASHcontext, (unsigned char*)syntax->ssyn_oid, syntax->ssyn_oidlen);
321 HASH_Update(HASHcontext, (unsigned char*)mr->smr_oid, mr->smr_oidlen);
327 HASH_CONTEXT *HASHcontext,
328 unsigned char *HASHdigest,
329 unsigned char *value,
332 HASH_CONTEXT ctx = *HASHcontext;
333 HASH_Update( &ctx, value, len );
334 HASH_Final( HASHdigest, &ctx );
337 /* Index generation function */
338 int octetStringIndexer(
343 struct berval *prefix,
351 HASH_CONTEXT HASHcontext;
352 unsigned char HASHdigest[HASH_BYTES];
353 struct berval digest;
354 digest.bv_val = (char *)HASHdigest;
355 digest.bv_len = sizeof(HASHdigest);
357 for( i=0; !BER_BVISNULL( &values[i] ); i++ ) {
358 /* just count them */
361 /* we should have at least one value at this point */
364 keys = slap_sl_malloc( sizeof( struct berval ) * (i+1), ctx );
366 slen = syntax->ssyn_oidlen;
367 mlen = mr->smr_oidlen;
369 hashPreset( &HASHcontext, prefix, 0, syntax, mr);
370 for( i=0; !BER_BVISNULL( &values[i] ); i++ ) {
371 hashIter( &HASHcontext, HASHdigest,
372 (unsigned char *)values[i].bv_val, values[i].bv_len );
373 ber_dupbv_x( &keys[i], &digest, ctx );
376 BER_BVZERO( &keys[i] );
383 /* Index generation function */
384 int octetStringFilter(
389 struct berval *prefix,
390 void * assertedValue,
396 HASH_CONTEXT HASHcontext;
397 unsigned char HASHdigest[HASH_BYTES];
398 struct berval *value = (struct berval *) assertedValue;
399 struct berval digest;
400 digest.bv_val = (char *)HASHdigest;
401 digest.bv_len = sizeof(HASHdigest);
403 slen = syntax->ssyn_oidlen;
404 mlen = mr->smr_oidlen;
406 keys = slap_sl_malloc( sizeof( struct berval ) * 2, ctx );
408 hashPreset( &HASHcontext, prefix, 0, syntax, mr );
409 hashIter( &HASHcontext, HASHdigest,
410 (unsigned char *)value->bv_val, value->bv_len );
412 ber_dupbv_x( keys, &digest, ctx );
413 BER_BVZERO( &keys[1] );
421 octetStringSubstringsMatch(
426 struct berval *value,
427 void *assertedValue )
430 SubstringsAssertion *sub = assertedValue;
431 struct berval left = *value;
435 /* Add up asserted input length */
436 if ( !BER_BVISNULL( &sub->sa_initial ) ) {
437 inlen += sub->sa_initial.bv_len;
440 for ( i = 0; !BER_BVISNULL( &sub->sa_any[i] ); i++ ) {
441 inlen += sub->sa_any[i].bv_len;
444 if ( !BER_BVISNULL( &sub->sa_final ) ) {
445 inlen += sub->sa_final.bv_len;
448 if ( !BER_BVISNULL( &sub->sa_initial ) ) {
449 if ( inlen > left.bv_len ) {
454 match = memcmp( sub->sa_initial.bv_val, left.bv_val,
455 sub->sa_initial.bv_len );
461 left.bv_val += sub->sa_initial.bv_len;
462 left.bv_len -= sub->sa_initial.bv_len;
463 inlen -= sub->sa_initial.bv_len;
466 if ( !BER_BVISNULL( &sub->sa_final ) ) {
467 if ( inlen > left.bv_len ) {
472 match = memcmp( sub->sa_final.bv_val,
473 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
474 sub->sa_final.bv_len );
480 left.bv_len -= sub->sa_final.bv_len;
481 inlen -= sub->sa_final.bv_len;
485 for ( i = 0; !BER_BVISNULL( &sub->sa_any[i] ); i++ ) {
490 if ( inlen > left.bv_len ) {
491 /* not enough length */
496 if ( BER_BVISEMPTY( &sub->sa_any[i] ) ) {
500 p = memchr( left.bv_val, *sub->sa_any[i].bv_val, left.bv_len );
507 idx = p - left.bv_val;
509 if ( idx >= left.bv_len ) {
510 /* this shouldn't happen */
517 if ( sub->sa_any[i].bv_len > left.bv_len ) {
518 /* not enough left */
523 match = memcmp( left.bv_val,
524 sub->sa_any[i].bv_val,
525 sub->sa_any[i].bv_len );
533 left.bv_val += sub->sa_any[i].bv_len;
534 left.bv_len -= sub->sa_any[i].bv_len;
535 inlen -= sub->sa_any[i].bv_len;
544 /* Substrings Index generation function */
546 octetStringSubstringsIndexer(
551 struct berval *prefix,
560 HASH_CONTEXT HCany, HCini, HCfin;
561 unsigned char HASHdigest[HASH_BYTES];
562 struct berval digest;
563 digest.bv_val = (char *)HASHdigest;
564 digest.bv_len = sizeof(HASHdigest);
568 for ( i = 0; !BER_BVISNULL( &values[i] ); i++ ) {
569 /* count number of indices to generate */
570 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
571 if( values[i].bv_len >= index_substr_if_maxlen ) {
572 nkeys += index_substr_if_maxlen -
573 (index_substr_if_minlen - 1);
574 } else if( values[i].bv_len >= index_substr_if_minlen ) {
575 nkeys += values[i].bv_len - (index_substr_if_minlen - 1);
579 if( flags & SLAP_INDEX_SUBSTR_ANY ) {
580 if( values[i].bv_len >= index_substr_any_len ) {
581 nkeys += values[i].bv_len - (index_substr_any_len - 1);
585 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
586 if( values[i].bv_len >= index_substr_if_maxlen ) {
587 nkeys += index_substr_if_maxlen -
588 (index_substr_if_minlen - 1);
589 } else if( values[i].bv_len >= index_substr_if_minlen ) {
590 nkeys += values[i].bv_len - (index_substr_if_minlen - 1);
596 /* no keys to generate */
601 keys = slap_sl_malloc( sizeof( struct berval ) * (nkeys+1), ctx );
603 slen = syntax->ssyn_oidlen;
604 mlen = mr->smr_oidlen;
606 if ( flags & SLAP_INDEX_SUBSTR_ANY )
607 hashPreset( &HCany, prefix, SLAP_INDEX_SUBSTR_PREFIX, syntax, mr );
608 if( flags & SLAP_INDEX_SUBSTR_INITIAL )
609 hashPreset( &HCini, prefix, SLAP_INDEX_SUBSTR_INITIAL_PREFIX, syntax, mr );
610 if( flags & SLAP_INDEX_SUBSTR_FINAL )
611 hashPreset( &HCfin, prefix, SLAP_INDEX_SUBSTR_FINAL_PREFIX, syntax, mr );
614 for ( i = 0; !BER_BVISNULL( &values[i] ); i++ ) {
617 if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
618 ( values[i].bv_len >= index_substr_any_len ) )
620 max = values[i].bv_len - (index_substr_any_len - 1);
622 for( j=0; j<max; j++ ) {
623 hashIter( &HCany, HASHdigest,
624 (unsigned char *)&values[i].bv_val[j],
625 index_substr_any_len );
626 ber_dupbv_x( &keys[nkeys++], &digest, ctx );
630 /* skip if too short */
631 if( values[i].bv_len < index_substr_if_minlen ) continue;
633 max = index_substr_if_maxlen < values[i].bv_len
634 ? index_substr_if_maxlen : values[i].bv_len;
636 for( j=index_substr_if_minlen; j<=max; j++ ) {
638 if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
639 hashIter( &HCini, HASHdigest,
640 (unsigned char *)values[i].bv_val, j );
641 ber_dupbv_x( &keys[nkeys++], &digest, ctx );
644 if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
645 hashIter( &HCfin, HASHdigest,
646 (unsigned char *)&values[i].bv_val[values[i].bv_len-j], j );
647 ber_dupbv_x( &keys[nkeys++], &digest, ctx );
654 BER_BVZERO( &keys[nkeys] );
665 octetStringSubstringsFilter (
670 struct berval *prefix,
671 void * assertedValue,
675 SubstringsAssertion *sa;
678 size_t slen, mlen, klen;
680 HASH_CONTEXT HASHcontext;
681 unsigned char HASHdigest[HASH_BYTES];
682 struct berval *value;
683 struct berval digest;
685 sa = (SubstringsAssertion *) assertedValue;
687 if( flags & SLAP_INDEX_SUBSTR_INITIAL &&
688 !BER_BVISNULL( &sa->sa_initial ) &&
689 sa->sa_initial.bv_len >= index_substr_if_minlen )
692 if ( sa->sa_initial.bv_len > index_substr_if_maxlen &&
693 ( flags & SLAP_INDEX_SUBSTR_ANY ))
695 nkeys += 1 + (sa->sa_initial.bv_len - index_substr_if_maxlen) / index_substr_any_step;
699 if ( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
701 for( i=0; !BER_BVISNULL( &sa->sa_any[i] ); i++ ) {
702 if( sa->sa_any[i].bv_len >= index_substr_any_len ) {
703 /* don't bother accounting with stepping */
704 nkeys += sa->sa_any[i].bv_len -
705 ( index_substr_any_len - 1 );
710 if( flags & SLAP_INDEX_SUBSTR_FINAL &&
711 !BER_BVISNULL( &sa->sa_final ) &&
712 sa->sa_final.bv_len >= index_substr_if_minlen )
715 if ( sa->sa_final.bv_len > index_substr_if_maxlen &&
716 ( flags & SLAP_INDEX_SUBSTR_ANY ))
718 nkeys += 1 + (sa->sa_final.bv_len - index_substr_if_maxlen) / index_substr_any_step;
727 digest.bv_val = (char *)HASHdigest;
728 digest.bv_len = sizeof(HASHdigest);
730 slen = syntax->ssyn_oidlen;
731 mlen = mr->smr_oidlen;
733 keys = slap_sl_malloc( sizeof( struct berval ) * (nkeys+1), ctx );
736 if( flags & SLAP_INDEX_SUBSTR_INITIAL &&
737 !BER_BVISNULL( &sa->sa_initial ) &&
738 sa->sa_initial.bv_len >= index_substr_if_minlen )
740 pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
741 value = &sa->sa_initial;
743 klen = index_substr_if_maxlen < value->bv_len
744 ? index_substr_if_maxlen : value->bv_len;
746 hashPreset( &HASHcontext, prefix, pre, syntax, mr );
747 hashIter( &HASHcontext, HASHdigest,
748 (unsigned char *)value->bv_val, klen );
749 ber_dupbv_x( &keys[nkeys++], &digest, ctx );
751 /* If initial is too long and we have subany indexed, use it
752 * to match the excess...
754 if (value->bv_len > index_substr_if_maxlen && (flags & SLAP_INDEX_SUBSTR_ANY))
757 pre = SLAP_INDEX_SUBSTR_PREFIX;
758 hashPreset( &HASHcontext, prefix, pre, syntax, mr);
759 for ( j=index_substr_if_maxlen-1; j <= value->bv_len - index_substr_any_len; j+=index_substr_any_step )
761 hashIter( &HASHcontext, HASHdigest,
762 (unsigned char *)&value->bv_val[j], index_substr_any_len );
763 ber_dupbv_x( &keys[nkeys++], &digest, ctx );
768 if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
770 pre = SLAP_INDEX_SUBSTR_PREFIX;
771 klen = index_substr_any_len;
773 for( i=0; !BER_BVISNULL( &sa->sa_any[i] ); i++ ) {
774 if( sa->sa_any[i].bv_len < index_substr_any_len ) {
778 value = &sa->sa_any[i];
780 hashPreset( &HASHcontext, prefix, pre, syntax, mr);
782 j <= value->bv_len - index_substr_any_len;
783 j += index_substr_any_step )
785 hashIter( &HASHcontext, HASHdigest,
786 (unsigned char *)&value->bv_val[j], klen );
787 ber_dupbv_x( &keys[nkeys++], &digest, ctx );
792 if( flags & SLAP_INDEX_SUBSTR_FINAL &&
793 !BER_BVISNULL( &sa->sa_final ) &&
794 sa->sa_final.bv_len >= index_substr_if_minlen )
796 pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
797 value = &sa->sa_final;
799 klen = index_substr_if_maxlen < value->bv_len
800 ? index_substr_if_maxlen : value->bv_len;
802 hashPreset( &HASHcontext, prefix, pre, syntax, mr );
803 hashIter( &HASHcontext, HASHdigest,
804 (unsigned char *)&value->bv_val[value->bv_len-klen], klen );
805 ber_dupbv_x( &keys[nkeys++], &digest, ctx );
807 /* If final is too long and we have subany indexed, use it
808 * to match the excess...
810 if (value->bv_len > index_substr_if_maxlen && (flags & SLAP_INDEX_SUBSTR_ANY))
813 pre = SLAP_INDEX_SUBSTR_PREFIX;
814 hashPreset( &HASHcontext, prefix, pre, syntax, mr);
815 for ( j=0; j <= value->bv_len - index_substr_if_maxlen; j+=index_substr_any_step )
817 hashIter( &HASHcontext, HASHdigest,
818 (unsigned char *)&value->bv_val[j], index_substr_any_len );
819 ber_dupbv_x( &keys[nkeys++], &digest, ctx );
825 BER_BVZERO( &keys[nkeys] );
842 /* very unforgiving validation, requires no normalization
843 * before simplistic matching
845 if( in->bv_len < 3 ) {
846 return LDAP_INVALID_SYNTAX;
849 /* RFC 4517 Section 3.3.2 Bit String:
850 * BitString = SQUOTE *binary-digit SQUOTE "B"
851 * binary-digit = "0" / "1"
853 * where SQUOTE [RFC4512] is
854 * SQUOTE = %x27 ; single quote ("'")
856 * Example: '0101111101'B
859 if( in->bv_val[0] != '\'' ||
860 in->bv_val[in->bv_len - 2] != '\'' ||
861 in->bv_val[in->bv_len - 1] != 'B' )
863 return LDAP_INVALID_SYNTAX;
866 for( i = in->bv_len - 3; i > 0; i-- ) {
867 if( in->bv_val[i] != '0' && in->bv_val[i] != '1' ) {
868 return LDAP_INVALID_SYNTAX;
876 * Syntaxes from RFC 4517
881 A value of the Bit String syntax is a sequence of binary digits. The
882 LDAP-specific encoding of a value of this syntax is defined by the
885 BitString = SQUOTE *binary-digit SQUOTE "B"
887 binary-digit = "0" / "1"
889 The <SQUOTE> rule is defined in [MODELS].
894 The LDAP definition for the Bit String syntax is:
896 ( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )
898 This syntax corresponds to the BIT STRING ASN.1 type from [ASN.1].
902 3.3.21. Name and Optional UID
904 A value of the Name and Optional UID syntax is the distinguished name
905 [MODELS] of an entity optionally accompanied by a unique identifier
906 that serves to differentiate the entity from others with an identical
909 The LDAP-specific encoding of a value of this syntax is defined by
912 NameAndOptionalUID = distinguishedName [ SHARP BitString ]
914 The <BitString> rule is defined in Section 3.3.2. The
915 <distinguishedName> rule is defined in [LDAPDN]. The <SHARP> rule is
918 Note that although the '#' character may occur in the string
919 representation of a distinguished name, no additional escaping of
920 this character is performed when a <distinguishedName> is encoded in
921 a <NameAndOptionalUID>.
924 1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB#'0101'B
926 The LDAP definition for the Name and Optional UID syntax is:
928 ( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )
930 This syntax corresponds to the NameAndOptionalUID ASN.1 type from
937 1.4. Common ABNF Productions
940 SHARP = %x23 ; octothorpe (or sharp sign) ("#")
942 SQUOTE = %x27 ; single quote ("'")
946 * Note: normalization strips any leading "0"s, unless the
947 * bit string is exactly "'0'B", so the normalized example,
948 * in slapd, would result in
950 * 1.3.6.1.4.1.1466.0=#04024869,o=test,c=gb#'101'B
952 * RFC 4514 clarifies that SHARP, i.e. "#", doesn't have to
953 * be escaped except when at the beginning of a value, the
954 * definition of Name and Optional UID appears to be flawed,
955 * because there is no clear means to determine whether the
956 * UID part is present or not.
960 * cn=Someone,dc=example,dc=com#'1'B
962 * could be either a NameAndOptionalUID with trailing UID, i.e.
964 * DN = "cn=Someone,dc=example,dc=com"
967 * or a NameAndOptionalUID with no trailing UID, and the AVA
968 * in the last RDN made of
971 * attributeValue = com#'1'B
973 * in fact "com#'1'B" is a valid IA5 string.
975 * As a consequence, current slapd code assumes that the
976 * presence of portions of a BitString at the end of the string
977 * representation of a NameAndOptionalUID means a BitString
978 * is expected, and cause an error otherwise. This is quite
979 * arbitrary, and might change in the future.
989 struct berval dn, uid;
991 if( BER_BVISEMPTY( in ) ) return LDAP_SUCCESS;
993 ber_dupbv( &dn, in );
994 if( !dn.bv_val ) return LDAP_OTHER;
996 /* if there's a "#", try bitStringValidate()... */
997 uid.bv_val = strrchr( dn.bv_val, '#' );
998 if ( !BER_BVISNULL( &uid ) ) {
1000 uid.bv_len = dn.bv_len - ( uid.bv_val - dn.bv_val );
1002 rc = bitStringValidate( NULL, &uid );
1003 if ( rc == LDAP_SUCCESS ) {
1004 /* in case of success, trim the UID,
1005 * otherwise treat it as part of the DN */
1006 dn.bv_len -= uid.bv_len + 1;
1007 uid.bv_val[-1] = '\0';
1011 rc = dnValidate( NULL, &dn );
1013 ber_memfree( dn.bv_val );
1024 assert( val != NULL );
1025 assert( out != NULL );
1028 Debug( LDAP_DEBUG_TRACE, ">>> nameUIDPretty: <%s>\n", val->bv_val, 0, 0 );
1030 if( BER_BVISEMPTY( val ) ) {
1031 ber_dupbv_x( out, val, ctx );
1033 } else if ( val->bv_len > SLAP_LDAPDN_MAXLEN ) {
1034 return LDAP_INVALID_SYNTAX;
1038 struct berval dnval = *val;
1039 struct berval uidval = BER_BVNULL;
1041 uidval.bv_val = strrchr( val->bv_val, '#' );
1042 if ( !BER_BVISNULL( &uidval ) ) {
1044 uidval.bv_len = val->bv_len - ( uidval.bv_val - val->bv_val );
1046 rc = bitStringValidate( NULL, &uidval );
1048 if ( rc == LDAP_SUCCESS ) {
1049 ber_dupbv_x( &dnval, val, ctx );
1050 dnval.bv_len -= uidval.bv_len + 1;
1051 dnval.bv_val[dnval.bv_len] = '\0';
1054 BER_BVZERO( &uidval );
1058 rc = dnPretty( syntax, &dnval, out, ctx );
1059 if ( dnval.bv_val != val->bv_val ) {
1060 slap_sl_free( dnval.bv_val, ctx );
1062 if( rc != LDAP_SUCCESS ) {
1066 if( !BER_BVISNULL( &uidval ) ) {
1070 tmp = slap_sl_realloc( out->bv_val, out->bv_len
1071 + STRLENOF( "#" ) + uidval.bv_len + 1,
1074 ber_memfree_x( out->bv_val, ctx );
1078 out->bv_val[out->bv_len++] = '#';
1079 out->bv_val[out->bv_len++] = '\'';
1081 got1 = uidval.bv_len < sizeof("'0'B");
1082 for( i = 1; i < uidval.bv_len - 2; i++ ) {
1083 c = uidval.bv_val[i];
1086 if( got1 ) out->bv_val[out->bv_len++] = c;
1090 out->bv_val[out->bv_len++] = c;
1095 out->bv_val[out->bv_len++] = '\'';
1096 out->bv_val[out->bv_len++] = 'B';
1097 out->bv_val[out->bv_len] = '\0';
1101 Debug( LDAP_DEBUG_TRACE, "<<< nameUIDPretty: <%s>\n", out->bv_val, 0, 0 );
1103 return LDAP_SUCCESS;
1107 uniqueMemberNormalize(
1112 struct berval *normalized,
1118 assert( SLAP_MR_IS_VALUE_OF_SYNTAX( usage ) != 0 );
1120 ber_dupbv_x( &out, val, ctx );
1121 if ( BER_BVISEMPTY( &out ) ) {
1125 struct berval uid = BER_BVNULL;
1127 uid.bv_val = strrchr( out.bv_val, '#' );
1128 if ( !BER_BVISNULL( &uid ) ) {
1130 uid.bv_len = out.bv_len - ( uid.bv_val - out.bv_val );
1132 rc = bitStringValidate( NULL, &uid );
1133 if ( rc == LDAP_SUCCESS ) {
1134 uid.bv_val[-1] = '\0';
1135 out.bv_len -= uid.bv_len + 1;
1141 rc = dnNormalize( 0, NULL, NULL, &out, normalized, ctx );
1143 if( rc != LDAP_SUCCESS ) {
1144 slap_sl_free( out.bv_val, ctx );
1145 return LDAP_INVALID_SYNTAX;
1148 if( !BER_BVISNULL( &uid ) ) {
1151 tmp = ch_realloc( normalized->bv_val,
1152 normalized->bv_len + uid.bv_len
1153 + STRLENOF("#") + 1 );
1154 if ( tmp == NULL ) {
1155 ber_memfree_x( normalized->bv_val, ctx );
1159 normalized->bv_val = tmp;
1161 /* insert the separator */
1162 normalized->bv_val[normalized->bv_len++] = '#';
1164 /* append the UID */
1165 AC_MEMCPY( &normalized->bv_val[normalized->bv_len],
1166 uid.bv_val, uid.bv_len );
1167 normalized->bv_len += uid.bv_len;
1170 normalized->bv_val[normalized->bv_len] = '\0';
1173 slap_sl_free( out.bv_val, ctx );
1176 return LDAP_SUCCESS;
1185 struct berval *value,
1186 void *assertedValue )
1189 struct berval *asserted = (struct berval *) assertedValue;
1190 struct berval assertedDN = *asserted;
1191 struct berval assertedUID = BER_BVNULL;
1192 struct berval valueDN = *value;
1193 struct berval valueUID = BER_BVNULL;
1194 int approx = ((flags & SLAP_MR_EQUALITY_APPROX) == SLAP_MR_EQUALITY_APPROX);
1196 if ( !BER_BVISEMPTY( asserted ) ) {
1197 assertedUID.bv_val = strrchr( assertedDN.bv_val, '#' );
1198 if ( !BER_BVISNULL( &assertedUID ) ) {
1199 assertedUID.bv_val++;
1200 assertedUID.bv_len = assertedDN.bv_len
1201 - ( assertedUID.bv_val - assertedDN.bv_val );
1203 if ( bitStringValidate( NULL, &assertedUID ) == LDAP_SUCCESS ) {
1204 assertedDN.bv_len -= assertedUID.bv_len + 1;
1207 BER_BVZERO( &assertedUID );
1212 if ( !BER_BVISEMPTY( value ) ) {
1214 valueUID.bv_val = strrchr( valueDN.bv_val, '#' );
1215 if ( !BER_BVISNULL( &valueUID ) ) {
1217 valueUID.bv_len = valueDN.bv_len
1218 - ( valueUID.bv_val - valueDN.bv_val );
1220 if ( bitStringValidate( NULL, &valueUID ) == LDAP_SUCCESS ) {
1221 valueDN.bv_len -= valueUID.bv_len + 1;
1224 BER_BVZERO( &valueUID );
1229 if( valueUID.bv_len && assertedUID.bv_len ) {
1230 match = valueUID.bv_len - assertedUID.bv_len;
1233 return LDAP_SUCCESS;
1236 match = memcmp( valueUID.bv_val, assertedUID.bv_val, valueUID.bv_len );
1239 return LDAP_SUCCESS;
1242 } else if ( !approx && valueUID.bv_len ) {
1245 return LDAP_SUCCESS;
1247 } else if ( !approx && assertedUID.bv_len ) {
1250 return LDAP_SUCCESS;
1253 return dnMatch( matchp, flags, syntax, mr, &valueDN, &assertedDN );
1257 uniqueMemberIndexer(
1262 struct berval *prefix,
1270 for( i=0; !BER_BVISNULL( &values[i] ); i++ ) {
1271 /* just count them */
1275 dnvalues = slap_sl_malloc( sizeof( struct berval ) * (i+1), ctx );
1277 for( i=0; !BER_BVISNULL( &values[i] ); i++ ) {
1278 struct berval assertedDN = values[i];
1279 struct berval assertedUID = BER_BVNULL;
1281 if ( !BER_BVISEMPTY( &assertedDN ) ) {
1282 assertedUID.bv_val = strrchr( assertedDN.bv_val, '#' );
1283 if ( !BER_BVISNULL( &assertedUID ) ) {
1284 assertedUID.bv_val++;
1285 assertedUID.bv_len = assertedDN.bv_len
1286 - ( assertedUID.bv_val - assertedDN.bv_val );
1288 if ( bitStringValidate( NULL, &assertedUID ) == LDAP_SUCCESS ) {
1289 assertedDN.bv_len -= assertedUID.bv_len + 1;
1292 BER_BVZERO( &assertedUID );
1297 dnvalues[i] = assertedDN;
1299 BER_BVZERO( &dnvalues[i] );
1301 rc = octetStringIndexer( use, flags, syntax, mr, prefix,
1302 dnvalues, keysp, ctx );
1304 slap_sl_free( dnvalues, ctx );
1314 struct berval *prefix,
1315 void * assertedValue,
1319 struct berval *asserted = (struct berval *) assertedValue;
1320 struct berval assertedDN = *asserted;
1321 struct berval assertedUID = BER_BVNULL;
1323 if ( !BER_BVISEMPTY( asserted ) ) {
1324 assertedUID.bv_val = strrchr( assertedDN.bv_val, '#' );
1325 if ( !BER_BVISNULL( &assertedUID ) ) {
1326 assertedUID.bv_val++;
1327 assertedUID.bv_len = assertedDN.bv_len
1328 - ( assertedUID.bv_val - assertedDN.bv_val );
1330 if ( bitStringValidate( NULL, &assertedUID ) == LDAP_SUCCESS ) {
1331 assertedDN.bv_len -= assertedUID.bv_len + 1;
1334 BER_BVZERO( &assertedUID );
1339 return octetStringFilter( use, flags, syntax, mr, prefix,
1340 &assertedDN, keysp, ctx );
1345 * Handling boolean syntax and matching is quite rigid.
1346 * A more flexible approach would be to allow a variety
1347 * of strings to be normalized and prettied into TRUE
1355 /* very unforgiving validation, requires no normalization
1356 * before simplistic matching
1359 if( in->bv_len == 4 ) {
1360 if( bvmatch( in, &slap_true_bv ) ) {
1361 return LDAP_SUCCESS;
1363 } else if( in->bv_len == 5 ) {
1364 if( bvmatch( in, &slap_false_bv ) ) {
1365 return LDAP_SUCCESS;
1369 return LDAP_INVALID_SYNTAX;
1378 struct berval *value,
1379 void *assertedValue )
1381 /* simplistic matching allowed by rigid validation */
1382 struct berval *asserted = (struct berval *) assertedValue;
1383 *matchp = value->bv_len != asserted->bv_len;
1384 return LDAP_SUCCESS;
1387 /*-------------------------------------------------------------------
1388 LDAP/X.500 string syntax / matching rules have a few oddities. This
1389 comment attempts to detail how slapd(8) treats them.
1392 StringSyntax X.500 LDAP Matching/Comments
1393 DirectoryString CHOICE UTF8 i/e + ignore insignificant spaces
1394 PrintableString subset subset i/e + ignore insignificant spaces
1395 PrintableString subset subset i/e + ignore insignificant spaces
1396 NumericString subset subset ignore all spaces
1397 IA5String ASCII ASCII i/e + ignore insignificant spaces
1398 TeletexString T.61 T.61 i/e + ignore insignificant spaces
1400 TelephoneNumber subset subset i + ignore all spaces and "-"
1402 See RFC 4518 for details.
1406 In X.500(93), a directory string can be either a PrintableString,
1407 a bmpString, or a UniversalString (e.g., UCS (a subset of Unicode)).
1408 In later versions, more CHOICEs were added. In all cases the string
1411 In LDAPv3, a directory string is a UTF-8 encoded UCS string.
1412 A directory string cannot be zero length.
1414 For matching, there are both case ignore and exact rules. Both
1415 also require that "insignificant" spaces be ignored.
1416 spaces before the first non-space are ignored;
1417 spaces after the last non-space are ignored;
1418 spaces after a space are ignored.
1419 Note: by these rules (and as clarified in X.520), a string of only
1420 spaces is to be treated as if held one space, not empty (which
1421 would be a syntax error).
1424 In ASN.1, numeric string is just a string of digits and spaces
1425 and could be empty. However, in X.500, all attribute values of
1426 numeric string carry a non-empty constraint. For example:
1428 internationalISDNNumber ATTRIBUTE ::= {
1429 WITH SYNTAX InternationalISDNNumber
1430 EQUALITY MATCHING RULE numericStringMatch
1431 SUBSTRINGS MATCHING RULE numericStringSubstringsMatch
1432 ID id-at-internationalISDNNumber }
1433 InternationalISDNNumber ::=
1434 NumericString (SIZE(1..ub-international-isdn-number))
1436 Unforunately, some assertion values are don't carry the same
1437 constraint (but its unclear how such an assertion could ever
1438 be true). In LDAP, there is one syntax (numericString) not two
1439 (numericString with constraint, numericString without constraint).
1440 This should be treated as numericString with non-empty constraint.
1441 Note that while someone may have no ISDN number, there are no ISDN
1442 numbers which are zero length.
1444 In matching, spaces are ignored.
1447 In ASN.1, Printable string is just a string of printable characters
1448 and can be empty. In X.500, semantics much like NumericString (see
1449 serialNumber for a like example) excepting uses insignificant space
1450 handling instead of ignore all spaces. They must be non-empty.
1453 Basically same as PrintableString. There are no examples in X.500,
1454 but same logic applies. Empty strings are allowed.
1456 -------------------------------------------------------------------*/
1465 unsigned char *u = (unsigned char *)in->bv_val;
1467 if( BER_BVISEMPTY( in ) && syntax == slap_schema.si_syn_directoryString ) {
1468 /* directory strings cannot be empty */
1469 return LDAP_INVALID_SYNTAX;
1472 for( count = in->bv_len; count > 0; count -= len, u += len ) {
1473 /* get the length indicated by the first byte */
1474 len = LDAP_UTF8_CHARLEN2( u, len );
1476 /* very basic checks */
1479 if( (u[5] & 0xC0) != 0x80 ) {
1480 return LDAP_INVALID_SYNTAX;
1483 if( (u[4] & 0xC0) != 0x80 ) {
1484 return LDAP_INVALID_SYNTAX;
1487 if( (u[3] & 0xC0) != 0x80 ) {
1488 return LDAP_INVALID_SYNTAX;
1491 if( (u[2] & 0xC0 )!= 0x80 ) {
1492 return LDAP_INVALID_SYNTAX;
1495 if( (u[1] & 0xC0) != 0x80 ) {
1496 return LDAP_INVALID_SYNTAX;
1499 /* CHARLEN already validated it */
1502 return LDAP_INVALID_SYNTAX;
1505 /* make sure len corresponds with the offset
1506 to the next character */
1507 if( LDAP_UTF8_OFFSET( (char *)u ) != len ) return LDAP_INVALID_SYNTAX;
1511 return LDAP_INVALID_SYNTAX;
1514 return LDAP_SUCCESS;
1518 UTF8StringNormalize(
1523 struct berval *normalized,
1526 struct berval tmp, nvalue;
1530 assert( SLAP_MR_IS_VALUE_OF_SYNTAX( use ) != 0 );
1532 if( BER_BVISNULL( val ) ) {
1533 /* assume we're dealing with a syntax (e.g., UTF8String)
1534 * which allows empty strings
1536 BER_BVZERO( normalized );
1537 return LDAP_SUCCESS;
1540 flags = SLAP_MR_ASSOCIATED( mr, slap_schema.si_mr_caseExactMatch )
1541 ? LDAP_UTF8_NOCASEFOLD : LDAP_UTF8_CASEFOLD;
1542 flags |= ( ( use & SLAP_MR_EQUALITY_APPROX ) == SLAP_MR_EQUALITY_APPROX )
1543 ? LDAP_UTF8_APPROX : 0;
1545 val = UTF8bvnormalize( val, &tmp, flags, ctx );
1550 /* collapse spaces (in place) */
1552 nvalue.bv_val = tmp.bv_val;
1554 /* trim leading spaces? */
1555 wasspace = !((( use & SLAP_MR_SUBSTR_ANY ) == SLAP_MR_SUBSTR_ANY ) ||
1556 (( use & SLAP_MR_SUBSTR_FINAL ) == SLAP_MR_SUBSTR_FINAL ));
1558 for( i = 0; i < tmp.bv_len; i++) {
1559 if ( ASCII_SPACE( tmp.bv_val[i] )) {
1560 if( wasspace++ == 0 ) {
1561 /* trim repeated spaces */
1562 nvalue.bv_val[nvalue.bv_len++] = tmp.bv_val[i];
1566 nvalue.bv_val[nvalue.bv_len++] = tmp.bv_val[i];
1570 if( !BER_BVISEMPTY( &nvalue ) ) {
1571 /* trim trailing space? */
1573 (( use & SLAP_MR_SUBSTR_INITIAL ) != SLAP_MR_SUBSTR_INITIAL ) &&
1574 ( use & SLAP_MR_SUBSTR_ANY ) != SLAP_MR_SUBSTR_ANY ))
1578 nvalue.bv_val[nvalue.bv_len] = '\0';
1581 /* string of all spaces is treated as one space */
1582 nvalue.bv_val[0] = ' ';
1583 nvalue.bv_val[1] = '\0';
1587 *normalized = nvalue;
1588 return LDAP_SUCCESS;
1592 directoryStringSubstringsMatch(
1597 struct berval *value,
1598 void *assertedValue )
1601 SubstringsAssertion *sub = assertedValue;
1602 struct berval left = *value;
1606 if ( !BER_BVISNULL( &sub->sa_initial ) ) {
1607 if ( sub->sa_initial.bv_len > left.bv_len ) {
1608 /* not enough left */
1613 match = memcmp( sub->sa_initial.bv_val, left.bv_val,
1614 sub->sa_initial.bv_len );
1620 left.bv_val += sub->sa_initial.bv_len;
1621 left.bv_len -= sub->sa_initial.bv_len;
1623 priorspace = ASCII_SPACE(
1624 sub->sa_initial.bv_val[sub->sa_initial.bv_len] );
1627 if ( sub->sa_any ) {
1628 for ( i = 0; !BER_BVISNULL( &sub->sa_any[i] ); i++ ) {
1632 if( priorspace && !BER_BVISEMPTY( &sub->sa_any[i] )
1633 && ASCII_SPACE( sub->sa_any[i].bv_val[0] ))
1635 /* allow next space to match */
1642 if ( BER_BVISEMPTY( &sub->sa_any[i] ) ) {
1646 if ( sub->sa_any[i].bv_len > left.bv_len ) {
1647 /* not enough left */
1652 p = memchr( left.bv_val, *sub->sa_any[i].bv_val, left.bv_len );
1659 idx = p - left.bv_val;
1661 if ( idx >= left.bv_len ) {
1662 /* this shouldn't happen */
1669 if ( sub->sa_any[i].bv_len > left.bv_len ) {
1670 /* not enough left */
1675 match = memcmp( left.bv_val,
1676 sub->sa_any[i].bv_val,
1677 sub->sa_any[i].bv_len );
1685 left.bv_val += sub->sa_any[i].bv_len;
1686 left.bv_len -= sub->sa_any[i].bv_len;
1688 priorspace = ASCII_SPACE(
1689 sub->sa_any[i].bv_val[sub->sa_any[i].bv_len] );
1693 if ( !BER_BVISNULL( &sub->sa_final ) ) {
1694 if( priorspace && !BER_BVISEMPTY( &sub->sa_final )
1695 && ASCII_SPACE( sub->sa_final.bv_val[0] ))
1697 /* allow next space to match */
1702 if ( sub->sa_final.bv_len > left.bv_len ) {
1703 /* not enough left */
1708 match = memcmp( sub->sa_final.bv_val,
1709 &left.bv_val[left.bv_len - sub->sa_final.bv_len],
1710 sub->sa_final.bv_len );
1719 return LDAP_SUCCESS;
1722 #if defined(SLAPD_APPROX_INITIALS)
1723 # define SLAPD_APPROX_DELIMITER "._ "
1724 # define SLAPD_APPROX_WORDLEN 2
1726 # define SLAPD_APPROX_DELIMITER " "
1727 # define SLAPD_APPROX_WORDLEN 1
1736 struct berval *value,
1737 void *assertedValue )
1739 struct berval *nval, *assertv;
1740 char *val, **values, **words, *c;
1741 int i, count, len, nextchunk=0, nextavail=0;
1743 /* Yes, this is necessary */
1744 nval = UTF8bvnormalize( value, NULL, LDAP_UTF8_APPROX, NULL );
1745 if( nval == NULL ) {
1747 return LDAP_SUCCESS;
1750 /* Yes, this is necessary */
1751 assertv = UTF8bvnormalize( ((struct berval *)assertedValue),
1752 NULL, LDAP_UTF8_APPROX, NULL );
1753 if( assertv == NULL ) {
1756 return LDAP_SUCCESS;
1759 /* Isolate how many words there are */
1760 for ( c = nval->bv_val, count = 1; *c; c++ ) {
1761 c = strpbrk( c, SLAPD_APPROX_DELIMITER );
1762 if ( c == NULL ) break;
1767 /* Get a phonetic copy of each word */
1768 words = (char **)ch_malloc( count * sizeof(char *) );
1769 values = (char **)ch_malloc( count * sizeof(char *) );
1770 for ( c = nval->bv_val, i = 0; i < count; i++, c += strlen(c) + 1 ) {
1772 values[i] = phonetic(c);
1775 /* Work through the asserted value's words, to see if at least some
1776 of the words are there, in the same order. */
1778 while ( (ber_len_t) nextchunk < assertv->bv_len ) {
1779 len = strcspn( assertv->bv_val + nextchunk, SLAPD_APPROX_DELIMITER);
1784 #if defined(SLAPD_APPROX_INITIALS)
1785 else if( len == 1 ) {
1786 /* Single letter words need to at least match one word's initial */
1787 for( i=nextavail; i<count; i++ )
1788 if( !strncasecmp( assertv->bv_val + nextchunk, words[i], 1 )) {
1795 /* Isolate the next word in the asserted value and phonetic it */
1796 assertv->bv_val[nextchunk+len] = '\0';
1797 val = phonetic( assertv->bv_val + nextchunk );
1799 /* See if this phonetic chunk is in the remaining words of *value */
1800 for( i=nextavail; i<count; i++ ){
1801 if( !strcmp( val, values[i] ) ){
1809 /* This chunk in the asserted value was NOT within the *value. */
1815 /* Go on to the next word in the asserted value */
1819 /* If some of the words were seen, call it a match */
1820 if( nextavail > 0 ) {
1827 /* Cleanup allocs */
1828 ber_bvfree( assertv );
1829 for( i=0; i<count; i++ ) {
1830 ch_free( values[i] );
1836 return LDAP_SUCCESS;
1845 struct berval *prefix,
1851 int i,j, len, wordcount, keycount=0;
1852 struct berval *newkeys;
1853 BerVarray keys=NULL;
1855 for( j = 0; !BER_BVISNULL( &values[j] ); j++ ) {
1856 struct berval val = BER_BVNULL;
1857 /* Yes, this is necessary */
1858 UTF8bvnormalize( &values[j], &val, LDAP_UTF8_APPROX, NULL );
1859 assert( !BER_BVISNULL( &val ) );
1861 /* Isolate how many words there are. There will be a key for each */
1862 for( wordcount = 0, c = val.bv_val; *c; c++) {
1863 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1864 if( len >= SLAPD_APPROX_WORDLEN ) wordcount++;
1866 if (*c == '\0') break;
1870 /* Allocate/increase storage to account for new keys */
1871 newkeys = (struct berval *)ch_malloc( (keycount + wordcount + 1)
1872 * sizeof(struct berval) );
1873 AC_MEMCPY( newkeys, keys, keycount * sizeof(struct berval) );
1874 if( keys ) ch_free( keys );
1877 /* Get a phonetic copy of each word */
1878 for( c = val.bv_val, i = 0; i < wordcount; c += len + 1 ) {
1880 if( len < SLAPD_APPROX_WORDLEN ) continue;
1881 ber_str2bv( phonetic( c ), 0, 0, &keys[keycount] );
1886 ber_memfree( val.bv_val );
1888 BER_BVZERO( &keys[keycount] );
1891 return LDAP_SUCCESS;
1900 struct berval *prefix,
1901 void * assertedValue,
1910 /* Yes, this is necessary */
1911 val = UTF8bvnormalize( ((struct berval *)assertedValue),
1912 NULL, LDAP_UTF8_APPROX, NULL );
1913 if( val == NULL || BER_BVISNULL( val ) ) {
1914 keys = (struct berval *)ch_malloc( sizeof(struct berval) );
1915 BER_BVZERO( &keys[0] );
1918 return LDAP_SUCCESS;
1921 /* Isolate how many words there are. There will be a key for each */
1922 for( count = 0,c = val->bv_val; *c; c++) {
1923 len = strcspn(c, SLAPD_APPROX_DELIMITER);
1924 if( len >= SLAPD_APPROX_WORDLEN ) count++;
1926 if (*c == '\0') break;
1930 /* Allocate storage for new keys */
1931 keys = (struct berval *)ch_malloc( (count + 1) * sizeof(struct berval) );
1933 /* Get a phonetic copy of each word */
1934 for( c = val->bv_val, i = 0; i < count; c += len + 1 ) {
1936 if( len < SLAPD_APPROX_WORDLEN ) continue;
1937 ber_str2bv( phonetic( c ), 0, 0, &keys[i] );
1943 BER_BVZERO( &keys[count] );
1946 return LDAP_SUCCESS;
1949 /* Remove all spaces and '-' characters */
1951 telephoneNumberNormalize(
1956 struct berval *normalized,
1961 assert( SLAP_MR_IS_VALUE_OF_SYNTAX( usage ) != 0 );
1963 /* validator should have refused an empty string */
1964 assert( !BER_BVISEMPTY( val ) );
1966 q = normalized->bv_val = slap_sl_malloc( val->bv_len + 1, ctx );
1968 for( p = val->bv_val; *p; p++ ) {
1969 if ( ! ( ASCII_SPACE( *p ) || *p == '-' )) {
1975 normalized->bv_len = q - normalized->bv_val;
1977 if( BER_BVISEMPTY( normalized ) ) {
1978 slap_sl_free( normalized->bv_val, ctx );
1979 BER_BVZERO( normalized );
1980 return LDAP_INVALID_SYNTAX;
1983 return LDAP_SUCCESS;
1991 struct berval val = *in;
1993 if( BER_BVISEMPTY( &val ) ) {
1994 /* disallow empty strings */
1995 return LDAP_INVALID_SYNTAX;
1998 while( OID_LEADCHAR( val.bv_val[0] ) ) {
1999 if ( val.bv_len == 1 ) {
2000 return LDAP_SUCCESS;
2003 if ( val.bv_val[0] == '0' && !OID_SEPARATOR( val.bv_val[1] )) {
2010 while ( OID_LEADCHAR( val.bv_val[0] )) {
2014 if ( val.bv_len == 0 ) {
2015 return LDAP_SUCCESS;
2019 if( !OID_SEPARATOR( val.bv_val[0] )) {
2027 return LDAP_INVALID_SYNTAX;
2036 struct berval val = *in;
2038 if ( BER_BVISEMPTY( &val ) ) return LDAP_INVALID_SYNTAX;
2040 if ( val.bv_val[0] == '-' ) {
2044 if( BER_BVISEMPTY( &val ) ) { /* bare "-" */
2045 return LDAP_INVALID_SYNTAX;
2048 if( val.bv_val[0] == '0' ) { /* "-0" */
2049 return LDAP_INVALID_SYNTAX;
2052 } else if ( val.bv_val[0] == '0' ) {
2053 if( val.bv_len > 1 ) { /* "0<more>" */
2054 return LDAP_INVALID_SYNTAX;
2057 return LDAP_SUCCESS;
2060 for( i=0; i < val.bv_len; i++ ) {
2061 if( !ASCII_DIGIT(val.bv_val[i]) ) {
2062 return LDAP_INVALID_SYNTAX;
2066 return LDAP_SUCCESS;
2075 struct berval *value,
2076 void *assertedValue )
2078 struct berval *asserted = (struct berval *) assertedValue;
2079 int vsign = 1, asign = 1; /* default sign = '+' */
2084 if( v.bv_val[0] == '-' ) {
2090 if( BER_BVISEMPTY( &v ) ) vsign = 0;
2093 if( a.bv_val[0] == '-' ) {
2099 if( BER_BVISEMPTY( &a ) ) vsign = 0;
2101 match = vsign - asign;
2103 match = ( v.bv_len != a.bv_len
2104 ? ( v.bv_len < a.bv_len ? -1 : 1 )
2105 : memcmp( v.bv_val, a.bv_val, v.bv_len ));
2106 if( vsign < 0 ) match = -match;
2110 return LDAP_SUCCESS;
2114 countryStringValidate(
2116 struct berval *val )
2118 if( val->bv_len != 2 ) return LDAP_INVALID_SYNTAX;
2120 if( !SLAP_PRINTABLE(val->bv_val[0]) ) {
2121 return LDAP_INVALID_SYNTAX;
2123 if( !SLAP_PRINTABLE(val->bv_val[1]) ) {
2124 return LDAP_INVALID_SYNTAX;
2127 return LDAP_SUCCESS;
2131 printableStringValidate(
2133 struct berval *val )
2137 if( BER_BVISEMPTY( val ) ) return LDAP_INVALID_SYNTAX;
2139 for(i=0; i < val->bv_len; i++) {
2140 if( !SLAP_PRINTABLE(val->bv_val[i]) ) {
2141 return LDAP_INVALID_SYNTAX;
2145 return LDAP_SUCCESS;
2149 printablesStringValidate(
2151 struct berval *val )
2155 if( BER_BVISEMPTY( val ) ) return LDAP_INVALID_SYNTAX;
2157 for(i=0,len=0; i < val->bv_len; i++) {
2158 int c = val->bv_val[i];
2162 return LDAP_INVALID_SYNTAX;
2166 } else if ( SLAP_PRINTABLE(c) ) {
2169 return LDAP_INVALID_SYNTAX;
2174 return LDAP_INVALID_SYNTAX;
2177 return LDAP_SUCCESS;
2183 struct berval *val )
2187 for(i=0; i < val->bv_len; i++) {
2188 if( !LDAP_ASCII(val->bv_val[i]) ) {
2189 return LDAP_INVALID_SYNTAX;
2193 return LDAP_SUCCESS;
2202 struct berval *normalized,
2206 int casefold = !SLAP_MR_ASSOCIATED( mr,
2207 slap_schema.si_mr_caseExactIA5Match );
2209 assert( SLAP_MR_IS_VALUE_OF_SYNTAX( use ) != 0 );
2213 /* Ignore initial whitespace */
2214 while ( ASCII_SPACE( *p ) ) p++;
2216 normalized->bv_len = val->bv_len - ( p - val->bv_val );
2217 normalized->bv_val = slap_sl_malloc( normalized->bv_len + 1, ctx );
2218 AC_MEMCPY( normalized->bv_val, p, normalized->bv_len );
2219 normalized->bv_val[normalized->bv_len] = '\0';
2221 p = q = normalized->bv_val;
2224 if ( ASCII_SPACE( *p ) ) {
2227 /* Ignore the extra whitespace */
2228 while ( ASCII_SPACE( *p ) ) {
2232 } else if ( casefold ) {
2233 /* Most IA5 rules require casefolding */
2234 *q++ = TOLOWER(*p); p++;
2241 assert( normalized->bv_val <= p );
2245 * If the string ended in space, backup the pointer one
2246 * position. One is enough because the above loop collapsed
2247 * all whitespace to a single space.
2249 if ( q > normalized->bv_val && ASCII_SPACE( q[-1] ) ) --q;
2251 /* null terminate */
2254 normalized->bv_len = q - normalized->bv_val;
2256 return LDAP_SUCCESS;
2265 if( in->bv_len != 36 ) {
2266 return LDAP_INVALID_SYNTAX;
2269 for( i=0; i<36; i++ ) {
2275 if( in->bv_val[i] != '-' ) {
2276 return LDAP_INVALID_SYNTAX;
2280 if( !ASCII_HEX( in->bv_val[i]) ) {
2281 return LDAP_INVALID_SYNTAX;
2286 return LDAP_SUCCESS;
2297 int rc=LDAP_INVALID_SYNTAX;
2299 assert( in != NULL );
2300 assert( out != NULL );
2302 if( in->bv_len != 36 ) return LDAP_INVALID_SYNTAX;
2305 out->bv_val = slap_sl_malloc( out->bv_len + 1, ctx );
2307 for( i=0; i<36; i++ ) {
2313 if( in->bv_val[i] != '-' ) {
2316 out->bv_val[i] = '-';
2320 if( !ASCII_HEX( in->bv_val[i]) ) {
2323 out->bv_val[i] = TOLOWER( in->bv_val[i] );
2328 out->bv_val[ out->bv_len ] = '\0';
2332 slap_sl_free( out->bv_val, ctx );
2345 struct berval *normalized,
2348 unsigned char octet = '\0';
2352 if ( SLAP_MR_IS_DENORMALIZE( usage ) ) {
2353 /* NOTE: must be a normalized UUID */
2354 assert( val->bv_len == 16 );
2356 normalized->bv_val = slap_sl_malloc( LDAP_LUTIL_UUIDSTR_BUFSIZE, ctx );
2357 normalized->bv_len = lutil_uuidstr_from_normalized( val->bv_val,
2358 val->bv_len, normalized->bv_val, LDAP_LUTIL_UUIDSTR_BUFSIZE );
2359 assert( normalized->bv_len == STRLENOF( "BADBADBA-DBAD-0123-4567-BADBADBADBAD" ) );
2361 return LDAP_SUCCESS;
2364 normalized->bv_len = 16;
2365 normalized->bv_val = slap_sl_malloc( normalized->bv_len + 1, ctx );
2367 for( i=0, j=0; i<36; i++ ) {
2368 unsigned char nibble;
2369 if( val->bv_val[i] == '-' ) {
2372 } else if( ASCII_DIGIT( val->bv_val[i] ) ) {
2373 nibble = val->bv_val[i] - '0';
2375 } else if( ASCII_HEXLOWER( val->bv_val[i] ) ) {
2376 nibble = val->bv_val[i] - ('a'-10);
2378 } else if( ASCII_HEXUPPER( val->bv_val[i] ) ) {
2379 nibble = val->bv_val[i] - ('A'-10);
2382 slap_sl_free( normalized->bv_val, ctx );
2383 return LDAP_INVALID_SYNTAX;
2388 normalized->bv_val[j>>1] = octet;
2390 octet = nibble << 4;
2395 normalized->bv_val[normalized->bv_len] = 0;
2396 return LDAP_SUCCESS;
2402 numericStringValidate(
2408 if( BER_BVISEMPTY( in ) ) return LDAP_INVALID_SYNTAX;
2410 for(i=0; i < in->bv_len; i++) {
2411 if( !SLAP_NUMERIC(in->bv_val[i]) ) {
2412 return LDAP_INVALID_SYNTAX;
2416 return LDAP_SUCCESS;
2420 numericStringNormalize(
2425 struct berval *normalized,
2428 /* removal all spaces */
2431 assert( !BER_BVISEMPTY( val ) );
2433 normalized->bv_val = slap_sl_malloc( val->bv_len + 1, ctx );
2436 q = normalized->bv_val;
2439 if ( ASCII_SPACE( *p ) ) {
2440 /* Ignore whitespace */
2447 /* we should have copied no more than is in val */
2448 assert( (q - normalized->bv_val) <= (p - val->bv_val) );
2450 /* null terminate */
2453 normalized->bv_len = q - normalized->bv_val;
2455 if( BER_BVISEMPTY( normalized ) ) {
2456 normalized->bv_val = slap_sl_realloc( normalized->bv_val, 2, ctx );
2457 normalized->bv_val[0] = ' ';
2458 normalized->bv_val[1] = '\0';
2459 normalized->bv_len = 1;
2462 return LDAP_SUCCESS;
2466 * Integer conversion macros that will use the largest available
2469 #if defined(HAVE_STRTOLL) && defined(HAVE_LONG_LONG)
2470 # define SLAP_STRTOL(n,e,b) strtoll(n,e,b)
2471 # define SLAP_LONG long long
2473 # define SLAP_STRTOL(n,e,b) strtol(n,e,b)
2474 # define SLAP_LONG long
2475 #endif /* HAVE_STRTOLL ... */
2483 struct berval *value,
2484 void *assertedValue )
2486 SLAP_LONG lValue, lAssertedValue;
2489 /* safe to assume integers are NUL terminated? */
2490 lValue = SLAP_STRTOL(value->bv_val, NULL, 10);
2491 if( errno == ERANGE )
2493 return LDAP_CONSTRAINT_VIOLATION;
2496 lAssertedValue = SLAP_STRTOL(((struct berval *)assertedValue)->bv_val,
2498 if( errno == ERANGE )
2500 return LDAP_CONSTRAINT_VIOLATION;
2503 *matchp = ((lValue & lAssertedValue) == lAssertedValue) ? 0 : 1;
2504 return LDAP_SUCCESS;
2513 struct berval *value,
2514 void *assertedValue )
2516 SLAP_LONG lValue, lAssertedValue;
2519 /* safe to assume integers are NUL terminated? */
2520 lValue = SLAP_STRTOL(value->bv_val, NULL, 10);
2521 if( errno == ERANGE )
2523 return LDAP_CONSTRAINT_VIOLATION;
2526 lAssertedValue = SLAP_STRTOL( ((struct berval *)assertedValue)->bv_val,
2528 if( errno == ERANGE )
2530 return LDAP_CONSTRAINT_VIOLATION;
2533 *matchp = ((lValue & lAssertedValue) != 0) ? 0 : -1;
2534 return LDAP_SUCCESS;
2538 serialNumberAndIssuerCheck(
2547 if( in->bv_len < 3 ) return LDAP_INVALID_SYNTAX;
2549 if( in->bv_val[0] != '{' && in->bv_val[in->bv_len-1] != '}' ) {
2550 /* Parse old format */
2551 is->bv_val = ber_bvchr( in, '$' );
2552 if( BER_BVISNULL( is ) ) return LDAP_INVALID_SYNTAX;
2554 sn->bv_val = in->bv_val;
2555 sn->bv_len = is->bv_val - in->bv_val;
2558 is->bv_len = in->bv_len - (sn->bv_len + 1);
2560 /* eat leading zeros */
2561 for( n=0; n < (sn->bv_len-1); n++ ) {
2562 if( sn->bv_val[n] != '0' ) break;
2567 for( n=0; n < sn->bv_len; n++ ) {
2568 if( !ASCII_DIGIT(sn->bv_val[n]) ) return LDAP_INVALID_SYNTAX;
2572 /* Parse GSER format */
2573 int havesn=0,haveissuer=0;
2574 struct berval x = *in;
2579 /* eat leading spaces */
2580 for( ; (x.bv_val[0] == ' ') && x.bv_len; x.bv_val++, x.bv_len--) {
2584 if ( x.bv_len < STRLENOF("serialNumber 0,issuer \"\"")) {
2585 return LDAP_INVALID_SYNTAX;
2588 /* should be at issuer or serialNumber NamedValue */
2589 if( strncasecmp( x.bv_val, "issuer", STRLENOF("issuer")) == 0 ) {
2591 x.bv_val += STRLENOF("issuer");
2592 x.bv_len -= STRLENOF("issuer");
2594 if( x.bv_val[0] != ' ' ) return LDAP_INVALID_SYNTAX;
2595 x.bv_val++; x.bv_len--;
2597 /* eat leading spaces */
2598 for( ; (x.bv_val[0] == ' ') && x.bv_len; x.bv_val++, x.bv_len--) {
2602 /* For backward compatibility, this part is optional */
2603 if( !strncasecmp( x.bv_val, "rdnSequence:", STRLENOF("rdnSequence:"))) {
2604 x.bv_val += STRLENOF("rdnSequence:");
2605 x.bv_len -= STRLENOF("rdnSequence:");
2608 if( x.bv_val[0] != '"' ) return LDAP_INVALID_SYNTAX;
2609 x.bv_val++; x.bv_len--;
2611 is->bv_val = x.bv_val;
2614 for( ; is->bv_len < x.bv_len; ) {
2615 if ( is->bv_val[is->bv_len] != '"' ) {
2619 if ( is->bv_val[is->bv_len+1] == '"' ) {
2626 x.bv_val += is->bv_len+1;
2627 x.bv_len -= is->bv_len+1;
2629 if ( x.bv_len < STRLENOF(",serialNumber 0")) {
2630 return LDAP_INVALID_SYNTAX;
2635 } else if( strncasecmp( x.bv_val, "serialNumber",
2636 STRLENOF("serialNumber")) == 0 )
2638 /* parse serialNumber */
2640 x.bv_val += STRLENOF("serialNumber");
2641 x.bv_len -= STRLENOF("serialNumber");
2643 if( x.bv_val[0] != ' ' ) return LDAP_INVALID_SYNTAX;
2644 x.bv_val++; x.bv_len--;
2646 /* eat leading spaces */
2647 for( ; (x.bv_val[0] == ' ') && x.bv_len; x.bv_val++, x.bv_len--) {
2651 sn->bv_val = x.bv_val;
2654 if( sn->bv_val[0] == '-' ) {
2659 if ( sn->bv_val[0] == '0' && ( sn->bv_val[1] == 'x' ||
2660 sn->bv_val[1] == 'X' )) {
2662 for( ; sn->bv_len < x.bv_len; sn->bv_len++ ) {
2663 if ( !ASCII_HEX( sn->bv_val[sn->bv_len] )) break;
2665 } else if ( sn->bv_val[0] == '\'' ) {
2666 for( ; sn->bv_len < x.bv_len; sn->bv_len++ ) {
2667 if ( !ASCII_HEX( sn->bv_val[sn->bv_len] )) break;
2669 if ( sn->bv_val[sn->bv_len] == '\'' &&
2670 sn->bv_val[sn->bv_len+1] == 'H' )
2673 return LDAP_INVALID_SYNTAX;
2676 for( ; sn->bv_len < x.bv_len; sn->bv_len++ ) {
2677 if ( !ASCII_DIGIT( sn->bv_val[sn->bv_len] )) break;
2681 if (!( sn->bv_len > neg )) return LDAP_INVALID_SYNTAX;
2682 if (( sn->bv_len > 1+neg ) && ( sn->bv_val[neg] == '0' )) {
2683 return LDAP_INVALID_SYNTAX;
2686 x.bv_val += sn->bv_len; x.bv_len -= sn->bv_len;
2688 if ( x.bv_len < STRLENOF( ",issuer \"\"" )) {
2689 return LDAP_INVALID_SYNTAX;
2694 } else return LDAP_INVALID_SYNTAX;
2696 if( x.bv_val[0] != ',' ) return LDAP_INVALID_SYNTAX;
2697 x.bv_val++; x.bv_len--;
2700 for( ; (x.bv_val[0] == ' ') && x.bv_len; x.bv_val++, x.bv_len--) {
2704 /* should be at remaining NamedValue */
2705 if( !haveissuer && (strncasecmp( x.bv_val, "issuer",
2706 STRLENOF("issuer" )) == 0 ))
2709 x.bv_val += STRLENOF("issuer");
2710 x.bv_len -= STRLENOF("issuer");
2712 if( x.bv_val[0] != ' ' ) return LDAP_INVALID_SYNTAX;
2713 x.bv_val++; x.bv_len--;
2715 /* eat leading spaces */
2716 for( ; (x.bv_val[0] == ' ') && x.bv_len; x.bv_val++, x.bv_len--) {
2720 /* For backward compatibility, this part is optional */
2721 if( !strncasecmp( x.bv_val, "rdnSequence:", STRLENOF("rdnSequence:"))) {
2722 x.bv_val += STRLENOF("rdnSequence:");
2723 x.bv_len -= STRLENOF("rdnSequence:");
2726 if( x.bv_val[0] != '"' ) return LDAP_INVALID_SYNTAX;
2727 x.bv_val++; x.bv_len--;
2729 is->bv_val = x.bv_val;
2732 for( ; is->bv_len < x.bv_len; ) {
2733 if ( is->bv_val[is->bv_len] != '"' ) {
2737 if ( is->bv_val[is->bv_len+1] == '"' ) {
2744 x.bv_val += is->bv_len+1;
2745 x.bv_len -= is->bv_len+1;
2747 } else if( !havesn && (strncasecmp( x.bv_val, "serialNumber",
2748 STRLENOF("serialNumber")) == 0 ))
2750 /* parse serialNumber */
2752 x.bv_val += STRLENOF("serialNumber");
2753 x.bv_len -= STRLENOF("serialNumber");
2755 if( x.bv_val[0] != ' ' ) return LDAP_INVALID_SYNTAX;
2756 x.bv_val++; x.bv_len--;
2758 /* eat leading spaces */
2759 for( ; (x.bv_val[0] == ' ') && x.bv_len ; x.bv_val++, x.bv_len--) {
2763 sn->bv_val = x.bv_val;
2766 if( sn->bv_val[0] == '-' ) {
2771 if ( sn->bv_val[0] == '0' && ( sn->bv_val[1] == 'x' ||
2772 sn->bv_val[1] == 'X' )) {
2774 for( ; sn->bv_len < x.bv_len; sn->bv_len++ ) {
2775 if ( !ASCII_HEX( sn->bv_val[sn->bv_len] )) break;
2777 } else if ( sn->bv_val[0] == '\'' ) {
2778 for( ; sn->bv_len < x.bv_len; sn->bv_len++ ) {
2779 if ( !ASCII_HEX( sn->bv_val[sn->bv_len] )) break;
2781 if ( sn->bv_val[sn->bv_len] == '\'' &&
2782 sn->bv_val[sn->bv_len+1] == 'H' )
2785 return LDAP_INVALID_SYNTAX;
2788 for( ; sn->bv_len < x.bv_len; sn->bv_len++ ) {
2789 if ( !ASCII_DIGIT( sn->bv_val[sn->bv_len] )) break;
2793 if (!( sn->bv_len > neg )) return LDAP_INVALID_SYNTAX;
2794 if (( sn->bv_len > 1+neg ) && ( sn->bv_val[neg] == '0' )) {
2795 return LDAP_INVALID_SYNTAX;
2798 x.bv_val += sn->bv_len;
2799 x.bv_len -= sn->bv_len;
2801 } else return LDAP_INVALID_SYNTAX;
2803 /* eat trailing spaces */
2804 for( ; (x.bv_val[0] == ' ') && x.bv_len; x.bv_val++, x.bv_len--) {
2808 /* should have no characters left... */
2809 if( x.bv_len ) return LDAP_INVALID_SYNTAX;
2811 ber_dupbv_x( &ni, is, ctx );
2814 /* need to handle double dquotes here */
2820 serialNumberAndIssuerValidate(
2825 struct berval sn, i;
2827 Debug( LDAP_DEBUG_TRACE, ">>> serialNumberAndIssuerValidate: <%s>\n",
2830 rc = serialNumberAndIssuerCheck( in, &sn, &i, NULL );
2834 /* validate DN -- doesn't handle double dquote */
2835 rc = dnValidate( NULL, &i );
2837 rc = LDAP_INVALID_SYNTAX;
2839 if( in->bv_val[0] == '{' && in->bv_val[in->bv_len-1] == '}' ) {
2840 slap_sl_free( i.bv_val, NULL );
2843 Debug( LDAP_DEBUG_TRACE, "<<< serialNumberAndIssuerValidate: OKAY\n",
2849 serialNumberAndIssuerPretty(
2856 struct berval sn, i, ni;
2858 assert( in != NULL );
2859 assert( out != NULL );
2861 Debug( LDAP_DEBUG_TRACE, ">>> serialNumberAndIssuerPretty: <%s>\n",
2864 rc = serialNumberAndIssuerCheck( in, &sn, &i, ctx );
2868 rc = dnPretty( syntax, &i, &ni, ctx );
2870 if( in->bv_val[0] == '{' && in->bv_val[in->bv_len-1] == '}' ) {
2871 slap_sl_free( i.bv_val, ctx );
2874 if( rc ) return LDAP_INVALID_SYNTAX;
2876 /* make room from sn + "$" */
2877 out->bv_len = STRLENOF("{ serialNumber , issuer rdnSequence:\"\" }")
2878 + sn.bv_len + ni.bv_len;
2879 out->bv_val = slap_sl_malloc( out->bv_len + 1, ctx );
2881 if( out->bv_val == NULL ) {
2883 slap_sl_free( ni.bv_val, ctx );
2888 AC_MEMCPY( &out->bv_val[n], "{ serialNumber ",
2889 STRLENOF("{ serialNumber "));
2890 n = STRLENOF("{ serialNumber ");
2892 AC_MEMCPY( &out->bv_val[n], sn.bv_val, sn.bv_len );
2895 AC_MEMCPY( &out->bv_val[n], ", issuer rdnSequence:\"", STRLENOF(", issuer rdnSequence:\""));
2896 n += STRLENOF(", issuer rdnSequence:\"");
2898 AC_MEMCPY( &out->bv_val[n], ni.bv_val, ni.bv_len );
2901 AC_MEMCPY( &out->bv_val[n], "\" }", STRLENOF("\" }"));
2902 n += STRLENOF("\" }");
2904 out->bv_val[n] = '\0';
2906 assert( n == out->bv_len );
2908 Debug( LDAP_DEBUG_TRACE, "<<< serialNumberAndIssuerPretty: <%s>\n",
2909 out->bv_val, 0, 0 );
2911 slap_sl_free( ni.bv_val, ctx );
2913 return LDAP_SUCCESS;
2917 * This routine is called by certificateExactNormalize when
2918 * certificateExactNormalize receives a search string instead of
2919 * a certificate. This routine checks if the search value is valid
2920 * and then returns the normalized value
2923 serialNumberAndIssuerNormalize(
2931 struct berval sn, sn2, i, ni;
2932 char sbuf[64], *stmp = sbuf;
2937 assert( in != NULL );
2938 assert( out != NULL );
2940 Debug( LDAP_DEBUG_TRACE, ">>> serialNumberAndIssuerNormalize: <%s>\n",
2943 rc = serialNumberAndIssuerCheck( in, &sn, &i, ctx );
2947 rc = dnNormalize( usage, syntax, mr, &i, &ni, ctx );
2949 if( in->bv_val[0] == '{' && in->bv_val[in->bv_len-1] == '}' ) {
2950 slap_sl_free( i.bv_val, ctx );
2953 if( rc ) return LDAP_INVALID_SYNTAX;
2955 /* Convert sn to canonical hex */
2956 if ( sn.bv_len > sizeof( sbuf )) {
2957 stmp = slap_sl_malloc( sn.bv_len, ctx );
2960 sn2.bv_len = sn.bv_len;
2961 if ( lutil_str2bin( &sn, &sn2 )) {
2962 rc = LDAP_INVALID_SYNTAX;
2966 /* make room for sn + "$" */
2967 out->bv_len = STRLENOF( "{ serialNumber , issuer rdnSequence:\"\" }" )
2968 + ( sn2.bv_len * 2 + 3 ) + ni.bv_len;
2969 out->bv_val = slap_sl_malloc( out->bv_len + 1, ctx );
2971 if( out->bv_val == NULL ) {
2973 slap_sl_free( ni.bv_val, ctx );
2979 AC_MEMCPY( &out->bv_val[n], "{ serialNumber ",
2980 STRLENOF( "{ serialNumber " ));
2981 n = STRLENOF( "{ serialNumber " );
2983 AC_MEMCPY( &out->bv_val[n], sn.bv_val, sn.bv_len );
2986 unsigned char *v = sn2.bv_val;
2987 out->bv_val[n++] = '\'';
2988 for ( j = 0; j < sn2.bv_len; j++ ) {
2989 sprintf( &out->bv_val[n], "%02X", v[j] );
2992 out->bv_val[n++] = '\'';
2993 out->bv_val[n++] = 'H';
2996 AC_MEMCPY( &out->bv_val[n], ", issuer rdnSequence:\"", STRLENOF( ", issuer rdnSequence:\"" ));
2997 n += STRLENOF( ", issuer rdnSequence:\"" );
2999 AC_MEMCPY( &out->bv_val[n], ni.bv_val, ni.bv_len );
3002 AC_MEMCPY( &out->bv_val[n], "\" }", STRLENOF( "\" }" ));
3003 n += STRLENOF( "\" }" );
3005 out->bv_val[n] = '\0';
3007 assert( n == out->bv_len );
3009 Debug( LDAP_DEBUG_TRACE, "<<< serialNumberAndIssuerNormalize: <%s>\n",
3010 out->bv_val, 0, 0 );
3014 slap_sl_free( stmp, ctx );
3015 slap_sl_free( ni.bv_val, ctx );
3021 certificateExactNormalize(
3026 struct berval *normalized,
3029 BerElementBuffer berbuf;
3030 BerElement *ber = (BerElement *)&berbuf;
3034 char serialbuf[64], *serial = serialbuf;
3035 ber_len_t seriallen;
3036 struct berval issuer_dn = BER_BVNULL, bvdn;
3038 int rc = LDAP_INVALID_SYNTAX;
3040 if( BER_BVISEMPTY( val ) ) goto done;
3042 if( SLAP_MR_IS_VALUE_OF_ASSERTION_SYNTAX(usage) ) {
3043 return serialNumberAndIssuerNormalize(0,NULL,NULL,val,normalized,ctx);
3046 assert( SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX(usage) != 0 );
3048 ber_init2( ber, val, LBER_USE_DER );
3049 tag = ber_skip_tag( ber, &len ); /* Signed Sequence */
3050 tag = ber_skip_tag( ber, &len ); /* Sequence */
3051 tag = ber_peek_tag( ber, &len ); /* Optional version? */
3052 if ( tag == SLAP_X509_OPT_C_VERSION ) {
3053 tag = ber_skip_tag( ber, &len );
3054 tag = ber_get_int( ber, &i ); /* version */
3057 /* NOTE: move the test here from certificateValidate,
3058 * so that we can validate certs with serial longer
3059 * than sizeof(ber_int_t) */
3060 tag = ber_peek_tag( ber, &len ); /* serial */
3062 /* Use hex format. '123456789abcdef'H
3068 tag = ber_skip_tag( ber, &len );
3069 ptr = (unsigned char *)ber->ber_ptr;
3070 ber_skip_data( ber, len );
3072 /* Check for minimal encodings */
3074 if ( ptr[0] & 0x80 ) {
3075 if (( ptr[0] == 0xff ) && ( ptr[1] & 0x80 ))
3076 return LDAP_INVALID_SYNTAX;
3077 } else if ( ptr[0] == 0 ) {
3078 if (!( ptr[1] & 0x80 ))
3079 return LDAP_INVALID_SYNTAX;
3083 seriallen = len * 2 + 4; /* quotes, H, NUL */
3084 if ( seriallen > sizeof( serialbuf ))
3085 serial = slap_sl_malloc( seriallen, ctx );
3088 for ( i = 0; i<len; i++ ) {
3089 sprintf( sptr, "%02X", ptr[i] );
3096 tag = ber_skip_tag( ber, &len ); /* SignatureAlg */
3097 ber_skip_data( ber, len );
3098 tag = ber_peek_tag( ber, &len ); /* IssuerDN */
3099 len = ber_ptrlen( ber );
3100 bvdn.bv_val = val->bv_val + len;
3101 bvdn.bv_len = val->bv_len - len;
3103 rc = dnX509normalize( &bvdn, &issuer_dn );
3104 if( rc != LDAP_SUCCESS ) goto done;
3106 normalized->bv_len = STRLENOF( "{ serialNumber , issuer rdnSequence:\"\" }" )
3107 + seriallen + issuer_dn.bv_len;
3108 normalized->bv_val = ch_malloc(normalized->bv_len+1);
3110 p = (unsigned char *)normalized->bv_val;
3112 AC_MEMCPY(p, "{ serialNumber ", STRLENOF( "{ serialNumber " ));
3113 p += STRLENOF( "{ serialNumber " );
3115 AC_MEMCPY(p, serial, seriallen);
3118 AC_MEMCPY(p, ", issuer rdnSequence:\"", STRLENOF( ", issuer rdnSequence:\"" ));
3119 p += STRLENOF( ", issuer rdnSequence:\"" );
3121 AC_MEMCPY(p, issuer_dn.bv_val, issuer_dn.bv_len);
3122 p += issuer_dn.bv_len;
3124 AC_MEMCPY(p, "\" }", STRLENOF( "\" }" ));
3125 p += STRLENOF( "\" }" );
3129 Debug( LDAP_DEBUG_TRACE, "certificateExactNormalize: %s\n",
3130 normalized->bv_val, NULL, NULL );
3135 if ( issuer_dn.bv_val ) ber_memfree( issuer_dn.bv_val );
3136 if ( serial != serialbuf ) ber_memfree_x( serial, ctx );
3148 assert( in != NULL );
3149 assert( !BER_BVISNULL( in ) );
3151 for ( i = 0; i < in->bv_len; i++ ) {
3152 if ( !ASCII_HEX( in->bv_val[ i ] ) ) {
3153 return LDAP_INVALID_SYNTAX;
3157 return LDAP_SUCCESS;
3160 /* Normalize a SID as used inside a CSN:
3161 * three-digit numeric string */
3168 struct berval *normalized,
3173 assert( val != NULL );
3174 assert( normalized != NULL );
3176 ber_dupbv_x( normalized, val, ctx );
3178 for ( i = 0; i < normalized->bv_len; i++ ) {
3179 if ( !ASCII_HEX( normalized->bv_val[ i ] ) ) {
3180 ber_memfree_x( normalized->bv_val, ctx );
3181 BER_BVZERO( normalized );
3182 return LDAP_INVALID_SYNTAX;
3185 normalized->bv_val[ i ] = TOLOWER( normalized->bv_val[ i ] );
3188 return LDAP_SUCCESS;
3196 assert( in != NULL );
3197 assert( !BER_BVISNULL( in ) );
3199 if ( in->bv_len != 3 ) {
3200 return LDAP_INVALID_SYNTAX;
3203 return hexValidate( NULL, in );
3206 /* Normalize a SID as used inside a CSN:
3207 * three-digit numeric string */
3214 struct berval *normalized,
3217 if ( val->bv_len != 3 ) {
3218 return LDAP_INVALID_SYNTAX;
3221 return hexNormalize( 0, NULL, NULL, val, normalized, ctx );
3231 return sidNormalize( SLAP_MR_VALUE_OF_SYNTAX, NULL, NULL, val, out, ctx );
3234 /* Normalize a SID as used inside a CSN, either as-is
3235 * (assertion value) or extracted from the CSN
3236 * (attribute value) */
3243 struct berval *normalized,
3251 if ( BER_BVISEMPTY( val ) ) {
3252 return LDAP_INVALID_SYNTAX;
3255 if ( SLAP_MR_IS_VALUE_OF_ASSERTION_SYNTAX(usage) ) {
3256 return sidNormalize( 0, NULL, NULL, val, normalized, ctx );
3259 assert( SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX(usage) != 0 );
3261 ptr = ber_bvchr( val, '#' );
3262 if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) {
3263 return LDAP_INVALID_SYNTAX;
3266 bv.bv_val = ptr + 1;
3267 bv.bv_len = val->bv_len - ( ptr + 1 - val->bv_val );
3269 ptr = ber_bvchr( &bv, '#' );
3270 if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) {
3271 return LDAP_INVALID_SYNTAX;
3274 bv.bv_val = ptr + 1;
3275 bv.bv_len = val->bv_len - ( ptr + 1 - val->bv_val );
3277 ptr = ber_bvchr( &bv, '#' );
3278 if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) {
3279 return LDAP_INVALID_SYNTAX;
3282 bv.bv_len = ptr - bv.bv_val;
3284 if ( bv.bv_len == 2 ) {
3285 /* OpenLDAP 2.3 SID */
3287 buf[ 1 ] = bv.bv_val[ 0 ];
3288 buf[ 2 ] = bv.bv_val[ 1 ];
3295 return sidNormalize( 0, NULL, NULL, &bv, normalized, ctx );
3307 assert( in != NULL );
3308 assert( !BER_BVISNULL( in ) );
3310 if ( BER_BVISEMPTY( in ) ) {
3311 return LDAP_INVALID_SYNTAX;
3316 ptr = ber_bvchr( &bv, '#' );
3317 if ( ptr == NULL || ptr - bv.bv_val == bv.bv_len ) {
3318 return LDAP_INVALID_SYNTAX;
3321 bv.bv_len = ptr - bv.bv_val;
3322 if ( bv.bv_len != STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ" ) &&
3323 bv.bv_len != STRLENOF( "YYYYmmddHHMMSSZ" ) )
3325 return LDAP_INVALID_SYNTAX;
3328 rc = generalizedTimeValidate( NULL, &bv );
3329 if ( rc != LDAP_SUCCESS ) {
3333 bv.bv_val = ptr + 1;
3334 bv.bv_len = in->bv_len - ( bv.bv_val - in->bv_val );
3336 ptr = ber_bvchr( &bv, '#' );
3337 if ( ptr == NULL || ptr - in->bv_val == in->bv_len ) {
3338 return LDAP_INVALID_SYNTAX;
3341 bv.bv_len = ptr - bv.bv_val;
3342 if ( bv.bv_len != 6 ) {
3343 return LDAP_INVALID_SYNTAX;
3346 rc = hexValidate( NULL, &bv );
3347 if ( rc != LDAP_SUCCESS ) {
3351 bv.bv_val = ptr + 1;
3352 bv.bv_len = in->bv_len - ( bv.bv_val - in->bv_val );
3354 ptr = ber_bvchr( &bv, '#' );
3355 if ( ptr == NULL || ptr - in->bv_val == in->bv_len ) {
3356 return LDAP_INVALID_SYNTAX;
3359 bv.bv_len = ptr - bv.bv_val;
3360 if ( bv.bv_len == 2 ) {
3361 /* tolerate old 2-digit replica-id */
3362 rc = hexValidate( NULL, &bv );
3365 rc = sidValidate( NULL, &bv );
3367 if ( rc != LDAP_SUCCESS ) {
3371 bv.bv_val = ptr + 1;
3372 bv.bv_len = in->bv_len - ( bv.bv_val - in->bv_val );
3374 if ( bv.bv_len != 6 ) {
3375 return LDAP_INVALID_SYNTAX;
3378 return hexValidate( NULL, &bv );
3381 /* Normalize a CSN in OpenLDAP 2.3 format */
3388 struct berval *normalized,
3391 struct berval gt, cnt, sid, mod;
3395 assert( SLAP_MR_IS_VALUE_OF_SYNTAX( usage ) != 0 );
3396 assert( !BER_BVISEMPTY( val ) );
3400 ptr = ber_bvchr( >, '#' );
3401 if ( ptr == NULL || ptr - gt.bv_val == gt.bv_len ) {
3402 return LDAP_INVALID_SYNTAX;
3405 gt.bv_len = ptr - gt.bv_val;
3406 assert( gt.bv_len == STRLENOF( "YYYYmmddHHMMSSZ" ) );
3408 cnt.bv_val = ptr + 1;
3409 cnt.bv_len = val->bv_len - ( cnt.bv_val - val->bv_val );
3411 ptr = ber_bvchr( &cnt, '#' );
3412 if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) {
3413 return LDAP_INVALID_SYNTAX;
3416 cnt.bv_len = ptr - cnt.bv_val;
3417 assert( cnt.bv_len == STRLENOF( "000000" ) );
3419 sid.bv_val = ptr + 1;
3420 sid.bv_len = val->bv_len - ( sid.bv_val - val->bv_val );
3422 ptr = ber_bvchr( &sid, '#' );
3423 if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) {
3424 return LDAP_INVALID_SYNTAX;
3427 sid.bv_len = ptr - sid.bv_val;
3428 assert( sid.bv_len == STRLENOF( "00" ) );
3430 mod.bv_val = ptr + 1;
3431 mod.bv_len = val->bv_len - ( mod.bv_val - val->bv_val );
3432 assert( mod.bv_len == STRLENOF( "000000" ) );
3434 normalized->bv_len = STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" );
3435 normalized->bv_val = ber_memalloc_x( normalized->bv_len + 1, ctx );
3437 ptr = normalized->bv_val;
3438 ptr = lutil_strncopy( ptr, gt.bv_val, gt.bv_len - 1 );
3439 ptr = lutil_strcopy( ptr, ".000000Z#" );
3440 ptr = lutil_strncopy( ptr, cnt.bv_val, cnt.bv_len );
3443 for ( i = 0; i < sid.bv_len; i++ ) {
3444 *ptr++ = TOLOWER( sid.bv_val[ i ] );
3447 for ( i = 0; i < mod.bv_len; i++ ) {
3448 *ptr++ = TOLOWER( mod.bv_val[ i ] );
3452 assert( ptr - normalized->bv_val == normalized->bv_len );
3454 return LDAP_SUCCESS;
3457 /* Normalize a CSN */
3464 struct berval *normalized,
3467 struct berval cnt, sid, mod;
3471 assert( val != NULL );
3472 assert( normalized != NULL );
3474 assert( SLAP_MR_IS_VALUE_OF_SYNTAX( usage ) != 0 );
3476 if ( BER_BVISEMPTY( val ) ) {
3477 return LDAP_INVALID_SYNTAX;
3480 if ( val->bv_len == STRLENOF( "YYYYmmddHHMMSSZ#SSSSSS#ID#ssssss" ) ) {
3481 /* Openldap <= 2.3 */
3483 return csnNormalize23( usage, syntax, mr, val, normalized, ctx );
3486 assert( val->bv_len == STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#SID#ssssss" ) );
3488 ptr = ber_bvchr( val, '#' );
3489 if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) {
3490 return LDAP_INVALID_SYNTAX;
3493 assert( ptr - val->bv_val == STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ" ) );
3495 cnt.bv_val = ptr + 1;
3496 cnt.bv_len = val->bv_len - ( cnt.bv_val - val->bv_val );
3498 ptr = ber_bvchr( &cnt, '#' );
3499 if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) {
3500 return LDAP_INVALID_SYNTAX;
3503 assert( ptr - cnt.bv_val == STRLENOF( "000000" ) );
3505 sid.bv_val = ptr + 1;
3506 sid.bv_len = val->bv_len - ( sid.bv_val - val->bv_val );
3508 ptr = ber_bvchr( &sid, '#' );
3509 if ( ptr == NULL || ptr - val->bv_val == val->bv_len ) {
3510 return LDAP_INVALID_SYNTAX;
3513 sid.bv_len = ptr - sid.bv_val;
3514 assert( sid.bv_len == STRLENOF( "000" ) );
3516 mod.bv_val = ptr + 1;
3517 mod.bv_len = val->bv_len - ( mod.bv_val - val->bv_val );
3519 assert( mod.bv_len == STRLENOF( "000000" ) );
3521 ber_dupbv_x( normalized, val, ctx );
3523 for ( i = STRLENOF( "YYYYmmddHHMMSS.uuuuuuZ#SSSSSS#" );
3524 i < normalized->bv_len; i++ )
3526 /* assume it's already validated that's all hex digits */
3527 normalized->bv_val[ i ] = TOLOWER( normalized->bv_val[ i ] );
3530 return LDAP_SUCCESS;
3540 return csnNormalize( SLAP_MR_VALUE_OF_SYNTAX, NULL, NULL, val, out, ctx );
3543 #ifndef SUPPORT_OBSOLETE_UTC_SYNTAX
3544 /* slight optimization - does not need the start parameter */
3545 #define check_time_syntax(v, start, p, f) (check_time_syntax)(v, p, f)
3550 check_time_syntax (struct berval *val,
3553 struct berval *fraction)
3556 * start=0 GeneralizedTime YYYYmmddHH[MM[SS]][(./,)d...](Z|(+/-)HH[MM])
3557 * start=1 UTCTime YYmmddHHMM[SS][Z|(+/-)HHMM]
3558 * GeneralizedTime supports leap seconds, UTCTime does not.
3560 static const int ceiling[9] = { 100, 100, 12, 31, 24, 60, 60, 24, 60 };
3561 static const int mdays[2][12] = {
3562 /* non-leap years */
3563 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
3565 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
3568 int part, c, c1, c2, tzoffset, leapyear = 0;
3571 e = p + val->bv_len;
3573 #ifdef SUPPORT_OBSOLETE_UTC_SYNTAX
3574 parts[0] = 20; /* century - any multiple of 4 from 04 to 96 */
3576 for (part = start; part < 7 && p < e; part++) {
3578 if (!ASCII_DIGIT(c1)) {
3583 return LDAP_INVALID_SYNTAX;
3586 if (!ASCII_DIGIT(c)) {
3587 return LDAP_INVALID_SYNTAX;
3589 c += c1 * 10 - '0' * 11;
3590 if ((part | 1) == 3) {
3593 return LDAP_INVALID_SYNTAX;
3596 if (c >= ceiling[part]) {
3597 if (! (c == 60 && part == 6 && start == 0))
3598 return LDAP_INVALID_SYNTAX;
3602 if (part < 5 + start) {
3603 return LDAP_INVALID_SYNTAX;
3605 for (; part < 9; part++) {
3609 /* leapyear check for the Gregorian calendar (year>1581) */
3610 if (parts[parts[1] == 0 ? 0 : 1] % 4 == 0) {
3614 if (parts[3] >= mdays[leapyear][parts[2]]) {
3615 return LDAP_INVALID_SYNTAX;
3619 fraction->bv_val = p;
3620 fraction->bv_len = 0;
3621 if (p < e && (*p == '.' || *p == ',')) {
3623 while (++p < e && ASCII_DIGIT(*p)) {
3626 if (p - fraction->bv_val == 1) {
3627 return LDAP_INVALID_SYNTAX;
3629 for (end_num = p; end_num[-1] == '0'; --end_num) {
3632 c = end_num - fraction->bv_val;
3633 if (c != 1) fraction->bv_len = c;
3639 return start == 0 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
3645 return LDAP_INVALID_SYNTAX;
3651 for (part = 7; part < 9 && p < e; part++) {
3653 if (!ASCII_DIGIT(c1)) {
3658 return LDAP_INVALID_SYNTAX;
3661 if (!ASCII_DIGIT(c2)) {
3662 return LDAP_INVALID_SYNTAX;
3664 parts[part] = c1 * 10 + c2 - '0' * 11;
3665 if (parts[part] >= ceiling[part]) {
3666 return LDAP_INVALID_SYNTAX;
3669 if (part < 8 + start) {
3670 return LDAP_INVALID_SYNTAX;
3673 if (tzoffset == '-') {
3674 /* negative offset to UTC, ie west of Greenwich */
3675 parts[4] += parts[7];
3676 parts[5] += parts[8];
3677 /* offset is just hhmm, no seconds */
3678 for (part = 6; --part >= 0; ) {
3682 c = mdays[leapyear][parts[2]];
3684 if (parts[part] >= c) {
3686 return LDAP_INVALID_SYNTAX;
3691 } else if (part != 5) {
3696 /* positive offset to UTC, ie east of Greenwich */
3697 parts[4] -= parts[7];
3698 parts[5] -= parts[8];
3699 for (part = 6; --part >= 0; ) {
3700 if (parts[part] < 0) {
3702 return LDAP_INVALID_SYNTAX;
3707 /* make first arg to % non-negative */
3708 c = mdays[leapyear][(parts[2] - 1 + 12) % 12];
3713 } else if (part != 5) {
3720 return p != e ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
3723 #ifdef SUPPORT_OBSOLETE_UTC_SYNTAX
3730 struct berval *normalized )
3734 rc = check_time_syntax(val, 1, parts, NULL);
3735 if (rc != LDAP_SUCCESS) {
3739 normalized->bv_val = ch_malloc( 14 );
3740 if ( normalized->bv_val == NULL ) {
3741 return LBER_ERROR_MEMORY;
3744 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02dZ",
3745 parts[1], parts[2] + 1, parts[3] + 1,
3746 parts[4], parts[5], parts[6] );
3747 normalized->bv_len = 13;
3749 return LDAP_SUCCESS;
3759 return check_time_syntax(in, 1, parts, NULL);
3762 #endif /* SUPPORT_OBSOLETE_UTC_SYNTAX */
3765 generalizedTimeValidate(
3770 struct berval fraction;
3771 return check_time_syntax(in, 0, parts, &fraction);
3775 generalizedTimeNormalize(
3780 struct berval *normalized,
3785 struct berval fraction;
3787 rc = check_time_syntax(val, 0, parts, &fraction);
3788 if (rc != LDAP_SUCCESS) {
3792 len = STRLENOF("YYYYmmddHHMMSSZ") + fraction.bv_len;
3793 normalized->bv_val = slap_sl_malloc( len + 1, ctx );
3794 if ( BER_BVISNULL( normalized ) ) {
3795 return LBER_ERROR_MEMORY;
3798 sprintf( normalized->bv_val, "%02d%02d%02d%02d%02d%02d%02d",
3799 parts[0], parts[1], parts[2] + 1, parts[3] + 1,
3800 parts[4], parts[5], parts[6] );
3801 if ( !BER_BVISEMPTY( &fraction ) ) {
3802 memcpy( normalized->bv_val + STRLENOF("YYYYmmddHHMMSSZ")-1,
3803 fraction.bv_val, fraction.bv_len );
3804 normalized->bv_val[STRLENOF("YYYYmmddHHMMSSZ")-1] = '.';
3806 strcpy( normalized->bv_val + len-1, "Z" );
3807 normalized->bv_len = len;
3809 return LDAP_SUCCESS;
3813 generalizedTimeOrderingMatch(
3818 struct berval *value,
3819 void *assertedValue )
3821 struct berval *asserted = (struct berval *) assertedValue;
3822 ber_len_t v_len = value->bv_len;
3823 ber_len_t av_len = asserted->bv_len;
3825 /* ignore trailing 'Z' when comparing */
3826 int match = memcmp( value->bv_val, asserted->bv_val,
3827 (v_len < av_len ? v_len : av_len) - 1 );
3828 if ( match == 0 ) match = v_len - av_len;
3831 return LDAP_SUCCESS;
3834 /* Index generation function */
3835 int generalizedTimeIndexer(
3840 struct berval *prefix,
3848 BerValue bvtmp; /* 40 bit index */
3850 struct lutil_timet tt;
3852 bvtmp.bv_len = sizeof(tmp);
3854 for( i=0; values[i].bv_val != NULL; i++ ) {
3855 /* just count them */
3858 /* we should have at least one value at this point */
3861 keys = slap_sl_malloc( sizeof( struct berval ) * (i+1), ctx );
3863 /* GeneralizedTime YYYYmmddHH[MM[SS]][(./,)d...](Z|(+/-)HH[MM]) */
3864 for( i=0, j=0; values[i].bv_val != NULL; i++ ) {
3865 assert(values[i].bv_val != NULL && values[i].bv_len >= 10);
3866 /* Use 40 bits of time for key */
3867 if ( lutil_parsetime( values[i].bv_val, &tm ) == 0 ) {
3868 lutil_tm2time( &tm, &tt );
3869 tmp[0] = tt.tt_gsec & 0xff;
3870 tmp[4] = tt.tt_sec & 0xff;
3872 tmp[3] = tt.tt_sec & 0xff;
3874 tmp[2] = tt.tt_sec & 0xff;
3876 tmp[1] = tt.tt_sec & 0xff;
3878 ber_dupbv_x(&keys[j++], &bvtmp, ctx );
3882 keys[j].bv_val = NULL;
3887 return LDAP_SUCCESS;
3890 /* Index generation function */
3891 int generalizedTimeFilter(
3896 struct berval *prefix,
3897 void * assertedValue,
3903 BerValue bvtmp; /* 40 bit index */
3904 BerValue *value = (BerValue *) assertedValue;
3906 struct lutil_timet tt;
3908 bvtmp.bv_len = sizeof(tmp);
3910 /* GeneralizedTime YYYYmmddHH[MM[SS]][(./,)d...](Z|(+/-)HH[MM]) */
3911 /* Use 40 bits of time for key */
3912 if ( value->bv_val && value->bv_len >= 10 &&
3913 lutil_parsetime( value->bv_val, &tm ) == 0 ) {
3915 lutil_tm2time( &tm, &tt );
3916 tmp[0] = tt.tt_gsec & 0xff;
3917 tmp[4] = tt.tt_sec & 0xff;
3919 tmp[3] = tt.tt_sec & 0xff;
3921 tmp[2] = tt.tt_sec & 0xff;
3923 tmp[1] = tt.tt_sec & 0xff;
3925 keys = slap_sl_malloc( sizeof( struct berval ) * 2, ctx );
3926 ber_dupbv_x(keys, &bvtmp, ctx );
3927 keys[1].bv_val = NULL;
3935 return LDAP_SUCCESS;
3939 deliveryMethodValidate(
3941 struct berval *val )
3944 #define LENOF(s) (sizeof(s)-1)
3945 struct berval tmp = *val;
3947 * DeliveryMethod = pdm *( WSP DOLLAR WSP DeliveryMethod )
3948 * pdm = "any" / "mhs" / "physical" / "telex" / "teletex" /
3949 * "g3fax" / "g4fax" / "ia5" / "videotex" / "telephone"
3952 if( tmp.bv_len < 3 ) return LDAP_INVALID_SYNTAX;
3954 switch( tmp.bv_val[0] ) {
3957 if(( tmp.bv_len >= LENOF("any") ) &&
3958 ( strncasecmp(tmp.bv_val, "any", LENOF("any")) == 0 ))
3960 tmp.bv_len -= LENOF("any");
3961 tmp.bv_val += LENOF("any");
3964 return LDAP_INVALID_SYNTAX;
3968 if(( tmp.bv_len >= LENOF("mhs") ) &&
3969 ( strncasecmp(tmp.bv_val, "mhs", LENOF("mhs")) == 0 ))
3971 tmp.bv_len -= LENOF("mhs");
3972 tmp.bv_val += LENOF("mhs");
3975 return LDAP_INVALID_SYNTAX;
3979 if(( tmp.bv_len >= LENOF("physical") ) &&
3980 ( strncasecmp(tmp.bv_val, "physical", LENOF("physical")) == 0 ))
3982 tmp.bv_len -= LENOF("physical");
3983 tmp.bv_val += LENOF("physical");
3986 return LDAP_INVALID_SYNTAX;
3989 case 'T': /* telex or teletex or telephone */
3990 if(( tmp.bv_len >= LENOF("telex") ) &&
3991 ( strncasecmp(tmp.bv_val, "telex", LENOF("telex")) == 0 ))
3993 tmp.bv_len -= LENOF("telex");
3994 tmp.bv_val += LENOF("telex");
3997 if(( tmp.bv_len >= LENOF("teletex") ) &&
3998 ( strncasecmp(tmp.bv_val, "teletex", LENOF("teletex")) == 0 ))
4000 tmp.bv_len -= LENOF("teletex");
4001 tmp.bv_val += LENOF("teletex");
4004 if(( tmp.bv_len >= LENOF("telephone") ) &&
4005 ( strncasecmp(tmp.bv_val, "telephone", LENOF("telephone")) == 0 ))
4007 tmp.bv_len -= LENOF("telephone");
4008 tmp.bv_val += LENOF("telephone");
4011 return LDAP_INVALID_SYNTAX;
4014 case 'G': /* g3fax or g4fax */
4015 if(( tmp.bv_len >= LENOF("g3fax") ) && (
4016 ( strncasecmp(tmp.bv_val, "g3fax", LENOF("g3fax")) == 0 ) ||
4017 ( strncasecmp(tmp.bv_val, "g4fax", LENOF("g4fax")) == 0 )))
4019 tmp.bv_len -= LENOF("g3fax");
4020 tmp.bv_val += LENOF("g3fax");
4023 return LDAP_INVALID_SYNTAX;
4027 if(( tmp.bv_len >= LENOF("ia5") ) &&
4028 ( strncasecmp(tmp.bv_val, "ia5", LENOF("ia5")) == 0 ))
4030 tmp.bv_len -= LENOF("ia5");
4031 tmp.bv_val += LENOF("ia5");
4034 return LDAP_INVALID_SYNTAX;
4038 if(( tmp.bv_len >= LENOF("videotex") ) &&
4039 ( strncasecmp(tmp.bv_val, "videotex", LENOF("videotex")) == 0 ))
4041 tmp.bv_len -= LENOF("videotex");
4042 tmp.bv_val += LENOF("videotex");
4045 return LDAP_INVALID_SYNTAX;
4048 return LDAP_INVALID_SYNTAX;
4051 if( BER_BVISEMPTY( &tmp ) ) return LDAP_SUCCESS;
4053 while( !BER_BVISEMPTY( &tmp ) && ( tmp.bv_val[0] == ' ' ) ) {
4057 if( !BER_BVISEMPTY( &tmp ) && ( tmp.bv_val[0] == '$' ) ) {
4061 return LDAP_INVALID_SYNTAX;
4063 while( !BER_BVISEMPTY( &tmp ) && ( tmp.bv_val[0] == ' ' ) ) {
4072 nisNetgroupTripleValidate(
4074 struct berval *val )
4079 if ( BER_BVISEMPTY( val ) ) {
4080 return LDAP_INVALID_SYNTAX;
4083 p = (char *)val->bv_val;
4084 e = p + val->bv_len;
4086 if ( *p != '(' /*')'*/ ) {
4087 return LDAP_INVALID_SYNTAX;
4090 for ( p++; ( p < e ) && ( *p != /*'('*/ ')' ); p++ ) {
4094 return LDAP_INVALID_SYNTAX;
4097 } else if ( !AD_CHAR( *p ) ) {
4098 return LDAP_INVALID_SYNTAX;
4102 if ( ( commas != 2 ) || ( *p != /*'('*/ ')' ) ) {
4103 return LDAP_INVALID_SYNTAX;
4109 return LDAP_INVALID_SYNTAX;
4112 return LDAP_SUCCESS;
4116 bootParameterValidate(
4118 struct berval *val )
4122 if ( BER_BVISEMPTY( val ) ) {
4123 return LDAP_INVALID_SYNTAX;
4126 p = (char *)val->bv_val;
4127 e = p + val->bv_len;
4130 for (; ( p < e ) && ( *p != '=' ); p++ ) {
4131 if ( !AD_CHAR( *p ) ) {
4132 return LDAP_INVALID_SYNTAX;
4137 return LDAP_INVALID_SYNTAX;
4141 for ( p++; ( p < e ) && ( *p != ':' ); p++ ) {
4142 if ( !AD_CHAR( *p ) ) {
4143 return LDAP_INVALID_SYNTAX;
4148 return LDAP_INVALID_SYNTAX;
4152 for ( p++; p < e; p++ ) {
4153 if ( !SLAP_PRINTABLE( *p ) ) {
4154 return LDAP_INVALID_SYNTAX;
4158 return LDAP_SUCCESS;
4162 firstComponentNormalize(
4167 struct berval *normalized,
4174 if( SLAP_MR_IS_VALUE_OF_ASSERTION_SYNTAX( usage )) {
4175 ber_dupbv_x( normalized, val, ctx );
4176 return LDAP_SUCCESS;
4179 if( val->bv_len < 3 ) return LDAP_INVALID_SYNTAX;
4181 if( val->bv_val[0] != '(' /*')'*/ &&
4182 val->bv_val[0] != '{' /*'}'*/ )
4184 return LDAP_INVALID_SYNTAX;
4187 /* trim leading white space */
4189 len < val->bv_len && ASCII_SPACE(val->bv_val[len]);
4195 /* grab next word */
4196 comp.bv_val = &val->bv_val[len];
4197 len = val->bv_len - len;
4198 for( comp.bv_len = 0;
4199 !ASCII_SPACE(comp.bv_val[comp.bv_len]) && comp.bv_len < len;
4205 if( mr == slap_schema.si_mr_objectIdentifierFirstComponentMatch ) {
4206 rc = numericoidValidate( NULL, &comp );
4207 } else if( mr == slap_schema.si_mr_integerFirstComponentMatch ) {
4208 rc = integerValidate( NULL, &comp );
4210 rc = LDAP_INVALID_SYNTAX;
4214 if( rc == LDAP_SUCCESS ) {
4215 ber_dupbv_x( normalized, &comp, ctx );
4221 static char *country_gen_syn[] = {
4222 "1.3.6.1.4.1.1466.115.121.1.15",
4223 "1.3.6.1.4.1.1466.115.121.1.26",
4224 "1.3.6.1.4.1.1466.115.121.1.44",
4228 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
4229 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
4231 static slap_syntax_defs_rec syntax_defs[] = {
4232 {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' "
4233 X_BINARY X_NOT_H_R ")",
4234 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
4235 {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
4236 0, NULL, NULL, NULL},
4237 {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
4238 0, NULL, NULL, NULL},
4239 {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' "
4241 SLAP_SYNTAX_BLOB, NULL, blobValidate, NULL},
4242 {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' "
4244 SLAP_SYNTAX_BER, NULL, berValidate, NULL},
4245 {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
4246 0, NULL, bitStringValidate, NULL },
4247 {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
4248 0, NULL, booleanValidate, NULL},
4249 {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
4250 X_BINARY X_NOT_H_R ")",
4251 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER,
4252 NULL, certificateValidate, NULL},
4253 {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
4254 X_BINARY X_NOT_H_R ")",
4255 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER,
4256 NULL, certificateListValidate, NULL},
4257 {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
4258 X_BINARY X_NOT_H_R ")",
4259 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER,
4260 NULL, sequenceValidate, NULL},
4261 #if 0 /* need to go __after__ printableString */
4262 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4263 0, "1.3.6.1.4.1.1466.115.121.1.44",
4264 countryStringValidate, NULL},
4266 {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
4267 0, NULL, dnValidate, dnPretty},
4268 {"( 1.2.36.79672281.1.5.0 DESC 'RDN' )",
4269 0, NULL, rdnValidate, rdnPretty},
4270 #ifdef LDAP_COMP_MATCH
4271 {"( 1.2.36.79672281.1.5.3 DESC 'allComponents' )",
4272 0, NULL, allComponentsValidate, NULL},
4273 {"( 1.2.36.79672281.1.5.2 DESC 'componentFilterMatch assertion') ",
4274 0, NULL, componentFilterValidate, NULL},
4276 {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
4277 0, NULL, NULL, NULL},
4278 {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
4279 0, NULL, deliveryMethodValidate, NULL},
4280 {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
4281 0, NULL, UTF8StringValidate, NULL},
4282 {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
4283 0, NULL, NULL, NULL},
4284 {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
4285 0, NULL, NULL, NULL},
4286 {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
4287 0, NULL, NULL, NULL},
4288 {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
4289 0, NULL, NULL, NULL},
4290 {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
4291 0, NULL, NULL, NULL},
4292 {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
4293 0, NULL, printablesStringValidate, NULL},
4294 {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
4295 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
4296 {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
4297 0, NULL, generalizedTimeValidate, NULL},
4298 {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
4299 0, NULL, NULL, NULL},
4300 {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
4301 0, NULL, IA5StringValidate, NULL},
4302 {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
4303 0, NULL, integerValidate, NULL},
4304 {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
4305 SLAP_SYNTAX_BLOB, NULL, blobValidate, NULL},
4306 {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
4307 0, NULL, NULL, NULL},
4308 {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
4309 0, NULL, NULL, NULL},
4310 {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
4311 0, NULL, NULL, NULL},
4312 {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
4313 0, NULL, NULL, NULL},
4314 {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
4315 0, NULL, NULL, NULL},
4316 {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
4317 0, NULL, nameUIDValidate, nameUIDPretty },
4318 {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
4319 0, NULL, NULL, NULL},
4320 {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
4321 0, NULL, numericStringValidate, NULL},
4322 {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
4323 0, NULL, NULL, NULL},
4324 {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
4325 0, NULL, numericoidValidate, NULL},
4326 {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
4327 0, NULL, IA5StringValidate, NULL},
4328 {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
4329 0, NULL, blobValidate, NULL},
4330 {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
4331 0, NULL, UTF8StringValidate, NULL},
4332 {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
4333 0, NULL, NULL, NULL},
4334 {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
4335 0, NULL, NULL, NULL},
4336 {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
4337 0, NULL, printableStringValidate, NULL},
4338 /* moved here because now depends on Directory String, IA5 String
4339 * and Printable String */
4340 {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
4341 0, country_gen_syn, countryStringValidate, NULL},
4342 {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' )",
4343 #define subtreeSpecificationValidate UTF8StringValidate /* FIXME */
4344 0, NULL, subtreeSpecificationValidate, NULL},
4345 {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
4346 X_BINARY X_NOT_H_R ")",
4347 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, berValidate, NULL},
4348 {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
4349 0, NULL, printableStringValidate, NULL},
4350 {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
4351 0, NULL, NULL, NULL},
4352 {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
4353 0, NULL, printablesStringValidate, NULL},
4354 #ifdef SUPPORT_OBSOLETE_UTC_SYNTAX
4355 {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
4356 0, NULL, utcTimeValidate, NULL},
4358 {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
4359 0, NULL, NULL, NULL},
4360 {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
4361 0, NULL, NULL, NULL},
4362 {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
4363 0, NULL, NULL, NULL},
4364 {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
4365 0, NULL, NULL, NULL},
4366 {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
4367 0, NULL, NULL, NULL},
4369 /* RFC 2307 NIS Syntaxes */
4370 {"( 1.3.6.1.1.1.0.0 DESC 'RFC2307 NIS Netgroup Triple' )",
4371 0, NULL, nisNetgroupTripleValidate, NULL},
4372 {"( 1.3.6.1.1.1.0.1 DESC 'RFC2307 Boot Parameter' )",
4373 0, NULL, bootParameterValidate, NULL},
4375 /* draft-zeilenga-ldap-x509 */
4376 {"( 1.3.6.1.1.15.1 DESC 'Certificate Exact Assertion' )",
4377 SLAP_SYNTAX_HIDE, NULL,
4378 serialNumberAndIssuerValidate,
4379 serialNumberAndIssuerPretty},
4380 {"( 1.3.6.1.1.15.2 DESC 'Certificate Assertion' )",
4381 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4382 {"( 1.3.6.1.1.15.3 DESC 'Certificate Pair Exact Assertion' )",
4383 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4384 {"( 1.3.6.1.1.15.4 DESC 'Certificate Pair Assertion' )",
4385 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4386 {"( 1.3.6.1.1.15.5 DESC 'Certificate List Exact Assertion' )",
4387 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4388 {"( 1.3.6.1.1.15.6 DESC 'Certificate List Assertion' )",
4389 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4390 {"( 1.3.6.1.1.15.7 DESC 'Algorithm Identifier' )",
4391 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4393 #ifdef SLAPD_AUTHPASSWD
4394 /* needs updating */
4395 {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
4396 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
4399 {"( 1.3.6.1.1.16.1 DESC 'UUID' )",
4400 0, NULL, UUIDValidate, UUIDPretty},
4402 {"( 1.3.6.1.4.1.4203.666.11.2.1 DESC 'CSN' )",
4403 SLAP_SYNTAX_HIDE, NULL, csnValidate, csnPretty },
4405 {"( 1.3.6.1.4.1.4203.666.11.2.4 DESC 'CSN SID' )",
4406 SLAP_SYNTAX_HIDE, NULL, sidValidate, sidPretty },
4408 /* OpenLDAP Void Syntax */
4409 {"( 1.3.6.1.4.1.4203.1.1.1 DESC 'OpenLDAP void' )" ,
4410 SLAP_SYNTAX_HIDE, NULL, inValidate, NULL},
4412 /* FIXME: OID is unused, but not registered yet */
4413 {"( 1.3.6.1.4.1.4203.666.2.7 DESC 'OpenLDAP authz' )",
4414 SLAP_SYNTAX_HIDE, NULL, authzValidate, authzPretty},
4416 {NULL, 0, NULL, NULL, NULL}
4419 char *csnSIDMatchSyntaxes[] = {
4420 "1.3.6.1.4.1.4203.666.11.2.1" /* csn */,
4423 char *certificateExactMatchSyntaxes[] = {
4424 "1.3.6.1.4.1.1466.115.121.1.8" /* certificate */,
4427 #ifdef LDAP_COMP_MATCH
4428 char *componentFilterMatchSyntaxes[] = {
4429 "1.3.6.1.4.1.1466.115.121.1.8" /* certificate */,
4433 char *directoryStringSyntaxes[] = {
4434 "1.3.6.1.4.1.1466.115.121.1.44" /* printableString */,
4437 char *integerFirstComponentMatchSyntaxes[] = {
4438 "1.3.6.1.4.1.1466.115.121.1.27" /* INTEGER */,
4439 "1.3.6.1.4.1.1466.115.121.1.17" /* dITStructureRuleDescription */,
4442 char *objectIdentifierFirstComponentMatchSyntaxes[] = {
4443 "1.3.6.1.4.1.1466.115.121.1.38" /* OID */,
4444 "1.3.6.1.4.1.1466.115.121.1.3" /* attributeTypeDescription */,
4445 "1.3.6.1.4.1.1466.115.121.1.16" /* dITContentRuleDescription */,
4446 "1.3.6.1.4.1.1466.115.121.1.54" /* ldapSyntaxDescription */,
4447 "1.3.6.1.4.1.1466.115.121.1.30" /* matchingRuleDescription */,
4448 "1.3.6.1.4.1.1466.115.121.1.31" /* matchingRuleUseDescription */,
4449 "1.3.6.1.4.1.1466.115.121.1.35" /* nameFormDescription */,
4450 "1.3.6.1.4.1.1466.115.121.1.37" /* objectClassDescription */,
4455 * Other matching rules in X.520 that we do not use (yet):
4457 * 2.5.13.25 uTCTimeMatch
4458 * 2.5.13.26 uTCTimeOrderingMatch
4459 * 2.5.13.31* directoryStringFirstComponentMatch
4460 * 2.5.13.32* wordMatch
4461 * 2.5.13.33* keywordMatch
4462 * 2.5.13.36+ certificatePairExactMatch
4463 * 2.5.13.37+ certificatePairMatch
4464 * 2.5.13.38+ certificateListExactMatch
4465 * 2.5.13.39+ certificateListMatch
4466 * 2.5.13.40+ algorithmIdentifierMatch
4467 * 2.5.13.41* storedPrefixMatch
4468 * 2.5.13.42 attributeCertificateMatch
4469 * 2.5.13.43 readerAndKeyIDMatch
4470 * 2.5.13.44 attributeIntegrityMatch
4472 * (*) described in RFC 3698 (LDAP: Additional Matching Rules)
4473 * (+) described in draft-zeilenga-ldap-x509
4475 static slap_mrule_defs_rec mrule_defs[] = {
4477 * EQUALITY matching rules must be listed after associated APPROX
4478 * matching rules. So, we list all APPROX matching rules first.
4480 {"( " directoryStringApproxMatchOID " NAME 'directoryStringApproxMatch' "
4481 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4482 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT, NULL,
4483 NULL, NULL, directoryStringApproxMatch,
4484 directoryStringApproxIndexer, directoryStringApproxFilter,
4487 {"( " IA5StringApproxMatchOID " NAME 'IA5StringApproxMatch' "
4488 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4489 SLAP_MR_HIDE | SLAP_MR_EQUALITY_APPROX | SLAP_MR_EXT, NULL,
4490 NULL, NULL, IA5StringApproxMatch,
4491 IA5StringApproxIndexer, IA5StringApproxFilter,
4495 * Other matching rules
4498 {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
4499 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4500 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4501 NULL, NULL, octetStringMatch,
4502 octetStringIndexer, octetStringFilter,
4505 {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
4506 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4507 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4508 NULL, dnNormalize, dnMatch,
4509 octetStringIndexer, octetStringFilter,
4512 {"( 1.3.6.1.4.1.4203.666.4.9 NAME 'dnSubtreeMatch' "
4513 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4514 SLAP_MR_HIDE | SLAP_MR_EXT, NULL,
4515 NULL, dnNormalize, dnRelativeMatch,
4519 {"( 1.3.6.1.4.1.4203.666.4.8 NAME 'dnOneLevelMatch' "
4520 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4521 SLAP_MR_HIDE | SLAP_MR_EXT, NULL,
4522 NULL, dnNormalize, dnRelativeMatch,
4526 {"( 1.3.6.1.4.1.4203.666.4.10 NAME 'dnSubordinateMatch' "
4527 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4528 SLAP_MR_HIDE | SLAP_MR_EXT, NULL,
4529 NULL, dnNormalize, dnRelativeMatch,
4533 {"( 1.3.6.1.4.1.4203.666.4.11 NAME 'dnSuperiorMatch' "
4534 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
4535 SLAP_MR_HIDE | SLAP_MR_EXT, NULL,
4536 NULL, dnNormalize, dnRelativeMatch,
4540 {"( 1.2.36.79672281.1.13.3 NAME 'rdnMatch' "
4541 "SYNTAX 1.2.36.79672281.1.5.0 )",
4542 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4543 NULL, rdnNormalize, rdnMatch,
4544 octetStringIndexer, octetStringFilter,
4547 #ifdef LDAP_COMP_MATCH
4548 {"( 1.2.36.79672281.1.13.2 NAME 'componentFilterMatch' "
4549 "SYNTAX 1.2.36.79672281.1.5.2 )",
4550 SLAP_MR_EXT|SLAP_MR_COMPONENT, componentFilterMatchSyntaxes,
4551 NULL, NULL , componentFilterMatch,
4552 octetStringIndexer, octetStringFilter,
4555 {"( 1.2.36.79672281.1.13.6 NAME 'allComponentsMatch' "
4556 "SYNTAX 1.2.36.79672281.1.5.3 )",
4557 SLAP_MR_EQUALITY|SLAP_MR_EXT|SLAP_MR_COMPONENT, NULL,
4558 NULL, NULL , allComponentsMatch,
4559 octetStringIndexer, octetStringFilter,
4562 {"( 1.2.36.79672281.1.13.7 NAME 'directoryComponentsMatch' "
4563 "SYNTAX 1.2.36.79672281.1.5.3 )",
4564 SLAP_MR_EQUALITY|SLAP_MR_EXT|SLAP_MR_COMPONENT, NULL,
4565 NULL, NULL , directoryComponentsMatch,
4566 octetStringIndexer, octetStringFilter,
4570 {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
4571 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4572 SLAP_MR_EQUALITY | SLAP_MR_EXT, directoryStringSyntaxes,
4573 NULL, UTF8StringNormalize, octetStringMatch,
4574 octetStringIndexer, octetStringFilter,
4575 directoryStringApproxMatchOID },
4577 {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
4578 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4579 SLAP_MR_ORDERING, directoryStringSyntaxes,
4580 NULL, UTF8StringNormalize, octetStringOrderingMatch,
4582 "caseIgnoreMatch" },
4584 {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
4585 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4586 SLAP_MR_SUBSTR, directoryStringSyntaxes,
4587 NULL, UTF8StringNormalize, directoryStringSubstringsMatch,
4588 octetStringSubstringsIndexer, octetStringSubstringsFilter,
4589 "caseIgnoreMatch" },
4591 {"( 2.5.13.5 NAME 'caseExactMatch' "
4592 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4593 SLAP_MR_EQUALITY | SLAP_MR_EXT, directoryStringSyntaxes,
4594 NULL, UTF8StringNormalize, octetStringMatch,
4595 octetStringIndexer, octetStringFilter,
4596 directoryStringApproxMatchOID },
4598 {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
4599 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
4600 SLAP_MR_ORDERING, directoryStringSyntaxes,
4601 NULL, UTF8StringNormalize, octetStringOrderingMatch,
4605 {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
4606 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4607 SLAP_MR_SUBSTR, directoryStringSyntaxes,
4608 NULL, UTF8StringNormalize, directoryStringSubstringsMatch,
4609 octetStringSubstringsIndexer, octetStringSubstringsFilter,
4612 {"( 2.5.13.8 NAME 'numericStringMatch' "
4613 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4614 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4615 NULL, numericStringNormalize, octetStringMatch,
4616 octetStringIndexer, octetStringFilter,
4619 {"( 2.5.13.9 NAME 'numericStringOrderingMatch' "
4620 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
4621 SLAP_MR_ORDERING, NULL,
4622 NULL, numericStringNormalize, octetStringOrderingMatch,
4624 "numericStringMatch" },
4626 {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
4627 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4628 SLAP_MR_SUBSTR, NULL,
4629 NULL, numericStringNormalize, octetStringSubstringsMatch,
4630 octetStringSubstringsIndexer, octetStringSubstringsFilter,
4631 "numericStringMatch" },
4633 {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
4634 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
4635 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4636 NULL, NULL, NULL, NULL, NULL, NULL },
4638 {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
4639 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4640 SLAP_MR_SUBSTR, NULL,
4641 NULL, NULL, NULL, NULL, NULL,
4642 "caseIgnoreListMatch" },
4644 {"( 2.5.13.13 NAME 'booleanMatch' "
4645 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )",
4646 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4647 NULL, NULL, booleanMatch,
4648 octetStringIndexer, octetStringFilter,
4651 {"( 2.5.13.14 NAME 'integerMatch' "
4652 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4653 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4654 NULL, NULL, integerMatch,
4655 octetStringIndexer, octetStringFilter,
4658 {"( 2.5.13.15 NAME 'integerOrderingMatch' "
4659 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4660 SLAP_MR_ORDERING, NULL,
4661 NULL, NULL, integerMatch,
4665 {"( 2.5.13.16 NAME 'bitStringMatch' "
4666 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
4667 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4668 NULL, NULL, octetStringMatch,
4669 octetStringIndexer, octetStringFilter,
4672 {"( 2.5.13.17 NAME 'octetStringMatch' "
4673 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4674 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4675 NULL, NULL, octetStringMatch,
4676 octetStringIndexer, octetStringFilter,
4679 {"( 2.5.13.18 NAME 'octetStringOrderingMatch' "
4680 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4681 SLAP_MR_ORDERING, NULL,
4682 NULL, NULL, octetStringOrderingMatch,
4684 "octetStringMatch" },
4686 {"( 2.5.13.19 NAME 'octetStringSubstringsMatch' "
4687 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4688 SLAP_MR_SUBSTR, NULL,
4689 NULL, NULL, octetStringSubstringsMatch,
4690 octetStringSubstringsIndexer, octetStringSubstringsFilter,
4691 "octetStringMatch" },
4693 {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
4694 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
4695 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4697 telephoneNumberNormalize, octetStringMatch,
4698 octetStringIndexer, octetStringFilter,
4701 {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
4702 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
4703 SLAP_MR_SUBSTR, NULL,
4704 NULL, telephoneNumberNormalize, octetStringSubstringsMatch,
4705 octetStringSubstringsIndexer, octetStringSubstringsFilter,
4706 "telephoneNumberMatch" },
4708 {"( 2.5.13.22 NAME 'presentationAddressMatch' "
4709 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
4710 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4711 NULL, NULL, NULL, NULL, NULL, NULL },
4713 {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
4714 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
4715 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4716 NULL, uniqueMemberNormalize, uniqueMemberMatch,
4717 uniqueMemberIndexer, uniqueMemberFilter,
4720 {"( 2.5.13.24 NAME 'protocolInformationMatch' "
4721 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
4722 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4723 NULL, NULL, NULL, NULL, NULL, NULL },
4725 {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
4726 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4727 SLAP_MR_EQUALITY | SLAP_MR_EXT | SLAP_MR_ORDERED_INDEX, NULL,
4728 NULL, generalizedTimeNormalize, octetStringMatch,
4729 generalizedTimeIndexer, generalizedTimeFilter,
4732 {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
4733 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
4734 SLAP_MR_ORDERING | SLAP_MR_ORDERED_INDEX, NULL,
4735 NULL, generalizedTimeNormalize, generalizedTimeOrderingMatch,
4737 "generalizedTimeMatch" },
4739 {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
4740 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4741 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4742 integerFirstComponentMatchSyntaxes,
4743 NULL, firstComponentNormalize, integerMatch,
4744 octetStringIndexer, octetStringFilter,
4747 {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
4748 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
4749 SLAP_MR_EQUALITY | SLAP_MR_EXT,
4750 objectIdentifierFirstComponentMatchSyntaxes,
4751 NULL, firstComponentNormalize, octetStringMatch,
4752 octetStringIndexer, octetStringFilter,
4755 {"( 2.5.13.34 NAME 'certificateExactMatch' "
4756 "SYNTAX 1.3.6.1.1.15.1 )",
4757 SLAP_MR_EQUALITY | SLAP_MR_EXT, certificateExactMatchSyntaxes,
4758 NULL, certificateExactNormalize, octetStringMatch,
4759 octetStringIndexer, octetStringFilter,
4762 {"( 2.5.13.35 NAME 'certificateMatch' "
4763 "SYNTAX 1.3.6.1.1.15.2 )",
4764 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4765 NULL, NULL, NULL, NULL, NULL,
4768 {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
4769 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4770 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4771 NULL, IA5StringNormalize, octetStringMatch,
4772 octetStringIndexer, octetStringFilter,
4773 IA5StringApproxMatchOID },
4775 {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
4776 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4777 SLAP_MR_EQUALITY | SLAP_MR_EXT, NULL,
4778 NULL, IA5StringNormalize, octetStringMatch,
4779 octetStringIndexer, octetStringFilter,
4780 IA5StringApproxMatchOID },
4782 {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
4783 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4784 SLAP_MR_SUBSTR, NULL,
4785 NULL, IA5StringNormalize, directoryStringSubstringsMatch,
4786 octetStringSubstringsIndexer, octetStringSubstringsFilter,
4787 "caseIgnoreIA5Match" },
4789 {"( 1.3.6.1.4.1.4203.1.2.1 NAME 'caseExactIA5SubstringsMatch' "
4790 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
4791 SLAP_MR_SUBSTR, NULL,
4792 NULL, IA5StringNormalize, directoryStringSubstringsMatch,
4793 octetStringSubstringsIndexer, octetStringSubstringsFilter,
4794 "caseExactIA5Match" },
4796 #ifdef SLAPD_AUTHPASSWD
4797 /* needs updating */
4798 {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
4799 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
4800 SLAP_MR_HIDE | SLAP_MR_EQUALITY, NULL,
4801 NULL, NULL, authPasswordMatch,
4806 {"( 1.2.840.113556.1.4.803 NAME 'integerBitAndMatch' "
4807 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4809 NULL, NULL, integerBitAndMatch,
4813 {"( 1.2.840.113556.1.4.804 NAME 'integerBitOrMatch' "
4814 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
4816 NULL, NULL, integerBitOrMatch,
4820 {"( 1.3.6.1.1.16.2 NAME 'UUIDMatch' "
4821 "SYNTAX 1.3.6.1.1.16.1 )",
4822 SLAP_MR_EQUALITY | SLAP_MR_MUTATION_NORMALIZER, NULL,
4823 NULL, UUIDNormalize, octetStringMatch,
4824 octetStringIndexer, octetStringFilter,
4827 {"( 1.3.6.1.1.16.3 NAME 'UUIDOrderingMatch' "
4828 "SYNTAX 1.3.6.1.1.16.1 )",
4829 SLAP_MR_ORDERING | SLAP_MR_MUTATION_NORMALIZER, NULL,
4830 NULL, UUIDNormalize, octetStringOrderingMatch,
4831 octetStringIndexer, octetStringFilter,
4834 {"( 1.3.6.1.4.1.4203.666.11.2.2 NAME 'CSNMatch' "
4835 "SYNTAX 1.3.6.1.4.1.4203.666.11.2.1 )",
4836 SLAP_MR_HIDE | SLAP_MR_EQUALITY | SLAP_MR_ORDERED_INDEX, NULL,
4837 NULL, csnNormalize, csnMatch,
4838 csnIndexer, csnFilter,
4841 {"( 1.3.6.1.4.1.4203.666.11.2.3 NAME 'CSNOrderingMatch' "
4842 "SYNTAX 1.3.6.1.4.1.4203.666.11.2.1 )",
4843 SLAP_MR_HIDE | SLAP_MR_ORDERING | SLAP_MR_ORDERED_INDEX, NULL,
4844 NULL, NULL, csnOrderingMatch,
4848 {"( 1.3.6.1.4.1.4203.666.11.2.5 NAME 'CSNSIDMatch' "
4849 "SYNTAX 1.3.6.1.4.1.4203.666.11.2.4 )",
4850 SLAP_MR_HIDE | SLAP_MR_EQUALITY | SLAP_MR_EXT, csnSIDMatchSyntaxes,
4851 NULL, csnSidNormalize, octetStringMatch,
4852 octetStringIndexer, octetStringFilter,
4855 /* FIXME: OID is unused, but not registered yet */
4856 {"( 1.3.6.1.4.1.4203.666.4.12 NAME 'authzMatch' "
4857 "SYNTAX 1.3.6.1.4.1.4203.666.2.7 )",
4858 SLAP_MR_HIDE | SLAP_MR_EQUALITY, NULL,
4859 NULL, authzNormalize, authzMatch,
4863 {NULL, SLAP_MR_NONE, NULL,
4864 NULL, NULL, NULL, NULL, NULL,
4869 slap_schema_init( void )
4874 /* we should only be called once (from main) */
4875 assert( schema_init_done == 0 );
4877 for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
4878 res = register_syntax( &syntax_defs[i] );
4881 fprintf( stderr, "slap_schema_init: Error registering syntax %s\n",
4882 syntax_defs[i].sd_desc );
4887 for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
4888 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE &&
4889 mrule_defs[i].mrd_compat_syntaxes == NULL )
4892 "slap_schema_init: Ignoring unusable matching rule %s\n",
4893 mrule_defs[i].mrd_desc );
4897 res = register_matching_rule( &mrule_defs[i] );
4901 "slap_schema_init: Error registering matching rule %s\n",
4902 mrule_defs[i].mrd_desc );
4907 res = slap_schema_load();
4908 schema_init_done = 1;
4913 schema_destroy( void )
4922 if( schema_init_done ) {
4923 ldap_pvt_thread_mutex_destroy( &ad_undef_mutex );
4924 ldap_pvt_thread_mutex_destroy( &oc_undef_mutex );