Commit Graph

85 Commits

Author SHA1 Message Date
Tobias Brunner 7d2d94f3e1 host-resolver: Don't wait for a reply if there are no threads
Without threads handling the resolution, there is no point waiting
for a reply.  If no subsequent resolution successfully starts a
thread (there might not even be one), we'd wait indefinitely.

Fixes #3634.
2020-12-03 08:36:20 +01:00
Josh Soref b3ab7a48cc Spelling fixes
* accumulating
* acquire
* alignment
* appropriate
* argument
* assign
* attribute
* authenticate
* authentication
* authenticator
* authority
* auxiliary
* brackets
* callback
* camellia
* can't
* cancelability
* certificate
* choinyambuu
* chunk
* collector
* collision
* communicating
* compares
* compatibility
* compressed
* confidentiality
* configuration
* connection
* consistency
* constraint
* construction
* constructor
* database
* decapsulated
* declaration
* decrypt
* derivative
* destination
* destroyed
* details
* devised
* dynamic
* ecapsulation
* encoded
* encoding
* encrypted
* enforcing
* enumerator
* establishment
* excluded
* exclusively
* exited
* expecting
* expire
* extension
* filter
* firewall
* foundation
* fulfillment
* gateways
* hashing
* hashtable
* heartbeats
* identifier
* identifiers
* identities
* identity
* implementers
* indicating
* initialize
* initiate
* initiation
* initiator
* inner
* instantiate
* legitimate
* libraries
* libstrongswan
* logger
* malloc
* manager
* manually
* measurement
* mechanism
* message
* network
* nonexistent
* object
* occurrence
* optional
* outgoing
* packages
* packets
* padding
* particular
* passphrase
* payload
* periodically
* policies
* possible
* previously
* priority
* proposal
* protocol
* provide
* provider
* pseudo
* pseudonym
* public
* qualifier
* quantum
* quintuplets
* reached
* reading
* recommendation to
* recommendation
* recursive
* reestablish
* referencing
* registered
* rekeying
* reliable
* replacing
* representing
* represents
* request
* request
* resolver
* result
* resulting
* resynchronization
* retriable
* revocation
* right
* rollback
* rule
* rules
* runtime
* scenario
* scheduled
* security
* segment
* service
* setting
* signature
* specific
* specified
* speed
* started
* steffen
* strongswan
* subjectaltname
* supported
* threadsafe
* traffic
* tremendously
* treshold
* unique
* uniqueness
* unknown
* until
* upper
* using
* validator
* verification
* version
* version
* warrior

Closes strongswan/strongswan#164.
2020-02-11 18:23:07 +01:00
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
Tobias Brunner 1b67166921 Unify format of HSR copyright statements 2018-05-23 16:32:53 +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 59e6e93323 tun-device: Use next free TUN device on FreeBSD
While this API is documented as legacy (and there is a sysctl option to
disable it) the documentation also mentions that it will probably stay
enabled by default due to compatibility issues with existing applications.

With the previous approach only 255 devices could be opened then the
daemon had to be restarted.

Fixes #2313.
2017-05-19 15:28:46 +02:00
Tobias Brunner fa959c0732 tun-device: TUN devices are not supported on iOS 2017-05-19 15:22:51 +02:00
Tobias Brunner 2283c8148a host: Don't log port if it is zero 2017-03-02 08:27:30 +01:00
Andreas Steffen b12c53ce77 Use standard unsigned integer types 2016-03-24 18:52:48 +01:00
Tobias Brunner 65579569ad host: Properly handle NULL in host_create_from_string[_and_family] 2015-07-27 11:53:26 +02:00
Martin Willi d0d8568356 host-resolver: Do not cancel threads waiting for new queries during cleanup
While it is currently unclear why it happens, canceling threads waiting in the
new_query condvar does not work as expected. The behavior is not fully
reproducible: Either cancel(), join() or destroying the condvar hangs.

The issue has been seen in the http-fetcher unit tests, where the stream service
triggers the use of the resolver for "localhost" hosts. It is reproducible with
any cleanup following a host_create_from_dns() use on a Ubuntu 14.04 x64 system.
Further, the issue is related to the use of libunwind, as only builds with
--enable-unwind-backtraces are affected.

