1 /* schema_check.c - routines to enforce schema definitions */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/string.h>
14 #include <ac/socket.h>
19 static char * oc_check_required(Entry *e, struct berval *ocname);
22 * entry_schema_check - check that entry e conforms to the schema required
23 * by its object class(es).
25 * returns 0 if so, non-zero otherwise.
30 Entry *e, Attribute *oldattrs, const char** text )
36 AttributeDescription *ad_objectClass = slap_schema.si_ad_objectClass;
39 if( !global_schemacheck ) return LDAP_SUCCESS;
41 /* find the object class attribute - could error out here */
42 if ( (aoc = attr_find( e->e_attrs, ad_objectClass )) == NULL ) {
43 Debug( LDAP_DEBUG_ANY, "No object class for entry (%s)\n",
45 *text = "no objectclass attribute";
46 return oldattrs != NULL
47 ? LDAP_OBJECT_CLASS_VIOLATION
48 : LDAP_NO_OBJECT_CLASS_MODS;
53 /* check that the entry has required attrs for each oc */
54 for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
55 if ( (oc = oc_find( aoc->a_vals[i]->bv_val )) == NULL ) {
56 Debug( LDAP_DEBUG_ANY,
57 "entry_check_schema(%s): objectclass \"%s\" not defined\n",
58 e->e_dn, aoc->a_vals[i]->bv_val, 0 );
61 char *s = oc_check_required( e, aoc->a_vals[i] );
64 Debug( LDAP_DEBUG_ANY,
65 "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
66 e->e_dn, aoc->a_vals[i]->bv_val, s );
67 *text = "missing required attribute";
68 ret = LDAP_OBJECT_CLASS_VIOLATION;
72 if( oc == slap_schema.si_oc_extensibleObject )
80 if ( ret != LDAP_SUCCESS ) {
88 /* check that each attr in the entry is allowed by some oc */
89 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
90 ret = oc_check_allowed( a->a_desc->ad_type, aoc->a_vals );
92 char *type = a->a_desc->ad_cname->bv_val;
93 Debug( LDAP_DEBUG_ANY,
94 "Entry (%s), attr \"%s\" not allowed\n",
96 *text = "attribute not allowed";
105 oc_check_required( Entry *e, struct berval *ocname )
112 Debug( LDAP_DEBUG_TRACE,
113 "oc_check_required entry (%s), objectclass \"%s\"\n",
114 e->e_dn, ocname->bv_val, 0 );
116 /* find global oc defn. it we don't know about it assume it's ok */
117 if ( (oc = oc_find( ocname->bv_val )) == NULL ) {
121 /* check for empty oc_required */
122 if(oc->soc_required == NULL) {
126 /* for each required attribute */
127 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
128 at = oc->soc_required[i];
129 /* see if it's in the entry */
130 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
131 if( a->a_desc->ad_type == at ) {
135 /* not there => schema violation */
137 return at->sat_cname;
144 int oc_check_allowed(
146 struct berval **ocl )
151 Debug( LDAP_DEBUG_TRACE,
152 "oc_check_allowed type \"%s\"\n",
153 at->sat_cname, 0, 0 );
155 /* always allow objectclass attribute */
156 if ( strcasecmp( at->sat_cname, "objectclass" ) == 0 ) {
162 * All operational attributions are allowed by schema rules.
164 if( is_at_operational(at) ) {
168 /* check that the type appears as req or opt in at least one oc */
169 for ( i = 0; ocl[i] != NULL; i++ ) {
170 /* if we know about the oc */
171 if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
172 /* does it require the type? */
173 for ( j = 0; oc->soc_required != NULL &&
174 oc->soc_required[j] != NULL; j++ )
176 if( at == oc->soc_required[j] ) {
180 /* does it allow the type? */
181 for ( j = 0; oc->soc_allowed != NULL &&
182 oc->soc_allowed[j] != NULL; j++ )
184 if( at == oc->soc_allowed[j] ) {
188 /* maybe the next oc allows it */
190 #ifdef OC_UNDEFINED_IMPLES_EXTENSIBLE
191 /* we don't know about the oc. assume it allows it */
201 /* not allowed by any oc */
202 return LDAP_OBJECT_CLASS_VIOLATION;