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 for ( i = 2; i < argc; i++ ) {
60 /* required attributes */
61 if ( strcasecmp( argv[i], "requires" ) == 0 ) {
65 char **s = str2charray( argv[i], "," );
66 last = argv[i][strlen( argv[i] ) - 1];
67 charray_merge( &oc->oc_at_oids_must, s );
70 } while ( i < argc && last == ',' );
72 /* optional attributes */
73 } else if ( strcasecmp( argv[i], "allows" ) == 0 ) {
77 char **s = str2charray( argv[i], "," );
78 last = argv[i][strlen( argv[i] ) - 1];
80 charray_merge( &oc->oc_at_oids_may, s );
83 } while ( i < argc && last == ',' );
87 "%s: line %d: expecting \"requires\" or \"allows\" got \"%s\"\n",
88 fname, lineno, argv[i] );
94 * There was no requirement in the old schema that all attributes
95 * types were defined before use and they would just default to
96 * SYNTAX_CIS. To support this, we need to make attribute types
99 if ( oc->oc_at_oids_must ) {
100 namep = oc->oc_at_oids_must;
102 code = at_fake_if_needed( *namep );
104 fprintf( stderr, "%s: line %d: %s %s\n",
105 fname, lineno, scherr2str(code), *namep);
111 if ( oc->oc_at_oids_may ) {
112 namep = oc->oc_at_oids_may;
114 code = at_fake_if_needed( *namep );
116 fprintf( stderr, "%s: line %d: %s %s\n",
117 fname, lineno, scherr2str(code), *namep);
124 code = oc_add(oc,&err);
126 fprintf( stderr, "%s: line %d: %s %s\n",
127 fname, lineno, scherr2str(code), err);
140 LDAP_OBJECT_CLASS *oc;
144 oc = ldap_str2objectclass(line,&code,&err);
146 fprintf( stderr, "%s: line %d: %s before %s\n",
147 fname, lineno, ldap_scherr2str(code), err );
150 code = oc_add(oc,&err);
152 fprintf( stderr, "%s: line %d: %s %s\n",
153 fname, lineno, scherr2str(code), err);
162 fprintf( stderr, "ObjectClassDescription = \"(\" whsp\n");
163 fprintf( stderr, " numericoid whsp ; ObjectClass identifier\n");
164 fprintf( stderr, " [ \"NAME\" qdescrs ]\n");
165 fprintf( stderr, " [ \"DESC\" qdstring ]\n");
166 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
167 fprintf( stderr, " [ \"SUP\" oids ] ; Superior ObjectClasses\n");
168 fprintf( stderr, " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n");
169 fprintf( stderr, " ; default structural\n");
170 fprintf( stderr, " [ \"MUST\" oids ] ; AttributeTypes\n");
171 fprintf( stderr, " [ \"MAY\" oids ] ; AttributeTypes\n");
172 fprintf( stderr, "whsp \")\"\n");
179 fprintf( stderr, "<oc clause> ::= objectclass <ocname>\n" );
180 fprintf( stderr, " [ requires <attrlist> ]\n" );
181 fprintf( stderr, " [ allows <attrlist> ]\n" );
188 fprintf( stderr, "AttributeTypeDescription = \"(\" whsp\n");
189 fprintf( stderr, " numericoid whsp ; AttributeType identifier\n");
190 fprintf( stderr, " [ \"NAME\" qdescrs ] ; name used in AttributeType\n");
191 fprintf( stderr, " [ \"DESC\" qdstring ] ; description\n");
192 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
193 fprintf( stderr, " [ \"SUP\" woid ] ; derived from this other\n");
194 fprintf( stderr, " ; AttributeType\n");
195 fprintf( stderr, " [ \"EQUALITY\" woid ] ; Matching Rule name\n");
196 fprintf( stderr, " [ \"ORDERING\" woid ] ; Matching Rule name\n");
197 fprintf( stderr, " [ \"SUBSTR\" woid ] ; Matching Rule name\n");
198 fprintf( stderr, " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n");
199 fprintf( stderr, " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n");
200 fprintf( stderr, " [ \"COLLECTIVE\" whsp ] ; default not collective\n");
201 fprintf( stderr, " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n");
202 fprintf( stderr, " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n");
203 fprintf( stderr, " ; userApplications\n");
204 fprintf( stderr, " ; directoryOperation\n");
205 fprintf( stderr, " ; distributedOperation\n");
206 fprintf( stderr, " ; dSAOperation\n");
207 fprintf( stderr, "whsp \")\"\n");
218 LDAP_ATTRIBUTE_TYPE *at;
222 at = ldap_str2attributetype(line,&code,&err);
224 fprintf( stderr, "%s: line %d: %s before %s\n",
225 fname, lineno, ldap_scherr2str(code), err );
228 code = at_add(at,&err);
230 fprintf( stderr, "%s: line %d: %s %s\n",
231 fname, lineno, scherr2str(code), err);