diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-11-23 10:38:09 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-11-23 10:38:09 +0100 |
commit | 4f4045fb845961564e4ccf84c2ce4b36285dae94 (patch) | |
tree | f06cdfdb48edc2be0c1491b59ffdac09372d5b3a /src/plugins/irc | |
parent | 570beab90afe7ae0715162d39ba50cabf6ac0aa2 (diff) | |
download | weechat-4f4045fb845961564e4ccf84c2ce4b36285dae94.zip |
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
Diffstat (limited to 'src/plugins/irc')
-rw-r--r-- | src/plugins/irc/irc-config.c | 11 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 51 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 35 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 11 |
4 files changed, 75 insertions, 33 deletions
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 1d9eb392a..3826f40d1 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -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, diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index b6b3c97c4..034cf9a0c 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -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)) - { - /* Check if we are already connected to the server, - * to prevent disconnects in case of 907. - */ + if (!server->is_connected) + irc_server_sendf (server, 0, NULL, "CAP END"); - if (!server->is_connected) - irc_server_disconnect (server, 0, 1); + 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)) + { + 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 }, diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index d154c0090..d962bb11f 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -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)", diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 910e7b766..d722db496 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -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 */ |