As we broadcast() the new_query condvar before destruction, a hard cancel() of
these threads is actually not required. Instead we let these threads clean up
themselves after receiving the condvar signal.
2015-02-24 16:00:38 +01:00
Martin Willi 2113f48271 host-resolver: Disable resolver thread cancellation by default
The default of new threads is cancellable, but the host-resolver thread code
clearly expects the opposite.
2015-02-24 15:59:35 +01:00
Martin Willi 04337fed02 apple: Redefine some additional clashing Mach types
While they usually are not included in a normal strongSwan build, the XPC
header indirectly defines these Mach types. To build charon-xpc, which uses
both XPC and strongSwan includes, we have to redefine these types.
2014-12-16 17:22:28 +01:00
Martin Willi 946cf367d4 tun-device: Read from tun to buffer on stack to avoid over-allocation of packets
Instead of allocating MTU-sized buffers for each packet, read to a stack buffer
and copy to an allocation of the actual packet size. While it requires an
additional copy on non-Apple platforms, this should make allocation more
efficient for small packets.
2014-11-21 12:02:07 +01:00
Martin Willi eaca7f2143 tun-device: Remove the superfluous use of select() before read() 2014-11-21 11:16:48 +01:00
Tobias Brunner cd67cd70c8 host: Ignore spaces around - when parsing ranges 2014-10-30 12:32:45 +01:00
Tobias Brunner 82be444eb9 host: Add function to create two hosts from a range definition 2014-10-30 12:32:45 +01:00
Tobias Brunner f00a9c1715 packet: Define a global default maximum size for IKE packets 2014-10-10 09:32:42 +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 43c5388470 tun-device: Rearrange headers to build properly when tun devices not supported 2014-06-03 12:24:34 +02:00
Martin Willi 922ee2c529 windows: Add a common Windows header for platform specific wrappers
Include some more basic system headers in utils.h, so we can use that common
header on the different platforms.
2014-06-03 12:24:34 +02:00
Tobias Brunner acc042fa7b tun-device: Use SIOCAIFADDR to set IP address on FreeBSD 10
FreeBSD 10 deprecated the SIOCSIFADDR etc. commands, so we use this
newer command to set the address and netmask.  A destination address
is now also required.

Fixes #566.
2014-04-25 12:18:06 +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
Tobias Brunner 8dc6e71632 lib: All settings use configured namespace 2014-02-12 14:34:32 +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 bfa2201537 tun-device: Include system headers before our own
On CentOS 6.5 the sys/capability.h header file defines _LINUX_TYPES_H
without actually including that header, preventing its later inclusion
here.

As library.h (via which the capabilities headers are included) is not
actually required in tun_device.[ch], moving the inclusion of tun_device.h
would not strictly be necessary.  But it's probably a good idea to
include our own headers after system headers anyway, for if one of the
recursively included files at a later point includes library.h we'd have
the same problem again.
2013-12-20 11:33:16 +01:00
Martin Willi 1cbe4e6ce4 tun-device: Include <linux/types.h> before <linux/if_tun.h>
Fixes a build error on CentOS 6.4.
2013-11-22 09:09:06 +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 bf32cdfbf6 tun_device: Add warning if TUN devices are not supported by platform 2013-09-12 01:44:49 +02:00
Tobias Brunner ed0efaef4c host: Properly initialize struct sockaddr_in[6] when parsing strings
Otherwise struct members like sin6_flowinfo or sin6_scope_id might be
set to bogus values.
2013-07-31 22:16:58 +02:00
Tobias Brunner d7dc4fedd1 stream: Ensure UNIX socket path is null terminated 2013-07-24 16:17:23 +02:00
Tobias Brunner 6e2ec33f9d host: Prevent overflow in host_create_netmask() if mask is 0 or 32/128 2013-07-24 16:17:03 +02:00
Tobias Brunner 0ceb288815 Fix various API doc issues and typos
Partially based on an old patch by Adrian-Ken Rueegsegger.
2013-07-18 18:30:36 +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