From f9bfd1158b8d08d6a5ed3bb7cc1ba7a6455e5201 Mon Sep 17 00:00:00 2001 From: Michael Biebl Date: Sun, 1 Sep 2024 22:38:35 +0200 Subject: New upstream version 1.49.90 --- src/nmcli/common.c | 2 +- src/nmcli/connections.c | 16 +++++++-- src/nmcli/devices.c | 43 ++++++++++--------------- src/nmcli/gen-metadata-nm-settings-nmcli.xml.in | 6 +++- src/nmcli/nmcli.c | 24 ++++++++------ 5 files changed, 50 insertions(+), 41 deletions(-) (limited to 'src/nmcli') diff --git a/src/nmcli/common.c b/src/nmcli/common.c index 2f205e50..fbabdffc 100644 --- a/src/nmcli/common.c +++ b/src/nmcli/common.c @@ -824,7 +824,7 @@ static char *rl_string; /** * nmc_cleanup_readline: * - * Cleanup readline when nmcli is terminated with a signal. + * Cleanup readline when nmcli is terminated. * It makes sure the terminal is not garbled. */ void diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 7e192388..002dd402 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -3799,6 +3799,7 @@ check_valid_name_toplevel(const char *val, const char **port_type, GError **erro gs_unref_ptrarray GPtrArray *tmp_arr = NULL; const NMMetaSettingInfoEditor *setting_info; gs_free_error GError *tmp_err = NULL; + GType gtype = G_TYPE_INVALID; const char *str; int i; @@ -3808,6 +3809,13 @@ check_valid_name_toplevel(const char *val, const char **port_type, GError **erro tmp_arr = g_ptr_array_sized_new(32); for (i = 0; i < _NM_META_SETTING_TYPE_NUM; i++) { setting_info = &nm_meta_setting_infos_editor[i]; + + /* skip "non-base" settings (that means, not valid for a connection's "type") */ + gtype = setting_info->general->get_setting_gtype(); + if (nm_meta_setting_info_get_base_type_priority(setting_info->general, gtype) + == NM_SETTING_PRIORITY_INVALID) + continue; + g_ptr_array_add(tmp_arr, (gpointer) setting_info->general->setting_name); if (setting_info->alias) g_ptr_array_add(tmp_arr, (gpointer) setting_info->alias); @@ -6629,9 +6637,11 @@ get_setting_and_property(const char *prompt, valid_settings_port = nm_meta_setting_info_valid_parts_for_port_type(s_type, NULL); setting_name = check_valid_name(sett, valid_settings_main, valid_settings_port, NULL); - setting = nm_meta_setting_info_editor_new_setting( - nm_meta_setting_info_editor_find_by_name(setting_name, FALSE), - NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT); + if (setting_name) { + setting = nm_meta_setting_info_editor_new_setting( + nm_meta_setting_info_editor_find_by_name(setting_name, FALSE), + NM_META_ACCESSOR_SETTING_INIT_TYPE_DEFAULT); + } } else setting = nm_g_object_ref(nmc_tab_completion.setting); diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index c55f0a39..f6163757 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -2221,6 +2221,13 @@ add_and_activate_cb(GObject *client, GAsyncResult *result, gpointer user_data) return; } + if (nmc->secret_agent) { + NMRemoteConnection *connection = nm_active_connection_get_connection(active); + + nm_secret_agent_simple_enable(nmc->secret_agent, + nm_connection_get_path(NM_CONNECTION(connection))); + } + if (nmc->nmc_config.print_output == NMC_PRINT_PRETTY) progress_id = g_timeout_add(120, progress_cb, info->device); @@ -3662,8 +3669,7 @@ do_device_wifi_connect(const NMCCommand *cmd, NmCli *nmc, int argc, const char * GByteArray *bssid2_arr = NULL; gs_free NMDevice **devices = NULL; int devices_idx; - char *ssid_ask = NULL; - char *passwd_ask = NULL; + char *ssid_ask = NULL; const GPtrArray *avail_cons; gboolean name_match = FALSE; int i; @@ -4021,29 +4027,15 @@ do_device_wifi_connect(const NMCCommand *cmd, NmCli *nmc, int argc, const char * || (ap_rsn_flags != NM_802_11_AP_SEC_NONE && !NM_FLAGS_ANY(ap_rsn_flags, NM_802_11_AP_SEC_KEY_MGMT_OWE | NM_802_11_AP_SEC_KEY_MGMT_OWE_TM))) { - const char *con_password = NULL; - NMSettingWirelessSecurity *s_wsec = NULL; - - if (connection) { - s_wsec = nm_connection_get_setting_wireless_security(connection); - if (s_wsec) { - if (ap_wpa_flags == NM_802_11_AP_SEC_NONE - && ap_rsn_flags == NM_802_11_AP_SEC_NONE) { - /* WEP */ - con_password = nm_setting_wireless_security_get_wep_key(s_wsec, 0); - } else if ((ap_wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK) - || (ap_rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK) - || (ap_rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_SAE)) { - /* WPA PSK */ - con_password = nm_setting_wireless_security_get_psk(s_wsec); - } - } - } - - /* Ask for missing password when one is expected and '--ask' is used */ - if (!password && !con_password && nmc->ask) { - password = passwd_ask = - nmc_readline_echo(&nmc->nmc_config, nmc->nmc_config.show_secrets, _("Password: ")); + NMSettingWirelessSecurity *s_wsec = NULL; + + /* Create secret agent */ + nmc->secret_agent = nm_secret_agent_simple_new("nmcli-connect"); + if (nmc->secret_agent) { + g_signal_connect(nmc->secret_agent, + NM_SECRET_AGENT_SIMPLE_REQUEST_SECRETS, + G_CALLBACK(nmc_secrets_requested), + nmc); } if (password) { @@ -4091,7 +4083,6 @@ finish: if (bssid2_arr) g_byte_array_free(bssid2_arr, TRUE); g_free(ssid_ask); - nm_free_secret(passwd_ask); } static GBytes * diff --git a/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in b/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in index b35a96a4..7f5bc2c7 100644 --- a/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in +++ b/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in @@ -89,6 +89,10 @@ nmcli-description="Configures AP isolation, which prevents communication between wireless devices connected to this AP. This property can be set to a value different from "default" (-1) only when the interface is configured in AP mode. If set to "true" (1), devices are not able to communicate with each other. This increases security because it protects devices against attacks from other clients in the network. At the same time, it prevents devices to access resources on the same wireless networks as file shares, printers, etc. If set to "false" (0), devices can talk to each other. When set to "default" (-1), the global default is used; in case the global default is unspecified it is assumed to be "false" (0)." format="ternary" values="true/yes/on, false/no/off, default/unknown" /> + @@ -1468,7 +1472,7 @@ values="0 - 2147483647" special-values="default (0)" /> argument. * Repeat the part leading to "=". */ - nmc_print("%s=", option); + nmc_print("%s\n", option); + } else { + nmc_print("%.*s%s%s\n", + (int) (last - prefix), + prefix, + name, + nm_streq(last, name) ? "," : ""); } - nmc_print("%.*s%s%s\n", - (int) (last - prefix), - prefix, - name, - strcmp(last, name) == 0 ? "," : ""); } } @@ -225,13 +226,14 @@ complete_option_with_value(const char *option, const char *prefix, ...) va_start(args, prefix); while ((candidate = va_arg(args, const char *))) { if (!*prefix || matches(prefix, candidate)) { - if (option != prefix) { + if (!nm_streq0(option, prefix)) { /* value prefix was not a standalone argument, * it was part of --option= argument. * Repeat the part leading to "=". */ - nmc_print("%s=", option); + nmc_print("%s%s\n", option, candidate + strlen(prefix)); + } else { + nmc_print("%s\n", candidate); } - nmc_print("%s\n", candidate); } } va_end(args); @@ -1044,6 +1046,8 @@ main(int argc, char *argv[]) if (process_command_line(&nm_cli, argc, argv)) g_main_loop_run(loop); + nmc_cleanup_readline(); + if (nm_cli.complete) { /* Remove error statuses from command completion runs. */ if (nm_cli.return_value < NMC_RESULT_COMPLETE_FILE) -- cgit 1.3.0-6-gf8a5