From f55160af3f25fff17d3af4dde50a606c2c78f79b Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sat, 9 Nov 2024 23:50:46 +0000 Subject: Make NOTICE alerts about client (dis)connection and authentication events optional. New configuration options added: - alertconnect - alertauthfail - alertauthsuccess - alertunautheddisconnect - alertautheddisconnect --- blabouncer.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'blabouncer.c') diff --git a/blabouncer.c b/blabouncer.c index 75ce966..56c21a0 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -888,16 +888,18 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) { // TODO - Handle the "find a free element" loop not finding a free element debugprint(DEBUG_FULL, "bouncer-client: new connection from %s on socket %d%s\n", remoteip, newfd, opensslfailmsg); - // Alert other clients about the new connection - char alertmsg[MAXDATASIZE]; - if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client connected from %s%s.", ircdstate.ircnick, - remoteip, opensslfailmsg)) { - fprintf(stderr, "Error while preparing new client connection NOTICE!\n"); - debugprint(DEBUG_CRIT, "Error while preparing new client connection NOTICE!\n"); - alertmsg[0] = '\0'; + // Alert other clients about the new connection (if enabled) + if (settings->alertconnect) { + char alertmsg[MAXDATASIZE]; + if (!snprintf(alertmsg, MAXDATASIZE, "NOTICE %s :blabouncer: new client connected from %s%s.", ircdstate.ircnick, + remoteip, opensslfailmsg)) { + fprintf(stderr, "Error while preparing new client connection NOTICE!\n"); + debugprint(DEBUG_CRIT, "Error while preparing new client connection NOTICE!\n"); + alertmsg[0] = '\0'; + } + // "except" 0 since we trust this message + sendtoallclients(clients, alertmsg, 0, settings); } - // "except" 0 since we trust this message - sendtoallclients(clients, alertmsg, 0, settings); debugprint(DEBUG_FULL, "bouncer-client: total client connections: %d\n", numclients(clients)); } // If using client TLS and still pending SSL_accept() then re-try SSL_accept() (it can't be real client data yet) @@ -1224,6 +1226,41 @@ int main(int argc, char *argv[]) { exit(1); } + // Is alerting (NOTICE) upon a new connection enabled? + settings.alertconnect = getconfint("alertconnect", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'alertconnect' from configuration file.\n"); + exit(1); + } + + // Is alerting (NOTICE) upon a failed authentication enabled? + settings.alertauthfail = getconfint("alertauthfail", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'alertauthfail' from configuration file.\n"); + exit(1); + } + + // Is alerting (NOTICE) upon a successful authentication enabled? + settings.alertauthsuccess = getconfint("alertauthsuccess", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'alertauthsuccess' from configuration file.\n"); + exit(1); + } + + // Is alerting (NOTICE) upon unauthenticated client disconnections enabled? + settings.alertunautheddisconnect = getconfint("alertunautheddisconnect", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'alertunautheddisconnect' from configuration file.\n"); + exit(1); + } + + // Is alerting (NOTICE) upon authenticated client disconnections enabled? + settings.alertautheddisconnect = getconfint("alertautheddisconnect", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'alertautheddisconnect' from configuration file.\n"); + exit(1); + } + // How many debug logs should we keep? settings.debugkeep = getconfint("debugkeep", settings.conffile); if (errno == ECONFINT) { -- cgit v1.2.3