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"
32 if ( code < 1 || code >= (sizeof(err2text)/sizeof(char *)) ) {
33 return "Unknown error";
35 return err2text[code];
50 LDAP_OBJECT_CLASS *oc;
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;
62 for ( i = 2; i < argc; i++ ) {
63 /* required attributes */
64 if ( strcasecmp( argv[i], "requires" ) == 0 ) {
68 char **s = str2charray( argv[i], "," );
69 last = argv[i][strlen( argv[i] ) - 1];
70 charray_merge( &oc->oc_at_oids_must, s );
73 } while ( i < argc && last == ',' );
75 /* optional attributes */
76 } else if ( strcasecmp( argv[i], "allows" ) == 0 ) {
80 char **s = str2charray( argv[i], "," );
81 last = argv[i][strlen( argv[i] ) - 1];
83 charray_merge( &oc->oc_at_oids_may, s );
86 } while ( i < argc && last == ',' );
90 "%s: line %d: expecting \"requires\" or \"allows\" got \"%s\"\n",
91 fname, lineno, argv[i] );
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
102 if ( oc->oc_at_oids_must ) {
103 namep = oc->oc_at_oids_must;
105 code = at_fake_if_needed( *namep );
107 fprintf( stderr, "%s: line %d: %s %s\n",
108 fname, lineno, scherr2str(code), *namep);
114 if ( oc->oc_at_oids_may ) {
115 namep = oc->oc_at_oids_may;
117 code = at_fake_if_needed( *namep );
119 fprintf( stderr, "%s: line %d: %s %s\n",
120 fname, lineno, scherr2str(code), *namep);
127 code = oc_add(oc,&err);
129 fprintf( stderr, "%s: line %d: %s %s\n",
130 fname, lineno, scherr2str(code), err);
143 LDAP_OBJECT_CLASS *oc;
147 oc = ldap_str2objectclass(line,&code,&err);
149 fprintf( stderr, "%s: line %d: %s before %s\n",
150 fname, lineno, ldap_scherr2str(code), err );
153 code = oc_add(oc,&err);
155 fprintf( stderr, "%s: line %d: %s %s\n",
156 fname, lineno, scherr2str(code), err);
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");
182 fprintf( stderr, "<oc clause> ::= objectclass <ocname>\n" );
183 fprintf( stderr, " [ requires <attrlist> ]\n" );
184 fprintf( stderr, " [ allows <attrlist> ]\n" );
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");
221 LDAP_ATTRIBUTE_TYPE *at;
225 at = ldap_str2attributetype(line,&code,&err);
227 fprintf( stderr, "%s: line %d: %s before %s\n",
228 fname, lineno, ldap_scherr2str(code), err );
231 code = at_add(at,&err);
233 fprintf( stderr, "%s: line %d: %s %s\n",
234 fname, lineno, scherr2str(code), err);