1 /* schemaparse.c - routines to parse config file objectclass definitions */
11 #include "ldap_schema.h"
13 ObjectClass *global_oc;
14 static Avlnode *object_classes = NULL;
16 AttributeType *global_at;
17 int global_schemacheck = 1; /* schemacheck on is default */
19 static void oc_usage_old(void);
20 static void oc_usage(void);
22 static char *err2text[] = {
25 "Objectclass not found",
26 "Attribute type not found",
27 "Duplicate objectclass",
28 "Duplicate attributetype"
34 if ( code < 1 || code >= (sizeof(err2text)/sizeof(char *)) ) {
35 return "Unknown error";
37 return err2text[code];
52 LDAP_OBJECT_CLASS *oc;
57 oc = (LDAP_OBJECT_CLASS *) ch_calloc( 1, sizeof(LDAP_OBJECT_CLASS) );
58 oc->oc_names = ch_calloc( 2, sizeof(char *) );
59 oc->oc_names[0] = ch_strdup( argv[1] );
60 oc->oc_names[1] = NULL;
61 for ( i = 2; i < argc; i++ ) {
62 /* required attributes */
63 if ( strcasecmp( argv[i], "requires" ) == 0 ) {
67 char **s = str2charray( argv[i], "," );
68 last = argv[i][strlen( argv[i] ) - 1];
69 charray_merge( &oc->oc_at_oids_must, s );
72 } while ( i < argc && last == ',' );
74 /* optional attributes */
75 } else if ( strcasecmp( argv[i], "allows" ) == 0 ) {
79 char **s = str2charray( argv[i], "," );
80 last = argv[i][strlen( argv[i] ) - 1];
82 charray_merge( &oc->oc_at_oids_may, s );
85 } while ( i < argc && last == ',' );
89 "%s: line %d: expecting \"requires\" or \"allows\" got \"%s\"\n",
90 fname, lineno, argv[i] );
96 * There was no requirement in the old schema that all attributes
97 * types were defined before use and they would just default to
98 * SYNTAX_CIS. To support this, we need to make attribute types
101 if ( oc->oc_at_oids_must ) {
102 namep = oc->oc_at_oids_must;
104 code = at_fake_if_needed( *namep );
106 fprintf( stderr, "%s: line %d: %s %s\n",
107 fname, lineno, scherr2str(code), *namep);
113 if ( oc->oc_at_oids_may ) {
114 namep = oc->oc_at_oids_may;
116 code = at_fake_if_needed( *namep );
118 fprintf( stderr, "%s: line %d: %s %s\n",
119 fname, lineno, scherr2str(code), *namep);
126 code = oc_add(oc,&err);
128 fprintf( stderr, "%s: line %d: %s %s\n",
129 fname, lineno, scherr2str(code), err);
142 LDAP_OBJECT_CLASS *oc;
146 oc = ldap_str2objectclass(line,&code,&err);
148 fprintf( stderr, "%s: line %d: %s before %s\n",
149 fname, lineno, ldap_scherr2str(code), err );
152 code = oc_add(oc,&err);
154 fprintf( stderr, "%s: line %d: %s %s\n",
155 fname, lineno, scherr2str(code), err);
164 fprintf( stderr, "ObjectClassDescription = \"(\" whsp\n");
165 fprintf( stderr, " numericoid whsp ; ObjectClass identifier\n");
166 fprintf( stderr, " [ \"NAME\" qdescrs ]\n");
167 fprintf( stderr, " [ \"DESC\" qdstring ]\n");
168 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
169 fprintf( stderr, " [ \"SUP\" oids ] ; Superior ObjectClasses\n");
170 fprintf( stderr, " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n");
171 fprintf( stderr, " ; default structural\n");
172 fprintf( stderr, " [ \"MUST\" oids ] ; AttributeTypes\n");
173 fprintf( stderr, " [ \"MAY\" oids ] ; AttributeTypes\n");
174 fprintf( stderr, "whsp \")\"\n");
181 fprintf( stderr, "<oc clause> ::= objectclass <ocname>\n" );
182 fprintf( stderr, " [ requires <attrlist> ]\n" );
183 fprintf( stderr, " [ allows <attrlist> ]\n" );
190 fprintf( stderr, "AttributeTypeDescription = \"(\" whsp\n");
191 fprintf( stderr, " numericoid whsp ; AttributeType identifier\n");
192 fprintf( stderr, " [ \"NAME\" qdescrs ] ; name used in AttributeType\n");
193 fprintf( stderr, " [ \"DESC\" qdstring ] ; description\n");
194 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
195 fprintf( stderr, " [ \"SUP\" woid ] ; derived from this other\n");
196 fprintf( stderr, " ; AttributeType\n");
197 fprintf( stderr, " [ \"EQUALITY\" woid ] ; Matching Rule name\n");
198 fprintf( stderr, " [ \"ORDERING\" woid ] ; Matching Rule name\n");
199 fprintf( stderr, " [ \"SUBSTR\" woid ] ; Matching Rule name\n");
200 fprintf( stderr, " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n");
201 fprintf( stderr, " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n");
202 fprintf( stderr, " [ \"COLLECTIVE\" whsp ] ; default not collective\n");
203 fprintf( stderr, " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n");
204 fprintf( stderr, " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n");
205 fprintf( stderr, " ; userApplications\n");
206 fprintf( stderr, " ; directoryOperation\n");
207 fprintf( stderr, " ; distributedOperation\n");
208 fprintf( stderr, " ; dSAOperation\n");
209 fprintf( stderr, "whsp \")\"\n");
220 LDAP_ATTRIBUTE_TYPE *at;
224 at = ldap_str2attributetype(line,&code,&err);
226 fprintf( stderr, "%s: line %d: %s before %s\n",
227 fname, lineno, ldap_scherr2str(code), err );
230 code = at_add(at,&err);
232 fprintf( stderr, "%s: line %d: %s %s\n",
233 fname, lineno, scherr2str(code), err);