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

611 Commits

Author SHA1 Message Date
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
James Yonan
1f69ae37e7 asio : updates for API changes to "work" object in latest github master.
The asio::io_context::work class has been replaced by a new
class having somewhat different and more verbose
semantics.

We create our own class AsioWork based on the new class
asio::executor_work_guard<asio::io_context::executor_type>
that implements the semantics of the original
asio::io_context::work class.
2017-03-18 12:24:54 -06:00
James Yonan
ad1989a547 asio: deal with symbol renaming in latest github master
mutable_buffers_1 -> mutable_buffer
const_buffers_1 -> const_buffer

This patch is a granularization of a patch by David Sommerseth
<davids@openvpn.net> where only the above renames are included.
2017-03-18 12:24:54 -06:00
James Yonan
4de93d5f65 write_binary_atomic() changes:
1. now uses write_binary_unix() for performance
2. use a leading '.' in generated temporary filenames
2017-03-18 12:24:54 -06:00
James Yonan
ee91c99d40 library : added set of file read/write helper methods
optimized for unix (openvpn/common/fileunix.hpp).
2017-03-18 12:24:54 -06:00
James Yonan
281d08599a string : added ends_with_crlf(),
add_trailing_unless_empty_copy(), and is_alphanumeric().

Implementation changes to ends_with(), trim_crlf(),
and is_word().
2017-03-18 12:24:54 -06:00
James Yonan
295a999fef stat : added file_mod_time_nanoseconds() and
file_mod_time_milliseconds().
2017-03-18 12:24:54 -06:00
James Yonan
03d3318482 ScopedFD : added close_with_errno() 2017-03-18 12:24:54 -06:00
James Yonan
02953d8797 path : added varargs join() 2017-03-18 12:24:54 -06:00
James Yonan
d095771529 hexstr : added class RenderHexByte 2017-03-18 12:24:54 -06:00
James Yonan
fa75e9f98e enum_dir : for consistency, libc function calls should
always include a "::" prefix before the function name.
2017-03-18 12:24:54 -06:00
James Yonan
31ae0e83b8 core version : updated to 3.1.2 2017-03-18 12:24:54 -06:00
James Yonan
18eb8c7646 daemonize/log_setup : Added optional SetUserGroup parameter
to allow chown of log file.
2017-03-18 12:24:54 -06:00
James Yonan
ac6c330dc7 UserGroup : Added strict flag to constructor to allow for
construction even when user/group lookup fails.

Updated calls to std::strerror() to use a saved version
of errno.

Added chown(), gid(), and additional defined() methods.

Use uid_t as the return type for uid().
2017-03-18 12:24:54 -06:00
James Yonan
83d575893f string::join : if tail is true, don't append a
lone delimiter char to return string if passed
string vector is empty.
2017-03-18 12:24:54 -06:00
James Yonan
9c0397ebd3 Added Relay capability, a kind of proxy function similar
to HTTP CONNECT but implemented over the OpenVPN protocol.

1. Client connects to relay server as if it were connecting
   to an ordinary OpenVPN server.

2. Client authenticates to relay server using its client
   certificate.

3. Client sends a PUSH_REQUEST method to relay server which
   then replies with a RELAY message instead of PUSH_REPLY.

4. On receiving the RELAY message, the client attempts to
   reconnect using the existing transport socket.  The
   server will proxy this new connection (at the transport
   layer) to a second server (chosen by the relay server)
   that is the target of proxy.

5. The client must establish and authenticate a new session
   from scratch with the target server, only reusing the
   transport layer socket from the original connection to
   the relay server.

6. The relay acts as a man-in-the-middle only at the
   transport layer (like most proxies), i.e. it forwards
   the encrypted session between client and target server
   without decrypting or having the capability to decrypt
   the session.

7. The client is designed to protect against potentially
   untrusted or malicious relays:

   (a) The client never transmits the target server
       username/password credentials to the relay server.

   (b) The relay forwards the encrypted OpenVPN session
       between client and target server without having
       access to the session keys.

   (c) The client configuration has a special directive
       for relay server CA (<relay-extra-ca>) and relay
       server tls-auth key (<relay-tls-auth>) to allow
       for separation of TLS/crypto configuration between
       relay and target servers.

   (d) The client will reject any PUSH_REPLY messages
       from the relay itself to prevent the relay from
       trying to establish a tunnel directly with the
       client.

