X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fcr.c;h=059eddda389e486d183eac0d8f243b112d1cc0b5;hb=3d522a0c9fd79b0275a219bde1f4465b181a9318;hp=12c06b99e0ee13fa0d9f98de2b16b2d112fdd4be;hpb=6939c531700652491f4be4688c6a1f35a1ab8a18;p=openldap diff --git a/servers/slapd/cr.c b/servers/slapd/cr.c index 12c06b99e0..059eddda38 100644 --- a/servers/slapd/cr.c +++ b/servers/slapd/cr.c @@ -1,8 +1,17 @@ /* cr.c - content rule routines */ /* $OpenLDAP$ */ -/* - * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2003 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . */ #include "portable.h" @@ -16,15 +25,14 @@ #include "slap.h" #include "ldap_pvt.h" -#ifdef SLAP_EXTENDED_SCHEMA - struct cindexrec { struct berval cir_name; ContentRule *cir_cr; }; static Avlnode *cr_index = NULL; -static ContentRule *cr_list = NULL; +static LDAP_SLIST_HEAD(CRList, slap_content_rule) cr_list + = LDAP_SLIST_HEAD_INITIALIZER(&cr_list); static int cr_index_cmp( @@ -34,8 +42,7 @@ cr_index_cmp( const struct cindexrec *cir1 = v_cir1; const struct cindexrec *cir2 = v_cir2; int i = cir1->cir_name.bv_len - cir2->cir_name.bv_len; - if (i) - return i; + if (i) return i; return strcasecmp( cir1->cir_name.bv_val, cir2->cir_name.bv_val ); } @@ -47,8 +54,7 @@ cr_index_name_cmp( const struct berval *name = v_name; const struct cindexrec *cir = v_cir; int i = name->bv_len - cir->cir_name.bv_len; - if (i) - return i; + if (i) return i; return strncasecmp( name->bv_val, cir->cir_name.bv_val, name->bv_len ); } @@ -77,20 +83,32 @@ cr_bvfind( struct berval *crname ) return( NULL ); } +static int +cr_destroy_one( ContentRule *c ) +{ + assert( c != NULL ); + + if (c->scr_auxiliaries) ldap_memfree(c->scr_auxiliaries); + if (c->scr_required) ldap_memfree(c->scr_required); + if (c->scr_allowed) ldap_memfree(c->scr_allowed); + if (c->scr_precluded) ldap_memfree(c->scr_precluded); + ldap_contentrule_free((LDAPContentRule *)c); + + return 0; +} + void cr_destroy( void ) { - ContentRule *c, *n; + ContentRule *c; avl_free(cr_index, ldap_memfree); - for (c=cr_list; c; c=n) - { - n = c->scr_next; - if (c->scr_auxiliaries) ldap_memfree(c->scr_auxiliaries); - if (c->scr_required) ldap_memfree(c->scr_required); - if (c->scr_allowed) ldap_memfree(c->scr_allowed); - if (c->scr_precluded) ldap_memfree(c->scr_precluded); - ldap_contentrule_free((LDAPContentRule *)c); + + while( !LDAP_SLIST_EMPTY(&cr_list) ) { + c = LDAP_SLIST_FIRST(&cr_list); + LDAP_SLIST_REMOVE_HEAD(&cr_list, scr_next); + + cr_destroy_one( c ); } } @@ -100,15 +118,11 @@ cr_insert( const char **err ) { - ContentRule **crp; struct cindexrec *cir; char **names; - crp = &cr_list; - while ( *crp != NULL ) { - crp = &(*crp)->scr_next; - } - *crp = scr; + LDAP_SLIST_NEXT( scr, scr_next ) = NULL; + LDAP_SLIST_INSERT_HEAD(&cr_list, scr, scr_next); if ( scr->scr_oid ) { cir = (struct cindexrec *) @@ -185,7 +199,11 @@ cr_add_auxiliaries( return SLAP_SCHERR_CLASS_NOT_FOUND; } - if( soc->soc_flags & SLAP_OC_OPERATIONAL ) (*op)++; + if( soc->soc_flags & SLAP_OC_OPERATIONAL && + soc != slap_schema.si_oc_extensibleObject ) + { + (*op)++; + } if( soc->soc_kind != LDAP_SCHEMA_AUXILIARY ) { *err = scr->scr_oc_oids_aux[naux]; @@ -194,7 +212,6 @@ cr_add_auxiliaries( } scr->scr_auxiliaries[naux] = NULL; - return 0; } @@ -378,42 +395,45 @@ cr_add( code = cr_create_precluded( scr, &op, err ); if ( code != 0 ) return code; - if( user && op ) return SLAP_SCHERR_CR_BAD_AUX; + if( user && op ) { + return SLAP_SCHERR_CR_BAD_AUX; + } code = cr_insert(scr,err); return code; } -#endif - int cr_schema_info( Entry *e ) { -#ifdef SLAP_EXTENDED_SCHEMA - struct berval vals[2]; + AttributeDescription *ad_ditContentRules + = slap_schema.si_ad_ditContentRules; ContentRule *cr; - AttributeDescription *ad_ditContentRules = slap_schema.si_ad_ditContentRules; - - vals[1].bv_val = NULL; + struct berval val; + struct berval nval; - for ( cr = cr_list; cr; cr = cr->scr_next ) { - if ( ldap_contentrule2bv( &cr->scr_crule, vals ) == NULL ) { + LDAP_SLIST_FOREACH(cr, &cr_list, scr_next) { + if ( ldap_contentrule2bv( &cr->scr_crule, &val ) == NULL ) { return -1; } #if 0 if( cr->scr_flags & SLAP_CR_HIDE ) continue; #endif - #if 0 Debug( LDAP_DEBUG_TRACE, "Merging cr [%ld] %s\n", - (long) vals[0].bv_len, vals[0].bv_val, 0 ); + (long) val.bv_len, val.bv_val, 0 ); #endif - if( attr_merge( e, ad_ditContentRules, vals ) ) + + nval.bv_val = cr->scr_oid; + nval.bv_len = strlen(cr->scr_oid); + + if( attr_merge_one( e, ad_ditContentRules, &val, &nval ) ) + { return -1; - ldap_memfree( vals[0].bv_val ); + } + ldap_memfree( val.bv_val ); } -#endif return 0; }