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 "Inconsistent duplicate objectClass",
41 "AttributeType not found",
42 "AttributeType inappropriate matching rule",
43 "AttributeType inappropriate USAGE",
44 "AttributeType inappropriate SUPerior",
45 "AttributeType SYNTAX or SUPerior required",
46 "Duplicate attributeType",
47 "Inconsistent duplicate attributeType",
48 "MatchingRule not found",
49 "MatchingRule incomplete",
50 "Duplicate matchingRule",
52 "Duplicate ldapSyntax",
53 "OID or name required",
54 "Qualifier not supported",
56 "OID could not be expanded",
57 "Duplicate Content Rule",
58 "Content Rule not for STRUCTURAL object class",
59 "Content Rule AUX contains inappropriate object class",
60 "Content Rule attribute type list contains duplicate",
67 if ( code < 0 || SLAP_SCHERR_LAST <= code ) {
68 return "Unknown error";
70 return err2text[code];
74 /* check schema descr validity */
75 int slap_valid_descr( const char *descr )
79 if( !DESC_LEADCHAR( descr[i] ) ) {
84 if( !DESC_CHAR( descr[i] ) ) {
95 /* String compare with delimiter check. Return 0 if not
96 * matched, otherwise return length matched.
99 dscompare(const char *s1, const char *s2, char delim)
101 const char *orig = s1;
102 while (*s1++ == *s2++)
106 if (!*s1 && (!*s2 || *s2 == delim))
115 "DITContentRuleDescription = \"(\" whsp\n"
116 " numericoid whsp ; StructuralObjectClass identifier\n"
117 " [ \"NAME\" qdescrs ]\n"
118 " [ \"DESC\" qdstring ]\n"
119 " [ \"OBSOLETE\" whsp ]\n"
120 " [ \"AUX\" oids ] ; Auxiliary ObjectClasses\n"
121 " [ \"MUST\" oids ] ; AttributeTypes\n"
122 " [ \"MAY\" oids ] ; AttributeTypes\n"
123 " [ \"NOT\" oids ] ; AttributeTypes\n"
139 cr = ldap_str2contentrule(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
141 fprintf( stderr, "%s: line %d: %s before %s\n",
142 fname, lineno, ldap_scherr2str(code), err );
147 if ( cr->cr_oid == NULL ) {
149 "%s: line %d: Content rule has no OID\n",
155 code = cr_add(cr,1,scr,&err);
157 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
158 fname, lineno, scherr2str(code), err);
178 oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
180 fprintf( stderr, "%s: line %d: %s before %s\n",
181 fname, lineno, ldap_scherr2str(code), err );
186 if ( oc->oc_oid == NULL ) {
188 "%s: line %d: objectclass has no OID\n",
194 code = oc_add(oc,1,soc,&err);
196 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
197 fname, lineno, scherr2str(code), err);
209 "ObjectClassDescription = \"(\" whsp\n"
210 " numericoid whsp ; ObjectClass identifier\n"
211 " [ \"NAME\" qdescrs ]\n"
212 " [ \"DESC\" qdstring ]\n"
213 " [ \"OBSOLETE\" whsp ]\n"
214 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
215 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
216 " ; default structural\n"
217 " [ \"MUST\" oids ] ; AttributeTypes\n"
218 " [ \"MAY\" oids ] ; AttributeTypes\n"
225 fprintf( stderr, "%s%s%s",
226 "AttributeTypeDescription = \"(\" whsp\n"
227 " numericoid whsp ; AttributeType identifier\n"
228 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
229 " [ \"DESC\" qdstring ] ; description\n"
230 " [ \"OBSOLETE\" whsp ]\n"
231 " [ \"SUP\" woid ] ; derived from this other\n"
232 " ; AttributeType\n",
233 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
234 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
235 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
236 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
237 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
238 " [ \"COLLECTIVE\" whsp ] ; default not collective\n",
239 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
240 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
241 " ; userApplications\n"
242 " ; directoryOperation\n"
243 " ; distributedOperation\n"
254 AttributeType **sat )
256 LDAPAttributeType *at;
260 at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
262 fprintf( stderr, "%s: line %d: %s before %s\n",
263 fname, lineno, ldap_scherr2str(code), err );
268 if ( at->at_oid == NULL ) {
270 "%s: line %d: attributeType has no OID\n",
276 /* operational attributes should be defined internally */
277 if ( at->at_usage ) {
278 fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
279 fname, lineno, at->at_oid );
283 code = at_add(at,1,sat,&err);
285 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
286 fname, lineno, scherr2str(code), err);