2008-03-26 10:10:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Martin Willi
|
|
|
|
* Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
2015-12-06 12:28:03 +00:00
|
|
|
* Copyright (C) 2015 Andreas Steffen
|
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
2008-03-26 10:10:40 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stroke_list.h"
|
|
|
|
|
2011-06-07 15:13:48 +00:00
|
|
|
#include <inttypes.h>
|
2008-11-05 08:32:38 +00:00
|
|
|
#include <time.h>
|
2012-06-28 09:56:40 +00:00
|
|
|
#include <sys/utsname.h>
|
2008-11-05 08:32:38 +00:00
|
|
|
|
2010-07-06 14:26:59 +00:00
|
|
|
#ifdef HAVE_MALLINFO
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif /* HAVE_MALLINFO */
|
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
#include <daemon.h>
|
2012-10-16 12:54:16 +00:00
|
|
|
#include <collections/linked_list.h>
|
2011-05-12 08:33:48 +00:00
|
|
|
#include <plugins/plugin.h>
|
2008-03-26 10:10:40 +00:00
|
|
|
#include <credentials/certificates/x509.h>
|
2015-12-06 12:28:03 +00:00
|
|
|
#include <credentials/certificates/certificate_printer.h>
|
2008-06-30 17:08:47 +00:00
|
|
|
#include <config/peer_cfg.h>
|
2008-03-26 10:10:40 +00:00
|
|
|
|
|
|
|
typedef struct private_stroke_list_t private_stroke_list_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* private data of stroke_list
|
|
|
|
*/
|
|
|
|
struct private_stroke_list_t {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* public functions
|
|
|
|
*/
|
|
|
|
stroke_list_t public;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-06-13 10:11:55 +00:00
|
|
|
/**
|
|
|
|
* Kind of *swan we run
|
|
|
|
*/
|
|
|
|
char *swan;
|
|
|
|
|
2008-03-26 16:13:14 +00:00
|
|
|
/**
|
|
|
|
* timestamp of daemon start
|
|
|
|
*/
|
|
|
|
time_t uptime;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-12-09 13:24:12 +00:00
|
|
|
/**
|
|
|
|
* strokes attribute provider
|
|
|
|
*/
|
|
|
|
stroke_attribute_t *attribute;
|
2008-03-26 10:10:40 +00:00
|
|
|
};
|
|
|
|
|
2015-12-11 17:24:58 +00:00
|
|
|
/**
|
|
|
|
* Static certificate printer object
|
|
|
|
*/
|
|
|
|
static certificate_printer_t *cert_printer = NULL;
|
|
|
|
|
2010-06-07 09:59:37 +00:00
|
|
|
/**
|
|
|
|
* Log tasks of a specific queue to out
|
|
|
|
*/
|
|
|
|
static void log_task_q(FILE *out, ike_sa_t *ike_sa, task_queue_t q, char *name)
|
|
|
|
{
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
bool has = FALSE;
|
|
|
|
task_t *task;
|
|
|
|
|
|
|
|
enumerator = ike_sa->create_task_enumerator(ike_sa, q);
|
|
|
|
while (enumerator->enumerate(enumerator, &task))
|
|
|
|
{
|
|
|
|
if (!has)
|
|
|
|
{
|
|
|
|
fprintf(out, "%12s[%d]: Tasks %s: ", ike_sa->get_name(ike_sa),
|
|
|
|
ike_sa->get_unique_id(ike_sa), name);
|
|
|
|
has = TRUE;
|
|
|
|
}
|
|
|
|
fprintf(out, "%N ", task_type_names, task->get_type(task));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
if (has)
|
|
|
|
{
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
/**
|
|
|
|
* log an IKE_SA to out
|
|
|
|
*/
|
|
|
|
static void log_ike_sa(FILE *out, ike_sa_t *ike_sa, bool all)
|
|
|
|
{
|
|
|
|
ike_sa_id_t *id = ike_sa->get_id(ike_sa);
|
2009-08-31 15:59:00 +00:00
|
|
|
time_t now = time_monotonic(NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-12-10 09:59:35 +00:00
|
|
|
fprintf(out, "%12s[%d]: %N",
|
2008-03-26 10:10:40 +00:00
|
|
|
ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
|
2008-12-10 09:59:35 +00:00
|
|
|
ike_sa_state_names, ike_sa->get_state(ike_sa));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-12-10 09:59:35 +00:00
|
|
|
if (ike_sa->get_state(ike_sa) == IKE_ESTABLISHED)
|
|
|
|
{
|
2009-02-11 16:37:16 +00:00
|
|
|
time_t established;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-02-11 16:37:16 +00:00
|
|
|
established = ike_sa->get_statistic(ike_sa, STAT_ESTABLISHED);
|
2009-03-12 18:07:32 +00:00
|
|
|
fprintf(out, " %V ago", &now, &established);
|
2008-12-10 09:59:35 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-04-30 11:37:54 +00:00
|
|
|
fprintf(out, ", %H[%Y]...%H[%Y]\n",
|
2008-03-26 10:10:40 +00:00
|
|
|
ike_sa->get_my_host(ike_sa), ike_sa->get_my_id(ike_sa),
|
2012-06-27 09:40:53 +00:00
|
|
|
ike_sa->get_other_host(ike_sa), ike_sa->get_other_id(ike_sa));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
if (all)
|
|
|
|
{
|
2008-10-28 16:07:06 +00:00
|
|
|
proposal_t *ike_proposal;
|
2012-06-27 09:40:53 +00:00
|
|
|
identification_t *eap_id;
|
|
|
|
|
|
|
|
eap_id = ike_sa->get_other_eap_id(ike_sa);
|
|
|
|
|
|
|
|
if (!eap_id->equals(eap_id, ike_sa->get_other_id(ike_sa)))
|
|
|
|
{
|
|
|
|
fprintf(out, "%12s[%d]: Remote %s identity: %Y\n",
|
|
|
|
ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
|
|
|
|
ike_sa->get_version(ike_sa) == IKEV1 ? "XAuth" : "EAP",
|
|
|
|
eap_id);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-30 12:58:54 +00:00
|
|
|
ike_proposal = ike_sa->get_proposal(ike_sa);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-01-18 16:50:07 +00:00
|
|
|
fprintf(out, "%12s[%d]: %N SPIs: %.16"PRIx64"_i%s %.16"PRIx64"_r%s",
|
2008-03-26 10:10:40 +00:00
|
|
|
ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
|
2012-01-18 16:50:07 +00:00
|
|
|
ike_version_names, ike_sa->get_version(ike_sa),
|
2016-03-04 09:19:37 +00:00
|
|
|
be64toh(id->get_initiator_spi(id)),
|
|
|
|
id->is_initiator(id) ? "*" : "",
|
|
|
|
be64toh(id->get_responder_spi(id)),
|
|
|
|
id->is_initiator(id) ? "" : "*");
|
2009-09-04 11:46:09 +00:00
|
|
|
|
|
|
|
|
2008-06-22 11:24:33 +00:00
|
|
|
if (ike_sa->get_state(ike_sa) == IKE_ESTABLISHED)
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
2009-02-11 16:37:16 +00:00
|
|
|
time_t rekey, reauth;
|
2009-04-14 10:34:24 +00:00
|
|
|
peer_cfg_t *peer_cfg;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-27 14:51:00 +00:00
|
|
|
rekey = ike_sa->get_statistic(ike_sa, STAT_REKEY);
|
|
|
|
reauth = ike_sa->get_statistic(ike_sa, STAT_REAUTH);
|
2009-04-14 10:34:24 +00:00
|
|
|
peer_cfg = ike_sa->get_peer_cfg(ike_sa);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-06-22 11:24:33 +00:00
|
|
|
if (rekey)
|
|
|
|
{
|
2009-03-12 18:07:32 +00:00
|
|
|
fprintf(out, ", rekeying in %V", &rekey, &now);
|
2008-06-22 11:24:33 +00:00
|
|
|
}
|
|
|
|
if (reauth)
|
|
|
|
{
|
2009-04-14 10:34:24 +00:00
|
|
|
bool first = TRUE;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
auth_cfg_t *auth;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-04-14 10:34:24 +00:00
|
|
|
fprintf(out, ", ");
|
|
|
|
enumerator = peer_cfg->create_auth_cfg_enumerator(peer_cfg, TRUE);
|
|
|
|
while (enumerator->enumerate(enumerator, &auth))
|
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
{
|
|
|
|
fprintf(out, "+");
|
|
|
|
}
|
|
|
|
first = FALSE;
|
|
|
|
fprintf(out, "%N", auth_class_names,
|
|
|
|
auth->get(auth, AUTH_RULE_AUTH_CLASS));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
fprintf(out, " reauthentication in %V", &reauth, &now);
|
2008-06-22 11:24:33 +00:00
|
|
|
}
|
|
|
|
if (!rekey && !reauth)
|
|
|
|
{
|
|
|
|
fprintf(out, ", rekeying disabled");
|
|
|
|
}
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-06-22 11:24:33 +00:00
|
|
|
if (ike_proposal)
|
|
|
|
{
|
2008-10-28 10:12:21 +00:00
|
|
|
char buf[BUF_LEN];
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-28 10:12:21 +00:00
|
|
|
snprintf(buf, BUF_LEN, "%P", ike_proposal);
|
2008-06-22 11:24:33 +00:00
|
|
|
fprintf(out, "%12s[%d]: IKE proposal: %s\n",
|
|
|
|
ike_sa->get_name(ike_sa), ike_sa->get_unique_id(ike_sa),
|
2008-10-28 10:12:21 +00:00
|
|
|
buf+4);
|
2008-10-28 16:07:06 +00:00
|
|
|
}
|
2010-06-07 09:59:37 +00:00
|
|
|
|
|
|
|
log_task_q(out, ike_sa, TASK_QUEUE_QUEUED, "queued");
|
|
|
|
log_task_q(out, ike_sa, TASK_QUEUE_ACTIVE, "active");
|
|
|
|
log_task_q(out, ike_sa, TASK_QUEUE_PASSIVE, "passive");
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* log an CHILD_SA to out
|
|
|
|
*/
|
|
|
|
static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)
|
|
|
|
{
|
2009-08-31 15:59:00 +00:00
|
|
|
time_t use_in, use_out, rekey, now;
|
2016-03-22 12:22:01 +00:00
|
|
|
uint64_t bytes_in, bytes_out, packets_in, packets_out;
|
2008-10-29 16:06:16 +00:00
|
|
|
proposal_t *proposal;
|
2013-07-17 08:01:22 +00:00
|
|
|
linked_list_t *my_ts, *other_ts;
|
|
|
|
child_cfg_t *config;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2013-07-17 08:01:22 +00:00
|
|
|
config = child_sa->get_config(child_sa);
|
2012-06-05 08:29:06 +00:00
|
|
|
now = time_monotonic(NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2014-10-27 13:07:14 +00:00
|
|
|
fprintf(out, "%12s{%d}: %N, %N%s, reqid %u",
|
|
|
|
child_sa->get_name(child_sa), child_sa->get_unique_id(child_sa),
|
2008-03-26 10:10:40 +00:00
|
|
|
child_sa_state_names, child_sa->get_state(child_sa),
|
2008-11-16 21:19:17 +00:00
|
|
|
ipsec_mode_names, child_sa->get_mode(child_sa),
|
2014-10-27 13:07:14 +00:00
|
|
|
config->use_proxy_mode(config) ? "_PROXY" : "",
|
|
|
|
child_sa->get_reqid(child_sa));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
if (child_sa->get_state(child_sa) == CHILD_INSTALLED)
|
|
|
|
{
|
2008-10-24 09:51:48 +00:00
|
|
|
fprintf(out, ", %N%s SPIs: %.8x_i %.8x_o",
|
2008-03-26 10:10:40 +00:00
|
|
|
protocol_id_names, child_sa->get_protocol(child_sa),
|
2008-11-16 21:19:17 +00:00
|
|
|
child_sa->has_encap(child_sa) ? " in UDP" : "",
|
2008-07-22 10:16:45 +00:00
|
|
|
ntohl(child_sa->get_spi(child_sa, TRUE)),
|
|
|
|
ntohl(child_sa->get_spi(child_sa, FALSE)));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-24 09:51:48 +00:00
|
|
|
if (child_sa->get_ipcomp(child_sa) != IPCOMP_NONE)
|
2008-07-22 12:03:58 +00:00
|
|
|
{
|
|
|
|
fprintf(out, ", IPCOMP CPIs: %.4x_i %.4x_o",
|
2008-10-24 09:51:48 +00:00
|
|
|
ntohs(child_sa->get_cpi(child_sa, TRUE)),
|
|
|
|
ntohs(child_sa->get_cpi(child_sa, FALSE)));
|
2008-07-22 12:03:58 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
if (all)
|
|
|
|
{
|
2009-09-04 11:46:09 +00:00
|
|
|
fprintf(out, "\n%12s{%d}: ", child_sa->get_name(child_sa),
|
2014-10-27 13:07:14 +00:00
|
|
|
child_sa->get_unique_id(child_sa));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-29 16:06:16 +00:00
|
|
|
proposal = child_sa->get_proposal(child_sa);
|
|
|
|
if (proposal)
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
2016-03-22 12:22:01 +00:00
|
|
|
uint16_t alg, ks;
|
2013-06-20 14:16:06 +00:00
|
|
|
bool first = TRUE;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2015-12-18 12:51:36 +00:00
|
|
|
if (proposal->get_algorithm(proposal, ENCRYPTION_ALGORITHM,
|
|
|
|
&alg, &ks) && alg != ENCR_UNDEFINED)
|
2008-05-17 21:52:58 +00:00
|
|
|
{
|
2015-12-18 12:51:36 +00:00
|
|
|
fprintf(out, "%N", encryption_algorithm_names, alg);
|
2013-06-20 14:16:06 +00:00
|
|
|
first = FALSE;
|
2015-12-18 12:51:36 +00:00
|
|
|
if (ks)
|
2008-10-29 16:06:16 +00:00
|
|
|
{
|
2015-12-18 12:51:36 +00:00
|
|
|
fprintf(out, "_%u", ks);
|
2008-10-29 16:06:16 +00:00
|
|
|
}
|
2008-05-17 21:52:58 +00:00
|
|
|
}
|
2015-12-18 12:51:36 +00:00
|
|
|
if (proposal->get_algorithm(proposal, INTEGRITY_ALGORITHM,
|
|
|
|
&alg, &ks) && alg != AUTH_UNDEFINED)
|
2008-10-29 16:06:16 +00:00
|
|
|
{
|
2015-12-18 12:51:36 +00:00
|
|
|
fprintf(out, "%s%N", first ? "" : "/",
|
|
|
|
integrity_algorithm_names, alg);
|
|
|
|
if (ks)
|
2008-10-29 16:06:16 +00:00
|
|
|
{
|
2015-12-18 12:51:36 +00:00
|
|
|
fprintf(out, "_%u", ks);
|
2008-10-29 16:06:16 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-18 12:51:36 +00:00
|
|
|
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP,
|
|
|
|
&alg, NULL))
|
|
|
|
{
|
|
|
|
fprintf(out, "/%N", diffie_hellman_group_names, alg);
|
|
|
|
}
|
|
|
|
if (proposal->get_algorithm(proposal, EXTENDED_SEQUENCE_NUMBERS,
|
|
|
|
&alg, NULL) && alg == EXT_SEQ_NUMBERS)
|
2011-07-16 09:09:38 +00:00
|
|
|
{
|
|
|
|
fprintf(out, "/ESN");
|
|
|
|
}
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2013-03-13 10:46:32 +00:00
|
|
|
child_sa->get_usestats(child_sa, TRUE,
|
|
|
|
&use_in, &bytes_in, &packets_in);
|
2011-06-07 15:13:48 +00:00
|
|
|
fprintf(out, ", %" PRIu64 " bytes_i", bytes_in);
|
2009-08-06 14:46:02 +00:00
|
|
|
if (use_in)
|
2009-07-30 19:33:19 +00:00
|
|
|
{
|
2013-03-22 20:13:59 +00:00
|
|
|
fprintf(out, " (%" PRIu64 " pkt%s, %" PRIu64 "s ago)",
|
|
|
|
packets_in, (packets_in == 1) ? "": "s",
|
2016-03-22 12:22:01 +00:00
|
|
|
(uint64_t)(now - use_in));
|
2009-07-30 19:33:19 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 10:46:32 +00:00
|
|
|
child_sa->get_usestats(child_sa, FALSE,
|
|
|
|
&use_out, &bytes_out, &packets_out);
|
2011-06-07 15:13:48 +00:00
|
|
|
fprintf(out, ", %" PRIu64 " bytes_o", bytes_out);
|
2009-08-06 14:46:02 +00:00
|
|
|
if (use_out)
|
2009-07-30 19:33:19 +00:00
|
|
|
{
|
2013-03-22 20:13:59 +00:00
|
|
|
fprintf(out, " (%" PRIu64 " pkt%s, %" PRIu64 "s ago)",
|
|
|
|
packets_out, (packets_out == 1) ? "": "s",
|
2016-03-22 12:22:01 +00:00
|
|
|
(uint64_t)(now - use_out));
|
2009-07-30 19:33:19 +00:00
|
|
|
}
|
2008-03-26 10:10:40 +00:00
|
|
|
fprintf(out, ", rekeying ");
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-24 08:02:35 +00:00
|
|
|
rekey = child_sa->get_lifetime(child_sa, FALSE);
|
2008-03-26 10:10:40 +00:00
|
|
|
if (rekey)
|
|
|
|
{
|
2009-05-12 08:56:21 +00:00
|
|
|
if (now > rekey)
|
|
|
|
{
|
|
|
|
fprintf(out, "active");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(out, "in %V", &now, &rekey);
|
|
|
|
}
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(out, "disabled");
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-24 17:36:49 +00:00
|
|
|
else if (child_sa->get_state(child_sa) == CHILD_REKEYING ||
|
|
|
|
child_sa->get_state(child_sa) == CHILD_REKEYED)
|
2012-06-05 08:29:06 +00:00
|
|
|
{
|
|
|
|
rekey = child_sa->get_lifetime(child_sa, TRUE);
|
|
|
|
fprintf(out, ", expires in %V", &now, &rekey);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2013-07-17 08:01:22 +00:00
|
|
|
my_ts = linked_list_create_from_enumerator(
|
|
|
|
child_sa->create_ts_enumerator(child_sa, TRUE));
|
|
|
|
other_ts = linked_list_create_from_enumerator(
|
|
|
|
child_sa->create_ts_enumerator(child_sa, FALSE));
|
2015-10-07 14:25:05 +00:00
|
|
|
fprintf(out, "\n%12s{%d}: %#R === %#R\n",
|
2014-10-27 13:07:14 +00:00
|
|
|
child_sa->get_name(child_sa), child_sa->get_unique_id(child_sa),
|
2013-07-17 08:01:22 +00:00
|
|
|
my_ts, other_ts);
|
|
|
|
my_ts->destroy(my_ts);
|
|
|
|
other_ts->destroy(other_ts);
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
|
2009-04-14 10:34:24 +00:00
|
|
|
/**
|
|
|
|
* Log a configs local or remote authentication config to out
|
|
|
|
*/
|
|
|
|
static void log_auth_cfgs(FILE *out, peer_cfg_t *peer_cfg, bool local)
|
|
|
|
{
|
|
|
|
enumerator_t *enumerator, *rules;
|
|
|
|
auth_rule_t rule;
|
|
|
|
auth_cfg_t *auth;
|
|
|
|
auth_class_t auth_class;
|
|
|
|
identification_t *id;
|
|
|
|
certificate_t *cert;
|
|
|
|
cert_validation_t valid;
|
|
|
|
char *name;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-04-14 10:34:24 +00:00
|
|
|
name = peer_cfg->get_name(peer_cfg);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-04-14 10:34:24 +00:00
|
|
|
enumerator = peer_cfg->create_auth_cfg_enumerator(peer_cfg, local);
|
|
|
|
while (enumerator->enumerate(enumerator, &auth))
|
|
|
|
{
|
2012-07-26 10:38:34 +00:00
|
|
|
fprintf(out, "%12s: %s", name, local ? "local: " : "remote:");
|
|
|
|
id = auth->get(auth, AUTH_RULE_IDENTITY);
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
fprintf(out, " [%Y]", id);
|
|
|
|
}
|
|
|
|
fprintf(out, " uses ");
|
2009-04-14 10:34:24 +00:00
|
|
|
|
|
|
|
auth_class = (uintptr_t)auth->get(auth, AUTH_RULE_AUTH_CLASS);
|
2011-12-15 12:13:30 +00:00
|
|
|
if (auth_class == AUTH_CLASS_EAP)
|
2009-04-14 10:34:24 +00:00
|
|
|
{
|
|
|
|
if ((uintptr_t)auth->get(auth, AUTH_RULE_EAP_TYPE) == EAP_NAK)
|
|
|
|
{
|
|
|
|
fprintf(out, "EAP authentication");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((uintptr_t)auth->get(auth, AUTH_RULE_EAP_VENDOR))
|
|
|
|
{
|
2011-06-07 15:13:48 +00:00
|
|
|
fprintf(out, "EAP_%" PRIuPTR "-%" PRIuPTR " authentication",
|
2009-04-14 10:34:24 +00:00
|
|
|
(uintptr_t)auth->get(auth, AUTH_RULE_EAP_TYPE),
|
|
|
|
(uintptr_t)auth->get(auth, AUTH_RULE_EAP_VENDOR));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(out, "%N authentication", eap_type_names,
|
|
|
|
(uintptr_t)auth->get(auth, AUTH_RULE_EAP_TYPE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
id = auth->get(auth, AUTH_RULE_EAP_IDENTITY);
|
|
|
|
if (id)
|
|
|
|
{
|
2009-04-30 11:37:54 +00:00
|
|
|
fprintf(out, " with EAP identity '%Y'", id);
|
2009-04-14 10:34:24 +00:00
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
2011-12-15 12:13:30 +00:00
|
|
|
else if (auth_class == AUTH_CLASS_XAUTH)
|
|
|
|
{
|
|
|
|
fprintf(out, "%N authentication: %s", auth_class_names, auth_class,
|
|
|
|
auth->get(auth, AUTH_RULE_XAUTH_BACKEND) ?: "any");
|
|
|
|
id = auth->get(auth, AUTH_RULE_XAUTH_IDENTITY);
|
|
|
|
if (id)
|
|
|
|
{
|
|
|
|
fprintf(out, " with XAuth identity '%Y'", id);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(out, "%N authentication\n", auth_class_names, auth_class);
|
|
|
|
}
|
2009-04-14 10:34:24 +00:00
|
|
|
|
|
|
|
cert = auth->get(auth, AUTH_RULE_CA_CERT);
|
|
|
|
if (cert)
|
|
|
|
{
|
2009-04-30 11:37:54 +00:00
|
|
|
fprintf(out, "%12s: ca: \"%Y\"\n", name, cert->get_subject(cert));
|
2009-04-14 10:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cert = auth->get(auth, AUTH_RULE_IM_CERT);
|
|
|
|
if (cert)
|
|
|
|
{
|
2009-04-30 11:37:54 +00:00
|
|
|
fprintf(out, "%12s: im-ca: \"%Y\"\n", name, cert->get_subject(cert));
|
2009-04-14 10:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cert = auth->get(auth, AUTH_RULE_SUBJECT_CERT);
|
|
|
|
if (cert)
|
|
|
|
{
|
2009-04-30 11:37:54 +00:00
|
|
|
fprintf(out, "%12s: cert: \"%Y\"\n", name,
|
2009-04-14 10:34:24 +00:00
|
|
|
cert->get_subject(cert));
|
|
|
|
}
|
|
|
|
|
|
|
|
valid = (uintptr_t)auth->get(auth, AUTH_RULE_OCSP_VALIDATION);
|
|
|
|
if (valid != VALIDATION_FAILED)
|
|
|
|
{
|
|
|
|
fprintf(out, "%12s: ocsp: status must be GOOD%s\n", name,
|
|
|
|
(valid == VALIDATION_SKIPPED) ? " or SKIPPED" : "");
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-04-14 10:34:24 +00:00
|
|
|
valid = (uintptr_t)auth->get(auth, AUTH_RULE_CRL_VALIDATION);
|
|
|
|
if (valid != VALIDATION_FAILED)
|
|
|
|
{
|
|
|
|
fprintf(out, "%12s: crl: status must be GOOD%s\n", name,
|
|
|
|
(valid == VALIDATION_SKIPPED) ? " or SKIPPED" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
rules = auth->create_enumerator(auth);
|
|
|
|
while (rules->enumerate(rules, &rule, &id))
|
|
|
|
{
|
2010-06-28 13:46:13 +00:00
|
|
|
if (rule == AUTH_RULE_GROUP)
|
2009-04-14 10:34:24 +00:00
|
|
|
{
|
2009-04-30 11:37:54 +00:00
|
|
|
fprintf(out, "%12s: group: %Y\n", name, id);
|
2009-04-14 10:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rules->destroy(rules);
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
}
|
|
|
|
|
2010-12-24 13:29:09 +00:00
|
|
|
METHOD(stroke_list_t, status, void,
|
2011-05-04 09:21:33 +00:00
|
|
|
private_stroke_list_t *this, stroke_msg_t *msg, FILE *out,
|
|
|
|
bool all, bool wait)
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
|
|
|
enumerator_t *enumerator, *children;
|
|
|
|
ike_cfg_t *ike_cfg;
|
|
|
|
child_cfg_t *child_cfg;
|
2009-05-06 17:50:18 +00:00
|
|
|
child_sa_t *child_sa;
|
2008-03-26 10:10:40 +00:00
|
|
|
ike_sa_t *ike_sa;
|
2011-06-28 17:42:54 +00:00
|
|
|
linked_list_t *my_ts, *other_ts;
|
2009-05-24 18:06:55 +00:00
|
|
|
bool first, found = FALSE;
|
2008-08-25 12:35:18 +00:00
|
|
|
char *name = msg->status.name;
|
2011-05-05 08:31:45 +00:00
|
|
|
u_int half_open;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
if (all)
|
|
|
|
{
|
2008-08-25 12:35:18 +00:00
|
|
|
peer_cfg_t *peer_cfg;
|
2012-05-23 09:12:27 +00:00
|
|
|
ike_version_t ike_version;
|
2012-01-19 11:27:56 +00:00
|
|
|
char *pool;
|
2008-08-25 12:35:18 +00:00
|
|
|
host_t *host;
|
2016-03-22 12:22:01 +00:00
|
|
|
uint32_t dpd;
|
2009-08-31 15:59:00 +00:00
|
|
|
time_t since, now;
|
2011-05-02 09:28:04 +00:00
|
|
|
u_int size, online, offline, i;
|
2012-06-28 09:56:40 +00:00
|
|
|
struct utsname utsname;
|
|
|
|
|
2009-08-31 15:59:00 +00:00
|
|
|
now = time_monotonic(NULL);
|
|
|
|
since = time(NULL) - (now - this->uptime);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-06-28 09:56:40 +00:00
|
|
|
fprintf(out, "Status of IKE charon daemon (%sSwan "VERSION, this->swan);
|
|
|
|
if (uname(&utsname) == 0)
|
|
|
|
{
|
|
|
|
fprintf(out, ", %s %s, %s",
|
|
|
|
utsname.sysname, utsname.release, utsname.machine);
|
|
|
|
}
|
|
|
|
fprintf(out, "):\n uptime: %V, since %T\n", &now, &this->uptime, &since,
|
2012-06-13 10:11:55 +00:00
|
|
|
FALSE);
|
2010-07-06 14:26:59 +00:00
|
|
|
#ifdef HAVE_MALLINFO
|
|
|
|
{
|
|
|
|
struct mallinfo mi = mallinfo();
|
|
|
|
|
2015-03-13 14:20:08 +00:00
|
|
|
fprintf(out, " malloc: sbrk %u, mmap %u, used %u, free %u\n",
|
2010-07-06 14:26:59 +00:00
|
|
|
mi.arena, mi.hblkhd, mi.uordblks, mi.fordblks);
|
|
|
|
}
|
|
|
|
#endif /* HAVE_MALLINFO */
|
2011-05-04 13:33:47 +00:00
|
|
|
fprintf(out, " worker threads: %d of %d idle, ",
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->processor->get_idle_threads(lib->processor),
|
|
|
|
lib->processor->get_total_threads(lib->processor));
|
2011-05-04 13:33:47 +00:00
|
|
|
for (i = 0; i < JOB_PRIO_MAX; i++)
|
|
|
|
{
|
|
|
|
fprintf(out, "%s%d", i == 0 ? "" : "/",
|
|
|
|
lib->processor->get_working_threads(lib->processor, i));
|
|
|
|
}
|
|
|
|
fprintf(out, " working, job queue: ");
|
2011-05-02 09:28:04 +00:00
|
|
|
for (i = 0; i < JOB_PRIO_MAX; i++)
|
|
|
|
{
|
|
|
|
fprintf(out, "%s%d", i == 0 ? "" : "/",
|
|
|
|
lib->processor->get_job_load(lib->processor, i));
|
|
|
|
}
|
2011-05-04 13:33:47 +00:00
|
|
|
fprintf(out, ", scheduled: %d\n",
|
2010-07-15 12:49:41 +00:00
|
|
|
lib->scheduler->get_job_load(lib->scheduler));
|
2012-01-19 11:27:56 +00:00
|
|
|
fprintf(out, " loaded plugins: %s\n",
|
|
|
|
lib->plugins->loaded_plugins(lib->plugins));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-05-24 18:06:55 +00:00
|
|
|
first = TRUE;
|
2008-12-09 13:24:12 +00:00
|
|
|
enumerator = this->attribute->create_pool_enumerator(this->attribute);
|
2009-01-14 08:10:16 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &pool, &size, &online, &offline))
|
2008-12-09 13:24:12 +00:00
|
|
|
{
|
2009-03-03 10:30:59 +00:00
|
|
|
if (name && !streq(name, pool))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2008-12-09 13:24:12 +00:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
first = FALSE;
|
|
|
|
fprintf(out, "Virtual IP pools (size/online/offline):\n");
|
|
|
|
}
|
2009-04-22 10:43:39 +00:00
|
|
|
fprintf(out, " %s: %u/%u/%u\n", pool, size, online, offline);
|
2008-12-09 13:24:12 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2016-02-12 14:30:18 +00:00
|
|
|
enumerator = charon->kernel->create_address_enumerator(charon->kernel,
|
|
|
|
ADDR_TYPE_REGULAR);
|
2008-03-26 10:10:40 +00:00
|
|
|
fprintf(out, "Listening IP addresses:\n");
|
2008-09-25 07:56:58 +00:00
|
|
|
while (enumerator->enumerate(enumerator, (void**)&host))
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
|
|
|
fprintf(out, " %H\n", host);
|
|
|
|
}
|
2008-09-25 07:56:58 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
fprintf(out, "Connections:\n");
|
2009-04-14 10:34:24 +00:00
|
|
|
enumerator = charon->backends->create_peer_cfg_enumerator(
|
2011-12-17 12:31:27 +00:00
|
|
|
charon->backends, NULL, NULL, NULL, NULL, IKE_ANY);
|
2009-04-14 10:34:24 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &peer_cfg))
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
2012-06-08 11:01:08 +00:00
|
|
|
char *my_addr, *other_addr;
|
|
|
|
|
2011-11-18 09:08:18 +00:00
|
|
|
if (name && !streq(name, peer_cfg->get_name(peer_cfg)))
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
ike_cfg = peer_cfg->get_ike_cfg(peer_cfg);
|
2012-05-23 09:12:27 +00:00
|
|
|
ike_version = peer_cfg->get_ike_version(peer_cfg);
|
2013-07-25 13:37:13 +00:00
|
|
|
my_addr = ike_cfg->get_my_addr(ike_cfg);
|
|
|
|
other_addr = ike_cfg->get_other_addr(ike_cfg);
|
2013-07-25 12:07:40 +00:00
|
|
|
fprintf(out, "%12s: %s...%s %N", peer_cfg->get_name(peer_cfg),
|
|
|
|
my_addr, other_addr, ike_version_names, ike_version);
|
2012-05-23 09:12:27 +00:00
|
|
|
|
|
|
|
if (ike_version == IKEV1 && peer_cfg->use_aggressive(peer_cfg))
|
|
|
|
{
|
|
|
|
fprintf(out, " Aggressive");
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-07-02 10:48:57 +00:00
|
|
|
dpd = peer_cfg->get_dpd(peer_cfg);
|
|
|
|
if (dpd)
|
|
|
|
{
|
|
|
|
fprintf(out, ", dpddelay=%us", dpd);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-04-14 10:34:24 +00:00
|
|
|
log_auth_cfgs(out, peer_cfg, TRUE);
|
|
|
|
log_auth_cfgs(out, peer_cfg, FALSE);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
children = peer_cfg->create_child_cfg_enumerator(peer_cfg);
|
|
|
|
while (children->enumerate(children, &child_cfg))
|
|
|
|
{
|
|
|
|
my_ts = child_cfg->get_traffic_selectors(child_cfg, TRUE, NULL, NULL);
|
|
|
|
other_ts = child_cfg->get_traffic_selectors(child_cfg, FALSE, NULL, NULL);
|
2015-10-07 14:25:05 +00:00
|
|
|
fprintf(out, "%12s: child: %#R === %#R %N",
|
2011-06-28 17:42:54 +00:00
|
|
|
child_cfg->get_name(child_cfg), my_ts, other_ts,
|
|
|
|
ipsec_mode_names, child_cfg->get_mode(child_cfg));
|
2008-03-26 10:10:40 +00:00
|
|
|
my_ts->destroy_offset(my_ts, offsetof(traffic_selector_t, destroy));
|
|
|
|
other_ts->destroy_offset(other_ts, offsetof(traffic_selector_t, destroy));
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-07-02 10:48:57 +00:00
|
|
|
if (dpd)
|
|
|
|
{
|
|
|
|
fprintf(out, ", dpdaction=%N", action_names,
|
|
|
|
child_cfg->get_dpd_action(child_cfg));
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
children->destroy(children);
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
}
|
2009-05-24 18:06:55 +00:00
|
|
|
|
2011-06-28 17:42:54 +00:00
|
|
|
/* Enumerate shunt policies */
|
|
|
|
first = TRUE;
|
|
|
|
enumerator = charon->shunts->create_enumerator(charon->shunts);
|
|
|
|
while (enumerator->enumerate(enumerator, &child_cfg))
|
|
|
|
{
|
|
|
|
if (name && !streq(name, child_cfg->get_name(child_cfg)))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
fprintf(out, "Shunted Connections:\n");
|
|
|
|
first = FALSE;
|
|
|
|
}
|
|
|
|
my_ts = child_cfg->get_traffic_selectors(child_cfg, TRUE, NULL, NULL);
|
|
|
|
other_ts = child_cfg->get_traffic_selectors(child_cfg, FALSE, NULL, NULL);
|
2015-10-07 14:25:05 +00:00
|
|
|
fprintf(out, "%12s: %#R === %#R %N\n",
|
2011-06-28 17:42:54 +00:00
|
|
|
child_cfg->get_name(child_cfg), my_ts, other_ts,
|
|
|
|
ipsec_mode_names, child_cfg->get_mode(child_cfg));
|
|
|
|
my_ts->destroy_offset(my_ts, offsetof(traffic_selector_t, destroy));
|
|
|
|
other_ts->destroy_offset(other_ts, offsetof(traffic_selector_t, destroy));
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
|
|
|
|
/* Enumerate traps */
|
2009-09-04 11:46:09 +00:00
|
|
|
first = TRUE;
|
2009-05-06 17:50:18 +00:00
|
|
|
enumerator = charon->traps->create_enumerator(charon->traps);
|
|
|
|
while (enumerator->enumerate(enumerator, NULL, &child_sa))
|
|
|
|
{
|
2011-06-28 17:42:54 +00:00
|
|
|
if (name && !streq(name, child_sa->get_name(child_sa)))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2009-05-24 18:06:55 +00:00
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
fprintf(out, "Routed Connections:\n");
|
|
|
|
first = FALSE;
|
|
|
|
}
|
2009-05-06 17:50:18 +00:00
|
|
|
log_child_sa(out, child_sa, all);
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-05-05 08:31:45 +00:00
|
|
|
half_open = charon->ike_sa_manager->get_half_open_count(
|
2015-08-24 10:18:16 +00:00
|
|
|
charon->ike_sa_manager, NULL, FALSE);
|
2011-05-05 08:31:45 +00:00
|
|
|
fprintf(out, "Security Associations (%u up, %u connecting):\n",
|
|
|
|
charon->ike_sa_manager->get_count(charon->ike_sa_manager) - half_open,
|
|
|
|
half_open);
|
2011-05-02 13:28:33 +00:00
|
|
|
enumerator = charon->controller->create_ike_sa_enumerator(
|
2011-05-04 09:21:33 +00:00
|
|
|
charon->controller, wait);
|
2013-08-23 12:22:29 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &ike_sa) && ferror(out) == 0)
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
|
|
|
bool ike_printed = FALSE;
|
2011-05-19 15:27:32 +00:00
|
|
|
enumerator_t *children = ike_sa->create_child_sa_enumerator(ike_sa);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
if (name == NULL || streq(name, ike_sa->get_name(ike_sa)))
|
|
|
|
{
|
|
|
|
log_ike_sa(out, ike_sa, all);
|
2008-04-14 11:37:46 +00:00
|
|
|
found = TRUE;
|
2008-03-26 10:10:40 +00:00
|
|
|
ike_printed = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-19 15:27:32 +00:00
|
|
|
while (children->enumerate(children, (void**)&child_sa))
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
|
|
|
if (name == NULL || streq(name, child_sa->get_name(child_sa)))
|
|
|
|
{
|
|
|
|
if (!ike_printed)
|
|
|
|
{
|
|
|
|
log_ike_sa(out, ike_sa, all);
|
2008-04-14 11:37:46 +00:00
|
|
|
found = TRUE;
|
2008-03-26 10:10:40 +00:00
|
|
|
ike_printed = TRUE;
|
|
|
|
}
|
|
|
|
log_child_sa(out, child_sa, all);
|
2009-09-04 11:46:09 +00:00
|
|
|
}
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
children->destroy(children);
|
|
|
|
}
|
2008-04-14 11:37:46 +00:00
|
|
|
enumerator->destroy(enumerator);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-04-14 11:37:46 +00:00
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
fprintf(out, " no match\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(out, " none\n");
|
|
|
|
}
|
|
|
|
}
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-31 20:21:24 +00:00
|
|
|
/**
|
|
|
|
* create a unique certificate list without duplicates
|
2008-04-01 12:11:09 +00:00
|
|
|
* certicates having the same issuer are grouped together.
|
2008-03-31 20:21:24 +00:00
|
|
|
*/
|
|
|
|
static linked_list_t* create_unique_cert_list(certificate_type_t type)
|
|
|
|
{
|
|
|
|
linked_list_t *list = linked_list_create();
|
2010-07-05 09:54:25 +00:00
|
|
|
enumerator_t *enumerator = lib->credmgr->create_cert_enumerator(
|
|
|
|
lib->credmgr, type, KEY_ANY, NULL, FALSE);
|
2008-03-31 20:21:24 +00:00
|
|
|
certificate_t *cert;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-03-31 20:21:24 +00:00
|
|
|
while (enumerator->enumerate(enumerator, (void**)&cert))
|
|
|
|
{
|
2011-05-19 16:52:57 +00:00
|
|
|
enumerator_t *added = list->create_enumerator(list);
|
2008-04-01 10:26:27 +00:00
|
|
|
identification_t *issuer = cert->get_issuer(cert);
|
2011-05-19 16:52:57 +00:00
|
|
|
bool previous_same, same = FALSE, found = FALSE;
|
2008-03-31 20:21:24 +00:00
|
|
|
certificate_t *list_cert;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-05-19 16:52:57 +00:00
|
|
|
while (added->enumerate(added, (void**)&list_cert))
|
2008-03-31 20:21:24 +00:00
|
|
|
{
|
2008-04-07 08:48:08 +00:00
|
|
|
if (list_cert->equals(list_cert, cert))
|
2011-05-19 16:52:57 +00:00
|
|
|
{ /* stop if we found a duplicate*/
|
|
|
|
found = TRUE;
|
2008-04-01 10:26:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
previous_same = same;
|
|
|
|
same = list_cert->has_issuer(list_cert, issuer);
|
|
|
|
if (previous_same && !same)
|
2011-05-19 16:52:57 +00:00
|
|
|
{ /* group certificates with same issuer */
|
2008-03-31 20:21:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-05-19 16:52:57 +00:00
|
|
|
if (!found)
|
2008-03-31 20:21:24 +00:00
|
|
|
{
|
2011-05-19 16:52:57 +00:00
|
|
|
list->insert_before(list, added, cert->get_ref(cert));
|
2008-03-31 20:21:24 +00:00
|
|
|
}
|
2011-05-19 16:52:57 +00:00
|
|
|
added->destroy(added);
|
2008-03-31 20:21:24 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2009-08-24 12:20:59 +00:00
|
|
|
/**
|
2015-12-06 12:28:03 +00:00
|
|
|
* Is there a matching private key?
|
2009-08-24 12:20:59 +00:00
|
|
|
*/
|
2015-12-06 12:28:03 +00:00
|
|
|
static bool has_privkey(certificate_t *cert)
|
2009-08-24 12:20:59 +00:00
|
|
|
{
|
2015-12-06 12:28:03 +00:00
|
|
|
public_key_t *public;
|
2009-08-24 12:20:59 +00:00
|
|
|
private_key_t *private = NULL;
|
|
|
|
chunk_t keyid;
|
|
|
|
identification_t *id;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2015-12-06 12:28:03 +00:00
|
|
|
public = cert->get_public_key(cert);
|
|
|
|
if (!public)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-13 09:28:04 +00:00
|
|
|
if (public->get_fingerprint(public, KEYID_PUBKEY_SHA1, &keyid))
|
2009-08-24 12:20:59 +00:00
|
|
|
{
|
|
|
|
id = identification_create_from_encoding(ID_KEY_ID, keyid);
|
2010-07-05 09:54:25 +00:00
|
|
|
private = lib->credmgr->get_private(lib->credmgr,
|
2012-01-23 11:25:38 +00:00
|
|
|
public->get_type(public), id, NULL);
|
2009-08-24 12:20:59 +00:00
|
|
|
id->destroy(id);
|
|
|
|
}
|
2015-12-06 12:28:03 +00:00
|
|
|
public->destroy(public);
|
2009-08-24 12:20:59 +00:00
|
|
|
DESTROY_IF(private);
|
2012-04-30 07:47:34 +00:00
|
|
|
|
2015-12-06 12:28:03 +00:00
|
|
|
return (private != NULL);
|
2008-10-08 07:00:13 +00:00
|
|
|
}
|
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
/**
|
|
|
|
* list all X.509 certificates matching the flags
|
|
|
|
*/
|
2015-12-11 17:24:58 +00:00
|
|
|
static void stroke_list_x509_certs(linked_list_t *list, x509_flag_t flag)
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
2009-12-23 13:17:28 +00:00
|
|
|
enumerator_t *enumerator;
|
2008-03-26 10:10:40 +00:00
|
|
|
certificate_t *cert;
|
2009-12-23 13:17:28 +00:00
|
|
|
|
|
|
|
enumerator = list->create_enumerator(list);
|
2008-03-26 10:10:40 +00:00
|
|
|
while (enumerator->enumerate(enumerator, (void**)&cert))
|
|
|
|
{
|
|
|
|
x509_t *x509 = (x509_t*)cert;
|
2015-12-11 17:24:58 +00:00
|
|
|
x509_flag_t flags = x509->get_flags(x509) & X509_ANY;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-12-23 13:17:28 +00:00
|
|
|
/* list only if flag is set or flag == 0 */
|
2015-12-11 17:24:58 +00:00
|
|
|
if ((flags & flag) || flags == flag)
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
cert_printer->print_caption(cert_printer, CERT_X509, flag);
|
|
|
|
cert_printer->print(cert_printer, cert, has_privkey(cert));
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
}
|
|
|
|
|
2008-03-31 20:21:24 +00:00
|
|
|
/**
|
2015-12-06 12:28:03 +00:00
|
|
|
* list all other certificates types
|
2008-03-31 20:21:24 +00:00
|
|
|
*/
|
2015-12-11 17:24:58 +00:00
|
|
|
static void stroke_list_other_certs(certificate_type_t type)
|
2008-03-31 20:21:24 +00:00
|
|
|
{
|
2014-02-04 14:41:09 +00:00
|
|
|
enumerator_t *enumerator;
|
2008-05-22 21:58:22 +00:00
|
|
|
certificate_t *cert;
|
2015-12-11 17:24:58 +00:00
|
|
|
linked_list_t *list;
|
2015-12-06 12:28:03 +00:00
|
|
|
|
2015-12-11 17:24:58 +00:00
|
|
|
list = create_unique_cert_list(type);
|
2008-03-31 20:21:24 +00:00
|
|
|
|
2014-02-04 14:41:09 +00:00
|
|
|
enumerator = list->create_enumerator(list);
|
|
|
|
while (enumerator->enumerate(enumerator, &cert))
|
2008-05-22 21:58:22 +00:00
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
cert_printer->print_caption(cert_printer, cert->get_type(cert), X509_NONE);
|
|
|
|
cert_printer->print(cert_printer, cert, has_privkey(cert));
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2010-09-10 20:14:12 +00:00
|
|
|
|
2015-12-11 17:24:58 +00:00
|
|
|
list->destroy_offset(list, offsetof(certificate_t, destroy));
|
2008-03-31 20:21:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-24 16:29:51 +00:00
|
|
|
/**
|
|
|
|
* Print the name of an algorithm plus the name of the plugin that registered it
|
|
|
|
*/
|
|
|
|
static void print_alg(FILE *out, int *len, enum_name_t *alg_names, int alg_type,
|
|
|
|
const char *plugin_name)
|
|
|
|
{
|
|
|
|
char alg_name[BUF_LEN];
|
|
|
|
int alg_name_len;
|
2011-04-11 16:54:18 +00:00
|
|
|
|
2012-05-16 16:26:36 +00:00
|
|
|
if (alg_names)
|
|
|
|
{
|
|
|
|
alg_name_len = sprintf(alg_name, " %N[%s]", alg_names, alg_type,
|
|
|
|
plugin_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
alg_name_len = sprintf(alg_name, " [%s]", plugin_name);
|
|
|
|
}
|
2010-12-26 16:11:02 +00:00
|
|
|
if (*len + alg_name_len > CRYPTO_MAX_ALG_LINE)
|
2010-12-24 16:29:51 +00:00
|
|
|
{
|
|
|
|
fprintf(out, "\n ");
|
2011-04-11 16:54:18 +00:00
|
|
|
*len = 13;
|
2010-12-24 16:29:51 +00:00
|
|
|
}
|
|
|
|
fprintf(out, "%s", alg_name);
|
|
|
|
*len += alg_name_len;
|
|
|
|
}
|
|
|
|
|
2008-08-28 09:24:42 +00:00
|
|
|
/**
|
2008-08-29 05:35:09 +00:00
|
|
|
* List of registered cryptographical algorithms
|
2008-08-28 09:24:42 +00:00
|
|
|
*/
|
|
|
|
static void list_algs(FILE *out)
|
|
|
|
{
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
encryption_algorithm_t encryption;
|
|
|
|
integrity_algorithm_t integrity;
|
|
|
|
hash_algorithm_t hash;
|
|
|
|
pseudo_random_function_t prf;
|
2016-07-28 12:42:42 +00:00
|
|
|
ext_out_function_t xof;
|
2008-08-28 09:24:42 +00:00
|
|
|
diffie_hellman_group_t group;
|
2010-12-18 15:31:01 +00:00
|
|
|
rng_quality_t quality;
|
|
|
|
const char *plugin_name;
|
2010-12-24 16:29:51 +00:00
|
|
|
int len;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-08-29 05:35:09 +00:00
|
|
|
fprintf(out, "\n");
|
2013-03-18 11:18:44 +00:00
|
|
|
fprintf(out, "List of registered IKE algorithms:\n");
|
2010-12-24 16:29:51 +00:00
|
|
|
fprintf(out, "\n encryption:");
|
|
|
|
len = 13;
|
2008-08-28 09:24:42 +00:00
|
|
|
enumerator = lib->crypto->create_crypter_enumerator(lib->crypto);
|
2010-12-18 15:31:01 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &encryption, &plugin_name))
|
2008-08-28 09:24:42 +00:00
|
|
|
{
|
2010-12-24 16:29:51 +00:00
|
|
|
print_alg(out, &len, encryption_algorithm_names, encryption, plugin_name);
|
2008-08-28 09:24:42 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2010-12-24 16:29:51 +00:00
|
|
|
fprintf(out, "\n integrity: ");
|
|
|
|
len = 13;
|
2008-08-28 09:24:42 +00:00
|
|
|
enumerator = lib->crypto->create_signer_enumerator(lib->crypto);
|
2010-12-18 15:31:01 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &integrity, &plugin_name))
|
2008-08-28 09:24:42 +00:00
|
|
|
{
|
2010-12-24 16:29:51 +00:00
|
|
|
print_alg(out, &len, integrity_algorithm_names, integrity, plugin_name);
|
2008-08-28 09:24:42 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2010-12-24 16:29:51 +00:00
|
|
|
fprintf(out, "\n aead: ");
|
|
|
|
len = 13;
|
2010-08-18 18:17:09 +00:00
|
|
|
enumerator = lib->crypto->create_aead_enumerator(lib->crypto);
|
2010-12-18 15:31:01 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &encryption, &plugin_name))
|
2010-08-18 18:17:09 +00:00
|
|
|
{
|
2010-12-24 16:29:51 +00:00
|
|
|
print_alg(out, &len, encryption_algorithm_names, encryption, plugin_name);
|
2010-08-18 18:17:09 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2010-12-24 16:29:51 +00:00
|
|
|
fprintf(out, "\n hasher: ");
|
|
|
|
len = 13;
|
2008-08-28 09:24:42 +00:00
|
|
|
enumerator = lib->crypto->create_hasher_enumerator(lib->crypto);
|
2010-12-18 15:31:01 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &hash, &plugin_name))
|
2008-08-28 09:24:42 +00:00
|
|
|
{
|
2010-12-24 16:29:51 +00:00
|
|
|
print_alg(out, &len, hash_algorithm_names, hash, plugin_name);
|
2008-08-28 09:24:42 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2010-12-24 16:29:51 +00:00
|
|
|
fprintf(out, "\n prf: ");
|
|
|
|
len = 13;
|
2008-08-28 09:24:42 +00:00
|
|
|
enumerator = lib->crypto->create_prf_enumerator(lib->crypto);
|
2010-12-18 15:31:01 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &prf, &plugin_name))
|
2008-08-28 09:24:42 +00:00
|
|
|
{
|
2010-12-24 16:29:51 +00:00
|
|
|
print_alg(out, &len, pseudo_random_function_names, prf, plugin_name);
|
2008-08-28 09:24:42 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2016-07-28 12:42:42 +00:00
|
|
|
fprintf(out, "\n xof: ");
|
|
|
|
len = 13;
|
|
|
|
enumerator = lib->crypto->create_xof_enumerator(lib->crypto);
|
|
|
|
while (enumerator->enumerate(enumerator, &xof, &plugin_name))
|
|
|
|
{
|
|
|
|
print_alg(out, &len, ext_out_function_names, xof, plugin_name);
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2010-12-24 16:29:51 +00:00
|
|
|
fprintf(out, "\n dh-group: ");
|
|
|
|
len = 13;
|
2008-08-28 09:24:42 +00:00
|
|
|
enumerator = lib->crypto->create_dh_enumerator(lib->crypto);
|
2010-12-18 15:31:01 +00:00
|
|
|
while (enumerator->enumerate(enumerator, &group, &plugin_name))
|
2008-08-28 09:24:42 +00:00
|
|
|
{
|
2010-12-24 16:29:51 +00:00
|
|
|
print_alg(out, &len, diffie_hellman_group_names, group, plugin_name);
|
2010-12-18 15:31:01 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2010-12-24 16:29:51 +00:00
|
|
|
fprintf(out, "\n random-gen:");
|
|
|
|
len = 13;
|
2010-12-18 15:31:01 +00:00
|
|
|
enumerator = lib->crypto->create_rng_enumerator(lib->crypto);
|
|
|
|
while (enumerator->enumerate(enumerator, &quality, &plugin_name))
|
|
|
|
{
|
2010-12-24 16:29:51 +00:00
|
|
|
print_alg(out, &len, rng_quality_names, quality, plugin_name);
|
2008-08-28 09:24:42 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2012-05-16 16:26:36 +00:00
|
|
|
fprintf(out, "\n nonce-gen: ");
|
|
|
|
len = 13;
|
|
|
|
enumerator = lib->crypto->create_nonce_gen_enumerator(lib->crypto);
|
|
|
|
while (enumerator->enumerate(enumerator, &plugin_name))
|
|
|
|
{
|
|
|
|
print_alg(out, &len, NULL, 0, plugin_name);
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
2008-08-28 09:24:42 +00:00
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
|
2011-06-29 13:45:32 +00:00
|
|
|
/**
|
|
|
|
* List loaded plugin information
|
|
|
|
*/
|
|
|
|
static void list_plugins(FILE *out)
|
|
|
|
{
|
|
|
|
plugin_feature_t *features, *fp;
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
linked_list_t *list;
|
|
|
|
plugin_t *plugin;
|
|
|
|
int count, i;
|
|
|
|
bool loaded;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
fprintf(out, "\n");
|
2011-10-26 08:32:54 +00:00
|
|
|
fprintf(out, "List of loaded Plugins:\n");
|
|
|
|
fprintf(out, "\n");
|
2011-06-29 13:45:32 +00:00
|
|
|
|
|
|
|
enumerator = lib->plugins->create_plugin_enumerator(lib->plugins);
|
|
|
|
while (enumerator->enumerate(enumerator, &plugin, &list))
|
|
|
|
{
|
|
|
|
fprintf(out, "%s:\n", plugin->get_name(plugin));
|
|
|
|
if (plugin->get_features)
|
|
|
|
{
|
|
|
|
count = plugin->get_features(plugin, &features);
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
str = plugin_feature_get_string(&features[i]);
|
|
|
|
switch (features[i].kind)
|
|
|
|
{
|
|
|
|
case FEATURE_PROVIDE:
|
|
|
|
fp = &features[i];
|
|
|
|
loaded = list->find_first(list, NULL,
|
|
|
|
(void**)&fp) == SUCCESS;
|
|
|
|
fprintf(out, " %s%s\n",
|
|
|
|
str, loaded ? "" : " (not loaded)");
|
|
|
|
break;
|
|
|
|
case FEATURE_DEPENDS:
|
|
|
|
fprintf(out, " %s\n", str);
|
|
|
|
break;
|
|
|
|
case FEATURE_SDEPEND:
|
2012-05-03 09:54:56 +00:00
|
|
|
fprintf(out, " %s (soft)\n", str);
|
2011-06-29 13:45:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
}
|
2013-06-08 13:46:33 +00:00
|
|
|
list->destroy(list);
|
2011-06-29 13:45:32 +00:00
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
}
|
|
|
|
|
2010-12-24 13:29:09 +00:00
|
|
|
METHOD(stroke_list_t, list, void,
|
|
|
|
private_stroke_list_t *this, stroke_msg_t *msg, FILE *out)
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
2008-03-31 20:21:24 +00:00
|
|
|
linked_list_t *cert_list = NULL;
|
|
|
|
|
2015-12-11 17:24:58 +00:00
|
|
|
cert_printer = certificate_printer_create(out, TRUE, msg->list.utc);
|
|
|
|
|
2008-10-08 07:00:13 +00:00
|
|
|
if (msg->list.flags & LIST_PUBKEYS)
|
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
stroke_list_other_certs(CERT_TRUSTED_PUBKEY);
|
2008-10-08 07:00:13 +00:00
|
|
|
}
|
2009-11-08 20:01:12 +00:00
|
|
|
if (msg->list.flags & LIST_CERTS)
|
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
stroke_list_other_certs(CERT_GPG);
|
2009-11-08 20:01:12 +00:00
|
|
|
}
|
2008-03-31 20:21:24 +00:00
|
|
|
if (msg->list.flags & (LIST_CERTS | LIST_CACERTS | LIST_OCSPCERTS | LIST_AACERTS))
|
|
|
|
{
|
|
|
|
cert_list = create_unique_cert_list(CERT_X509);
|
|
|
|
}
|
2008-03-26 10:10:40 +00:00
|
|
|
if (msg->list.flags & LIST_CERTS)
|
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
stroke_list_x509_certs(cert_list, X509_NONE);
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
if (msg->list.flags & LIST_CACERTS)
|
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
stroke_list_x509_certs(cert_list, X509_CA);
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
if (msg->list.flags & LIST_OCSPCERTS)
|
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
stroke_list_x509_certs(cert_list, X509_OCSP_SIGNER);
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
if (msg->list.flags & LIST_AACERTS)
|
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
stroke_list_x509_certs(cert_list, X509_AA);
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
2009-11-08 20:01:12 +00:00
|
|
|
DESTROY_OFFSET_IF(cert_list, offsetof(certificate_t, destroy));
|
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
if (msg->list.flags & LIST_ACERTS)
|
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
stroke_list_other_certs(CERT_X509_AC);
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
if (msg->list.flags & LIST_CRLS)
|
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
stroke_list_other_certs(CERT_X509_CRL);
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
if (msg->list.flags & LIST_OCSP)
|
|
|
|
{
|
2015-12-11 17:24:58 +00:00
|
|
|
stroke_list_other_certs(CERT_X509_OCSP_RESPONSE);
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
2008-08-28 09:24:42 +00:00
|
|
|
if (msg->list.flags & LIST_ALGS)
|
|
|
|
{
|
|
|
|
list_algs(out);
|
|
|
|
}
|
2011-06-29 13:45:32 +00:00
|
|
|
if (msg->list.flags & LIST_PLUGINS)
|
|
|
|
{
|
|
|
|
list_plugins(out);
|
|
|
|
}
|
2015-12-11 17:24:58 +00:00
|
|
|
cert_printer->destroy(cert_printer);
|
|
|
|
cert_printer = NULL;
|
2008-03-26 10:10:40 +00:00
|
|
|
}
|
|
|
|
|
2008-12-10 13:00:02 +00:00
|
|
|
/**
|
|
|
|
* Print leases of a single pool
|
|
|
|
*/
|
|
|
|
static void pool_leases(private_stroke_list_t *this, FILE *out, char *pool,
|
|
|
|
host_t *address, u_int size, u_int online, u_int offline)
|
|
|
|
{
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
identification_t *id;
|
|
|
|
host_t *lease;
|
|
|
|
bool on;
|
|
|
|
int found = 0;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2010-10-24 18:30:19 +00:00
|
|
|
fprintf(out, "Leases in pool '%s', usage: %u/%u, %u online\n",
|
2008-12-10 13:00:02 +00:00
|
|
|
pool, online + offline, size, online);
|
|
|
|
enumerator = this->attribute->create_lease_enumerator(this->attribute, pool);
|
|
|
|
while (enumerator && enumerator->enumerate(enumerator, &id, &lease, &on))
|
|
|
|
{
|
|
|
|
if (!address || address->ip_equals(address, lease))
|
|
|
|
{
|
2009-04-30 11:37:54 +00:00
|
|
|
fprintf(out, " %15H %s '%Y'\n",
|
2008-12-10 13:00:02 +00:00
|
|
|
lease, on ? "online" : "offline", id);
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
fprintf(out, " no matching leases found\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-24 13:29:09 +00:00
|
|
|
METHOD(stroke_list_t, leases, void,
|
|
|
|
private_stroke_list_t *this, stroke_msg_t *msg, FILE *out)
|
2008-12-10 13:00:02 +00:00
|
|
|
{
|
|
|
|
enumerator_t *enumerator;
|
|
|
|
u_int size, offline, online;
|
|
|
|
host_t *address = NULL;
|
|
|
|
char *pool;
|
|
|
|
int found = 0;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-12-10 13:00:02 +00:00
|
|
|
if (msg->leases.address)
|
|
|
|
{
|
|
|
|
address = host_create_from_string(msg->leases.address, 0);
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-12-10 13:00:02 +00:00
|
|
|
enumerator = this->attribute->create_pool_enumerator(this->attribute);
|
|
|
|
while (enumerator->enumerate(enumerator, &pool, &size, &online, &offline))
|
|
|
|
{
|
|
|
|
if (!msg->leases.pool || streq(msg->leases.pool, pool))
|
|
|
|
{
|
|
|
|
pool_leases(this, out, pool, address, size, online, offline);
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enumerator->destroy(enumerator);
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
if (msg->leases.pool)
|
|
|
|
{
|
|
|
|
fprintf(out, "pool '%s' not found\n", msg->leases.pool);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(out, "no pools found\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DESTROY_IF(address);
|
|
|
|
}
|
|
|
|
|
2010-12-24 13:29:09 +00:00
|
|
|
METHOD(stroke_list_t, destroy, void,
|
|
|
|
private_stroke_list_t *this)
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see header file
|
|
|
|
*/
|
2008-12-09 13:24:12 +00:00
|
|
|
stroke_list_t *stroke_list_create(stroke_attribute_t *attribute)
|
2008-03-26 10:10:40 +00:00
|
|
|
{
|
2010-12-24 13:29:09 +00:00
|
|
|
private_stroke_list_t *this;
|
|
|
|
|
|
|
|
INIT(this,
|
|
|
|
.public = {
|
|
|
|
.list = _list,
|
|
|
|
.status = _status,
|
|
|
|
.leases = _leases,
|
|
|
|
.destroy = _destroy,
|
|
|
|
},
|
|
|
|
.uptime = time_monotonic(NULL),
|
2012-06-13 10:11:55 +00:00
|
|
|
.swan = "strong",
|
2010-12-24 13:29:09 +00:00
|
|
|
.attribute = attribute,
|
|
|
|
);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2012-06-13 10:11:55 +00:00
|
|
|
if (lib->settings->get_bool(lib->settings,
|
|
|
|
"charon.i_dont_care_about_security_and_use_aggressive_mode_psk", FALSE))
|
|
|
|
{
|
|
|
|
this->swan = "weak";
|
|
|
|
}
|
|
|
|
|
2008-03-26 10:10:40 +00:00
|
|
|
return &this->public;
|
|
|
|
}
|