2012-12-09 19:38:32 -05:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
/* NetworkManager Applet -- allow user control over networking
|
|
|
|
*
|
|
|
|
* Dan Williams <dcbw@redhat.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2016-06-07 12:03:22 +02:00
|
|
|
* Copyright 2007 - 2014 Red Hat, Inc.
|
2012-12-09 19:38:32 -05:00
|
|
|
*/
|
|
|
|
|
2019-11-12 09:53:18 +13:00
|
|
|
#include <glib/gi18n.h>
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
#include "helpers.h"
|
2016-06-07 12:03:22 +02:00
|
|
|
#include "nma-ui-utils.h"
|
2019-11-12 10:08:14 +13:00
|
|
|
#include "ui-helpers.h"
|
|
|
|
#include "wireless-security.h"
|
|
|
|
#include "ws-leap.h"
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
struct _WirelessSecurityLEAP {
|
2019-12-03 09:47:46 +13:00
|
|
|
GtkGrid parent;
|
2019-10-15 12:25:48 +13:00
|
|
|
|
|
|
|
GtkEntry *password_entry;
|
|
|
|
GtkLabel *password_label;
|
|
|
|
GtkCheckButton *show_password_check;
|
|
|
|
GtkEntry *username_entry;
|
|
|
|
GtkLabel *username_label;
|
|
|
|
|
2016-06-07 12:03:22 +02:00
|
|
|
gboolean editing_connection;
|
|
|
|
const char *password_flags_name;
|
2012-12-09 19:38:32 -05:00
|
|
|
};
|
|
|
|
|
2019-12-03 09:27:03 +13:00
|
|
|
static void wireless_security_iface_init (WirelessSecurityInterface *);
|
|
|
|
|
2019-12-03 09:47:46 +13:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (WirelessSecurityLEAP, ws_leap, GTK_TYPE_GRID,
|
2019-12-03 09:27:03 +13:00
|
|
|
G_IMPLEMENT_INTERFACE (wireless_security_get_type (), wireless_security_iface_init));
|
2019-11-07 12:37:34 +13:00
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static void
|
2019-10-15 11:15:30 +13:00
|
|
|
show_toggled_cb (WirelessSecurityLEAP *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
gboolean visible;
|
|
|
|
|
2019-10-15 12:25:48 +13:00
|
|
|
visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check));
|
|
|
|
gtk_entry_set_visibility (self->password_entry, visible);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-11-07 12:37:34 +13:00
|
|
|
validate (WirelessSecurity *security, GError **error)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2019-11-07 12:37:34 +13:00
|
|
|
WirelessSecurityLEAP *self = WS_LEAP (security);
|
2012-12-09 19:38:32 -05:00
|
|
|
const char *text;
|
2014-08-13 13:46:03 +02:00
|
|
|
gboolean ret = TRUE;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:25:48 +13:00
|
|
|
text = gtk_entry_get_text (self->username_entry);
|
2014-08-07 18:32:34 +02:00
|
|
|
if (!text || !strlen (text)) {
|
2019-10-15 12:25:48 +13:00
|
|
|
widget_set_error (GTK_WIDGET (self->username_entry));
|
2016-06-07 12:03:22 +02:00
|
|
|
g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing leap-username"));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
2016-06-07 16:53:04 +02:00
|
|
|
} else
|
2019-10-15 12:25:48 +13:00
|
|
|
widget_unset_error (GTK_WIDGET (self->username_entry));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:25:48 +13:00
|
|
|
text = gtk_entry_get_text (self->password_entry);
|
2016-06-07 12:03:22 +02:00
|
|
|
if (!text || !strlen (text)) {
|
2019-10-15 12:25:48 +13:00
|
|
|
widget_set_error (GTK_WIDGET (self->password_entry));
|
2016-06-07 16:53:04 +02:00
|
|
|
if (ret) {
|
2016-06-07 12:03:22 +02:00
|
|
|
g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing leap-password"));
|
2016-06-07 16:53:04 +02:00
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
} else
|
2019-10-15 12:25:48 +13:00
|
|
|
widget_unset_error (GTK_WIDGET (self->password_entry));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2014-08-13 13:46:03 +02:00
|
|
|
return ret;
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-07 12:37:34 +13:00
|
|
|
add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2019-11-07 12:37:34 +13:00
|
|
|
WirelessSecurityLEAP *self = WS_LEAP (security);
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_size_group_add_widget (group, GTK_WIDGET (self->username_label));
|
|
|
|
gtk_size_group_add_widget (group, GTK_WIDGET (self->password_label));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-07 12:37:34 +13:00
|
|
|
fill_connection (WirelessSecurity *security, NMConnection *connection)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2019-11-07 12:37:34 +13:00
|
|
|
WirelessSecurityLEAP *self = WS_LEAP (security);
|
2012-12-09 19:38:32 -05:00
|
|
|
NMSettingWirelessSecurity *s_wireless_sec;
|
2016-06-07 12:03:22 +02:00
|
|
|
NMSettingSecretFlags secret_flags;
|
2012-12-09 19:38:32 -05:00
|
|
|
const char *leap_password = NULL, *leap_username = NULL;
|
|
|
|
|
|
|
|
/* Blow away the old 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);
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
leap_username = gtk_entry_get_text (self->username_entry);
|
|
|
|
leap_password = gtk_entry_get_text (self->password_entry);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
g_object_set (s_wireless_sec,
|
|
|
|
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x",
|
|
|
|
NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap",
|
|
|
|
NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, leap_username,
|
|
|
|
NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, leap_password,
|
|
|
|
NULL);
|
|
|
|
|
2016-06-07 12:03:22 +02:00
|
|
|
/* Save LEAP_PASSWORD_FLAGS to the connection */
|
2019-10-18 11:47:17 +13:00
|
|
|
secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->password_entry));
|
|
|
|
nm_setting_set_secret_flags (NM_SETTING (s_wireless_sec), self->password_flags_name,
|
2016-06-07 12:03:22 +02:00
|
|
|
secret_flags, NULL);
|
|
|
|
|
|
|
|
/* Update secret flags and popup when editing the connection */
|
2019-10-18 11:47:17 +13:00
|
|
|
if (self->editing_connection)
|
|
|
|
nma_utils_update_password_storage (GTK_WIDGET (self->password_entry), secret_flags,
|
|
|
|
NM_SETTING (s_wireless_sec), self->password_flags_name);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2019-11-07 13:58:30 +13:00
|
|
|
static gboolean
|
|
|
|
adhoc_compatible (WirelessSecurity *security)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static void
|
2019-11-07 12:37:34 +13:00
|
|
|
changed_cb (WirelessSecurityLEAP *self)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
2019-11-07 12:37:34 +13:00
|
|
|
wireless_security_notify_changed ((WirelessSecurity *) self);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
2019-11-07 12:37:34 +13:00
|
|
|
void
|
|
|
|
ws_leap_init (WirelessSecurityLEAP *self)
|
2019-10-15 10:33:17 +13:00
|
|
|
{
|
2019-12-03 09:47:46 +13:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (self));
|
2019-11-07 12:37:34 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ws_leap_class_init (WirelessSecurityLEAPClass *klass)
|
|
|
|
{
|
2019-12-03 09:47:46 +13:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/ws-leap.ui");
|
2019-11-07 12:37:34 +13:00
|
|
|
|
2019-12-03 09:47:46 +13:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, WirelessSecurityLEAP, password_entry);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, WirelessSecurityLEAP, password_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, WirelessSecurityLEAP, show_password_check);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, WirelessSecurityLEAP, username_entry);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, WirelessSecurityLEAP, username_label);
|
2019-12-03 09:27:03 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wireless_security_iface_init (WirelessSecurityInterface *iface)
|
|
|
|
{
|
|
|
|
iface->validate = validate;
|
|
|
|
iface->add_to_size_group = add_to_size_group;
|
|
|
|
iface->fill_connection = fill_connection;
|
|
|
|
iface->adhoc_compatible = adhoc_compatible;
|
2019-10-15 10:33:17 +13:00
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
WirelessSecurityLEAP *
|
|
|
|
ws_leap_new (NMConnection *connection, gboolean secrets_only)
|
|
|
|
{
|
2019-10-18 11:47:17 +13:00
|
|
|
WirelessSecurityLEAP *self;
|
2012-12-09 19:38:32 -05:00
|
|
|
NMSettingWirelessSecurity *wsec = NULL;
|
|
|
|
|
2019-11-07 12:37:34 +13:00
|
|
|
self = g_object_new (ws_leap_get_type (), NULL);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
if (connection) {
|
|
|
|
wsec = nm_connection_get_setting_wireless_security (connection);
|
|
|
|
if (wsec) {
|
|
|
|
const char *auth_alg;
|
|
|
|
|
|
|
|
/* Ignore if wireless security doesn't specify LEAP */
|
|
|
|
auth_alg = nm_setting_wireless_security_get_auth_alg (wsec);
|
|
|
|
if (!auth_alg || strcmp (auth_alg, "leap"))
|
|
|
|
wsec = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
self->editing_connection = secrets_only ? FALSE : TRUE;
|
|
|
|
self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD;
|
2019-10-15 12:25:48 +13:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
g_signal_connect_swapped (self->password_entry, "changed", G_CALLBACK (changed_cb), self);
|
2016-06-07 12:03:22 +02:00
|
|
|
|
|
|
|
/* Create password-storage popup menu for password entry under entry's secondary icon */
|
2019-10-18 11:47:17 +13:00
|
|
|
nma_utils_setup_password_storage (GTK_WIDGET (self->password_entry), 0, (NMSetting *) wsec, self->password_flags_name,
|
2016-06-07 12:03:22 +02:00
|
|
|
FALSE, secrets_only);
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
if (wsec)
|
2019-11-07 12:37:34 +13:00
|
|
|
helper_fill_secret_entry (connection,
|
|
|
|
self->password_entry,
|
|
|
|
NM_TYPE_SETTING_WIRELESS_SECURITY,
|
|
|
|
(HelperSecretFunc) nm_setting_wireless_security_get_leap_password);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
g_signal_connect_swapped (self->username_entry, "changed", G_CALLBACK (changed_cb), self);
|
2012-12-09 19:38:32 -05:00
|
|
|
if (wsec)
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_entry_set_text (self->username_entry, nm_setting_wireless_security_get_leap_username (wsec));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
if (secrets_only)
|
2019-10-18 11:47:17 +13:00
|
|
|
gtk_widget_hide (GTK_WIDGET (self->username_entry));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
g_signal_connect_swapped (self->show_password_check, "toggled", G_CALLBACK (show_toggled_cb), self);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-18 11:47:17 +13:00
|
|
|
return self;
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|