[network-manager-applet: 1/6] wifi-security: Use NMAWs classes instead of WirelessSecurity




commit 5cd875dd699998a95bdd9665598d2c996968e648
Author: Andrew Zaborowski <andrew zaborowski intel com>
Date:   Sat Nov 7 00:35:05 2020 +0100

    wifi-security: Use NMAWs classes instead of WirelessSecurity
    
    This is an almost mechanical conversion to use the NMAWs classes and
    remove the dependency on wireless-security to work around issue #92.
    There may be things in the libnma version that are not taken advantage
    of in this patch, it's just the conversion.
    
    This is still leaking memory as much as it was before.

 src/connection-editor/page-wifi-security.c | 105 +++++++++++++++--------------
 1 file changed, 56 insertions(+), 49 deletions(-)
---
diff --git a/src/connection-editor/page-wifi-security.c b/src/connection-editor/page-wifi-security.c
index 729ad6234..41e2ccdc8 100644
--- a/src/connection-editor/page-wifi-security.c
+++ b/src/connection-editor/page-wifi-security.c
@@ -10,7 +10,7 @@
 
 #include <string.h>
 
-#include "wireless-security.h"
+#include "nma-ws.h"
 #include "page-wifi.h"
 #include "page-wifi-security.h"
 #include "nm-connection-editor.h"
@@ -129,8 +129,10 @@ get_default_type_for_security (NMSettingWirelessSecurity *sec)
                        return NMU_SEC_WPA_ENTERPRISE;
        }
 
+#if NM_CHECK_VERSION(1,22,0)
        if (!strcmp (key_mgmt, "sae"))
                return NMU_SEC_SAE;
+#endif
 
 #if NM_CHECK_VERSION(1,24,0)
        if (!strcmp (key_mgmt, "owe"))
@@ -141,7 +143,7 @@ get_default_type_for_security (NMSettingWirelessSecurity *sec)
 }
 
 static void
-stuff_changed_cb (WirelessSecurity *sec, gpointer user_data)
+stuff_changed_cb (NMAWs *ws, gpointer user_data)
 {
        ce_page_changed (CE_PAGE (user_data));
 }
@@ -160,19 +162,19 @@ wsec_size_group_clear (GtkSizeGroup *group)
        }
 }
 
-static WirelessSecurity *
+static NMAWs *
 wireless_security_combo_get_active (CEPageWifiSecurity *self)
 {
        CEPageWifiSecurityPrivate *priv = CE_PAGE_WIFI_SECURITY_GET_PRIVATE (self);
        GtkTreeIter iter;
        GtkTreeModel *model;
-       WirelessSecurity *sec = NULL;
+       NMAWs *ws = NULL;
 
        model = gtk_combo_box_get_model (priv->security_combo);
        gtk_combo_box_get_active_iter (priv->security_combo, &iter);
-       gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
+       gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &ws, -1);
 
-       return sec;
+       return ws;
 }
 
 static void
@@ -183,7 +185,7 @@ wireless_security_combo_changed (GtkComboBox *combo,
        CEPageWifiSecurityPrivate *priv = CE_PAGE_WIFI_SECURITY_GET_PRIVATE (self);
        GtkWidget *vbox;
        GList *elt, *children;
-       WirelessSecurity *sec;
+       NMAWs *ws;
 
        vbox = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (self)->builder, "wifi_security_vbox"));
        g_assert (vbox);
@@ -195,23 +197,20 @@ wireless_security_combo_changed (GtkComboBox *combo,
        for (elt = children; elt; elt = g_list_next (elt))
                gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data));
 
-       sec = wireless_security_combo_get_active (self);
-       if (sec) {
-               GtkWidget *sec_widget;
+       ws = wireless_security_combo_get_active (self);
+       if (ws) {
                GtkWidget *widget, *parent;
 
-               sec_widget = wireless_security_get_widget (sec);
-               g_assert (sec_widget);
-               parent = gtk_widget_get_parent (sec_widget);
+               parent = gtk_widget_get_parent (GTK_WIDGET (ws));
                if (parent)
-                       gtk_container_remove (GTK_CONTAINER (parent), sec_widget);
+                       gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (ws));
 
                widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (self)->builder, 
"wifi_security_combo_label"));
                gtk_size_group_add_widget (priv->group, widget);
