[libnma/ignore-ca] utils: make nma_utils_ca_cert_ignore_{save, load} available




commit 962ef066abc983d2cbe0e579310c71dbfea1ad24
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Tue Oct 4 13:48:42 2022 +0200

    utils: make nma_utils_ca_cert_ignore_{save,load} available
    
    These save/restore UI hints about CA certificate for a NMConnection in
    GSettings.
    
    Both the connection editor and g-c-c need this, let's make it available so
    that they'll be able to stop reaching into our GSettings directly.

 src/libnma.ver        |   5 ++
 src/nma-private.h     |   3 ++
 src/nma-ui-utils.c    | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/nma-ui-utils.h    |   4 +-
 src/nma-wifi-dialog.c |   7 +--
 src/nma-ws/nma-eap.c  | 112 ++-------------------------------------
 6 files changed, 162 insertions(+), 112 deletions(-)
---
diff --git a/src/libnma.ver b/src/libnma.ver
index dd9e33e7..4ef21135 100644
--- a/src/libnma.ver
+++ b/src/libnma.ver
@@ -139,3 +139,8 @@ libnma_1_8_36 {
        nma_ws_owe_get_type;
        nma_ws_owe_new;
 } libnma_1_8_28;
+
+libnma_1_10_4 {
+       nma_utils_ca_cert_ignore_load;
+       nma_utils_ca_cert_ignore_save;
+} libnma_1_8_36;
diff --git a/src/nma-private.h b/src/nma-private.h
index 254bb639..817f5cf0 100644
--- a/src/nma-private.h
+++ b/src/nma-private.h
@@ -30,6 +30,9 @@ typedef void GtkRoot;
 
 int nma_gtk_dialog_run (GtkDialog *dialog);
 
+void nma_utils_ca_cert_ignore_set (NMConnection *connection, gboolean phase2, gboolean ignore);
+gboolean nma_utils_ca_cert_ignore_get (NMConnection *connection, gboolean phase2);
+
 #define NMA_PRIVATE_H
 
 #endif /* NMA_PRIVATE_H */
diff --git a/src/nma-ui-utils.c b/src/nma-ui-utils.c
index 8013760a..6b767e65 100644
--- a/src/nma-ui-utils.c
+++ b/src/nma-ui-utils.c
@@ -457,3 +457,146 @@ nma_gtk_dialog_run (GtkDialog *dialog)
 
        return data.response_id;
 }
