2005-12-21 Dan Williams <dcbw@redhat.com>

* gnome/applet/nm-gconf-wso*
		- Make the serialize functions return gboolean
			rather than int

	* gnome/applet/nm-gconf-wso.c
		- (nm_gconf_wso_dispose, nm_gconf_wso_finalize): fix up
			parent class handling so we don't segfault

	* src/NetworkManagerAP.[ch]
		- (nm_ap_get_capabilities): new function, return capabilities
			now that something can use them
		- (nm_ap_set_encrypted): assume that an access point supports
			both WEP104 and WEP40 if its set encrypted.  FIXME: can
			we even tell whether it just supports WEP40?

	* src/NetworkManagerDevice.c
		- (ap_need_key): resurrect and update for the New World Order
		- (nm_device_wireless_get_activation_ap): if we're not given
			security info to use, create some based on access point
			capabilities

	* src/nm-ap-security-wep.c
		- (nm_ap_security_wep_new_from_ap): create a new object
			based on a certain access point's capabilities

	* src/nm-ap-security.c
		- (nm_ap_security_new_from_ap): delegate creation of a new
			object based on access point capabilities to a subclass
		- (nm_ap_security_copy_properties): don't segfault if we
			don't have a key yet

	* src/nm-dbus-nm.c
		- (nm_dbus_nm_set_active_device): provide more informative
			output when errors occur.  Also construct security info
			for a given access point if we weren't given any


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1219 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2005-12-21 21:08:00 +00:00
parent 9c1c832db2
commit b5c3269266
13 changed files with 207 additions and 57 deletions

View file

@ -1,3 +1,41 @@
2005-12-21 Dan Williams <dcbw@redhat.com>
* gnome/applet/nm-gconf-wso*
- Make the serialize functions return gboolean
rather than int
* gnome/applet/nm-gconf-wso.c
- (nm_gconf_wso_dispose, nm_gconf_wso_finalize): fix up
parent class handling so we don't segfault
* src/NetworkManagerAP.[ch]
- (nm_ap_get_capabilities): new function, return capabilities
now that something can use them
- (nm_ap_set_encrypted): assume that an access point supports
both WEP104 and WEP40 if its set encrypted. FIXME: can
we even tell whether it just supports WEP40?
* src/NetworkManagerDevice.c
- (ap_need_key): resurrect and update for the New World Order
- (nm_device_wireless_get_activation_ap): if we're not given
security info to use, create some based on access point
capabilities
* src/nm-ap-security-wep.c
- (nm_ap_security_wep_new_from_ap): create a new object
based on a certain access point's capabilities
* src/nm-ap-security.c
- (nm_ap_security_new_from_ap): delegate creation of a new
object based on access point capabilities to a subclass
- (nm_ap_security_copy_properties): don't segfault if we
don't have a key yet
* src/nm-dbus-nm.c
- (nm_dbus_nm_set_active_device): provide more informative
output when errors occur. Also construct security info
for a given access point if we weren't given any
2005-12-21 Žygimantas Beručka <zygis@gnome.org>
* configure.in: Added Lithuanian to ALL_LINGUAS.

View file

