1 /* oc.c - object class routines */
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 int is_object_subclass(
25 if( sub == NULL || sup == NULL ) return 0;
28 Debug( LDAP_DEBUG_TRACE, "is_object_subclass(%s,%s) %d\n",
29 sub->soc_oid, sup->soc_oid, sup == sub );
36 if( sup->soc_sups == NULL ) {
40 for( i=0; sup->soc_sups[i] != NULL; i++ ) {
41 if( is_object_subclass( sub, sup->soc_sups[i] ) ) {
49 int is_entry_objectclass(
55 AttributeDescription *objectClass = slap_schema.si_ad_objectClass;
56 assert(!( e == NULL || oc == NULL ));
58 if( e == NULL || oc == NULL ) {
63 * find objectClass attribute
65 attr = attr_find(e->e_attrs, objectClass);
68 /* no objectClass attribute */
69 Debug( LDAP_DEBUG_ANY, "is_entry_objectclass(\"%s\", \"%s\") "
70 "no objectClass attribute\n",
71 e->e_dn == NULL ? "" : e->e_dn,
72 oc->soc_oclass.oc_oid, 0 );
77 for( i=0; attr->a_vals[i]; i++ ) {
78 ObjectClass *objectClass = oc_find( attr->a_vals[i]->bv_val );
80 if( objectClass == oc ) {
95 static Avlnode *oc_index = NULL;
96 static ObjectClass *oc_list = NULL;
100 struct oindexrec *oir1,
101 struct oindexrec *oir2 )
103 assert( oir1->oir_name );
104 assert( oir1->oir_oc );
105 assert( oir2->oir_name );
106 assert( oir2->oir_oc );
108 return (strcasecmp( oir1->oir_name, oir2->oir_name ));
114 struct oindexrec *oir )
116 assert( oir->oir_name );
117 assert( oir->oir_oc );
119 return (strcasecmp( name, oir->oir_name ));
123 oc_find( const char *ocname )
125 struct oindexrec *oir;
127 oir = (struct oindexrec *) avl_find( oc_index, ocname,
128 (AVL_CMP) oc_index_name_cmp );
131 assert( oir->oir_name );
132 assert( oir->oir_oc );
134 return( oir->oir_oc );
148 AttributeType **satp;
154 sat = at_find(*attrs1);
157 return SLAP_SCHERR_ATTR_NOT_FOUND;
159 if ( at_find_in_list(sat, soc->soc_required) < 0) {
160 if ( at_append_to_list(sat, &soc->soc_required) ) {
162 return SLAP_SCHERR_OUTOFMEM;
167 /* Now delete duplicates from the allowed list */
168 for ( satp = soc->soc_required; *satp; satp++ ) {
169 i = at_find_in_list(*satp,soc->soc_allowed);
171 at_delete_from_list(i, &soc->soc_allowed);
190 sat = at_find(*attrs1);
193 return SLAP_SCHERR_ATTR_NOT_FOUND;
195 if ( at_find_in_list(sat, soc->soc_required) < 0 &&
196 at_find_in_list(sat, soc->soc_allowed) < 0 ) {
197 if ( at_append_to_list(sat, &soc->soc_allowed) ) {
199 return SLAP_SCHERR_OUTOFMEM;
221 if ( !soc->soc_sups ) {
222 /* We are at the first recursive level */
231 soc->soc_sups = (ObjectClass **)ch_calloc(nsups,
232 sizeof(ObjectClass *));
237 soc1 = oc_find(*sups1);
240 return SLAP_SCHERR_CLASS_NOT_FOUND;
244 soc->soc_sups[nsups] = soc1;
246 code = oc_add_sups( soc, soc1->soc_sup_oids, err );
247 if ( code ) return code;
249 code = oc_create_required( soc, soc1->soc_at_oids_must, err );
250 if ( code ) return code;
252 code = oc_create_allowed( soc, soc1->soc_at_oids_may, err );
253 if ( code ) return code;
269 struct oindexrec *oir;
273 while ( *ocp != NULL ) {
274 ocp = &(*ocp)->soc_next;
278 if ( soc->soc_oid ) {
279 oir = (struct oindexrec *)
280 ch_calloc( 1, sizeof(struct oindexrec) );
281 oir->oir_name = soc->soc_oid;
284 assert( oir->oir_name );
285 assert( oir->oir_oc );
287 if ( avl_insert( &oc_index, (caddr_t) oir,
288 (AVL_CMP) oc_index_cmp,
289 (AVL_DUP) avl_dup_error ) )
292 ldap_memfree(oir->oir_name);
294 return SLAP_SCHERR_DUP_CLASS;
297 /* FIX: temporal consistency check */
298 assert( oc_find(oir->oir_name) != NULL );
301 if ( (names = soc->soc_names) ) {
303 oir = (struct oindexrec *)
304 ch_calloc( 1, sizeof(struct oindexrec) );
305 oir->oir_name = ch_strdup(*names);
308 assert( oir->oir_name );
309 assert( oir->oir_oc );
311 if ( avl_insert( &oc_index, (caddr_t) oir,
312 (AVL_CMP) oc_index_cmp,
313 (AVL_DUP) avl_dup_error ) )
316 ldap_memfree(oir->oir_name);
318 return SLAP_SCHERR_DUP_CLASS;
321 /* FIX: temporal consistency check */
322 assert( oc_find(oir->oir_name) != NULL );
333 LDAP_OBJECT_CLASS *oc,
340 soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
341 memcpy( &soc->soc_oclass, oc, sizeof(LDAP_OBJECT_CLASS) );
343 if( soc->soc_sup_oids == NULL &&
344 soc->soc_kind == LDAP_SCHEMA_STRUCTURAL )
346 /* structural object classes implicitly inherit from 'top' */
347 static char *top_oids[] = { SLAPD_TOP_OID, NULL };
348 code = oc_add_sups( soc, top_oids, err );
350 code = oc_add_sups( soc, soc->soc_sup_oids, err );
352 if ( code != 0 ) return code;
354 code = oc_create_required( soc, soc->soc_at_oids_must, err );
355 if ( code != 0 ) return code;
357 code = oc_create_allowed( soc, soc->soc_at_oids_may, err );
358 if ( code != 0 ) return code;
360 code = oc_insert(soc,err);
367 oc_print( ObjectClass *oc )
372 printf( "objectclass %s\n", ldap_objectclass2name( &oc->soc_oclass ) );
373 if ( oc->soc_required != NULL ) {
375 for ( i = 0; oc->soc_required[i] != NULL; i++, mid = "," )
377 ldap_attributetype2name( &oc->soc_required[i]->sat_atype ) );
380 if ( oc->soc_allowed != NULL ) {
382 for ( i = 0; oc->soc_allowed[i] != NULL; i++, mid = "," )
384 ldap_attributetype2name( &oc->soc_allowed[i]->sat_atype ) );
392 #if defined( SLAPD_SCHEMA_DN )
395 oc_schema_info( Entry *e )
398 struct berval *vals[2];
401 AttributeDescription *ad_objectClasses = slap_schema.si_ad_objectClasses;
406 for ( oc = oc_list; oc; oc = oc->soc_next ) {
407 val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
408 if ( val.bv_val == NULL ) {
411 val.bv_len = strlen( val.bv_val );
413 Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s\n",
414 (long) val.bv_len, val.bv_val, 0 );
416 attr_merge( e, ad_objectClasses, vals );
417 ldap_memfree( val.bv_val );