~khurshid-alam/unity-control-center/use-usd-schemas

« back to all changes in this revision

Viewing changes to panels/network/connection-editor/ce-page-8021x-security.c

  • Committer: Sebastien Bacher
  • Author(s): Khurshid Alam
  • Date: 2019-05-17 07:34:33 UTC
  • mfrom: (12920.1.1 unity-control-center)
  • Revision ID: seb128@ubuntu.com-20190517073433-ch2kybdhhzpkmvq4
Network: Port to libnm 1.2 (lp: #1744619)

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 - 2012 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
 
 
32
#include "wireless-security.h"
 
33
#include "ce-page-ethernet.h"
 
34
#include "ce-page-8021x-security.h"
 
35
 
 
36
G_DEFINE_TYPE (CEPage8021xSecurity, ce_page_8021x_security, CE_TYPE_PAGE)
 
37
 
 
38
static void
 
39
enable_toggled (GObject *sw, GParamSpec *pspec, gpointer user_data)
 
40
{
 
41
        CEPage8021xSecurity *page = CE_PAGE_8021X_SECURITY (user_data);
 
42
 
 
43
        gtk_widget_set_sensitive (page->security_widget, gtk_switch_get_active (page->enabled));
 
44
        ce_page_changed (CE_PAGE (page));
 
45
}
 
46
 
 
47
static void
 
48
stuff_changed (WirelessSecurity *sec, gpointer user_data)
 
49
{
 
50
        ce_page_changed (CE_PAGE (user_data));
 
51
}
 
52
 
 
53
static void
 
54
finish_setup (CEPage8021xSecurity *page, gpointer unused, GError *error, gpointer user_data)
 
55
{
 
56
        GtkWidget *parent;
 
57
        GtkWidget *vbox;
 
58
        GtkWidget *heading;
 
59
 
 
60
        if (error)
 
61
                return;
 
62
 
 
63
        vbox = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "vbox"));
 
64
        heading = GTK_WIDGET (gtk_builder_get_object (CE_PAGE (page)->builder, "heading_sec"));
 
65
 
 
66
        page->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
67
 
 
68
        page->security = (WirelessSecurity *) ws_wpa_eap_new (CE_PAGE (page)->connection, TRUE, FALSE);
 
69
        if (!page->security) {
 
70
                g_warning ("Could not load 802.1x user interface.");
 
71
                return;
 
72
        }
 
73
 
 
74
        wireless_security_set_changed_notify (page->security, stuff_changed, page);
 
75
        page->security_widget = wireless_security_get_widget (page->security);
 
76
        parent = gtk_widget_get_parent (page->security_widget);
 
77
        if (parent)
 
78
                gtk_container_remove (GTK_CONTAINER (parent), page->security_widget);
 
79
 
 
80
        gtk_switch_set_active (page->enabled, page->initial_have_8021x);
 
81
        g_signal_connect (page->enabled, "notify::active", G_CALLBACK (enable_toggled), page);
 
82
        gtk_widget_set_sensitive (page->security_widget, page->initial_have_8021x);
 
83
 
 
84
        gtk_size_group_add_widget (page->group, heading);
 
85
        wireless_security_add_to_size_group (page->security, page->group);
 
86
 
 
87
        gtk_container_add (GTK_CONTAINER (vbox), page->security_widget);
 
88
 
 
89
}
 
90
 
 
91
CEPage *
 
92
ce_page_8021x_security_new (NMConnection     *connection,
 
93
                            NMClient         *client)
 
94
{
 
95
        CEPage8021xSecurity *page;
 
96
 
 
97
        page = CE_PAGE_8021X_SECURITY (ce_page_new (CE_TYPE_PAGE_8021X_SECURITY,
 
98
                                                    connection,
 
99
                                                    client,
 
100
                                                    "/org/gnome/control-center/network/8021x-security-page.ui",
 
101
                                                    _("Security")));
 
102
 
 
103
        if (nm_connection_get_setting_802_1x (connection))
 
104
                page->initial_have_8021x = TRUE;
 
105
 
 
106
        page->enabled = GTK_SWITCH (gtk_builder_get_object (CE_PAGE (page)->builder, "8021x_switch"));
 
107
 
 
108
        g_signal_connect (page, "initialized", G_CALLBACK (finish_setup), NULL);
 
109
 
 
110
        if (page->initial_have_8021x)
 
111
                CE_PAGE (page)->security_setting = NM_SETTING_802_1X_SETTING_NAME;
 
112
 
 
113
        return CE_PAGE (page);
 
114
}
 
115
 
 
116
static gboolean
 
117
validate (CEPage *cepage, NMConnection *connection, GError **error)
 
118
{
 
119
        CEPage8021xSecurity *page = CE_PAGE_8021X_SECURITY (cepage);
 
120
        gboolean valid = TRUE;
 
121
 
 
122
        if (gtk_switch_get_active (page->enabled)) {
 
123
                NMConnection *tmp_connection;
 
124
                NMSetting *s_8021x;
 
125
 
 
126
                /* FIXME: get failed property and error out of wireless security objects */
 
127
                valid = wireless_security_validate (page->security, error);
 
128
                if (valid) {
 
129
                        NMSetting *s_con;
 
130
 
 
131
                        /* Here's a nice hack to work around the fact that ws_802_1x_fill_connection needs wireless setting. */
 
132
                        tmp_connection = nm_simple_connection_new ();
 
133
                        nm_connection_add_setting (tmp_connection, nm_setting_wireless_new ());
 
134
 
 
135
                        /* temp connection needs a 'connection' setting too, since most of
 
136
                         * the EAP methods need the UUID for CA cert ignore stuff.
 
137
                         */
 
138
                        s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
 
139
                        nm_connection_add_setting (tmp_connection, nm_setting_duplicate (s_con));
 
140
 
 
141
                        ws_802_1x_fill_connection (page->security, "wpa_eap_auth_combo", tmp_connection);
 
142
 
 
143
                        s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X);
 
144
                        nm_connection_add_setting (connection, NM_SETTING (g_object_ref (s_8021x)));
 
145
 
 
146
                        g_object_unref (tmp_connection);
 
147
                }
 
148
        } else {
 
149
                nm_connection_remove_setting (connection, NM_TYPE_SETTING_802_1X);
 
150
                valid = TRUE;
 
151
        }
 
152
 
 
153
        return valid;
 
154
}
 
155
 
 
156
static void
 
157
ce_page_8021x_security_init (CEPage8021xSecurity *page)
 
158
{
 
159
}
 
160
 
 
161
static void
 
162
dispose (GObject *object)
 
163
{
 
164
        CEPage8021xSecurity *page = CE_PAGE_8021X_SECURITY (object);
 
165
 
 
166
        if (page->security) {
 
167
                wireless_security_unref (page->security);
 
168
                page->security = NULL;
 
169
        }
 
170
 
 
171
        g_clear_object (&page->group);
 
172
 
 
173
        G_OBJECT_CLASS (ce_page_8021x_security_parent_class)->dispose (object);
 
174
}
 
175
 
 
176
static void
 
177
ce_page_8021x_security_class_init (CEPage8021xSecurityClass *security_class)
 
178
{
 
179
        GObjectClass *object_class = G_OBJECT_CLASS (security_class);
 
180
        CEPageClass *parent_class = CE_PAGE_CLASS (security_class);
 
181
 
 
182
        /* virtual methods */
 
183
        object_class->dispose = dispose;
 
184
 
 
185
        parent_class->validate = validate;
 
186
}