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

* include/NetworkManager.h
		- Finally kill NMEncKeyType

	* gnome/applet/applet-dbus-info.c
		- (nmi_save_network_info): convert to NMGConfWSO

	* gnome/applet/nm-gconf-wso-*.c
		- Implement gconf serialization functions

	* src/NetworkManagerPolicy.c
		- (nm_policy_activation_finish): fix up meaning of
			automatic/user_requested


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1211 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2005-12-17 21:39:19 +00:00
parent a601e80848
commit f003ba8ef7
7 changed files with 121 additions and 99 deletions

View File

@@ -1,3 +1,18 @@
2005-12-17 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h
- Finally kill NMEncKeyType
* gnome/applet/applet-dbus-info.c
- (nmi_save_network_info): convert to NMGConfWSO
* gnome/applet/nm-gconf-wso-*.c
- Implement gconf serialization functions
* src/NetworkManagerPolicy.c
- (nm_policy_activation_finish): fix up meaning of
automatic/user_requested
2005-12-17 Dan Williams <dcbw@redhat.com> 2005-12-17 Dan Williams <dcbw@redhat.com>
* gnome/applet/* * gnome/applet/*

View File

@@ -30,6 +30,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glade/glade.h> #include <glade/glade.h>
#include <gnome-keyring.h> #include <gnome-keyring.h>
#include <iwlib.h>
#include "NetworkManager.h" #include "NetworkManager.h"
#include "applet.h" #include "applet.h"
@@ -794,80 +795,71 @@ nmi_dbus_get_vpn_connection_routes (DBusConnection *connection,
* Save information about a wireless network in gconf and the gnome keyring. * Save information about a wireless network in gconf and the gnome keyring.
* *
*/ */
static void nmi_save_network_info (NMWirelessApplet *applet, const char *essid, const char *enc_key_source, static void
const NMEncKeyType enc_key_type, int auth_method, gboolean user_requested) nmi_save_network_info (NMWirelessApplet *applet,
const char *essid,
gboolean automatic,
NMGConfWSO * gconf_wso)
{ {
char * key; GnomeKeyringAttributeList * attributes;
GConfEntry * gconf_entry; GnomeKeyringAttribute attr;
char * escaped_network; char * key;
GConfEntry * gconf_entry;
char * escaped_network;
GnomeKeyringResult ret;
const char * name;
guint32 item_id;
g_return_if_fail (applet != NULL); g_return_if_fail (applet != NULL);
g_return_if_fail (essid != NULL); g_return_if_fail (essid != NULL);
g_return_if_fail (gconf_wso != NULL);
escaped_network = gconf_escape_key (essid, strlen (essid)); escaped_network = gconf_escape_key (essid, strlen (essid));
key = g_strdup_printf ("%s/%s", GCONF_PATH_WIRELESS_NETWORKS, escaped_network); key = g_strdup_printf ("%s/%s", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
gconf_entry = gconf_client_get_entry (applet->gconf_client, key, NULL, TRUE, NULL); gconf_entry = gconf_client_get_entry (applet->gconf_client, key, NULL, TRUE, NULL);
g_free (key); g_free (key);
if (gconf_entry) if (gconf_entry)
goto out;
gconf_entry_unref (gconf_entry);
if (nm_gconf_wso_get_we_cipher (gconf_wso) != IW_AUTH_CIPHER_NONE)
{ {
GnomeKeyringAttributeList *attributes; /* Setup a request to the keyring to save the network passphrase */
GnomeKeyringAttribute attr; name = g_strdup_printf (_("Passphrase for wireless network %s"), essid);
GnomeKeyringResult ret; attributes = gnome_keyring_attribute_list_new ();
const char *name; attr.name = g_strdup ("essid"); /* FIXME: Do we need to free this ? */
guint32 item_id; attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
attr.value.string = g_strdup (essid);
g_array_append_val (attributes, attr);
if (enc_key_source && strlen (enc_key_source) ret = gnome_keyring_item_create_sync (NULL,
&& (enc_key_type != NM_ENC_TYPE_UNKNOWN) && (enc_key_type != NM_ENC_TYPE_NONE)) GNOME_KEYRING_ITEM_GENERIC_SECRET,
{ name,
/* Setup a request to the keyring to save the network passphrase */ attributes,
name = g_strdup_printf (_("Passphrase for wireless network %s"), essid); nm_gconf_wso_get_key (gconf_wso),
attributes = gnome_keyring_attribute_list_new (); TRUE,
attr.name = g_strdup ("essid"); /* FIXME: Do we need to free this ? */ &item_id);
attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING; if (ret != GNOME_KEYRING_RESULT_OK)
attr.value.string = g_strdup (essid); g_warning ("Error saving passphrase in keyring. Ret=%d", ret);
g_array_append_val (attributes, attr);
ret = gnome_keyring_item_create_sync (NULL, gnome_keyring_attribute_list_free (attributes);
GNOME_KEYRING_ITEM_GENERIC_SECRET,
name,
attributes,
enc_key_source,
TRUE,
&item_id);
if (ret != GNOME_KEYRING_RESULT_OK)
g_warning ("Error saving passphrase in keyring. Ret=%d", ret);
gnome_keyring_attribute_list_free (attributes);
}
gconf_entry_unref (gconf_entry);
key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
gconf_client_set_string (applet->gconf_client, key, essid, NULL);
g_free (key);
key = g_strdup_printf ("%s/%s/key_type", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
gconf_client_set_int (applet->gconf_client, key, (int)enc_key_type, NULL);
g_free (key);
/* We only update the timestamp if the user requested a particular network, not if
* NetworkManager decided to switch access points by itself.
*/
if (user_requested)
{
key = g_strdup_printf ("%s/%s/timestamp", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
gconf_client_set_int (applet->gconf_client, key, time (NULL), NULL);
g_free (key);
}
if (auth_method != -1)
{
key = g_strdup_printf ("%s/%s/auth_method", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
gconf_client_set_int (applet->gconf_client, key, auth_method, NULL);
g_free (key);
}
} }
key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
gconf_client_set_string (applet->gconf_client, key, essid, NULL);
g_free (key);
/* We only update the timestamp if the user requested a particular network, not if
* NetworkManager decided to switch access points by itself.
*/
if (!automatic)
{
key = g_strdup_printf ("%s/%s/timestamp", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
gconf_client_set_int (applet->gconf_client, key, time (NULL), NULL);
g_free (key);
}
out:
g_free (escaped_network); g_free (escaped_network);
} }
@@ -885,28 +877,36 @@ nmi_dbus_update_network_info (DBusConnection *connection,
void *user_data) void *user_data)
{ {
NMWirelessApplet * applet = (NMWirelessApplet *) user_data; NMWirelessApplet * applet = (NMWirelessApplet *) user_data;
char * network = NULL; char * essid = NULL;
int auth_method = -1; gboolean automatic;
char * enc_key_source = NULL;
int enc_key_type = -1;
gboolean user_requested;
dbus_bool_t args_good; dbus_bool_t args_good;
NMGConfWSO * gconf_wso = NULL;
DBusMessageIter iter;
g_return_val_if_fail (applet != NULL, NULL); g_return_val_if_fail (applet != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL); g_return_val_if_fail (message != NULL, NULL);
args_good = dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &network, dbus_message_iter_init (message, &iter);
DBUS_TYPE_STRING, &enc_key_source,
DBUS_TYPE_INT32, &enc_key_type,
DBUS_TYPE_INT32, &auth_method,
DBUS_TYPE_BOOLEAN, &user_requested,
DBUS_TYPE_INVALID);
if (!args_good || (strlen (network) <= 0) || (auth_method == -1))
return NULL;
if (enc_key_source && strlen (enc_key_source) && ((enc_key_type == NM_ENC_TYPE_UNKNOWN) || (enc_key_type == NM_ENC_TYPE_NONE)))
return NULL;
nmi_save_network_info (applet, network, enc_key_source, (NMEncKeyType) enc_key_type, auth_method, user_requested); /* First argument: ESSID (STRING) */
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)
goto out;
dbus_message_iter_get_basic (&iter, &essid);
if (strlen (essid) <= 0)
goto out;
/* Second argument: Automatic (BOOLEAN) */
if (!dbus_message_iter_next (&iter) || (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_BOOLEAN))
goto out;
dbus_message_iter_get_basic (&iter, &automatic);
/* Deserialize the sercurity option out of the message */
if (!(gconf_wso = nm_gconf_wso_new_deserialize_dbus (&iter)))
goto out;
nmi_save_network_info (applet, essid, automatic, gconf_wso);
out:
return NULL; return NULL;
} }

View File

@@ -98,7 +98,7 @@ out:
static int static int
real_serialize_dbus (NMGConfWSO *instance, DBusMessageIter *iter) real_serialize_dbus (NMGConfWSO *instance, DBusMessageIter *iter)
{ {
NMGConfWSOWEP * self = NM_GCONF_WSO_WEP (instance); NMGConfWSOWEP * self = NM_GCONF_WSO_WEP (instance);
if (!nmu_security_serialize_wep (iter, if (!nmu_security_serialize_wep (iter,
nm_gconf_wso_get_key (instance), nm_gconf_wso_get_key (instance),
@@ -108,8 +108,15 @@ real_serialize_dbus (NMGConfWSO *instance, DBusMessageIter *iter)
} }
static int static int
real_serialize_gconf (NMGConfWSO *self, GConfClient *client, const char *network) real_serialize_gconf (NMGConfWSO *instance, GConfClient *client, const char *network)
{ {
NMGConfWSOWEP *self = NM_GCONF_WSO_WEP (instance);
char * key;
key = g_strdup_printf ("%s/%s/%sauth_algorithm", GCONF_PATH_WIRELESS_NETWORKS, network, WEP_PREFIX);
gconf_client_set_int (client, key, self->priv->auth_algorithm, NULL);
g_free (key);
return 0; return 0;
} }

View File

@@ -120,8 +120,19 @@ real_serialize_dbus (NMGConfWSO *instance, DBusMessageIter *iter)
} }
static int static int
real_serialize_gconf (NMGConfWSO *self, GConfClient *client, const char *network) real_serialize_gconf (NMGConfWSO *instance, GConfClient *client, const char *network)
{ {
NMGConfWSOWPA_PSK * self = NM_GCONF_WSO_WPA_PSK (instance);
char * key;
key = g_strdup_printf ("%s/%s/%swpa_version", GCONF_PATH_WIRELESS_NETWORKS, network, WPA_PSK_PREFIX);
gconf_client_set_int (client, key, self->priv->wpa_version, NULL);
g_free (key);
key = g_strdup_printf ("%s/%s/%skey_mgt", GCONF_PATH_WIRELESS_NETWORKS, network, WPA_PSK_PREFIX);
gconf_client_set_int (client, key, self->priv->key_mgt, NULL);
g_free (key);
return 0; return 0;
} }

View File

@@ -247,6 +247,7 @@ int
nm_gconf_wso_serialize_gconf (NMGConfWSO *self, GConfClient *client, const char *network) nm_gconf_wso_serialize_gconf (NMGConfWSO *self, GConfClient *client, const char *network)
{ {
dbus_int32_t dbus_we_cipher; dbus_int32_t dbus_we_cipher;
char * key;
g_return_val_if_fail (self != NULL, -1); g_return_val_if_fail (self != NULL, -1);
g_return_val_if_fail (client != NULL, -1); g_return_val_if_fail (client != NULL, -1);
@@ -255,11 +256,11 @@ nm_gconf_wso_serialize_gconf (NMGConfWSO *self, GConfClient *client, const char
if (self->priv->dispose_has_run) if (self->priv->dispose_has_run)
return -1; return -1;
#if 0 key = g_strdup_printf ("%s/%s/we_cipher", GCONF_PATH_WIRELESS_NETWORKS, network);
/* First arg: WE cipher (INT32) */ gconf_client_set_int (client, key, self->priv->we_cipher, NULL);
dbus_we_cipher = (dbus_int32_t) self->priv->we_cipher; g_free (key);
dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &dbus_we_cipher);
#endif /* Encryption key doesn't get serialized since its stored in the keyring */
return NM_GCONF_WSO_GET_CLASS (self)->serialize_gconf_func (self, client, network); return NM_GCONF_WSO_GET_CLASS (self)->serialize_gconf_func (self, client, network);
} }

View File

@@ -79,20 +79,6 @@ typedef enum NMDeviceType
} NMDeviceType; } NMDeviceType;
/*
* Encryption key types
*/
typedef enum NMEncKeyType
{
NM_ENC_TYPE_UNKNOWN = 0,
NM_ENC_TYPE_NONE,
NM_ENC_TYPE_HEX_KEY,
NM_ENC_TYPE_ASCII_KEY,
NM_ENC_TYPE_128_BIT_PASSPHRASE
/* FIXME: 802.1x support */
} NMEncKeyType;
/* /*
* General device capability bits * General device capability bits
* *

View File

@@ -64,9 +64,11 @@ static gboolean nm_policy_activation_finish (NMActRequest *req)
struct ether_addr addr; struct ether_addr addr;
NMAccessPoint * ap = nm_act_request_get_ap (req); NMAccessPoint * ap = nm_act_request_get_ap (req);
NMAccessPoint * tmp_ap; NMAccessPoint * tmp_ap;
gboolean automatic;
/* Cache details in the info-daemon since the connect was successful */ /* Cache details in the info-daemon since the connect was successful */
nm_dbus_update_network_info (data->dbus_connection, ap, nm_act_request_get_user_requested (req)); automatic = !nm_act_request_get_user_requested (req);
nm_dbus_update_network_info (data->dbus_connection, ap, automatic);
nm_device_get_ap_address (dev, &addr); nm_device_get_ap_address (dev, &addr);
if (!nm_ap_get_address (ap) || !nm_ethernet_address_is_valid (nm_ap_get_address (ap))) if (!nm_ap_get_address (ap) || !nm_ethernet_address_is_valid (nm_ap_get_address (ap)))