+
+/*---------------------------------------------------------------------------*/
+
+/* Used as both GSettings keys and GObject data tags */
+#define IGNORE_CA_CERT_TAG "ignore-ca-cert"
+#define IGNORE_PHASE2_CA_CERT_TAG "ignore-phase2-ca-cert"
+
+/**
+ * nma_utils_ca_cert_ignore_set:
+ * @phase2: EAP method phase
+ * @connection: the #NMConnection
+ * @filename: the certificate file, if any
+ * @ca_cert_error: %TRUE if an error was encountered loading the given CA
+ * certificate, %FALSE if not or if a CA certificate is not present
+ *
+ * Updates the connection's CA cert ignore value to %TRUE if the "CA certificate
+ * not required" checkbox is checked.  If @ca_cert_error is %TRUE, then the
+ * connection's CA cert ignore value will always be set to %FALSE, because it
+ * means that the user selected an invalid certificate (thus he does not want to
+ * ignore the CA cert)..
+ */
+void
+nma_utils_ca_cert_ignore_set (NMConnection *connection,
+                              gboolean phase2,
+                              gboolean ignore)
+{
+       NMSetting8021x *s_8021x;
+
+       s_8021x = nm_connection_get_setting_802_1x (connection);
+       if (s_8021x) {
+               g_object_set_data (G_OBJECT (s_8021x),
+                                  phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG,
+                                  GUINT_TO_POINTER (ignore));
+       }
+}
+
+/**
+ * nma_utils_ca_cert_ignore_get:
+ * @phase2: EAP method phase
+ * @connection: the #NMConnection
+ *
+ * Returns: %TRUE if a missing CA certificate can be ignored, %FALSE if a CA
+ * certificate should be required for the connection to be valid.
+ */
+gboolean
+nma_utils_ca_cert_ignore_get (NMConnection *connection,
+                              gboolean phase2)
+{
+       NMSetting8021x *s_8021x;
+
+       s_8021x = nm_connection_get_setting_802_1x (connection);
+       if (s_8021x) {
+               return !!g_object_get_data (G_OBJECT (s_8021x),
+                                           phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG);
+       }
+       return FALSE;
+}
+
+static GSettings *
+_get_ca_ignore_settings (NMConnection *connection)
+{
+       GSettings *settings;
+       char *path = NULL;
+       const char *uuid;
+
+       g_return_val_if_fail (connection, NULL);
+
+       uuid = nm_connection_get_uuid (connection);
+       g_return_val_if_fail (uuid && *uuid, NULL);
+
+       path = g_strdup_printf ("/org/gnome/nm-applet/eap/%s/", uuid);
+       settings = g_settings_new_with_path ("org.gnome.nm-applet.eap", path);
+       g_free (path);
+
+       return settings;
+}
+
+/**
+ * nma_utils_ca_cert_ignore_save:
+ * @connection: the connection for which to save CA cert ignore values to GSettings
+ *
+ * Reads the CA cert ignore tags from the 802.1x setting GObject data and saves
+ * then to GSettings if present, using the connection UUID as the index.
+ */
+void
+nma_utils_ca_cert_ignore_save (NMConnection *connection)
+{
+       NMSetting8021x *s_8021x;
+       GSettings *settings;
+       gboolean ignore = FALSE, phase2_ignore = FALSE;
+
+       g_return_if_fail (connection);
+
+       s_8021x = nm_connection_get_setting_802_1x (connection);
+       if (s_8021x) {
+               ignore = !!g_object_get_data (G_OBJECT (s_8021x), IGNORE_CA_CERT_TAG);
+               phase2_ignore = !!g_object_get_data (G_OBJECT (s_8021x), IGNORE_PHASE2_CA_CERT_TAG);
+       }
+
+       settings = _get_ca_ignore_settings (connection);
+       if (!settings)
+               return;
+
+       g_settings_set_boolean (settings, IGNORE_CA_CERT_TAG, ignore);
+       g_settings_set_boolean (settings, IGNORE_PHASE2_CA_CERT_TAG, phase2_ignore);
+       g_object_unref (settings);
+}
+
+/**
+ * nma_utils_ca_cert_ignore_load:
+ * @connection: the connection for which to load CA cert ignore values to GSettings
+ *
+ * Reads the CA cert ignore tags from the 802.1x setting GObject data and saves
+ * then to GSettings if present, using the connection UUID as the index.
+ */
+void
+nma_utils_ca_cert_ignore_load (NMConnection *connection)
+{
+       GSettings *settings;
+       NMSetting8021x *s_8021x;
+       gboolean ignore, phase2_ignore;
+
+       g_return_if_fail (connection);
+
+       s_8021x = nm_connection_get_setting_802_1x (connection);
+       if (!s_8021x)
+               return;
+
+       settings = _get_ca_ignore_settings (connection);
+       if (!settings)
+               return;
+
+       ignore = g_settings_get_boolean (settings, IGNORE_CA_CERT_TAG);
+       phase2_ignore = g_settings_get_boolean (settings, IGNORE_PHASE2_CA_CERT_TAG);
+
+       g_object_set_data (G_OBJECT (s_8021x),
+                          IGNORE_CA_CERT_TAG,
+                          GUINT_TO_POINTER (ignore));
+       g_object_set_data (G_OBJECT (s_8021x),
+                          IGNORE_PHASE2_CA_CERT_TAG,
+                          GUINT_TO_POINTER (phase2_ignore));
+       g_object_unref (settings);
+}
diff --git a/src/nma-ui-utils.h b/src/nma-ui-utils.h
index bde5f487..e2cc28fd 100644
--- a/src/nma-ui-utils.h
+++ b/src/nma-ui-utils.h
@@ -22,5 +22,7 @@ void nma_utils_update_password_storage (GtkWidget *passwd_entry,
                                         NMSetting *setting,
                                         const char *password_flags_name);
 
