1 /* schemaparse.c - routines to parse config file objectclass definitions */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
17 #include "ldap_schema.h"
19 int global_schemacheck = 1; /* schemacheck on is default */
21 static void oc_usage(void) LDAP_GCCATTR((noreturn));
22 static void at_usage(void) LDAP_GCCATTR((noreturn));
24 static char *const err2text[] = {
27 "ObjectClass not found",
28 "AttributeType not found",
29 "Duplicate objectClass",
30 "Duplicate attributeType",
31 "Duplicate ldapSyntax",
32 "Duplicate matchingRule",
33 "OID or name required",
34 "SYNTAX or SUPerior required",
35 "MatchingRule not found",
43 if ( code < 1 || code >= (sizeof(err2text)/sizeof(char *)) ) {
46 return err2text[code];
53 /* String compare with delimiter check. Return 0 if not
54 * matched, otherwise return length matched.
57 dscompare(const char *s1, const char *s2, char delim)
59 const char *orig = s1;
60 while (*s1++ == *s2++)
64 if (!*s1 && (!*s2 || *s2 == delim))
69 static OidMacro *om_list = NULL;
71 /* Replace an OID Macro invocation with its full numeric OID.
72 * If the macro is used with "macroname:suffix" append ".suffix"
80 /* OID macros must start alpha */
81 if ( isdigit( *oid ) ) {
85 for (om = om_list; om; om=om->som_next) {
86 char **names = om->som_names;
92 for( ; *names != NULL ; names++ ) {
93 int pos = dscompare(*names, oid, ':');
96 int suflen = strlen(oid + pos);
97 char *new = ch_calloc(1,
98 om->som_oid.bv_len + suflen + 1);
99 strcpy(new, om->som_oid.bv_val);
102 suflen = om->som_oid.bv_len;
104 strcpy(new+suflen, oid+pos+1);
125 fprintf( stderr, "%s: line %d: too many arguments\n",
127 usage: fprintf( stderr, "\tObjectIdentifier <name> <oid>\n");
128 exit( EXIT_FAILURE );
131 oid = find_oidm( argv[1] );
135 "ObjectIdentifier \"%s\" previously defined \"%s\"",
136 fname, lineno, argv[1], oid );
137 exit( EXIT_FAILURE );
140 om = (OidMacro *) ch_malloc( sizeof(OidMacro) );
142 om->som_names = NULL;
143 charray_add( &om->som_names, argv[1] );
144 om->som_oid.bv_val = find_oidm( argv[2] );
146 if (!om->som_oid.bv_val) {
147 fprintf( stderr, "%s: line %d: OID %s not recognized\n",
148 fname, lineno, argv[2] );
152 if (om->som_oid.bv_val == argv[2]) {
153 om->som_oid.bv_val = ch_strdup( argv[2] );
156 om->som_oid.bv_len = strlen( om->som_oid.bv_val );
157 om->som_next = om_list;
169 LDAP_OBJECT_CLASS *oc;
174 oc = ldap_str2objectclass(line,&code,&err,LDAP_SCHEMA_ALLOW_ALL);
176 fprintf( stderr, "%s: line %d: %s before %s\n",
177 fname, lineno, ldap_scherr2str(code), err );
181 if ( !isdigit( oc->oc_oid[0] )) {
182 /* Expand OID macros */
183 oid = find_oidm( oc->oc_oid );
186 "%s: line %d: OID %s not recognized\n",
187 fname, lineno, oc->oc_oid);
188 exit( EXIT_FAILURE );
190 if ( oid != oc->oc_oid ) {
191 ldap_memfree( oc->oc_oid );
196 /* oc->oc_oid == NULL will be an error someday */
197 code = oc_add(oc,&err);
199 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
200 fname, lineno, scherr2str(code), err);
201 exit( EXIT_FAILURE );
209 fprintf( stderr, "ObjectClassDescription = \"(\" whsp\n");
210 fprintf( stderr, " numericoid whsp ; ObjectClass identifier\n");
211 fprintf( stderr, " [ \"NAME\" qdescrs ]\n");
212 fprintf( stderr, " [ \"DESC\" qdstring ]\n");
213 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
214 fprintf( stderr, " [ \"SUP\" oids ] ; Superior ObjectClasses\n");
215 fprintf( stderr, " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n");
216 fprintf( stderr, " ; default structural\n");
217 fprintf( stderr, " [ \"MUST\" oids ] ; AttributeTypes\n");
218 fprintf( stderr, " [ \"MAY\" oids ] ; AttributeTypes\n");
219 fprintf( stderr, "whsp \")\"\n");
220 exit( EXIT_FAILURE );
227 fprintf( stderr, "AttributeTypeDescription = \"(\" whsp\n");
228 fprintf( stderr, " numericoid whsp ; AttributeType identifier\n");
229 fprintf( stderr, " [ \"NAME\" qdescrs ] ; name used in AttributeType\n");
230 fprintf( stderr, " [ \"DESC\" qdstring ] ; description\n");
231 fprintf( stderr, " [ \"OBSOLETE\" whsp ]\n");
232 fprintf( stderr, " [ \"SUP\" woid ] ; derived from this other\n");
233 fprintf( stderr, " ; AttributeType\n");
234 fprintf( stderr, " [ \"EQUALITY\" woid ] ; Matching Rule name\n");
235 fprintf( stderr, " [ \"ORDERING\" woid ] ; Matching Rule name\n");
236 fprintf( stderr, " [ \"SUBSTR\" woid ] ; Matching Rule name\n");
237 fprintf( stderr, " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n");
238 fprintf( stderr, " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n");
239 fprintf( stderr, " [ \"COLLECTIVE\" whsp ] ; default not collective\n");
240 fprintf( stderr, " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n");
241 fprintf( stderr, " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n");
242 fprintf( stderr, " ; userApplications\n");
243 fprintf( stderr, " ; directoryOperation\n");
244 fprintf( stderr, " ; distributedOperation\n");
245 fprintf( stderr, " ; dSAOperation\n");
246 fprintf( stderr, "whsp \")\"\n");
247 exit( EXIT_FAILURE );
258 LDAP_ATTRIBUTE_TYPE *at;
264 /* Kludge for OIDmacros for syntaxes. If the syntax field starts
265 * nonnumeric, look for and expand a macro. The macro's place in
266 * the input line will be replaced with a field of '0's to keep
267 * ldap_str2attributetype happy. The actual oid will be swapped
268 * into place afterwards.
270 for (; argv[3]; argv++)
272 if (!strcasecmp(argv[3], "syntax") &&
277 syn = syn_find_desc(argv[4], &slen);
280 fprintf(stderr, "%s: line %d: OID %s not found\n",
281 fname, lineno, argv[4]);
282 exit( EXIT_FAILURE );
284 memset(strstr(line, argv[4]), '0', slen);
285 soid = ch_strdup(syn->ssyn_syn.syn_oid );
289 at = ldap_str2attributetype(line,&code,&err,LDAP_SCHEMA_ALLOW_ALL);
291 fprintf( stderr, "%s: line %d: %s before %s\n",
292 fname, lineno, ldap_scherr2str(code), err );
296 if ( !isdigit( at->at_oid[0] )) {
297 /* Expand OID macros */
298 oid = find_oidm( at->at_oid );
301 "%s: line %d: OID %s not recognized\n",
302 fname, lineno, at->at_oid);
303 exit( EXIT_FAILURE );
305 if ( oid != at->at_oid ) {
306 ldap_memfree( at->at_oid );
311 /* at->at_oid == NULL will be an error someday */
314 ldap_memfree(at->at_syntax_oid);
315 at->at_syntax_oid = soid;
317 code = at_add(at,&err);
319 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
320 fname, lineno, scherr2str(code), err);
321 exit( EXIT_FAILURE );