From ea2b675dca28771341fcaf04d5dffd480af0f516 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Thu, 30 Dec 2010 23:29:46 +0000 Subject: [PATCH] ITS#6758 Add rs_assert*, RS_ASSERT, USE_RS_ASSERT --- servers/slapd/proto-slap.h | 13 ++++++++- servers/slapd/result.c | 59 +++++++++++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 27e6d3945d..489b61c064 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1537,6 +1537,18 @@ LDAP_SLAPD_F (int) get_alias_dn LDAP_P(( /* * result.c */ +#if USE_RS_ASSERT /*defined(USE_RS_ASSERT)?(USE_RS_ASSERT):defined(LDAP_TEST)*/ +# define RS_ASSERT assert +#else +# define RS_ASSERT(cond) ((void) 0) +# define rs_assert_ok(rs) ((void) (rs)) +# define rs_assert_ready(rs) ((void) (rs)) +# define rs_assert_done(rs) ((void) (rs)) +#endif +LDAP_SLAPD_F (void) (rs_assert_ok) LDAP_P(( const SlapReply *rs )); +LDAP_SLAPD_F (void) (rs_assert_ready) LDAP_P(( const SlapReply *rs )); +LDAP_SLAPD_F (void) (rs_assert_done) LDAP_P(( const SlapReply *rs )); + LDAP_SLAPD_F (void) rs_replace_entry LDAP_P(( Operation *op, SlapReply *rs, slap_overinst *on, Entry *e )); LDAP_SLAPD_F (int) rs_ensure_entry_modifiable LDAP_P(( Operation *op, @@ -2146,4 +2158,3 @@ LDAP_SLAPD_F (int) fe_access_allowed LDAP_P(( LDAP_END_DECL #endif /* PROTO_SLAP_H */ - diff --git a/servers/slapd/result.c b/servers/slapd/result.c index 7c1ec249de..e8fa1262d0 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -132,12 +132,63 @@ slap_req2res( ber_tag_t tag ) return tag; } -#ifdef RS_ASSERT -#elif 0 && defined LDAP_DEVEL /* FIXME: this should not crash. ITS#5340. */ -#define RS_ASSERT assert +/* SlapReply debugging, prodo-slap.h overrides it in OpenLDAP releases */ +#if defined(LDAP_TEST) || (defined(USE_RS_ASSERT) && (USE_RS_ASSERT)) +void +(rs_assert_ok)( const SlapReply *rs ) +{ + const slap_mask_t flags = rs->sr_flags; + + if ( flags & REP_ENTRY_MASK ) { + RS_ASSERT( !(flags & REP_ENTRY_MUSTRELEASE) + || !(flags & (REP_ENTRY_MASK ^ REP_ENTRY_MUSTRELEASE)) ); + RS_ASSERT( rs->sr_entry != NULL ); + RS_ASSERT( (1 << rs->sr_type) & + ((1 << REP_SEARCH) | (1 << REP_SEARCHREF) | + (1 << REP_RESULT) | (1 << REP_GLUE_RESULT)) ); + } +#if defined(USE_RS_ASSERT) && (USE_RS_ASSERT) > 1 /* TODO: Enable when safe */ + if ( (flags & (REP_MATCHED_MASK | REP_REF_MASK | REP_CTRLS_MASK)) ) { + RS_ASSERT( !(flags & REP_MATCHED_MASK) || rs->sr_matched ); + RS_ASSERT( !(flags & REP_CTRLS_MASK ) || rs->sr_ctrls ); + /* Note: LDAP_REFERRAL + !sr_ref is OK, becomes LDAP_NO_SUCH_OBJECT */ + } +#if (USE_RS_ASSERT) > 2 + if ( rs->sr_err == LDAP_SUCCESS ) { + RS_ASSERT( rs->sr_text == NULL ); + RS_ASSERT( rs->sr_matched == NULL ); + } +#endif +#endif +} +void +(rs_assert_ready)( const SlapReply *rs ) +{ + RS_ASSERT( !rs->sr_entry ); +#if defined(USE_RS_ASSERT) && (USE_RS_ASSERT) > 1 /* TODO: Enable when safe */ + RS_ASSERT( !rs->sr_text ); + RS_ASSERT( !rs->sr_ref ); + RS_ASSERT( !rs->sr_matched ); + RS_ASSERT( !rs->sr_ctrls ); + RS_ASSERT( !rs->sr_flags ); +#if (USE_RS_ASSERT) > 2 + RS_ASSERT( rs->sr_err == LDAP_SUCCESS ); +#endif #else -#define RS_ASSERT(cond) ((void) 0) + RS_ASSERT( !(rs->sr_flags & REP_ENTRY_MASK) ); #endif +} +void +(rs_assert_done)( const SlapReply *rs ) +{ +#if defined(USE_RS_ASSERT) && (USE_RS_ASSERT) > 1 /* TODO: Enable when safe */ + RS_ASSERT( !(rs->sr_flags & ~(REP_ENTRY_MODIFIABLE|REP_NO_OPERATIONALS)) ); + rs_assert_ok( rs ); +#else + RS_ASSERT( !(rs->sr_flags & REP_ENTRY_MUSTFLUSH) ); +#endif +} +#endif /* LDAP_TEST || USE_RS_ASSERT */ /* Set rs->sr_entry after obyeing and clearing sr_flags & REP_ENTRY_MASK. */ void -- 2.39.5