~oem-solutions-group/network-manager/network-mananger-applet-hardy

« back to all changes in this revision

Viewing changes to src/wireless-security/ws-leap.c

  • Committer: Neil Jagdish Patel
  • Date: 2008-11-19 16:42:12 UTC
  • Revision ID: neil.patel@canonical.com-20081119164212-0v212d4hpst66ish
* Initial import
  - Source from https://edge.launchpad.net/%7Enetwork-manager/+archive/+files/network-manager-applet_0.7~~svn20081012t133407.orig.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
 
2
 *
 
3
 * Dan Williams <dcbw@redhat.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
18
 *
 
19
 * (C) Copyright 2007 Red Hat, Inc.
 
20
 */
 
21
 
 
22
#include <glade/glade.h>
 
23
#include <string.h>
 
24
#include <nm-setting-wireless.h>
 
25
 
 
26
#include "wireless-security.h"
 
27
#include "utils.h"
 
28
#include "gconf-helpers.h"
 
29
 
 
30
 
 
31
static void
 
32
show_toggled_cb (GtkCheckButton *button, WirelessSecurity *sec)
 
33
{
 
34
        GtkWidget *widget;
 
35
        gboolean visible;
 
36
 
 
37
        widget = glade_xml_get_widget (sec->xml, "leap_password_entry");
 
38
        g_assert (widget);
 
39
 
 
40
        visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
 
41
        gtk_entry_set_visibility (GTK_ENTRY (widget), visible);
 
42
}
 
43
 
 
44
static void
 
45
destroy (WirelessSecurity *parent)
 
46
{
 
47
        WirelessSecurityLEAP *sec = (WirelessSecurityLEAP *) parent;
 
48
 
 
49
        g_slice_free (WirelessSecurityLEAP, sec);
 
50
}
 
51
 
 
52
static gboolean
 
53
validate (WirelessSecurity *parent, const GByteArray *ssid)
 
54
{
 
55
        GtkWidget *entry;
 
56
        const char *text;
 
57
 
 
58
        entry = glade_xml_get_widget (parent->xml, "leap_username_entry");
 
59
        g_assert (entry);
 
60
        text = gtk_entry_get_text (GTK_ENTRY (entry));
 
61
        if (!text || !strlen (text))
 
62
                return FALSE;
 
63
 
 
64
        entry = glade_xml_get_widget (parent->xml, "leap_password_entry");
 
65
        g_assert (entry);
 
66
        text = gtk_entry_get_text (GTK_ENTRY (entry));
 
67
        if (!text || !strlen (text))
 
68
                return FALSE;
 
69
 
 
70
        return TRUE;
 
71
}
 
72
 
 
73
static void
 
74
add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group)
 
75
{
 
76
        GtkWidget *widget;
 
77
 
 
78
        widget = glade_xml_get_widget (parent->xml, "leap_username_label");
 
79
        gtk_size_group_add_widget (group, widget);
 
80
 
 
81
        widget = glade_xml_get_widget (parent->xml, "leap_password_label");
 
82
        gtk_size_group_add_widget (group, widget);
 
83
}
 
84
 
 
85
static void
 
86
fill_connection (WirelessSecurity *parent, NMConnection *connection)
 
