From 4476fbbad9e66421dbaf4fa9a1a47566d7b0bdc6 Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 12 Oct 2019 15:37:49 -0700 Subject: [PATCH 1/3] Fix indentation --- src/core/servers-reconnect.c | 4 ++-- src/core/servers-setup.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/servers-reconnect.c b/src/core/servers-reconnect.c index 97175f78..dd949ead 100644 --- a/src/core/servers-reconnect.c +++ b/src/core/servers-reconnect.c @@ -181,7 +181,7 @@ server_connect_copy_skeleton(SERVER_CONNECT_REC *src, int connect_info) dest->tag = g_strdup(src->tag); if (connect_info) { - dest->family = src->family; + dest->family = src->family; dest->address = g_strdup(src->address); dest->port = src->port; dest->password = g_strdup(src->password); @@ -293,7 +293,7 @@ static void sig_reconnect(SERVER_REC *server) (!rec->last_connect || !rec->last_failed || rec->last_connect < now-FAILED_RECONNECT_WAIT)) { if (rec == sserver) - conn->port = server->connrec->port; + conn->port = server->connrec->port; sserver_connect(rec, conn); return; } diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c index a505df5b..e1313791 100644 --- a/src/core/servers-setup.c +++ b/src/core/servers-setup.c @@ -159,11 +159,11 @@ static void server_setup_fill_server(SERVER_CONNECT_REC *conn, sserver->last_connect = time(NULL); - if (sserver->no_proxy) + if (sserver->no_proxy) g_free_and_null(conn->proxy); if (sserver->family != 0 && conn->family == 0) - conn->family = sserver->family; + conn->family = sserver->family; if (sserver->port > 0 && conn->port <= 0) conn->port = sserver->port; From 163942521718328110152388203ca7494c3416df Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 12 Oct 2019 15:43:14 -0700 Subject: [PATCH 2/3] Do not copy TLS settings to reconnection record This was causing us to use the TLS settings from one server on another which is not always appropriate. Instead, we now treat it like other connection information and do not copy it. We get the TLS settings later as appropriate when connecting. Note there is still probably more that could be cleaned up here. For example, the unix socket might be better treated as connection info too. Fixes #1027. --- src/core/servers-reconnect.c | 20 +++++++++---------- src/core/servers-setup.c | 38 ++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/core/servers-reconnect.c b/src/core/servers-reconnect.c index dd949ead..2098a6cc 100644 --- a/src/core/servers-reconnect.c +++ b/src/core/servers-reconnect.c @@ -185,6 +185,16 @@ server_connect_copy_skeleton(SERVER_CONNECT_REC *src, int connect_info) dest->address = g_strdup(src->address); dest->port = src->port; dest->password = g_strdup(src->password); + + dest->use_tls = src->use_tls; + dest->tls_cert = g_strdup(src->tls_cert); + dest->tls_pkey = g_strdup(src->tls_pkey); + dest->tls_verify = src->tls_verify; + dest->tls_cafile = g_strdup(src->tls_cafile); + dest->tls_capath = g_strdup(src->tls_capath); + dest->tls_ciphers = g_strdup(src->tls_ciphers); + dest->tls_pinned_cert = g_strdup(src->tls_pinned_cert); + dest->tls_pinned_pubkey = g_strdup(src->tls_pinned_pubkey); } dest->chatnet = g_strdup(src->chatnet); @@ -207,16 +217,6 @@ server_connect_copy_skeleton(SERVER_CONNECT_REC *src, int connect_info) dest->no_autosendcmd = src->no_autosendcmd; dest->unix_socket = src->unix_socket; - dest->use_tls = src->use_tls; - dest->tls_cert = g_strdup(src->tls_cert); - dest->tls_pkey = g_strdup(src->tls_pkey); - dest->tls_verify = src->tls_verify; - dest->tls_cafile = g_strdup(src->tls_cafile); - dest->tls_capath = g_strdup(src->tls_capath); - dest->tls_ciphers = g_strdup(src->tls_ciphers); - dest->tls_pinned_cert = g_strdup(src->tls_pinned_cert); - dest->tls_pinned_pubkey = g_strdup(src->tls_pinned_pubkey); - return dest; } diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c index e1313791..fa68c049 100644 --- a/src/core/servers-setup.c +++ b/src/core/servers-setup.c @@ -108,6 +108,25 @@ void server_setup_fill_reconn(SERVER_CONNECT_REC *conn, if (sserver->password != NULL && conn->password == NULL) conn->password = g_strdup(sserver->password); + conn->use_tls = sserver->use_tls; + if (conn->tls_cert == NULL && sserver->tls_cert != NULL && sserver->tls_cert[0] != '\0') + conn->tls_cert = g_strdup(sserver->tls_cert); + if (conn->tls_pkey == NULL && sserver->tls_pkey != NULL && sserver->tls_pkey[0] != '\0') + conn->tls_pkey = g_strdup(sserver->tls_pkey); + if (conn->tls_pass == NULL && sserver->tls_pass != NULL && sserver->tls_pass[0] != '\0') + conn->tls_pass = g_strdup(sserver->tls_pass); + conn->tls_verify = sserver->tls_verify; + if (conn->tls_cafile == NULL && sserver->tls_cafile != NULL && sserver->tls_cafile[0] != '\0') + conn->tls_cafile = g_strdup(sserver->tls_cafile); + if (conn->tls_capath == NULL && sserver->tls_capath != NULL && sserver->tls_capath[0] != '\0') + conn->tls_capath = g_strdup(sserver->tls_capath); + if (conn->tls_ciphers == NULL && sserver->tls_ciphers != NULL && sserver->tls_ciphers[0] != '\0') + conn->tls_ciphers = g_strdup(sserver->tls_ciphers); + if (conn->tls_pinned_cert == NULL && sserver->tls_pinned_cert != NULL && sserver->tls_pinned_cert[0] != '\0') + conn->tls_pinned_cert = g_strdup(sserver->tls_pinned_cert); + if (conn->tls_pinned_pubkey == NULL && sserver->tls_pinned_pubkey != NULL && sserver->tls_pinned_pubkey[0] != '\0') + conn->tls_pinned_pubkey = g_strdup(sserver->tls_pinned_pubkey); + signal_emit("server setup fill reconn", 2, conn, sserver); } @@ -167,25 +186,6 @@ static void server_setup_fill_server(SERVER_CONNECT_REC *conn, if (sserver->port > 0 && conn->port <= 0) conn->port = sserver->port; - conn->use_tls = sserver->use_tls; - if (conn->tls_cert == NULL && sserver->tls_cert != NULL && sserver->tls_cert[0] != '\0') - conn->tls_cert = g_strdup(sserver->tls_cert); - if (conn->tls_pkey == NULL && sserver->tls_pkey != NULL && sserver->tls_pkey[0] != '\0') - conn->tls_pkey = g_strdup(sserver->tls_pkey); - if (conn->tls_pass == NULL && sserver->tls_pass != NULL && sserver->tls_pass[0] != '\0') - conn->tls_pass = g_strdup(sserver->tls_pass); - conn->tls_verify = sserver->tls_verify; - if (conn->tls_cafile == NULL && sserver->tls_cafile != NULL && sserver->tls_cafile[0] != '\0') - conn->tls_cafile = g_strdup(sserver->tls_cafile); - if (conn->tls_capath == NULL && sserver->tls_capath != NULL && sserver->tls_capath[0] != '\0') - conn->tls_capath = g_strdup(sserver->tls_capath); - if (conn->tls_ciphers == NULL && sserver->tls_ciphers != NULL && sserver->tls_ciphers[0] != '\0') - conn->tls_ciphers = g_strdup(sserver->tls_ciphers); - if (conn->tls_pinned_cert == NULL && sserver->tls_pinned_cert != NULL && sserver->tls_pinned_cert[0] != '\0') - conn->tls_pinned_cert = g_strdup(sserver->tls_pinned_cert); - if (conn->tls_pinned_pubkey == NULL && sserver->tls_pinned_pubkey != NULL && sserver->tls_pinned_pubkey[0] != '\0') - conn->tls_pinned_pubkey = g_strdup(sserver->tls_pinned_pubkey); - server_setup_fill_reconn(conn, sserver); signal_emit("server setup fill server", 2, conn, sserver); From 34effcec01c01775db7c8575a88e1ae2adbd12de Mon Sep 17 00:00:00 2001 From: Will Storey Date: Sat, 12 Oct 2019 15:46:09 -0700 Subject: [PATCH 3/3] Fill more connection information in one spot --- src/core/servers-reconnect.c | 4 ---- src/core/servers-setup.c | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/core/servers-reconnect.c b/src/core/servers-reconnect.c index 2098a6cc..2cbe60b4 100644 --- a/src/core/servers-reconnect.c +++ b/src/core/servers-reconnect.c @@ -151,10 +151,6 @@ static int server_reconnect_timeout(void) static void sserver_connect(SERVER_SETUP_REC *rec, SERVER_CONNECT_REC *conn) { - conn->family = rec->family; - conn->address = g_strdup(rec->address); - if (conn->port == 0) conn->port = rec->port; - server_setup_fill_reconn(conn, rec); server_reconnect_add(conn, rec->last_connect+reconnect_time); server_connect_unref(conn); diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c index fa68c049..8662b30c 100644 --- a/src/core/servers-setup.c +++ b/src/core/servers-setup.c @@ -108,6 +108,16 @@ void server_setup_fill_reconn(SERVER_CONNECT_REC *conn, if (sserver->password != NULL && conn->password == NULL) conn->password = g_strdup(sserver->password); + if (sserver->no_proxy) + g_free_and_null(conn->proxy); + + if (sserver->family != 0 && conn->family == 0) + conn->family = sserver->family; + if (sserver->address && !conn->address) + conn->address = g_strdup(sserver->address); + if (sserver->port > 0 && conn->port <= 0) + conn->port = sserver->port; + conn->use_tls = sserver->use_tls; if (conn->tls_cert == NULL && sserver->tls_cert != NULL && sserver->tls_cert[0] != '\0') conn->tls_cert = g_strdup(sserver->tls_cert); @@ -178,14 +188,6 @@ static void server_setup_fill_server(SERVER_CONNECT_REC *conn, sserver->last_connect = time(NULL); - if (sserver->no_proxy) - g_free_and_null(conn->proxy); - - if (sserver->family != 0 && conn->family == 0) - conn->family = sserver->family; - if (sserver->port > 0 && conn->port <= 0) - conn->port = sserver->port; - server_setup_fill_reconn(conn, sserver); signal_emit("server setup fill server", 2, conn, sserver);