aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/winapi/sid.hpp
blob: eeb603543a93d50f94b872fd7319120db998a511 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2020 Egor Tensin <egor@tensin.name>
// 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 <windows.h>

#include <cstddef>
#include <string>

namespace winapi {

class Sid {
public:
    static constexpr std::size_t MAX_SID_SIZE = SECURITY_MAX_SID_SIZE;

    using Impl = SID;

    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