diff --git a/core/logic/HandleSys.h b/core/logic/HandleSys.h index 1ca35d2b2..8e10881f3 100644 --- a/core/logic/HandleSys.h +++ b/core/logic/HandleSys.h @@ -262,4 +262,43 @@ private: Handle_t hndl; }; +struct AutoHandleIdentLocker +{ +public: + AutoHandleIdentLocker() : pSecurity(nullptr) + { + } + + AutoHandleIdentLocker(Handle_t hndl) : pSecurity(nullptr) + { + if (hndl != BAD_HANDLE) + { + if (g_HandleSys.GetHandleAccess(hndl, this->pSecurity) == HandleError_None) + { + if ((this->pSecurity[HandleAccess_Delete] & HANDLE_RESTRICT_IDENTEXCLUSIVE) == HANDLE_RESTRICT_IDENTEXCLUSIVE) + this->pSecurity = nullptr; + else + pSecurity->access[HandleAccess_Delete] |= HANDLE_RESTRICT_IDENTEXCLUSIVE; + } + } + } + + ~AutoHandleIdentLocker() + { + if (this->pSecurity) + this->pSecurity->access[HandleAccess_Delete] &= ~HANDLE_RESTRICT_IDENTEXCLUSIVE; + + this->pSecurity = nullptr; + } + +public: + AutoHandleIdentLocker &operator =(const AutoHandleIdentLocker &other) + { + ~AutoHandleIdentLocker(); + this->pSecurity = other.pSecurity; + } +private: + HandleAccess *pSecurity; +} + #endif //_INCLUDE_SOURCEMOD_HANDLESYSTEM_H_ diff --git a/public/AutoHandleRooter.h b/public/AutoHandleRooter.h index d7aae7b0a..3c93699cc 100644 --- a/public/AutoHandleRooter.h +++ b/public/AutoHandleRooter.h @@ -87,5 +87,44 @@ public: } }; +class AutoHandleIdentLocker +{ +public: + AutoHandleIdentLocker() : pSecurity(nullptr) + { + } + + AutoHandleIdentLocker(Handle_t hndl) : pSecurity(nullptr) + { + if (hndl != BAD_HANDLE) + { + if (handlesys->GetHandleAccess(hndl, this->pSecurity) == HandleError_None) + { + if ((this->pSecurity[HandleAccess_Delete] & HANDLE_RESTRICT_IDENTEXCLUSIVE) == HANDLE_RESTRICT_IDENTEXCLUSIVE) + this->pSecurity = nullptr; + else + pSecurity->access[HandleAccess_Delete] |= HANDLE_RESTRICT_IDENTEXCLUSIVE; + } + } + } + + ~AutoHandleIdentLocker() + { + if (this->pSecurity) + this->pSecurity->access[HandleAccess_Delete] &= ~HANDLE_RESTRICT_IDENTEXCLUSIVE; + + this->pSecurity = nullptr; + } + +public: + AutoHandleIdentLocker &operator =(const AutoHandleIdentLocker &other) + { + ~AutoHandleIdentLocker(); + this->pSecurity = other.pSecurity; + } +private: + HandleAccess *pSecurity; +}; + #endif /* _INCLUDE_SOURCEMOD_AUTO_HANDLE_ROOTER_H_ */