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