Commit Graph

36 Commits

Author SHA1 Message Date
Tobias Brunner 02b348403a Fixed some typos, courtesy of codespell 2019-04-29 15:09:20 +02:00
Micah Morton 4f1d2f2b09 Allow charon to change group on files before dropping caps
Allow charon to start as a non-root user without CAP_CHOWN and still be
able to change the group on files that need to be accessed by charon
after capabilities have been dropped. This requires the user charon starts
as to have access to socket/pidfile directory as well as belong to the
group that charon will run as after dropping capabilities.

Closes strongswan/strongswan#105.
2018-06-12 10:25:30 +02:00
Tobias Brunner 89bd016ef4 Fixed some typos, courtesy of codespell 2018-05-23 16:33:02 +02:00
Micah Morton b9fcc61991 Allow strongSwan to be spawned as non-root user
This patch allows for giving strongSwan only the runtime capabilities it
needs, rather than full root privileges.

Adds preprocessor directives which allow strongSwan to be configured to
 1) start up as a non-root user
 2) avoid modprobe()'ing IPsec kernel modules into the kernel, which
    would normally require root or CAP_SYS_MODULE

Additionally, some small mods to charon/libstrongswan ensure that charon
fully supports starting as a non-root user.

Tested with strongSwan 5.5.3.
2018-05-14 15:50:01 +02:00
Tobias Brunner d889f20ca1 streams: Remove registered systemd stream service
Fixes: 59db98fb94 ("stream: Add basic stream service for systemd sockets")
2017-10-18 09:25:15 +02:00
Tobias Brunner 23e76d250f streams: Named systemd sockets are only supported since systemd v227 2017-10-13 10:17:37 +02:00
aszlig 59db98fb94 stream: Add basic stream service for systemd sockets
This allows systemd socket activation by passing URIs such as systemd://foo
to plugins such as VICI.

For example setting charon.plugins.vici.socket = systemd://vici, a
systemd socket file descriptor with the name "vici" will be picked up.

So these would be the corresponding unit options:

  [Socket]
  FileDescriptorName=vici
  Service=strongswan.service

  ListenStream=/run/charon.vici

The implementation currently is very basic and right now only the first
file descriptor for a particular identifier is picked up if there are
multiple socket units with the same FileDescriptorName.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>

Closes strongswan/strongswan#79.
2017-10-10 11:11:11 +02:00
Tobias Brunner cee338eccd stream-service: Prevent race conditions due to blocking call to destroy()
In the previous implementation queued jobs could prevent a service from
getting destroyed.  This could have lead to a deadlock when the
processor is cancelled.  Now destroy() still blocks, but waits only for
actually running tasks.  The service instance is reference counted so that
queued jobs can safely be destroyed.
2014-09-09 10:58:59 +02:00
Tobias Brunner 10859adfd4 stream-service: Do not accept or re-register when service is terminated 2014-09-09 10:58:59 +02:00
Tobias Brunner 22e90cad00 stream-service: Restart accepting without blocking
Calling on_accept() sometimes lead to deadlocks when service->destroy()
was called concurrently.  That is, two threads waiting in on_accept() but
the last worker would only wake one due to the call to signal().  Calling
broadcast() wouldn't help either as that could lead to crashes if the thread
that called destroy() is woken first.

This is also more efficient as a constant pool of concurrent workers can
be maintained, otherwise peaks at the limit were followed by only a single
worker being active.
2014-09-09 10:58:58 +02:00
Martin Willi aa5b49c037 stream: Separate TCP/Unix stream helpers from stream/service implementations
This allows us to disable Unix sockets cleanly on Windows. Replaces some
read/write calls with recv/send counterparts, as Winsock does not like
read/writes.
2014-06-04 15:53:00 +02:00
Martin Willi 961409b668 lookip: Disconnect asynchronously to avoid dead-locking watcher unregistration
While it really would be desirable to allow stream destruction during on_read()
callbacks, this does not work anymore since e49b2998. Until we have a proper
solution for this issue, use asynchronous disconnects for the only user doing
so.

