Commit Graph
346 Commits
Author SHA1 Message Date
Dimitri Papadopoulos 2e89f38e1e Avoid NULL dereference in case of memory exhaustion
Fixes #721.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-16 15:54:08 +02:00
Dimitri Papadopoulos 5a81433f47 Log messages don't need a trailing \n
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-12 08:14:21 +02:00
Dimitri Papadopoulos bd5e1636dc Use strerror() and pass proper errno to it
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-11 19:57:15 +02:00
Nikos Mavrogiannopoulos 139ff827d9 config: restructure per-vhost configuration for clarity and maintainability
Introduce a protobuf-generated ReloadableConfig (cfg.proto) to hold all
fields that reload on SIGHUP, and separate them from static_cfg_st, which
holds fields that require a server restart.  Named vhosts inherit from the
default vhost via a pack/unpack round-trip. Adding a new config field
only requires editing cfg.proto.  Struct and accessor names (ReloadableConfig,
static_cfg_st, GETRCONFIG, GETSCONFIG) now reflect each field's lifetime.
A new unit test covers the full inheritance path.

Resolves: #705

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-22 20:29:15 +02:00
Grigory Trenin eddd29f59b Do not forward UDP until client is authenticated
Do not forward DTLS packets until the client is authenticated to
prevent the race between AUTH_COOKIE_REP and CMD_UDP_FD messages
on the command socket.

Closes #706

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-21 07:06:59 -04:00
Grigory Trenin db125634b8 Allow using no-udp option in vhosts
Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-14 13:26:32 -04:00
Grigory Trenin a644718fd7 Fix worker process title not being set
Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-01-25 07:33:21 -05:00
Grigory Trenin 8636464880 tests: replace strcpy() with strlcpy()
- Replaced strcpy() with strlcpy() in test files
- Added linking to libcommon.a (and its dependency libnettle)
  as not all systems provide strlcpy()
- Centralized syslog_open variable by moving it from multiple definitions
  in main.c, worker.c, and test files into log.c. This avoids duplication
  and resolves a linking conflict with libcommon.a

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-01-07 15:46:16 -05:00
Grigory TreninandNikos Mavrogiannopoulos 3892e032d9 Fix DTLS with systemd socket activation
Remove IPV6_V6ONLY flag from per-client UDP sockets as it prevents
IPv4 traffic on systemd-provided IPv6 sockets. This was a legacy
from the old reopen_udp_port() code and is no longer needed.

Fixes: #647

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2025-12-21 10:48:59 +01:00
Dimitri Papadopoulos Orfanos 31b3d6b930 Merge branch 'tmp-cloexec' into 'master'
Update cloexec.* vendored files

See merge request openconnect/ocserv!439
2025-12-06 11:10:11 +01:00
Dimitri Papadopoulos e8139682fb Move cloexec.* files out of common
These files are only used by the main program.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2025-04-02 09:05:42 +02:00
Dimitri Papadopoulos 5d1eeee8ca Main() signature compliant with C standard
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2024-12-06 12:08:52 +01:00
Nikos Mavrogiannopoulos 60dce59d97 forward_udp_to_owner: modified check to help static analyzer
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2024-12-01 20:52:12 +01:00
Nikos Mavrogiannopoulos 78c65b5adf Updated code to follow with kernel coding style
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2024-12-01 17:01:05 +01:00
Dimitri Papadopoulos 20ed2bfc7a Do not include <malloc.h> but for malloc_trim()
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2024-03-22 13:56:38 +01:00
Dimitri Papadopoulos Orfanos aa41bfb8fe Merge branch 'PACKAGE_NAME' into 'master'
Further improvements to arguments of AC_INIT

