diff --git a/panels/network/cc-wifi-hotspot-dialog.c b/panels/network/cc-wifi-hotspot-dialog.c index 0ef536264e181ba62308c3244a1a4045e2212e27..f13e52bf287351534aea1d22c3cfdd64204b3a20 100644 --- a/panels/network/cc-wifi-hotspot-dialog.c +++ b/panels/network/cc-wifi-hotspot-dialog.c @@ -30,9 +30,9 @@ #include #include "list-box-helper.h" -#include "connection-editor/ui-helpers.h" #include "cc-wifi-hotspot-dialog.h" #include "cc-network-resources.h" +#include "ui-helpers.h" /** * @short_description: WWAN network type selection dialog diff --git a/panels/network/connection-editor/ce-page-8021x-security.c b/panels/network/connection-editor/ce-page-8021x-security.c index e38e2a71eafc1a856e0680ce805e5400242e8389..794e29cd51ce3e37cb65e693900df841f48e29c2 100644 --- a/panels/network/connection-editor/ce-page-8021x-security.c +++ b/panels/network/connection-editor/ce-page-8021x-security.c @@ -41,7 +41,7 @@ struct _CEPage8021xSecurity { NMConnection *connection; GtkWidget *security_widget; - WirelessSecurity *security; + WirelessSecurityWPAEAP *security; GtkSizeGroup *group; gboolean initial_have_8021x; }; @@ -59,9 +59,9 @@ enable_toggled (CEPage8021xSecurity *self) } static void -stuff_changed (WirelessSecurity *sec, gpointer user_data) +security_item_changed_cb (CEPage8021xSecurity *self) { - ce_page_changed (CE_PAGE (user_data)); + ce_page_changed (CE_PAGE (self)); } static void @@ -74,14 +74,14 @@ finish_setup (CEPage8021xSecurity *self, gpointer unused, GError *error, gpointe self->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - self->security = (WirelessSecurity *) ws_wpa_eap_new (self->connection, TRUE, FALSE); + self->security = ws_wpa_eap_new (self->connection, TRUE, FALSE); if (!self->security) { g_warning ("Could not load 802.1x user interface."); return; } - wireless_security_set_changed_notify (self->security, stuff_changed, self); - self->security_widget = wireless_security_get_widget (self->security); + g_signal_connect_object (WIRELESS_SECURITY (self->security), "changed", G_CALLBACK (security_item_changed_cb), self, G_CONNECT_SWAPPED); + self->security_widget = wireless_security_get_widget (WIRELESS_SECURITY (self->security)); parent = gtk_widget_get_parent (self->security_widget); if (parent) gtk_container_remove (GTK_CONTAINER (parent), self->security_widget); @@ -91,7 +91,7 @@ finish_setup (CEPage8021xSecurity *self, gpointer unused, GError *error, gpointe gtk_widget_set_sensitive (self->security_widget, self->initial_have_8021x); gtk_size_group_add_widget (self->group, GTK_WIDGET (self->security_label)); - wireless_security_add_to_size_group (self->security, self->group); + wireless_security_add_to_size_group (WIRELESS_SECURITY (self->security), self->group); gtk_container_add (GTK_CONTAINER (self->box), self->security_widget); @@ -124,7 +124,7 @@ ce_page_8021x_security_validate (CEPage *cepage, NMConnection *connection, GErro NMSetting *s_8021x; /* FIXME: get failed property and error out of wireless security objects */ - valid = wireless_security_validate (self->security, error); + valid = wireless_security_validate (WIRELESS_SECURITY (self->security), error); if (valid) { g_autoptr(NMConnection) tmp_connection = NULL; NMSetting *s_con; @@ -139,7 +139,7 @@ ce_page_8021x_security_validate (CEPage *cepage, NMConnection *connection, GErro s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); nm_connection_add_setting (tmp_connection, nm_setting_duplicate (s_con)); - ws_802_1x_fill_connection (GTK_COMBO_BOX (gtk_builder_get_object (self->security->builder, "auth_combo")), tmp_connection); + ws_wpa_eap_fill_connection (self->security, tmp_connection); s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X); nm_connection_add_setting (connection, NM_SETTING (g_object_ref (s_8021x))); @@ -164,7 +164,7 @@ ce_page_8021x_security_dispose (GObject *object) CEPage8021xSecurity *self = CE_PAGE_8021X_SECURITY (object); g_clear_object (&self->connection); - g_clear_pointer (&self->security, wireless_security_unref); + g_clear_object (&self->security); g_clear_object (&self->group); G_OBJECT_CLASS (ce_page_8021x_security_parent_class)->dispose (object); diff --git a/panels/network/connection-editor/ce-page-security.c b/panels/network/connection-editor/ce-page-security.c index f716d7ef4e226f28c2ba18add684f54915061ac4..e2532696aa9ced20caf6e91293199aeb0de1275e 100644 --- a/panels/network/connection-editor/ce-page-security.c +++ b/panels/network/connection-editor/ce-page-security.c @@ -174,9 +174,9 @@ security_combo_changed (CEPageSecurity *self) } static void -stuff_changed_cb (WirelessSecurity *sec, gpointer user_data) +security_item_changed_cb (CEPageSecurity *self) { - ce_page_changed (CE_PAGE (user_data)); + ce_page_changed (CE_PAGE (self)); } static void @@ -187,14 +187,14 @@ add_security_item (CEPageSecurity *self, const char *text, gboolean adhoc_valid) { - wireless_security_set_changed_notify (sec, stuff_changed_cb, self); + g_signal_connect_object (sec, "changed", G_CALLBACK (security_item_changed_cb), self, G_CONNECT_SWAPPED); gtk_list_store_append (model, iter); gtk_list_store_set (model, iter, S_NAME_COLUMN, text, S_SEC_COLUMN, sec, S_ADHOC_VALID_COLUMN, adhoc_valid, -1); - wireless_security_unref (sec); + g_object_unref (sec); } static void @@ -250,7 +250,7 @@ finish_setup (CEPageSecurity *self) if (sws) default_type = get_default_type_for_security (sws); - sec_model = gtk_list_store_new (3, G_TYPE_STRING, WIRELESS_TYPE_SECURITY, G_TYPE_BOOLEAN); + sec_model = gtk_list_store_new (3, G_TYPE_STRING, wireless_security_get_type (), G_TYPE_BOOLEAN); if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) { gtk_list_store_insert_with_values (sec_model, &iter, -1, diff --git a/panels/network/connection-editor/meson.build b/panels/network/connection-editor/meson.build index 9ba9b3784659e6ec4e32c6524a5e71c30eea8dd6..856833fff7dce2837dc6967b66afdb684689e233 100644 --- a/panels/network/connection-editor/meson.build +++ b/panels/network/connection-editor/meson.build @@ -11,7 +11,6 @@ sources = files( 'ce-page-wifi.c', 'ce-page.c', 'net-connection-editor.c', - 'ui-helpers.c', 'vpn-helpers.c' ) @@ -40,7 +39,7 @@ sources += gnome.compile_resources( libconnection_editor = static_library( name, sources: sources, - include_directories: [top_inc, common_inc, wireless_security_inc], + include_directories: [top_inc, common_inc, network_inc, wireless_security_inc], dependencies: deps, c_args: cflags, link_with: libwireless_security diff --git a/panels/network/meson.build b/panels/network/meson.build index 6bb3a942851b7eca8c39ed131a15473aa3847073..439b2b847a92aa23ffa7469a10f0c978b89571d4 100644 --- a/panels/network/meson.build +++ b/panels/network/meson.build @@ -3,6 +3,8 @@ deps = common_deps + network_manager_deps + [ dependency('gmodule-2.0') ] +network_inc = include_directories('.') + subdir('wireless-security') subdir('connection-editor') @@ -46,7 +48,8 @@ sources = files( 'net-proxy.c', 'net-vpn.c', 'network-dialogs.c', - 'panel-common.c' + 'panel-common.c', + 'ui-helpers.c' ) resource_data = files( diff --git a/panels/network/connection-editor/ui-helpers.c b/panels/network/ui-helpers.c similarity index 100% rename from panels/network/connection-editor/ui-helpers.c rename to panels/network/ui-helpers.c diff --git a/panels/network/connection-editor/ui-helpers.h b/panels/network/ui-helpers.h similarity index 100% rename from panels/network/connection-editor/ui-helpers.h rename to panels/network/ui-helpers.h diff --git a/panels/network/wireless-security/eap-method-fast.c b/panels/network/wireless-security/eap-method-fast.c index 858c049cb837888b34354924e9226ee19c0faaf1..28b42b63918b268ca62234f969e59c12ab45f1f3 100644 --- a/panels/network/wireless-security/eap-method-fast.c +++ b/panels/network/wireless-security/eap-method-fast.c @@ -20,52 +20,65 @@ * Copyright 2012 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - -#include -#include +#include #include "eap-method.h" -#include "wireless-security.h" -#include "utils.h" +#include "eap-method-fast.h" +#include "eap-method-simple.h" #include "helpers.h" +#include "ui-helpers.h" +#include "wireless-security.h" -#define I_NAME_COLUMN 0 -#define I_METHOD_COLUMN 1 +#define I_NAME_COLUMN 0 +#define I_ID_COLUMN 1 struct _EAPMethodFAST { - EAPMethod parent; + GtkGrid parent; GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; GtkComboBox *inner_auth_combo; GtkLabel *inner_auth_label; + GtkListStore *inner_auth_model; GtkBox *inner_auth_box; GtkFileChooserButton *pac_file_button; GtkLabel *pac_file_label; GtkCheckButton *pac_provision_check; GtkComboBox *pac_provision_combo; - GtkSizeGroup *size_group; - WirelessSecurity *sec_parent; + EAPMethodSimple *em_gtc; + EAPMethodSimple *em_mschap_v2; + gboolean is_editor; }; -static void -destroy (EAPMethod *parent) +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodFAST, eap_method_fast, GTK_TYPE_GRID, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + +static EAPMethod * +get_inner_method (EAPMethodFAST *self) { - EAPMethodFAST *self = (EAPMethodFAST *) parent; + 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); - g_clear_object (&self->size_group); + if (strcmp (id, "gtc") == 0) + return EAP_METHOD (self->em_gtc); + if (strcmp (id, "mschapv2") == 0) + return EAP_METHOD (self->em_mschap_v2); + + return NULL; } static gboolean validate (EAPMethod *parent, GError **error) { EAPMethodFAST *self = (EAPMethodFAST *) parent; - GtkTreeModel *model; - GtkTreeIter iter; - g_autoptr(EAPMethod) eap = NULL; const char *file; gboolean provisioning; gboolean valid = TRUE; @@ -79,35 +92,21 @@ validate (EAPMethod *parent, GError **error) } else widget_unset_error (GTK_WIDGET (self->pac_file_button)); - 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, valid ? error : NULL) && valid; - return valid; + return eap_method_validate (get_inner_method (self), valid ? error : NULL) && valid; } static void add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) { EAPMethodFAST *self = (EAPMethodFAST *) parent; - 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->anon_identity_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->pac_file_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->pac_provision_check)); 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_gtc), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_mschap_v2), group); } static void @@ -117,9 +116,6 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla NMSetting8021x *s_8021x; const char *text; char *filename; - g_autoptr(EAPMethod) eap = NULL; - GtkTreeModel *model; - GtkTreeIter iter; gboolean enabled; int pac_provisioning = 0; @@ -158,116 +154,45 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla } } - 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 (EAPMethodFAST *self) { - g_autoptr(EAPMethod) eap = NULL; + EAPMethod *inner_method; GList *elt, *children; - GtkTreeModel *model; - GtkTreeIter iter; - GtkWidget *eap_widget; - /* 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); - - eap_widget = eap_method_get_widget (eap); - g_assert (eap_widget); - gtk_widget_unparent (eap_widget); - if (self->size_group) - eap_method_add_to_size_group (eap, self->size_group); - gtk_container_add (GTK_CONTAINER (self->inner_auth_box), eap_widget); + 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); + eap_method_emit_changed (EAP_METHOD (self)); } static void -inner_auth_combo_init (EAPMethodFAST *self, - NMConnection *connection, - NMSetting8021x *s_8021x, - gboolean secrets_only) +update_secrets (EAPMethod *parent, NMConnection *connection) { - g_autoptr(GtkListStore) auth_model = NULL; - GtkTreeIter iter; - g_autoptr(EAPMethodSimple) em_gtc = NULL; - g_autoptr(EAPMethodSimple) em_mschap_v2 = 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; - if (self->is_editor) - simple_flags |= EAP_METHOD_SIMPLE_FLAG_IS_EDITOR; - if (secrets_only) - simple_flags |= EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY; - - 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 = 0; - - 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")) - active = 1; - - gtk_combo_box_set_model (self->inner_auth_combo, GTK_TREE_MODEL (auth_model)); - gtk_combo_box_set_active (self->inner_auth_combo, active); + EAPMethodFAST *self = (EAPMethodFAST *) parent; - g_signal_connect_swapped (self->inner_auth_combo, "changed", G_CALLBACK (inner_auth_combo_changed_cb), self); + eap_method_update_secrets (EAP_METHOD (self->em_gtc), connection); + eap_method_update_secrets (EAP_METHOD (self->em_mschap_v2), connection); } -static void -update_secrets (EAPMethod *parent, NMConnection *connection) +static GtkWidget * +get_default_field (EAPMethod *parent) { EAPMethodFAST *self = (EAPMethodFAST *) parent; - eap_method_phase2_update_secrets_helper (parent, - connection, - self->inner_auth_combo, - I_METHOD_COLUMN); + return GTK_WIDGET (self->anon_identity_entry); +} + +static const gchar * +get_password_flags_name (EAPMethod *parent) +{ + return NM_SETTING_802_1X_PASSWORD; } static void @@ -278,13 +203,49 @@ pac_toggled_cb (EAPMethodFAST *self) enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->pac_provision_check)); gtk_widget_set_sensitive (GTK_WIDGET (self->pac_provision_combo), enabled); - wireless_security_notify_changed (self->sec_parent); + eap_method_emit_changed (EAP_METHOD (self)); } static void changed_cb (EAPMethodFAST *self) { - wireless_security_notify_changed (self->sec_parent); + eap_method_emit_changed (EAP_METHOD (self)); +} + +static void +eap_method_fast_init (EAPMethodFAST *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +static void +eap_method_fast_class_init (EAPMethodFASTClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-fast.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, anon_identity_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, anon_identity_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, inner_auth_combo); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, inner_auth_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, inner_auth_model); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, inner_auth_box); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, pac_file_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, pac_file_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, pac_provision_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, pac_provision_combo); +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; } EAPMethodFAST * @@ -293,41 +254,18 @@ eap_method_fast_new (WirelessSecurity *ws_parent, gboolean is_editor, gboolean secrets_only) { - EAPMethod *parent; EAPMethodFAST *self; GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; const char *filename; gboolean provisioning_enabled = TRUE; + EAPMethodSimpleFlags simple_flags; + const gchar *phase2_auth = NULL; + GtkTreeIter iter; - parent = eap_method_init (sizeof (EAPMethodFAST), - validate, - add_to_size_group, - fill_connection, - update_secrets, - destroy, - "/org/gnome/ControlCenter/network/eap-method-fast.ui", - "grid", - "anon_identity_entry", - FALSE); - if (!parent) - return NULL; - - parent->password_flags_name = NM_SETTING_802_1X_PASSWORD; - self = (EAPMethodFAST *) parent; - self->sec_parent = ws_parent; + self = g_object_new (eap_method_fast_get_type (), NULL); self->is_editor = is_editor; - self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "anon_identity_entry")); - self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "anon_identity_label")); - self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "inner_auth_combo")); - self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "inner_auth_label")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); - self->pac_file_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "pac_file_button")); - self->pac_file_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "pac_file_label")); - self->pac_provision_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "pac_provision_check")); - self->pac_provision_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "pac_provision_combo")); - if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); @@ -377,7 +315,45 @@ eap_method_fast_new (WirelessSecurity *ws_parent, gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (self->pac_file_button), filename); } - inner_auth_combo_init (self, connection, s_8021x, secrets_only); + simple_flags = EAP_METHOD_SIMPLE_FLAG_PHASE2; + 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_gtc = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_GTC, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_gtc)); + g_signal_connect_object (self->em_gtc, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + self->em_mschap_v2 = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_MSCHAP_V2, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_mschap_v2)); + g_signal_connect_object (self->em_mschap_v2, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + 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 = "gtc"; + + 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-fast.h b/panels/network/wireless-security/eap-method-fast.h index c19722058a0ba98dd638f71ee6c2ab3a99200c5c..474571d57779fae9c9b5e6ae2210b9625b92755c 100644 --- a/panels/network/wireless-security/eap-method-fast.h +++ b/panels/network/wireless-security/eap-method-fast.h @@ -20,20 +20,20 @@ * (C) Copyright 2012 Red Hat, Inc. */ -#ifndef EAP_METHOD_FAST_H -#define EAP_METHOD_FAST_H +#pragma once + +#include +#include #include "wireless-security.h" -typedef struct _EAPMethodFAST EAPMethodFAST; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodFAST, eap_method_fast, EAP, METHOD_FAST, GtkGrid) EAPMethodFAST *eap_method_fast_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean is_editor, gboolean secrets_only); -static void eap_method_fast_unref (EAPMethodFAST *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodFAST, eap_method_fast_unref) - -#endif /* EAP_METHOD_FAST_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-fast.ui b/panels/network/wireless-security/eap-method-fast.ui index c6470d1ed1cd3b9faff197ea92fc7a15ace7f83d..3d4f1dd2550c21484f2a77b3d5c63d75fd139289 100644 --- a/panels/network/wireless-security/eap-method-fast.ui +++ b/panels/network/wireless-security/eap-method-fast.ui @@ -1,14 +1,21 @@ - + - + + + - + GTC + gtc + + + MSCHAPv2 + mschapv2 @@ -29,8 +36,7 @@ - - True + diff --git a/panels/network/wireless-security/eap-method-leap.c b/panels/network/wireless-security/eap-method-leap.c index 48cede21bf81bd35bb2be999e5dd1c0e288bd04f..ed799b3cd93a93a45ec1f5996020d1adaf93a97e 100644 --- a/panels/network/wireless-security/eap-method-leap.c +++ b/panels/network/wireless-security/eap-method-leap.c @@ -20,21 +20,18 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - -#include -#include +#include #include "eap-method.h" -#include "wireless-security.h" +#include "eap-method-leap.h" #include "helpers.h" #include "nma-ui-utils.h" -#include "utils.h" +#include "ui-helpers.h" +#include "wireless-security.h" struct _EAPMethodLEAP { - EAPMethod parent; + GtkGrid parent; - GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; GtkCheckButton *show_password_check; @@ -46,6 +43,11 @@ struct _EAPMethodLEAP { gboolean editing_connection; }; +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodLEAP, eap_method_leap, GTK_TYPE_GRID, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + static void show_toggled_cb (EAPMethodLEAP *self) { @@ -107,13 +109,13 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla /* Save 802.1X password flags to the connection */ secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->password_entry)); - nm_setting_set_secret_flags (NM_SETTING (s_8021x), parent->password_flags_name, + nm_setting_set_secret_flags (NM_SETTING (s_8021x), NM_SETTING_802_1X_PASSWORD, secret_flags, NULL); /* Update secret flags and popup when editing the connection */ if (self->editing_connection) nma_utils_update_password_storage (GTK_WIDGET (self->password_entry), secret_flags, - NM_SETTING (s_8021x), parent->password_flags_name); + NM_SETTING (s_8021x), NM_SETTING_802_1X_PASSWORD); } static void @@ -126,6 +128,19 @@ update_secrets (EAPMethod *parent, NMConnection *connection) (HelperSecretFunc) nm_setting_802_1x_get_password); } +static GtkWidget * +get_default_field (EAPMethod *parent) +{ + EAPMethodLEAP *self = (EAPMethodLEAP *) parent; + return GTK_WIDGET (self->username_entry); +} + +static const gchar * +get_password_flags_name (EAPMethod *parent) +{ + return NM_SETTING_802_1X_PASSWORD; +} + /* Set the UI fields for user, password and show_password to the * values as provided by self->ws_parent. */ static void @@ -153,28 +168,62 @@ widgets_realized (EAPMethodLEAP *self) static void widgets_unrealized (EAPMethodLEAP *self) { - wireless_security_set_userpass (self->ws_parent, - gtk_entry_get_text (self->username_entry), - gtk_entry_get_text (self->password_entry), - (gboolean) -1, - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check))); + wireless_security_set_username (self->ws_parent, gtk_entry_get_text (self->username_entry)); + wireless_security_set_password (self->ws_parent, gtk_entry_get_text (self->password_entry)); + wireless_security_set_show_password (self->ws_parent, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check))); } static void -destroy (EAPMethod *parent) +eap_method_leap_dispose (GObject *object) { - EAPMethodLEAP *self = (EAPMethodLEAP *) parent; + EAPMethodLEAP *self = EAP_METHOD_LEAP (object); - g_signal_handlers_disconnect_by_data (self->grid, self); + g_signal_handlers_disconnect_by_data (self, self); g_signal_handlers_disconnect_by_data (self->username_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->show_password_check, self); + + G_OBJECT_CLASS (eap_method_leap_parent_class)->dispose (object); } static void changed_cb (EAPMethodLEAP *self) { - wireless_security_notify_changed (self->ws_parent); + eap_method_emit_changed (EAP_METHOD (self)); +} + +static void +eap_method_leap_init (EAPMethodLEAP *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +static void +eap_method_leap_class_init (EAPMethodLEAPClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = eap_method_leap_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-leap.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, password_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, password_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, show_password_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, username_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, username_label); +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; } EAPMethodLEAP * @@ -183,36 +232,14 @@ eap_method_leap_new (WirelessSecurity *ws_parent, gboolean secrets_only) { EAPMethodLEAP *self; - EAPMethod *parent; NMSetting8021x *s_8021x = NULL; - parent = eap_method_init (sizeof (EAPMethodLEAP), - validate, - add_to_size_group, - fill_connection, - update_secrets, - destroy, - "/org/gnome/ControlCenter/network/eap-method-leap.ui", - "grid", - "username_entry", - FALSE); - if (!parent) - return NULL; - - parent->password_flags_name = NM_SETTING_802_1X_PASSWORD; - self = (EAPMethodLEAP *) parent; + self = g_object_new (eap_method_leap_get_type (), NULL); self->editing_connection = secrets_only ? FALSE : TRUE; self->ws_parent = ws_parent; - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "password_entry")); - self->password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->username_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "username_entry")); - self->username_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "username_label")); - - g_signal_connect_swapped (self->grid, "realize", G_CALLBACK (widgets_realized), self); - g_signal_connect_swapped (self->grid, "unrealize", G_CALLBACK (widgets_unrealized), self); + g_signal_connect_swapped (self, "realize", G_CALLBACK (widgets_realized), self); + g_signal_connect_swapped (self, "unrealize", G_CALLBACK (widgets_unrealized), self); g_signal_connect_swapped (self->username_entry, "changed", G_CALLBACK (changed_cb), self); @@ -224,7 +251,7 @@ eap_method_leap_new (WirelessSecurity *ws_parent, /* Create password-storage popup menu for password entry under entry's secondary icon */ if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); - nma_utils_setup_password_storage (GTK_WIDGET (self->password_entry), 0, (NMSetting *) s_8021x, parent->password_flags_name, + nma_utils_setup_password_storage (GTK_WIDGET (self->password_entry), 0, (NMSetting *) s_8021x, NM_SETTING_802_1X_PASSWORD, FALSE, secrets_only); g_signal_connect_swapped (self->show_password_check, "toggled", G_CALLBACK (show_toggled_cb), self); diff --git a/panels/network/wireless-security/eap-method-leap.h b/panels/network/wireless-security/eap-method-leap.h index 2d205d71905491c017473e666c9adcf3fa2ea5e4..5b3491643140dce7116378f0fe7fb663e4477c82 100644 --- a/panels/network/wireless-security/eap-method-leap.h +++ b/panels/network/wireless-security/eap-method-leap.h @@ -20,19 +20,19 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_LEAP_H -#define EAP_METHOD_LEAP_H +#pragma once + +#include +#include #include "wireless-security.h" -typedef struct _EAPMethodLEAP EAPMethodLEAP; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodLEAP, eap_method_leap, EAP, METHOD_LEAP, GtkGrid) EAPMethodLEAP *eap_method_leap_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean secrets_only); -static void eap_method_leap_unref (EAPMethodLEAP *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodLEAP, eap_method_leap_unref) - -#endif /* EAP_METHOD_LEAP_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-leap.ui b/panels/network/wireless-security/eap-method-leap.ui index b08802c15e412c61652c0595fd2ad274c39f2ce2..abb6ea4428e91ad843e83bc659fd9bfc3b7c6743 100644 --- a/panels/network/wireless-security/eap-method-leap.ui +++ b/panels/network/wireless-security/eap-method-leap.ui @@ -1,8 +1,7 @@ - - True + diff --git a/panels/network/wireless-security/eap-method-peap.c b/panels/network/wireless-security/eap-method-peap.c index a70aaccceda1f5b7d2225c51a3d28dc318232aba..5487a5e51979c746936874e3bfcc0ef2ac32e3d9 100644 --- a/panels/network/wireless-security/eap-method-peap.c +++ b/panels/network/wireless-security/eap-method-peap.c @@ -20,20 +20,20 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - -#include -#include +#include #include "eap-method.h" +#include "eap-method-peap.h" +#include "eap-method-simple.h" +#include "helpers.h" +#include "ui-helpers.h" #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 _EAPMethodPEAP { - EAPMethod parent; + GtkGrid parent; GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; @@ -43,30 +43,46 @@ struct _EAPMethodPEAP { GtkBox *inner_auth_box; GtkComboBox *inner_auth_combo; GtkLabel *inner_auth_label; + GtkListStore *inner_auth_model; GtkComboBox *version_combo; GtkLabel *version_label; - GtkSizeGroup *size_group; - WirelessSecurity *sec_parent; + EAPMethodSimple *em_gtc; + EAPMethodSimple *em_md5; + EAPMethodSimple *em_mschap_v2; + gboolean is_editor; }; -static void -destroy (EAPMethod *parent) +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodPEAP, eap_method_peap, GTK_TYPE_GRID, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + +static EAPMethod * +get_inner_method (EAPMethodPEAP *self) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + 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); - g_clear_object (&self->size_group); + 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, "mschapv2") == 0) + return EAP_METHOD (self->em_mschap_v2); + + return NULL; } static gboolean -validate (EAPMethod *parent, GError **error) +validate (EAPMethod *method, GError **error) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; - GtkTreeModel *model; - GtkTreeIter iter; - g_autoptr(EAPMethod) eap = NULL; - gboolean valid = FALSE; + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); g_autoptr(GError) local_error = NULL; if (!eap_method_validate_filepicker (GTK_FILE_CHOOSER (self->ca_cert_button), @@ -74,18 +90,18 @@ validate (EAPMethod *parent, GError **error) g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-PEAP CA certificate: %s"), local_error->message); return FALSE; } - if (eap_method_ca_cert_required (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), - GTK_FILE_CHOOSER (self->ca_cert_button))) { - g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-PEAP CA certificate: no certificate specified")); - return FALSE; + + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check))) { + g_autofree gchar *filename = NULL; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button)); + if (filename == NULL) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-PEAP CA certificate: no certificate specified")); + 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 @@ -93,19 +109,13 @@ ca_cert_not_required_toggled (EAPMethodPEAP *self) { eap_method_ca_cert_not_required_toggled (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), GTK_FILE_CHOOSER (self->ca_cert_button)); - wireless_security_notify_changed (self->sec_parent); + eap_method_emit_changed (EAP_METHOD (self)); } static void -add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) +add_to_size_group (EAPMethod *method, GtkSizeGroup *group) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; - GtkTreeModel *model; - GtkTreeIter iter; - g_autoptr(EAPMethod) eap = NULL; - - g_clear_object (&self->size_group); - self->size_group = g_object_ref (group); + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); 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)); @@ -113,24 +123,19 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) gtk_size_group_add_widget (group, GTK_WIDGET (self->version_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_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_v2), group); } static void -fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags) +fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); NMSetting8021x *s_8021x; 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; int peapver_active = 0; g_autoptr(GError) error = NULL; gboolean ca_cert_error = FALSE; @@ -149,7 +154,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla g_warning ("Couldn't read CA certificate '%s': %s", filename, error ? error->message : "(unknown)"); ca_cert_error = TRUE; } - eap_method_ca_cert_ignore_set (parent, connection, filename, ca_cert_error); + eap_method_ca_cert_ignore_set (method, connection, filename, ca_cert_error); peapver_active = gtk_combo_box_get_active (self->version_combo); switch (peapver_active) { @@ -164,136 +169,89 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla break; } - 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 (EAPMethodPEAP *self) { - g_autoptr(EAPMethod) eap = NULL; + EAPMethod *inner_method; GList *elt, *children; - GtkTreeModel *model; - GtkTreeIter iter; - GtkWidget *eap_widget; - /* 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)); - 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); + inner_method = get_inner_method (self); + gtk_container_add (GTK_CONTAINER (self->inner_auth_box), g_object_ref (GTK_WIDGET (inner_method))); - eap_widget = eap_method_get_widget (eap); - g_assert (eap_widget); - gtk_widget_unparent (eap_widget); - - if (self->size_group) - eap_method_add_to_size_group (eap, self->size_group); - gtk_container_add (GTK_CONTAINER (self->inner_auth_box), eap_widget); - - wireless_security_notify_changed (self->sec_parent); + eap_method_emit_changed (EAP_METHOD (self)); } static void -inner_auth_combo_init (EAPMethodPEAP *self, - NMConnection *connection, - NMSetting8021x *s_8021x, - gboolean secrets_only) +update_secrets (EAPMethod *method, NMConnection *connection) { - g_autoptr(GtkListStore) auth_model = NULL; - GtkTreeIter iter; - g_autoptr(EAPMethodSimple) em_mschap_v2 = NULL; - g_autoptr(EAPMethodSimple) em_md5 = NULL; - g_autoptr(EAPMethodSimple) em_gtc = NULL; - guint32 active = 0; - const char *phase2_auth = NULL; - EAPMethodSimpleFlags simple_flags; + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); - auth_model = gtk_list_store_new (2, G_TYPE_STRING, eap_method_get_type ()); + 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_v2), connection); +} - 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); - } +static GtkWidget * +get_default_field (EAPMethod *method) +{ + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); + return GTK_WIDGET (self->anon_identity_entry); +} - simple_flags = EAP_METHOD_SIMPLE_FLAG_PHASE2; - if (self->is_editor) - simple_flags |= EAP_METHOD_SIMPLE_FLAG_IS_EDITOR; - if (secrets_only) - simple_flags |= EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY; +static const gchar * +get_password_flags_name (EAPMethod *method) +{ + return NM_SETTING_802_1X_PASSWORD; +} - 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")) - active = 0; - - 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 = 1; - - 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 = 2; - - gtk_combo_box_set_model (self->inner_auth_combo, GTK_TREE_MODEL (auth_model)); - gtk_combo_box_set_active (self->inner_auth_combo, active); +static void +changed_cb (EAPMethodPEAP *self) +{ + eap_method_emit_changed (EAP_METHOD (self)); +} - g_signal_connect_swapped (self->inner_auth_combo, "changed", G_CALLBACK (inner_auth_combo_changed_cb), self); +static void +eap_method_peap_init (EAPMethodPEAP *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); } static void -update_secrets (EAPMethod *parent, NMConnection *connection) +eap_method_peap_class_init (EAPMethodPEAPClass *klass) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; - eap_method_phase2_update_secrets_helper (parent, - connection, - self->inner_auth_combo, - I_METHOD_COLUMN); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-peap.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, anon_identity_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, anon_identity_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, ca_cert_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, ca_cert_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, ca_cert_not_required_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, inner_auth_box); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, inner_auth_combo); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, inner_auth_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, inner_auth_model); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, version_combo); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, version_label); } static void -changed_cb (EAPMethodPEAP *self) +eap_method_iface_init (EAPMethodInterface *iface) { - wireless_security_notify_changed (self->sec_parent); + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; } EAPMethodPEAP * @@ -302,41 +260,17 @@ eap_method_peap_new (WirelessSecurity *ws_parent, gboolean is_editor, gboolean secrets_only) { - EAPMethod *parent; EAPMethodPEAP *self; GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; const char *filename; + EAPMethodSimpleFlags simple_flags; + const gchar *phase2_auth = NULL; + GtkTreeIter iter; - parent = eap_method_init (sizeof (EAPMethodPEAP), - validate, - add_to_size_group, - fill_connection, - update_secrets, - destroy, - "/org/gnome/ControlCenter/network/eap-method-peap.ui", - "grid", - "anon_identity_entry", - FALSE); - if (!parent) - return NULL; - - parent->password_flags_name = NM_SETTING_802_1X_PASSWORD; - self = (EAPMethodPEAP *) parent; - self->sec_parent = ws_parent; + self = g_object_new (eap_method_peap_get_type (), NULL); self->is_editor = is_editor; - self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "anon_identity_entry")); - self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "anon_identity_label")); - self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_button")); - self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "ca_cert_label")); - self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_not_required_check")); - self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "inner_auth_combo")); - self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "inner_auth_label")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); - self->version_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "version_combo")); - self->version_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "version_label")); - if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); @@ -356,10 +290,55 @@ eap_method_peap_new (WirelessSecurity *ws_parent, gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (self->ca_cert_button), filename); } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), - !filename && eap_method_ca_cert_ignore_get (parent, connection)); + !filename && eap_method_ca_cert_ignore_get (EAP_METHOD (self), connection)); + } + + simple_flags = EAP_METHOD_SIMPLE_FLAG_PHASE2; + 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_mschap_v2 = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_MSCHAP_V2, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_mschap_v2)); + g_signal_connect_object (self->em_mschap_v2, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + self->em_md5 = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_MD5, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_md5)); + g_signal_connect_object (self->em_md5, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + self->em_gtc = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_GTC, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_gtc)); + g_signal_connect_object (self->em_gtc, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + 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 = "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)); } - inner_auth_combo_init (self, connection, s_8021x, secrets_only); + g_signal_connect_swapped (self->inner_auth_combo, "changed", G_CALLBACK (inner_auth_combo_changed_cb), self); inner_auth_combo_changed_cb (self); gtk_combo_box_set_active (self->version_combo, 0); diff --git a/panels/network/wireless-security/eap-method-peap.h b/panels/network/wireless-security/eap-method-peap.h index 45625fb933968e66d0c96080f6a55f0d0def8f94..b79641799fc30a686777b4517e3c2ba3db984b9d 100644 --- a/panels/network/wireless-security/eap-method-peap.h +++ b/panels/network/wireless-security/eap-method-peap.h @@ -20,20 +20,20 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_PEAP_H -#define EAP_METHOD_PEAP_H +#pragma once + +#include +#include #include "wireless-security.h" -typedef struct _EAPMethodPEAP EAPMethodPEAP; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodPEAP, eap_method_peap, EAP, METHOD_PEAP, GtkGrid) EAPMethodPEAP *eap_method_peap_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean is_editor, gboolean secrets_only); -static void eap_method_peap_unref (EAPMethodPEAP *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodPEAP, eap_method_peap_unref) - -#endif /* EAP_METHOD_PEAP_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-peap.ui b/panels/network/wireless-security/eap-method-peap.ui index 8190d489852739cc1da6a93b1853bb79db9a654a..32766bf7aa90b3581cceffaa8a2bc7dca6ddb1d5 100644 --- a/panels/network/wireless-security/eap-method-peap.ui +++ b/panels/network/wireless-security/eap-method-peap.ui @@ -1,14 +1,25 @@ - + - + + + - + MSCHAPv2 + mschapv2 + + + MD5 + md5 + + + GTC + gtc @@ -29,8 +40,7 @@ - - True + diff --git a/panels/network/wireless-security/eap-method-simple.c b/panels/network/wireless-security/eap-method-simple.c index 59b49a40d4776eff90d51dcf12ec133124ae93ef..f4324e92dbfcd6c9fbd8ce0790203f912b737f45 100644 --- a/panels/network/wireless-security/eap-method-simple.c +++ b/panels/network/wireless-security/eap-method-simple.c @@ -20,21 +20,18 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - -#include -#include +#include #include "eap-method.h" -#include "wireless-security.h" +#include "eap-method-simple.h" #include "helpers.h" #include "nma-ui-utils.h" -#include "utils.h" +#include "ui-helpers.h" +#include "wireless-security.h" struct _EAPMethodSimple { - EAPMethod parent; + GtkGrid parent; - GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; GtkToggleButton *show_password_check; @@ -49,6 +46,11 @@ struct _EAPMethodSimple { guint idle_func_id; }; +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodSimple, eap_method_simple, GTK_TYPE_GRID, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + static void show_toggled_cb (EAPMethodSimple *self) { @@ -66,9 +68,9 @@ always_ask_selected (GtkEntry *passwd_entry) } static gboolean -validate (EAPMethod *parent, GError **error) +validate (EAPMethod *method, GError **error) { - EAPMethodSimple *self = (EAPMethodSimple *)parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); const char *text; gboolean ret = TRUE; @@ -99,9 +101,9 @@ validate (EAPMethod *parent, GError **error) } static void -add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) +add_to_size_group (EAPMethod *method, GtkSizeGroup *group) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); gtk_size_group_add_widget (group, GTK_WIDGET (self->username_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->password_label)); } @@ -124,9 +126,9 @@ static const EapType eap_table[EAP_METHOD_SIMPLE_TYPE_LAST] = { }; static void -fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags prev_flags) +fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags prev_flags) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); NMSetting8021x *s_8021x; gboolean not_saved = FALSE; NMSettingSecretFlags flags; @@ -138,11 +140,11 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla /* If this is the main EAP method, clear any existing methods because the * user-selected on will replace it. */ - if (parent->phase2 == FALSE) + if (eap_method_get_phase2 (method) == FALSE) nm_setting_802_1x_clear_eap_methods (s_8021x); eap_type = &eap_table[self->type]; - if (parent->phase2) { + if (eap_method_get_phase2 (method)) { /* If the outer EAP method (TLS, TTLS, PEAP, etc) allows inner/phase2 * EAP methods (which only TTLS allows) *and* the inner/phase2 method * supports being an inner EAP method, then set PHASE2_AUTHEAP. @@ -176,24 +178,44 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla /* Update secret flags and popup when editing the connection */ if (!(self->flags & EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY)) { nma_utils_update_password_storage (GTK_WIDGET (self->password_entry), flags, - NM_SETTING (s_8021x), parent->password_flags_name); + NM_SETTING (s_8021x), NM_SETTING_802_1X_PASSWORD); } } static void -update_secrets (EAPMethod *parent, NMConnection *connection) +update_secrets (EAPMethod *method, NMConnection *connection) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); helper_fill_secret_entry (connection, self->password_entry, NM_TYPE_SETTING_802_1X, (HelperSecretFunc) nm_setting_802_1x_get_password); } +static GtkWidget * +get_default_field (EAPMethod *method) +{ + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); + return GTK_WIDGET (self->username_entry); +} + +static const gchar * +get_password_flags_name (EAPMethod *method) +{ + return NM_SETTING_802_1X_PASSWORD; +} + +static const gboolean +get_phase2 (EAPMethod *method) +{ + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); + return self->flags & EAP_METHOD_SIMPLE_FLAG_PHASE2; +} + static gboolean stuff_changed (EAPMethodSimple *self) { - wireless_security_notify_changed (self->ws_parent); + eap_method_emit_changed (EAP_METHOD (self)); self->idle_func_id = 0; return FALSE; } @@ -246,31 +268,70 @@ widgets_realized (EAPMethodSimple *self) static void widgets_unrealized (EAPMethodSimple *self) { - wireless_security_set_userpass (self->ws_parent, - gtk_entry_get_text (self->username_entry), - gtk_entry_get_text (self->password_entry), - always_ask_selected (self->password_entry), - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check))); + wireless_security_set_username (self->ws_parent, gtk_entry_get_text (self->username_entry)); + wireless_security_set_password (self->ws_parent, gtk_entry_get_text (self->password_entry)); + wireless_security_set_always_ask (self->ws_parent, always_ask_selected (self->password_entry)); + wireless_security_set_show_password (self->ws_parent, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check))); } static void -destroy (EAPMethod *parent) +eap_method_simple_dispose (GObject *object) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (object); - g_signal_handlers_disconnect_by_data (self->grid, self); + g_signal_handlers_disconnect_by_data (self, self); g_signal_handlers_disconnect_by_data (self->username_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self); g_signal_handlers_disconnect_by_data (self->show_password_check, self); - nm_clear_g_source (&self->idle_func_id); + if (self->idle_func_id != 0) { + g_source_remove (self->idle_func_id); + self->idle_func_id = 0; + } + + G_OBJECT_CLASS (eap_method_simple_parent_class)->dispose (object); } static void changed_cb (EAPMethodSimple *self) { - wireless_security_notify_changed (self->ws_parent); + eap_method_emit_changed (EAP_METHOD (self)); +} + +static void +eap_method_simple_init (EAPMethodSimple *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +static void +eap_method_simple_class_init (EAPMethodSimpleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->dispose = eap_method_simple_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-simple.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, password_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, username_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, password_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, show_password_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, username_entry); +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; + iface->get_phase2 = get_phase2; } EAPMethodSimple * @@ -279,39 +340,17 @@ eap_method_simple_new (WirelessSecurity *ws_parent, EAPMethodSimpleType type, EAPMethodSimpleFlags flags) { - EAPMethod *parent; EAPMethodSimple *self; NMSetting8021x *s_8021x = NULL; - parent = eap_method_init (sizeof (EAPMethodSimple), - validate, - add_to_size_group, - fill_connection, - update_secrets, - destroy, - "/org/gnome/ControlCenter/network/eap-method-simple.ui", - "grid", - "username_entry", - flags & EAP_METHOD_SIMPLE_FLAG_PHASE2); - if (!parent) - return NULL; - - parent->password_flags_name = NM_SETTING_802_1X_PASSWORD; - self = (EAPMethodSimple *) parent; + self = g_object_new (eap_method_simple_get_type (), NULL); self->ws_parent = ws_parent; self->flags = flags; self->type = type; g_assert (type < EAP_METHOD_SIMPLE_TYPE_LAST); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "password_label")); - self->username_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "username_label")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "password_entry")); - self->show_password_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->username_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "username_entry")); - - g_signal_connect_swapped (self->grid, "realize", G_CALLBACK (widgets_realized), self); - g_signal_connect_swapped (self->grid, "unrealize", G_CALLBACK (widgets_unrealized), self); + g_signal_connect_swapped (self, "realize", G_CALLBACK (widgets_realized), self); + g_signal_connect_swapped (self, "unrealize", G_CALLBACK (widgets_unrealized), self); g_signal_connect_swapped (self->username_entry, "changed", G_CALLBACK (changed_cb), self); @@ -323,7 +362,7 @@ eap_method_simple_new (WirelessSecurity *ws_parent, /* Create password-storage popup menu for password entry under entry's secondary icon */ if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); - nma_utils_setup_password_storage (GTK_WIDGET (self->password_entry), 0, (NMSetting *) s_8021x, parent->password_flags_name, + nma_utils_setup_password_storage (GTK_WIDGET (self->password_entry), 0, (NMSetting *) s_8021x, NM_SETTING_802_1X_PASSWORD, FALSE, flags & EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY); g_signal_connect_swapped (self->password_entry, "notify::secondary-icon-name", G_CALLBACK (password_storage_changed), self); diff --git a/panels/network/wireless-security/eap-method-simple.h b/panels/network/wireless-security/eap-method-simple.h index 8a2c3400edbce4e6d027b2a804563ec6fbb24d40..527b7dbc45c731e2d925ebae41601b0040d54df8 100644 --- a/panels/network/wireless-security/eap-method-simple.h +++ b/panels/network/wireless-security/eap-method-simple.h @@ -20,11 +20,17 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_SIMPLE_H -#define EAP_METHOD_SIMPLE_H +#pragma once + +#include +#include #include "wireless-security.h" +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodSimple, eap_method_simple, EAP, METHOD_SIMPLE, GtkGrid) + typedef enum { /* NOTE: when updating this table, also update eap_methods[] */ EAP_METHOD_SIMPLE_TYPE_PAP = 0, @@ -52,15 +58,9 @@ typedef enum { EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY = 0x08 } EAPMethodSimpleFlags; -typedef struct _EAPMethodSimple EAPMethodSimple; - EAPMethodSimple *eap_method_simple_new (WirelessSecurity *ws_parent, NMConnection *connection, EAPMethodSimpleType type, EAPMethodSimpleFlags flags); -static void eap_method_simple_unref (EAPMethodSimple *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodSimple, eap_method_simple_unref) - -#endif /* EAP_METHOD_SIMPLE_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-simple.ui b/panels/network/wireless-security/eap-method-simple.ui index 00799ac93fbef9e8ff8f1c4702ba711b9cade116..59691ba7b5ab292052d14fae72bed01b06166734 100644 --- a/panels/network/wireless-security/eap-method-simple.ui +++ b/panels/network/wireless-security/eap-method-simple.ui @@ -1,8 +1,7 @@ - - True + diff --git a/panels/network/wireless-security/eap-method-tls.c b/panels/network/wireless-security/eap-method-tls.c index ffc6632b394d2a462c041c1936f55081c33d0e56..fadd6e06641de00632597c62c7310c32e3e9b275 100644 --- a/panels/network/wireless-security/eap-method-tls.c +++ b/panels/network/wireless-security/eap-method-tls.c @@ -20,19 +20,17 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - -#include -#include +#include #include "eap-method.h" -#include "wireless-security.h" +#include "eap-method-tls.h" #include "helpers.h" #include "nma-ui-utils.h" -#include "utils.h" +#include "ui-helpers.h" +#include "wireless-security.h" struct _EAPMethodTLS { - EAPMethod parent; + GtkGrid parent; GtkFileChooserButton *ca_cert_button; GtkLabel *ca_cert_label; @@ -47,10 +45,15 @@ struct _EAPMethodTLS { GtkFileChooserButton *user_cert_button; GtkLabel *user_cert_label; - WirelessSecurity *sec_parent; + gboolean phase2; + const gchar *password_flags_name; gboolean editing_connection; }; +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodTLS, eap_method_tls, GTK_TYPE_GRID, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) static void show_toggled_cb (EAPMethodTLS *self) @@ -62,9 +65,9 @@ show_toggled_cb (EAPMethodTLS *self) } static gboolean -validate (EAPMethod *parent, GError **error) +validate (EAPMethod *method, GError **error) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char *password, *identity; g_autoptr(GError) ca_cert_error = NULL; @@ -88,10 +91,12 @@ validate (EAPMethod *parent, GError **error) g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TLS CA certificate: %s"), ca_cert_error->message); ret = FALSE; } - } else if (eap_method_ca_cert_required (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), - GTK_FILE_CHOOSER (self->ca_cert_button))) { - widget_set_error (GTK_WIDGET (self->ca_cert_button)); - if (ret) { + } else if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check))) { + g_autofree gchar *filename = NULL; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button)); + if (filename == NULL) { + widget_set_error (GTK_WIDGET (self->ca_cert_button)); g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TLS CA certificate: no certificate specified")); ret = FALSE; } @@ -130,13 +135,13 @@ ca_cert_not_required_toggled (EAPMethodTLS *self) { eap_method_ca_cert_not_required_toggled (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), GTK_FILE_CHOOSER (self->ca_cert_button)); - wireless_security_notify_changed (self->sec_parent); + eap_method_emit_changed (EAP_METHOD (self)); } static void -add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) +add_to_size_group (EAPMethod *method, GtkSizeGroup *group) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); gtk_size_group_add_widget (group, GTK_WIDGET (self->ca_cert_not_required_check)); gtk_size_group_add_widget (group, GTK_WIDGET (self->identity_label)); @@ -147,9 +152,9 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) } static void -fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags) +fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; NMSetting8021x *s_8021x; NMSettingSecretFlags secret_flags; @@ -161,7 +166,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla s_8021x = nm_connection_get_setting_802_1x (connection); g_assert (s_8021x); - if (parent->phase2) + if (self->phase2) g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "tls", NULL); else nm_setting_802_1x_add_eap_method (s_8021x, "tls"); @@ -174,7 +179,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla pk_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->private_key_button)); g_assert (pk_filename); - if (parent->phase2) { + if (self->phase2) { g_autoptr(GError) error = NULL; if (!nm_setting_802_1x_set_phase2_private_key (s_8021x, pk_filename, password, NM_SETTING_802_1X_CK_SCHEME_PATH, &format, &error)) g_warning ("Couldn't read phase2 private key '%s': %s", pk_filename, error ? error->message : "(unknown)"); @@ -186,13 +191,13 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla /* Save 802.1X password flags to the connection */ secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->private_key_password_entry)); - nm_setting_set_secret_flags (NM_SETTING (s_8021x), parent->password_flags_name, + nm_setting_set_secret_flags (NM_SETTING (s_8021x), self->password_flags_name, secret_flags, NULL); /* Update secret flags and popup when editing the connection */ if (self->editing_connection) { nma_utils_update_password_storage (GTK_WIDGET (self->private_key_password_entry), secret_flags, - NM_SETTING (s_8021x), parent->password_flags_name); + NM_SETTING (s_8021x), self->password_flags_name); } /* TLS client certificate */ @@ -206,7 +211,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla g_assert (cc_filename); format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - if (parent->phase2) { + if (self->phase2) { g_autoptr(GError) error = NULL; if (!nm_setting_802_1x_set_phase2_client_cert (s_8021x, cc_filename, NM_SETTING_802_1X_CK_SCHEME_PATH, &format, &error)) g_warning ("Couldn't read phase2 client certificate '%s': %s", cc_filename, error ? error->message : "(unknown)"); @@ -221,7 +226,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla ca_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button)); format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - if (parent->phase2) { + if (self->phase2) { g_autoptr(GError) error = NULL; if (!nm_setting_802_1x_set_phase2_ca_cert (s_8021x, ca_filename, NM_SETTING_802_1X_CK_SCHEME_PATH, &format, &error)) { g_warning ("Couldn't read phase2 CA certificate '%s': %s", ca_filename, error ? error->message : "(unknown)"); @@ -234,13 +239,12 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla ca_cert_error = TRUE; } } - eap_method_ca_cert_ignore_set (parent, connection, ca_filename, ca_cert_error); + eap_method_ca_cert_ignore_set (method, connection, ca_filename, ca_cert_error); } static void -private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean changed) +private_key_picker_helper (EAPMethodTLS *self, const char *filename, gboolean changed) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; g_autoptr(NMSetting8021x) setting = NULL; NMSetting8021xCKFormat cert_format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char *password; @@ -263,7 +267,7 @@ private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean cha GtkWidget *toplevel; GtkWindow *parent_window = NULL; - toplevel = gtk_widget_get_toplevel (parent->ui_widget); + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); if (gtk_widget_is_toplevel (toplevel)) parent_window = GTK_WINDOW (toplevel); @@ -284,12 +288,12 @@ private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean cha static void private_key_picker_file_set_cb (GtkWidget *chooser, gpointer user_data) { - EAPMethod *parent = (EAPMethod *) user_data; + EAPMethodTLS *self = user_data; g_autofree gchar *filename = NULL; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); if (filename) - private_key_picker_helper (parent, filename, TRUE); + private_key_picker_helper (self, filename, TRUE); } static void reset_filter (GtkWidget *widget, GParamSpec *spec, gpointer user_data) @@ -307,14 +311,14 @@ typedef NMSetting8021xCKScheme (*SchemeFunc) (NMSetting8021x *setting); static void changed_cb (EAPMethodTLS *self) { - wireless_security_notify_changed (self->sec_parent); + eap_method_emit_changed (EAP_METHOD (self)); } static void -setup_filepicker (GtkFileChooserButton *button, +setup_filepicker (EAPMethodTLS *self, + GtkFileChooserButton *button, const char *title, WirelessSecurity *ws_parent, - EAPMethod *parent, NMSetting8021x *s_8021x, SchemeFunc scheme_func, PathFunc path_func, @@ -341,12 +345,12 @@ setup_filepicker (GtkFileChooserButton *button, if (privkey) { g_signal_connect (button, "selection-changed", (GCallback) private_key_picker_file_set_cb, - parent); + self); if (filename) - private_key_picker_helper (parent, filename, FALSE); + private_key_picker_helper (self, filename, FALSE); } - g_signal_connect_swapped (button, "selection-changed", G_CALLBACK (changed_cb), parent); + g_signal_connect_swapped (button, "selection-changed", G_CALLBACK (changed_cb), self); filter = eap_method_default_file_chooser_filter_new (privkey); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (button), filter); @@ -361,16 +365,16 @@ setup_filepicker (GtkFileChooserButton *button, } static void -update_secrets (EAPMethod *parent, NMConnection *connection) +update_secrets (EAPMethod *method, NMConnection *connection) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); NMSetting8021x *s_8021x; HelperSecretFunc password_func; SchemeFunc scheme_func; PathFunc path_func; const char *filename; - if (parent->phase2) { + if (self->phase2) { password_func = (HelperSecretFunc) nm_setting_802_1x_get_phase2_private_key_password; scheme_func = nm_setting_802_1x_get_phase2_private_key_scheme; path_func = nm_setting_802_1x_get_phase2_private_key_path; @@ -394,6 +398,66 @@ update_secrets (EAPMethod *parent, NMConnection *connection) } } +static GtkWidget * +get_default_field (EAPMethod *method) +{ + EAPMethodTLS *self = EAP_METHOD_TLS (method); + return GTK_WIDGET (self->identity_entry); +} + +static const gchar * +get_password_flags_name (EAPMethod *method) +{ + EAPMethodTLS *self = EAP_METHOD_TLS (method); + return self->password_flags_name; +} + +static gboolean +get_phase2 (EAPMethod *method) +{ + EAPMethodTLS *self = EAP_METHOD_TLS (method); + return self->phase2; +} + +static void +eap_method_tls_init (EAPMethodTLS *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); +} + +static void +eap_method_tls_class_init (EAPMethodTLSClass *klass) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-tls.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, ca_cert_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, ca_cert_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, ca_cert_not_required_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, identity_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, identity_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, private_key_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, private_key_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, private_key_password_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, private_key_password_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, show_password_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, user_cert_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, user_cert_label); +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; + iface->get_phase2 = get_phase2; +} + EAPMethodTLS * eap_method_tls_new (WirelessSecurity *ws_parent, NMConnection *connection, @@ -401,43 +465,16 @@ eap_method_tls_new (WirelessSecurity *ws_parent, gboolean secrets_only) { EAPMethodTLS *self; - EAPMethod *parent; NMSetting8021x *s_8021x = NULL; gboolean ca_not_required = FALSE; - parent = eap_method_init (sizeof (EAPMethodTLS), - validate, - add_to_size_group, - fill_connection, - update_secrets, - NULL, - "/org/gnome/ControlCenter/network/eap-method-tls.ui", - "grid", - "identity_entry", - phase2); - if (!parent) - return NULL; - - parent->password_flags_name = phase2 ? - NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD : - NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD; - self = (EAPMethodTLS *) parent; - self->sec_parent = ws_parent; + self = g_object_new (eap_method_tls_get_type (), NULL); + self->phase2 = phase2; + self->password_flags_name = phase2 ? + NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD : + NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD; self->editing_connection = secrets_only ? FALSE : TRUE; - self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_button")); - self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "ca_cert_label")); - self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_not_required_check")); - self->identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "identity_entry")); - self->identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "identity_label")); - self->private_key_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "private_key_button")); - self->private_key_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "private_key_label")); - self->private_key_password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "private_key_password_entry")); - self->private_key_password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "private_key_password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->user_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "user_cert_button")); - self->user_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "user_cert_label")); - if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); @@ -447,37 +484,40 @@ eap_method_tls_new (WirelessSecurity *ws_parent, if (s_8021x && nm_setting_802_1x_get_identity (s_8021x)) gtk_entry_set_text (self->identity_entry, nm_setting_802_1x_get_identity (s_8021x)); - setup_filepicker (self->user_cert_button, + setup_filepicker (self, + self->user_cert_button, _("Choose your personal certificate"), - ws_parent, parent, s_8021x, + ws_parent, s_8021x, phase2 ? nm_setting_802_1x_get_phase2_client_cert_scheme : nm_setting_802_1x_get_client_cert_scheme, phase2 ? nm_setting_802_1x_get_phase2_client_cert_path : nm_setting_802_1x_get_client_cert_path, FALSE, TRUE); - setup_filepicker (self->ca_cert_button, + setup_filepicker (self, + self->ca_cert_button, _("Choose a Certificate Authority certificate"), - ws_parent, parent, s_8021x, + ws_parent, s_8021x, phase2 ? nm_setting_802_1x_get_phase2_ca_cert_scheme : nm_setting_802_1x_get_ca_cert_scheme, phase2 ? nm_setting_802_1x_get_phase2_ca_cert_path : nm_setting_802_1x_get_ca_cert_path, FALSE, FALSE); - setup_filepicker (self->private_key_button, + setup_filepicker (self, + self->private_key_button, _("Choose your private key"), - ws_parent, parent, s_8021x, + ws_parent, s_8021x, phase2 ? nm_setting_802_1x_get_phase2_private_key_scheme : nm_setting_802_1x_get_private_key_scheme, phase2 ? nm_setting_802_1x_get_phase2_private_key_path : nm_setting_802_1x_get_private_key_path, TRUE, FALSE); - if (connection && eap_method_ca_cert_ignore_get (parent, connection)) + if (connection && eap_method_ca_cert_ignore_get (EAP_METHOD (self), connection)) ca_not_required = !gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), ca_not_required); /* Fill secrets, if any */ if (connection) - update_secrets (parent, connection); + update_secrets (EAP_METHOD (self), connection); g_signal_connect_swapped (self->private_key_password_entry, "changed", G_CALLBACK (changed_cb), self); /* Create password-storage popup menu for password entry under entry's secondary icon */ - nma_utils_setup_password_storage (GTK_WIDGET (self->private_key_password_entry), 0, (NMSetting *) s_8021x, parent->password_flags_name, + nma_utils_setup_password_storage (GTK_WIDGET (self->private_key_password_entry), 0, (NMSetting *) s_8021x, self->password_flags_name, FALSE, secrets_only); g_signal_connect_swapped (self->show_password_check, "toggled", G_CALLBACK (show_toggled_cb), self); diff --git a/panels/network/wireless-security/eap-method-tls.h b/panels/network/wireless-security/eap-method-tls.h index 341580f093310b06457e021c38cf814b17d934d9..fff224565d1cb3986392c999b45877583fc98a75 100644 --- a/panels/network/wireless-security/eap-method-tls.h +++ b/panels/network/wireless-security/eap-method-tls.h @@ -20,20 +20,20 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_TLS_H -#define EAP_METHOD_TLS_H +#pragma once + +#include +#include #include "wireless-security.h" -typedef struct _EAPMethodTLS EAPMethodTLS; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodTLS, eap_method_tls, EAP, METHOD_TLS, GtkGrid) EAPMethodTLS *eap_method_tls_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean phase2, gboolean secrets_only); -static void eap_method_tls_unref (EAPMethodTLS *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodTLS, eap_method_tls_unref) - -#endif /* EAP_METHOD_TLS_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-tls.ui b/panels/network/wireless-security/eap-method-tls.ui index 194ac41e5615e0d59e0cf7022bd30982e7b300d1..61f8e5d4d55f7aab28ebc378db28c5390cc517e6 100644 --- a/panels/network/wireless-security/eap-method-tls.ui +++ b/panels/network/wireless-security/eap-method-tls.ui @@ -1,8 +1,7 @@ - - True + diff --git a/panels/network/wireless-security/eap-method-ttls.c b/panels/network/wireless-security/eap-method-ttls.c index c474f7795d4b5747d8d067a036a598a092716a33..198b08a18283411e59c801adfad887d61c4f555d 100644 --- a/panels/network/wireless-security/eap-method-ttls.c +++ b/panels/network/wireless-security/eap-method-ttls.c @@ -20,20 +20,19 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - -#include -#include +#include #include "eap-method.h" +#include "eap-method-simple.h" +#include "eap-method-ttls.h" +#include "helpers.h" #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 { - EAPMethod parent; + GtkGrid parent; GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; @@ -44,29 +43,57 @@ 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; - WirelessSecurity *sec_parent; + EAPMethodSimple *em_chap; + EAPMethodSimple *em_gtc; + EAPMethodSimple *em_md5; + EAPMethodSimple *em_mschap; + EAPMethodSimple *em_mschap_v2; + EAPMethodSimple *em_pap; + EAPMethodSimple *em_plain_mschap_v2; + gboolean is_editor; }; -static void -destroy (EAPMethod *parent) +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 EAPMethod * +get_inner_method (EAPMethodTTLS *self) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + GtkTreeIter iter; + g_autofree gchar *id = NULL; - g_clear_object (&self->size_group); + 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 *parent, GError **error) +validate (EAPMethod *method, GError **error) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; - GtkTreeModel *model; - GtkTreeIter iter; - g_autoptr(EAPMethod) eap = NULL; - gboolean valid = FALSE; + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); g_autoptr(GError) local_error = NULL; if (!eap_method_validate_filepicker (GTK_FILE_CHOOSER (self->ca_cert_button), @@ -74,18 +101,17 @@ validate (EAPMethod *parent, GError **error) g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TTLS CA certificate: %s"), local_error->message); return FALSE; } - if (eap_method_ca_cert_required (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), - GTK_FILE_CHOOSER (self->ca_cert_button))) { - g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TTLS CA certificate: no certificate specified")); - return FALSE; + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check))) { + g_autofree gchar *filename = NULL; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button)); + if (filename == NULL) { + g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid EAP-TTLS CA certificate: no certificate specified")); + 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 @@ -93,19 +119,13 @@ ca_cert_not_required_toggled (EAPMethodTTLS *self) { eap_method_ca_cert_not_required_toggled (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), GTK_FILE_CHOOSER (self->ca_cert_button)); - wireless_security_notify_changed (self->sec_parent); + eap_method_emit_changed (EAP_METHOD (self)); } static void -add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) +add_to_size_group (EAPMethod *method, GtkSizeGroup *group) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; - GtkTreeModel *model; - GtkTreeIter iter; - g_autoptr(EAPMethod) eap = NULL; - - g_clear_object (&self->size_group); - self->size_group = g_object_ref (group); + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); 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)); @@ -113,24 +133,23 @@ add_to_size_group (EAPMethod *parent, 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 -fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags) +fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); NMSetting8021x *s_8021x; 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; @@ -152,201 +171,95 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla g_warning ("Couldn't read CA certificate '%s': %s", filename, error ? error->message : "(unknown)"); ca_cert_error = TRUE; } - eap_method_ca_cert_ignore_set (parent, connection, filename, ca_cert_error); + 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; - GtkWidget *eap_widget; - /* 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); - eap_widget = eap_method_get_widget (eap); - g_assert (eap_widget); - gtk_widget_unparent (eap_widget); + inner_method = get_inner_method (self); + gtk_container_add (GTK_CONTAINER (self->inner_auth_box), g_object_ref (GTK_WIDGET (inner_method))); - if (self->size_group) - eap_method_add_to_size_group (eap, self->size_group); - gtk_container_add (GTK_CONTAINER (self->inner_auth_box), eap_widget); - - wireless_security_notify_changed (self->sec_parent); + eap_method_emit_changed (EAP_METHOD (self)); } static void -inner_auth_combo_init (EAPMethodTTLS *self, - NMConnection *connection, - NMSetting8021x *s_8021x, - gboolean secrets_only) +update_secrets (EAPMethod *method, NMConnection *connection) { - 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 ()); + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); + + 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); +} - 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); - } +static GtkWidget * +get_default_field (EAPMethod *method) +{ + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); + return GTK_WIDGET (self->anon_identity_entry); +} - 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; +static const gchar * +get_password_flags_name (EAPMethod *method) +{ + return NM_SETTING_802_1X_PASSWORD; +} - 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); +static void +changed_cb (EAPMethodTTLS *self) +{ + eap_method_emit_changed (EAP_METHOD (self)); +} - g_signal_connect_swapped (self->inner_auth_combo, "changed", G_CALLBACK (inner_auth_combo_changed_cb), self); +static void +eap_method_ttls_init (EAPMethodTTLS *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); } static void -update_secrets (EAPMethod *parent, NMConnection *connection) +eap_method_ttls_class_init (EAPMethodTTLSClass *klass) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; - eap_method_phase2_update_secrets_helper (parent, - connection, - self->inner_auth_combo, - I_METHOD_COLUMN); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + 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); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, anon_identity_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, ca_cert_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, ca_cert_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, ca_cert_not_required_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, domain_match_entry); + 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); } static void -changed_cb (EAPMethodTTLS *self) +eap_method_iface_init (EAPMethodInterface *iface) { - wireless_security_notify_changed (self->sec_parent); + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; } EAPMethodTTLS * @@ -355,41 +268,17 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, gboolean is_editor, gboolean secrets_only) { - EAPMethod *parent; EAPMethodTTLS *self; GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; const char *filename; + EAPMethodSimpleFlags simple_flags; + const char *phase2_auth = NULL; + GtkTreeIter iter; - parent = eap_method_init (sizeof (EAPMethodTTLS), - validate, - add_to_size_group, - fill_connection, - update_secrets, - destroy, - "/org/gnome/ControlCenter/network/eap-method-ttls.ui", - "grid", - "anon_identity_entry", - FALSE); - if (!parent) - return NULL; - - parent->password_flags_name = NM_SETTING_802_1X_PASSWORD; - self = (EAPMethodTTLS *) parent; - self->sec_parent = ws_parent; + self = g_object_new (eap_method_ttls_get_type (), NULL); self->is_editor = is_editor; - self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "anon_identity_entry")); - self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "anon_identity_label")); - self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_button")); - self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "ca_cert_label")); - self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_not_required_check")); - self->domain_match_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "domain_match_entry")); - self->domain_match_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "domain_match_label")); - self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "inner_auth_combo")); - self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "inner_auth_label")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); - if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); @@ -409,7 +298,7 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (self->ca_cert_button), filename); } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), - !filename && eap_method_ca_cert_ignore_get (parent, connection)); + !filename && eap_method_ca_cert_ignore_get (EAP_METHOD (self), connection)); } if (s_8021x && nm_setting_802_1x_get_anonymous_identity (s_8021x)) @@ -419,7 +308,83 @@ 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 (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_PAP, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_pap)); + g_signal_connect_object (self->em_pap, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + self->em_mschap = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_MSCHAP, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_mschap)); + g_signal_connect_object (self->em_mschap, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + self->em_mschap_v2 = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_MSCHAP_V2, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_mschap_v2)); + g_signal_connect_object (self->em_mschap_v2, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + self->em_plain_mschap_v2 = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_PLAIN_MSCHAP_V2, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_plain_mschap_v2)); + g_signal_connect_object (self->em_plain_mschap_v2, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + self->em_chap = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_CHAP, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_chap)); + g_signal_connect_object (self->em_chap, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + self->em_md5 = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_MD5, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_md5)); + g_signal_connect_object (self->em_md5, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + self->em_gtc = eap_method_simple_new (ws_parent, + connection, + EAP_METHOD_SIMPLE_TYPE_GTC, + simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_gtc)); + g_signal_connect_object (self->em_gtc, "changed", G_CALLBACK (eap_method_emit_changed), self, G_CONNECT_SWAPPED); + + 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.h b/panels/network/wireless-security/eap-method-ttls.h index 836a6d9e6ab2797cfa51a743d9b5319dc3356241..9a0be55efaee94cbaebf22a07e2fd1bdd1f147da 100644 --- a/panels/network/wireless-security/eap-method-ttls.h +++ b/panels/network/wireless-security/eap-method-ttls.h @@ -20,20 +20,20 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_TTLS_H -#define EAP_METHOD_TTLS_H +#pragma once + +#include +#include #include "wireless-security.h" -typedef struct _EAPMethodTTLS EAPMethodTTLS; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodTTLS, eap_method_ttls, EAP, METHOD_TTLS, GtkGrid) EAPMethodTTLS *eap_method_ttls_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean is_editor, gboolean secrets_only); -static void eap_method_ttls_unref (EAPMethodTTLS *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodTTLS, eap_method_ttls_unref) - -#endif /* EAP_METHOD_TTLS_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-ttls.ui b/panels/network/wireless-security/eap-method-ttls.ui index 519d99379f02612e3796eaaedebde82a088fcd73..2ba7d2011e534d8b08b75c056e68f2156aaa115d 100644 --- a/panels/network/wireless-security/eap-method-ttls.ui +++ b/panels/network/wireless-security/eap-method-ttls.ui @@ -1,19 +1,45 @@ - + - + + + - + PAP + pap + + + MSCHAP + mschap + + + MSCHAPv2 + mschapv2 + + + MSCHAPv2 (no EAP) + plain_mschapv2 + + + CHAP + chap + + + MD5 + md5 + + + GTC + gtc - - True + diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c index 2030e954ac3b3c65042eff6d4249ecb2c0bc966d..c392da8f534565cd78354f78414dc845fe85a61e 100644 --- a/panels/network/wireless-security/eap-method.c +++ b/panels/network/wireless-security/eap-method.c @@ -21,38 +21,63 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - -#include -#include -#include #include -#include +#include #include "eap-method.h" -#include "utils.h" #include "helpers.h" +#include "ui-helpers.h" -GType -eap_method_get_type (void) -{ - static GType type_id = 0; +G_DEFINE_INTERFACE (EAPMethod, eap_method, G_TYPE_OBJECT) + +enum { + CHANGED, + LAST_SIGNAL +}; - if (!type_id) { - type_id = g_boxed_type_register_static ("CcEAPMethod", - (GBoxedCopyFunc) eap_method_ref, - (GBoxedFreeFunc) eap_method_unref); - } +static guint signals[LAST_SIGNAL] = { 0 }; - return type_id; +static void +eap_method_default_init (EAPMethodInterface *iface) +{ + signals[CHANGED] = + g_signal_new ("changed", + G_TYPE_FROM_INTERFACE (iface), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } GtkWidget * -eap_method_get_widget (EAPMethod *self) +eap_method_get_default_field (EAPMethod *self) +{ + g_return_val_if_fail (self != NULL, NULL); + + return EAP_METHOD_GET_IFACE (self)->get_default_field (self); +} + +const gchar * +eap_method_get_password_flags_name (EAPMethod *self) { g_return_val_if_fail (self != NULL, NULL); - return self->ui_widget; + if (EAP_METHOD_GET_IFACE (self)->get_password_flags_name) + return EAP_METHOD_GET_IFACE (self)->get_password_flags_name (self); + else + return NULL; +} + +gboolean +eap_method_get_phase2 (EAPMethod *self) +{ + g_return_val_if_fail (self != NULL, FALSE); + + if (EAP_METHOD_GET_IFACE (self)->get_phase2) + return EAP_METHOD_GET_IFACE (self)->get_phase2 (self); + else + return FALSE; } gboolean @@ -62,149 +87,47 @@ eap_method_validate (EAPMethod *self, GError **error) g_return_val_if_fail (self != NULL, FALSE); - g_assert (self->validate); - result = (*(self->validate)) (self, error); + result = (*(EAP_METHOD_GET_IFACE (self)->validate)) (self, error); if (!result && error && !*error) g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("undefined error in 802.1X security (wpa-eap)")); return result; } void -eap_method_add_to_size_group (EAPMethod *self, GtkSizeGroup *group) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (group != NULL); - - g_assert (self->add_to_size_group); - return (*(self->add_to_size_group)) (self, group); -} - -void -eap_method_fill_connection (EAPMethod *self, - NMConnection *connection, - NMSettingSecretFlags flags) +eap_method_update_secrets (EAPMethod *self, NMConnection *connection) { g_return_if_fail (self != NULL); - g_return_if_fail (connection != NULL); - g_assert (self->fill_connection); - return (*(self->fill_connection)) (self, connection, flags); + if (EAP_METHOD_GET_IFACE (self)->update_secrets) + EAP_METHOD_GET_IFACE (self)->update_secrets (self, connection); } void -eap_method_update_secrets (EAPMethod *self, NMConnection *connection) +eap_method_add_to_size_group (EAPMethod *self, GtkSizeGroup *group) { g_return_if_fail (self != NULL); - g_return_if_fail (connection != NULL); + g_return_if_fail (group != NULL); - if (self->update_secrets) - self->update_secrets (self, connection); + return (*(EAP_METHOD_GET_IFACE (self)->add_to_size_group)) (self, group); } void -eap_method_phase2_update_secrets_helper (EAPMethod *self, - NMConnection *connection, - GtkComboBox *combo, - guint32 column) +eap_method_fill_connection (EAPMethod *self, + NMConnection *connection, + NMSettingSecretFlags flags) { - GtkTreeIter iter; - GtkTreeModel *model; - g_return_if_fail (self != NULL); g_return_if_fail (connection != NULL); - g_return_if_fail (combo != NULL); - - /* Let each EAP phase2 method try to update its secrets */ - model = gtk_combo_box_get_model (combo); - if (gtk_tree_model_get_iter_first (model, &iter)) { - do { - g_autoptr(EAPMethod) eap = NULL; - - gtk_tree_model_get (model, &iter, column, &eap, -1); - if (eap) - eap_method_update_secrets (eap, connection); - } while (gtk_tree_model_iter_next (model, &iter)); - } -} - -EAPMethod * -eap_method_init (gsize obj_size, - EMValidateFunc validate, - EMAddToSizeGroupFunc add_to_size_group, - EMFillConnectionFunc fill_connection, - EMUpdateSecretsFunc update_secrets, - EMDestroyFunc destroy, - const char *ui_resource, - const char *ui_widget_name, - const char *default_field, - gboolean phase2) -{ - g_autoptr(EAPMethod) self = NULL; - g_autoptr(GError) error = NULL; - - g_return_val_if_fail (obj_size > 0, NULL); - g_return_val_if_fail (ui_resource != NULL, NULL); - g_return_val_if_fail (ui_widget_name != NULL, NULL); - - self = g_slice_alloc0 (obj_size); - g_assert (self); - - self->refcount = 1; - self->obj_size = obj_size; - self->validate = validate; - self->add_to_size_group = add_to_size_group; - self->fill_connection = fill_connection; - self->update_secrets = update_secrets; - self->default_field = default_field; - self->phase2 = phase2; - - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, ui_resource, &error)) { - g_warning ("Couldn't load UI builder resource %s: %s", - ui_resource, error->message); - return NULL; - } - - self->ui_widget = GTK_WIDGET (gtk_builder_get_object (self->builder, ui_widget_name)); - if (!self->ui_widget) { - g_warning ("Couldn't load UI widget '%s' from UI file %s", - ui_widget_name, ui_resource); - return NULL; - } - g_object_ref_sink (self->ui_widget); - - self->destroy = destroy; - - return g_steal_pointer (&self); -} - - -EAPMethod * -eap_method_ref (EAPMethod *self) -{ - g_return_val_if_fail (self != NULL, NULL); - g_return_val_if_fail (self->refcount > 0, NULL); - self->refcount++; - return self; + return (*(EAP_METHOD_GET_IFACE (self)->fill_connection)) (self, connection, flags); } void -eap_method_unref (EAPMethod *self) +eap_method_emit_changed (EAPMethod *self) { - g_return_if_fail (self != NULL); - g_return_if_fail (self->refcount > 0); - - self->refcount--; - if (self->refcount == 0) { - if (self->destroy) - self->destroy (self); - - g_clear_object (&self->builder); - g_clear_object (&self->ui_widget); + g_return_if_fail (EAP_IS_METHOD (self)); - g_slice_free1 (self->obj_size, self); - } + g_signal_emit (self, signals[CHANGED], 0); } gboolean @@ -459,27 +382,6 @@ eap_method_is_encrypted_private_key (const char *path) return is_encrypted; } -/* Some methods (PEAP, TLS, TTLS) require a CA certificate. The user can choose - * not to provide such a certificate. This method whether the checkbox - * id_ca_cert_not_required_checkbutton is checked or id_ca_cert_chooser has a certificate - * selected. - */ -gboolean -eap_method_ca_cert_required (GtkToggleButton *id_ca_cert_not_required_checkbutton, GtkFileChooser *id_ca_cert_chooser) -{ - g_assert (id_ca_cert_not_required_checkbutton && id_ca_cert_chooser); - - if (!gtk_toggle_button_get_active (id_ca_cert_not_required_checkbutton)) { - g_autofree gchar *filename = NULL; - - filename = gtk_file_chooser_get_filename (id_ca_cert_chooser); - if (!filename) - return TRUE; - } - return FALSE; -} - - void eap_method_ca_cert_not_required_toggled (GtkToggleButton *id_ca_cert_not_required_checkbutton, GtkFileChooser *id_ca_cert_chooser) { @@ -539,7 +441,7 @@ eap_method_ca_cert_ignore_set (EAPMethod *self, if (s_8021x) { ignore = !ca_cert_error && filename == NULL; g_object_set_data (G_OBJECT (s_8021x), - self->phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG, + eap_method_get_phase2 (self) ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG, GUINT_TO_POINTER (ignore)); } } @@ -560,7 +462,7 @@ eap_method_ca_cert_ignore_get (EAPMethod *self, NMConnection *connection) s_8021x = nm_connection_get_setting_802_1x (connection); if (s_8021x) { return !!g_object_get_data (G_OBJECT (s_8021x), - self->phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG); + eap_method_get_phase2 (self) ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG); } return FALSE; } diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index 9f2f898b0d0764e7a1378dc6d0a9efb4463272ca..f51f309c91d552b9eb32bc85b94b109e2b05a490 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -20,43 +20,34 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef EAP_METHOD_H -#define EAP_METHOD_H +#pragma once +#include #include -typedef struct _EAPMethod EAPMethod; +G_BEGIN_DECLS -typedef void (*EMAddToSizeGroupFunc) (EAPMethod *method, GtkSizeGroup *group); -typedef void (*EMFillConnectionFunc) (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags); -typedef void (*EMUpdateSecretsFunc) (EAPMethod *method, NMConnection *connection); -typedef void (*EMDestroyFunc) (EAPMethod *method); -typedef gboolean (*EMValidateFunc) (EAPMethod *method, GError **error); +G_DECLARE_INTERFACE (EAPMethod, eap_method, EAP, METHOD, GtkGrid) -struct _EAPMethod { - guint32 refcount; - gsize obj_size; +struct _EAPMethodInterface { + GTypeInterface g_iface; - GtkBuilder *builder; - GtkWidget *ui_widget; - - const char *default_field; - const char *password_flags_name; - - gboolean phase2; - gboolean secrets_only; - - EMAddToSizeGroupFunc add_to_size_group; - EMFillConnectionFunc fill_connection; - EMUpdateSecretsFunc update_secrets; - EMValidateFunc validate; - EMDestroyFunc destroy; + void (*add_to_size_group) (EAPMethod *method, GtkSizeGroup *group); + void (*fill_connection) (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags); + void (*update_secrets) (EAPMethod *method, NMConnection *connection); + gboolean (*validate) (EAPMethod *method, GError **error); + GtkWidget* (*get_default_field) (EAPMethod *method); + const gchar* (*get_password_flags_name) (EAPMethod *method); + gboolean (*get_phase2) (EAPMethod *method); }; -#define EAP_METHOD(x) ((EAPMethod *) x) +GtkWidget *eap_method_get_default_field (EAPMethod *method); +const gchar *eap_method_get_password_flags_name (EAPMethod *method); -GtkWidget *eap_method_get_widget (EAPMethod *method); +gboolean eap_method_get_phase2 (EAPMethod *method); + +void eap_method_update_secrets (EAPMethod *method, NMConnection *connection); gboolean eap_method_validate (EAPMethod *method, GError **error); @@ -66,34 +57,10 @@ void eap_method_fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags); -void eap_method_update_secrets (EAPMethod *method, NMConnection *connection); - -EAPMethod *eap_method_ref (EAPMethod *method); - -void eap_method_unref (EAPMethod *method); - -GType eap_method_get_type (void); +void eap_method_emit_changed (EAPMethod *method); /* Below for internal use only */ -#include "eap-method-tls.h" -#include "eap-method-leap.h" -#include "eap-method-fast.h" -#include "eap-method-ttls.h" -#include "eap-method-peap.h" -#include "eap-method-simple.h" - -EAPMethod *eap_method_init (gsize obj_size, - EMValidateFunc validate, - EMAddToSizeGroupFunc add_to_size_group, - EMFillConnectionFunc fill_connection, - EMUpdateSecretsFunc update_secrets, - EMDestroyFunc destroy, - const char *ui_resource, - const char *ui_widget_name, - const char *default_field, - gboolean phase2); - GtkFileFilter * eap_method_default_file_chooser_filter_new (gboolean privkey); gboolean eap_method_is_encrypted_private_key (const char *path); @@ -108,13 +75,6 @@ gboolean eap_method_validate_filepicker (GtkFileChooser *chooser, NMSetting8021xCKFormat *out_format, GError **error); -void eap_method_phase2_update_secrets_helper (EAPMethod *method, - NMConnection *connection, - GtkComboBox *combo, - guint32 column); - -gboolean eap_method_ca_cert_required (GtkToggleButton *id_ca_cert_is_not_required_checkbutton, - GtkFileChooser *id_ca_cert_chooser); void eap_method_ca_cert_not_required_toggled (GtkToggleButton *id_ca_cert_is_not_required_checkbox, GtkFileChooser *id_ca_cert_chooser); @@ -127,6 +87,4 @@ gboolean eap_method_ca_cert_ignore_get (EAPMethod *method, NMConnection *connect void eap_method_ca_cert_ignore_save (NMConnection *connection); void eap_method_ca_cert_ignore_load (NMConnection *connection); -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethod, eap_method_unref) - -#endif /* EAP_METHOD_H */ +G_END_DECLS diff --git a/panels/network/wireless-security/helpers.c b/panels/network/wireless-security/helpers.c index 083c66ffb0b30e35b2311dc4e17ca4942276001b..ea08093de4aa0158d81225b9d85d83e535acd1f8 100644 --- a/panels/network/wireless-security/helpers.c +++ b/panels/network/wireless-security/helpers.c @@ -20,8 +20,6 @@ * Copyright 2009 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - #include "helpers.h" void @@ -46,3 +44,17 @@ helper_fill_secret_entry (NMConnection *connection, } } +void +wireless_security_clear_ciphers (NMConnection *connection) +{ + NMSettingWirelessSecurity *s_wireless_sec; + + g_return_if_fail (connection != NULL); + + s_wireless_sec = nm_connection_get_setting_wireless_security (connection); + g_assert (s_wireless_sec); + + nm_setting_wireless_security_clear_protos (s_wireless_sec); + nm_setting_wireless_security_clear_pairwise (s_wireless_sec); + nm_setting_wireless_security_clear_groups (s_wireless_sec); +} diff --git a/panels/network/wireless-security/helpers.h b/panels/network/wireless-security/helpers.h index 43a8cd6ff86b358a4f161898ae68a7334dc75e55..6a402d8dded0aa3ac1f09de34936e94a30f8cd8b 100644 --- a/panels/network/wireless-security/helpers.h +++ b/panels/network/wireless-security/helpers.h @@ -23,6 +23,15 @@ #ifndef _HELPERS_H_ #define _HELPERS_H_ +#include +#include + +#define NMA_ERROR (g_quark_from_static_string ("nma-error-quark")) + +typedef enum { + NMA_ERROR_GENERIC +} NMAError; + typedef const char * (*HelperSecretFunc)(NMSetting *); void helper_fill_secret_entry (NMConnection *connection, @@ -30,5 +39,7 @@ void helper_fill_secret_entry (NMConnection *connection, GType setting_type, HelperSecretFunc func); +void wireless_security_clear_ciphers (NMConnection *connection); + #endif /* _HELPERS_H_ */ diff --git a/panels/network/wireless-security/meson.build b/panels/network/wireless-security/meson.build index 5e6e0157b9a25df9e5338ab83dfa7ac3964a814d..277be5a8525f1709b1dd0a1ae8b87a8a932c3467 100644 --- a/panels/network/wireless-security/meson.build +++ b/panels/network/wireless-security/meson.build @@ -63,6 +63,6 @@ sources += gnome.compile_resources( libwireless_security = static_library( name, sources: sources, - include_directories: top_inc, + include_directories: [top_inc, network_inc], dependencies: deps ) diff --git a/panels/network/wireless-security/nm-default.h b/panels/network/wireless-security/nm-default.h deleted file mode 100644 index 95ddef521a9d5ec6272a9abf6af0cd91ed1a1657..0000000000000000000000000000000000000000 --- a/panels/network/wireless-security/nm-default.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager -- Network link manager - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301 USA. - * - * (C) Copyright 2015 Red Hat, Inc. - */ - -#ifndef __NM_DEFAULT_H__ -#define __NM_DEFAULT_H__ - -#define LIBNM_GLIB_BUILD -#define NETWORKMANAGER_COMPILATION - -/*****************************************************************************/ - -/* always include these headers for our internal source files. */ - -#ifndef ___CONFIG_H__ -#define ___CONFIG_H__ -#include -#endif - -#include - -#include - -#include -#include -#include - -static inline gboolean -nm_clear_g_source (guint *id) -{ - if (id && *id) { - g_source_remove (*id); - *id = 0; - return TRUE; - } - return FALSE; -} - -/*****************************************************************************/ - -#include - -/*****************************************************************************/ - -#endif /* __NM_DEFAULT_H__ */ diff --git a/panels/network/wireless-security/utils.h b/panels/network/wireless-security/utils.h deleted file mode 100644 index 4465ca61136c5670e110c3bee48deaded9009346..0000000000000000000000000000000000000000 --- a/panels/network/wireless-security/utils.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* NetworkManager Applet -- allow user control over networking - * - * Dan Williams - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Copyright 2007 - 2015 Red Hat, Inc. - */ - -#include -#include - -#define NMA_ERROR (g_quark_from_static_string ("nma-error-quark")) - -typedef enum { - NMA_ERROR_GENERIC -} NMAError; - -extern void widget_set_error (GtkWidget *widget); -extern void widget_unset_error (GtkWidget *widget); diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index d671c278b5e0cbc6a59f96bf34ec2f3b9b01fc3b..2759b80b9e8763436b597893394f388c8dad3bcb 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -20,91 +20,89 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - -#include +#include +#include "helpers.h" #include "wireless-security.h" #include "wireless-security-resources.h" -#include "eap-method.h" -#include "utils.h" - -struct _WirelessSecurityPrivate { - guint32 refcount; - gsize obj_size; - WSChangedFunc changed_notify; - gpointer changed_notify_data; - gboolean adhoc_compatible; - gboolean hotspot_compatible; +typedef struct { char *username, *password; gboolean always_ask, show_password; +} WirelessSecurityPrivate; - WSAddToSizeGroupFunc add_to_size_group; - WSFillConnectionFunc fill_connection; - WSGetWidgetFunc get_widget; - WSValidateFunc validate; - WSDestroyFunc destroy; +G_DEFINE_TYPE_WITH_PRIVATE (WirelessSecurity, wireless_security, G_TYPE_OBJECT) + +enum { + CHANGED, + LAST_SIGNAL }; -GType -wireless_security_get_type (void) +static guint signals[LAST_SIGNAL] = { 0 }; + +static void +wireless_security_dispose (GObject *object) { - static GType type_id = 0; + WirelessSecurity *self = WIRELESS_SECURITY (object); + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - if (!type_id) { - g_resources_register (wireless_security_get_resource ()); + if (priv->password) + memset (priv->password, 0, strlen (priv->password)); - type_id = g_boxed_type_register_static ("CcWirelessSecurity", - (GBoxedCopyFunc) wireless_security_ref, - (GBoxedFreeFunc) wireless_security_unref); - } + g_clear_pointer (&priv->username, g_free); + g_clear_pointer (&priv->password, g_free); - return type_id; + G_OBJECT_CLASS (wireless_security_parent_class)->dispose (object); } -GtkWidget * -wireless_security_get_widget (WirelessSecurity *self) +void +wireless_security_init (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; - g_return_val_if_fail (self != NULL, NULL); - - g_assert (priv->get_widget); - return (*(priv->get_widget)) (self); + g_resources_register (wireless_security_get_resource ()); } void -wireless_security_set_changed_notify (WirelessSecurity *self, - WSChangedFunc func, - gpointer user_data) +wireless_security_class_init (WirelessSecurityClass *klass) { - WirelessSecurityPrivate *priv = self->priv; - g_return_if_fail (self != NULL); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - priv->changed_notify = func; - priv->changed_notify_data = user_data; + object_class->dispose = wireless_security_dispose; + + signals[CHANGED] = + g_signal_new ("changed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +GtkWidget * +wireless_security_get_widget (WirelessSecurity *self) +{ + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), NULL); + + return WIRELESS_SECURITY_GET_CLASS (self)->get_widget (self); } void wireless_security_notify_changed (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; + g_return_if_fail (WIRELESS_IS_SECURITY (self)); - if (priv->changed_notify) - (*(priv->changed_notify)) (self, priv->changed_notify_data); + g_signal_emit (self, signals[CHANGED], 0); } gboolean wireless_security_validate (WirelessSecurity *self, GError **error) { - WirelessSecurityPrivate *priv = self->priv; gboolean result; - g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); g_return_val_if_fail (!error || !*error, FALSE); - g_assert (priv->validate); - result = (*(priv->validate)) (self, error); + result = WIRELESS_SECURITY_GET_CLASS (self)->validate (self, error); if (!result && error && !*error) g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Unknown error validating 802.1X security")); return result; @@ -113,521 +111,112 @@ wireless_security_validate (WirelessSecurity *self, GError **error) void wireless_security_add_to_size_group (WirelessSecurity *self, GtkSizeGroup *group) { - WirelessSecurityPrivate *priv = self->priv; - - g_return_if_fail (self != NULL); - g_return_if_fail (group != NULL); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); + g_return_if_fail (GTK_IS_SIZE_GROUP (group)); - g_assert (priv->add_to_size_group); - return (*(priv->add_to_size_group)) (self, group); + return WIRELESS_SECURITY_GET_CLASS (self)->add_to_size_group (self, group); } void wireless_security_fill_connection (WirelessSecurity *self, NMConnection *connection) { - WirelessSecurityPrivate *priv = self->priv; - - g_return_if_fail (self != NULL); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); g_return_if_fail (connection != NULL); - g_assert (priv->fill_connection); - return (*(priv->fill_connection)) (self, connection); -} - -WirelessSecurity * -wireless_security_ref (WirelessSecurity *self) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_val_if_fail (self != NULL, NULL); - g_return_val_if_fail (priv->refcount > 0, NULL); - - priv->refcount++; - return self; -} - -void -wireless_security_unref (WirelessSecurity *self) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_if_fail (self != NULL); - g_return_if_fail (priv->refcount > 0); - - priv->refcount--; - if (priv->refcount == 0) { - if (priv->destroy) - priv->destroy (self); - - if (priv->password) - memset (priv->password, 0, strlen (priv->password)); - - g_clear_pointer (&priv->username, g_free); - g_clear_pointer (&priv->password, g_free); - - g_clear_object (&self->builder); - g_slice_free1 (priv->obj_size, self); - g_free (priv); - } -} - -WirelessSecurity * -wireless_security_init (gsize obj_size, - WSGetWidgetFunc get_widget, - WSValidateFunc validate, - WSAddToSizeGroupFunc add_to_size_group, - WSFillConnectionFunc fill_connection, - WSDestroyFunc destroy, - const char *ui_resource) -{ - g_autoptr(WirelessSecurity) self = NULL; - WirelessSecurityPrivate *priv; - g_autoptr(GError) error = NULL; - - g_return_val_if_fail (obj_size > 0, NULL); - g_return_val_if_fail (ui_resource != NULL, NULL); - - g_type_ensure (WIRELESS_TYPE_SECURITY); - - self = g_slice_alloc0 (obj_size); - g_assert (self); - self->priv = priv = g_new0 (WirelessSecurityPrivate, 1); - - priv->refcount = 1; - priv->obj_size = obj_size; - - priv->get_widget = get_widget; - priv->validate = validate; - priv->add_to_size_group = add_to_size_group; - priv->fill_connection = fill_connection; - - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, ui_resource, &error)) { - g_warning ("Couldn't load UI builder resource %s: %s", - ui_resource, error->message); - return NULL; - } - - priv->destroy = destroy; - priv->adhoc_compatible = TRUE; - priv->hotspot_compatible = TRUE; - - return g_steal_pointer (&self); -} - -void -wireless_security_set_adhoc_compatible (WirelessSecurity *self, gboolean adhoc_compatible) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_if_fail (self != NULL); - - priv->adhoc_compatible = adhoc_compatible; + return WIRELESS_SECURITY_GET_CLASS (self)->fill_connection (self, connection); } gboolean wireless_security_adhoc_compatible (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; - - g_return_val_if_fail (self != NULL, FALSE); - - return priv->adhoc_compatible; + if (WIRELESS_SECURITY_GET_CLASS (self)->adhoc_compatible) + return WIRELESS_SECURITY_GET_CLASS (self)->adhoc_compatible (self); + else + return TRUE; } void -wireless_security_set_hotspot_compatible (WirelessSecurity *self, gboolean hotspot_compatible) +wireless_security_set_username (WirelessSecurity *self, const gchar *username) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_if_fail (self != NULL); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); - priv->hotspot_compatible = hotspot_compatible; -} - -gboolean -wireless_security_hotspot_compatible (WirelessSecurity *self) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_val_if_fail (self != NULL, FALSE); - - return priv->hotspot_compatible; + g_clear_pointer (&priv->username, g_free); + priv->username = g_strdup (username); } const gchar * wireless_security_get_username (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_val_if_fail (self != NULL, NULL); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), NULL); return priv->username; } -const gchar * -wireless_security_get_password (WirelessSecurity *self) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_val_if_fail (self != NULL, NULL); - - return priv->password; -} - -gboolean -wireless_security_get_always_ask (WirelessSecurity *self) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_val_if_fail (self != NULL, FALSE); - - return priv->always_ask; -} - -gboolean -wireless_security_get_show_password (WirelessSecurity *self) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_val_if_fail (self != NULL, FALSE); - - return priv->show_password; -} - void -wireless_security_set_userpass (WirelessSecurity *self, - const char *user, - const char *password, - gboolean always_ask, - gboolean show_password) +wireless_security_set_password (WirelessSecurity *self, const gchar *password) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_clear_pointer (&priv->username, g_free); - priv->username = g_strdup (user); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); if (priv->password) memset (priv->password, 0, strlen (priv->password)); g_clear_pointer (&priv->password, g_free); priv->password = g_strdup (password); - - if (always_ask != (gboolean) -1) - priv->always_ask = always_ask; - priv->show_password = show_password; } -void -wireless_security_set_userpass_802_1x (WirelessSecurity *self, - NMConnection *connection) -{ - const char *user = NULL, *password = NULL; - gboolean always_ask = FALSE, show_password = FALSE; - NMSetting8021x *setting; - NMSettingSecretFlags flags; - - if (!connection) - goto set; - - setting = nm_connection_get_setting_802_1x (connection); - if (!setting) - goto set; - - user = nm_setting_802_1x_get_identity (setting); - password = nm_setting_802_1x_get_password (setting); - - if (nm_setting_get_secret_flags (NM_SETTING (setting), NM_SETTING_802_1X_PASSWORD, &flags, NULL)) - always_ask = !!(flags & NM_SETTING_SECRET_FLAG_NOT_SAVED); - -set: - wireless_security_set_userpass (self, user, password, always_ask, show_password); -} - -void -wireless_security_clear_ciphers (NMConnection *connection) +const gchar * +wireless_security_get_password (WirelessSecurity *self) { - NMSettingWirelessSecurity *s_wireless_sec; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_if_fail (connection != NULL); - - s_wireless_sec = nm_connection_get_setting_wireless_security (connection); - g_assert (s_wireless_sec); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), NULL); - nm_setting_wireless_security_clear_protos (s_wireless_sec); - nm_setting_wireless_security_clear_pairwise (s_wireless_sec); - nm_setting_wireless_security_clear_groups (s_wireless_sec); + return priv->password; } void -ws_802_1x_add_to_size_group (GtkSizeGroup *size_group, - GtkLabel *label, - GtkComboBox *combo) +wireless_security_set_always_ask (WirelessSecurity *self, gboolean always_ask) { - GtkTreeModel *model; - GtkTreeIter iter; - g_autoptr(EAPMethod) eap = NULL; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - gtk_size_group_add_widget (size_group, GTK_WIDGET (label)); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); - model = gtk_combo_box_get_model (combo); - gtk_combo_box_get_active_iter (combo, &iter); - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); - g_assert (eap); - eap_method_add_to_size_group (eap, size_group); + priv->always_ask = always_ask; } gboolean -ws_802_1x_validate (GtkComboBox *combo, GError **error) +wireless_security_get_always_ask (WirelessSecurity *self) { - GtkTreeModel *model; - GtkTreeIter iter; - g_autoptr(EAPMethod) eap = NULL; - gboolean valid = FALSE; - - model = gtk_combo_box_get_model (combo); - gtk_combo_box_get_active_iter (combo, &iter); - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); - g_assert (eap); - valid = eap_method_validate (eap, error); - return valid; -} + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); -void -ws_802_1x_auth_combo_changed (GtkWidget *combo, - WirelessSecurity *self, - GtkBox *vbox, - GtkSizeGroup *size_group) -{ - g_autoptr(EAPMethod) eap = NULL; - GList *elt, *children; - GtkTreeModel *model; - GtkTreeIter iter; - GtkWidget *eap_widget; - GtkWidget *eap_default_widget = NULL; - - /* Remove any previous wireless security widgets */ - children = gtk_container_get_children (GTK_CONTAINER (vbox)); - for (elt = children; elt; elt = g_list_next (elt)) - gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data)); - - model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo)); - gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter); - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); - g_assert (eap); - - eap_widget = eap_method_get_widget (eap); - g_assert (eap_widget); - gtk_widget_unparent (eap_widget); - - if (size_group) - eap_method_add_to_size_group (eap, size_group); - gtk_container_add (GTK_CONTAINER (vbox), eap_widget); - - /* Refocus the EAP method's default widget */ - if (eap->default_field) { - eap_default_widget = GTK_WIDGET (gtk_builder_get_object (eap->builder, eap->default_field)); - if (eap_default_widget) - gtk_widget_grab_focus (eap_default_widget); - } - - wireless_security_notify_changed (WIRELESS_SECURITY (self)); -} + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); -void -ws_802_1x_auth_combo_init (WirelessSecurity *self, - GtkComboBox *combo, - GtkLabel *label, - GCallback auth_combo_changed_cb, - NMConnection *connection, - gboolean is_editor, - gboolean secrets_only) -{ - g_autoptr(GtkListStore) auth_model = NULL; - GtkTreeIter iter; - g_autoptr(EAPMethodTLS) em_tls = NULL; - g_autoptr(EAPMethodSimple) em_pwd = NULL; - g_autoptr(EAPMethodFAST) em_fast = NULL; - g_autoptr(EAPMethodTTLS) em_ttls = NULL; - g_autoptr(EAPMethodPEAP) em_peap = NULL; - const char *default_method = NULL, *ctype = NULL; - int active = -1, item = 0; - gboolean wired = FALSE; - EAPMethodSimpleFlags simple_flags = EAP_METHOD_SIMPLE_FLAG_NONE; - - /* Grab the default EAP method out of the security object */ - if (connection) { - NMSettingConnection *s_con; - NMSetting8021x *s_8021x; - - s_con = nm_connection_get_setting_connection (connection); - if (s_con) - ctype = nm_setting_connection_get_connection_type (s_con); - if ( (g_strcmp0 (ctype, NM_SETTING_WIRED_SETTING_NAME) == 0) - || nm_connection_get_setting_wired (connection)) - wired = TRUE; - - s_8021x = nm_connection_get_setting_802_1x (connection); - if (s_8021x && nm_setting_802_1x_get_num_eap_methods (s_8021x)) - default_method = nm_setting_802_1x_get_eap_method (s_8021x, 0); - } - - /* initialize WirelessSecurity userpass from connection (clear if no connection) */ - wireless_security_set_userpass_802_1x (self, connection); - - auth_model = gtk_list_store_new (2, G_TYPE_STRING, eap_method_get_type ()); - - if (is_editor) - simple_flags |= EAP_METHOD_SIMPLE_FLAG_IS_EDITOR; - if (secrets_only) - simple_flags |= EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY; - - if (wired) { - g_autoptr(EAPMethodSimple) em_md5 = NULL; - - em_md5 = eap_method_simple_new (self, connection, EAP_METHOD_SIMPLE_TYPE_MD5, simple_flags); - gtk_list_store_append (auth_model, &iter); - gtk_list_store_set (auth_model, &iter, - AUTH_NAME_COLUMN, _("MD5"), - AUTH_METHOD_COLUMN, em_md5, - -1); - if (default_method && (active < 0) && !strcmp (default_method, "md5")) - active = item; - item++; - } - - em_tls = eap_method_tls_new (self, connection, FALSE, secrets_only); - gtk_list_store_append (auth_model, &iter); - gtk_list_store_set (auth_model, &iter, - AUTH_NAME_COLUMN, _("TLS"), - AUTH_METHOD_COLUMN, em_tls, - -1); - if (default_method && (active < 0) && !strcmp (default_method, "tls")) - active = item; - item++; - - if (!wired) { - g_autoptr(EAPMethodLEAP) em_leap = NULL; - - em_leap = eap_method_leap_new (self, connection, secrets_only); - gtk_list_store_append (auth_model, &iter); - gtk_list_store_set (auth_model, &iter, - AUTH_NAME_COLUMN, _("LEAP"), - AUTH_METHOD_COLUMN, em_leap, - -1); - if (default_method && (active < 0) && !strcmp (default_method, "leap")) - active = item; - item++; - } - - em_pwd = eap_method_simple_new (self, connection, EAP_METHOD_SIMPLE_TYPE_PWD, simple_flags); - gtk_list_store_append (auth_model, &iter); - gtk_list_store_set (auth_model, &iter, - AUTH_NAME_COLUMN, _("PWD"), - AUTH_METHOD_COLUMN, em_pwd, - -1); - if (default_method && (active < 0) && !strcmp (default_method, "pwd")) - active = item; - item++; - - em_fast = eap_method_fast_new (self, connection, is_editor, secrets_only); - gtk_list_store_append (auth_model, &iter); - gtk_list_store_set (auth_model, &iter, - AUTH_NAME_COLUMN, _("FAST"), - AUTH_METHOD_COLUMN, em_fast, - -1); - if (default_method && (active < 0) && !strcmp (default_method, "fast")) - active = item; - item++; - - em_ttls = eap_method_ttls_new (self, connection, is_editor, secrets_only); - gtk_list_store_append (auth_model, &iter); - gtk_list_store_set (auth_model, &iter, - AUTH_NAME_COLUMN, _("Tunneled TLS"), - AUTH_METHOD_COLUMN, em_ttls, - -1); - if (default_method && (active < 0) && !strcmp (default_method, "ttls")) - active = item; - item++; - - em_peap = eap_method_peap_new (self, connection, is_editor, secrets_only); - gtk_list_store_append (auth_model, &iter); - gtk_list_store_set (auth_model, &iter, - AUTH_NAME_COLUMN, _("Protected EAP (PEAP)"), - AUTH_METHOD_COLUMN, em_peap, - -1); - if (default_method && (active < 0) && !strcmp (default_method, "peap")) - active = item; - item++; - - gtk_combo_box_set_model (combo, GTK_TREE_MODEL (auth_model)); - gtk_combo_box_set_active (combo, active < 0 ? 0 : (guint32) active); - - g_signal_connect (G_OBJECT (combo), "changed", auth_combo_changed_cb, self); - - if (secrets_only) { - gtk_widget_hide (GTK_WIDGET (combo)); - gtk_widget_hide (GTK_WIDGET (label)); - } + return priv->always_ask; } void -ws_802_1x_fill_connection (GtkComboBox *combo, - NMConnection *connection) +wireless_security_set_show_password (WirelessSecurity *self, gboolean show_password) { - NMSettingWirelessSecurity *s_wireless_sec; - NMSetting8021x *s_8021x; - NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; - g_autoptr(EAPMethod) eap = NULL; - GtkTreeModel *model; - GtkTreeIter iter; - - /* Get the EAPMethod object */ - model = gtk_combo_box_get_model (combo); - gtk_combo_box_get_active_iter (combo, &iter); - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); - g_assert (eap); - - /* Get previous pasword flags, if any. Otherwise default to agent-owned secrets */ - s_8021x = nm_connection_get_setting_802_1x (connection); - if (s_8021x) - nm_setting_get_secret_flags (NM_SETTING (s_8021x), eap->password_flags_name, &secret_flags, NULL); - else - secret_flags = NM_SETTING_SECRET_FLAG_AGENT_OWNED; - - /* Blow away the old wireless security setting by adding a clear one */ - s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); - nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec); + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - /* Blow away the old 802.1x setting by adding a clear one */ - s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); - nm_connection_add_setting (connection, (NMSetting *) s_8021x); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); - eap_method_fill_connection (eap, connection, secret_flags); + priv->show_password = show_password; } -void -ws_802_1x_update_secrets (GtkComboBox *combo, - NMConnection *connection) +gboolean +wireless_security_get_show_password (WirelessSecurity *self) { - GtkTreeModel *model; - GtkTreeIter iter; - - g_return_if_fail (combo != NULL); - g_return_if_fail (connection != NULL); + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - model = gtk_combo_box_get_model (combo); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); - /* Let each EAP method try to update its secrets */ - if (gtk_tree_model_get_iter_first (model, &iter)) { - do { - g_autoptr(EAPMethod) eap = NULL; - - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); - if (eap) - eap_method_update_secrets (eap, connection); - } while (gtk_tree_model_iter_next (model, &iter)); - } + return priv->show_password; } - diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 065a8fc8e9a6032187058d13d51cd17e51d86358..00ded70a4f0b4d53b286f5fb320e92a1994ba1f2 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -20,38 +20,27 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WIRELESS_SECURITY_H -#define WIRELESS_SECURITY_H +#pragma once #include +#include -#define WIRELESS_TYPE_SECURITY (wireless_security_get_type ()) +G_BEGIN_DECLS -typedef struct _WirelessSecurity WirelessSecurity; -typedef struct _WirelessSecurityPrivate WirelessSecurityPrivate; +G_DECLARE_DERIVABLE_TYPE (WirelessSecurity, wireless_security, WIRELESS, SECURITY, GObject) -typedef void (*WSChangedFunc) (WirelessSecurity *sec, gpointer user_data); +struct _WirelessSecurityClass { + GObjectClass parent_class; -typedef void (*WSAddToSizeGroupFunc) (WirelessSecurity *sec, GtkSizeGroup *group); -typedef void (*WSFillConnectionFunc) (WirelessSecurity *sec, NMConnection *connection); -typedef void (*WSDestroyFunc) (WirelessSecurity *sec); -typedef gboolean (*WSValidateFunc) (WirelessSecurity *sec, GError **error); -typedef GtkWidget* (*WSGetWidgetFunc) (WirelessSecurity *sec); - -struct _WirelessSecurity { - WirelessSecurityPrivate *priv; - GtkBuilder *builder; + void (*add_to_size_group) (WirelessSecurity *sec, GtkSizeGroup *group); + void (*fill_connection) (WirelessSecurity *sec, NMConnection *connection); + gboolean (*validate) (WirelessSecurity *sec, GError **error); + gboolean (*adhoc_compatible) (WirelessSecurity *sec); + GtkWidget* (*get_widget) (WirelessSecurity *sec); }; -#define WIRELESS_SECURITY(x) ((WirelessSecurity *) x) - - GtkWidget *wireless_security_get_widget (WirelessSecurity *sec); -void wireless_security_set_changed_notify (WirelessSecurity *sec, - WSChangedFunc func, - gpointer user_data); - gboolean wireless_security_validate (WirelessSecurity *sec, GError **error); void wireless_security_add_to_size_group (WirelessSecurity *sec, @@ -60,81 +49,24 @@ void wireless_security_add_to_size_group (WirelessSecurity *sec, void wireless_security_fill_connection (WirelessSecurity *sec, NMConnection *connection); -void wireless_security_set_adhoc_compatible (WirelessSecurity *sec, - gboolean adhoc_compatible); - gboolean wireless_security_adhoc_compatible (WirelessSecurity *sec); -void wireless_security_set_hotspot_compatible (WirelessSecurity *sec, - gboolean hotspot_compatible); - -gboolean wireless_security_hotspot_compatible (WirelessSecurity *sec); +void wireless_security_set_username (WirelessSecurity *sec, const gchar *username); const gchar *wireless_security_get_username (WirelessSecurity *sec); -const gchar *wireless_security_get_password (WirelessSecurity *sec); +void wireless_security_set_password (WirelessSecurity *sec, const gchar *password); -gboolean wireless_security_get_always_ask (WirelessSecurity *sec); - -gboolean wireless_security_get_show_password (WirelessSecurity *sec); - -void wireless_security_set_userpass (WirelessSecurity *sec, - const char *user, - const char *password, - gboolean always_ask, - gboolean show_password); -void wireless_security_set_userpass_802_1x (WirelessSecurity *sec, - NMConnection *connection); - -WirelessSecurity *wireless_security_ref (WirelessSecurity *sec); +const gchar *wireless_security_get_password (WirelessSecurity *sec); -void wireless_security_unref (WirelessSecurity *sec); +void wireless_security_set_always_ask (WirelessSecurity *sec, gboolean always_ask); -GType wireless_security_get_type (void); +gboolean wireless_security_get_always_ask (WirelessSecurity *sec); -/* Below for internal use only */ +void wireless_security_set_show_password (WirelessSecurity *sec, gboolean show_password); -WirelessSecurity *wireless_security_init (gsize obj_size, - WSGetWidgetFunc get_widget, - WSValidateFunc validate, - WSAddToSizeGroupFunc add_to_size_group, - WSFillConnectionFunc fill_connection, - WSDestroyFunc destroy, - const char *ui_resource); +gboolean wireless_security_get_show_password (WirelessSecurity *sec); void wireless_security_notify_changed (WirelessSecurity *sec); -void wireless_security_clear_ciphers (NMConnection *connection); - -#define AUTH_NAME_COLUMN 0 -#define AUTH_METHOD_COLUMN 1 - -void ws_802_1x_auth_combo_init (WirelessSecurity *sec, - GtkComboBox *combo, - GtkLabel *label, - GCallback auth_combo_changed_cb, - NMConnection *connection, - gboolean is_editor, - gboolean secrets_only); - -void ws_802_1x_auth_combo_changed (GtkWidget *combo, - WirelessSecurity *sec, - GtkBox *vbox, - GtkSizeGroup *size_group); - -gboolean ws_802_1x_validate (GtkComboBox *combo, GError **error); - -void ws_802_1x_add_to_size_group (GtkSizeGroup *size_group, - GtkLabel *label, - GtkComboBox *combo); - -void ws_802_1x_fill_connection (GtkComboBox *combo, - NMConnection *connection); - -void ws_802_1x_update_secrets (GtkComboBox *combo, - NMConnection *connection); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC (WirelessSecurity, wireless_security_unref) - -#endif /* WIRELESS_SECURITY_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index 46fa9eda1deb7b916cd68d0b7ec5fb1913dcdaba..0c4c999306e321b97ba7cc86c4db8a43f271a136 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -20,83 +20,183 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" +#include -#include -#include - -#include "ws-dynamic-wep.h" -#include "wireless-security.h" #include "eap-method.h" +#include "eap-method-fast.h" +#include "eap-method-leap.h" +#include "eap-method-peap.h" +#include "eap-method-simple.h" +#include "eap-method-tls.h" +#include "eap-method-ttls.h" +#include "wireless-security.h" +#include "ws-dynamic-wep.h" struct _WirelessSecurityDynamicWEP { WirelessSecurity parent; - GtkComboBox *auth_combo; - GtkLabel *auth_label; - GtkGrid *grid; - GtkBox *method_box; + GtkBuilder *builder; + GtkComboBox *auth_combo; + GtkLabel *auth_label; + GtkListStore *auth_model; + GtkGrid *grid; + GtkBox *method_box; - GtkSizeGroup *size_group; + EAPMethodTLS *em_tls; + EAPMethodLEAP *em_leap; + EAPMethodSimple *em_pwd; + EAPMethodFAST *em_fast; + EAPMethodTTLS *em_ttls; + EAPMethodPEAP *em_peap; }; +G_DEFINE_TYPE (WirelessSecurityDynamicWEP, ws_dynamic_wep, wireless_security_get_type ()) + +#define AUTH_NAME_COLUMN 0 +#define AUTH_ID_COLUMN 1 + +static EAPMethod * +get_eap (WirelessSecurityDynamicWEP *self) +{ + GtkTreeIter iter; + g_autofree gchar *id = NULL; + + if (!gtk_combo_box_get_active_iter (self->auth_combo, &iter)) + return NULL; + gtk_tree_model_get (GTK_TREE_MODEL (self->auth_model), &iter, AUTH_ID_COLUMN, &id, -1); + + if (strcmp (id, "tls") == 0) + return EAP_METHOD (self->em_tls); + if (strcmp (id, "leap") == 0) + return EAP_METHOD (self->em_leap); + if (strcmp (id, "pwd") == 0) + return EAP_METHOD (self->em_pwd); + if (strcmp (id, "fast") == 0) + return EAP_METHOD (self->em_fast); + if (strcmp (id, "ttls") == 0) + return EAP_METHOD (self->em_ttls); + if (strcmp (id, "peap") == 0) + return EAP_METHOD (self->em_peap); + + return NULL; +} + static void -destroy (WirelessSecurity *parent) +ws_dynamic_wep_dispose (GObject *object) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (object); + + g_clear_object (&self->builder); - g_clear_object (&self->size_group); + G_OBJECT_CLASS (ws_dynamic_wep_parent_class)->dispose (object); } static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (security); return GTK_WIDGET (self->grid); } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; - return ws_802_1x_validate (self->auth_combo, error); + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (security); + return eap_method_validate (get_eap (self), error); } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (security); - g_clear_object (&self->size_group); - self->size_group = g_object_ref (group); - - ws_802_1x_add_to_size_group (self->size_group, self->auth_label, self->auth_combo); + gtk_size_group_add_widget (group, GTK_WIDGET (self->auth_label)); + eap_method_add_to_size_group (EAP_METHOD (self->em_tls), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_leap), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_pwd), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_fast), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_ttls), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_peap), group); } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (security); NMSettingWirelessSecurity *s_wireless_sec; + NMSetting8021x *s_8021x; + NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; + EAPMethod *eap; + + /* Get the EAPMethod object */ + eap = get_eap (self); + + /* Get previous pasword flags, if any. Otherwise default to agent-owned secrets */ + s_8021x = nm_connection_get_setting_802_1x (connection); + if (s_8021x) + nm_setting_get_secret_flags (NM_SETTING (s_8021x), eap_method_get_password_flags_name (eap), &secret_flags, NULL); + else + secret_flags = NM_SETTING_SECRET_FLAG_AGENT_OWNED; - ws_802_1x_fill_connection (self->auth_combo, connection); + /* Blow away the old wireless security setting by adding a clear one */ + s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); + nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec); - s_wireless_sec = nm_connection_get_setting_wireless_security (connection); - g_assert (s_wireless_sec); + /* Blow away the old 802.1x setting by adding a clear one */ + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); + nm_connection_add_setting (connection, (NMSetting *) s_8021x); + + eap_method_fill_connection (eap, connection, secret_flags); g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL); } +static gboolean +adhoc_compatible (WirelessSecurity *security) +{ + return FALSE; +} + static void -auth_combo_changed_cb (GtkWidget *combo, gpointer user_data) +auth_combo_changed_cb (WirelessSecurityDynamicWEP *self) { - WirelessSecurity *parent = WIRELESS_SECURITY (user_data); - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + EAPMethod *eap; + GList *elt, *children; + GtkWidget *eap_default_field; - ws_802_1x_auth_combo_changed (combo, - parent, - self->method_box, - self->size_group); + /* Remove any previous wireless security widgets */ + children = gtk_container_get_children (GTK_CONTAINER (self->method_box)); + for (elt = children; elt; elt = g_list_next (elt)) + gtk_container_remove (GTK_CONTAINER (self->method_box), GTK_WIDGET (elt->data)); + + eap = get_eap (self); + gtk_container_add (GTK_CONTAINER (self->method_box), g_object_ref (GTK_WIDGET (eap))); + + /* Refocus the EAP method's default widget */ + eap_default_field = eap_method_get_default_field (eap); + if (eap_default_field) + gtk_widget_grab_focus (eap_default_field); + + wireless_security_notify_changed (WIRELESS_SECURITY (self)); +} + +void +ws_dynamic_wep_init (WirelessSecurityDynamicWEP *self) +{ +} + +void +ws_dynamic_wep_class_init (WirelessSecurityDynamicWEPClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_dynamic_wep_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; + ws_class->adhoc_compatible = adhoc_compatible; } WirelessSecurityDynamicWEP * @@ -104,36 +204,99 @@ ws_dynamic_wep_new (NMConnection *connection, gboolean is_editor, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityDynamicWEP *self; + const gchar *user = NULL, *password = NULL; + gboolean always_ask = FALSE; + const gchar *default_method = NULL; + EAPMethodSimpleFlags simple_flags = EAP_METHOD_SIMPLE_FLAG_NONE; + GtkTreeIter iter; + g_autoptr(GError) error = NULL; + + self = g_object_new (ws_dynamic_wep_get_type (), NULL); - parent = wireless_security_init (sizeof (WirelessSecurityDynamicWEP), - get_widget, - validate, - add_to_size_group, - fill_connection, - destroy, - "/org/gnome/ControlCenter/network/ws-dynamic-wep.ui"); - if (!parent) + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-dynamic-wep.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); return NULL; - self = (WirelessSecurityDynamicWEP *) parent; - - self->auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "auth_combo")); - self->auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "auth_label")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->method_box = GTK_BOX (gtk_builder_get_object (parent->builder, "method_box")); - - wireless_security_set_adhoc_compatible (parent, FALSE); - wireless_security_set_hotspot_compatible (parent, FALSE); - - ws_802_1x_auth_combo_init (parent, - self->auth_combo, - self->auth_label, - (GCallback) auth_combo_changed_cb, - connection, - is_editor, - secrets_only); - auth_combo_changed_cb (GTK_WIDGET (self->auth_combo), (gpointer) parent); + } + + self->auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "auth_combo")); + self->auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "auth_label")); + self->auth_model = GTK_LIST_STORE (gtk_builder_get_object (self->builder, "auth_model")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->method_box = GTK_BOX (gtk_builder_get_object (self->builder, "method_box")); + + /* Grab the default EAP method out of the security object */ + if (connection) { + NMSetting8021x *s_8021x; + + s_8021x = nm_connection_get_setting_802_1x (connection); + if (s_8021x && nm_setting_802_1x_get_num_eap_methods (s_8021x)) + default_method = nm_setting_802_1x_get_eap_method (s_8021x, 0); + } + if (default_method == NULL) + default_method = "tls"; + + /* initialize WirelessSecurity userpass from connection (clear if no connection) */ + if (connection) { + NMSetting8021x *setting; + + setting = nm_connection_get_setting_802_1x (connection); + if (setting) { + NMSettingSecretFlags flags; + + user = nm_setting_802_1x_get_identity (setting); + password = nm_setting_802_1x_get_password (setting); + + if (nm_setting_get_secret_flags (NM_SETTING (setting), NM_SETTING_802_1X_PASSWORD, &flags, NULL)) + always_ask = !!(flags & NM_SETTING_SECRET_FLAG_NOT_SAVED); + } + } + wireless_security_set_username (WIRELESS_SECURITY (self), user); + wireless_security_set_password (WIRELESS_SECURITY (self), password); + wireless_security_set_always_ask (WIRELESS_SECURITY (self), always_ask); + wireless_security_set_show_password (WIRELESS_SECURITY (self), FALSE); + + if (is_editor) + simple_flags |= EAP_METHOD_SIMPLE_FLAG_IS_EDITOR; + if (secrets_only) + simple_flags |= EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY; + + self->em_tls = eap_method_tls_new (WIRELESS_SECURITY (self), connection, FALSE, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_tls)); + g_signal_connect_object (self->em_tls, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_leap = eap_method_leap_new (WIRELESS_SECURITY (self), connection, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_leap)); + g_signal_connect_object (self->em_leap, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_pwd = eap_method_simple_new (WIRELESS_SECURITY (self), connection, EAP_METHOD_SIMPLE_TYPE_PWD, simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_pwd)); + g_signal_connect_object (self->em_pwd, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_fast = eap_method_fast_new (WIRELESS_SECURITY (self), connection, is_editor, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_fast)); + g_signal_connect_object (self->em_fast, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_ttls = eap_method_ttls_new (WIRELESS_SECURITY (self), connection, is_editor, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_ttls)); + g_signal_connect_object (self->em_ttls, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_peap = eap_method_peap_new (WIRELESS_SECURITY (self), connection, is_editor, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_peap)); + g_signal_connect_object (self->em_peap, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + + if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->auth_model), &iter)) { + do { + g_autofree gchar *id = NULL; + gtk_tree_model_get (GTK_TREE_MODEL (self->auth_model), &iter, AUTH_ID_COLUMN, &id, -1); + if (strcmp (id, default_method) == 0) + gtk_combo_box_set_active_iter (self->auth_combo, &iter); + } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->auth_model), &iter)); + } + + if (secrets_only) { + gtk_widget_hide (GTK_WIDGET (self->auth_combo)); + gtk_widget_hide (GTK_WIDGET (self->auth_label)); + } + + g_signal_connect_object (G_OBJECT (self->auth_combo), "changed", G_CALLBACK (auth_combo_changed_cb), self, G_CONNECT_SWAPPED); + auth_combo_changed_cb (self); return self; } diff --git a/panels/network/wireless-security/ws-dynamic-wep.h b/panels/network/wireless-security/ws-dynamic-wep.h index e2e5f6a113e43f8d369929743c0fe3488d98f195..95fdf0de8d34cfcd02af2641521a8bc171bf6406 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.h +++ b/panels/network/wireless-security/ws-dynamic-wep.h @@ -20,13 +20,18 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_DYNAMIC_WEP_H -#define WS_DYNAMIC_WEP_H +#pragma once -typedef struct _WirelessSecurityDynamicWEP WirelessSecurityDynamicWEP; +#include + +#include "wireless-security.h" + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityDynamicWEP, ws_dynamic_wep, WS, DYNAMIC_WEP, WirelessSecurity) WirelessSecurityDynamicWEP *ws_dynamic_wep_new (NMConnection *connection, gboolean is_editor, gboolean secrets_only); -#endif /* WS_DYNAMIC_WEP_H */ +G_END_DECLS diff --git a/panels/network/wireless-security/ws-dynamic-wep.ui b/panels/network/wireless-security/ws-dynamic-wep.ui index 35446762421240d97148ed2d44e5d0ee039a4c04..c3293e4b17a911f0bbc42115f26275fab7b353d3 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.ui +++ b/panels/network/wireless-security/ws-dynamic-wep.ui @@ -3,12 +3,43 @@ - + + + + + - + TLS + tls + True + + + LEAP + leap + True + + + PWD + pwd + True + + + FAST + fast + True + + + Tunneled TLS + ttls + True + + + Protected EAP (PEAP) + peap + True diff --git a/panels/network/wireless-security/ws-leap.c b/panels/network/wireless-security/ws-leap.c index 0e5ef7c72bfce45ab392ceb03221f2c399902372..48a22b57cfaeaff61db3c647c160dc98070bfffc 100644 --- a/panels/network/wireless-security/ws-leap.c +++ b/panels/network/wireless-security/ws-leap.c @@ -20,19 +20,18 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" +#include -#include - -#include "ws-leap.h" -#include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" -#include "utils.h" +#include "ui-helpers.h" +#include "wireless-security.h" +#include "ws-leap.h" struct _WirelessSecurityLEAP { WirelessSecurity parent; + GtkBuilder *builder; GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; @@ -44,6 +43,18 @@ struct _WirelessSecurityLEAP { const char *password_flags_name; }; +G_DEFINE_TYPE (WirelessSecurityLEAP, ws_leap, wireless_security_get_type ()) + +static void +ws_leap_dispose (GObject *object) +{ + WirelessSecurityLEAP *self = WS_LEAP (object); + + g_clear_object (&self->builder); + + G_OBJECT_CLASS (ws_leap_parent_class)->dispose (object); +} + static void show_toggled_cb (WirelessSecurityLEAP *self) { @@ -54,16 +65,16 @@ show_toggled_cb (WirelessSecurityLEAP *self) } static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + WirelessSecurityLEAP *self = WS_LEAP (security); return GTK_WIDGET (self->grid); } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + WirelessSecurityLEAP *self = WS_LEAP (security); const char *text; gboolean ret = TRUE; @@ -89,17 +100,17 @@ validate (WirelessSecurity *parent, GError **error) } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + WirelessSecurityLEAP *self = WS_LEAP (security); gtk_size_group_add_widget (group, GTK_WIDGET (self->username_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->password_label)); } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + WirelessSecurityLEAP *self = WS_LEAP (security); NMSettingWirelessSecurity *s_wireless_sec; NMSettingSecretFlags secret_flags; const char *leap_password = NULL, *leap_username = NULL; @@ -129,14 +140,10 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection) NM_SETTING (s_wireless_sec), self->password_flags_name); } -static void -update_secrets (WirelessSecurity *parent, NMConnection *connection) +static gboolean +adhoc_compatible (WirelessSecurity *security) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; - helper_fill_secret_entry (connection, - self->password_entry, - NM_TYPE_SETTING_WIRELESS_SECURITY, - (HelperSecretFunc) nm_setting_wireless_security_get_leap_password); + return FALSE; } static void @@ -145,22 +152,33 @@ changed_cb (WirelessSecurityLEAP *self) wireless_security_notify_changed ((WirelessSecurity *) self); } +void +ws_leap_init (WirelessSecurityLEAP *self) +{ +} + +void +ws_leap_class_init (WirelessSecurityLEAPClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_leap_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; + ws_class->adhoc_compatible = adhoc_compatible; +} + WirelessSecurityLEAP * ws_leap_new (NMConnection *connection, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityLEAP *self; NMSettingWirelessSecurity *wsec = NULL; + g_autoptr(GError) error = NULL; - parent = wireless_security_init (sizeof (WirelessSecurityLEAP), - get_widget, - validate, - add_to_size_group, - fill_connection, - NULL, - "/org/gnome/ControlCenter/network/ws-leap.ui"); - if (!parent) - return NULL; + self = g_object_new (ws_leap_get_type (), NULL); if (connection) { wsec = nm_connection_get_setting_wireless_security (connection); @@ -174,18 +192,21 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only) } } - wireless_security_set_adhoc_compatible (parent, FALSE); - wireless_security_set_hotspot_compatible (parent, FALSE); - self = (WirelessSecurityLEAP *) parent; self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD; - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "password_entry")); - self->password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->username_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "username_entry")); - self->username_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "username_label")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-leap.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "password_entry")); + self->password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "password_label")); + self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); + self->username_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "username_entry")); + self->username_label = GTK_LABEL (gtk_builder_get_object (self->builder, "username_label")); g_signal_connect_swapped (self->password_entry, "changed", G_CALLBACK (changed_cb), self); @@ -194,7 +215,10 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only) FALSE, secrets_only); if (wsec) - update_secrets (WIRELESS_SECURITY (self), connection); + helper_fill_secret_entry (connection, + self->password_entry, + NM_TYPE_SETTING_WIRELESS_SECURITY, + (HelperSecretFunc) nm_setting_wireless_security_get_leap_password); g_signal_connect_swapped (self->username_entry, "changed", G_CALLBACK (changed_cb), self); if (wsec) diff --git a/panels/network/wireless-security/ws-leap.h b/panels/network/wireless-security/ws-leap.h index fedc06d6645ce3cd65c0f5fad5e7970f0263e18f..33abc6062730a6a76684d2fc1fce5ff4574a3d3b 100644 --- a/panels/network/wireless-security/ws-leap.h +++ b/panels/network/wireless-security/ws-leap.h @@ -20,11 +20,16 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_LEAP_H -#define WS_LEAP_H +#pragma once -typedef struct _WirelessSecurityLEAP WirelessSecurityLEAP; +#include + +#include "wireless-security.h" + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityLEAP, ws_leap, WS, LEAP, WirelessSecurity) WirelessSecurityLEAP * ws_leap_new (NMConnection *connection, gboolean secrets_only); -#endif /* WS_LEAP_H */ +G_END_DECLS diff --git a/panels/network/wireless-security/ws-wep-key.c b/panels/network/wireless-security/ws-wep-key.c index 90fad5d29a35d04411b62c1bb2f928449ee73dde..bf09163f2ad5e9ec8622d6f2aa7fbea496796f14 100644 --- a/panels/network/wireless-security/ws-wep-key.c +++ b/panels/network/wireless-security/ws-wep-key.c @@ -20,19 +20,18 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" +#include -#include - -#include "ws-wep-key.h" -#include "wireless-security.h" -#include "utils.h" #include "helpers.h" #include "nma-ui-utils.h" +#include "ui-helpers.h" +#include "ws-wep-key.h" +#include "wireless-security.h" struct _WirelessSecurityWEPKey { WirelessSecurity parent; + GtkBuilder *builder; GtkComboBox *auth_method_combo; GtkLabel *auth_method_label; GtkGrid *grid; @@ -50,6 +49,8 @@ struct _WirelessSecurityWEPKey { guint8 cur_index; }; +G_DEFINE_TYPE (WirelessSecurityWEPKey, ws_wep_key, wireless_security_get_type ()) + static void show_toggled_cb (WirelessSecurityWEPKey *self) { @@ -84,26 +85,29 @@ key_index_combo_changed_cb (WirelessSecurityWEPKey *self) } static void -destroy (WirelessSecurity *parent) +ws_wep_key_dispose (GObject *object) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (object); int i; + g_clear_object (&self->builder); for (i = 0; i < 4; i++) memset (self->keys[i], 0, sizeof (self->keys[i])); + + G_OBJECT_CLASS (ws_wep_key_parent_class)->dispose (object); } static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (security); return GTK_WIDGET (self->grid); } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (security); const char *key; int i; @@ -152,18 +156,18 @@ validate (WirelessSecurity *parent, GError **error) } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (security); gtk_size_group_add_widget (group, GTK_WIDGET (self->auth_method_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->key_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->key_index_label)); } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (security); NMSettingWirelessSecurity *s_wsec; NMSettingSecretFlags secret_flags; gint auth_alg; @@ -227,9 +231,8 @@ wep_entry_filter_cb (WirelessSecurityWEPKey *self, } static void -update_secrets (WirelessSecurity *parent, NMConnection *connection) +update_secrets (WirelessSecurityWEPKey *self, NMConnection *connection) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; NMSettingWirelessSecurity *s_wsec; const char *tmp; int i; @@ -251,39 +254,54 @@ changed_cb (WirelessSecurityWEPKey *self) wireless_security_notify_changed ((WirelessSecurity *) self); } +void +ws_wep_key_init (WirelessSecurityWEPKey *self) +{ +} + +void +ws_wep_key_class_init (WirelessSecurityWEPKeyClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_wep_key_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; +} + WirelessSecurityWEPKey * ws_wep_key_new (NMConnection *connection, NMWepKeyType type, gboolean adhoc_create, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityWEPKey *self; NMSettingWirelessSecurity *s_wsec = NULL; NMSetting *setting = NULL; guint8 default_key_idx = 0; gboolean is_adhoc = adhoc_create; gboolean is_shared_key = FALSE; + g_autoptr(GError) error = NULL; + + self = g_object_new (ws_wep_key_get_type (), NULL); - parent = wireless_security_init (sizeof (WirelessSecurityWEPKey), - get_widget, - validate, - add_to_size_group, - fill_connection, - destroy, - "/org/gnome/ControlCenter/network/ws-wep-key.ui"); - if (!parent) + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-wep-key.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); return NULL; - self = (WirelessSecurityWEPKey *) parent; + } - self->auth_method_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "auth_method_combo")); - self->auth_method_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "auth_method_label")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->key_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "key_entry")); - self->key_index_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "key_index_combo")); - self->key_index_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "key_index_label")); - self->key_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "key_label")); - self->show_key_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_key_check")); + self->auth_method_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "auth_method_combo")); + self->auth_method_label = GTK_LABEL (gtk_builder_get_object (self->builder, "auth_method_label")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->key_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "key_entry")); + self->key_index_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "key_index_combo")); + self->key_index_label = GTK_LABEL (gtk_builder_get_object (self->builder, "key_index_label")); + self->key_label = GTK_LABEL (gtk_builder_get_object (self->builder, "key_label")); + self->show_key_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_key_check")); self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_WEP_KEY0; @@ -336,7 +354,7 @@ ws_wep_key_new (NMConnection *connection, /* Fill the key entry with the key for that index */ if (connection) - update_secrets (WIRELESS_SECURITY (self), connection); + update_secrets (self, connection); g_signal_connect_swapped (self->show_key_check, "toggled", G_CALLBACK (show_toggled_cb), self); diff --git a/panels/network/wireless-security/ws-wep-key.h b/panels/network/wireless-security/ws-wep-key.h index 604eba6bb81ff31af4ffffe202fd17328e8b24cb..85003e2e6bb7f7d4cec306f5327e446bb638d29a 100644 --- a/panels/network/wireless-security/ws-wep-key.h +++ b/panels/network/wireless-security/ws-wep-key.h @@ -20,14 +20,19 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_WEP_KEY_H -#define WS_WEP_KEY_H +#pragma once -typedef struct _WirelessSecurityWEPKey WirelessSecurityWEPKey; +#include + +#include "wireless-security.h" + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityWEPKey, ws_wep_key, WS, WEP_KEY, WirelessSecurity) WirelessSecurityWEPKey *ws_wep_key_new (NMConnection *connection, NMWepKeyType type, gboolean adhoc_create, gboolean secrets_only); -#endif /* WS_WEP_KEY_H */ +G_END_DECLS diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index 02c5eb26be840b56b42cc7e0da5c33d9f620a0c4..aecd5a291ea848e2acede088a97d0862685e0d62 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -20,67 +20,145 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - -#include -#include +#include #include "ws-wpa-eap.h" #include "wireless-security.h" #include "eap-method.h" +#include "eap-method-fast.h" +#include "eap-method-leap.h" +#include "eap-method-peap.h" +#include "eap-method-simple.h" +#include "eap-method-tls.h" +#include "eap-method-ttls.h" struct _WirelessSecurityWPAEAP { WirelessSecurity parent; - GtkComboBox *auth_combo; - GtkLabel *auth_label; - GtkGrid *grid; - GtkBox *method_box; + GtkBuilder *builder; + GtkComboBox *auth_combo; + GtkLabel *auth_label; + GtkListStore *auth_model; + GtkGrid *grid; + GtkBox *method_box; - GtkSizeGroup *size_group; + EAPMethodSimple *em_md5; + EAPMethodTLS *em_tls; + EAPMethodLEAP *em_leap; + EAPMethodSimple *em_pwd; + EAPMethodFAST *em_fast; + EAPMethodTTLS *em_ttls; + EAPMethodPEAP *em_peap; }; +G_DEFINE_TYPE (WirelessSecurityWPAEAP, ws_wpa_eap, wireless_security_get_type ()) + +#define AUTH_NAME_COLUMN 0 +#define AUTH_ID_COLUMN 1 + +static EAPMethod * +get_eap (WirelessSecurityWPAEAP *self) +{ + GtkTreeIter iter; + g_autofree gchar *id = NULL; + + if (!gtk_combo_box_get_active_iter (self->auth_combo, &iter)) + return NULL; + gtk_tree_model_get (GTK_TREE_MODEL (self->auth_model), &iter, AUTH_ID_COLUMN, &id, -1); + + if (strcmp (id, "md5") == 0) + return EAP_METHOD (self->em_md5); + if (strcmp (id, "tls") == 0) + return EAP_METHOD (self->em_tls); + if (strcmp (id, "leap") == 0) + return EAP_METHOD (self->em_leap); + if (strcmp (id, "pwd") == 0) + return EAP_METHOD (self->em_pwd); + if (strcmp (id, "fast") == 0) + return EAP_METHOD (self->em_fast); + if (strcmp (id, "ttls") == 0) + return EAP_METHOD (self->em_ttls); + if (strcmp (id, "peap") == 0) + return EAP_METHOD (self->em_peap); + + return NULL; +} static void -destroy (WirelessSecurity *parent) +ws_wpa_eap_dispose (GObject *object) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + WirelessSecurityWPAEAP *self = WS_WPA_EAP (object); - g_clear_object (&self->size_group); + g_clear_object (&self->builder); + + G_OBJECT_CLASS (ws_wpa_eap_parent_class)->dispose (object); } static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + WirelessSecurityWPAEAP *self = WS_WPA_EAP (security); return GTK_WIDGET (self->grid); } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; - return ws_802_1x_validate (self->auth_combo, error); + WirelessSecurityWPAEAP *self = WS_WPA_EAP (security); + return eap_method_validate (get_eap (self), error); } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + WirelessSecurityWPAEAP *self = WS_WPA_EAP (security); - g_clear_object (&self->size_group); - self->size_group = g_object_ref (group); + gtk_size_group_add_widget (group, GTK_WIDGET (self->auth_label)); + eap_method_add_to_size_group (EAP_METHOD (self->em_md5), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_tls), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_leap), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_pwd), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_fast), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_ttls), group); + eap_method_add_to_size_group (EAP_METHOD (self->em_peap), group); +} - ws_802_1x_add_to_size_group (self->size_group, self->auth_label, self->auth_combo); +static void +ws_802_1x_fill_connection (WirelessSecurityWPAEAP *self, NMConnection *connection) +{ + NMSettingWirelessSecurity *s_wireless_sec; + NMSetting8021x *s_8021x; + NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; + EAPMethod *eap; + + /* Get the EAPMethod object */ + eap = get_eap (self); + + /* Get previous pasword flags, if any. Otherwise default to agent-owned secrets */ + s_8021x = nm_connection_get_setting_802_1x (connection); + if (s_8021x) + nm_setting_get_secret_flags (NM_SETTING (s_8021x), eap_method_get_password_flags_name (eap), &secret_flags, NULL); + else + secret_flags = NM_SETTING_SECRET_FLAG_AGENT_OWNED; + + /* Blow away the old wireless security setting by adding a clear one */ + s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new (); + nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec); + + /* Blow away the old 802.1x setting by adding a clear one */ + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new (); + nm_connection_add_setting (connection, (NMSetting *) s_8021x); + + eap_method_fill_connection (eap, connection, secret_flags); } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + WirelessSecurityWPAEAP *self = WS_WPA_EAP (security); NMSettingWirelessSecurity *s_wireless_sec; - ws_802_1x_fill_connection (self->auth_combo, connection); + ws_802_1x_fill_connection (self, connection); s_wireless_sec = nm_connection_get_setting_wireless_security (connection); g_assert (s_wireless_sec); @@ -88,16 +166,52 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection) g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL); } +static gboolean +adhoc_compatible (WirelessSecurity *security) +{ + return FALSE; +} + static void -auth_combo_changed_cb (GtkWidget *combo, gpointer user_data) +auth_combo_changed_cb (WirelessSecurityWPAEAP *self) { - WirelessSecurity *parent = WIRELESS_SECURITY (user_data); - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + EAPMethod *eap; + GList *elt, *children; + GtkWidget *eap_default_field; - ws_802_1x_auth_combo_changed (combo, - parent, - self->method_box, - self->size_group); + /* Remove any previous wireless security widgets */ + children = gtk_container_get_children (GTK_CONTAINER (self->method_box)); + for (elt = children; elt; elt = g_list_next (elt)) + gtk_container_remove (GTK_CONTAINER (self->method_box), GTK_WIDGET (elt->data)); + + eap = get_eap (self); + gtk_container_add (GTK_CONTAINER (self->method_box), g_object_ref (GTK_WIDGET (eap))); + + /* Refocus the EAP method's default widget */ + eap_default_field = eap_method_get_default_field (eap); + if (eap_default_field) + gtk_widget_grab_focus (eap_default_field); + + wireless_security_notify_changed (WIRELESS_SECURITY (self)); +} + +void +ws_wpa_eap_init (WirelessSecurityWPAEAP *self) +{ +} + +void +ws_wpa_eap_class_init (WirelessSecurityWPAEAPClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_wpa_eap_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; + ws_class->adhoc_compatible = adhoc_compatible; } WirelessSecurityWPAEAP * @@ -105,37 +219,136 @@ ws_wpa_eap_new (NMConnection *connection, gboolean is_editor, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityWPAEAP *self; + const gchar *user = NULL, *password = NULL; + gboolean always_ask = FALSE; + const gchar *remove_method, *default_method = NULL; + gboolean wired = FALSE; + EAPMethodSimpleFlags simple_flags = EAP_METHOD_SIMPLE_FLAG_NONE; + GtkTreeIter iter; + g_autoptr(GError) error = NULL; + + self = g_object_new (ws_wpa_eap_get_type (), NULL); - parent = wireless_security_init (sizeof (WirelessSecurityWPAEAP), - get_widget, - validate, - add_to_size_group, - fill_connection, - destroy, - "/org/gnome/ControlCenter/network/ws-wpa-eap.ui"); - if (!parent) + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-wpa-eap.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); return NULL; - self = (WirelessSecurityWPAEAP *) parent; + } + + self->auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "auth_combo")); + self->auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "auth_label")); + self->auth_model = GTK_LIST_STORE (gtk_builder_get_object (self->builder, "auth_model")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->method_box = GTK_BOX (gtk_builder_get_object (self->builder, "method_box")); - self->auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "auth_combo")); - self->auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "auth_label")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->method_box = GTK_BOX (gtk_builder_get_object (parent->builder, "method_box")); + /* Grab the default EAP method out of the security object */ + if (connection) { + NMSettingConnection *s_con; + NMSetting8021x *s_8021x; + const char *ctype = NULL; - wireless_security_set_adhoc_compatible (parent, FALSE); - wireless_security_set_hotspot_compatible (parent, FALSE); + s_con = nm_connection_get_setting_connection (connection); + if (s_con) + ctype = nm_setting_connection_get_connection_type (s_con); + if ((g_strcmp0 (ctype, NM_SETTING_WIRED_SETTING_NAME) == 0) + || nm_connection_get_setting_wired (connection)) + wired = TRUE; - ws_802_1x_auth_combo_init (parent, - self->auth_combo, - self->auth_label, - (GCallback) auth_combo_changed_cb, - connection, - is_editor, - secrets_only); - auth_combo_changed_cb (GTK_WIDGET (self->auth_combo), parent); + s_8021x = nm_connection_get_setting_802_1x (connection); + if (s_8021x && nm_setting_802_1x_get_num_eap_methods (s_8021x)) + default_method = nm_setting_802_1x_get_eap_method (s_8021x, 0); + } + if (wired) + remove_method = "leap"; + else + remove_method = "md5"; + if (default_method == NULL) { + if (wired) + default_method = "md5"; + else + default_method = "tls"; + } + + /* initialize WirelessSecurity userpass from connection (clear if no connection) */ + if (connection) { + NMSetting8021x *setting; + + setting = nm_connection_get_setting_802_1x (connection); + if (setting) { + NMSettingSecretFlags flags; + + user = nm_setting_802_1x_get_identity (setting); + password = nm_setting_802_1x_get_password (setting); + + if (nm_setting_get_secret_flags (NM_SETTING (setting), NM_SETTING_802_1X_PASSWORD, &flags, NULL)) + always_ask = !!(flags & NM_SETTING_SECRET_FLAG_NOT_SAVED); + } + } + wireless_security_set_username (WIRELESS_SECURITY (self), user); + wireless_security_set_password (WIRELESS_SECURITY (self), password); + wireless_security_set_always_ask (WIRELESS_SECURITY (self), always_ask); + wireless_security_set_show_password (WIRELESS_SECURITY (self), FALSE); + + if (is_editor) + simple_flags |= EAP_METHOD_SIMPLE_FLAG_IS_EDITOR; + if (secrets_only) + simple_flags |= EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY; + + self->em_md5 = eap_method_simple_new (WIRELESS_SECURITY (self), connection, EAP_METHOD_SIMPLE_TYPE_MD5, simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_md5)); + g_signal_connect_object (self->em_md5, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_tls = eap_method_tls_new (WIRELESS_SECURITY (self), connection, FALSE, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_tls)); + g_signal_connect_object (self->em_tls, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_leap = eap_method_leap_new (WIRELESS_SECURITY (self), connection, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_leap)); + g_signal_connect_object (self->em_leap, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_pwd = eap_method_simple_new (WIRELESS_SECURITY (self), connection, EAP_METHOD_SIMPLE_TYPE_PWD, simple_flags); + gtk_widget_show (GTK_WIDGET (self->em_pwd)); + g_signal_connect_object (self->em_pwd, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_fast = eap_method_fast_new (WIRELESS_SECURITY (self), connection, is_editor, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_fast)); + g_signal_connect_object (self->em_fast, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_ttls = eap_method_ttls_new (WIRELESS_SECURITY (self), connection, is_editor, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_ttls)); + g_signal_connect_object (self->em_ttls, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + self->em_peap = eap_method_peap_new (WIRELESS_SECURITY (self), connection, is_editor, secrets_only); + gtk_widget_show (GTK_WIDGET (self->em_peap)); + g_signal_connect_object (self->em_peap, "changed", G_CALLBACK (wireless_security_notify_changed), self, G_CONNECT_SWAPPED); + + if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->auth_model), &iter)) { + do { + g_autofree gchar *id = NULL; + gtk_tree_model_get (GTK_TREE_MODEL (self->auth_model), &iter, AUTH_ID_COLUMN, &id, -1); + if (strcmp (id, remove_method) == 0) { + gtk_list_store_remove (self->auth_model, &iter); + break; + } + } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->auth_model), &iter)); + } + if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->auth_model), &iter)) { + do { + g_autofree gchar *id = NULL; + gtk_tree_model_get (GTK_TREE_MODEL (self->auth_model), &iter, AUTH_ID_COLUMN, &id, -1); + if (strcmp (id, default_method) == 0) + gtk_combo_box_set_active_iter (self->auth_combo, &iter); + } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->auth_model), &iter)); + } + + if (secrets_only) { + gtk_widget_hide (GTK_WIDGET (self->auth_combo)); + gtk_widget_hide (GTK_WIDGET (self->auth_label)); + } + + g_signal_connect_object (G_OBJECT (self->auth_combo), "changed", G_CALLBACK (auth_combo_changed_cb), self, G_CONNECT_SWAPPED); + auth_combo_changed_cb (self); return self; } +void +ws_wpa_eap_fill_connection (WirelessSecurityWPAEAP *self, NMConnection *connection) +{ + ws_802_1x_fill_connection (self, connection); +} diff --git a/panels/network/wireless-security/ws-wpa-eap.h b/panels/network/wireless-security/ws-wpa-eap.h index 0ebff700c70fc61986199ccb113aac416471cba6..682e982b00602336bf920919155517a0a1cf915d 100644 --- a/panels/network/wireless-security/ws-wpa-eap.h +++ b/panels/network/wireless-security/ws-wpa-eap.h @@ -20,13 +20,21 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_WPA_EAP_H -#define WS_WPA_EAP_H +#pragma once -typedef struct _WirelessSecurityWPAEAP WirelessSecurityWPAEAP; +#include -WirelessSecurityWPAEAP * ws_wpa_eap_new (NMConnection *connection, - gboolean is_editor, - gboolean secrets_only); +#include "wireless-security.h" -#endif /* WS_WPA_EAP_H */ +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityWPAEAP, ws_wpa_eap, WS, WPA_EAP, WirelessSecurity) + +WirelessSecurityWPAEAP *ws_wpa_eap_new (NMConnection *connection, + gboolean is_editor, + gboolean secrets_only); + +void ws_wpa_eap_fill_connection (WirelessSecurityWPAEAP *sec, + NMConnection *connection); + +G_END_DECLS diff --git a/panels/network/wireless-security/ws-wpa-eap.ui b/panels/network/wireless-security/ws-wpa-eap.ui index bf0d673dd177616e3ada0c42b17b62681774855d..95b129fa19196fdf90565094a0032dc348a1d122 100644 --- a/panels/network/wireless-security/ws-wpa-eap.ui +++ b/panels/network/wireless-security/ws-wpa-eap.ui @@ -3,12 +3,48 @@ - + + + + + - + MD5 + md5 + True + + + TLS + tls + True + + + LEAP + leap + True + + + PWD + pwd + True + + + FAST + fast + True + + + Tunneled TLS + ttls + True + + + Protected EAP (PEAP) + peap + True diff --git a/panels/network/wireless-security/ws-wpa-psk.c b/panels/network/wireless-security/ws-wpa-psk.c index 9e4dac7011761876cb4cc8c67e433724dd1afabb..e6d4c25f92e1cd866f18bb4de6c2d24403c65ee8 100644 --- a/panels/network/wireless-security/ws-wpa-psk.c +++ b/panels/network/wireless-security/ws-wpa-psk.c @@ -20,22 +20,21 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#include "nm-default.h" - #include -#include +#include -#include "ws-wpa-psk.h" -#include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" -#include "utils.h" +#include "ui-helpers.h" +#include "ws-wpa-psk.h" +#include "wireless-security.h" #define WPA_PMK_LEN 32 struct _WirelessSecurityWPAPSK { WirelessSecurity parent; + GtkBuilder *builder; GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; @@ -47,10 +46,22 @@ struct _WirelessSecurityWPAPSK { const char *password_flags_name; }; +G_DEFINE_TYPE (WirelessSecurityWPAPSK, ws_wpa_psk, wireless_security_get_type ()) + +static void +ws_wpa_psk_dispose (GObject *object) +{ + WirelessSecurityWPAPSK *self = WS_WPA_PSK (object); + + g_clear_object (&self->builder); + + G_OBJECT_CLASS (ws_wpa_psk_parent_class)->dispose (object); +} + static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + WirelessSecurityWPAPSK *self = WS_WPA_PSK (security); return GTK_WIDGET (self->grid); } @@ -64,9 +75,9 @@ show_toggled_cb (WirelessSecurityWPAPSK *self) } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + WirelessSecurityWPAPSK *self = WS_WPA_PSK (security); const char *key; gsize len; int i; @@ -97,17 +108,17 @@ validate (WirelessSecurity *parent, GError **error) } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + WirelessSecurityWPAPSK *self = WS_WPA_PSK (security); gtk_size_group_add_widget (group, GTK_WIDGET (self->type_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->password_label)); } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + WirelessSecurityWPAPSK *self = WS_WPA_PSK (security); const char *key; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; @@ -159,14 +170,10 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection) } } -static void -update_secrets (WirelessSecurity *parent, NMConnection *connection) +static gboolean +adhoc_compatible (WirelessSecurity *security) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; - helper_fill_secret_entry (connection, - self->password_entry, - NM_TYPE_SETTING_WIRELESS_SECURITY, - (HelperSecretFunc) nm_setting_wireless_security_get_psk); + return FALSE; } static void @@ -175,32 +182,46 @@ changed_cb (WirelessSecurityWPAPSK *self) wireless_security_notify_changed ((WirelessSecurity *) self); } +void +ws_wpa_psk_init (WirelessSecurityWPAPSK *self) +{ +} + +void +ws_wpa_psk_class_init (WirelessSecurityWPAPSKClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_wpa_psk_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; + ws_class->adhoc_compatible = adhoc_compatible; +} + WirelessSecurityWPAPSK * ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityWPAPSK *self; NMSetting *setting = NULL; + g_autoptr(GError) error = NULL; - parent = wireless_security_init (sizeof (WirelessSecurityWPAPSK), - get_widget, - validate, - add_to_size_group, - fill_connection, - NULL, - "/org/gnome/ControlCenter/network/ws-wpa-psk.ui"); - if (!parent) - return NULL; - self = (WirelessSecurityWPAPSK *) parent; + self = g_object_new (ws_wpa_psk_get_type (), NULL); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "password_entry")); - self->password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->type_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "type_combo")); - self->type_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "type_label")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-wpa-psk.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } - wireless_security_set_adhoc_compatible (parent, FALSE); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "password_entry")); + self->password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "password_label")); + self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); + self->type_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "type_combo")); + self->type_label = GTK_LABEL (gtk_builder_get_object (self->builder, "type_label")); self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_PSK; @@ -215,8 +236,12 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only) FALSE, secrets_only); /* Fill secrets, if any */ - if (connection) - update_secrets (WIRELESS_SECURITY (self), connection); + if (connection) { + helper_fill_secret_entry (connection, + self->password_entry, + NM_TYPE_SETTING_WIRELESS_SECURITY, + (HelperSecretFunc) nm_setting_wireless_security_get_psk); + } g_signal_connect_swapped (self->show_password_check, "toggled", G_CALLBACK (show_toggled_cb), self); diff --git a/panels/network/wireless-security/ws-wpa-psk.h b/panels/network/wireless-security/ws-wpa-psk.h index 8b84ed856354adfb54f4595f32190b7041a61d7a..d2c4a5bd22c48156e5f492427ef248494293b2ce 100644 --- a/panels/network/wireless-security/ws-wpa-psk.h +++ b/panels/network/wireless-security/ws-wpa-psk.h @@ -20,11 +20,16 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_WPA_PSK_H -#define WS_WPA_PSK_H +#pragma once -typedef struct _WirelessSecurityWPAPSK WirelessSecurityWPAPSK; +#include + +#include "wireless-security.h" + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityWPAPSK, ws_wpa_psk, WS, WPA_PSK, WirelessSecurity) WirelessSecurityWPAPSK * ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only); -#endif /* WS_WEP_KEY_H */ +G_END_DECLS