diff options
| author | Dmitry Podgorny <pasis.ua@gmail.com> | 2020-02-27 01:22:05 +0200 |
|---|---|---|
| committer | Dmitry Podgorny <pasis.ua@gmail.com> | 2020-06-05 11:37:51 +0300 |
| commit | ac410445af65b9d332d4606a08ff549672042766 (patch) | |
| tree | 0a898a43ee4a5c704fe496d004efa7e57b0cb735 /src/command | |
| parent | 8c9aee22e81804bda6590ba80e9450ca90f56d14 (diff) | |
| download | profani-tty-ac410445af65b9d332d4606a08ff549672042766.tar.gz | |
Add option for legacy authentication
New options:
/connect <account> [auth default|legacy]
/account <account> set auth default|legacy
Fixes #1236.
Diffstat (limited to 'src/command')
| -rw-r--r-- | src/command/cmd_ac.c | 90 | ||||
| -rw-r--r-- | src/command/cmd_defs.c | 9 | ||||
| -rw-r--r-- | src/command/cmd_funcs.c | 33 |
3 files changed, 126 insertions, 6 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 94081510..09de573c 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -195,6 +195,7 @@ static Autocomplete omemo_sendfile_ac; #endif static Autocomplete connect_property_ac; static Autocomplete tls_property_ac; +static Autocomplete auth_property_ac; static Autocomplete alias_ac; static Autocomplete aliases_ac; static Autocomplete join_property_ac; @@ -425,6 +426,7 @@ cmd_ac_init(void) autocomplete_add(account_set_ac, "pgpkeyid"); autocomplete_add(account_set_ac, "startscript"); autocomplete_add(account_set_ac, "tls"); + autocomplete_add(account_set_ac, "auth"); autocomplete_add(account_set_ac, "theme"); account_clear_ac = autocomplete_new(); @@ -686,6 +688,7 @@ cmd_ac_init(void) #endif connect_property_ac = autocomplete_new(); + autocomplete_add(connect_property_ac, "auth"); autocomplete_add(connect_property_ac, "server"); autocomplete_add(connect_property_ac, "port"); autocomplete_add(connect_property_ac, "tls"); @@ -697,6 +700,10 @@ cmd_ac_init(void) autocomplete_add(tls_property_ac, "legacy"); autocomplete_add(tls_property_ac, "disable"); + auth_property_ac = autocomplete_new(); + autocomplete_add(auth_property_ac, "default"); + autocomplete_add(auth_property_ac, "legacy"); + join_property_ac = autocomplete_new(); autocomplete_add(join_property_ac, "nick"); autocomplete_add(join_property_ac, "password"); @@ -1263,6 +1270,7 @@ cmd_ac_reset(ProfWin *window) #endif autocomplete_reset(connect_property_ac); autocomplete_reset(tls_property_ac); + autocomplete_reset(auth_property_ac); autocomplete_reset(alias_ac); autocomplete_reset(aliases_ac); autocomplete_reset(join_property_ac); @@ -1419,6 +1427,7 @@ cmd_ac_uninit(void) #endif autocomplete_free(connect_property_ac); autocomplete_free(tls_property_ac); + autocomplete_free(auth_property_ac); autocomplete_free(alias_ac); autocomplete_free(aliases_ac); autocomplete_free(join_property_ac); @@ -3206,7 +3215,7 @@ _connect_autocomplete(ProfWin *window, const char *const input, gboolean previou char *found = NULL; gboolean result = FALSE; - gchar **args = parse_args(input, 1, 7, &result); + gchar **args = parse_args(input, 1, 9, &result); if (result) { gboolean space_at_end = g_str_has_suffix(input, " "); @@ -3274,6 +3283,74 @@ _connect_autocomplete(ProfWin *window, const char *const input, gboolean previou return found; } } + if ((num_args == 7 && space_at_end) || (num_args == 8 && !space_at_end)) { + GString *beginning = g_string_new("/connect"); + g_string_append_printf(beginning, " %s %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE, previous); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 8 && space_at_end && (g_strcmp0(args[7], "tls") == 0)) + || (num_args == 9 && (g_strcmp0(args[7], "tls") == 0) && !space_at_end)) { + GString *beginning = g_string_new("/connect"); + g_string_append_printf(beginning, " %s %s %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); + found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE, previous); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + + /* auth option */ + + if ((num_args == 2 && space_at_end && (g_strcmp0(args[1], "auth") == 0)) + || (num_args == 3 && (g_strcmp0(args[1], "auth") == 0) && !space_at_end)) { + GString *beginning = g_string_new("/connect"); + g_string_append_printf(beginning, " %s %s", args[0], args[1]); + found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 4 && space_at_end && (g_strcmp0(args[3], "auth") == 0)) + || (num_args == 5 && (g_strcmp0(args[3], "auth") == 0) && !space_at_end)) { + GString *beginning = g_string_new("/connect"); + g_string_append_printf(beginning, " %s %s %s %s", args[0], args[1], args[2], args[3]); + found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 6 && space_at_end && (g_strcmp0(args[5], "auth") == 0)) + || (num_args == 7 && (g_strcmp0(args[5], "auth") == 0) && !space_at_end)) { + GString *beginning = g_string_new("/connect"); + g_string_append_printf(beginning, " %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5]); + found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 8 && space_at_end && (g_strcmp0(args[7], "auth") == 0)) + || (num_args == 9 && (g_strcmp0(args[7], "auth") == 0) && !space_at_end)) { + GString *beginning = g_string_new("/connect"); + g_string_append_printf(beginning, " %s %s %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); + found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } } g_strfreev(args); @@ -3484,6 +3561,17 @@ _account_autocomplete(ProfWin *window, const char *const input, gboolean previou return found; } } + if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "auth") == 0)) + || (num_args == 4 && (g_strcmp0(args[2], "auth") == 0) && !space_at_end)) { + GString *beginning = g_string_new("/account"); + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); + found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "startscript") == 0)) || (num_args == 4 && (g_strcmp0(args[2], "startscript") == 0) && !space_at_end)) { GString *beginning = g_string_new("/account"); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 70331542..85140430 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -160,7 +160,7 @@ static struct cmd_t command_defs[] = CMD_TAG_CONNECTION) CMD_SYN( "/connect [<account>]", - "/connect <account> [server <server>] [port <port>] [tls force|allow|trust|legacy|disable]") + "/connect <account> [server <server>] [port <port>] [tls force|allow|trust|legacy|disable] [auth default|legacy]") CMD_DESC( "Login to a chat service. " "If no account is specified, the default is used if one is configured. " @@ -173,7 +173,9 @@ static struct cmd_t command_defs[] = { "tls allow", "Use TLS for the connection if it is available." }, { "tls trust", "Force TLS connection and trust server's certificate." }, { "tls legacy", "Use legacy TLS for the connection. It means server doesn't support STARTTLS and TLS is forced just after TCP connection is established." }, - { "tls disable", "Disable TLS for the connection." }) + { "tls disable", "Disable TLS for the connection." }, + { "auth default", "Default authentication process." }, + { "auth legacy", "Allow legacy authentication." }) CMD_EXAMPLES( "/connect", "/connect odin@valhalla.edda", @@ -2003,6 +2005,7 @@ static struct cmd_t command_defs[] = "/account set <account> pgpkeyid <pgpkeyid>", "/account set <account> startscript <script>", "/account set <account> tls force|allow|trust|legacy|disable", + "/account set <account> auth default|legacy", "/account set <account> theme <theme>", "/account clear <account> password", "/account clear <account> eval_password", @@ -2045,6 +2048,8 @@ static struct cmd_t command_defs[] = { "set <account> tls trust", "Force TLS connection and trust server's certificate." }, { "set <account> tls legacy", "Use legacy TLS for the connection. It means server doesn't support STARTTLS and TLS is forced just after TCP connection is established." }, { "set <account> tls disable", "Disable TLS for the connection." }, + { "set <account> auth default", "Use default authentication process." }, + { "set <account> auth legacy", "Allow legacy authentication." }, { "set <account> <theme>", "Set the UI theme for the account." }, { "clear <account> server", "Remove the server setting for this account." }, { "clear <account> port", "Remove the port setting for this account." }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 7329046a..1c13d12f 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -338,7 +338,7 @@ cmd_connect(ProfWin *window, const char *const command, gchar **args) return TRUE; } - gchar *opt_keys[] = { "server", "port", "tls", NULL }; + gchar *opt_keys[] = { "server", "port", "tls", "auth", NULL }; gboolean parsed; GHashTable *options = parse_options(&args[args[0] ? 1 : 0], opt_keys, &parsed); @@ -364,6 +364,16 @@ cmd_connect(ProfWin *window, const char *const command, gchar **args) return TRUE; } + char *auth_policy = g_hash_table_lookup(options, "auth"); + if (auth_policy && + (g_strcmp0(auth_policy, "default") != 0) && + (g_strcmp0(auth_policy, "legacy") != 0)) { + cons_bad_cmd_usage(command); + cons_show(""); + options_destroy(options); + return TRUE; + } + int port = 0; if (g_hash_table_contains(options, "port")) { char *port_str = g_hash_table_lookup(options, "port"); @@ -406,6 +416,8 @@ cmd_connect(ProfWin *window, const char *const command, gchar **args) account_set_port(account, port); if (tls_policy != NULL) account_set_tls_policy(account, tls_policy); + if (auth_policy != NULL) + account_set_auth_policy(account, auth_policy); // use password if set if (account->password) { @@ -441,7 +453,7 @@ cmd_connect(ProfWin *window, const char *const command, gchar **args) } else { jid = g_utf8_strdown(user, -1); char *passwd = ui_ask_password(); - conn_status = cl_ev_connect_jid(jid, passwd, altdomain, port, tls_policy); + conn_status = cl_ev_connect_jid(jid, passwd, altdomain, port, tls_policy, auth_policy); free(passwd); } @@ -497,7 +509,7 @@ cmd_account_add(ProfWin *window, const char *const command, gchar **args) return TRUE; } - accounts_add(account_name, NULL, 0, NULL); + accounts_add(account_name, NULL, 0, NULL, NULL); cons_show("Account created."); cons_show(""); @@ -844,6 +856,20 @@ _account_set_tls(char *account_name, char *policy) } gboolean +_account_set_auth(char *account_name, char *policy) +{ + if ((g_strcmp0(policy, "default") != 0) + && (g_strcmp0(policy, "legacy") != 0)) { + cons_show("Auth policy must be either default or legacy."); + } else { + accounts_set_auth_policy(account_name, policy); + cons_show("Updated auth policy for account %s: %s", account_name, policy); + cons_show(""); + } + return TRUE; +} + +gboolean _account_set_presence_priority(char *account_name, char *presence, char *priority) { int intval; @@ -919,6 +945,7 @@ cmd_account_set(ProfWin *window, const char *const command, gchar **args) if (strcmp(property, "startscript") == 0) return _account_set_startscript(account_name, value); if (strcmp(property, "theme") == 0) return _account_set_theme(account_name, value); if (strcmp(property, "tls") == 0) return _account_set_tls(account_name, value); + if (strcmp(property, "auth") == 0) return _account_set_auth(account_name, value); if (valid_resource_presence_string(property)) { return _account_set_presence_priority(account_name, property, value); |