summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2020-04-12 19:36:12 +0200
committerSébastien Helleu <flashcode@flashtux.org>2020-04-12 19:36:12 +0200
commitb947512c9a59e615f8dc9cf15428a18e135808f9 (patch)
tree4da790d96654894325893459b2fd0a9b4c8b5fc0 /src/plugins
parentfb6fc22c747ae807256b2de7cd7e5c7d5e82ac75 (diff)
downloadweechat-b947512c9a59e615f8dc9cf15428a18e135808f9.zip
relay: add option relay.network.auth_timeout
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/relay/relay-client.c15
-rw-r--r--src/plugins/relay/relay-config.c10
-rw-r--r--src/plugins/relay/relay-config.h1
3 files changed, 25 insertions, 1 deletions
diff --git a/src/plugins/relay/relay-client.c b/src/plugins/relay/relay-client.c
index acc6363d8..d3d157e9e 100644
--- a/src/plugins/relay/relay-client.c
+++ b/src/plugins/relay/relay-client.c
@@ -1209,7 +1209,7 @@ int
relay_client_timer_cb (const void *pointer, void *data, int remaining_calls)
{
struct t_relay_client *ptr_client, *ptr_next_client;
- int purge_delay;
+ int purge_delay, auth_timeout;
time_t current_time;
/* make C compiler happy */
@@ -1218,6 +1218,7 @@ relay_client_timer_cb (const void *pointer, void *data, int remaining_calls)
(void) remaining_calls;
purge_delay = weechat_config_integer (relay_config_network_clients_purge_delay);
+ auth_timeout = weechat_config_integer (relay_config_network_auth_timeout);
current_time = time (NULL);
@@ -1237,7 +1238,19 @@ relay_client_timer_cb (const void *pointer, void *data, int remaining_calls)
}
else if (ptr_client->sock >= 0)
{
+ /* send messages in outqueue */
relay_client_send_outqueue (ptr_client);
+
+ /* disconnect clients not authenticated */
+ if ((auth_timeout > 0)
+ && (ptr_client->status == RELAY_STATUS_WAITING_AUTH))
+ {
+ if (current_time - ptr_client->start_time > auth_timeout)
+ {
+ relay_client_set_status (ptr_client,
+ RELAY_STATUS_AUTH_FAILED);
+ }
+ }
}
ptr_client = ptr_next_client;
diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c
index 6f9e66667..f9c66ce47 100644
--- a/src/plugins/relay/relay-config.c
+++ b/src/plugins/relay/relay-config.c
@@ -60,6 +60,7 @@ struct t_config_option *relay_config_color_text_selected;
struct t_config_option *relay_config_network_allow_empty_password;
struct t_config_option *relay_config_network_allowed_ips;
+struct t_config_option *relay_config_network_auth_timeout;
struct t_config_option *relay_config_network_bind_address;
struct t_config_option *relay_config_network_clients_purge_delay;
struct t_config_option *relay_config_network_compression_level;
@@ -1031,6 +1032,15 @@ relay_config_init ()
NULL, NULL, NULL,
&relay_config_change_network_allowed_ips, NULL, NULL,
NULL, NULL, NULL);
+ relay_config_network_auth_timeout = weechat_config_new_option (
+ relay_config_file, ptr_section,
+ "auth_timeout", "integer",
+ N_("timeout (in seconds) for client authentication: connection is "
+ "closed if the client is still not authenticated after this delay "
+ "and the client status is set to \"authentication failed\" "
+ "(0 = wait forever)"),
+ NULL, 0, INT_MAX, "60", NULL, 0,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
relay_config_network_bind_address = weechat_config_new_option (
relay_config_file, ptr_section,
"bind_address", "string",
diff --git a/src/plugins/relay/relay-config.h b/src/plugins/relay/relay-config.h
index 355c4ab41..35253abb9 100644
--- a/src/plugins/relay/relay-config.h
+++ b/src/plugins/relay/relay-config.h
@@ -39,6 +39,7 @@ extern struct t_config_option *relay_config_color_text_selected;
extern struct t_config_option *relay_config_network_allow_empty_password;
extern struct t_config_option *relay_config_network_allowed_ips;
+extern struct t_config_option *relay_config_network_auth_timeout;
extern struct t_config_option *relay_config_network_bind_address;
extern struct t_config_option *relay_config_network_clients_purge_delay;
extern struct t_config_option *relay_config_network_compression_level;