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-2006 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 "OID or name required",
53 "Qualifier not supported",
55 "OID could not be expanded",
56 "Duplicate Content Rule",
57 "Content Rule not for STRUCTURAL object class",
58 "Content Rule AUX contains inappropriate object class",
59 "Content Rule attribute type list contains duplicate",
66 if ( code < 0 || SLAP_SCHERR_LAST <= code ) {
67 return "Unknown error";
69 return err2text[code];
73 /* check schema descr validity */
74 int slap_valid_descr( const char *descr )
78 if( !DESC_LEADCHAR( descr[i] ) ) {
83 if( !DESC_CHAR( descr[i] ) ) {
94 /* String compare with delimiter check. Return 0 if not
95 * matched, otherwise return length matched.
98 dscompare(const char *s1, const char *s2, char delim)
100 const char *orig = s1;
101 while (*s1++ == *s2++)
105 if (!*s1 && (!*s2 || *s2 == delim))
114 "DITContentRuleDescription = \"(\" whsp\n"
115 " numericoid whsp ; StructuralObjectClass identifier\n"
116 " [ \"NAME\" qdescrs ]\n"
117 " [ \"DESC\" qdstring ]\n"
118 " [ \"OBSOLETE\" whsp ]\n"
119 " [ \"AUX\" oids ] ; Auxiliary ObjectClasses\n"
120 " [ \"MUST\" oids ] ; AttributeTypes\n"
121 " [ \"MAY\" oids ] ; AttributeTypes\n"
122 " [ \"NOT\" oids ] ; AttributeTypes\n"
128 struct config_args_s *c,
134 char *line = strchr( c->line, '(' );
136 cr = ldap_str2contentrule( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
138 snprintf( c->msg, sizeof( c->msg ), "%s: %s before %s",
139 c->argv[0], ldap_scherr2str( code ), err );
140 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
141 "%s %s\n", c->log, c->msg, 0 );
146 if ( cr->cr_oid == NULL ) {
147 snprintf( c->msg, sizeof( c->msg ), "%s: OID is missing",
149 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
150 "%s %s\n", c->log, c->msg, 0 );
156 code = cr_add( cr, 1, scr, &err );
158 snprintf( c->msg, sizeof( c->msg ), "%s: %s: \"%s\"",
159 c->argv[0], scherr2str(code), err);
160 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
161 "%s %s\n", c->log, c->msg, 0 );
168 ldap_contentrule_free( cr );
179 struct config_args_s *c,
186 char *line = strchr( c->line, '(' );
188 oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
190 snprintf( c->msg, sizeof( c->msg ), "%s: %s before %s",
191 c->argv[0], ldap_scherr2str( code ), err );
192 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
193 "%s %s\n", c->log, c->msg, 0 );
198 if ( oc->oc_oid == NULL ) {
199 snprintf( c->msg, sizeof( c->msg ), "%s: OID is missing",
201 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
202 "%s %s\n", c->log, c->msg, 0 );
208 code = oc_add( oc, 1, soc, prev, &err );
210 snprintf( c->msg, sizeof( c->msg ), "%s: %s: \"%s\"",
211 c->argv[0], scherr2str(code), err);
212 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
213 "%s %s\n", c->log, c->msg, 0 );
220 ldap_objectclass_free( oc );
233 "ObjectClassDescription = \"(\" whsp\n"
234 " numericoid whsp ; ObjectClass identifier\n"
235 " [ \"NAME\" qdescrs ]\n"
236 " [ \"DESC\" qdstring ]\n"
237 " [ \"OBSOLETE\" whsp ]\n"
238 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
239 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
240 " ; default structural\n"
241 " [ \"MUST\" oids ] ; AttributeTypes\n"
242 " [ \"MAY\" oids ] ; AttributeTypes\n"
249 fprintf( stderr, "%s%s%s",
250 "AttributeTypeDescription = \"(\" whsp\n"
251 " numericoid whsp ; AttributeType identifier\n"
252 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
253 " [ \"DESC\" qdstring ] ; description\n"
254 " [ \"OBSOLETE\" whsp ]\n"
255 " [ \"SUP\" woid ] ; derived from this other\n"
256 " ; AttributeType\n",
257 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
258 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
259 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
260 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
261 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
262 " [ \"COLLECTIVE\" whsp ] ; default not collective\n",
263 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
264 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
265 " ; userApplications\n"
266 " ; directoryOperation\n"
267 " ; distributedOperation\n"
274 struct config_args_s *c,
276 AttributeType *prev )
278 LDAPAttributeType *at;
281 char *line = strchr( c->line, '(' );
283 at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
285 snprintf( c->msg, sizeof( c->msg ), "%s: %s before %s",
286 c->argv[0], ldap_scherr2str(code), err );
287 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
288 "%s %s\n", c->log, c->msg, 0 );
293 if ( at->at_oid == NULL ) {
294 snprintf( c->msg, sizeof( c->msg ), "%s: OID is missing",
296 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
297 "%s %s\n", c->log, c->msg, 0 );
303 /* operational attributes should be defined internally */
304 if ( at->at_usage ) {
305 snprintf( c->msg, sizeof( c->msg ), "%s: \"%s\" is operational",
306 c->argv[0], at->at_oid );
307 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
308 "%s %s\n", c->log, c->msg, 0 );
313 code = at_add( at, 1, sat, prev, &err);
315 snprintf( c->msg, sizeof( c->msg ), "%s: %s: \"%s\"",
316 c->argv[0], scherr2str(code), err);
317 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
318 "%s %s\n", c->log, c->msg, 0 );
325 ldap_attributetype_free( at );