~vcs-imports/network-manager-applet/trunk

« back to all changes in this revision

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

  • Committer: dcbw
  • Date: 2009-04-03 13:28:12 UTC
  • Revision ID: vcs-imports@canonical.com-20090403132812-u8nztkdrskz0mxp1
2009-04-03  Dan Williams  <dcbw@redhat.com>

        * Ensure PolicyKit autorization before editing system connections, and
                request secrets from the system settings service for system connections.
                This requires splitting each CEPage subclass's *_new() method into
                two parts, the first doing minimal setup, and the second filling in
                the UI with details from the backing NMConnection.  Between the first
                and second parts, if required, secrets are requested from the system
                settings service using PolicyKit.  As a bonus, actually handle errors
                instead of dropping them on the floor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
        wireless_security_unref (sec);
184
184
}
185
185
 
186
 
CEPageWirelessSecurity *
187
 
ce_page_wireless_security_new (NMConnection *connection)
 
186
static void
 
187
finish_setup (CEPageWirelessSecurity *self, gpointer unused, GError *error, gpointer user_data)
188
188
{
189
 
        CEPageWirelessSecurity *self;
190
 
        CEPage *parent;
 
189
        CEPage *parent = CE_PAGE (self);
191
190
        NMSettingWireless *s_wireless;
192
191
        NMSettingWirelessSecurity *s_wireless_sec;
 
192
        NMConnection *connection = parent->connection;
193
193
        gboolean is_adhoc = FALSE;
194
194
        GtkListStore *sec_model;
195
195
        GtkTreeIter iter;
202
202
        const char *glade_file = GLADEDIR "/applet.glade";
203
203
        GtkComboBox *combo;
204
204
 
205
 
        self = CE_PAGE_WIRELESS_SECURITY (g_object_new (CE_TYPE_PAGE_WIRELESS_SECURITY, NULL));
206
 
        parent = CE_PAGE (self);
 
205
        if (error)
 
206
                return;
207
207
 
208
208
        s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
209
 
        if (!s_wireless) {
210
 
                g_warning ("%s: Connection didn't have a wireless setting!", __func__);
211
 
                g_object_unref (self);
212
 
                return NULL;
213
 
        }
214
 
 
215
 
        parent->xml = glade_xml_new (GLADEDIR "/ce-page-wireless-security.glade", "WirelessSecurityPage", NULL);
216
 
        if (!parent->xml) {
217
 
                g_warning ("%s: Couldn't load wireless security page glade file.", __func__);
218
 
                g_object_unref (self);
219
 
                return NULL;
220
 
        }
221
 
 
222
 
        parent->page = glade_xml_get_widget (parent->xml, "WirelessSecurityPage");
223
 
        if (!parent->page) {
224
 
                g_warning ("%s: Couldn't load wireless security page from glade file.", __func__);
225
 
                g_object_unref (self);
226
 
                return NULL;
227
 
        }
228
 
        g_object_ref_sink (parent->page);
229
 
 
230
 
        parent->title = g_strdup (_("Wireless Security"));
231
 
 
232
 
        self->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
209
        g_assert (s_wireless);
233
210
 
234
211
        combo = GTK_COMBO_BOX (glade_xml_get_widget (parent->xml, "wireless_security_combo"));
235
212
 
355
332
        g_signal_connect (combo, "changed",
356
333
                          G_CALLBACK (wireless_security_combo_changed),
357
334
                          self);
358
 
 
359
 
        return self;
 
335
}
 
336
 
 
337
CEPage *
 
338
ce_page_wireless_security_new (NMConnection *connection, GtkWindow *parent_window, GError **error)
 
339
{
 
340
        CEPageWirelessSecurity *self;
 
341
        CEPage *parent;
 
342
        NMSettingWireless *s_wireless;
 
343
        NMSettingWirelessSecurity *s_wsec = NULL;
 
344
        const char *setting_name = NULL;
 
345
        NMUtilsSecurityType default_type = NMU_SEC_NONE;
 
346
        const char *security;
 
347
 
 
348
        self = CE_PAGE_WIRELESS_SECURITY (g_object_new (CE_TYPE_PAGE_WIRELESS_SECURITY,
 
349
                                                        CE_PAGE_CONNECTION, connection,
 
350
                                                        CE_PAGE_PARENT_WINDOW, parent_window,
 
351
                                                        NULL));
 
352
        parent = CE_PAGE (self);
 
353
 
 
354
        s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
 
355
        if (!s_wireless) {
 
356
                g_set_error (error, 0, 0, "%s", _("Could not load WiFi security user interface; missing WiFi setting."));
 
357
                g_object_unref (self);
 
358
                return NULL;
 
359
        }
 
360
 
 
361
        parent->xml = glade_xml_new (GLADEDIR "/ce-page-wireless-security.glade", "WirelessSecurityPage", NULL);
 
362
        if (!parent->xml) {
 
363
                g_set_error (error, 0, 0, "%s", _("Could not load WiFi security user interface."));
 
364
                g_object_unref (self);
 
365
                return NULL;
 
366
        }
 
367
 
 
368
        parent->page = glade_xml_get_widget (parent->xml, "WirelessSecurityPage");
 
369
        if (!parent->page) {
 
370
                g_set_error (error, 0, 0, "%s", _("Could not load WiFi security user interface."));
 
371
                g_object_unref (self);
 
372
                return NULL;
 
373
        }
 
374
        g_object_ref_sink (parent->page);
 
375
 
 
376
        parent->title = g_strdup (_("Wireless Security"));
 
377
 
 
378
        self->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
379
 
 
380
        g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL);
 
381
 
 
382
        s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, 
 
383
                                               NM_TYPE_SETTING_WIRELESS_SECURITY));
 
384
 
 
385
        security = nm_setting_wireless_get_security (s_wireless);
 
386
        if (!security || strcmp (security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
 
387
                s_wsec = NULL;
 
388
        if (s_wsec)
 
389
                default_type = get_default_type_for_security (s_wsec);
 
390
 
 
391
        /* Get secrets if the connection is not 802.1x enabled */
 
392
        if (   default_type == NMU_SEC_STATIC_WEP
 
393
            || default_type == NMU_SEC_LEAP
 
394
            || default_type == NMU_SEC_WPA_PSK
 
395
            || default_type == NMU_SEC_WPA2_PSK) {
 
396
                setting_name = NM_SETTING_WIRELESS_SECURITY_SETTING_NAME;
 
397
        }
 
398
 
 
399
        /* Or if it is 802.1x enabled */
 
400
        if (   default_type == NMU_SEC_DYNAMIC_WEP
 
401
            || default_type == NMU_SEC_WPA_ENTERPRISE
 
402
            || default_type == NMU_SEC_WPA2_ENTERPRISE) {
 
403
                setting_name = NM_SETTING_802_1X_SETTING_NAME;
 
404
        }
 
405
 
 
406
        if (!ce_page_initialize (parent, setting_name, error)) {
 
407
                g_object_unref (self);
 
408
                return NULL;
 
409
        }
 
410
 
 
411
        return CE_PAGE (self);
360
412
}
361
413
 
362
414
static void