aboutsummaryrefslogtreecommitdiff
path: root/kike.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-08-19 20:54:16 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-08-19 21:00:12 +0200
commit37e1895fd0eee62b12834b18c23e46ea92ce556c (patch)
treec438eaff34a20f229a951953f1c60375670d5f77 /kike.c
parent19ff2715b5733c8d476f97c8d1cd7cd95cbd2d9f (diff)
downloadxK-37e1895fd0eee62b12834b18c23e46ea92ce556c.tar.gz
xK-37e1895fd0eee62b12834b18c23e46ea92ce556c.tar.xz
xK-37e1895fd0eee62b12834b18c23e46ea92ce556c.zip
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().
Diffstat (limited to 'kike.c')
-rw-r--r--kike.c22
1 files 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++;