hirc

IRC client
Log | Files | Refs

commit edb6bdd6a6a66abc04a1fa33da59e1e15f34c9d5
parent 721b6fa7203c7cdbbbd90b35b161db6287b08336
Author: hhvn <dev@hhvn.uk>
Date:   Fri, 25 Feb 2022 11:33:34 +0000

Don't store tls_config

Diffstat:
Msrc/hirc.h | 1+
Msrc/serv.c | 37++++++++++++++++---------------------
Msrc/struct.h | 2+-
3 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/src/hirc.h b/src/hirc.h @@ -36,6 +36,7 @@ size_t strlcpy(char *dst, const char *src, size_t dsize); /* main.c */ void * emalloc(size_t size); +void * erealloc(void *ptr, size_t size); char * estrdup(const char *str); void * talloc(size_t size); char * tstrdup(const char *str); diff --git a/src/serv.c b/src/serv.c @@ -54,12 +54,9 @@ serv_free(struct Server *server) { free(p->value); } #ifdef TLS - if (server->tls) { + if (server->tls) if (server->tls_ctx) tls_free(server->tls_ctx); - if (server->tls_conf) - tls_config_free(server->tls_conf); - } #endif /* TLS */ free(p); } @@ -110,7 +107,6 @@ serv_create(char *name, char *host, char *port, char *nick, server->tls_verify = tls_verify; server->tls = tls; server->tls_ctx = NULL; - server->tls_conf = NULL; #else if (tls) hist_format(server->history, Activity_error, HIST_SHOW, @@ -196,6 +192,7 @@ serv_remove(struct Server **head, char *name) { void serv_connect(struct Server *server) { + struct tls_config *tls_conf; struct Support *s, *prev; struct addrinfo hints; struct addrinfo *ai; @@ -250,31 +247,28 @@ serv_connect(struct Server *server) { #ifdef TLS if (server->tls) { - if (server->tls_conf) - tls_config_free(server->tls_conf); if (server->tls_ctx) tls_free(server->tls_ctx); - server->tls_conf = NULL; server->tls_ctx = NULL; - if ((server->tls_conf = tls_config_new()) == NULL) { - ui_tls_config_error(server->tls_conf, "tls_config_new()"); - server->tls = 0; + if ((tls_conf = tls_config_new()) == NULL) { + ui_tls_config_error(tls_conf, "tls_config_new()"); + goto fail; } if (!server->tls_verify) { - tls_config_insecure_noverifycert(server->tls_conf); - tls_config_insecure_noverifyname(server->tls_conf); + tls_config_insecure_noverifycert(tls_conf); + tls_config_insecure_noverifyname(tls_conf); } if ((server->tls_ctx = tls_client()) == NULL) { ui_perror("tls_client()"); - server->tls = 0; + goto fail; } - if (tls_configure(server->tls_ctx, server->tls_conf) == -1) { + if (tls_configure(server->tls_ctx, tls_conf) == -1) { ui_tls_error(server->tls_ctx, "tls_configure()"); - server->tls = 0; + goto fail; } if (tls_connect_socket(server->tls_ctx, fd, server->host) == -1) { @@ -284,6 +278,8 @@ serv_connect(struct Server *server) { goto fail; } + tls_config_free(tls_conf); + if (tls_peer_cert_provided(server->tls_ctx)) { hist_format(server->history, Activity_status, HIST_SHOW, "SELF_TLS_VERSION %s %s %s %s", @@ -352,20 +348,19 @@ void serv_disconnect(struct Server *server, int reconnect, char *msg) { struct Channel *chan; struct Support *s, *prev = NULL; + int ret; if (msg) ircprintf(server, "QUIT %s\r\n", msg); #ifdef TLS if (server->tls) { if (server->tls_ctx) { - tls_close(server->tls_ctx); - tls_reset(server->tls_ctx); + do { + ret = tls_close(server->tls_ctx); + } while (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT); tls_free(server->tls_ctx); } - if (server->tls_conf) - tls_config_free(server->tls_conf); server->tls_ctx = NULL; - server->tls_conf = NULL; } else { #endif /* TLS */ shutdown(server->rfd, SHUT_RDWR); diff --git a/src/struct.h b/src/struct.h @@ -157,8 +157,8 @@ struct Server { time_t pingsent; /* last time a ping was sent to server */ #ifdef TLS int tls; + int tls_verify; struct tls *tls_ctx; - struct tls_config *tls_conf; #endif /* TLS */ struct Server *next; };