Add AutoHandleIdentLocker to pub/internal API

This commit is contained in:
Kyle Sanderson 2019-07-21 08:33:10 -07:00
parent 45dd841330
commit 60841f42b7
2 changed files with 78 additions and 0 deletions

View File

@ -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_

View File

@ -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_ */