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 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 "AttributeType not found",
39 "AttributeType inappropriate matching rule",
40 "AttributeType inappropriate USAGE",
41 "AttributeType inappropriate SUPerior",
42 "AttributeType SYNTAX or SUPerior required",
43 "Duplicate attributeType",
44 "MatchingRule not found",
45 "MatchingRule incomplete",
46 "Duplicate matchingRule",
48 "Duplicate ldapSyntax",
49 "OID or name required",
50 "Qualifier not supported",
52 "OID could not be expanded",
53 "Duplicate Content Rule",
54 "Content Rule not for STRUCTURAL object class",
55 "Content Rule AUX contains inappropriate object class",
56 "Content Rule attribute type list contains duplicate"
62 if ( code < 0 || SLAP_SCHERR_LAST <= code ) {
63 return "Unknown error";
65 return err2text[code];
69 /* check schema descr validity */
70 int slap_valid_descr( const char *descr )
74 if( !DESC_LEADCHAR( descr[i] ) ) {
79 if( !DESC_CHAR( descr[i] ) ) {
90 /* String compare with delimiter check. Return 0 if not
91 * matched, otherwise return length matched.
94 dscompare(const char *s1, const char *s2, char delim)
96 const char *orig = s1;
97 while (*s1++ == *s2++)
101 if (!*s1 && (!*s2 || *s2 == delim))
110 "DITContentRuleDescription = \"(\" whsp\n"
111 " numericoid whsp ; StructuralObjectClass identifier\n"
112 " [ \"NAME\" qdescrs ]\n"
113 " [ \"DESC\" qdstring ]\n"
114 " [ \"OBSOLETE\" whsp ]\n"
115 " [ \"AUX\" oids ] ; Auxiliary ObjectClasses\n"
116 " [ \"MUST\" oids ] ; AttributeTypes\n"
117 " [ \"MAY\" oids ] ; AttributeTypes\n"
118 " [ \"NOT\" oids ] ; AttributeTypes\n"
133 cr = ldap_str2contentrule(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
135 fprintf( stderr, "%s: line %d: %s before %s\n",
136 fname, lineno, ldap_scherr2str(code), err );
141 if ( cr->cr_oid == NULL ) {
143 "%s: line %d: Content rule has no OID\n",
149 code = cr_add(cr,1,&err);
151 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
152 fname, lineno, scherr2str(code), err);
171 oc = ldap_str2objectclass(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
173 fprintf( stderr, "%s: line %d: %s before %s\n",
174 fname, lineno, ldap_scherr2str(code), err );
179 if ( oc->oc_oid == NULL ) {
181 "%s: line %d: objectclass has no OID\n",
187 code = oc_add(oc,1,&err);
189 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
190 fname, lineno, scherr2str(code), err);
202 "ObjectClassDescription = \"(\" whsp\n"
203 " numericoid whsp ; ObjectClass identifier\n"
204 " [ \"NAME\" qdescrs ]\n"
205 " [ \"DESC\" qdstring ]\n"
206 " [ \"OBSOLETE\" whsp ]\n"
207 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
208 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
209 " ; default structural\n"
210 " [ \"MUST\" oids ] ; AttributeTypes\n"
211 " [ \"MAY\" oids ] ; AttributeTypes\n"
218 fprintf( stderr, "%s%s%s",
219 "AttributeTypeDescription = \"(\" whsp\n"
220 " numericoid whsp ; AttributeType identifier\n"
221 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
222 " [ \"DESC\" qdstring ] ; description\n"
223 " [ \"OBSOLETE\" whsp ]\n"
224 " [ \"SUP\" woid ] ; derived from this other\n"
225 " ; AttributeType\n",
226 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
227 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
228 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
229 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
230 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
231 " [ \"COLLECTIVE\" whsp ] ; default not collective\n",
232 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
233 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
234 " ; userApplications\n"
235 " ; directoryOperation\n"
236 " ; distributedOperation\n"
248 LDAPAttributeType *at;
252 at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
254 fprintf( stderr, "%s: line %d: %s before %s\n",
255 fname, lineno, ldap_scherr2str(code), err );
260 if ( at->at_oid == NULL ) {
262 "%s: line %d: attributeType has no OID\n",
268 /* operational attributes should be defined internally */
269 if ( at->at_usage ) {
270 fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
271 fname, lineno, at->at_oid );
275 code = at_add(at,&err);
277 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
278 fname, lineno, scherr2str(code), err);