]> git.sur5r.net Git - openldap/blob - servers/slapd/schemaparse.c
Removed unnecessary definition that is already in core.schema.
[openldap] / servers / slapd / schemaparse.c
1 /* schemaparse.c - routines to parse config file objectclass definitions */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/string.h>
8 #include <ac/socket.h>
9
10 #include "slap.h"
11 #include "ldap_schema.h"
12
13 static Avlnode          *object_classes = NULL;
14
15 int     global_schemacheck = 1; /* schemacheck on is default */
16
17 static void             oc_usage_old(void);
18 static void             oc_usage(void);
19
20 static char *err2text[] = {
21         "",
22         "Out of memory",
23         "Objectclass not found",
24         "Attribute type not found",
25         "Duplicate objectclass",
26         "Duplicate attributetype"
27 };
28
29 char *
30 scherr2str(int code)
31 {
32         if ( code < 1 || code >= (sizeof(err2text)/sizeof(char *)) ) {
33                 return "Unknown error";
34         } else {
35                 return err2text[code];
36         }
37 }
38
39 void
40 parse_oc_old(
41     Backend     *be,
42     char        *fname,
43     int         lineno,
44     int         argc,
45     char        **argv
46 )
47 {
48         int             i;
49         char            last;
50         LDAP_OBJECT_CLASS       *oc;
51         int             code;
52         char            *err;
53         char            **namep;
54
55         oc = (LDAP_OBJECT_CLASS *) ch_calloc( 1, sizeof(LDAP_OBJECT_CLASS) );
56         oc->oc_names = ch_calloc( 2, sizeof(char *) );
57         oc->oc_names[0] = ch_strdup( argv[1] );
58         oc->oc_names[1] = NULL;
59         if ( strcasecmp( oc->oc_names[0], "top" ) ) {
60                 oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
61         }
62         for ( i = 2; i < argc; i++ ) {
63                 /* required attributes */
64                 if ( strcasecmp( argv[i], "requires" ) == 0 ) {
65                         do {
66                                 i++;
67                                 if ( i < argc ) {
68                                         char **s = str2charray( argv[i], "," );
69                                         last = argv[i][strlen( argv[i] ) - 1];
70                                         charray_merge( &oc->oc_at_oids_must, s );
71                                         charray_free( s );
72                                 }
73                         } while ( i < argc && last == ',' );
74
75                 /* optional attributes */
76                 } else if ( strcasecmp( argv[i], "allows" ) == 0 ) {
77                         do {
78                                 i++;
79                                 if ( i < argc ) {
80                                         char **s = str2charray( argv[i], "," );
81                                         last = argv[i][strlen( argv[i] ) - 1];
82                                         
83                                         charray_merge( &oc->oc_at_oids_may, s );
84                                         charray_free( s );
85                                 }
86                         } while ( i < argc && last == ',' );
87
88                 } else {
89                         fprintf( stderr,
90             "%s: line %d: expecting \"requires\" or \"allows\" got \"%s\"\n",
91                             fname, lineno, argv[i] );
92                         oc_usage_old();
93                 }
94         }
95
96         /*
97          * There was no requirement in the old schema that all attributes
98          * types were defined before use and they would just default to
99          * SYNTAX_CIS.  To support this, we need to make attribute types
100          * out of thin air.
101          */
102         if ( oc->oc_at_oids_must ) {
103                 namep = oc->oc_at_oids_must;
104                 while ( *namep ) {
105                         code = at_fake_if_needed( *namep );
106                         if ( code ) {
107                                 fprintf( stderr, "%s: line %d: %s %s\n",
108                                          fname, lineno, scherr2str(code), *namep);
109                                 exit( 1 );
110                         }
111                         namep++;
112                 }
113         }
114         if ( oc->oc_at_oids_may ) {
115                 namep = oc->oc_at_oids_may;
116                 while ( *namep ) {
117                         code = at_fake_if_needed( *namep );
118                         if ( code ) {
119                                 fprintf( stderr, "%s: line %d: %s %s\n",
120                                          fname, lineno, scherr2str(code), *namep);
121                                 exit( 1 );
122                         }
123                         namep++;
124                 }
125         }
126         
127         code = oc_add(oc,&err);
128         if ( code ) {
129                 fprintf( stderr, "%s: line %d: %s %s\n",
130                          fname, lineno, scherr2str(code), err);
131                 exit( 1 );
132         }
133         ldap_memfree(oc);
134 }
135
136 void
137 parse_oc(
138     char        *fname,
139     int         lineno,
140     char        *line
141 )
142 {
143         LDAP_OBJECT_CLASS *oc;
144         int             code;
145         char            *err;
146
147         oc = ldap_str2objectclass(line,&code,&err);
148         if ( !oc ) {
149                 fprintf( stderr, "%s: line %d: %s before %s\n",
150                          fname, lineno, ldap_scherr2str(code), err );
151                 oc_usage();
152         }
153         code = oc_add(oc,&err);
154         if ( code ) {
155                 fprintf( stderr, "%s: line %d: %s %s\n",
156                          fname, lineno, scherr2str(code), err);
157                 exit( 1 );
158         }
159         ldap_memfree(oc);
160 }
161
162 static void
163 oc_usage( void )
164 {
165         fprintf( stderr, "ObjectClassDescription = \"(\" whsp\n");
166         fprintf( stderr, "  numericoid whsp      ; ObjectClass identifier\n");
167         fprintf( stderr, "  [ \"NAME\" qdescrs ]\n");
168         fprintf( stderr, "  [ \"DESC\" qdstring ]\n");
169         fprintf( stderr, "  [ \"OBSOLETE\" whsp ]\n");
170         fprintf( stderr, "  [ \"SUP\" oids ]       ; Superior ObjectClasses\n");
171         fprintf( stderr, "  [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n");
172         fprintf( stderr, "                       ; default structural\n");
173         fprintf( stderr, "  [ \"MUST\" oids ]      ; AttributeTypes\n");
174         fprintf( stderr, "  [ \"MAY\" oids ]       ; AttributeTypes\n");
175         fprintf( stderr, "whsp \")\"\n");
176         exit( 1 );
177 }
178
179 static void
180 oc_usage_old( void )
181 {
182         fprintf( stderr, "<oc clause> ::= objectclass <ocname>\n" );
183         fprintf( stderr, "                [ requires <attrlist> ]\n" );
184         fprintf( stderr, "                [ allows <attrlist> ]\n" );
185         exit( 1 );
186 }
187
188 static void
189 at_usage( void )
190 {
191         fprintf( stderr, "AttributeTypeDescription = \"(\" whsp\n");
192         fprintf( stderr, "  numericoid whsp      ; AttributeType identifier\n");
193         fprintf( stderr, "  [ \"NAME\" qdescrs ]             ; name used in AttributeType\n");
194         fprintf( stderr, "  [ \"DESC\" qdstring ]            ; description\n");
195         fprintf( stderr, "  [ \"OBSOLETE\" whsp ]\n");
196         fprintf( stderr, "  [ \"SUP\" woid ]                 ; derived from this other\n");
197         fprintf( stderr, "                                 ; AttributeType\n");
198         fprintf( stderr, "  [ \"EQUALITY\" woid ]            ; Matching Rule name\n");
199         fprintf( stderr, "  [ \"ORDERING\" woid ]            ; Matching Rule name\n");
200         fprintf( stderr, "  [ \"SUBSTR\" woid ]              ; Matching Rule name\n");
201         fprintf( stderr, "  [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n");
202         fprintf( stderr, "  [ \"SINGLE-VALUE\" whsp ]        ; default multi-valued\n");
203         fprintf( stderr, "  [ \"COLLECTIVE\" whsp ]          ; default not collective\n");
204         fprintf( stderr, "  [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n");
205         fprintf( stderr, "  [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n");
206         fprintf( stderr, "                                 ; userApplications\n");
207         fprintf( stderr, "                                 ; directoryOperation\n");
208         fprintf( stderr, "                                 ; distributedOperation\n");
209         fprintf( stderr, "                                 ; dSAOperation\n");
210         fprintf( stderr, "whsp \")\"\n");
211         exit( 1 );
212 }
213
214 void
215 parse_at(
216     char        *fname,
217     int         lineno,
218     char        *line
219 )
220 {
221         LDAP_ATTRIBUTE_TYPE *at;
222         int             code;
223         char            *err;
224
225         at = ldap_str2attributetype(line,&code,&err);
226         if ( !at ) {
227                 fprintf( stderr, "%s: line %d: %s before %s\n",
228                          fname, lineno, ldap_scherr2str(code), err );
229                 at_usage();
230         }
231         code = at_add(at,&err);
232         if ( code ) {
233                 fprintf( stderr, "%s: line %d: %s %s\n",
234                          fname, lineno, scherr2str(code), err);
235                 exit( 1 );
236         }
237         ldap_memfree(at);
238 }