-               wireless_security_add_to_size_group (sec, priv->group);
+               nma_ws_add_to_size_group (ws, priv->group);
 
-               gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
-               wireless_security_unref (sec);
+               gtk_container_add (GTK_CONTAINER (vbox), GTK_WIDGET (ws));
+               g_object_unref (ws);
        }
 
        ce_page_changed (CE_PAGE (self));
@@ -219,22 +218,24 @@ wireless_security_combo_changed (GtkComboBox *combo,
 
 static void
 add_security_item (CEPageWifiSecurity *self,
-                   WirelessSecurity *sec,
+                   NMAWs *ws,
                    GtkListStore *model,
                    GtkTreeIter *iter,
                    const char *text,
                    gboolean adhoc_valid,
                    gboolean hotspot_valid)
 {
-       wireless_security_set_changed_notify (sec, stuff_changed_cb, self);
+       if (G_IS_INITIALLY_UNOWNED (ws))
+               g_object_ref_sink (ws);
+       g_signal_connect (ws, "ws-changed", G_CALLBACK (stuff_changed_cb), self);
        gtk_list_store_append (model, iter);
        gtk_list_store_set (model, iter,
                            S_NAME_COLUMN, text,
-                           S_SEC_COLUMN, sec,
+                           S_SEC_COLUMN, ws,
                            S_ADHOC_VALID_COLUMN, adhoc_valid,
                            S_HOTSPOT_VALID_COLUMN, hotspot_valid,
                            -1);
-       wireless_security_unref (sec);
+       g_object_unref (ws);
 }
 
 static void
@@ -272,8 +273,10 @@ security_valid (NMUtilsSecurityType sectype, NM80211Mode mode)
 
        switch (mode) {
        case NM_802_11_MODE_AP:
+#if NM_CHECK_VERSION(1,22,0)
                if (sectype == NMU_SEC_SAE)
                        return TRUE;
+#endif
                return nm_utils_ap_mode_security_valid (sectype, NM_WIFI_DEVICE_CAP_AP);
        case NM_802_11_MODE_ADHOC:
        case NM_802_11_MODE_INFRA:
@@ -317,7 +320,7 @@ finish_setup (CEPageWifiSecurity *self, gpointer user_data)
        if (s_wireless_sec)
                default_type = get_default_type_for_security (s_wireless_sec);
 
-       sec_model = gtk_list_store_new (4, G_TYPE_STRING, WIRELESS_TYPE_SECURITY, G_TYPE_BOOLEAN, 
G_TYPE_BOOLEAN);
+       sec_model = gtk_list_store_new (4, G_TYPE_STRING, NMA_TYPE_WS, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
 
        if (security_valid (NMU_SEC_NONE, mode)) {
                gtk_list_store_append (sec_model, &iter);
@@ -332,7 +335,7 @@ finish_setup (CEPageWifiSecurity *self, gpointer user_data)
        }
 
        if (security_valid (NMU_SEC_STATIC_WEP, mode)) {
-               WirelessSecurityWEPKey *ws_wep;
+               NMAWsWepKey *ws_wep;
                NMWepKeyType wep_type = NM_WEP_KEY_TYPE_KEY;
 
                if (default_type == NMU_SEC_STATIC_WEP) {
@@ -345,9 +348,9 @@ finish_setup (CEPageWifiSecurity *self, gpointer user_data)
                                wep_type = NM_WEP_KEY_TYPE_KEY;
                }
 
-               ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_KEY, FALSE, FALSE);
+               ws_wep = nma_ws_wep_key_new (connection, NM_WEP_KEY_TYPE_KEY, FALSE, FALSE);
                if (ws_wep) {
-                       add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
+                       add_security_item (self, NMA_WS (ws_wep), sec_model,
                                           &iter, _("WEP 40/128-bit Key (Hex or ASCII)"),
                                           TRUE, TRUE);
                        if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == 
NM_WEP_KEY_TYPE_KEY))
@@ -355,9 +358,9 @@ finish_setup (CEPageWifiSecurity *self, gpointer user_data)
                        item++;
                }
 
-               ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_PASSPHRASE, FALSE, FALSE);
+               ws_wep = nma_ws_wep_key_new (connection, NM_WEP_KEY_TYPE_PASSPHRASE, FALSE, FALSE);
                if (ws_wep) {
-                       add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
+                       add_security_item (self, NMA_WS (ws_wep), sec_model,
                                           &iter, _("WEP 128-bit Passphrase"), TRUE, TRUE);
                        if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == 
NM_WEP_KEY_TYPE_PASSPHRASE))
                                active = item;
