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-2005 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 int global_schemacheck = 1; /* schemacheck ON is default */
30 static void oc_usage(void);
31 static void at_usage(void);
33 static char *const err2text[] = {
36 "ObjectClass not found",
37 "user-defined ObjectClass includes operational attributes",
38 "user-defined ObjectClass has inappropriate SUPerior",
39 "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 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"
138 cr = ldap_str2contentrule(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
140 fprintf( stderr, "%s: line %d: %s before %s\n",
141 fname, lineno, ldap_scherr2str(code), err );
146 if ( cr->cr_oid == NULL ) {
148 "%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);
177 oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
179 fprintf( stderr, "%s: line %d: %s before %s\n",
180 fname, lineno, ldap_scherr2str(code), err );
185 if ( oc->oc_oid == NULL ) {
187 "%s: line %d: objectclass has no OID\n",
193 code = oc_add(oc,1,soc,&err);
195 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
196 fname, lineno, scherr2str(code), err);
208 "ObjectClassDescription = \"(\" whsp\n"
209 " numericoid whsp ; ObjectClass identifier\n"
210 " [ \"NAME\" qdescrs ]\n"
211 " [ \"DESC\" qdstring ]\n"
212 " [ \"OBSOLETE\" whsp ]\n"
213 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
214 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
215 " ; default structural\n"
216 " [ \"MUST\" oids ] ; AttributeTypes\n"
217 " [ \"MAY\" oids ] ; AttributeTypes\n"
224 fprintf( stderr, "%s%s%s",
225 "AttributeTypeDescription = \"(\" whsp\n"
226 " numericoid whsp ; AttributeType identifier\n"
227 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
228 " [ \"DESC\" qdstring ] ; description\n"
229 " [ \"OBSOLETE\" whsp ]\n"
230 " [ \"SUP\" woid ] ; derived from this other\n"
231 " ; AttributeType\n",
232 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
233 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
234 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
235 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
236 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
237 " [ \"COLLECTIVE\" whsp ] ; default not collective\n",
238 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
239 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
240 " ; userApplications\n"
241 " ; directoryOperation\n"
242 " ; distributedOperation\n"
253 AttributeType **sat )
255 LDAPAttributeType *at;
259 at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
261 fprintf( stderr, "%s: line %d: %s before %s\n",
262 fname, lineno, ldap_scherr2str(code), err );
267 if ( at->at_oid == NULL ) {
269 "%s: line %d: attributeType has no OID\n",
275 /* operational attributes should be defined internally */
276 if ( at->at_usage ) {
277 fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
278 fname, lineno, at->at_oid );
282 code = at_add(at,1,sat,&err);
284 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
285 fname, lineno, scherr2str(code), err);