summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 00d339e..64b6f36 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -412,6 +412,7 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
clients[i].pendingcap = 0;
clients[i].clientcode[0] = '\0';
clients[i].remoteip[0] = '\0';
+ clients[i].connecttime = 0;
}
// Struct of various strings from and for the real IRCd (such as the greeting strings, the real IRCd's name,
@@ -502,6 +503,23 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
}
}
+ // Always check for client timeouts (clients who have been unauthed for AUTHTIMEOUT seconds) to stop the clients array getting filled up
+ int disconnected = 0;
+ for (int i = 0; i < MAXCLIENTS; i++) {
+ if (clients[i].fd > 0 && !clients[i].authed) {
+ if (time(NULL) > clients[i].connecttime + AUTHTIMEOUT) {
+ debugprint(DEBUG_SOME, "dochat(): auth timed out for client fd '%d', disconnecting!\n", clients[i].fd);
+ disconnectclient(clients[i].fd, clients, &ircdstate, settings, clientcodes);
+ // We disconnected a client, make a note to continue later...
+ disconnected = 1;
+ }
+ }
+ }
+ // If we disconnected someone, active client fds might have changed, start the loop again
+ if (disconnected) {
+ continue;
+ }
+
debugprint(DEBUG_FULL, "pselect()ing...\n");
// Check to see if any fd in the fd_set is waiting or a signal happened - blocks here until one one of those things happens
// (pselect() to do signal handling in addition to fd monitoring)
@@ -858,6 +876,9 @@ void dochat(int *serversockfd, int *clientsockfd, struct settings *settings) {
// Record the remote IP address of this client in the clients array
strncpy(clients[j].remoteip, remoteip, INET6_ADDRSTRLEN);
+ // Record the connect time
+ clients[j].connecttime = time(NULL);
+
// If using TLS then...
if (settings->clienttls) {
// ...set as OpenSSL FD and SSL_accept it