mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
Squashed 'Sources/OpenVPNAdapter/Libraries/Vendors/openvpn/' changes from 275cf80efb..7db7a009b0
7db7a009b0 proto: Client complains about stub compressors 390154d0e4 Update Build instructions for OSX 1b92069834 deps: Update to mbedtls-2.7.12 8cab79540d compression: Extend compression alert to include server pushes 67b4641a99 CompressContext: Add is_any_stub() method cdf9e7bece compression: Issue an Event if compression is activated fa38064403 build script: added a new PROF type "auto" that tries to automatically determine the local platform 7ce7b52b7c MTRand: added OPENVPN_INSECURE_RANDOM compile flag that allows MTRand to masquerade as a secure RNG 85e7e49f72 MTRand: added constructor accepting an initialization seed 1fa3229a10 IPv4, IPv6: added #include <openvpn/common/hash.hpp> 48e9217d26 vcxproj: add missing header file d2a2601b2f Wintun: unmap ring buffers e320bc63ff openssl: Improve OpenSSLContext fencing against multiple declarations 2f8fe2d318 openssl: Missing inline keyword in a couple of compat functions 32b984c0ff enum_dir: use a function template 725ee04593 VPNServerNetblock::Netblock::to_string(): show prefix_len 409d1c52b8 ManClientInstance::Send::describe_user(): added bool show_userprop parameter e05fc16b20 string::indent(): try to fix all the corner cases 4e1645ea80 RunContext: mark virtual Stop* async_stop() with override attribute e8b31c5454 cli: advertise "openurl" as supported SSO method 80b45731eb ICMPv6: added DEST_UNREACH code 679003094d AsioTimerSafe: refactor to allow as drop-in replacement for AsioTimer f7845578f1 RunContext: check for halt in timer closure 84483eda25 AsioPolySock: add support for socket shutdown 1b3402aec3 tcplinkcommon.hpp: added missing include 2e26c7565c time: added nanotime_t typedef c3c8ab7f6b string: added additional detail to split() comment 95ce4f22c8 string: added to_delim() method then redefined first_line() method to use it 448218b1e1 string: added add_leading() method e3b0bf4f5c MSF iterator: allow conversion from ordinary iterator and added exists() method 11412ac50a AsioPolySock: in remote_endpoint_str() method, test for alt_routing_enabled() 9fb4e705f9 Added TimeSkew to skew a time duration by a random flux 7496383002 write_binary_atomic: reduce the length of the temporary filename b31d9c0191 auth-token-user: increase size limit to 340 chars c82644c03a Added BufferLineIterator 115cb656b6 RandomAPI: added randbyte() and randbool() methods 4fa8348689 RunContext: ASIO SIGNAL message now shows signal name rather than number ebfce58513 Added StaticBuffer, a constant-length Buffer for writing that cannot be extended c8f9cb88a4 string::split(): call reserve() on return vector f15e566065 read_binary_unix_fast: should return an int (i.e. errno), not a bool 60501b4513 random: factor out rand32_distribute() from RandomAPI::randrange32() 90123495a5 wintun: get device interfaces list only once ec790df73b wintun: read packets in bulk 0f85d3f729 wintun: use correct io_context when performing initial read a6151cdeab wintun: use auto-reset events 29acfd95f3 libs: update ASIO to 1.14.0 438a0ef287 Remove outdated and unused android build files e9df57969f Merge remote-tracking branch 'origin/released' 44725ad094 ssl: Fix building with OpenSSL 1.0.2 efe3f1f635 version: Reset version reference for git master 8c79c06d94 Make tls-crypt/tls-cryptv2 compile with multiple compilation units 4d18aaeb88 Fix LLVM warnings reported during OS X build 8c9496bb4d Use const_cast for SSL_session_reused 33be562a39 Add missing override keywords to openssl/sslctx.hpp 2c5435a000 dcocli: use compile time define for Tun methods instead of hardcoded iproute 7c39088f00 Allow overriding reported HW_ADDR and support IV_PLAT_VER 7bb1ea19ee Move sending IV_UI_VER and IV_SSO to build_peer_info 23959fa705 Add reporting of IV_SSL_VER 63ab5b5e46 Only initialise static member in OpenSSLContext once ecebb40304 Merge remote-tracking branch 'origin/qa' 52c9702502 wintun: replace volatiles with atomics d720c7104c appveyor: install Strawberry perl 60a253a7ef appveyor: update to VS2019 48f2b5100b wintun: support for privilege separation 6f266be3d8 wintun: ring buffers support baa1ce2ccf vcxproj: bump VS version to 2019 98bfd037e3 tun/win: factor out ClientConfig into separate header aeb5ce0ad7 wintun: open device with SetupAPI 3998d303ce Finalizing the OpenVPN 3 Core library 3.3 release 728733aee7 deps/mbedtls: rebase "enable unsupported critical extensions" patch 43e36ca45a lib-version: update to mbedtls-2.7.11 4dbcd85e50 openssl/cipher.hpp: add missing include <compat.hpp> 69d72ed64f DCOTransport: Fix server side specific trunk handling ff732e3b5d Fix OpenVPN Core build with OpenSSL 1.1.0 0da42f393f Do not use deprecated OpenSSL 1.1.0 methods 35062c0b60 travis.yml: update environment 47046cf6d2 Merge branch 'qa' 6933c395a4 [OVPN3-423] cliconnect.hpp: fix reconnect on Windows after sleep 462c36c813 random_subnet(): added comment ac1d447156 IP::Addr::from_byte_string(): fixed bug for IPv6 case d6eaea3468 string::split(): minor implementation tweaks ca15b7cdf4 hexstr: added dump_hex() variant accepting void * 0e61a2afd7 SessionIDType::find_weak: added conflict parameter 089aec00b1 DCOTransport: new routing code for trunk links 5befbd430f build: added CAP=1 -- build with libcap eb85ada21e signals: added trivial signal_name() function f89013ef92 RunContext: don't try to catch SIGQUIT by default e0ee540135 SessionIDType: added hash() method f0e1f8aa42 logging: added basic components for logrotate fbb0c81f29 UMask: added UMaskDaemon, a umask context object appropriate for daemons 1c7bac90d9 build script: when building with DEBUG=1 on Linux, use -ggdb instead of -g 73cce80e43 OpenSSL: added openssl_reseed_rng() function 25780cf798 OpenSSL: fixed some memory leaks in CipherContextGCM and TokenEncrypt 168dba95f5 OpenSSL: define OPENSSL_SERVER_SNI when OpenSSL version is at least 1.1 84e78d8fed SNI: added OpenVPN client support for SNI (currently OpenSSL only) 310766b270 build: added MTLS_DIST setting 4eaa46a879 MbedTLS: added MBEDTLS_DISABLE_NAME_CONSTRAINTS preprocessor flag 16226d1b05 OpenSSLSign: updated for OpenSSL 1.1 aed0678c96 SSL: added SNI::Metadata, an abstract base class for packaging app-specific SNI metadata in AuthCert 001b731fe2 SNI: create SNI namespace and rename SNIHandlerBase -> SNI::HandlerBase 4bd5869305 README.rst: Make Windows-specific build steps up to date. ac365ee977 wintun: support for 0.4 9245056a2a wintun: support for 0.3 b73d484950 mbedtls: throw exception on unsupported SSL:Const::PEER_CERT_OPTIONAL option 1d6bae4b5b tcplinkcommon: bubble up real exception error c18c8bd156 tcpcli: ensure SSL Factory survives as long as TLS link 4192193087 tls: parse and load TLS specific CA 2a19b7fcff win/tuncli.hpp: fix Wintun padding calculation 44cb9f44da appveyor: make ReleaseOpenSSL default configuration 5485de19a2 win/impersonate: refactor impersonate logic 29a655147b win/tunsetup.hpp: remove unneeded parameter 61794b0efd win: link OpenSSL dynamically e569b84465 win/tuncli.hpp: fix indentation 374c57e708 frame_init.hpp: tweak wintun read buf size c3c45c9b38 tun: added Error::TUN_HALT for tun_error() signaling acd7af5e9a RandomAPI: added randrange32() method c1a7f8cc68 std::clamp() is useful but only available in C++17 and up, so we add our own clamp() f8c71ef1ce Minor change to Error::INACTIVE_TIMEOUT handler 3202ab5fce OpenSSLSign: renamed OpenSSLPKI::X509Base to OpenSSLPKI::X509 to conform to changes in OpenSSLPKI 8d767febb5 ReachabilityBase: added virtual destructor 6a4826965f MbedTLS: update json_override() prototype bee0d8d187 SSL: added SSLConst::SEND_CLIENT_CA_LIST server-side flag and implemented for OpenSSL 5eb39c1dea AuthCert: save the SNI name 3b34449d0e SSLAPI: auth_cert() can now be const a672e91631 SNI server-side: support additional JSON configuration settings 95e761f3cc OpenSSL PKI cleanup d5eb77c53c AuthCert::Fail cleanup 6e98b9aadc SSLAPI: move PKType from SSLConfigAPI into standalone header to avoid dependency inversion bbae814864 OpenSSL: added SNI implementation 5def1d23ab OpenSSLContext: in constructor, removed redundant if statement 1a0747e783 OpenSSLContext: in constructor, consolidate sslopt fixed flags eef9868816 OpenSSLContext::SSL::ssl_handshake_details(): include leaf-cert CN in details f9631cd90f AuthCert::Fail: use std::string for the reason string (instead of const char *) a17b77641f OpenSSLPKI::X509: copy constructor doesn't need erase() and define X509::Ptr 78cae5bb52 OpenSSLPKI::DH: copy constructor doesn't need erase() c0d43a4153 RCPtr: added static_pointer_cast() method 34a3f264f5 [OVPN-314] Add support for signalling SSO support via IV_SSO 7d112eb3e5 cli: enable utf8 console output 980ef1eff8 win/call.hpp: re-encode command output to utf8 fddb440e99 unicode.hpp: customize utf16 conversion routine 4d7c12ac4d [OVPN3-405] Support for non-ASCII profile path on Windows git-subtree-dir: Sources/OpenVPNAdapter/Libraries/Vendors/openvpn git-subtree-split: 7db7a009b0b4eca0fc3733c99c50aff7f7c2556f
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2019 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
// loose emulation of std::clamp for pre-C++17
|
||||
|
||||
namespace openvpn {
|
||||
|
||||
template <typename T>
|
||||
T clamp(T value, T low, T high)
|
||||
{
|
||||
if (value < low)
|
||||
return low;
|
||||
else if (value > high)
|
||||
return high;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
+53
-11
@@ -34,17 +34,52 @@
|
||||
#include <openvpn/common/logrotate.hpp>
|
||||
#include <openvpn/common/redir.hpp>
|
||||
#include <openvpn/common/usergroup.hpp>
|
||||
#include <openvpn/common/logsetup.hpp>
|
||||
|
||||
namespace openvpn {
|
||||
|
||||
OPENVPN_EXCEPTION(daemon_err);
|
||||
|
||||
inline void log_setup(const std::string& log_fn,
|
||||
const SetUserGroup* user_group,
|
||||
const bool log_append,
|
||||
const int log_versions,
|
||||
const bool stdin_to_dev_null,
|
||||
const bool combine_out_err)
|
||||
class LogReopen : public LogSetup
|
||||
{
|
||||
public:
|
||||
LogReopen(const std::string& log_fn,
|
||||
const bool combine_out_err)
|
||||
: log_fn_(log_fn),
|
||||
combine_out_err_(combine_out_err)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void reopen() const override
|
||||
{
|
||||
try {
|
||||
// open redirection log file, but don't redirect yet
|
||||
RedirectStd redir(std::string(),
|
||||
log_fn_,
|
||||
RedirectStd::FLAGS_APPEND,
|
||||
RedirectStd::MODE_USER_GROUP,
|
||||
combine_out_err_);
|
||||
|
||||
// now do the redirect
|
||||
redir.redirect();
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << "LogReopen: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string log_fn_;
|
||||
const bool combine_out_err_;
|
||||
};
|
||||
|
||||
inline LogSetup::Ptr log_setup(const std::string& log_fn,
|
||||
const SetUserGroup* user_group,
|
||||
const bool log_append,
|
||||
const int log_versions,
|
||||
const bool stdin_to_dev_null,
|
||||
const bool combine_out_err)
|
||||
{
|
||||
if (!log_append && log_versions >= 1)
|
||||
log_rotate(log_fn, log_versions);
|
||||
@@ -62,6 +97,12 @@ namespace openvpn {
|
||||
{
|
||||
}
|
||||
redir.redirect();
|
||||
|
||||
// possibly return a LogReopen object
|
||||
if (!log_versions)
|
||||
return LogSetup::Ptr(new LogReopen(log_fn, combine_out_err));
|
||||
else
|
||||
return LogSetup::Ptr();
|
||||
}
|
||||
|
||||
inline void daemonize()
|
||||
@@ -70,13 +111,14 @@ namespace openvpn {
|
||||
throw daemon_err("daemon() failed");
|
||||
}
|
||||
|
||||
inline void daemonize(const std::string& log_fn,
|
||||
const SetUserGroup* user_group,
|
||||
const bool log_append,
|
||||
const int log_versions)
|
||||
inline LogSetup::Ptr daemonize(const std::string& log_fn,
|
||||
const SetUserGroup* user_group,
|
||||
const bool log_append,
|
||||
const int log_versions)
|
||||
{
|
||||
log_setup(log_fn, user_group, log_append, log_versions, true, true);
|
||||
LogSetup::Ptr ret = log_setup(log_fn, user_group, log_append, log_versions, true, true);
|
||||
daemonize();
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline void write_pid(const std::string& fn)
|
||||
|
||||
@@ -34,13 +34,13 @@
|
||||
#include <openvpn/common/size.hpp>
|
||||
#include <openvpn/common/exception.hpp>
|
||||
#include <openvpn/common/uniqueptr.hpp>
|
||||
#include <openvpn/common/function.hpp>
|
||||
|
||||
namespace openvpn {
|
||||
OPENVPN_EXCEPTION(enum_dir_error);
|
||||
|
||||
template <typename F>
|
||||
inline bool enum_dir(const std::string& dirname,
|
||||
Function<void(std::string fn)> func)
|
||||
F func)
|
||||
{
|
||||
unique_ptr_del<DIR> dir(::opendir(dirname.c_str()), [](DIR* d) { ::closedir(d); });
|
||||
if (!dir)
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
#define OPENVPN_COMMON_EXTERN_H
|
||||
|
||||
#ifndef OPENVPN_EXTERN
|
||||
// Remember that OPENVPN_EXTERN was not defined since something like
|
||||
// #if OPENVPN_EXTERN == extern or OPENVPN_EXTERN == "" is not allowed
|
||||
// in C/C++ preprocessor
|
||||
#define OPENVPN_NO_EXTERN
|
||||
#define OPENVPN_EXTERN
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,6 +35,10 @@
|
||||
#include <openvpn/buffer/bufstr.hpp>
|
||||
#include <openvpn/buffer/buflist.hpp>
|
||||
|
||||
#if defined(OPENVPN_PLATFORM_WIN)
|
||||
#include <openvpn/win/unicode.hpp>
|
||||
#endif
|
||||
|
||||
namespace openvpn {
|
||||
|
||||
OPENVPN_UNTAGGED_EXCEPTION(file_exception);
|
||||
@@ -61,7 +65,12 @@ namespace openvpn {
|
||||
const std::uint64_t max_size = 0,
|
||||
const unsigned int buffer_flags = 0)
|
||||
{
|
||||
#if defined(OPENVPN_PLATFORM_WIN)
|
||||
Win::UTF16 filenamew(Win::utf16(filename));
|
||||
std::ifstream ifs(filenamew.get(), std::ios::binary);
|
||||
#else
|
||||
std::ifstream ifs(filename.c_str(), std::ios::binary);
|
||||
#endif
|
||||
if (!ifs)
|
||||
OPENVPN_THROW(open_file_error, "cannot open for read: " << filename);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace openvpn {
|
||||
// generate temporary filename
|
||||
unsigned char data[16];
|
||||
rng.rand_fill(data);
|
||||
const std::string tfn = path::join(tmpdir, '.' + path::basename(fn) + '.' + render_hex(data, sizeof(data)));
|
||||
const std::string tfn = path::join(tmpdir, '.' + path::basename(fn).substr(0, 64) + '.' + render_hex(data, sizeof(data)));
|
||||
|
||||
// write to temporary file
|
||||
write_binary_unix(tfn, mode, mtime_ns, buf);
|
||||
|
||||
@@ -158,12 +158,12 @@ namespace openvpn {
|
||||
return bp;
|
||||
}
|
||||
|
||||
inline bool read_binary_unix_fast(const std::string& fn,
|
||||
Buffer& out)
|
||||
inline int read_binary_unix_fast(const std::string& fn,
|
||||
Buffer& out)
|
||||
{
|
||||
ScopedFD fd(::open(fn.c_str(), O_RDONLY|O_CLOEXEC));
|
||||
if (!fd.defined())
|
||||
return errno;
|
||||
return errno;
|
||||
const ssize_t status = ::read(fd(), out.data_end(), out.remaining(0));
|
||||
if (status < 0)
|
||||
return errno;
|
||||
|
||||
@@ -279,6 +279,21 @@ namespace openvpn {
|
||||
return os.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a combined hexadecimal and character dump of a buffer,
|
||||
* with the typical 16 bytes split between hexadecimal and character
|
||||
* separation per line.
|
||||
*
|
||||
* @param data Void pointer to the buffer to dump.
|
||||
* @param size Size of the buffer to render.
|
||||
*
|
||||
* @return Returns a string containing a preformatted output of the
|
||||
* hexadecimal dump.
|
||||
*/
|
||||
inline std::string dump_hex(void* data, size_t size)
|
||||
{
|
||||
return dump_hex((const unsigned char *)data, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a combined hexadecimal and character dump of a std::string buffer,
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2019 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <openvpn/common/rc.hpp>
|
||||
|
||||
namespace openvpn {
|
||||
|
||||
class LogSetup : public RC<thread_unsafe_refcount>
|
||||
{
|
||||
public:
|
||||
typedef RCPtr<LogSetup> Ptr;
|
||||
|
||||
virtual void reopen() const = 0;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -29,16 +29,23 @@
|
||||
namespace openvpn {
|
||||
namespace MSF {
|
||||
|
||||
template <typename MAP_SET, typename ITERATOR>
|
||||
template <typename ITERATOR>
|
||||
class Iter : public ITERATOR
|
||||
{
|
||||
public:
|
||||
template <typename MAP_SET>
|
||||
Iter(const MAP_SET& ms, ITERATOR&& iter)
|
||||
: ITERATOR(std::move(iter)),
|
||||
exists_(*this != ms.end())
|
||||
{
|
||||
}
|
||||
|
||||
Iter(ITERATOR&& iter)
|
||||
: ITERATOR(std::move(iter)),
|
||||
exists_(true)
|
||||
{
|
||||
}
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return exists_;
|
||||
@@ -50,11 +57,34 @@ namespace openvpn {
|
||||
|
||||
// Like ordinary map/set find, but returns an iterator
|
||||
// that defines an operator bool() method for testing if
|
||||
// the iterator is defined, i.e. iter != map_or_set.end()
|
||||
// the iterator is defined, so instead of:
|
||||
//
|
||||
// if (iter != map.end())
|
||||
// do_stuff();
|
||||
//
|
||||
// you can say:
|
||||
//
|
||||
// if (iter)
|
||||
// do_stuff();
|
||||
//
|
||||
template <typename MAP_SET, typename KEY>
|
||||
inline auto find(MAP_SET& ms, const KEY& k)
|
||||
{
|
||||
return Iter<MAP_SET, decltype(ms.find(k))>(ms, ms.find(k));
|
||||
return Iter<decltype(ms.find(k))>(ms, ms.find(k));
|
||||
}
|
||||
|
||||
// Does key exist in map/set?
|
||||
template <typename MAP_SET, typename KEY>
|
||||
inline bool exists(MAP_SET& ms, const KEY& k)
|
||||
{
|
||||
return ms.find(k) != ms.end();
|
||||
}
|
||||
|
||||
// Convert an ordinary, dereferenceable iterator to an MSF::Iter
|
||||
template <typename ITERATOR>
|
||||
inline auto iter(ITERATOR i)
|
||||
{
|
||||
return Iter<ITERATOR>(std::move(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +196,12 @@ namespace openvpn {
|
||||
return px != rhs.px;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
RCPtr<U> static_pointer_cast() const noexcept
|
||||
{
|
||||
return RCPtr<U>(static_cast<U*>(px));
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
RCPtr<U> dynamic_pointer_cast() const noexcept
|
||||
{
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include <type_traits> // for std::is_nothrow_move_constructible
|
||||
#include <utility>
|
||||
|
||||
#include <openvpn/common/platform.hpp>
|
||||
#include <openvpn/common/exception.hpp>
|
||||
@@ -45,10 +46,12 @@
|
||||
#include <openvpn/common/stop.hpp>
|
||||
#include <openvpn/common/environ.hpp>
|
||||
#include <openvpn/common/number.hpp>
|
||||
#include <openvpn/common/signal_name.hpp>
|
||||
#include <openvpn/asio/asiosignal.hpp>
|
||||
#include <openvpn/time/time.hpp>
|
||||
#include <openvpn/time/asiotimer.hpp>
|
||||
#include <openvpn/time/timestr.hpp>
|
||||
#include <openvpn/common/logsetup.hpp>
|
||||
|
||||
#ifdef ASIO_HAS_LOCAL_SOCKETS
|
||||
#include <openvpn/common/scoped_fd.hpp>
|
||||
@@ -131,6 +134,11 @@ namespace openvpn {
|
||||
async_stop_ = async_stop;
|
||||
}
|
||||
|
||||
void set_log_reopen(LogSetup::Ptr lr)
|
||||
{
|
||||
log_reopen = std::move(lr);
|
||||
}
|
||||
|
||||
void set_thread(const unsigned int unit, std::thread* thread)
|
||||
{
|
||||
while (threadlist.size() <= unit)
|
||||
@@ -312,7 +320,7 @@ namespace openvpn {
|
||||
stats = stats_arg;
|
||||
}
|
||||
|
||||
virtual Stop* async_stop()
|
||||
virtual Stop* async_stop() override
|
||||
{
|
||||
return async_stop_;
|
||||
}
|
||||
@@ -342,14 +350,11 @@ namespace openvpn {
|
||||
{
|
||||
if (!error && !halt)
|
||||
{
|
||||
OPENVPN_LOG("ASIO SIGNAL " << signum);
|
||||
OPENVPN_LOG("ASIO SIGNAL: " << signal_name(signum));
|
||||
switch (signum)
|
||||
{
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
#if !defined(OPENVPN_PLATFORM_WIN)
|
||||
case SIGQUIT:
|
||||
#endif
|
||||
cancel();
|
||||
break;
|
||||
#if !defined(OPENVPN_PLATFORM_WIN)
|
||||
@@ -358,6 +363,11 @@ namespace openvpn {
|
||||
OPENVPN_LOG(stats->dump());
|
||||
signal_rearm();
|
||||
break;
|
||||
case SIGHUP:
|
||||
if (log_reopen)
|
||||
log_reopen->reopen();
|
||||
signal_rearm();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
signal_rearm();
|
||||
@@ -385,7 +395,7 @@ namespace openvpn {
|
||||
exit_timer.expires_after(Time::Duration::seconds(n_sec));
|
||||
exit_timer.async_wait([self=Ptr(this)](const openvpn_io::error_code& error)
|
||||
{
|
||||
if (error)
|
||||
if (error || self->halt)
|
||||
return;
|
||||
OPENVPN_LOG("DEBUG EXIT");
|
||||
self->cancel();
|
||||
@@ -420,6 +430,7 @@ namespace openvpn {
|
||||
// logging
|
||||
Log::Context log_context;
|
||||
Log::Context::Wrapper log_wrap; // must be constructed after log_context
|
||||
LogSetup::Ptr log_reopen;
|
||||
|
||||
protected:
|
||||
volatile bool halt = false;
|
||||
|
||||
@@ -115,6 +115,12 @@ namespace openvpn {
|
||||
return u.dataz[0];
|
||||
}
|
||||
|
||||
template <typename HASH>
|
||||
void hash(HASH& h) const
|
||||
{
|
||||
h(u.dataz[0]);
|
||||
}
|
||||
|
||||
// Use a URL-safe base64 encoding.
|
||||
std::string to_string() const
|
||||
{
|
||||
@@ -160,13 +166,15 @@ namespace openvpn {
|
||||
}
|
||||
|
||||
// Find an element in an unordered map (keyed by Session ID)
|
||||
// using weak equality.
|
||||
// using weak equality. If conflict is true, only return
|
||||
// element that is present by weak equality, but which is
|
||||
// not equal to *this by strong equality.
|
||||
template <typename UNORDERED_MAP>
|
||||
const SessionIDType* find_weak(const UNORDERED_MAP& m) const
|
||||
const SessionIDType* find_weak(const UNORDERED_MAP& m, const bool conflict) const
|
||||
{
|
||||
const size_t bi = m.bucket(*this);
|
||||
for (auto i = m.cbegin(bi); i != m.cend(bi); ++i)
|
||||
if (shortform() == i->first.shortform())
|
||||
if (shortform() == i->first.shortform() && (!conflict || *this != i->first))
|
||||
return &i->first;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2019 OpenVPN Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program in the COPYING file.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <signal.h>
|
||||
|
||||
namespace openvpn {
|
||||
|
||||
inline std::string signal_name(const int signum)
|
||||
{
|
||||
switch (signum)
|
||||
{
|
||||
case SIGINT:
|
||||
return "SIGINT";
|
||||
case SIGTERM:
|
||||
return "SIGTERM";
|
||||
case SIGHUP:
|
||||
return "SIGHUP";
|
||||
case SIGUSR1:
|
||||
return "SIGUSR1";
|
||||
case SIGUSR2:
|
||||
return "SIGUSR2";
|
||||
case SIGPIPE:
|
||||
return "SIGPIPE";
|
||||
default:
|
||||
return std::to_string(signum);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -150,6 +150,21 @@ namespace openvpn {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prepend leading characters (c) to str to obtain a minimum string length (min_len).
|
||||
// Useful for adding leading zeros to numeric values or formatting tables.
|
||||
inline std::string add_leading(const std::string& str, const size_t min_len, const char c)
|
||||
{
|
||||
if (min_len <= str.length())
|
||||
return str;
|
||||
size_t len = min_len - str.length();
|
||||
std::string ret;
|
||||
ret.reserve(min_len);
|
||||
while (len--)
|
||||
ret += c;
|
||||
ret += str;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// make sure that string ends with char c, if not append it
|
||||
inline std::string add_trailing_copy(const std::string& str, const char c)
|
||||
{
|
||||
@@ -235,16 +250,23 @@ namespace openvpn {
|
||||
return str.find_first_of('\n') != std::string::npos;
|
||||
}
|
||||
|
||||
// return the first line (without newline) of a multi-line string
|
||||
inline std::string first_line(const std::string& str)
|
||||
// Return string up to a delimiter (without the delimiter).
|
||||
// Returns the entire string if no delimiter is found.
|
||||
inline std::string to_delim(const std::string& str, const char delim)
|
||||
{
|
||||
const size_t pos = str.find_first_of('\n');
|
||||
const size_t pos = str.find_first_of(delim);
|
||||
if (pos != std::string::npos)
|
||||
return str.substr(0, pos);
|
||||
else
|
||||
return str;
|
||||
}
|
||||
|
||||
// return the first line (without newline) of a multi-line string
|
||||
inline std::string first_line(const std::string& str)
|
||||
{
|
||||
return to_delim(str, '\n');
|
||||
}
|
||||
|
||||
// Define a common interpretation of what constitutes a space character.
|
||||
// Return true if c is a space char.
|
||||
inline bool is_space(const char c)
|
||||
@@ -385,12 +407,16 @@ namespace openvpn {
|
||||
// indent a multiline string
|
||||
inline std::string indent(const std::string& str, const int first, const int remaining)
|
||||
{
|
||||
std::string ret = spaces(first);
|
||||
std::string ret;
|
||||
int n_spaces = first;
|
||||
for (auto &c : str)
|
||||
{
|
||||
if (n_spaces)
|
||||
ret += spaces(n_spaces);
|
||||
n_spaces = 0;
|
||||
ret += c;
|
||||
if (c == '\n')
|
||||
ret += spaces(remaining);
|
||||
n_spaces = remaining;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -447,7 +473,8 @@ namespace openvpn {
|
||||
}
|
||||
|
||||
// Split a string on sep delimiter. The size of the
|
||||
// returned string list will be at most maxsplit + 1.
|
||||
// returned string vector will be at least 1 and at
|
||||
// most maxsplit + 1 (unless maxsplit is passed as -1).
|
||||
inline std::vector<std::string> split(const std::string& str,
|
||||
const char sep,
|
||||
const int maxsplit = -1)
|
||||
@@ -456,13 +483,16 @@ namespace openvpn {
|
||||
int nterms = 0;
|
||||
std::string term;
|
||||
|
||||
for (auto &c : str)
|
||||
if (maxsplit >= 0)
|
||||
ret.reserve(maxsplit + 1);
|
||||
|
||||
for (const auto c : str)
|
||||
{
|
||||
if (c == sep && (maxsplit < 0 || nterms < maxsplit))
|
||||
{
|
||||
ret.push_back(std::move(term));
|
||||
++nterms;
|
||||
term = "";
|
||||
term.clear();
|
||||
}
|
||||
else
|
||||
term += c;
|
||||
|
||||
@@ -56,5 +56,13 @@ namespace openvpn {
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct UMaskDaemon : public UMask
|
||||
{
|
||||
UMaskDaemon()
|
||||
: UMask(S_IWOTH)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -76,6 +76,16 @@ namespace openvpn {
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& user() const
|
||||
{
|
||||
return user_name;
|
||||
}
|
||||
|
||||
const std::string& group() const
|
||||
{
|
||||
return group_name;
|
||||
}
|
||||
|
||||
void activate() const
|
||||
{
|
||||
if (gr)
|
||||
|
||||
@@ -24,5 +24,5 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef OPENVPN_VERSION
|
||||
#define OPENVPN_VERSION "3.2 (qa:d87f5bbc04)"
|
||||
#define OPENVPN_VERSION "3.git:master"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user