-#endif /* NMA_UI_UTILS_H */
+void nma_utils_ca_cert_ignore_load (NMConnection *connection);
+void nma_utils_ca_cert_ignore_save (NMConnection *connection);
 
+#endif /* NMA_UI_UTILS_H */
diff --git a/src/nma-wifi-dialog.c b/src/nma-wifi-dialog.c
index d2802b27..4222f333 100644
--- a/src/nma-wifi-dialog.c
+++ b/src/nma-wifi-dialog.c
@@ -17,6 +17,7 @@
 #include "nma-wifi-dialog.h"
 #include "nma-ws.h"
 #include "nma-eap.h"
+#include "nma-ui-utils.h"
 
 G_DEFINE_TYPE (NMAWifiDialog, nma_wifi_dialog, GTK_TYPE_DIALOG)
 
@@ -349,7 +350,7 @@ connection_combo_changed (GtkWidget *combo,
                            C_NEW_COLUMN, &is_new, -1);
 
        if (priv->connection)
-               nma_eap_ca_cert_ignore_load (priv->connection);
+               nma_utils_ca_cert_ignore_load (priv->connection);
 
        if (!security_combo_init (self, priv->secrets_only, NULL, NULL)) {
                g_warning ("Couldn't change Wi-Fi security combo box.");
@@ -1317,7 +1318,7 @@ nma_wifi_dialog_get_connection (NMAWifiDialog *self,
        }
 
        /* Save new CA cert ignore values to GSettings */
-       nma_eap_ca_cert_ignore_save (connection);
+       nma_utils_ca_cert_ignore_save (connection);
 
        /* Fill device */
        if (device) {
@@ -1360,7 +1361,7 @@ internal_new_dialog (NMClient *client,
                priv->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
                /* Handle CA cert ignore stuff */
-               nma_eap_ca_cert_ignore_load (connection);
+               nma_utils_ca_cert_ignore_load (connection);
 
                if (!internal_init (self, connection, device, secrets_only, secrets_setting_name, 
secrets_hints)) {
                        g_warning ("Couldn't create Wi-Fi security dialog.");
diff --git a/src/nma-ws/nma-eap.c b/src/nma-ws/nma-eap.c
index f666dab9..49ff3c50 100644
--- a/src/nma-ws/nma-eap.c
+++ b/src/nma-ws/nma-eap.c
@@ -6,6 +6,7 @@
  */
 
 #include "nm-default.h"
+#include "nma-private.h"
 
 #include <string.h>
 #include <sys/types.h>
@@ -188,10 +189,6 @@ nma_eap_unref (NMAEap *method)
        }
 }
 
-/* Used as both GSettings keys and GObject data tags */
-#define IGNORE_CA_CERT_TAG "ignore-ca-cert"
-#define IGNORE_PHASE2_CA_CERT_TAG "ignore-phase2-ca-cert"
-
 /**
  * nma_eap_ca_cert_ignore_set:
  * @method: the #NMAEap object
@@ -212,16 +209,8 @@ nma_eap_ca_cert_ignore_set (NMAEap *method,
                             const char *filename,
                             gboolean ca_cert_error)
 {
-       NMSetting8021x *s_8021x;
-       gboolean ignore;
-
-       s_8021x = nm_connection_get_setting_802_1x (connection);
-       if (s_8021x) {
-               ignore = !ca_cert_error && filename == NULL;
-               g_object_set_data (G_OBJECT (s_8021x),
-                                  method->phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG,
-                                  GUINT_TO_POINTER (ignore));
-       }
+       nma_utils_ca_cert_ignore_set (connection, method->phase2,
+                                     !ca_cert_error && filename == NULL);
 }
 
 /**
@@ -235,100 +224,7 @@ nma_eap_ca_cert_ignore_set (NMAEap *method,
 gboolean
 nma_eap_ca_cert_ignore_get (NMAEap *method, NMConnection *connection)
 {
-       NMSetting8021x *s_8021x;
-
-       s_8021x = nm_connection_get_setting_802_1x (connection);
-       if (s_8021x) {
-               return !!g_object_get_data (G_OBJECT (s_8021x),
-                                           method->phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG);
-       }
-       return FALSE;
-}
-
-static GSettings *
-_get_ca_ignore_settings (NMConnection *connection)
-{
-       GSettings *settings;
-       char *path = NULL;
-       const char *uuid;
-
-       g_return_val_if_fail (connection, NULL);
-
-       uuid = nm_connection_get_uuid (connection);
-       g_return_val_if_fail (uuid && *uuid, NULL);
-
-       path = g_strdup_printf ("/org/gnome/nm-applet/eap/%s/", uuid);
-       settings = g_settings_new_with_path ("org.gnome.nm-applet.eap", path);
-       g_free (path);
-
-       return settings;
-}
-
-/**
- * nma_eap_ca_cert_ignore_save:
- * @connection: the connection for which to save CA cert ignore values to GSettings
- *
- * Reads the CA cert ignore tags from the 802.1x setting GObject data and saves
- * then to GSettings if present, using the connection UUID as the index.
- */
-void
-nma_eap_ca_cert_ignore_save (NMConnection *connection)
-{
-       NMSetting8021x *s_8021x;
-       GSettings *settings;
-       gboolean ignore = FALSE, phase2_ignore = FALSE;
-
-       g_return_if_fail (connection);
-
-       s_8021x = nm_connection_get_setting_802_1x (connection);
-       if (s_8021x) {
-               ignore = !!g_object_get_data (G_OBJECT (s_8021x), IGNORE_CA_CERT_TAG);
-               phase2_ignore = !!g_object_get_data (G_OBJECT (s_8021x), IGNORE_PHASE2_CA_CERT_TAG);
-       }
-
-       settings = _get_ca_ignore_settings (connection);
-       if (!settings)
-               return;
-
-       g_settings_set_boolean (settings, IGNORE_CA_CERT_TAG, ignore);
-       g_settings_set_boolean (settings, IGNORE_PHASE2_CA_CERT_TAG, phase2_ignore);
-       g_object_unref (settings);
-}
-
-/**
- * nma_eap_ca_cert_ignore_load:
- * @connection: the connection for which to load CA cert ignore values to GSettings
- *
- * Reads the CA cert ignore tags from the 802.1x setting GObject data and saves
- * then to GSettings if present, using the connection UUID as the index.
- */
-void
-nma_eap_ca_cert_ignore_load (NMConnection *connection)
-{
-       GSettings *settings;
-       NMSetting8021x *s_8021x;
-       gboolean ignore, phase2_ignore;
-
-       g_return_if_fail (connection);
-
-       s_8021x = nm_connection_get_setting_802_1x (connection);
-       if (!s_8021x)
-               return;
-
-       settings = _get_ca_ignore_settings (connection);
-       if (!settings)
-               return;
-
-       ignore = g_settings_get_boolean (settings, IGNORE_CA_CERT_TAG);
-       phase2_ignore = g_settings_get_boolean (settings, IGNORE_PHASE2_CA_CERT_TAG);
-
-       g_object_set_data (G_OBJECT (s_8021x),
-                          IGNORE_CA_CERT_TAG,
-                          GUINT_TO_POINTER (ignore));
-       g_object_set_data (G_OBJECT (s_8021x),
-                          IGNORE_PHASE2_CA_CERT_TAG,
-                          GUINT_TO_POINTER (phase2_ignore));
-       g_object_unref (settings);
+       return nma_utils_ca_cert_ignore_get (connection, method->phase2);
 }
 
 GError *


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