X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fcr.c;h=948f4ec0cda34e88a00aeca5d01188cf5d725f5d;hb=d7396583d5bac01fda89da592824b1c8179984f4;hp=24c546e364bf3244951e2d9fd0e3b6eb0e00aae8;hpb=c75be97ae946dab41f002a31d8347cc38cda7658;p=openldap diff --git a/servers/slapd/cr.c b/servers/slapd/cr.c index 24c546e364..948f4ec0cd 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-2005 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" @@ -14,9 +23,6 @@ #include #include "slap.h" -#include "ldap_pvt.h" - -#ifdef SLAP_EXTENDED_SCHEMA struct cindexrec { struct berval cir_name; @@ -24,8 +30,8 @@ struct cindexrec { }; static Avlnode *cr_index = NULL; -static LDAP_SLIST_HEAD(CRList, slap_content_rule) cr_list - = LDAP_SLIST_HEAD_INITIALIZER(&cr_list); +static LDAP_STAILQ_HEAD(CRList, slap_content_rule) cr_list + = LDAP_STAILQ_HEAD_INITIALIZER(cr_list); static int cr_index_cmp( @@ -35,8 +41,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 ); } @@ -48,8 +53,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 ); } @@ -99,9 +103,9 @@ cr_destroy( void ) avl_free(cr_index, ldap_memfree); - while( !LDAP_SLIST_EMPTY(&cr_list) ) { - c = LDAP_SLIST_FIRST(&cr_list); - LDAP_SLIST_REMOVE_HEAD(&cr_list, scr_next); + while( !LDAP_STAILQ_EMPTY(&cr_list) ) { + c = LDAP_STAILQ_FIRST(&cr_list); + LDAP_STAILQ_REMOVE_HEAD(&cr_list, scr_next); cr_destroy_one( c ); } @@ -116,9 +120,6 @@ cr_insert( struct cindexrec *cir; char **names; - LDAP_SLIST_NEXT( scr, scr_next ) = NULL; - LDAP_SLIST_INSERT_HEAD(&cr_list, scr, scr_next); - if ( scr->scr_oid ) { cir = (struct cindexrec *) ch_calloc( 1, sizeof(struct cindexrec) ); @@ -167,6 +168,8 @@ cr_insert( } } + LDAP_STAILQ_INSERT_TAIL(&cr_list, scr, scr_next); + return 0; } @@ -194,7 +197,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]; @@ -203,7 +210,6 @@ cr_add_auxiliaries( } scr->scr_auxiliaries[naux] = NULL; - return 0; } @@ -327,6 +333,7 @@ int cr_add( LDAPContentRule *cr, int user, + ContentRule **rscr, const char **err ) { @@ -387,18 +394,68 @@ 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); + if ( code == 0 && rscr ) + *rscr = scr; return code; } -#endif +void +cr_unparse( BerVarray *res, ContentRule *start, ContentRule *end, int sys ) +{ + ContentRule *cr; + int i, num; + struct berval bv, *bva = NULL, idx; + char ibuf[32], *ptr; + + if ( !start ) + start = LDAP_STAILQ_FIRST( &cr_list ); + + /* count the result size */ + i = 0; + for ( cr=start; cr; cr=LDAP_STAILQ_NEXT(cr, scr_next)) { + if ( sys && !(cr->scr_flags & SLAP_CR_HARDCODE)) continue; + i++; + if ( cr == end ) break; + } + if (!i) return; + + num = i; + bva = ch_malloc( (num+1) * sizeof(struct berval) ); + BER_BVZERO( bva ); + idx.bv_val = ibuf; + if ( sys ) { + idx.bv_len = 0; + ibuf[0] = '\0'; + } + i = 0; + for ( cr=start; cr; cr=LDAP_STAILQ_NEXT(cr, scr_next)) { + if ( sys && !(cr->scr_flags & SLAP_CR_HARDCODE)) continue; + if ( ldap_contentrule2bv( &cr->scr_crule, &bv ) == NULL ) { + ber_bvarray_free( bva ); + } + if ( !sys ) { + idx.bv_len = sprintf(idx.bv_val, "{%02d}", i); + } + bva[i].bv_len = idx.bv_len + bv.bv_len; + bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 ); + strcpy( bva[i].bv_val, ibuf ); + strcpy( bva[i].bv_val + idx.bv_len, bv.bv_val ); + i++; + bva[i].bv_val = NULL; + ldap_memfree( bv.bv_val ); + if ( cr == end ) break; + } + *res = bva; +} int cr_schema_info( Entry *e ) { -#ifdef SLAP_EXTENDED_SCHEMA AttributeDescription *ad_ditContentRules = slap_schema.si_ad_ditContentRules; ContentRule *cr; @@ -406,7 +463,7 @@ cr_schema_info( Entry *e ) struct berval val; struct berval nval; - LDAP_SLIST_FOREACH(cr, &cr_list, scr_next) { + LDAP_STAILQ_FOREACH(cr, &cr_list, scr_next) { if ( ldap_contentrule2bv( &cr->scr_crule, &val ) == NULL ) { return -1; } @@ -428,6 +485,5 @@ cr_schema_info( Entry *e ) } ldap_memfree( val.bv_val ); } -#endif return 0; }