Fixes #518.
2014-02-17 09:48:55 +01:00
Martin Willi e49b299867 stream: Make sure no watcher callback is active while changing stream callbacks
When changing async callbacks on streams, we have to make sure the watcher
callback is not currently active and has temporarily disabled callbacks. This
could have been the case, as we didn't explicitly removed any pending
watcher registration if both callbacks are NULL.

By enforcing the watcher unregistration, we are sure the watcher callback is
not active and currently is not mangling the callback hooks. This should make
sure we avoid any races for the callback variables.
2014-01-22 15:34:53 +01:00
Tobias Brunner 60ddf6284f Use exact mask when calling umask(2)
Due to the previous negation the high bits of the mask were set, which
at least some versions of the Android build system prevent with a compile-time
check.
2013-10-29 16:01:55 +01:00
Tobias Brunner d7dc4fedd1 stream: Ensure UNIX socket path is null terminated 2013-07-24 16:17:23 +02:00
Martin Willi b4b3959b22 stream-service: move CAP_CHOWN check from plugins to service constructor
A plugin service can be a TCP socket now, so it does not make much sense
to strictly check for CAP_CHOWN.
2013-07-18 16:00:31 +02:00
Martin Willi 4701929266 stream: allow async read/write callback to destroy the stream explicitly 2013-07-18 16:00:29 +02:00
Martin Willi c9d1742b5d stream: don't close underlying socket when creating a stream from it 2013-07-18 16:00:29 +02:00
Martin Willi e6e8a2b2e0 stream: support keeping the service alive outside of service callback 2013-07-18 16:00:28 +02:00
Martin Willi d57b9e7c82 stream: add read/write_all() methods to stream 2013-07-18 16:00:28 +02:00
Martin Willi 1d1ef9e7ca stream: support cancellation of stream service callback 2013-07-18 16:00:28 +02:00
Martin Willi 047a190600 stream: use a service constructor to create services
It does not make much sense to reference running services in the manager,
especially as unregistration would need the URI (which a user would have to
store instead of the service reference).
2013-07-18 16:00:28 +02:00
Martin Willi fbdc65debb stream: replace print/vprint() convenience functions by a FILE* getter
While this will complicate the implementation of streams not based on a fd,
it allows us to unleash the full power of FILE based convenience functions.
2013-07-18 16:00:28 +02:00
Martin Willi 70d1ccec96 stream: add a concurrency option to services, limiting parallel callbacks 2013-07-18 16:00:28 +02:00
Martin Willi db0e160ba2 stream: add a job priority option to stream services 2013-07-18 16:00:28 +02:00
Martin Willi 441bb9e7b7 stream: add backlog option to stream services, forward to listen() 2013-07-18 16:00:28 +02:00
Martin Willi c5597a4b56 stream: add support for TCP stream services 2013-07-18 16:00:28 +02:00
Martin Willi db1c8aa460 stream: add support for TCP streams 2013-07-18 16:00:28 +02:00
Martin Willi f04746d9b4 stream: add support for UNIX stream services 2013-07-18 16:00:28 +02:00
Martin Willi b785cfe05b stream: add support for UNIX streams 2013-07-18 16:00:28 +02:00
Martin Willi c1fd8c22ce stream: support async operation using watcher 2013-07-18 16:00:28 +02:00
Martin Willi 7a23588195 stream: add printf()-style covenience functions 2013-07-18 16:00:28 +02:00
Martin Willi 2ba276017d stream: create library instance of stream-manager 2013-07-18 16:00:28 +02:00
Martin Willi d6ff53940f stream: add a manager to dynamically register streams and services 2013-07-18 16:00:28 +02:00
Martin Willi daf1880b39 stream: add a stream service class abstracting services using BSD sockets 2013-07-18 16:00:27 +02:00
Martin Willi b6b940001a stream: add a stream class abstracting BSD sockets
Currently only synchronous operation is supported, but this will be extended
with asynchronous methods using the new watcher.
2013-07-18 16:00:27 +02:00