0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00
Commit Graph

794 Commits

Author SHA1 Message Date
Lev Stipakov
b2e8cb42f0
Add GPL headers
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-02-05 20:08:58 +02:00
James Yonan
f3c5a7a77e
json: added write_fast() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:57 +02:00
James Yonan
d9681076c1
json: read_fast(): added optional flag
Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:57 +02:00
James Yonan
ce7dc7cad4
json::write_atomic: support mtime_ns parameter (nanoseconds-since-epoch)
Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:56 +02:00
James Yonan
558cd3770a
json::write_atomic(): fixed bug where method was not writing actual JSON content
Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:56 +02:00
James Yonan
45298001a0
json::read_fast: make optional flag implicit
Also interpret an empty file the same as a non-existent file.

Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:55 +02:00
James Yonan
f5dcb29b83
jsonfile.hpp: for read_fast() and read_binary_unix(), rename "must_exist" boolean to "optional" with reversal of value interpretation.
Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:55 +02:00
James Yonan
4110d23d25
Added json::read_fast() and json::write_atomic()
Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:54 +02:00
Lev Stipakov
5491b30657
xmlhelper.hpp: support for new tinyxml2 API
Since version 6.0.0, tinyxml2 has introduced an API change
which broke compatibility with previous versions, see
https://github.com/leethomason/tinyxml2/issues/635

The library doesn't provide macros to check its version
in compile time, so we use pkg-config to determine library
version and define our own macro which we use for compatibility
with old (Ubuntu 16) and new (Ubuntu 18) library versions.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-02-05 20:08:39 +02:00
James Yonan
4253b28896
xmlhelper: misc changes
* added next_sibling() methods
* fully specify tinyxml2::XMLDocument::Parse()
* use #pragma once

Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:38 +02:00
James Yonan
71c55b6e48
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:38 +02:00
James Yonan
624f9d1467
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-02-05 20:08:37 +02:00
James Yonan
92b9b51b30
library : added TinyXML2 dependency 2020-02-05 20:08:37 +02:00
James Yonan
f250c4c921 WS::ClientSet: silently ignore when Asio is missing the results.randomize() method
If HTTPCLI_RANDOMIZE_RESULTS_REQUIRED is defined, cause a compile-time
error if Asio is not compiled with results.randomize() method.

If HTTPCLI_RANDOMIZE_RESULTS_REQUIRED is NOT defined, opportunistically
compile results.randomize() usage only if available in Asio.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-29 09:27:46 -07:00
Arne Schwabe
9c50badeb4
Fix integer comparison problems introduced by the merge of released
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-01-16 15:34:32 +01:00
Arne Schwabe
c8fb3f112d
use std::enable_if with sizeof(T) instead if(sizeof(T))
This silences a compiler warning about error=shift-count-overflow
2020-01-15 23:08:31 +01:00
Arne Schwabe
984c601090
Fix multiple instances of comparison of signed with unsigned 2020-01-15 23:08:30 +01:00
Lev Stipakov
a4d9989d81
Update license on files moved from common
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:24:20 +02:00
James Yonan
1d090e7e88
Use openvpn::strerror_str() instead of std::strerror().
std::strerror() doesn't claim to be thread-safe, so
add openvpn::strerror_str() which is thread-safe by
virtue of the fact that it backs to strerror_r().

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:18 +02:00
James Yonan
0368d32cb6
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:17 +02:00
James Yonan
6e51d02eff
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:17 +02:00
James Yonan
e6f67cedc7
copyright : updated to 2016 2020-01-09 12:23:17 +02:00
James Yonan
7dc71fa837
Added write_private() methods from core (no Windows implementation yet).
In httpcreds.hpp, use write_private() for creating creds
files rather than UMask.
2020-01-09 12:23:17 +02:00
James Yonan
0057bb7ec4
jsonhelper: allow NAME or TITLE parameters to be an array index
Also, break out json::fmt_name* methods into their own
source file.

NOTE: this code includes some SFINAE, so may need #ifdefs for
Visual Studio.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:16 +02:00
James Yonan
02b531e619
jsonhelper: extend polymorphism to allow string or numerical indices
Updated StringTempl to work with numeric types.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:16 +02:00
James Yonan
f02ea1f762
library: added BijectiveSetMapping and enhanced StringTempl::to_string()
BijectiveSetMapping is a one-to-many bijective mapping.

If K is the key and V is the value, you can:

1. add to the forward map in the form [ K : set(V) ]
2. delete K from the forward map

The BijectiveSetMapping automatically maintains the
reverse mapping where each element is the form:

  [ V: set(K) ]

Also enhanced StringTempl::to_string() with an SFINAE
variant that supports objects having a to_string() method.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:16 +02:00
James Yonan
730a57c39e
jsonhelper: allow NAME or TITLE parameters to be an array index
Also, break out json::fmt_name* methods into their own
source file.

