]> git.sur5r.net Git - openldap/blob - servers/slapd/schema_init.c
e8b4630fac06d45b912158dc5c71c3de2208ec37
[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         }
372
373         if( sub->sa_final ) {
374                 match = strncmp( sub->sa_final->bv_val,
375                         &left.bv_val[left.bv_len - sub->sa_final->bv_len],
376                         sub->sa_final->bv_len );
377
378                 if( match != 0 ) {
379                         goto done;
380                 }
381
382                 left.bv_len -= sub->sa_final->bv_len;
383         }
384
385         if( sub->sa_any ) {
386                 return LDAP_OTHER;
387         }
388
389 done:
390         *matchp = match;
391         return LDAP_SUCCESS;
392 }
393 #endif
394
395 static int
396 caseIgnoreIA5Match(
397         int *match,
398         unsigned use,
399         Syntax *syntax,
400         MatchingRule *mr,
401         struct berval *value,
402         void *assertedValue )
403 {
404         *match = strcasecmp( value->bv_val,
405                 ((struct berval *) assertedValue)->bv_val );
406         return LDAP_SUCCESS;
407 }
408
409 #ifdef SLAPD_SCHEMA_NOT_COMPAT
410 static int
411 caseIgnoreIA5SubstringsMatch(
412         int *matchp,
413         unsigned use,
414         Syntax *syntax,
415         MatchingRule *mr,
416         struct berval *value,
417         void *assertedValue )
418 {
419         int match = 0;
420         SubstringsAssertion *sub = assertedValue;
421         struct berval left = *value;
422         int i;
423         ber_len_t inlen=0;
424
425         if( sub->sa_initial ) {
426                 inlen += sub->sa_initial->bv_len;
427         }
428         if( sub->sa_any ) {
429                 for(i=0; sub->sa_any[i]; i++) {
430                         inlen += sub->sa_final->bv_len;
431                 }
432         }
433         if( sub->sa_final ) {
434                 inlen += sub->sa_final->bv_len;
435         }
436
437         if( inlen > value->bv_len ) {
438                 match = 1;
439                 goto done;
440         }
441
442         if( sub->sa_initial ) {
443                 match = strncasecmp( sub->sa_initial->bv_val, left.bv_val,
444                         sub->sa_initial->bv_len );
445
446                 if( match != 0 ) {
447                         goto done;
448                 }
449
450                 left.bv_val += sub->sa_initial->bv_len;
451                 left.bv_len -= sub->sa_initial->bv_len;
452         }
453
454         if( sub->sa_final ) {
455                 match = strncasecmp( sub->sa_final->bv_val,
456                         &left.bv_val[left.bv_len - sub->sa_final->bv_len],
457                         sub->sa_final->bv_len );
458
459                 if( match != 0 ) {
460                         goto done;
461                 }
462
463                 left.bv_len -= sub->sa_final->bv_len;
464         }
465
466         if( sub->sa_any ) {
467                 return LDAP_OTHER;
468         }
469
470 done:
471         *matchp = match;
472         return LDAP_SUCCESS;
473 }
474 #endif
475
476 struct syntax_defs_rec {
477         char *sd_desc;
478         int sd_flags;
479         slap_syntax_validate_func *sd_validate;
480         slap_syntax_transform_func *sd_normalize;
481         slap_syntax_transform_func *sd_pretty;
482 #ifdef SLAPD_BINARY_CONVERSION
483         slap_syntax_transform_func *sd_ber2str;
484         slap_syntax_transform_func *sd_str2ber;
485 #endif
486 };
487
488 #define X_HIDE "X-HIDE 'TRUE' "
489 #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' "
490 #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' "
491
492 struct syntax_defs_rec syntax_defs[] = {
493         {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")",
494                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL},
495         {"( 1.3.6.1.4.1.1466.115.121.1.2 DESC 'Access Point' " X_NOT_H_R ")",
496                 0, NULL, NULL, NULL},
497         {"( 1.3.6.1.4.1.1466.115.121.1.3 DESC 'Attribute Type Description' )",
498                 0, NULL, NULL, NULL},
499         {"( 1.3.6.1.4.1.1466.115.121.1.4 DESC 'Audio' " X_NOT_H_R ")",
500                 SLAP_SYNTAX_BLOB, blobValidate, NULL, NULL},
501         {"( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' " X_BINARY X_NOT_H_R ")",
502                 SLAP_SYNTAX_BER, berValidate, NULL, NULL},
503         {"( 1.3.6.1.4.1.1466.115.121.1.6 DESC 'Bit String' )",
504                 0, NULL, NULL, NULL},
505         {"( 1.3.6.1.4.1.1466.115.121.1.7 DESC 'Boolean' )",
506                 0, NULL, NULL, NULL},
507         {"( 1.3.6.1.4.1.1466.115.121.1.8 DESC 'Certificate' "
508                 X_BINARY X_NOT_H_R ")",
509                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
510         {"( 1.3.6.1.4.1.1466.115.121.1.9 DESC 'Certificate List' "
511                 X_BINARY X_NOT_H_R ")",
512                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
513         {"( 1.3.6.1.4.1.1466.115.121.1.10 DESC 'Certificate Pair' "
514                 X_BINARY X_NOT_H_R ")",
515                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
516         {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )",
517                 0, NULL, NULL, NULL},
518         {"( 1.3.6.1.4.1.1466.115.121.1.12 DESC 'DN' )",
519                 0, blobValidate, NULL, NULL},
520         {"( 1.3.6.1.4.1.1466.115.121.1.13 DESC 'Data Quality' )",
521                 0, NULL, NULL, NULL},
522         {"( 1.3.6.1.4.1.1466.115.121.1.14 DESC 'Delivery Method' )",
523                 0, NULL, NULL, NULL},
524         {"( 1.3.6.1.4.1.1466.115.121.1.15 DESC 'Directory String' )",
525                 0, UTF8StringValidate, UTF8StringNormalize, NULL},
526         {"( 1.3.6.1.4.1.1466.115.121.1.16 DESC 'DIT Content Rule Description' )",
527                 0, NULL, NULL, NULL},
528         {"( 1.3.6.1.4.1.1466.115.121.1.17 DESC 'DIT Structure Rule Description' )",
529                 0, NULL, NULL, NULL},
530         {"( 1.3.6.1.4.1.1466.115.121.1.19 DESC 'DSA Quality' )",
531                 0, NULL, NULL, NULL},
532         {"( 1.3.6.1.4.1.1466.115.121.1.20 DESC 'DSE Type' )",
533                 0, NULL, NULL, NULL},
534         {"( 1.3.6.1.4.1.1466.115.121.1.21 DESC 'Enhanced Guide' )",
535                 0, NULL, NULL, NULL},
536         {"( 1.3.6.1.4.1.1466.115.121.1.22 DESC 'Facsimile Telephone Number' )",
537                 0, blobValidate, NULL, NULL},
538         {"( 1.3.6.1.4.1.1466.115.121.1.23 DESC 'Fax' " X_NOT_H_R ")",
539                 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
540         {"( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )",
541                 0, NULL, NULL, NULL},
542         {"( 1.3.6.1.4.1.1466.115.121.1.25 DESC 'Guide' )",
543                 0, NULL, NULL, NULL},
544         {"( 1.3.6.1.4.1.1466.115.121.1.26 DESC 'IA5 String' )",
545                 0, IA5StringValidate, IA5StringNormalize, NULL},
546         {"( 1.3.6.1.4.1.1466.115.121.1.27 DESC 'Integer' )",
547                 0, integerValidate, NULL, NULL},
548         {"( 1.3.6.1.4.1.1466.115.121.1.28 DESC 'JPEG' " X_NOT_H_R ")",
549                 SLAP_SYNTAX_BLOB, NULL, NULL, NULL},
550         {"( 1.3.6.1.4.1.1466.115.121.1.29 DESC 'Master And Shadow Access Points' )",
551                 0, NULL, NULL, NULL},
552         {"( 1.3.6.1.4.1.1466.115.121.1.30 DESC 'Matching Rule Description' )",
553                 0, NULL, NULL, NULL},
554         {"( 1.3.6.1.4.1.1466.115.121.1.31 DESC 'Matching Rule Use Description' )",
555                 0, NULL, NULL, NULL},
556         {"( 1.3.6.1.4.1.1466.115.121.1.32 DESC 'Mail Preference' )",
557                 0, NULL, NULL, NULL},
558         {"( 1.3.6.1.4.1.1466.115.121.1.33 DESC 'MHS OR Address' )",
559                 0, NULL, NULL, NULL},
560         {"( 1.3.6.1.4.1.1466.115.121.1.34 DESC 'Name And Optional UID' )",
561                 0, NULL, NULL, NULL},
562         {"( 1.3.6.1.4.1.1466.115.121.1.35 DESC 'Name Form Description' )",
563                 0, NULL, NULL, NULL},
564         {"( 1.3.6.1.4.1.1466.115.121.1.36 DESC 'Numeric String' )",
565                 0, NULL, NULL, NULL},
566         {"( 1.3.6.1.4.1.1466.115.121.1.37 DESC 'Object Class Description' )",
567                 0, NULL, NULL, NULL},
568         {"( 1.3.6.1.4.1.1466.115.121.1.38 DESC 'OID' )",
569                 0, oidValidate, NULL, NULL},
570         {"( 1.3.6.1.4.1.1466.115.121.1.39 DESC 'Other Mailbox' )",
571                 0, NULL, NULL, NULL},
572         {"( 1.3.6.1.4.1.1466.115.121.1.40 DESC 'Octet String' )",
573                 0, blobValidate, NULL, NULL},
574         {"( 1.3.6.1.4.1.1466.115.121.1.41 DESC 'Postal Address' )",
575                 0, blobValidate, NULL, NULL},
576         {"( 1.3.6.1.4.1.1466.115.121.1.42 DESC 'Protocol Information' )",
577                 0, NULL, NULL, NULL},
578         {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )",
579                 0, NULL, NULL, NULL},
580         {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )",
581                 0, printableStringValidate, NULL, NULL},
582         {"( 1.3.6.1.4.1.1466.115.121.1.49 DESC 'Supported Algorithm' "
583                 X_BINARY X_NOT_H_R ")",
584                 SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, berValidate, NULL, NULL},
585         {"( 1.3.6.1.4.1.1466.115.121.1.50 DESC 'Telephone Number' )",
586                 0, blobValidate, NULL, NULL},
587         {"( 1.3.6.1.4.1.1466.115.121.1.51 DESC 'Teletex Terminal Identifier' )",
588                 0, NULL, NULL, NULL},
589         {"( 1.3.6.1.4.1.1466.115.121.1.52 DESC 'Telex Number' )",
590                 0, NULL, NULL, NULL},
591         {"( 1.3.6.1.4.1.1466.115.121.1.53 DESC 'UTC Time' )",
592                 0, NULL, NULL, NULL},
593         {"( 1.3.6.1.4.1.1466.115.121.1.54 DESC 'LDAP Syntax Description' )",
594                 0, NULL, NULL, NULL},
595         {"( 1.3.6.1.4.1.1466.115.121.1.55 DESC 'Modify Rights' )",
596                 0, NULL, NULL, NULL},
597         {"( 1.3.6.1.4.1.1466.115.121.1.56 DESC 'LDAP Schema Definition' )",
598                 0, NULL, NULL, NULL},
599         {"( 1.3.6.1.4.1.1466.115.121.1.57 DESC 'LDAP Schema Description' )",
600                 0, NULL, NULL, NULL},
601         {"( 1.3.6.1.4.1.1466.115.121.1.58 DESC 'Substring Assertion' )",
602                 0, NULL, NULL, NULL},
603
604         /* OpenLDAP Experimental Syntaxes */
605         {"( 1.3.6.1.4.1.4203.666.2.1 DESC 'OpenLDAP Experimental ACI' )",
606                 0, NULL, NULL, NULL},
607         {"( 1.3.6.1.4.1.4203.666.2.2 DESC 'OpenLDAP void' " X_HIDE ")" ,
608                 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
609         {"( 1.3.6.1.4.1.4203.666.2.3 DESC 'OpenLDAP DN' " X_HIDE ")" ,
610                 SLAP_SYNTAX_HIDE, NULL, NULL, NULL},
611
612         {NULL, 0, NULL, NULL, NULL}
613 };
614
615 struct mrule_defs_rec {
616         char *                                          mrd_desc;
617         unsigned                                        mrd_usage;
618         slap_mr_convert_func *          mrd_convert;
619         slap_mr_normalize_func *        mrd_normalize;
620         slap_mr_match_func *            mrd_match;
621         slap_mr_indexer_func *          mrd_indexer;
622         slap_mr_filter_func *           mrd_filter;
623 };
624
625 /*
626  * Other matching rules in X.520 that we do not use:
627  *
628  * 2.5.13.9             numericStringOrderingMatch
629  * 2.5.13.13    booleanMatch
630  * 2.5.13.15    integerOrderingMatch
631  * 2.5.13.18    octetStringOrderingMatch
632  * 2.5.13.19    octetStringSubstringsMatch
633  * 2.5.13.25    uTCTimeMatch
634  * 2.5.13.26    uTCTimeOrderingMatch
635  * 2.5.13.31    directoryStringFirstComponentMatch
636  * 2.5.13.32    wordMatch
637  * 2.5.13.33    keywordMatch
638  * 2.5.13.34    certificateExactMatch
639  * 2.5.13.35    certificateMatch
640  * 2.5.13.36    certificatePairExactMatch
641  * 2.5.13.37    certificatePairMatch
642  * 2.5.13.38    certificateListExactMatch
643  * 2.5.13.39    certificateListMatch
644  * 2.5.13.40    algorithmIdentifierMatch
645  * 2.5.13.41    storedPrefixMatch
646  * 2.5.13.42    attributeCertificateMatch
647  * 2.5.13.43    readerAndKeyIDMatch
648  * 2.5.13.44    attributeIntegrityMatch
649  */
650
651 #ifndef SLAPD_SCHEMA_NOT_COMPAT
652 #define caseIgnoreIA5SubstringsMatch NULL
653 #define caseExactIA5SubstringsMatch NULL
654 #endif
655
656 /* recycled matching functions */
657 #define caseIgnoreMatch caseIgnoreIA5Match
658 #define caseIgnoreOrderingMatch caseIgnoreMatch
659 #define caseIgnoreSubstringsMatch caseIgnoreIA5SubstringsMatch
660 #define caseExactMatch caseExactIA5Match
661 #define caseExactOrderingMatch caseExactMatch
662 #define caseExactSubstringsMatch caseExactIA5SubstringsMatch
663
664 /* unimplemented matching functions */
665 #define objectIdentifierMatch NULL
666 #define distinguishedNameMatch NULL
667 #define numericStringMatch NULL
668 #define numericStringSubstringsMatch NULL
669 #define caseIgnoreListMatch NULL
670 #define caseIgnoreListSubstringsMatch NULL
671 #define integerMatch NULL
672 #define bitStringMatch NULL
673 #define octetStringMatch NULL
674 #define telephoneNumberMatch NULL
675 #define telephoneNumberSubstringsMatch NULL
676 #define presentationAddressMatch NULL
677 #define uniqueMemberMatch NULL
678 #define protocolInformationMatch NULL
679 #define generalizedTimeMatch NULL
680 #define generalizedTimeOrderingMatch NULL
681 #define integerFirstComponentMatch NULL
682 #define objectIdentifierFirstComponentMatch NULL
683
684 struct mrule_defs_rec mrule_defs[] = {
685         {"( 2.5.13.0 NAME 'objectIdentifierMatch' "
686                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
687                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
688                 NULL, NULL, objectIdentifierMatch, NULL, NULL},
689
690         {"( 2.5.13.1 NAME 'distinguishedNameMatch' "
691                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )",
692                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
693                 NULL, NULL, distinguishedNameMatch, NULL, NULL},
694
695         {"( 2.5.13.2 NAME 'caseIgnoreMatch' "
696                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
697                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
698                 NULL, NULL, caseIgnoreMatch, NULL, NULL},
699
700         {"( 2.5.13.3 NAME 'caseIgnoreOrderingMatch' "
701                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
702                 SLAP_MR_ORDERING,
703                 NULL, NULL, caseIgnoreOrderingMatch, NULL, NULL},
704
705         {"( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch' "
706                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
707                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
708                 NULL, NULL, caseIgnoreSubstringsMatch, NULL, NULL},
709
710         /* Next three are not in the RFC's, but are needed for compatibility */
711         {"( 2.5.13.5 NAME 'caseExactMatch' "
712                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
713                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
714                 NULL, NULL, caseExactMatch, NULL, NULL},
715
716         {"( 2.5.13.6 NAME 'caseExactOrderingMatch' "
717                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
718                 SLAP_MR_ORDERING,
719                 NULL, NULL, caseExactOrderingMatch, NULL, NULL},
720
721         {"( 2.5.13.7 NAME 'caseExactSubstringsMatch' "
722                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
723                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
724                 NULL, NULL, caseExactSubstringsMatch, NULL, NULL},
725
726         {"( 2.5.13.8 NAME 'numericStringMatch' "
727                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )",
728                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
729                 NULL, NULL, numericStringMatch, NULL, NULL},
730
731         {"( 2.5.13.10 NAME 'numericStringSubstringsMatch' "
732                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
733                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
734                 NULL, NULL, numericStringSubstringsMatch, NULL, NULL},
735
736         {"( 2.5.13.11 NAME 'caseIgnoreListMatch' "
737                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )",
738                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
739                 NULL, NULL, caseIgnoreListMatch, NULL, NULL},
740
741         {"( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch' "
742                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
743                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
744                 NULL, NULL, caseIgnoreListSubstringsMatch, NULL, NULL},
745
746         {"( 2.5.13.14 NAME 'integerMatch' "
747                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
748                 SLAP_MR_NONE | SLAP_MR_EXT,
749                 NULL, NULL, integerMatch, NULL, NULL},
750
751         {"( 2.5.13.16 NAME 'bitStringMatch' "
752                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )",
753                 SLAP_MR_NONE | SLAP_MR_EXT,
754                 NULL, NULL, bitStringMatch, NULL, NULL},
755
756         {"( 2.5.13.17 NAME 'octetStringMatch' "
757                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )",
758                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
759                 NULL, NULL, octetStringMatch, NULL, NULL},
760
761         {"( 2.5.13.20 NAME 'telephoneNumberMatch' "
762                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )",
763                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
764                 NULL, NULL, telephoneNumberMatch, NULL, NULL},
765
766         {"( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch' "
767                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )",
768                 SLAP_MR_SUBSTR | SLAP_MR_EXT,
769                 NULL, NULL, telephoneNumberSubstringsMatch, NULL, NULL},
770
771         {"( 2.5.13.22 NAME 'presentationAddressMatch' "
772                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )",
773                 SLAP_MR_NONE | SLAP_MR_EXT,
774                 NULL, NULL, presentationAddressMatch, NULL, NULL},
775
776         {"( 2.5.13.23 NAME 'uniqueMemberMatch' "
777                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )",
778                 SLAP_MR_NONE | SLAP_MR_EXT,
779                 NULL, NULL, uniqueMemberMatch, NULL, NULL},
780
781         {"( 2.5.13.24 NAME 'protocolInformationMatch' "
782                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )",
783                 SLAP_MR_NONE | SLAP_MR_EXT,
784                 NULL, NULL, protocolInformationMatch, NULL, NULL},
785
786         {"( 2.5.13.27 NAME 'generalizedTimeMatch' "
787                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
788                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
789                 NULL, NULL, generalizedTimeMatch, NULL, NULL},
790
791         {"( 2.5.13.28 NAME 'generalizedTimeOrderingMatch' "
792                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )",
793                 SLAP_MR_ORDERING,
794                 NULL, NULL, generalizedTimeOrderingMatch, NULL, NULL},
795
796         {"( 2.5.13.29 NAME 'integerFirstComponentMatch' "
797                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
798                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
799                 NULL, NULL, integerFirstComponentMatch, NULL, NULL},
800
801         {"( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch' "
802                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )",
803                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
804                 NULL, NULL, objectIdentifierFirstComponentMatch, NULL, NULL},
805
806         {"( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match' "
807                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
808                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
809                 NULL, NULL, caseExactIA5Match, NULL, NULL},
810
811         {"( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match' "
812                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
813                 SLAP_MR_EQUALITY | SLAP_MR_EXT,
814                 NULL, NULL, caseIgnoreIA5Match, NULL, NULL},
815
816         {"( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch' "
817                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )",
818                 SLAP_MR_SUBSTR,
819                 NULL, NULL, caseIgnoreIA5SubstringsMatch, NULL, NULL},
820
821         {NULL, SLAP_MR_NONE, NULL, NULL, NULL}
822 };
823
824 int
825 schema_init( void )
826 {
827         int             res;
828         int             i;
829
830         /* we should only be called once (from main) */
831         assert( schema_init_done == 0 );
832
833         for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) {
834                 res = register_syntax( syntax_defs[i].sd_desc,
835                     syntax_defs[i].sd_flags,
836                     syntax_defs[i].sd_validate,
837                     syntax_defs[i].sd_normalize,
838                         syntax_defs[i].sd_pretty
839 #ifdef SLAPD_BINARY_CONVERSION
840                         ,
841                     syntax_defs[i].sd_ber2str,
842                         syntax_defs[i].sd_str2ber
843 #endif
844                 );
845
846                 if ( res ) {
847                         fprintf( stderr, "schema_init: Error registering syntax %s\n",
848                                  syntax_defs[i].sd_desc );
849                         return LDAP_OTHER;
850                 }
851         }
852
853         for ( i=0; mrule_defs[i].mrd_desc != NULL; i++ ) {
854                 if( mrule_defs[i].mrd_usage == SLAP_MR_NONE ) {
855                         fprintf( stderr,
856                                 "schema_init: Ingoring unusable matching rule %s\n",
857                                  mrule_defs[i].mrd_desc );
858                         continue;
859                 }
860
861                 res = register_matching_rule(
862                         mrule_defs[i].mrd_desc,
863                         mrule_defs[i].mrd_usage,
864                         mrule_defs[i].mrd_convert,
865                         mrule_defs[i].mrd_normalize,
866                     mrule_defs[i].mrd_match,
867                         mrule_defs[i].mrd_indexer,
868                         mrule_defs[i].mrd_filter );
869
870                 if ( res ) {
871                         fprintf( stderr,
872                                 "schema_init: Error registering matching rule %s\n",
873                                  mrule_defs[i].mrd_desc );
874                         return LDAP_OTHER;
875                 }
876         }
877         schema_init_done = 1;
878         return LDAP_SUCCESS;
879 }