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);
22 static void at_usage(void);
24 static char *const err2text[] = {
27 "ObjectClass not found",
28 "ObjectClass inappropriate SUPerior",
29 "AttributeType not found",
30 "AttributeType inappropriate USAGE",
31 "Duplicate objectClass",
32 "Duplicate attributeType",
33 "Duplicate ldapSyntax",
34 "Duplicate matchingRule",
35 "OID or name required",
36 "SYNTAX or SUPerior required",
37 "MatchingRule not found",
40 "Qualifier not supported",
47 if ( code < 0 || code >= (sizeof(err2text)/sizeof(char *)) ) {
48 return "Unknown error";
50 return err2text[code];
54 /* check schema descr validity */
55 int slap_valid_descr( const char *descr )
59 if( !DESC_LEADCHAR( descr[i] ) ) {
64 if( !DESC_CHAR( descr[i] ) ) {
75 /* String compare with delimiter check. Return 0 if not
76 * matched, otherwise return length matched.
79 dscompare(const char *s1, const char *s2, char delim)
81 const char *orig = s1;
82 while (*s1++ == *s2++)
86 if (!*s1 && (!*s2 || *s2 == delim))
91 static OidMacro *om_list = NULL;
93 /* Replace an OID Macro invocation with its full numeric OID.
94 * If the macro is used with "macroname:suffix" append ".suffix"
102 /* OID macros must start alpha */
103 if ( OID_LEADCHAR( *oid ) ) {
107 for (om = om_list; om; om=om->som_next) {
108 char **names = om->som_names;
110 if( names == NULL ) {
114 for( ; *names != NULL ; names++ ) {
115 int pos = dscompare(*names, oid, ':');
118 int suflen = strlen(oid + pos);
119 char *new = ch_calloc(1,
120 om->som_oid.bv_len + suflen + 1);
121 strcpy(new, om->som_oid.bv_val);
124 suflen = om->som_oid.bv_len;
126 strcpy(new+suflen, oid+pos+1);
147 fprintf( stderr, "%s: line %d: too many arguments\n",
149 usage: fprintf( stderr, "\tObjectIdentifier <name> <oid>\n");
153 oid = find_oidm( argv[1] );
157 "ObjectIdentifier \"%s\" previously defined \"%s\"",
158 fname, lineno, argv[1], oid );
162 om = (OidMacro *) ch_malloc( sizeof(OidMacro) );
164 om->som_names = NULL;
165 charray_add( &om->som_names, argv[1] );
166 om->som_oid.bv_val = find_oidm( argv[2] );
168 if (!om->som_oid.bv_val) {
169 fprintf( stderr, "%s: line %d: OID %s not recognized\n",
170 fname, lineno, argv[2] );
174 if (om->som_oid.bv_val == argv[2]) {
175 om->som_oid.bv_val = ch_strdup( argv[2] );
178 om->som_oid.bv_len = strlen( om->som_oid.bv_val );
179 om->som_next = om_list;
198 oc = ldap_str2objectclass(line,&code,&err,LDAP_SCHEMA_ALLOW_ALL);
200 fprintf( stderr, "%s: line %d: %s before %s\n",
201 fname, lineno, ldap_scherr2str(code), err );
206 if ( oc->oc_oid == NULL ) {
208 "%s: line %d: objectclass has no OID\n",
214 if ( !OID_LEADCHAR( oc->oc_oid[0] )) {
215 /* Expand OID macros */
216 oid = find_oidm( oc->oc_oid );
219 "%s: line %d: OID %s not recognized\n",
220 fname, lineno, oc->oc_oid);
223 if ( oid != oc->oc_oid ) {
224 ldap_memfree( oc->oc_oid );
229 code = oc_add(oc,&err);
231 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
232 fname, lineno, scherr2str(code), err);
244 "ObjectClassDescription = \"(\" whsp\n"
245 " numericoid whsp ; ObjectClass identifier\n"
246 " [ \"NAME\" qdescrs ]\n"
247 " [ \"DESC\" qdstring ]\n"
248 " [ \"OBSOLETE\" whsp ]\n"
249 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
250 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
251 " ; default structural\n"
252 " [ \"MUST\" oids ] ; AttributeTypes\n"
253 " [ \"MAY\" oids ] ; AttributeTypes\n"
262 "AttributeTypeDescription = \"(\" whsp\n"
263 " numericoid whsp ; AttributeType identifier\n"
264 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
265 " [ \"DESC\" qdstring ] ; description\n"
266 " [ \"OBSOLETE\" whsp ]\n"
267 " [ \"SUP\" woid ] ; derived from this other\n"
269 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
270 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
271 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
272 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
273 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
274 " [ \"COLLECTIVE\" whsp ] ; default not collective\n"
275 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
276 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
277 " ; userApplications\n"
278 " ; directoryOperation\n"
279 " ; distributedOperation\n"
292 LDAPAttributeType *at;
297 at = ldap_str2attributetype(line,&code,&err,LDAP_SCHEMA_ALLOW_ALL);
299 fprintf( stderr, "%s: line %d: %s before %s\n",
300 fname, lineno, ldap_scherr2str(code), err );
305 if ( at->at_oid == NULL ) {
307 "%s: line %d: attributeType has no OID\n",
313 if ( !OID_LEADCHAR( at->at_oid[0] )) {
314 /* Expand OID macros */
315 oid = find_oidm( at->at_oid );
318 "%s: line %d: OID %s not recognized\n",
319 fname, lineno, at->at_oid);
322 if ( oid != at->at_oid ) {
323 ldap_memfree( at->at_oid );
328 if ( at->at_syntax_oid && !OID_LEADCHAR( at->at_syntax_oid[0] )) {
329 /* Expand OID macros */
330 oid = find_oidm( at->at_syntax_oid );
333 "%s: line %d: OID %s not recognized\n",
334 fname, lineno, at->at_syntax_oid);
337 if ( oid != at->at_syntax_oid ) {
338 ldap_memfree( at->at_syntax_oid );
339 at->at_syntax_oid = oid;
343 code = at_add(at,&err);
345 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
346 fname, lineno, scherr2str(code), err);