WinStd Windows Win32 API using Standard C++

Loading...
Searching...
No Matches
SDDL.h
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 2022-2024 Amebis
4*/
5
7
8#pragma once
9
10#include "Common.h"
11#include <sddl.h>
12
13 namespace winstd
14{
17
18 class security_attributes : public SECURITY_ATTRIBUTES
19 {
20 WINSTD_NONCOPYABLE(security_attributes)
21
22 public:
26 security_attributes() noexcept
27 {
28 nLength = sizeof(SECURITY_ATTRIBUTES);
29 lpSecurityDescriptor = NULL;
30 bInheritHandle = FALSE;
31 }
32
36 security_attributes(_Inout_ security_attributes &&a) noexcept
37 {
38 nLength = sizeof(SECURITY_ATTRIBUTES);
39 lpSecurityDescriptor = a.lpSecurityDescriptor;
40 bInheritHandle = a.bInheritHandle;
41 a.lpSecurityDescriptor = NULL;
42 }
43
47 ~security_attributes()
48 {
49 if (lpSecurityDescriptor)
50 LocalFree(lpSecurityDescriptor);
51 }
52
56 security_attributes& operator=(_Inout_ security_attributes &&a) noexcept
57 {
58 if (this != &a) {
59 nLength = sizeof(SECURITY_ATTRIBUTES);
60 if (lpSecurityDescriptor)
61 LocalFree(lpSecurityDescriptor);
62 lpSecurityDescriptor = a.lpSecurityDescriptor;
63 bInheritHandle = a.bInheritHandle;
64 a.lpSecurityDescriptor = NULL;
65 }
66 return *this;
67 }
68 };
69
71}
72
75
76#pragma warning(push)
77#pragma warning(disable: 4505) // Don't warn on unused code
78
80_Success_(return != FALSE) static BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(_In_ LPCSTR StringSecurityDescriptor, _In_ DWORD StringSDRevision, _Inout_ winstd::security_attributes &sa, _Out_opt_ PULONG SecurityDescriptorSize)
81{
82 PSECURITY_DESCRIPTOR sd;
83 BOOL bResult = ConvertStringSecurityDescriptorToSecurityDescriptorA(StringSecurityDescriptor, StringSDRevision, &sd, SecurityDescriptorSize);
84 if (bResult) {
85 if (sa.lpSecurityDescriptor)
86 LocalFree(sa.lpSecurityDescriptor);
87 sa.lpSecurityDescriptor = sd;
88 }
89 return bResult;
90}
91
97_Success_(return != FALSE) static BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(_In_ LPCWSTR StringSecurityDescriptor, _In_ DWORD StringSDRevision, _Inout_ winstd::security_attributes &sa, _Out_opt_ PULONG SecurityDescriptorSize)
98{
99 PSECURITY_DESCRIPTOR sd;
100 BOOL bResult = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptor, StringSDRevision, &sd, SecurityDescriptorSize);
101 if (bResult) {
102 if (sa.lpSecurityDescriptor)
103 LocalFree(sa.lpSecurityDescriptor);
104 sa.lpSecurityDescriptor = sd;
105 }
106 return bResult;
107}
108
109#pragma warning(pop)
110
winstd::ref_unique_ptr
Helper class for returning pointers to std::unique_ptr.
Definition Common.h:863
winstd::security_attributes
Definition SDDL.h:19
winstd::security_attributes::security_attributes
security_attributes(security_attributes &&a) noexcept
Moves an existing SECURITY_ATTRIBUTES.
Definition SDDL.h:36
winstd::security_attributes::~security_attributes
~security_attributes()
Destroys the SECURITY_ATTRIBUTES.
Definition SDDL.h:47
winstd::security_attributes::operator=
security_attributes & operator=(security_attributes &&a) noexcept
Moves an existing SECURITY_ATTRIBUTES.
Definition SDDL.h:56
winstd::security_attributes::security_attributes
security_attributes() noexcept
Initializes a new SECURITY_ATTRIBUTES.
Definition SDDL.h:26
WINSTD_NONCOPYABLE
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition Common.h:67
ConvertStringSecurityDescriptorToSecurityDescriptorA
static BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(LPCSTR StringSecurityDescriptor, DWORD StringSDRevision, winstd::security_attributes &sa, PULONG SecurityDescriptorSize)
Converts a string-format security descriptor into a valid, functional security descriptor.
Definition SDDL.h:80
ConvertStringSecurityDescriptorToSecurityDescriptorW
static BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(LPCWSTR StringSecurityDescriptor, DWORD StringSDRevision, winstd::security_attributes &sa, PULONG SecurityDescriptorSize)
Converts a string-format security descriptor into a valid, functional security descriptor.
Definition SDDL.h:97