1
/* NetworkManager -- Network link manager
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.
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.
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.
17
* (C) Copyright 2006 Thiago Jung Bauermann <thiago.bauermann@gmail.com>
20
/* This file is heavily based on nm-ap-security-wpa-eap.c */
23
#include <glib/gi18n.h>
24
#include <dbus/dbus.h>
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"
34
#define NM_AP_SECURITY_LEAP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_LEAP, NMAPSecurityLEAPPrivate))
36
struct _NMAPSecurityLEAPPrivate
44
nm_ap_security_leap_new_deserialize (DBusMessageIter *iter)
46
NMAPSecurityLEAP * security = NULL;
47
char * username = NULL;
48
char * password = NULL;
49
char * key_mgmt = NULL;
51
g_return_val_if_fail (iter != NULL, NULL);
53
if (!nmu_security_deserialize_leap (iter, &username, &password, &key_mgmt))
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);
60
nm_ap_security_set_key (NM_AP_SECURITY (security), password, strlen(password));
62
security->priv->username = g_strdup (username);
64
security->priv->key_mgmt = g_strdup (key_mgmt);
66
nm_ap_security_set_description (NM_AP_SECURITY (security), _("LEAP"));
74
nm_ap_security_leap_new_from_ap (NMAccessPoint *ap)
76
NMAPSecurityLEAP * security = NULL;
78
g_return_val_if_fail (ap != NULL, NULL);
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"));
89
real_serialize (NMAPSecurity *instance, DBusMessageIter *iter)
91
NMAPSecurityLEAP * self = NM_AP_SECURITY_LEAP (instance);
93
if (!nmu_security_serialize_leap (iter, self->priv->username,
94
nm_ap_security_get_key(instance), self->priv->key_mgmt))
100
real_write_supplicant_config (NMAPSecurity *instance,
101
struct wpa_ctrl *ctrl,
103
NMAPSecurityWriteFlags flag)
105
NMAPSecurityLEAP * self = NM_AP_SECURITY_LEAP (instance);
106
gboolean success = FALSE;
108
const char * password = nm_ap_security_get_key(instance);
110
g_return_val_if_fail (nm_ap_security_get_we_cipher (instance) == NM_AUTH_TYPE_LEAP, FALSE);
112
/* LEAP is not valid for wired */
113
if (flag == NM_AP_SECURITY_WRITE_FLAG_WIRED)
117
if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, NULL, "SET_NETWORK %i proto WPA", nwid))
120
if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, NULL, "SET_NETWORK %i key_mgmt %s",
121
nwid, self->priv->key_mgmt))
124
if (!nm_utils_supplicant_request_with_check (ctrl, "OK", __func__, NULL, "SET_NETWORK %i eap LEAP", nwid))
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))
132
if (password && strlen (password) > 0)
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\"",
151
real_get_default_capabilities (NMAPSecurity *instance)
153
guint32 caps = NM_802_11_CAP_NONE;
155
caps |= NM_802_11_CAP_KEY_MGMT_802_1X;
161
real_get_authentication_required (NMAPSecurity *instance)
166
static NMAPSecurity *
167
real_copy_constructor (NMAPSecurity *instance)
169
NMAPSecurityLEAP * dst = g_object_new (NM_TYPE_AP_SECURITY_LEAP, NULL);
170
NMAPSecurityLEAP * self = NM_AP_SECURITY_LEAP (instance);
172
dst->priv->username = self->priv->username;
173
dst->priv->key_mgmt = self->priv->key_mgmt;
175
nm_ap_security_copy_properties (NM_AP_SECURITY (self), NM_AP_SECURITY (dst));
177
return NM_AP_SECURITY (dst);
182
nm_ap_security_leap_init (NMAPSecurityLEAP * self)
184
self->priv = NM_AP_SECURITY_LEAP_GET_PRIVATE (self);
185
self->priv->username = NULL;
186
self->priv->key_mgmt = NULL;
191
nm_ap_security_leap_class_init (NMAPSecurityLEAPClass *klass)
193
GObjectClass *object_class = G_OBJECT_CLASS (klass);
194
NMAPSecurityClass *par_class = NM_AP_SECURITY_CLASS (klass);
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;
202
g_type_class_add_private (object_class, sizeof (NMAPSecurityLEAPPrivate));
207
nm_ap_security_leap_get_type (void)
209
static GType 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),
220
(GInstanceInitFunc) nm_ap_security_leap_init,
221
NULL /* value_table */
223
type = g_type_register_static (NM_TYPE_AP_SECURITY,