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
24#include <openvpn/win/reg.hpp>
26
27namespace openvpn::Win {
28
29inline 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
41inline std::string module_name_utf8()
42{
43 return wstring::to_utf8(module_name());
44}
45
46inline 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
#define OPENVPN_THROW_EXCEPTION(stuff)
std::string module_name_utf8()
Definition modname.hpp:41
std::string omiclient_path()
Definition modname.hpp:46
std::wstring module_name()
Definition modname.hpp:29