~ubuntu-branches/ubuntu/wily/network-manager-applet/wily-proposed

« back to all changes in this revision

Viewing changes to src/wireless-security/eap-method-leap.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2015-01-26 23:08:58 UTC
  • mfrom: (1.2.37)
  • Revision ID: package-import@ubuntu.com-20150126230858-fmlex10ew00r1u9p
Tags: 0.9.10.1-0ubuntu1
* New upstream release: 0.9.10.1.
* Resync packaging with Debian:
  - debian/rules: Set DEB_HOST_MULTIARCH, use dh_install exclusions rather
    than removing .la and .a files separately. 
  - debian/control: Build-depends: update NM b-deps, 
    bump to dh 9, update libgtk/libglib2.0 b-deps versions and make
    libnm-gtk Multi-Arch-aware.
  - debian/*.install: update paths for multi-arch.
  - debian/compat: bump to compat level 9.
* debian/patches dropped because they were applied upstream:
  - git_use_paths_in_vpn_name_files_4867951.patch,
  - git_revert_system_ca_cert.patch,
  - lp289466_always_show_tray_icon.patch,
  - key-certificate-extensions.patch,
  - lp829673_gconf_hide_applet.patch,
  - 0001_Move_on_with_enter_in_the_country_page_of_the_new_mobile_wizard.patch
* debian/patches/lp328572-dxteam-connect-text.patch,
  debian/patches/lp330571_dxteam_wired_connect_text.patch,
  debian/patches/lp330608_dxteam_gsm_connect_text.patch: stop carrying
  needless string changes causing delta with upstream; any changes to the
  strings should happen there so we stay in sync.
  dropped; included upstream.
* Refreshed remaining patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "eap-method.h"
28
28
#include "wireless-security.h"
29
29
#include "helpers.h"
 
30
#include "utils.h"
30
31
 
31
32
struct _EAPMethodLEAP {
32
33
        EAPMethod parent;
33
34
 
34
 
        gboolean new_connection;
 
35
        WirelessSecurity *ws_parent;
 
36
 
 
37
        gboolean editing_connection;
 
38
 
 
39
        GtkEntry *username_entry;
 
40
        GtkEntry *password_entry;
 
41
        GtkToggleButton *show_password;
35
42
};
36
43
 
37
44
static void
38
 
show_toggled_cb (GtkCheckButton *button, EAPMethod *method)
 
45
show_toggled_cb (GtkToggleButton *button, EAPMethodLEAP *method)
39
46
{
40
 
        GtkWidget *widget;
41
47
        gboolean visible;
42
48
 
43
 
        widget = GTK_WIDGET (gtk_builder_get_object (method->builder, "eap_leap_password_entry"));
44
 
        g_assert (widget);
45
 
 
46
 
        visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
47
 
        gtk_entry_set_visibility (GTK_ENTRY (widget), visible);
 
49
        visible = gtk_toggle_button_get_active (button);
 
50
        gtk_entry_set_visibility (method->password_entry, visible);
48
51
}
49
52
 
50
53
static gboolean
51
54
validate (EAPMethod *parent)
52
55
{
53
 
        GtkWidget *widget;
 
56
        EAPMethodLEAP *method = (EAPMethodLEAP *)parent;
54
57
        const char *text;
55
58
 
56
 
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_username_entry"));
57
 
        g_assert (widget);
58
 
        text = gtk_entry_get_text (GTK_ENTRY (widget));
 
59
        text = gtk_entry_get_text (method->username_entry);
59
60
        if (!text || !strlen (text))
60
61
                return FALSE;
61
62
 
62
 
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_password_entry"));
63
 
        g_assert (widget);
64
 
        text = gtk_entry_get_text (GTK_ENTRY (widget));
 
63
        text = gtk_entry_get_text (method->password_entry);
65
64
        if (!text || !strlen (text))
66
65
                return FALSE;
67
66
 
83
82
}
84
83
 
85
84
static void
86
 
fill_connection (EAPMethod *parent, NMConnection *connection)
 
85
fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags)
87
86
{
88
87
        EAPMethodLEAP *method = (EAPMethodLEAP *) parent;
89
88
        NMSetting8021x *s_8021x;
90
 
        GtkWidget *widget;
91
89
 
92
90
        s_8021x = nm_connection_get_setting_802_1x (connection);
93
91
        g_assert (s_8021x);
94
92
 
95
93
        nm_setting_802_1x_add_eap_method (s_8021x, "leap");
96
94
 
97
 
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_username_entry"));
98
 
        g_assert (widget);
99
 
        g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, gtk_entry_get_text (GTK_ENTRY (widget)), NULL);
100
 
 
101
 
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_password_entry"));
102
 
        g_assert (widget);
103
 
        g_object_set (s_8021x, NM_SETTING_802_1X_PASSWORD, gtk_entry_get_text (GTK_ENTRY (widget)), NULL);
104
 
 
105
 
        /* Default to agent-owned secrets for new connections */