@ -95,7 +95,7 @@ out:
return security;
}
static int
static gboolean
real_serialize_dbus (NMGConfWSO *instance, DBusMessageIter *iter)
{
NMGConfWSOWEP * self = NM_GCONF_WSO_WEP (instance);
@ -103,11 +103,11 @@ real_serialize_dbus (NMGConfWSO *instance, DBusMessageIter *iter)
if (!nmu_security_serialize_wep (iter,
nm_gconf_wso_get_key (instance),
self->priv->auth_algorithm))
return -1;
return 0;
return FALSE;
return TRUE;
}
static int
static gboolean
real_serialize_gconf (NMGConfWSO *instance, GConfClient *client, const char *network)
{
NMGConfWSOWEP *self = NM_GCONF_WSO_WEP (instance);
@ -117,7 +117,7 @@ real_serialize_gconf (NMGConfWSO *instance, GConfClient *client, const char *net
gconf_client_set_int (client, key, self->priv->auth_algorithm, NULL);
g_free (key);
return 0;
return TRUE;
}
static void

View file

@ -106,7 +106,7 @@ out:
return security;
}
static int
static gboolean
real_serialize_dbus (NMGConfWSO *instance, DBusMessageIter *iter)
{
NMGConfWSOWPA_PSK * self = NM_GCONF_WSO_WPA_PSK (instance);
@ -115,11 +115,11 @@ real_serialize_dbus (NMGConfWSO *instance, DBusMessageIter *iter)
nm_gconf_wso_get_key (instance),
self->priv->wpa_version,
self->priv->key_mgt))
return -1;
return 0;
return FALSE;
return TRUE;
}
static int
static gboolean
real_serialize_gconf (NMGConfWSO *instance, GConfClient *client, const char *network)
{
NMGConfWSOWPA_PSK * self = NM_GCONF_WSO_WPA_PSK (instance);
@ -133,7 +133,7 @@ real_serialize_gconf (NMGConfWSO *instance, GConfClient *client, const char *net
gconf_client_set_int (client, key, self->priv->key_mgt, NULL);
g_free (key);
return 0;
return TRUE;
}
static void

View file

@ -44,8 +44,6 @@ struct _NMGConfWSOPrivate
gboolean dispose_has_run;
};
static GObjectClass *parent_class = NULL;
static NMGConfWSO *
nm_gconf_wso_new (int we_cipher)
{
@ -225,16 +223,16 @@ nm_gconf_wso_get_key (NMGConfWSO *self)
return self->priv->key;
}
int
gboolean
nm_gconf_wso_serialize_dbus (NMGConfWSO *self, DBusMessageIter *iter)
{
dbus_int32_t dbus_we_cipher;
g_return_val_if_fail (self != NULL, -1);
g_return_val_if_fail (iter != NULL, -1);
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (iter != NULL, FALSE);
if (self->priv->dispose_has_run)
return -1;
return FALSE;
/* First arg: WE cipher (INT32) */
dbus_we_cipher = (dbus_int32_t) self->priv->we_cipher;
@ -243,18 +241,18 @@ nm_gconf_wso_serialize_dbus (NMGConfWSO *self, DBusMessageIter *iter)
return NM_GCONF_WSO_GET_CLASS (self)->serialize_dbus_func (self, iter);
}
int
gboolean
nm_gconf_wso_serialize_gconf (NMGConfWSO *self, GConfClient *client, const char *network)
{
dbus_int32_t dbus_we_cipher;
char * key;
g_return_val_if_fail (self != NULL, -1);
g_return_val_if_fail (client != NULL, -1);
g_return_val_if_fail (network != NULL, -1);
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (client != NULL, FALSE);
g_return_val_if_fail (network != NULL, FALSE);
if (self->priv->dispose_has_run)
return -1;
return FALSE;
key = g_strdup_printf ("%s/%s/we_cipher", GCONF_PATH_WIRELESS_NETWORKS, network);
gconf_client_set_int (client, key, self->priv->we_cipher, NULL);
@ -277,7 +275,9 @@ nm_gconf_wso_init (NMGConfWSO * self)
static void
nm_gconf_wso_dispose (GObject *object)
{
NMGConfWSO *self = (NMGConfWSO *) object;
NMGConfWSO * self = (NMGConfWSO *) object;
NMGConfWSOClass * klass;
GObjectClass * parent_class;
if (self->priv->dispose_has_run)
/* If dispose did already run, return. */
@ -294,19 +294,25 @@ nm_gconf_wso_dispose (GObject *object)
*/
/* Chain up to the parent class */
G_OBJECT_CLASS (parent_class)->dispose (object);
klass = NM_GCONF_WSO_CLASS (g_type_class_peek (NM_TYPE_GCONF_WSO));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
parent_class->dispose (object);
}
static void
nm_gconf_wso_finalize (GObject *object)
{
NMGConfWSO *self = (NMGConfWSO *) object;
NMGConfWSO * self = (NMGConfWSO *) object;
NMGConfWSOClass * klass;
GObjectClass * parent_class;
/* Complete object destruction */
g_free (self->priv->key);
/* Chain up to the parent class */
G_OBJECT_CLASS (parent_class)->finalize (object);
klass = NM_GCONF_WSO_CLASS (g_type_class_peek (NM_TYPE_GCONF_WSO));
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
parent_class->finalize (object);
}

View file

@ -54,9 +54,9 @@ struct _NMGConfWSOClass
GObjectClass parent;
/* class members */
int (*serialize_dbus_func) (NMGConfWSO *self, DBusMessageIter *iter);
gboolean (*serialize_dbus_func) (NMGConfWSO *self, DBusMessageIter *iter);
int (*serialize_gconf_func) (NMGConfWSO *self, GConfClient *client, const char *network);
gboolean (*serialize_gconf_func) (NMGConfWSO *self, GConfClient *client, const char *network);
};
@ -74,8 +74,8 @@ const char * nm_gconf_wso_get_key (NMGConfWSO *self);
void nm_gconf_wso_set_key (NMGConfWSO *self, const char *key, int key_len);
int nm_gconf_wso_serialize_dbus (NMGConfWSO *self, DBusMessageIter *iter);
gboolean nm_gconf_wso_serialize_dbus (NMGConfWSO *self, DBusMessageIter *iter);
int nm_gconf_wso_serialize_gconf (NMGConfWSO *self, GConfClient *client, const char *network);
gboolean nm_gconf_wso_serialize_gconf (NMGConfWSO *self, GConfClient *client, const char *network);
#endif /* NM_GCONF_WSO_H */