@@ -366,11 +369,11 @@ finish_setup (CEPageWifiSecurity *self, gpointer user_data)
        }
 
        if (security_valid (NMU_SEC_LEAP, mode)) {
-               WirelessSecurityLEAP *ws_leap;
+               NMAWsLeap *ws_leap;
 
-               ws_leap = ws_leap_new (connection, FALSE);
+               ws_leap = nma_ws_leap_new (connection, FALSE);
                if (ws_leap) {
-                       add_security_item (self, WIRELESS_SECURITY (ws_leap), sec_model,
+                       add_security_item (self, NMA_WS (ws_leap), sec_model,
                                           &iter, _("LEAP"), FALSE, FALSE);
                        if ((active < 0) && (default_type == NMU_SEC_LEAP))
                                active = item;
@@ -379,11 +382,11 @@ finish_setup (CEPageWifiSecurity *self, gpointer user_data)
        }
 
        if (security_valid (NMU_SEC_DYNAMIC_WEP, mode)) {
-               WirelessSecurityDynamicWEP *ws_dynamic_wep;
+               NMAWsDynamicWep *ws_dynamic_wep;
 
-               ws_dynamic_wep = ws_dynamic_wep_new (connection, TRUE, FALSE);
+               ws_dynamic_wep = nma_ws_dynamic_wep_new (connection, TRUE, FALSE);
                if (ws_dynamic_wep) {
-                       add_security_item (self, WIRELESS_SECURITY (ws_dynamic_wep), sec_model,
+                       add_security_item (self, NMA_WS (ws_dynamic_wep), sec_model,
                                           &iter, _("Dynamic WEP (802.1X)"), FALSE, FALSE);
                        if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP))
                                active = item;
@@ -392,11 +395,11 @@ finish_setup (CEPageWifiSecurity *self, gpointer user_data)
        }
 
        if (security_valid (NMU_SEC_WPA_PSK, mode) || security_valid (NMU_SEC_WPA2_PSK, mode)) {
-               WirelessSecurityWPAPSK *ws_wpa_psk;
+               NMAWsWpaPsk *ws_wpa_psk;
 
-               ws_wpa_psk = ws_wpa_psk_new (connection, FALSE);
+               ws_wpa_psk = nma_ws_wpa_psk_new (connection, FALSE);
                if (ws_wpa_psk) {
-                       add_security_item (self, WIRELESS_SECURITY (ws_wpa_psk), sec_model,
+                       add_security_item (self, NMA_WS (ws_wpa_psk), sec_model,
                                           &iter, _("WPA & WPA2 Personal"), TRUE, TRUE);
                        if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == 
NMU_SEC_WPA2_PSK)))
                                active = item;
@@ -405,11 +408,11 @@ finish_setup (CEPageWifiSecurity *self, gpointer user_data)
        }
 
        if (security_valid (NMU_SEC_WPA_ENTERPRISE, mode) || security_valid (NMU_SEC_WPA2_ENTERPRISE, mode)) {
-               WirelessSecurityWPAEAP *ws_wpa_eap;
+               NMAWsWpaEap *ws_wpa_eap;
 
-               ws_wpa_eap = ws_wpa_eap_new (connection, TRUE, FALSE, NULL);
+               ws_wpa_eap = nma_ws_wpa_eap_new (connection, TRUE, FALSE, NULL);
                if (ws_wpa_eap) {
-                       add_security_item (self, WIRELESS_SECURITY (ws_wpa_eap), sec_model,
+                       add_security_item (self, NMA_WS (ws_wpa_eap), sec_model,
                                           &iter, _("WPA & WPA2 Enterprise"), FALSE, FALSE);
                        if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == 
NMU_SEC_WPA2_ENTERPRISE)))
                                active = item;
@@ -417,18 +420,20 @@ finish_setup (CEPageWifiSecurity *self, gpointer user_data)
                }
        }
 