NOTE: this code includes some SFINAE, so may need #ifdefs for
Visual Studio.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:16 +02:00
Arne Schwabe
ec7d4746b3
Update jsonhelper to current JSONcpp library
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2020-01-09 12:23:15 +02:00
James Yonan
e79add27a8
jsonhelper: C++ standard appears to indicate no need to do explicit std::move on return value
This edit also silences a warning in clang.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:15 +02:00
James Yonan
b0669ab4e3
jsonhelper: added dict_result() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:15 +02:00
James Yonan
6e242ee555
jsonhelper: added error() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:15 +02:00
James Yonan
0c61d0dfa8
jsonhelper: minor fix: typo in exception string
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:14 +02:00
James Yonan
201e0e68a2
jsonhelper: added cast() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:14 +02:00
James Yonan
9f3afbae91
Json: support parsing from ConstBuffer
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:14 +02:00
James Yonan
e13f1f3859
JSON: added #ifdef OPENVPN_JSON_INTERNAL around code requiring internal JSON lib
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:14 +02:00
James Yonan
d30c6f4e8f
jsonhelper: added get_string_ref() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
121d647fe2
jsonhelper: added get_bool_tristate() method
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
df1695dc74
jsonhelper: get_bool_optional: removed string interpretation
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
580bbb9bf0
jsonhelper: allow NAME or TITLE parameters to be an array index
Also, break out json::fmt_name* methods into their own
source file.

NOTE: this code includes some SFINAE, so may need #ifdefs for
Visual Studio.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
819cc56962
jsonhelper: minor changes
* Added simple parse() method that only requires
  JSON string to be parsed.

* Added get_string_from_array() method that doesn't
  require title parameter.

* Added cast_array() method that doesn't require
  title parameter.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:13 +02:00
James Yonan
550d308480
jsonhelper: extend polymorphism to allow string or numerical indices
Updated StringTempl to work with numeric types.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:12 +02:00
James Yonan
672e07f210
jsonhelper: trivial indentation change
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:12 +02:00
James Yonan
372eb97457
jsonhelper: Use new JSON library implementation.
Also:

* break up some long lines in source code

* added get_uint_optional_via_string() and
  get_uint64_optional_via_string()

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:12 +02:00
James Yonan
04c3aa9b0a
jsonhelper: added format() method outputting to Buffer.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:11 +02:00
James Yonan
407b83e529
jsonhelper: added get_array() method without title argument.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:11 +02:00
James Yonan
a01d34deaa
jsonhelper: exists() method should return false if argument is not a JSON object.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:11 +02:00
James Yonan
3d0d9de34e
jsonhelper.hpp misc changes
* use namespace json instead of class json so that other
  source files can also add stuff to namespace json

* make fmt_name() method public

* added get_string_from_array() method

* added get_(int|uint|uint64)_optional() methods

* added get_(uint|uint64)_via_string() methods

* added some title-free method variants such as get_dict()
  and cast_dict()

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:11 +02:00
James Yonan
cb6914e6a4
copyright: updated to 2017
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:10 +02:00
James Yonan
b8f64a02b7
license : this branch (common) is proprietary, so remove all GPL headers.
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:10 +02:00
James Yonan
6e33ef89c0
jsonhelper: major refactor
* Templatize name and title parameters.
* String construct the json_parse exceptions instead of
  using OPENVPN_THROW.
* Refactor to_x() methods to derive from get_x() methods
  instead of the other way around.
* Added get_uint64() method.
* Added cast_array() method.
* Added format() method.
2020-01-09 12:23:10 +02:00
James Yonan
bfb9833354
jsonhelper : added default_value parameter to get_bool_optional() 2020-01-09 12:23:10 +02:00
James Yonan
6e5b04fd01
jsonhelper : added parse_from_buffer() 2020-01-09 12:23:09 +02:00
James Yonan
760ae4a5f1
jsonhelper : added json::format_compact() methods for formatting JSON into a compact representation without extraneous whitespace. 2020-01-09 12:23:09 +02:00
James Yonan
ff804f93f0
copyright : updated to 2016 2020-01-09 12:23:09 +02:00
James Yonan
b850f4875c
jsonhelper : added json::get_string_optional() method. 2020-01-09 12:23:09 +02:00
James Yonan
8831925837
jsonhelper : added json::exists() method. 2020-01-09 12:23:08 +02:00
James Yonan
90ece7de04
jsonhelper : for consistency, swap the order of title and default_value in to_uint_optional(). 2020-01-09 12:23:08 +02:00
James Yonan
3154ec0f92
jsonhelper : in get_bool_optional(), convert string "true" (case insensitive) to boolean true. 2020-01-09 12:23:08 +02:00
James Yonan
5c25bb7089
jsonhelper.hpp : added new methods parse_from_file(), cast_dict(), and get_array(). 2020-01-09 12:23:08 +02:00
James Yonan
76b5f880b5
jsonhelper : added get_bool_optional(). 2020-01-09 12:23:07 +02:00
James Yonan
042c0194ac
For jsoncpp usage, rename deprecated misspelled method name:
getFormatedErrorMessages -> getFormattedErrorMessages
2020-01-09 12:23:07 +02:00
James Yonan
ba18268dfc
In class json (jsonhelper.hpp):
Added new static method parse().

