]> git.sur5r.net Git - openldap/blob - servers/slapd/schema_init.c
Move experimental Back-BDB2 to Attic
[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 #ifdef SLAPD_SCHEMA_NOT_COMPAT
525 static int
526 caseExactIA5SubstringsMatch(
527         int *matchp,
528         unsigned use,
529         Syntax *syntax,
530         MatchingRule *mr,
531         struct berval *value,
532         void *assertedValue )
533 {
534         int match = 0;
535         SubstringsAssertion *sub = assertedValue;
536         struct berval left = *value;
537         int i;
538         ber_len_t inlen=0;
539
540         if( sub->sa_initial ) {
541                 inlen += sub->sa_initial->bv_len;
542         }
543         if( sub->sa_any ) {
544                 for(i=0; sub->sa_any[i]; i++) {
545                         inlen += sub->sa_final->bv_len;
546                 }
547         }
548         if( sub->sa_final ) {
549                 inlen += sub->sa_final->bv_len;
550         }
551
552         if( inlen > value->bv_len ) {
553                 match = 1;
554                 goto done;
555         }
556
557         if( sub->sa_initial ) {
558                 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
559                         sub->sa_initial->bv_len );
560
561                 if( match != 0 ) {
562                         goto done;
563                 }
564
565                 left.bv_val += sub->sa_initial->bv_len;
566                 left.bv_len -= sub->sa_initial->bv_len;
567                 inlen -= sub->sa_initial->bv_len;
568         }
569
570         if( sub->sa_final ) {
571                 match = strncmp( sub->sa_final->bv_val,
572                         &left.bv_val[left.bv_len - sub->sa_final->bv_len],
573                         sub->sa_final->bv_len );
574
575                 if( match != 0 ) {
576                         goto done;
577                 }
578
579                 left.bv_len -= sub->sa_final->bv_len;
580                 inlen -= sub->sa_initial->bv_len;
581         }
582
583         if( sub->sa_any ) {
584                 for(i=0; sub->sa_any[i]; i++) {
585                         ber_len_t idx;
586                         char *p;
587
588 retry:
589                         if( inlen < left.bv_len ) {
590                                 /* not enough length */
591                                 match = 1;
592                                 goto done;
593                         }
594
595                         if( sub->sa_any[i]->bv_len == 0 ) {
596                                 continue;
597                         }
598
599                         p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
600
601                         if( p == NULL ) {
602                                 match = 1;
603                                 goto done;
604                         }
605
606                         idx = p - left.bv_val;
607                         assert( idx < left.bv_len );
608
609                         if( idx >= left.bv_len ) {
610                                 /* this shouldn't happen */
611                                 return LDAP_OTHER;
612                         }
613
614                         left.bv_val = p;
615                         left.bv_len -= idx;
616
617                         if( sub->sa_any[i]->bv_len > left.bv_len ) {
618                                 /* not enough left */
619                                 match = 1;
620                                 goto done;
621                         }
622
623                         match = strncmp( left.bv_val,
624                                 sub->sa_any[i]->bv_val,
625                                 sub->sa_any[i]->bv_len );
626
627
628                         if( match != 0 ) {
629                                 goto retry;
630                         }
631
632                         left.bv_val += sub->sa_any[i]->bv_len;
633                         left.bv_len -= sub->sa_any[i]->bv_len;
634                 }
635         }
636
637 done:
638         *matchp = match;
639         return LDAP_SUCCESS;
640 }
641 #endif
642
643 static int
644 caseIgnoreIA5Match(
645         int *match,
646         unsigned use,
647         Syntax *syntax,
648         MatchingRule *mr,
649         struct berval *value,
650         void *assertedValue )
651 {
652         *match = strcasecmp( value->bv_val,
653                 ((struct berval *) assertedValue)->bv_val );
654         return LDAP_SUCCESS;
655 }
656
657 #ifdef SLAPD_SCHEMA_NOT_COMPAT
658 static char *strcasechr( const char *str, int c )
659 {
660         char *lower = strchr( str, TOLOWER(c) );
661         char *upper = strchr( str, TOUPPER(c) );
662
663         if( lower && upper ) {
664                 return lower < upper ? lower : upper;
665         } else if ( lower ) {
666                 return lower;
667         } else {
668                 return upper;
669         }
670 }
671
672 static int
673 caseIgnoreIA5SubstringsMatch(
674         int *matchp,
675         unsigned use,
676         Syntax *syntax,
677         MatchingRule *mr,
678         struct berval *value,
679         void *assertedValue )
680 {
681         int match = 0;
682         SubstringsAssertion *sub = assertedValue;
683         struct berval left = *value;
684         int i;
685         ber_len_t inlen=0;
686
687         if( sub->sa_initial ) {
688                 inlen += sub->sa_initial->bv_len;
689         }
690         if( sub->sa_any ) {
691                 for(i=0; sub->sa_any[i]; i++) {
692                         inlen += sub->sa_final->bv_len;
693                 }
694         }
695         if( sub->sa_final ) {
696                 inlen += sub->sa_final->bv_len;
697         }
698
699         if( inlen > value->bv_len ) {
700                 match = 1;
701                 goto done;
702         }
703
704         if( sub->sa_initial ) {
705                 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
706                         sub->sa_initial->bv_len );
707
708                 if( match != 0 ) {
709                         goto done;
710                 }
711
712                 left.bv_val += sub->sa_initial->bv_len;
713                 left.bv_len -= sub->sa_initial->bv_len;
714         }
715
716         if( sub->sa_final ) {
717                 match = strncasecmp( sub->sa_final->bv_val,
718                         &left.bv_val[left.bv_len - sub->sa_final->bv_len],
719                         sub->sa_final->bv_len );
720
721                 if( match != 0 ) {
722                         goto done;
723                 }
724
725                 left.bv_len -= sub->sa_final->bv_len;
726         }
727
728         if( sub->sa_any ) {
729                 for(i=0; sub->sa_any[i]; i++) {
730                         ber_len_t idx;
731                         char *p;
732
733 retry:
734                         if( inlen < left.bv_len ) {
735                                 /* not enough length */
736                                 match = 1;
737                                 goto done;
738                         }
739
740                         if( sub->sa_any[i]->bv_len == 0 ) {
741                                 continue;
742                         }
743
744                         p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
745
746                         if( p == NULL ) {
747                                 match = 1;
748                                 goto done;
749                         }
750
751                         idx = p - left.bv_val;
752                         assert( idx < left.bv_len );
753
754                         if( idx >= left.bv_len ) {
755                                 /* this shouldn't happen */
756                                 return LDAP_OTHER;
757                         }
758
759                         left.bv_val = p;
760                         left.bv_len -= idx;
761
762                         if( sub->sa_any[i]->bv_len > left.bv_len ) {
763                                 /* not enough left */
764                                 match = 1;
765                                 goto done;
766                         }
767
768                         match = strncasecmp( left.bv_val,
769                                 sub->sa_any[i]->bv_val,
770                                 sub->sa_any[i]->bv_len );
771
772
773                         if( match != 0 ) {
774                                 goto retry;
775                         }
776
777                         left.bv_val += sub->sa_any[i]->bv_len;
778                         left.bv_len -= sub->sa_any[i]->bv_len;
779                 }
780         }
781
782 done:
783         *matchp = match;
784         return LDAP_SUCCESS;
785 }
786 #endif
787
788 /* Index generation function */
789 int caseIgnoreIA5Indexer(
790         unsigned use,
791         Syntax *syntax,
792         MatchingRule *mr,
793         struct berval *prefix,
794         struct berval **values,
795         struct berval ***keysp )
796 {
797         int i;
798         size_t slen, mlen;
799         struct berval **keys;
800         lutil_MD5_CTX   MD5context;
801         unsigned char   MD5digest[16];
802         struct berval digest;
803         digest.bv_val = MD5digest;
804         digest.bv_len = sizeof(MD5digest);
805
806         for( i=0; values[i] != NULL; i++ ) {
807                 /* just count them */
808         }
809
810         assert( i > 0 );
811
812         keys = ch_malloc( sizeof( struct berval * ) * (i+1) );
813
814         slen = strlen( syntax->ssyn_oid );
815         mlen = strlen( mr->smr_oid );
816
817         for( i=0; values[i] != NULL; i++ ) {
818                 struct berval *value = ber_bvdup( values[i] );
819                 ldap_pvt_str2upper( value->bv_val );
820
821                 lutil_MD5Init( &MD5context );
822                 if( prefix != NULL && prefix->bv_len > 0 ) {
823                         lutil_MD5Update( &MD5context,
824                                 prefix->bv_val, prefix->bv_len );
825                 }
826                 lutil_MD5Update( &MD5context,
827                         syntax->ssyn_oid, slen );
828                 lutil_MD5Update( &MD5context,
829                         mr->smr_oid, mlen );
830                 lutil_MD5Update( &MD5context,
831                         value->bv_val, value->bv_len );
832                 lutil_MD5Final( MD5digest, &MD5context );
833
834                 ber_bvfree( value );
835
836                 keys[i] = ber_bvdup( &digest );
837         }
838
839         keys[i] = NULL;
840         *keysp = keys;
841         return LDAP_SUCCESS;
842 }
843
844 /* Index generation function */
845 int caseIgnoreIA5Filter(
846         unsigned use,
847         Syntax *syntax,
848         MatchingRule *mr,
849         struct berval *prefix,
850         void * assertValue,
851         struct berval ***keysp )
852 {
853         size_t slen, mlen;
854         struct berval **keys;
855         lutil_MD5_CTX   MD5context;
856         unsigned char   MD5digest[LUTIL_MD5_BYTES];
857         struct berval *value;
858         struct berval digest;
859         digest.bv_val = MD5digest;
860         digest.bv_len = sizeof(MD5digest);
861
862         slen = strlen( syntax->ssyn_oid );
863         mlen = strlen( mr->smr_oid );
864
865         value = ber_bvdup( (struct berval *) assertValue );
866         ldap_pvt_str2upper( value->bv_val );
867
868         keys = ch_malloc( sizeof( struct berval * ) * 2 );
869
870         lutil_MD5Init( &MD5context );
871         if( prefix != NULL && prefix->bv_len > 0 ) {
872                 lutil_MD5Update( &MD5context,
873                         prefix->bv_val, prefix->bv_len );
874         }
875         lutil_MD5Update( &MD5context,
876                 syntax->ssyn_oid, slen );
877         lutil_MD5Update( &MD5context,
878                 mr->smr_oid, mlen );
879         lutil_MD5Update( &MD5context,
880                 value->bv_val, value->bv_len );
881         lutil_MD5Final( MD5digest, &MD5context );
882
883         keys[0] = ber_bvdup( &digest );
884         keys[1] = NULL;
885
886         ber_bvfree( value );
887
888         *keysp = keys;
889         return LDAP_SUCCESS;
890 }
891
892 static int
893 NumericStringNormalize(
894         Syntax *syntax,
895         struct berval *val,
896         struct berval **normalized )
897 {
898         /* similiar to IA5StringNormalize except removes all spaces */
899         struct berval *newval;
900         char *p, *q;
901
902         newval = ch_malloc( sizeof( struct berval ) );
903
904         p = val->bv_val;
905
906         /* Ignore initial whitespace */
907         while ( isspace( *p++ ) ) {
908                 /* EMPTY */  ;
909         }
910
911         if( *p != '\0' ) {
912                 ch_free( newval );
913                 return LDAP_INVALID_SYNTAX;
914         }
915
916         newval->bv_val = ch_strdup( p );
917         p = q = newval->bv_val;
918
919         while ( *p ) {
920                 if ( isspace( *p ) ) {
921                         /* Ignore whitespace */
922                         p++;
923                 } else {
924                         *q++ = *p++;
925                 }
926         }
927
928         assert( *newval->bv_val );
929         assert( newval->bv_val < p );
930         assert( p <= q );
931
932         /* cannot start with a space */
933         assert( !isspace(*newval->bv_val) );
934
935         /* cannot end with a space */
936         assert( !isspace( q[-1] ) );
937
938         /* null terminate */
939         *q = '\0';
940
941         newval->bv_len = q - newval->bv_val;
942         *normalized = newval;
943
944         return LDAP_SUCCESS;
945 }
946
947 struct syntax_defs_rec {
948         char *sd_desc;
949         int sd_flags;
950         slap_syntax_validate_func *sd_validate;
951         slap_syntax_transform_func *sd_normalize;
952         slap_syntax_transform_func *sd_pretty;
953 #ifdef SLAPD_BINARY_CONVERSION
954         slap_syntax_transform_func *sd_ber2str;
955         slap_syntax_transform_func *sd_str2ber;
956 #endif
957 };
958
959 #define X_HIDE "X-HIDE 'TRUE' "
960 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
961 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
962
963 struct syntax_defs_rec syntax_defs[] = {
964         {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
965                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
966         {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
967                 0, NULL, NULL, NULL},
968         {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
969                 0, NULL, NULL, NULL},
970         {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
971                 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
972         {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
973                 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
974         {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
975                 0, NULL, NULL, NULL},
976         {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
977                 0, NULL, NULL, NULL},
978         {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
979                 X_BINARY X_NOT_H_R ")",
980                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
981         {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
982                 X_BINARY X_NOT_H_R ")",
983                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
984         {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
985                 X_BINARY X_NOT_H_R ")",
986                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
987         {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
988                 0, NULL, NULL, NULL},
989         {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'Distinguished Name' )",
990                 0, dnValidate, dnNormalize, NULL},
991         {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
992                 0, NULL, NULL, NULL},
993         {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
994                 0, NULL, NULL, NULL},
995         {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
996                 0, UTF8StringValidate, UTF8StringNormalize, NULL},
997         {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
998                 0, NULL, NULL, NULL},
999         {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
1000                 0, NULL, NULL, NULL},
1001         {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
1002                 0, NULL, NULL, NULL},
1003         {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
1004                 0, NULL, NULL, NULL},
1005         {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
1006                 0, NULL, NULL, NULL},
1007         {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
1008                 0, blobValidate, NULL, NULL},
1009         {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
1010                 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
1011         {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
1012                 0, NULL, NULL, NULL},
1013         {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
1014                 0, NULL, NULL, NULL},
1015         {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
1016                 0, IA5StringValidate, IA5StringNormalize, NULL},
1017         {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
1018                 0, integerValidate, NULL, NULL},
1019         {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
1020                 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
1021         {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
1022                 0, NULL, NULL, NULL},
1023         {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
1024                 0, NULL, NULL, NULL},
1025         {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
1026                 0, NULL, NULL, NULL},
1027         {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
1028                 0, NULL, NULL, NULL},
1029         {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
1030                 0, NULL, NULL, NULL},
1031         {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
1032                 0, NULL, NULL, NULL},
1033         {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
1034                 0, NULL, NULL, NULL},
1035         {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
1036                 0, IA5StringValidate, NumericStringNormalize, NULL},
1037         {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
1038                 0, NULL, NULL, NULL},
1039         {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
1040                 0, oidValidate, NULL, NULL},
1041         {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
1042                 0, NULL, NULL, NULL},
1043         {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
1044                 0, blobValidate, NULL, NULL},
1045         {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
1046                 0, blobValidate, NULL, NULL},
1047         {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
1048                 0, NULL, NULL, NULL},
1049         {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
1050                 0, NULL, NULL, NULL},
1051         {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
1052                 0, printableStringValidate, NULL, NULL},
1053         {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
1054                 X_BINARY X_NOT_H_R ")",
1055                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
1056         {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
1057                 0, blobValidate, NULL, NULL},
1058         {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
1059                 0, NULL, NULL, NULL},
1060         {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
1061                 0, NULL, NULL, NULL},
1062         {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
1063                 0, NULL, NULL, NULL},
1064         {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
1065                 0, NULL, NULL, NULL},
1066         {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
1067                 0, NULL, NULL, NULL},
1068         {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
1069                 0, NULL, NULL, NULL},
1070         {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
1071                 0, NULL, NULL, NULL},
1072         {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
1073                 0, NULL, NULL, NULL},
1074
1075         /* OpenLDAP Experimental Syntaxes */
1076         {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
1077                 0, NULL, NULL, NULL},
1078         {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP authPassword' )",
1079                 0, NULL, NULL, NULL},
1080         {"( 1.3.6.1.4.1.4203.666.2.3 DESC 'OpenLDAP void' " X_HIDE ")" ,
1081                 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
1082 #if 0 /* not needed */
1083         {"( 1.3.6.1.4.1.4203.666.2.4 DESC 'OpenLDAP DN' " X_HIDE ")" ,
1084                 SLAP_SYNTAX_HIDE, inValidate, NULL, NULL},
1085 #endif
1086
1087         {NULL, 0, NULL, NULL, NULL}
1088 };
1089
1090 struct mrule_defs_rec {
1091         char *                                          mrd_desc;
1092         unsigned                                        mrd_usage;
1093         slap_mr_convert_func *          mrd_convert;
1094         slap_mr_normalize_func *        mrd_normalize;
1095         slap_mr_match_func *            mrd_match;
1096         slap_mr_indexer_func *          mrd_indexer;
1097         slap_mr_filter_func *           mrd_filter;
1098 };
1099
1100 /*
1101  * Other matching rules in X.520 that we do not use:
1102  *
1103  * 2.5.13.9             numericStringOrderingMatch
1104  * 2.5.13.13    booleanMatch
1105  * 2.5.13.15    integerOrderingMatch
1106  * 2.5.13.18    octetStringOrderingMatch
1107  * 2.5.13.19    octetStringSubstringsMatch
1108  * 2.5.13.25    uTCTimeMatch
1109  * 2.5.13.26    uTCTimeOrderingMatch
1110  * 2.5.13.31    directoryStringFirstComponentMatch
1111  * 2.5.13.32    wordMatch
1112  * 2.5.13.33    keywordMatch
1113  * 2.5.13.34    certificateExactMatch
1114  * 2.5.13.35    certificateMatch
1115  * 2.5.13.36    certificatePairExactMatch
1116  * 2.5.13.37    certificatePairMatch
1117  * 2.5.13.38    certificateListExactMatch
1118  * 2.5.13.39    certificateListMatch
1119  * 2.5.13.40    algorithmIdentifierMatch
1120  * 2.5.13.41    storedPrefixMatch
1121  * 2.5.13.42    attributeCertificateMatch
1122  * 2.5.13.43    readerAndKeyIDMatch
1123  * 2.5.13.44    attributeIntegrityMatch
1124  */
1125
1126 #ifndef SLAPD_SCHEMA_NOT_COMPAT
1127 #define caseIgnoreIA5SubstringsMatch NULL
1128 #define caseExactIA5SubstringsMatch NULL
1129 #endif
1130
1131 /* recycled matching functions */
1132 #define caseIgnoreMatch caseIgnoreIA5Match
1133 #define caseIgnoreOrderingMatch caseIgnoreMatch
1134 #define caseIgnoreSubstringsMatch caseIgnoreIA5SubstringsMatch
1135 #define caseExactMatch caseExactIA5Match
1136 #define caseExactOrderingMatch caseExactMatch
1137 #define caseExactSubstringsMatch caseExactIA5SubstringsMatch
1138
1139 /* unimplemented matching functions */
1140 #define objectIdentifierMatch NULL
1141 #define caseIgnoreListMatch NULL
1142 #define caseIgnoreListSubstringsMatch NULL
1143 #define integerMatch NULL
1144 #define bitStringMatch NULL
1145 #define octetStringMatch NULL
1146 #define telephoneNumberMatch NULL
1147 #define telephoneNumberSubstringsMatch NULL
1148 #define presentationAddressMatch NULL
1149 #define uniqueMemberMatch NULL
1150 #define protocolInformationMatch NULL
1151 #define generalizedTimeMatch NULL
1152 #define generalizedTimeOrderingMatch NULL
1153 #define integerFirstComponentMatch NULL
1154 #define objectIdentifierFirstComponentMatch NULL
1155
1156 #define OpenLDAPaciMatch NULL
1157 #define authPasswordMatch NULL
1158
1159 /* unimplied indexer/filter routines */
1160 #define dnIndexer NULL
1161 #define dnFilter NULL
1162
1163 #define caseIgnoreIndexer               caseIgnoreIA5Indexer
1164 #define caseIgnoreFilter                caseIgnoreIA5Filter
1165 #define caseExactIndexer                caseExactIA5Indexer
1166 #define caseExactFilter                 caseExactIA5Filter
1167 #define caseExactIA5Indexer             caseIgnoreIA5Indexer
1168 #define caseExactIA5Filter              caseIgnoreIA5Filter
1169
1170 struct mrule_defs_rec mrule_defs[] = {
1171         {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
1172                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1173                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1174                 NULL, NULL, objectIdentifierMatch,
1175                 caseIgnoreIA5Indexer, caseIgnoreIA5Filter},
1176
1177         {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
1178                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
1179                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1180                 NULL, NULL, dnMatch, dnIndexer, dnFilter},
1181
1182         {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
1183                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1184                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1185                 NULL, NULL, caseIgnoreMatch, caseIgnoreIndexer, caseIgnoreFilter},
1186
1187         {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
1188                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1189                 SLAP_MR_ORDERING,
1190                 NULL, NULL, caseIgnoreOrderingMatch, NULL, NULL},
1191
1192         {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
1193                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1194                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1195                 NULL, NULL, caseIgnoreSubstringsMatch, NULL, NULL},
1196
1197         /* Next three are not in the RFC's, but are needed for compatibility */
1198         {"( 2.5.13.5 NAME 'caseExactMatch' "
1199                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1200                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1201                 NULL, NULL, caseExactMatch, caseExactIndexer, caseExactFilter},
1202
1203         {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
1204                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
1205                 SLAP_MR_ORDERING,
1206                 NULL, NULL, caseExactOrderingMatch, NULL, NULL},
1207
1208         {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
1209                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1210                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1211                 NULL, NULL, caseExactSubstringsMatch, NULL, NULL},
1212
1213         {"( 2.5.13.8 NAME 'numericStringMatch' "
1214                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
1215                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1216                 NULL, NULL, caseIgnoreIA5Match, NULL, NULL},
1217
1218         {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
1219                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1220                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1221                 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1222
1223         {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
1224                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
1225                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1226                 NULL, NULL, caseIgnoreListMatch, NULL, NULL},
1227
1228         {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
1229                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1230                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1231                 NULL, NULL, caseIgnoreListSubstringsMatch, NULL, NULL},
1232
1233         {"( 2.5.13.14 NAME 'integerMatch' "
1234                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1235                 SLAP_MR_NONE | SLAP_MR_EXT,
1236                 NULL, NULL, integerMatch, NULL, NULL},
1237
1238         {"( 2.5.13.16 NAME 'bitStringMatch' "
1239                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
1240                 SLAP_MR_NONE | SLAP_MR_EXT,
1241                 NULL, NULL, bitStringMatch, NULL, NULL},
1242
1243         {"( 2.5.13.17 NAME 'octetStringMatch' "
1244                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1245                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1246                 NULL, NULL, octetStringMatch, octetStringIndexer, octetStringFilter},
1247
1248         {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
1249                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
1250                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1251                 NULL, NULL, telephoneNumberMatch, NULL, NULL},
1252
1253         {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
1254                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
1255                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
1256                 NULL, NULL, telephoneNumberSubstringsMatch, NULL, NULL},
1257
1258         {"( 2.5.13.22 NAME 'presentationAddressMatch' "
1259                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
1260                 SLAP_MR_NONE | SLAP_MR_EXT,
1261                 NULL, NULL, presentationAddressMatch, NULL, NULL},
1262
1263         {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
1264                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
1265                 SLAP_MR_NONE | SLAP_MR_EXT,
1266                 NULL, NULL, uniqueMemberMatch, NULL, NULL},
1267
1268         {"( 2.5.13.24 NAME 'protocolInformationMatch' "
1269                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
1270                 SLAP_MR_NONE | SLAP_MR_EXT,
1271                 NULL, NULL, protocolInformationMatch, NULL, NULL},
1272
1273         {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
1274                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1275                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1276                 NULL, NULL, generalizedTimeMatch, NULL, NULL},
1277
1278         {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
1279                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
1280                 SLAP_MR_ORDERING,
1281                 NULL, NULL, generalizedTimeOrderingMatch, NULL, NULL},
1282
1283         {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
1284                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
1285                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1286                 NULL, NULL, integerFirstComponentMatch, NULL, NULL},
1287
1288         {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
1289                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
1290                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1291                 NULL, NULL, objectIdentifierFirstComponentMatch, NULL, NULL},
1292
1293         {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
1294                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1295                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1296                 NULL, NULL, caseExactIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1297
1298         {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
1299                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1300                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
1301                 NULL, NULL, caseIgnoreIA5Match, caseExactIA5Indexer, caseExactIA5Filter},
1302
1303         {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
1304                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
1305                 SLAP_MR_SUBSTR,
1306                 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
1307
1308         {"( 1.3.6.1.4.1.4203.666.4.1 NAME 'authPasswordMatch' "
1309                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
1310                 SLAP_MR_EQUALITY,
1311                 NULL, NULL, authPasswordMatch, NULL, NULL},
1312
1313         {"( 1.3.6.1.4.1.4203.666.4.2 NAME 'OpenLDAPaciMatch' "
1314                 "SYNTAX 1.3.6.1.4.1.4203.666.2.1 )",
1315                 SLAP_MR_EQUALITY,
1316                 NULL, NULL, OpenLDAPaciMatch, NULL, NULL},
1317
1318         {NULL, SLAP_MR_NONE, NULL, NULL, NULL}
1319 };
1320
1321 int
1322 schema_init( void )
1323 {
1324         int             res;
1325         int             i;
1326
1327         /* we should only be called once (from main) */
1328         assert( schema_init_done == 0 );
1329
1330         for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
1331                 res = register_syntax( syntax_defs[i].sd_desc,
1332                     syntax_defs[i].sd_flags,
1333                     syntax_defs[i].sd_validate,
1334                     syntax_defs[i].sd_normalize,
1335                         syntax_defs[i].sd_pretty
1336 #ifdef SLAPD_BINARY_CONVERSION
1337                         ,
1338                     syntax_defs[i].sd_ber2str,
1339                         syntax_defs[i].sd_str2ber
1340 #endif
1341                 );
1342
1343                 if ( res ) {
1344                         fprintf( stderr, "schema_init: Error registering syntax %s\n",
1345                                  syntax_defs[i].sd_desc );
1346                         return LDAP_OTHER;
1347                 }
1348         }
1349
1350         for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
1351                 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
1352                         fprintf( stderr,
1353                                 "schema_init: Ingoring unusable matching rule %s\n",
1354                                  mrule_defs[i].mrd_desc );
1355                         continue;
1356                 }
1357
1358                 res = register_matching_rule(
1359                         mrule_defs[i].mrd_desc,
1360                         mrule_defs[i].mrd_usage,
1361                         mrule_defs[i].mrd_convert,
1362                         mrule_defs[i].mrd_normalize,
1363                     mrule_defs[i].mrd_match,
1364                         mrule_defs[i].mrd_indexer,
1365                         mrule_defs[i].mrd_filter );
1366
1367                 if ( res ) {
1368                         fprintf( stderr,
1369                                 "schema_init: Error registering matching rule %s\n",
1370                                  mrule_defs[i].mrd_desc );
1371                         return LDAP_OTHER;
1372                 }
1373         }
1374         schema_init_done = 1;
1375         return LDAP_SUCCESS;
1376 }