1 /* schemaparse.c - routines to parse config file objectclass definitions */
3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
12 #include <ac/socket.h>
15 #include "ldap_schema.h"
17 static Avlnode *object_classes = NULL;
19 int global_schemacheck = 1; /* schemacheck on is default */
21 static void oc_usage_old(void);
22 static void oc_usage(void);
24 static char *err2text[] = {
27 "Objectclass not found",
28 "Attribute type not found",
29 "Duplicate objectclass",
30 "Duplicate attributetype",
32 "Duplicate matchingrule",
33 "OID or name required",
34 "Syntax or superior required",
35 "Matchingrule not found",
43 if ( code < 1 || code >= (sizeof(err2text)/sizeof(char *)) ) {
44 return "Unknown error";
46 return err2text[code];
61 LDAP_OBJECT_CLASS *oc;
66 oc = (LDAP_OBJECT_CLASS *) ch_calloc( 1, sizeof(LDAP_OBJECT_CLASS) );
67 oc->oc_names = ch_calloc( 2, sizeof(char *) );
68 oc->oc_names[0] = ch_strdup( argv[1] );
69 oc->oc_names[1] = NULL;
70 if ( strcasecmp( oc->oc_names[0], "top" ) ) {
71 oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
73 for ( i = 2; i < argc; i++ ) {
74 /* required attributes */
75 if ( strcasecmp( argv[i], "requires" ) == 0 ) {
79 char **s = str2charray( argv[i], "," );
80 last = argv[i][strlen( argv[i] ) - 1];
81 charray_merge( &oc->oc_at_oids_must, s );
84 } while ( i < argc && last == ',' );
86 /* optional attributes */
87 } else if ( strcasecmp( argv[i], "allows" ) == 0 ) {
91 char **s = str2charray( argv[i], "," );
92 last = argv[i][strlen( argv[i] ) - 1];
94 charray_merge( &oc->oc_at_oids_may, s );
97 } while ( i < argc && last == ',' );
101 "%s: line %d: expecting \"requires\" or \"allows\" got \"%s\"\n",
102 fname, lineno, argv[i] );
108 * There was no requirement in the old schema that all attributes
109 * types were defined before use and they would just default to
110 * SYNTAX_CIS. To support this, we need to make attribute types
113 if ( oc->oc_at_oids_must ) {
114 namep = oc->oc_at_oids_must;
116 code = at_fake_if_needed( *namep );
118 fprintf( stderr, "%s: line %d: %s %s\n",
119 fname, lineno, scherr2str(code), *namep);
120 exit( EXIT_FAILURE );
125 if ( oc->oc_at_oids_may ) {
126 namep = oc->oc_at_oids_may;
128 code = at_fake_if_needed( *namep );
130 fprintf( stderr, "%s: line %d: %s %s\n",
131 fname, lineno, scherr2str(code), *namep);
132 exit( EXIT_FAILURE );
138 code = oc_add(oc,&err);
140 fprintf( stderr, "%s: line %d: %s %s\n",
141 fname, lineno, scherr2str(code), err);
142 exit( EXIT_FAILURE );
154 LDAP_OBJECT_CLASS *oc;
158 oc = ldap_str2objectclass(line,&code,&err);
160 fprintf( stderr, "%s: line %d: %s before %s\n",
161 fname, lineno, ldap_scherr2str(code), err );
164 code = oc_add(oc,&err);
166 fprintf( stderr, "%s: line %d: %s %s\n",
167 fname, lineno, scherr2str(code), err);
168 exit( EXIT_FAILURE );
176 fprintf( stderr, "ObjectClassDescription = \"(\" whsp\n");
177 fprintf( stderr, " numericoid whsp ; ObjectClass identifier\n");
178 fprintf( stderr, " [ \"NAME\" qdescrs ]\n");
179 fprintf( stderr, " [ \"DESC\" qdstring ]\n");
180 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
181 fprintf( stderr, " [ \"SUP\" oids ] ; Superior ObjectClasses\n");
182 fprintf( stderr, " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n");
183 fprintf( stderr, " ; default structural\n");
184 fprintf( stderr, " [ \"MUST\" oids ] ; AttributeTypes\n");
185 fprintf( stderr, " [ \"MAY\" oids ] ; AttributeTypes\n");
186 fprintf( stderr, "whsp \")\"\n");
187 exit( EXIT_FAILURE );
193 fprintf( stderr, "<oc clause> ::= objectclass <ocname>\n" );
194 fprintf( stderr, " [ requires <attrlist> ]\n" );
195 fprintf( stderr, " [ allows <attrlist> ]\n" );
196 exit( EXIT_FAILURE );
202 fprintf( stderr, "AttributeTypeDescription = \"(\" whsp\n");
203 fprintf( stderr, " numericoid whsp ; AttributeType identifier\n");
204 fprintf( stderr, " [ \"NAME\" qdescrs ] ; name used in AttributeType\n");
205 fprintf( stderr, " [ \"DESC\" qdstring ] ; description\n");
206 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
207 fprintf( stderr, " [ \"SUP\" woid ] ; derived from this other\n");
208 fprintf( stderr, " ; AttributeType\n");
209 fprintf( stderr, " [ \"EQUALITY\" woid ] ; Matching Rule name\n");
210 fprintf( stderr, " [ \"ORDERING\" woid ] ; Matching Rule name\n");
211 fprintf( stderr, " [ \"SUBSTR\" woid ] ; Matching Rule name\n");
212 fprintf( stderr, " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n");
213 fprintf( stderr, " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n");
214 fprintf( stderr, " [ \"COLLECTIVE\" whsp ] ; default not collective\n");
215 fprintf( stderr, " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n");
216 fprintf( stderr, " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n");
217 fprintf( stderr, " ; userApplications\n");
218 fprintf( stderr, " ; directoryOperation\n");
219 fprintf( stderr, " ; distributedOperation\n");
220 fprintf( stderr, " ; dSAOperation\n");
221 fprintf( stderr, "whsp \")\"\n");
222 exit( EXIT_FAILURE );
232 LDAP_ATTRIBUTE_TYPE *at;
236 at = ldap_str2attributetype(line,&code,&err);
238 fprintf( stderr, "%s: line %d: %s before %s\n",
239 fname, lineno, ldap_scherr2str(code), err );
242 code = at_add(at,&err);
244 fprintf( stderr, "%s: line %d: %s %s\n",
245 fname, lineno, scherr2str(code), err);
246 exit( EXIT_FAILURE );