See merge request openconnect/ocserv!410
2024-01-07 16:28:04 +00:00
Nikos Mavrogiannopoulos 313e68b933 main: increased details on error message
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2024-01-07 00:37:33 +01:00
Dimitri Papadopoulos badf9be99a Further improvements to arguments of AC_INIT
Reapply df6a3c2a, this time without regression.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2024-01-06 18:21:27 +01:00
Nikos Mavrogiannopoulos e44cc6fd78 Separated logging for worker and main and oc_syslog() respects log-level
This makes oc_syslog respect the configured log-level. This also introduces
a clear separation of the logging function between the two processes.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2023-12-17 11:18:47 +01:00
Nikos Mavrogiannopoulos f0067ae0ea Cleanup of the logging subsystem; allow logging to stderr only
Separated the logging logically from any remaining debugging
features. Introduced command line option for logging to stderr
only (for systemd and containers). The default log level is set
to (2) info.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2023-12-15 13:04:40 +01:00
Nikos Mavrogiannopoulos aaf2a53246 Improve graceful termination
Wait for all processes to terminate within 5 seconds, and
report the number of processes that did not terminate.

Resolves: #563

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2023-12-13 23:02:07 +01:00
Nikos Mavrogiannopoulos 26258d7cb1 Revert "Fixing issue: Authentication requests from the same IP address are not load balanced among security modules"
Each cookie is valid for its IP address and when reconnected it must
reach the same sec-mod that contains the corresponding session
information.

This reverts commit 4ec99609ca.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2023-09-15 15:19:13 +02:00
Nikos Mavrogiannopoulos 1ca50d7337 Removed gnulib
Supporting gnulib brought a whole class of problems due to its complexity.
Removing its support eliminates this class of problems and simplifies the
code significantly.

This sets the locale explicitly on server startup to eliminate the
need for custom string comparison functions.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2023-06-13 16:54:38 +02:00
Dimitri Papadopoulos 5e881697e7 void function return statements are not generally useful
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2023-06-04 14:33:58 +02:00
Nikos Mavrogiannopoulos f828f8d5bb use modern libtasn1 definitions
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2023-06-01 19:47:41 +02:00
Dimitri Papadopoulos eb657c8354 Use ARRAY_SIZE macro for more readable code
Copied over from the Linux kernel.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2023-01-12 09:31:50 +01:00
Dimitri Papadopoulos 7b2cb88350 Use EXIT_SUCCESS and EXIT_FAILURE with exit()
The use of `EXIT_SUCCESS` and `EXIT_FAILURE` is slightly more portable
than the use than the use of 0 and nonzero value like 1 or -1. In
practice, this is not an issue on Unix-like systems, but it does make
the intent clearer.
2022-12-30 17:31:21 +01:00
Dimitri Papadopoulos cd4c4c26eb The second argument of time() is a pointer
Do not use `0` instead of `NULL` in C.
2022-12-30 17:31:13 +01:00
Nikos Mavrogiannopoulos 30ae99084d libtasn1: no longer use deprecated types
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2022-12-02 19:59:52 +01:00
Dimitri Papadopoulos f28669bf60 Remove spaces
* Remove trailing spaces at end-of-line
* Remove blank lines at end-of-file

Signed-off-by: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com>
2022-11-28 11:22:33 +01:00
Feng Xie 4ec99609ca Fixing issue: Authentication requests from the same IP address are not load balanced among security modules 2022-02-28 16:00:13 +00:00
Nikos Mavrogiannopoulos 53b08d2433 forward_udp_to_owner: sanity check of session_id_size
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2022-02-15 10:33:45 +01:00
Nikos Mavrogiannopoulos 94af87c7a2 libtasn1: use NULL instead of ASN1_TYPE_EMPTY
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2022-02-10 15:31:39 +01:00
Russ Young e9ddacde59 Changes offensive messages.
Changed noisy messages to be logged at LOG_DEBUG level.
2021-02-24 11:45:36 -07:00
Nikos Mavrogiannopoulos 8d4a5924e4 worker.h: share OCSERV_ENV_WORKER_STARTUP_MSG between main and worker
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2020-12-14 23:26:17 +01:00
Nikos Mavrogiannopoulos 3d7c846ecd ocserv: renamed main_loop
This avoids warnings and static analyzers complains about
libev functions hiding the global 'loop' variable.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2020-12-09 15:56:29 +01:00
Nikos Mavrogiannopoulos 85817d38b7 get_session_id: avoid parameter hiding
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2020-12-09 15:47:52 +01:00
Nikos Mavrogiannopoulos 5cf457b425 Removed the listen-clear-file config option
This option was almost impossible to use in general and worked with
very few clients only (not including openconnect). That also meant that
it could not be tested. Removed to reduce maintenance to parameters
that are used in practice.

