~ubuntu-branches/debian/lenny/network-manager/lenny

« back to all changes in this revision

Viewing changes to src/nm-ap-security-leap.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2008-07-05 15:11:33 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080705151133-rnwi7uuhda2iulug
Tags: 0.6.6-2
* debian/control
  - Add Build-Depends on pkg-config.
  - Drop obsolete Depends on iputils-arping. (Closes: #487794)
* debian/patches/09-nm_dbus_get_ap_from_object_path-mem_leak_fix.patch 
  - Fix memory leak in src/nm-dbus-net.c. (Closes: #488604)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* NetworkManager -- Network link manager
 
2
 *
 
3
 * This program is free software; you can redistribute it and/or modify
 
4
 * it under the terms of the GNU General Public License as published by
 
5
 * the Free Software Foundation; either version 2 of the License, or
 
6
 * (at your option) any later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program; if not, write to the Free Software
 
15
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
16
 *
 
17
 * (C) Copyright 2006 Thiago Jung Bauermann <thiago.bauermann@gmail.com>
 
18
 */
 
19
 
 
20
/* This file is heavily based on nm-ap-security-wpa-eap.c */
 
21
 
 
22
#include <glib.h>
 
23
#include <glib/gi18n.h>
 
24
#include <dbus/dbus.h>
 
25
#include <iwlib.h>
 
26
 
 
27
#include "nm-ap-security.h"
 
28
#include "nm-ap-security-leap.h"
 
29
#include "nm-ap-security-private.h"
 
30
#include "dbus-helpers.h"
 
31
#include "nm-device-802-11-wireless.h"
 
32
#include "NetworkManagerUtils.h"
 
33
 
 
34
#define NM_AP_SECURITY_LEAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_LEAP, NMAPSecurityLEAPPrivate))
 
35
 
 
36
struct _NMAPSecurityLEAPPrivate
 
37
{
 
38
        char *  username;
 
39
        char *  key_mgmt;
 
40
};
 
41
 
 
42
 
 
43
NMAPSecurityLEAP *
 
44
nm_ap_security_leap_new_deserialize (DBusMessageIter *iter)
 
45
{
 
46
        NMAPSecurityLEAP *      security = NULL;
 
47
        char *                  username = NULL;
 
48
        char *                  password = NULL;
 
49
        char *                  key_mgmt = NULL;
 
50
 
 
51
        g_return_val_if_fail (iter != NULL, NULL);
 
52
 
 
53
        if (!nmu_security_deserialize_leap (iter, &username, &password, &key_mgmt))
 
54
                goto out;
 
55
 
 
56
        /* Success, build up our security object */
 
57
        security = g_object_new (NM_TYPE_AP_SECURITY_LEAP, NULL);
 
58
        nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), NM_AUTH_TYPE_LEAP);
 
59
        if (password)
 
60
                nm_ap_security_set_key (NM_AP_SECURITY (security), password, strlen(password));
 
61
        if (username)
 
62
                security->priv->username = g_strdup (username);
 
63
        if (key_mgmt)
 
64
                security->priv->key_mgmt = g_strdup (key_mgmt);
 
65
 
 
66
        nm_ap_security_set_description (NM_AP_SECURITY (security), _("LEAP"));
 
67
 
 
68
out:
 
69
        return security;
 
70
}
 
71
 
 
72
 
 
73
NMAPSecurityLEAP *
 
74
nm_ap_security_leap_new_from_ap (NMAccessPoint *ap)
 
75
{
 
76
        NMAPSecurityLEAP *      security = NULL;
 
77
 
 
78
        g_return_val_if_fail (ap != NULL, NULL);
 
79
 
 
80
        security = g_object_new (NM_TYPE_AP_SECURITY_LEAP, NULL);
 
81
        nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), NM_AUTH_TYPE_LEAP);
 
82
        nm_ap_security_set_description (NM_AP_SECURITY (security), _("LEAP"));
 
83
 
 
84
        return security;
 
85
}
 
86
 
 
87
 
 
88
static int 
 
89
real_serialize (NMAPSecurity *instance, DBusMessageIter *iter)
 
90
{
 
91
        NMAPSecurityLEAP * self = NM_AP_SECURITY_LEAP (instance);
 
92
 
 
93
        if (!nmu_security_serialize_leap (iter, self->priv->username,
 
94
                        nm_ap_security_get_key(instance), self->priv->key_mgmt))
 
95
                return -1;
 
96
        return 0;
 
97
}
 
98
 
 
99
static gboolean 
 
100
real_write_supplicant_config (NMAPSecurity *instance,
 
101
                              struct wpa_ctrl *ctrl,
 
102
                              int nwid,
 
103
                              NMAPSecurityWriteFlags flag)
 