Example configuring a client for relay:

  # remote addresses point to the relay server
  remote ... 1194 udp
  remote ... 443 tcp

  # include all other directives for connecting
  # to the target server

  # enable relay mode
  relay-mode

  # constrain the relay server's cert type
  relay-ns-cert-type server

  # include extra CAs that validate the relay
  # server cert (optional).
  <relay-extra-ca>
  -----BEGIN CERTIFICATE-----
  . . .
  -----END CERTIFICATE-----
  </relay-extra-ca>

  # specify the TLS auth key for the relay server
  relay-key-direction 1
  <relay-tls-auth>
  -----BEGIN OpenVPN Static key V1-----
  . . .
  -----END OpenVPN Static key V1-----
  </relay-tls-auth>
2017-03-18 12:24:54 -06:00
James Yonan
b862ca8ff8 library : moved class Environ into its own source file and
added find_static() method.
2017-03-18 12:19:39 -06:00
James Yonan
a2367c5f4d process : added Environ::assign() method. 2017-03-18 12:19:39 -06:00
James Yonan
5d52181cbe runcontext : trigger async_stop before thread join(). 2017-03-18 12:19:39 -06:00
James Yonan
85b49d89b5 TempFile : added additional methods including reset(),
truncate(), read(), and set_delete().

Added buf_read() methods to read from a file descriptor
into a Buffer.
2017-03-18 12:19:39 -06:00
James Yonan
184c6d672b redir.hpp : break out pipe i/o into its own source file. 2017-03-18 12:19:39 -06:00
James Yonan
74e05d8607 library : added class RedirectNull for redirecting stdin,
stdout, and stderr to /dev/null
2017-03-18 12:19:39 -06:00
Samuli Seppänen
04b2a3c9b7 Switch from AGPLv3 to GPLv3
Signed-off-by: Samuli Seppänen <samuli@openvpn.net>
2017-03-16 14:43:55 +02:00
James Yonan
883d967bae Incremented core version to 3.1.1 2016-09-23 16:46:24 -06:00
James Yonan
cf8d5b5c3f Incremented core version to 3.1.0 2016-09-16 04:16:40 +03:00
James Yonan
971abda88f copyright : updated to 2016 2016-09-03 23:29:23 -06:00
James Yonan
3fd2c451f5 Incremented core version to 3.0.21 2016-09-02 12:57:51 -06:00
James Yonan
662bf7833e ovpn3 core : Added automatic data limits for Blowfish,
Triple DES, and other 64-bit block-size ciphers vulnerable
to "Sweet32" birthday attack (CVE-2016-6329).  Limit such
cipher keys to no more than 64 MB of data
encrypted/decrypted.  While our overall goal is to limit
data-limited keys to 64 MB, we trigger a renegotiation
at 48 MB to compensate for possible delays in renegotiation
and rollover to the new key.

This client-side implementation extends data limit
protection to the entire session, even when the server
doesn't implement data limits.

This capability is advertised to servers via the a
peer info setting:

  IV_BS64DL=1

meaning "Block-Size 64-bit Data Limit".  The "1" indicates
the implementation version.

The implementation currently has some limitations:

* Keys are renegotiated at a maximum rate of once per
  5 seconds to reduce the likelihood of loss of
  synchronization between peers.

* The maximum renegotiation rate may be further extended
  if the peer delays rollover from the old to new key
  after renegotiation.

Added N_KEY_LIMIT_RENEG stats counter to count the number
of data-limit-triggered renegotiations.

Added new stats counter KEY_STATE_ERROR which roughly
corresponds to the OpenVPN 2.x error "TLS Error:
local/remote TLS keys are out of sync".

Prevously, the TLS ack/retransmit timeout was hardcoded to
2 seconds.  Now we lower the default to 1 second and make
it variable using the (pushable) "tls-timeout" directive.
Additionally, the tls-timeout directive can be specified
in milliseconds instead of seconds by using the
"tls-timeout-ms" form of the directive.

Made the "become primary" time duration configurable via
the (pushable) "become-primary" directive which accepts
a number-of-seconds parameter.  become-primary indicates
the time delay between renegotiation and rollover to the
new key for encryption/transmission.  become-primary
defaults to the handshake-window which in turn defaults
to 60 seconds.

Incremented core version to 3.0.20.
2016-09-01 15:19:00 -06:00
James Yonan
44813d7c6f core version : incremented to 3.0.19 2016-08-17 15:31:07 -06:00
James Yonan
96586adff0 Cleanup template : general cleanup including added missing
"inline" and using "typename" instead of "class" in
templates.
2016-08-17 11:32:01 -07:00
James Yonan
ea7cc9efd7 core version : incremented to 3.0.18 2016-08-05 10:57:36 -06:00
James Yonan
41c9857fd2 core version : incremented to 3.0.17 2016-07-13 19:02:02 -07:00
James Yonan
93790ab02b usergroup : minor changes:
* Added uid() method.

