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
|
|
|
*/
|
|
|
|
|
2016-06-07 12:03:22 +02:00
|
|
|
#include "nm-default.h"
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-10-14 16:32:15 +13:00
|
|
|
#include "ws-leap.h"
|
2012-12-09 19:38:32 -05:00
|
|
|
#include "wireless-security.h"
|
|
|
|
#include "helpers.h"
|
2016-06-07 12:03:22 +02:00
|
|
|
#include "nma-ui-utils.h"
|
|
|
|
#include "utils.h"
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
struct _WirelessSecurityLEAP {
|
|
|
|
WirelessSecurity parent;
|
2016-06-07 12:03:22 +02:00
|
|
|
gboolean editing_connection;
|
|
|
|
const char *password_flags_name;
|
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
|
|
|
{
|
2019-10-15 11:15:30 +13:00
|
|
|
WirelessSecurity *sec = (WirelessSecurity *) self;
|
2012-12-09 19:38:32 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
gboolean visible;
|
|
|
|
|
2019-10-15 12:34:44 +13:00
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (sec->builder, "show_password_check"));
|
2019-10-15 11:15:30 +13:00
|
|
|
visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:34:44 +13:00
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (sec->builder, "password_entry"));
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_entry_set_visibility (GTK_ENTRY (widget), visible);
|
|
|
|
}
|
|
|
|
|
2019-10-03 21:39:37 +13:00
|
|
|
static GtkWidget *
|
|
|
|
get_widget (WirelessSecurity *parent)
|
|
|
|
{
|
2019-10-15 12:34:44 +13:00
|
|
|
return GTK_WIDGET (gtk_builder_get_object (parent->builder, "grid"));
|
2019-10-03 21:39:37 +13:00
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
static gboolean
|
2016-06-07 12:03:22 +02:00
|
|
|
validate (WirelessSecurity *parent, GError **error)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
|
|
|
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:34:44 +13:00
|
|
|
entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "username_entry"));
|
2012-12-09 19:38:32 -05:00
|
|
|
g_assert (entry);
|
|
|
|
text = gtk_entry_get_text (GTK_ENTRY (entry));
|
2014-08-07 18:32:34 +02:00
|
|
|
if (!text || !strlen (text)) {
|
|
|
|
widget_set_error (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
|
2014-08-13 13:46:03 +02:00
|
|
|
widget_unset_error (entry);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:34:44 +13:00
|
|
|
entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "password_entry"));
|
2012-12-09 19:38:32 -05:00
|
|
|
g_assert (entry);
|
|
|
|
text = gtk_entry_get_text (GTK_ENTRY (entry));
|
2016-06-07 12:03:22 +02:00
|
|
|
if (!text || !strlen (text)) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (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
|
2014-08-13 13:46:03 +02:00
|
|
|
widget_unset_error (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
|
|
|
|
add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group)
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2019-10-15 12:34:44 +13:00
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "username_label"));
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_size_group_add_widget (group, widget);
|
|
|
|
|
2019-10-15 12:34:44 +13:00
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "password_label"));
|
2012-12-09 19:38:32 -05:00
|
|
|
gtk_size_group_add_widget (group, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fill_connection (WirelessSecurity *parent, NMConnection *connection)
|
|
|
|
{
|
|
|
|
WirelessSecurityLEAP *sec = (WirelessSecurityLEAP *) parent;
|
|
|
|
NMSettingWirelessSecurity *s_wireless_sec;
|
2016-06-07 12:03:22 +02:00
|
|
|
NMSettingSecretFlags secret_flags;
|
|
|
|
GtkWidget *widget, *passwd_entry;
|
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-15 12:34:44 +13:00
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "username_entry"));
|
2012-12-09 19:38:32 -05:00
|
|
|
leap_username = gtk_entry_get_text (GTK_ENTRY (widget));
|
|
|
|
|
2019-10-15 12:34:44 +13:00
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "password_entry"));
|
2016-06-07 12:03:22 +02:00
|
|
|
passwd_entry = widget;
|
2012-12-09 19:38:32 -05:00
|
|
|
leap_password = gtk_entry_get_text (GTK_ENTRY (widget));
|
|
|
|
|
|
|
|
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 */
|
|
|
|
secret_flags = nma_utils_menu_to_secret_flags (passwd_entry);
|
|
|
|
nm_setting_set_secret_flags (NM_SETTING (s_wireless_sec), sec->password_flags_name,
|
|
|
|
secret_flags, NULL);
|
|
|
|
|
|
|
|
/* Update secret flags and popup when editing the connection */
|
|
|
|
if (sec->editing_connection)
|
|
|
|
nma_utils_update_password_storage (passwd_entry, secret_flags,
|
|
|
|
NM_SETTING (s_wireless_sec), sec->password_flags_name);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_secrets (WirelessSecurity *parent, NMConnection *connection)
|
|
|
|
{
|
|
|
|
helper_fill_secret_entry (connection,
|
2019-10-15 12:34:44 +13:00
|
|
|
GTK_ENTRY (gtk_builder_get_object (parent->builder, "password_entry")),
|
2012-12-09 19:38:32 -05:00
|
|
|
NM_TYPE_SETTING_WIRELESS_SECURITY,
|
|
|
|
(HelperSecretFunc) nm_setting_wireless_security_get_leap_password);
|
|
|
|
}
|
|
|
|
|
2019-10-15 10:33:17 +13:00
|
|
|
static void
|
|
|
|
changed_cb (WirelessSecurityLEAP *self)
|
|
|
|
{
|
|
|
|
wireless_security_notify_changed ((WirelessSecurity *) self);
|
|
|
|
}
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
WirelessSecurityLEAP *
|
|
|
|
ws_leap_new (NMConnection *connection, gboolean secrets_only)
|
|
|
|
{
|
|
|
|
WirelessSecurity *parent;
|
|
|
|
WirelessSecurityLEAP *sec;
|
|
|
|
GtkWidget *widget;
|
|
|
|
NMSettingWirelessSecurity *wsec = NULL;
|
|
|
|
|
|
|
|
parent = wireless_security_init (sizeof (WirelessSecurityLEAP),
|
2019-10-03 21:39:37 +13:00
|
|
|
get_widget,
|
2012-12-09 19:38:32 -05:00
|
|
|
validate,
|
|
|
|
add_to_size_group,
|
|
|
|
fill_connection,
|
|
|
|
NULL,
|
2019-10-03 21:39:37 +13:00
|
|
|
"/org/gnome/ControlCenter/network/ws-leap.ui");
|
2012-12-09 19:38:32 -05:00
|
|
|
if (!parent)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
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-03 21:07:25 +13:00
|
|
|
wireless_security_set_adhoc_compatible (parent, FALSE);
|
|
|
|
wireless_security_set_hotspot_compatible (parent, FALSE);
|
2012-12-09 19:38:32 -05:00
|
|
|
sec = (WirelessSecurityLEAP *) parent;
|
2016-06-07 12:03:22 +02:00
|
|
|
sec->editing_connection = secrets_only ? FALSE : TRUE;
|
|
|
|
sec->password_flags_name = NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:34:44 +13:00
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "password_entry"));
|
2012-12-09 19:38:32 -05:00
|
|
|
g_assert (widget);
|
2019-10-15 10:33:17 +13:00
|
|
|
g_signal_connect_swapped (widget, "changed", G_CALLBACK (changed_cb), sec);
|
2016-06-07 12:03:22 +02:00
|
|
|
|
|
|
|
/* Create password-storage popup menu for password entry under entry's secondary icon */
|
|
|
|
nma_utils_setup_password_storage (widget, 0, (NMSetting *) wsec, sec->password_flags_name,
|
|
|
|
FALSE, secrets_only);
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
if (wsec)
|
|
|
|
update_secrets (WIRELESS_SECURITY (sec), connection);
|
|
|
|
|
2019-10-15 12:34:44 +13:00
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "username_entry"));
|
2012-12-09 19:38:32 -05:00
|
|
|
g_assert (widget);
|
2019-10-15 10:33:17 +13:00
|
|
|
g_signal_connect_swapped (widget, "changed", G_CALLBACK (changed_cb), sec);
|
2012-12-09 19:38:32 -05:00
|
|
|
if (wsec)
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget), nm_setting_wireless_security_get_leap_username (wsec));
|
|
|
|
|
|
|
|
if (secrets_only)
|
|
|
|
gtk_widget_hide (widget);
|
|
|
|
|
2019-10-15 12:34:44 +13:00
|
|
|
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "show_password_check"));
|
2012-12-09 19:38:32 -05:00
|
|
|
g_assert (widget);
|
2019-10-15 11:15:30 +13:00
|
|
|
g_signal_connect_swapped (widget, "toggled", G_CALLBACK (show_toggled_cb), sec);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
return sec;
|
|
|
|
}
|
|
|
|
|