Initialize Store client in bongo-testtool
Debian Trixie package bundle / packages (push) Successful in 22m15s
Debian Trixie package bundle / packages (push) Successful in 22m15s
This commit is contained in:
@@ -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 <xpl.h>
|
||||
#include <xpldns.h>
|
||||
#include <msgapi.h>
|
||||
#include <bongotlsrpt.h>
|
||||
#include <connio.h>
|
||||
#include <nmlib.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
@@ -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 <UTC-day>\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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user