* Removed "explicit" qualifier from constructors since it
  appears to be superfluous.

* Added "::" prefix to global libc functions.

* Added clarifying comment that SetUserGroup object does not
  own passwd and group objects, therefore *pw and *gr can
  change under us.
2016-07-12 22:02:37 -07:00
James Yonan
28c6cc2a57 peercred : added match_uid() method. 2016-07-12 22:01:16 -07:00
James Yonan
8a3e809d76 hexstr : print NULL when passed data pointer is null. 2016-07-12 22:00:35 -07:00
James Yonan
fb4a31b9c1 file utilities : added write_binary_atomic() method. 2016-07-12 21:29:50 -07:00
James Yonan
433ba64f59 stat.hpp : added file_mod_time() method. 2016-07-02 00:56:53 -06:00
James Yonan
0fb78ea766 RC : added use_count() method to RC bases to provide client
visibility of the object reference count.
2016-07-02 00:54:39 -06:00
James Yonan
ed6d523e2f number : added parse_number_throw() overload that accepts
error parameter as a const std::string&
2016-07-02 00:53:17 -06:00
James Yonan
d0fee8db51 core version : incremented to 3.0.16. 2016-06-29 00:59:43 -06:00
James Yonan
ca5205b4f3 random : consolidate random functionality in RandomAPI. 2016-06-28 22:31:17 -06:00
James Yonan
5777c6ea1b ActionList : added ActionListReversed class to execute
actions in reverse.  Useful for remove/destroy/unwind
command sets.
2016-06-26 22:01:36 -06:00
James Yonan
3eab705ad1 ActionList : added execute_log() method. 2016-06-26 22:00:48 -06:00
James Yonan
59fbfb6451 Version 3.0.15 2016-06-18 13:54:07 -06:00
James Yonan
f7baa5c812 Core version 3.0.14 2016-06-11 12:12:32 -06:00
James Yonan
7c597f2755 Core version 3.0.13 2016-06-09 19:45:10 -06:00
James Yonan
51bd6133be SplitLines : turned SplitLines into a template so it can work
with other sources of input such as Buffers.
2016-06-09 16:55:53 -06:00
James Yonan
94c61e5864 UserPass : added OPT_OPTIONAL flag, to enable logic where if
option is not present, USERNAME_REQUIRED and
PASSWORD_REQUIRED are ignored.  Also added some rvalue/move
optimizations.
2016-05-27 23:08:33 -06:00
James Yonan
12274e696f string : added replace_copy() method. 2016-05-27 23:08:05 -06:00
James Yonan
a894ef9a97 splitlines : support rvalue/move semantics. 2016-05-27 23:07:00 -06:00
James Yonan
da4fdc5280 RunContext : don't own the Stop object (async_stop), instead
keep an optional pointer to it.  Also, minor updates for
C++ member initializers.
2016-05-27 23:04:07 -06:00
James Yonan
17eb3bcd59 library : added async_sleep_milliseconds(), an interruptible
sleep function.
2016-05-27 22:55:20 -06:00
James Yonan
61b6646bd0 options/hexstr : refactored parse_hex_number() to allow
error detection without throwing an exception, and
extended get_num() method in Option and OptionList to
parse both decimal and hex strings, where hex strings
are prefixed with "0x".
2016-05-12 13:45:14 -06:00
James Yonan
a66058e94e client core : incremented version to 3.0.12 2016-05-10 22:44:45 -06:00
James Yonan
a2b11689e3 AsioBoundSocket : previously declared but did not define:
asio::detail::service_id<SocketService> SocketService::id;

This causes compile issues when compiling without
optimization.
2016-05-06 17:11:20 -06:00
James Yonan
458ffadc70 string : added reduce_spaces() method. 2016-05-05 00:34:33 -06:00
James Yonan
a2f31fbf75 Stop : immediately call newly-registered Stop::Scope handlers
if stop() method was already called before the Stop::Scope
handler was constructed.
2016-05-05 00:33:35 -06:00
James Yonan
8e370c16d3 runcontext : new features to support OMI requirements.
* Support log observers.

* Support asynchronous stop.

* More flexibility on choosing the RC base class of
  ServerThreadType and inherit virtually to allow
  for shared RC bases.
2016-05-05 00:31:43 -06:00
James Yonan
096a8a09fb PThreadBarrier : major refactor to use C++11
<condition_variable> header rather than pthreads directly.

