1 /* schema_check.c - routines to enforce schema definitions */
4 * Copyright 1998-1999 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, char *ocname);
20 static int oc_check_allowed(char *type, struct berval **ocl);
23 * entry_schema_check - check that entry e conforms to the schema required
24 * by its object class(es).
26 * returns 0 if so, non-zero otherwise.
30 schema_check_entry( Entry *e )
37 if( !global_schemacheck ) return 0;
39 /* find the object class attribute - could error out here */
40 if ( (aoc = attr_find( e->e_attrs, "objectclass" )) == NULL ) {
41 Debug( LDAP_DEBUG_ANY, "No object class for entry (%s)\n",
46 /* check that the entry has required attrs for each oc */
47 for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
48 if ( (oc = oc_find( aoc->a_vals[i]->bv_val )) == NULL ) {
49 Debug( LDAP_DEBUG_ANY,
50 "Objectclass \"%s\" not defined\n",
51 aoc->a_vals[i]->bv_val, 0, 0 );
55 char *s = oc_check_required( e, aoc->a_vals[i]->bv_val );
58 Debug( LDAP_DEBUG_ANY,
59 "Entry (%s), oc \"%s\" requires attr \"%s\"\n",
60 e->e_dn, aoc->a_vals[i]->bv_val, s );
70 /* check that each attr in the entry is allowed by some oc */
71 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
72 #ifdef SLAPD_SCHEMA_NOT_COMPAT
73 if ( oc_check_allowed( a->a_desc.ad_type, aoc->a_vals ) != 0 ) {
74 Debug( LDAP_DEBUG_ANY,
75 "Entry (%s), attr \"%s\" not allowed\n",
76 e->e_dn, a->a_desc.ad_cname->bv_val, 0 );
80 if ( oc_check_allowed( a->a_type, aoc->a_vals ) != 0 ) {
81 Debug( LDAP_DEBUG_ANY,
82 "Entry (%s), attr \"%s\" not allowed\n",
83 e->e_dn, a->a_type, 0 );
93 oc_check_required( Entry *e, char *ocname )
100 Debug( LDAP_DEBUG_TRACE,
101 "oc_check_required entry (%s), objectclass \"%s\"\n",
102 e->e_dn, ocname, 0 );
104 /* find global oc defn. it we don't know about it assume it's ok */
105 if ( (oc = oc_find( ocname )) == NULL ) {
109 /* check for empty oc_required */
110 if(oc->soc_required == NULL) {
114 /* for each required attribute */
115 for ( i = 0; oc->soc_required[i] != NULL; i++ ) {
116 at = oc->soc_required[i];
117 /* see if it's in the entry */
118 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
119 #ifdef SLAPD_SCHEMA_NOT_COMPAT
120 if( a->a_desc.ad_type == at ) {
127 strcmp( a->a_type, at->sat_oid ) == 0 ) {
132 /* Empty name list => not found */
137 if ( strcasecmp( a->a_type, *pp ) == 0 ) {
147 /* not there => schema violation */
149 if ( at->sat_names && at->sat_names[0] ) {
150 return at->sat_names[0];
161 oc_check_allowed( char *type, struct berval **ocl )
169 Debug( LDAP_DEBUG_TRACE,
170 "oc_check_allowed type \"%s\"\n", type, 0, 0 );
172 /* always allow objectclass attribute */
173 if ( strcasecmp( type, "objectclass" ) == 0 ) {
177 #ifndef SLAPD_SCHEMA_NOT_COMPAT
178 /* Treat any attribute type with option as an unknown attribute type */
180 * The "type" we have received is actually an AttributeDescription.
181 * Let's find out the corresponding type.
183 p = strchr( type, ';' );
185 t = ch_malloc( p-type+1 );
186 strncpy( t, type, p-type );
188 Debug( LDAP_DEBUG_TRACE,
189 "oc_check_allowed type \"%s\" from \"%s\"\n",
200 * All operational attributions are allowed by schema rules.
202 if ( oc_check_op_attr( t ) ) {
206 /* check that the type appears as req or opt in at least one oc */
207 for ( i = 0; ocl[i] != NULL; i++ ) {
208 /* if we know about the oc */
209 if ( (oc = oc_find( ocl[i]->bv_val )) != NULL ) {
210 /* does it require the type? */
211 for ( j = 0; oc->soc_required != NULL &&
212 oc->soc_required[j] != NULL; j++ ) {
213 at = oc->soc_required[j];
215 strcmp(at->sat_oid, t ) == 0 ) {
224 if ( strcasecmp( *pp, t ) == 0 ) {
232 /* does it allow the type? */
233 for ( j = 0; oc->soc_allowed != NULL &&
234 oc->soc_allowed[j] != NULL; j++ ) {
235 at = oc->soc_allowed[j];
237 strcmp( at->sat_oid, t ) == 0 ) {
246 if ( strcasecmp( *pp, t ) == 0 ||
247 strcmp( *pp, "*" ) == 0 ) {
255 /* maybe the next oc allows it */
257 #ifdef OC_UNDEFINED_IMPLES_EXTENSIBLE
258 /* we don't know about the oc. assume it allows it */
269 /* not allowed by any oc */