Modified to_uint_optional() to make 'title' the last
parameter.

Moved to_vector() method.
2020-01-09 12:23:07 +02:00
James Yonan
1e7e8210ab
Added new file openvpn/common/jsonhelper.hpp with convenience methods for dealing with Json::Value objects. 2020-01-09 12:23:07 +02:00
Lev Stipakov
e86b3bef38
endian64.hpp: Add MSVS version of int64 byte swap
Signed-off-by: Lev Stipakov <lev@openvpn.net>
2020-01-09 12:23:06 +02:00
James Yonan
b9b4bb8c55
Endian: use more portable method to determine machine byte order
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:06 +02:00
Arne Schwabe
c8a2405722
Add Clang specific swap 64 bit builtin macro
This fixes build on Android NDK with clang/clang++

Neither the Android libc nor the libc++ used by Android by default
have the __bswap_constant_64 macro.

The more standard include of byteswap.h and bswap_64 exists only on
Linux and Android. Mac OS X defines no function in its includes that
does a byteswap. Therefore keep the compiler internal but choose
Clang's when compiling with Clang.
2020-01-09 12:23:06 +02:00
James Yonan
02d95918e4
Endian: added missing inline
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:06 +02:00
James Yonan
db7c5613f3
HTTP layer: added Websocket support
Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:05 +02:00
James Yonan
341d983734
JsonClient/AppServer: full HTTP compression support
* gzip or lz4 supported for standard HTTP.

* lz4 support for websocket.

Signed-off-by: James Yonan <james@openvpn.net>
2020-01-09 12:23:05 +02:00
James Yonan
a9f2055d07 string: added starts_with_delim() function
Signed-off-by: James Yonan <james@openvpn.net>
2019-12-26 03:44:14 -07:00
David Sommerseth
81d6e5c3c1
Update version to indicate development base version
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-11-14 18:41:25 +01:00
Arne Schwabe
f6aada9577 Tempfile.hpp is unix only, add error when including it on win32
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
Arne Schwabe
54fbe7604c Fix file modifcation time retrieval stat.hpp on macOS
Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-11-07 09:58:54 +01:00
James Yonan
32b984c0ff enum_dir: use a function template
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-10 14:08:09 -06:00
James Yonan
e05fc16b20 string::indent(): try to fix all the corner cases
1. Don't emit spaces if the input string is empty.
2. Don't emit spaces after the last newline in the input string.

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-09 21:01:30 -06:00
James Yonan
4e1645ea80 RunContext: mark virtual Stop* async_stop() with override attribute
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-07 00:18:00 -06:00
James Yonan
f7845578f1 RunContext: check for halt in timer closure
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:57 -06:00
James Yonan
c3c8ab7f6b string: added additional detail to split() comment
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
95ce4f22c8 string: added to_delim() method then redefined first_line() method to use it
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
448218b1e1 string: added add_leading() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
e3b0bf4f5c MSF iterator: allow conversion from ordinary iterator and added exists() method
Also added better comments for MSF::find().

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
7496383002 write_binary_atomic: reduce the length of the temporary filename
Linux has a filename maximum of 255 chars, but we need to
be careful about the composition of the temporary filename
so that we don't exceed this limitation on the temporary,
even when the original is within the limit.

Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
4fa8348689 RunContext: ASIO SIGNAL message now shows signal name rather than number
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
c8f9cb88a4 string::split(): call reserve() on return vector
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
James Yonan
f15e566065 read_binary_unix_fast: should return an int (i.e. errno), not a bool
Signed-off-by: James Yonan <james@openvpn.net>
2019-09-06 22:24:56 -06:00
Lev Stipakov
a6151cdeab wintun: use auto-reset events
Wintun documentation clearly states that we must use auto-reset events in ring buffers.
Auto-reset sets event back to non-signalled state after calling WaitForSingleObject.
Without auto-reset and explicit ResetEvent call we got a busy loop.

To avoid confusion move event.hpp from common/ to win/, since it is
Windows-specific code.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-09-05 13:45:41 +03:00
David Sommerseth
efe3f1f635
version: Reset version reference for git master
Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-08-29 17:27:57 +02:00
Arne Schwabe
63ab5b5e46 Only initialise static member in OpenSSLContext once
This avoid a linkage problem encountered when building core with two
compilation units and OPENVPN_EXTERN being used.