106
 
        if (method->new_connection) {
107
 
                g_object_set (s_8021x,
108
 
                              NM_SETTING_802_1X_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_AGENT_OWNED,
109
 
                              NULL);
 
95
        g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, gtk_entry_get_text (method->username_entry), NULL);
 
96
        g_object_set (s_8021x, NM_SETTING_802_1X_PASSWORD, gtk_entry_get_text (method->password_entry), NULL);
 
97
 
 
98
        /* Update secret flags and popup when editing the connection */
 
99
        if (method->editing_connection) {
 
100
                GtkWidget *passwd_entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_password_entry"));
 
101
                g_assert (passwd_entry);
 
102
 
 
103
                utils_update_password_storage (NM_SETTING (s_8021x), flags, passwd_entry, parent->password_flags_name);
110
104
        }
111
105
}
112
106
 
120
114
                                  (HelperSecretFunc) nm_setting_802_1x_get_password);
121
115
}
122
116
 
 
117
/* Set the UI fields for user, password and show_password to the
 
118
 * values as provided by method->ws_parent. */
 
119
static void
 
120
set_userpass_ui (EAPMethodLEAP *method)
 
121
{
 
122
        if (method->ws_parent->username)
 
123
                gtk_entry_set_text (method->username_entry, method->ws_parent->username);
 
124
        else
 
125
                gtk_entry_set_text (method->username_entry, "");
 
126
 
 
127
        if (method->ws_parent->password && !method->ws_parent->always_ask)
 
128
                gtk_entry_set_text (method->password_entry, method->ws_parent->password);
 
129
        else
 
130
                gtk_entry_set_text (method->password_entry, "");
 
131
 
 
132
        gtk_toggle_button_set_active (method->show_password, method->ws_parent->show_password);
 
133
}
 
134
 
 
135
static void
 
136
widgets_realized (GtkWidget *widget, EAPMethodLEAP *method)
 
137
{
 
138
        set_userpass_ui (method);
 
139
}
 
140
 
 
141
static void
 
142
widgets_unrealized (GtkWidget *widget, EAPMethodLEAP *method)
 
143
{
 
144
        wireless_security_set_userpass (method->ws_parent,
 
145
                                        gtk_entry_get_text (method->username_entry),
 
146
                                        gtk_entry_get_text (method->password_entry),
 
147
                                        (gboolean) -1,
 
148
                                        gtk_toggle_button_get_active (method->show_password));
 
149
}
 
150
 
 
151
static void
 
152
destroy (EAPMethod *parent)
 
153
{
 
154
        EAPMethodLEAP *method = (EAPMethodLEAP *) parent;
 
155
        GtkWidget *widget;
 
156
 
 
157
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_notebook"));
 
158
        g_assert (widget);
 
159
 
 
160
        g_signal_handlers_disconnect_by_func (G_OBJECT (widget),
 
161
                                              (GCallback) widgets_realized,
 
162
                                              method);
 
163
        g_signal_handlers_disconnect_by_func (G_OBJECT (widget),
 
164
                                              (GCallback) widgets_unrealized,
 
165
                                              method);
 
166
 
 
167
        wireless_security_unref (method->ws_parent);
 
168
}
 