Added asynchronous stop support.
2016-05-05 00:30:11 -06:00
James Yonan
67e12552cf Option : refactor get_num() to provide variants with and
without a default value.  When throwing errors, cite the
index of the parameter in addition to its name.
2016-05-05 00:29:06 -06:00
James Yonan
62645b9563 daemon : in log_setup(), added stdin_to_dev_null and
combine_out_err flags.
2016-05-05 00:28:24 -06:00
James Yonan
ab2645129f daemon: getpid() should be ::getpid(). 2016-05-05 00:27:53 -06:00
James Yonan
c6a78ee27b core : incremented OPENVPN_VERSION to 3.0.11. 2016-04-14 12:30:23 -06:00
James Yonan
dbaf26bbc9 client : support push-peer-info directive.
If either "push-peer-info" or "setenv PUSH_PEER_INFO"
directives are specified, client will push "setenv UV_x"
directives to the server via peer info data.
2016-04-14 00:30:42 -06:00
James Yonan
f59b96d0b2 hexstr : added render_hex_number() method for unsigned char. 2016-03-30 00:08:51 -06:00
James Yonan
e20a62c3c9 string : added force_eol flag (default=false) to unix2dos(). 2016-03-28 14:44:14 -06:00
James Yonan
211af3a91b string : rename methods for consistency with in-place/copy
variants of other string methods:

* rename add_trailing() -> add_trailing_copy()
* rename add_trailing_in_place() -> add_trailing()
2016-03-28 09:42:13 -06:00
James Yonan
e135add60e options : refactored get_num() so that it can be called on
either an Option or OptionList.
2016-03-28 00:02:58 -06:00
James Yonan
6ab7feff15 Make Option::err_ref() public, as it's useful when formatting
error messages that refer to a particular option.
2016-03-28 00:01:23 -06:00
James Yonan
2e06d3a367 Option : exception-proof Option::printable_directive() 2016-03-28 00:00:25 -06:00
James Yonan
5b35f09ff2 platform_string() : added app_version parameter. 2016-03-27 23:57:36 -06:00
James Yonan
8a90f0bd79 string:
* Added ends_with() method to test for trailing char.

* Added add_trailing_crlf() methods.
2016-03-27 23:49:38 -06:00
James Yonan
59c6f3d43a Added string::is_alpha() method. 2016-03-19 01:50:09 -06:00
James Yonan
ea935109b9 SplitLines: added default values for max_line_len and trim. 2016-03-19 01:48:34 -06:00
James Yonan
63f45f0dbc process: added move-aware Command(Argv) constructor. 2016-03-19 01:47:18 -06:00
James Yonan
55011e4a9d Added ActionList::to_string() method. 2016-03-19 01:46:25 -06:00
James Yonan
1a9ad56946 RedirectStd : in constructor, allow in_fn to be empty to
not redirect stdin.
2016-03-15 15:07:22 -06:00
James Yonan
6d59eea0fb Added optional title string to platform_string() method. 2016-03-15 15:06:08 -06:00
James Yonan
ec879a1a1d Added OptionList::parse_option_from_line() method. 2016-03-15 15:04:18 -06:00
James Yonan
c01506670f asiopolysock : added is_open() method. 2016-03-15 15:03:46 -06:00
James Yonan
7d4bebca25 Added string::is_ctrl() and string::contains_non_space_ctrl()
methods.
2016-03-14 17:14:24 -06:00
James Yonan
f950741131 Added read_stdin() method. 2016-03-14 17:13:19 -06:00
James Yonan
a7ba46e6f7 In PThreadBarrier, allow late-setting of limit after
construction by using using new set_limit() method.
2016-03-14 00:12:51 -06:00
James Yonan
1e907bc0e6 In file_exists(), if filename is the empty string,
return false before calling stat().
2016-03-08 12:59:09 -07:00
James Yonan
01a4dba328 Added OptionList::parse_from_argv_static() method for parsing
argv-style command-line.
2016-03-02 00:53:01 -07:00
James Yonan
ebf6713c77 Incremented OpenVPN core version to 3.0.10. 2016-03-02 00:31:18 -07:00
James Yonan
4d42ff8b0e Added wstring::pack_string_vector() method.
Also added forgotten "inline" qualifiers to
all wstring.hpp methods.
2016-02-24 23:39:41 -07:00
James Yonan
13b2945d8c Added string::join() method. 2016-02-24 23:38:55 -07:00
James Yonan
c97503c4f8 Incremented ovpn3 client core version to 3.0.9. 2016-02-22 14:36:09 -07:00
James Yonan
c05cbaf46a Fixed bug in base64 encode when std::string containing UTF-8
chars is passed to this template method:

    template <typename V>
    std::string encode(const V& data) const

