1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-28 13:56:37 +02:00

irc: rename server option "sasl_disconnect_on_fail" to "sasl_fail", change type to integer (enum)

New possible values are:
- "continue": ignore the SASL failed (continue connection to server
  without authentication)
- "reconnect": disconnect and schedule a reconnection to server
- "disconnect": disconnect
This commit is contained in:
Sébastien Helleu
2014-11-23 10:38:09 +01:00
parent 570beab90a
commit 4f4045fb84
4 changed files with 76 additions and 34 deletions
+7 -4
View File
@@ -1772,12 +1772,15 @@ irc_config_server_new_option (struct t_config_file *config_file,
callback_change, callback_change_data,
NULL, NULL);
break;
case IRC_SERVER_OPTION_SASL_DISCONNECT_ON_FAIL:
case IRC_SERVER_OPTION_SASL_FAIL:
new_option = weechat_config_new_option (
config_file, section,
option_name, "boolean",
N_("disconnect if SASL authentication fails (to prevent hostname leaks)"),
NULL, 0, 0,
option_name, "integer",
N_("action to perform if SASL authentication fails: "
"\"continue\" to ignore the authentication problem, "
"\"reconnect\" to schedule a reconnection to the server, "
"\"disconnect\" to disconnect from server"),
"continue|reconnect|disconnect", 0, 0,
default_value, value,
null_value_allowed,
callback_check_value, callback_check_value_data,
+37 -16
View File
@@ -5076,28 +5076,49 @@ IRC_PROTOCOL_CALLBACK(901)
}
/*
* Callback for the IRC messages "902" to "907".
* Callback for the IRC messages "903" and "907" (SASL OK).
*
* Messages look like:
* :server 903 nick :SASL authentication successful
* :server 904 nick :SASL authentication failed
*/
IRC_PROTOCOL_CALLBACK(sasl_end)
IRC_PROTOCOL_CALLBACK(sasl_end_ok)
{
int sasl_fail;
irc_protocol_cb_numeric (server,
date, nick, address, host, command,
ignored, argc, argv, argv_eol);
if (strcmp (argv[1], "903") != 0 && IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SASL_DISCONNECT_ON_FAIL))
if (!server->is_connected)
irc_server_sendf (server, 0, NULL, "CAP END");
return WEECHAT_RC_OK;
}
/*
* Callback for the IRC messages "902", "904", "905", "906" (SASL failed).
*
* Messages look like:
* :server 904 nick :SASL authentication failed
*/
IRC_PROTOCOL_CALLBACK(sasl_end_fail)
{
int sasl_fail;
irc_protocol_cb_numeric (server,
date, nick, address, host, command,
ignored, argc, argv, argv_eol);
sasl_fail = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SASL_FAIL);
if ((sasl_fail == IRC_SERVER_SASL_FAIL_RECONNECT)
|| (sasl_fail == IRC_SERVER_SASL_FAIL_DISCONNECT))
{
/* Check if we are already connected to the server,
* to prevent disconnects in case of 907.
*/
if (!server->is_connected)
irc_server_disconnect (server, 0, 1);
irc_server_disconnect (
server, 0,
(sasl_fail == IRC_SERVER_SASL_FAIL_RECONNECT) ? 1 : 0);
return WEECHAT_RC_OK;
}
@@ -5375,12 +5396,12 @@ irc_protocol_recv_command (struct t_irc_server *server,
{ "734", /* monitor list is full */ 1, 0, &irc_protocol_cb_734 },
{ "900", /* logged in as (SASL) */ 1, 0, &irc_protocol_cb_900 },
{ "901", /* you are now logged in */ 1, 0, &irc_protocol_cb_901 },
{ "902", /* SASL authentication failed because account is locked or held */ 1, 0, &irc_protocol_cb_sasl_end },
{ "903", /* SASL authentication successful */ 1, 0, &irc_protocol_cb_sasl_end },
{ "904", /* SASL authentication failed */ 1, 0, &irc_protocol_cb_sasl_end },
{ "905", /* SASL message too long */ 1, 0, &irc_protocol_cb_sasl_end },
{ "906", /* SASL authentication aborted */ 1, 0, &irc_protocol_cb_sasl_end },
{ "907", /* You have already completed SASL authentication */ 1, 0, &irc_protocol_cb_sasl_end },
{ "902", /* SASL authentication failed (account locked/held) */ 1, 0, &irc_protocol_cb_sasl_end_fail },
{ "903", /* SASL authentication successful */ 1, 0, &irc_protocol_cb_sasl_end_ok },
{ "904", /* SASL authentication failed */ 1, 0, &irc_protocol_cb_sasl_end_fail },
{ "905", /* SASL message too long */ 1, 0, &irc_protocol_cb_sasl_end_fail },
{ "906", /* SASL authentication aborted */ 1, 0, &irc_protocol_cb_sasl_end_fail },
{ "907", /* You have already completed SASL authentication */ 1, 0, &irc_protocol_cb_sasl_end_ok },
{ "936", /* censored word */ 1, 0, &irc_protocol_cb_generic_error },
{ "973", /* whois (secure connection) */ 1, 0, &irc_protocol_cb_server_mode_reason },
{ "974", /* whois (secure connection) */ 1, 0, &irc_protocol_cb_server_mode_reason },
+22 -13
View File
@@ -71,6 +71,9 @@ struct t_irc_server *last_irc_server = NULL;
struct t_irc_message *irc_recv_msgq = NULL;
struct t_irc_message *irc_msgq_last_msg = NULL;
char *irc_server_sasl_fail_string[IRC_SERVER_NUM_SASL_FAIL] =
{ "continue", "reconnect", "disconnect" };
char *irc_server_options[IRC_SERVER_NUM_OPTIONS][2] =
{ { "addresses", "" },
{ "proxy", "" },
@@ -87,7 +90,7 @@ char *irc_server_options[IRC_SERVER_NUM_OPTIONS][2] =
{ "sasl_username", "" },
{ "sasl_password", "" },
{ "sasl_timeout", "15" },
{ "sasl_disconnect_on_fail", "off" },
{ "sasl_fail", "continue" },
{ "autoconnect", "off" },
{ "autoreconnect", "on" },
{ "autoreconnect_delay", "10" },
@@ -2777,6 +2780,7 @@ int
irc_server_timer_sasl_cb (void *data, int remaining_calls)
{
struct t_irc_server *server;
int sasl_fail;
/* make C compiler happy */
(void) remaining_calls;
@@ -2793,8 +2797,15 @@ irc_server_timer_sasl_cb (void *data, int remaining_calls)
weechat_printf (server->buffer,
_("%s%s: sasl authentication timeout"),
weechat_prefix ("error"), IRC_PLUGIN_NAME);
if (IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SASL_DISCONNECT_ON_FAIL))
irc_server_disconnect (server, 0, 1);
sasl_fail = IRC_SERVER_OPTION_INTEGER(server,
IRC_SERVER_OPTION_SASL_FAIL);
if ((sasl_fail == IRC_SERVER_SASL_FAIL_RECONNECT)
|| (sasl_fail == IRC_SERVER_SASL_FAIL_DISCONNECT))
{
irc_server_disconnect (
server, 0,
(sasl_fail == IRC_SERVER_SASL_FAIL_RECONNECT) ? 1 : 0);
}
else
irc_server_sendf (server, 0, NULL, "CAP END");
}
@@ -5077,8 +5088,8 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
if (!weechat_infolist_new_var_string (ptr_item, "sasl_password",
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_SASL_PASSWORD)))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "sasl_disconnect_on_fail",
IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_SASL_DISCONNECT_ON_FAIL)))
if (!weechat_infolist_new_var_integer (ptr_item, "sasl_fail",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SASL_FAIL)))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "autoconnect",
IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTOCONNECT)))
@@ -5338,15 +5349,13 @@ irc_server_print_log ()
weechat_log_printf (" sasl_password. . . . : null");
else
weechat_log_printf (" sasl_password. . . . : (hidden)");
/* sasl_disconnect_on_fail */
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SASL_DISCONNECT_ON_FAIL]))
weechat_log_printf (" sasl_disconnect_on_fail: null (%s)",
(IRC_SERVER_OPTION_BOOLEAN(ptr_server, IRC_SERVER_OPTION_SASL_DISCONNECT_ON_FAIL)) ?
"on" : "off");
/* sasl_fail */
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_SASL_FAIL]))
weechat_log_printf (" sasl_fail. . . . . . : null ('%s')",
irc_server_sasl_fail_string[IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_SASL_FAIL)]);
else
weechat_log_printf (" sasl_disconnect_on_fail: %s",
weechat_config_boolean (ptr_server->options[IRC_SERVER_OPTION_SASL_DISCONNECT_ON_FAIL]) ?
"on" : "off");
weechat_log_printf (" sasl_fail. . . . . . : '%s'",
irc_server_sasl_fail_string[weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_SASL_FAIL])]);
/* autoconnect */
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT]))
weechat_log_printf (" autoconnect. . . . . : null (%s)",
+10 -1
View File
@@ -32,6 +32,15 @@
#define NI_MAXHOST 256
#endif
enum t_irc_server_sasl_fail
{
IRC_SERVER_SASL_FAIL_CONTINUE = 0,
IRC_SERVER_SASL_FAIL_RECONNECT,
IRC_SERVER_SASL_FAIL_DISCONNECT,
/* number of SASL fail options */
IRC_SERVER_NUM_SASL_FAIL,
};
enum t_irc_server_option
{
IRC_SERVER_OPTION_ADDRESSES = 0, /* server addresses (IP/name with port) */
@@ -49,7 +58,7 @@ enum t_irc_server_option
IRC_SERVER_OPTION_SASL_USERNAME, /* username for SASL authentication */
IRC_SERVER_OPTION_SASL_PASSWORD, /* password for SASL authentication */
IRC_SERVER_OPTION_SASL_TIMEOUT, /* timeout for SASL authentication */
IRC_SERVER_OPTION_SASL_DISCONNECT_ON_FAIL, /* disconnect on SASL fail */
IRC_SERVER_OPTION_SASL_FAIL, /* action on SASL fail */
IRC_SERVER_OPTION_AUTOCONNECT, /* autoconnect to server at startup */
IRC_SERVER_OPTION_AUTORECONNECT, /* autoreconnect when disconnected */
IRC_SERVER_OPTION_AUTORECONNECT_DELAY, /* delay before trying again reco */