]> git.sur5r.net Git - openldap/blob - servers/slapd/schemaparse.c
Add HARDCODE schema flags
[openldap] / servers / slapd / schemaparse.c
1 /* schemaparse.c - routines to parse config file objectclass definitions */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2005 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/ctype.h>
22 #include <ac/string.h>
23 #include <ac/socket.h>
24
25 #include "slap.h"
26 #include "ldap_schema.h"
27
28 int     global_schemacheck = 1; /* schemacheck ON is default */
29
30 static void             oc_usage(void); 
31 static void             at_usage(void);
32
33 static char *const err2text[] = {
34         "Success",
35         "Out of memory",
36         "ObjectClass not found",
37         "user-defined ObjectClass includes operational attributes",
38         "user-defined ObjectClass has inappropriate SUPerior",
39         "Duplicate objectClass",
40         "AttributeType not found",
41         "AttributeType inappropriate matching rule",
42         "AttributeType inappropriate USAGE",
43         "AttributeType inappropriate SUPerior",
44         "AttributeType SYNTAX or SUPerior required",
45         "Duplicate attributeType",
46         "MatchingRule not found",
47         "MatchingRule incomplete",
48         "Duplicate matchingRule",
49         "Syntax not found",
50         "Duplicate ldapSyntax",
51         "OID or name required",
52         "Qualifier not supported",
53         "Invalid NAME",
54         "OID could not be expanded",
55         "Duplicate Content Rule",
56         "Content Rule not for STRUCTURAL object class",
57         "Content Rule AUX contains inappropriate object class",
58         "Content Rule attribute type list contains duplicate"
59 };
60
61 char *
62 scherr2str(int code)
63 {
64         if ( code < 0 || SLAP_SCHERR_LAST <= code ) {
65                 return "Unknown error";
66         } else {
67                 return err2text[code];
68         }
69 }
70
71 /* check schema descr validity */
72 int slap_valid_descr( const char *descr )
73 {
74         int i=0;
75
76         if( !DESC_LEADCHAR( descr[i] ) ) {
77                 return 0;
78         }
79
80         while( descr[++i] ) {
81                 if( !DESC_CHAR( descr[i] ) ) {
82                         return 0;
83                 }
84         }
85
86         return 1;
87 }
88
89
90 /* OID Macros */
91
92 /* String compare with delimiter check. Return 0 if not
93  * matched, otherwise return length matched.
94  */
95 int
96 dscompare(const char *s1, const char *s2, char delim)
97 {
98         const char *orig = s1;
99         while (*s1++ == *s2++)
100                 if (!s1[-1]) break;
101         --s1;
102         --s2;
103         if (!*s1 && (!*s2 || *s2 == delim))
104                 return s1 - orig;
105         return 0;
106 }
107
108 static void
109 cr_usage( void )
110 {
111         fprintf( stderr,
112                 "DITContentRuleDescription = \"(\" whsp\n"
113                 "  numericoid whsp       ; StructuralObjectClass identifier\n"
114                 "  [ \"NAME\" qdescrs ]\n"
115                 "  [ \"DESC\" qdstring ]\n"
116                 "  [ \"OBSOLETE\" whsp ]\n"
117                 "  [ \"AUX\" oids ]      ; Auxiliary ObjectClasses\n"
118                 "  [ \"MUST\" oids ]     ; AttributeTypes\n"
119                 "  [ \"MAY\" oids ]      ; AttributeTypes\n"
120                 "  [ \"NOT\" oids ]      ; AttributeTypes\n"
121                 "  whsp \")\"\n" );
122 }
123
124 int
125 parse_cr(
126     const char  *fname,
127     int         lineno,
128     char        *line,
129     char        **argv )
130 {
131         LDAPContentRule *cr;
132         int             code;
133         const char      *err;
134
135         cr = ldap_str2contentrule(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
136         if ( !cr ) {
137                 fprintf( stderr, "%s: line %d: %s before %s\n",
138                          fname, lineno, ldap_scherr2str(code), err );
139                 cr_usage();
140                 return 1;
141         }
142
143         if ( cr->cr_oid == NULL ) {
144                 fprintf( stderr,
145                         "%s: line %d: Content rule has no OID\n",
146                         fname, lineno );
147                 cr_usage();
148                 return 1;
149         }
150
151         code = cr_add(cr,1,&err);
152         if ( code ) {
153                 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
154                          fname, lineno, scherr2str(code), err);
155                 return 1;
156         }
157
158         ldap_memfree(cr);
159         return 0;
160 }
161
162 int
163 parse_oc(
164     const char  *fname,
165     int         lineno,
166     char        *line,
167     char        **argv )
168 {
169         LDAPObjectClass *oc;
170         int             code;
171         const char      *err;
172
173         oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
174         if ( !oc ) {
175                 fprintf( stderr, "%s: line %d: %s before %s\n",
176                          fname, lineno, ldap_scherr2str(code), err );
177                 oc_usage();
178                 return 1;
179         }
180
181         if ( oc->oc_oid == NULL ) {
182                 fprintf( stderr,
183                         "%s: line %d: objectclass has no OID\n",
184                         fname, lineno );
185                 oc_usage();
186                 return 1;
187         }
188
189         code = oc_add(oc,1,&err);
190         if ( code ) {
191                 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
192                          fname, lineno, scherr2str(code), err);
193                 return 1;
194         }
195
196         ldap_memfree(oc);
197         return 0;
198 }
199
200 static void
201 oc_usage( void )
202 {
203         fprintf( stderr,
204                 "ObjectClassDescription = \"(\" whsp\n"
205                 "  numericoid whsp                 ; ObjectClass identifier\n"
206                 "  [ \"NAME\" qdescrs ]\n"
207                 "  [ \"DESC\" qdstring ]\n"
208                 "  [ \"OBSOLETE\" whsp ]\n"
209                 "  [ \"SUP\" oids ]                ; Superior ObjectClasses\n"
210                 "  [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
211                 "                                  ; default structural\n"
212                 "  [ \"MUST\" oids ]               ; AttributeTypes\n"
213                 "  [ \"MAY\" oids ]                ; AttributeTypes\n"
214                 "  whsp \")\"\n" );
215 }
216
217 static void
218 at_usage( void )
219 {
220         fprintf( stderr, "%s%s%s",
221                 "AttributeTypeDescription = \"(\" whsp\n"
222                 "  numericoid whsp      ; AttributeType identifier\n"
223                 "  [ \"NAME\" qdescrs ]             ; name used in AttributeType\n"
224                 "  [ \"DESC\" qdstring ]            ; description\n"
225                 "  [ \"OBSOLETE\" whsp ]\n"
226                 "  [ \"SUP\" woid ]                 ; derived from this other\n"
227                 "                                   ; AttributeType\n",
228                 "  [ \"EQUALITY\" woid ]            ; Matching Rule name\n"
229                 "  [ \"ORDERING\" woid ]            ; Matching Rule name\n"
230                 "  [ \"SUBSTR\" woid ]              ; Matching Rule name\n"
231                 "  [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
232                 "  [ \"SINGLE-VALUE\" whsp ]        ; default multi-valued\n"
233                 "  [ \"COLLECTIVE\" whsp ]          ; default not collective\n",
234                 "  [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
235                 "  [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
236                 "                                   ; userApplications\n"
237                 "                                   ; directoryOperation\n"
238                 "                                   ; distributedOperation\n"
239                 "                                   ; dSAOperation\n"
240                 "  whsp \")\"\n");
241 }
242
243 int
244 parse_at(
245     const char  *fname,
246     int         lineno,
247     char        *line,
248     char        **argv )
249 {
250         LDAPAttributeType *at;
251         int             code;
252         const char      *err;
253
254         at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
255         if ( !at ) {
256                 fprintf( stderr, "%s: line %d: %s before %s\n",
257                          fname, lineno, ldap_scherr2str(code), err );
258                 at_usage();
259                 return 1;
260         }
261
262         if ( at->at_oid == NULL ) {
263                 fprintf( stderr,
264                         "%s: line %d: attributeType has no OID\n",
265                         fname, lineno );
266                 at_usage();
267                 return 1;
268         }
269
270         /* operational attributes should be defined internally */
271         if ( at->at_usage ) {
272                 fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
273                          fname, lineno, at->at_oid );
274                 return 1;
275         }
276
277         code = at_add(at,1,&err);
278         if ( code ) {
279                 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
280                          fname, lineno, scherr2str(code), err);
281                 return 1;
282         }
283         ldap_memfree(at);
284         return 0;
285 }