The problem is that references to data[] were failing to
cast the value to unsigned char, so UTF-8 chars >= 0x80
were being interpreted as negative values.
2016-02-22 14:26:07 -07:00
James Yonan
7a17151992 Added dump_hex(const std::string&) method. 2016-02-22 14:22:14 -07:00
James Yonan
53453bd7af Incremented client API version to 3.0.8. 2016-02-05 12:20:56 -07:00
James Yonan
4a00d11a4a OptionList::extend(other, name) now returns the number
of elements processed.
2016-02-05 12:11:08 -07:00
James Yonan
93913a3479 class Option -- provide a vararg constructor. 2016-02-05 12:09:37 -07:00
James Yonan
984ec7a4c9 Incremented core version to 3.0.7. 2016-01-28 21:45:35 -07:00
James Yonan
5c85473243 Some linux platforms don't define SO_REUSEPORT, so don't
compile SockOpt::reuseport() in this case.  Since only
servers actually call it, the client should compile fine
without it.
2016-01-23 10:28:35 -08:00
James Yonan
8f63eb883c In ActionList, added add(Action* action) method. 2015-12-28 13:22:15 -07:00
James Yonan
7728ab5bc3 Extended Unicode::is_valid_utf8() to check additional string
attributes such as length and presence of control and/or
space chars.
2015-12-22 19:10:53 -07:00
James Yonan
92d4591507 Because of Android NDK issues with std::to_string, change
printfmt() to use PrintFormatted<std::ostringstream> instead
of PrintFormatted<std::string> as its underlying formatter.
2015-12-16 13:34:11 -07:00
James Yonan
42424a3b47 Apparently Android NDK doesn't support std::to_string (WTF?),
so work around it.

http://stackoverflow.com/questions/22774009/android-ndk-stdto-string-support
2015-12-16 13:20:33 -07:00
James Yonan
306f9f1951 Moved classes Argv and ArgvWrapper out of process.hpp
and into a new source file openvpn/common/argv.hpp
2015-11-25 19:41:37 -07:00
James Yonan
4ecf9594e8 ovpn3 -- support multiple compilation units by managing the
definition of mutable globals.

For all but the first compilation unit, define:

  #define OPENVPN_EXTERN extern

This will cause mutable globals to be referenced as
extern.
2015-11-25 12:11:36 -07:00
James Yonan
134ba710f2 ovpn3 core globals cleanup:
1. move all const globals into anonymous namespace
2. make sure that all non-class functions are inline
3. refactor class static data members
2015-11-25 11:34:41 -07:00
James Yonan
20cba09579 In runcontext.hpp, use "<< std::flush" instead
of std::cout.flush();
2015-11-24 19:22:17 -07:00
James Yonan
331827fd06 In SockOpt::Creds, added root_uid() method. 2015-11-20 19:02:37 -07:00
James Yonan
693909ae42 Restructured class Cleanup to no longer depend on
std::function.
2015-11-20 19:00:45 -07:00
James Yonan
59f0c72674 Added classes Stop and AsioStopScope for terminating a
nested asio::io_context.
2015-11-20 18:58:13 -07:00
James Yonan
34410f6721 In openvpn/common/hostport.hpp, added is_valid_port()
and validate_port() methods.
2015-11-10 23:07:43 -07:00
James Yonan
054946ca5f Minor mod to openvpn/common/abort.hpp for C++11. 2015-11-10 23:04:05 -07:00
James Yonan
2f40c52fbc Change to calls of Windows API methods:
* Where unicode/ansi versions of a method exist, always
  explicitly call one of unicode or ansi methods by
  appending a 'W' or 'A' to the end of the method name.
  Never omit the 'W' or 'A' because that will cause the
  default method to be used which may vary according to
  build flags.

* Prepend all Windows API method references with "::" to
  indicate that the method names should be resolved from
  the top-level namespace.
