From dfeb02025dcfc6a75d1ccd9485c058bec466f86e Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Tue, 28 Jul 2026 16:49:56 +0200 Subject: [PATCH] Initialize Store client in bongo-testtool --- src/apps/testtool/testtool.c | 59 +++++++++++++++++++++++---------- src/libs/msgapi/tlsrpt-client.c | 17 ++++++++-- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/apps/testtool/testtool.c b/src/apps/testtool/testtool.c index 4cdbb3b..fb30f00 100644 --- a/src/apps/testtool/testtool.c +++ b/src/apps/testtool/testtool.c @@ -1,12 +1,15 @@ /* This program is free software, licensed under the terms of the GNU GPL. * See the Bongo COPYING file for full details * Copyright (c) 2007 Alex Hudson + * Parts Copyright (C) 2026 Mario Fetka. See COPYING for details. */ #include #include #include #include +#include +#include #include #include #include @@ -60,6 +63,42 @@ LookupMxRecords(const char *domain) XplDnsFreeMxLookup(mx); } +static int +DumpTlsRptEvents(const char *argument) +{ + char *end = NULL; + char *json = NULL; + int64_t day; + int result = 1; + + if (!ConnStartup(DEFAULT_CONNECTION_TIMEOUT)) { + printf(_("ERROR: Unable to initialize networking\n")); + return result; + } + MsgInit(); + if (!NMAPInitialize()) { + printf(_("ERROR: Unable to load the Store credential\n")); + goto done; + } + + errno = 0; + day = strtoimax(argument, &end, 10); + if (errno || end == argument || *end || day < 0 || + day % 86400 != 0 || + !BongoTlsRptNmapEventSnapshot(day, &json)) { + printf(_("ERROR: Unable to read TLSRPT events\n")); + goto done; + } + printf("%s\n", json); + result = 0; + +done: + MemFree(json); + MsgShutdown(); + ConnShutdown(); + return result; +} + int main(int argc, char *argv[]) { int next_arg = 0; @@ -102,28 +141,12 @@ main(int argc, char *argv[]) { } break; case 2: - { - char *end = NULL; - char *json = NULL; - int64_t day; - next_arg++; if (next_arg >= argc) { printf(_("Usage: tlsrpt-events \n")); - exit(1); + return 1; } - errno = 0; - day = strtoimax(argv[next_arg], &end, 10); - if (errno || end == argv[next_arg] || *end || day < 0 || - day % 86400 != 0 || - !BongoTlsRptNmapEventSnapshot(day, &json)) { - printf(_("ERROR: Unable to read TLSRPT events\n")); - exit(1); - } - printf("%s\n", json); - MemFree(json); - break; - } + return DumpTlsRptEvents(argv[next_arg]); default: break; } diff --git a/src/libs/msgapi/tlsrpt-client.c b/src/libs/msgapi/tlsrpt-client.c index f24a6a3..a0370f8 100644 --- a/src/libs/msgapi/tlsrpt-client.c +++ b/src/libs/msgapi/tlsrpt-client.c @@ -46,19 +46,30 @@ OpenSystemStore(void) Connection *connection; char response[CONN_BUFSIZE + 1]; + TraceEventSnapshot("opening 127.0.0.1 NMAP connection"); connection = NMAPConnect("127.0.0.1", NULL); if (!connection) return NULL; + TraceEventSnapshot("NMAP TCP connection established"); if (!ConnSetTimeout(connection, 30)) { ConnFree(connection); return NULL; } - if (!NMAPAuthenticateToStore(connection, response, CONN_BUFSIZE) || - NMAPRunCommandF(connection, response, sizeof(response), - "STORE _system\r\n") != 1000) { + TraceEventSnapshot("NMAP timeout configured"); + if (!NMAPAuthenticateToStore(connection, response, CONN_BUFSIZE)) { + TraceEventSnapshot("NMAP Store authentication failed"); NMAPQuit(connection); ConnFree(connection); return NULL; } + TraceEventSnapshot("NMAP Store authentication complete"); + if (NMAPRunCommandF(connection, response, sizeof(response), + "STORE _system\r\n") != 1000) { + TraceEventSnapshot("NMAP _system selection failed"); + NMAPQuit(connection); + ConnFree(connection); + return NULL; + } + TraceEventSnapshot("NMAP _system selection complete"); return connection; }