From 512a25658dd6b737a16b91fb7eba43deef004d87 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 18 Oct 2020 04:05:48 +0300 Subject: add Sid class It's another newcomer straight from privilege-check. --- include/winapi/sid.hpp | 43 ++++++++++++++++++++++++++++++++++++++++++ include/winapi/utils.hpp | 24 +++++++++++++++++++++++ include/winapi/workarounds.hpp | 8 -------- 3 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 include/winapi/sid.hpp create mode 100644 include/winapi/utils.hpp delete mode 100644 include/winapi/workarounds.hpp (limited to 'include/winapi') diff --git a/include/winapi/sid.hpp b/include/winapi/sid.hpp new file mode 100644 index 0000000..f418b89 --- /dev/null +++ b/include/winapi/sid.hpp @@ -0,0 +1,43 @@ +// Copyright (c) 2020 Egor Tensin +// This file is part of the "winapi-common" project. +// For details, see https://github.com/egor-tensin/winapi-common. +// Distributed under the MIT License. + +#pragma once + +#include "buffer.hpp" + +#include + +#include + +#include +#include + +namespace winapi { + +class Sid { +public: + BOOST_STATIC_CONSTEXPR std::size_t MAX_SID_SIZE = SECURITY_MAX_SID_SIZE; + + typedef SID Impl; + + static Sid well_known(WELL_KNOWN_SID_TYPE type); + + static Sid builtin_administrators(); + + explicit Sid(const Buffer& buffer) : m_buffer(buffer) {} + + explicit operator SID&() { return get_impl(); } + explicit operator const SID&() const { return get_impl(); } + + std::string to_string() const; + +private: + Impl& get_impl() { return *reinterpret_cast(m_buffer.data()); } + const Impl& get_impl() const { return *reinterpret_cast(m_buffer.data()); } + + Buffer m_buffer; +}; + +} // namespace winapi diff --git a/include/winapi/utils.hpp b/include/winapi/utils.hpp new file mode 100644 index 0000000..8e8407c --- /dev/null +++ b/include/winapi/utils.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2020 Egor Tensin +// This file is part of the "winapi-common" project. +// For details, see https://github.com/egor-tensin/winapi-common. +// Distributed under the MIT License. + +#pragma once + +#include + +#include + +#define WINAPI_UNUSED_PARAMETER(...) (void)(__VA_ARGS__) + +namespace winapi { + +struct LocalDelete { + void operator()(void* ptr) const { + const auto ret = ::LocalFree(ptr); + assert(ret == NULL); + WINAPI_UNUSED_PARAMETER(ret); + } +}; + +} // namespace winapi diff --git a/include/winapi/workarounds.hpp b/include/winapi/workarounds.hpp deleted file mode 100644 index a5a3607..0000000 --- a/include/winapi/workarounds.hpp +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2020 Egor Tensin -// This file is part of the "winapi-common" project. -// For details, see https://github.com/egor-tensin/winapi-common. -// Distributed under the MIT License. - -#pragma once - -#define WINAPI_UNUSED_PARAMETER(...) (void)(__VA_ARGS__) -- cgit v1.2.3