From 37e1895fd0eee62b12834b18c23e46ea92ce556c Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Tue, 19 Aug 2014 20:54:16 +0200
Subject: kike: better debug messages
I had a wonderful "I'm a fucking idiot" moment when I tried connecting
over SSL/TLS with no certificate at the server.
By the way, ZyklonB crashes with FreeBSD 10's Valgrind and gdb
seemingly loses track of execution while in getaddrinfo().
---
kike.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/kike.c b/kike.c
index 5d0b1e5..2a05ead 100644
--- a/kike.c
+++ b/kike.c
@@ -316,6 +316,7 @@ struct client
char *realname; ///< IRC realname (e-mail)
char *hostname; ///< Hostname shown to the network
+ char *address; ///< Full address including port
unsigned mode; ///< User's mode
char *away_message; ///< Away message
@@ -351,6 +352,7 @@ client_free (struct client *self)
free (self->realname);
free (self->hostname);
+ free (self->address);
free (self->away_message);
flood_detector_free (&self->antiflood);
}
@@ -775,6 +777,10 @@ client_kill (struct client *c, const char *reason)
if (c->ssl)
(void) SSL_shutdown (c->ssl);
xclose (c->socket_fd);
+
+ print_debug ("closed connection to %s (%s)",
+ c->address, reason ? reason : "Reason omitted");
+
c->socket_fd = -1;
client_free (c);
LIST_UNLINK (ctx->clients, c);
@@ -2541,16 +2547,19 @@ start:
static bool
client_initialize_ssl (struct client *c)
{
- // SSL support not enabled
+ const char *error_info = NULL;
if (!c->ctx->ssl_ctx)
- return false;
+ {
+ error_info = "SSL support disabled";
+ goto error_ssl_1;
+ }
c->ssl = SSL_new (c->ctx->ssl_ctx);
if (!c->ssl)
goto error_ssl_1;
-
if (!SSL_set_fd (c->ssl, c->socket_fd))
goto error_ssl_2;
+
SSL_set_accept_state (c->ssl);
return true;
@@ -2560,8 +2569,9 @@ error_ssl_2:
error_ssl_1:
// XXX: these error strings are really nasty; also there could be
// multiple errors on the OpenSSL stack.
- print_debug ("%s: %s: %s", "could not initialize SSL",
- c->hostname, ERR_error_string (ERR_get_error (), NULL));
+ if (!error_info)
+ error_info = ERR_error_string (ERR_get_error (), NULL);
+ print_debug ("could not initialize SSL for %s: %s", c->address, error_info);
return false;
}
@@ -2664,13 +2674,13 @@ on_irc_client_available (const struct pollfd *pfd, void *user_data)
char *address = format_host_port_pair (host, port);
print_debug ("accepted connection from %s", address);
- free (address);
struct client *c = xmalloc (sizeof *c);
client_init (c);
c->ctx = ctx;
c->socket_fd = fd;
c->hostname = xstrdup (host);
+ c->address = address;
c->last_active = time (NULL);
LIST_PREPEND (ctx->clients, c);
ctx->n_clients++;
--
cgit v1.2.3-70-g09d2