OpenVPN 3 Core Library
Loading...
Searching...
No Matches
secattr.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#pragma once
13
14// windows SECURITY_ATTRIBUTES utilities
15
16#include <windows.h>
17#include <sddl.h>
18
21
22namespace openvpn::Win {
23
25{
26 OPENVPN_EXCEPTION(win_sec_attr);
27
28 SecurityAttributes(const std::string &sddl_string,
29 const bool inherit,
30 const std::string &title)
31 {
32 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
33 sa.bInheritHandle = inherit ? TRUE : FALSE;
34 sa.lpSecurityDescriptor = nullptr;
35 if (!sddl_string.empty())
36 {
37 if (!::ConvertStringSecurityDescriptorToSecurityDescriptorA(
38 sddl_string.c_str(),
39 SDDL_REVISION_1,
40 &sa.lpSecurityDescriptor, // allocates memory
41 NULL))
42 {
43 const Win::LastError err;
44 OPENVPN_THROW(win_sec_attr, "failed to create security descriptor for " << title << " : " << err.message());
45 }
46 }
47 }
48
50 {
51 ::LocalFree(sa.lpSecurityDescriptor);
52 }
53
54 SECURITY_ATTRIBUTES sa;
55};
56
57} // namespace openvpn::Win
#define OPENVPN_THROW(exc, stuff)
SecurityAttributes(const std::string &sddl_string, const bool inherit, const std::string &title)
Definition secattr.hpp:28