OpenVPN 3 Core Library
Loading...
Searching...
No Matches
modname.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
// windows SECURITY_ATTRIBUTES utilities
13
14
#ifndef OPENVPN_WIN_MODNAME_H
15
#define OPENVPN_WIN_MODNAME_H
16
17
#include <windows.h>
18
19
#include <string>
20
21
#include <
openvpn/common/exception.hpp
>
22
#include <
openvpn/common/wstring.hpp
>
23
#include <
openvpn/win/winerr.hpp
>
24
#include <
openvpn/win/reg.hpp
>
25
#include <
openvpn/win/npinfo.hpp
>
26
27
namespace
openvpn::Win
{
28
29
inline
std::wstring
module_name
()
30
{
31
// get path to our binary
32
wchar_t
path[MAX_PATH];
33
if
(!::GetModuleFileNameW(NULL, path, MAX_PATH))
34
{
35
const
Win::LastError
err;
36
OPENVPN_THROW_EXCEPTION
(
"GetModuleFileNameW failed: "
<< err.message());
37
}
38
return
std::wstring(path);
39
}
40
41
inline
std::string
module_name_utf8
()
42
{
43
return
wstring::to_utf8(
module_name
());
44
}
45
46
inline
std::string
omiclient_path
()
47
{
48
char
strbuf[256] = {0};
49
DWORD len =
sizeof
(strbuf);
50
DWORD data_type;
51
auto
status = ::RegGetValueA(HKEY_LOCAL_MACHINE,
52
"SOFTWARE\\OpenVPN"
,
53
"omi_exe_path"
,
54
RRF_RT_REG_SZ,
55
&data_type,
56
(LPBYTE)strbuf,
57
&len);
58
59
if
(status != ERROR_SUCCESS)
60
{
61
const
Win::Error
err(status);
62
OPENVPN_THROW_EXCEPTION
(
"Cannot read HKLM\\SOFTWARE\\OpenVPN\\omi_exe_path: "
<< err.message());
63
}
64
65
return
strbuf;
66
}
67
}
// namespace openvpn::Win
68
69
#endif
exception.hpp
OPENVPN_THROW_EXCEPTION
#define OPENVPN_THROW_EXCEPTION(stuff)
Definition
exception.hpp:166
openvpn::Win
Definition
call.hpp:27
openvpn::Win::module_name_utf8
std::string module_name_utf8()
Definition
modname.hpp:41
openvpn::Win::omiclient_path
std::string omiclient_path()
Definition
modname.hpp:46
openvpn::Win::module_name
std::wstring module_name()
Definition
modname.hpp:29
npinfo.hpp
reg.hpp
openvpn::Win::Error
Definition
winerr.hpp:23
openvpn::Win::LastError
Definition
winerr.hpp:31
winerr.hpp
wstring.hpp
openvpn
win
modname.hpp
Generated by
1.9.8