From bda21d12f9e8131650180bfbab6e7343402d763a Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 12 May 2022 12:30:58 +0200 Subject: [PATCH 1/3] nmcli/connections: export nmc_connection_check_deprecated() It's going to be useful with "nmcli dev wifi connect" that also creates a connection that should be checked. --- src/nmcli/connections.c | 11 ++++++----- src/nmcli/connections.h | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 648583eb1d..4d9f662bf5 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -639,8 +639,8 @@ _con_show_fcn_get_type(NMConnection *c, NMActiveConnection *ac, NMMetaAccessorGe return connection_type_to_display(s, get_type); } -static const char * -_connection_check_deprecated(NMConnection *c) +const char * +nmc_connection_check_deprecated(NMConnection *c) { NMSettingWirelessSecurity *s_wsec; const char *key_mgmt; @@ -667,7 +667,7 @@ _connection_to_color(NMConnection *c, NMActiveConnection *ac) if (ac) return nmc_active_connection_state_to_color(ac); - if (_connection_check_deprecated(c)) + if (nmc_connection_check_deprecated(c)) return NM_META_COLOR_CONNECTION_DEPRECATED; return NM_META_COLOR_CONNECTION_UNKNOWN; @@ -2039,7 +2039,8 @@ con_show_get_items_cmp(gconstpointer pa, gconstpointer pb, gpointer user_data) } } - NM_CMP_DIRECT(!!_connection_check_deprecated(c_a), !!_connection_check_deprecated(c_b)); + NM_CMP_DIRECT(!!nmc_connection_check_deprecated(c_a), + !!nmc_connection_check_deprecated(c_b)); NM_CMP_DIRECT_STRCMP0(nm_connection_get_uuid(c_a), nm_connection_get_uuid(c_b)); NM_CMP_DIRECT_STRCMP0(nm_connection_get_path(c_a), nm_connection_get_path(c_b)); } @@ -5381,7 +5382,7 @@ connection_warnings(NmCli *nmc, NMConnection *connection) const char *id; const char *deprecated; - deprecated = _connection_check_deprecated(NM_CONNECTION(connection)); + deprecated = nmc_connection_check_deprecated(NM_CONNECTION(connection)); if (deprecated) g_printerr(_("Warning: %s.\n"), deprecated); diff --git a/src/nmcli/connections.h b/src/nmcli/connections.h index 782c4eafca..c610766a62 100644 --- a/src/nmcli/connections.h +++ b/src/nmcli/connections.h @@ -10,6 +10,8 @@ void monitor_connections(NmCli *nmc); +const char *nmc_connection_check_deprecated(NMConnection *c); + gboolean nmc_process_connection_properties(NmCli *nmc, NMConnection *connection, int *argc, -- GitLab From 94154fd8242276ee27c0075f965329f8566bdd95 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 12 May 2022 12:31:32 +0200 Subject: [PATCH 2/3] nmcli/devices: check connection created with "wifi connect" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to warn the user if they're connecting to an insecure network: $ nmcli d wifi IN-USE BSSID SSID MODE CHAN RATE SIGNAL BARS SECURITY BA:00:6A:3C:C2:09 Secured Network Infra 2 54 Mbit/s 100 ▂▄▆█ WPA3 FA:7C:46:CC:9F:BE Ye Olde Wlan Infra 1 54 Mbit/s 100 ▂▄▆█ WEP $ nmcli d wifi connect 'Ye Olde Wlan' Warning: WEP encryption is known to be insecure. ... --- src/nmcli/devices.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index 2bfc4cece3..8a4e942281 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -2127,6 +2127,7 @@ add_and_activate_cb(GObject *client, GAsyncResult *result, gpointer user_data) NmCli *nmc = info->nmc; gs_unref_object NMActiveConnection *active = NULL; gs_free_error GError *error = NULL; + const char *deprecated; if (info->create) active = nm_client_add_and_activate_connection_finish(NM_CLIENT(client), result, &error); @@ -2152,6 +2153,11 @@ add_and_activate_cb(GObject *client, GAsyncResult *result, gpointer user_data) return; } + deprecated = + nmc_connection_check_deprecated(NM_CONNECTION(nm_active_connection_get_connection(active))); + if (deprecated) + g_printerr(_("Warning: %s.\n"), deprecated); + if (nmc->nowait_flag) { quit(); return; -- GitLab From 5bccfef88ebce83ddb04a72e42256147dfac82d8 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 12 May 2022 12:32:50 +0200 Subject: [PATCH 3/3] nmcli/devices: fix sorting of APs Sort WEP access points as intended -- down, not up. Fixes: 550e3bbdd8f5 ('cli: device: color WEP APs differently in "wifi list"') --- src/nmcli/devices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index 8a4e942281..6fce9de731 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -1238,7 +1238,7 @@ compare_aps(gconstpointer a, gconstpointer b, gpointer user_data) NMAccessPoint *apb = *(NMAccessPoint **) b; /* Sort the deprecated WEP connections last. */ - NM_CMP_DIRECT(_ap_is_wep(apb), _ap_is_wep(apa)); + NM_CMP_DIRECT(_ap_is_wep(apa), _ap_is_wep(apb)); NM_CMP_DIRECT(nm_access_point_get_strength(apb), nm_access_point_get_strength(apa)); NM_CMP_DIRECT(nm_access_point_get_frequency(apa), nm_access_point_get_frequency(apb)); -- GitLab