1 /* schemaparse.c - routines to parse config file objectclass definitions */
11 #include "ldap_schema.h"
13 static Avlnode *object_classes = NULL;
15 int global_schemacheck = 1; /* schemacheck on is default */
17 static void oc_usage_old(void);
18 static void oc_usage(void);
20 static char *err2text[] = {
23 "Objectclass not found",
24 "Attribute type not found",
25 "Duplicate objectclass",
26 "Duplicate attributetype",
28 "Duplicate matchingrule",
29 "OID or name required",
30 "Syntax or superior required",
31 "Matchingrule not found",
39 if ( code < 1 || code >= (sizeof(err2text)/sizeof(char *)) ) {
40 return "Unknown error";
42 return err2text[code];
57 LDAP_OBJECT_CLASS *oc;
62 oc = (LDAP_OBJECT_CLASS *) ch_calloc( 1, sizeof(LDAP_OBJECT_CLASS) );
63 oc->oc_names = ch_calloc( 2, sizeof(char *) );
64 oc->oc_names[0] = ch_strdup( argv[1] );
65 oc->oc_names[1] = NULL;
66 if ( strcasecmp( oc->oc_names[0], "top" ) ) {
67 oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
69 for ( i = 2; i < argc; i++ ) {
70 /* required attributes */
71 if ( strcasecmp( argv[i], "requires" ) == 0 ) {
75 char **s = str2charray( argv[i], "," );
76 last = argv[i][strlen( argv[i] ) - 1];
77 charray_merge( &oc->oc_at_oids_must, s );
80 } while ( i < argc && last == ',' );
82 /* optional attributes */
83 } else if ( strcasecmp( argv[i], "allows" ) == 0 ) {
87 char **s = str2charray( argv[i], "," );
88 last = argv[i][strlen( argv[i] ) - 1];
90 charray_merge( &oc->oc_at_oids_may, s );
93 } while ( i < argc && last == ',' );
97 "%s: line %d: expecting \"requires\" or \"allows\" got \"%s\"\n",
98 fname, lineno, argv[i] );
104 * There was no requirement in the old schema that all attributes
105 * types were defined before use and they would just default to
106 * SYNTAX_CIS. To support this, we need to make attribute types
109 if ( oc->oc_at_oids_must ) {
110 namep = oc->oc_at_oids_must;
112 code = at_fake_if_needed( *namep );
114 fprintf( stderr, "%s: line %d: %s %s\n",
115 fname, lineno, scherr2str(code), *namep);
116 exit( EXIT_FAILURE );
121 if ( oc->oc_at_oids_may ) {
122 namep = oc->oc_at_oids_may;
124 code = at_fake_if_needed( *namep );
126 fprintf( stderr, "%s: line %d: %s %s\n",
127 fname, lineno, scherr2str(code), *namep);
128 exit( EXIT_FAILURE );
134 code = oc_add(oc,&err);
136 fprintf( stderr, "%s: line %d: %s %s\n",
137 fname, lineno, scherr2str(code), err);
138 exit( EXIT_FAILURE );
150 LDAP_OBJECT_CLASS *oc;
154 oc = ldap_str2objectclass(line,&code,&err);
156 fprintf( stderr, "%s: line %d: %s before %s\n",
157 fname, lineno, ldap_scherr2str(code), err );
160 code = oc_add(oc,&err);
162 fprintf( stderr, "%s: line %d: %s %s\n",
163 fname, lineno, scherr2str(code), err);
164 exit( EXIT_FAILURE );
172 fprintf( stderr, "ObjectClassDescription = \"(\" whsp\n");
173 fprintf( stderr, " numericoid whsp ; ObjectClass identifier\n");
174 fprintf( stderr, " [ \"NAME\" qdescrs ]\n");
175 fprintf( stderr, " [ \"DESC\" qdstring ]\n");
176 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
177 fprintf( stderr, " [ \"SUP\" oids ] ; Superior ObjectClasses\n");
178 fprintf( stderr, " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n");
179 fprintf( stderr, " ; default structural\n");
180 fprintf( stderr, " [ \"MUST\" oids ] ; AttributeTypes\n");
181 fprintf( stderr, " [ \"MAY\" oids ] ; AttributeTypes\n");
182 fprintf( stderr, "whsp \")\"\n");
183 exit( EXIT_FAILURE );
189 fprintf( stderr, "<oc clause> ::= objectclass <ocname>\n" );
190 fprintf( stderr, " [ requires <attrlist> ]\n" );
191 fprintf( stderr, " [ allows <attrlist> ]\n" );
192 exit( EXIT_FAILURE );
198 fprintf( stderr, "AttributeTypeDescription = \"(\" whsp\n");
199 fprintf( stderr, " numericoid whsp ; AttributeType identifier\n");
200 fprintf( stderr, " [ \"NAME\" qdescrs ] ; name used in AttributeType\n");
201 fprintf( stderr, " [ \"DESC\" qdstring ] ; description\n");
202 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
203 fprintf( stderr, " [ \"SUP\" woid ] ; derived from this other\n");
204 fprintf( stderr, " ; AttributeType\n");
205 fprintf( stderr, " [ \"EQUALITY\" woid ] ; Matching Rule name\n");
206 fprintf( stderr, " [ \"ORDERING\" woid ] ; Matching Rule name\n");
207 fprintf( stderr, " [ \"SUBSTR\" woid ] ; Matching Rule name\n");
208 fprintf( stderr, " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n");
209 fprintf( stderr, " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n");
210 fprintf( stderr, " [ \"COLLECTIVE\" whsp ] ; default not collective\n");
211 fprintf( stderr, " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n");
212 fprintf( stderr, " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n");
213 fprintf( stderr, " ; userApplications\n");
214 fprintf( stderr, " ; directoryOperation\n");
215 fprintf( stderr, " ; distributedOperation\n");
216 fprintf( stderr, " ; dSAOperation\n");
217 fprintf( stderr, "whsp \")\"\n");
218 exit( EXIT_FAILURE );
228 LDAP_ATTRIBUTE_TYPE *at;
232 at = ldap_str2attributetype(line,&code,&err);
234 fprintf( stderr, "%s: line %d: %s before %s\n",
235 fname, lineno, ldap_scherr2str(code), err );
238 code = at_add(at,&err);
240 fprintf( stderr, "%s: line %d: %s %s\n",
241 fname, lineno, scherr2str(code), err);
242 exit( EXIT_FAILURE );