X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-bdb%2Fcompare.c;h=bf8b5146158a18423eebd9253e3b599e52c3d714;hb=f96e6378d6cd06c744a47af5e5e551cbb494826a;hp=d44c26ac6f15e24bcdaaa4c87ddd41ad1405ba2b;hpb=a8e859a40124ecf94e31837b1963b07fe5a9d4f6;p=openldap diff --git a/servers/slapd/back-bdb/compare.c b/servers/slapd/back-bdb/compare.c index d44c26ac6f..bf8b514615 100644 --- a/servers/slapd/back-bdb/compare.c +++ b/servers/slapd/back-bdb/compare.c @@ -1,8 +1,17 @@ /* compare.c - bdb backend compare routine */ /* $OpenLDAP$ */ -/* - * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 2000-2006 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" @@ -11,7 +20,6 @@ #include #include "back-bdb.h" -#include "external.h" int bdb_compare( Operation *op, SlapReply *rs ) @@ -36,7 +44,8 @@ bdb_compare( Operation *op, SlapReply *rs ) dn2entry_retry: /* get entry */ - rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1, locker, &lock ); + rs->sr_err = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1, + locker, &lock ); switch( rs->sr_err ) { case DB_NOTFOUND: @@ -57,19 +66,32 @@ dn2entry_retry: e = ei->bei_e; if ( rs->sr_err == DB_NOTFOUND ) { if ( e != NULL ) { - rs->sr_matched = ch_strdup( e->e_dn ); - rs->sr_ref = is_entry_referral( e ) - ? get_entry_referrals( op, e ) - : NULL; +#ifdef SLAP_ACL_HONOR_DISCLOSE + /* return referral only if "disclose" is granted on the object */ + if ( ! access_allowed( op, e, slap_schema.si_ad_entry, + NULL, ACL_DISCLOSE, NULL ) ) + { + rs->sr_err = LDAP_NO_SUCH_OBJECT; + + } else +#endif /* SLAP_ACL_HONOR_DISCLOSE */ + { + rs->sr_matched = ch_strdup( e->e_dn ); + rs->sr_ref = is_entry_referral( e ) + ? get_entry_referrals( op, e ) + : NULL; + rs->sr_err = LDAP_REFERRAL; + } + bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock ); e = NULL; } else { rs->sr_ref = referral_rewrite( default_referral, NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT ); + rs->sr_err = rs->sr_ref ? LDAP_REFERRAL : LDAP_NO_SUCH_OBJECT; } - rs->sr_err = LDAP_REFERRAL; send_ldap_result( op, rs ); ber_bvarray_free( rs->sr_ref ); @@ -81,19 +103,23 @@ dn2entry_retry: } if (!manageDSAit && is_entry_referral( e ) ) { - /* entry is a referral, don't allow add */ - rs->sr_ref = get_entry_referrals( op, e ); - -#ifdef NEW_LOGGING - LDAP_LOG ( OPERATION, DETAIL1, - "bdb_compare: entry is referral\n", 0, 0, 0 ); -#else - Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0, - 0, 0 ); -#endif - - rs->sr_err = LDAP_REFERRAL; - rs->sr_matched = e->e_name.bv_val; +#ifdef SLAP_ACL_HONOR_DISCLOSE + /* return referral only if "disclose" is granted on the object */ + if ( !access_allowed( op, e, slap_schema.si_ad_entry, + NULL, ACL_DISCLOSE, NULL ) ) + { + rs->sr_err = LDAP_NO_SUCH_OBJECT; + } else +#endif /* SLAP_ACL_HONOR_DISCLOSE */ + { + /* entry is a referral, don't allow compare */ + rs->sr_ref = get_entry_referrals( op, e ); + rs->sr_err = LDAP_REFERRAL; + rs->sr_matched = e->e_name.bv_val; + } + + Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0, 0, 0 ); + send_ldap_result( op, rs ); ber_bvarray_free( rs->sr_ref ); @@ -105,29 +131,50 @@ dn2entry_retry: if ( get_assert( op ) && ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE )) { - rs->sr_err = LDAP_ASSERTION_FAILED; +#ifdef SLAP_ACL_HONOR_DISCLOSE + if ( !access_allowed( op, e, slap_schema.si_ad_entry, + NULL, ACL_DISCLOSE, NULL ) ) + { + rs->sr_err = LDAP_NO_SUCH_OBJECT; + } else +#endif /* SLAP_ACL_HONOR_DISCLOSE */ + { + rs->sr_err = LDAP_ASSERTION_FAILED; + } goto return_results; } - rs->sr_err = access_allowed( op, e, op->oq_compare.rs_ava->aa_desc, - &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL ); - if ( ! rs->sr_err ) { - rs->sr_err = LDAP_INSUFFICIENT_ACCESS; + if ( !access_allowed( op, e, op->oq_compare.rs_ava->aa_desc, + &op->oq_compare.rs_ava->aa_value, ACL_COMPARE, NULL ) ) + { +#ifdef SLAP_ACL_HONOR_DISCLOSE + /* return error only if "disclose" + * is granted on the object */ + if ( !access_allowed( op, e, slap_schema.si_ad_entry, + NULL, ACL_DISCLOSE, NULL ) ) + { + rs->sr_err = LDAP_NO_SUCH_OBJECT; + } else +#endif /* SLAP_ACL_HONOR_DISCLOSE */ + { + rs->sr_err = LDAP_INSUFFICIENT_ACCESS; + } goto return_results; } rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE; - for(a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc ); + for ( a = attrs_find( e->e_attrs, op->oq_compare.rs_ava->aa_desc ); a != NULL; - a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc )) + a = attrs_find( a->a_next, op->oq_compare.rs_ava->aa_desc ) ) { rs->sr_err = LDAP_COMPARE_FALSE; if ( value_find_ex( op->oq_compare.rs_ava->aa_desc, SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH, - a->a_nvals, &op->oq_compare.rs_ava->aa_value, op->o_tmpmemctx ) == 0 ) + a->a_nvals, &op->oq_compare.rs_ava->aa_value, + op->o_tmpmemctx ) == 0 ) { rs->sr_err = LDAP_COMPARE_TRUE; break; @@ -137,17 +184,20 @@ dn2entry_retry: return_results: send_ldap_result( op, rs ); - if( rs->sr_err == LDAP_COMPARE_FALSE || rs->sr_err == LDAP_COMPARE_TRUE ) { + switch ( rs->sr_err ) { + case LDAP_COMPARE_FALSE: + case LDAP_COMPARE_TRUE: rs->sr_err = LDAP_SUCCESS; + break; } done: /* free entry */ - if( e != NULL ) { - bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock ); + if ( e != NULL ) { + bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, + e, &lock ); } LOCK_ID_FREE ( bdb->bi_dbenv, locker ); - return rs->sr_err; }