summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2024-11-09 23:50:46 +0000
committerLuke Bratch <luke@bratch.co.uk>2024-11-09 23:50:46 +0000
commitf55160af3f25fff17d3af4dde50a606c2c78f79b (patch)
treebc0eb6a581a33d3b81d5b1cf1becf40418c8e9ed /blabouncer.c
parent59addf47eca6a0be54e3b07c4ed2b156a8431376 (diff)
Make NOTICE alerts about client (dis)connection and authentication events optional.
New configuration options added: - alertconnect - alertauthfail - alertauthsuccess - alertunautheddisconnect - alertautheddisconnect
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c55
1 files changed, 46 insertions, 9 deletions
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) {