Also adjust core unit tests with regard to now different extern usage
2019-08-29 16:21:57 +02:00
Lev Stipakov
48f2b5100b wintun: support for privilege separation
This allows to run openvpn under normal user account,
in which case ring buffers registration is performed
by a separate privileged process.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-08-21 19:09:11 +03:00
Antonio Quartulli
47046cf6d2
Merge branch 'qa' 2019-07-19 14:39:43 +02:00
James Yonan
d6eaea3468 string::split(): minor implementation tweaks
Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
James Yonan
ca15b7cdf4 hexstr: added dump_hex() variant accepting void *
Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
James Yonan
0e61a2afd7 SessionIDType::find_weak: added conflict parameter
Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
James Yonan
eb85ada21e signals: added trivial signal_name() function
Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
James Yonan
f89013ef92 RunContext: don't try to catch SIGQUIT by default
SIGQUIT is better left wired to its standard use of core
dump generation.

Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
James Yonan
e0ee540135 SessionIDType: added hash() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
James Yonan
f0e1f8aa42 logging: added basic components for logrotate
Added LogSetup, an abstract base class with a virtual method
reopen() that accomplishes the log file reopen.

Added RunContext::set_log_reopen() method that accepts
a LogSetup object and calls its reopen() method on
SIGHUP.

daemonize() and log_setup() methods in daemon.hpp
now return a LogSetup object.

Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
James Yonan
fbb0c81f29 UMask: added UMaskDaemon, a umask context object appropriate for daemons
Signed-off-by: James Yonan <james@openvpn.net>
2019-07-17 10:53:46 -06:00
James Yonan
c1a7f8cc68
std::clamp() is useful but only available in C++17 and up, so we add our own clamp()
Signed-off-by: James Yonan <james@openvpn.net>
2019-06-19 18:35:19 +02:00
James Yonan
c0d43a4153
RCPtr: added static_pointer_cast() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-06-19 18:20:56 +02:00
James Yonan
eec139a100
MSF::find: renamed template type names to avoid conflict with preprocessor symbol (ITER) in test/ssl/proto.cpp
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
1024d37f33
str_neq: fixed bug where neq was not initialized
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
dd18d6c806
crypto::str_neq: use atomic_thread_fence(std::memory_order_acq_rel) instead of OPENVPN_COMPILER_FENCE
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
3ecbcbc81b
OptionList: fixed compile errors that occur when get_num<T>() is used with a const type
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
658fcc50eb
OptionList: added get_num methods with min/max but no default
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-16 14:50:06 +02:00
James Yonan
74c0a4f995
string: added copy_fill() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 19:12:59 +02:00
James Yonan
3d6b6b2319
library: added convenience method MSF::find() for maps/sets
MSF::find() is like ordinary map/set find(), but returns an
iterator that defines an operator bool() method for testing
if the iterator is defined, e.g.:

  std::map<std::string, std::string> m;
  m.emplace("hello", "world");

  auto e = MSF::find(m, "hello");
  if (e)
    std::cout << e->first << " -> " << e->second << std::endl;

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 19:12:59 +02:00
James Yonan
18dcfd616c
Added crypto::str_neq() function for securely comparing variable-length strings
The goal is to prevent the leakage of timing data about
the length or content of the target string.

Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 18:56:47 +02:00
James Yonan
4fc5725b9e
RunContext: added get_servers() method
Signed-off-by: James Yonan <james@openvpn.net>
2019-05-15 18:56:46 +02:00
Lev Stipakov
4d7c12ac4d [OVPN3-405] Support for non-ASCII profile path on Windows
This uses Windows-specific wchar_t override of std::ifstream
to make it work with UNICODE paths. It is assumed that caller
passes UTF8-encoded string.

To support passing non-ASCII chars via command line, we
read it as wstring and then convert to UTF-8 encoded string.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-04-30 17:45:01 +03:00
David Sommerseth
aa785c30c1
Fix Base64::UCharWrap compiler warnings
Without this fix, some gcc compilers will issue the warning below when
building the reference client:

    ../../openvpn/common/base64.hpp: In constructor
    ‘openvpn::Base64::UCharWrap::UCharWrap(unsigned char*, size_t)’:
    ../../openvpn/common/base64.hpp:77:9: warning:
    ‘openvpn::Base64::UCharWrap::size’ will be initialized after [-Wreorder]
      size_t size;
             ^
    ../../openvpn/common/base64.hpp:76:17: warning:   ‘unsigned char*
    openvpn::Base64::UCharWrap::data’ [-Wreorder]
      unsigned char *data;
                     ^
    ../../openvpn/common/base64.hpp:63:2: warning:   when initialized here
    [-Wreorder]
      UCharWrap(unsigned char *data, size_t size):
      ^

This patch fixes this issue as well as removing a redundant public
declaration and fixing some whitespace issues.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2019-04-25 22:02:54 +02:00
Arne Schwabe
017bc545ce Add base64 decode for void* data
Also add some casts to avoid warnings
2019-04-15 17:23:37 +02:00
Antonio Quartulli
e6ec025932
Merge branch 'qa' 2019-04-10 22:09:08 +02:00
Lev Stipakov
752a38c067 [OVPN3-397] size.hpp: wrap typedef in guards
NodeJS C++ environment defines ssize_t and causes
core build to fail because of type redefinition.

