summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2019-11-11 14:03:47 +1300
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>2019-11-27 22:05:46 +0000
commitc8231a5099c9cc797b12beabcd5fdec27481a778 (patch)
treef5a6c43956aef52b8912851f4caca7d58ca28090
parent90c190dd5c9c92fff67ce0e660e66d2436e862ff (diff)
downloadgnome-control-center-c8231a5099c9cc797b12beabcd5fdec27481a778.tar.gz
network: Simplify TTLS inner auth widgets
-rw-r--r--panels/network/wireless-security/eap-method-ttls.c340
-rw-r--r--panels/network/wireless-security/eap-method-ttls.ui35
2 files changed, 160 insertions, 215 deletions
diff --git a/panels/network/wireless-security/eap-method-ttls.c b/panels/network/wireless-security/eap-method-ttls.c
index 531528c07..207c96ad3 100644
--- a/panels/network/wireless-security/eap-method-ttls.c
+++ b/panels/network/wireless-security/eap-method-ttls.c
@@ -31,8 +31,8 @@
#include "wireless-security.h"
#include "utils.h"
-#define I_NAME_COLUMN 0
-#define I_METHOD_COLUMN 1
+#define I_NAME_COLUMN 0
+#define I_ID_COLUMN 1
struct _EAPMethodTTLS {
GtkGrid parent;
@@ -46,9 +46,17 @@ struct _EAPMethodTTLS {
GtkLabel *domain_match_label;
GtkComboBox *inner_auth_combo;
GtkLabel *inner_auth_label;
+ GtkListStore *inner_auth_model;
GtkBox *inner_auth_box;
- GtkSizeGroup *size_group;
+ EAPMethodSimple *em_chap;
+ EAPMethodSimple *em_gtc;
+ EAPMethodSimple *em_md5;
+ EAPMethodSimple *em_mschap;
+ EAPMethodSimple *em_mschap_v2;
+ EAPMethodSimple *em_pap;
+ EAPMethodSimple *em_plain_mschap_v2;
+
WirelessSecurity *sec_parent;
gboolean is_editor;
};
@@ -58,24 +66,38 @@ static void eap_method_iface_init (EAPMethodInterface *);
G_DEFINE_TYPE_WITH_CODE (EAPMethodTTLS, eap_method_ttls, GTK_TYPE_GRID,
G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init))
-static void
-eap_method_ttls_dispose (GObject *object)
+static EAPMethod *
+get_inner_method (EAPMethodTTLS *self)
{
- EAPMethodTTLS *self = EAP_METHOD_TTLS (object);
-
- g_clear_object (&self->size_group);
-
- G_OBJECT_CLASS (eap_method_ttls_parent_class)->dispose (object);
+ GtkTreeIter iter;
+ g_autofree gchar *id = NULL;
+
+ if (!gtk_combo_box_get_active_iter (self->inner_auth_combo, &iter))
+ return NULL;
+ gtk_tree_model_get (GTK_TREE_MODEL (self->inner_auth_model), &iter, I_ID_COLUMN, &id, -1);
+
+ if (strcmp (id, "chap") == 0)
+ return EAP_METHOD (self->em_chap);
+ if (strcmp (id, "gtc") == 0)
+ return EAP_METHOD (self->em_gtc);
+ if (strcmp (id, "md5") == 0)
+ return EAP_METHOD (self->em_md5);
+ if (strcmp (id, "mschap") == 0)
+ return EAP_METHOD (self->em_mschap);
+ if (strcmp (id, "mschapv2") == 0)
+ return EAP_METHOD (self->em_mschap_v2);
+ if (strcmp (id, "pap") == 0)
+ return EAP_METHOD (self->em_pap);
+ if (strcmp (id, "plain_mschapv2") == 0)
+ return EAP_METHOD (self->em_plain_mschap_v2);
+
+ return NULL;
}
static gboolean
validate (EAPMethod *method, GError **error)
{
EAPMethodTTLS *self = EAP_METHOD_TTLS (method);
- GtkTreeModel *model;
- GtkTreeIter iter;
- g_autoptr(EAPMethod) eap = NULL;
- gboolean valid = FALSE;
g_autoptr(GError) local_error = NULL;
if (!eap_method_validate_filepicker (GTK_FILE_CHOOSER (self->ca_cert_button),
@@ -89,12 +111,7 @@ validate (EAPMethod *method, GError **error)
return FALSE;
}
- model = gtk_combo_box_get_model (self->inner_auth_combo);
- gtk_combo_box_get_active_iter (self->inner_auth_combo, &iter);
- gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
- g_assert (eap);
- valid = eap_method_validate (eap, error);
- return valid;
+ return eap_method_validate (get_inner_method (self), error);
}
static void
@@ -109,12 +126,6 @@ static void
add_to_size_group (EAPMethod *method, GtkSizeGroup *group)
{
EAPMethodTTLS *self = EAP_METHOD_TTLS (method);
- GtkTreeModel *model;
- GtkTreeIter iter;
- g_autoptr(EAPMethod) eap = NULL;
-
- g_clear_object (&self->size_group);
- self->size_group = g_object_ref (group);
gtk_size_group_add_widget (group, GTK_WIDGET (self->ca_cert_not_required_check));
gtk_size_group_add_widget (group, GTK_WIDGET (self->anon_identity_label));
@@ -122,11 +133,13 @@ add_to_size_group (EAPMethod *method, GtkSizeGroup *group)
gtk_size_group_add_widget (group, GTK_WIDGET (self->ca_cert_label));
gtk_size_group_add_widget (group, GTK_WIDGET (self->inner_auth_label));
- model = gtk_combo_box_get_model (self->inner_auth_combo);
- gtk_combo_box_get_active_iter (self->inner_auth_combo, &iter);
- gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
- g_assert (eap);
- eap_method_add_to_size_group (eap, group);
+ eap_method_add_to_size_group (EAP_METHOD (self->em_chap), group);
+ eap_method_add_to_size_group (EAP_METHOD (self->em_gtc), group);
+ eap_method_add_to_size_group (EAP_METHOD (self->em_md5), group);
+ eap_method_add_to_size_group (EAP_METHOD (self->em_mschap), group);
+ eap_method_add_to_size_group (EAP_METHOD (self->em_mschap_v2), group);
+ eap_method_add_to_size_group (EAP_METHOD (self->em_pap), group);
+ eap_method_add_to_size_group (EAP_METHOD (self->em_plain_mschap_v2), group);
}
static void
@@ -137,9 +150,6 @@ fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFla
NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
const char *text;
g_autofree gchar *filename = NULL;
- g_autoptr(EAPMethod) eap = NULL;
- GtkTreeModel *model;
- GtkTreeIter iter;
g_autoptr(GError) error = NULL;
gboolean ca_cert_error = FALSE;
@@ -163,199 +173,37 @@ fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFla
}
eap_method_ca_cert_ignore_set (method, connection, filename, ca_cert_error);
- model = gtk_combo_box_get_model (self->inner_auth_combo);
- gtk_combo_box_get_active_iter (self->inner_auth_combo, &iter);
- gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
- g_assert (eap);
-
- eap_method_fill_connection (eap, connection, flags);
+ eap_method_fill_connection (get_inner_method (self), connection, flags);
}
static void
inner_auth_combo_changed_cb (EAPMethodTTLS *self)
{
- g_autoptr(EAPMethod) eap = NULL;
+ EAPMethod *inner_method;
GList *elt, *children;
- GtkTreeModel *model;
- GtkTreeIter iter;
- /* Remove any previous wireless security widgets */
children = gtk_container_get_children (GTK_CONTAINER (self->inner_auth_box));
for (elt = children; elt; elt = g_list_next (elt))
gtk_container_remove (GTK_CONTAINER (self->inner_auth_box), GTK_WIDGET (elt->data));
- g_list_free (children);
-
- model = gtk_combo_box_get_model (self->inner_auth_combo);
- gtk_combo_box_get_active_iter (self->inner_auth_combo, &iter);
- gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
- g_assert (eap);
- gtk_widget_unparent (GTK_WIDGET (eap));
- if (self->size_group)
- eap_method_add_to_size_group (eap, self->size_group);
- gtk_widget_show (GTK_WIDGET (eap));
- gtk_container_add (GTK_CONTAINER (self->inner_auth_box), g_object_ref (GTK_WIDGET (eap)));
+ inner_method = get_inner_method (self);
+ gtk_container_add (GTK_CONTAINER (self->inner_auth_box), g_object_ref (GTK_WIDGET (inner_method)));
wireless_security_notify_changed (self->sec_parent);
}
static void
-inner_auth_combo_init (EAPMethodTTLS *self,
- NMConnection *connection,
- NMSetting8021x *s_8021x,
- gboolean secrets_only)
-{
- g_autoptr(GtkListStore) auth_model = NULL;
- GtkTreeIter iter;
- g_autoptr(EAPMethodSimple) em_pap = NULL;
- g_autoptr(EAPMethodSimple) em_mschap = NULL;
- g_autoptr(EAPMethodSimple) em_mschap_v2 = NULL;
- g_autoptr(EAPMethodSimple) em_plain_mschap_v2 = NULL;
- g_autoptr(EAPMethodSimple) em_chap = NULL;
- g_autoptr(EAPMethodSimple) em_md5 = NULL;
- g_autoptr(EAPMethodSimple) em_gtc = NULL;
- guint32 active = 0;
- const char *phase2_auth = NULL;
- EAPMethodSimpleFlags simple_flags;
-
- auth_model = gtk_list_store_new (2, G_TYPE_STRING, eap_method_get_type ());
-
- if (s_8021x) {
- if (nm_setting_802_1x_get_phase2_auth (s_8021x))
- phase2_auth = nm_setting_802_1x_get_phase2_auth (s_8021x);
- else if (nm_setting_802_1x_get_phase2_autheap (s_8021x))
- phase2_auth = nm_setting_802_1x_get_phase2_autheap (s_8021x);
- }
-
- simple_flags = EAP_METHOD_SIMPLE_FLAG_PHASE2 | EAP_METHOD_SIMPLE_FLAG_AUTHEAP_ALLOWED;
- if (self->is_editor)
- simple_flags |= EAP_METHOD_SIMPLE_FLAG_IS_EDITOR;
- if (secrets_only)
- simple_flags |= EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY;
-
- em_pap = eap_method_simple_new (self->sec_parent,
- connection,
- EAP_METHOD_SIMPLE_TYPE_PAP,
- simple_flags);
- gtk_list_store_append (auth_model, &iter);
- gtk_list_store_set (auth_model, &iter,
- I_NAME_COLUMN, _("PAP"),
- I_METHOD_COLUMN, em_pap,
- -1);
-
- /* Check for defaulting to PAP */
- if (phase2_auth && !strcasecmp (phase2_auth, "pap"))
- active = 0;
-
- em_mschap = eap_method_simple_new (self->sec_parent,
- connection,
- EAP_METHOD_SIMPLE_TYPE_MSCHAP,
- simple_flags);
- gtk_list_store_append (auth_model, &iter);
- gtk_list_store_set (auth_model, &iter,
- I_NAME_COLUMN, _("MSCHAP"),
- I_METHOD_COLUMN, em_mschap,
- -1);
-
- /* Check for defaulting to MSCHAP */
- if (phase2_auth && !strcasecmp (phase2_auth, "mschap"))
- active = 1;
-
- em_mschap_v2 = eap_method_simple_new (self->sec_parent,
- connection,
- EAP_METHOD_SIMPLE_TYPE_MSCHAP_V2,
- simple_flags);
- gtk_list_store_append (auth_model, &iter);
- gtk_list_store_set (auth_model, &iter,
- I_NAME_COLUMN, _("MSCHAPv2"),
- I_METHOD_COLUMN, em_mschap_v2,
- -1);
-
- /* Check for defaulting to MSCHAPv2 */
- if (phase2_auth && !strcasecmp (phase2_auth, "mschapv2") &&
- nm_setting_802_1x_get_phase2_autheap (s_8021x) != NULL)
- active = 2;
-
- em_plain_mschap_v2 = eap_method_simple_new (self->sec_parent,
- connection,
- EAP_METHOD_SIMPLE_TYPE_PLAIN_MSCHAP_V2,
- simple_flags);
- gtk_list_store_append (auth_model, &iter);
- gtk_list_store_set (auth_model, &iter,
- I_NAME_COLUMN, _("MSCHAPv2 (no EAP)"),
- I_METHOD_COLUMN, em_plain_mschap_v2,
- -1);
-
- /* Check for defaulting to plain MSCHAPv2 */
- if (phase2_auth && !strcasecmp (phase2_auth, "mschapv2") &&
- nm_setting_802_1x_get_phase2_auth (s_8021x) != NULL)
- active = 3;
-
- em_chap = eap_method_simple_new (self->sec_parent,
- connection,
- EAP_METHOD_SIMPLE_TYPE_CHAP,
- simple_flags);
- gtk_list_store_append (auth_model, &iter);
- gtk_list_store_set (auth_model, &iter,
- I_NAME_COLUMN, _("CHAP"),
- I_METHOD_COLUMN, em_chap,
- -1);
-
- /* Check for defaulting to CHAP */
- if (phase2_auth && !strcasecmp (phase2_auth, "chap"))
- active = 4;
-
- em_md5 = eap_method_simple_new (self->sec_parent,
- connection,
- EAP_METHOD_SIMPLE_TYPE_MD5,
- simple_flags);
- gtk_list_store_append (auth_model, &iter);
- gtk_list_store_set (auth_model, &iter,
- I_NAME_COLUMN, _("MD5"),
- I_METHOD_COLUMN, em_md5,
- -1);
-
- /* Check for defaulting to MD5 */
- if (phase2_auth && !strcasecmp (phase2_auth, "md5"))
- active = 5;
-
- em_gtc = eap_method_simple_new (self->sec_parent,
- connection,
- EAP_METHOD_SIMPLE_TYPE_GTC,
- simple_flags);
- gtk_list_store_append (auth_model, &iter);
- gtk_list_store_set (auth_model, &iter,
- I_NAME_COLUMN, _("GTC"),
- I_METHOD_COLUMN, em_gtc,
- -1);
-
- /* Check for defaulting to GTC */
- if (phase2_auth && !strcasecmp (phase2_auth, "gtc"))
- active = 6;
-
- gtk_combo_box_set_model (self->inner_auth_combo, GTK_TREE_MODEL (auth_model));
- gtk_combo_box_set_active (self->inner_auth_combo, active);
-
- g_signal_connect_swapped (self->inner_auth_combo, "changed", G_CALLBACK (inner_auth_combo_changed_cb), self);
-}
-
-static void
update_secrets (EAPMethod *method, NMConnection *connection)
{
EAPMethodTTLS *self = EAP_METHOD_TTLS (method);
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- model = gtk_combo_box_get_model (self->inner_auth_combo);
- if (!gtk_tree_model_get_iter_first (model, &iter))
- return;
- do {
- g_autoptr(EAPMethod) eap = NULL;
-
- gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1);
- eap_method_update_secrets (eap, connection);
- } while (gtk_tree_model_iter_next (model, &iter));
+ eap_method_update_secrets (EAP_METHOD (self->em_chap), connection);
+ eap_method_update_secrets (EAP_METHOD (self->em_gtc), connection);
+ eap_method_update_secrets (EAP_METHOD (self->em_md5), connection);
+ eap_method_update_secrets (EAP_METHOD (self->em_mschap), connection);
+ eap_method_update_secrets (EAP_METHOD (self->em_mschap_v2), connection);
+ eap_method_update_secrets (EAP_METHOD (self->em_pap), connection);
+ eap_method_update_secrets (EAP_METHOD (self->em_plain_mschap_v2), connection);
}
static GtkWidget *
@@ -386,11 +234,8 @@ eap_method_ttls_init (EAPMethodTTLS *self)
static void
eap_method_ttls_class_init (EAPMethodTTLSClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->dispose = eap_method_ttls_dispose;
-
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-ttls.ui");
gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, anon_identity_entry);
@@ -402,6 +247,7 @@ eap_method_ttls_class_init (EAPMethodTTLSClass *klass)
gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, domain_match_label);
gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, inner_auth_combo);
gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, inner_auth_label);
+ gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, inner_auth_model);
gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, inner_auth_box);
}
@@ -426,6 +272,9 @@ eap_method_ttls_new (WirelessSecurity *ws_parent,
GtkFileFilter *filter;
NMSetting8021x *s_8021x = NULL;
const char *filename;
+ EAPMethodSimpleFlags simple_flags;
+ const char *phase2_auth = NULL;
+ GtkTreeIter iter;
self = g_object_new (eap_method_ttls_get_type (), NULL);
self->sec_parent = ws_parent;
@@ -460,7 +309,76 @@ eap_method_ttls_new (WirelessSecurity *ws_parent,
gtk_entry_set_text (self->domain_match_entry, nm_setting_802_1x_get_domain_suffix_match (s_8021x));
g_signal_connect_swapped (self->domain_match_entry, "changed", G_CALLBACK (changed_cb), self);
- inner_auth_combo_init (self, connection, s_8021x, secrets_only);
+ simple_flags = EAP_METHOD_SIMPLE_FLAG_PHASE2 | EAP_METHOD_SIMPLE_FLAG_AUTHEAP_ALLOWED;
+ if (self->is_editor)
+ simple_flags |= EAP_METHOD_SIMPLE_FLAG_IS_EDITOR;
+ if (secrets_only)
+ simple_flags |= EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY;
+
+ self->em_pap = eap_method_simple_new (self->sec_parent,
+ connection,
+ EAP_METHOD_SIMPLE_TYPE_PAP,
+ simple_flags);
+ gtk_widget_show (GTK_WIDGET (self->em_pap));
+
+ self->em_mschap = eap_method_simple_new (self->sec_parent,
+ connection,
+ EAP_METHOD_SIMPLE_TYPE_MSCHAP,
+ simple_flags);
+ gtk_widget_show (GTK_WIDGET (self->em_mschap));
+
+ self->em_mschap_v2 = eap_method_simple_new (self->sec_parent,
+ connection,
+ EAP_METHOD_SIMPLE_TYPE_MSCHAP_V2,
+ simple_flags);
+ gtk_widget_show (GTK_WIDGET (self->em_mschap_v2));
+
+ self->em_plain_mschap_v2 = eap_method_simple_new (self->sec_parent,
+ connection,
+ EAP_METHOD_SIMPLE_TYPE_PLAIN_MSCHAP_V2,
+ simple_flags);
+ gtk_widget_show (GTK_WIDGET (self->em_plain_mschap_v2));
+
+ self->em_chap = eap_method_simple_new (self->sec_parent,
+ connection,
+ EAP_METHOD_SIMPLE_TYPE_CHAP,
+ simple_flags);
+ gtk_widget_show (GTK_WIDGET (self->em_chap));
+
+ self->em_md5 = eap_method_simple_new (self->sec_parent,
+ connection,
+ EAP_METHOD_SIMPLE_TYPE_MD5,
+ simple_flags);
+ gtk_widget_show (GTK_WIDGET (self->em_md5));
+
+ self->em_gtc = eap_method_simple_new (self->sec_parent,
+ connection,
+ EAP_METHOD_SIMPLE_TYPE_GTC,
+ simple_flags);
+ gtk_widget_show (GTK_WIDGET (self->em_gtc));
+
+ if (s_8021x) {
+ if (nm_setting_802_1x_get_phase2_auth (s_8021x))
+ phase2_auth = nm_setting_802_1x_get_phase2_auth (s_8021x);
+ else if (nm_setting_802_1x_get_phase2_autheap (s_8021x))
+ phase2_auth = nm_setting_802_1x_get_phase2_autheap (s_8021x);
+ }
+ if (phase2_auth == NULL)
+ phase2_auth = "pap";
+
+ if (strcmp (phase2_auth, "mschapv2") == 0 && nm_setting_802_1x_get_phase2_auth (s_8021x) != NULL)
+ phase2_auth = "plain_mschapv2";
+
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->inner_auth_model), &iter)) {
+ do {
+ g_autofree gchar *id = NULL;
+ gtk_tree_model_get (GTK_TREE_MODEL (self->inner_auth_model), &iter, I_ID_COLUMN, &id, -1);
+ if (strcmp (id, phase2_auth) == 0)
+ gtk_combo_box_set_active_iter (self->inner_auth_combo, &iter);
+ } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->inner_auth_model), &iter));
+ }
+
+ g_signal_connect_swapped (self->inner_auth_combo, "changed", G_CALLBACK (inner_auth_combo_changed_cb), self);
inner_auth_combo_changed_cb (self);
if (secrets_only) {
diff --git a/panels/network/wireless-security/eap-method-ttls.ui b/panels/network/wireless-security/eap-method-ttls.ui
index 31978b9ae..2ba7d2011 100644
--- a/panels/network/wireless-security/eap-method-ttls.ui
+++ b/panels/network/wireless-security/eap-method-ttls.ui
@@ -1,14 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.4"/>
- <object class="GtkListStore" id="auth_model">
+ <object class="GtkListStore" id="inner_auth_model">
<columns>
- <!-- column-name gchararray -->
+ <!-- column-name label -->
+ <column type="gchararray"/>
+ <!-- column-name id -->
<column type="gchararray"/>
</columns>
<data>
<row>
- <col id="0"> </col>
+ <col id="0" translatable="yes">PAP</col>
+ <col id="1">pap</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">MSCHAP</col>
+ <col id="1">mschap</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">MSCHAPv2</col>
+ <col id="1">mschapv2</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">MSCHAPv2 (no EAP)</col>
+ <col id="1">plain_mschapv2</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">CHAP</col>
+ <col id="1">chap</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">MD5</col>
+ <col id="1">md5</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">GTC</col>
+ <col id="1">gtc</col>
</row>
</data>
</object>
@@ -128,7 +155,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
- <property name="model">auth_model</property>
+ <property name="model">inner_auth_model</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>