logging: migrate remaining cold paths to facade

Sweeps startup banners, config validation, HTTP /status lifecycle, TLS
and certificate diagnostics, MQTT and Redis publisher lifecycle, and
ReflectorMsg serialisation errors through geulog::{info,warn,error}.
No behaviour change — every line retains its message content and level.

After this commit, grep for cout/cerr << in src/svxlink/reflector/
returns no real call sites (only #if 0 blocks and string literals).
This commit is contained in:
Audric committed 2026-04-18 19:28:16 +02:00
1 parent ccec8f1e95
commit 14878d285c
8 files changed
+305 -345

No files matched your search

+30 -26
View File
@@ -4,6 +4,7 @@
#include <sstream> #include <sstream>
#include <mosquitto.h> #include <mosquitto.h>
#include <AsyncConfig.h> #include <AsyncConfig.h>
#include <Log.h>
using namespace std; using namespace std;
@@ -12,12 +13,12 @@ static void on_connect_cb(struct mosquitto*, void*, int rc)
{ {
if (rc == 0) if (rc == 0)
{ {
cout << "MQTT: Connected to broker" << endl; geulog::info("mqtt", "MQTT: Connected to broker");
} }
else else
{ {
cerr << "*** WARNING: MQTT connection failed: " geulog::warn("mqtt", "MQTT connection failed: ",
<< mosquitto_connack_string(rc) << endl; mosquitto_connack_string(rc));
} }
} }
@@ -26,8 +27,8 @@ static void on_disconnect_cb(struct mosquitto*, void*, int rc)
{ {
if (rc != 0) if (rc != 0)
{ {
cerr << "*** WARNING: MQTT disconnected unexpectedly (rc=" << rc geulog::warn("mqtt", "MQTT disconnected unexpectedly (rc=", rc,
<< "), will reconnect" << endl; "), will reconnect");
} }
} }
@@ -49,7 +50,7 @@ bool MqttPublisher::initialize(void)
// Read required config values // Read required config values
if (!m_cfg.getValue("MQTT", "HOST", m_host) || m_host.empty()) if (!m_cfg.getValue("MQTT", "HOST", m_host) || m_host.empty())
{ {
cerr << "*** ERROR: MQTT/HOST not configured" << endl; geulog::error("mqtt", "MQTT/HOST not configured");
return false; return false;
} }
@@ -60,26 +61,26 @@ bool MqttPublisher::initialize(void)
} }
else else
{ {
cerr << "*** ERROR: MQTT/PORT not configured" << endl; geulog::error("mqtt", "MQTT/PORT not configured");
return false; return false;
} }
if (!m_cfg.getValue("MQTT", "USERNAME", m_username) || m_username.empty()) if (!m_cfg.getValue("MQTT", "USERNAME", m_username) || m_username.empty())
{ {
cerr << "*** ERROR: MQTT/USERNAME not configured" << endl; geulog::error("mqtt", "MQTT/USERNAME not configured");
return false; return false;
} }
if (!m_cfg.getValue("MQTT", "PASSWORD", m_password) || m_password.empty()) if (!m_cfg.getValue("MQTT", "PASSWORD", m_password) || m_password.empty())
{ {
cerr << "*** ERROR: MQTT/PASSWORD not configured" << endl; geulog::error("mqtt", "MQTT/PASSWORD not configured");
return false; return false;
} }
if (!m_cfg.getValue("MQTT", "TOPIC_PREFIX", m_topic_prefix) || if (!m_cfg.getValue("MQTT", "TOPIC_PREFIX", m_topic_prefix) ||
m_topic_prefix.empty()) m_topic_prefix.empty())
{ {
cerr << "*** ERROR: MQTT/TOPIC_PREFIX not configured" << endl; geulog::error("mqtt", "MQTT/TOPIC_PREFIX not configured");
return false; return false;
} }
@@ -107,7 +108,7 @@ bool MqttPublisher::initialize(void)
if (!m_cfg.getValue("MQTT", "TLS_CA_CERT", m_tls_ca_cert) || if (!m_cfg.getValue("MQTT", "TLS_CA_CERT", m_tls_ca_cert) ||
m_tls_ca_cert.empty()) m_tls_ca_cert.empty())
{ {
cerr << "*** ERROR: MQTT/TLS_CA_CERT required when TLS_ENABLED=1" << endl; geulog::error("mqtt", "MQTT/TLS_CA_CERT required when TLS_ENABLED=1");
return false; return false;
} }
m_cfg.getValue("MQTT", "TLS_CLIENT_CERT", m_tls_client_cert); m_cfg.getValue("MQTT", "TLS_CLIENT_CERT", m_tls_client_cert);
@@ -120,7 +121,7 @@ bool MqttPublisher::initialize(void)
m_mosq = mosquitto_new(nullptr, true, nullptr); m_mosq = mosquitto_new(nullptr, true, nullptr);
if (m_mosq == nullptr) if (m_mosq == nullptr)
{ {
cerr << "*** ERROR: mosquitto_new() failed" << endl; geulog::error("mqtt", "mosquitto_new() failed");
return false; return false;
} }
@@ -141,8 +142,8 @@ bool MqttPublisher::initialize(void)
client_cert, client_key, nullptr); client_cert, client_key, nullptr);
if (rc != MOSQ_ERR_SUCCESS) if (rc != MOSQ_ERR_SUCCESS)
{ {
cerr << "*** ERROR: MQTT TLS configuration failed: " geulog::error("mqtt", "MQTT TLS configuration failed: ",
<< mosquitto_strerror(rc) << endl; mosquitto_strerror(rc));
return false; return false;
} }
} }
@@ -154,8 +155,8 @@ bool MqttPublisher::initialize(void)
int rc = mosquitto_loop_start(m_mosq); int rc = mosquitto_loop_start(m_mosq);
if (rc != MOSQ_ERR_SUCCESS) if (rc != MOSQ_ERR_SUCCESS)
{ {
cerr << "*** ERROR: mosquitto_loop_start() failed: " geulog::error("mqtt", "mosquitto_loop_start() failed: ",
<< mosquitto_strerror(rc) << endl; mosquitto_strerror(rc));
return false; return false;
} }
@@ -163,13 +164,12 @@ bool MqttPublisher::initialize(void)
rc = mosquitto_connect_async(m_mosq, m_host.c_str(), m_port, 60); rc = mosquitto_connect_async(m_mosq, m_host.c_str(), m_port, 60);
if (rc != MOSQ_ERR_SUCCESS) if (rc != MOSQ_ERR_SUCCESS)
{ {
cerr << "*** WARNING: MQTT initial connect failed: " geulog::warn("mqtt", "MQTT initial connect failed: ",
<< mosquitto_strerror(rc) mosquitto_strerror(rc), " -- will retry in background");
<< " -- will retry in background" << endl;
} }
cout << "MQTT: Publisher initialized, broker=" << m_host << ":" << m_port geulog::info("mqtt", "MQTT: Publisher initialized, broker=", m_host, ":",
<< " topic_prefix=" << m_topic_prefix << endl; m_port, " topic_prefix=", m_topic_prefix);
return true; return true;
} }
@@ -184,7 +184,7 @@ void MqttPublisher::shutdown(void)
mosquitto_destroy(m_mosq); mosquitto_destroy(m_mosq);
m_mosq = nullptr; m_mosq = nullptr;
mosquitto_lib_cleanup(); mosquitto_lib_cleanup();
cout << "MQTT: Publisher shut down" << endl; geulog::info("mqtt", "MQTT: Publisher shut down");
} }
} }
@@ -214,13 +214,17 @@ void MqttPublisher::publish(const std::string& topic_suffix,
if (first || code_changed || cooldown_ok) if (first || code_changed || cooldown_ok)
{ {
cerr << "*** WARNING: MQTT publish failed: topic=" << topic
<< " rc=" << rc << " (" << mosquitto_strerror(rc) << ")";
if (m_pub_err_suppressed > 0) if (m_pub_err_suppressed > 0)
{ {
cerr << " [suppressed " << m_pub_err_suppressed << " prior]"; geulog::warn("mqtt", "MQTT publish failed: topic=", topic,
" rc=", rc, " (", mosquitto_strerror(rc), ")",
" [suppressed ", m_pub_err_suppressed, " prior]");
}
else
{
geulog::warn("mqtt", "MQTT publish failed: topic=", topic,
" rc=", rc, " (", mosquitto_strerror(rc), ")");
} }
cerr << endl;
m_last_pub_err_code = rc; m_last_pub_err_code = rc;
m_last_pub_err_logged = now; m_last_pub_err_logged = now;
m_pub_err_suppressed = 0; m_pub_err_suppressed = 0;
+21 -21
View File
@@ -6,6 +6,7 @@
#include "RedisLiveQueue.h" #include "RedisLiveQueue.h"
#include <iostream> #include <iostream>
#include <ctime> #include <ctime>
#include <Log.h>
namespace { namespace {
@@ -52,15 +53,15 @@ bool RedisStore::connectSync(void) {
m_sync = redisConnectWithTimeout(m_cfg.host.c_str(), m_cfg.port, tv); m_sync = redisConnectWithTimeout(m_cfg.host.c_str(), m_cfg.port, tv);
} }
if (!m_sync || m_sync->err) { if (!m_sync || m_sync->err) {
std::cerr << "*** ERROR: Redis sync connect failed: " geulog::error("redis", "Redis sync connect failed: ",
<< (m_sync ? m_sync->errstr : "alloc failed") << std::endl; (m_sync ? m_sync->errstr : "alloc failed"));
if (m_sync) { redisFree(m_sync); m_sync = nullptr; } if (m_sync) { redisFree(m_sync); m_sync = nullptr; }
return false; return false;
} }
if (!m_cfg.password.empty()) { if (!m_cfg.password.empty()) {
redisReply* r = (redisReply*)redisCommand(m_sync, "AUTH %s", m_cfg.password.c_str()); redisReply* r = (redisReply*)redisCommand(m_sync, "AUTH %s", m_cfg.password.c_str());
if (!r || r->type == REDIS_REPLY_ERROR) { if (!r || r->type == REDIS_REPLY_ERROR) {
std::cerr << "*** ERROR: Redis AUTH failed" << std::endl; geulog::error("redis", "Redis AUTH failed");
if (r) freeReplyObject(r); if (r) freeReplyObject(r);
redisFree(m_sync); m_sync = nullptr; redisFree(m_sync); m_sync = nullptr;
return false; return false;
@@ -70,7 +71,7 @@ bool RedisStore::connectSync(void) {
if (m_cfg.db != 0) { if (m_cfg.db != 0) {
redisReply* r = (redisReply*)redisCommand(m_sync, "SELECT %d", m_cfg.db); redisReply* r = (redisReply*)redisCommand(m_sync, "SELECT %d", m_cfg.db);
if (!r || r->type == REDIS_REPLY_ERROR) { if (!r || r->type == REDIS_REPLY_ERROR) {
std::cerr << "*** ERROR: Redis SELECT failed" << std::endl; geulog::error("redis", "Redis SELECT failed");
if (r) freeReplyObject(r); if (r) freeReplyObject(r);
redisFree(m_sync); m_sync = nullptr; redisFree(m_sync); m_sync = nullptr;
return false; return false;
@@ -95,8 +96,8 @@ bool RedisStore::connect(void) {
m_heartbeat_timer->expired.connect( m_heartbeat_timer->expired.connect(
sigc::mem_fun(*this, &RedisStore::refreshLiveExpire)); sigc::mem_fun(*this, &RedisStore::refreshLiveExpire));
std::cout << "RedisStore: connected sync+async, subscribed to " geulog::info("redis", "RedisStore: connected sync+async, subscribed to ",
<< channelName() << std::endl; channelName());
return true; return true;
} }
@@ -122,7 +123,7 @@ std::string RedisStore::lookupUserKey(const std::string& callsign) {
} }
freeReplyObject(r); freeReplyObject(r);
if (!enabled) { if (!enabled) {
std::cout << "RedisStore: user " << callsign << " disabled" << std::endl; geulog::info("redis", "RedisStore: user ", callsign, " disabled");
return ""; return "";
} }
@@ -130,7 +131,7 @@ std::string RedisStore::lookupUserKey(const std::string& callsign) {
r = (redisReply*)redisCommand(m_sync, "HGET %s password", group_key.c_str()); r = (redisReply*)redisCommand(m_sync, "HGET %s password", group_key.c_str());
if (!r || r->type != REDIS_REPLY_STRING) { if (!r || r->type != REDIS_REPLY_STRING) {
if (r) freeReplyObject(r); if (r) freeReplyObject(r);
std::cout << "*** WARNING: group " << group << " missing password" << std::endl; geulog::warn("redis", "group ", group, " missing password");
return ""; return "";
} }
std::string pw(r->str, r->len); std::string pw(r->str, r->len);
@@ -243,9 +244,9 @@ RedisStore::loadTrunkPeers(void)
// Require host + secret + remote_prefix // Require host + secret + remote_prefix
if (cfg.host.empty() || cfg.secret.empty() || cfg.remote_prefix.empty()) { if (cfg.host.empty() || cfg.secret.empty() || cfg.remote_prefix.empty()) {
std::cerr << "*** WARN: RedisStore: trunk peer " << section geulog::warn("redis", "RedisStore: trunk peer ", section,
<< " missing required fields (host/secret/remote_prefix); " " missing required fields (host/secret/remote_prefix); "
<< "skipping" << std::endl; "skipping");
continue; continue;
} }
out[section] = std::move(cfg); out[section] = std::move(cfg);
@@ -446,8 +447,8 @@ bool RedisStore::connectAsync(void) {
m_async = redisAsyncConnect(m_cfg.host.c_str(), m_cfg.port); m_async = redisAsyncConnect(m_cfg.host.c_str(), m_cfg.port);
} }
if (!m_async || m_async->err) { if (!m_async || m_async->err) {
std::cerr << "*** ERROR: Redis async connect failed: " geulog::error("redis", "Redis async connect failed: ",
<< (m_async ? m_async->errstr : "alloc failed") << std::endl; (m_async ? m_async->errstr : "alloc failed"));
if (m_async) { redisAsyncFree(m_async); m_async = nullptr; } if (m_async) { redisAsyncFree(m_async); m_async = nullptr; }
return false; return false;
} }
@@ -474,9 +475,8 @@ bool RedisStore::connectAsyncWrite(void) {
m_async_write = redisAsyncConnect(m_cfg.host.c_str(), m_cfg.port); m_async_write = redisAsyncConnect(m_cfg.host.c_str(), m_cfg.port);
} }
if (!m_async_write || m_async_write->err) { if (!m_async_write || m_async_write->err) {
std::cerr << "*** ERROR: Redis async-write connect failed: " geulog::error("redis", "Redis async-write connect failed: ",
<< (m_async_write ? m_async_write->errstr : "alloc failed") (m_async_write ? m_async_write->errstr : "alloc failed"));
<< std::endl;
if (m_async_write) { redisAsyncFree(m_async_write); m_async_write = nullptr; } if (m_async_write) { redisAsyncFree(m_async_write); m_async_write = nullptr; }
return false; return false;
} }
@@ -504,7 +504,7 @@ void RedisStore::subscribe(void) {
} }
void RedisStore::onAsyncDisconnect(int /*status*/) { void RedisStore::onAsyncDisconnect(int /*status*/) {
if (m_shutting_down) return; if (m_shutting_down) return;
std::cerr << "*** WARN: Redis async disconnect" << std::endl; geulog::warn("redis", "Redis async disconnect");
// hiredis will free the context after this returns — just null out. // hiredis will free the context after this returns — just null out.
m_async = nullptr; m_async = nullptr;
scheduleReconnect(); scheduleReconnect();
@@ -512,7 +512,7 @@ void RedisStore::onAsyncDisconnect(int /*status*/) {
void RedisStore::onAsyncWriteDisconnect(int /*status*/) { void RedisStore::onAsyncWriteDisconnect(int /*status*/) {
if (m_shutting_down) return; if (m_shutting_down) return;
std::cerr << "*** WARN: Redis async-write disconnect" << std::endl; geulog::warn("redis", "Redis async-write disconnect");
m_async_write = nullptr; m_async_write = nullptr;
scheduleReconnect(); scheduleReconnect();
} }
@@ -540,14 +540,14 @@ void RedisStore::scheduleReconnect(void) {
// Rebuild sync context too — its TCP socket is likely dead. // Rebuild sync context too — its TCP socket is likely dead.
if (m_sync) { redisFree(m_sync); m_sync = nullptr; } if (m_sync) { redisFree(m_sync); m_sync = nullptr; }
if (!connectSync()) { if (!connectSync()) {
std::cerr << "*** WARN: Redis sync reconnect failed" << std::endl; geulog::warn("redis", "Redis sync reconnect failed");
// async is up but sync isn't — schedule another retry so we fix sync. // async is up but sync isn't — schedule another retry so we fix sync.
m_reconnect_backoff_s = std::min(m_reconnect_backoff_s * 2, 30); m_reconnect_backoff_s = std::min(m_reconnect_backoff_s * 2, 30);
scheduleReconnect(); scheduleReconnect();
return; return;
} }
std::cout << "RedisStore: reconnected, re-subscribing and requesting " geulog::info("redis", "RedisStore: reconnected, re-subscribing and requesting "
"full reload" << std::endl; "full reload");
m_reconnect_backoff_s = 1; m_reconnect_backoff_s = 1;
configChanged.emit("all"); configChanged.emit("all");
}); });
+126 -150
View File
@@ -167,11 +167,10 @@ namespace {
dirname += part + "/"; dirname += part + "/";
if (access(dirname.c_str(), F_OK) != 0) if (access(dirname.c_str(), F_OK) != 0)
{ {
std::cout << "Create directory '" << dirname << "'" << std::endl; geulog::info("core", "Create directory '", dirname, "'");
if (mkdir(dirname.c_str(), 0777) != 0) if (mkdir(dirname.c_str(), 0777) != 0)
{ {
std::cerr << "*** ERROR: Could not create directory '" geulog::error("core", "Could not create directory '", dirname, "'");
<< dirname << "'" << std::endl;
return false; return false;
} }
} }
@@ -268,8 +267,7 @@ Reflector::Reflector(void)
{ {
if (!loadServerCertificateFiles()) if (!loadServerCertificateFiles())
{ {
std::cerr << "*** WARNING: Failed to renew server certificate" geulog::warn("core", "Failed to renew server certificate");
<< std::endl;
} }
}); });
m_renew_issue_ca_cert_timer.expired.connect( m_renew_issue_ca_cert_timer.expired.connect(
@@ -277,8 +275,7 @@ Reflector::Reflector(void)
{ {
if (!loadSigningCAFiles()) if (!loadSigningCAFiles())
{ {
std::cerr << "*** WARNING: Failed to renew issuing CA certificate" geulog::warn("core", "Failed to renew issuing CA certificate");
<< std::endl;
} }
}); });
m_sat_cleanup_timer.setEnable(false); m_sat_cleanup_timer.setEnable(false);
@@ -369,8 +366,7 @@ bool Reflector::initialize(Async::Config &cfg)
(err="initialization failure", !m_udp_sock->initOk()) || (err="initialization failure", !m_udp_sock->initOk()) ||
(err="unsupported cipher", !m_udp_sock->setCipher(UdpCipher::NAME))) (err="unsupported cipher", !m_udp_sock->setCipher(UdpCipher::NAME)))
{ {
std::cerr << "*** ERROR: Could not initialize UDP socket due to " geulog::error("core", "Could not initialize UDP socket due to ", err);
<< err << std::endl;
return false; return false;
} }
m_udp_sock->setCipherAADLength(UdpCipher::AADLEN); m_udp_sock->setCipherAADLength(UdpCipher::AADLEN);
@@ -397,8 +393,7 @@ bool Reflector::initialize(Async::Config &cfg)
m_random_qsy_hi = m_random_qsy_lo + random_qsy_range.second-1; m_random_qsy_hi = m_random_qsy_lo + random_qsy_range.second-1;
if ((m_random_qsy_lo < 1) || (m_random_qsy_hi < m_random_qsy_lo)) if ((m_random_qsy_lo < 1) || (m_random_qsy_hi < m_random_qsy_lo))
{ {
cout << "*** WARNING: Illegal RANDOM_QSY_RANGE specified. Ignored." geulog::warn("core", "Illegal RANDOM_QSY_RANGE specified. Ignored.");
<< endl;
m_random_qsy_hi = m_random_qsy_lo = 0; m_random_qsy_hi = m_random_qsy_lo = 0;
} }
m_random_qsy_tg = m_random_qsy_hi; m_random_qsy_tg = m_random_qsy_hi;
@@ -422,9 +417,8 @@ bool Reflector::initialize(Async::Config &cfg)
m_cmd_pty = new Pty(pty_path); m_cmd_pty = new Pty(pty_path);
if ((m_cmd_pty == nullptr) || !m_cmd_pty->open()) if ((m_cmd_pty == nullptr) || !m_cmd_pty->open())
{ {
std::cerr << "*** ERROR: Could not open command PTY '" << pty_path geulog::error("core", "Could not open command PTY '", pty_path,
<< "' as specified in configuration variable " "' as specified in configuration variable GLOBAL/COMMAND_PTY");
"GLOBAL/COMMAND_PTY" << std::endl;
return false; return false;
} }
m_cmd_pty->setLineBuffered(true); m_cmd_pty->setLineBuffered(true);
@@ -458,16 +452,16 @@ bool Reflector::initialize(Async::Config &cfg)
m_redis = new RedisStore(rcfg); m_redis = new RedisStore(rcfg);
if (!m_redis->connect()) { if (!m_redis->connect()) {
std::cerr << "*** ERROR: [REDIS] is configured but Redis is unreachable. " geulog::error("redis", "[REDIS] is configured but Redis is unreachable. "
<< "Aborting startup." << std::endl; "Aborting startup.");
return false; return false;
} }
auto warn_if_nonempty = [this](const char* section) { auto warn_if_nonempty = [this](const char* section) {
std::list<std::string> keys = m_cfg->listSection(section); std::list<std::string> keys = m_cfg->listSection(section);
if (!keys.empty()) { if (!keys.empty()) {
std::cerr << "WARN: [" << section << "] in svxreflector.conf is " geulog::warn("redis", "[", section, "] in svxreflector.conf is "
"ignored because [REDIS] is configured. " "ignored because [REDIS] is configured. "
<< "Run --import-conf-to-redis to migrate." << std::endl; "Run --import-conf-to-redis to migrate.");
} }
}; };
warn_if_nonempty("USERS"); warn_if_nonempty("USERS");
@@ -492,7 +486,7 @@ bool Reflector::initialize(Async::Config &cfg)
m_mqtt = new MqttPublisher(cfg); m_mqtt = new MqttPublisher(cfg);
if (!m_mqtt->initialize()) if (!m_mqtt->initialize())
{ {
cerr << "*** WARNING: MQTT publisher failed to initialize, continuing without MQTT" << endl; geulog::warn("mqtt", "MQTT publisher failed to initialize, continuing without MQTT");
delete m_mqtt; delete m_mqtt;
m_mqtt = nullptr; m_mqtt = nullptr;
} }
@@ -522,8 +516,7 @@ bool Reflector::initialize(Async::Config &cfg)
m_satellite_client = new SatelliteClient(this, cfg); m_satellite_client = new SatelliteClient(this, cfg);
if (!m_satellite_client->initialize()) if (!m_satellite_client->initialize())
{ {
std::cerr << "*** ERROR: Failed to initialize satellite connection" geulog::error("core", "Failed to initialize satellite connection");
<< std::endl;
return false; return false;
} }
// Satellites don't participate in the trunk mesh // Satellites don't participate in the trunk mesh
@@ -539,7 +532,7 @@ bool Reflector::initialize(Async::Config &cfg)
|| trunk_debug_str == "yes"); || trunk_debug_str == "yes");
if (m_trunk_debug) if (m_trunk_debug)
{ {
std::cout << "Trunk debug logging enabled" << std::endl; geulog::info("core", "Trunk debug logging enabled");
} }
} }
@@ -714,8 +707,7 @@ bool Reflector::signClientCert(Async::SslX509& cert, const std::string& ca_op)
auto cn = cert.commonName(); auto cn = cert.commonName();
if (!cert.sign(m_issue_ca_pkey)) if (!cert.sign(m_issue_ca_pkey))
{ {
std::cerr << "*** ERROR: Certificate signing failed for client " geulog::error("core", "Certificate signing failed for client ", cn);
<< cn << std::endl;
return false; return false;
} }
auto crtfile = m_certs_dir + "/" + cn + ".crt"; auto crtfile = m_certs_dir + "/" + cn + ".crt";
@@ -728,8 +720,8 @@ bool Reflector::signClientCert(Async::SslX509& cert, const std::string& ca_op)
} }
else else
{ {
std::cerr << "*** WARNING: Failed to write client certificate file '" geulog::warn("core", "Failed to write client certificate file '",
<< crtfile << "'" << std::endl; crtfile, "'");
} }
return true; return true;
} /* Reflector::signClientCert */ } /* Reflector::signClientCert */
@@ -744,8 +736,7 @@ Async::SslX509 Reflector::signClientCsr(const std::string& cn)
auto req = loadClientPendingCsr(cn); auto req = loadClientPendingCsr(cn);
if (req.isNull()) if (req.isNull())
{ {
std::cerr << "*** ERROR: Cannot find CSR to sign '" << req.filePath() geulog::error("core", "Cannot find CSR to sign '", req.filePath(), "'");
<< "'" << std::endl;
return cert; return cert;
} }
@@ -773,9 +764,8 @@ Async::SslX509 Reflector::signClientCsr(const std::string& cn)
if (rename(req.filePath().c_str(), csr_path.c_str()) != 0) if (rename(req.filePath().c_str(), csr_path.c_str()) != 0)
{ {
auto errstr = SvxLink::strError(errno); auto errstr = SvxLink::strError(errno);
std::cerr << "*** WARNING: Failed to move signed CSR from '" geulog::warn("core", "Failed to move signed CSR from '",
<< req.filePath() << "' to '" << csr_path << "': " req.filePath(), "' to '", csr_path, "': ", errstr);
<< errstr << std::endl;
} }
auto client = ReflectorClient::lookup(cn); auto client = ReflectorClient::lookup(cn);
@@ -1967,10 +1957,9 @@ void Reflector::ctrlPtyDataReceived(const void *buf, size_t count)
m_cmd_pty->write("---------- Signed Client Certificate ----------\n"); m_cmd_pty->write("---------- Signed Client Certificate ----------\n");
m_cmd_pty->write(cert.toString()); m_cmd_pty->write(cert.toString());
m_cmd_pty->write("-----------------------------------------------\n"); m_cmd_pty->write("-----------------------------------------------\n");
std::cout << "---------- Signed Client Certificate ----------\n" geulog::info("core", "---------- Signed Client Certificate ----------");
<< cert.toString() geulog::info("core", cert.toString());
<< "-----------------------------------------------" geulog::info("core", "-----------------------------------------------");
<< std::endl;
} }
else else
{ {
@@ -1990,7 +1979,7 @@ void Reflector::ctrlPtyDataReceived(const void *buf, size_t count)
{ {
std::string msg(cn + ": Removed client certificate and CSR"); std::string msg(cn + ": Removed client certificate and CSR");
m_cmd_pty->write(msg + "\n"); m_cmd_pty->write(msg + "\n");
std::cout << msg << std::endl; geulog::info("core", msg);
} }
else else
{ {
@@ -2261,9 +2250,9 @@ void Reflector::initTrunkLinks(void)
if (s.size() >= 6 && s.substr(0, 6) == "TRUNK_") { conf_has_trunk = true; break; } if (s.size() >= 6 && s.substr(0, 6) == "TRUNK_") { conf_has_trunk = true; break; }
} }
if (conf_has_trunk) { if (conf_has_trunk) {
std::cerr << "WARN: [TRUNK_*] sections in svxreflector.conf are " geulog::warn("core", "[TRUNK_*] sections in svxreflector.conf are "
"ignored because [REDIS] is configured. Run " "ignored because [REDIS] is configured. Run "
"--import-conf-to-redis to migrate." << std::endl; "--import-conf-to-redis to migrate.");
} }
auto peers = m_redis->loadTrunkPeers(); auto peers = m_redis->loadTrunkPeers();
@@ -2316,8 +2305,8 @@ void Reflector::initTrunkLinks(void)
} }
else else
{ {
std::cerr << "*** ERROR: Failed to initialize trunk link '" geulog::error("core", "Failed to initialize trunk link '",
<< section << "'" << std::endl; section, "'");
delete link; delete link;
} }
} }
@@ -2331,10 +2320,9 @@ void Reflector::initTrunkLinks(void)
if (s.size() >= prefix.size() && if (s.size() >= prefix.size() &&
s.compare(0, prefix.size(), prefix) == 0) s.compare(0, prefix.size(), prefix) == 0)
{ {
std::cerr << "*** WARNING: Cluster TG " << tg geulog::warn("core", "Cluster TG ", tg, " conflicts with prefix ",
<< " conflicts with prefix " << prefix prefix,
<< " — this TG will be routed as cluster (broadcast to all)" " — this TG will be routed as cluster (broadcast to all)");
<< std::endl;
} }
} }
} }
@@ -2357,7 +2345,7 @@ void Reflector::initTrunkServer(void)
m_trunk_srv->clientDisconnected.connect( m_trunk_srv->clientDisconnected.connect(
sigc::mem_fun(*this, &Reflector::trunkClientDisconnected)); sigc::mem_fun(*this, &Reflector::trunkClientDisconnected));
std::cout << "Trunk server listening on port " << trunk_port << std::endl; geulog::info("core", "Trunk server listening on port ", trunk_port);
} /* Reflector::initTrunkServer */ } /* Reflector::initTrunkServer */
@@ -2645,7 +2633,7 @@ void Reflector::initSatelliteServer(void)
m_sat_srv->clientDisconnected.connect( m_sat_srv->clientDisconnected.connect(
sigc::mem_fun(*this, &Reflector::satelliteDisconnected)); sigc::mem_fun(*this, &Reflector::satelliteDisconnected));
std::cout << "Satellite server listening on port " << sat_port << std::endl; geulog::info("core", "Satellite server listening on port ", sat_port);
} /* Reflector::initSatelliteServer */ } /* Reflector::initSatelliteServer */
@@ -3275,15 +3263,15 @@ bool Reflector::loadCertificateFiles(void)
if (!ensureDirectoryExist(m_ca_bundle_file) || if (!ensureDirectoryExist(m_ca_bundle_file) ||
!m_ca_cert.writePemFile(m_ca_bundle_file)) !m_ca_cert.writePemFile(m_ca_bundle_file))
{ {
std::cout << "*** ERROR: Failed to write CA bundle file '" geulog::error("core", "Failed to write CA bundle file '",
<< m_ca_bundle_file << "'" << std::endl; m_ca_bundle_file, "'");
return false; return false;
} }
} }
if (!m_ssl_ctx.setCaCertificateFile(m_ca_bundle_file)) if (!m_ssl_ctx.setCaCertificateFile(m_ca_bundle_file))
{ {
std::cout << "*** ERROR: Failed to read CA certificate bundle '" geulog::error("core", "Failed to read CA certificate bundle '",
<< m_ca_bundle_file << "'" << std::endl; m_ca_bundle_file, "'");
return false; return false;
} }
@@ -3291,8 +3279,8 @@ bool Reflector::loadCertificateFiles(void)
if (stat(m_ca_bundle_file.c_str(), &st) != 0) if (stat(m_ca_bundle_file.c_str(), &st) != 0)
{ {
auto errstr = SvxLink::strError(errno); auto errstr = SvxLink::strError(errno);
std::cerr << "*** ERROR: Failed to read CA file from '" geulog::error("core", "Failed to read CA file from '",
<< m_ca_bundle_file << "': " << errstr << std::endl; m_ca_bundle_file, "': ", errstr);
return false; return false;
} }
auto bundle = caBundlePem(); auto bundle = caBundlePem();
@@ -3300,8 +3288,7 @@ bool Reflector::loadCertificateFiles(void)
Async::Digest ca_dgst; Async::Digest ca_dgst;
if (!ca_dgst.md(m_ca_md, MsgCABundle::MD_ALG, bundle)) if (!ca_dgst.md(m_ca_md, MsgCABundle::MD_ALG, bundle))
{ {
std::cerr << "*** ERROR: CA bundle checksumming failed" geulog::error("core", "CA bundle checksumming failed");
<< std::endl;
return false; return false;
} }
ca_dgst.signInit(MsgCABundle::MD_ALG, m_issue_ca_pkey); ca_dgst.signInit(MsgCABundle::MD_ALG, m_issue_ca_pkey);
@@ -3319,9 +3306,9 @@ bool Reflector::loadServerCertificateFiles(void)
if (!m_cfg->getValue("SERVER_CERT", "COMMON_NAME", cert_cn) || if (!m_cfg->getValue("SERVER_CERT", "COMMON_NAME", cert_cn) ||
cert_cn.empty()) cert_cn.empty())
{ {
std::cerr << "*** ERROR: The 'SERVER_CERT/COMMON_NAME' variable is " geulog::error("core", "The 'SERVER_CERT/COMMON_NAME' variable is "
"unset which is needed for certificate signing request " "unset which is needed for certificate signing request "
"generation." << std::endl; "generation.");
return false; return false;
} }
@@ -3333,8 +3320,8 @@ bool Reflector::loadServerCertificateFiles(void)
Async::SslKeypair pkey; Async::SslKeypair pkey;
if (access(keyfile.c_str(), F_OK) != 0) if (access(keyfile.c_str(), F_OK) != 0)
{ {
std::cout << "Server private key file not found. Generating '" geulog::info("core", "Server private key file not found. Generating '",
<< keyfile << "'" << std::endl; keyfile, "'");
if (!generateKeyFile(pkey, keyfile)) if (!generateKeyFile(pkey, keyfile))
{ {
return false; return false;
@@ -3342,8 +3329,8 @@ bool Reflector::loadServerCertificateFiles(void)
} }
else if (!pkey.readPrivateKeyFile(keyfile)) else if (!pkey.readPrivateKeyFile(keyfile))
{ {
std::cerr << "*** ERROR: Failed to read private key file from '" geulog::error("core", "Failed to read private key file from '",
<< keyfile << "'" << std::endl; keyfile, "'");
return false; return false;
} }
@@ -3359,9 +3346,9 @@ bool Reflector::loadServerCertificateFiles(void)
!cert.verify(m_issue_ca_pkey); !cert.verify(m_issue_ca_pkey);
if (generate_cert) if (generate_cert)
{ {
std::cerr << "*** WARNING: Failed to read server certificate " geulog::warn("core", "Failed to read server certificate from '",
"from '" << m_crtfile << "' or the cert is invalid. " m_crtfile, "' or the cert is invalid. "
"Generating new certificate." << std::endl; "Generating new certificate.");
cert.clear(); cert.clear();
} }
else else
@@ -3374,9 +3361,9 @@ bool Reflector::loadServerCertificateFiles(void)
time_t renew_time = tnow + (days*24*3600 + seconds)*RENEW_AFTER; time_t renew_time = tnow + (days*24*3600 + seconds)*RENEW_AFTER;
if (!cert.timeIsWithinRange(tnow, renew_time)) if (!cert.timeIsWithinRange(tnow, renew_time))
{ {
std::cerr << "Time to renew the server certificate '" << m_crtfile geulog::info("core", "Time to renew the server certificate '",
<< "'. It's valid until " m_crtfile, "'. It's valid until ",
<< cert.notAfterLocaltimeString() << "." << std::endl; cert.notAfterLocaltimeString(), ".");
cert.clear(); cert.clear();
generate_cert = true; generate_cert = true;
} }
@@ -3395,8 +3382,8 @@ bool Reflector::loadServerCertificateFiles(void)
csrfile = m_csrs_dir + "/" + cert_cn + ".csr"; csrfile = m_csrs_dir + "/" + cert_cn + ".csr";
} }
Async::SslCertSigningReq req; Async::SslCertSigningReq req;
std::cout << "Generating server certificate signing request file '" geulog::info("core", "Generating server certificate signing request file '",
<< csrfile << "'" << std::endl; csrfile, "'");
req.setVersion(Async::SslCertSigningReq::VERSION_1); req.setVersion(Async::SslCertSigningReq::VERSION_1);
req.addSubjectName("CN", cert_cn); req.addSubjectName("CN", cert_cn);
Async::SslX509Extensions req_exts; Async::SslX509Extensions req_exts;
@@ -3426,17 +3413,14 @@ bool Reflector::loadServerCertificateFiles(void)
{ {
// FIXME: Read SSL error stack // FIXME: Read SSL error stack
std::cerr << "*** WARNING: Failed to write server certificate " geulog::warn("core", "Failed to write server certificate "
"signing request file to '" << csrfile << "'" "signing request file to '", csrfile, "'");
<< std::endl;
//return false; //return false;
} }
std::cout << "-------- Certificate Signing Request -------" << std::endl; geulog::info("core", "-------- Certificate Signing Request -------");
req.print(); req.print();
std::cout << "--------------------------------------------" << std::endl; geulog::info("core", "--------------------------------------------");
geulog::info("core", "Generating server certificate file '", m_crtfile, "'");
std::cout << "Generating server certificate file '" << m_crtfile << "'"
<< std::endl;
cert.setSerialNumber(); cert.setSerialNumber();
cert.setVersion(Async::SslX509::VERSION_3); cert.setVersion(Async::SslX509::VERSION_3);
cert.setIssuerName(m_issue_ca_cert.subjectName()); cert.setIssuerName(m_issue_ca_cert.subjectName());
@@ -3449,27 +3433,25 @@ bool Reflector::loadServerCertificateFiles(void)
if (!ensureDirectoryExist(m_crtfile) || !cert.writePemFile(m_crtfile) || if (!ensureDirectoryExist(m_crtfile) || !cert.writePemFile(m_crtfile) ||
!m_issue_ca_cert.appendPemFile(m_crtfile)) !m_issue_ca_cert.appendPemFile(m_crtfile))
{ {
std::cout << "*** ERROR: Failed to write server certificate file '" geulog::error("core", "Failed to write server certificate file '",
<< m_crtfile << "'" << std::endl; m_crtfile, "'");
return false; return false;
} }
} }
std::cout << "------------ Server Certificate ------------" << std::endl; geulog::info("core", "------------ Server Certificate ------------");
cert.print(); cert.print();
std::cout << "--------------------------------------------" << std::endl; geulog::info("core", "--------------------------------------------");
if (!m_ssl_ctx.setCertificateFiles(keyfile, m_crtfile)) if (!m_ssl_ctx.setCertificateFiles(keyfile, m_crtfile))
{ {
std::cout << "*** ERROR: Failed to read and verify key ('" geulog::error("core", "Failed to read and verify key ('",
<< keyfile << "') and certificate ('" keyfile, "') and certificate ('", m_crtfile, "') files. "
<< m_crtfile << "') files. " "If key- and cert-file does not match, the certificate "
<< "If key- and cert-file does not match, the certificate "
"is invalid for any other reason, you need " "is invalid for any other reason, you need "
"to remove the cert file in order to trigger the " "to remove the cert file in order to trigger the "
"generation of a new certificate signing request." "generation of a new certificate signing request."
"Then the CSR need to be signed by the CA which creates a " "Then the CSR need to be signed by the CA which creates a "
"valid certificate." "valid certificate.");
<< std::endl;
return false; return false;
} }
@@ -3485,8 +3467,8 @@ bool Reflector::generateKeyFile(Async::SslKeypair& pkey,
pkey.generate(2048); pkey.generate(2048);
if (!ensureDirectoryExist(keyfile) || !pkey.writePrivateKeyFile(keyfile)) if (!ensureDirectoryExist(keyfile) || !pkey.writePrivateKeyFile(keyfile))
{ {
std::cerr << "*** ERROR: Failed to write private key file to '" geulog::error("core", "Failed to write private key file to '",
<< keyfile << "'" << std::endl; keyfile, "'");
return false; return false;
} }
return true; return true;
@@ -3503,25 +3485,25 @@ bool Reflector::loadRootCAFiles(void)
} }
if (access(ca_keyfile.c_str(), F_OK) != 0) if (access(ca_keyfile.c_str(), F_OK) != 0)
{ {
std::cout << "Root CA private key file not found. Generating '" geulog::info("core", "Root CA private key file not found. Generating '",
<< ca_keyfile << "'" << std::endl; ca_keyfile, "'");
if (!m_ca_pkey.generate(4096)) if (!m_ca_pkey.generate(4096))
{ {
std::cout << "*** ERROR: Failed to generate root CA key" << std::endl; geulog::error("core", "Failed to generate root CA key");
return false; return false;
} }
if (!ensureDirectoryExist(ca_keyfile) || if (!ensureDirectoryExist(ca_keyfile) ||
!m_ca_pkey.writePrivateKeyFile(ca_keyfile)) !m_ca_pkey.writePrivateKeyFile(ca_keyfile))
{ {
std::cerr << "*** ERROR: Failed to write root CA private key file to '" geulog::error("core", "Failed to write root CA private key file to '",
<< ca_keyfile << "'" << std::endl; ca_keyfile, "'");
return false; return false;
} }
} }
else if (!m_ca_pkey.readPrivateKeyFile(ca_keyfile)) else if (!m_ca_pkey.readPrivateKeyFile(ca_keyfile))
{ {
std::cerr << "*** ERROR: Failed to read root CA private key file from '" geulog::error("core", "Failed to read root CA private key file from '",
<< ca_keyfile << "'" << std::endl; ca_keyfile, "'");
return false; return false;
} }
@@ -3538,16 +3520,15 @@ bool Reflector::loadRootCAFiles(void)
!m_ca_cert.verify(m_ca_pkey) || !m_ca_cert.verify(m_ca_pkey) ||
!m_ca_cert.timeIsWithinRange()) !m_ca_cert.timeIsWithinRange())
{ {
std::cerr << "*** ERROR: Failed to read root CA certificate file " geulog::error("core", "Failed to read root CA certificate file from '",
"from '" << ca_crtfile << "' or the cert is invalid." ca_crtfile, "' or the cert is invalid.");
<< std::endl;
return false; return false;
} }
} }
if (generate_ca_cert) if (generate_ca_cert)
{ {
std::cout << "Generating root CA certificate file '" << ca_crtfile << "'" geulog::info("core", "Generating root CA certificate file '",
<< std::endl; ca_crtfile, "'");
m_ca_cert.setSerialNumber(); m_ca_cert.setSerialNumber();
m_ca_cert.setVersion(Async::SslX509::VERSION_3); m_ca_cert.setVersion(Async::SslX509::VERSION_3);
@@ -3556,9 +3537,8 @@ bool Reflector::loadRootCAFiles(void)
(void)m_cfg->getValue("ROOT_CA", "COMMON_NAME", value); (void)m_cfg->getValue("ROOT_CA", "COMMON_NAME", value);
if (value.empty()) if (value.empty())
{ {
std::cerr << "*** ERROR: The 'ROOT_CA/COMMON_NAME' variable is " geulog::error("core", "The 'ROOT_CA/COMMON_NAME' variable is "
"unset which is needed for root CA certificate generation." "unset which is needed for root CA certificate generation.");
<< std::endl;
return false; return false;
} }
m_ca_cert.addIssuerName("CN", value); m_ca_cert.addIssuerName("CN", value);
@@ -3599,14 +3579,14 @@ bool Reflector::loadRootCAFiles(void)
m_ca_cert.sign(m_ca_pkey); m_ca_cert.sign(m_ca_pkey);
if (!m_ca_cert.writePemFile(ca_crtfile)) if (!m_ca_cert.writePemFile(ca_crtfile))
{ {
std::cout << "*** ERROR: Failed to write root CA certificate file '" geulog::error("core", "Failed to write root CA certificate file '",
<< ca_crtfile << "'" << std::endl; ca_crtfile, "'");
return false; return false;
} }
} }
std::cout << "----------- Root CA Certificate ------------" << std::endl; geulog::info("core", "----------- Root CA Certificate ------------");
m_ca_cert.print(); m_ca_cert.print();
std::cout << "--------------------------------------------" << std::endl; geulog::info("core", "--------------------------------------------");
return true; return true;
} /* Reflector::loadRootCAFiles */ } /* Reflector::loadRootCAFiles */
@@ -3622,25 +3602,25 @@ bool Reflector::loadSigningCAFiles(void)
} }
if (access(ca_keyfile.c_str(), F_OK) != 0) if (access(ca_keyfile.c_str(), F_OK) != 0)
{ {
std::cout << "Issuing CA private key file not found. Generating '" geulog::info("core", "Issuing CA private key file not found. Generating '",
<< ca_keyfile << "'" << std::endl; ca_keyfile, "'");
if (!m_issue_ca_pkey.generate(2048)) if (!m_issue_ca_pkey.generate(2048))
{ {
std::cout << "*** ERROR: Failed to generate CA key" << std::endl; geulog::error("core", "Failed to generate CA key");
return false; return false;
} }
if (!ensureDirectoryExist(ca_keyfile) || if (!ensureDirectoryExist(ca_keyfile) ||
!m_issue_ca_pkey.writePrivateKeyFile(ca_keyfile)) !m_issue_ca_pkey.writePrivateKeyFile(ca_keyfile))
{ {
std::cerr << "*** ERROR: Failed to write issuing CA private key file " geulog::error("core", "Failed to write issuing CA private key file to '",
"to '" << ca_keyfile << "'" << std::endl; ca_keyfile, "'");
return false; return false;
} }
} }
else if (!m_issue_ca_pkey.readPrivateKeyFile(ca_keyfile)) else if (!m_issue_ca_pkey.readPrivateKeyFile(ca_keyfile))
{ {
std::cerr << "*** ERROR: Failed to read issuing CA private key file " geulog::error("core", "Failed to read issuing CA private key file from '",
"from '" << ca_keyfile << "'" << std::endl; ca_keyfile, "'");
return false; return false;
} }
@@ -3658,9 +3638,9 @@ bool Reflector::loadSigningCAFiles(void)
!m_issue_ca_cert.timeIsWithinRange(); !m_issue_ca_cert.timeIsWithinRange();
if (generate_ca_cert) if (generate_ca_cert)
{ {
std::cerr << "*** WARNING: Failed to read issuing CA certificate " geulog::warn("core", "Failed to read issuing CA certificate from '",
"from '" << ca_crtfile << "' or the cert is invalid. " ca_crtfile, "' or the cert is invalid. "
"Generating new certificate." << std::endl; "Generating new certificate.");
m_issue_ca_cert.clear(); m_issue_ca_cert.clear();
} }
else else
@@ -3671,10 +3651,9 @@ bool Reflector::loadSigningCAFiles(void)
time_t renew_time = tnow + (days*24*3600 + seconds)*RENEW_AFTER; time_t renew_time = tnow + (days*24*3600 + seconds)*RENEW_AFTER;
if (!m_issue_ca_cert.timeIsWithinRange(tnow, renew_time)) if (!m_issue_ca_cert.timeIsWithinRange(tnow, renew_time))
{ {
std::cerr << "Time to renew the issuing CA certificate '" geulog::info("core", "Time to renew the issuing CA certificate '",
<< ca_crtfile << "'. It's valid until " ca_crtfile, "'. It's valid until ",
<< m_issue_ca_cert.notAfterLocaltimeString() << "." m_issue_ca_cert.notAfterLocaltimeString(), ".");
<< std::endl;
m_issue_ca_cert.clear(); m_issue_ca_cert.clear();
generate_ca_cert = true; generate_ca_cert = true;
} }
@@ -3688,8 +3667,8 @@ bool Reflector::loadSigningCAFiles(void)
{ {
ca_csrfile = m_csrs_dir + "/svxreflector_issuing_ca.csr"; ca_csrfile = m_csrs_dir + "/svxreflector_issuing_ca.csr";
} }
std::cout << "Generating issuing CA CSR file '" << ca_csrfile geulog::info("core", "Generating issuing CA CSR file '",
<< "'" << std::endl; ca_csrfile, "'");
Async::SslCertSigningReq csr; Async::SslCertSigningReq csr;
csr.setVersion(Async::SslCertSigningReq::VERSION_1); csr.setVersion(Async::SslCertSigningReq::VERSION_1);
std::string value; std::string value;
@@ -3697,9 +3676,9 @@ bool Reflector::loadSigningCAFiles(void)
(void)m_cfg->getValue("ISSUING_CA", "COMMON_NAME", value); (void)m_cfg->getValue("ISSUING_CA", "COMMON_NAME", value);
if (value.empty()) if (value.empty())
{ {
std::cerr << "*** ERROR: The 'ISSUING_CA/COMMON_NAME' variable is " geulog::error("core", "The 'ISSUING_CA/COMMON_NAME' variable is "
"unset which is needed for issuing CA certificate " "unset which is needed for issuing CA certificate "
"generation." << std::endl; "generation.");
return false; return false;
} }
csr.addSubjectName("CN", value); csr.addSubjectName("CN", value);
@@ -3738,13 +3717,13 @@ bool Reflector::loadSigningCAFiles(void)
//csr.print(); //csr.print();
if (!csr.writePemFile(ca_csrfile)) if (!csr.writePemFile(ca_csrfile))
{ {
std::cout << "*** ERROR: Failed to write issuing CA CSR file '" geulog::error("core", "Failed to write issuing CA CSR file '",
<< ca_csrfile << "'" << std::endl; ca_csrfile, "'");
return false; return false;
} }
std::cout << "Generating issuing CA certificate file '" << ca_crtfile geulog::info("core", "Generating issuing CA certificate file '",
<< "'" << std::endl; ca_crtfile, "'");
m_issue_ca_cert.setSerialNumber(); m_issue_ca_cert.setSerialNumber();
m_issue_ca_cert.setVersion(Async::SslX509::VERSION_3); m_issue_ca_cert.setVersion(Async::SslX509::VERSION_3);
m_issue_ca_cert.setSubjectName(csr.subjectName()); m_issue_ca_cert.setSubjectName(csr.subjectName());
@@ -3755,14 +3734,14 @@ bool Reflector::loadSigningCAFiles(void)
m_issue_ca_cert.sign(m_ca_pkey); m_issue_ca_cert.sign(m_ca_pkey);
if (!m_issue_ca_cert.writePemFile(ca_crtfile)) if (!m_issue_ca_cert.writePemFile(ca_crtfile))
{ {
std::cout << "*** ERROR: Failed to write issuing CA certificate file '" geulog::error("core", "Failed to write issuing CA certificate file '",
<< ca_crtfile << "'" << std::endl; ca_crtfile, "'");
return false; return false;
} }
} }
std::cout << "---------- Issuing CA Certificate ----------" << std::endl; geulog::info("core", "---------- Issuing CA Certificate ----------");
m_issue_ca_cert.print(); m_issue_ca_cert.print();
std::cout << "--------------------------------------------" << std::endl; geulog::info("core", "--------------------------------------------");
startCertRenewTimer(m_issue_ca_cert, m_renew_issue_ca_cert_timer); startCertRenewTimer(m_issue_ca_cert, m_renew_issue_ca_cert_timer);
@@ -3781,11 +3760,10 @@ bool Reflector::onVerifyPeer(TcpConnection *con, bool preverify_ok,
preverify_ok = preverify_ok && !cert.commonName().empty(); preverify_ok = preverify_ok && !cert.commonName().empty();
if (!preverify_ok) if (!preverify_ok)
{ {
std::cout << "*** ERROR: Certificate verification failed for client" geulog::error("client", "Certificate verification failed for client");
<< std::endl; geulog::info("client", "------------ Client Certificate -------------");
std::cout << "------------ Client Certificate -------------" << std::endl;
cert.print(); cert.print();
std::cout << "---------------------------------------------" << std::endl; geulog::info("client", "---------------------------------------------");
} }
return preverify_ok; return preverify_ok;
@@ -3827,7 +3805,7 @@ bool Reflector::removeClientCertFiles(const std::string& cn)
{ {
if (!isCallsignPathSafe(cn)) if (!isCallsignPathSafe(cn))
{ {
std::cerr << "*** ERROR: Unsafe callsign in removeClientCertFiles" << std::endl; geulog::error("core", "Unsafe callsign in removeClientCertFiles");
return false; return false;
} }
@@ -3849,8 +3827,7 @@ bool Reflector::removeClientCertFiles(const std::string& cn)
{ {
success = false; success = false;
auto errstr = SvxLink::strError(errno); auto errstr = SvxLink::strError(errno);
std::cerr << "*** WARNING: Failed to remove file '" << path << "': " geulog::warn("core", "Failed to remove file '", path, "': ", errstr);
<< errstr << std::endl;
} }
} }
@@ -3867,14 +3844,14 @@ void Reflector::runCAHook(const Async::Exec::Environment& env)
ca_hook->addEnvironmentVars(env); ca_hook->addEnvironmentVars(env);
ca_hook->setTimeout(300); // Five minutes timeout ca_hook->setTimeout(300); // Five minutes timeout
ca_hook->stdoutData.connect( ca_hook->stdoutData.connect(
[=](const char* buf, int cnt) [=](const char* buf, int /*cnt*/)
{ {
std::cout << buf; geulog::info("core", buf);
}); });
ca_hook->stderrData.connect( ca_hook->stderrData.connect(
[=](const char* buf, int cnt) [=](const char* buf, int /*cnt*/)
{ {
std::cerr << buf; geulog::warn("core", buf);
}); });
ca_hook->exited.connect( ca_hook->exited.connect(
[=](void) { [=](void) {
@@ -3882,14 +3859,14 @@ void Reflector::runCAHook(const Async::Exec::Environment& env)
{ {
if (ca_hook->exitStatus() != 0) if (ca_hook->exitStatus() != 0)
{ {
std::cerr << "*** ERROR: CA hook exited with exit status " geulog::error("core", "CA hook exited with exit status ",
<< ca_hook->exitStatus() << std::endl; ca_hook->exitStatus());
} }
} }
else if (ca_hook->ifSignaled()) else if (ca_hook->ifSignaled())
{ {
std::cerr << "*** ERROR: CA hook exited with signal " geulog::error("core", "CA hook exited with signal ",
<< ca_hook->termSig() << std::endl; ca_hook->termSig());
} }
Async::Application::app().runTask([=]{ delete ca_hook; }); Async::Application::app().runTask([=]{ delete ca_hook; });
}); });
@@ -4143,8 +4120,7 @@ void Reflector::initTwinServer(void)
m_twin_srv->clientDisconnected.connect( m_twin_srv->clientDisconnected.connect(
sigc::mem_fun(*this, &Reflector::twinClientDisconnected)); sigc::mem_fun(*this, &Reflector::twinClientDisconnected));
std::cout << "TWIN: server listening on port " << m_twin_listen_port geulog::info("twin", "TWIN: server listening on port ", m_twin_listen_port);
<< std::endl;
} /* Reflector::initTwinServer */ } /* Reflector::initTwinServer */
+39 -50
View File
@@ -411,9 +411,8 @@ void ReflectorClient::onSslConnectionReady(TcpConnection *con)
if (m_con_state != STATE_EXPECT_SSL_CON_READY) if (m_con_state != STATE_EXPECT_SSL_CON_READY)
{ {
std::cout << "*** ERROR[" << m_con->remoteHost() << ":" geulog::error("client", "[", m_con->remoteHost(), ":", m_con->remotePort(),
<< m_con->remotePort() "] SSL connection ready event unexpected");
<< "]: SSL connection ready event unexpected" << std::endl;
disconnect(); disconnect();
return; return;
} }
@@ -423,9 +422,9 @@ void ReflectorClient::onSslConnectionReady(TcpConnection *con)
Async::SslX509 peer_cert(con->sslPeerCertificate()); Async::SslX509 peer_cert(con->sslPeerCertificate());
if (peer_cert.isNull()) if (peer_cert.isNull())
{ {
std::cout << m_con->remoteHost() << ":" << m_con->remotePort() geulog::info("client", m_con->remoteHost(), ":", m_con->remotePort(),
<< ": No client certificate. Requesting Certificate " ": No client certificate. Requesting Certificate "
"Signing Request from client." << std::endl; "Signing Request from client.");
sendMsg(MsgClientCsrRequest()); sendMsg(MsgClientCsrRequest());
m_con_state = STATE_EXPECT_CSR; m_con_state = STATE_EXPECT_CSR;
return; return;
@@ -442,17 +441,15 @@ void ReflectorClient::onSslConnectionReady(TcpConnection *con)
//return; //return;
} }
std::cout << "------------- Client Certificate --------------" << std::endl; geulog::info("client", "------------- Client Certificate --------------");
peer_cert.print(); peer_cert.print();
std::cout << "-----------------------------------------------" << std::endl; geulog::info("client", "-----------------------------------------------");
std::string callsign = peer_cert.commonName(); std::string callsign = peer_cert.commonName();
if (!m_reflector->callsignOk(callsign)) if (!m_reflector->callsignOk(callsign))
{ {
std::cout << "*** WARNING[" << m_con->remoteHost() << ":" geulog::warn("client", "[", m_con->remoteHost(), ":", m_con->remotePort(),
<< m_con->remotePort() "] client certificate has invalid CN (callsign)");
<< "]: client certificate has invalid CN (callsign)"
<< std::endl;
disconnect(); disconnect();
return; return;
} }
@@ -471,7 +468,7 @@ void ReflectorClient::onSslConnectionReady(TcpConnection *con)
m_renew_cert_timer.setTimeout(renew_time); m_renew_cert_timer.setTimeout(renew_time);
m_renew_cert_timer.start(); m_renew_cert_timer.start();
std::cout << callsign << ": " << peer_cert.subjectNameString() << std::endl; geulog::info("client", callsign, ": ", peer_cert.subjectNameString());
connectionAuthenticated(callsign); connectionAuthenticated(callsign);
} /* ReflectorClient::onSslConnectionReady */ } /* ReflectorClient::onSslConnectionReady */
@@ -662,9 +659,8 @@ void ReflectorClient::handleMsgCABundleRequest(std::istream& is)
if (m_con_state != STATE_EXPECT_START_ENCRYPTION) if (m_con_state != STATE_EXPECT_START_ENCRYPTION)
{ {
std::cout << "*** ERROR[" << m_con->remoteHost() << ":" geulog::error("client", "[", m_con->remoteHost(), ":", m_con->remotePort(),
<< m_con->remotePort() << "]: Unexpected MsgCABundleRequest" "] Unexpected MsgCABundleRequest");
<< std::endl;
disconnect(); disconnect();
return; return;
} }
@@ -683,9 +679,8 @@ void ReflectorClient::handleMsgStartEncryptionRequest(std::istream& is)
if (m_con_state != STATE_EXPECT_START_ENCRYPTION) if (m_con_state != STATE_EXPECT_START_ENCRYPTION)
{ {
std::cout << "*** ERROR[" << m_con->remoteHost() << ":" geulog::error("client", "[", m_con->remoteHost(), ":", m_con->remotePort(),
<< m_con->remotePort() "] Unexpected MsgStartEncryptionRequest");
<< "]: Unexpected MsgStartEncryptionRequest" << std::endl;
disconnect(); disconnect();
return; return;
} }
@@ -693,15 +688,14 @@ void ReflectorClient::handleMsgStartEncryptionRequest(std::istream& is)
MsgStartEncryptionRequest msg; MsgStartEncryptionRequest msg;
if (!msg.unpack(is)) if (!msg.unpack(is))
{ {
std::cerr << "*** ERROR[" << m_con->remoteHost() << ":" geulog::error("client", "[", m_con->remoteHost(), ":", m_con->remotePort(),
<< m_con->remotePort() "] Could not unpack MsgStartEncryptionRequest");
<< "]: Could not unpack MsgStartEncryptionRequest" << std::endl;
disconnect(); disconnect();
return; return;
} }
std::cout << m_con->remoteHost() << ":" << m_con->remotePort() geulog::info("client", m_con->remoteHost(), ":", m_con->remotePort(),
<< ": Starting encryption" << std::endl; ": Starting encryption");
m_con->setMaxRxFrameSize(ReflectorMsg::MAX_SSL_SETUP_FRAME_SIZE); m_con->setMaxRxFrameSize(ReflectorMsg::MAX_SSL_SETUP_FRAME_SIZE);
sendMsg(MsgStartEncryption()); sendMsg(MsgStartEncryption());
@@ -714,9 +708,8 @@ void ReflectorClient::handleMsgAuthResponse(std::istream& is)
{ {
if (m_con_state != STATE_EXPECT_AUTH_RESPONSE) if (m_con_state != STATE_EXPECT_AUTH_RESPONSE)
{ {
std::cerr << "*** ERROR[" << m_con->remoteHost() << ":" geulog::error("client", "[", m_con->remoteHost(), ":", m_con->remotePort(),
<< m_con->remotePort() "] Authentication response unexpected");
<< "]: Authentication response unexpected" << std::endl;
sendError("Authentication response unexpected"); sendError("Authentication response unexpected");
return; return;
} }
@@ -724,20 +717,17 @@ void ReflectorClient::handleMsgAuthResponse(std::istream& is)
MsgAuthResponse msg; MsgAuthResponse msg;
if (!msg.unpack(is)) if (!msg.unpack(is))
{ {
std::cerr << "*** ERROR[" << m_con->remoteHost() << ":" geulog::error("client", "[", m_con->remoteHost(), ":", m_con->remotePort(),
<< m_con->remotePort() "] Could not unpack MsgAuthResponse");
<< "]: Could not unpack MsgAuthResponse" << std::endl;
sendError("Illegal MsgAuthResponse protocol message received"); sendError("Illegal MsgAuthResponse protocol message received");
return; return;
} }
if (!m_reflector->callsignOk(msg.callsign())) if (!m_reflector->callsignOk(msg.callsign()))
{ {
std::cerr << "*** ERROR[" << m_con->remoteHost() << ":" geulog::error("client", "[", m_con->remoteHost(), ":", m_con->remotePort(),
<< m_con->remotePort() "] Invalid node callsign '", msg.callsign(),
<< "]: Invalid node callsign '" << msg.callsign() "' in MsgAuthResponse");
<< "' in MsgAuthResponse"
<< std::endl;
sendError("Invalid callsign"); sendError("Invalid callsign");
return; return;
} }
@@ -764,14 +754,13 @@ void ReflectorClient::handleMsgAuthResponse(std::istream& is)
string auth_key = lookupUserKey(msg.callsign()); string auth_key = lookupUserKey(msg.callsign());
if (!auth_key.empty() && msg.verify(auth_key, m_auth_challenge)) if (!auth_key.empty() && msg.verify(auth_key, m_auth_challenge))
{ {
std::cout << msg.callsign() << ": Received valid auth key" << std::endl; geulog::info("client", msg.callsign(), ": Received valid auth key");
connectionAuthenticated(msg.callsign()); connectionAuthenticated(msg.callsign());
} }
else else
{ {
std::cerr << "*** ERROR[" << m_con->remoteHost() << ":" geulog::error("client", "[", m_con->remoteHost(), ":", m_con->remotePort(),
<< m_con->remotePort() << "]: Authentication failed for user '" "] Authentication failed for user '", msg.callsign(), "'");
<< msg.callsign() << "'" << std::endl;
sendError("Access denied"); sendError("Access denied");
} }
} /* ReflectorClient::handleMsgAuthResponse */ } /* ReflectorClient::handleMsgAuthResponse */
@@ -791,8 +780,8 @@ void ReflectorClient::handleMsgClientCsr(std::istream& is)
if ((m_con_state != STATE_CONNECTED) && (m_con_state != STATE_EXPECT_CSR)) if ((m_con_state != STATE_CONNECTED) && (m_con_state != STATE_EXPECT_CSR))
{ {
std::cerr << "*** ERROR[" << idss.str() geulog::error("client", "[", idss.str(),
<< "]: Certificate Signing Request unexpected" << std::endl; "] Certificate Signing Request unexpected");
sendError("Certificate Signing Request unexpected"); sendError("Certificate Signing Request unexpected");
return; return;
} }
@@ -800,19 +789,19 @@ void ReflectorClient::handleMsgClientCsr(std::istream& is)
MsgClientCsr msg; MsgClientCsr msg;
if (!msg.unpack(is)) if (!msg.unpack(is))
{ {
std::cout << "*** ERROR[" << idss.str() geulog::error("client", "[", idss.str(),
<< "]: Could not unpack MsgClientCsr" << std::endl; "] Could not unpack MsgClientCsr");
sendError("Illegal MsgClientCsr protocol message received"); sendError("Illegal MsgClientCsr protocol message received");
return; return;
} }
std::cerr << idss.str() << ": Received CSR" << std::endl; geulog::info("client", idss.str(), ": Received CSR");
Async::SslCertSigningReq req; Async::SslCertSigningReq req;
if (!req.readPem(msg.csrPem()) || req.isNull()) if (!req.readPem(msg.csrPem()) || req.isNull())
{ {
std::cerr << "*** ERROR[" << idss.str() << "]: Invalid CSR received:\n" geulog::error("client", "[", idss.str(), "] Invalid CSR received:\n",
<< msg.csrPem() << std::endl; msg.csrPem());
sendError("Invalid CSR received"); sendError("Invalid CSR received");
return; return;
} }
@@ -820,7 +809,7 @@ void ReflectorClient::handleMsgClientCsr(std::istream& is)
auto errstr = m_reflector->checkCsr(req); auto errstr = m_reflector->checkCsr(req);
if (!errstr.empty()) if (!errstr.empty())
{ {
std::cerr << "*** ERROR[" << idss.str() << "]: " << errstr << std::endl; geulog::error("client", "[", idss.str(), "] ", errstr);
sendError(errstr); sendError(errstr);
return; return;
} }
@@ -833,14 +822,14 @@ void ReflectorClient::handleMsgClientCsr(std::istream& is)
) && ) &&
sendClientCert(cert)) sendClientCert(cert))
{ {
std::cout << idss.str() << ": Sent certificate to peer" << std::endl; geulog::info("client", idss.str(), ": Sent certificate to peer");
//cert.print(); //cert.print();
m_con_state = STATE_EXPECT_DISCONNECT; m_con_state = STATE_EXPECT_DISCONNECT;
} }
else if (m_con_state == STATE_EXPECT_CSR) else if (m_con_state == STATE_EXPECT_CSR)
{ {
std::cout << idss.str() << ": No valid certificate found matching CSR. " geulog::info("client", idss.str(), ": No valid certificate found matching CSR. "
"Sending authentication challenge." << std::endl; "Sending authentication challenge.");
sendAuthChallenge(); sendAuthChallenge();
m_con_state = STATE_EXPECT_AUTH_RESPONSE; m_con_state = STATE_EXPECT_AUTH_RESPONSE;
} }
+6 -9
View File
@@ -37,6 +37,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <vector> #include <vector>
#include <Log.h>
/**************************************************************************** /****************************************************************************
@@ -373,9 +374,8 @@ class MsgAuthChallenge : public ReflectorMsgBase<10>
if (rc != 1) if (rc != 1)
{ {
unsigned long err = ERR_get_error(); unsigned long err = ERR_get_error();
std::cerr << "*** WARNING: Failed to generate challenge. " geulog::warn("core", "Failed to generate challenge. "
"RAND_bytes failed with error code " << err "RAND_bytes failed with error code ", err);
<< std::endl;
m_challenge.clear(); m_challenge.clear();
} }
} }
@@ -427,8 +427,7 @@ class MsgAuthResponse : public ReflectorMsgBase<11>
{ {
if (!calcHMAC(m_digest, key, challenge)) if (!calcHMAC(m_digest, key, challenge))
{ {
std::cerr << "*** ERROR: Digest calculation failed in MsgAuthResponse" geulog::error("core", "Digest calculation failed in MsgAuthResponse");
<< std::endl;
abort(); abort();
} }
} }
@@ -1440,15 +1439,13 @@ class MsgTrunkHello : public ReflectorMsgBase<115>
int rc = RAND_bytes(&m_nonce.front(), NONCE_LEN); int rc = RAND_bytes(&m_nonce.front(), NONCE_LEN);
if (rc != 1) if (rc != 1)
{ {
std::cerr << "*** WARNING: RAND_bytes failed in MsgTrunkHello" geulog::warn("core", "RAND_bytes failed in MsgTrunkHello");
<< std::endl;
m_nonce.clear(); m_nonce.clear();
return; return;
} }
if (!calcHMAC(m_digest, secret, m_nonce.data(), m_nonce.size())) if (!calcHMAC(m_digest, secret, m_nonce.data(), m_nonce.size()))
{ {
std::cerr << "*** ERROR: HMAC calculation failed in MsgTrunkHello" geulog::error("core", "HMAC calculation failed in MsgTrunkHello");
<< std::endl;
} }
} }
+32 -30
View File
@@ -203,7 +203,7 @@ bool TrunkLink::initialize(void)
std::string host_str; std::string host_str;
if (!m_cfg.getValue(m_section, "HOST", host_str) || host_str.empty()) if (!m_cfg.getValue(m_section, "HOST", host_str) || host_str.empty())
{ {
cerr << "*** ERROR[" << m_section << "]: Missing HOST" << endl; geulog::error("trunk", "[", m_section, "] Missing HOST");
return false; return false;
} }
@@ -220,9 +220,9 @@ bool TrunkLink::initialize(void)
} }
if (m_peer_hosts.size() < 2) if (m_peer_hosts.size() < 2)
{ {
cerr << "*** ERROR[" << m_section geulog::error("trunk", "[", m_section,
<< "]: PAIRED=1 requires HOST to list at least 2 hosts, got '" "] PAIRED=1 requires HOST to list at least 2 hosts, got '",
<< host_str << "'" << endl; host_str, "'");
return false; return false;
} }
} }
@@ -237,7 +237,7 @@ bool TrunkLink::initialize(void)
// SECRET // SECRET
if (!m_cfg.getValue(m_section, "SECRET", m_secret) || m_secret.empty()) if (!m_cfg.getValue(m_section, "SECRET", m_secret) || m_secret.empty())
{ {
cerr << "*** ERROR[" << m_section << "]: Missing SECRET" << endl; geulog::error("trunk", "[", m_section, "] Missing SECRET");
return false; return false;
} }
@@ -247,7 +247,7 @@ bool TrunkLink::initialize(void)
m_local_prefix = splitPrefixes(local_prefix_str); m_local_prefix = splitPrefixes(local_prefix_str);
if (m_local_prefix.empty()) if (m_local_prefix.empty())
{ {
cerr << "*** ERROR: Missing or empty LOCAL_PREFIX in [GLOBAL]" << endl; geulog::error("trunk", "Missing or empty LOCAL_PREFIX in [GLOBAL]");
return false; return false;
} }
@@ -256,13 +256,13 @@ bool TrunkLink::initialize(void)
if (!m_cfg.getValue(m_section, "REMOTE_PREFIX", remote_prefix_str) || if (!m_cfg.getValue(m_section, "REMOTE_PREFIX", remote_prefix_str) ||
remote_prefix_str.empty()) remote_prefix_str.empty())
{ {
cerr << "*** ERROR[" << m_section << "]: Missing REMOTE_PREFIX" << endl; geulog::error("trunk", "[", m_section, "] Missing REMOTE_PREFIX");
return false; return false;
} }
m_remote_prefix = splitPrefixes(remote_prefix_str); m_remote_prefix = splitPrefixes(remote_prefix_str);
if (m_remote_prefix.empty()) if (m_remote_prefix.empty())
{ {
cerr << "*** ERROR[" << m_section << "]: Invalid REMOTE_PREFIX" << endl; geulog::error("trunk", "[", m_section, "] Invalid REMOTE_PREFIX");
return false; return false;
} }
@@ -281,8 +281,8 @@ bool TrunkLink::initialize(void)
{ {
m_blacklist_filter = TgFilter::parse(blacklist_str); m_blacklist_filter = TgFilter::parse(blacklist_str);
if (!m_blacklist_filter.empty()) if (!m_blacklist_filter.empty())
cout << m_section << ": Blacklisted TGs: " geulog::info("trunk", m_section, ": Blacklisted TGs: ",
<< m_blacklist_filter.toString() << endl; m_blacklist_filter.toString());
} }
// ALLOW_TGS — flexible whitelist (empty = allow all) // ALLOW_TGS — flexible whitelist (empty = allow all)
@@ -291,8 +291,8 @@ bool TrunkLink::initialize(void)
{ {
m_allow_filter = TgFilter::parse(allow_str); m_allow_filter = TgFilter::parse(allow_str);
if (!m_allow_filter.empty()) if (!m_allow_filter.empty())
cout << m_section << ": Allowed TGs: " geulog::info("trunk", m_section, ": Allowed TGs: ",
<< m_allow_filter.toString() << endl; m_allow_filter.toString());
} }
// TG_MAP — bidirectional TG remap, syntax "peer:local,peer2:local2" // TG_MAP — bidirectional TG remap, syntax "peer:local,peer2:local2"
@@ -314,25 +314,29 @@ bool TrunkLink::initialize(void)
} }
if (!m_tg_map_in.empty()) if (!m_tg_map_in.empty())
{ {
cout << m_section << ": TG mappings (peer<->local):"; std::ostringstream _tgmap_oss;
_tgmap_oss << m_section << ": TG mappings (peer<->local):";
for (const auto& kv : m_tg_map_in) for (const auto& kv : m_tg_map_in)
cout << " " << kv.first << "<->" << kv.second; _tgmap_oss << " " << kv.first << "<->" << kv.second;
cout << endl; geulog::info("trunk", _tgmap_oss.str());
} }
} }
if (m_paired) if (m_paired)
{ {
cout << m_section << ": PAIRED=1, " << m_peer_hosts.size() {
std::ostringstream _paired_oss;
_paired_oss << m_section << ": PAIRED=1, " << m_peer_hosts.size()
<< " partner hosts:"; << " partner hosts:";
for (const auto& x : m_peer_hosts) cout << " " << x; for (const auto& x : m_peer_hosts) _paired_oss << " " << x;
cout << " port=" << m_peer_port _paired_oss << " port=" << m_peer_port
<< " local_prefix=" << joinPrefixes(m_local_prefix) << " local_prefix=" << joinPrefixes(m_local_prefix)
<< " remote_prefix=" << joinPrefixes(m_remote_prefix) << " remote_prefix=" << joinPrefixes(m_remote_prefix)
<< (m_blacklist_filter.empty() ? "" : " [blacklist]") << (m_blacklist_filter.empty() ? "" : " [blacklist]")
<< (m_allow_filter.empty() ? "" : " [whitelist]") << (m_allow_filter.empty() ? "" : " [whitelist]")
<< (m_tg_map_in.empty() ? "" : " [tg_map]") << (m_tg_map_in.empty() ? "" : " [tg_map]");
<< endl; geulog::info("trunk", _paired_oss.str());
}
// Create one outbound client per host // Create one outbound client per host
m_ob_cons.reserve(m_peer_hosts.size()); m_ob_cons.reserve(m_peer_hosts.size());
@@ -359,20 +363,18 @@ bool TrunkLink::initialize(void)
client->connect(); client->connect();
m_ob_cons.push_back(client); m_ob_cons.push_back(client);
cout << m_section << ": paired outbound #" << i geulog::info("trunk", m_section, ": paired outbound #", i,
<< " connecting to " << m_peer_hosts[i] << ":" << m_peer_port " connecting to ", m_peer_hosts[i], ":", m_peer_port);
<< endl;
} }
return true; return true;
} }
cout << m_section << ": Trunk to " << m_peer_host << ":" << m_peer_port geulog::info("trunk", m_section, ": Trunk to ", m_peer_host, ":", m_peer_port,
<< " local_prefix=" << joinPrefixes(m_local_prefix) " local_prefix=", joinPrefixes(m_local_prefix),
<< " remote_prefix=" << joinPrefixes(m_remote_prefix) " remote_prefix=", joinPrefixes(m_remote_prefix),
<< (m_blacklist_filter.empty() ? "" : " [blacklist]") (m_blacklist_filter.empty() ? "" : " [blacklist]"),
<< (m_allow_filter.empty() ? "" : " [whitelist]") (m_allow_filter.empty() ? "" : " [whitelist]"),
<< (m_tg_map_in.empty() ? "" : " [tg_map]") (m_tg_map_in.empty() ? "" : " [tg_map]"));
<< endl;
m_con.addStaticSRVRecord(0, 0, 0, m_peer_port, m_peer_host); m_con.addStaticSRVRecord(0, 0, 0, m_peer_port, m_peer_host);
m_con.setReconnectMinTime(2000); m_con.setReconnectMinTime(2000);
+6 -6
View File
@@ -122,7 +122,7 @@ bool TwinLink::initialize(void)
if (!m_cfg.getValue(m_peer_id_config, "HOST", m_peer_host) if (!m_cfg.getValue(m_peer_id_config, "HOST", m_peer_host)
|| m_peer_host.empty()) || m_peer_host.empty())
{ {
cerr << "*** ERROR[TWIN]: Missing HOST in [TWIN] section" << endl; geulog::error("twin", "[TWIN] Missing HOST in [TWIN] section");
return false; return false;
} }
@@ -137,7 +137,7 @@ bool TwinLink::initialize(void)
if (!m_cfg.getValue(m_peer_id_config, "SECRET", m_secret) if (!m_cfg.getValue(m_peer_id_config, "SECRET", m_secret)
|| m_secret.empty()) || m_secret.empty())
{ {
cerr << "*** ERROR[TWIN]: Missing SECRET in [TWIN] section" << endl; geulog::error("twin", "[TWIN] Missing SECRET in [TWIN] section");
return false; return false;
} }
@@ -145,13 +145,13 @@ bool TwinLink::initialize(void)
if (!m_cfg.getValue("GLOBAL", "LOCAL_PREFIX", m_local_prefix) if (!m_cfg.getValue("GLOBAL", "LOCAL_PREFIX", m_local_prefix)
|| m_local_prefix.empty()) || m_local_prefix.empty())
{ {
cerr << "*** ERROR[TWIN]: Missing LOCAL_PREFIX in [GLOBAL]" << endl; geulog::error("twin", "[TWIN] Missing LOCAL_PREFIX in [GLOBAL]");
return false; return false;
} }
cout << "TWIN: partner=" << m_peer_host << ":" << m_peer_port geulog::info("twin", "TWIN: partner=", m_peer_host, ":", m_peer_port,
<< " local_prefix=" << m_local_prefix " local_prefix=", m_local_prefix,
<< " priority=" << m_priority << endl; " priority=", m_priority);
m_con.addStaticSRVRecord(0, 0, 0, m_peer_port, m_peer_host); m_con.addStaticSRVRecord(0, 0, 0, m_peer_port, m_peer_host);
m_con.setReconnectMinTime(2000); m_con.setReconnectMinTime(2000);
+45 -53
View File
@@ -172,8 +172,7 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
cfg.getValue("REDIS", "KEY_PREFIX", rcfg.key_prefix); cfg.getValue("REDIS", "KEY_PREFIX", rcfg.key_prefix);
cfg.getValue("REDIS", "UNIX_SOCKET", rcfg.unix_socket); cfg.getValue("REDIS", "UNIX_SOCKET", rcfg.unix_socket);
if (rcfg.host.empty() && rcfg.unix_socket.empty()) { if (rcfg.host.empty() && rcfg.unix_socket.empty()) {
std::cerr << "*** ERROR: --import-conf-to-redis requires [REDIS] in conf" geulog::error("core", "--import-conf-to-redis requires [REDIS] in conf");
<< std::endl;
return false; return false;
} }
@@ -184,8 +183,8 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
? redisConnectWithTimeout(rcfg.host.c_str(), rcfg.port, tv) ? redisConnectWithTimeout(rcfg.host.c_str(), rcfg.port, tv)
: redisConnectUnixWithTimeout(rcfg.unix_socket.c_str(), tv); : redisConnectUnixWithTimeout(rcfg.unix_socket.c_str(), tv);
if (!ctx || ctx->err) { if (!ctx || ctx->err) {
std::cerr << "*** ERROR: import: Redis connect failed: " geulog::error("core", "import: Redis connect failed: ",
<< (ctx ? ctx->errstr : "alloc failed") << std::endl; (ctx ? ctx->errstr : "alloc failed"));
if (ctx) redisFree(ctx); if (ctx) redisFree(ctx);
return false; return false;
} }
@@ -210,8 +209,8 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
if (!cfg.getValue("USERS", cs, group) || group.empty()) continue; if (!cfg.getValue("USERS", cs, group) || group.empty()) continue;
std::string ukey = kf("user:" + cs); std::string ukey = kf("user:" + cs);
if (dry_run) { if (dry_run) {
std::cout << "[dry-run] HSET " << ukey << " group " << group geulog::info("core", "[dry-run] HSET ", ukey, " group ", group,
<< " enabled 1" << std::endl; " enabled 1");
} else { } else {
redisReply* r = (redisReply*)redisCommand(ctx, redisReply* r = (redisReply*)redisCommand(ctx,
"HSET %s group %s enabled 1", ukey.c_str(), group.c_str()); "HSET %s group %s enabled 1", ukey.c_str(), group.c_str());
@@ -225,8 +224,7 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
if (!cfg.getValue("PASSWORDS", g, pw) || pw.empty()) continue; if (!cfg.getValue("PASSWORDS", g, pw) || pw.empty()) continue;
std::string gkey = kf("group:" + g); std::string gkey = kf("group:" + g);
if (dry_run) { if (dry_run) {
std::cout << "[dry-run] HSET " << gkey << " password <REDACTED>" geulog::info("core", "[dry-run] HSET ", gkey, " password <REDACTED>");
<< std::endl;
} else { } else {
redisReply* r = (redisReply*)redisCommand(ctx, redisReply* r = (redisReply*)redisCommand(ctx,
"HSET %s password %s", gkey.c_str(), pw.c_str()); "HSET %s password %s", gkey.c_str(), pw.c_str());
@@ -248,7 +246,7 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
tok.erase(tok.find_last_not_of(" \t") + 1); tok.erase(tok.find_last_not_of(" \t") + 1);
if (tok.empty()) continue; if (tok.empty()) continue;
if (dry_run) { if (dry_run) {
std::cout << "[dry-run] SADD " << ck << " " << tok << std::endl; geulog::info("core", "[dry-run] SADD ", ck, " ", tok);
} else { } else {
redisReply* r = (redisReply*)redisCommand(ctx, "SADD %s %s", redisReply* r = (redisReply*)redisCommand(ctx, "SADD %s %s",
ck.c_str(), tok.c_str()); ck.c_str(), tok.c_str());
@@ -279,9 +277,8 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
auto setField = [&](const char* field, const std::string& value) { auto setField = [&](const char* field, const std::string& value) {
if (value.empty()) return; if (value.empty()) return;
if (dry_run) { if (dry_run) {
std::cout << "[dry-run] HSET " << pk << " " << field geulog::info("core", "[dry-run] HSET ", pk, " ", field, " ",
<< " " << (std::string(field) == "secret" ? "<REDACTED>" : value) (std::string(field) == "secret" ? "<REDACTED>" : value));
<< std::endl;
} else { } else {
redisReply* r = (redisReply*)redisCommand(ctx, "HSET %s %s %s", redisReply* r = (redisReply*)redisCommand(ctx, "HSET %s %s %s",
pk.c_str(), field, value.c_str()); pk.c_str(), field, value.c_str());
@@ -307,7 +304,7 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
tok.erase(tok.find_last_not_of(" \t") + 1); tok.erase(tok.find_last_not_of(" \t") + 1);
if (tok.empty()) continue; if (tok.empty()) continue;
if (dry_run) { if (dry_run) {
std::cout << "[dry-run] SADD " << k << " " << tok << std::endl; geulog::info("core", "[dry-run] SADD ", k, " ", tok);
} else { } else {
redisReply* r = (redisReply*)redisCommand(ctx, "SADD %s %s", redisReply* r = (redisReply*)redisCommand(ctx, "SADD %s %s",
k.c_str(), tok.c_str()); k.c_str(), tok.c_str());
@@ -336,8 +333,7 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
local.erase(0, local.find_first_not_of(" \t")); local.erase(0, local.find_first_not_of(" \t"));
local.erase(local.find_last_not_of(" \t") + 1); local.erase(local.find_last_not_of(" \t") + 1);
if (dry_run) { if (dry_run) {
std::cout << "[dry-run] HSET " << k << " " << peer geulog::info("core", "[dry-run] HSET ", k, " ", peer, " ", local);
<< " " << local << std::endl;
} else { } else {
redisReply* r = (redisReply*)redisCommand(ctx, "HSET %s %s %s", redisReply* r = (redisReply*)redisCommand(ctx, "HSET %s %s %s",
k.c_str(), peer.c_str(), local.c_str()); k.c_str(), peer.c_str(), local.c_str());
@@ -347,9 +343,8 @@ static bool runImportConfToRedis(Async::Config& cfg, bool dry_run)
} }
} }
std::cout << "Imported " << users << " users, " << groups << " groups, " geulog::info("core", "Imported ", users, " users, ", groups, " groups, ",
<< cluster_n << " cluster TGs, " << trunks_n << " trunks." cluster_n, " cluster TGs, ", trunks_n, " trunks.");
<< std::endl;
if (ctx) redisFree(ctx); if (ctx) redisFree(ctx);
return true; return true;
@@ -491,8 +486,7 @@ int main(int argc, const char *argv[])
cfg_filename = string(config); cfg_filename = string(config);
if (!cfg.open(cfg_filename)) if (!cfg.open(cfg_filename))
{ {
cerr << "*** ERROR: Could not open configuration file: " geulog::error("core", "Could not open configuration file: ", config);
<< config << endl;
exit(1); exit(1);
} }
} }
@@ -505,18 +499,19 @@ int main(int argc, const char *argv[])
cfg_filename = SVX_SYSCONF_INSTALL_DIR "/svxreflector.conf"; cfg_filename = SVX_SYSCONF_INSTALL_DIR "/svxreflector.conf";
if (!cfg.open(cfg_filename)) if (!cfg.open(cfg_filename))
{ {
cerr << "*** ERROR: Could not open configuration file";
if (errno != 0)
{ {
cerr << " (" << strerror(errno) << ")"; std::ostringstream _cfg_oss;
} _cfg_oss << "Could not open configuration file";
cerr << ".\n"; if (errno != 0) _cfg_oss << " (" << strerror(errno) << ")";
cerr << "Tried the following paths:\n" _cfg_oss << ".\n"
<< "Tried the following paths:\n"
<< "\t" << home_dir << "/.svxlink/svxreflector.conf\n" << "\t" << home_dir << "/.svxlink/svxreflector.conf\n"
<< "\t" SVX_SYSCONF_INSTALL_DIR "/svxreflector.conf\n" << "\t" SVX_SYSCONF_INSTALL_DIR "/svxreflector.conf\n"
<< "Possible reasons for failure are: None of the files exist,\n" << "Possible reasons for failure are: None of the files exist,\n"
<< "you do not have permission to read the file or there was a\n" << "you do not have permission to read the file or there was a\n"
<< "syntax error in the file.\n"; << "syntax error in the file.";
geulog::error("core", _cfg_oss.str());
}
exit(1); exit(1);
} }
} }
@@ -541,8 +536,8 @@ int main(int argc, const char *argv[])
DIR *dir = opendir(cfg_dir.c_str()); DIR *dir = opendir(cfg_dir.c_str());
if (dir == NULL) if (dir == NULL)
{ {
cerr << "*** ERROR: Could not read from directory spcified by " geulog::error("core", "Could not read from directory specified by "
<< "configuration variable GLOBAL/CFG_DIR=" << cfg_dir << endl; "configuration variable GLOBAL/CFG_DIR=", cfg_dir);
exit(1); exit(1);
} }
@@ -558,16 +553,16 @@ int main(int argc, const char *argv[])
cfg_filename = cfg_dir + "/" + dirent->d_name; cfg_filename = cfg_dir + "/" + dirent->d_name;
if (!cfg.open(cfg_filename)) if (!cfg.open(cfg_filename))
{ {
cerr << "*** ERROR: Could not open configuration file: " geulog::error("core", "Could not open configuration file: ",
<< cfg_filename << endl; cfg_filename);
exit(1); exit(1);
} }
} }
if (closedir(dir) == -1) if (closedir(dir) == -1)
{ {
cerr << "*** ERROR: Error closing directory specified by" geulog::error("core", "Error closing directory specified by "
<< "configuration variable GLOBAL/CFG_DIR=" << cfg_dir << endl; "configuration variable GLOBAL/CFG_DIR=", cfg_dir);
exit(1); exit(1);
} }
} }
@@ -578,20 +573,19 @@ int main(int argc, const char *argv[])
if (!geulog::configure(cfg)) if (!geulog::configure(cfg))
{ {
cerr << "*** ERROR: logging facade configuration failed" << endl; geulog::error("core", "logging facade configuration failed");
exit(1); exit(1);
} }
cout << PROGRAM_NAME " v" SVXREFLECTOR_VERSION geulog::info("core", PROGRAM_NAME " v" SVXREFLECTOR_VERSION
" Copyright (C) 2003-2025 Tobias Blomberg / SM0SVX\n"; " Copyright (C) 2003-2025 Tobias Blomberg / SM0SVX");
cout << "Modified with server-to-server trunk support by IW1GEU.\n\n"; geulog::info("core", "Modified with server-to-server trunk support by IW1GEU.");
cout << PROGRAM_NAME " comes with ABSOLUTELY NO WARRANTY. " geulog::info("core", PROGRAM_NAME " comes with ABSOLUTELY NO WARRANTY. "
"This is free software, and you are\n"; "This is free software, and you are");
cout << "welcome to redistribute it in accordance with the " geulog::info("core", "welcome to redistribute it in accordance with the "
"terms and conditions in the\n"; "terms and conditions in the");
cout << "GNU GPL (General Public License) version 2 or later.\n"; geulog::info("core", "GNU GPL (General Public License) version 2 or later.");
geulog::info("core", "Using configuration file: ", main_cfg_filename);
cout << "\nUsing configuration file: " << main_cfg_filename << endl;
struct termios org_termios = {0}; struct termios org_termios = {0};
if (logfile_name == 0) if (logfile_name == 0)
@@ -615,13 +609,12 @@ int main(int argc, const char *argv[])
Reflector ref; Reflector ref;
if (ref.initialize(cfg)) if (ref.initialize(cfg))
{ {
std::cout << "NOTICE: Initialization done. Starting main application." geulog::info("core", "NOTICE: Initialization done. Starting main application.");
<< std::endl;
app.exec(); app.exec();
} }
else else
{ {
cerr << ":-(" << endl; geulog::error("core", ":-( Initialization failed");
} }
if (stdin_watch != 0) if (stdin_watch != 0)
@@ -722,7 +715,7 @@ static void parse_arguments(int argc, const char **argv)
if (print_version) if (print_version)
{ {
std::cout << SVXREFLECTOR_VERSION << std::endl; geulog::info("core", SVXREFLECTOR_VERSION);
exit(0); exit(0);
} }
} /* parse_arguments */ } /* parse_arguments */
@@ -766,10 +759,10 @@ static void sighup_handler(int signal)
{ {
if (logfile_name == 0) if (logfile_name == 0)
{ {
cout << "Ignoring SIGHUP\n"; geulog::info("core", "Ignoring SIGHUP");
return; return;
} }
std::cout << "SIGHUP received" << std::endl; geulog::info("core", "SIGHUP received");
logwriter.reopenLogfile(); logwriter.reopenLogfile();
} /* sighup_handler */ } /* sighup_handler */
@@ -790,9 +783,8 @@ static void sigterm_handler(int signal)
break; break;
} }
std::cout << "\nNOTICE: " << signame geulog::info("core", "NOTICE: ", signame,
<< " received. Shutting down application..." " received. Shutting down application...");
<< std::endl;
Application::app().quit(); Application::app().quit();
} /* sigterm_handler */ } /* sigterm_handler */