Resolves: #376

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2020-12-03 10:04:57 +01:00
Nikos Mavrogiannopoulos 6c9615618d Merge branch 'tmp-coverity-fixes' into 'master'
Several fixes or annotations attributed to coverity scan

See merge request openconnect/ocserv!237
2020-12-03 09:00:59 +00:00
Alan Jowett 50ab40782a Fix coverty warning in forward_udp_to_owner
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
2020-12-02 12:58:56 -07:00
Nikos Mavrogiannopoulos 56c6ab9cbf _listen_unix_ports: error when remove fails
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2020-11-26 14:20:26 +01:00
Nikos Mavrogiannopoulos d83a39da51 set_env_from_ws: ensure there are no uninitialized variables from snapshot
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2020-10-30 22:11:09 +01:00
Alan Jowett 3436705a9c Allow setup of new DTLS session while processing on old session
Resolves: #359

Signed-off-by: Alan Jowett alan.jowett@microsoft.com
2020-10-19 10:36:03 -06:00
Alan Jowett cd0f382628 Latency stats should be at LOG_DEBUG not LOG_INFO level
Resolves: #363

Signed-off-by: Alan Jowett alan.jowett@microsoft.com
2020-10-07 13:09:05 -06:00
Alan Jowett 5b402014fd Don't apply BanIP checks to clients on the same subnet.
Resolves #360

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
2020-10-01 11:59:41 -06:00
Alan JowettandNikos Mavrogiannopoulos 12c3d62276 Stop listening on ocserv-sm socket on error to prevent looping.
Resolves #356

Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
2020-09-29 22:51:52 +02:00
William DauchyandNikos Mavrogiannopoulos 80babceacf listen-netns: fix worker case for DTLS
while using udp, we later open a file descriptor for the worker. With a
listen netns config, I overlooked this case which oblige me to move the
struct containing the file descriptor in the main one. Then I can access
them from each worker to make it possible to open the socket in the
correct netns. I also need to keep the netns fd open during the whole
life of the process.

the issue was not visible on a tcp-only case, but while using udp you
can see logs such as:

main[user]: x.x.x.x:54024 bind UDP to 0.0.0.0:443: Cannot assign requested address
worker[user]: x.x.x.x setting up DTLS-PSK connection
main[user]: x.x.x.x:54024 bind UDP to 0.0.0.0:443: Cannot assign requested address

update tests to reflects that:
- instead of creating our own netns, use the one created in common.sh
- we start server in ns1, but listen in ns2, and test client from ns3
  (we don't want to listen in ns1 to test listen-ns)

Signed-off-by: William Dauchy <w.dauchy@criteo.com>
2020-09-20 21:49:08 +02:00
Alan Jowett 77dfa36c71 Stop accepting new TCP connections when the server is at maximum active connection capacity.
Add support for gracefully stopping the server.
Add primer on using ocserv with L3 load balancer.

Resolves: #345

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2020-08-28 16:01:35 -06:00
Alan Jowett 945699097d Modify ocserv-sm to permit it to scale up to the number of CPUs. This permits a higher rate of client connections and prevents TLS signing from becoming a bottleneck for clients connecting.
Resolves: #341

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
2020-08-26 09:46:04 -06:00
William Dauchy f4c7d41d14 add basic namespace support for listen address
- this patch adds `listen-netns` parameter
- when set the listening socket will be created in the given namespace

it allows to properly segregate your traffic:
- do the backend traffic in the root namespace
- receive the VIP traffic in a given namespace

All this patch is widely inspired by haproxy implementation which allows
to bind each IP in a given namespace.

Resolves: #316

Signed-off-by: William Dauchy <w.dauchy@criteo.com>
2020-07-13 18:11:30 +02:00