2015-11-09 14:56:08 -07:00
James Yonan
2c7bfc37ed Added new file openvpn/common/sleep.hpp with
portable sleep_milliseconds() function.
2015-11-05 16:11:49 -08:00
James Yonan
c859a46187 Added class Cleanup (openvpn/common/cleanup.hpp), a
general model for executing a std::function in the
destructor.
2015-11-02 20:10:46 -07:00
James Yonan
dcebf7b559 Added sort parameter (bool) to enum_dir() to sort results. 2015-10-30 16:41:18 -06:00
James Yonan
4b1379e919 In hexstr.hpp, extended dump_hex() to show both hex and ascii. 2015-10-30 16:39:38 -06:00
James Yonan
d4be16c109 Added string::is_printable() methods for char and unsigned char. 2015-10-30 16:38:41 -06:00
James Yonan
4c7f7af10d In process.hpp, added new system_cmd() variant that uses pipes
to communicate with subprocess and provides std::strings for
input/output/error.

Updated Command class with new execute() signature.

Added RedirectPipe (redir.hpp) to deal with handling
input/output/error pipes for a subprocess.
2015-10-28 22:40:15 -06:00
James Yonan
27061e01b1 In openvpn/common/signal.hpp, added SIGPIPE support. 2015-10-28 22:38:14 -06:00
James Yonan
0cb18b6084 Created new ActionListFactory abstraction, to allow client tun
implementations to provide custom ActionList handlers.
This can be used, for example, to forward tun configuration
commands requiring higher privileges to a remote daemon.
2015-10-27 18:34:13 -06:00
James Yonan
aa4f2773f3 Added openvpn/common/wstring.hpp for classes that deal
with wchar_t and std::wstring types.
2015-10-27 18:30:57 -06:00
James Yonan
5e1a706c67 Added string::remove_blanks() method. 2015-10-27 18:19:32 -06:00
James Yonan
5f6989465a Fixed recent regression in userpass.hpp where parse()
method was failing to identify auth-user-pass directive
when given without parameters.
2015-10-19 08:07:17 -07:00
James Yonan
a35ed0375f Removed write_private() as it's no longer used on this branch. 2015-10-18 15:21:25 -07:00
James Yonan
ee6882725b Added comment that class UMask is not thread-safe. 2015-10-18 15:07:17 -07:00
James Yonan
32b6912931 Added Windows named-pipe support to RemoteList,
Listen::List, Protocol, and AsioPolySock.
2015-10-16 21:00:51 -06:00
James Yonan
d0dcfe759c In file.hpp, added write_binary_list() method. 2015-10-15 23:37:00 -07:00
James Yonan
508d6858ac Ported runcontext.hpp to Windows. 2015-10-08 21:54:22 -06:00
James Yonan
b2769db93a In format.hpp, work around a Windows symbol conflict
by renaming template var OUT to OUTPUT.
2015-10-08 21:52:59 -06:00
James Yonan
0268d210dd Added Windows implementation for n_cores(). 2015-10-08 21:51:29 -06:00
James Yonan
c90eb0b74b Made n_cores() portable between Linux and Mac OS X and
moved it to new file openvpn/common/core.hpp
2015-10-08 00:30:35 -07:00
James Yonan
c26f8d7375 Make PThreadCondBase portable between Linux and Mac OS X. 2015-10-08 00:25:06 -07:00
James Yonan
6b92002fde Make peercreds() portable between Linux or Mac OS X. 2015-10-08 00:23:19 -07:00
James Yonan
97c967be57 In unicode.hpp, added Unicode::UTF8Iterator. 2015-10-01 17:34:13 -07:00
James Yonan
8b6b2015a0 Fixed issue where utf8_length() was not properly reducing
the length passed to isLegalUTF8() for characters near the
end of the string.
2015-10-01 16:35:45 -07:00
James Yonan
0710d1f327 Added string::is_empty() method that returns true if
passed string is empty or contains only space chars.
2015-10-01 16:33:19 -07:00
James Yonan
07bcab9ab3 Extend is_close_tag() in options.hpp to search for
wildcard close tag if tag string is empty.
2015-10-01 16:29:38 -07:00
James Yonan
2df4f44711 Added/changed printfmt() format specifiers:
* %r formats any argument regardless of type
     and single-quotes it.
* %R formats any argument regardless of type
     and double-quotes it.
2015-10-01 16:21:21 -07:00
James Yonan
f3e9dbde86 Added OPENVPN_FMT(...) macro. 2015-10-01 16:20:15 -07:00
James Yonan
e6d27bc57e In format.hpp, added specializations for bool. 2015-10-01 16:18:45 -07:00
James Yonan
96866ac7e1 format.hpp:
* Added static polymorphic sink for print formatting in
  print_formatted_detail::Output<T> where T can be
  std::string or std::ostringstream

* By default printfmt() uses:

  PrintFormatted<std::string> pf(fmt, 256);

* prune openvpn::to_string() methods prior to removal
  (obsoleted by C++11 std::to_string())
