~ubuntu-branches/ubuntu/saucy/network-manager-applet/saucy-updates

« back to all changes in this revision

Viewing changes to .pc/applet_adhoc_use_wpa_rsn_part1.patch/src/connection-editor/page-wireless-security.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-09-07 16:06:37 UTC
  • Revision ID: package-import@ubuntu.com-20120907160637-tf6bw2ya7s6nxulm
Tags: 0.9.6.2-0ubuntu3
debian/patches/applet_adhoc_use_wpa_rsn_part1.patch: enable the use of
WPA2/RSN for adhoc again, instead of WPA-None; to provide a way to get a
"good" encryption method available for adhoc networks. (LP: #1046918)

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