From 4ee9021adbb10140c30d6027a97e4748cb2f5903 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 1 Nov 2013 04:58:38 -0400 Subject: Compare access entries created with the levels access system by access level and not by privilege set, as two entries can have the same privset but different levels, but still represent two different levels of access. This prevented users from adding other users at a lower access level when that level had the same privset as them. Spotted by TSG. --- include/access.h | 4 ++-- include/anope.h | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/access.h b/include/access.h index 19b6b3b02..cb24a6030 100644 --- a/include/access.h +++ b/include/access.h @@ -123,8 +123,8 @@ class CoreExport ChanAccess : public Serializable virtual void AccessUnserialize(const Anope::string &data) = 0; /* Comparison operators to other Access entries */ - bool operator>(const ChanAccess &other) const; - bool operator<(const ChanAccess &other) const; + virtual bool operator>(const ChanAccess &other) const; + virtual bool operator<(const ChanAccess &other) const; bool operator>=(const ChanAccess &other) const; bool operator<=(const ChanAccess &other) const; }; diff --git a/include/anope.h b/include/anope.h index 51ece1cd6..07ed29ebf 100644 --- a/include/anope.h +++ b/include/anope.h @@ -762,17 +762,31 @@ template inline T convertTo(const Anope::string &s, bool failIfLefto */ #ifdef DEBUG_BUILD # include -#endif -template inline T anope_dynamic_static_cast(O ptr) + +template inline T anope_dynamic_static_cast(O* ptr) { -#ifdef DEBUG_BUILD T ret = dynamic_cast(ptr); if (ptr != NULL && ret == NULL) - throw CoreException(Anope::string("anope_dynamic_static_cast<") + typeid(T).name() + ">(" + typeid(O).name() + ") fail"); + throw CoreException(Anope::string("anope_dynamic_static_cast<") + typeid(T).name() + ">(" + typeid(O*).name() + ") fail"); return ret; +} + +template inline T anope_dynamic_static_cast(O& ref) +{ + try + { + return dynamic_cast(ref); + } + catch (const std::bad_cast &ex) + { + throw CoreException(Anope::string("std::bad_cast from anope_dynamic_static_cast<") + typeid(T).name() + ">(" + typeid(O&).name() + "): " + ex.what()); + } +} #else +template inline T anope_dynamic_static_cast(O ptr) +{ return static_cast(ptr); -#endif } +#endif #endif // ANOPE_H -- cgit