1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* NetworkManager Applet -- allow user control over networking
4
* Dan Williams <dcbw@redhat.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
* Copyright 2007 - 2014 Red Hat, Inc.
23
#include "nm-default.h"
27
#include "wireless-security.h"
29
#include "nma-ui-utils.h"
32
struct _WirelessSecurityLEAP {
33
WirelessSecurity parent;
34
gboolean editing_connection;
35
const char *password_flags_name;
39
show_toggled_cb (GtkCheckButton *button, WirelessSecurity *sec)
44
widget = GTK_WIDGET (gtk_builder_get_object (sec->builder, "leap_password_entry"));
47
visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
48
gtk_entry_set_visibility (GTK_ENTRY (widget), visible);
52
validate (WirelessSecurity *parent, GError **error)
58
entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_username_entry"));
60
text = gtk_entry_get_text (GTK_ENTRY (entry));
61
if (!text || !strlen (text)) {
62
widget_set_error (entry);
63
g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing leap-username"));
66
widget_unset_error (entry);
68
entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_password_entry"));
70
text = gtk_entry_get_text (GTK_ENTRY (entry));
71
if (!text || !strlen (text)) {
72
widget_set_error (entry);
74
g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("missing leap-password"));
78
widget_unset_error (entry);
84
add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group)
88
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_username_label"));
89
gtk_size_group_add_widget (group, widget);
91
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_password_label"));
92
gtk_size_group_add_widget (group, widget);
96
fill_connection (WirelessSecurity *parent, NMConnection *connection)
98
WirelessSecurityLEAP *sec = (WirelessSecurityLEAP *) parent;
99
NMSettingWirelessSecurity *s_wireless_sec;
100
NMSettingSecretFlags secret_flags;
101
GtkWidget *widget, *passwd_entry;
102
const char *leap_password = NULL, *leap_username = NULL;
104
/* Blow away the old security setting by adding a clear one */
105
s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
106
nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec);
108
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_username_entry"));
109
leap_username = gtk_entry_get_text (GTK_ENTRY (widget));
111
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_password_entry"));
112
passwd_entry = widget;
113
leap_password = gtk_entry_get_text (GTK_ENTRY (widget));
115
g_object_set (s_wireless_sec,
116
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x",
117
NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap",
118
NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, leap_username,
119
NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, leap_password,
122
/* Save LEAP_PASSWORD_FLAGS to the connection */
123
secret_flags = nma_utils_menu_to_secret_flags (passwd_entry);
124
nm_setting_set_secret_flags (NM_SETTING (s_wireless_sec), sec->password_flags_name,
127
/* Update secret flags and popup when editing the connection */
128
if (sec->editing_connection)
129
nma_utils_update_password_storage (passwd_entry, secret_flags,
130
NM_SETTING (s_wireless_sec), sec->password_flags_name);
134
update_secrets (WirelessSecurity *parent, NMConnection *connection)
136
helper_fill_secret_entry (connection,
138
"leap_password_entry",
139
NM_TYPE_SETTING_WIRELESS_SECURITY,
140
(HelperSecretFunc) nm_setting_wireless_security_get_leap_password);
143
WirelessSecurityLEAP *
144
ws_leap_new (NMConnection *connection, gboolean secrets_only)
146
WirelessSecurity *parent;
147
WirelessSecurityLEAP *sec;
149
NMSettingWirelessSecurity *wsec = NULL;
151
parent = wireless_security_init (sizeof (WirelessSecurityLEAP),
157
"/org/freedesktop/network-manager-applet/ws-leap.ui",
159
"leap_username_entry");
164
wsec = nm_connection_get_setting_wireless_security (connection);
166
const char *auth_alg;
168
/* Ignore if wireless security doesn't specify LEAP */
169
auth_alg = nm_setting_wireless_security_get_auth_alg (wsec);
170
if (!auth_alg || strcmp (auth_alg, "leap"))
175
parent->adhoc_compatible = FALSE;
176
parent->hotspot_compatible = FALSE;
177
sec = (WirelessSecurityLEAP *) parent;
178
sec->editing_connection = secrets_only ? FALSE : TRUE;
179
sec->password_flags_name = NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD;
181
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_password_entry"));
183
g_signal_connect (G_OBJECT (widget), "changed",
184
(GCallback) wireless_security_changed_cb,
187
/* Create password-storage popup menu for password entry under entry's secondary icon */
188
nma_utils_setup_password_storage (widget, 0, (NMSetting *) wsec, sec->password_flags_name,
189
FALSE, secrets_only);
192
update_secrets (WIRELESS_SECURITY (sec), connection);
194
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_username_entry"));
196
g_signal_connect (G_OBJECT (widget), "changed",
197
(GCallback) wireless_security_changed_cb,
200
gtk_entry_set_text (GTK_ENTRY (widget), nm_setting_wireless_security_get_leap_username (wsec));
203
gtk_widget_hide (widget);
205
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "show_checkbutton_leap"));
207
g_signal_connect (G_OBJECT (widget), "toggled",
208
(GCallback) show_toggled_cb,