To fix, surround core's definition with same #ifdef guards
used in Node.JS.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2019-04-03 17:36:35 +03:00
Arne Schwabe
525a9a88a6 Merge branch qa
* schwabe/UCONNECT-1186-fix-custom-memcpy:
  Replace custom memcpy implementation
  Workaround for compiler bug in memneq
  [UCONNECT-1027] use one AsioWork object for the whole pre-resolve opertation
  Revert "[UCONNECT-1027] remotelist: create standalone object for resolve thread"

Signed-off-by: Arne Schwabe <arne@openvpn.net>
2019-03-19 14:48:04 +01:00
Arne Schwabe
de7c672ee7 Workaround for compiler bug in memneq
Use OpenSSL's or alternative implementation to avoid crashing on
Android armeabiv7a release builds.
2019-03-18 14:09:45 +01:00
Antonio Quartulli
04de9c4259
Merge branch 'qa' 2019-01-29 21:12:59 +10:00
James Yonan
5713ff34af Fixed some breakage caused by recent endian/ffs commits
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-19 12:08:43 +01:00
James Yonan
a9ce44a229 endian.hpp: break out endian compile-time tests to endian_platform.hpp
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-19 11:55:38 +01:00
James Yonan
996f866356 RunContext: fixed rebase issue that added two "default: signal_rearm();" clauses
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:42:41 -07:00
James Yonan
1d754072c6 modstat: make update_file_mod_time_nanoseconds() a no-op on non-Linux
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:26:12 -07:00
James Yonan
7974c9867d Fixed some breakage caused by recent endian/ffs commits
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:26:12 -07:00
James Yonan
a0dd7fe8b1 endian.hpp: break out endian compile-time tests to endian_platform.hpp
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:26:12 -07:00
James Yonan
c8bdf5a348 ffs.hpp: support additional numeric types
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:26:12 -07:00
James Yonan
39e71b7ddf event_loop_wait_barrier: use a longer default timeout when running under valgrind
Running under valgrind is so slow compared to normal execution,
that some timeouts need to be extended.

Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:26:12 -07:00
James Yonan
8b7e08e9b5 string::contains_non_space_ctrl: consider ASCII char 127 (DEL) to be a control char
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:26:12 -07:00
James Yonan
e43024d7c4 RunContext: rearm non-terminating signals
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:26:12 -07:00
James Yonan
6ab3793235 write_binary_atomic: remove temporary file on move failure
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:26:12 -07:00
James Yonan
55dc653cde path: added is_contained()
Signed-off-by: James Yonan <james@openvpn.net>
2018-12-12 23:26:12 -07:00
Antonio Quartulli
10d636cfec
version: switch to 3.2
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-12-06 13:31:56 +01:00
Antonio Quartulli
68508fe564
bigmutex: include missing extern.hpp header
bigmutex.hpp relies on OPENVPN_EXTERN and therefore it must include
extern.hpp so that it can get defined when not specified elsewhere.

Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-11-30 08:47:13 +10:00
Antonio Quartulli
923e10d13b
runcontext: arrange members to allow inheritance
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-11-15 17:41:02 +10:00
James Yonan
d9b1f78b69
JSON: #define OPENVPN_JSON_INTERNAL when internal JSON library is used
Signed-off-by: James Yonan <james@openvpn.net>
2018-10-19 16:09:39 +08:00
David Sommerseth
39290f19d4
Fix build issues with #if macro on big-endian hardware
When building for big-endian machines, it fails with

   openvpn/common/endian.hpp:65:28: error: #elif with no expression
   #   elif OPENVPN_BIG_ENDIAN
                              ^

This is resolved by adding defined().  Also did the same for the first
for consistency.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2018-10-18 14:27:15 +02:00
Lev Stipakov
4b072bce10 [OVPN3-311] function.hpp: fix Windows build
Visual Studio is not happy with SFINAE, so do not use
it for Windows build.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-09-06 11:13:10 +03:00
Lev Stipakov
48b9b78de8 [OVPN3-310] logging: fix 'OPENVPN_LOG_NTNL': identifier not found
When we define OPENVPN_EXTERNAL_TRANSPORT_FACTORY, we also use
OPENVPN_LOG_NTNL macro:

ovpncli.cpp -> ovpncli.hpp -> extern/fw.hpp -> transbase.hpp -> protocol.hpp -> options.hpp

The problem is that macro is defined after ovpncli.hpp is included.

To fix this, we break link between protocol.hpp and options.hpp by moving option_error
into separate include file, which we include from protocol.hpp (instead of options.hpp) and
options.hpp.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-09-06 10:46:35 +03:00
James Yonan
8178ae06f5 unix file utils: added update_file_mod_time_nanoseconds()
Signed-off-by: James Yonan <james@openvpn.net>
2018-08-30 13:00:27 +03:00
James Yonan
0eaa2586f1 string: added remove_spaces() method
Signed-off-by: James Yonan <james@openvpn.net>
2018-08-30 13:00:27 +03:00
James Yonan
d47ae03ccf OptionList: added get_c_str() method
Signed-off-by: James Yonan <james@openvpn.net>
2018-08-30 13:00:27 +03:00
James Yonan
1eb9cd657c unix file utils: added mtime_ns parameter to write_binary_unix() and write_binary_atomic()
mtime_ns is nanoseconds-since-epoch.

