1 /* schemaparse.c - routines to parse config file objectclass definitions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2010 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
22 #include <ac/string.h>
23 #include <ac/socket.h>
26 #include "ldap_schema.h"
29 static void oc_usage(void);
30 static void at_usage(void);
32 static char *const err2text[] = {
35 "ObjectClass not found",
36 "user-defined ObjectClass includes operational attributes",
37 "user-defined ObjectClass has inappropriate SUPerior",
38 "Duplicate objectClass",
39 "Inconsistent duplicate objectClass",
40 "AttributeType not found",
41 "AttributeType inappropriate matching rule",
42 "AttributeType inappropriate USAGE",
43 "AttributeType inappropriate SUPerior",
44 "AttributeType SYNTAX or SUPerior required",
45 "Duplicate attributeType",
46 "Inconsistent duplicate attributeType",
47 "MatchingRule not found",
48 "MatchingRule incomplete",
49 "Duplicate matchingRule",
51 "Duplicate ldapSyntax",
52 "Superior syntax not found",
53 "Substitute syntax not specified",
54 "Substitute syntax not found",
55 "OID or name required",
56 "Qualifier not supported",
58 "OID could not be expanded",
59 "Duplicate Content Rule",
60 "Content Rule not for STRUCTURAL object class",
61 "Content Rule AUX contains inappropriate object class",
62 "Content Rule attribute type list contains duplicate",
69 if ( code < 0 || SLAP_SCHERR_LAST <= code ) {
70 return "Unknown error";
72 return err2text[code];
76 /* check schema descr validity */
77 int slap_valid_descr( const char *descr )
81 if( !DESC_LEADCHAR( descr[i] ) ) {
86 if( !DESC_CHAR( descr[i] ) ) {
97 /* String compare with delimiter check. Return 0 if not
98 * matched, otherwise return length matched.
101 dscompare(const char *s1, const char *s2, char delim)
103 const char *orig = s1;
104 while (*s1++ == *s2++)
108 if (!*s1 && (!*s2 || *s2 == delim))
117 "DITContentRuleDescription = \"(\" whsp\n"
118 " numericoid whsp ; StructuralObjectClass identifier\n"
119 " [ \"NAME\" qdescrs ]\n"
120 " [ \"DESC\" qdstring ]\n"
121 " [ \"OBSOLETE\" whsp ]\n"
122 " [ \"AUX\" oids ] ; Auxiliary ObjectClasses\n"
123 " [ \"MUST\" oids ] ; AttributeTypes\n"
124 " [ \"MAY\" oids ] ; AttributeTypes\n"
125 " [ \"NOT\" oids ] ; AttributeTypes\n"
131 struct config_args_s *c,
137 char *line = strchr( c->line, '(' );
139 cr = ldap_str2contentrule( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
141 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s before %s",
142 c->argv[0], ldap_scherr2str( code ), err );
143 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
144 "%s %s\n", c->log, c->cr_msg, 0 );
149 if ( cr->cr_oid == NULL ) {
150 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: OID is missing",
152 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
153 "%s %s\n", c->log, c->cr_msg, 0 );
159 code = cr_add( cr, 1, scr, &err );
161 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s: \"%s\"",
162 c->argv[0], scherr2str(code), err);
163 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
164 "%s %s\n", c->log, c->cr_msg, 0 );
171 ldap_contentrule_free( cr );
182 struct config_args_s *c,
189 char *line = strchr( c->line, '(' );
191 oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
193 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s before %s",
194 c->argv[0], ldap_scherr2str( code ), err );
195 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
196 "%s %s\n", c->log, c->cr_msg, 0 );
201 if ( oc->oc_oid == NULL ) {
202 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: OID is missing",
204 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
205 "%s %s\n", c->log, c->cr_msg, 0 );
211 code = oc_add( oc, 1, soc, prev, &err );
213 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s: \"%s\"",
214 c->argv[0], scherr2str(code), err);
215 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
216 "%s %s\n", c->log, c->cr_msg, 0 );
223 ldap_objectclass_free( oc );
236 "ObjectClassDescription = \"(\" whsp\n"
237 " numericoid whsp ; ObjectClass identifier\n"
238 " [ \"NAME\" qdescrs ]\n"
239 " [ \"DESC\" qdstring ]\n"
240 " [ \"OBSOLETE\" whsp ]\n"
241 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
242 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
243 " ; default structural\n"
244 " [ \"MUST\" oids ] ; AttributeTypes\n"
245 " [ \"MAY\" oids ] ; AttributeTypes\n"
252 fprintf( stderr, "%s%s%s",
253 "AttributeTypeDescription = \"(\" whsp\n"
254 " numericoid whsp ; AttributeType identifier\n"
255 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
256 " [ \"DESC\" qdstring ] ; description\n"
257 " [ \"OBSOLETE\" whsp ]\n"
258 " [ \"SUP\" woid ] ; derived from this other\n"
259 " ; AttributeType\n",
260 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
261 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
262 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
263 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
264 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
265 " [ \"COLLECTIVE\" whsp ] ; default not collective\n",
266 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
267 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
268 " ; userApplications\n"
269 " ; directoryOperation\n"
270 " ; distributedOperation\n"
277 struct config_args_s *c,
279 AttributeType *prev )
281 LDAPAttributeType *at;
284 char *line = strchr( c->line, '(' );
286 at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
288 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s before %s",
289 c->argv[0], ldap_scherr2str(code), err );
290 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
291 "%s %s\n", c->log, c->cr_msg, 0 );
296 if ( at->at_oid == NULL ) {
297 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: OID is missing",
299 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
300 "%s %s\n", c->log, c->cr_msg, 0 );
306 /* operational attributes should be defined internally */
307 if ( at->at_usage ) {
308 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: \"%s\" is operational",
309 c->argv[0], at->at_oid );
310 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
311 "%s %s\n", c->log, c->cr_msg, 0 );
316 code = at_add( at, 1, sat, prev, &err);
318 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s: \"%s\"",
319 c->argv[0], scherr2str(code), err);
320 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
321 "%s %s\n", c->log, c->cr_msg, 0 );
328 ldap_attributetype_free( at );
340 fprintf( stderr, "%s",
341 "SyntaxDescription = \"(\" whsp\n"
342 " numericoid whsp ; object identifier\n"
343 " [ whsp \"DESC\" whsp qdstring ] ; description\n"
344 " extensions whsp \")\" ; extensions\n"
350 struct config_args_s *c,
355 slap_syntax_defs_rec def = { 0 };
358 char *line = strchr( c->line, '(' );
360 syn = ldap_str2syntax( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
362 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s before %s",
363 c->argv[0], ldap_scherr2str(code), err );
364 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
365 "%s %s\n", c->log, c->cr_msg, 0 );
370 if ( syn->syn_oid == NULL ) {
371 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: OID is missing",
373 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
374 "%s %s\n", c->log, c->cr_msg, 0 );
380 code = syn_add( syn, 1, &def, ssyn, prev, &err );
382 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s: \"%s\"",
383 c->argv[0], scherr2str(code), err);
384 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
385 "%s %s\n", c->log, c->cr_msg, 0 );
392 ldap_syntax_free( syn );