2015-09-25 11:39:12 -07:00
James Yonan
d0b570bd7e In userpass.hpp:
* Added new parse method that parses creds out
  of a file.

* Added dedicated exception creds_error.
2015-09-24 14:28:15 -07:00
James Yonan
5885b35731 In format.hpp:
(1) Create new versions of to_string() method:
    (a) for numeric types, dispatch to std::to_string()
    (b) for string, char, and nullptr_t types, handle directly
    (c) for other types, use std::ostringstream

(2) Create vararg methods prints, print, and printd
    for printing argument lists.

(3) Create method printfmt() with string formatting
    similar to sprintf but fully type-safe.
    usage: printfmt(<format_string>, args...)
    options:
      %s formats any argument regardless of type.
      %r formats any argument regardless of type and quotes it.
      %% formats '%'
2015-09-24 13:52:24 -07:00
James Yonan
6378339776 Changes to hash.hpp and users:
1. Hash code is now compatible with VS 2015, so
   HAVE_HASH_COMBINE can be removed.

2. Added OPENVPN_HASH_METHOD macro for defining std::hash<>
   classes.

3. Make Hash::combine() into a varargs method.
2015-09-24 13:43:38 -07:00
James Yonan
29e427241b In exception.hpp, optimize Exception() constructor for
string move.

Also added noexcept qualifier to most Exception methods.
2015-09-23 23:26:30 -07:00
James Yonan
415dc9067b In splitlines.hpp, rename S_OK to S_OKAY due to Windows symbol
conflict.
2015-09-23 23:11:55 -07:00
James Yonan
a9ed9d47f2 ovpn3 client API now supports adding user-defined peer-info
data to the OpenVPN handshake (peer-info is a client -> server
key/value list that is part of the OpenVPN protocol).  To
add peer-info key/value pairs, use ClientAPI::Config::peerInfo.

Incremented core OPENVPN_VERSION to "3.0.6".
2015-09-21 19:42:24 -07:00
James Yonan
ba91532554 In merge.hpp, detect multiline breakout attempt. 2015-09-18 21:25:40 -07:00
James Yonan
d3d45937dc Added write_private() method, for writing a string to a file
that is created with access bits limited to owner access.
2015-09-18 10:26:21 -07:00
James Yonan
9c2fa0a6e5 In namespace string::, added new methods:
* ends_with_newline()
* spaces()
* indent()
* is_empty()
2015-09-18 10:23:18 -07:00
James Yonan
a8e8881510 In splitlines.hpp, added a const line_ref() method. 2015-09-18 10:22:47 -07:00
James Yonan
8dcf7dc828 Asio async_wait() lambdas should always check error status. 2015-09-18 10:22:11 -07:00
James Yonan
48a9d237d7 In options.hpp, added detect_multiline_breakout() method as
a security check to ensure that untrusted content pasted into
multiline config file directives such as:

<cert>
. . .
</cert>

doesn't try to break out of the pseudo-XML block
by inserting its own </cert>.
2015-09-18 10:19:38 -07:00
James Yonan
ecfd16e432 In hostport.hpp, when validating host/port, include the bad
host/port string in the thrown exception by sanitizing it
with Unicode::utf8_printable().
2015-09-18 10:18:22 -07:00
James Yonan
50118b0444 Extended UserPass methods with new flags:
OPT_REQUIRED
  USERNAME_REQUIRED
  PASSWORD_REQUIRED
  TRY_FILE
2015-09-18 10:16:37 -07:00
James Yonan
d38101d5c2 In buflist.hpp:
* Added explicit flag to turn on size=1 optimization.
* Added join() method without arguments.
* Added copy() method.
2015-09-18 10:14:03 -07:00
James Yonan
685c7601e2 In common/file.hpp, added read_binary_linear() to read a
file without seeking to determine its length.
2015-09-08 22:16:46 -07:00
James Yonan
1b913b16f1 Added PersistentFile::stat() method to return
struct stat of active file.
2015-09-08 22:14:52 -07:00
James Yonan
b4dea33463 Renamed PersistentOutputFile to PersistentFile, since class
will soon have input methods as well.
2015-09-08 11:37:55 -07:00
James Yonan
494cf8bd2d Added string::is_digit() method. 2015-09-08 05:57:51 -07:00
James Yonan
40bc68bb74 Added SockOpt::Creds::root_or_self_uid() method to test if
local socket client is root or has our own UID.
2015-09-08 05:55:08 -07:00
James Yonan
1c67469856 In AsioPolySock::Base, add boolean is_local() method to
test if socket is a unix domain socket.
2015-09-08 05:52:56 -07:00
James Yonan
af66ff434b In redir.hpp, add "::" prefix to libc methods. 2015-09-07 06:02:50 -07:00
James Yonan
03057dee0d In OptionList, touched_ private bool is now mutable AND
volatile.  The volatile qualifier is added because
OptionList const methods are often called from multiple
threads concurrently.
2015-09-06 16:42:39 -07:00
James Yonan
865176c6c6 Added HostList::Host, List, and Iterator for managing lists
of HOST::PORT pairs.
2015-09-02 12:06:24 -07:00
James Yonan
c4761ebb85 Added AutoReset class template to automatically reset
a target object when AutoReset goes out of scope.
2015-09-02 12:04:04 -07:00
James Yonan
347427b81c In string.hpp:
* Added string::trim_crlf_copy().

