summaryrefslogtreecommitdiff
path: root/src/libcharon/daemon.c
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2013-01-02 14:18:20 +0100
committerYves-Alexis Perez <corsac@debian.org>2013-01-02 14:18:20 +0100
commitc1343b3278cdf99533b7902744d15969f9d6fdc1 (patch)
treed5ed3dc5677a59260ec41cd39bb284d3e94c91b3 /src/libcharon/daemon.c
parentb34738ed08c2227300d554b139e2495ca5da97d6 (diff)
downloadvyos-strongswan-c1343b3278cdf99533b7902744d15969f9d6fdc1.tar.gz
vyos-strongswan-c1343b3278cdf99533b7902744d15969f9d6fdc1.zip
Imported Upstream version 5.0.1
Diffstat (limited to 'src/libcharon/daemon.c')
-rw-r--r--src/libcharon/daemon.c172
1 files changed, 62 insertions, 110 deletions
diff --git a/src/libcharon/daemon.c b/src/libcharon/daemon.c
index 3fb49d475..6e977efc4 100644
--- a/src/libcharon/daemon.c
+++ b/src/libcharon/daemon.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006-2010 Tobias Brunner
+ * Copyright (C) 2006-2012 Tobias Brunner
* Copyright (C) 2005-2009 Martin Willi
* Copyright (C) 2006 Daniel Roethlisberger
* Copyright (C) 2005 Jan Hutter
@@ -21,22 +21,18 @@
#include <unistd.h>
#include <time.h>
-#ifdef CAPABILITIES
-# ifdef HAVE_SYS_CAPABILITY_H
-# include <sys/capability.h>
-# elif defined(CAPABILITIES_NATIVE)
-# include <linux/capability.h>
-# endif /* CAPABILITIES_NATIVE */
-#endif /* CAPABILITIES */
-
#include "daemon.h"
#include <library.h>
-#include <plugins/plugin.h>
+#include <plugins/plugin_feature.h>
#include <config/proposal.h>
#include <kernel/kernel_handler.h>
#include <processing/jobs/start_action_job.h>
+#ifndef CAP_NET_ADMIN
+#define CAP_NET_ADMIN 12
+#endif
+
typedef struct private_daemon_t private_daemon_t;
/**
@@ -52,17 +48,6 @@ struct private_daemon_t {
* Handler for kernel events
*/
kernel_handler_t *kernel_handler;
-
- /**
- * capabilities to keep
- */
-#ifdef CAPABILITIES_LIBCAP
- cap_t caps;
-#endif /* CAPABILITIES_LIBCAP */
-#ifdef CAPABILITIES_NATIVE
- struct __user_cap_data_struct caps[2];
-#endif /* CAPABILITIES_NATIVE */
-
};
/**
@@ -109,27 +94,31 @@ static void destroy(private_daemon_t *this)
{
this->public.traps->flush(this->public.traps);
}
- DESTROY_IF(this->public.receiver);
- DESTROY_IF(this->public.sender);
+ if (this->public.sender)
+ {
+ this->public.sender->flush(this->public.sender);
+ }
+
+ /* cancel all threads and wait for their termination */
+ lib->processor->cancel(lib->processor);
+
#ifdef ME
DESTROY_IF(this->public.connect_manager);
DESTROY_IF(this->public.mediation_manager);
#endif /* ME */
/* make sure the cache is clear before unloading plugins */
lib->credmgr->flush_cache(lib->credmgr, CERT_ANY);
- /* unload plugins to release threads */
lib->plugins->unload(lib->plugins);
-#ifdef CAPABILITIES_LIBCAP
- cap_free(this->caps);
-#endif /* CAPABILITIES_LIBCAP */
DESTROY_IF(this->kernel_handler);
DESTROY_IF(this->public.traps);
DESTROY_IF(this->public.shunts);
DESTROY_IF(this->public.ike_sa_manager);
DESTROY_IF(this->public.controller);
DESTROY_IF(this->public.eap);
+ DESTROY_IF(this->public.xauth);
DESTROY_IF(this->public.backends);
DESTROY_IF(this->public.socket);
+ DESTROY_IF(this->public.caps);
/* rehook library logging, shutdown logging */
dbg = dbg_old;
@@ -138,86 +127,63 @@ static void destroy(private_daemon_t *this)
offsetof(file_logger_t, destroy));
this->public.sys_loggers->destroy_offset(this->public.sys_loggers,
offsetof(sys_logger_t, destroy));
+ free((void*)this->public.name);
free(this);
}
-METHOD(daemon_t, keep_cap, void,
- private_daemon_t *this, u_int cap)
+METHOD(daemon_t, start, void,
+ private_daemon_t *this)
{
-#ifdef CAPABILITIES_LIBCAP
- cap_set_flag(this->caps, CAP_EFFECTIVE, 1, &cap, CAP_SET);
- cap_set_flag(this->caps, CAP_INHERITABLE, 1, &cap, CAP_SET);
- cap_set_flag(this->caps, CAP_PERMITTED, 1, &cap, CAP_SET);
-#endif /* CAPABILITIES_LIBCAP */
-#ifdef CAPABILITIES_NATIVE
- int i = 0;
-
- if (cap >= 32)
- {
- i++;
- cap -= 32;
- }
- this->caps[i].effective |= 1 << cap;
- this->caps[i].permitted |= 1 << cap;
- this->caps[i].inheritable |= 1 << cap;
-#endif /* CAPABILITIES_NATIVE */
+ /* start the engine, go multithreaded */
+ lib->processor->set_threads(lib->processor,
+ lib->settings->get_int(lib->settings, "%s.threads",
+ DEFAULT_THREADS, charon->name));
}
-METHOD(daemon_t, drop_capabilities, bool,
- private_daemon_t *this)
+
+/**
+ * Initialize/deinitialize sender and receiver
+ */
+static bool sender_receiver_cb(void *plugin, plugin_feature_t *feature,
+ bool reg, private_daemon_t *this)
{
-#ifdef CAPABILITIES_LIBCAP
- if (cap_set_proc(this->caps) != 0)
+ if (reg)
{
- return FALSE;
+ this->public.receiver = receiver_create();
+ if (!this->public.receiver)
+ {
+ return FALSE;
+ }
+ this->public.sender = sender_create();
}
-#endif /* CAPABILITIES_LIBCAP */
-#ifdef CAPABILITIES_NATIVE
- struct __user_cap_header_struct header = {
-#if defined(_LINUX_CAPABILITY_VERSION_3)
- .version = _LINUX_CAPABILITY_VERSION_3,
-#elif defined(_LINUX_CAPABILITY_VERSION_2)
- .version = _LINUX_CAPABILITY_VERSION_2,
-#elif defined(_LINUX_CAPABILITY_VERSION_1)
- .version = _LINUX_CAPABILITY_VERSION_1,
-#else
- .version = _LINUX_CAPABILITY_VERSION,
-#endif
- };
- if (capset(&header, this->caps) != 0)
+ else
{
- return FALSE;
+ DESTROY_IF(this->public.receiver);
+ DESTROY_IF(this->public.sender);
}
-#endif /* CAPABILITIES_NATIVE */
return TRUE;
}
-METHOD(daemon_t, start, void,
- private_daemon_t *this)
-{
- /* start the engine, go multithreaded */
- lib->processor->set_threads(lib->processor,
- lib->settings->get_int(lib->settings, "charon.threads",
- DEFAULT_THREADS));
-}
-
METHOD(daemon_t, initialize, bool,
- private_daemon_t *this)
+ private_daemon_t *this, char *plugins)
{
- DBG1(DBG_DMN, "Starting IKEv2 charon daemon (strongSwan "VERSION")");
-
- if (lib->integrity)
- {
- DBG1(DBG_DMN, "integrity tests enabled:");
- DBG1(DBG_DMN, "lib 'libstrongswan': passed file and segment integrity tests");
- DBG1(DBG_DMN, "lib 'libhydra': passed file and segment integrity tests");
- DBG1(DBG_DMN, "lib 'libcharon': passed file and segment integrity tests");
- DBG1(DBG_DMN, "daemon 'charon': passed file integrity test");
- }
+ plugin_feature_t features[] = {
+ PLUGIN_PROVIDE(CUSTOM, "libcharon"),
+ PLUGIN_DEPENDS(NONCE_GEN),
+ PLUGIN_DEPENDS(CUSTOM, "libcharon-receiver"),
+ PLUGIN_DEPENDS(CUSTOM, "kernel-ipsec"),
+ PLUGIN_DEPENDS(CUSTOM, "kernel-net"),
+ PLUGIN_CALLBACK((plugin_feature_callback_t)sender_receiver_cb, this),
+ PLUGIN_PROVIDE(CUSTOM, "libcharon-receiver"),
+ PLUGIN_DEPENDS(HASHER, HASH_SHA1),
+ PLUGIN_DEPENDS(RNG, RNG_STRONG),
+ PLUGIN_DEPENDS(CUSTOM, "socket"),
+ };
+ lib->plugins->add_static_features(lib->plugins, charon->name, features,
+ countof(features), TRUE);
/* load plugins, further infrastructure may need it */
- if (!lib->plugins->load(lib->plugins, NULL,
- lib->settings->get_str(lib->settings, "charon.load", PLUGINS)))
+ if (!lib->plugins->load(lib->plugins, NULL, plugins))
{
return FALSE;
}
@@ -229,12 +195,6 @@ METHOD(daemon_t, initialize, bool,
{
return FALSE;
}
- this->public.sender = sender_create();
- this->public.receiver = receiver_create();
- if (this->public.receiver == NULL)
- {
- return FALSE;
- }
/* Queue start_action job */
lib->processor->queue_job(lib->processor, (job_t*)start_action_job_create());
@@ -254,40 +214,32 @@ METHOD(daemon_t, initialize, bool,
/**
* Create the daemon.
*/
-private_daemon_t *daemon_create()
+private_daemon_t *daemon_create(const char *name)
{
private_daemon_t *this;
INIT(this,
.public = {
- .keep_cap = _keep_cap,
- .drop_capabilities = _drop_capabilities,
.initialize = _initialize,
.start = _start,
.bus = bus_create(),
.file_loggers = linked_list_create(),
.sys_loggers = linked_list_create(),
+ .name = strdup(name ?: "libcharon"),
},
);
charon = &this->public;
+ this->public.caps = capabilities_create();
this->public.controller = controller_create();
this->public.eap = eap_manager_create();
+ this->public.xauth = xauth_manager_create();
this->public.backends = backend_manager_create();
this->public.socket = socket_manager_create();
this->public.traps = trap_manager_create();
this->public.shunts = shunt_manager_create();
this->kernel_handler = kernel_handler_create();
-#ifdef CAPABILITIES
-#ifdef CAPABILITIES_LIBCAP
- this->caps = cap_init();
-#endif /* CAPABILITIES_LIBCAP */
- keep_cap(this, CAP_NET_ADMIN);
- if (lib->leak_detective)
- {
- keep_cap(this, CAP_SYS_NICE);
- }
-#endif /* CAPABILITIES */
+ this->public.caps->keep(this->public.caps, CAP_NET_ADMIN);
return this;
}
@@ -304,9 +256,9 @@ void libcharon_deinit()
/**
* Described in header.
*/
-bool libcharon_init()
+bool libcharon_init(const char *name)
{
- daemon_create();
+ daemon_create(name);
/* for uncritical pseudo random numbers */
srandom(time(NULL) + getpid());