169
 
123
170
EAPMethodLEAP *
124
171
eap_method_leap_new (WirelessSecurity *ws_parent,
125
172
                     NMConnection *connection,
134
181
                                  add_to_size_group,
135
182
                                  fill_connection,
136
183
                                  update_secrets,
137
 
                                  NULL,
 
184
                                  destroy,
138
185
                                  UIDIR "/eap-method-leap.ui",
139
186
                                  "eap_leap_notebook",
140
187
                                  "eap_leap_username_entry",
142
189
        if (!parent)
143
190
                return NULL;
144
191
 
 
192
        parent->password_flags_name = NM_SETTING_802_1X_PASSWORD;
145
193
        method = (EAPMethodLEAP *) parent;
146
 
        method->new_connection = secrets_only ? FALSE : TRUE;
 
194
        method->editing_connection = secrets_only ? FALSE : TRUE;
 
195
        method->ws_parent = wireless_security_ref (ws_parent);
 
196
 
 
197
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_notebook"));
 
198
        g_assert (widget);
 
199
        g_signal_connect (G_OBJECT (widget), "realize",
 
200
                          (GCallback) widgets_realized,
 
201
                          method);
 
202
        g_signal_connect (G_OBJECT (widget), "unrealize",
 
203
                          (GCallback) widgets_unrealized,
 
204
                          method);
147
205
 
148
206
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_username_entry"));
149
207
        g_assert (widget);
 
208
        method->username_entry = GTK_ENTRY (widget);
150
209
        g_signal_connect (G_OBJECT (widget), "changed",
151
210
                          (GCallback) wireless_security_changed_cb,
152
211
                          ws_parent);
153
 
        if (connection) {
154
 
                NMSetting8021x *s_8021x;
155
 
 
156
 
                s_8021x = nm_connection_get_setting_802_1x (connection);
157
 
                if (s_8021x && nm_setting_802_1x_get_identity (s_8021x))
158
 
                        gtk_entry_set_text (GTK_ENTRY (widget), nm_setting_802_1x_get_identity (s_8021x));
159
 
        }
160
212
 
161
213
        if (secrets_only)
162
214
                gtk_widget_set_sensitive (widget, FALSE);
163
215
 
164
216
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_leap_password_entry"));
165
217
        g_assert (widget);
 
218
        method->password_entry = GTK_ENTRY (widget);
166
219
        g_signal_connect (G_OBJECT (widget), "changed",
167
220
                          (GCallback) wireless_security_changed_cb,
168
221
                          ws_parent);
169
222
 
170
 
        /* Fill secrets, if any */
171
 
        if (connection)
172
 
                update_secrets (parent, connection);
 
223
        /* Create password-storage popup menu for password entry under entry's secondary icon */
 
224
        utils_setup_password_storage (connection, NM_SETTING_802_1X_SETTING_NAME, widget, parent->password_flags_name);
173
225
 
174
226
        widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "show_checkbutton_eapleap"));
175
227
        g_assert (widget);
 
228
        method->show_password = GTK_TOGGLE_BUTTON (widget);
176
229
        g_signal_connect (G_OBJECT (widget), "toggled",
177
230
                          (GCallback) show_toggled_cb,
178
231
                          parent);
179
232
 
 
233
        /* Initialize the UI fields with the security settings from method->ws_parent.
 
234
         * This will be done again when the widget gets realized. It must be done here as well,
 
235
         * because the outer dialog will ask to 'validate' the connection before the security tab
 
236
         * is shown/realized (to enable the 'Apply' button).
 
237
         * As 'validate' accesses the contents of the UI fields, they must be initialized now, even
 
238
         * if the widgets are not yet visible. */
 
239
        set_userpass_ui (method);
 
240
 
180
241
        return method;
181
242
}
182
243