X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fcr.c;h=19c0bfa7cd4b8c1d1af6ba1a5dd4b0a0245519b6;hb=01c38dd6ea7f02cfdc9f77f9299771a4ef6ce968;hp=eb9178d7e7f90b55c0be1c0c35110385042b3ce0;hpb=119cbcaba43185e483b74b359e56fcf5d921404f;p=openldap diff --git a/servers/slapd/cr.c b/servers/slapd/cr.c index eb9178d7e7..19c0bfa7cd 100644 --- a/servers/slapd/cr.c +++ b/servers/slapd/cr.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2005 The OpenLDAP Foundation. + * Copyright 1998-2006 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -127,8 +127,8 @@ cr_insert( cir->cir_name.bv_len = strlen( scr->scr_oid ); cir->cir_cr = scr; - assert( cir->cir_name.bv_val ); - assert( cir->cir_cr ); + assert( cir->cir_name.bv_val != NULL ); + assert( cir->cir_cr != NULL ); if ( avl_insert( &cr_index, (caddr_t) cir, cr_index_cmp, avl_dup_error ) ) @@ -150,8 +150,8 @@ cr_insert( cir->cir_name.bv_len = strlen( *names ); cir->cir_cr = scr; - assert( cir->cir_name.bv_val ); - assert( cir->cir_cr ); + assert( cir->cir_name.bv_val != NULL ); + assert( cir->cir_cr != NULL ); if ( avl_insert( &cr_index, (caddr_t) cir, cr_index_cmp, avl_dup_error ) ) @@ -340,6 +340,7 @@ cr_add( ContentRule *scr; int code; int op = 0; + char *oidm = NULL; if ( cr->cr_names != NULL ) { int i; @@ -359,7 +360,7 @@ cr_add( return SLAP_SCHERR_OIDM; } if ( oid != cr->cr_oid ) { - ldap_memfree( cr->cr_oid ); + oidm = cr->cr_oid; cr->cr_oid = oid; } } @@ -367,41 +368,48 @@ cr_add( scr = (ContentRule *) ch_calloc( 1, sizeof(ContentRule) ); AC_MEMCPY( &scr->scr_crule, cr, sizeof(LDAPContentRule) ); + scr->scr_oidmacro = oidm; scr->scr_sclass = oc_find(cr->cr_oid); if ( !scr->scr_sclass ) { *err = cr->cr_oid; - return SLAP_SCHERR_CLASS_NOT_FOUND; + code = SLAP_SCHERR_CLASS_NOT_FOUND; + goto fail; } /* check object class usage */ if( scr->scr_sclass->soc_kind != LDAP_SCHEMA_STRUCTURAL ) { *err = cr->cr_oid; - return SLAP_SCHERR_CR_BAD_STRUCT; + code = SLAP_SCHERR_CR_BAD_STRUCT; + goto fail; } if( scr->scr_sclass->soc_flags & SLAP_OC_OPERATIONAL ) op++; code = cr_add_auxiliaries( scr, &op, err ); - if ( code != 0 ) return code; + if ( code != 0 ) goto fail; code = cr_create_required( scr, &op, err ); - if ( code != 0 ) return code; + if ( code != 0 ) goto fail; code = cr_create_allowed( scr, &op, err ); - if ( code != 0 ) return code; + if ( code != 0 ) goto fail; code = cr_create_precluded( scr, &op, err ); - if ( code != 0 ) return code; + if ( code != 0 ) goto fail; if( user && op ) { - return SLAP_SCHERR_CR_BAD_AUX; + code = SLAP_SCHERR_CR_BAD_AUX; + goto fail; } code = cr_insert(scr,err); if ( code == 0 && rscr ) *rscr = scr; return code; +fail: + ch_free( scr ); + return code; } void @@ -410,16 +418,17 @@ 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; + char ibuf[32]; if ( !start ) start = LDAP_STAILQ_FIRST( &cr_list ); /* count the result size */ i = 0; - for ( cr=start; cr && cr!=end; cr=LDAP_STAILQ_NEXT(cr, scr_next)) { + 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; @@ -432,13 +441,21 @@ cr_unparse( BerVarray *res, ContentRule *start, ContentRule *end, int sys ) ibuf[0] = '\0'; } i = 0; - for ( cr=start; cr && cr!=end; cr=LDAP_STAILQ_NEXT(cr, scr_next)) { + for ( cr=start; cr; cr=LDAP_STAILQ_NEXT(cr, scr_next)) { + LDAPContentRule lcr, *lcrp; if ( sys && !(cr->scr_flags & SLAP_CR_HARDCODE)) continue; - if ( ldap_contentrule2bv( &cr->scr_crule, &bv ) == NULL ) { + if ( cr->scr_oidmacro ) { + lcr = cr->scr_crule; + lcr.cr_oid = cr->scr_oidmacro; + lcrp = &lcr; + } else { + lcrp = &cr->scr_crule; + } + if ( ldap_contentrule2bv( lcrp, &bv ) == NULL ) { ber_bvarray_free( bva ); } if ( !sys ) { - idx.bv_len = sprintf(idx.bv_val, "{%02d}", i); + idx.bv_len = sprintf(idx.bv_val, "{%d}", i); } bva[i].bv_len = idx.bv_len + bv.bv_len; bva[i].bv_val = ch_malloc( bva[i].bv_len + 1 ); @@ -447,6 +464,7 @@ cr_unparse( BerVarray *res, ContentRule *start, ContentRule *end, int sys ) i++; bva[i].bv_val = NULL; ldap_memfree( bv.bv_val ); + if ( cr == end ) break; } *res = bva; }