Commit 438d37f1 authored by Dan Williams's avatar Dan Williams
Browse files

2005-08-04 Dan Williams <dcbw@redhat.com>

	* gnome/applet/applet-dbus-info.c
	  gnome/applet/applet-dbus-info.h
		- (nmi_dbus_update_network_auth_method->nmi_save_network_info): generalize
			to store key, key type, and auth method rather than just auth method
		- (nmi_dbus_update_network_info): new function
		- (nmi_dbus_info_message_handler): updateNetworkAuthMethod -> updateNetworkInfo

	* gnome/applet/passphrase-dialog.c
		- (nmi_passphrase_dialog_ok_clicked): call nmi_save_network_info() instead
			of saving the info ourselves

	* gnome/libnm_glib/libnm_glib.c
		- Remove the stupid version check for dbus

	* src/NetworkManagerAP.c
	  src/NetworkManagerAP.h
		- (nm_ap_get_enc_key_source): return 'const char *' rather than 'char *'

	* src/NetworkManagerDbus.c
	  src/NetworkManagerDbus.h
		- (nm_dbus_update_network_auth_method -> nm_dbus_update_network_info): Update
			more than just the auth method

	* src/NetworkManagerDevice.c
		- Update network info at the appropriate times


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@817 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent a7015476
2005-08-04 Dan Williams <dcbw@redhat.com>
* gnome/applet/applet-dbus-info.c
gnome/applet/applet-dbus-info.h
- (nmi_dbus_update_network_auth_method->nmi_save_network_info): generalize
to store key, key type, and auth method rather than just auth method
- (nmi_dbus_update_network_info): new function
- (nmi_dbus_info_message_handler): updateNetworkAuthMethod -> updateNetworkInfo
* gnome/applet/passphrase-dialog.c
- (nmi_passphrase_dialog_ok_clicked): call nmi_save_network_info() instead
of saving the info ourselves
* gnome/libnm_glib/libnm_glib.c
- Remove the stupid version check for dbus
* src/NetworkManagerAP.c
src/NetworkManagerAP.h
- (nm_ap_get_enc_key_source): return 'const char *' rather than 'char *'
* src/NetworkManagerDbus.c
src/NetworkManagerDbus.h
- (nm_dbus_update_network_auth_method -> nm_dbus_update_network_info): Update
more than just the auth method
* src/NetworkManagerDevice.c
- Update network info at the appropriate times
2005-07-29 Ray Strode <rstrode@redhat.com>
* src/NetworkManager.c (nm_info_handler): don't use input as format
......
......@@ -804,52 +804,114 @@ static DBusMessage *nmi_dbus_get_vpn_connection_routes (NMWirelessApplet *applet
/*
* nmi_dbus_update_network_auth_method
* nmi_save_network_info
*
* Update a network's authentication method entry in gconf
* Save information about a wireless network in gconf and the gnome keyring.
*
*/
static DBusMessage *nmi_dbus_update_network_auth_method (NMWirelessApplet *applet, DBusMessage *message)
void nmi_save_network_info (NMWirelessApplet *applet, const char *essid, const char *enc_key_source,
const NMEncKeyType enc_key_type, const NMDeviceAuthMethod auth_method)
{
DBusMessage *reply_message = NULL;
char *network = NULL;
NMDeviceAuthMethod auth_method = NM_DEVICE_AUTH_METHOD_UNKNOWN;
char *key;
GConfValue *value;
DBusError error;
char *escaped_network;
char * key;
GConfEntry * gconf_entry;
char * escaped_network;
g_return_val_if_fail (applet != NULL, NULL);
g_return_val_if_fail (message != NULL, NULL);
dbus_error_init (&error);
if ( !dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &auth_method, DBUS_TYPE_INVALID)
|| (strlen (network) <= 0)
|| (auth_method == NM_DEVICE_AUTH_METHOD_UNKNOWN))
{
reply_message = nmwa_dbus_create_error_message (message, NMI_DBUS_INTERFACE, "InvalidArguments",
"NetworkManagerInfo::updateNetworkAuthMethod called with invalid arguments.");
return (reply_message);
}
g_return_if_fail (applet != NULL);
g_return_if_fail (essid != NULL);
/* Ensure the access point exists in GConf */
escaped_network = gconf_escape_key (network, strlen (network));
key = g_strdup_printf ("%s/%s/essid", GCONF_PATH_WIRELESS_NETWORKS, escaped_network);
value = gconf_client_get (applet->gconf_client, key, NULL);
escaped_network = gconf_escape_key (essid, strlen (essid));
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);
g_free (key);
if (value && (value->type == GCONF_VALUE_STRING))
if (gconf_entry)
{
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);
GnomeKeyringAttributeList *attributes;
GnomeKeyringAttribute attr;
GnomeKeyringResult ret;
const char *name;
guint32 item_id;
if (enc_key_source && strlen (enc_key_source)
&& (enc_key_type != NM_ENC_TYPE_UNKNOWN) && (enc_key_type != NM_ENC_TYPE_NONE))
{
/* Setup a request to the keyring to save the network passphrase */
name = g_strdup_printf (_("Passphrase for wireless network %s"), essid);
attributes = gnome_keyring_attribute_list_new ();
attr.name = g_strdup ("essid"); /* FIXME: Do we need to free this ? */
attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
attr.value.string = g_strdup (essid);
g_array_append_val (attributes, attr);
ret = gnome_keyring_item_create_sync (NULL,
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);
else
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);
}
if (value)
gconf_value_free (value);
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);
if (auth_method != NM_DEVICE_AUTH_METHOD_UNKNOWN)
{
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);
}
}
g_free (escaped_network);
}
return (NULL);
/*
* nmi_dbus_update_network_info
*
* Update a network's authentication method and encryption key in gconf & the keyring
*
*/
static void nmi_dbus_update_network_info (NMWirelessApplet *applet, DBusMessage *message)
{
DBusMessage * reply_message = NULL;
char * network = NULL;
NMDeviceAuthMethod auth_method = NM_DEVICE_AUTH_METHOD_UNKNOWN;
char * enc_key_source = NULL;
int enc_key_type = -1;
char * key;
GConfValue * value;
DBusError error;
char * escaped_network;
dbus_bool_t args_good;
g_return_if_fail (applet != NULL);
g_return_if_fail (message != NULL);
dbus_error_init (&error);
args_good = dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network,
DBUS_TYPE_STRING, &enc_key_source,
DBUS_TYPE_INT32, &enc_key_type,
DBUS_TYPE_INT32, &auth_method,
DBUS_TYPE_INVALID);
if (!args_good || (strlen (network) <= 0) || (auth_method == NM_DEVICE_AUTH_METHOD_UNKNOWN))
return;
if (enc_key_source && strlen (enc_key_source) && ((enc_key_type == NM_ENC_TYPE_UNKNOWN) || (enc_key_type == NM_ENC_TYPE_NONE)))
return;
nmi_save_network_info (applet, network, enc_key_source, (NMEncKeyType) enc_key_type, auth_method);
}
......@@ -999,8 +1061,8 @@ DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBu
reply = nmi_dbus_get_networks (applet, message);
else if (strcmp ("getNetworkProperties", method) == 0)
reply = nmi_dbus_get_network_properties (applet, message);
else if (strcmp ("updateNetworkAuthMethod", method) == 0)
nmi_dbus_update_network_auth_method (applet, message);
else if (strcmp ("updateNetworkInfo", method) == 0)
nmi_dbus_update_network_info (applet, message);
else if (strcmp ("addNetworkAddress", method) == 0)
nmi_dbus_add_network_address (applet, message);
else if (strcmp ("getVPNConnections", method) == 0)
......
......@@ -28,14 +28,18 @@
#include "wireless-network.h"
#include "NetworkManager.h"
DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data);
DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data);
void nmi_dbus_return_user_key (DBusConnection *connection, DBusMessage *message, const char *passphrase, const NMEncKeyType key_type);
void nmi_dbus_return_user_key (DBusConnection *connection, DBusMessage *message, const char *passphrase, const NMEncKeyType key_type);
void nmi_dbus_signal_update_scan_method (DBusConnection *connection);
void nmi_dbus_signal_update_scan_method (DBusConnection *connection);
void nmi_dbus_signal_update_network (DBusConnection *connection, const char *network, NMNetworkType type);
void nmi_dbus_signal_update_network (DBusConnection *connection, const char *network, NMNetworkType type);
void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const char *name);
void nmi_save_network_info (NMWirelessApplet *applet, const char *essid, const char *enc_key_source,
const NMEncKeyType enc_key_type, const NMDeviceAuthMethod auth_method);
void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const char *name);
#endif
......@@ -191,10 +191,7 @@ static void nmi_passphrase_dialog_ok_clicked (GtkWidget *ok_button, gpointer use
NetworkDevice * dev = g_object_get_data (G_OBJECT (dialog), "device");
WirelessNetwork * net = g_object_get_data (G_OBJECT (dialog), "network");
DBusMessage * message = g_object_get_data (G_OBJECT (dialog), "dbus-message");
char * key = NULL;
NMEncKeyType key_type_return = NM_ENC_TYPE_UNKNOWN;
GConfEntry * gconf_entry;
char * escaped_network;
g_return_if_fail ((dialog_xml = get_dialog_xml (dialog)) != NULL);
......@@ -220,53 +217,7 @@ static void nmi_passphrase_dialog_ok_clicked (GtkWidget *ok_button, gpointer use
/* Tell NetworkManager about the key the user typed in */
nmi_dbus_return_user_key (applet->connection, message, passphrase, key_type_return);
/* Update GConf with the new user key */
escaped_network = gconf_escape_key (wireless_network_get_essid (net), strlen (wireless_network_get_essid (net)));
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);
g_free (key);
if (gconf_entry)
{
GnomeKeyringAttributeList *attributes;
GnomeKeyringAttribute attr;
GnomeKeyringResult ret;
const char *essid, *name;
guint32 item_id;
/* Setup a request to the keyring to save the network passphrase */
essid = wireless_network_get_essid (net);
name = g_strdup_printf (_("Passphrase for wireless network %s"), essid);
attributes = gnome_keyring_attribute_list_new ();
attr.name = g_strdup ("essid"); /* FIXME: Do we need to free this ? */
attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
attr.value.string = g_strdup (essid);
g_array_append_val (attributes, attr);
ret = gnome_keyring_item_create_sync (NULL,
GNOME_KEYRING_ITEM_GENERIC_SECRET,
name,
attributes,
passphrase,
TRUE,
&item_id);
if (ret != GNOME_KEYRING_RESULT_OK)
g_warning ("Error saving passphrase in keyring. Ret=%d", ret);
else
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, key_type_return, NULL);
g_free (key);
}
g_free (escaped_network);
nmi_save_network_info (applet, wireless_network_get_essid(net), passphrase, key_type_return, NM_DEVICE_AUTH_METHOD_UNKNOWN);
nmi_passphrase_dialog_clear (dialog);
}
}
......
......@@ -200,7 +200,6 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu
dbus_connection_disconnect (ctx->dbus_con);
libnm_glib_schedule_dbus_watcher (ctx);
}
#if ((DBUS_VERSION_MAJOR == 0) && ((DBUS_VERSION_MINOR == 30) || (DBUS_VERSION_MINOR == 31) || (DBUS_VERSION_MINOR == 32) || (DBUS_VERSION_MINOR == 33) || (DBUS_VERSION_MINOR == 34) || (DBUS_VERSION_MINOR == 35)))
else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
{
/* New signal for dbus 0.23... */
......@@ -226,10 +225,6 @@ static DBusHandlerResult libnm_glib_dbus_filter (DBusConnection *connection, DBu
}
}
}
#else
#error "Unrecognized version of DBUS."
#endif
else if ( dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNowActive")
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceNoLongerActive")
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivating")
......
......@@ -40,7 +40,7 @@ NetworkManager_SOURCES = \
nm-netlink-monitor.h \
nm-activation-request.c \
nm-activation-request.h \
autoip.c \
autoip.c \
autoip.h
NetworkManager_CPPFLAGS = \
......
......@@ -204,7 +204,7 @@ void nm_ap_set_essid (NMAccessPoint *ap, const char * essid)
* Get/set functions for encryption key
*
*/
char * nm_ap_get_enc_key_source (const NMAccessPoint *ap)
const char * nm_ap_get_enc_key_source (const NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, NULL);
......@@ -224,8 +224,8 @@ void nm_ap_set_enc_key_source (NMAccessPoint *ap, const char * key, NMEncKeyType
char *nm_ap_get_enc_key_hashed (const NMAccessPoint *ap)
{
char *hashed = NULL;
char *source_key;
char * hashed = NULL;
const char * source_key;
g_return_val_if_fail (ap != NULL, NULL);
......
......@@ -40,7 +40,7 @@ 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);
char * nm_ap_get_enc_key_source (const NMAccessPoint *ap);
const char * nm_ap_get_enc_key_source (const NMAccessPoint *ap);
char * nm_ap_get_enc_key_hashed (const NMAccessPoint *ap);
void nm_ap_set_enc_key_source (NMAccessPoint *ap, const char *key, NMEncKeyType type);
NMEncKeyType nm_ap_get_enc_type (const NMAccessPoint *ap);
......
......@@ -626,35 +626,50 @@ void nm_dbus_update_wireless_scan_method (DBusConnection *connection, NMData *da
/*
* nm_dbus_update_network_auth_method
* nm_dbus_update_network_info
*
* Tell NetworkManagerInfo the updated auth_method of the AP
* Tell NetworkManagerInfo the updated info of the AP
*
*/
gboolean nm_dbus_update_network_auth_method (DBusConnection *connection, const char *network, const NMDeviceAuthMethod auth_method)
gboolean nm_dbus_update_network_info (DBusConnection *connection, NMAccessPoint *ap)
{
DBusMessage * message;
gboolean success = FALSE;
dbus_int32_t auth_method_as_int32 = (dbus_int32_t) auth_method;
dbus_int32_t auth_method;
const char * essid;
const char * enc_key_source;
dbus_int32_t enc_key_type;
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (network != NULL, FALSE);
g_return_val_if_fail (auth_method != NM_DEVICE_AUTH_METHOD_UNKNOWN, FALSE);
g_return_val_if_fail (ap != NULL, FALSE);
auth_method = nm_ap_get_auth_method (ap);
if (auth_method == NM_DEVICE_AUTH_METHOD_UNKNOWN)
return FALSE;
essid = nm_ap_get_essid (ap);
if (!(enc_key_source = nm_ap_get_enc_key_source (ap)))
enc_key_source = "";
enc_key_type = nm_ap_get_enc_type (ap);
if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "updateNetworkAuthMethod")))
if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "updateNetworkInfo")))
{
nm_warning ("nm_dbus_update_network_auth_method (): Couldn't allocate the dbus message");
return (FALSE);
nm_warning ("nm_dbus_update_network_info(): Couldn't allocate the dbus message");
return FALSE;
}
dbus_message_append_args (message, DBUS_TYPE_STRING, &network, DBUS_TYPE_INT32, &auth_method, DBUS_TYPE_INVALID);
dbus_message_append_args (message, DBUS_TYPE_STRING, &essid,
DBUS_TYPE_STRING, &enc_key_source,
DBUS_TYPE_INT32, &enc_key_type,
DBUS_TYPE_INT32, &auth_method,
DBUS_TYPE_INVALID);
if (!dbus_connection_send (connection, message, NULL))
nm_warning ("nm_dbus_update_network_auth_method (): failed to send dbus message.");
nm_warning ("nm_dbus_update_network_info(): failed to send dbus message.");
else
success = TRUE;
dbus_message_unref (message);
return (success);
return success;
}
......
......@@ -76,7 +76,7 @@ NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetwo
gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType type, const char *network, struct ether_addr *addr);
gboolean nm_dbus_update_network_auth_method (DBusConnection *connection, const char *network, const NMDeviceAuthMethod auth_method);
gboolean nm_dbus_update_network_info (DBusConnection *connection, NMAccessPoint *ap);
void nm_dbus_update_allowed_networks (DBusConnection *connection, NMAccessPointList *list, NMData *data);
......
......@@ -2968,8 +2968,10 @@ static gboolean nm_device_activate_stage5_ip_config_commit (NMActRequest *req)
NMAccessPoint *ap = nm_act_request_get_ap (req);
NMAccessPoint *tmp_ap;
/* Cache the last known good auth method in both NetworkManagerInfo and our allowed AP list */
nm_dbus_update_network_auth_method (data->dbus_connection, nm_ap_get_essid (ap), nm_ap_get_auth_method (ap));
/* Cache details in the info-daemon since the connect was successful */
nm_dbus_update_network_info (data->dbus_connection, ap);
/* Cache the correct auth method in our AP list too */
if ((tmp_ap = nm_ap_list_get_ap_by_essid (data->allowed_ap_list, nm_ap_get_essid (ap))))
nm_ap_set_auth_method (tmp_ap, nm_ap_get_auth_method (ap));
}
......@@ -3280,7 +3282,7 @@ void nm_device_set_user_key_for_network (NMActRequest *req, const char *key, con
/* Be sure to update NMI with the new auth mode */
nm_ap_set_auth_method (allowed_ap, NM_DEVICE_AUTH_METHOD_OPEN_SYSTEM);
nm_dbus_update_network_auth_method (data->dbus_connection, nm_ap_get_essid (allowed_ap), nm_ap_get_auth_method (allowed_ap));
nm_dbus_update_network_info (data->dbus_connection, allowed_ap);
nm_device_activate_schedule_stage1_device_prepare (req);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment