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-2004 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 "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"
64 if ( code < 0 || SLAP_SCHERR_LAST <= code ) {
65 return "Unknown error";
67 return err2text[code];
71 /* check schema descr validity */
72 int slap_valid_descr( const char *descr )
76 if( !DESC_LEADCHAR( descr[i] ) ) {
81 if( !DESC_CHAR( descr[i] ) ) {
92 /* String compare with delimiter check. Return 0 if not
93 * matched, otherwise return length matched.
96 dscompare(const char *s1, const char *s2, char delim)
98 const char *orig = s1;
99 while (*s1++ == *s2++)
103 if (!*s1 && (!*s2 || *s2 == delim))
112 "DITContentRuleDescription = \"(\" whsp\n"
113 " numericoid whsp ; StructuralObjectClass identifier\n"
114 " [ \"NAME\" qdescrs ]\n"
115 " [ \"DESC\" qdstring ]\n"
116 " [ \"OBSOLETE\" whsp ]\n"
117 " [ \"AUX\" oids ] ; Auxiliary ObjectClasses\n"
118 " [ \"MUST\" oids ] ; AttributeTypes\n"
119 " [ \"MAY\" oids ] ; AttributeTypes\n"
120 " [ \"NOT\" oids ] ; AttributeTypes\n"
136 cr = ldap_str2contentrule(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
138 fprintf( stderr, "%s: line %d: %s before %s\n",
139 fname, lineno, ldap_scherr2str(code), err );
144 if ( cr->cr_oid == NULL ) {
146 "%s: line %d: Content rule has no OID\n",
152 code = cr_add(cr,1,&err);
154 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
155 fname, lineno, scherr2str(code), err);
175 oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
177 fprintf( stderr, "%s: line %d: %s before %s\n",
178 fname, lineno, ldap_scherr2str(code), err );
183 if ( oc->oc_oid == NULL ) {
185 "%s: line %d: objectclass has no OID\n",
191 code = oc_add(oc,1,&err);
193 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
194 fname, lineno, scherr2str(code), err);
206 "ObjectClassDescription = \"(\" whsp\n"
207 " numericoid whsp ; ObjectClass identifier\n"
208 " [ \"NAME\" qdescrs ]\n"
209 " [ \"DESC\" qdstring ]\n"
210 " [ \"OBSOLETE\" whsp ]\n"
211 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
212 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
213 " ; default structural\n"
214 " [ \"MUST\" oids ] ; AttributeTypes\n"
215 " [ \"MAY\" oids ] ; AttributeTypes\n"
222 fprintf( stderr, "%s%s%s",
223 "AttributeTypeDescription = \"(\" whsp\n"
224 " numericoid whsp ; AttributeType identifier\n"
225 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
226 " [ \"DESC\" qdstring ] ; description\n"
227 " [ \"OBSOLETE\" whsp ]\n"
228 " [ \"SUP\" woid ] ; derived from this other\n"
229 " ; AttributeType\n",
230 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
231 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
232 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
233 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
234 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
235 " [ \"COLLECTIVE\" whsp ] ; default not collective\n",
236 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
237 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
238 " ; userApplications\n"
239 " ; directoryOperation\n"
240 " ; distributedOperation\n"
253 LDAPAttributeType *at;
257 at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
259 fprintf( stderr, "%s: line %d: %s before %s\n",
260 fname, lineno, ldap_scherr2str(code), err );
265 if ( at->at_oid == NULL ) {
267 "%s: line %d: attributeType has no OID\n",
273 /* operational attributes should be defined internally */
274 if ( at->at_usage ) {
275 fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
276 fname, lineno, at->at_oid );
280 code = at_add(at,&err);
282 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
283 fname, lineno, scherr2str(code), err);