diff options
Diffstat (limited to '')
-rw-r--r-- | include/winapi/sid.hpp | 43 | ||||
-rw-r--r-- | include/winapi/utils.hpp (renamed from include/winapi/workarounds.hpp) | 16 |
2 files changed, 59 insertions, 0 deletions
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 <Egor.Tensin@gmail.com> +// 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 <boost/config.hpp> + +#include <windows.h> + +#include <cstddef> +#include <string> + +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<SID*>(m_buffer.data()); } + const Impl& get_impl() const { return *reinterpret_cast<const SID*>(m_buffer.data()); } + + Buffer m_buffer; +}; + +} // namespace winapi diff --git a/include/winapi/workarounds.hpp b/include/winapi/utils.hpp index a5a3607..8e8407c 100644 --- a/include/winapi/workarounds.hpp +++ b/include/winapi/utils.hpp @@ -5,4 +5,20 @@ #pragma once +#include <windows.h> + +#include <cassert> + #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 |