From 91a460c0b4b18acfa2e9c11edd21de62189ce760 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 30 Nov 2017 16:37:24 +0100 Subject: [PATCH] tui: fix creation of open Wi-Fi connections Commit 6a4af482f02c ("nmtui: always create ethernet settings for VLAN and wireless security for wifi.") changed nmtui to always add the wireless security setting to the new connection, but without initializing it. This leads to a crash that was fixed in 40fcf67a8415 ("tui: fix crash creating Wi-Fi connection"). There is an additional bug: connections without authentication can't be saved because the wireless security setting has uninitialized fields. To fix this, revert both patches (the first partially) because the previous code did the right thing as it added the setting only when needed. Fixes: 6a4af482f02c4342c69cd38dd46c078aeaf60d0d https://bugzilla.redhat.com/show_bug.cgi?id=1518167 (cherry picked from commit fead82f4192c24eb017eac405f98ccb02402453f) --- clients/tui/nm-editor-bindings.c | 3 --- clients/tui/nmt-page-wifi.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/clients/tui/nm-editor-bindings.c b/clients/tui/nm-editor-bindings.c index 647ac8df17..24803868e5 100644 --- a/clients/tui/nm-editor-bindings.c +++ b/clients/tui/nm-editor-bindings.c @@ -585,9 +585,6 @@ get_security_type (NMEditorWirelessSecurityMethodBinding *binding) return "none"; key_mgmt = nm_setting_wireless_security_get_key_mgmt (binding->s_wsec); - if (!key_mgmt) - return "none"; - auth_alg = nm_setting_wireless_security_get_auth_alg (binding->s_wsec); /* No IEEE 802.1x */ diff --git a/clients/tui/nmt-page-wifi.c b/clients/tui/nmt-page-wifi.c index f846345c69..35625fe4c7 100644 --- a/clients/tui/nmt-page-wifi.c +++ b/clients/tui/nmt-page-wifi.c @@ -38,6 +38,13 @@ G_DEFINE_TYPE (NmtPageWifi, nmt_page_wifi, NMT_TYPE_EDITOR_PAGE_DEVICE) +#define NMT_PAGE_WIFI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_WIFI, NmtPageWifiPrivate)) + +typedef struct { + NMSettingWirelessSecurity *s_wsec; + +} NmtPageWifiPrivate; + NmtEditorPage * nmt_page_wifi_new (NMConnection *conn, NmtDeviceEntry *deventry) @@ -170,6 +177,7 @@ ssid_transform_from_entry (GBinding *binding, static void nmt_page_wifi_constructed (GObject *object) { + NmtPageWifiPrivate *priv = NMT_PAGE_WIFI_GET_PRIVATE (object); NmtPageWifi *wifi = NMT_PAGE_WIFI (object); NmtDeviceEntry *deventry; NmtEditorSection *section; @@ -190,9 +198,13 @@ nmt_page_wifi_constructed (GObject *object) s_wsec = nm_connection_get_setting_wireless_security (conn); if (!s_wsec) { - nm_connection_add_setting (conn, nm_setting_wireless_security_new ()); - s_wsec = nm_connection_get_setting_wireless_security (conn); + /* It makes things simpler if we always have a + * NMSettingWirelessSecurity; we'll hold a ref on one, and add + * it to and remove it from the connection as needed. + */ + s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ()); } + priv->s_wsec = g_object_ref_sink (s_wsec); deventry = nmt_editor_page_device_get_device_entry (NMT_EDITOR_PAGE_DEVICE (object)); g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS, @@ -362,10 +374,24 @@ nmt_page_wifi_constructed (GObject *object) G_OBJECT_CLASS (nmt_page_wifi_parent_class)->constructed (object); } +static void +nmt_page_wifi_finalize (GObject *object) +{ + NmtPageWifiPrivate *priv = NMT_PAGE_WIFI_GET_PRIVATE (object); + + g_clear_object (&priv->s_wsec); + + G_OBJECT_CLASS (nmt_page_wifi_parent_class)->finalize (object); +} + + static void nmt_page_wifi_class_init (NmtPageWifiClass *wifi_class) { GObjectClass *object_class = G_OBJECT_CLASS (wifi_class); + g_type_class_add_private (wifi_class, sizeof (NmtPageWifiPrivate)); + object_class->constructed = nmt_page_wifi_constructed; + object_class->finalize = nmt_page_wifi_finalize; }