1 /* schemaparse.c - routines to parse config file objectclass definitions */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
17 #include "ldap_schema.h"
19 int global_schemacheck = 1; /* schemacheck ON is default */
21 static void oc_usage(void);
22 static void at_usage(void);
24 static char *const err2text[SLAP_SCHERR_LAST+1] = {
27 "ObjectClass not found",
28 "ObjectClass inappropriate SUPerior",
29 "AttributeType not found",
30 "AttributeType inappropriate USAGE",
31 "Duplicate objectClass",
32 "Duplicate attributeType",
33 "Duplicate ldapSyntax",
34 "Duplicate matchingRule",
35 "OID or name required",
36 "SYNTAX or SUPerior required",
37 "MatchingRule not found",
40 "Qualifier not supported",
42 "OID could not be expanded"
48 if ( code < 0 || code >= (sizeof(err2text)/sizeof(char *)) ) {
49 return "Unknown error";
51 return err2text[code];
55 /* check schema descr validity */
56 int slap_valid_descr( const char *descr )
60 if( !DESC_LEADCHAR( descr[i] ) ) {
65 if( !DESC_CHAR( descr[i] ) ) {
76 /* String compare with delimiter check. Return 0 if not
77 * matched, otherwise return length matched.
80 dscompare(const char *s1, const char *s2, char delim)
82 const char *orig = s1;
83 while (*s1++ == *s2++)
87 if (!*s1 && (!*s2 || *s2 == delim))
106 oc = ldap_str2objectclass(line,&code,&err,LDAP_SCHEMA_ALLOW_ALL);
108 fprintf( stderr, "%s: line %d: %s before %s\n",
109 fname, lineno, ldap_scherr2str(code), err );
114 if ( oc->oc_oid == NULL ) {
116 "%s: line %d: objectclass has no OID\n",
122 if ( !OID_LEADCHAR( oc->oc_oid[0] )) {
123 /* Expand OID macros */
124 oid = oidm_find( oc->oc_oid );
127 "%s: line %d: OID %s not recognized\n",
128 fname, lineno, oc->oc_oid);
131 if ( oid != oc->oc_oid ) {
132 ldap_memfree( oc->oc_oid );
137 code = oc_add(oc,&err);
139 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
140 fname, lineno, scherr2str(code), err);
152 "ObjectClassDescription = \"(\" whsp\n"
153 " numericoid whsp ; ObjectClass identifier\n"
154 " [ \"NAME\" qdescrs ]\n"
155 " [ \"DESC\" qdstring ]\n"
156 " [ \"OBSOLETE\" whsp ]\n"
157 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
158 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
159 " ; default structural\n"
160 " [ \"MUST\" oids ] ; AttributeTypes\n"
161 " [ \"MAY\" oids ] ; AttributeTypes\n"
170 "AttributeTypeDescription = \"(\" whsp\n"
171 " numericoid whsp ; AttributeType identifier\n"
172 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
173 " [ \"DESC\" qdstring ] ; description\n"
174 " [ \"OBSOLETE\" whsp ]\n"
175 " [ \"SUP\" woid ] ; derived from this other\n"
177 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
178 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
179 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
180 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
181 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
182 " [ \"COLLECTIVE\" whsp ] ; default not collective\n"
183 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
184 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
185 " ; userApplications\n"
186 " ; directoryOperation\n"
187 " ; distributedOperation\n"
200 LDAPAttributeType *at;
205 at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
207 fprintf( stderr, "%s: line %d: %s before %s\n",
208 fname, lineno, ldap_scherr2str(code), err );
213 if ( at->at_oid == NULL ) {
215 "%s: line %d: attributeType has no OID\n",
221 /* operational attributes should be defined internally */
222 if ( at->at_usage ) {
223 fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
224 fname, lineno, at->at_oid );
228 code = at_add(at,&err);
230 fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
231 fname, lineno, scherr2str(code), err);