~dylanmccall/ubuntu/oneiric/network-manager-applet/lp852961-disable-autostart-for-gnome-shell

« back to all changes in this revision

Viewing changes to src/wso-wpa-psk.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2007-06-15 12:46:22 UTC
  • Revision ID: james.westby@ubuntu.com-20070615124622-01cyrnf0uxxun4lz
Tags: upstream-0.6.5
ImportĀ upstreamĀ versionĀ 0.6.5

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
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 * (C) Copyright 2005 Red Hat, Inc.
 
20
 */
 
21
 
 
22
#include <glib.h>
 
23
#include <glib/gi18n.h>
 
24
#include <gtk/gtk.h>
 
25
#include <glade/glade.h>
 
26
#include <dbus/dbus.h>
 
27
#include <iwlib.h>
 
28
 
 
29
#include "wireless-security-option.h"
 
30
#include "wso-wpa-psk.h"
 
31
#include "wso-private.h"
 
32
#include "cipher.h"
 
33
#include "cipher-wpa-psk-hex.h"
 
34
#include "cipher-wpa-psk-passphrase.h"
 
35
#include "dbus-helpers.h"
 
36
#include "NetworkManager.h"
 
37
 
 
38
 
 
39
struct OptData
 
40
{
 
41
        gboolean                                wpa2;
 
42
        const char *                    entry_name;
 
43
        const char *                    key_type_combo_name;
 
44
        const char *                    show_checkbutton_name;
 
45
        IEEE_802_11_Cipher *    hex_cipher;
 
46
        IEEE_802_11_Cipher *    passphrase_cipher;
 
47
};
 
48
 
 
49
static void
 
50
data_free_func (WirelessSecurityOption *opt)
 
51
{
 
52
        g_return_if_fail (opt != NULL);
 
53
        g_return_if_fail (opt->data != NULL);
 
54
 
 
55
        ieee_802_11_cipher_ref (opt->data->passphrase_cipher);
 
56
        ieee_802_11_cipher_ref (opt->data->hex_cipher);
 
57
        memset (opt->data, 0, sizeof (opt->data));
 
58
        g_free (opt->data);
 
59
}
 
60
 
 
61
 
 
62
static void show_passphrase_cb (GtkToggleButton *button, GtkEntry *entry)
 
63
{
 
64
        gtk_entry_set_visibility (entry, gtk_toggle_button_get_active (button));
 
65
}
 
66
 
 
67
 
 
68
static GtkWidget *
 
69
widget_create_func (WirelessSecurityOption *opt,
 
70
                    GtkSignalFunc validate_cb,
 
71
                    gpointer user_data)
 
72
{
 
73
        GtkWidget *     entry;
 
74
        GtkWidget *     checkbutton;
 
75
        GtkWidget *     widget;
 
76
 
 
77
        g_return_val_if_fail (opt != NULL, NULL);
 
78
        g_return_val_if_fail (opt->data != NULL, NULL);
 
79
        g_return_val_if_fail (validate_cb != NULL, NULL);
 
80
 
 
81
        widget = wso_widget_helper (opt);
 
82
        entry = glade_xml_get_widget (opt->uixml, opt->data->entry_name);
 
83
        g_signal_connect (G_OBJECT (entry), "changed", validate_cb, user_data);
 
84
 
 
85
        checkbutton = glade_xml_get_widget (opt->uixml, opt->data->show_checkbutton_name);
 
86
        g_signal_connect (G_OBJECT (checkbutton), "toggled", GTK_SIGNAL_FUNC (show_passphrase_cb), GTK_ENTRY (entry));
 
87
 
 
88
        return widget;
 
89
}
 
90
 
 
91
 
 
92
static gboolean
 
93
validate_input_func (WirelessSecurityOption *opt,
 
94
                     const char *ssid,
 
95
                     IEEE_802_11_Cipher **out_cipher)
 
96
{
 
97
        GtkWidget *     entry;
 
98
        const char *    input;
 
99
 
 
100
        g_return_val_if_fail (opt != NULL, FALSE);
 
101
 
 
102
        entry = glade_xml_get_widget (opt->uixml, opt->data->entry_name);
 
103
        input = gtk_entry_get_text (GTK_ENTRY (entry));
 
104
        return wso_validate_helper (opt, ssid, input, out_cipher);
 
105
}
 
106
 
 
107
 
 
108
static gboolean
 
109
append_dbus_params_func (WirelessSecurityOption *opt,
 
110
                         const char *ssid,
 
111
                         DBusMessage *message)
 
112
{
 
113
        IEEE_802_11_Cipher *    cipher = NULL;
 
114
        GtkWidget *                     entry;
 
115
        const char *                    input;
 
116
 
 
117
        g_return_val_if_fail (opt != NULL, FALSE);
 
118
        g_return_val_if_fail (opt->data != NULL, FALSE);
 
119
        g_return_val_if_fail (opt->data->entry_name != NULL, FALSE);
 
120
 
 
121
        entry = glade_xml_get_widget (opt->uixml, opt->data->entry_name);
 
122
        input = gtk_entry_get_text (GTK_ENTRY (entry));
 
123
        if (!wso_validate_helper (opt, ssid, input, &cipher) || !cipher)
 
124
                return FALSE;
 
125
 
 
126
        nmu_security_serialize_wpa_psk_with_cipher (message, cipher, ssid, input,
 
127
             opt->data->wpa2 ? IW_AUTH_WPA_VERSION_WPA2 : IW_AUTH_WPA_VERSION_WPA,
 
128
             IW_AUTH_KEY_MGMT_PSK);
 
129
 
 
130
        return TRUE;
 
131
}
 
132
 
 
133
 
 
134
static void
 
135
key_type_combo_changed_cb (GtkComboBox *combo,
 
136
                           gpointer user_data)
 
137
{
 
138
        WirelessSecurityOption * opt = (WirelessSecurityOption *) user_data;
 
139
        int                                     we_cipher;
 
140
        GtkTreeModel *                  model;
 
141
        GtkTreeIter                     iter;
 
142
        GSList *                                elt;
 
143
 
 
144
        g_return_if_fail (opt != NULL);
 
145
 
 
146
        model = gtk_combo_box_get_model (combo);
 
147
        gtk_combo_box_get_active_iter (combo, &iter);
 
148
        gtk_tree_model_get (model, &iter, WPA_KEY_TYPE_CIPHER_COL, &we_cipher, -1);
 
149
 
 
150
        for (elt = opt->ciphers; elt; elt = g_slist_next (elt))
 
151
        {
 
152
                IEEE_802_11_Cipher * cipher = (IEEE_802_11_Cipher *)(elt->data);
 
153
 
 
154
                if (cipher == opt->data->passphrase_cipher)
 
155
                        cipher_wpa_psk_passphrase_set_we_cipher (cipher, we_cipher);
 
156
                else if (cipher == opt->data->hex_cipher)
 
157
                        cipher_wpa_psk_hex_set_we_cipher (cipher, we_cipher);
 
158
        }
 
159
}
 
160
 
 
161
 
 
162
WirelessSecurityOption *
 
163
wso_wpa_psk_new (const char *glade_file,
 
164
                 int capabilities,
 
165
                 gboolean wpa2)
 
166
{
 
167
        WirelessSecurityOption * opt = NULL;
 
168
        OptData *                               data = NULL;
 
169
        GtkWidget *                     key_type_combo;
 
170
        int                                     num_added;
 
171
        GtkTreeModel *                  model;
 
172
        GtkTreeIter                     iter;
 
173
 
 
174
        g_return_val_if_fail (glade_file != NULL, NULL);
 
175
 
 
176
        opt = g_malloc0 (sizeof (WirelessSecurityOption));
 
177
        if (wpa2)
 
178
                opt->name = g_strdup (_("WPA2 Personal"));
 
179
        else
 
180
                opt->name = g_strdup (_("WPA Personal"));
 
181
        opt->widget_name = "wpa_psk_notebook";
 
182
        opt->data_free_func = data_free_func;
 
183
        opt->validate_input_func = validate_input_func;
 
184
        opt->widget_create_func = widget_create_func;
 
185
        opt->append_dbus_params_func = append_dbus_params_func;
 
186
 
 
187
        if (!(opt->uixml = glade_xml_new (glade_file, opt->widget_name, NULL)))
 
188
        {
 
189
                wso_free (opt);
 
190
                return NULL;
 
191
        }
 
192
 
 
193
        /* Option-specific data */
 
194
        opt->data = data = g_malloc0 (sizeof (OptData));
 
195
        data->wpa2 = wpa2;
 
196
        data->entry_name = "wpa_psk_entry";
 
197
        data->key_type_combo_name = "wpa_psk_type_combo";
 
198
        data->show_checkbutton_name = "show_checkbutton";
 
199
 
 
200
        /* Set up our ciphers */
 
201
        data->passphrase_cipher = cipher_wpa_psk_passphrase_new ();
 
202
        ieee_802_11_cipher_ref (data->passphrase_cipher);
 
203
        opt->ciphers = g_slist_append (opt->ciphers, data->passphrase_cipher);
 
204
        data->hex_cipher = cipher_wpa_psk_hex_new ();
 
205
        ieee_802_11_cipher_ref (data->hex_cipher);
 
206
        opt->ciphers = g_slist_append (opt->ciphers, data->hex_cipher);
 
207
 
 
208
        key_type_combo = glade_xml_get_widget (opt->uixml, data->key_type_combo_name);
 
209
        g_signal_connect (G_OBJECT (key_type_combo), "changed", (GCallback) key_type_combo_changed_cb, opt);
 
210
        model = wso_wpa_create_key_type_model (capabilities, FALSE, &num_added);
 
211
        gtk_combo_box_set_model (GTK_COMBO_BOX (key_type_combo), model);
 
212
        gtk_tree_model_get_iter_first (model, &iter);
 
213
        gtk_combo_box_set_active_iter (GTK_COMBO_BOX (key_type_combo), &iter);
 
214
        if (num_added == 1)
 
215
                gtk_widget_set_sensitive (key_type_combo, FALSE);
 
216
 
 
217
        return opt;
 
218
}
 
219