mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-03 20:40:34 +01:00
cli: don't use global nm_cli in nmc_readline_*()
Globals are bad. Don't let nmc_readline_helper() access
nm_cli.
Instead, pass nmc_config along. nmc_config albeit being
a complex struct, is much more begning:
- the configuration nmc_config is initialized early on
and afterwards immutable.
- it only contains simple fields, which affect the behavior.
- it's not a global. While passing around the complex configuration
struct, it is clear that all callpaths don't access additional
global information.
This commit is contained in:
parent
0be65a4b78
commit
411243c654
6 changed files with 194 additions and 135 deletions
|
|
@ -85,7 +85,8 @@ set_deftext (void)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
get_secrets_from_user (const char *request_id,
|
||||
get_secrets_from_user (const NmcConfig *nmc_config,
|
||||
const char *request_id,
|
||||
const char *title,
|
||||
const char *msg,
|
||||
GPtrArray *secrets)
|
||||
|
|
@ -104,7 +105,7 @@ get_secrets_from_user (const char *request_id,
|
|||
rl_startup_hook = set_deftext;
|
||||
pre_input_deftext = g_strdup (secret->value);
|
||||
}
|
||||
pwd = nmc_readline ("%s (%s): ", secret->pretty_name, secret->entry_id);
|
||||
pwd = nmc_readline (nmc_config, "%s (%s): ", secret->pretty_name, secret->entry_id);
|
||||
|
||||
/* No password provided, cancel the secrets. */
|
||||
if (!pwd)
|
||||
|
|
@ -123,17 +124,16 @@ secrets_requested (NMSecretAgentSimple *agent,
|
|||
GPtrArray *secrets,
|
||||
gpointer user_data)
|
||||
{
|
||||
NmCli *nmc = (NmCli *) user_data;
|
||||
gboolean success = FALSE;
|
||||
NmCli *nmc = user_data;
|
||||
gboolean success;
|
||||
|
||||
if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY)
|
||||
nmc_terminal_erase_line ();
|
||||
|
||||
success = get_secrets_from_user (request_id, title, msg, secrets);
|
||||
if (success)
|
||||
nm_secret_agent_simple_response (agent, request_id, secrets);
|
||||
else
|
||||
nm_secret_agent_simple_response (agent, request_id, NULL);
|
||||
success = get_secrets_from_user (&nmc->nmc_config, request_id, title, msg, secrets);
|
||||
nm_secret_agent_simple_response (agent,
|
||||
request_id,
|
||||
success ? secrets : NULL);
|
||||
}
|
||||
|
||||
static NMCResultCode
|
||||
|
|
|
|||
|
|
@ -661,12 +661,12 @@ vpn_openconnect_get_secrets (NMConnection *connection, GPtrArray *secrets)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
get_secrets_from_user (const char *request_id,
|
||||
get_secrets_from_user (const NmcConfig *nmc_config,
|
||||
const char *request_id,
|
||||
const char *title,
|
||||
const char *msg,
|
||||
NMConnection *connection,
|
||||
gboolean ask,
|
||||
gboolean echo_on,
|
||||
GHashTable *pwds_hash,
|
||||
GPtrArray *secrets)
|
||||
{
|
||||
|
|
@ -698,8 +698,9 @@ get_secrets_from_user (const char *request_id,
|
|||
}
|
||||
if (msg)
|
||||
g_print ("%s\n", msg);
|
||||
pwd = nmc_readline_echo (secret->is_secret
|
||||
? echo_on
|
||||
pwd = nmc_readline_echo (nmc_config,
|
||||
secret->is_secret
|
||||
? nmc_config->show_secrets
|
||||
: TRUE,
|
||||
"%s (%s): ", secret->pretty_name, secret->entry_id);
|
||||
if (!pwd)
|
||||
|
|
@ -763,8 +764,14 @@ nmc_secrets_requested (NMSecretAgentSimple *agent,
|
|||
g_free (path);
|
||||
}
|
||||
|
||||
success = get_secrets_from_user (request_id, title, msg, connection, nmc->nmc_config.in_editor || nmc->ask,
|
||||
nmc->nmc_config.show_secrets, nmc->pwds_hash, secrets);
|
||||
success = get_secrets_from_user (&nmc->nmc_config,
|
||||
request_id,
|
||||
title,
|
||||
msg,
|
||||
connection,
|
||||
nmc->nmc_config.in_editor || nmc->ask,
|
||||
nmc->pwds_hash,
|
||||
secrets);
|
||||
if (success)
|
||||
nm_secret_agent_simple_response (agent, request_id, secrets);
|
||||
else {
|
||||
|
|
@ -847,7 +854,8 @@ stdin_ready_cb (GIOChannel * io, GIOCondition condition, gpointer data)
|
|||
}
|
||||
|
||||
static char *
|
||||
nmc_readline_helper (const char *prompt)
|
||||
nmc_readline_helper (const NmcConfig *nmc_config,
|
||||
const char *prompt)
|
||||
{
|
||||
GIOChannel *io = NULL;
|
||||
guint io_watch_id;
|
||||
|
|
@ -884,7 +892,7 @@ read_again:
|
|||
if (nmc_seen_sigint ()) {
|
||||
/* Ctrl-C */
|
||||
nmc_clear_sigint ();
|
||||
if ( nm_cli.nmc_config.in_editor
|
||||
if ( nmc_config->in_editor
|
||||
|| (rl_string && *rl_string)) {
|
||||
/* In editor, or the line is not empty */
|
||||
/* Call readline again to get new prompt (repeat) */
|
||||
|
|
@ -926,20 +934,17 @@ read_again:
|
|||
* this function returns NULL.
|
||||
*/
|
||||
char *
|
||||
nmc_readline (const char *prompt_fmt, ...)
|
||||
nmc_readline (const NmcConfig *nmc_config,
|
||||
const char *prompt_fmt,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
char *prompt, *str;
|
||||
gs_free char *prompt = NULL;
|
||||
|
||||
va_start (args, prompt_fmt);
|
||||
prompt = g_strdup_vprintf (prompt_fmt, args);
|
||||
va_end (args);
|
||||
|
||||
str = nmc_readline_helper (prompt);
|
||||
|
||||
g_free (prompt);
|
||||
|
||||
return str;
|
||||
return nmc_readline_helper (nmc_config, prompt);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -974,10 +979,14 @@ nmc_secret_redisplay (void)
|
|||
* nmc_readline(TRUE, ...) == nmc_readline(...)
|
||||
*/
|
||||
char *
|
||||
nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...)
|
||||
nmc_readline_echo (const NmcConfig *nmc_config,
|
||||
gboolean echo_on,
|
||||
const char *prompt_fmt,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
char *prompt, *str;
|
||||
gs_free char *prompt = NULL;
|
||||
char *str;
|
||||
HISTORY_STATE *saved_history;
|
||||
HISTORY_STATE passwd_history = { 0, };
|
||||
|
||||
|
|
@ -992,9 +1001,7 @@ nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...)
|
|||
rl_redisplay_function = nmc_secret_redisplay;
|
||||
}
|
||||
|
||||
str = nmc_readline_helper (prompt);
|
||||
|
||||
g_free (prompt);
|
||||
str = nmc_readline_helper (nmc_config, prompt);
|
||||
|
||||
/* Restore the non-hiding behavior */
|
||||
if (!echo_on) {
|
||||
|
|
|
|||
|
|
@ -59,8 +59,13 @@ char *nmc_unique_connection_name (const GPtrArray *connections,
|
|||
const char *try_name);
|
||||
|
||||
void nmc_cleanup_readline (void);
|
||||
char *nmc_readline (const char *prompt_fmt, ...) G_GNUC_PRINTF (1, 2);
|
||||
char *nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...) G_GNUC_PRINTF (2, 3);
|
||||
char *nmc_readline (const NmcConfig *nmc_config,
|
||||
const char *prompt_fmt,
|
||||
...) G_GNUC_PRINTF (2, 3);
|
||||
char *nmc_readline_echo (const NmcConfig *nmc_config,
|
||||
gboolean echo_on,
|
||||
const char *prompt_fmt,
|
||||
...) G_GNUC_PRINTF (3, 4);
|
||||
NmcCompEntryFunc nmc_rl_compentry_func_wrap (const char *const*values);
|
||||
char *nmc_rl_gen_func_basic (const char *text, int state, const char *const*words);
|
||||
char *nmc_rl_gen_func_ifnames (const char *text, int state);
|
||||
|
|
|
|||
|
|
@ -2765,14 +2765,14 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
|
|||
argc_ptr = &argc;
|
||||
|
||||
if (argc == 0 && nmc->ask) {
|
||||
char *line;
|
||||
gs_free char *line = NULL;
|
||||
|
||||
/* nmc_do_cmd() should not call this with argc=0. */
|
||||
g_assert (!nmc->complete);
|
||||
|
||||
line = nmc_readline (PROMPT_CONNECTION);
|
||||
line = nmc_readline (&nmc->nmc_config,
|
||||
PROMPT_CONNECTION);
|
||||
nmc_string_to_arg_array (line, NULL, TRUE, &arg_arr, &arg_num);
|
||||
g_free (line);
|
||||
argv_ptr = &arg_arr;
|
||||
argc_ptr = &arg_num;
|
||||
}
|
||||
|
|
@ -3019,9 +3019,11 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
|
|||
g_assert (!nmc->complete);
|
||||
|
||||
if (nmc->ask) {
|
||||
char *line = nmc_readline (PROMPT_ACTIVE_CONNECTIONS);
|
||||
gs_free char *line = NULL;
|
||||
|
||||
line = nmc_readline (&nmc->nmc_config,
|
||||
PROMPT_ACTIVE_CONNECTIONS);
|
||||
nmc_string_to_arg_array (line, NULL, TRUE, &arg_arr, &arg_num);
|
||||
g_free (line);
|
||||
arg_ptr = arg_arr;
|
||||
}
|
||||
if (arg_num == 0) {
|
||||
|
|
@ -4892,7 +4894,9 @@ ask_option (NmCli *nmc, NMConnection *connection, const NMMetaAbstractInfo *abst
|
|||
g_print (_("You can specify this option more than once. Press <Enter> when you're done.\n"));
|
||||
|
||||
again:
|
||||
value = nmc_readline ("%s", prompt);
|
||||
value = nmc_readline (&nmc->nmc_config,
|
||||
"%s",
|
||||
prompt);
|
||||
if (multi && !value)
|
||||
return;
|
||||
|
||||
|
|
@ -4982,23 +4986,25 @@ questionnaire_mandatory (NmCli *nmc, NMConnection *connection)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
want_provide_opt_args (const char *type, int num)
|
||||
want_provide_opt_args (const NmcConfig *nmc_config,
|
||||
const char *type,
|
||||
guint num)
|
||||
{
|
||||
char *answer;
|
||||
gboolean ret = TRUE;
|
||||
gs_free char *answer = NULL;
|
||||
|
||||
/* Ask for optional arguments. */
|
||||
g_print (ngettext ("There is %d optional setting for %s.\n",
|
||||
"There are %d optional settings for %s.\n", num),
|
||||
num, type);
|
||||
answer = nmc_readline (ngettext ("Do you want to provide it? %s",
|
||||
"Do you want to provide them? %s", num),
|
||||
"There are %d optional settings for %s.\n",
|
||||
num),
|
||||
(int) num,
|
||||
type);
|
||||
answer = nmc_readline (nmc_config,
|
||||
ngettext ("Do you want to provide it? %s",
|
||||
"Do you want to provide them? %s",
|
||||
num),
|
||||
prompt_yes_no (TRUE, NULL));
|
||||
answer = answer ? g_strstrip (answer) : NULL;
|
||||
if (answer && !matches (answer, WORD_YES))
|
||||
ret = FALSE;
|
||||
g_free (answer);
|
||||
return ret;
|
||||
nm_strstrip (answer);
|
||||
return !answer || matches (answer, WORD_YES);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -5068,7 +5074,9 @@ again:
|
|||
|
||||
/* Now ask for the settings. */
|
||||
if ( already_confirmed
|
||||
|| want_provide_opt_args (_(setting_info->pretty_name), infos->len)) {
|
||||
|| want_provide_opt_args (&nmc->nmc_config,
|
||||
_(setting_info->pretty_name),
|
||||
infos->len)) {
|
||||
ask_option (nmc, connection, infos->pdata[0]);
|
||||
already_confirmed = TRUE;
|
||||
/* asking for an option may enable other options. Create the list again. */
|
||||
|
|
@ -6786,20 +6794,16 @@ is_connection_dirty (NMConnection *connection, NMRemoteConnection *remote)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
confirm_quit (void)
|
||||
confirm_quit (const NmcConfig *nmc_config)
|
||||
{
|
||||
char *answer;
|
||||
gboolean want_quit = FALSE;
|
||||
gs_free char *answer = NULL;
|
||||
|
||||
answer = nmc_readline (_("The connection is not saved. "
|
||||
answer = nmc_readline (nmc_config,
|
||||
_("The connection is not saved. "
|
||||
"Do you really want to quit? %s"),
|
||||
prompt_yes_no (FALSE, NULL));
|
||||
answer = answer ? g_strstrip (answer) : NULL;
|
||||
if (answer && matches (answer, WORD_YES))
|
||||
want_quit = TRUE;
|
||||
|
||||
g_free (answer);
|
||||
return want_quit;
|
||||
nm_strstrip (answer);
|
||||
return (answer && matches (answer, WORD_YES));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -6847,10 +6851,13 @@ property_edit_submenu (NmCli *nmc,
|
|||
if (nmc->editor_status_line)
|
||||
editor_show_status_line (connection, dirty, temp_changes);
|
||||
|
||||
cmd_property_user = nmc_readline ("%s", prompt);
|
||||
cmd_property_user = nmc_readline (&nmc->nmc_config,
|
||||
"%s",
|
||||
prompt);
|
||||
if (!cmd_property_user || !*cmd_property_user)
|
||||
continue;
|
||||
cmdsub = parse_editor_sub_cmd (g_strstrip (cmd_property_user), &cmd_property_arg);
|
||||
g_strstrip (cmd_property_user);
|
||||
cmdsub = parse_editor_sub_cmd (cmd_property_user, &cmd_property_arg);
|
||||
|
||||
switch (cmdsub) {
|
||||
case NMC_EDITOR_SUB_CMD_SET:
|
||||
|
|
@ -6871,7 +6878,9 @@ property_edit_submenu (NmCli *nmc,
|
|||
g_print (_("Allowed values for '%s' property: %s\n"),
|
||||
prop_name, avals_str);
|
||||
}
|
||||
prop_val_user = nmc_readline (_("Enter '%s' value: "), prop_name);
|
||||
prop_val_user = nmc_readline (&nmc->nmc_config,
|
||||
_("Enter '%s' value: "),
|
||||
prop_name);
|
||||
} else
|
||||
prop_val_user = g_strdup (cmd_property_arg);
|
||||
|
||||
|
|
@ -6899,7 +6908,9 @@ property_edit_submenu (NmCli *nmc,
|
|||
case NMC_EDITOR_SUB_CMD_CHANGE:
|
||||
rl_startup_hook = nmc_rl_set_deftext;
|
||||
nmc_rl_pre_input_deftext = nmc_setting_get_property_parsable (curr_setting, prop_name, NULL);
|
||||
prop_val_user = nmc_readline (_("Edit '%s' value: "), prop_name);
|
||||
prop_val_user = nmc_readline (&nmc->nmc_config,
|
||||
_("Edit '%s' value: "),
|
||||
prop_name);
|
||||
|
||||
nmc_property_get_gvalue (curr_setting, prop_name, &prop_g_value);
|
||||
nmc_property_set_default_value (curr_setting, prop_name);
|
||||
|
|
@ -6916,19 +6927,20 @@ property_edit_submenu (NmCli *nmc,
|
|||
case NMC_EDITOR_SUB_CMD_REMOVE:
|
||||
if (cmd_property_arg) {
|
||||
unsigned long val_int = G_MAXUINT32;
|
||||
char *option = NULL;
|
||||
gs_free char *option = NULL;
|
||||
|
||||
if (!nmc_string_to_uint (cmd_property_arg, TRUE, 0, G_MAXUINT32, &val_int))
|
||||
if (!nmc_string_to_uint (cmd_property_arg, TRUE, 0, G_MAXUINT32, &val_int)) {
|
||||
option = g_strdup (cmd_property_arg);
|
||||
g_strstrip (option);
|
||||
}
|
||||
|
||||
if (!nmc_setting_remove_property_option (curr_setting, prop_name,
|
||||
option ? g_strstrip (option) : NULL,
|
||||
option,
|
||||
(guint32) val_int,
|
||||
&tmp_err)) {
|
||||
g_print (_("Error: %s\n"), tmp_err->message);
|
||||
g_clear_error (&tmp_err);
|
||||
}
|
||||
g_free (option);
|
||||
} else {
|
||||
if (!nmc_setting_reset_property (curr_setting, prop_name, &tmp_err)) {
|
||||
g_print (_("Error: failed to remove value of '%s': %s\n"), prop_name,
|
||||
|
|
@ -6971,7 +6983,7 @@ property_edit_submenu (NmCli *nmc,
|
|||
|
||||
case NMC_EDITOR_SUB_CMD_QUIT:
|
||||
if (is_connection_dirty (connection, *rem_con)) {
|
||||
if (confirm_quit ())
|
||||
if (confirm_quit (&nmc->nmc_config))
|
||||
return FALSE;
|
||||
} else
|
||||
return FALSE;
|
||||
|
|
@ -7032,7 +7044,8 @@ create_setting_by_name (const char *name, const NMMetaSettingValidPartItem *cons
|
|||
}
|
||||
|
||||
static const char *
|
||||
ask_check_setting (const char *arg,
|
||||
ask_check_setting (const NmcConfig *nmc_config,
|
||||
const char *arg,
|
||||
const NMMetaSettingValidPartItem *const*valid_settings_main,
|
||||
const NMMetaSettingValidPartItem *const*valid_settings_slave,
|
||||
const char *valid_settings_str)
|
||||
|
|
@ -7043,12 +7056,12 @@ ask_check_setting (const char *arg,
|
|||
|
||||
if (!arg) {
|
||||
g_print (_("Available settings: %s\n"), valid_settings_str);
|
||||
setting_name_user = nmc_readline (EDITOR_PROMPT_SETTING);
|
||||
setting_name_user = nmc_readline (nmc_config,
|
||||
EDITOR_PROMPT_SETTING);
|
||||
} else
|
||||
setting_name_user = g_strdup (arg);
|
||||
|
||||
if (setting_name_user)
|
||||
g_strstrip (setting_name_user);
|
||||
nm_strstrip (setting_name_user);
|
||||
|
||||
if (!(setting_name = check_valid_name (setting_name_user,
|
||||
valid_settings_main,
|
||||
|
|
@ -7062,7 +7075,8 @@ ask_check_setting (const char *arg,
|
|||
}
|
||||
|
||||
static const char *
|
||||
ask_check_property (const char *arg,
|
||||
ask_check_property (const NmcConfig *nmc_config,
|
||||
const char *arg,
|
||||
const char **valid_props,
|
||||
const char *valid_props_str)
|
||||
{
|
||||
|
|
@ -7072,9 +7086,9 @@ ask_check_property (const char *arg,
|
|||
|
||||
if (!arg) {
|
||||
g_print (_("Available properties: %s\n"), valid_props_str);
|
||||
prop_name_user = nmc_readline (EDITOR_PROMPT_PROPERTY);
|
||||
if (prop_name_user)
|
||||
g_strstrip (prop_name_user);
|
||||
prop_name_user = nmc_readline (nmc_config,
|
||||
EDITOR_PROMPT_PROPERTY);
|
||||
nm_strstrip (prop_name_user);
|
||||
} else
|
||||
prop_name_user = g_strdup (arg);
|
||||
|
||||
|
|
@ -7101,7 +7115,9 @@ update_connection_timestamp (NMConnection *src, NMConnection *dst)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
confirm_connection_saving (NMConnection *local, NMConnection *remote)
|
||||
confirm_connection_saving (const NmcConfig *nmc_config,
|
||||
NMConnection *local,
|
||||
NMConnection *remote)
|
||||
{
|
||||
NMSettingConnection *s_con_loc, *s_con_rem;
|
||||
gboolean ac_local, ac_remote;
|
||||
|
|
@ -7119,16 +7135,15 @@ confirm_connection_saving (NMConnection *local, NMConnection *remote)
|
|||
ac_remote = FALSE;
|
||||
|
||||
if (ac_local && !ac_remote) {
|
||||
char *answer;
|
||||
answer = nmc_readline (_("Saving the connection with 'autoconnect=yes'. "
|
||||
gs_free char *answer = NULL;
|
||||
|
||||
answer = nmc_readline (nmc_config,
|
||||
_("Saving the connection with 'autoconnect=yes'. "
|
||||
"That might result in an immediate activation of the connection.\n"
|
||||
"Do you still want to save? %s"), prompt_yes_no (TRUE, NULL));
|
||||
answer = answer ? g_strstrip (answer) : NULL;
|
||||
if (!answer || matches (answer, WORD_YES))
|
||||
confirmed = TRUE;
|
||||
else
|
||||
confirmed = FALSE;
|
||||
g_free (answer);
|
||||
"Do you still want to save? %s"),
|
||||
prompt_yes_no (TRUE, NULL));
|
||||
nm_strstrip (answer);
|
||||
confirmed = (!answer || matches (answer, WORD_YES));
|
||||
}
|
||||
return confirmed;
|
||||
}
|
||||
|
|
@ -7223,7 +7238,9 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
if (nmc->editor_status_line)
|
||||
editor_show_status_line (connection, dirty, temp_changes);
|
||||
|
||||
cmd_user = nmc_readline ("%s", menu_ctx.main_prompt);
|
||||
cmd_user = nmc_readline (&nmc->nmc_config,
|
||||
"%s",
|
||||
menu_ctx.main_prompt);
|
||||
|
||||
/* Get the remote connection again, it may have disappeared */
|
||||
removed = refresh_remote_connection (&weak, &rem_con);
|
||||
|
|
@ -7235,7 +7252,9 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
if (!cmd_user || !*cmd_user)
|
||||
continue;
|
||||
|
||||
cmd = parse_editor_main_cmd (g_strstrip (cmd_user), &cmd_arg);
|
||||
g_strstrip (cmd_user);
|
||||
|
||||
cmd = parse_editor_main_cmd (cmd_user, &cmd_arg);
|
||||
|
||||
split_editor_main_cmd_args (cmd_arg, &cmd_arg_s, &cmd_arg_p, &cmd_arg_v);
|
||||
switch (cmd) {
|
||||
|
|
@ -7249,7 +7268,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
const char *const*avals;
|
||||
GError *tmp_err = NULL;
|
||||
|
||||
prop_name = ask_check_property (cmd_arg,
|
||||
prop_name = ask_check_property (&nmc->nmc_config,
|
||||
cmd_arg,
|
||||
(const char **) menu_ctx.valid_props,
|
||||
menu_ctx.valid_props_str);
|
||||
if (!prop_name)
|
||||
|
|
@ -7263,7 +7283,9 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
g_print (_("Allowed values for '%s' property: %s\n"),
|
||||
prop_name, avals_str);
|
||||
}
|
||||
prop_val_user = nmc_readline (_("Enter '%s' value: "), prop_name);
|
||||
prop_val_user = nmc_readline (&nmc->nmc_config,
|
||||
_("Enter '%s' value: "),
|
||||
prop_name);
|
||||
|
||||
/* Set property value */
|
||||
if (!nmc_setting_set_property (menu_ctx.curr_setting, prop_name, prop_val_user, &tmp_err)) {
|
||||
|
|
@ -7321,7 +7343,9 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
g_print (_("Allowed values for '%s' property: %s\n"),
|
||||
prop_name, avals_str);
|
||||
}
|
||||
cmd_arg_v = nmc_readline (_("Enter '%s' value: "), prop_name);
|
||||
cmd_arg_v = nmc_readline (&nmc->nmc_config,
|
||||
_("Enter '%s' value: "),
|
||||
prop_name);
|
||||
}
|
||||
|
||||
/* Set property value */
|
||||
|
|
@ -7344,7 +7368,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
NMSetting *setting;
|
||||
const char *user_arg = cmd_arg_s ?: cmd_arg_p;
|
||||
|
||||
setting_name = ask_check_setting (user_arg,
|
||||
setting_name = ask_check_setting (&nmc->nmc_config,
|
||||
user_arg,
|
||||
valid_settings_main,
|
||||
valid_settings_slave,
|
||||
valid_settings_str);
|
||||
|
|
@ -7390,7 +7415,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
/* level 1 - setting selected */
|
||||
const char *prop_name;
|
||||
|
||||
prop_name = ask_check_property (cmd_arg_p,
|
||||
prop_name = ask_check_property (&nmc->nmc_config,
|
||||
cmd_arg_p,
|
||||
(const char **) menu_ctx.valid_props,
|
||||
menu_ctx.valid_props_str);
|
||||
if (!prop_name)
|
||||
|
|
@ -7413,7 +7439,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
GError *tmp_err = NULL;
|
||||
const char *prop_name;
|
||||
|
||||
prop_name = ask_check_property (cmd_arg,
|
||||
prop_name = ask_check_property (&nmc->nmc_config,
|
||||
cmd_arg,
|
||||
(const char **) menu_ctx.valid_props,
|
||||
menu_ctx.valid_props_str);
|
||||
if (!prop_name)
|
||||
|
|
@ -7507,7 +7534,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
if (menu_ctx.level == 1) {
|
||||
const char *prop_name;
|
||||
|
||||
prop_name = ask_check_property (cmd_arg,
|
||||
prop_name = ask_check_property (&nmc->nmc_config,
|
||||
cmd_arg,
|
||||
(const char **) menu_ctx.valid_props,
|
||||
menu_ctx.valid_props_str);
|
||||
if (!prop_name)
|
||||
|
|
@ -7705,9 +7733,12 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
}
|
||||
|
||||
/* Ask for save confirmation if the connection changes to autoconnect=yes */
|
||||
if (nmc->editor_save_confirmation)
|
||||
if (!confirm_connection_saving (connection, NM_CONNECTION (rem_con)))
|
||||
if (nmc->editor_save_confirmation) {
|
||||
if (!confirm_connection_saving (&nmc->nmc_config,
|
||||
connection,
|
||||
NM_CONNECTION (rem_con)))
|
||||
break;
|
||||
}
|
||||
|
||||
if (!rem_con) {
|
||||
/* Tell the settings service to add the new connection */
|
||||
|
|
@ -7824,7 +7855,8 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
nmc_editor_error->message);
|
||||
g_error_free (nmc_editor_error);
|
||||
} else {
|
||||
nmc_readline (_("Monitoring connection activation (press any key to continue)\n"));
|
||||
nmc_readline (&nmc->nmc_config,
|
||||
_("Monitoring connection activation (press any key to continue)\n"));
|
||||
}
|
||||
|
||||
if (nmc_editor_monitor_ac) {
|
||||
|
|
@ -7898,7 +7930,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t
|
|||
|
||||
case NMC_EDITOR_MAIN_CMD_QUIT:
|
||||
if (is_connection_dirty (connection, rem_con)) {
|
||||
if (confirm_quit ())
|
||||
if (confirm_quit (&nmc->nmc_config))
|
||||
cmd_loop = FALSE; /* quit command loop */
|
||||
} else
|
||||
cmd_loop = FALSE; /* quit command loop */
|
||||
|
|
@ -8174,8 +8206,9 @@ do_connection_edit (NmCli *nmc, int argc, char **argv)
|
|||
g_print (_("Error: invalid connection type; %s\n"), err1->message);
|
||||
g_clear_error (&err1);
|
||||
|
||||
type_ask = nmc_readline (EDITOR_PROMPT_CON_TYPE);
|
||||
type = type_ask = type_ask ? g_strstrip (type_ask) : NULL;
|
||||
type_ask = nmc_readline (&nmc->nmc_config,
|
||||
EDITOR_PROMPT_CON_TYPE);
|
||||
type = type_ask = nm_strstrip (type_ask);
|
||||
connection_type = check_valid_name_toplevel (type_ask, &slave_type, &err1);
|
||||
}
|
||||
nm_clear_g_free (&tmp_str);
|
||||
|
|
@ -8368,14 +8401,14 @@ do_connection_clone (NmCli *nmc, int argc, char **argv)
|
|||
argc_ptr = &argc;
|
||||
|
||||
if (argc == 0 && nmc->ask) {
|
||||
char *line;
|
||||
gs_free char *line = NULL;
|
||||
|
||||
/* nmc_do_cmd() should not call this with argc=0. */
|
||||
g_assert (!nmc->complete);
|
||||
|
||||
line = nmc_readline (PROMPT_CONNECTION);
|
||||
line = nmc_readline (&nmc->nmc_config,
|
||||
PROMPT_CONNECTION);
|
||||
nmc_string_to_arg_array (line, NULL, TRUE, &arg_arr, &arg_num);
|
||||
g_free (line);
|
||||
argv_ptr = &arg_arr;
|
||||
argc_ptr = &arg_num;
|
||||
}
|
||||
|
|
@ -8391,9 +8424,10 @@ do_connection_clone (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
if (argv[0])
|
||||
new_name = *argv;
|
||||
else if (nmc->ask)
|
||||
new_name = new_name_ask = nmc_readline (_("New connection name: "));
|
||||
else {
|
||||
else if (nmc->ask) {
|
||||
new_name = new_name_ask = nmc_readline (&nmc->nmc_config,
|
||||
_("New connection name: "));
|
||||
} else {
|
||||
g_string_printf (nmc->return_text, _("Error: <new name> argument is missing."));
|
||||
NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT);
|
||||
}
|
||||
|
|
@ -8478,14 +8512,14 @@ do_connection_delete (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
if (argc == 0) {
|
||||
if (nmc->ask) {
|
||||
char *line;
|
||||
gs_free char *line = NULL;
|
||||
|
||||
/* nmc_do_cmd() should not call this with argc=0. */
|
||||
g_assert (!nmc->complete);
|
||||
|
||||
line = nmc_readline (PROMPT_CONNECTIONS);
|
||||
line = nmc_readline (&nmc->nmc_config,
|
||||
PROMPT_CONNECTIONS);
|
||||
nmc_string_to_arg_array (line, NULL, TRUE, &arg_arr, &arg_num);
|
||||
g_free (line);
|
||||
arg_ptr = arg_arr;
|
||||
}
|
||||
if (arg_num == 0) {
|
||||
|
|
@ -8734,10 +8768,13 @@ do_connection_import (NmCli *nmc, int argc, char **argv)
|
|||
g_assert (!nmc->complete);
|
||||
|
||||
if (nmc->ask) {
|
||||
type_ask = nmc_readline ("%s: ", gettext (NM_META_TEXT_PROMPT_VPN_TYPE));
|
||||
filename_ask = nmc_readline (gettext (PROMPT_IMPORT_FILE));
|
||||
type = type_ask = type_ask ? g_strstrip (type_ask) : NULL;
|
||||
filename = filename_ask = filename_ask ? g_strstrip (filename_ask) : NULL;
|
||||
type_ask = nmc_readline (&nmc->nmc_config,
|
||||
"%s: ",
|
||||
gettext (NM_META_TEXT_PROMPT_VPN_TYPE));
|
||||
type = nm_strstrip (type_ask);
|
||||
filename_ask = nmc_readline (&nmc->nmc_config,
|
||||
gettext (PROMPT_IMPORT_FILE));
|
||||
filename = nm_strstrip (filename_ask);
|
||||
} else {
|
||||
g_string_printf (nmc->return_text, _("Error: No arguments provided."));
|
||||
NMC_RETURN (nmc, NMC_RESULT_ERROR_USER_INPUT);
|
||||
|
|
@ -8854,14 +8891,14 @@ do_connection_export (NmCli *nmc, int argc, char **argv)
|
|||
argc_ptr = &argc;
|
||||
|
||||
if (argc == 0 && nmc->ask) {
|
||||
char *line;
|
||||
gs_free char *line = NULL;
|
||||
|
||||
/* nmc_do_cmd() should not call this with argc=0. */
|
||||
g_assert (!nmc->complete);
|
||||
|
||||
line = nmc_readline (PROMPT_VPN_CONNECTION);
|
||||
line = nmc_readline (&nmc->nmc_config,
|
||||
PROMPT_VPN_CONNECTION);
|
||||
nmc_string_to_arg_array (line, NULL, TRUE, &arg_arr, &arg_num);
|
||||
g_free (line);
|
||||
argv_ptr = &arg_arr;
|
||||
argc_ptr = &arg_num;
|
||||
}
|
||||
|
|
@ -8884,8 +8921,10 @@ do_connection_export (NmCli *nmc, int argc, char **argv)
|
|||
goto finish;
|
||||
}
|
||||
|
||||
if (out_name == NULL && nmc->ask)
|
||||
out_name = out_name_ask = nmc_readline (_("Output file name: "));
|
||||
if (!out_name && nmc->ask) {
|
||||
out_name = out_name_ask = nmc_readline (&nmc->nmc_config,
|
||||
_("Output file name: "));
|
||||
}
|
||||
|
||||
type = nm_connection_get_connection_type (connection);
|
||||
if (g_strcmp0 (type, NM_SETTING_VPN_SETTING_NAME) != 0) {
|
||||
|
|
|
|||
|
|
@ -1029,9 +1029,11 @@ get_device_list (NmCli *nmc, int argc, char **argv)
|
|||
|
||||
if (argc == 0) {
|
||||
if (nmc->ask) {
|
||||
char *line = nmc_readline (PROMPT_INTERFACES);
|
||||
gs_free char *line = NULL;
|
||||
|
||||
line = nmc_readline (&nmc->nmc_config,
|
||||
PROMPT_INTERFACES);
|
||||
nmc_string_to_arg_array (line, NULL, FALSE, &arg_arr, &arg_num);
|
||||
g_free (line);
|
||||
arg_ptr = arg_arr;
|
||||
}
|
||||
if (arg_num == 0) {
|
||||
|
|
@ -1086,8 +1088,10 @@ get_device (NmCli *nmc, int *argc, char ***argv, GError **error)
|
|||
int i;
|
||||
|
||||
if (*argc == 0) {
|
||||
if (nmc->ask)
|
||||
ifname = ifname_ask = nmc_readline (PROMPT_INTERFACE);
|
||||
if (nmc->ask) {
|
||||
ifname = ifname_ask = nmc_readline (&nmc->nmc_config,
|
||||
PROMPT_INTERFACE);
|
||||
}
|
||||
|
||||
if (!ifname_ask) {
|
||||
g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
|
||||
|
|
@ -3211,7 +3215,7 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
g_assert (!nmc->complete);
|
||||
|
||||
if (nmc->ask) {
|
||||
ssid_ask = nmc_readline (_("SSID or BSSID: "));
|
||||
ssid_ask = nmc_readline (&nmc->nmc_config, _("SSID or BSSID: "));
|
||||
param_user = ssid_ask ?: "";
|
||||
bssid1_arr = nm_utils_hwaddr_atoba (param_user, ETH_ALEN);
|
||||
}
|
||||
|
|
@ -3470,8 +3474,11 @@ do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|||
|| ap_wpa_flags != NM_802_11_AP_SEC_NONE
|
||||
|| ap_rsn_flags != NM_802_11_AP_SEC_NONE) {
|
||||
/* Ask for missing password when one is expected and '--ask' is used */
|
||||
if (!password && nmc->ask)
|
||||
password = passwd_ask = nmc_readline_echo (nmc->nmc_config.show_secrets, _("Password: "));
|
||||
if (!password && nmc->ask) {
|
||||
password = passwd_ask = nmc_readline_echo (&nmc->nmc_config,
|
||||
nmc->nmc_config.show_secrets,
|
||||
_("Password: "));
|
||||
}
|
||||
|
||||
if (password) {
|
||||
if (!connection)
|
||||
|
|
|
|||
|
|
@ -40,24 +40,25 @@ polkit_request (NMPolkitListener *listener,
|
|||
gboolean echo_on,
|
||||
gpointer user_data)
|
||||
{
|
||||
char *response, *tmp, *p;
|
||||
NmCli *nmc = user_data;
|
||||
|
||||
g_print ("%s\n", message);
|
||||
g_print ("(action_id: %s)\n", action_id);
|
||||
|
||||
/* Ask user for polkit authorization password */
|
||||
if (user) {
|
||||
gs_free char *tmp = NULL;
|
||||
char *p;
|
||||
|
||||
/* chop of ": " if present */
|
||||
tmp = g_strdup (request);
|
||||
p = strrchr (tmp, ':');
|
||||
if (p && !strcmp (p, ": "))
|
||||
if (p && nm_streq (p, ": "))
|
||||
*p = '\0';
|
||||
response = nmc_readline_echo (echo_on, "%s (%s): ", tmp, user);
|
||||
g_free (tmp);
|
||||
} else
|
||||
response = nmc_readline_echo (echo_on, "%s", request);
|
||||
return nmc_readline_echo (&nmc->nmc_config, echo_on, "%s (%s): ", tmp, user);
|
||||
}
|
||||
|
||||
return response;
|
||||
return nmc_readline_echo (&nmc->nmc_config, echo_on, "%s", request);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue