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

« back to all changes in this revision

Viewing changes to src/connection-editor/page-wifi-security.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-11-19 14:46:29 UTC
  • mfrom: (1.2.31)
  • Revision ID: package-import@ubuntu.com-20121119144629-5423hii02a4vrh2n
Tags: 0.9.6.2+git201211052130.2d666bc-0ubuntu1
* upstream snapshot 2012-11-05 21:30:03 (GMT)
  + 2d666bc7aa6f0b731d131319b36f07b0f2bdce16
* debian/patches/git_fix_some_leaks_80ef61b.patch,
  debian/patches/git_indicate_hspa+_lte_tech_dbe3b12.patch,
  debian/patches/git_mac_addr_string_leakage_6dae878.patch: dropped, included
  in upstream tarball.
* debian/patches/lp328572-dxteam-connect-text.patch: refreshed.
* debian/patches/lp330571_dxteam_wired_connect_text.patch: refreshed.
* debian/patches/lp337960_dxteam_notification_icon_names.diff,
  debian/patches/lp337960_dxteam_notification_icon_names_part2-images.diff:
  disabled patches, they don't seem to be used (the icons don't match up with
  what is currently observable on the desktop). Let's see if someone screams.
* debian/patches/applet-wifi-menu-before-vpn.patch: refreshed.
* debian/patches/lp830178_adhoc_ip6_ignore.patch: refreshed.
* debian/patches/lp829673_gconf_hide_applet.patch: refreshed.
* debian/patches/nm-applet-use-indicator.patch: refreshed.
* debian/patches/hide_policy_items_env_var.patch: refreshed.
* debian/patches/applet_adhoc_use_wpa_rsn_part1.patch: refreshed.
* debian/patches/lp341684_device_sensitive_disconnect_notify.patch:
  refreshed.
* debian/patches/lp460144_correctly_update_notification.patch: refreshed.
* debian/patches/make_menu_items_insensitive_based_on_permissions.patch:
  refreshed.
* debian/control:
  - add gobject-introspection to Build-Depends.
  - add gudev-dev to Build-Depends.
  - bump network-manager and libnm-* Build-Depends and Depends to require
    at least 0.9.6.0+git201211131441.e9e2c56-0ubuntu1.
* debian/rules:
  - use autogen.sh with dh_autoreconf instead of calling intltoolize and
    gtkdocize manually.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 
2
/* NetworkManager Connection editor -- Connection editor for NetworkManager
 
3
 *
 
4
 * Dan Williams <dcbw@redhat.com>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 * (C) Copyright 2008 - 2011 Red Hat, Inc.
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
 
 
25
#include <string.h>
 
26
 
 
27
#include <gtk/gtk.h>
 
28
#include <glib/gi18n.h>
 
29
 
 
30
#include <NetworkManager.h>
 
31
#include <nm-setting-connection.h>
 
32
#include <nm-setting-wireless.h>
 
33
#include <nm-setting-wireless-security.h>
 
34
#include <nm-setting-8021x.h>
 
35
#include <nm-utils.h>
 
36
 
 
37
#include "wireless-security.h"
 
38
#include "page-wifi.h"
 
39
#include "page-wifi-security.h"
 
40
#include "nm-connection-editor.h"
 
41
 
 
42
 
 
43
G_DEFINE_TYPE (CEPageWifiSecurity, ce_page_wifi_security, CE_TYPE_PAGE)
 
44
 
 
45
 
 
46
#define S_NAME_COLUMN   0
 
47
#define S_SEC_COLUMN    1
 
48
#define S_ADHOC_VALID_COLUMN  2
 
49
 
 
50
static gboolean
 
51
find_proto (NMSettingWirelessSecurity *sec, const char *item)
 
52
{
 
53
        guint32 i;
 
54
 
 
55
        for (i = 0; i < nm_setting_wireless_security_get_num_protos (sec); i++) {
 
56
                if (!strcmp (item, nm_setting_wireless_security_get_proto (sec, i)))
 
57
                        return TRUE;
 
58
        }
 
59
        return FALSE;
 
60
}
 
61
 
 
62
static NMUtilsSecurityType
 
63
get_default_type_for_security (NMSettingWirelessSecurity *sec)
 
64
{
 
65
        const char *key_mgmt, *auth_alg;
 
66
 
 
67
        g_return_val_if_fail (sec != NULL, NMU_SEC_NONE);
 
68
 
 
69
        key_mgmt = nm_setting_wireless_security_get_key_mgmt (sec);
 
70
        auth_alg = nm_setting_wireless_security_get_auth_alg (sec);
 
71
 
 
72
        /* No IEEE 802.1x */
 
73
        if (!strcmp (key_mgmt, "none"))
 
74
                return NMU_SEC_STATIC_WEP;
 
75
 
 
76
        if (!strcmp (key_mgmt, "ieee8021x")) {
 
77
                if (auth_alg && !strcmp (auth_alg, "leap"))
 
78
                        return NMU_SEC_LEAP;
 
79
                return NMU_SEC_DYNAMIC_WEP;
 
80
        }
 
81
 
 
82
        if (!strcmp (key_mgmt, "wpa-psk")) {
 
83
                if (find_proto (sec, "rsn"))
 
84
                        return NMU_SEC_WPA2_PSK;
 
85
                else if (find_proto (sec, "wpa"))
 
86
                        return NMU_SEC_WPA_PSK;
 
87
                else
 
88
                        return NMU_SEC_WPA_PSK;
 
89
        }
 
90
 
 
91
        if (!strcmp (key_mgmt, "wpa-eap")) {
 
92
                if (find_proto (sec, "rsn"))
 
93
                        return NMU_SEC_WPA2_ENTERPRISE;
 
94
                else if (find_proto (sec, "wpa"))
 
95
                        return NMU_SEC_WPA_ENTERPRISE;
 
96
                else
 
97
                        return NMU_SEC_WPA_ENTERPRISE;
 
98
        }
 
99
 
 
100
        return NMU_SEC_INVALID;
 
101
}
 
102
 
 
103
static void
 
104
stuff_changed_cb (WirelessSecurity *sec, gpointer user_data)
 
105
{
 
106
        ce_page_changed (CE_PAGE (user_data));
 
107
}
 
108
 
 
109
static void
 
110
wsec_size_group_clear (GtkSizeGroup *group)
 
111
{
 
112
        GSList *children;
 
113
        GSList *iter;
 
114
 
 
115
        g_return_if_fail (group != NULL);
 
116
 
 
117
        children = gtk_size_group_get_widgets (group);
 
118
        for (iter = children; iter; iter = g_slist_next (iter))
 
119
                gtk_size_group_remove_widget (group, GTK_WIDGET (iter->data));
 
120
}
 
121
 
 
122
static WirelessSecurity *
 
123
wireless_security_combo_get_active (CEPageWifiSecurity *self)
 
124
{
 
125
        GtkTreeIter iter;
 
126
        GtkTreeModel *model;
 
127
        WirelessSecurity *sec = NULL;
 
128
 
 
129
        model = gtk_combo_box_get_model (self->security_combo);
 
130
        gtk_combo_box_get_active_iter (self->security_combo, &iter);
 
131
        gtk_tree_model_get (model, &iter, S_SEC_COLUMN, &sec, -1);
 
132
 
 
133
        return sec;
 
134
}
 
135
 
 
136
static void
 
137
wireless_security_combo_changed (GtkComboBox *combo,
 
138
                                 gpointer user_data)
 
139
{
 
140
        CEPageWifiSecurity *self = CE_PAGE_WIFI_SECURITY (user_data);
 
141
        GtkWidget *vbox;
 
142
        GList *elt, *children;
 
143
        WirelessSecurity *sec;
 
144
 
 
145
        vbox = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (self)->builder, "wifi_security_vbox"));
 
146
        g_assert (vbox);
 
147
 
 
148
        wsec_size_group_clear (self->group);
 
149
 
 
150
        /* Remove any previous wifi security widgets */
 
151
        children = gtk_container_get_children (GTK_CONTAINER (vbox));
 
152
        for (elt = children; elt; elt = g_list_next (elt))
 
153
                gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data));
 
154
 
 
155
        sec = wireless_security_combo_get_active (self);
 
156
        if (sec) {
 
157
                GtkWidget *sec_widget;
 
158
                GtkWidget *widget, *parent;
 
159
 
 
160
                sec_widget = wireless_security_get_widget (sec);
 
161
                g_assert (sec_widget);
 
162
                parent = gtk_widget_get_parent (sec_widget);
 
163
                if (parent)
 
164
                        gtk_container_remove (GTK_CONTAINER (parent), sec_widget);
 
165
 
 
166
                widget = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (self)->builder, "wifi_security_combo_label"));
 
167
                gtk_size_group_add_widget (self->group, widget);
 
168
                wireless_security_add_to_size_group (sec, self->group);
 
169
 
 
170
                gtk_container_add (GTK_CONTAINER (vbox), sec_widget);
 
171
                wireless_security_unref (sec);
 
172
        }
 
173
 
 
174
        ce_page_changed (CE_PAGE (self));
 
175
}
 
176
 
 
177
static void
 
178
add_security_item (CEPageWifiSecurity *self,
 
179
                   WirelessSecurity *sec,
 
180
                   GtkListStore *model,
 
181
                   GtkTreeIter *iter,
 
182
                   const char *text,
 
183
                   gboolean adhoc_valid)
 
184
{
 
185
        wireless_security_set_changed_notify (sec, stuff_changed_cb, self);
 
186
        gtk_list_store_append (model, iter);
 
187
        gtk_list_store_set (model, iter,
 
188
                            S_NAME_COLUMN, text,
 
189
                            S_SEC_COLUMN, sec,
 
190
                            S_ADHOC_VALID_COLUMN, adhoc_valid,
 
191
                            -1);
 
192
        wireless_security_unref (sec);
 
193
}
 
194
 
 
195
static void
 
196
set_sensitive (GtkCellLayout *cell_layout,
 
197
               GtkCellRenderer *cell,
 
198
               GtkTreeModel *tree_model,
 
199
               GtkTreeIter *iter,
 
200
               gpointer data)
 
201
{
 
202
        gboolean *adhoc = data;
 
203
        gboolean sensitive = TRUE, adhoc_valid = TRUE;
 
204
 
 
205
        gtk_tree_model_get (tree_model, iter, S_ADHOC_VALID_COLUMN, &adhoc_valid, -1);
 
206
        if (*adhoc && !adhoc_valid)
 
207
                sensitive = FALSE;
 
208
 
 
209
        g_object_set (cell, "sensitive", sensitive, NULL);
 
210
}
 
211
 
 
212
static void
 
213
finish_setup (CEPageWifiSecurity *self, gpointer unused, GError *error, gpointer user_data)
 
214
{
 
215
        CEPage *parent = CE_PAGE (self);
 
216
        NMSettingWireless *s_wireless;
 
217
        NMSettingWirelessSecurity *s_wireless_sec;
 
218
        NMConnection *connection = parent->connection;
 
219
        gboolean is_adhoc = FALSE;
 
220
        GtkListStore *sec_model;
 
221
        GtkTreeIter iter;
 
222
        const char *mode;
 
223
        const char *security;
 
224
        guint32 dev_caps = 0;
 
225
        NMUtilsSecurityType default_type = NMU_SEC_NONE;
 
226
        int active = -1;
 
227
        int item = 0;
 
228
        GtkComboBox *combo;
 
229
        GtkCellRenderer *renderer;
 
230
 
 
231
        if (error)
 
232
                return;
 
233
 
 
234
        s_wireless = nm_connection_get_setting_wireless (connection);
 
235
        g_assert (s_wireless);
 
236
 
 
237
        combo = GTK_COMBO_BOX (GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_security_combo")));
 
238
 
 
239
        dev_caps =   NM_WIFI_DEVICE_CAP_CIPHER_WEP40
 
240
                   | NM_WIFI_DEVICE_CAP_CIPHER_WEP104
 
241
                   | NM_WIFI_DEVICE_CAP_CIPHER_TKIP
 
242
                   | NM_WIFI_DEVICE_CAP_CIPHER_CCMP
 
243
                   | NM_WIFI_DEVICE_CAP_WPA
 
244
                   | NM_WIFI_DEVICE_CAP_RSN;
 
245
 
 
246
        mode = nm_setting_wireless_get_mode (s_wireless);
 
247
        if (mode && !strcmp (mode, "adhoc"))
 
248
                is_adhoc = TRUE;
 
249
        self->adhoc = is_adhoc;
 
250
 
 
251
        s_wireless_sec = nm_connection_get_setting_wireless_security (connection);
 
252
 
 
253
        security = nm_setting_wireless_get_security (s_wireless);
 
254
        if (!security || strcmp (security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
 
255
                s_wireless_sec = NULL;
 
256
        if (s_wireless_sec)
 
257
                default_type = get_default_type_for_security (s_wireless_sec);
 
258
 
 
259
        sec_model = gtk_list_store_new (3, G_TYPE_STRING, wireless_security_get_g_type (), G_TYPE_BOOLEAN);
 
260
 
 
261
        if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
 
262
                gtk_list_store_append (sec_model, &iter);
 
263
                gtk_list_store_set (sec_model, &iter,
 
264
                                    S_NAME_COLUMN, C_("Wi-Fi/Ethernet security", "None"),
 
265
                                    S_ADHOC_VALID_COLUMN, TRUE,
 
266
                                    -1);
 
267
                if (default_type == NMU_SEC_NONE)
 
268
                        active = item;
 
269
                item++;
 
270
        }
 
271
 
 
272
        if (nm_utils_security_valid (NMU_SEC_STATIC_WEP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
 
273
                WirelessSecurityWEPKey *ws_wep;
 
274
                NMWepKeyType wep_type = NM_WEP_KEY_TYPE_KEY;
 
275
 
 
276
                if (default_type == NMU_SEC_STATIC_WEP) {
 
277
                        NMSettingWirelessSecurity *s_wsec;
 
278
 
 
279
                        s_wsec = nm_connection_get_setting_wireless_security (connection);
 
280
                        if (s_wsec)
 
281
                                wep_type = nm_setting_wireless_security_get_wep_key_type (s_wsec);
 
282
                        if (wep_type == NM_WEP_KEY_TYPE_UNKNOWN)
 
283
                                wep_type = NM_WEP_KEY_TYPE_KEY;
 
284
                }
 
285
 
 
286
                ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_KEY, FALSE, FALSE);
 
287
                if (ws_wep) {
 
288
                        add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
 
289
                                           &iter, _("WEP 40/128-bit Key (Hex or ASCII)"),
 
290
                                           TRUE);
 
291
                        if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_KEY))
 
292
                                active = item;
 
293
                        item++;
 
294
                }
 
295
 
 
296
                ws_wep = ws_wep_key_new (connection, NM_WEP_KEY_TYPE_PASSPHRASE, FALSE, FALSE);
 
297
                if (ws_wep) {
 
298
                        add_security_item (self, WIRELESS_SECURITY (ws_wep), sec_model,
 
299
                                           &iter, _("WEP 128-bit Passphrase"), TRUE);
 
300
                        if ((active < 0) && (default_type == NMU_SEC_STATIC_WEP) && (wep_type == NM_WEP_KEY_TYPE_PASSPHRASE))
 
301
                                active = item;
 
302
                        item++;
 
303
                }
 
304
        }
 
305
 
 
306
        if (nm_utils_security_valid (NMU_SEC_LEAP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
 
307
                WirelessSecurityLEAP *ws_leap;
 
308
 
 
309
                ws_leap = ws_leap_new (connection, FALSE);
 
310
                if (ws_leap) {
 
311
                        add_security_item (self, WIRELESS_SECURITY (ws_leap), sec_model,
 
312
                                           &iter, _("LEAP"), FALSE);
 
313
                        if ((active < 0) && (default_type == NMU_SEC_LEAP))
 
314
                                active = item;
 
315
                        item++;
 
316
                }
 
317
        }
 
318
 
 
319
        if (nm_utils_security_valid (NMU_SEC_DYNAMIC_WEP, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
 
320
                WirelessSecurityDynamicWEP *ws_dynamic_wep;
 
321
 
 
322
                ws_dynamic_wep = ws_dynamic_wep_new (connection, TRUE, FALSE);
 
323
                if (ws_dynamic_wep) {
 
324
                        add_security_item (self, WIRELESS_SECURITY (ws_dynamic_wep), sec_model,
 
325
                                           &iter, _("Dynamic WEP (802.1x)"), FALSE);
 
326
                        if ((active < 0) && (default_type == NMU_SEC_DYNAMIC_WEP))
 
327
                                active = item;
 
328
                        item++;
 
329
                }
 
330
        }
 
331
 
 
332
        if (   nm_utils_security_valid (NMU_SEC_WPA_PSK, dev_caps, FALSE, is_adhoc, 0, 0, 0)
 
333
            || nm_utils_security_valid (NMU_SEC_WPA2_PSK, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
 
334
                WirelessSecurityWPAPSK *ws_wpa_psk;
 
335
 
 
336
                ws_wpa_psk = ws_wpa_psk_new (connection, FALSE);
 
337
                if (ws_wpa_psk) {
 
338
                        add_security_item (self, WIRELESS_SECURITY (ws_wpa_psk), sec_model,
 
339
                                           &iter, _("WPA & WPA2 Personal"), TRUE);
 
340
                        if ((active < 0) && ((default_type == NMU_SEC_WPA_PSK) || (default_type == NMU_SEC_WPA2_PSK)))
 
341
                                active = item;
 
342
                        item++;
 
343
                }
 
344
        }
 
345
 
 
346
        if (   nm_utils_security_valid (NMU_SEC_WPA_ENTERPRISE, dev_caps, FALSE, is_adhoc, 0, 0, 0)
 
347
            || nm_utils_security_valid (NMU_SEC_WPA2_ENTERPRISE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) {
 
348
                WirelessSecurityWPAEAP *ws_wpa_eap;
 
349
 
 
350
                ws_wpa_eap = ws_wpa_eap_new (connection, TRUE, FALSE);
 
351
                if (ws_wpa_eap) {
 
352
                        add_security_item (self, WIRELESS_SECURITY (ws_wpa_eap), sec_model,
 
353
                                           &iter, _("WPA & WPA2 Enterprise"), FALSE);
 
354
                        if ((active < 0) && ((default_type == NMU_SEC_WPA_ENTERPRISE) || (default_type == NMU_SEC_WPA2_ENTERPRISE)))
 
355
                                active = item;
 
356
                        item++;
 
357
                }
 
358
        }
 
359
 
 
360
        gtk_combo_box_set_model (combo, GTK_TREE_MODEL (sec_model));
 
361
        gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo));
 
362
 
 
363
        renderer = gtk_cell_renderer_text_new ();
 
364
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
 
365
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer, "text", S_NAME_COLUMN, NULL);
 
366
        gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo), renderer, set_sensitive, &self->adhoc, NULL);
 
