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(
29 if( sup->soc_sups == NULL ) {
33 for( i=0; sup->soc_sups[i] != NULL; i++ ) {
34 if( is_object_subclass( sup->soc_sups[i], sup ) ) {
42 int is_entry_objectclass(
49 AttributeDescription *objectClass = slap_schema.si_ad_objectClass;
50 assert(!( e == NULL || oc == NULL ));
52 if( e == NULL || oc == NULL ) {
57 * find objectClass attribute
59 attr = attr_find(e->e_attrs, objectClass);
62 /* no objectClass attribute */
63 Debug( LDAP_DEBUG_ANY, "is_entry_objectclass(\"%s\", \"%s\") "
64 "no objectClass attribute\n",
65 e->e_dn == NULL ? "" : e->e_dn,
66 oc->soc_oclass.oc_oid, 0 );
71 for( i=0; attr->a_vals[i]; i++ ) {
72 ObjectClass *objectClass = oc_find( attr->a_vals[i]->bv_val );
74 if( objectClass == oc ) {
91 static Avlnode *oc_index = NULL;
92 static ObjectClass *oc_list = NULL;
96 struct oindexrec *oir1,
97 struct oindexrec *oir2
100 assert( oir1->oir_name );
101 assert( oir1->oir_oc );
102 assert( oir2->oir_name );
103 assert( oir2->oir_oc );
105 return (strcasecmp( oir1->oir_name, oir2->oir_name ));
111 struct oindexrec *oir
114 assert( oir->oir_name );
115 assert( oir->oir_oc );
117 return (strcasecmp( name, oir->oir_name ));
121 oc_find( const char *ocname )
123 struct oindexrec *oir;
125 oir = (struct oindexrec *) avl_find( oc_index, ocname,
126 (AVL_CMP) oc_index_name_cmp );
129 assert( oir->oir_name );
130 assert( oir->oir_oc );
132 return( oir->oir_oc );
147 AttributeType **satp;
153 sat = at_find(*attrs1);
156 return SLAP_SCHERR_ATTR_NOT_FOUND;
158 if ( at_find_in_list(sat, soc->soc_required) < 0) {
159 if ( at_append_to_list(sat, &soc->soc_required) ) {
161 return SLAP_SCHERR_OUTOFMEM;
166 /* Now delete duplicates from the allowed list */
167 for ( satp = soc->soc_required; *satp; satp++ ) {
168 i = at_find_in_list(*satp,soc->soc_allowed);
170 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;
222 if ( !soc->soc_sups ) {
223 /* We are at the first recursive level */
232 soc->soc_sups = (ObjectClass **)ch_calloc(nsups,
233 sizeof(ObjectClass *));
238 soc1 = oc_find(*sups1);
241 return SLAP_SCHERR_CLASS_NOT_FOUND;
245 soc->soc_sups[nsups] = soc1;
247 code = oc_add_sups(soc,soc1->soc_sup_oids, err);
251 code = oc_create_required(soc,soc1->soc_at_oids_must,err);
254 code = oc_create_allowed(soc,soc1->soc_at_oids_may,err);
272 struct oindexrec *oir;
276 while ( *ocp != NULL ) {
277 ocp = &(*ocp)->soc_next;
281 if ( soc->soc_oid ) {
282 oir = (struct oindexrec *)
283 ch_calloc( 1, sizeof(struct oindexrec) );
284 oir->oir_name = soc->soc_oid;
287 assert( oir->oir_name );
288 assert( oir->oir_oc );
290 if ( avl_insert( &oc_index, (caddr_t) oir,
291 (AVL_CMP) oc_index_cmp,
292 (AVL_DUP) avl_dup_error ) )
295 ldap_memfree(oir->oir_name);
297 return SLAP_SCHERR_DUP_CLASS;
300 /* FIX: temporal consistency check */
301 assert( oc_find(oir->oir_name) != NULL );
304 if ( (names = soc->soc_names) ) {
306 oir = (struct oindexrec *)
307 ch_calloc( 1, sizeof(struct oindexrec) );
308 oir->oir_name = ch_strdup(*names);
311 assert( oir->oir_name );
312 assert( oir->oir_oc );
314 if ( avl_insert( &oc_index, (caddr_t) oir,
315 (AVL_CMP) oc_index_cmp,
316 (AVL_DUP) avl_dup_error ) )
319 ldap_memfree(oir->oir_name);
321 return SLAP_SCHERR_DUP_CLASS;
324 /* FIX: temporal consistency check */
325 assert( oc_find(oir->oir_name) != NULL );
336 LDAP_OBJECT_CLASS *oc,
343 soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
344 memcpy( &soc->soc_oclass, oc, sizeof(LDAP_OBJECT_CLASS));
345 if ( (code = oc_add_sups(soc,soc->soc_sup_oids,err)) != 0 )
347 if ( (code = oc_create_required(soc,soc->soc_at_oids_must,err)) != 0 )
349 if ( (code = oc_create_allowed(soc,soc->soc_at_oids_may,err)) != 0 )
351 code = oc_insert(soc,err);
358 oc_print( ObjectClass *oc )
363 printf( "objectclass %s\n", ldap_objectclass2name( &oc->soc_oclass ) );
364 if ( oc->soc_required != NULL ) {
366 for ( i = 0; oc->soc_required[i] != NULL; i++, mid = "," )
368 ldap_attributetype2name( &oc->soc_required[i]->sat_atype ) );
371 if ( oc->soc_allowed != NULL ) {
373 for ( i = 0; oc->soc_allowed[i] != NULL; i++, mid = "," )
375 ldap_attributetype2name( &oc->soc_allowed[i]->sat_atype ) );
383 #if defined( SLAPD_SCHEMA_DN )
386 oc_schema_info( Entry *e )
389 struct berval *vals[2];
392 AttributeDescription *ad_objectClasses = slap_schema.si_ad_objectClasses;
397 for ( oc = oc_list; oc; oc = oc->soc_next ) {
398 val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
399 if ( val.bv_val == NULL ) {
402 val.bv_len = strlen( val.bv_val );
404 Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s\n",
405 (long) val.bv_len, val.bv_val, 0 );
407 attr_merge( e, ad_objectClasses, vals );
408 ldap_memfree( val.bv_val );