abort pluto or charon if initialization fails
This commit is contained in:
+1
-1
@@ -759,7 +759,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
DBG1(DBG_DMN, "initialization failed - aborting charon");
|
DBG1(DBG_DMN, "initialization failed - aborting charon");
|
||||||
destroy(private_charon);
|
destroy(private_charon);
|
||||||
exit(-1);
|
exit(SS_RC_INITIALIZATION_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_pidfile())
|
if (check_pidfile())
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
*/
|
*/
|
||||||
#define SS_RC_LIBSTRONGSWAN_INTEGRITY 64
|
#define SS_RC_LIBSTRONGSWAN_INTEGRITY 64
|
||||||
#define SS_RC_DAEMON_INTEGRITY 65
|
#define SS_RC_DAEMON_INTEGRITY 65
|
||||||
|
#define SS_RC_INITIALIZATION_FAILED 66
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of bits in a byte
|
* Number of bits in a byte
|
||||||
|
|||||||
+8
-7
@@ -235,7 +235,7 @@ static struct dh_desc dh_desc_ecp_224 = {
|
|||||||
ke_size: 2*224 / BITS_PER_BYTE
|
ke_size: 2*224 / BITS_PER_BYTE
|
||||||
};
|
};
|
||||||
|
|
||||||
void init_crypto(void)
|
bool init_crypto(void)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
encryption_algorithm_t encryption_alg;
|
encryption_algorithm_t encryption_alg;
|
||||||
@@ -275,13 +275,13 @@ void init_crypto(void)
|
|||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
|
|
||||||
if (no_sha1)
|
if (no_sha1 || no_md5)
|
||||||
{
|
{
|
||||||
exit_log("pluto cannot run without a SHA-1 hasher");
|
plog("pluto cannot run without a %s%s%s hasher",
|
||||||
}
|
(no_sha1) ? "SHA-1" : "",
|
||||||
if (no_md5)
|
(no_sha1 && no_md5) ? " and " : "",
|
||||||
{
|
(no_md5) ? "MD5" : "");
|
||||||
exit_log("pluto cannot run without an MD5 hasher");
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
enumerator = lib->crypto->create_crypter_enumerator(lib->crypto);
|
enumerator = lib->crypto->create_crypter_enumerator(lib->crypto);
|
||||||
@@ -363,6 +363,7 @@ void init_crypto(void)
|
|||||||
ike_alg_add((struct ike_alg *)desc);
|
ike_alg_add((struct ike_alg *)desc);
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_crypto(void)
|
void free_crypto(void)
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include "ike_alg.h"
|
#include "ike_alg.h"
|
||||||
|
|
||||||
extern void init_crypto(void);
|
extern bool init_crypto(void);
|
||||||
extern void free_crypto(void);
|
extern void free_crypto(void);
|
||||||
|
|
||||||
extern const struct dh_desc unset_group; /* magic signifier */
|
extern const struct dh_desc unset_group; /* magic signifier */
|
||||||
|
|||||||
@@ -655,13 +655,16 @@ int main(int argc, char **argv)
|
|||||||
lib->settings->get_str(lib->settings, "pluto.load", PLUGINS));
|
lib->settings->get_str(lib->settings, "pluto.load", PLUGINS));
|
||||||
print_plugins();
|
print_plugins();
|
||||||
|
|
||||||
|
if (!init_secret() || !init_crypto())
|
||||||
|
{
|
||||||
|
plog("initialization failed - aborting pluto");
|
||||||
|
exit_pluto(SS_RC_INITIALIZATION_FAILED);
|
||||||
|
}
|
||||||
init_nat_traversal(nat_traversal, keep_alive, force_keepalive, nat_t_spf);
|
init_nat_traversal(nat_traversal, keep_alive, force_keepalive, nat_t_spf);
|
||||||
init_virtual_ip(virtual_private);
|
init_virtual_ip(virtual_private);
|
||||||
scx_init(pkcs11_module_path, pkcs11_init_args);
|
scx_init(pkcs11_module_path, pkcs11_init_args);
|
||||||
xauth_init();
|
xauth_init();
|
||||||
init_secret();
|
|
||||||
init_states();
|
init_states();
|
||||||
init_crypto();
|
|
||||||
init_demux();
|
init_demux();
|
||||||
init_kernel();
|
init_kernel();
|
||||||
init_adns();
|
init_adns();
|
||||||
|
|||||||
+8
-1
@@ -140,14 +140,21 @@ void event_schedule(enum event_type type, time_t tm, struct state *st)
|
|||||||
* Generate the secret value for responder cookies, and
|
* Generate the secret value for responder cookies, and
|
||||||
* schedule an event for refresh.
|
* schedule an event for refresh.
|
||||||
*/
|
*/
|
||||||
void init_secret(void)
|
bool init_secret(void)
|
||||||
{
|
{
|
||||||
rng_t *rng;
|
rng_t *rng;
|
||||||
|
|
||||||
rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
|
rng = lib->crypto->create_rng(lib->crypto, RNG_STRONG);
|
||||||
|
|
||||||
|
if (rng == NULL)
|
||||||
|
{
|
||||||
|
plog("secret initialization failed, no RNG supported");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
rng->get_bytes(rng, sizeof(secret_of_the_day), secret_of_the_day);
|
rng->get_bytes(rng, sizeof(secret_of_the_day), secret_of_the_day);
|
||||||
rng->destroy(rng);
|
rng->destroy(rng);
|
||||||
event_schedule(EVENT_REINIT_SECRET, EVENT_REINIT_SECRET_DELAY, NULL);
|
event_schedule(EVENT_REINIT_SECRET, EVENT_REINIT_SECRET_DELAY, NULL);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -31,4 +31,4 @@ extern void delete_event(struct state *st);
|
|||||||
extern void delete_dpd_event(struct state *st);
|
extern void delete_dpd_event(struct state *st);
|
||||||
extern void daily_log_event(void);
|
extern void daily_log_event(void);
|
||||||
extern void free_events(void);
|
extern void free_events(void);
|
||||||
extern void init_secret(void);
|
extern bool init_secret(void);
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ void starter_charon_sigchild(pid_t pid, int status)
|
|||||||
(status == 64) ? "libstrongswan" : "charon");
|
(status == 64) ? "libstrongswan" : "charon");
|
||||||
_stop_requested = 1;
|
_stop_requested = 1;
|
||||||
}
|
}
|
||||||
|
else if (status == SS_RC_INITIALIZATION_FAILED)
|
||||||
|
{
|
||||||
|
plog("charon has quit: initialization failed");
|
||||||
|
_stop_requested = 1;
|
||||||
|
}
|
||||||
if (!_stop_requested)
|
if (!_stop_requested)
|
||||||
{
|
{
|
||||||
plog("charon has died -- restart scheduled (%dsec)"
|
plog("charon has died -- restart scheduled (%dsec)"
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ starter_pluto_sigchild(pid_t pid, int status)
|
|||||||
(status == 64) ? "libstrongswan" : "pluto");
|
(status == 64) ? "libstrongswan" : "pluto");
|
||||||
_stop_requested = 1;
|
_stop_requested = 1;
|
||||||
}
|
}
|
||||||
|
else if (status == SS_RC_INITIALIZATION_FAILED)
|
||||||
|
{
|
||||||
|
plog("pluto has quit: initialization failed");
|
||||||
|
_stop_requested = 1;
|
||||||
|
}
|
||||||
if (!_stop_requested)
|
if (!_stop_requested)
|
||||||
{
|
{
|
||||||
plog("pluto has died -- restart scheduled (%dsec)"
|
plog("pluto has died -- restart scheduled (%dsec)"
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ static void fsig(int signal)
|
|||||||
else if (WIFEXITED(status))
|
else if (WIFEXITED(status))
|
||||||
{
|
{
|
||||||
exit_status = WEXITSTATUS(status);
|
exit_status = WEXITSTATUS(status);
|
||||||
if (exit_status == SS_RC_LIBSTRONGSWAN_INTEGRITY ||
|
if (exit_status >= SS_RC_LIBSTRONGSWAN_INTEGRITY &&
|
||||||
exit_status == SS_RC_DAEMON_INTEGRITY)
|
exit_status <= SS_RC_INITIALIZATION_FAILED)
|
||||||
{
|
{
|
||||||
_action_ = FLAG_ACTION_QUIT;
|
_action_ = FLAG_ACTION_QUIT;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user