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"
28 static void oc_usage(void);
29 static void at_usage(void);
31 static char *const err2text[] = {
34 "ObjectClass not found",
35 "user-defined ObjectClass includes operational attributes",
36 "user-defined ObjectClass has inappropriate SUPerior",
37 "Duplicate objectClass",
38 "Inconsistent duplicate objectClass",
39 "AttributeType not found",
40 "AttributeType inappropriate matching rule",
41 "AttributeType inappropriate USAGE",
42 "AttributeType inappropriate SUPerior",
43 "AttributeType SYNTAX or SUPerior required",
44 "Duplicate attributeType",
45 "Inconsistent duplicate attributeType",
46 "MatchingRule not found",
47 "MatchingRule incomplete",
48 "Duplicate matchingRule",
50 "Duplicate ldapSyntax",
51 "OID or name required",
52 "Qualifier not supported",
54 "OID could not be expanded",
55 "Duplicate Content Rule",
56 "Content Rule not for STRUCTURAL object class",
57 "Content Rule AUX contains inappropriate object class",
58 "Content Rule attribute type list contains duplicate",
65 if ( code < 0 || SLAP_SCHERR_LAST <= code ) {
66 return "Unknown error";
68 return err2text[code];
72 /* check schema descr validity */
73 int slap_valid_descr( const char *descr )
77 if( !DESC_LEADCHAR( descr[i] ) ) {
82 if( !DESC_CHAR( descr[i] ) ) {
93 /* String compare with delimiter check. Return 0 if not
94 * matched, otherwise return length matched.
97 dscompare(const char *s1, const char *s2, char delim)
99 const char *orig = s1;
100 while (*s1++ == *s2++)
104 if (!*s1 && (!*s2 || *s2 == delim))
113 "DITContentRuleDescription = \"(\" whsp\n"
114 " numericoid whsp ; StructuralObjectClass identifier\n"
115 " [ \"NAME\" qdescrs ]\n"
116 " [ \"DESC\" qdstring ]\n"
117 " [ \"OBSOLETE\" whsp ]\n"
118 " [ \"AUX\" oids ] ; Auxiliary ObjectClasses\n"
119 " [ \"MUST\" oids ] ; AttributeTypes\n"
120 " [ \"MAY\" oids ] ; AttributeTypes\n"
121 " [ \"NOT\" oids ] ; AttributeTypes\n"
137 cr = ldap_str2contentrule( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
139 fprintf( stderr, "%s: line %d: %s before %s\n",
140 fname, lineno, ldap_scherr2str(code), err );
145 if ( cr->cr_oid == NULL ) {
147 "%s: line %d: Content rule has no OID\n",
154 code = cr_add( cr, 1, scr, &err );
156 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
157 fname, lineno, scherr2str( code ), err );
164 ldap_contentrule_free( cr );
185 oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
187 fprintf( stderr, "%s: line %d: %s before %s\n",
188 fname, lineno, ldap_scherr2str( code ), err );
193 if ( oc->oc_oid == NULL ) {
195 "%s: line %d: objectclass has no OID\n",
202 code = oc_add( oc, 1, soc, &err );
204 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
205 fname, lineno, scherr2str( code ), err );
212 ldap_objectclass_free( oc );
225 "ObjectClassDescription = \"(\" whsp\n"
226 " numericoid whsp ; ObjectClass identifier\n"
227 " [ \"NAME\" qdescrs ]\n"
228 " [ \"DESC\" qdstring ]\n"
229 " [ \"OBSOLETE\" whsp ]\n"
230 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
231 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
232 " ; default structural\n"
233 " [ \"MUST\" oids ] ; AttributeTypes\n"
234 " [ \"MAY\" oids ] ; AttributeTypes\n"
241 fprintf( stderr, "%s%s%s",
242 "AttributeTypeDescription = \"(\" whsp\n"
243 " numericoid whsp ; AttributeType identifier\n"
244 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
245 " [ \"DESC\" qdstring ] ; description\n"
246 " [ \"OBSOLETE\" whsp ]\n"
247 " [ \"SUP\" woid ] ; derived from this other\n"
248 " ; AttributeType\n",
249 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
250 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
251 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
252 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
253 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
254 " [ \"COLLECTIVE\" whsp ] ; default not collective\n",
255 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
256 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
257 " ; userApplications\n"
258 " ; directoryOperation\n"
259 " ; distributedOperation\n"
270 AttributeType **sat )
272 LDAPAttributeType *at;
276 at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
278 fprintf( stderr, "%s: line %d: %s before %s\n",
279 fname, lineno, ldap_scherr2str(code), err );
284 if ( at->at_oid == NULL ) {
286 "%s: line %d: attributeType has no OID\n",
293 /* operational attributes should be defined internally */
294 if ( at->at_usage ) {
295 fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
296 fname, lineno, at->at_oid );
301 code = at_add( at, 1, sat, &err);
303 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
304 fname, lineno, scherr2str(code), err);
311 ldap_attributetype_free( at );