OpenVPN 3 Core Library
Loading...
Searching...
No Matches
agentconfig.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// OVPNAGENT_NAME can be passed on build command line.
15// Customized agent name is needed with purpose to install
16// few app with agents on one OS (e.g OC 3.0 and PT)
17#ifdef OVPNAGENT_NAME
18#define OVPNAGENT_NAME_STRING OPENVPN_STRINGIZE(OVPNAGENT_NAME)
19#else
20#define OVPNAGENT_NAME_STRING "ovpnagent"
21#endif
22
25
26namespace openvpn {
27class Agent
28{
29 public:
30 static std::string named_pipe_path()
31 {
32 return "\\\\.\\pipe\\" OVPNAGENT_NAME_STRING;
33 }
34
35 static bool valid_pipe(const std::string &client_exe,
36 const std::string &server_exe)
37 {
38#ifdef OVPNAGENT_DISABLE_PATH_CHECK
39 return true;
40#else
41 return normalize_exe_path(client_exe) == normalize_exe_path(server_exe);
42#endif
43 }
44
45 private:
46 // If path starts with C:\..., lower-case the drive letter.
47 // Then strip off the basename and only return the dir.
48 static std::string normalize_exe_path(const std::string &path)
49 {
50 std::string p;
51 if (path.length() >= 3
52 && std::isalpha(static_cast<unsigned char>(path[0])) != 0
53 && path[1] == ':'
54 && path[2] == '\\')
55 p = string::to_lower_copy(path.substr(0, 3)) + path.substr(3);
56 else
57 p = path;
58 p = path::dirname(p);
59 return p;
60 }
61};
62} // namespace openvpn
static std::string named_pipe_path()
static bool valid_pipe(const std::string &client_exe, const std::string &server_exe)
static std::string normalize_exe_path(const std::string &path)
std::string dirname(const std::string &path)
Definition path.hpp:91
std::string to_lower_copy(const std::string &str)
Definition string.hpp:587
#define OVPNAGENT_NAME_STRING
Definition cmdagent.hpp:33