# WinStd: include/WinStd/SDDL.h Source File

Loading...
Searching...
No Matches
SDDL.h
/*
SPDX-License-Identifier: MIT
Copyright © 2022-2024 Amebis
*/
#pragma once
#include "Common.h"
#include <sddl.h>
namespace winstd
{
class security_attributes : public SECURITY_ATTRIBUTES
{
WINSTD_NONCOPYABLE(security_attributes)
public:
security_attributes() noexcept
{
nLength = sizeof(SECURITY_ATTRIBUTES);
lpSecurityDescriptor = NULL;
bInheritHandle = FALSE;
}
security_attributes(_Inout_ security_attributes &&a) noexcept
{
nLength = sizeof(SECURITY_ATTRIBUTES);
lpSecurityDescriptor = a.lpSecurityDescriptor;
bInheritHandle = a.bInheritHandle;
a.lpSecurityDescriptor = NULL;
}
~security_attributes()
{
if (lpSecurityDescriptor)
LocalFree(lpSecurityDescriptor);
}
security_attributes& operator=(_Inout_ security_attributes &&a) noexcept
{
if (this != &a) {
nLength = sizeof(SECURITY_ATTRIBUTES);
if (lpSecurityDescriptor)
LocalFree(lpSecurityDescriptor);
lpSecurityDescriptor = a.lpSecurityDescriptor;
bInheritHandle = a.bInheritHandle;
a.lpSecurityDescriptor = NULL;
}
return *this;
}
};
}
#pragma warning(push)
#pragma warning(disable: 4505) // Don't warn on unused code
_Success_(return != FALSE) static BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(_In_ LPCSTR StringSecurityDescriptor, _In_ DWORD StringSDRevision, _Inout_ winstd::security_attributes &sa, _Out_opt_ PULONG SecurityDescriptorSize)
{
PSECURITY_DESCRIPTOR sd;
BOOL bResult = ConvertStringSecurityDescriptorToSecurityDescriptorA(StringSecurityDescriptor, StringSDRevision, &sd, SecurityDescriptorSize);
if (bResult) {
if (sa.lpSecurityDescriptor)
LocalFree(sa.lpSecurityDescriptor);
sa.lpSecurityDescriptor = sd;
}
return bResult;
}
_Success_(return != FALSE) static BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(_In_ LPCWSTR StringSecurityDescriptor, _In_ DWORD StringSDRevision, _Inout_ winstd::security_attributes &sa, _Out_opt_ PULONG SecurityDescriptorSize)
{
PSECURITY_DESCRIPTOR sd;
BOOL bResult = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptor, StringSDRevision, &sd, SecurityDescriptorSize);
if (bResult) {
if (sa.lpSecurityDescriptor)
LocalFree(sa.lpSecurityDescriptor);
sa.lpSecurityDescriptor = sd;
}
return bResult;
}
#pragma warning(pop)
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