1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-03 08:13:14 +02:00

irc: add server option "registered_mode" (closes #1625)

Two new fields are added in IRC server structure:

- "authentication_method", possible values:
    0: not authenticated
    1: authenticated with SASL
    2: authenticated with other method
- "sasl_mechanism_used", possible values: see enum t_irc_sasl_mechanism
  in src/plugins/irc/irc-sasl.h
This commit is contained in:
Andrew Potter
2023-01-29 16:43:20 +01:00
committed by Sébastien Helleu
parent 3909d77617
commit 4f0b6115a1
36 changed files with 301 additions and 15 deletions
+37
View File
@@ -34,6 +34,7 @@
#include "irc-channel.h"
#include "irc-ctcp.h"
#include "irc-ignore.h"
#include "irc-mode.h"
#include "irc-msgbuffer.h"
#include "irc-nick.h"
#include "irc-notify.h"
@@ -1000,6 +1001,9 @@ irc_config_server_default_change_cb (const void *pointer, void *data,
else
irc_server_remove_away (ptr_server);
break;
case IRC_SERVER_OPTION_REGISTERED_MODE:
irc_mode_registered_mode_change (ptr_server);
break;
}
}
}
@@ -1218,6 +1222,20 @@ irc_config_server_check_value_cb (const void *pointer, void *data,
return 0;
}
break;
case IRC_SERVER_OPTION_REGISTERED_MODE:
if (!value || !value[0])
break;
/* Only one character should be accepted */
if (value[1])
{
weechat_printf (
NULL,
_("%s%s: invalid registered mode, must be a single "
"character"),
weechat_prefix ("error"), IRC_PLUGIN_NAME);
return 0;
}
break;
}
}
@@ -1270,6 +1288,9 @@ irc_config_server_change_cb (const void *pointer, void *data,
case IRC_SERVER_OPTION_NOTIFY:
irc_notify_new_for_server (ptr_server);
break;
case IRC_SERVER_OPTION_REGISTERED_MODE:
irc_mode_registered_mode_change (ptr_server);
break;
}
}
}
@@ -2502,6 +2523,22 @@ irc_config_server_new_option (struct t_config_file *config_file,
callback_change_data,
NULL, NULL, NULL);
break;
case IRC_SERVER_OPTION_REGISTERED_MODE:
new_option = weechat_config_new_option (
config_file, section,
option_name, "string",
N_("mode that is set on registered users (default is \"r\")"),
NULL, 0, 0,
default_value, value,
null_value_allowed,
callback_check_value,
callback_check_value_pointer,
callback_check_value_data,
callback_change,
callback_change_pointer,
callback_change_data,
NULL, NULL, NULL);
break;
case IRC_SERVER_NUM_OPTIONS:
break;
}
+44
View File
@@ -585,6 +585,7 @@ void
irc_mode_user_add (struct t_irc_server *server, char mode)
{
char str_mode[2], *nick_modes2;
const char *registered_mode;
str_mode[0] = mode;
str_mode[1] = '\0';
@@ -617,6 +618,15 @@ irc_mode_user_add (struct t_irc_server *server, char mode)
weechat_bar_item_update ("input_prompt");
weechat_bar_item_update ("irc_nick_modes");
}
registered_mode = IRC_SERVER_OPTION_STRING(
server, IRC_SERVER_OPTION_REGISTERED_MODE);
if (registered_mode
&& (registered_mode[0] == mode)
&& (server->authentication_method == IRC_SERVER_AUTH_METHOD_NONE))
{
server->authentication_method = IRC_SERVER_AUTH_METHOD_OTHER;
}
}
/*
@@ -627,6 +637,7 @@ void
irc_mode_user_remove (struct t_irc_server *server, char mode)
{
char *pos, *nick_modes2;
const char *registered_mode;
int new_size;
if (server->nick_modes)
@@ -643,6 +654,11 @@ irc_mode_user_remove (struct t_irc_server *server, char mode)
weechat_bar_item_update ("irc_nick_modes");
}
}
registered_mode = IRC_SERVER_OPTION_STRING(
server, IRC_SERVER_OPTION_REGISTERED_MODE);
if (registered_mode && (registered_mode[0] == mode))
server->authentication_method = IRC_SERVER_AUTH_METHOD_NONE;
}
/*
@@ -695,3 +711,31 @@ irc_mode_user_set (struct t_irc_server *server, const char *modes,
weechat_bar_item_update ("input_prompt");
weechat_bar_item_update ("irc_nick_modes");
}
/*
* Updates authentication_method when IRC_SERVER_OPTION_REGISTERED_MODE
* changes.
*/
void
irc_mode_registered_mode_change (struct t_irc_server *server)
{
const char *ptr_mode, *registered_mode;
registered_mode = IRC_SERVER_OPTION_STRING(
server, IRC_SERVER_OPTION_REGISTERED_MODE);
ptr_mode = (server->nick_modes && registered_mode[0]) ?
strchr (server->nick_modes, registered_mode[0]) : NULL;
if (ptr_mode)
{
if (server->authentication_method == IRC_SERVER_AUTH_METHOD_NONE)
server->authentication_method = IRC_SERVER_AUTH_METHOD_OTHER;
}
else
{
if (server->authentication_method == IRC_SERVER_AUTH_METHOD_OTHER)
server->authentication_method = IRC_SERVER_AUTH_METHOD_NONE;
}
}
+1
View File
@@ -33,5 +33,6 @@ extern int irc_mode_channel_set (struct t_irc_server *server,
const char *modes_arguments);
extern void irc_mode_user_set (struct t_irc_server *server, const char *modes,
int reset_modes);
extern void irc_mode_registered_mode_change (struct t_irc_server *server);
#endif /* WEECHAT_PLUGIN_IRC_MODE_H */
+9
View File
@@ -571,6 +571,10 @@ IRC_PROTOCOL_CALLBACK(authenticate)
IRC_PLUGIN_NAME,
sasl_error);
}
else
{
server->sasl_mechanism_used = sasl_mechanism;
}
irc_server_sendf (server, 0, NULL, "AUTHENTICATE %s", answer);
free (answer);
}
@@ -7281,6 +7285,8 @@ IRC_PROTOCOL_CALLBACK(sasl_end_ok)
IRC_PROTOCOL_RUN_CALLBACK(numeric);
server->authentication_method = IRC_SERVER_AUTH_METHOD_SASL;
if (!server->is_connected)
irc_server_sendf (server, 0, NULL, "CAP END");
@@ -7306,6 +7312,9 @@ IRC_PROTOCOL_CALLBACK(sasl_end_fail)
server->hook_timer_sasl = NULL;
}
server->authentication_method = IRC_SERVER_AUTH_METHOD_NONE;
server->sasl_mechanism_used = -1;
IRC_PROTOCOL_RUN_CALLBACK(numeric);
sasl_fail = IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SASL_FAIL);
+13
View File
@@ -122,6 +122,7 @@ char *irc_server_options[IRC_SERVER_NUM_OPTIONS][2] =
{ "split_msg_max_length", "512" },
{ "charset_message", "message" },
{ "default_chantypes", "#&" },
{ "registered_mode", "r" },
};
char *irc_server_casemapping_string[IRC_SERVER_NUM_CASEMAPPING] =
@@ -1555,6 +1556,8 @@ irc_server_alloc (const char *name)
new_server->sasl_scram_auth_message = NULL;
new_server->sasl_temp_username = NULL;
new_server->sasl_temp_password = NULL;
new_server->authentication_method = IRC_SERVER_AUTH_METHOD_NONE;
new_server->sasl_mechanism_used = -1;
new_server->is_connected = 0;
new_server->ssl_connected = 0;
new_server->disconnected = 0;
@@ -3975,6 +3978,8 @@ irc_server_close_connection (struct t_irc_server *server)
weechat_hashtable_remove_all (server->join_noswitch);
/* server is now disconnected */
server->authentication_method = IRC_SERVER_AUTH_METHOD_NONE;
server->sasl_mechanism_used = -1;
server->is_connected = 0;
server->ssl_connected = 0;
@@ -6113,6 +6118,8 @@ irc_server_hdata_server_cb (const void *pointer, void *data,
WEECHAT_HDATA_VAR(struct t_irc_server, sasl_scram_auth_message, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, sasl_temp_username, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, sasl_temp_password, STRING, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, authentication_method, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, sasl_mechanism_used, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, is_connected, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, ssl_connected, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, disconnected, INTEGER, 0, NULL, NULL);
@@ -6483,6 +6490,10 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
if (!weechat_infolist_new_var_time (ptr_item, "lag_last_refresh", server->lag_last_refresh))
return 0;
}
if (!weechat_infolist_new_var_integer (ptr_item, "authentication_method", server->authentication_method))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "sasl_mechanism_used", server->sasl_mechanism_used))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "isupport", server->isupport))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "prefix_modes", server->prefix_modes))
@@ -6857,6 +6868,8 @@ irc_server_print_log ()
weechat_log_printf (" sasl_scram_auth_message . : (hidden)");
weechat_log_printf (" sasl_temp_username. . . . : '%s'", ptr_server->sasl_temp_username);
weechat_log_printf (" sasl_temp_password. . . . : (hidden)");
weechat_log_printf (" authentication_method . . : %d", ptr_server->authentication_method);
weechat_log_printf (" sasl_mechanism_used . . . : %d", ptr_server->sasl_mechanism_used);
weechat_log_printf (" is_connected. . . . . . . : %d", ptr_server->is_connected);
weechat_log_printf (" ssl_connected . . . . . . : %d", ptr_server->ssl_connected);
weechat_log_printf (" disconnected. . . . . . . : %d", ptr_server->disconnected);
+11
View File
@@ -94,6 +94,7 @@ enum t_irc_server_option
IRC_SERVER_OPTION_SPLIT_MSG_MAX_LENGTH, /* max length of messages */
IRC_SERVER_OPTION_CHARSET_MESSAGE, /* what to decode/encode in msg */
IRC_SERVER_OPTION_DEFAULT_CHANTYPES, /* chantypes if not received */
IRC_SERVER_OPTION_REGISTERED_MODE, /* mode set on registered user */
/* number of server options */
IRC_SERVER_NUM_OPTIONS,
};
@@ -153,6 +154,14 @@ enum t_irc_server_utf8mapping
IRC_SERVER_NUM_UTF8MAPPING,
};
/* authentication method */
enum t_irc_server_auth_method
{
IRC_SERVER_AUTH_METHOD_NONE = 0,
IRC_SERVER_AUTH_METHOD_SASL,
IRC_SERVER_AUTH_METHOD_OTHER,
};
/* output queue of messages to server (for sending slowly to server) */
struct t_irc_outqueue
@@ -200,6 +209,8 @@ struct t_irc_server
char *sasl_scram_auth_message; /* auth message for SASL SCRAM */
char *sasl_temp_username; /* temp SASL username (set by /auth cmd) */
char *sasl_temp_password; /* temp SASL password (set by /auth cmd) */
int authentication_method; /* authentication method used to login */
int sasl_mechanism_used; /* SASL method used at login time */
int is_connected; /* 1 if WeeChat is connected to server */
int ssl_connected; /* = 1 if connected with SSL */
int disconnected; /* 1 if server has been disconnected */
+14
View File
@@ -416,6 +416,20 @@ irc_upgrade_read_cb (const void *pointer, void *data,
irc_upgrade_current_server,
NULL);
}
/*
* "authentication_method" and "sasl_mechanism_used" are
* new in WeeChat 3.9
*/
if (weechat_infolist_search_var (infolist, "authentication_method"))
{
irc_upgrade_current_server->authentication_method = weechat_infolist_integer (infolist, "authentication_method");
irc_upgrade_current_server->sasl_mechanism_used = weechat_infolist_integer (infolist, "sasl_mechanism_used");
}
else
{
irc_upgrade_current_server->authentication_method = IRC_SERVER_AUTH_METHOD_NONE;
irc_upgrade_current_server->sasl_mechanism_used = -1;
}
irc_upgrade_current_server->is_connected = weechat_infolist_integer (infolist, "is_connected");
irc_upgrade_current_server->ssl_connected = weechat_infolist_integer (infolist, "ssl_connected");
irc_upgrade_current_server->disconnected = weechat_infolist_integer (infolist, "disconnected");