* Added a simplified string::split() method.
2015-09-02 03:10:12 -07:00
James Yonan
a14ca71a5f Changed all ::write() calls to use write_retry() instead.
write_retry() is a thin wrapper around ::write() that can
potentially call ::write() multiple times to fully write
the buffer.
2015-09-02 03:08:31 -07:00
James Yonan
22b9fb347f In split_host_port(), allow caller to specify a default
port and handle cases where IP address or host is bracketed,
such as "[IP]:PORT".
2015-09-02 03:06:32 -07:00
James Yonan
8d78caf733 In getpw.hpp, fixed issue where OPENVPN_PLATFORM_WIN was being used
before the source file that defines it was being included.
2015-09-02 03:04:19 -07:00
James Yonan
7826daa516 In asiopolysock.hpp and sockopt.hpp, added socket methods for
setting FD_CLOEXEC and getting the remote IP address and port.
2015-09-02 03:02:22 -07:00
James Yonan
061706ebd9 In process.hpp, use vfork() instead of fork() when possible,
such as when execve() can be executed immediately after fork()
on the child side.
2015-08-24 21:08:35 -07:00
James Yonan
00aa2f05d5 In hexstr.hpp, added parse_hex_number() method that accepts
a std::string argument.
2015-08-24 21:07:24 -07:00
James Yonan
e2e55ba6ec Forgot to specify "inline" for to_string() method
in common/format.hpp.
2015-08-24 21:06:23 -07:00
James Yonan
63233836f8 Added openvpn/common/glob.hpp, a wrapper for the unix
glob() function used for filename wildcard expansion.
2015-08-20 12:46:34 -07:00
James Yonan
50868f3e37 Fixed minor bug in rc.hpp where the rhs argument of a
move-assignment method was mistakenly declared as const.
2015-08-20 12:43:58 -07:00
James Yonan
d9f807ba50 Added close() method to AsioPolySock::Base and derived classes. 2015-07-21 05:36:15 -07:00
James Yonan
ba44de2911 In SetUserGroup (on Linux), retain core dumpability after
setgid/setuid.
2015-07-16 18:51:20 -07:00
James Yonan
3a0bd15039 runcontext.hpp changes:
* added ServerThreadWeakBase, an alternative version of
  ServerThreadBase that supports weak pointers,

* added set_exit_socket() method for triggering a mutual
  exit between two partner processes if either process
  closes their end of the socket,

* added a prefix string to distinguish between multiple
  RunContext objects, and

* refactored cancel() method to better leverage on asio::post.
2015-07-04 16:36:15 -06:00
James Yonan
d014f2ebb6 Added class PersistentOutputFile, an object that holds
a file descriptor to a writable file, and keeps the
file open over multiple write cycles to the file.
Useful for updating a file after privilege downgrade.
2015-07-04 16:19:58 -06:00
James Yonan
014c53d005 Added UMask helper class to manage umask using RAII pattern. 2015-07-04 16:17:08 -06:00
James Yonan
570a1642ad Added SockOpt::peercreds(), to get credentials of process on
other end of unix domain socket using SO_PEERCRED socket op.
2015-07-04 16:14:33 -06:00
James Yonan
23cfbd2c2a Added Asio polymorphic socket object for handling TCP
and unix domain sockets.
2015-07-04 16:12:40 -06:00
James Yonan
006bf0d838 Added class AsioContextStore, a container for asio::io_context
objects from different threads.
2015-07-04 16:09:39 -06:00
James Yonan
56c07b1152 In class SetUserGroup, added invalidate() method.
Also added leading :: to some global functions.
2015-07-04 15:58:47 -06:00
James Yonan
35c920626b Added convenience method next() in class SplitLines. 2015-07-04 15:57:31 -06:00