+#if NM_CHECK_VERSION(1,22,0)
        if (security_valid (NMU_SEC_SAE, mode)) {
-               WirelessSecuritySAE *ws_sae;
+               NMAWsSae *ws_sae;
 
-               ws_sae = ws_sae_new (connection, FALSE);
+               ws_sae = nma_ws_sae_new (connection, FALSE);
                if (ws_sae) {
-                       add_security_item (self, WIRELESS_SECURITY (ws_sae), sec_model,
+                       add_security_item (self, NMA_WS (ws_sae), sec_model,
                                           &iter, _("WPA3 Personal"), TRUE, TRUE);
                        if ((active < 0) && ((default_type == NMU_SEC_SAE)))
                                active = item;
                        item++;
                }
        }
+#endif
 
 #if NM_CHECK_VERSION(1,24,0)
        if (security_valid (NMU_SEC_OWE, mode)) {
@@ -508,7 +513,9 @@ ce_page_wifi_security_new (NMConnectionEditor *editor,
        /* Get secrets if the connection is not 802.1X enabled */
        if (   default_type == NMU_SEC_STATIC_WEP
            || default_type == NMU_SEC_LEAP
+#if NM_CHECK_VERSION(1,22,0)
            || default_type == NMU_SEC_SAE
+#endif
            || default_type == NMU_SEC_WPA_PSK
            || default_type == NMU_SEC_WPA2_PSK) {
                *out_secrets_setting_name = NM_SETTING_WIRELESS_SECURITY_SETTING_NAME;
@@ -550,7 +557,7 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
        CEPageWifiSecurity *self = CE_PAGE_WIFI_SECURITY (page);
        CEPageWifiSecurityPrivate *priv = CE_PAGE_WIFI_SECURITY_GET_PRIVATE (self);
        NMSettingWireless *s_wireless;
-       WirelessSecurity *sec;
+       NMAWs *ws;
        gboolean valid = FALSE;
        const char *mode;
 
@@ -565,27 +572,27 @@ ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error)
        else
                priv->mode = NM_802_11_MODE_INFRA;
 
-       sec = wireless_security_combo_get_active (self);
-       if (sec) {
+       ws = wireless_security_combo_get_active (self);
+       if (ws) {
                GBytes *ssid = nm_setting_wireless_get_ssid (s_wireless);
 
                if (ssid) {
-                       valid = wireless_security_validate (sec, error);
+                       valid = nma_ws_validate (ws, error);
                        if (valid)
-                               wireless_security_fill_connection (sec, connection);
+                               nma_ws_fill_connection (ws, connection);
                } else {
                        g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing SSID"));
                        valid = FALSE;
                }
 
                if (priv->mode == NM_802_11_MODE_ADHOC) {
-                       if (!wireless_security_adhoc_compatible (sec)) {
+                       if (!nma_ws_adhoc_compatible (ws)) {
                                g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Security not compatible 
with Ad-Hoc mode"));
                                valid = FALSE;
                        }
                }
 
-               wireless_security_unref (sec);
+               g_object_unref (ws);
        } else {
                /* No security, unencrypted */
                nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]