winapi_common
sid.hpp
1 // Copyright (c) 2020 Egor Tensin <Egor.Tensin@gmail.com>
2 // This file is part of the "winapi-common" project.
3 // For details, see https://github.com/egor-tensin/winapi-common.
4 // Distributed under the MIT License.
5 
6 #pragma once
7 
8 #include "buffer.hpp"
9 
10 #include <windows.h>
11 
12 #include <cstddef>
13 #include <string>
14 
15 namespace winapi {
16 
17 class Sid {
18 public:
19  static constexpr std::size_t MAX_SID_SIZE = SECURITY_MAX_SID_SIZE;
20 
21  typedef SID Impl;
22 
23  static Sid well_known(WELL_KNOWN_SID_TYPE type);
24 
25  static Sid builtin_administrators();
26 
27  explicit Sid(const Buffer& buffer) : m_buffer(buffer) {}
28 
29  explicit operator SID&() { return get_impl(); }
30  explicit operator const SID&() const { return get_impl(); }
31 
32  std::string to_string() const;
33 
34 private:
35  Impl& get_impl() { return *reinterpret_cast<SID*>(m_buffer.data()); }
36  const Impl& get_impl() const { return *reinterpret_cast<const SID*>(m_buffer.data()); }
37 
38  Buffer m_buffer;
39 };
40 
41 } // namespace winapi
Binary data container.
Definition: buffer.hpp:24