View file

@ -201,6 +201,14 @@ void nm_ap_set_essid (NMAccessPoint *ap, const char * essid)
}
guint32 nm_ap_get_capabilities (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, -1);
return ap->capabilities;
}
/*
* Get/set functions for encrypted flag
*
@ -216,12 +224,13 @@ gboolean nm_ap_get_encrypted (const NMAccessPoint *ap)
void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean privacy)
{
#define ALL_WEP (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP104 | NM_802_11_CAP_CIPHER_WEP40)
g_return_if_fail (ap != NULL);
if (privacy)
ap->capabilities |= NM_802_11_CAP_PROTO_WEP;
ap->capabilities |= ALL_WEP;
else
ap->capabilities &= ~NM_802_11_CAP_PROTO_WEP;
ap->capabilities &= ~ALL_WEP;
}
/*

View file

@ -43,6 +43,8 @@ void nm_ap_set_timestamp (NMAccessPoint *ap, const GTimeVal *timestamp);
char * nm_ap_get_essid (const NMAccessPoint *ap);
void nm_ap_set_essid (NMAccessPoint *ap, const char *essid);
guint32 nm_ap_get_capabilities (NMAccessPoint *ap);
gboolean nm_ap_get_encrypted (const NMAccessPoint *ap);
void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean privacy);

View file

@ -2483,15 +2483,17 @@ static gboolean nm_device_wireless_wait_for_link (NMDevice *dev, const char *ess
}
#if 0
static gboolean ap_need_key (NMDevice *dev, NMAccessPoint *ap)
{
char *essid;
gboolean need_key = FALSE;
char * essid;
gboolean need_key = FALSE;
NMAPSecurity * security;
g_return_val_if_fail (ap != NULL, FALSE);
essid = nm_ap_get_essid (ap);
security = nm_ap_get_security (ap);
g_assert (security);
if (!nm_ap_get_encrypted (ap))
{
@ -2500,7 +2502,7 @@ static gboolean ap_need_key (NMDevice *dev, NMAccessPoint *ap)
}
else
{
if (nm_ap_is_enc_key_valid (ap))
if (nm_ap_security_get_key (security))
{
nm_info ("Activation (%s/wireless): access point '%s' "
"is encrypted, and a key exists. No new key needed.",
@ -2510,15 +2512,13 @@ static gboolean ap_need_key (NMDevice *dev, NMAccessPoint *ap)
{
nm_info ("Activation (%s/wireless): access point '%s' "
"is encrypted, but NO valid key exists. New key needed.",
nm_device_get_iface (dev),
essid ? essid : "(null)");
nm_device_get_iface (dev), essid ? essid : "(null)");
need_key = TRUE;
}
}
return need_key;
}
#endif
/*
@ -2549,14 +2549,11 @@ static void nm_device_wireless_configure (NMActRequest *req)
nm_info ("Activation (%s/wireless) Stage 2 (Device Configure) will connect to access point '%s'.", nm_device_get_iface (dev), nm_ap_get_essid (ap));
#if 0
// FIXME
if (ap_need_key (dev, ap))
{
nm_dbus_get_user_key_for_network (data->dbus_connection, req, FALSE);
return;
}
#endif
while (success == FALSE)
{
@ -2574,7 +2571,7 @@ static void nm_device_wireless_configure (NMActRequest *req)
if (!link)
{
nm_debug ("Activation (%s/wireless): no hardware link to '%s'.",
nm_info ("Activation (%s/wireless): no hardware link to '%s'.",
nm_device_get_iface (dev), nm_ap_get_essid (ap) ? nm_ap_get_essid (ap) : "(none)");
nm_policy_schedule_activation_failed (req);
break;
@ -3641,7 +3638,6 @@ NMAccessPoint * nm_device_wireless_get_activation_ap (NMDevice *dev, const char
g_return_val_if_fail (dev != NULL, NULL);
g_return_val_if_fail (dev->app_data != NULL, NULL);
g_return_val_if_fail (essid != NULL, NULL);
g_return_val_if_fail (security != NULL, NULL);
nm_debug ("Forcing AP '%s'", essid);
@ -3650,8 +3646,18 @@ NMAccessPoint * nm_device_wireless_get_activation_ap (NMDevice *dev, const char
*/
if (!(ap = nm_ap_list_get_ap_by_essid (nm_device_ap_list_get (dev), essid)))
{
/* Okay, the card didn't see it in the scan, Cisco cards sometimes do this.
* So we make a "fake" access point and add it to the scan list.
/* We need security information from the user if the network they
* request isn't in our scan list.
*/
if (!security)
{
nm_warning ("%s: tried to manually connect to network '%s' without "
"providing security information!", __func__, essid);
return NULL;
}
/* User chose a network we haven't seen in a scan, so create a
* "fake" access point and add it to yhe scan list.
*/
ap = nm_ap_new ();
nm_ap_set_essid (ap, essid);
@ -3665,7 +3671,12 @@ NMAccessPoint * nm_device_wireless_get_activation_ap (NMDevice *dev, const char
* the User Knows What's Best.
*/
nm_ap_list_remove_ap_by_essid (dev->app_data->invalid_ap_list, nm_ap_get_essid (ap));
/* If we didn't get any security info, make some up. */
if (!security)
security = nm_ap_security_new_from_ap (ap);
}
g_assert (security);
nm_ap_set_security (ap, security);
return ap;

View file

@ -37,6 +37,17 @@ struct _NMAPSecurityWEPPrivate
int auth_algorithm;
};
static void set_description (NMAPSecurityWEP *security)
{
NMAPSecurity * parent = NM_AP_SECURITY (security);
if (nm_ap_security_get_we_cipher (parent) == IW_AUTH_CIPHER_WEP40)
nm_ap_security_set_description (parent, _("40-bit WEP"));
else
nm_ap_security_set_description (parent, _("104-bit WEP"));
}
NMAPSecurityWEP *
nm_ap_security_wep_new_deserialize (DBusMessageIter *iter, int we_cipher)
{
@ -58,15 +69,29 @@ nm_ap_security_wep_new_deserialize (DBusMessageIter *iter, int we_cipher)
nm_ap_security_set_key (NM_AP_SECURITY (security), key, key_len);
security->priv->auth_algorithm = auth_algorithm;
if (we_cipher == IW_AUTH_CIPHER_WEP40)
nm_ap_security_set_description (NM_AP_SECURITY (security), _("40-bit WEP"));
else
nm_ap_security_set_description (NM_AP_SECURITY (security), _("104-bit WEP"));
set_description (security);
out:
return security;
}
NMAPSecurityWEP *
nm_ap_security_wep_new_from_ap (NMAccessPoint *ap, int we_cipher)
{
NMAPSecurityWEP * security = NULL;
g_return_val_if_fail (ap != NULL, NULL);
g_return_val_if_fail ((we_cipher == IW_AUTH_CIPHER_WEP40) || (we_cipher == IW_AUTH_CIPHER_WEP104), NULL);
security = g_object_new (NM_TYPE_AP_SECURITY_WEP, NULL);
nm_ap_security_set_we_cipher (NM_AP_SECURITY (security), we_cipher);
security->priv->auth_algorithm = IW_AUTH_ALG_OPEN_SYSTEM;
set_description (security);
return security;
}
static int
real_serialize (NMAPSecurity *instance, DBusMessageIter *iter)
{

View file

@ -55,4 +55,7 @@ GType nm_ap_security_wep_get_type (void);
NMAPSecurityWEP * nm_ap_security_wep_new_deserialize (DBusMessageIter *iter, int we_cipher);
struct NMAccessPoint;
NMAPSecurityWEP * nm_ap_security_wep_new_from_ap (struct NMAccessPoint *ap, int we_cipher);
#endif /* NM_AP_SECURITY_WEP_H */

View file

@ -95,6 +95,42 @@ out:
return security;
}
#define WPA2_CCMP_PSK (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_CIPHER_CCMP | NM_802_11_CAP_KEY_MGMT_PSK)
#define WPA2_TKIP_PSK (NM_802_11_CAP_PROTO_WPA2 | NM_802_11_CAP_CIPHER_TKIP | NM_802_11_CAP_KEY_MGMT_PSK)
#define WPA_TKIP_PSK (NM_802_11_CAP_PROTO_WPA | NM_802_11_CAP_CIPHER_TKIP | NM_802_11_CAP_KEY_MGMT_PSK)
#define WEP_WEP104 (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP104)
#define WEP_WEP40 (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP40)
NMAPSecurity *
nm_ap_security_new_from_ap (NMAccessPoint *ap)
{
NMAPSecurity * security = NULL;
guint32 caps;
g_return_val_if_fail (ap != NULL, NULL);
/* Deteremine best encryption algorithm to use */
caps = nm_ap_get_capabilities (ap);
/*
if (caps & WPA2_CCMP_PSK)
stuff
else if (caps & WPA2_TKIP_PSK)
stuff
else if (caps & WPA_TKIP_PSK)
stuff
else
*/
if (caps & WEP_WEP104)
security = NM_AP_SECURITY (nm_ap_security_wep_new_from_ap (ap, IW_AUTH_CIPHER_WEP104));
else if (caps & WEP_WEP40)
security = NM_AP_SECURITY (nm_ap_security_wep_new_from_ap (ap, IW_AUTH_CIPHER_WEP40));
else if (!nm_ap_get_encrypted (ap))
security = nm_ap_security_new (IW_AUTH_CIPHER_NONE);
return security;
}
void
nm_ap_security_write_wpa_supplicant_config (NMAPSecurity *self, int fd)
{
@ -246,7 +282,8 @@ nm_ap_security_copy_properties (NMAPSecurity *self, NMAPSecurity *dst)
g_return_if_fail (self != dst);
nm_ap_security_set_we_cipher (dst, self->priv->we_cipher);
nm_ap_security_set_key (dst, self->priv->key, strlen (self->priv->key));
if (self->priv->key)
nm_ap_security_set_key (dst, self->priv->key, strlen (self->priv->key));
nm_ap_security_set_description (dst, self->priv->description);
}