367
 
 
368
        gtk_combo_box_set_active (combo, active < 0 ? 0 : (guint32) active);
 
369
        g_object_unref (G_OBJECT (sec_model));
 
370
 
 
371
        self->security_combo = combo;
 
372
 
 
373
        wireless_security_combo_changed (combo, self);
 
374
        g_signal_connect (combo, "changed",
 
375
                          G_CALLBACK (wireless_security_combo_changed),
 
376
                          self);
 
377
}
 
378
 
 
379
CEPage *
 
380
ce_page_wifi_security_new (NMConnection *connection,
 
381
                           GtkWindow *parent_window,
 
382
                           NMClient *client,
 
383
                           NMRemoteSettings *settings,
 
384
                           const char **out_secrets_setting_name,
 
385
                           GError **error)
 
386
{
 
387
        CEPageWifiSecurity *self;
 
388
        NMSettingWireless *s_wireless;
 
389
        NMSettingWirelessSecurity *s_wsec = NULL;
 
390
        NMUtilsSecurityType default_type = NMU_SEC_NONE;
 
391
        const char *security;
 
392
 
 
393
        s_wireless = nm_connection_get_setting_wireless (connection);
 
394
        if (!s_wireless) {
 
395
                g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load Wi-Fi security user interface; missing Wi-Fi setting."));
 
396
                return NULL;
 
397
        }
 
398
 
 
399
        self = CE_PAGE_WIFI_SECURITY (ce_page_new (CE_TYPE_PAGE_WIFI_SECURITY,
 
400
                                                   connection,
 
401
                                                   parent_window,
 
402
                                                   client,
 
403
                                                   settings,
 
404
                                                   UIDIR "/ce-page-wifi-security.ui",
 
405
                                                   "WifiSecurityPage",
 
406
                                                   _("Wi-Fi Security")));
 
407
        if (!self) {
 
408
                g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load Wi-Fi security user interface."));
 
409
                return NULL;
 
410
        }
 
411
 
 
412
        self->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
413
 
 
414
        s_wsec = nm_connection_get_setting_wireless_security (connection);
 
415
 
 
416
        security = nm_setting_wireless_get_security (s_wireless);
 
417
        if (!security || strcmp (security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
 
418
                s_wsec = NULL;
 
419
        if (s_wsec)
 
420
                default_type = get_default_type_for_security (s_wsec);
 
421
 
 
422
        /* Get secrets if the connection is not 802.1x enabled */
 
423
        if (   default_type == NMU_SEC_STATIC_WEP
 
424
            || default_type == NMU_SEC_LEAP
 
425
            || default_type == NMU_SEC_WPA_PSK
 
426
            || default_type == NMU_SEC_WPA2_PSK) {
 
427
                *out_secrets_setting_name = NM_SETTING_WIRELESS_SECURITY_SETTING_NAME;
 
428
        }
 
429
 
 
430
        /* Or if it is 802.1x enabled */
 
431
        if (   default_type == NMU_SEC_DYNAMIC_WEP
 
432
            || default_type == NMU_SEC_WPA_ENTERPRISE
 
433
            || default_type == NMU_SEC_WPA2_ENTERPRISE) {
 
434
                *out_secrets_setting_name = NM_SETTING_802_1X_SETTING_NAME;
 
435
        }
 
436
 
 
437
        g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);
 
438
 
 
439
        return CE_PAGE (self);
 
440
}
 
441
 
 
442
static void
 
443
ce_page_wifi_security_init (CEPageWifiSecurity *self)
 
444
{
 
445
        self->disposed = FALSE;
 
446
}
 
447
 
 
448
static void
 
449
dispose (GObject *object)
 
450
{
 
451
        CEPageWifiSecurity *self = CE_PAGE_WIFI_SECURITY (object);
 
452
 
 
453
        if (self->disposed)
 
454
                return;
 
455
 
 
456
        self->disposed = TRUE;
 
457
 
 
458
        if (self->group)
 
459
                g_object_unref (self->group);
 
460
 
 
461
        G_OBJECT_CLASS (ce_page_wifi_security_parent_class)->dispose (object);
 
462
}
 
463
 
 
464
static gboolean
 
465
validate (CEPage *page, NMConnection *connection, GError **error)
 
466
{
 
467
        CEPageWifiSecurity *self = CE_PAGE_WIFI_SECURITY (page);
 
468
        NMSettingWireless *s_wireless;
 
469
        WirelessSecurity *sec;
 
470
        gboolean valid = FALSE;
 
471
        const char *mode;
 
472
 
 
473
        s_wireless = nm_connection_get_setting_wireless (connection);
 
474
        g_assert (s_wireless);
 
475
 
 
476
        mode = nm_setting_wireless_get_mode (s_wireless);
 
477
        if (g_strcmp0 (mode, NM_SETTING_WIRELESS_MODE_ADHOC) == 0)
 
478
                self->adhoc = TRUE;
 
479
        else
 
480
                self->adhoc = FALSE;
 
481
 
 
482
        sec = wireless_security_combo_get_active (self);
 
483
        if (sec) {
 
484
                const GByteArray *ssid = nm_setting_wireless_get_ssid (s_wireless);
 
485
 
 
486
                if (ssid) {
 
487
                        /* FIXME: get failed property and error out of wifi security objects */
 
488
                        valid = wireless_security_validate (sec, ssid);
 
489
                        if (valid)
 
490
                                wireless_security_fill_connection (sec, connection);
 
491
                        else
 
492
                                g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Invalid Wi-Fi security");
 
493
                } else {
 
494
                        g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Missing SSID");
 
495
                        valid = FALSE;
 
496
                }
 
497
 
 
498
                if (self->adhoc) {
 
499
                        if (!wireless_security_adhoc_compatible (sec)) {
 
500
                                g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Security not compatible with Ad-Hoc mode");
 
501
                                valid = FALSE;
 
502
                        }
 
503
                }
 
504
 
 
505
                wireless_security_unref (sec);
 
506
        } else {
 
507
                /* No security, unencrypted */
 
508
                g_object_set (s_wireless, NM_SETTING_WIRELESS_SEC, NULL, NULL);
 
509
                nm_connection_remove_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
 
510
                nm_connection_remove_setting (connection, NM_TYPE_SETTING_802_1X);
 
511
                valid = TRUE;
 
512
        }
 
513
 
 
514
        return valid;
 
515
}
 
516
 
 
517
static GtkWidget *
 
518
nag_user (CEPage *page)
 
519
{
 
520
        WirelessSecurity *sec;
 
521
        GtkWidget *nag = NULL;
 
522
 
 
523
        sec = wireless_security_combo_get_active (CE_PAGE_WIFI_SECURITY (page));
 
524
        if (sec) {
 
525
                nag = wireless_security_nag_user (sec);
 
526
                wireless_security_unref (sec);
 
527
        }
 
528
        return nag;
 
529
}
 
530
 
 
531
static void
 
532
ce_page_wifi_security_class_init (CEPageWifiSecurityClass *wireless_security_class)
 
533
{
 
534
        GObjectClass *object_class = G_OBJECT_CLASS (wireless_security_class);
 
535
        CEPageClass *parent_class = CE_PAGE_CLASS (wireless_security_class);
 
536
 
 
537
        /* virtual methods */
 
538
        object_class->dispose = dispose;
 
539
 
 
540
        parent_class->validate = validate;
 
541
        parent_class->nag_user = nag_user;
 
542
}