]> git.sur5r.net Git - openldap/blob - servers/slapd/schema_init.c
7814abdf7a0a58eba14b61a1e4d1396eb2b79e75
[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
19 static int
20 inValidate(
21         Syntax *syntax,
22         struct berval *in )
23 {
24         /* any value allowed */
25         return LDAP_OTHER;
26 }
27
28 static int
29 blobValidate(
30         Syntax *syntax,
31         struct berval *in )
32 {
33         /* any value allowed */
34         return LDAP_SUCCESS;
35 }
36
37 #define berValidate blobValidate
38
39 static int
40 UTF8StringValidate(
41         Syntax *syntax,
42         struct berval *in )
43 {
44         ber_len_t count;
45         int len;
46         unsigned char *u = in->bv_val;
47
48         for( count = in->bv_len; count > 0; count-=len, u+=len ) {
49                 /* get the length indicated by the first byte */
50                 len = LDAP_UTF8_CHARLEN( u );
51
52                 /* should not be zero */
53                 if( len == 0 ) return LDAP_INVALID_SYNTAX;
54
55                 /* make sure len corresponds with the offset
56                         to the next character */
57                 if( LDAP_UTF8_OFFSET( u ) != len ) return LDAP_INVALID_SYNTAX;
58         }
59
60         if( count != 0 ) return LDAP_INVALID_SYNTAX;
61
62         return LDAP_SUCCESS;
63 }
64
65 static int
66 UTF8StringNormalize(
67         Syntax *syntax,
68         struct berval *val,
69         struct berval **normalized )
70 {
71         struct berval *newval;
72         char *p, *q, *s;
73
74         newval = ch_malloc( sizeof( struct berval ) );
75
76         p = val->bv_val;
77
78         /* Ignore initial whitespace */
79         while ( ldap_utf8_isspace( p ) ) {
80                 LDAP_UTF8_INCR( p );
81         }
82
83         if( *p == '\0' ) {
84                 ch_free( newval );
85                 return LDAP_INVALID_SYNTAX;
86         }
87
88         newval->bv_val = ch_strdup( p );
89         p = q = newval->bv_val;
90         s = NULL;
91
92         while ( *p ) {
93                 int len;
94
95                 if ( ldap_utf8_isspace( p ) ) {
96                         len = LDAP_UTF8_COPY(q,p);
97                         s=q;
98                         p+=len;
99                         q+=len;
100
101                         /* Ignore the extra whitespace */
102                         while ( ldap_utf8_isspace( p ) ) {
103                                 LDAP_UTF8_INCR( p );
104                         }
105                 } else {
106                         len = LDAP_UTF8_COPY(q,p);
107                         s=NULL;
108                         p+=len;
109                         q+=len;
110                 }
111         }
112
113         assert( *newval->bv_val );
114         assert( newval->bv_val < p );
115         assert( p <= q );
116
117         /* cannot start with a space */
118         assert( !ldap_utf8_isspace(newval->bv_val) );
119
120         /*
121          * If the string ended in space, backup the pointer one
122          * position.  One is enough because the above loop collapsed
123          * all whitespace to a single space.
124          */
125
126         if ( s != NULL ) {
127                 q = s;
128         }
129
130         /* cannot end with a space */
131         assert( !ldap_utf8_isspace( LDAP_UTF8_PREV(q) ) );
132
133         /* null terminate */
134         *q = '\0';
135
136         newval->bv_len = q - newval->bv_val;
137         *normalized = newval;
138
139         return LDAP_SUCCESS;
140 }
141
142 static int
143 oidValidate(
144         Syntax *syntax,
145         struct berval *val )
146 {
147         ber_len_t i;
148
149         if( val->bv_len == 0 ) return 0;
150
151         if( isdigit(val->bv_val[0]) ) {
152                 int dot = 0;
153                 for(i=1; i < val->bv_len; i++) {
154                         if( val->bv_val[i] == '.' ) {
155                                 if( dot++ ) return 1;
156                         } else if ( isdigit(val->bv_val[i]) ) {
157                                 dot = 0;
158                         } else {
159                                 return LDAP_INVALID_SYNTAX;
160                         }
161                 }
162
163                 return !dot ? LDAP_SUCCESS : LDAP_INVALID_SYNTAX;
164
165         } else if( isalpha(val->bv_val[0]) ) {
166                 for(i=1; i < val->bv_len; i++) {
167                         if( !isalpha(val->bv_val[i] ) ) {
168                                 return LDAP_INVALID_SYNTAX;
169                         }
170                 }
171
172                 return LDAP_SUCCESS;
173         }
174         
175         return LDAP_INVALID_SYNTAX;
176 }
177
178 static int
179 integerValidate(
180         Syntax *syntax,
181         struct berval *val )
182 {
183         ber_len_t i;
184
185         for(i=0; i < val->bv_len; i++) {
186                 if( !isdigit(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
187         }
188
189         return LDAP_SUCCESS;
190 }
191
192 static int
193 printableStringValidate(
194         Syntax *syntax,
195         struct berval *val )
196 {
197         ber_len_t i;
198
199         for(i=0; i < val->bv_len; i++) {
200                 if( !isprint(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
201         }
202
203         return LDAP_SUCCESS;
204 }
205
206 static int
207 IA5StringValidate(
208         Syntax *syntax,
209         struct berval *val )
210 {
211         ber_len_t i;
212
213         for(i=0; i < val->bv_len; i++) {
214                 if( !isascii(val->bv_val[i]) ) return LDAP_INVALID_SYNTAX;
215         }
216
217         return LDAP_SUCCESS;
218 }
219
220 static int
221 IA5StringConvert(
222         Syntax *syntax,
223         struct berval *in,
224         struct berval **out )
225 {
226         ldap_unicode_t *u;
227         ber_len_t i, len = in->bv_len;
228         struct berval *bv = ch_malloc( sizeof(struct berval) );
229
230         bv->bv_len = len * sizeof( ldap_unicode_t );
231         bv->bv_val = (char *) u = ch_malloc( bv->bv_len + sizeof( ldap_unicode_t ) );;
232
233         for(i=0; i < len; i++ ) {
234                 /*
235                  * IA5StringValidate should have been called to ensure
236                  * input is limited to IA5.
237                  */
238                 u[i] = in->bv_val[i];
239         }
240         u[i] = 0;
241
242         *out = bv;
243         return LDAP_SUCCESS;
244 }
245
246 static int
247 IA5StringNormalize(
248         Syntax *syntax,
249         struct berval *val,
250         struct berval **normalized )
251 {
252         struct berval *newval;
253         char *p, *q;
254
255         newval = ch_malloc( sizeof( struct berval ) );
256
257         p = val->bv_val;
258
259         /* Ignore initial whitespace */
260         while ( isspace( *p++ ) ) {
261                 /* EMPTY */  ;
262         }
263
264         if( *p != '\0' ) {
265                 ch_free( newval );
266                 return LDAP_INVALID_SYNTAX;
267         }
268
269         newval->bv_val = ch_strdup( p );
270         p = q = newval->bv_val;
271
272         while ( *p ) {
273                 if ( isspace( *p ) ) {
274                         *q++ = *p++;
275
276                         /* Ignore the extra whitespace */
277                         while ( isspace( *p++ ) ) {
278                                 /* EMPTY */  ;
279                         }
280                 } else {
281                         *q++ = *p++;
282                 }
283         }
284
285         assert( *newval->bv_val );
286         assert( newval->bv_val < p );
287         assert( p <= q );
288
289         /* cannot start with a space */
290         assert( !isspace(*newval->bv_val) );
291
292         /*
293          * If the string ended in space, backup the pointer one
294          * position.  One is enough because the above loop collapsed
295          * all whitespace to a single space.
296          */
297
298         if ( isspace( q[-1] ) ) {
299                 --q;
300         }
301
302         /* cannot end with a space */
303         assert( !isspace( q[-1] ) );
304
305         /* null terminate */
306         *q = '\0';
307
308         newval->bv_len = q - newval->bv_val;
309         *normalized = newval;
310
311         return LDAP_SUCCESS;
312 }
313
314 static int
315 caseExactIA5Match(
316         int *match,
317         unsigned use,
318         Syntax *syntax,
319         MatchingRule *mr,
320         struct berval *value,
321         void *assertedValue )
322 {
323         *match = strcmp( value->bv_val,
324                 ((struct berval *) assertedValue)->bv_val );
325         return LDAP_SUCCESS;
326 }
327
328 #ifdef SLAPD_SCHEMA_NOT_COMPAT
329 static int
330 caseExactIA5SubstringsMatch(
331         int *matchp,
332         unsigned use,
333         Syntax *syntax,
334         MatchingRule *mr,
335         struct berval *value,
336         void *assertedValue )
337 {
338         int match = 0;
339         SubstringsAssertion *sub = assertedValue;
340         struct berval left = *value;
341         int i;
342         ber_len_t inlen=0;
343
344         if( sub->sa_initial ) {
345                 inlen += sub->sa_initial->bv_len;
346         }
347         if( sub->sa_any ) {
348                 for(i=0; sub->sa_any[i]; i++) {
349                         inlen += sub->sa_final->bv_len;
350                 }
351         }
352         if( sub->sa_final ) {
353                 inlen += sub->sa_final->bv_len;
354         }
355
356         if( inlen > value->bv_len ) {
357                 match = 1;
358                 goto done;
359         }
360
361         if( sub->sa_initial ) {
362                 match = strncmp( sub->sa_initial->bv_val, left.bv_val,
363                         sub->sa_initial->bv_len );
364
365                 if( match != 0 ) {
366                         goto done;
367                 }
368
369                 left.bv_val += sub->sa_initial->bv_len;
370                 left.bv_len -= sub->sa_initial->bv_len;
371                 inlen -= sub->sa_initial->bv_len;
372         }
373
374         if( sub->sa_final ) {
375                 match = strncmp( sub->sa_final->bv_val,
376                         &left.bv_val[left.bv_len - sub->sa_final->bv_len],
377                         sub->sa_final->bv_len );
378
379                 if( match != 0 ) {
380                         goto done;
381                 }
382
383                 left.bv_len -= sub->sa_final->bv_len;
384                 inlen -= sub->sa_initial->bv_len;
385         }
386
387         if( sub->sa_any ) {
388                 for(i=0; sub->sa_any[i]; i++) {
389                         ber_len_t idx;
390                         char *p;
391
392 retry:
393                         if( inlen < left.bv_len ) {
394                                 /* not enough length */
395                                 match = 1;
396                                 goto done;
397                         }
398
399                         if( sub->sa_any[i]->bv_len == 0 ) {
400                                 continue;
401                         }
402
403                         p = strchr( left.bv_val, *sub->sa_any[i]->bv_val );
404
405                         if( p == NULL ) {
406                                 match = 1;
407                                 goto done;
408                         }
409
410                         idx = p - left.bv_val;
411                         assert( idx < left.bv_len );
412
413                         if( idx >= left.bv_len ) {
414                                 /* this shouldn't happen */
415                                 return LDAP_OTHER;
416                         }
417
418                         left.bv_val = p;
419                         left.bv_len -= idx;
420
421                         if( sub->sa_any[i]->bv_len > left.bv_len ) {
422                                 /* not enough left */
423                                 match = 1;
424                                 goto done;
425                         }
426
427                         match = strncmp( left.bv_val,
428                                 sub->sa_any[i]->bv_val,
429                                 sub->sa_any[i]->bv_len );
430
431
432                         if( match != 0 ) {
433                                 goto retry;
434                         }
435
436                         left.bv_val += sub->sa_any[i]->bv_len;
437                         left.bv_len -= sub->sa_any[i]->bv_len;
438                 }
439         }
440
441 done:
442         *matchp = match;
443         return LDAP_SUCCESS;
444 }
445 #endif
446
447 static int
448 caseIgnoreIA5Match(
449         int *match,
450         unsigned use,
451         Syntax *syntax,
452         MatchingRule *mr,
453         struct berval *value,
454         void *assertedValue )
455 {
456         *match = strcasecmp( value->bv_val,
457                 ((struct berval *) assertedValue)->bv_val );
458         return LDAP_SUCCESS;
459 }
460
461 #ifdef SLAPD_SCHEMA_NOT_COMPAT
462 static char *strcasechr( const char *str, int c )
463 {
464         char *lower = strchr( str, TOLOWER(c) );
465         char *upper = strchr( str, TOUPPER(c) );
466
467         if( lower && upper ) {
468                 return lower < upper ? lower : upper;
469         } else if ( lower ) {
470                 return lower;
471         } else {
472                 return upper;
473         }
474 }
475
476 static int
477 caseIgnoreIA5SubstringsMatch(
478         int *matchp,
479         unsigned use,
480         Syntax *syntax,
481         MatchingRule *mr,
482         struct berval *value,
483         void *assertedValue )
484 {
485         int match = 0;
486         SubstringsAssertion *sub = assertedValue;
487         struct berval left = *value;
488         int i;
489         ber_len_t inlen=0;
490
491         if( sub->sa_initial ) {
492                 inlen += sub->sa_initial->bv_len;
493         }
494         if( sub->sa_any ) {
495                 for(i=0; sub->sa_any[i]; i++) {
496                         inlen += sub->sa_final->bv_len;
497                 }
498         }
499         if( sub->sa_final ) {
500                 inlen += sub->sa_final->bv_len;
501         }
502
503         if( inlen > value->bv_len ) {
504                 match = 1;
505                 goto done;
506         }
507
508         if( sub->sa_initial ) {
509                 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
510                         sub->sa_initial->bv_len );
511
512                 if( match != 0 ) {
513                         goto done;
514                 }
515
516                 left.bv_val += sub->sa_initial->bv_len;
517                 left.bv_len -= sub->sa_initial->bv_len;
518         }
519
520         if( sub->sa_final ) {
521                 match = strncasecmp( sub->sa_final->bv_val,
522                         &left.bv_val[left.bv_len - sub->sa_final->bv_len],
523                         sub->sa_final->bv_len );
524
525                 if( match != 0 ) {
526                         goto done;
527                 }
528
529                 left.bv_len -= sub->sa_final->bv_len;
530         }
531
532         if( sub->sa_any ) {
533                 for(i=0; sub->sa_any[i]; i++) {
534                         ber_len_t idx;
535                         char *p;
536
537 retry:
538                         if( inlen < left.bv_len ) {
539                                 /* not enough length */
540                                 match = 1;
541                                 goto done;
542                         }
543
544                         if( sub->sa_any[i]->bv_len == 0 ) {
545                                 continue;
546                         }
547
548                         p = strcasechr( left.bv_val, *sub->sa_any[i]->bv_val );
549
550                         if( p == NULL ) {
551                                 match = 1;
552                                 goto done;
553                         }
554
555                         idx = p - left.bv_val;
556                         assert( idx < left.bv_len );
557
558                         if( idx >= left.bv_len ) {
559                                 /* this shouldn't happen */
560                                 return LDAP_OTHER;
561                         }
562
563                         left.bv_val = p;
564                         left.bv_len -= idx;
565
566                         if( sub->sa_any[i]->bv_len > left.bv_len ) {
567                                 /* not enough left */
568                                 match = 1;
569                                 goto done;
570                         }
571
572                         match = strncasecmp( left.bv_val,
573                                 sub->sa_any[i]->bv_val,
574                                 sub->sa_any[i]->bv_len );
575
576
577                         if( match != 0 ) {
578                                 goto retry;
579                         }
580
581                         left.bv_val += sub->sa_any[i]->bv_len;
582                         left.bv_len -= sub->sa_any[i]->bv_len;
583                 }
584         }
585
586 done:
587         *matchp = match;
588         return LDAP_SUCCESS;
589 }
590 #endif
591
592 struct syntax_defs_rec {
593         char *sd_desc;
594         int sd_flags;
595         slap_syntax_validate_func *sd_validate;
596         slap_syntax_transform_func *sd_normalize;
597         slap_syntax_transform_func *sd_pretty;
598 #ifdef SLAPD_BINARY_CONVERSION
599         slap_syntax_transform_func *sd_ber2str;
600         slap_syntax_transform_func *sd_str2ber;
601 #endif
602 };
603
604 #define X_HIDE "X-HIDE 'TRUE' "
605 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
606 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
607
608 struct syntax_defs_rec syntax_defs[] = {
609         {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
610                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
611         {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
612                 0, NULL, NULL, NULL},
613         {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
614                 0, NULL, NULL, NULL},
615         {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
616                 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
617         {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
618                 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
619         {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
620                 0, NULL, NULL, NULL},
621         {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
622                 0, NULL, NULL, NULL},
623         {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
624                 X_BINARY X_NOT_H_R ")",
625                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
626         {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
627                 X_BINARY X_NOT_H_R ")",
628                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
629         {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
630                 X_BINARY X_NOT_H_R ")",
631                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
632         {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
633                 0, NULL, NULL, NULL},
634         {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )",
635                 0, blobValidate, NULL, NULL},
636         {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
637                 0, NULL, NULL, NULL},
638         {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
639                 0, NULL, NULL, NULL},
640         {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
641                 0, UTF8StringValidate, UTF8StringNormalize, NULL},
642         {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
643                 0, NULL, NULL, NULL},
644         {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
645                 0, NULL, NULL, NULL},
646         {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
647                 0, NULL, NULL, NULL},
648         {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
649                 0, NULL, NULL, NULL},
650         {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
651                 0, NULL, NULL, NULL},
652         {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
653                 0, blobValidate, NULL, NULL},
654         {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
655                 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
656         {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
657                 0, NULL, NULL, NULL},
658         {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
659                 0, NULL, NULL, NULL},
660         {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
661                 0, IA5StringValidate, IA5StringNormalize, NULL},
662         {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
663                 0, integerValidate, NULL, NULL},
664         {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
665                 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
666         {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
667                 0, NULL, NULL, NULL},
668         {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
669                 0, NULL, NULL, NULL},
670         {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
671                 0, NULL, NULL, NULL},
672         {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
673                 0, NULL, NULL, NULL},
674         {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
675                 0, NULL, NULL, NULL},
676         {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
677                 0, NULL, NULL, NULL},
678         {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
679                 0, NULL, NULL, NULL},
680         {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
681                 0, NULL, NULL, NULL},
682         {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
683                 0, NULL, NULL, NULL},
684         {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
685                 0, oidValidate, NULL, NULL},
686         {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
687                 0, NULL, NULL, NULL},
688         {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
689                 0, blobValidate, NULL, NULL},
690         {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
691                 0, blobValidate, NULL, NULL},
692         {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
693                 0, NULL, NULL, NULL},
694         {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
695                 0, NULL, NULL, NULL},
696         {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
697                 0, printableStringValidate, NULL, NULL},
698         {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
699                 X_BINARY X_NOT_H_R ")",
700                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
701         {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
702                 0, blobValidate, NULL, NULL},
703         {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
704                 0, NULL, NULL, NULL},
705         {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
706                 0, NULL, NULL, NULL},
707         {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
708                 0, NULL, NULL, NULL},
709         {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
710                 0, NULL, NULL, NULL},
711         {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
712                 0, NULL, NULL, NULL},
713         {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
714                 0, NULL, NULL, NULL},
715         {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
716                 0, NULL, NULL, NULL},
717         {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
718                 0, NULL, NULL, NULL},
719
720         /* OpenLDAP Experimental Syntaxes */
721         {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
722                 0, NULL, NULL, NULL},
723         {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP void' " X_HIDE ")" ,
724                 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
725         {"( 1.3.6.1.4.1.4203.666.2.3 DESC 'OpenLDAP DN' " X_HIDE ")" ,
726                 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
727
728         {NULL, 0, NULL, NULL, NULL}
729 };
730
731 struct mrule_defs_rec {
732         char *                                          mrd_desc;
733         unsigned                                        mrd_usage;
734         slap_mr_convert_func *          mrd_convert;
735         slap_mr_normalize_func *        mrd_normalize;
736         slap_mr_match_func *            mrd_match;
737         slap_mr_indexer_func *          mrd_indexer;
738         slap_mr_filter_func *           mrd_filter;
739 };
740
741 /*
742  * Other matching rules in X.520 that we do not use:
743  *
744  * 2.5.13.9             numericStringOrderingMatch
745  * 2.5.13.13    booleanMatch
746  * 2.5.13.15    integerOrderingMatch
747  * 2.5.13.18    octetStringOrderingMatch
748  * 2.5.13.19    octetStringSubstringsMatch
749  * 2.5.13.25    uTCTimeMatch
750  * 2.5.13.26    uTCTimeOrderingMatch
751  * 2.5.13.31    directoryStringFirstComponentMatch
752  * 2.5.13.32    wordMatch
753  * 2.5.13.33    keywordMatch
754  * 2.5.13.34    certificateExactMatch
755  * 2.5.13.35    certificateMatch
756  * 2.5.13.36    certificatePairExactMatch
757  * 2.5.13.37    certificatePairMatch
758  * 2.5.13.38    certificateListExactMatch
759  * 2.5.13.39    certificateListMatch
760  * 2.5.13.40    algorithmIdentifierMatch
761  * 2.5.13.41    storedPrefixMatch
762  * 2.5.13.42    attributeCertificateMatch
763  * 2.5.13.43    readerAndKeyIDMatch
764  * 2.5.13.44    attributeIntegrityMatch
765  */
766
767 #ifndef SLAPD_SCHEMA_NOT_COMPAT
768 #define caseIgnoreIA5SubstringsMatch NULL
769 #define caseExactIA5SubstringsMatch NULL
770 #endif
771
772 /* recycled matching functions */
773 #define caseIgnoreMatch caseIgnoreIA5Match
774 #define caseIgnoreOrderingMatch caseIgnoreMatch
775 #define caseIgnoreSubstringsMatch caseIgnoreIA5SubstringsMatch
776 #define caseExactMatch caseExactIA5Match
777 #define caseExactOrderingMatch caseExactMatch
778 #define caseExactSubstringsMatch caseExactIA5SubstringsMatch
779
780 /* unimplemented matching functions */
781 #define objectIdentifierMatch NULL
782 #define distinguishedNameMatch NULL
783 #define numericStringMatch NULL
784 #define numericStringSubstringsMatch NULL
785 #define caseIgnoreListMatch NULL
786 #define caseIgnoreListSubstringsMatch NULL
787 #define integerMatch NULL
788 #define bitStringMatch NULL
789 #define octetStringMatch NULL
790 #define telephoneNumberMatch NULL
791 #define telephoneNumberSubstringsMatch NULL
792 #define presentationAddressMatch NULL
793 #define uniqueMemberMatch NULL
794 #define protocolInformationMatch NULL
795 #define generalizedTimeMatch NULL
796 #define generalizedTimeOrderingMatch NULL
797 #define integerFirstComponentMatch NULL
798 #define objectIdentifierFirstComponentMatch NULL
799
800 struct mrule_defs_rec mrule_defs[] = {
801         {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
802                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
803                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
804                 NULL, NULL, objectIdentifierMatch, NULL, NULL},
805
806         {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
807                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
808                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
809                 NULL, NULL, distinguishedNameMatch, NULL, NULL},
810
811         {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
812                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
813                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
814                 NULL, NULL, caseIgnoreMatch, NULL, NULL},
815
816         {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
817                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
818                 SLAP_MR_ORDERING,
819                 NULL, NULL, caseIgnoreOrderingMatch, NULL, NULL},
820
821         {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
822                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
823                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
824                 NULL, NULL, caseIgnoreSubstringsMatch, NULL, NULL},
825
826         /* Next three are not in the RFC's, but are needed for compatibility */
827         {"( 2.5.13.5 NAME 'caseExactMatch' "
828                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
829                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
830                 NULL, NULL, caseExactMatch, NULL, NULL},
831
832         {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
833                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
834                 SLAP_MR_ORDERING,
835                 NULL, NULL, caseExactOrderingMatch, NULL, NULL},
836
837         {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
838                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
839                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
840                 NULL, NULL, caseExactSubstringsMatch, NULL, NULL},
841
842         {"( 2.5.13.8 NAME 'numericStringMatch' "
843                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
844                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
845                 NULL, NULL, numericStringMatch, NULL, NULL},
846
847         {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
848                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
849                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
850                 NULL, NULL, numericStringSubstringsMatch, NULL, NULL},
851
852         {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
853                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
854                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
855                 NULL, NULL, caseIgnoreListMatch, NULL, NULL},
856
857         {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
858                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
859                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
860                 NULL, NULL, caseIgnoreListSubstringsMatch, NULL, NULL},
861
862         {"( 2.5.13.14 NAME 'integerMatch' "
863                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
864                 SLAP_MR_NONE | SLAP_MR_EXT,
865                 NULL, NULL, integerMatch, NULL, NULL},
866
867         {"( 2.5.13.16 NAME 'bitStringMatch' "
868                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
869                 SLAP_MR_NONE | SLAP_MR_EXT,
870                 NULL, NULL, bitStringMatch, NULL, NULL},
871
872         {"( 2.5.13.17 NAME 'octetStringMatch' "
873                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
874                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
875                 NULL, NULL, octetStringMatch, NULL, NULL},
876
877         {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
878                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
879                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
880                 NULL, NULL, telephoneNumberMatch, NULL, NULL},
881
882         {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
883                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
884                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
885                 NULL, NULL, telephoneNumberSubstringsMatch, NULL, NULL},
886
887         {"( 2.5.13.22 NAME 'presentationAddressMatch' "
888                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
889                 SLAP_MR_NONE | SLAP_MR_EXT,
890                 NULL, NULL, presentationAddressMatch, NULL, NULL},
891
892         {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
893                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
894                 SLAP_MR_NONE | SLAP_MR_EXT,
895                 NULL, NULL, uniqueMemberMatch, NULL, NULL},
896
897         {"( 2.5.13.24 NAME 'protocolInformationMatch' "
898                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
899                 SLAP_MR_NONE | SLAP_MR_EXT,
900                 NULL, NULL, protocolInformationMatch, NULL, NULL},
901
902         {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
903                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
904                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
905                 NULL, NULL, generalizedTimeMatch, NULL, NULL},
906
907         {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
908                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
909                 SLAP_MR_ORDERING,
910                 NULL, NULL, generalizedTimeOrderingMatch, NULL, NULL},
911
912         {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
913                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
914                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
915                 NULL, NULL, integerFirstComponentMatch, NULL, NULL},
916
917         {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
918                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
919                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
920                 NULL, NULL, objectIdentifierFirstComponentMatch, NULL, NULL},
921
922         {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
923                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
924                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
925                 NULL, NULL, caseExactIA5Match, NULL, NULL},
926
927         {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
928                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
929                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
930                 NULL, NULL, caseIgnoreIA5Match, NULL, NULL},
931
932         {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
933                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
934                 SLAP_MR_SUBSTR,
935                 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
936
937         {NULL, SLAP_MR_NONE, NULL, NULL, NULL}
938 };
939
940 int
941 schema_init( void )
942 {
943         int             res;
944         int             i;
945
946         /* we should only be called once (from main) */
947         assert( schema_init_done == 0 );
948
949         for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
950                 res = register_syntax( syntax_defs[i].sd_desc,
951                     syntax_defs[i].sd_flags,
952                     syntax_defs[i].sd_validate,
953                     syntax_defs[i].sd_normalize,
954                         syntax_defs[i].sd_pretty
955 #ifdef SLAPD_BINARY_CONVERSION
956                         ,
957                     syntax_defs[i].sd_ber2str,
958                         syntax_defs[i].sd_str2ber
959 #endif
960                 );
961
962                 if ( res ) {
963                         fprintf( stderr, "schema_init: Error registering syntax %s\n",
964                                  syntax_defs[i].sd_desc );
965                         return LDAP_OTHER;
966                 }
967         }
968
969         for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
970                 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
971                         fprintf( stderr,
972                                 "schema_init: Ingoring unusable matching rule %s\n",
973                                  mrule_defs[i].mrd_desc );
974                         continue;
975                 }
976
977                 res = register_matching_rule(
978                         mrule_defs[i].mrd_desc,
979                         mrule_defs[i].mrd_usage,
980                         mrule_defs[i].mrd_convert,
981                         mrule_defs[i].mrd_normalize,
982                     mrule_defs[i].mrd_match,
983                         mrule_defs[i].mrd_indexer,
984                         mrule_defs[i].mrd_filter );
985
986                 if ( res ) {
987                         fprintf( stderr,
988                                 "schema_init: Error registering matching rule %s\n",
989                                  mrule_defs[i].mrd_desc );
990                         return LDAP_OTHER;
991                 }
992         }
993         schema_init_done = 1;
994         return LDAP_SUCCESS;
995 }