104
{
 
105
        NMAPSecurityLEAP *      self = NM_AP_SECURITY_LEAP (instance);
 
106
        gboolean                        success = FALSE;
 
107
        char *                  msg;
 
108
        const char *            password = nm_ap_security_get_key(instance);
 
109
 
 
110
        g_return_val_if_fail (nm_ap_security_get_we_cipher (instance) == NM_AUTH_TYPE_LEAP, FALSE);
 
111
 
 
112
        /* LEAP is not valid for wired */
 
113
        if (flag == NM_AP_SECURITY_WRITE_FLAG_WIRED)
 
114
                goto out;
 
115
 
 
116
 
 
117
        if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, NULL, "SET_NETWORK %i proto WPA", nwid))
 
118
                   goto out;
 
119
 
 
120
        if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, NULL, "SET_NETWORK %i key_mgmt %s",
 
121
                                            nwid, self->priv->key_mgmt))
 
122
                   goto out;
 
123
 
 
124
        if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, NULL, "SET_NETWORK %i eap LEAP", nwid))
 
125
                goto out;
 
126
 
 
127
        if (self->priv->username && strlen (self->priv->username) > 0)
 
128
                if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, NULL, "SET_NETWORK %i identity \"%s\"",
 
129
                                                    nwid, self->priv->username))
 
130
                        goto out;
 
131
 
 
132
        if (password && strlen (password) > 0)
 
133
        {
 
134
                msg = g_strdup_printf ("SET_NETWORK %i password <password>", nwid);
 
135
                if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, msg, "SET_NETWORK %i password \"%s\"",
 
136
                                                    nwid, password))
 
137
                {
 
138
                        g_free (msg);
 
139
                        goto out;
 
140
                }
 
141
                g_free (msg);
 
142
        }
 
143
 
 
144
        success = TRUE;
 
145
 
 
146
out:
 
147
        return success;
 
148
}
 
149
 
 
150
static guint32
 
151
real_get_default_capabilities (NMAPSecurity *instance)
 
152
{
 
153
        guint32                 caps = NM_802_11_CAP_NONE;
 
154
 
 
155
        caps |= NM_802_11_CAP_KEY_MGMT_802_1X;
 
156
 
 
157
        return caps;
 
158
}
 
159
 
 
160
static gboolean
 
161
real_get_authentication_required (NMAPSecurity *instance)
 
162
{
 
163
        return TRUE;
 
164
}
 
165
 
 
166
static NMAPSecurity *
 
167
real_copy_constructor (NMAPSecurity *instance)
 
168
{
 
169
        NMAPSecurityLEAP * dst = g_object_new (NM_TYPE_AP_SECURITY_LEAP, NULL);
 
170
        NMAPSecurityLEAP * self = NM_AP_SECURITY_LEAP (instance);
 
171
 
 
172
        dst->priv->username = self->priv->username;
 
173
        dst->priv->key_mgmt = self->priv->key_mgmt;
 
174
 
 
175
        nm_ap_security_copy_properties (NM_AP_SECURITY (self), NM_AP_SECURITY (dst));
 
176
 
 
177
        return NM_AP_SECURITY (dst);
 
178
}
 
179
 
 
180
 
 
181
static void
 
182
nm_ap_security_leap_init (NMAPSecurityLEAP * self)
 
183
{
 
184
        self->priv = NM_AP_SECURITY_LEAP_GET_PRIVATE (self);
 
185
        self->priv->username = NULL;
 
186
        self->priv->key_mgmt = NULL;
 
187
}
 
188
 
 
189
 
 
190
static void
 
191
nm_ap_security_leap_class_init (NMAPSecurityLEAPClass *klass)
 
192
{
 
193
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
194
        NMAPSecurityClass *par_class = NM_AP_SECURITY_CLASS (klass);
 
195
 
 
196
        par_class->copy_constructor_func = real_copy_constructor;
 
197
        par_class->serialize_func = real_serialize;
 
198
        par_class->write_supplicant_config_func = real_write_supplicant_config;
 
199
        par_class->get_default_capabilities_func = real_get_default_capabilities;
 
200
        par_class->get_authentication_required_func = real_get_authentication_required;
 
201
 
 
202
        g_type_class_add_private (object_class, sizeof (NMAPSecurityLEAPPrivate));
 
203
}
 
204
 
 
205
 
 
206
GType
 
207
nm_ap_security_leap_get_type (void)
 
208
{
 
209
        static GType type = 0;
 
210
        if (type == 0) {
 
211
                static const GTypeInfo info = {
 
212
                        sizeof (NMAPSecurityLEAPClass),
 
213
                        NULL,   /* base_init */
 
214
                        NULL,   /* base_finalize */
 
215
                        (GClassInitFunc) nm_ap_security_leap_class_init,
 
216
                        NULL,   /* class_finalize */
 
217
                        NULL,   /* class_data */
 
218
                        sizeof (NMAPSecurityLEAP),
 
219
                        0,              /* n_preallocs */
 
220
                        (GInstanceInitFunc) nm_ap_security_leap_init,
 
221
                        NULL            /* value_table */
 
222
                };
 
223
                type = g_type_register_static (NM_TYPE_AP_SECURITY,
 
224
                                                         "NMAPSecurityLEAP",
 
225
                                                         &info, 0);
 
226
        }
 
227
        return type;
 
228
}