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",
38 if ( code < 1 || code >= (sizeof(err2text)/sizeof(char *)) ) {
39 return "Unknown error";
41 return err2text[code];
56 LDAP_OBJECT_CLASS *oc;
61 oc = (LDAP_OBJECT_CLASS *) ch_calloc( 1, sizeof(LDAP_OBJECT_CLASS) );
62 oc->oc_names = ch_calloc( 2, sizeof(char *) );
63 oc->oc_names[0] = ch_strdup( argv[1] );
64 oc->oc_names[1] = NULL;
65 if ( strcasecmp( oc->oc_names[0], "top" ) ) {
66 oc->oc_kind = LDAP_SCHEMA_STRUCTURAL;
68 for ( i = 2; i < argc; i++ ) {
69 /* required attributes */
70 if ( strcasecmp( argv[i], "requires" ) == 0 ) {
74 char **s = str2charray( argv[i], "," );
75 last = argv[i][strlen( argv[i] ) - 1];
76 charray_merge( &oc->oc_at_oids_must, s );
79 } while ( i < argc && last == ',' );
81 /* optional attributes */
82 } else if ( strcasecmp( argv[i], "allows" ) == 0 ) {
86 char **s = str2charray( argv[i], "," );
87 last = argv[i][strlen( argv[i] ) - 1];
89 charray_merge( &oc->oc_at_oids_may, s );
92 } while ( i < argc && last == ',' );
96 "%s: line %d: expecting \"requires\" or \"allows\" got \"%s\"\n",
97 fname, lineno, argv[i] );
103 * There was no requirement in the old schema that all attributes
104 * types were defined before use and they would just default to
105 * SYNTAX_CIS. To support this, we need to make attribute types
108 if ( oc->oc_at_oids_must ) {
109 namep = oc->oc_at_oids_must;
111 code = at_fake_if_needed( *namep );
113 fprintf( stderr, "%s: line %d: %s %s\n",
114 fname, lineno, scherr2str(code), *namep);
120 if ( oc->oc_at_oids_may ) {
121 namep = oc->oc_at_oids_may;
123 code = at_fake_if_needed( *namep );
125 fprintf( stderr, "%s: line %d: %s %s\n",
126 fname, lineno, scherr2str(code), *namep);
133 code = oc_add(oc,&err);
135 fprintf( stderr, "%s: line %d: %s %s\n",
136 fname, lineno, scherr2str(code), err);
149 LDAP_OBJECT_CLASS *oc;
153 oc = ldap_str2objectclass(line,&code,&err);
155 fprintf( stderr, "%s: line %d: %s before %s\n",
156 fname, lineno, ldap_scherr2str(code), err );
159 code = oc_add(oc,&err);
161 fprintf( stderr, "%s: line %d: %s %s\n",
162 fname, lineno, scherr2str(code), err);
171 fprintf( stderr, "ObjectClassDescription = \"(\" whsp\n");
172 fprintf( stderr, " numericoid whsp ; ObjectClass identifier\n");
173 fprintf( stderr, " [ \"NAME\" qdescrs ]\n");
174 fprintf( stderr, " [ \"DESC\" qdstring ]\n");
175 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
176 fprintf( stderr, " [ \"SUP\" oids ] ; Superior ObjectClasses\n");
177 fprintf( stderr, " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n");
178 fprintf( stderr, " ; default structural\n");
179 fprintf( stderr, " [ \"MUST\" oids ] ; AttributeTypes\n");
180 fprintf( stderr, " [ \"MAY\" oids ] ; AttributeTypes\n");
181 fprintf( stderr, "whsp \")\"\n");
188 fprintf( stderr, "<oc clause> ::= objectclass <ocname>\n" );
189 fprintf( stderr, " [ requires <attrlist> ]\n" );
190 fprintf( stderr, " [ allows <attrlist> ]\n" );
197 fprintf( stderr, "AttributeTypeDescription = \"(\" whsp\n");
198 fprintf( stderr, " numericoid whsp ; AttributeType identifier\n");
199 fprintf( stderr, " [ \"NAME\" qdescrs ] ; name used in AttributeType\n");
200 fprintf( stderr, " [ \"DESC\" qdstring ] ; description\n");
201 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
202 fprintf( stderr, " [ \"SUP\" woid ] ; derived from this other\n");
203 fprintf( stderr, " ; AttributeType\n");
204 fprintf( stderr, " [ \"EQUALITY\" woid ] ; Matching Rule name\n");
205 fprintf( stderr, " [ \"ORDERING\" woid ] ; Matching Rule name\n");
206 fprintf( stderr, " [ \"SUBSTR\" woid ] ; Matching Rule name\n");
207 fprintf( stderr, " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n");
208 fprintf( stderr, " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n");
209 fprintf( stderr, " [ \"COLLECTIVE\" whsp ] ; default not collective\n");
210 fprintf( stderr, " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n");
211 fprintf( stderr, " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n");
212 fprintf( stderr, " ; userApplications\n");
213 fprintf( stderr, " ; directoryOperation\n");
214 fprintf( stderr, " ; distributedOperation\n");
215 fprintf( stderr, " ; dSAOperation\n");
216 fprintf( stderr, "whsp \")\"\n");
227 LDAP_ATTRIBUTE_TYPE *at;
231 at = ldap_str2attributetype(line,&code,&err);
233 fprintf( stderr, "%s: line %d: %s before %s\n",
234 fname, lineno, ldap_scherr2str(code), err );
237 code = at_add(at,&err);
239 fprintf( stderr, "%s: line %d: %s %s\n",
240 fname, lineno, scherr2str(code), err);