87
{
 
88
        NMSettingWireless *s_wireless;
 
89
        NMSettingWirelessSecurity *s_wireless_sec;
 
90
        GtkWidget *widget;
 
91
 
 
92
        s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
 
93
        g_assert (s_wireless);
 
94
 
 
95
        if (s_wireless->security)
 
96
                g_free (s_wireless->security);
 
97
        s_wireless->security = g_strdup (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
 
98
 
 
99
        /* Blow away the old security setting by adding a clear one */
 
100
        s_wireless_sec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
 
101
        nm_connection_add_setting (connection, (NMSetting *) s_wireless_sec);
 
102
 
 
103
        s_wireless_sec->key_mgmt = g_strdup ("ieee8021x");
 
104
        s_wireless_sec->auth_alg = g_strdup ("leap");
 
105
 
 
106
        widget = glade_xml_get_widget (parent->xml, "leap_username_entry");
 
107
        s_wireless_sec->leap_username = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
 
108
 
 
109
        widget = glade_xml_get_widget (parent->xml, "leap_password_entry");
 
110
        s_wireless_sec->leap_password = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
 
111
}
 
112
 
 
113
WirelessSecurityLEAP *
 
114
ws_leap_new (const char *glade_file, NMConnection *connection)
 
115
{
 
116
        WirelessSecurityLEAP *sec;
 
117
        GtkWidget *widget;
 
118
        GladeXML *xml;
 
119
        NMSettingWirelessSecurity *wsec = NULL;
 
120
 
 
121
        g_return_val_if_fail (glade_file != NULL, NULL);
 
122
 
 
123
        xml = glade_xml_new (glade_file, "leap_notebook", NULL);
 
124
        if (xml == NULL) {
 
125
                g_warning ("Couldn't get leap_widget from glade xml");
 
126
                return NULL;
 
127
        }
 
128
 
 
129
        widget = glade_xml_get_widget (xml, "leap_notebook");
 
130
        g_assert (widget);
 
131
        g_object_ref_sink (widget);
 
132
 
 
133
        sec = g_slice_new0 (WirelessSecurityLEAP);
 
134
        if (!sec) {
 
135
                g_object_unref (xml);
 
136
                g_object_unref (widget);
 
137
                return NULL;
 
138
        }
 
139
 
 
140
        wireless_security_init (WIRELESS_SECURITY (sec),
 
141
                                validate,
 
142
                                add_to_size_group,
 
143
                                fill_connection,
 
144
                                destroy,
 
145
                                xml,
 
146
                                widget);
 
147
 
 
148
        if (connection) {
 
149
                wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY));
 
150
                if (wsec) {
 
151
                        /* Ignore if wireless security doesn't specify LEAP */
 
152
                        if (!wsec->auth_alg || strcmp (wsec->auth_alg, "leap"))
 
153
                                wsec = NULL;
 
154
                }
 
155
        }
 
156
 
 
157
        widget = glade_xml_get_widget (xml, "leap_password_entry");
 
158
        g_assert (widget);
 
159
        g_signal_connect (G_OBJECT (widget), "changed",
 
160
                          (GCallback) wireless_security_changed_cb,
 
161
                          sec);
 
162
        if (wsec) {
 
163
                GHashTable *secrets;
 
164
                GError *error = NULL;
 
165
                GValue *value;
 
166
 
 
167
                secrets = nm_gconf_get_keyring_items (connection,
 
168
                                                      NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
 
169
                                                      FALSE,
 
170
                                                      &error);
 
171
                if (secrets) {
 
172
                        value = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD);
 
173
                        if (value)
 
174
                                gtk_entry_set_text (GTK_ENTRY (widget), g_value_get_string (value));
 
175
                        g_hash_table_destroy (secrets);
 
176
                } else if (error)
 
177
                        g_error_free (error);
 
178
        }
 
179
 
 
180
        widget = glade_xml_get_widget (xml, "leap_username_entry");
 
181
        g_assert (widget);
 
182
        g_signal_connect (G_OBJECT (widget), "changed",
 
183
                          (GCallback) wireless_security_changed_cb,
 
184
                          sec);
 
185
        if (wsec)
 
186
                gtk_entry_set_text (GTK_ENTRY (widget), wsec->leap_username);
 
187
 
 
188
        widget = glade_xml_get_widget (xml, "show_checkbutton");
 
189
        g_assert (widget);
 
190
        g_signal_connect (G_OBJECT (widget), "toggled",
 
191
                          (GCallback) show_toggled_cb,
 
192
                          sec);
 
193
 
 
194
        return sec;
 
195
}
 
196