View file

@ -47,6 +47,7 @@ struct _NMAPSecurity
};
struct NMDevice;
struct NMAccessPoint;
struct _NMAPSecurityClass
{
@ -69,6 +70,8 @@ NMAPSecurity * nm_ap_security_new_copy (NMAPSecurity *self);
NMAPSecurity * nm_ap_security_new_deserialize (DBusMessageIter *iter);
NMAPSecurity * nm_ap_security_new_from_ap (struct NMAccessPoint *ap);
int nm_ap_security_get_we_cipher (NMAPSecurity *self);
const char * nm_ap_security_get_key (NMAPSecurity *self);

View file

@ -202,7 +202,8 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_OBJECT_PATH)
{
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE);
nm_warning ("%s:%d (%s): Invalid arguments (first arg type was not OBJECT_PATH).",
__FILE__, __LINE__, __func__);
goto out;
}
@ -216,6 +217,7 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
{
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeviceNotFound",
"The requested network device does not exist.");
nm_warning ("%s:%d (%s): Invalid device (device not found).", __FILE__, __LINE__, __func__);
goto out;
}
@ -226,22 +228,30 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
if (!dbus_message_iter_next (&iter) || (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING))
{
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE);
nm_warning ("%s:%d (%s): Invalid argument type (essid).", __FILE__, __LINE__, __func__);
goto out;
}
/* grab ssid and ensure validity */
dbus_message_iter_get_basic (&iter, &essid);
if (!essid || (strlen (essid) <= 0) || !dbus_message_iter_next (&iter))
if (!essid || (strlen (essid) <= 0))
{
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE);
nm_warning ("%s:%d (%s): Invalid argument (essid).", __FILE__, __LINE__, __func__);
goto out;
}
if (!(security = nm_ap_security_new_deserialize (&iter)))
/* If there's security information, we use that. If not, we
* make some up from the scan list.
*/
if (dbus_message_iter_has_next (&iter))
{
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE);
goto out;
if (!(security = nm_ap_security_new_deserialize (&iter)))
{
/* There was security info, but it was invalid */
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE);
nm_warning ("%s:%d (%s): Invalid argument (wireless security info).", __FILE__, __LINE__, __func__);
goto out;
}
}
/* Set up the wireless-specific activation request properties */
@ -260,6 +270,12 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
nm_policy_schedule_device_activation (nm_act_request_new (data->data, dev, ap, TRUE));
out:
if (!reply)
{
reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE,
INVALID_ARGS_ERROR, INVALID_ARGS_MESSAGE);
}
return reply;
}