Signed-off-by: James Yonan <james@openvpn.net>
2018-08-30 13:00:27 +03:00
James Yonan
d92021c99b strerror.hpp: added #include <errno.h> for benefit of users
Signed-off-by: James Yonan <james@openvpn.net>
2018-08-30 13:00:27 +03:00
James Yonan
363cbece33 Function: misc cleanup
1. include <type_traits>
2. make operator() method const
3. use SFINAE and std::enable_if to choose between Intern and Extern
4. use rvalue references in passed arguments whenever possible

Signed-off-by: James Yonan <james@openvpn.net>
2018-08-30 13:00:27 +03:00
Arne Schwabe
bcdb279930 Merged in schwabe/fix_clang_warnings (pull request #25)
Fix warnings reported by LLVM/Clang

Approved-by: David Sommerseth <davids@openvpn.net>
Approved-by: Lev Stipakov <lev@openvpn.net>
Approved-by: James Yonan <james@openvpn.net>
2018-08-23 07:37:12 +00:00
Arne Schwabe
c0d580d24e Merged in schwabe/fix_openvpn_extern (pull request #26)
Fix multiple inclusion of OpenVPN3 header with OPENPVN_EXTERN

Approved-by: James Yonan <james@openvpn.net>
2018-08-23 07:35:34 +00:00
Arne Schwabe
ba264862a5 Send also kovpn statistics of CPU Cores >= 16 via status message
Also let the function ncores function use the more standard C++
implementation and only fall back to our custom implementation if
it does not work.
2018-07-09 16:02:35 +02:00
Arne Schwabe
2991d38b31 Fix warnings reported by LLVM/Clang 2018-07-05 18:49:10 +02:00
Arne Schwabe
02d2a7975e Fix multiple inclusion of OpenVPN3 header with OPENPVN_EXTERN
To bundle ptcore and openvpncli into the same shared library for
OpenVPN Connect, the two libraries need both to include OpenVPN (or
parts of it).

Ptcore defines OPENVPN_EXTERN as extern to define the symbols as extern
in that library but a few places are missing proper weak symbol (inline)
or extern declaration.
2018-07-05 15:38:48 +02:00
David Sommerseth
554d8b8881
Document functions and classes in common/hexstr.hpp
This file contains generic functions for parsing and rendering various
data types to/from hexadecimal strings.  This patch just adds generic
documentation to all functions and the RenderHexByte class.

Signed-off-by: David Sommerseth <davids@openvpn.net>

---
v2 - Improved and clarified serveral aspects raised by Antonio
2018-06-29 11:10:37 +02:00
Antonio Quartulli
08dfbf98c1
version: make OPENVPN_VERSION a compile time option
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
2018-06-25 16:34:43 +08:00
Lev Stipakov
9e600c89e7 Merged in OVPN3-211-implement-big-mutex (pull request #5)
[OVPN3-211] bigmutex: introduce macro to ensure thread-safety

Approved-by: James Yonan <james@openvpn.net>
2018-06-08 08:03:44 +00:00
Lev Stipakov
ccc17a5631 [OVPN3-211] bigmutex: introduce macro to ensure thread-safety
Platforms like UWP and iOS may call core methods
from another threads. Since core is not thread-safe,
we provide OPENVPN_ASYNC_HANDLER macro which instantiates
lock guard. It follows RAII principle and locks global
mutex in constructor and unlocks in destructor. This
guarantees that code in block protected with this macro
won't be called simultaneously from different threads.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2018-06-07 21:17:42 +03:00
James Yonan
46d2a642f8 RC: added is_thread_safe() method to indicate if refcount is thread-safe
is_thread_safe() is constexpr, so it can be checked at compile time
using static_assert().

Signed-off-by: James Yonan <james@openvpn.net>
2018-05-21 11:34:02 +03:00
James Yonan
2c06ac24cd SessionIDType: allow generation from non-crypto RNGs
Signed-off-by: James Yonan <james@openvpn.net>
2018-05-21 11:34:01 +03:00
James Yonan
caf9cf6c1d
RedirectPipe: added additional flags for flexibility
COMBINE_OUT_ERR : capture combined stdout/stderr using a pipe
  ENABLE_IN       : make a string -> stdin pipe, otherwise redirect stdin from /dev/null
  IGNORE_IN       : don't touch stdin
  IGNORE_OUT      : don't touch stdout
  IGNORE_ERR      : don't touch stderr

Signed-off-by: James Yonan <james@openvpn.net>
2018-03-26 23:58:35 +08:00
James Yonan
37d848ca20
Log lines from C++ exceptions should contain the text "exception"
This makes it easier to scan log files for exceptions.

Signed-off-by: James Yonan <james@openvpn.net>
2018-03-26 23:58:35 +08:00
James Yonan
322ae24b53
OptionList: support variadic template parameter pack in constructors
This allows usage such as:

const OptionList opt(Option("dev", "tun"),
		     Option("remote", "openvpn.example.com", "1194", "udp"));

Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:35 +08:00
James Yonan
32e3ea117c
OptionList: added show_unused_options() method
ClientOptions in cliopt.hpp now uses this method
rather than defining its own.

Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:34 +08:00
David Sommerseth
79ad5ededb
Estblishing a stable branch
This branch is targeted for consumers of the library, where we will do
release handling.  This branch should contain reasonably well tested and
stable code only.  Features under development and testing should only be
worked on outside of this branch until it is ready and can be merged
into stable.

Since it has been quite some time since the version.hpp file was
updated, this change will now set version to 3.2 - to start this new
versioning regime.

The version numbering and release process is further described in
VersionNumbering.rst

Signed-off-by: David Sommerseth <davids@openvpn.net>
2018-03-10 02:28:33 +08:00
James Yonan
8c3af27040
HostPort::split_host_port: support unix socket filename as an alternative kind of host
Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:32 +08:00
James Yonan
8cb8d52cda
string: added first_line() method
Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:31 +08:00
James Yonan
02e786bc92
write_binary_atomic: support ConstBuffer
Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:31 +08:00
James Yonan
6745799c93
fileunix: added read_binary_unix_fast()
Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:31 +08:00
James Yonan
5689c2d9c9
write_binary_unix(): added ConstBuffer variant
Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:31 +08:00
James Yonan
2b0e764534
enum_dir: refactor to allow enumeration via lambda
Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:30 +08:00
James Yonan
c4af9f68b0
event_loop_wait_barrier: raise default timeout to 30 seconds
Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:30 +08:00
James Yonan
d7fe87540d
appversion.hpp: rename VERSION -> BUILD_VERSION
Pass BUILD_VERSION instead of VERSION on command line to
avoid symbol conflicts.

Signed-off-by: James Yonan <james@openvpn.net>
2018-03-10 02:28:29 +08:00
David Sommerseth
16b10559f2 [OVPN3-140] Update company names in copyrights
OpenVPN Technologies, Inc. change their name to OpenVPN Inc. during the
autumn of 2017.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2017-12-22 17:59:39 +08:00
David Sommerseth
6caca2c313 [OVPN3-140] Relicense back to AGPLv3
This is essentially a revert of commit 04b2a3c9b7 and commit
ef42e59e05.

Signed-off-by: David Sommerseth <davids@openvpn.net>
2017-12-22 17:59:39 +08:00
James Yonan
2b4c85091d Debugging: added header and build flag for valgrind run-time
extensions.

Signed-off-by: James Yonan <james@openvpn.net>
2017-12-22 17:59:38 +08:00
James Yonan
106981c3e2 JSON: allow alternative JSON library implementations
Allow source files that require JSON library functionality
to include a single file (openvpn/common/jsonlib.hpp) which
will then draw in the appropriate JSON library header based
on configuration #defines.

Code can #ifdef on HAVE_JSON to test whether or not JSON
functionality is available (previously, HAVE_JSONCPP
was used).

Currently supports JsonCpp and an OpenVPN-internal JSON
implementation.

This model assumes that alternative JSON implementations
are API-compatible with JsonCpp.

Signed-off-by: James Yonan <james@openvpn.net>
2017-12-22 17:59:38 +08:00
James Yonan
569b1da08e daemon.hpp: added class WritePid for managing pid files
Signed-off-by: James Yonan <james@openvpn.net>
2017-12-22 17:59:38 +08:00
James Yonan
f64b501295 Cleanup: allow functor to be passed by value.
Previously Cleanup only allowed its functor argument to
be passed by rvalue reference.

Signed-off-by: James Yonan <james@openvpn.net>
2017-12-22 17:59:38 +08:00
James Yonan
ebe256068b RunContext: add configurable exit via EXIT_IN env var for debugging
Change the OPENVPN_EXIT_IN compile-time flag to be
a run-time option instead, controllable via the
EXIT_IN env var.  Set EXIT_IN to the number of
seconds to run before exiting.

Signed-off-by: James Yonan <james@openvpn.net>
2017-12-22 17:59:38 +08:00
James Yonan
b428f742d1 library: added integer is_pow2() and log2() methods based on
efficient __builtin_ffs and __builtin_clz intrinsics.

Signed-off-by: James Yonan <james@openvpn.net>
2017-12-22 17:59:38 +08:00
Lev Stipakov
8166ea8b3b common: define uwp platform macro
OVPN3-95

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2017-12-22 17:59:38 +08:00
Lev Stipakov
0186bf62c7 common: report platform name as "uwp"
OVPN3-94

Signed-off-by: Lev Stipakov <lev@openvpn.net>
2017-12-22 17:59:38 +08:00
James Yonan
04175c2b84 appversion.hpp: Stringize VERSION -> MY_VERSION
Default to "0.1.0" if VERSION is undefined.

Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:18 +08:00
James Yonan
bd75cd787b RCPtr: added operator==() and operator!=() methods
Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
7be33c5980 PThreadBarrier: fixed incorrect comment
Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
6f5f77bc10 Link: use move semantics
Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
17a5d89c9f inotify.hpp: no longer used
Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
8ce39fc991 added render_hex() and render_hex_sep() methods that accept void* data
Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
ddc8e8a434 Function: use std::forward
Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
76ee5875a9 write_binary_atomic(): added tmpdir (temporary directory) parameter
Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
f366d55105 base64: encode() now accepts void* data
Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
ce0977b2ea Support Cityhash.
When running build script, add CITY=1 to build with Cityhash library.

Signed-off-by: James Yonan <james@openvpn.net>
2017-09-27 16:16:17 +08:00
James Yonan
1e855667a1 Use openvpn::strerror_str() instead of std::strerror().
std::strerror() doesn't claim to be thread-safe, so
add openvpn::strerror_str() which is thread-safe by
virtue of the fact that it backs to strerror_r().

Signed-off-by: James Yonan <james@openvpn.net>
2017-04-22 17:54:01 -06:00
James Yonan
4bfaafc295 AsioTimer: use expires_after() method when possible.
A common AsioTimer usage pattern is:

  expires_at(Time::now() + duration)

This is more succinctly and efficiently stated as:

  expires_after(duration).

Signed-off-by: James Yonan <james@openvpn.net>
2017-04-12 14:01:11 -06:00
James Yonan
1215912c90 Revamped Function (our own functor object) to be more flexible.
* Automatically overflow to dynamic allocation if function
  object is too large.

* Added optional N and INTERN_ONLY parameters to fine-tune
  internal allocation.

* Added default constructor.

* Added move assignment method.

* Added reset() methods.

* Added operator bool() method to test if functor has
  been defined.

Signed-off-by: James Yonan <james@openvpn.net>
2017-04-12 11:54:16 -06:00
James Yonan
10fa276421 process.hpp: added compile option to avoid async pipe usage.
Define OPENVPN_PROCESS_AVOID_PIPES to build process.hpp
without using asynchronous pipes.

Signed-off-by: James Yonan <james@openvpn.net>
2017-04-12 11:52:15 -06:00
James Yonan
691a641a43 Added i/o abstraction layer.
Created a lightweight abstraction layer so that another i/o
reactor can be dropped in place of asio.

The basic approach is to rename all references to asio::xxx
types to openvpn_io::xxx and then make openvpn_io a
preprocessor variable that points to the top-level namespace
of the i/o reactor implementation.

All of the source files that currently include <asio.hpp> now
include <openvpn/io/io.hpp> instead:

This gives us a lightweight abstraction layer that allows us
to define openvpn_io to be something other than asio.

Other changes:

* Inclusion of asio by scripts/build is now optional, and is
  enabled by passing ASIO=1 or ASIO_DIR=<dir>.

* Refactored openvpn/common/socktypes.hpp to no longer
  require asio.

* Refactored openvpn/log/logthread.hpp to no longer require
  asio.

* Added openvpn::get_hostname() method as alternative to
  calling asio directly.

* openvpn/openssl/util/init.hpp will now #error
  if USE_ASIO is undefined.

Signed-off-by: James Yonan <james@openvpn.net>
2017-03-30 15:48:14 -06:00
James Yonan
2855053680 Moved asio files from openvpn/common to openvpn/asio
Signed-off-by: James Yonan <james@openvpn.net>
2017-03-30 15:48:14 -06:00
James Yonan
f221a27efc documentation: updated for reference-counted GC classes
in openvpn/common/rc.hpp.

Signed-off-by: James Yonan <james@openvpn.net>
2017-03-19 16:32:45 -06:00
James Yonan
6e8f2a73f8 Moved openvpn::to_string() to separate source file.
Signed-off-by: James Yonan <james@openvpn.net>
2017-03-18 15:46:45 -06:00
James Yonan
b2cd82a5bf copyright: updated to 2017.
Signed-off-by: James Yonan <james@openvpn.net>
2017-03-18 13:11:09 -06:00
James Yonan
ef42e59e05 Switch from AGPLv3 to GPLv3 on recently added files.
Signed-off-by: James Yonan <james@openvpn.net>
2017-03-18 12:47:11 -06:00
James Yonan
7e1aca0b54 Added a general-purpose Session ID class. 2017-03-18 12:24:54 -06:00
James Yonan
77c79f8905 StringTempl : added type-independent string methods. 2017-03-18 12:24:54 -06:00
James Yonan
9e55ad955a base64 changes
* Added URL-safe alternate encoding
* Verify length of altmap
* Added is_base64() method
2017-03-18 12:24:54 -06:00
James Yonan
3b399a6101 asio : the latest Asio master on Github has deprecated
user-defined service objects.  This commit attempts
to work around that but requires a specially patched
version of Asio that includes the virtual
async_connect_post_open() method.
2017-03-18 12:24:54 -06:00