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"
135 cr = ldap_str2contentrule(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
137 fprintf( stderr, "%s: line %d: %s before %s\n",
138 fname, lineno, ldap_scherr2str(code), err );
143 if ( cr->cr_oid == NULL ) {
145 "%s: line %d: Content rule has no OID\n",
151 code = cr_add(cr,1,&err);
153 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
154 fname, lineno, scherr2str(code), err);
173 oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
175 fprintf( stderr, "%s: line %d: %s before %s\n",
176 fname, lineno, ldap_scherr2str(code), err );
181 if ( oc->oc_oid == NULL ) {
183 "%s: line %d: objectclass has no OID\n",
189 code = oc_add(oc,1,&err);
191 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
192 fname, lineno, scherr2str(code), err);
204 "ObjectClassDescription = \"(\" whsp\n"
205 " numericoid whsp ; ObjectClass identifier\n"
206 " [ \"NAME\" qdescrs ]\n"
207 " [ \"DESC\" qdstring ]\n"
208 " [ \"OBSOLETE\" whsp ]\n"
209 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
210 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
211 " ; default structural\n"
212 " [ \"MUST\" oids ] ; AttributeTypes\n"
213 " [ \"MAY\" oids ] ; AttributeTypes\n"
220 fprintf( stderr, "%s%s%s",
221 "AttributeTypeDescription = \"(\" whsp\n"
222 " numericoid whsp ; AttributeType identifier\n"
223 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
224 " [ \"DESC\" qdstring ] ; description\n"
225 " [ \"OBSOLETE\" whsp ]\n"
226 " [ \"SUP\" woid ] ; derived from this other\n"
227 " ; AttributeType\n",
228 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
229 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
230 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
231 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
232 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
233 " [ \"COLLECTIVE\" whsp ] ; default not collective\n",
234 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
235 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
236 " ; userApplications\n"
237 " ; directoryOperation\n"
238 " ; distributedOperation\n"
250 LDAPAttributeType *at;
254 at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
256 fprintf( stderr, "%s: line %d: %s before %s\n",
257 fname, lineno, ldap_scherr2str(code), err );
262 if ( at->at_oid == NULL ) {
264 "%s: line %d: attributeType has no OID\n",
270 /* operational attributes should be defined internally */
271 if ( at->at_usage ) {
272 fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
273 fname, lineno, at->at_oid );
277 code = at_add(at,&err);
279 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
280 fname, lineno, scherr2str(code), err);