1 /* schemaparse.c - routines to parse config file objectclass definitions */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/schemaparse.c,v 1.80.2.4 2008/02/11 23:26:44 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 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"
29 static void oc_usage(void);
30 static void at_usage(void);
32 static char *const err2text
[] = {
35 "ObjectClass not found",
36 "user-defined ObjectClass includes operational attributes",
37 "user-defined ObjectClass has inappropriate SUPerior",
38 "Duplicate objectClass",
39 "Inconsistent 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 "Inconsistent duplicate attributeType",
47 "MatchingRule not found",
48 "MatchingRule incomplete",
49 "Duplicate matchingRule",
51 "Duplicate ldapSyntax",
52 "Superior syntax not found",
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"
129 struct config_args_s
*c
,
135 char *line
= strchr( c
->line
, '(' );
137 cr
= ldap_str2contentrule( line
, &code
, &err
, LDAP_SCHEMA_ALLOW_ALL
);
139 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: %s before %s",
140 c
->argv
[0], ldap_scherr2str( code
), err
);
141 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
142 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
147 if ( cr
->cr_oid
== NULL
) {
148 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: OID is missing",
150 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
151 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
157 code
= cr_add( cr
, 1, scr
, &err
);
159 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: %s: \"%s\"",
160 c
->argv
[0], scherr2str(code
), err
);
161 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
162 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
169 ldap_contentrule_free( cr
);
180 struct config_args_s
*c
,
187 char *line
= strchr( c
->line
, '(' );
189 oc
= ldap_str2objectclass(line
, &code
, &err
, LDAP_SCHEMA_ALLOW_ALL
);
191 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: %s before %s",
192 c
->argv
[0], ldap_scherr2str( code
), err
);
193 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
194 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
199 if ( oc
->oc_oid
== NULL
) {
200 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: OID is missing",
202 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
203 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
209 code
= oc_add( oc
, 1, soc
, prev
, &err
);
211 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: %s: \"%s\"",
212 c
->argv
[0], scherr2str(code
), err
);
213 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
214 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
221 ldap_objectclass_free( oc
);
234 "ObjectClassDescription = \"(\" whsp\n"
235 " numericoid whsp ; ObjectClass identifier\n"
236 " [ \"NAME\" qdescrs ]\n"
237 " [ \"DESC\" qdstring ]\n"
238 " [ \"OBSOLETE\" whsp ]\n"
239 " [ \"SUP\" oids ] ; Superior ObjectClasses\n"
240 " [ ( \"ABSTRACT\" / \"STRUCTURAL\" / \"AUXILIARY\" ) whsp ]\n"
241 " ; default structural\n"
242 " [ \"MUST\" oids ] ; AttributeTypes\n"
243 " [ \"MAY\" oids ] ; AttributeTypes\n"
250 fprintf( stderr
, "%s%s%s",
251 "AttributeTypeDescription = \"(\" whsp\n"
252 " numericoid whsp ; AttributeType identifier\n"
253 " [ \"NAME\" qdescrs ] ; name used in AttributeType\n"
254 " [ \"DESC\" qdstring ] ; description\n"
255 " [ \"OBSOLETE\" whsp ]\n"
256 " [ \"SUP\" woid ] ; derived from this other\n"
257 " ; AttributeType\n",
258 " [ \"EQUALITY\" woid ] ; Matching Rule name\n"
259 " [ \"ORDERING\" woid ] ; Matching Rule name\n"
260 " [ \"SUBSTR\" woid ] ; Matching Rule name\n"
261 " [ \"SYNTAX\" whsp noidlen whsp ] ; see section 4.3\n"
262 " [ \"SINGLE-VALUE\" whsp ] ; default multi-valued\n"
263 " [ \"COLLECTIVE\" whsp ] ; default not collective\n",
264 " [ \"NO-USER-MODIFICATION\" whsp ]; default user modifiable\n"
265 " [ \"USAGE\" whsp AttributeUsage ]; default userApplications\n"
266 " ; userApplications\n"
267 " ; directoryOperation\n"
268 " ; distributedOperation\n"
275 struct config_args_s
*c
,
277 AttributeType
*prev
)
279 LDAPAttributeType
*at
;
282 char *line
= strchr( c
->line
, '(' );
284 at
= ldap_str2attributetype( line
, &code
, &err
, LDAP_SCHEMA_ALLOW_ALL
);
286 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: %s before %s",
287 c
->argv
[0], ldap_scherr2str(code
), err
);
288 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
289 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
294 if ( at
->at_oid
== NULL
) {
295 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: OID is missing",
297 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
298 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
304 /* operational attributes should be defined internally */
305 if ( at
->at_usage
) {
306 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: \"%s\" is operational",
307 c
->argv
[0], at
->at_oid
);
308 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
309 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
314 code
= at_add( at
, 1, sat
, prev
, &err
);
316 snprintf( c
->cr_msg
, sizeof( c
->cr_msg
), "%s: %s: \"%s\"",
317 c
->argv
[0], scherr2str(code
), err
);
318 Debug( LDAP_DEBUG_CONFIG
|LDAP_DEBUG_NONE
,
319 "%s %s\n", c
->log
, c
->cr_msg
, 0 );
326 ldap_attributetype_free( at
);