]> git.sur5r.net Git - openldap/blob - servers/slapd/schema_init.c
96e3fdbdf8bf0fa26c17a213085f8b04481f92eb
[openldap] / servers / slapd / schema_init.c
1 /* schema_init.c - init builtin schema */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/ctype.h>
13 #include <ac/string.h>
14 #include <ac/socket.h>
15
16 #include "slap.h"
17 #include "ldap_pvt.h"
18 #include "lutil_md5.h"
19
20 static int
21 octetStringMatch(
22         int *matchp,
23         unsigned use,
24         Syntax *syntax,
25         MatchingRule *mr,
26         struct berval *value,
27         void *assertedValue )
28 {
29         int match = value->bv_len - ((struct berval *) assertedValue)->bv_len;
30
31         if( match == 0 ) {
32                 match = memcmp( value->bv_val,
33                         ((struct berval *) assertedValue)->bv_val,
34                         value->bv_len );
35         }
36
37         *matchp = match;
38         return LDAP_SUCCESS;
39 }
40
41 /* Index generation function */
42 int octetStringIndexer(
43         unsigned use,
44         Syntax *syntax,
45         MatchingRule *mr,
46         struct berval *prefix,
47         struct berval **values,
48         struct berval ***keysp )
49 {
50         int i;
51         size_t slen, mlen;
52         struct berval **keys;
53         lutil_MD5_CTX   MD5context;
54         unsigned char   MD5digest[16];
55         struct berval digest;
56         digest.bv_val = MD5digest;
57         digest.bv_len = sizeof(MD5digest);
58
59         for( i=0; values[i] != NULL; i++ ) {
60                 /* just count them */
61         }
62
63         assert( i > 0 );
64
65         keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
66
67         slen = strlen( syntax->ssyn_oid );
68         mlen = strlen( mr->smr_oid );
69
70         for( i=0; values[i] != NULL; i++ ) {
71                 lutil_MD5Init( &MD5context );
72                 if( prefix != NULL && prefix->bv_len > 0 ) {
73                         lutil_MD5Update( &MD5context,
74                                 prefix->bv_val, prefix->bv_len );
75                 }
76                 lutil_MD5Update( &MD5context,
77                         syntax->ssyn_oid, slen );
78                 lutil_MD5Update( &MD5context,
79                         mr->smr_oid, mlen );
80                 lutil_MD5Update( &MD5context,
81                         values[i]->bv_val, values[i]->bv_len );
82                 lutil_MD5Final( MD5digest, &MD5context );
83
84                 keys[i] = ber_bvdup( &digest );
85         }
86
87         keys[i] = NULL;
88
89         *keysp = keys;
90
91         return LDAP_SUCCESS;
92 }
93
94 /* Index generation function */
95 int octetStringFilter(
96         unsigned use,
97         Syntax *syntax,
98         MatchingRule *mr,
99         struct berval *prefix,
100         void * assertValue,
101         struct berval ***keysp )
102 {
103         size_t slen, mlen;
104         struct berval **keys;
105         lutil_MD5_CTX   MD5context;
106         unsigned char   MD5digest[LUTIL_MD5_BYTES];
107         struct berval *value = (struct berval *) assertValue;
108         struct berval digest;
109         digest.bv_val = MD5digest;
110         digest.bv_len = sizeof(MD5digest);
111
112         slen = strlen( syntax->ssyn_oid );
113         mlen = strlen( mr->smr_oid );
114
115         keys = ch_malloc( sizeof( struct berval * ) * 2 );
116
117         lutil_MD5Init( &MD5context );
118         if( prefix != NULL && prefix->bv_len > 0 ) {
119                 lutil_MD5Update( &MD5context,
120                         prefix->bv_val, prefix->bv_len );
121         }
122         lutil_MD5Update( &MD5context,
123                 syntax->ssyn_oid, slen );
124         lutil_MD5Update( &MD5context,
125                 mr->smr_oid, mlen );
126         lutil_MD5Update( &MD5context,
127                 value->bv_val, value->bv_len );
128         lutil_MD5Final( MD5digest, &MD5context );
129
130         keys[0] = ber_bvdup( &digest );
131         keys[1] = NULL;
132
133         *keysp = keys;
134
135         return LDAP_SUCCESS;
136 }
137
138 static int
139 dnValidate(
140         Syntax *syntax,
141         struct berval *in )
142 {
143         int rc;
144         char *dn;
145
146         if( in->bv_len == 0 ) return LDAP_SUCCESS;
147
148         dn = ch_strdup( in->bv_val );
149
150         rc = dn_validate( dn ) == NULL
151                 ? LDAP_INVALID_SYNTAX : LDAP_SUCCESS;
152
153         ch_free( dn );
154         return rc;
155 }
156
157 static int
158 dnNormalize(
159         Syntax *syntax,
160         struct berval *val,
161         struct berval **normalized )
162 {
163         struct berval *out = ber_bvdup( val );
164
165         if( out->bv_len != 0 ) {
166                 char *dn;
167 #ifdef USE_DN_NORMALIZE
168                 dn = dn_normalize( out->bv_val );
169 #else
170                 dn = dn_validate( out->bv_val );
171 #endif
172
173                 if( dn == NULL ) {
174                         ber_bvfree( out );
175                         return LDAP_INVALID_SYNTAX;
176                 }
177
178                 out->bv_val = dn;
179                 out->bv_len = strlen( dn );
180         }
181
182         *normalized = out;
183         return LDAP_SUCCESS;
184 }
185
186 static int
187 dnMatch(
188         int *matchp,
189         unsigned use,
190         Syntax *syntax,
191         MatchingRule *mr,
192         struct berval *value,
193         void *assertedValue )
194 {
195         int match;
196         struct berval *asserted = (struct berval *) assertedValue;
197         
198         match = value->bv_len - asserted->bv_len;
199
200         if( match == 0 ) {
201 #ifdef USE_DN_NORMALIZE
202                 match = strcmp( value->bv_val, asserted->bv_val );
203 #else
204                 match = strcasecmp( value->bv_val, asserted->bv_val );
205 #endif
206         }
207
208         Debug( LDAP_DEBUG_ARGS, "dnMatch %d\n\t\"%s\"\n\t\"%s\"\n",
209             match, value->bv_val, asserted->bv_val );
210
211         *matchp = match;
212         return LDAP_SUCCESS;
213 }
214         
215 static int
216 inValidate(
217         Syntax *syntax,
218         struct berval *in )
219 {
220         /* any value allowed */
221         return LDAP_OTHER;
222 }
223
224 static int
225 blobValidate(
226         Syntax *syntax,
227         struct berval *in )
228 {
229         /* any value allowed */
230         return LDAP_SUCCESS;
231 }
232
233 #define berValidate blobValidate
234
235 static int
236 UTF8StringValidate(
237         Syntax *syntax,
238         struct berval *in )
239 {
240         ber_len_t count;
241         int len;
242         unsigned char *u = in->bv_val;
243
244         for( count = in->bv_len; count > 0; count-=len, u+=len ) {
245                 /* get the length indicated by the first byte */
246                 len = LDAP_UTF8_CHARLEN( u );
247
248                 /* should not be zero */
249                 if( len == 0 ) return LDAP_INVALID_SYNTAX;
250
251                 /* make sure len corresponds with the offset
252                         to the next character */
253                 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
254         }
255
256         if( count != 0 ) return LDAP_INVALID_SYNTAX;
257
258         return LDAP_SUCCESS;
259 }
260
261 static int
262 UTF8StringNormalize(
263         Syntax *syntax,
264         struct berval *val,
265         struct berval **normalized )
266 {
267         struct berval *newval;
268         char *p, *q, *s;
269
270         newval = ch_malloc( sizeof( struct berval ) );
271
272         p = val->bv_val;
273
274         /* Ignore initial whitespace */
275         while ( ldap_utf8_isspace( p ) ) {
276                 LDAP_UTF8_INCR( p );
277         }
278
279         if( *p == '\0' ) {
280                 ch_free( newval );
281                 return LDAP_INVALID_SYNTAX;
282         }
283
284         newval->bv_val = ch_strdup( p );
285         p = q = newval->bv_val;
286         s = NULL;
287
288         while ( *p ) {
289                 int len;
290
291                 if ( ldap_utf8_isspace( p ) ) {
292                         len = LDAP_UTF8_COPY(q,p);
293                         s=q;
294                         p+=len;
295                         q+=len;
296
297                         /* Ignore the extra whitespace */
298                         while ( ldap_utf8_isspace( p ) ) {
299                                 LDAP_UTF8_INCR( p );
300                         }
301                 } else {
302                         len = LDAP_UTF8_COPY(q,p);
303                         s=NULL;
304                         p+=len;
305                         q+=len;
306                 }
307         }
308
309         assert( *newval->bv_val );
310         assert( newval->bv_val < p );
311         assert( p <= q );
312
313         /* cannot start with a space */
314         assert( !ldap_utf8_isspace(newval->bv_val) );
315
316         /*
317          * If the string ended in space, backup the pointer one
318          * position.  One is enough because the above loop collapsed
319          * all whitespace to a single space.
320          */
321
322         if ( s != NULL ) {
323                 q = s;
324         }
325
326         /* cannot end with a space */
327         assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
328
329         /* null terminate */
330         *q = '\0';
331
332         newval->bv_len = q - newval->bv_val;
333         *normalized = newval;
334
335         return LDAP_SUCCESS;
336 }
337
338 static int
339 oidValidate(
340         Syntax *syntax,
341         struct berval *val )
342 {
343         ber_len_t i;
344
345         if( val->bv_len == 0 ) return 0;
346
347         if( isdigit(val->bv_val[0]) ) {
348                 int dot = 0;
349                 for(i=1; i < val->bv_len; i++) {
350                         if( val->bv_val[i] == '.' ) {
351                                 if( dot++ ) return 1;
352                         } else if ( isdigit(val->bv_val[i]) ) {
353                                 dot = 0;
354                         } else {
355                                 return LDAP_INVALID_SYNTAX;
356                         }
357                 }
358
359                 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
360
361         } else if( isalpha(val->bv_val[0]) ) {
362                 for(i=1; i < val->bv_len; i++) {
363                         if( !isalpha(val->bv_val[i] ) ) {
364                                 return LDAP_INVALID_SYNTAX;
365                         }
366                 }
367
368                 return LDAP_SUCCESS;
369         }
370         
371         return LDAP_INVALID_SYNTAX;
372 }
373
374 static int
375 integerValidate(
376         Syntax *syntax,
377         struct berval *val )
378 {
379         ber_len_t i;
380
381         for(i=0; i < val->bv_len; i++) {
382                 if( !isdigit(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
383         }
384
385         return LDAP_SUCCESS;
386 }
387
388 static int
389 printableStringValidate(
390         Syntax *syntax,
391         struct berval *val )
392 {
393         ber_len_t i;
394
395         for(i=0; i < val->bv_len; i++) {
396                 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
397         }
398
399         return LDAP_SUCCESS;
400 }
401
402 static int
403 IA5StringValidate(
404         Syntax *syntax,
405         struct berval *val )
406 {
407         ber_len_t i;
408
409         for(i=0; i < val->bv_len; i++) {
410                 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
411         }
412
413         return LDAP_SUCCESS;
414 }
415
416 static int
417 IA5StringConvert(
418         Syntax *syntax,
419         struct berval *in,
420         struct berval **out )
421 {
422         ldap_unicode_t *u;
423         ber_len_t i, len = in->bv_len;
424         struct berval *bv = ch_malloc( sizeof(struct berval) );
425
426         bv->bv_len = len * sizeof( ldap_unicode_t );
427         bv->bv_val = (char *) u = ch_malloc( bv->bv_len + sizeof( ldap_unicode_t ) );;
428
429         for(i=0; i < len; i++ ) {
430                 /*
431                  * IA5StringValidate should have been called to ensure
432                  * input is limited to IA5.
433                  */
434                 u[i] = in->bv_val[i];
435         }
436         u[i] = 0;
437
438         *out = bv;
439         return LDAP_SUCCESS;
440 }
441
442 static int
443 IA5StringNormalize(
444         Syntax *syntax,
445         struct berval *val,
446         struct berval **normalized )
447 {
448         struct berval *newval;
449         char *p, *q;
450
451         newval = ch_malloc( sizeof( struct berval ) );
452
453         p = val->bv_val;
454
455         /* Ignore initial whitespace */
456         while ( isspace( *p++ ) ) {
457                 /* EMPTY */  ;
458         }
459
460         if( *p != '\0' ) {
461                 ch_free( newval );
462                 return LDAP_INVALID_SYNTAX;
463         }
464
465         newval->bv_val = ch_strdup( p );
466         p = q = newval->bv_val;
467
468         while ( *p ) {
469                 if ( isspace( *p ) ) {
470                         *q++ = *p++;
471
472                         /* Ignore the extra whitespace */
473                         while ( isspace( *p++ ) ) {
474                                 /* EMPTY */  ;
475                         }
476                 } else {
477                         *q++ = *p++;
478                 }
479         }
480
481         assert( *newval->bv_val );
482         assert( newval->bv_val < p );
483         assert( p <= q );
484
485         /* cannot start with a space */
486         assert( !isspace(*newval->bv_val) );
487
488         /*
489          * If the string ended in space, backup the pointer one
490          * position.  One is enough because the above loop collapsed
491          * all whitespace to a single space.
492          */
493
494         if ( isspace( q[-1] ) ) {
495                 --q;
496         }
497
498         /* cannot end with a space */
499         assert( !isspace( q[-1] ) );
500
501         /* null terminate */
502         *q = '\0';
503
504         newval->bv_len = q - newval->bv_val;
505         *normalized = newval;
506
507         return LDAP_SUCCESS;
508 }
509
510 static int
511 caseExactIA5Match(
512         int *match,
513         unsigned use,
514         Syntax *syntax,
515         MatchingRule *mr,
516         struct berval *value,
517         void *assertedValue )
518 {
519         *match = strcmp( value->bv_val,
520                 ((struct berval *) assertedValue)->bv_val );
521         return LDAP_SUCCESS;
522 }
523
524 static int
525 caseExactIA5SubstringsMatch(
526         int *matchp,
527         unsigned use,
528         Syntax *syntax,
529         MatchingRule *mr,
530         struct berval *value,
531         void *assertedValue )
532 {
533         int match = 0;
534         SubstringsAssertion *sub = assertedValue;
535         struct berval left = *value;
536         int i;
537         ber_len_t inlen=0;
538
539         if( sub->sa_initial ) {
540                 inlen += sub->sa_initial->bv_len;
541         }
542         if( sub->sa_any ) {
543                 for(i=0; sub->sa_any[i]; i++) {
544                         inlen += sub->sa_final->bv_len;
545                 }
546         }
547         if( sub->sa_final ) {
548                 inlen += sub->sa_final->bv_len;
549         }
550
551         if( inlen > value->bv_len ) {
552                 match = 1;
553                 goto done;
554         }
555
556         if( sub->sa_initial ) {
557                 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
558                         sub->sa_initial->bv_len );
559
560                 if( match != 0 ) {
561                         goto done;
562                 }
563
564                 left.bv_val += sub->sa_initial->bv_len;
565                 left.bv_len -= sub->sa_initial->bv_len;
566                 inlen -= sub->sa_initial->bv_len;
567         }
568
569         if( sub->sa_final ) {
570                 match = strncmp( sub->sa_final->bv_val,
571                         &left.bv_val[left.bv_len - sub->sa_final->bv_len],
572                         sub->sa_final->bv_len );
573
574                 if( match != 0 ) {
575                         goto done;
576                 }
577
578                 left.bv_len -= sub->sa_final->bv_len;
579                 inlen -= sub->sa_initial->bv_len;
580         }
581
582         if( sub->sa_any ) {
583                 for(i=0; sub->sa_any[i]; i++) {
584                         ber_len_t idx;
585                         char *p;
586
587 retry:
588                         if( inlen < left.bv_len ) {
589                                 /* not enough length */
590                                 match = 1;
591                                 goto done;
592                         }
593
594                         if( sub->sa_any[i]->bv_len == 0 ) {
595                                 continue;
596                         }
597
598                         p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
599
600                         if( p == NULL ) {
601                                 match = 1;
602                                 goto done;
603                         }
604
605                         idx = p - left.bv_val;
606                         assert( idx < left.bv_len );
607
608                         if( idx >= left.bv_len ) {
609                                 /* this shouldn't happen */
610                                 return LDAP_OTHER;
611                         }
612
613                         left.bv_val = p;
614                         left.bv_len -= idx;
615
616                         if( sub->sa_any[i]->bv_len > left.bv_len ) {
617                                 /* not enough left */
618                                 match = 1;
619                                 goto done;
620                         }
621
622                         match = strncmp( left.bv_val,
623                                 sub->sa_any[i]->bv_val,
624                                 sub->sa_any[i]->bv_len );
625
626
627                         if( match != 0 ) {
628                                 goto retry;
629                         }
630
631                         left.bv_val += sub->sa_any[i]->bv_len;
632                         left.bv_len -= sub->sa_any[i]->bv_len;
633                 }
634         }
635
636 done:
637         *matchp = match;
638         return LDAP_SUCCESS;
639 }
640
641 static int
642 caseIgnoreIA5Match(
643         int *match,
644         unsigned use,
645         Syntax *syntax,
646         MatchingRule *mr,
647         struct berval *value,
648         void *assertedValue )
649 {
650         *match = strcasecmp( value->bv_val,
651                 ((struct berval *) assertedValue)->bv_val );
652         return LDAP_SUCCESS;
653 }
654
655 static char *strcasechr( const char *str, int c )
656 {
657         char *lower = strchr( str, TOLOWER(c) );
658         char *upper = strchr( str, TOUPPER(c) );
659
660         if( lower && upper ) {
661                 return lower < upper ? lower : upper;
662         } else if ( lower ) {
663                 return lower;
664         } else {
665                 return upper;
666         }
667 }
668
669 static int
670 caseIgnoreIA5SubstringsMatch(
671         int *matchp,
672         unsigned use,
673         Syntax *syntax,
674         MatchingRule *mr,
675         struct berval *value,
676         void *assertedValue )
677 {
678         int match = 0;
679         SubstringsAssertion *sub = assertedValue;
680         struct berval left = *value;
681         int i;
682         ber_len_t inlen=0;
683
684         if( sub->sa_initial ) {
685                 inlen += sub->sa_initial->bv_len;
686         }
687         if( sub->sa_any ) {
688                 for(i=0; sub->sa_any[i]; i++) {
689                         inlen += sub->sa_final->bv_len;
690                 }
691         }
692         if( sub->sa_final ) {
693                 inlen += sub->sa_final->bv_len;
694         }
695
696         if( inlen > value->bv_len ) {
697                 match = 1;
698                 goto done;
699         }
700
701         if( sub->sa_initial ) {
702                 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
703                         sub->sa_initial->bv_len );
704
705                 if( match != 0 ) {
706                         goto done;
707                 }
708
709                 left.bv_val += sub->sa_initial->bv_len;
710                 left.bv_len -= sub->sa_initial->bv_len;
711         }
712
713         if( sub->sa_final ) {
714                 match = strncasecmp( sub->sa_final->bv_val,
715                         &left.bv_val[left.bv_len - sub->sa_final->bv_len],
716                         sub->sa_final->bv_len );
717
718                 if( match != 0 ) {
719                         goto done;
720                 }
721
722                 left.bv_len -= sub->sa_final->bv_len;
723         }
724
725         if( sub->sa_any ) {
726                 for(i=0; sub->sa_any[i]; i++) {
727                         ber_len_t idx;
728                         char *p;
729
730 retry:
731                         if( inlen < left.bv_len ) {
732                                 /* not enough length */
733                                 match = 1;
734                                 goto done;
735                         }
736
737                         if( sub->sa_any[i]->bv_len == 0 ) {
738                                 continue;
739                         }
740
741                         p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
742
743                         if( p == NULL ) {
744                                 match = 1;
745                                 goto done;
746                         }
747
748                         idx = p - left.bv_val;
749                         assert( idx < left.bv_len );
750
751                         if( idx >= left.bv_len ) {
752                                 /* this shouldn't happen */
753                                 return LDAP_OTHER;
754                         }
755
756                         left.bv_val = p;
757                         left.bv_len -= idx;
758
759                         if( sub->sa_any[i]->bv_len > left.bv_len ) {
760                                 /* not enough left */
761                                 match = 1;
762                                 goto done;
763                         }
764
765                         match = strncasecmp( left.bv_val,
766                                 sub->sa_any[i]->bv_val,
767                                 sub->sa_any[i]->bv_len );
768
769
770                         if( match != 0 ) {
771                                 goto retry;
772                         }
773
774                         left.bv_val += sub->sa_any[i]->bv_len;
775                         left.bv_len -= sub->sa_any[i]->bv_len;
776                 }
777         }
778
779 done:
780         *matchp = match;
781         return LDAP_SUCCESS;
782 }
783
784 /* Index generation function */
785 int caseIgnoreIA5Indexer(
786         unsigned use,
787         Syntax *syntax,
788         MatchingRule *mr,
789         struct berval *prefix,
790         struct berval **values,
791         struct berval ***keysp )
792 {
793         int i;
794         size_t slen, mlen;
795         struct berval **keys;
796         lutil_MD5_CTX   MD5context;
797         unsigned char   MD5digest[16];
798         struct berval digest;
799         digest.bv_val = MD5digest;
800         digest.bv_len = sizeof(MD5digest);
801
802         for( i=0; values[i] != NULL; i++ ) {
803                 /* just count them */
804         }
805
806         assert( i > 0 );
807
808         keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
809
810         slen = strlen( syntax->ssyn_oid );
811         mlen = strlen( mr->smr_oid );
812
813         for( i=0; values[i] != NULL; i++ ) {
814                 struct berval *value = ber_bvdup( values[i] );
815                 ldap_pvt_str2upper( value->bv_val );
816
817                 lutil_MD5Init( &MD5context );
818                 if( prefix != NULL && prefix->bv_len > 0 ) {
819                         lutil_MD5Update( &MD5context,
820                                 prefix->bv_val, prefix->bv_len );
821                 }
822                 lutil_MD5Update( &MD5context,
823                         syntax->ssyn_oid, slen );
824                 lutil_MD5Update( &MD5context,
825                         mr->smr_oid, mlen );
826                 lutil_MD5Update( &MD5context,
827                         value->bv_val, value->bv_len );
828                 lutil_MD5Final( MD5digest, &MD5context );
829
830                 ber_bvfree( value );
831
832                 keys[i] = ber_bvdup( &digest );
833         }
834
835         keys[i] = NULL;
836         *keysp = keys;
837         return LDAP_SUCCESS;
838 }
839
840 /* Index generation function */
841 int caseIgnoreIA5Filter(
842         unsigned use,
843         Syntax *syntax,
844         MatchingRule *mr,
845         struct berval *prefix,
846         void * assertValue,
847         struct berval ***keysp )
848 {
849         size_t slen, mlen;
850         struct berval **keys;
851         lutil_MD5_CTX   MD5context;
852         unsigned char   MD5digest[LUTIL_MD5_BYTES];
853         struct berval *value;
854         struct berval digest;
855         digest.bv_val = MD5digest;
856         digest.bv_len = sizeof(MD5digest);
857
858         slen = strlen( syntax->ssyn_oid );
859         mlen = strlen( mr->smr_oid );
860
861         value = ber_bvdup( (struct berval *) assertValue );
862         ldap_pvt_str2upper( value->bv_val );
863
864         keys = ch_malloc( sizeof( struct berval * ) * 2 );
865
866         lutil_MD5Init( &MD5context );
867         if( prefix != NULL && prefix->bv_len > 0 ) {
868                 lutil_MD5Update( &MD5context,
869                         prefix->bv_val, prefix->bv_len );
870         }
871         lutil_MD5Update( &MD5context,
872                 syntax->ssyn_oid, slen );
873         lutil_MD5Update( &MD5context,
874                 mr->smr_oid, mlen );
875         lutil_MD5Update( &MD5context,
876                 value->bv_val, value->bv_len );
877         lutil_MD5Final( MD5digest, &MD5context );
878
879         keys[0] = ber_bvdup( &digest );
880         keys[1] = NULL;
881
882         ber_bvfree( value );
883
884         *keysp = keys;
885         return LDAP_SUCCESS;
886 }
887
888 static int
889 NumericStringNormalize(
890         Syntax *syntax,
891         struct berval *val,
892         struct berval **normalized )
893 {
894         /* similiar to IA5StringNormalize except removes all spaces */
895         struct berval *newval;
896         char *p, *q;
897
898         newval = ch_malloc( sizeof( struct berval ) );
899
900         p = val->bv_val;
901
902         /* Ignore initial whitespace */
903         while ( isspace( *p++ ) ) {
904                 /* EMPTY */  ;
905         }
906
907         if( *p != '\0' ) {
908                 ch_free( newval );
909                 return LDAP_INVALID_SYNTAX;
910         }
911
912         newval->bv_val = ch_strdup( p );
913         p = q = newval->bv_val;
914
915         while ( *p ) {
916                 if ( isspace( *p ) ) {
917                         /* Ignore whitespace */
918                         p++;
919                 } else {
920                         *q++ = *p++;
921                 }
922         }
923
924         assert( *newval->bv_val );
925         assert( newval->bv_val < p );
926         assert( p <= q );
927
928         /* cannot start with a space */
929         assert( !isspace(*newval->bv_val) );
930
931         /* cannot end with a space */
932         assert( !isspace( q[-1] ) );
933
934         /* null terminate */
935         *q = '\0';
936
937         newval->bv_len = q - newval->bv_val;
938         *normalized = newval;
939
940         return LDAP_SUCCESS;
941 }
942
943 struct syntax_defs_rec {
944         char *sd_desc;
945         int sd_flags;
946         slap_syntax_validate_func *sd_validate;
947         slap_syntax_transform_func *sd_normalize;
948         slap_syntax_transform_func *sd_pretty;
949 #ifdef SLAPD_BINARY_CONVERSION
950         slap_syntax_transform_func *sd_ber2str;
951         slap_syntax_transform_func *sd_str2ber;
952 #endif
953 };
954
955 #define X_HIDE "X-HIDE 'TRUE' "
956 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
957 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
958
959 struct syntax_defs_rec syntax_defs[] = {
960         {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
961                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
962         {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
963                 0, NULL, NULL, NULL},
964         {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
965                 0, NULL, NULL, NULL},
966         {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
967                 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
968         {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
969                 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
970         {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
971                 0, NULL, NULL, NULL},
972         {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
973                 0, NULL, NULL, NULL},
974         {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
975                 X_BINARY X_NOT_H_R ")",
976                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
977         {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
978                 X_BINARY X_NOT_H_R ")",
979                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
980         {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
981                 X_BINARY X_NOT_H_R ")",
982                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
983         {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
984                 0, NULL, NULL, NULL},
985         {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
986                 0, dnValidate, dnNormalize, NULL},
987         {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
988                 0, NULL, NULL, NULL},
989         {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
990                 0, NULL, NULL, NULL},
991         {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
992                 0, UTF8StringValidate, UTF8StringNormalize, NULL},
993         {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
994                 0, NULL, NULL, NULL},
995         {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
996                 0, NULL, NULL, NULL},
997         {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
998                 0, NULL, NULL, NULL},
999         {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
1000                 0, NULL, NULL, NULL},
1001         {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
1002                 0, NULL, NULL, NULL},
1003         {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
1004                 0, blobValidate, NULL, NULL},
1005         {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
1006                 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
1007         {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
1008                 0, NULL, NULL, NULL},
1009         {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
1010                 0, NULL, NULL, NULL},
1011         {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
1012                 0, IA5StringValidate, IA5StringNormalize, NULL},
1013         {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
1014                 0, integerValidate, NULL, NULL},
1015         {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
1016                 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
1017         {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
1018                 0, NULL, NULL, NULL},
1019         {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
1020                 0, NULL, NULL, NULL},
1021         {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
1022                 0, NULL, NULL, NULL},
1023         {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
1024                 0, NULL, NULL, NULL},
1025         {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
1026                 0, NULL, NULL, NULL},
1027         {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
1028                 0, NULL, NULL, NULL},
1029         {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
1030                 0, NULL, NULL, NULL},
1031         {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
1032                 0, IA5StringValidate, NumericStringNormalize, NULL},
1033         {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
1034                 0, NULL, NULL, NULL},
1035         {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
1036                 0, oidValidate, NULL, NULL},
1037         {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
1038                 0, NULL, NULL, NULL},
1039         {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
1040                 0, blobValidate, NULL, NULL},
1041         {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
1042                 0, blobValidate, NULL, NULL},
1043         {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
1044                 0, NULL, NULL, NULL},
1045         {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
1046                 0, NULL, NULL, NULL},
1047         {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
1048                 0, printableStringValidate, NULL, NULL},
1049         {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
1050                 X_BINARY X_NOT_H_R ")",
1051                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1052         {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
1053                 0, blobValidate, NULL, NULL},
1054         {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
1055                 0, NULL, NULL, NULL},
1056         {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
1057                 0, NULL, NULL, NULL},
1058         {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
1059                 0, NULL, NULL, NULL},
1060         {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
1061                 0, NULL, NULL, NULL},
1062         {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
1063                 0, NULL, NULL, NULL},
1064         {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
1065                 0, NULL, NULL, NULL},
1066         {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
1067                 0, NULL, NULL, NULL},
1068         {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
1069                 0, NULL, NULL, NULL},
1070
1071         /* OpenLDAP Experimental Syntaxes */
1072         {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
1073                 0, NULL, NULL, NULL},
1074         {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
1075                 0, NULL, NULL, NULL},
1076         {"( 1.3.6.1.4.1.4203.666.2.3 DESC 'OpenLDAP void' " X_HIDE ")" ,
1077                 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
1078 #if 0 /* not needed */
1079         {"( 1.3.6.1.4.1.4203.666.2.4 DESC 'OpenLDAP DN' " X_HIDE ")" ,
1080                 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
1081 #endif
1082
1083         {NULL, 0, NULL, NULL, NULL}
1084 };
1085
1086 struct mrule_defs_rec {
1087         char *                                          mrd_desc;
1088         unsigned                                        mrd_usage;
1089         slap_mr_convert_func *          mrd_convert;
1090         slap_mr_normalize_func *        mrd_normalize;
1091         slap_mr_match_func *            mrd_match;
1092         slap_mr_indexer_func *          mrd_indexer;
1093         slap_mr_filter_func *           mrd_filter;
1094 };
1095
1096 /*
1097  * Other matching rules in X.520 that we do not use:
1098  *
1099  * 2.5.13.9             numericStringOrderingMatch
1100  * 2.5.13.13    booleanMatch
1101  * 2.5.13.15    integerOrderingMatch
1102  * 2.5.13.18    octetStringOrderingMatch
1103  * 2.5.13.19    octetStringSubstringsMatch
1104  * 2.5.13.25    uTCTimeMatch
1105  * 2.5.13.26    uTCTimeOrderingMatch
1106  * 2.5.13.31    directoryStringFirstComponentMatch
1107  * 2.5.13.32    wordMatch
1108  * 2.5.13.33    keywordMatch
1109  * 2.5.13.34    certificateExactMatch
1110  * 2.5.13.35    certificateMatch
1111  * 2.5.13.36    certificatePairExactMatch
1112  * 2.5.13.37    certificatePairMatch
1113  * 2.5.13.38    certificateListExactMatch
1114  * 2.5.13.39    certificateListMatch
1115  * 2.5.13.40    algorithmIdentifierMatch
1116  * 2.5.13.41    storedPrefixMatch
1117  * 2.5.13.42    attributeCertificateMatch
1118  * 2.5.13.43    readerAndKeyIDMatch
1119  * 2.5.13.44    attributeIntegrityMatch
1120  */
1121
1122
1123 /* recycled matching functions */
1124 #define caseIgnoreMatch caseIgnoreIA5Match
1125 #define caseIgnoreOrderingMatch caseIgnoreMatch
1126 #define caseIgnoreSubstringsMatch caseIgnoreIA5SubstringsMatch
1127 #define caseExactMatch caseExactIA5Match
1128 #define caseExactOrderingMatch caseExactMatch
1129 #define caseExactSubstringsMatch caseExactIA5SubstringsMatch
1130
1131 /* unimplemented matching functions */
1132 #define objectIdentifierMatch NULL
1133 #define caseIgnoreListMatch NULL
1134 #define caseIgnoreListSubstringsMatch NULL
1135 #define integerMatch NULL
1136 #define bitStringMatch NULL
1137 #define octetStringMatch NULL
1138 #define telephoneNumberMatch NULL
1139 #define telephoneNumberSubstringsMatch NULL
1140 #define presentationAddressMatch NULL
1141 #define uniqueMemberMatch NULL
1142 #define protocolInformationMatch NULL
1143 #define generalizedTimeMatch NULL
1144 #define generalizedTimeOrderingMatch NULL
1145 #define integerFirstComponentMatch NULL
1146 #define objectIdentifierFirstComponentMatch NULL
1147
1148 #define OpenLDAPaciMatch NULL
1149 #define authPasswordMatch NULL
1150
1151 /* unimplied indexer/filter routines */
1152 #define dnIndexer NULL
1153 #define dnFilter NULL
1154
1155 #define caseIgnoreIndexer               caseIgnoreIA5Indexer
1156 #define caseIgnoreFilter                caseIgnoreIA5Filter
1157 #define caseExactIndexer                caseExactIA5Indexer
1158 #define caseExactFilter                 caseExactIA5Filter
1159 #define caseExactIA5Indexer             caseIgnoreIA5Indexer
1160 #define caseExactIA5Filter              caseIgnoreIA5Filter
1161
1162 struct mrule_defs_rec mrule_defs[] = {
1163         {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
1164                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1165                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1166                 NULL, NULL, objectIdentifierMatch,
1167                 caseIgnoreIA5Indexer, caseIgnoreIA5Filter},
1168
1169         {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
1170                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
1171                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1172                 NULL, NULL, dnMatch, dnIndexer, dnFilter},
1173
1174         {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
1175                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1176                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1177                 NULL, NULL, caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter},
1178
1179         {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
1180                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1181                 SLAP_MR_ORDERING,
1182                 NULL, NULL, caseIgnoreOrderingMatch, NULL, NULL},
1183
1184         {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
1185                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1186                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1187                 NULL, NULL, caseIgnoreSubstringsMatch, NULL, NULL},
1188
1189         /* Next three are not in the RFC's, but are needed for compatibility */
1190         {"( 2.5.13.5 NAME 'caseExactMatch' "
1191                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1192                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1193                 NULL, NULL, caseExactMatch, caseExactIndexer, caseExactFilter},
1194
1195         {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
1196                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1197                 SLAP_MR_ORDERING,
1198                 NULL, NULL, caseExactOrderingMatch, NULL, NULL},
1199
1200         {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
1201                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1202                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1203                 NULL, NULL, caseExactSubstringsMatch, NULL, NULL},
1204
1205         {"( 2.5.13.8 NAME 'numericStringMatch' "
1206                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
1207                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1208                 NULL, NULL, caseIgnoreIA5Match, NULL, NULL},
1209
1210         {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
1211                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1212                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1213                 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1214
1215         {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
1216                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
1217                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1218                 NULL, NULL, caseIgnoreListMatch, NULL, NULL},
1219
1220         {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
1221                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1222                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1223                 NULL, NULL, caseIgnoreListSubstringsMatch, NULL, NULL},
1224
1225         {"( 2.5.13.14 NAME 'integerMatch' "
1226                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1227                 SLAP_MR_NONE | SLAP_MR_EXT,
1228                 NULL, NULL, integerMatch, NULL, NULL},
1229
1230         {"( 2.5.13.16 NAME 'bitStringMatch' "
1231                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
1232                 SLAP_MR_NONE | SLAP_MR_EXT,
1233                 NULL, NULL, bitStringMatch, NULL, NULL},
1234
1235         {"( 2.5.13.17 NAME 'octetStringMatch' "
1236                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1237                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1238                 NULL, NULL, octetStringMatch, octetStringIndexer, octetStringFilter},
1239
1240         {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
1241                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
1242                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1243                 NULL, NULL, telephoneNumberMatch, NULL, NULL},
1244
1245         {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
1246                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1247                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1248                 NULL, NULL, telephoneNumberSubstringsMatch, NULL, NULL},
1249
1250         {"( 2.5.13.22 NAME 'presentationAddressMatch' "
1251                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
1252                 SLAP_MR_NONE | SLAP_MR_EXT,
1253                 NULL, NULL, presentationAddressMatch, NULL, NULL},
1254
1255         {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
1256                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
1257                 SLAP_MR_NONE | SLAP_MR_EXT,
1258                 NULL, NULL, uniqueMemberMatch, NULL, NULL},
1259
1260         {"( 2.5.13.24 NAME 'protocolInformationMatch' "
1261                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
1262                 SLAP_MR_NONE | SLAP_MR_EXT,
1263                 NULL, NULL, protocolInformationMatch, NULL, NULL},
1264
1265         {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
1266                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1267                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1268                 NULL, NULL, generalizedTimeMatch, NULL, NULL},
1269
1270         {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
1271                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1272                 SLAP_MR_ORDERING,
1273                 NULL, NULL, generalizedTimeOrderingMatch, NULL, NULL},
1274
1275         {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
1276                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1277                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1278                 NULL, NULL, integerFirstComponentMatch, NULL, NULL},
1279
1280         {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
1281                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1282                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1283                 NULL, NULL, objectIdentifierFirstComponentMatch, NULL, NULL},
1284
1285         {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
1286                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1287                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1288                 NULL, NULL, caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1289
1290         {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
1291                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1292                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1293                 NULL, NULL, caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1294
1295         {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
1296                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1297                 SLAP_MR_SUBSTR,
1298                 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1299
1300         {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
1301                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1302                 SLAP_MR_EQUALITY,
1303                 NULL, NULL, authPasswordMatch, NULL, NULL},
1304
1305         {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
1306                 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
1307                 SLAP_MR_EQUALITY,
1308                 NULL, NULL, OpenLDAPaciMatch, NULL, NULL},
1309
1310         {NULL, SLAP_MR_NONE, NULL, NULL, NULL}
1311 };
1312
1313 int
1314 schema_init( void )
1315 {
1316         int             res;
1317         int             i;
1318
1319         /* we should only be called once (from main) */
1320         assert( schema_init_done == 0 );
1321
1322         for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1323                 res = register_syntax( syntax_defs[i].sd_desc,
1324                     syntax_defs[i].sd_flags,
1325                     syntax_defs[i].sd_validate,
1326                     syntax_defs[i].sd_normalize,
1327                         syntax_defs[i].sd_pretty
1328 #ifdef SLAPD_BINARY_CONVERSION
1329                         ,
1330                     syntax_defs[i].sd_ber2str,
1331                         syntax_defs[i].sd_str2ber
1332 #endif
1333                 );
1334
1335                 if ( res ) {
1336                         fprintf( stderr, "schema_init: Error registering syntax %s\n",
1337                                  syntax_defs[i].sd_desc );
1338                         return LDAP_OTHER;
1339                 }
1340         }
1341
1342         for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1343                 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
1344                         fprintf( stderr,
1345                                 "schema_init: Ingoring unusable matching rule %s\n",
1346                                  mrule_defs[i].mrd_desc );
1347                         continue;
1348                 }
1349
1350                 res = register_matching_rule(
1351                         mrule_defs[i].mrd_desc,
1352                         mrule_defs[i].mrd_usage,
1353                         mrule_defs[i].mrd_convert,
1354                         mrule_defs[i].mrd_normalize,
1355                     mrule_defs[i].mrd_match,
1356                         mrule_defs[i].mrd_indexer,
1357                         mrule_defs[i].mrd_filter );
1358
1359                 if ( res ) {
1360                         fprintf( stderr,
1361                                 "schema_init: Error registering matching rule %s\n",
1362                                  mrule_defs[i].mrd_desc );
1363                         return LDAP_OTHER;
1364                 }
1365         }
1366         schema_init_done = 1;
1367         return LDAP_SUCCESS;
1368 }